@ms-cloudpack/esm-stub-utilities 0.10.13 → 0.11.0

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.
@@ -1,4 +1,4 @@
1
- import type { BundleMessage } from '@ms-cloudpack/bundler-types';
1
+ import type { BundleMessage } from '@ms-cloudpack/common-types';
2
2
  export type ErrorLike = {
3
3
  name?: string;
4
4
  message: string;
@@ -1 +1 @@
1
- {"version":3,"file":"processError.d.ts","sourceRoot":"","sources":["../src/processError.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAGjE,MAAM,MAAM,SAAS,GAAG;IAAE,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,YAAY,CAAC,EAAE,MAAM,EAAE,CAAA;CAAE,CAAC;AAYnH;;GAEG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,aAAa,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAAE,GAAG,aAAa,CA2G/G"}
1
+ {"version":3,"file":"processError.d.ts","sourceRoot":"","sources":["../src/processError.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAGhE,MAAM,MAAM,SAAS,GAAG;IAAE,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,YAAY,CAAC,EAAE,MAAM,EAAE,CAAA;CAAE,CAAC;AAYnH;;GAEG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC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CAAC,CAAC;QACrC,CAAC;IACH,CAAC;IAED,gFAAgF;IAChF,MAAM,aAAa,GAAG,KAAK,EAAE,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,iBAAiB,CAAC,CAAC;IAClH,IAAI,aAAa,EAAE,CAAC;QAClB,UAAU,GAAG,MAAM,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC;QACtC,YAAY,GAAG,MAAM,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC;IAC1C,CAAC;IAED,uEAAuE;IACvE,kFAAkF;IAClF,6FAA6F;IAC7F,sBAAsB;IACtB,IAAI,KAAK,EAAE,MAAM,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,aAAa,CAAC,IAAI,IAAI,KAAK,UAAU,CAAC,cAAc,EAAE,CAAC;QAChG,+BAA+B;QAC/B,OAAO,IAAI,gDAAgD,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;IAChF,CAAC;IAED,OAAO;QACL,IAAI,EAAE,oCAAoC,QAAQ,OAAO,OAAO,EAAE;QAClE,QAAQ,EAAE,EAAE,IAAI,EAAE,KAAK,CAAC,aAAa,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,YAAY,EAAE;KACjF,CAAC;AACJ,CAAC","sourcesContent":["import type { BundleMessage } from '@ms-cloudpack/bundler-types';\nimport { slash } from '@ms-cloudpack/path-string-parsing';\n\nexport type ErrorLike = { name?: string; message: string; stack?: string; code?: string; requireStack?: string[] };\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 esmPackageName = 'esm-stub-utilities';\nconst workerPackageName = 'worker-pool';\nconst workerEntryName = 'workerEntry.js';\n\n/**\n * Get info from an error which may be useful for debugging.\n */\nexport function processError(params: { entryKey: string; entryFullPath: string; error: unknown }): BundleMessage {\n const { entryKey, entryFullPath, error: errorParam } = params;\n const error = (errorParam as Error).message ? (errorParam as ErrorLike) : { message: String(errorParam) };\n\n const { message: originalMessage, name, code, stack: originalStack, requireStack } = error;\n\n let lineNumber = 1;\n let columnNumber = 0;\n let message = originalMessage;\n\n 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 message = message.split('\\n')[0];\n } else if (code === errorCodes.moduleNotFound && requireStack) {\n // Module not found errors have a require stack included in the error message, as well as a\n // requireStack property. Remove the stack from the message and rebuild it with filtering.\n // Error: Cannot find module 'foo'\n // Require stack:\n // - [...]/index.js\n // - [...]/generateESMStubFromCJS.js\n message = message.split('\\n')[0];\n // remove the generateESMStubFromCJS require line (not interesting)\n const filteredStack = requireStack.filter(\n (line) => !line.includes(esmPackageName) && !line.includes(workerPackageName),\n );\n if (filteredStack.length > 1) {\n // Only include the stack if it goes beyond the original file\n message += `.\\nRequire stack:\\n${filteredStack.map((line) => ` - ${line}`).join('\\n')}`;\n }\n } else if (name === 'SyntaxError' && originalStack) {\n // SyntaxErrors will have a `stack` like this:\n // /path/to/file.js:1\n // oh no\n // ^^\n // SyntaxError: Unexpected identifier\n // at ....\n // Use the first part as the message, but remove the stack trace (will be added back later if needed).\n message = originalStack.split(/\\n\\s+at /)[0];\n\n // If the error is in the entry point file, get the line and possibly column number.\n // (There won't be a stack line for the file with the syntax error, so the normal logic to get\n // the line and column later won't work.)\n const lineNumberMatch = message.match(/^(.*?):(\\d+)\\n/);\n if (lineNumberMatch && slash(lineNumberMatch[1]).includes(slash(entryFullPath))) {\n lineNumber = Number(lineNumberMatch[2]);\n\n // Get the column if the stack includes ^^ indicating the error location\n // (not all of them will have this, e.g. \"unexpected end of input\" errors won't)\n const columnNumberMatch = message.match(/^\\s*\\^/m);\n if (columnNumberMatch) {\n columnNumber = columnNumberMatch[0].length - 1;\n }\n }\n\n // This happens if a file is inferred from context or extension to be CJS but is actually ESM.\n if (/Unexpected token '(import|export)'/.test(message)) {\n message = `File appears to be an ES module that was loaded with require:\\n${message}`;\n }\n } else if (name !== 'Error') {\n message = `${name}: ${message}`;\n }\n\n let stack: string[] | undefined;\n if (originalStack) {\n // Get stack frame lines from the original error stack, and remove parts that are less likely\n // to be useful (node internals, and jest internals for errors while running tests).\n stack = originalStack\n .split('\\n')\n .filter((line) => /^\\s+at /.test(line) && !/\\(node:|jest-runtime|jest-resolve/.test(line));\n\n // The user probably only cares about the error location in the original code,\n // so make it easier to see that by removing all the esm-stub-utilities frames.\n const workerEntryIndex = stack.findIndex((line) => line.includes(workerEntryName));\n if (workerEntryIndex !== -1) {\n // Special case: if the error came from the file calling process.exit(), the most recent stack\n // frame will be from workerEntry.js, and the real frames will be after that.\n stack = stack.slice(workerEntryIndex + 1);\n }\n // Find the first esm-stub-utilities line and remove that and everything after.\n const utilsIndex = stack.findIndex((line) => line.includes(esmPackageName));\n if (utilsIndex !== -1) {\n stack = stack.slice(0, utilsIndex);\n }\n }\n\n // See if we can find the line and column in the entry file from the stack trace\n const locationMatch = stack?.find((line) => slash(line).includes(slash(entryFullPath)))?.match(/:(\\d+):(\\d+)\\)$/);\n if (locationMatch) {\n lineNumber = Number(locationMatch[1]);\n columnNumber = Number(locationMatch[2]);\n }\n\n // Include the stack if present, provided it's not just the entry file,\n // and this isn't a module not found error which already includes a require stack.\n // (If the only interesting stack line is the entry file, this is redundant with the returned\n // `location` object.)\n if (stack?.length && (stack.length > 1 || !locationMatch) && code !== errorCodes.moduleNotFound) {\n // Add the stack to the message\n message += `\\n\\nPartial stack (node internals omitted):\\n${stack.join('\\n')}`;\n }\n\n return {\n text: `Error creating stub for entry \"./${entryKey}\":\\n${message}`,\n location: { file: slash(entryFullPath), line: lineNumber, column: columnNumber },\n };\n}\n"]}
1
+ {"version":3,"file":"processError.js","sourceRoot":"","sources":["../src/processError.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,mCAAmC,CAAC;AAI1D,8EAA8E;AAC9E,MAAM,UAAU,GAAG;IACjB,UAAU,EAAE,iBAAiB;IAC7B,cAAc,EAAE,kBAAkB;CACnC,CAAC;AAEF,MAAM,cAAc,GAAG,oBAAoB,CAAC;AAC5C,MAAM,iBAAiB,GAAG,aAAa,CAAC;AACxC,MAAM,eAAe,GAAG,gBAAgB,CAAC;AAEzC;;GAEG;AACH,MAAM,UAAU,YAAY,CAAC,MAAmE;IAC9F,MAAM,EAAE,QAAQ,EAAE,aAAa,EAAE,KAAK,EAAE,UAAU,EAAE,GAAG,MAAM,CAAC;IAC9D,MAAM,KAAK,GAAI,UAAoB,CAAC,OAAO,CAAC,CAAC,CAAE,UAAwB,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,UAAU,CAAC,EAAE,CAAC;IAE1G,MAAM,EAAE,OAAO,EAAE,eAAe,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,GAAG,KAAK,CAAC;IAE3F,IAAI,UAAU,GAAG,CAAC,CAAC;IACnB,IAAI,YAAY,GAAG,CAAC,CAAC;IACrB,IAAI,OAAO,GAAG,eAAe,CAAC;IAE9B,IAAI,IAAI,KAAK,UAAU,CAAC,UAAU,EAAE,CAAC;QACnC,sGAAsG;QACtG,iFAAiF;QACjF,kHAAkH;QAClH,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;IACnC,CAAC;SAAM,IAAI,IAAI,KAAK,UAAU,CAAC,cAAc,IAAI,YAAY,EAAE,CAAC;QAC9D,2FAA2F;QAC3F,0FAA0F;QAC1F,oCAAoC;QACpC,mBAAmB;QACnB,qBA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,gFAAgF;IAChF,MAAM,aAAa,GAAG,KAAK,EAAE,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,iBAAiB,CAAC,CAAC;IAClH,IAAI,aAAa,EAAE,CAAC;QAClB,UAAU,GAAG,MAAM,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC;QACtC,YAAY,GAAG,MAAM,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC;IAC1C,CAAC;IAED,uEAAuE;IACvE,kFAAkF;IAClF,6FAA6F;IAC7F,sBAAsB;IACtB,IAAI,KAAK,EAAE,MAAM,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,aAAa,CAAC,IAAI,IAAI,KAAK,UAAU,CAAC,cAAc,EAAE,CAAC;QAChG,+BAA+B;QAC/B,OAAO,IAAI,gDAAgD,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;IAChF,CAAC;IAED,OAAO;QACL,IAAI,EAAE,oCAAoC,QAAQ,OAAO,OAAO,EAAE;QAClE,QAAQ,EAAE,EAAE,IAAI,EAAE,KAAK,CAAC,aAAa,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,YAAY,EAAE;KACjF,CAAC;AACJ,CAAC","sourcesContent":["import type { BundleMessage } from '@ms-cloudpack/common-types';\nimport { slash } from '@ms-cloudpack/path-string-parsing';\n\nexport type ErrorLike = { name?: string; message: string; stack?: string; code?: string; requireStack?: string[] };\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 esmPackageName = 'esm-stub-utilities';\nconst workerPackageName = 'worker-pool';\nconst workerEntryName = 'workerEntry.js';\n\n/**\n * Get info from an error which may be useful for debugging.\n */\nexport function processError(params: { entryKey: string; entryFullPath: string; error: unknown }): BundleMessage {\n const { entryKey, entryFullPath, error: errorParam } = params;\n const error = (errorParam as Error).message ? (errorParam as ErrorLike) : { message: String(errorParam) };\n\n const { message: originalMessage, name, code, stack: originalStack, requireStack } = error;\n\n let lineNumber = 1;\n let columnNumber = 0;\n let message = originalMessage;\n\n 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 message = message.split('\\n')[0];\n } else if (code === errorCodes.moduleNotFound && requireStack) {\n // Module not found errors have a require stack included in the error message, as well as a\n // requireStack property. Remove the stack from the message and rebuild it with filtering.\n // Error: Cannot find module 'foo'\n // Require stack:\n // - [...]/index.js\n // - [...]/generateESMStubFromCJS.js\n message = message.split('\\n')[0];\n // remove the generateESMStubFromCJS require line (not interesting)\n const filteredStack = requireStack.filter(\n (line) => !line.includes(esmPackageName) && !line.includes(workerPackageName),\n );\n if (filteredStack.length > 1) {\n // Only include the stack if it goes beyond the original file\n message += `.\\nRequire stack:\\n${filteredStack.map((line) => ` - ${line}`).join('\\n')}`;\n }\n } else if (name === 'SyntaxError' && originalStack) {\n // SyntaxErrors will have a `stack` like this:\n // /path/to/file.js:1\n // oh no\n // ^^\n // SyntaxError: Unexpected identifier\n // at ....\n // Use the first part as the message, but remove the stack trace (will be added back later if needed).\n message = originalStack.split(/\\n\\s+at /)[0];\n\n // If the error is in the entry point file, get the line and possibly column number.\n // (There won't be a stack line for the file with the syntax error, so the normal logic to get\n // the line and column later won't work.)\n const lineNumberMatch = message.match(/^(.*?):(\\d+)\\n/);\n if (lineNumberMatch && slash(lineNumberMatch[1]).includes(slash(entryFullPath))) {\n lineNumber = Number(lineNumberMatch[2]);\n\n // Get the column if the stack includes ^^ indicating the error location\n // (not all of them will have this, e.g. \"unexpected end of input\" errors won't)\n const columnNumberMatch = message.match(/^\\s*\\^/m);\n if (columnNumberMatch) {\n columnNumber = columnNumberMatch[0].length - 1;\n }\n }\n\n // This happens if a file is inferred from context or extension to be CJS but is actually ESM.\n if (/Unexpected token '(import|export)'/.test(message)) {\n message = `File appears to be an ES module that was loaded with require:\\n${message}`;\n }\n } else if (name !== 'Error') {\n message = `${name}: ${message}`;\n }\n\n let stack: string[] | undefined;\n if (originalStack) {\n // Get stack frame lines from the original error stack, and remove parts that are less likely\n // to be useful (node internals, and jest internals for errors while running tests).\n stack = originalStack\n .split('\\n')\n .filter((line) => /^\\s+at /.test(line) && !/\\(node:|jest-runtime|jest-resolve/.test(line));\n\n // The user probably only cares about the error location in the original code,\n // so make it easier to see that by removing all the esm-stub-utilities frames.\n const workerEntryIndex = stack.findIndex((line) => line.includes(workerEntryName));\n if (workerEntryIndex !== -1) {\n // Special case: if the error came from the file calling process.exit(), the most recent stack\n // frame will be from workerEntry.js, and the real frames will be after that.\n stack = stack.slice(workerEntryIndex + 1);\n }\n // Find the first esm-stub-utilities line and remove that and everything after.\n const utilsIndex = stack.findIndex((line) => line.includes(esmPackageName));\n if (utilsIndex !== -1) {\n stack = stack.slice(0, utilsIndex);\n }\n }\n\n // See if we can find the line and column in the entry file from the stack trace\n const locationMatch = stack?.find((line) => slash(line).includes(slash(entryFullPath)))?.match(/:(\\d+):(\\d+)\\)$/);\n if (locationMatch) {\n lineNumber = Number(locationMatch[1]);\n columnNumber = Number(locationMatch[2]);\n }\n\n // Include the stack if present, provided it's not just the entry file,\n // and this isn't a module not found error which already includes a require stack.\n // (If the only interesting stack line is the entry file, this is redundant with the returned\n // `location` object.)\n if (stack?.length && (stack.length > 1 || !locationMatch) && code !== errorCodes.moduleNotFound) {\n // Add the stack to the message\n message += `\\n\\nPartial stack (node internals omitted):\\n${stack.join('\\n')}`;\n }\n\n return {\n text: `Error creating stub for entry \"./${entryKey}\":\\n${message}`,\n location: { file: slash(entryFullPath), line: lineNumber, column: columnNumber },\n };\n}\n"]}
@@ -1,4 +1,4 @@
1
- import type { BundleMessage } from '@ms-cloudpack/bundler-types';
1
+ import type { BundleMessage } from '@ms-cloudpack/common-types';
2
2
  export type WriteESMStubsResult = {
3
3
  /**
4
4
  * Mapping from entry key to full path:
@@ -1 +1 @@
1
- {"version":3,"file":"WriteESMStubsResult.d.ts","sourceRoot":"","sources":["../../src/types/WriteESMStubsResult.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAEjE,MAAM,MAAM,mBAAmB,GAAG;IAChC;;;;OAIG;IACH,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAEnC,+BAA+B;IAC/B,MAAM,EAAE,aAAa,EAAE,CAAC;CACzB,CAAC"}
1
+ {"version":3,"file":"WriteESMStubsResult.d.ts","sourceRoot":"","sources":["../../src/types/WriteESMStubsResult.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAEhE,MAAM,MAAM,mBAAmB,GAAG;IAChC;;;;OAIG;IACH,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAEnC,+BAA+B;IAC/B,MAAM,EAAE,aAAa,EAAE,CAAC;CACzB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"WriteESMStubsResult.js","sourceRoot":"","sources":["../../src/types/WriteESMStubsResult.ts"],"names":[],"mappings":"","sourcesContent":["import type { BundleMessage } from '@ms-cloudpack/bundler-types';\n\nexport type WriteESMStubsResult = {\n /**\n * Mapping from entry key to full path:\n * - Stub file path, if the file needed to be stubbed and was successful\n * - Original path, if the file didn't need to be stubbed or stubbing was unsuccessful\n */\n newEntries: Record<string, string>;\n\n /** Any errors that occurred */\n errors: BundleMessage[];\n};\n"]}
1
+ {"version":3,"file":"WriteESMStubsResult.js","sourceRoot":"","sources":["../../src/types/WriteESMStubsResult.ts"],"names":[],"mappings":"","sourcesContent":["import type { BundleMessage } from '@ms-cloudpack/common-types';\n\nexport type WriteESMStubsResult = {\n /**\n * Mapping from entry key to full path:\n * - Stub file path, if the file needed to be stubbed and was successful\n * - Original path, if the file didn't need to be stubbed or stubbing was unsuccessful\n */\n newEntries: Record<string, string>;\n\n /** Any errors that occurred */\n errors: BundleMessage[];\n};\n"]}
@@ -52,6 +52,7 @@ async function tryImportStub(request) {
52
52
  let moduleExports;
53
53
  let step = 'Import';
54
54
  try {
55
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
55
56
  moduleExports = await import(stubPath);
56
57
  step = 'Running test code';
57
58
  if (testCode) {
@@ -1 +1 @@
1
- {"version":3,"file":"loadStubWorker.js","sourceRoot":"","sources":["../../src/verifyStub/loadStubWorker.js"],"names":[],"mappings":"AAAA,EAAE;AACF,EAAE;AACF,oFAAoF;AACpF,qDAAqD;AACrD,EAAE;AACF,uDAAuD;AACvD,EAAE;AACF,EAAE;AAEF,+DAA+D;AAC/D,wDAAwD;AACxD,0DAA0D;AAE1D;;;;;;GAMG;AACH,MAAM;AACN,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,CAAC;IAChC,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAAC;AACxE,CAAC;AAED,iDAAiD;AACjD,MAAM,sBAAsB,EAAE,CAAC;AAC/B,MAAM,uBAAuB,GAAG,mBAAmB,EAAE,CAAC;AAEtD;;;GAGG;AACH,SAAS,WAAW,CAAC,OAAO;IAC1B,UAAU,EAAE,WAAW,CAAC,OAAO,CAAC,CAAC;AACnC,CAAC;AAED,UAAU,CAAC,EAAE,C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AC,CAAC;IAC/B,CAAC;AACH,CAAC","sourcesContent":["//\n//\n// This worker is used in tests to verify that generated stub files can be imported,\n// and that the results of importing are as expected.\n//\n// See verifyStub.ts for more about why this is needed.\n//\n//\n\n/* 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/**\n * @typedef {Pick<import('../types/VerifyStubOptions.js')._VerifyStubOptions, 'stubPath' | 'testCode'>}\n * LoadStubWorkerRequest Request to `loadStubWorker.js`\n *\n * @typedef {{ value: unknown } | { error: string }} LoadStubWorkerResponse Response from `loadStubWorker.js`.\n * `value` is the IPC-friendly result of importing the module.\n */\n/** */\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 {LoadStubWorkerResponse} message\n */\nfunction emitMessage(message) {\n parentPort?.postMessage(message);\n}\n\nparentPort.on('message', (/** @type {LoadStubWorkerRequest} */ request) => {\n if (typeof request.stubPath !== 'string') {\n emitMessage({\n error: `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 {LoadStubWorkerRequest} request */\nasync function tryImportStub(request) {\n const { stubPath, testCode } = request;\n let moduleExports;\n let step = 'Import';\n try {\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 error: `${step} failed: ${/** @type {Error} */ (err).stack || String(err)}`,\n });\n return;\n } finally {\n cleanUpGlobals(initialGlobalProperties);\n }\n\n try {\n emitMessage({ value: serialize(moduleExports) });\n } catch (err) {\n emitMessage({\n error: `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, so it can be passed back to the test and verified.\n * @param {*} value\n * @returns {*}\n */\nfunction serialize(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 // Convert non-serializable types\n if (value instanceof Set) {\n return `Set ${JSON.stringify([...value])}`;\n }\n if (value instanceof Map) {\n return `Map ${JSON.stringify(Object.fromEntries(value))}`;\n }\n if (value instanceof Error) {\n return `[${value.name}: ${value.message}]`;\n }\n if (value instanceof RegExp) {\n return value.toString();\n }\n if (Array.isArray(value)) {\n return value.map((v) => serialize(v, depth + 1, encountered));\n }\n if (Object.keys(value).length || value.constructor?.name === 'Object') {\n return Object.fromEntries(Object.entries(value).map(([k, v]) => [k, serialize(v, depth + 1, encountered)]));\n }\n if (value.constructor) {\n return `[${value.constructor.name}]`;\n }\n if (value[Symbol.toStringTag] == 'Module') {\n return '[empty module]';\n }\n }\n\n if (typeof value === 'function') {\n const properties = JSON.stringify({ ...value });\n return `[Function ${value.name || '<anonymous>'}${properties === '{}' ? '' : ` ${properties}`}]`;\n }\n\n if (typeof value === 'symbol') {\n return value.toString();\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 JSON.stringify(value);\n }\n}\n"]}
1
+ {"version":3,"file":"loadStubWorker.js","sourceRoot":"","sources":["../../src/verifyStub/loadStubWorker.js"],"names":[],"mappings":"AAAA,EAAE;AACF,EAAE;AACF,oFAAoF;AAC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AC,MAAM,CAAC,WAAW,CAAC,IAAI,QAAQ,EAAE,CAAC;YAC1C,OAAO,gBAAgB,CAAC;QAC1B,CAAC;IACH,CAAC;IAED,IAAI,OAAO,KAAK,KAAK,UAAU,EAAE,CAAC;QAChC,MAAM,UAAU,GAAG,IAAI,CAAC,SAAS,CAAC,EAAE,GAAG,KAAK,EAAE,CAAC,CAAC;QAChD,OAAO,aAAa,KAAK,CAAC,IAAI,IAAI,aAAa,GAAG,UAAU,KAAK,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,UAAU,EAAE,GAAG,CAAC;IACnG,CAAC;IAED,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO,KAAK,CAAC,QAAQ,EAAE,CAAC;IAC1B,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,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IAC/B,CAAC;AACH,CAAC","sourcesContent":["//\n//\n// This worker is used in tests to verify that generated stub files can be imported,\n// and that the results of importing are as expected.\n//\n// See verifyStub.ts for more about why this is needed.\n//\n//\n\n/* 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/**\n * @typedef {Pick<import('../types/VerifyStubOptions.js')._VerifyStubOptions, 'stubPath' | 'testCode'>}\n * LoadStubWorkerRequest Request to `loadStubWorker.js`\n *\n * @typedef {{ value: unknown } | { error: string }} LoadStubWorkerResponse Response from `loadStubWorker.js`.\n * `value` is the IPC-friendly result of importing the module.\n */\n/** */\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 {LoadStubWorkerResponse} message\n */\nfunction emitMessage(message) {\n parentPort?.postMessage(message);\n}\n\nparentPort.on('message', (/** @type {LoadStubWorkerRequest} */ request) => {\n if (typeof request.stubPath !== 'string') {\n emitMessage({\n error: `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 {LoadStubWorkerRequest} 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 error: `${step} failed: ${/** @type {Error} */ (err).stack || String(err)}`,\n });\n return;\n } finally {\n cleanUpGlobals(initialGlobalProperties);\n }\n\n try {\n emitMessage({ value: serialize(moduleExports) });\n } catch (err) {\n emitMessage({\n error: `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, so it can be passed back to the test and verified.\n * @param {*} value\n * @returns {*}\n */\nfunction serialize(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 // Convert non-serializable types\n if (value instanceof Set) {\n return `Set ${JSON.stringify([...value])}`;\n }\n if (value instanceof Map) {\n return `Map ${JSON.stringify(Object.fromEntries(value))}`;\n }\n if (value instanceof Error) {\n return `[${value.name}: ${value.message}]`;\n }\n if (value instanceof RegExp) {\n return value.toString();\n }\n if (Array.isArray(value)) {\n return value.map((v) => serialize(v, depth + 1, encountered));\n }\n if (Object.keys(value).length || value.constructor?.name === 'Object') {\n return Object.fromEntries(Object.entries(value).map(([k, v]) => [k, serialize(v, depth + 1, encountered)]));\n }\n if (value.constructor) {\n return `[${value.constructor.name}]`;\n }\n if (value[Symbol.toStringTag] == 'Module') {\n return '[empty module]';\n }\n }\n\n if (typeof value === 'function') {\n const properties = JSON.stringify({ ...value });\n return `[Function ${value.name || '<anonymous>'}${properties === '{}' ? '' : ` ${properties}`}]`;\n }\n\n if (typeof value === 'symbol') {\n return value.toString();\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 JSON.stringify(value);\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"initBrowserEnvironment.d.ts","sourceRoot":"","sources":["../../src/worker/initBrowserEnvironment.js"],"names":[],"mappings":"AAQA;;GAEG;AACH,wDAsEC"}
1
+ {"version":3,"file":"initBrowserEnvironment.d.ts","sourceRoot":"","sources":["../../src/worker/initBrowserEnvironment.js"],"names":[],"mappings":"AAQA;;GAEG;AACH,wDA6EC"}
@@ -12,7 +12,8 @@ export async function initBrowserEnvironment() {
12
12
  global.performance ??= /** @type {*} */ (performance);
13
13
  global.TextEncoder ??= util.TextEncoder;
14
14
  global.TextDecoder ??= /** @type {*} */ (util.TextDecoder);
15
- (await import('jsdom-global')).default();
15
+ const url = 'http://localhost';
16
+ (await import('jsdom-global')).default(undefined, { url });
16
17
  await import('regenerator-runtime');
17
18
  // Ensure assigning to and reading from `window.foo` globals works as expected by copying all the
18
19
  // properties from the jsdom `window` to node's `global`, then assigning `global` to `window`.
@@ -33,6 +34,7 @@ export async function initBrowserEnvironment() {
33
34
  global.btoa = (str) => Buffer.from(str, 'binary').toString('base64');
34
35
  global.atob = (str) => Buffer.from(str, 'base64').toString('binary');
35
36
  // Simulate WebSocket existence. (Needed for isomorphic-ws)
37
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
36
38
  global.WebSocket = window.WebSocket = /** @type {*} */ (class WebSocket {
37
39
  });
38
40
  // Fake MessageChannel so scheduler won't hang the process by opening a channel.
@@ -56,7 +58,7 @@ export async function initBrowserEnvironment() {
56
58
  measureText: () => ({}),
57
59
  });
58
60
  }
59
- return createElement.apply(window.document, [tagName, options]);
61
+ return createElement(tagName, options);
60
62
  };
61
63
  // eslint-disable-next-line etc/no-deprecated
62
64
  global.document.createElement =
@@ -68,5 +70,9 @@ export async function initBrowserEnvironment() {
68
70
  process.env.DEBUG_COLORS = '0';
69
71
  // Some packages like readable-stream@2.3.7 read process.browser to avoid node code
70
72
  /** @type {*} */ (process).browser = true;
73
+ // Add a script tag so that webpack automatic publicPath detection won't throw
74
+ const scriptTag = createElement('script');
75
+ scriptTag.src = `${url}/fake.js`;
76
+ document.body.appendChild(scriptTag);
71
77
  }
72
78
  //# sourceMappingURL=initBrowserEnvironment.js.map
@@ -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,WAA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AO,EAAE,OAAO,CAAC,CAAC,CAAC;IAClE,CAAC,CAAC;IACF,6CAA6C;IAC7C,MAAM,CAAC,QAAQ,CAAC,aAAa;QAC3B,gBAAgB,CAAC,CAAC,MAAM,CAAC,CAAC,aAAa;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;AAC5C,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 (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 = (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 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.apply(window.document, [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"]}
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,KA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gBACvB,UAAU,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAE,CAAC,EAAE,CAAC;gBAC1C,WAAW,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC;aACxB,CAAC,CAAC;QACL,CAAC;QAED,OAAO,aAAa,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IACzC,CAAC,CAAC;IACF,6CAA6C;IAC7C,MAAM,CAAC,QAAQ,CAAC,aAAa;QAC3B,gBAAgB,CAAC,CAAC,MAAM,CAAC,CAAC,aAAa;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 window.requestAnimationFrame = window.setTimeout;\n window.cancelAnimationFrame = window.clearTimeout;\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"]}
@@ -1 +1 @@
1
- {"version":3,"file":"writeESMStubs.d.ts","sourceRoot":"","sources":["../src/writeESMStubs.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AAC5E,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AAE1E;;;GAGG;AACH,wBAAsB,aAAa,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAsC/F"}
1
+ {"version":3,"file":"writeESMStubs.d.ts","sourceRoot":"","sources":["../src/writeESMStubs.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AAC5E,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AAE1E;;;GAGG;AACH,wBAAsB,aAAa,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAwC/F"}
@@ -25,6 +25,7 @@ export async function writeESMStubs(options) {
25
25
  result.newEntries[safeEntryKey] = path.join(inputPath, entryPath);
26
26
  continue;
27
27
  }
28
+ console.debug(`Generating ESM stub for ${filePath} at ${stubPath}`);
28
29
  let stubContent = '';
29
30
  if (path.extname(entryPath).toLowerCase() === '.json') {
30
31
  stubContent = await generateESMStubFromJSON({ filePath });
@@ -1 +1 @@
1
- {"version":3,"file":"writeESMStubs.js","sourceRoot":"","sources":["../src/writeESMStubs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,mCAAmC,CAAC;AAC1D,OAAO,EA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,EAAE,CAAC,CAAC;YAC5D,CAAC;iBAAM,CAAC;gBACN,WAAW,GAAG,sBAAsB,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC,CAAC;YAC/D,CAAC;YAED,+BAA+B;YAC/B,MAAM,SAAS,CAAC,QAAQ,EAAE,WAAW,EAAE,OAAO,CAAC,CAAC;YAEhD,MAAM,CAAC,UAAU,CAAC,YAAY,CAAC,GAAG,QAAQ,CAAC;QAC7C,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,MAAM,aAAa,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;YACtD,MAAM,CAAC,UAAU,CAAC,YAAY,CAAC,GAAG,aAAa,CAAC;YAChD,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,EAAE,QAAQ,EAAE,YAAY,EAAE,aAAa,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;QACxF,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,SAAS,wBAAwB,CAAC,YAAoB;IACpD,OAAO,YAAY,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;AAC3C,CAAC","sourcesContent":["import { slash } from '@ms-cloudpack/path-string-parsing';\nimport { writeFile } from 'fs/promises';\nimport path from 'path';\nimport { generateESMStubFromCJS } from './generateESMStubFromCJS.js';\nimport { generateESMStubFromJSON } from './generateESMStubFromJSON.js';\nimport { getStubPath } from './getStubPath.js';\nimport { processError } from './processError.js';\nimport type { WriteESMStubsOptions } from './types/WriteESMStubsOptions.js';\nimport type { WriteESMStubsResult } from './types/WriteESMStubsResult.js';\n\n/**\n * Generates a set of ESM stubs for given entries and writes it to disk.\n * If any files doesn't need a stub, the returned entry will use the original path.\n */\nexport async function writeESMStubs(options: WriteESMStubsOptions): Promise<WriteESMStubsResult> {\n const { inputPath, entries, forceCJS } = options;\n const result: WriteESMStubsResult = {\n newEntries: {},\n errors: [],\n };\n\n for (const [entryKey, entryPath] of Object.entries(entries)) {\n const filePath = slash(path.join(inputPath, entryPath));\n const safeEntryKey = stripLeadingRelativePath(entryKey);\n\n try {\n const stubPath = await getStubPath({ inputPath, entryPath, forceCJS });\n if (!stubPath) {\n // Stub not needed\n result.newEntries[safeEntryKey] = path.join(inputPath, entryPath);\n continue;\n }\n\n let stubContent: string = '';\n if (path.extname(entryPath).toLowerCase() === '.json') {\n stubContent = await generateESMStubFromJSON({ filePath });\n } else {\n stubContent = generateESMStubFromCJS({ filePath, stubPath });\n }\n\n // Attempt to write it to disk.\n await writeFile(stubPath, stubContent, 'utf-8');\n\n result.newEntries[safeEntryKey] = stubPath;\n } catch (e) {\n const entryFullPath = path.join(inputPath, entryPath);\n result.newEntries[safeEntryKey] = entryFullPath;\n result.errors.push(processError({ entryKey: safeEntryKey, entryFullPath, error: e }));\n }\n }\n\n return result;\n}\n\nfunction stripLeadingRelativePath(relativePath: string) {\n return relativePath.replace(/^\\.\\//, '');\n}\n"]}
1
+ {"version":3,"file":"writeESMStubs.js","sourceRoot":"","sources":["../src/writeESMStubs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,mCAAmC,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AACvE,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAIjD;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,OAA6B;IAC/D,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC;IACjD,MAAM,MAAM,GAAwB;QAClC,UA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AAS,EAAE,SAAS,CAAC,CAAC;YACtD,MAAM,CAAC,UAAU,CAAC,YAAY,CAAC,GAAG,aAAa,CAAC;YAChD,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,EAAE,QAAQ,EAAE,YAAY,EAAE,aAAa,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;QACxF,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,SAAS,wBAAwB,CAAC,YAAoB;IACpD,OAAO,YAAY,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;AAC3C,CAAC","sourcesContent":["import { slash } from '@ms-cloudpack/path-string-parsing';\nimport { writeFile } from 'fs/promises';\nimport path from 'path';\nimport { generateESMStubFromCJS } from './generateESMStubFromCJS.js';\nimport { generateESMStubFromJSON } from './generateESMStubFromJSON.js';\nimport { getStubPath } from './getStubPath.js';\nimport { processError } from './processError.js';\nimport type { WriteESMStubsOptions } from './types/WriteESMStubsOptions.js';\nimport type { WriteESMStubsResult } from './types/WriteESMStubsResult.js';\n\n/**\n * Generates a set of ESM stubs for given entries and writes it to disk.\n * If any files doesn't need a stub, the returned entry will use the original path.\n */\nexport async function writeESMStubs(options: WriteESMStubsOptions): Promise<WriteESMStubsResult> {\n const { inputPath, entries, forceCJS } = options;\n const result: WriteESMStubsResult = {\n newEntries: {},\n errors: [],\n };\n\n for (const [entryKey, entryPath] of Object.entries(entries)) {\n const filePath = slash(path.join(inputPath, entryPath));\n const safeEntryKey = stripLeadingRelativePath(entryKey);\n\n try {\n const stubPath = await getStubPath({ inputPath, entryPath, forceCJS });\n if (!stubPath) {\n // Stub not needed\n result.newEntries[safeEntryKey] = path.join(inputPath, entryPath);\n continue;\n }\n\n console.debug(`Generating ESM stub for ${filePath} at ${stubPath}`);\n\n let stubContent: string = '';\n if (path.extname(entryPath).toLowerCase() === '.json') {\n stubContent = await generateESMStubFromJSON({ filePath });\n } else {\n stubContent = generateESMStubFromCJS({ filePath, stubPath });\n }\n\n // Attempt to write it to disk.\n await writeFile(stubPath, stubContent, 'utf-8');\n\n result.newEntries[safeEntryKey] = stubPath;\n } catch (e) {\n const entryFullPath = path.join(inputPath, entryPath);\n result.newEntries[safeEntryKey] = entryFullPath;\n result.errors.push(processError({ entryKey: safeEntryKey, entryFullPath, error: e }));\n }\n }\n\n return result;\n}\n\nfunction stripLeadingRelativePath(relativePath: string) {\n return relativePath.replace(/^\\.\\//, '');\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ms-cloudpack/esm-stub-utilities",
3
- "version": "0.10.13",
3
+ "version": "0.11.0",
4
4
  "description": "Generates ESM stubs for CommonJS entry files.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -19,19 +19,19 @@
19
19
  }
20
20
  },
21
21
  "dependencies": {
22
- "@ms-cloudpack/bundler-types": "^0.25.2",
22
+ "@ms-cloudpack/common-types": "^0.1.1",
23
23
  "@ms-cloudpack/json-utilities": "^0.1.4",
24
- "@ms-cloudpack/package-utilities": "^7.0.1",
24
+ "@ms-cloudpack/package-utilities": "^7.1.0",
25
25
  "@ms-cloudpack/path-string-parsing": "^1.2.1",
26
- "@ms-cloudpack/worker-pool": "^0.1.1",
26
+ "@ms-cloudpack/worker-pool": "^0.1.2",
27
27
  "jsdom": "^22.0.0",
28
28
  "jsdom-global": "^3.0.2",
29
29
  "regenerator-runtime": "^0.14.1"
30
30
  },
31
31
  "devDependencies": {
32
- "@ms-cloudpack/eslint-plugin-internal": "*",
33
- "@ms-cloudpack/scripts": "*",
34
- "@ms-cloudpack/test-utilities": "*",
32
+ "@ms-cloudpack/eslint-plugin-internal": "^0.0.1",
33
+ "@ms-cloudpack/scripts": "^0.0.1",
34
+ "@ms-cloudpack/test-utilities": "^0.5.0",
35
35
  "@types/jsdom": "^21.1.1",
36
36
  "@types/regenerator-runtime": "^0.13.1"
37
37
  },