@dxos/phoenix 0.8.4-main.dedc0f3 → 0.8.4-main.dfabb4ec29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/watchdog.mjs +5 -0
- package/dist/lib/node-esm/index.mjs +13 -58
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/phoenix.d.ts +2 -2
- package/dist/types/src/phoenix.d.ts.map +1 -1
- package/dist/types/src/testing-utils.d.ts.map +1 -1
- package/dist/types/src/utils.d.ts.map +1 -1
- package/dist/types/src/watchdog.d.ts +3 -3
- package/dist/types/src/watchdog.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +9 -8
- package/src/phoenix.node.test.ts +7 -9
- package/src/phoenix.ts +2 -3
- package/src/watchdog.node.test.ts +2 -3
- package/src/watchdog.ts +3 -3
package/package.json
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/phoenix",
|
|
3
|
-
"version": "0.8.4-main.
|
|
3
|
+
"version": "0.8.4-main.dfabb4ec29",
|
|
4
4
|
"description": "Basic node daemon.",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/dxos/dxos"
|
|
10
|
+
},
|
|
7
11
|
"license": "MIT",
|
|
8
12
|
"author": "DXOS.org",
|
|
9
13
|
"sideEffects": true,
|
|
@@ -16,9 +20,6 @@
|
|
|
16
20
|
}
|
|
17
21
|
},
|
|
18
22
|
"types": "dist/types/src/index.d.ts",
|
|
19
|
-
"typesVersions": {
|
|
20
|
-
"*": {}
|
|
21
|
-
},
|
|
22
23
|
"files": [
|
|
23
24
|
"bin",
|
|
24
25
|
"dist",
|
|
@@ -26,10 +27,10 @@
|
|
|
26
27
|
],
|
|
27
28
|
"dependencies": {
|
|
28
29
|
"pkg-up": "^3.1.0",
|
|
29
|
-
"@dxos/async": "0.8.4-main.
|
|
30
|
-
"@dxos/invariant": "0.8.4-main.
|
|
31
|
-
"@dxos/
|
|
32
|
-
"@dxos/
|
|
30
|
+
"@dxos/async": "0.8.4-main.dfabb4ec29",
|
|
31
|
+
"@dxos/invariant": "0.8.4-main.dfabb4ec29",
|
|
32
|
+
"@dxos/node-std": "0.8.4-main.dfabb4ec29",
|
|
33
|
+
"@dxos/log": "0.8.4-main.dfabb4ec29"
|
|
33
34
|
},
|
|
34
35
|
"publishConfig": {
|
|
35
36
|
"access": "public"
|
package/src/phoenix.node.test.ts
CHANGED
|
@@ -3,9 +3,8 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { spawn } from 'node:child_process';
|
|
6
|
-
import {
|
|
6
|
+
import { readFileSync } from 'node:fs';
|
|
7
7
|
import { join } from 'node:path';
|
|
8
|
-
|
|
9
8
|
import { describe, expect, onTestFinished, test } from 'vitest';
|
|
10
9
|
|
|
11
10
|
import { Trigger } from '@dxos/async';
|
|
@@ -13,7 +12,7 @@ import { Trigger } from '@dxos/async';
|
|
|
13
12
|
import { Phoenix } from './phoenix';
|
|
14
13
|
import { TEST_DIR, clearFiles, neverEndingProcess } from './testing-utils';
|
|
15
14
|
|
|
16
|
-
describe('DaemonManager', () => {
|
|
15
|
+
describe.skipIf(process.env.CI)('DaemonManager', () => {
|
|
17
16
|
test('kill process by pid', async () => {
|
|
18
17
|
const child = spawn('node', ['-e', `(${neverEndingProcess.toString()})()`]);
|
|
19
18
|
const trigger = new Trigger();
|
|
@@ -22,11 +21,9 @@ describe('DaemonManager', () => {
|
|
|
22
21
|
});
|
|
23
22
|
|
|
24
23
|
process.kill(child.pid!, 'SIGKILL');
|
|
25
|
-
|
|
26
24
|
await trigger.wait({ timeout: 1_000 });
|
|
27
25
|
});
|
|
28
26
|
|
|
29
|
-
// Fails on CI
|
|
30
27
|
test('start/stop detached watchdog', async () => {
|
|
31
28
|
const runId = Math.random().toString();
|
|
32
29
|
const pidFile = join(TEST_DIR, `pid-${runId}.pid`);
|
|
@@ -46,9 +43,11 @@ describe('DaemonManager', () => {
|
|
|
46
43
|
errFile,
|
|
47
44
|
});
|
|
48
45
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
expect
|
|
46
|
+
// Poll for log content directly — the file is pre-created empty by Phoenix.start(),
|
|
47
|
+
// so polling for existence would resolve immediately before the child writes its output.
|
|
48
|
+
await expect
|
|
49
|
+
.poll(() => readFileSync(params.logFile, { encoding: 'utf-8' }), { timeout: 5000 })
|
|
50
|
+
.toContain('neverEndingProcess started');
|
|
52
51
|
}
|
|
53
52
|
|
|
54
53
|
// Stop
|
|
@@ -57,7 +56,6 @@ describe('DaemonManager', () => {
|
|
|
57
56
|
expect(info.profile).to.equal(runId);
|
|
58
57
|
|
|
59
58
|
await Phoenix.stop(pidFile);
|
|
60
|
-
|
|
61
59
|
await expect.poll(() => readFileSync(logFile, { encoding: 'utf-8' })).toContain('Stopped with exit code');
|
|
62
60
|
}
|
|
63
61
|
});
|
package/src/phoenix.ts
CHANGED
|
@@ -5,14 +5,13 @@
|
|
|
5
5
|
import { fork } from 'node:child_process';
|
|
6
6
|
import { existsSync, mkdirSync, readFileSync, unlinkSync, writeFileSync } from 'node:fs';
|
|
7
7
|
import { dirname, join } from 'node:path';
|
|
8
|
-
|
|
9
8
|
import pkgUp from 'pkg-up';
|
|
10
9
|
|
|
11
10
|
import { invariant } from '@dxos/invariant';
|
|
12
11
|
import { log } from '@dxos/log';
|
|
13
12
|
|
|
14
13
|
import { waitForPidDeletion, waitForPidFileBeingFilledWithInfo } from './utils';
|
|
15
|
-
import { type ProcessInfo, type
|
|
14
|
+
import { type ProcessInfo, type WatchDogProps } from './watchdog';
|
|
16
15
|
|
|
17
16
|
const scriptDir = typeof __dirname === 'string' ? __dirname : dirname(new URL(import.meta.url).pathname);
|
|
18
17
|
|
|
@@ -23,7 +22,7 @@ export class Phoenix {
|
|
|
23
22
|
/**
|
|
24
23
|
* Starts detached watchdog process which starts and monitors selected command.
|
|
25
24
|
*/
|
|
26
|
-
static async start(params:
|
|
25
|
+
static async start(params: WatchDogProps): Promise<ProcessInfo> {
|
|
27
26
|
{
|
|
28
27
|
// Clear stale pid file.
|
|
29
28
|
if (existsSync(params.pidFile)) {
|
|
@@ -4,13 +4,12 @@
|
|
|
4
4
|
|
|
5
5
|
import { existsSync } from 'node:fs';
|
|
6
6
|
import { join } from 'node:path';
|
|
7
|
-
|
|
8
7
|
import { describe, expect, onTestFinished, test } from 'vitest';
|
|
9
8
|
|
|
10
9
|
import { TEST_DIR, clearFiles, neverEndingProcess } from './testing-utils';
|
|
11
10
|
import { WatchDog } from './watchdog';
|
|
12
11
|
|
|
13
|
-
describe('WatchDog', () => {
|
|
12
|
+
describe.skipIf(process.env.CI)('WatchDog', () => {
|
|
14
13
|
test('Start/stop process', async () => {
|
|
15
14
|
const runId = Math.random();
|
|
16
15
|
const pidFile = join(TEST_DIR, `pid-${runId}.pid`);
|
|
@@ -27,8 +26,8 @@ describe('WatchDog', () => {
|
|
|
27
26
|
});
|
|
28
27
|
|
|
29
28
|
expect(existsSync(pidFile)).to.be.false;
|
|
30
|
-
await watchDog.start();
|
|
31
29
|
|
|
30
|
+
await watchDog.start();
|
|
32
31
|
expect(existsSync(pidFile)).to.be.true;
|
|
33
32
|
|
|
34
33
|
await watchDog.kill();
|
package/src/watchdog.ts
CHANGED
|
@@ -12,14 +12,14 @@ import { log } from '@dxos/log';
|
|
|
12
12
|
|
|
13
13
|
import { waitForPidDeletion, waitForPidFileBeingFilledWithInfo } from './utils';
|
|
14
14
|
|
|
15
|
-
export type ProcessInfo =
|
|
15
|
+
export type ProcessInfo = WatchDogProps & {
|
|
16
16
|
pid?: number;
|
|
17
17
|
started?: number;
|
|
18
18
|
restarts?: number;
|
|
19
19
|
running?: boolean;
|
|
20
20
|
};
|
|
21
21
|
|
|
22
|
-
export type
|
|
22
|
+
export type WatchDogProps = {
|
|
23
23
|
profile?: string; // Human readable process identifier
|
|
24
24
|
pidFile: string; // Path to PID file
|
|
25
25
|
|
|
@@ -56,7 +56,7 @@ export class WatchDog {
|
|
|
56
56
|
private _child?: ChildProcessWithoutNullStreams;
|
|
57
57
|
private _restarts = 0;
|
|
58
58
|
|
|
59
|
-
constructor(private readonly _params:
|
|
59
|
+
constructor(private readonly _params: WatchDogProps) {}
|
|
60
60
|
|
|
61
61
|
@synchronized
|
|
62
62
|
async start(): Promise<void> {
|