@ms-cloudpack/esm-stub-utilities 0.13.12 → 0.13.14

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.
@@ -6,6 +6,7 @@ import { initializeWorker } from '@ms-cloudpack/worker-pool';
6
6
  await initBrowserEnvironment();
7
7
  // TODO should the globals be marked as readonly if possible?
8
8
  const initialGlobalProperties = getGlobalProperties();
9
+ // eslint-disable-next-line no-restricted-properties -- exit handling for a worker
9
10
  const processExit = process.exit.bind(process);
10
11
  // Then initialize the worker with the appropriate listeners and api dictionary.
11
12
  initializeWorker({
@@ -15,11 +16,13 @@ initializeWorker({
15
16
  beforeEach: () => {
16
17
  // Override process.exit calls to throw rather than exit the process, in case we load some
17
18
  // CJS code that calls process.exit. This gives an actual call stack for debugging.
19
+ // eslint-disable-next-line no-restricted-properties
18
20
  process.exit = (code) => {
19
21
  throw new Error(`process.exit called with code ${code}`);
20
22
  };
21
23
  },
22
24
  afterEach: () => {
25
+ // eslint-disable-next-line no-restricted-properties
23
26
  process.exit = processExit;
24
27
  cleanUpGlobals(initialGlobalProperties);
25
28
  },
@@ -1 +1 @@
1
- {"version":3,"file":"workerEntry.js","sourceRoot":"","sources":["../../src/worker/workerEntry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACnE,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAE7D,4CAA4C;AAC5C,MAAM,sBAAsB,EAAE,CAAC;AAE/B,6DAA6D;AAC7D,MAAM,uBAAuB,GAAG,mBAAmB,EAAE,CAAC;AAEtD,MAAM,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AAE/C,gFAAgF;AAChF,gBAAgB,CAAC;IACf,OAAO,EAAE;QACP,aAAa;KACd;IACD,UAAU,EAAE,GAAG,EAAE;QACf,0FAA0F;QAC1F,mFAAmF;QACnF,OAAO,CAAC,IAAI,GAAG,CAAC,IAAI,EAAE,EAAE;YACtB,MAAM,IAAI,KAAK,CAAC,iCAAiC,IAAI,EAAE,CAAC,CAAC;QAC3D,CAAC,CAAC;IACJ,CAAC;IACD,SAAS,EAAE,GAAG,EAAE;QACd,OAAO,CAAC,IAAI,GAAG,WAAW,CAAC;QAC3B,cAAc,CAAC,uBAAuB,CAAC,CAAC;IAC1C,CAAC;IACD,4FAA4F;IAC5F,+DAA+D;IAC/D,OAAO,EAAE,EAAE,GAAG,IAAI;CACnB,CAAC,CAAC","sourcesContent":["import { initBrowserEnvironment } from './initBrowserEnvironment.js';\nimport { cleanUpGlobals, getGlobalProperties } from './globals.js';\nimport { writeESMStubs } from '../writeESMStubs.js';\nimport { initializeWorker } from '@ms-cloudpack/worker-pool';\n\n// Load any environmental side effects here.\nawait initBrowserEnvironment();\n\n// TODO should the globals be marked as readonly if possible?\nconst initialGlobalProperties = getGlobalProperties();\n\nconst processExit = process.exit.bind(process);\n\n// Then initialize the worker with the appropriate listeners and api dictionary.\ninitializeWorker({\n methods: {\n writeESMStubs,\n },\n beforeEach: () => {\n // Override process.exit calls to throw rather than exit the process, in case we load some\n // CJS code that calls process.exit. This gives an actual call stack for debugging.\n process.exit = (code) => {\n throw new Error(`process.exit called with code ${code}`);\n };\n },\n afterEach: () => {\n process.exit = processExit;\n cleanUpGlobals(initialGlobalProperties);\n },\n // Stop the worker after 30s. This is much longer than should usually be necessary, but it's\n // good to be conservative here in case of resource contention.\n timeout: 30 * 1000,\n});\n"]}
1
+ {"version":3,"file":"workerEntry.js","sourceRoot":"","sources":["../../src/worker/workerEntry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACnE,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAE7D,4CAA4C;AAC5C,MAAM,sBAAsB,EAAE,CAAC;AAE/B,6DAA6D;AAC7D,MAAM,uBAAuB,GAAG,mBAAmB,EAAE,CAAC;AAEtD,kFAAkF;AAClF,MAAM,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AAE/C,gFAAgF;AAChF,gBAAgB,CAAC;IACf,OAAO,EAAE;QACP,aAAa;KACd;IACD,UAAU,EAAE,GAAG,EAAE;QACf,0FAA0F;QAC1F,mFAAmF;QACnF,oDAAoD;QACpD,OAAO,CAAC,IAAI,GAAG,CAAC,IAAI,EAAE,EAAE;YACtB,MAAM,IAAI,KAAK,CAAC,iCAAiC,IAAI,EAAE,CAAC,CAAC;QAC3D,CAAC,CAAC;IACJ,CAAC;IACD,SAAS,EAAE,GAAG,EAAE;QACd,oDAAoD;QACpD,OAAO,CAAC,IAAI,GAAG,WAAW,CAAC;QAC3B,cAAc,CAAC,uBAAuB,CAAC,CAAC;IAC1C,CAAC;IACD,4FAA4F;IAC5F,+DAA+D;IAC/D,OAAO,EAAE,EAAE,GAAG,IAAI;CACnB,CAAC,CAAC","sourcesContent":["import { initBrowserEnvironment } from './initBrowserEnvironment.js';\nimport { cleanUpGlobals, getGlobalProperties } from './globals.js';\nimport { writeESMStubs } from '../writeESMStubs.js';\nimport { initializeWorker } from '@ms-cloudpack/worker-pool';\n\n// Load any environmental side effects here.\nawait initBrowserEnvironment();\n\n// TODO should the globals be marked as readonly if possible?\nconst initialGlobalProperties = getGlobalProperties();\n\n// eslint-disable-next-line no-restricted-properties -- exit handling for a worker\nconst processExit = process.exit.bind(process);\n\n// Then initialize the worker with the appropriate listeners and api dictionary.\ninitializeWorker({\n methods: {\n writeESMStubs,\n },\n beforeEach: () => {\n // Override process.exit calls to throw rather than exit the process, in case we load some\n // CJS code that calls process.exit. This gives an actual call stack for debugging.\n // eslint-disable-next-line no-restricted-properties\n process.exit = (code) => {\n throw new Error(`process.exit called with code ${code}`);\n };\n },\n afterEach: () => {\n // eslint-disable-next-line no-restricted-properties\n process.exit = processExit;\n cleanUpGlobals(initialGlobalProperties);\n },\n // Stop the worker after 30s. This is much longer than should usually be necessary, but it's\n // good to be conservative here in case of resource contention.\n timeout: 30 * 1000,\n});\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"writeESMStubsInWorker.d.ts","sourceRoot":"","sources":["../src/writeESMStubsInWorker.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AAC5E,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AAI1E;;GAEG;AAGH,wBAAsB,qBAAqB,CACzC,OAAO,EAAE,oBAAoB,GAAG;IAAE,UAAU,CAAC,EAAE,MAAM,CAAA;CAAE,GACtD,OAAO,CAAC,mBAAmB,CAAC,CAiC9B;AAED,wBAAsB,qBAAqB,kBAG1C"}
1
+ {"version":3,"file":"writeESMStubsInWorker.d.ts","sourceRoot":"","sources":["../src/writeESMStubsInWorker.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AAC5E,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AAI1E;;GAEG;AAGH,wBAAsB,qBAAqB,CACzC,OAAO,EAAE,oBAAoB,GAAG;IAAE,UAAU,CAAC,EAAE,MAAM,CAAA;CAAE,GACtD,OAAO,CAAC,mBAAmB,CAAC,CA6C9B;AAED,wBAAsB,qBAAqB,kBAG1C"}
@@ -6,19 +6,35 @@ let workerPool;
6
6
  // This is tested in bundler-rollup/src/writeESMStubsInWorker.test.ts so we can
7
7
  // use the compiled version of the workerEntry file.
8
8
  export async function writeESMStubsInWorker(options) {
9
- const { maxWorkers = 5, ...stubOptions } = options;
9
+ // Trim the options to only the necessary ones for the worker to reduce what's serialized
10
+ // (a larger BundleOptions object was likely passed in)
11
+ const onlyStubOptions = {
12
+ inputPath: options.inputPath,
13
+ entries: options.entries,
14
+ forceCJS: options.forceCJS,
15
+ };
10
16
  workerPool ??= new WorkerPool({
11
17
  name: 'ESM stub generation',
12
18
  parentPath: import.meta.url,
13
19
  entryPath: './worker/workerEntry',
14
- maxWorkers,
20
+ maxWorkers: options.maxWorkers || 5,
21
+ // Stop inactive workers after 5 minutes. This is intended to prevent one possible cause of
22
+ // OOM crashes if cloudpack start is left running for a long time (though it's much more likely
23
+ // that the issue is caused by servers or file watchers). The timeout is conservative because
24
+ // the fake browser environment has nontrivial startup time, so killing workers too quickly
25
+ // could slow down rebuilds.
26
+ inactiveTimeout: 5 * 60 * 1000,
27
+ // Most stubs seem to stay well under this size, and Node appears to be decent about freeing
28
+ // memory after writeESMStubs finishes, but this will catch anything giant or leaky.
29
+ // (This is only checked after task completion, so a package exceeding it will still be stubbed.)
30
+ maxHeapSize: 500 * 1024 * 1024,
31
+ // console.warn if a stub takes longer than this
32
+ warnAboveTime: process.env.CI ? 4000 : 2000,
15
33
  });
16
- const startTime = Date.now();
17
- console.info(`Starting ESM stub generation for ${options.inputPath}`);
18
34
  try {
19
35
  return await workerPool.execute({
20
36
  method: 'writeESMStubs',
21
- args: [stubOptions],
37
+ args: [onlyStubOptions],
22
38
  });
23
39
  }
24
40
  catch (err) {
@@ -33,9 +49,6 @@ export async function writeESMStubsInWorker(options) {
33
49
  ],
34
50
  };
35
51
  }
36
- finally {
37
- console.info(`Finished ESM stub generation for ${options.inputPath} in ${((Date.now() - startTime) / 1000).toFixed(3)}s`);
38
- }
39
52
  }
40
53
  export async function disposeStubWorkerPool() {
41
54
  await workerPool?.dispose();
@@ -1 +1 @@
1
- {"version":3,"file":"writeESMStubsInWorker.js","sourceRoot":"","sources":["../src/writeESMStubsInWorker.ts"],"names":[],"mappings":"A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E,OAAO,EAAE,CAAC;IAC5B,UAAU,GAAG,SAAS,CAAC;AACzB,CAAC","sourcesContent":["import { WorkerPool } from '@ms-cloudpack/worker-pool';\nimport type { WriteESMStubsOptions } from './types/WriteESMStubsOptions.js';\nimport type { WriteESMStubsResult } from './types/WriteESMStubsResult.js';\n\nlet workerPool: WorkerPool | undefined;\n\n/**\n * Write ESM stubs using a worker pool.\n */\n// This is tested in bundler-rollup/src/writeESMStubsInWorker.test.ts so we can\n// use the compiled version of the workerEntry file.\nexport async function writeESMStubsInWorker(\n options: WriteESMStubsOptions & { maxWorkers?: number },\n): Promise<WriteESMStubsResult> {\n const { maxWorkers = 5, ...stubOptions } = options;\n\n workerPool ??= new WorkerPool({\n name: 'ESM stub generation',\n parentPath: import.meta.url,\n entryPath: './worker/workerEntry',\n maxWorkers,\n });\n\n const startTime = Date.now();\n console.info(`Starting ESM stub generation for ${options.inputPath}`);\n try {\n return await workerPool.execute<WriteESMStubsResult>({\n method: 'writeESMStubs',\n args: [stubOptions],\n });\n } catch (err) {\n return {\n newEntries: {},\n errors: [\n {\n source: 'ESM stub generation',\n // note: err won't be an instance of Error because of serialization\n text: (err as Error)?.stack || (err as Error)?.message || String(err),\n },\n ],\n };\n } finally {\n console.info(\n `Finished ESM stub generation for ${options.inputPath} in ${((Date.now() - startTime) / 1000).toFixed(3)}s`,\n );\n }\n}\n\nexport async function disposeStubWorkerPool() {\n await workerPool?.dispose();\n workerPool = undefined;\n}\n"]}
1
+ {"version":3,"file":"writeESMStubsInWorker.js","sourceRoot":"","sources":["../src/writeESMStubsInWorker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAIvD,IAAI,UAAkC,CAAC;AAEvC;;GAEG;AACH,+EAA+E;AAC/E,oDAAoD;AACpD,MAAM,CAAC,KAAK,UAAU,qBAAqB,CACzC,OAAuD;IAEvD,yFAAyF;IACzF,uDAAuD;IACvD,MAAM,eAAe,GAAyB;QAC5C,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/worker-pool';\nimport type { WriteESMStubsOptions } from './types/WriteESMStubsOptions.js';\nimport type { WriteESMStubsResult } from './types/WriteESMStubsResult.js';\n\nlet workerPool: WorkerPool | undefined;\n\n/**\n * Write ESM stubs using a worker pool.\n */\n// This is tested in bundler-rollup/src/writeESMStubsInWorker.test.ts so we can\n// use the compiled version of the workerEntry file.\nexport async function writeESMStubsInWorker(\n options: WriteESMStubsOptions & { maxWorkers?: number },\n): Promise<WriteESMStubsResult> {\n // Trim the options to only the necessary ones for the worker to reduce what's serialized\n // (a larger BundleOptions object was likely passed in)\n const onlyStubOptions: WriteESMStubsOptions = {\n inputPath: options.inputPath,\n entries: options.entries,\n forceCJS: options.forceCJS,\n };\n\n workerPool ??= new WorkerPool({\n name: 'ESM stub generation',\n parentPath: import.meta.url,\n entryPath: './worker/workerEntry',\n maxWorkers: options.maxWorkers || 5,\n // Stop inactive workers after 5 minutes. This is intended to prevent one possible cause of\n // OOM crashes if cloudpack start is left running for a long time (though it's much more likely\n // that the issue is caused by servers or file watchers). The timeout is conservative because\n // the fake browser environment has nontrivial startup time, so killing workers too quickly\n // could slow down rebuilds.\n inactiveTimeout: 5 * 60 * 1000,\n // Most stubs seem to stay well under this size, and Node appears to be decent about freeing\n // memory after writeESMStubs finishes, but this will catch anything giant or leaky.\n // (This is only checked after task completion, so a package exceeding it will still be stubbed.)\n maxHeapSize: 500 * 1024 * 1024,\n // console.warn if a stub takes longer than this\n warnAboveTime: process.env.CI ? 4000 : 2000,\n });\n\n try {\n return await workerPool.execute<WriteESMStubsResult>({\n method: 'writeESMStubs',\n args: [onlyStubOptions],\n });\n } catch (err) {\n return {\n newEntries: {},\n errors: [\n {\n source: 'ESM stub generation',\n // note: err won't be an instance of Error because of serialization\n text: (err as Error)?.stack || (err as Error)?.message || String(err),\n },\n ],\n };\n }\n}\n\nexport async function disposeStubWorkerPool() {\n await workerPool?.dispose();\n workerPool = undefined;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ms-cloudpack/esm-stub-utilities",
3
- "version": "0.13.12",
3
+ "version": "0.13.14",
4
4
  "description": "Generates ESM stubs for CommonJS entry files.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -16,9 +16,9 @@
16
16
  "dependencies": {
17
17
  "@ms-cloudpack/common-types": "^0.23.3",
18
18
  "@ms-cloudpack/json-utilities": "^0.1.8",
19
- "@ms-cloudpack/package-utilities": "^10.2.8",
19
+ "@ms-cloudpack/package-utilities": "^10.2.10",
20
20
  "@ms-cloudpack/path-string-parsing": "^1.2.4",
21
- "@ms-cloudpack/worker-pool": "^0.2.0",
21
+ "@ms-cloudpack/worker-pool": "^0.3.0",
22
22
  "jsdom": "^24.0.0",
23
23
  "jsdom-global": "^3.0.2",
24
24
  "regenerator-runtime": "^0.14.1"