Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ RUN npm install
RUN npx node-pre-gyp package

COPY lib ./lib
COPY typings ./typings
COPY tests ./tests
COPY ./wait-for-it.sh /

Expand Down
11 changes: 11 additions & 0 deletions binding.gyp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"target_name": "action_after_build",
"type": "none",
"dependencies": [ "<(module_name)" ],
"copies": [
{
"files": [ "<(PRODUCT_DIR)/<(module_name).node" ],
"destination": "<(module_path)"
}
]
}
4 changes: 2 additions & 2 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import {
powerOff,
reboot,
system,
} from '../native/index.node';
} from './systemd-bindings';

export { system, SystemBus } from '../native/index.node';
export { system, SystemBus } from './systemd-bindings';

/**
* Convenience method to return a singleton instance of the system bus.
Expand Down
59 changes: 59 additions & 0 deletions lib/systemd-bindings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/**
* We need to import binaries according to
* https://nodejs.github.io/node-addon-examples/build-tools/node-pre-gyp/#javascript-updates
* however, node-pre-gyp does not have typescript declarations so
* eslint will complain, which is why we add the eslint-disable-line
* statements
*/
const binary = require('@mapbox/node-pre-gyp'); // eslint-disable-line
const path = require('path'); // eslint-disable-line
const bindingPath = binary.find(
path.resolve(path.join(__dirname, '../package.json')),
);
const binding = require(bindingPath); // eslint-disable-line

export declare class SystemBus {
// Needed for typechecking
private static readonly __id: unique symbol;

// Do not allow direct instantiation
// or sub-classing
private constructor();
}

export declare function system(): Promise<SystemBus>;

// These methods
export declare function unitActiveState(
bus: SystemBus,
unitName: string,
): Promise<string>;
export declare function unitPartOf(
bus: SystemBus,
unitName: string,
): Promise<string[]>;
export declare function unitStart(
bus: SystemBus,
unitName: string,
mode: string,
): Promise<void>;
export declare function unitStop(
bus: SystemBus,
unitName: string,
mode: string,
): Promise<void>;
export declare function unitRestart(
bus: SystemBus,
unitName: string,
mode: string,
): Promise<void>;
export declare function reboot(
bus: SystemBus,
interactive: boolean,
): Promise<void>;
export declare function powerOff(
bus: SystemBus,
interactive: boolean,
): Promise<void>;

module.exports = exports = binding;
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"author": "Balena Inc. <hello@balena.io>",
"license": "Apache-2.0",
"devDependencies": {
"@balena/lint": "^7.2.0",
"@balena/lint": "^7.2.4",
"@types/chai": "^4.3.5",
"@types/chai-as-promised": "^7.1.5",
"@types/mocha": "^10.0.1",
Expand All @@ -49,7 +49,7 @@
"mocha": "^10.2.0",
"rimraf": "^5.0.1",
"ts-node": "^10.9.1",
"typescript": "^5.1.6"
"typescript": "^5.3.0"
},
"versionist": {
"publishedAt": "2023-09-29T15:45:49.697Z"
Expand Down
1 change: 0 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,5 @@
"include": [
"lib/**/*.ts",
"tests/**/*.ts",
"typings/**/*.d.ts"
]
}
15 changes: 7 additions & 8 deletions tsconfig.release.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
{
"extends": "./tsconfig.json",
"include": [
"lib/**/*.ts",
"typings/**/*.d.ts"
],
"exclude": [
"lib/**/*.spec.ts"
]
"extends": "./tsconfig.json",
"include": [
"lib/**/*.ts",
],
"exclude": [
"lib/**/*.spec.ts"
]
}
21 changes: 0 additions & 21 deletions typings/index.node.d.ts

This file was deleted.