@ms-cloudpack/esm-stub-utilities 0.7.21 → 0.7.23
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/__fixtures__/loadStubWorker.js.map +1 -1
- package/lib/__fixtures__/tryImportStub.js.map +1 -1
- package/lib/createESMStub.js.map +1 -1
- package/lib/createJSONStub.js.map +1 -1
- package/lib/runInSandbox.js.map +1 -1
- package/lib/worker/globals.js.map +1 -1
- package/lib/worker/initBrowserEnvironment.js.map +1 -1
- package/lib/worker/worker.js +1 -1
- package/lib/worker/worker.js.map +1 -1
- package/lib/writeESMStub.js.map +1 -1
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loadStubWorker.js","sourceRoot":"","sources":["../../src/__fixtures__/loadStubWorker.js"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,wDAAwD;AACxD,0DAA0D;AAE1D,8FAA8F;AAC9F,+DAA+D;AAE/D;;;GAGG;AACH,MAAM;AACN,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC1D,OAAO,EAAE,sBAAsB,EAAE,MAAM,qCAAqC,CAAC;AAC7E,OAAO,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAE3E,IAAI,YAAY,IAAI,CAAC,UAAU,EAAE;
|
|
1
|
+
{"version":3,"file":"loadStubWorker.js","sourceRoot":"","sources":["../../src/__fixtures__/loadStubWorker.js"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,wDAAwD;AACxD,0DAA0D;AAE1D,8FAA8F;AAC9F,+DAA+D;AAE/D;;;GAGG;AACH,MAAM;AACN,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAA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,EAAE,CAAC,cAAc,CAAC,CAAC,EAAE,KAAK,GAAG,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC;QACrE,CAAC;QAED,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM,IAAI,KAAK,CAAC,WAAW,EAAE,IAAI,KAAK,QAAQ,EAAE,CAAC;YACtE,OAAO,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,cAAc,CAAC,CAAC,EAAE,KAAK,GAAG,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;QACnH,CAAC;QAED,wFAAwF;QACxF,mHAAmH;QACnH,OAAO,WAAW,CAAC,KAAK,CAAC,CAAC;IAC5B,CAAC;IAED,IAAI,CAAC;QACH,sDAAsD;QACtD,+EAA+E;QAC/E,EAAE,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;QACpB,OAAO,KAAK,CAAC;IACf,CAAC;IAAC,MAAM,CAAC;QACP,gDAAgD;QAChD,OAAO,WAAW,CAAC,KAAK,CAAC,CAAC;IAC5B,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,SAAS,WAAW,CAAC,gBAAgB,CAAC,KAAK;IACzC,OAAO,MAAM,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AACnE,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/no-unsafe-member-access */\n/* eslint-disable @typescript-eslint/no-unsafe-return */\n/* eslint-disable @typescript-eslint/no-unsafe-argument */\n\n// This file is used in tests to verify that a stub file can be imported in a Node environment\n// without interference from Jest's wrappers and transpilation.\n\n/**\n * @typedef {import('./tryImportStub.js').StubImportRequest} StubImportRequest\n * @typedef {import('./tryImportStub.js').StubImportResponse} StubImportResponse\n */\n/** */\nimport { format } from 'pretty-format';\nimport v8 from 'v8';\nimport { isMainThread, parentPort } from 'worker_threads';\nimport { initBrowserEnvironment } from '../worker/initBrowserEnvironment.js';\nimport { cleanUpGlobals, getGlobalProperties } from '../worker/globals.js';\n\nif (isMainThread || !parentPort) {\n throw new Error('This file should only be loaded in a worker thread');\n}\n\n// These modules may expect a browser environment\nawait initBrowserEnvironment();\nconst initialGlobalProperties = getGlobalProperties();\n\n/**\n * Type helper for sending messages to the parent.\n * @param {StubImportResponse} message\n */\nfunction emitMessage(message) {\n parentPort?.postMessage(message);\n}\n\nparentPort.on('message', (/** @type {StubImportRequest} */ request) => {\n if (typeof request.stubPath !== 'string') {\n emitMessage({\n type: 'error',\n message: `Unexpected request format: ${JSON.stringify(request)}`,\n });\n } else {\n // Import the stub and send a reponse\n // (`void` ignores the promise result since callbacks can't be async)\n void tryImportStub(request);\n }\n});\n\n/** @param {StubImportRequest} request */\nasync function tryImportStub(request) {\n const { stubPath, testCode } = request;\n let moduleExports;\n let step = 'Import';\n try {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n moduleExports = await import(stubPath);\n step = 'Running test code';\n if (testCode) {\n // eslint-disable-next-line @typescript-eslint/no-implied-eval\n new Function('moduleExports', testCode)(moduleExports);\n }\n } catch (err) {\n emitMessage({\n type: 'error',\n message: `${step} failed: ${/** @type {Error} */ (err).stack || String(err)}`,\n });\n return;\n } finally {\n cleanUpGlobals(initialGlobalProperties);\n }\n\n try {\n emitMessage({\n type: 'result',\n value: toSerializable(moduleExports),\n });\n } catch (err) {\n emitMessage({\n type: 'error',\n message: `Error formatting or serializing exports: ${/** @type {Error} */ (err).stack || String(err)}`,\n });\n }\n}\n\n/**\n * Convert a value into an IPC-serializable form.\n * @param {*} value\n * @returns {*}\n */\nfunction toSerializable(value, depth = 1, encountered = new WeakSet()) {\n if (depth > 3) {\n return '...';\n }\n\n if (value && typeof value === 'object') {\n // track encountered objects to avoid entering circular references\n if (encountered.has(value)) {\n return '[Circular]';\n }\n encountered.add(value);\n\n if (Array.isArray(value)) {\n return value.map((v) => toSerializable(v, depth + 1, encountered));\n }\n\n if (Object.keys(value).length || value.constructor?.name === 'Object') {\n return Object.fromEntries(Object.entries(value).map(([k, v]) => [k, toSerializable(v, depth + 1, encountered)]));\n }\n\n // Always format other objects (even if they're serializable) to avoid comparison issues\n // in expect(...).toEqual() (like \"TypeError: Method Map.prototype.entries called on incompatible receiver #<Map>\")\n return formatValue(value);\n }\n\n try {\n // try to serialize the same way postMessage does, per\n // https://nodejs.org/api/worker_threads.html#portpostmessagevalue-transferlist\n v8.serialize(value);\n return value;\n } catch {\n // not serializable, so format the value instead\n return formatValue(value);\n }\n}\n\n/**\n * Pretty-format a value, removing newlines.\n * (`pretty-format` has a `min` option, but it removes additional detail which isn't desired.)\n */\nfunction formatValue(/** @type {*} */ value) {\n return format(value, {}).replace(/\\n/g, '').replace(/\\s+/g, ' ');\n}\n"]}
|
|
@@ -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,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AC;QACF,MAAM,EAAE,IAAI,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;QACnC,MAAM,EAAE,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QAE/B,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IAC9B,CAAC,CAAC,CAAC;AACL,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,iBAAiB;IACrC,IAAI,MAAM,EAAE,CAAC;QACX,2FAA2F;QAC3F,MAAM,CAAC,kBAAkB,EAAE,CAAC;QAC5B,IAAI,CAAC;YACH,MAAM,MAAM,CAAC,SAAS,EAAE,CAAC;QAC3B,CAAC;QAAC,MAAM,CAAC;YACP,SAAS;QACX,CAAC;QACD,MAAM,GAAG,SAAS,CAAC;IACrB,CAAC;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/lib/createESMStub.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createESMStub.js","sourceRoot":"","sources":["../src/createESMStub.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,KAAK,EAAE,MAAM,mCAAmC,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,MAAM,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CAAC,IAAI,CAAC,YAAY,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACrD,CAAC;IAED,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACzB,CAAC","sourcesContent":["import os from 'os';\nimport path from 'path';\nimport { slash } from '@ms-cloudpack/path-string-parsing';\nimport { runInSandbox } from './runInSandbox.js';\nimport { createJSONStub } from './createJSONStub.js';\nimport { isValidIdentifierName } from './isValidIdentifierName.js';\nimport type { StubError } from './types/StubError.js';\n\n/**\n * Generates an ESM stub for a CommonJS module.\n * @returns The stub file contents, or an error object if the module could not be stubbed.\n * Should only throw an error on bad input or other cases that likely indicate either a bug\n * or bad configuration (as opposed to a problem with the file being stubbed).\n */\nexport async function createESMStub(params: {\n /** The full path to the CommonJS entry file. */\n entryPath: string;\n /** The path where the stub file will live. This is important for determining relative import paths. */\n stubPath: string;\n}): Promise<string | StubError> {\n const { entryPath, stubPath } = params;\n\n if (path.extname(entryPath).toLowerCase() === '.json') {\n return createJSONStub(entryPath);\n }\n\n // Run the entry point file in a sandbox to determine the exports\n const exportInfo = await runInSandbox(entryPath);\n if ('error' in exportInfo) {\n return exportInfo.error;\n }\n\n let relativePath: string;\n if (os.platform() === 'win32' && path.parse(entryPath).root !== path.parse(stubPath).root) {\n // Different drive letters. These can't be relative to each other.\n relativePath = entryPath;\n } else {\n relativePath = './' + slash(path.relative(path.dirname(stubPath), entryPath));\n }\n\n const exportType = exportInfo.type;\n\n if (exportType === 'none') {\n // No exports. Just import the module.\n return `import \"${relativePath}\";`;\n }\n\n if (exportType === 'other') {\n // Some kind of value. Import then re-export as default.\n // (Note that even for values such as numbers which we could in theory rewrite inline,\n // we don't know how the value is calculated at runtime or what other side effects the module\n // might have, so we should preserve the import.)\n return `import moduleExport from \"${relativePath}\";\\nexport default moduleExport;`;\n }\n\n // Object or function. Export both named properties (if any, and filtering keywords) and a default.\n const namedExports = exportInfo.keys.filter((name) => isValidIdentifierName(name));\n const hasDefaultExport = exportInfo.keys.includes('default');\n\n const stub = [`import moduleExport from \"${relativePath}\";`];\n\n if (namedExports.length) {\n stub.push(`const { ${namedExports.join(', ')} } = moduleExport;`);\n }\n\n if (hasDefaultExport) {\n stub.push(\n `const defaultExport = (moduleExport?.default?.default) ?? moduleExport?.default;`,\n `export default defaultExport;`,\n );\n } else {\n stub.push(`export default moduleExport;`);\n }\n\n if (namedExports.length) {\n stub.push(`export { ${namedExports.join(', ')} }`);\n }\n\n return stub.join('\\n');\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createJSONStub.js","sourceRoot":"","sources":["../src/createJSONStub.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AACxD,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAEnE;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,SAAiB;IACpD,IAAI,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,WAAW,EAAE,KAAK,OAAO,EAAE;
|
|
1
|
+
{"version":3,"file":"createJSONStub.js","sourceRoot":"","sources":["../src/createJSONStub.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AACxD,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAEnE;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,SAAiB;IACpD,IAAI,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,WAAW,EAAE,KAAK,OAAO,EAAE,CAAC;QACtD,MAAM,IAAI,KAAK,CAAC,mBAAmB,GAAG,SAAS,CAAC,CAAC;IACnD,CAAC;IAED,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC;QAC9B,MAAM,IAAI,KAAK,CAAC,uBAAuB,GAAG,SAAS,CAAC,CAAC;IACvD,CAAC;IAED,MAAM,QAAQ,GAAG,MAAM,QAAQ,CAAC,SAAS,CAAC,CAAC;IAC3C,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,MAAM,IAAI,KAAK,CAAC,0BAA0B,GAAG,SAAS,CAAC,CAAC;IAC1D,CAAC;IAED,MAAM,MAAM,GAAG,CAAC,gBAAgB,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,GAAG,EAAE,sBAAsB,CAAC,CAAC;IAE9F,IAAI,QAAQ,IAAI,OAAO,QAAQ,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;QACzE,iEAAiE;QACjE,MAAM,CAAC,IAAI,CACT,GAAG,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC;aACrB,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,qBAAqB,CAAC,IAAI,CAAC,CAAC;aAC7C,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,gBAAgB,IAAI,WAAW,IAAI,GAAG,CAAC,CACzD,CAAC;IACJ,CAAC;IAED,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC3B,CAAC","sourcesContent":["import fs from 'fs';\nimport path from 'path';\nimport { readJson } from '@ms-cloudpack/json-utilities';\nimport { isValidIdentifierName } from './isValidIdentifierName.js';\n\n/**\n * Generates an ESM stub of a JSON file. This just inlines the file contents rather than running\n * it in the sandbox.\n * @param entryPath - The full path to the JSON entry file.\n */\nexport async function createJSONStub(entryPath: string): Promise<string> {\n if (path.extname(entryPath).toLowerCase() !== '.json') {\n throw new Error('Not a JSON file: ' + entryPath);\n }\n\n if (!fs.existsSync(entryPath)) {\n throw new Error('File does not exist: ' + entryPath);\n }\n\n const jsonData = await readJson(entryPath);\n if (!jsonData) {\n throw new Error('File is not valid JSON: ' + entryPath);\n }\n\n const result = [`const data = ${JSON.stringify(jsonData, null, 2)};`, 'export default data;'];\n\n if (jsonData && typeof jsonData === 'object' && !Array.isArray(jsonData)) {\n // Export individual properties if they're valid identifier names\n result.push(\n ...Object.keys(jsonData)\n .filter((name) => isValidIdentifierName(name))\n .map((prop) => `export const ${prop} = data.${prop};`),\n );\n }\n\n return result.join('\\n');\n}\n"]}
|
package/lib/runInSandbox.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runInSandbox.js","sourceRoot":"","sources":["../src/runInSandbox.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AACpC,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAGxC,OAAO,EAAE,KAAK,EAAE,MAAM,mCAAmC,CAAC;AAG1D,8EAA8E;AAC9E,MAAM,UAAU,GAAG;IACjB,UAAU,EAAE,iBAAiB;IAC7B,cAAc,EAAE,kBAAkB;CACnC,CAAC;AAEF,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AAC7D,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,kBAAkB,CAAC,CAAC;AAE1D,0BAA0B;AAC1B,IAAI,MAA0B,CAAC;AAE/B,kCAAkC;AAClC,MAAM,CAAC,KAAK,UAAU,WAAW;IAC/B,MAAM,MAAM,EAAE,SAAS,EAAE,CAAC;IAC1B,MAAM,GAAG,SAAS,CAAC;AACrB,CAAC;AAED,SAAS,YAAY,CAAC,KAAkD;IACtE,MAAM,EAAE,OAAO,EAAE,IAA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CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;aAC7B;iBAAM,IAAI,OAAO,CAAC,KAAK,EAAE;gBACxB,OAAO,CAAC,EAAE,KAAK,EAAE,YAAY,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;aACjD;iBAAM;gBACL,oCAAoC;gBACpC,MAAM,CAAC,IAAI,KAAK,CAAC,mDAAmD,SAAS,KAAK,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC;aAC/G;QACH,CAAC;QAED,4DAA4D;QAC5D,SAAS,cAAc,CAAC,GAAU;YAChC,WAAW,EAAE,CAAC;YACd,MAAM,CACJ,IAAI,KAAK,CAAC,iEAAiE,SAAS,KAAK,GAAG,CAAC,KAAK,IAAI,GAAG,IAAI,CAAC,CAC/G,CAAC;QACJ,CAAC;QAED,gFAAgF;QAChF,SAAS,OAAO,CAAC,GAAU;YACzB,WAAW,EAAE,CAAC;YACd,MAAM,CAAC,IAAI,KAAK,CAAC,kDAAkD,SAAS,KAAK,GAAG,CAAC,KAAK,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC;QAC1G,CAAC;QAED;;;WAGG;QACH,SAAS,MAAM;YACb,MAAM,CAAC,IAAI,KAAK,CAAC,oDAAoD,SAAS,EAAE,CAAC,CAAC,CAAC;QACrF,CAAC;QAED,gFAAgF;QAChF,SAAS,WAAW;YAClB,MAAM,EAAE,GAAG,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;YAClC,MAAM,EAAE,GAAG,CAAC,cAAc,EAAE,cAAc,CAAC,CAAC;YAC5C,MAAM,EAAE,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;YAC9B,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAC9B,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import fs from 'fs';\nimport path from 'path';\nimport { fileURLToPath } from 'url';\nimport { Worker } from 'worker_threads';\nimport type { SandboxWorkerResponse } from './types/SandboxWorkerResponse.js';\nimport type { StubExportInfo } from './types/StubExportInfo.js';\nimport { slash } from '@ms-cloudpack/path-string-parsing';\nimport type { StubError } from './types/StubError.js';\n\n/** Some known error codes that can occur when running a file in a sandbox. */\nconst errorCodes = {\n requireESM: 'ERR_REQUIRE_ESM',\n moduleNotFound: 'MODULE_NOT_FOUND',\n};\n\nconst dirname = path.dirname(fileURLToPath(import.meta.url));\nconst workerPath = path.join(dirname, 'worker/worker.js');\n\n// TODO do we need a pool?\nlet worker: Worker | undefined;\n\n/** Stop the worker for testing */\nexport async function _stopWorker() {\n await worker?.terminate();\n worker = undefined;\n}\n\nfunction processError(error: NonNullable<SandboxWorkerResponse['error']>): StubError {\n const { message, code, name: errorName } = error;\n\n let newMessage: string;\n let type: StubError['type'];\n\n if (code === errorCodes.moduleNotFound) {\n // Remove the require stack from MODULE_NOT_FOUND errors (we'll handle it separately).\n // Error: Cannot find module 'foo'\n // Require stack:\n // - [...]/index.js\n // - [.]/worker.js\n newMessage = message.split('\\n')[0];\n type = 'module-not-found';\n } else if (code === errorCodes.requireESM) {\n // Remove the instruction to change to a dynamic import, since it's less likely to be applicable here.\n // Error [ERR_REQUIRE_ESM]: require() of ES Module [...]/esm.mjs not supported.\n // Instead change the require of [...]/esm.mjs to a dynamic import() which is available in all CommonJS modules.\n newMessage = message.split('\\n')[0];\n type = 'require-esm';\n } else if (errorName === 'SyntaxError') {\n newMessage = message;\n type = 'invalid-syntax';\n } else {\n newMessage = message;\n type = 'other-error';\n }\n\n let stack: string[] | undefined;\n if (error.stack) {\n // Get stack frame lines from the original error stack\n stack = error.stack\n .split('\\n')\n .filter((line) => /^\\s+at /.test(line))\n .map((line) => line.trim());\n\n // Remove the worker frame and anything after it\n const workerIndex = stack.findIndex(\n (line) => slash(line).includes('esm-stub-utilities') && line.includes('worker.js'),\n );\n if (workerIndex !== -1) {\n stack = stack.slice(0, workerIndex);\n }\n\n if (!stack.length) {\n stack = undefined;\n if (code === errorCodes.requireESM) {\n // This error code + no stack outside the worker strongly implies that the file itself\n // If we ended up with no stack besides the worker, this strongly implies that the file\n // itself is an ESM file, not a CommonJS file.\n newMessage =\n \"It appears you're trying to create a stub of an ES module, which is not supported. \" +\n 'You may need to add a cloudpack override to bundle this package with ori.';\n type = 'entry-is-esm';\n }\n }\n }\n\n // Remove node internals from the stack\n const partialStack = stack?.filter((line) => !line.includes('(node:'));\n\n return {\n message: newMessage,\n type,\n partialStack: partialStack?.length ? partialStack : undefined,\n };\n}\n\n/**\n * Run a CommonJS file within a sandboxed environment.\n * @param entryPath - Path to a CommonJS file to run in a sandbox (does not work with ESM files)\n * @returns Info about the file's exports, or error info if there was an issue.\n * Should only throw an error on bad input or other cases that likely indicate either a bug\n * or bad configuration (as opposed to a problem with the file being stubbed).\n */\n// TODO add mechanism to force one-off worker\nexport async function runInSandbox(entryPath: string): Promise<StubExportInfo | { error: StubError }> {\n if (!path.isAbsolute(entryPath)) {\n throw new Error('Entry path must be absolute. Received: ' + entryPath);\n }\n if (!fs.existsSync(entryPath)) {\n throw new Error('Entry path does not exist: ' + entryPath);\n }\n\n if (!worker) {\n try {\n worker = new Worker(workerPath, { stdout: true, stderr: true, execArgv: [] });\n worker.stdout?.on('data', (data) => {\n console.debug(`[sandbox stdout] ${data}`);\n });\n worker.stderr?.on('data', (data) => {\n console.debug(`[sandbox stderr] ${data}`);\n });\n worker.on('exit', () => {\n worker = undefined;\n });\n // don't hold the process open if only the worker is left\n worker.unref();\n } catch (err) {\n throw new Error(`Error initializing sandbox worker: ${(err as Error)?.stack || err}`);\n }\n }\n\n return new Promise((resolve, reject) => {\n // just for type checking\n if (!worker) return;\n\n worker.on('message', onMessage);\n worker.on('messageerror', onMessageError);\n worker.on('error', onError);\n worker.on('exit', onExit);\n\n // Send a message requesting the file to be run.\n worker.postMessage(entryPath);\n\n /** Normally, both success and error results should be sent back as messages. */\n function onMessage(message: SandboxWorkerResponse) {\n if (message.entryPath !== entryPath) {\n return; // message about a different file\n }\n\n handlersOff();\n if (message.exportInfo) {\n resolve(message.exportInfo);\n } else if (message.error) {\n resolve({ error: processError(message.error) });\n } else {\n // this indicates a bug in cloudpack\n reject(new Error(`Unexpected sandbox worker message while running ${entryPath}: ${JSON.stringify(message)}`));\n }\n }\n\n /** 'messageerror' event: deserializing a message failed. */\n function onMessageError(err: Error) {\n handlersOff();\n reject(\n new Error(`Error with sandbox worker message serialization while running ${entryPath}: ${err.stack || err}\\n`),\n );\n }\n\n /** 'error' event: unhandled exception in the worker, which shouldn't happen. */\n function onError(err: Error) {\n handlersOff();\n reject(new Error(`Uncaught error in sandbox worker while running ${entryPath}: ${err.stack || err}\\n`));\n }\n\n /**\n * Make sure the promise rejects if the worker exits unexpectedly. (This handler is unlikely\n * to be used because the worker should throw an error if a file calls process.exit().)\n */\n function onExit() {\n reject(new Error(`Sandbox worker exited unexpectedly while running ${entryPath}`));\n }\n\n /** Remove all event handlers to avoid interference with future sandbox runs. */\n function handlersOff() {\n worker?.off('message', onMessage);\n worker?.off('messageerror', onMessageError);\n worker?.off('error', onError);\n worker?.off('exit', onExit);\n }\n });\n}\n"]}
|
|
1
|
+
{"version":3,"file":"runInSandbox.js","sourceRoot":"","sources":["../src/runInSandbox.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AACpC,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAGxC,OAAO,EAAE,KAAK,EAAE,MAAM,mCAAmC,CAAC;AAG1D,8EAA8E;AAC9E,MAAM,UAAU,GAAG;IACjB,UAAU,EAAE,iBAAiB;IAC7B,cAAc,EAAE,kBAAkB;CACnC,CAAC;AAEF,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AAC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QAC1G,CAAC;QAED;;;WAGG;QACH,SAAS,MAAM;YACb,MAAM,CAAC,IAAI,KAAK,CAAC,oDAAoD,SAAS,EAAE,CAAC,CAAC,CAAC;QACrF,CAAC;QAED,gFAAgF;QAChF,SAAS,WAAW;YAClB,MAAM,EAAE,GAAG,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;YAClC,MAAM,EAAE,GAAG,CAAC,cAAc,EAAE,cAAc,CAAC,CAAC;YAC5C,MAAM,EAAE,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;YAC9B,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAC9B,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import fs from 'fs';\nimport path from 'path';\nimport { fileURLToPath } from 'url';\nimport { Worker } from 'worker_threads';\nimport type { SandboxWorkerResponse } from './types/SandboxWorkerResponse.js';\nimport type { StubExportInfo } from './types/StubExportInfo.js';\nimport { slash } from '@ms-cloudpack/path-string-parsing';\nimport type { StubError } from './types/StubError.js';\n\n/** Some known error codes that can occur when running a file in a sandbox. */\nconst errorCodes = {\n requireESM: 'ERR_REQUIRE_ESM',\n moduleNotFound: 'MODULE_NOT_FOUND',\n};\n\nconst dirname = path.dirname(fileURLToPath(import.meta.url));\nconst workerPath = path.join(dirname, 'worker/worker.js');\n\n// TODO do we need a pool?\nlet worker: Worker | undefined;\n\n/** Stop the worker for testing */\nexport async function _stopWorker() {\n await worker?.terminate();\n worker = undefined;\n}\n\nfunction processError(error: NonNullable<SandboxWorkerResponse['error']>): StubError {\n const { message, code, name: errorName } = error;\n\n let newMessage: string;\n let type: StubError['type'];\n\n if (code === errorCodes.moduleNotFound) {\n // Remove the require stack from MODULE_NOT_FOUND errors (we'll handle it separately).\n // Error: Cannot find module 'foo'\n // Require stack:\n // - [...]/index.js\n // - [.]/worker.js\n newMessage = message.split('\\n')[0];\n type = 'module-not-found';\n } else if (code === errorCodes.requireESM) {\n // Remove the instruction to change to a dynamic import, since it's less likely to be applicable here.\n // Error [ERR_REQUIRE_ESM]: require() of ES Module [...]/esm.mjs not supported.\n // Instead change the require of [...]/esm.mjs to a dynamic import() which is available in all CommonJS modules.\n newMessage = message.split('\\n')[0];\n type = 'require-esm';\n } else if (errorName === 'SyntaxError') {\n newMessage = message;\n type = 'invalid-syntax';\n } else {\n newMessage = message;\n type = 'other-error';\n }\n\n let stack: string[] | undefined;\n if (error.stack) {\n // Get stack frame lines from the original error stack\n stack = error.stack\n .split('\\n')\n .filter((line) => /^\\s+at /.test(line))\n .map((line) => line.trim());\n\n // Remove the worker frame and anything after it\n const workerIndex = stack.findIndex(\n (line) => slash(line).includes('esm-stub-utilities') && line.includes('worker.js'),\n );\n if (workerIndex !== -1) {\n stack = stack.slice(0, workerIndex);\n }\n\n if (!stack.length) {\n stack = undefined;\n if (code === errorCodes.requireESM) {\n // This error code + no stack outside the worker strongly implies that the file itself\n // If we ended up with no stack besides the worker, this strongly implies that the file\n // itself is an ESM file, not a CommonJS file.\n newMessage =\n \"It appears you're trying to create a stub of an ES module, which is not supported. \" +\n 'You may need to add a cloudpack override to bundle this package with ori.';\n type = 'entry-is-esm';\n }\n }\n }\n\n // Remove node internals from the stack\n const partialStack = stack?.filter((line) => !line.includes('(node:'));\n\n return {\n message: newMessage,\n type,\n partialStack: partialStack?.length ? partialStack : undefined,\n };\n}\n\n/**\n * Run a CommonJS file within a sandboxed environment.\n * @param entryPath - Path to a CommonJS file to run in a sandbox (does not work with ESM files)\n * @returns Info about the file's exports, or error info if there was an issue.\n * Should only throw an error on bad input or other cases that likely indicate either a bug\n * or bad configuration (as opposed to a problem with the file being stubbed).\n */\n// TODO add mechanism to force one-off worker\nexport async function runInSandbox(entryPath: string): Promise<StubExportInfo | { error: StubError }> {\n if (!path.isAbsolute(entryPath)) {\n throw new Error('Entry path must be absolute. Received: ' + entryPath);\n }\n if (!fs.existsSync(entryPath)) {\n throw new Error('Entry path does not exist: ' + entryPath);\n }\n\n if (!worker) {\n try {\n worker = new Worker(workerPath, { stdout: true, stderr: true, execArgv: [] });\n worker.stdout?.on('data', (data) => {\n console.debug(`[sandbox stdout] ${data}`);\n });\n worker.stderr?.on('data', (data) => {\n console.debug(`[sandbox stderr] ${data}`);\n });\n worker.on('exit', () => {\n worker = undefined;\n });\n // don't hold the process open if only the worker is left\n worker.unref();\n } catch (err) {\n throw new Error(`Error initializing sandbox worker: ${(err as Error)?.stack || err}`);\n }\n }\n\n return new Promise((resolve, reject) => {\n // just for type checking\n if (!worker) return;\n\n worker.on('message', onMessage);\n worker.on('messageerror', onMessageError);\n worker.on('error', onError);\n worker.on('exit', onExit);\n\n // Send a message requesting the file to be run.\n worker.postMessage(entryPath);\n\n /** Normally, both success and error results should be sent back as messages. */\n function onMessage(message: SandboxWorkerResponse) {\n if (message.entryPath !== entryPath) {\n return; // message about a different file\n }\n\n handlersOff();\n if (message.exportInfo) {\n resolve(message.exportInfo);\n } else if (message.error) {\n resolve({ error: processError(message.error) });\n } else {\n // this indicates a bug in cloudpack\n reject(new Error(`Unexpected sandbox worker message while running ${entryPath}: ${JSON.stringify(message)}`));\n }\n }\n\n /** 'messageerror' event: deserializing a message failed. */\n function onMessageError(err: Error) {\n handlersOff();\n reject(\n new Error(`Error with sandbox worker message serialization while running ${entryPath}: ${err.stack || err}\\n`),\n );\n }\n\n /** 'error' event: unhandled exception in the worker, which shouldn't happen. */\n function onError(err: Error) {\n handlersOff();\n reject(new Error(`Uncaught error in sandbox worker while running ${entryPath}: ${err.stack || err}\\n`));\n }\n\n /**\n * Make sure the promise rejects if the worker exits unexpectedly. (This handler is unlikely\n * to be used because the worker should throw an error if a file calls process.exit().)\n */\n function onExit() {\n reject(new Error(`Sandbox worker exited unexpectedly while running ${entryPath}`));\n }\n\n /** Remove all event handlers to avoid interference with future sandbox runs. */\n function handlersOff() {\n worker?.off('message', onMessage);\n worker?.off('messageerror', onMessageError);\n worker?.off('error', onError);\n worker?.off('exit', onExit);\n }\n });\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"globals.js","sourceRoot":"","sources":["../../src/worker/globals.js"],"names":[],"mappings":"AAAA,2CAA2C;AAE3C,gEAAgE;AAChE,MAAM,UAAU,mBAAmB;IACjC,OAAO,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,yBAAyB,CAAC,MAAM,CAAC,CAAC,CAAC;AAC/D,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,cAAc,CAAC,uBAAuB;IACpD,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,yBAAyB,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,EAAE;QAC7E,IAAI,CAAC,uBAAuB,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,YAAY,EAAE;
|
|
1
|
+
{"version":3,"file":"globals.js","sourceRoot":"","sources":["../../src/worker/globals.js"],"names":[],"mappings":"AAAA,2CAA2C;AAE3C,gEAAgE;AAChE,MAAM,UAAU,mBAAmB;IACjC,OAAO,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,yBAAyB,CAAC,MAAM,CAAC,CAAC,CAAC;AAC/D,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,cAAc,CAAC,uBAAuB;IACpD,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,yBAAyB,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,EAAE;QAC7E,IAAI,CAAC,uBAAuB,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,YAAY,EAAE,CAAC;YAC9D,IAAI,CAAC;gBACH,OAAO,EAAC,gBAAiB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YACxC,CAAC;YAAC,MAAM,CAAC;gBACP,SAAS;YACX,CAAC;QACH,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["// See worker.js for why this is a JS file.\n\n/** Get all property descriptor names from the global object. */\nexport function getGlobalProperties() {\n return Object.keys(Object.getOwnPropertyDescriptors(global));\n}\n\n/**\n * Delete any new properties from the global object.\n * @param {string[]} initialGlobalProperties\n */\nexport function cleanUpGlobals(initialGlobalProperties) {\n Object.entries(Object.getOwnPropertyDescriptors(global)).forEach(([k, desc]) => {\n if (!initialGlobalProperties.includes(k) && desc.configurable) {\n try {\n delete (/** @type {*} */ (global)[k]);\n } catch {\n // ignore\n }\n }\n });\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"initBrowserEnvironment.js","sourceRoot":"","sources":["../../src/worker/initBrowserEnvironment.js"],"names":[],"mappings":"AAAA,2CAA2C;AAE3C,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,sBAAsB;IAC1C,oCAAoC;IACpC,CAAC,MAAM,CAAC,WAAW,IAAI,CAAC,MAAM,CAAC,WAAW,GAAG,gBAAgB,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC;IAC7E,CAAC,MAAM,CAAC,WAAW,IAAI,CAAC,MAAM,CAAC,WAAW,GAAG,IAAI,CAAC,WAAW,CAAC,CAAC;IAC/D,CAAC,MAAM,CAAC,WAAW,IAAI,CAAC,MAAM,CAAC,WAAW,GAAG,gBAAgB,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC;IAElF,CAAC,MAAM,MAAM,CAAC,cAAc,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC;IAEzC,MAAM,MAAM,CAAC,qBAAqB,CAAC,CAAC;IAEpC,iGAAiG;IACjG,8FAA8F;IAC9F,MAAM,CAAC,OAAO,CAAC,MAAM,CA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AC,QAAQ,CAAC,aAAa;QAC3B,gBAAgB,CAAC,CAAC,MAAM,CAAC,CAAC,aAAa;YACvC,gBAAgB,CAAC,CAAC,MAAM,CAAC,CAAC,aAAa;gBACrC,CAAC,qBAAqB,CAAC,OAAO,EAAE,qCAAqC,CAAC,OAAO,EAAE,EAAE;oBAC/E,IAAI,OAAO,KAAK,QAAQ,EAAE,CAAC;wBACzB,OAAO,gBAAgB,CAAC,CAAC;4BACvB,UAAU,EAAE,GAAG,EAAE,CAAC,CAAC;gCACjB,QAAQ,EAAE,GAAG,EAAE,GAAE,CAAC;6BACnB,CAAC;4BACF,WAAW,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC;yBACxB,CAAC,CAAC;oBACL,CAAC;oBAED,OAAO,aAAa,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC;gBAClE,CAAC,CAAC;IAEN,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;AAC5C,CAAC","sourcesContent":["// See worker.js for why this is a JS file.\n\nimport btoa from 'btoa';\nimport atob from 'atob';\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 && (global.performance = /** @type {*} */ (performance));\n !global.TextEncoder && (global.TextEncoder = util.TextEncoder);\n !global.TextDecoder && (global.TextDecoder = /** @type {*} */ (util.TextDecoder));\n\n (await import('jsdom-global')).default();\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 window.requestAnimationFrame = window.setTimeout;\n window.cancelAnimationFrame = window.clearTimeout;\n global.btoa = btoa;\n global.atob = atob;\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 // eslint-disable-next-line etc/no-deprecated\n const createElement = window.document.createElement.bind(window.document);\n\n // Mock out canvas.\n // eslint-disable-next-line etc/no-deprecated\n global.document.createElement =\n /** @type {*} */ (window).createElement =\n /** @type {*} */ (global).createElement =\n (/** @type {string} */ tagName, /** @type {ElementCreationOptions} */ options) => {\n if (tagName === 'canvas') {\n return /** @type {*} */ ({\n getContext: () => ({\n fillRect: () => {},\n }),\n measureText: () => ({}),\n });\n }\n\n return createElement.apply(window.document, [tagName, options]);\n };\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"]}
|
package/lib/worker/worker.js
CHANGED
|
@@ -53,7 +53,7 @@ parentPort.on('message', (/** @type {string} */ entryPath) => {
|
|
|
53
53
|
entryPath,
|
|
54
54
|
// Spreading doesn't work with errors, so copy manually
|
|
55
55
|
error: {
|
|
56
|
-
message: String(err),
|
|
56
|
+
message: String(err), // handle non-Errors, and include the error name if present
|
|
57
57
|
name: err.name,
|
|
58
58
|
code: err.code,
|
|
59
59
|
stack: err.stack,
|
package/lib/worker/worker.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker.js","sourceRoot":"","sources":["../../src/worker/worker.js"],"names":[],"mappings":"AAAA,0FAA0F;AAC1F,4FAA4F;AAC5F,8FAA8F;AAC9F,8CAA8C;AAE9C,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC1D,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAEnE,IAAI,YAAY,IAAI,CAAC,UAAU,EAAE;
|
|
1
|
+
{"version":3,"file":"worker.js","sourceRoot":"","sources":["../../src/worker/worker.js"],"names":[],"mappings":"AAAA,0FAA0F;AAC1F,4FAA4F;AAC5F,8FAA8F;AAC9F,8CAA8C;AAE9C,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC1D,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAEnE,IAAI,YAAY,IAAI,CAAC,UAAU,EAAE,CAAC;IAChC,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAAC;AACxE,CAAC;AAED,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAE/C,MAAM,sBAAsB,EAAE,CAAC;AAC/B,6DA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IACL,CAAC;YAAS,CAAC;QACT,cAAc,CAAC,uBAAuB,CAAC,CAAC;QACxC,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC9B,CAAC;AACH,CAAC,CAAC,CAAC;AAEH;;;;GAIG;AACH,SAAS,aAAa,CAAC,YAAY;IACjC,IAAI,YAAY,KAAK,SAAS,EAAE,CAAC;QAC/B,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;IAC1B,CAAC;IAED,IAAI,OAAO,YAAY,KAAK,UAAU,EAAE,CAAC;QACvC,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,EAAE,CAAC;IAC/D,CAAC;IAED,IAAI,YAAY,IAAI,OAAO,YAAY,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE,CAAC;QACrF,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,EAAE,CAAC;IAC7D,CAAC;IAED,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;AAC3B,CAAC","sourcesContent":["// These files use JS because they're loaded directly into a worker (see runInSandbox.ts),\n// which must work both during tests (where the files are loaded from \"src\") and at runtime.\n// They can still be type checked like TS, and the transpilation step doesn't do anything that\n// should change the desired runtime behavior.\n\nimport { createRequire } from 'module';\nimport { isMainThread, parentPort } from 'worker_threads';\nimport { initBrowserEnvironment } from './initBrowserEnvironment.js';\nimport { cleanUpGlobals, getGlobalProperties } from './globals.js';\n\nif (isMainThread || !parentPort) {\n throw new Error('This file should only be loaded in a worker thread');\n}\n\nconst require = createRequire(import.meta.url);\n\nawait initBrowserEnvironment();\n// TODO should the globals be marked as readonly if possible?\nconst initialGlobalProperties = getGlobalProperties();\n\n/**\n * Type helper for sending messages to the parent.\n * @param {import('../types/SandboxWorkerResponse.js').SandboxWorkerResponse} message\n */\nfunction emitMessage(message) {\n parentPort?.postMessage(message);\n}\n\nparentPort.on('message', (/** @type {string} */ entryPath) => {\n if (typeof entryPath !== 'string') {\n emitMessage({\n error: { message: `Expected message to be a string; received: ${JSON.stringify(entryPath)}` },\n entryPath: '',\n });\n return;\n }\n\n function onExit() {\n // In this case, throw an error rather than sending a message to avoid handling it twice.\n // Don't include the filename since that's potentially ambiguous (and redundant with info\n // included by the runInSandbox error handler).\n throw new Error('process.exit() was unexpectedly called');\n }\n process.on('exit', onExit);\n\n try {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n const moduleExports = require(entryPath);\n emitMessage({\n entryPath,\n exportInfo: getExportInfo(moduleExports),\n });\n } catch (e) {\n // Some errors running a module have a string `code` property.\n // MODULE_NOT_FOUND errors have a `requireStack` property with a list of paths\n // (right now we're using the call stack instead, but we could reconsider depending on\n // which one seems more useful in practice).\n const err = /** @type {Error & { code?: string; requireStack?: string[] }} */ (e);\n emitMessage({\n entryPath,\n // Spreading doesn't work with errors, so copy manually\n error: {\n message: String(err), // handle non-Errors, and include the error name if present\n name: err.name,\n code: err.code,\n stack: err.stack,\n },\n });\n } finally {\n cleanUpGlobals(initialGlobalProperties);\n process.off('exit', onExit);\n }\n});\n\n/**\n * Get information about a CJS module's exports, for purposes of creating a stub.\n * @param {unknown} moduleExport The module's exports.\n * @returns {import('../types/StubExportInfo.js').StubExportInfo}\n */\nfunction getExportInfo(moduleExport) {\n if (moduleExport === undefined) {\n return { type: 'none' };\n }\n\n if (typeof moduleExport === 'function') {\n return { type: 'function', keys: Object.keys(moduleExport) };\n }\n\n if (moduleExport && typeof moduleExport === 'object' && !Array.isArray(moduleExport)) {\n return { type: 'object', keys: Object.keys(moduleExport) };\n }\n\n return { type: 'other' };\n}\n"]}
|
package/lib/writeESMStub.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"writeESMStub.js","sourceRoot":"","sources":["../src/writeESMStub.ts"],"names":[],"m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,IAAI,CAAC,WAAW,EAAE,sCAAsC,CAAC,CAAC;IACtF,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,YAAY,CAAC,CAAC;IAEzD,yCAAyC;IACzC,MAAM,UAAU,CAAC,KAAK,CAAC,cAAc,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAE5D,8BAA8B;IAC9B,MAAM,aAAa,GAAG,MAAM,aAAa,CAAC,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC,CAAC;IACnE,IAAI,OAAO,aAAa,KAAK,QAAQ,EAAE,CAAC;QACtC,MAAM,UAAU,CAAC,SAAS,CAAC,QAAQ,EAAE,aAAa,CAAC,CAAC;QACpD,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,6CAA6C;IAC7C,OAAO,aAAa,CAAC;AACvB,CAAC","sourcesContent":["import fsPromises from 'fs/promises';\nimport path from 'path';\nimport { createESMStub } from './createESMStub.js';\nimport { findPackageRoot } from '@ms-cloudpack/path-utilities';\nimport { slash } from '@ms-cloudpack/path-string-parsing';\nimport type { StubError } from './index.js';\n\n/**\n * Generates an ESM stub for CommonJS modules.\n * @returns Path to the stub, or error info if there was an issue.\n * Should only throw an error on bad input or other cases that likely indicate either a bug\n * or bad configuration (as opposed to a problem with the file being stubbed).\n */\nexport async function writeESMStub(entryPath: string): Promise<string | StubError> {\n // Ensure forward slashes\n entryPath = slash(entryPath);\n\n // Figure out where to put the stub\n const packageRoot = findPackageRoot(entryPath);\n if (!packageRoot) {\n throw new Error(`Unable to find package root for ${entryPath}`);\n }\n const stubFilename = path.basename(entryPath, path.extname(entryPath)) + '-stub.mjs';\n const stubFolderPath = path.join(packageRoot, 'node_modules/.cache/cloudpack-stubs/');\n const stubPath = path.join(stubFolderPath, stubFilename);\n\n // Create parent directories for the stub\n await fsPromises.mkdir(stubFolderPath, { recursive: true });\n\n // Generate and write the stub\n const esmStubResult = await createESMStub({ entryPath, stubPath });\n if (typeof esmStubResult === 'string') {\n await fsPromises.writeFile(stubPath, esmStubResult);\n return stubPath;\n }\n\n // There was an error, so return that instead\n return esmStubResult;\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.23",
|
|
4
4
|
"description": "Generates ESM stubs for CommonJS entry files.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"@types/jsdom": "^21.1.1",
|
|
34
34
|
"@types/regenerator-runtime": "^0.13.1",
|
|
35
35
|
"lodash": "^4.17.21",
|
|
36
|
-
"pretty-format": "^
|
|
36
|
+
"pretty-format": "^30.0.0-alpha.1"
|
|
37
37
|
},
|
|
38
38
|
"scripts": {
|
|
39
39
|
"api": "cloudpack-scripts api",
|