@ohos-ports/jest-dev-server 11.0.0-beta.0 → 11.0.0-beta.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/dist/index.js +37 -1
  2. package/package.json +4 -1
package/dist/index.js CHANGED
@@ -4,6 +4,23 @@ var node_stream = require('node:stream');
4
4
  var node_net = require('node:net');
5
5
  var node_util = require('node:util');
6
6
  var chalk = require('chalk');
7
+ // HarmonyOS: spawnd's destroy() kills the process tree via its own transitive
8
+ // 'tree-kill' dependency, which is unpatched on openharmony whenever this
9
+ // package is not the install root (npm applies "overrides" only from the
10
+ // install root). Redirect the 'tree-kill' module instance resolvable from
11
+ // here to @ohos-ports/tree-kill BEFORE spawnd is loaded, so spawnd's own
12
+ // kill primitive is the HarmonyOS-fixed one. No-op when the resolved
13
+ // implementation is already the patched one.
14
+ try {
15
+ var ohosTreeKill = require('@ohos-ports/tree-kill');
16
+ var tkPath = require.resolve('tree-kill');
17
+ require(tkPath); // ensure the module instance is cached
18
+ if (require.cache[tkPath].exports !== ohosTreeKill) {
19
+ require.cache[tkPath].exports = ohosTreeKill;
20
+ }
21
+ } catch (e) {
22
+ // 'tree-kill' not resolvable from here — leave resolution untouched
23
+ }
7
24
  var spawnd = require('spawnd');
8
25
  var cwd = require('cwd');
9
26
  var waitOn = require('wait-on');
@@ -201,7 +218,26 @@ async function setup(providedConfigs) {
201
218
  }
202
219
  async function teardown(procs) {
203
220
  if (procs.length) {
204
- await Promise.all(procs.map((proc)=>proc.destroy()));
221
+ await Promise.all(procs.map(async (proc)=>{
222
+ await proc.destroy();
223
+ // HarmonyOS: spawnd's destroy() may leave the spawned process tree
224
+ // alive when its own transitive 'tree-kill' is unpatched (consumer
225
+ // installs where npm overrides do not apply: `ps --no-headers` is
226
+ // unsupported by toybox and the `sh -c` wrapper ignores SIGTERM).
227
+ // destroy() has already removed spawnd's exit listeners and
228
+ // unregistered signal-exit, so a direct fallback kill is safe.
229
+ // Verify the pid is gone and hard-kill survivors with this
230
+ // module's own pTreeKill (@ohos-ports/tree-kill is a direct
231
+ // dependency that resolves at any install depth).
232
+ if (typeof proc.pid === "number") {
233
+ try {
234
+ process.kill(proc.pid, 0); // throws ESRCH when already dead -> nothing to do
235
+ await pTreeKill(proc.pid); // kills the full sh->node tree
236
+ } catch (err) {
237
+ // already dead (ESRCH) or the kill raced with process exit — acceptable
238
+ }
239
+ }
240
+ }));
205
241
  }
206
242
  }
207
243
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ohos-ports/jest-dev-server",
3
3
  "description": "Starts a server before your Jest tests and tears it down after.",
4
- "version": "11.0.0-beta.0",
4
+ "version": "11.0.0-beta.1",
5
5
  "type": "commonjs",
6
6
  "main": "./dist/index.js",
7
7
  "types": "./dist/index.d.ts",
@@ -33,6 +33,9 @@
33
33
  "publishConfig": {
34
34
  "access": "public"
35
35
  },
36
+ "overrides": {
37
+ "tree-kill": "npm:@ohos-ports/tree-kill@^1.2.2-beta.0"
38
+ },
36
39
  "scripts": {
37
40
  "prebuild": "rm -rf dist",
38
41
  "build": "rollup -c"