@ms-cloudpack/esm-stub-utilities 0.12.16 → 0.13.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.
- package/lib/index.d.ts +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/tsdoc-metadata.json +1 -1
- package/lib/worker/initBrowserEnvironment.d.ts.map +1 -1
- package/lib/worker/initBrowserEnvironment.js +3 -0
- package/lib/worker/initBrowserEnvironment.js.map +1 -1
- package/lib/worker/workerEntry.js +12 -5
- package/lib/worker/workerEntry.js.map +1 -1
- package/lib/writeESMStubsInWorker.d.ts +10 -0
- package/lib/writeESMStubsInWorker.d.ts.map +1 -0
- package/lib/writeESMStubsInWorker.js +35 -0
- package/lib/writeESMStubsInWorker.js.map +1 -0
- package/package.json +4 -9
package/lib/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { writeESMStubsInWorker, disposeStubWorkerPool } from './writeESMStubsInWorker.js';
|
|
2
2
|
export type { WriteESMStubsOptions } from './types/WriteESMStubsOptions.js';
|
|
3
3
|
export type { WriteESMStubsResult } from './types/WriteESMStubsResult.js';
|
|
4
4
|
export { _verifyStub } from './verifyStub/verifyStub.js';
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAC1F,YAAY,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AAC5E,YAAY,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AAC1E,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACzD,YAAY,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC"}
|
package/lib/index.js
CHANGED
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAG1F,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC","sourcesContent":["export { writeESMStubsInWorker, disposeStubWorkerPool } from './writeESMStubsInWorker.js';\nexport type { WriteESMStubsOptions } from './types/WriteESMStubsOptions.js';\nexport type { WriteESMStubsResult } from './types/WriteESMStubsResult.js';\nexport { _verifyStub } from './verifyStub/verifyStub.js';\nexport type { _VerifyStubOptions } from './types/VerifyStubOptions.js';\n"]}
|
package/lib/tsdoc-metadata.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"initBrowserEnvironment.d.ts","sourceRoot":"","sources":["../../src/worker/initBrowserEnvironment.js"],"names":[],"mappings":"AAQA;;GAEG;AACH,
|
|
1
|
+
{"version":3,"file":"initBrowserEnvironment.d.ts","sourceRoot":"","sources":["../../src/worker/initBrowserEnvironment.js"],"names":[],"mappings":"AAQA;;GAEG;AACH,wDAiFC"}
|
|
@@ -29,6 +29,9 @@ export async function initBrowserEnvironment() {
|
|
|
29
29
|
/** @type {*} */ (global).window = global;
|
|
30
30
|
/** @type {*} */ (global).self = global;
|
|
31
31
|
/** @type {*} */ (document).window = global;
|
|
32
|
+
// Don't allow setting timeouts or intervals
|
|
33
|
+
window.setTimeout = /** @type {*} */ (() => 0);
|
|
34
|
+
window.setInterval = /** @type {*} */ (() => 0);
|
|
32
35
|
window.requestAnimationFrame = window.setTimeout;
|
|
33
36
|
window.cancelAnimationFrame = window.clearTimeout;
|
|
34
37
|
global.btoa = (str) => Buffer.from(str, 'binary').toString('base64');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"initBrowserEnvironment.js","sourceRoot":"","sources":["../../src/worker/initBrowserEnvironment.js"],"names":[],"mappings":"AAAA,EAAE;AACF,+EAA+E;AAC/E,qDAAqD;AACrD,EAAE;AAEF,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,sBAAsB;IAC1C,oCAAoC;IACpC,MAAM,CAAC,WAAW,KAAK,gBAAgB,CAAC,CAAC,WAAW,CAAC,CAAC;IACtD,MAAM,CAAC,WAAW,KAAK,IAAI,CAAC,WAAW,CAAC;IACxC,MAAM,CAAC,WAAW,KAAK,gBAAgB,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IAE3D,MAAM,GAAG,GAAG,kBAAkB,CAAC;IAC/B,CAAC,MAAM,MAAM,CAAC,cAAc,CAAC,CAAC,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,GAAG,EAAE,CAAC,CAAC;IAE3D,MAAM,MAAM,CAAC,qBAAqB,CAAC,CAAC;IAEpC,iGAAiG;IACjG,8FAA8F;IAC9F,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,yBAAyB,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,EAAE;QAC7E,kFAAkF;QAClF,6FAA6F;QAC7F,4FAA4F;QAC5F,0CAA0C;QAC1C,IAAI,CAAC,CAAC,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC,cAAc,EAAE,gBAAgB,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC;YACtE,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,CAAC,EAAE,IAAI,CAAC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AAa;YACvC,gBAAgB,CAAC,CAAC,MAAM,CAAC,CAAC,aAAa;gBACrC,iBAAiB,CAAC;IAEtB,MAAM,CAAC,KAAK,GAAG,gBAAgB,CAAC,CAAC,KAAK,IAAI,EAAE,GAAE,CAAC,CAAC,CAAC;IAEjD,wDAAwD;IACxD,OAAO,CAAC,GAAG,CAAC,YAAY,GAAG,GAAG,CAAC;IAE/B,mFAAmF;IACnF,gBAAgB,CAAC,CAAC,OAAO,CAAC,CAAC,OAAO,GAAG,IAAI,CAAC;IAE1C,8EAA8E;IAC9E,MAAM,SAAS,GAAG,aAAa,CAAC,QAAQ,CAAC,CAAC;IAC1C,SAAS,CAAC,GAAG,GAAG,GAAG,GAAG,UAAU,CAAC;IACjC,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC;AACvC,CAAC","sourcesContent":["//\n// This file is JS because it's also used in a test worker within this package.\n// See verifyStub/loadStubWorker.js for more details.\n//\n\nimport { performance } from 'perf_hooks';\nimport util from 'util';\n\n/**\n * Initialize a fake browser environment.\n */\nexport async function initBrowserEnvironment() {\n // These must be set up before JSDOM\n global.performance ??= /** @type {*} */ (performance);\n global.TextEncoder ??= util.TextEncoder;\n global.TextDecoder ??= /** @type {*} */ (util.TextDecoder);\n\n const url = 'http://localhost';\n (await import('jsdom-global')).default(undefined, { url });\n\n await import('regenerator-runtime');\n\n // Ensure assigning to and reading from `window.foo` globals works as expected by copying all the\n // properties from the jsdom `window` to node's `global`, then assigning `global` to `window`.\n Object.entries(Object.getOwnPropertyDescriptors(window)).forEach(([k, desc]) => {\n // Skip storage to avoid errors \"localStorage is not available for opaque origins\"\n // (these errors could in theory be resolved by passing a URL to jsdom-global setup, but that\n // triggers some weird issues with whatwg-url using TextDecoder in a way that works in other\n // environments but throws in the sandbox)\n if (!(k in global) && !['localStorage', 'sessionStorage'].includes(k)) {\n Object.defineProperty(global, k, desc);\n }\n });\n /** @type {*} */ (global).window = global;\n /** @type {*} */ (global).self = global;\n /** @type {*} */ (document).window = global;\n\n // Don't allow setting timeouts or intervals\n window.setTimeout = /** @type {*} */ (() => 0);\n window.setInterval = /** @type {*} */ (() => 0);\n window.requestAnimationFrame = window.setTimeout;\n window.cancelAnimationFrame = window.clearTimeout;\n\n global.btoa = (str) => Buffer.from(str, 'binary').toString('base64');\n global.atob = (str) => Buffer.from(str, 'base64').toString('binary');\n\n // Simulate WebSocket existence. (Needed for isomorphic-ws)\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n global.WebSocket = window.WebSocket = /** @type {*} */ (class WebSocket {});\n\n // Fake MessageChannel so scheduler won't hang the process by opening a channel.\n global.MessageChannel = window.MessageChannel = class MessageChannel {\n port1 = /** @type {*} */ ({});\n port2 = /** @type {*} */ ({});\n };\n\n // Prevent adding event listeners.\n global.addEventListener = window.addEventListener = document.addEventListener = () => {};\n global.removeEventListener = window.removeEventListener = document.removeEventListener = () => {};\n global.dispatchEvent = window.dispatchEvent = document.dispatchEvent = () => false;\n\n // Mock out canvas.\n // eslint-disable-next-line etc/no-deprecated\n const createElement = window.document.createElement.bind(window.document);\n const createElementMock = (/** @type {string} */ tagName, /** @type {ElementCreationOptions} */ options) => {\n if (tagName === 'canvas') {\n return /** @type {*} */ ({\n getContext: () => ({ fillRect: () => {} }),\n measureText: () => ({}),\n });\n }\n\n return createElement(tagName, options);\n };\n // eslint-disable-next-line etc/no-deprecated\n global.document.createElement =\n /** @type {*} */ (window).createElement =\n /** @type {*} */ (global).createElement =\n createElementMock;\n\n window.fetch = /** @type {*} */ (async () => {});\n\n // prevent 'debug' package from accessing process.stderr\n process.env.DEBUG_COLORS = '0';\n\n // Some packages like readable-stream@2.3.7 read process.browser to avoid node code\n /** @type {*} */ (process).browser = true;\n\n // Add a script tag so that webpack automatic publicPath detection won't throw\n const scriptTag = createElement('script');\n scriptTag.src = `${url}/fake.js`;\n document.body.appendChild(scriptTag);\n}\n"]}
|
|
@@ -6,18 +6,25 @@ 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
|
-
|
|
10
|
-
// we load some CJS code that calls process.exit on parse.
|
|
11
|
-
process.exit = (code) => {
|
|
12
|
-
throw new Error(`process.exit called with code ${code}`);
|
|
13
|
-
};
|
|
9
|
+
const processExit = process.exit.bind(process);
|
|
14
10
|
// Then initialize the worker with the appropriate listeners and api dictionary.
|
|
15
11
|
initializeWorker({
|
|
16
12
|
methods: {
|
|
17
13
|
writeESMStubs,
|
|
18
14
|
},
|
|
15
|
+
beforeEach: () => {
|
|
16
|
+
// Override process.exit calls to throw rather than exit the process, in case we load some
|
|
17
|
+
// CJS code that calls process.exit. This gives an actual call stack for debugging.
|
|
18
|
+
process.exit = (code) => {
|
|
19
|
+
throw new Error(`process.exit called with code ${code}`);
|
|
20
|
+
};
|
|
21
|
+
},
|
|
19
22
|
afterEach: () => {
|
|
23
|
+
process.exit = processExit;
|
|
20
24
|
cleanUpGlobals(initialGlobalProperties);
|
|
21
25
|
},
|
|
26
|
+
// Stop the worker after 30s. This is much longer than should usually be necessary, but it's
|
|
27
|
+
// good to be conservative here in case of resource contention.
|
|
28
|
+
timeout: 30 * 1000,
|
|
22
29
|
});
|
|
23
30
|
//# sourceMappingURL=workerEntry.js.map
|
|
@@ -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,
|
|
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"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { WriteESMStubsOptions } from './types/WriteESMStubsOptions.js';
|
|
2
|
+
import type { WriteESMStubsResult } from './types/WriteESMStubsResult.js';
|
|
3
|
+
/**
|
|
4
|
+
* Write ESM stubs using a worker pool.
|
|
5
|
+
*/
|
|
6
|
+
export declare function writeESMStubsInWorker(options: WriteESMStubsOptions & {
|
|
7
|
+
maxWorkers?: number;
|
|
8
|
+
}): Promise<WriteESMStubsResult>;
|
|
9
|
+
export declare function disposeStubWorkerPool(): Promise<void>;
|
|
10
|
+
//# sourceMappingURL=writeESMStubsInWorker.d.ts.map
|
|
@@ -0,0 +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,CAuB9B;AAED,wBAAsB,qBAAqB,kBAG1C"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { WorkerPool } from '@ms-cloudpack/worker-pool';
|
|
2
|
+
let workerPool;
|
|
3
|
+
/**
|
|
4
|
+
* Write ESM stubs using a worker pool.
|
|
5
|
+
*/
|
|
6
|
+
// This is tested in bundler-plugin-rollup/src/writeESMStubsInWorker.test.ts so we can
|
|
7
|
+
// use the compiled version of the workerEntry file.
|
|
8
|
+
export async function writeESMStubsInWorker(options) {
|
|
9
|
+
const { maxWorkers = 5, ...stubOptions } = options;
|
|
10
|
+
workerPool ??= new WorkerPool({
|
|
11
|
+
parentPath: import.meta.url,
|
|
12
|
+
entryPath: './worker/workerEntry',
|
|
13
|
+
maxWorkers,
|
|
14
|
+
});
|
|
15
|
+
try {
|
|
16
|
+
return await workerPool.execute('writeESMStubs', [stubOptions]);
|
|
17
|
+
}
|
|
18
|
+
catch (err) {
|
|
19
|
+
return {
|
|
20
|
+
newEntries: {},
|
|
21
|
+
errors: [
|
|
22
|
+
{
|
|
23
|
+
source: 'ESM stub generation',
|
|
24
|
+
// note: err won't be an instance of Error because of serialization
|
|
25
|
+
text: err?.stack || err?.message || String(err),
|
|
26
|
+
},
|
|
27
|
+
],
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
export async function disposeStubWorkerPool() {
|
|
32
|
+
await workerPool?.dispose();
|
|
33
|
+
workerPool = undefined;
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=writeESMStubsInWorker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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,sFAAsF;AACtF,oDAAoD;AACpD,MAAM,CAAC,KAAK,UAAU,qBAAqB,CACzC,OAAuD;IAEvD,MAAM,EAAE,UAAU,GAAG,CAAC,EAAE,GAAG,WAAW,EAAE,GAAG,OAAO,CAAC;IAEnD,UAAU,KAAK,IAAI,UAAU,CAAC;QAC5B,UAAU,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG;QAC3B,SAAS,EAAE,sBAAsB;QACjC,UAAU;KACX,CAAC,CAAC;IAEH,IAAI,CAAC;QACH,OAAO,MAAM,UAAU,CAAC,OAAO,CAAC,eAAe,EAAE,CAAC,WAAW,CAAC,CAAC,CAAC;IAClE,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO;YACL,UAAU,EAAE,EAAE;YACd,MAAM,EAAE;gBACN;oBACE,MAAM,EAAE,qBAAqB;oBAC7B,mEAAmE;oBACnE,IAAI,EAAG,GAAa,EAAE,KAAK,IAAK,GAAa,EAAE,OAAO,IAAI,MAAM,CAAC,GAAG,CAAC;iBACtE;aACF;SACF,CAAC;IACJ,CAAC;AACH,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,qBAAqB;IACzC,MAAM,UAAU,EAAE,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-plugin-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 parentPath: import.meta.url,\n entryPath: './worker/workerEntry',\n maxWorkers,\n });\n\n try {\n return await workerPool.execute('writeESMStubs', [stubOptions]);\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.
|
|
3
|
+
"version": "0.13.1",
|
|
4
4
|
"description": "Generates ESM stubs for CommonJS entry files.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -11,19 +11,14 @@
|
|
|
11
11
|
"source": "./src/index.ts",
|
|
12
12
|
"types": "./lib/index.d.ts",
|
|
13
13
|
"import": "./lib/index.js"
|
|
14
|
-
},
|
|
15
|
-
"./workerEntry": {
|
|
16
|
-
"source": "./src/worker/workerEntry.ts",
|
|
17
|
-
"types": "./lib/worker/workerEntry.d.ts",
|
|
18
|
-
"import": "./lib/worker/workerEntry.js"
|
|
19
14
|
}
|
|
20
15
|
},
|
|
21
16
|
"dependencies": {
|
|
22
|
-
"@ms-cloudpack/common-types": "^0.
|
|
17
|
+
"@ms-cloudpack/common-types": "^0.21.0",
|
|
23
18
|
"@ms-cloudpack/json-utilities": "^0.1.7",
|
|
24
|
-
"@ms-cloudpack/package-utilities": "^10.1.
|
|
19
|
+
"@ms-cloudpack/package-utilities": "^10.1.3",
|
|
25
20
|
"@ms-cloudpack/path-string-parsing": "^1.2.4",
|
|
26
|
-
"@ms-cloudpack/worker-pool": "^0.1.
|
|
21
|
+
"@ms-cloudpack/worker-pool": "^0.1.3",
|
|
27
22
|
"jsdom": "^24.0.0",
|
|
28
23
|
"jsdom-global": "^3.0.2",
|
|
29
24
|
"regenerator-runtime": "^0.14.1"
|