@ms-cloudpack/esm-stub-utilities 0.7.7 → 0.7.9
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.
|
@@ -11,7 +11,7 @@ type StubImportResult = {
|
|
|
11
11
|
type: 'result';
|
|
12
12
|
/**
|
|
13
13
|
* IPC-friendly result of importing the module.
|
|
14
|
-
* Any non-IPC-
|
|
14
|
+
* Any non-IPC-friendly values (such as functions) will be pretty-printed as strings.
|
|
15
15
|
*/
|
|
16
16
|
value: unknown;
|
|
17
17
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tryImportStub.js","sourceRoot":"","sources":["../../src/__fixtures__/tryImportStub.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AACpC,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAwBxC,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AAC7D,MAAM,cAAc,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,mBAAmB,CAAC,CAAC;AAE/D,IAAI,MAA0B,CAAC;AAE/B;;;;GAIG;AACH,MAAM,UAAU,gBAAgB;IAC9B,IAAI,MAAM;QAAE,OAAO;IAEnB,MAAM,GAAG,IAAI,MAAM,CAAC,cAAc,CAAC,CAAC;IAEpC,sFAAsF;IACtF,yFAAyF;IACzF,uFAAuF;IACvF,2EAA2E;IAC3E,IAAI,SAA4B,CAAC;IACjC,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,GAAG,EAAE,EAAE;QACzB,SAAS,GAAG,GAAG,CAAC;IAClB,CAAC,CAAC,CAAC;IACH,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE;QACzB,MAAM,IA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;QACD,MAAM,GAAG,SAAS,CAAC;KACpB;AACH,CAAC","sourcesContent":["import path from 'path';\nimport { fileURLToPath } from 'url';\nimport { Worker } from 'worker_threads';\n\n// this type is used by loadStubWorker.js\n// (it's test-specific, so no reason to put it in the types folder)\nexport type StubImportRequest = {\n stubPath: string;\n /**\n * Test function body which receives a parameter `moduleExports`.\n * The result is not returned, but this can be used to verify that an expected API is available\n * (code calling it doesn't throw) even if it doesn't show up in the named exports.\n */\n testCode?: string;\n};\n\ntype StubImportResult = {\n type: 'result';\n /**\n * IPC-friendly result of importing the module.\n * Any non-IPC-
|
|
1
|
+
{"version":3,"file":"tryImportStub.js","sourceRoot":"","sources":["../../src/__fixtures__/tryImportStub.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AACpC,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAwBxC,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AAC7D,MAAM,cAAc,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,mBAAmB,CAAC,CAAC;AAE/D,IAAI,MAA0B,CAAC;AAE/B;;;;GAIG;AACH,MAAM,UAAU,gBAAgB;IAC9B,IAAI,MAAM;QAAE,OAAO;IAEnB,MAAM,GAAG,IAAI,MAAM,CAAC,cAAc,CAAC,CAAC;IAEpC,sFAAsF;IACtF,yFAAyF;IACzF,uFAAuF;IACvF,2EAA2E;IAC3E,IAAI,SAA4B,CAAC;IACjC,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,GAAG,EAAE,EAAE;QACzB,SAAS,GAAG,GAAG,CAAC;IAClB,CAAC,CAAC,CAAC;IACH,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE;QACzB,MAAM,IAAI,K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,MAAM,GAAG,SAAS,CAAC;KACpB;AACH,CAAC","sourcesContent":["import path from 'path';\nimport { fileURLToPath } from 'url';\nimport { Worker } from 'worker_threads';\n\n// this type is used by loadStubWorker.js\n// (it's test-specific, so no reason to put it in the types folder)\nexport type StubImportRequest = {\n stubPath: string;\n /**\n * Test function body which receives a parameter `moduleExports`.\n * The result is not returned, but this can be used to verify that an expected API is available\n * (code calling it doesn't throw) even if it doesn't show up in the named exports.\n */\n testCode?: string;\n};\n\ntype StubImportResult = {\n type: 'result';\n /**\n * IPC-friendly result of importing the module.\n * Any non-IPC-friendly values (such as functions) will be pretty-printed as strings.\n */\n value: unknown;\n};\nexport type StubImportResponse = StubImportResult | { type: 'error'; message: string };\n\nconst dirname = path.dirname(fileURLToPath(import.meta.url));\nconst testWorkerPath = path.join(dirname, 'loadStubWorker.js');\n\nlet worker: Worker | undefined;\n\n/**\n * Initialize a worker used for importing stubs.\n * (The worker is reused between tests for now because it's expensive to set up and tear down;\n * this can be changed later for certain tests if needed.)\n */\nexport function ensureStubWorker() {\n if (worker) return;\n\n worker = new Worker(testWorkerPath);\n\n // An 'error' event from a worker means an unhandled exception and it's about to exit.\n // Don't throw an error in this fallback handler in case the error occurred during a call\n // to `tryImportStub` (which has its own error handler that can fail the calling test),\n // but save the error to be included in the 'exit' handler's error message.\n let lastError: Error | undefined;\n worker.on('error', (err) => {\n lastError = err;\n });\n worker.on('exit', (code) => {\n throw new Error(\n lastError\n ? `Worker exited due to an uncaught exception: ${lastError.stack}`\n : `Worker exited unexpectedly with code ${code || 0}`,\n );\n });\n}\n\n/**\n * Import the stub in a worker and return the result.\n * Note that non-IPC-friendly values (such as functions) will be pretty-printed as strings.\n *\n * Why use a worker?\n * - Ensure that the module is imported in a \"vanilla\" way, without interference from Jest\n * transpilation or custom module resolution\n * - Allow the module to run in a simulated browser environment if needed\n * - Avoid potential pollution of the current process's globals\n *\n * (The worker is reused between tests for now because it's expensive to set up and tear down;\n * this can be changed later for certain tests if needed.)\n */\nexport async function tryImportStub(params: StubImportRequest): Promise<unknown> {\n ensureStubWorker();\n\n return new Promise((resolve, reject) => {\n const onMessage = (response: StubImportResponse) => {\n worker?.off('error', onError);\n if (response.type === 'error') {\n // error importing the module\n reject(response.message);\n } else {\n resolve(response.value);\n }\n };\n // unhandled exception (not expected)\n const onError = (err: Error) => {\n worker?.off('message', onMessage);\n reject(err);\n };\n worker?.once('message', onMessage);\n worker?.once('error', onError);\n\n worker?.postMessage(params);\n });\n}\n\nexport async function cleanUpStubWorker() {\n if (worker) {\n // Remove all listeners so that the exit handler set up during initialization doesn't throw\n worker.removeAllListeners();\n try {\n await worker.terminate();\n } catch {\n // ignore\n }\n worker = undefined;\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ms-cloudpack/esm-stub-utilities",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.9",
|
|
4
4
|
"description": "Generates ESM stubs for CommonJS entry files.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
}
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@ms-cloudpack/json-utilities": "^0.1.
|
|
17
|
+
"@ms-cloudpack/json-utilities": "^0.1.2",
|
|
18
18
|
"@ms-cloudpack/path-utilities": "^2.3.5",
|
|
19
19
|
"@ms-cloudpack/path-string-parsing": "^1.1.1",
|
|
20
20
|
"atob": "^2.1.2",
|