@deveco-test/deveco-cli 1.3.5-Test.4 → 1.3.10-Test.1

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.
Files changed (2) hide show
  1. package/cli.js +56 -13
  2. package/package.json +3 -3
package/cli.js CHANGED
@@ -1,17 +1,19 @@
1
1
  #!/usr/bin/env node
2
2
  // Shell entry: map process.platform to an implementation package, resolve its
3
- // absolute cli.js path, and spawnSync-exec it with all argv forwarded.
3
+ // absolute cli.js path, and spawn it with all argv forwarded.
4
4
  // Command parsing, error handling, and exit code are all owned by the impl pkg.
5
- import { spawnSync } from 'node:child_process';
5
+ import { spawn } from 'node:child_process';
6
6
  import { createRequire } from 'node:module';
7
7
  import { readFileSync } from 'node:fs';
8
+ import { constants } from 'node:os';
9
+ import process from 'node:process';
8
10
 
9
11
  // Pass wrapper identity to the impl process so `devecocli update` installs
10
12
  // THIS package (the one the user installed), not the nested impl dependency.
11
13
  // These env names are NOT in tsup's `env` map, so they survive as runtime
12
14
  // process.env reads in the built impl bundle.
13
15
  const wrapperPkg = JSON.parse(
14
- readFileSync(new URL('./package.json', import.meta.url), 'utf8'),
16
+ readFileSync(new URL('./package.json', import.meta.url), 'utf8')
15
17
  );
16
18
  process.env.DEVECO_CLI_WRAPPER_NAME = wrapperPkg.name;
17
19
  process.env.DEVECO_CLI_WRAPPER_VERSION = wrapperPkg.version;
@@ -25,8 +27,8 @@ const IMPL_PKG = (() => {
25
27
  if (!match) {
26
28
  process.stderr.write(
27
29
  `devecocli: no implementation package found for platform "${process.platform}".\n` +
28
- ` available: ${deps.length ? deps.join(', ') : '(none)'}\n` +
29
- ` expected a package containing "${needle}"\n`
30
+ ` available: ${deps.length ? deps.join(', ') : '(none)'}\n` +
31
+ ` expected a package containing "${needle}"\n`
30
32
  );
31
33
  process.exit(1);
32
34
  }
@@ -39,19 +41,60 @@ try {
39
41
  } catch (err) {
40
42
  process.stderr.write(
41
43
  `devecocli: implementation package "${IMPL_PKG}" is not installed for this platform.\n` +
42
- ` platform: ${process.platform}\n` +
43
- ` expected: ${IMPL_PKG}\n` +
44
- ` cause: ${err && err.message ? err.message : err}\n`
44
+ ` platform: ${process.platform}\n` +
45
+ ` expected: ${IMPL_PKG}\n` +
46
+ ` cause: ${err && err.message ? err.message : err}\n`
45
47
  );
46
48
  process.exit(1);
47
49
  }
48
50
 
49
- const result = spawnSync(process.execPath, [cliPath, ...process.argv.slice(2)], {
51
+ const args = [cliPath, ...process.argv.slice(2)];
52
+ if (process.env.DEVECO_CLI_DEBUG) {
53
+ process.stderr.write(
54
+ `[DEBUG] Executing: ${process.execPath} ${args.join(' ')}\n`
55
+ );
56
+ }
57
+ const child = spawn(process.execPath, args, {
50
58
  stdio: 'inherit',
59
+ windowsHide: true,
51
60
  });
52
61
 
53
- if (result.error) {
54
- process.stderr.write(`devecocli: failed to spawn implementation: ${result.error.message}\n`);
55
- process.exit(1);
62
+ let interrupted = false;
63
+ const handlers = new Map();
64
+ for (const signal of ['SIGINT', 'SIGTERM', 'SIGHUP']) {
65
+ const handler = () => {
66
+ if (child.exitCode !== null || child.signalCode !== null) {
67
+ return;
68
+ }
69
+ if (interrupted) {
70
+ child.kill('SIGKILL');
71
+ return;
72
+ }
73
+ interrupted = true;
74
+ // Windows console Ctrl+C reaches the child; kill('SIGINT') would force it to exit.
75
+ if (process.platform !== 'win32' || signal !== 'SIGINT') {
76
+ child.kill(signal);
77
+ }
78
+ };
79
+ handlers.set(signal, handler);
80
+ process.on(signal, handler);
81
+ }
82
+
83
+ function cleanup() {
84
+ for (const [signal, handler] of handlers) {
85
+ process.off(signal, handler);
86
+ }
56
87
  }
57
- process.exit(result.status ?? 1);
88
+
89
+ child.once('error', (error) => {
90
+ cleanup();
91
+ process.stderr.write(
92
+ `devecocli: failed to spawn implementation: ${error.message}\n`
93
+ );
94
+ process.exitCode = 1;
95
+ });
96
+ child.once('close', (code, signal) => {
97
+ cleanup();
98
+ process.exitCode ??=
99
+ code ?? (signal ? 128 + (constants.signals[signal] || 1) : 1);
100
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deveco-test/deveco-cli",
3
- "version": "1.3.5-Test.4",
3
+ "version": "1.3.10-Test.1",
4
4
  "description": "HarmonyOS application development command line tool",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -20,7 +20,7 @@
20
20
  "openharmony"
21
21
  ],
22
22
  "optionalDependencies": {
23
- "@deveco-test/deveco-cli-openharmony-arm64": "1.3.5-Test.4",
24
- "@deveco-test/deveco-cli-common": "1.3.5-Test.4"
23
+ "@deveco-test/deveco-cli-openharmony-arm64": "1.3.10-Test.1",
24
+ "@deveco-test/deveco-cli-common": "1.3.10-Test.1"
25
25
  }
26
26
  }