@ms-cloudpack/package-utilities 13.2.4 → 13.2.5

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 +1 @@
1
- {"version":3,"file":"detectModuleType.d.ts","sourceRoot":"","sources":["../src/detectModuleType.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAK7D,iCAAiC;AACjC,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS,CA+GjF;AAED;;;GAGG;AACH,wBAAsB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,CAmBxF"}
1
+ {"version":3,"file":"detectModuleType.d.ts","sourceRoot":"","sources":["../src/detectModuleType.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAE7D,iCAAiC;AACjC,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS,CA+GjF;AAED;;;GAGG;AACH,wBAAsB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,CAmBxF"}
@@ -2,9 +2,7 @@ import fsPromises from 'fs/promises';
2
2
  import { parse } from 'acorn';
3
3
  import { simple as simpleWalk } from 'acorn-walk';
4
4
  import path from 'path';
5
- import { javascriptExtensions, typescriptExtensions } from '@ms-cloudpack/path-utilities';
6
- const cjsExtensions = [...javascriptExtensions, ...typescriptExtensions].filter((ext) => ext.startsWith('.c'));
7
- const esmExtensions = [...javascriptExtensions, ...typescriptExtensions].filter((ext) => ext.startsWith('.m'));
5
+ import { esmSourceRegex, cjsSourceRegex, typescriptRegex } from '@ms-cloudpack/path-utilities';
8
6
  /** Exported for testing only. */
9
7
  export function detectModuleTypeFromSource(source) {
10
8
  let ast;
@@ -115,11 +113,11 @@ export function detectModuleTypeFromSource(source) {
115
113
  export async function detectModuleType(filePath) {
116
114
  // Check for explicit cjs or esm extensions.
117
115
  const fileExt = path.extname(filePath);
118
- if (cjsExtensions.includes(fileExt)) {
116
+ if (cjsSourceRegex.test(fileExt)) {
119
117
  return 'cjs';
120
118
  }
121
119
  // For esm extensions or any TS files which aren't explicitly cjs, return esm immediately.
122
- if (esmExtensions.includes(fileExt) || typescriptExtensions.includes(fileExt)) {
120
+ if (esmSourceRegex.test(fileExt) || typescriptRegex.test(fileExt)) {
123
121
  return 'esm';
124
122
  }
125
123
  let source;
@@ -1 +1 @@
1
- {"version":3,"file":"detectModuleType.js","sourceRoot":"","sources":["../src/detectModuleType.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,aAAa,CAAC;AAUrC,OAAO,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AAC9B,OAAO,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,YAAY,CAAC;AAClD,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AAG1F,MAAM,aAAa,GAAG,CAAC,GAAG,oBAAoB,EAAE,GAAG,oBAAoB,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC;AAC/G,MAAM,aAAa,GAAG,CAAC,GAAG,oBAAoB,EAAE,GAAG,oBAAoB,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC;AAE/G,iCAAiC;AACjC,MAAM,UAAU,0BAA0B,CAAC,MAAc;IACvD,IAAI,GAAY,CAAC;IAEjB,IAAI,CAAC;QACH,GAAG,GAAG,KAAK,CAAC,MAAM,EAAE;YAClB,WAAW,EAAE,QAAQ;YACrB,UAAU,EAAE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,KAAK,sBAAsB,CAAC;AAC9C,CAAC;AAED;;GAEG;AACH,SAAS,kBAAkB,CAAC,IAAU;IACpC,OAAO,IAAI,CAAC,IAAI,KAAK,kBAAkB,CAAC;AAC1C,CAAC;AAED;;GAEG;AACH,SAAS,YAAY,CAAC,IAAU;IAC9B,OAAO,IAAI,CAAC,IAAI,KAAK,YAAY,CAAC;AACpC,CAAC;AAED;;GAEG;AACH,SAAS,iBAAiB,CAAC,IAAU;IACnC,OAAO,IAAI,CAAC,IAAI,KAAK,iBAAiB,CAAC;AACzC,CAAC","sourcesContent":["import fsPromises from 'fs/promises';\nimport type {\n AssignmentExpression,\n CallExpression,\n Identifier,\n MemberExpression,\n Node,\n Program,\n UnaryExpression,\n} from 'acorn';\nimport { parse } from 'acorn';\nimport { simple as simpleWalk } from 'acorn-walk';\nimport path from 'path';\nimport { javascriptExtensions, typescriptExtensions } from '@ms-cloudpack/path-utilities';\nimport type { ModuleType } from '@ms-cloudpack/common-types';\n\nconst cjsExtensions = [...javascriptExtensions, ...typescriptExtensions].filter((ext) => ext.startsWith('.c'));\nconst esmExtensions = [...javascriptExtensions, ...typescriptExtensions].filter((ext) => ext.startsWith('.m'));\n\n/** Exported for testing only. */\nexport function detectModuleTypeFromSource(source: string): ModuleType | undefined {\n let ast: Program;\n\n try {\n ast = parse(source, {\n ecmaVersion: 'latest',\n sourceType: 'module', // Try to parse as a module first.\n });\n } catch {\n // If the parse fails, try again as a script.\n try {\n ast = parse(source, {\n ecmaVersion: 'latest',\n sourceType: 'script', // Parse as a script for CommonJS.\n });\n } catch {\n // If parsing fails again, the code is not valid JavaScript or too complex for a simple parse.\n return undefined;\n }\n }\n\n // Basic check for AMD-style modules.\n const firstNode = ast.body[0];\n if (\n firstNode &&\n firstNode.type === 'ExpressionStatement' &&\n firstNode.expression.type === 'CallExpression' &&\n firstNode.expression.callee.type === 'Identifier' &&\n firstNode.expression.callee.name === 'define'\n ) {\n return 'amd';\n }\n\n let isCJS = false;\n let isESM = false;\n\n const returnESM = (): never => {\n isESM = true;\n throw new Error('Found moduleType.');\n };\n\n const returnCJS = (): void => {\n isCJS = true;\n // Note, we do not throw for CJS and instead parse the full file. Sometimes ESM output can still have checks\n // for CommonJS, and short circuiting too soon might miss ESM syntax.\n };\n\n try {\n simpleWalk(ast, {\n // ESM checks\n ImportDeclaration: returnESM,\n ExportNamedDeclaration: returnESM,\n ExportAllDeclaration: returnESM,\n ExportDefaultDeclaration: returnESM,\n\n // CommonJS checks\n CallExpression(node: Node) {\n if (isCallExpression(node) && node.callee.type === 'Identifier' && node.callee.name === 'require') {\n returnCJS();\n }\n },\n Identifier(node: Node) {\n if (isIdentifier(node) && node.name === 'exports') {\n returnCJS();\n }\n },\n UnaryExpression(node: Node) {\n if (isUnaryExpression(node) && node.operator === 'typeof') {\n const argument = node.argument;\n\n // Handle expressions like `typeof exports`\n if (isIdentifier(argument) && argument.name === 'exports') {\n returnCJS();\n }\n }\n },\n AssignmentExpression(node: Node) {\n if (isAssignmentExpression(node)) {\n const left = node.left;\n // Handle expressions like `module.exports = ...`\n if (isMemberExpression(left)) {\n if (\n 'object' in left &&\n left.object.type === 'Identifier' &&\n left.object.name === 'module' &&\n isIdentifier(left.property) &&\n left.property.name === 'exports'\n ) {\n returnCJS();\n }\n // Handle expressions like `exports.someProperty = ...`\n else if ('object' in left && left.object.type === 'Identifier' && left.object.name === 'exports') {\n returnCJS();\n }\n }\n }\n },\n });\n } catch {\n /* no-op */\n }\n\n if (isESM) {\n // Note: While it's possible for a file to include both styles, we'll prefer ESM if we find it.\n return 'esm';\n } else if (isCJS) {\n return 'cjs';\n }\n\n // We didn't find either.\n return undefined;\n}\n\n/**\n * Determines the module type of the given file (undefined means we can't determine).\n * This will use the extension if it's clear, or if not, it will parse the file.\n */\nexport async function detectModuleType(filePath: string): Promise<ModuleType | undefined> {\n // Check for explicit cjs or esm extensions.\n const fileExt = path.extname(filePath);\n if (cjsExtensions.includes(fileExt)) {\n return 'cjs';\n }\n // For esm extensions or any TS files which aren't explicitly cjs, return esm immediately.\n if (esmExtensions.includes(fileExt) || typescriptExtensions.includes(fileExt)) {\n return 'esm';\n }\n\n let source: string;\n try {\n source = (await fsPromises.readFile(filePath, 'utf8')).toString();\n } catch {\n return undefined;\n }\n\n return detectModuleTypeFromSource(source);\n}\n\n/**\n * Type guard for CallExpression.\n */\nfunction isCallExpression(node: Node): node is CallExpression {\n return node.type === 'CallExpression';\n}\n\n/**\n * Type guard for AssignmentExpression.\n */\nfunction isAssignmentExpression(node: Node): node is AssignmentExpression {\n return node.type === 'AssignmentExpression';\n}\n\n/**\n * Type guard for MemberExpression.\n */\nfunction isMemberExpression(node: Node): node is MemberExpression {\n return node.type === 'MemberExpression';\n}\n\n/**\n * Type guard for Identifier.\n */\nfunction isIdentifier(node: Node): node is Identifier {\n return node.type === 'Identifier';\n}\n\n/**\n * Type guard for UnaryExpression.\n */\nfunction isUnaryExpression(node: Node): node is UnaryExpression {\n return node.type === 'UnaryExpression';\n}\n"]}
1
+ {"version":3,"file":"detectModuleType.js","sourceRoot":"","sources":["../src/detectModuleType.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,aAAa,CAAC;AAUrC,OAAO,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AAC9B,OAAO,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,YAAY,CAAC;AAClD,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAG/F,iCAAiC;AACjC,MAAM,UAAU,0BAA0B,CAAC,MAAc;IACvD,IAAI,GAAY,CAAC;IAEjB,IAAI,CAAC;QACH,GAAG,GAAG,KAAK,CAAC,MAAM,EAAE;YAClB,WAAW,EAAE,QAAQ;YACrB,UAAU,EAAE,QAAQ,EAAE,kCAAkC;SACzD,CAAC,CAAC;IACL,CAAC;IAAC,MAAM,CAAC;QACP,6CAA6C;QAC7C,IAAI,CAAC;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AAK,kBAAkB,CAAC;AAC1C,CAAC;AAED;;GAEG;AACH,SAAS,YAAY,CAAC,IAAU;IAC9B,OAAO,IAAI,CAAC,IAAI,KAAK,YAAY,CAAC;AACpC,CAAC;AAED;;GAEG;AACH,SAAS,iBAAiB,CAAC,IAAU;IACnC,OAAO,IAAI,CAAC,IAAI,KAAK,iBAAiB,CAAC;AACzC,CAAC","sourcesContent":["import fsPromises from 'fs/promises';\nimport type {\n AssignmentExpression,\n CallExpression,\n Identifier,\n MemberExpression,\n Node,\n Program,\n UnaryExpression,\n} from 'acorn';\nimport { parse } from 'acorn';\nimport { simple as simpleWalk } from 'acorn-walk';\nimport path from 'path';\nimport { esmSourceRegex, cjsSourceRegex, typescriptRegex } from '@ms-cloudpack/path-utilities';\nimport type { ModuleType } from '@ms-cloudpack/common-types';\n\n/** Exported for testing only. */\nexport function detectModuleTypeFromSource(source: string): ModuleType | undefined {\n let ast: Program;\n\n try {\n ast = parse(source, {\n ecmaVersion: 'latest',\n sourceType: 'module', // Try to parse as a module first.\n });\n } catch {\n // If the parse fails, try again as a script.\n try {\n ast = parse(source, {\n ecmaVersion: 'latest',\n sourceType: 'script', // Parse as a script for CommonJS.\n });\n } catch {\n // If parsing fails again, the code is not valid JavaScript or too complex for a simple parse.\n return undefined;\n }\n }\n\n // Basic check for AMD-style modules.\n const firstNode = ast.body[0];\n if (\n firstNode &&\n firstNode.type === 'ExpressionStatement' &&\n firstNode.expression.type === 'CallExpression' &&\n firstNode.expression.callee.type === 'Identifier' &&\n firstNode.expression.callee.name === 'define'\n ) {\n return 'amd';\n }\n\n let isCJS = false;\n let isESM = false;\n\n const returnESM = (): never => {\n isESM = true;\n throw new Error('Found moduleType.');\n };\n\n const returnCJS = (): void => {\n isCJS = true;\n // Note, we do not throw for CJS and instead parse the full file. Sometimes ESM output can still have checks\n // for CommonJS, and short circuiting too soon might miss ESM syntax.\n };\n\n try {\n simpleWalk(ast, {\n // ESM checks\n ImportDeclaration: returnESM,\n ExportNamedDeclaration: returnESM,\n ExportAllDeclaration: returnESM,\n ExportDefaultDeclaration: returnESM,\n\n // CommonJS checks\n CallExpression(node: Node) {\n if (isCallExpression(node) && node.callee.type === 'Identifier' && node.callee.name === 'require') {\n returnCJS();\n }\n },\n Identifier(node: Node) {\n if (isIdentifier(node) && node.name === 'exports') {\n returnCJS();\n }\n },\n UnaryExpression(node: Node) {\n if (isUnaryExpression(node) && node.operator === 'typeof') {\n const argument = node.argument;\n\n // Handle expressions like `typeof exports`\n if (isIdentifier(argument) && argument.name === 'exports') {\n returnCJS();\n }\n }\n },\n AssignmentExpression(node: Node) {\n if (isAssignmentExpression(node)) {\n const left = node.left;\n // Handle expressions like `module.exports = ...`\n if (isMemberExpression(left)) {\n if (\n 'object' in left &&\n left.object.type === 'Identifier' &&\n left.object.name === 'module' &&\n isIdentifier(left.property) &&\n left.property.name === 'exports'\n ) {\n returnCJS();\n }\n // Handle expressions like `exports.someProperty = ...`\n else if ('object' in left && left.object.type === 'Identifier' && left.object.name === 'exports') {\n returnCJS();\n }\n }\n }\n },\n });\n } catch {\n /* no-op */\n }\n\n if (isESM) {\n // Note: While it's possible for a file to include both styles, we'll prefer ESM if we find it.\n return 'esm';\n } else if (isCJS) {\n return 'cjs';\n }\n\n // We didn't find either.\n return undefined;\n}\n\n/**\n * Determines the module type of the given file (undefined means we can't determine).\n * This will use the extension if it's clear, or if not, it will parse the file.\n */\nexport async function detectModuleType(filePath: string): Promise<ModuleType | undefined> {\n // Check for explicit cjs or esm extensions.\n const fileExt = path.extname(filePath);\n if (cjsSourceRegex.test(fileExt)) {\n return 'cjs';\n }\n // For esm extensions or any TS files which aren't explicitly cjs, return esm immediately.\n if (esmSourceRegex.test(fileExt) || typescriptRegex.test(fileExt)) {\n return 'esm';\n }\n\n let source: string;\n try {\n source = (await fsPromises.readFile(filePath, 'utf8')).toString();\n } catch {\n return undefined;\n }\n\n return detectModuleTypeFromSource(source);\n}\n\n/**\n * Type guard for CallExpression.\n */\nfunction isCallExpression(node: Node): node is CallExpression {\n return node.type === 'CallExpression';\n}\n\n/**\n * Type guard for AssignmentExpression.\n */\nfunction isAssignmentExpression(node: Node): node is AssignmentExpression {\n return node.type === 'AssignmentExpression';\n}\n\n/**\n * Type guard for MemberExpression.\n */\nfunction isMemberExpression(node: Node): node is MemberExpression {\n return node.type === 'MemberExpression';\n}\n\n/**\n * Type guard for Identifier.\n */\nfunction isIdentifier(node: Node): node is Identifier {\n return node.type === 'Identifier';\n}\n\n/**\n * Type guard for UnaryExpression.\n */\nfunction isUnaryExpression(node: Node): node is UnaryExpression {\n return node.type === 'UnaryExpression';\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"findFileInPackage.d.ts","sourceRoot":"","sources":["../../src/findFileInPackage/findFileInPackage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,uBAAuB,EAAE,MAAM,4BAA4B,CAAC;AAgB3F,MAAM,MAAM,wBAAwB,GAAG;IACrC,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,oBAAoB,EAAE,OAAO,CAAC;CAC/B,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG;IACpC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF;;;;;;;;;GASG;AACH,wBAAsB,iBAAiB,CACrC,OAAO,EAAE,wBAAwB,EACjC,OAAO,EAAE;IAAE,QAAQ,EAAE,uBAAuB,CAAC;IAAC,MAAM,EAAE,IAAI,CAAC,eAAe,EAAE,UAAU,CAAC,CAAA;CAAE,GACxF,OAAO,CAAC,uBAAuB,CAAC,CAgGlC"}
1
+ {"version":3,"file":"findFileInPackage.d.ts","sourceRoot":"","sources":["../../src/findFileInPackage/findFileInPackage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,uBAAuB,EAAE,MAAM,4BAA4B,CAAC;AAe3F,MAAM,MAAM,wBAAwB,GAAG;IACrC,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,oBAAoB,EAAE,OAAO,CAAC;CAC/B,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG;IACpC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF;;;;;;;;;GASG;AACH,wBAAsB,iBAAiB,CACrC,OAAO,EAAE,wBAAwB,EACjC,OAAO,EAAE;IAAE,QAAQ,EAAE,uBAAuB,CAAC;IAAC,MAAM,EAAE,IAAI,CAAC,eAAe,EAAE,UAAU,CAAC,CAAA;CAAE,GACxF,OAAO,CAAC,uBAAuB,CAAC,CA2FlC"}
@@ -1,11 +1,9 @@
1
1
  import { normalizeRelativePath, slash } from '@ms-cloudpack/path-string-parsing';
2
- import { intermediateToSourcePath, isExternalPackage, isFileSync, sourceToIntermediatePath, } from '@ms-cloudpack/path-utilities';
2
+ import { intermediateToSourcePath, isExternalPackage, isFileSync, plainJsRegex, sourceToIntermediatePath, transpiledSourceRegex, } from '@ms-cloudpack/path-utilities';
3
3
  import path from 'path';
4
4
  import { flattenExportsMap } from '../exportsMap/flattenExportsMap.js';
5
5
  import { getCandidates } from './getCandidates.js';
6
6
  import { getExportsMap } from '../exportsMap/getExportsMap.js';
7
- const sourceExtensions = ['.ts', '.tsx', '.cts', '.mts', '.jsx'];
8
- const javascriptExtensions = ['.js', '.mjs', '.cjs'];
9
7
  /**
10
8
  * Given a requested partial filePath, resolves the relative intermediate path if the file exists, with special
11
9
  * consideration for internal packages, which may not have intermediate files but only source files. Paths returned
@@ -71,21 +69,17 @@ export async function findFileInPackage(options, context) {
71
69
  }
72
70
  }
73
71
  // If the resolved file is a typescript file in an internal package, try to resolve the intermediate.
74
- if (filePath && sourceExtensions.includes(path.extname(filePath))) {
72
+ if (filePath && transpiledSourceRegex.test(filePath)) {
75
73
  sourcePath = filePath;
76
74
  filePath = isInternal ? sourceToIntermediatePath(filePath) : undefined;
77
75
  }
78
76
  // If we haven't resolved a sourcePath, try to resolve it from the intermediate.
79
- if (isInternal && filePath && !sourcePath) {
80
- const ext = path.extname(filePath);
81
- const isJavaScriptExt = javascriptExtensions.includes(ext);
82
- if (isJavaScriptExt) {
83
- // Not a TS file, but a JS file. Try to find the source.
84
- sourcePath = intermediateToSourcePath(filePath, packagePath);
85
- // If we couldn't find a TS file, clear sourcePath.
86
- if (sourcePath === filePath) {
87
- sourcePath = undefined;
88
- }
77
+ if (isInternal && filePath && !sourcePath && plainJsRegex.test(filePath)) {
78
+ // Not a TS file, but a JS file. Try to find the source.
79
+ sourcePath = intermediateToSourcePath(filePath, packagePath);
80
+ // If we couldn't find a TS file, clear sourcePath.
81
+ if (sourcePath === filePath) {
82
+ sourcePath = undefined;
89
83
  }
90
84
  }
91
85
  if (filePath) {
@@ -1 +1 @@
1
- {"version":3,"file":"findFileInPackage.js","sourceRoot":"","sources":["../../src/findFileInPackage/findFileInPackage.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,KAAK,EAAE,MAAM,mCAAmC,CAAC;AACjF,OAAO,EACL,wBAAwB,EACxB,iBAAiB,EACjB,UAAU,EACV,wBAAwB,GACzB,MAAM,8BAA8B,CAAC;AACtC,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,iBAAiB,EAAE,MAAM,oCAAoC,CAAC;AACvE,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAE/D,MAAM,gBAAgB,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AACjE,MAAM,oBAAoB,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AAarD;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,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H,CAAC;IAED,qGAAqG;IACrG,IAAI,QAAQ,IAAI,gBAAgB,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC;QAClE,UAAU,GAAG,QAAQ,CAAC;QACtB,QAAQ,GAAG,UAAU,CAAC,CAAC,CAAC,wBAAwB,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IACzE,CAAC;IAED,gFAAgF;IAChF,IAAI,UAAU,IAAI,QAAQ,IAAI,CAAC,UAAU,EAAE,CAAC;QAC1C,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QACnC,MAAM,eAAe,GAAG,oBAAoB,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;QAE3D,IAAI,eAAe,EAAE,CAAC;YACpB,wDAAwD;YACxD,UAAU,GAAG,wBAAwB,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC;YAE7D,mDAAmD;YACnD,IAAI,UAAU,KAAK,QAAQ,EAAE,CAAC;gBAC5B,UAAU,GAAG,SAAS,CAAC;YACzB,CAAC;QACH,CAAC;IACH,CAAC;IAED,IAAI,QAAQ,EAAE,CAAC;QACb,MAAM,CAAC,QAAQ,GAAG,qBAAqB,CAAC,QAAQ,CAAC,CAAC;IACpD,CAAC;IAED,IAAI,UAAU,EAAE,CAAC;QACf,MAAM,CAAC,UAAU,GAAG,qBAAqB,CAAC,UAAU,CAAC,CAAC;IACxD,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import type { CloudpackConfig, PackageDefinitionsCache } from '@ms-cloudpack/common-types';\nimport { normalizeRelativePath, slash } from '@ms-cloudpack/path-string-parsing';\nimport {\n intermediateToSourcePath,\n isExternalPackage,\n isFileSync,\n sourceToIntermediatePath,\n} from '@ms-cloudpack/path-utilities';\nimport path from 'path';\nimport { flattenExportsMap } from '../exportsMap/flattenExportsMap.js';\nimport { getCandidates } from './getCandidates.js';\nimport { getExportsMap } from '../exportsMap/getExportsMap.js';\n\nconst sourceExtensions = ['.ts', '.tsx', '.cts', '.mts', '.jsx'];\nconst javascriptExtensions = ['.js', '.mjs', '.cjs'];\n\nexport type FindFileInPackageOptions = {\n packagePath: string;\n filePath: string;\n resolveWebExtensions: boolean;\n};\n\nexport type FindFileInPackageResult = {\n filePath?: string;\n sourcePath?: string;\n};\n\n/**\n * Given a requested partial filePath, resolves the relative intermediate path if the file exists, with special\n * consideration for internal packages, which may not have intermediate files but only source files. Paths returned\n * are always relative and start with `./`.\n *\n * This helper is used in deriving if the given package.json entries are actual validate candidates when constructing an\n * exports map from existing metadata. For example, a package.json may list `main` as `lib/index.js`. If this file\n * exists, or in internal packages, if `src/index.tsx` exists, then this is a valid candidate. If the file does not\n * exist, then we should not include it in the exports map.\n */\nexport async function findFileInPackage(\n options: FindFileInPackageOptions,\n context: { packages: PackageDefinitionsCache; config: Pick<CloudpackConfig, 'features'> },\n): Promise<FindFileInPackageResult> {\n const { resolveWebExtensions } = options;\n const originalPath = normalizeRelativePath(options.filePath);\n const packagePath = slash(options.packagePath);\n let filePath: string | undefined;\n let sourcePath: string | undefined;\n const isInternal = !isExternalPackage(packagePath);\n const pathsToConsider = [originalPath];\n\n const originalDefinition = await context.packages.tryGet(packagePath, { disableTransforms: true });\n // If the original package.json has an exports map, we should not use main and module as hints.\n if (originalPath === '.' && originalDefinition && !originalDefinition.exports) {\n const { main, module } = originalDefinition;\n if (main) {\n pathsToConsider.unshift(main);\n }\n if (module) {\n pathsToConsider.unshift(module);\n }\n }\n\n if (originalDefinition && originalDefinition.exports) {\n // Pass in packagePath so that we can expand wildcards in the exports map.\n const expandedExportsMap = flattenExportsMap(originalDefinition.exports, { packagePath });\n if (expandedExportsMap[originalPath]) {\n // If the original path is an entry in the exports map, we should use that as a candidate.\n pathsToConsider.unshift(expandedExportsMap[originalPath]);\n }\n }\n\n for (const currentPath of pathsToConsider) {\n const candidates = await getCandidates({ filePath: currentPath, packagePath, resolveWebExtensions }, context);\n\n // Try and resolve a physical file given the candidates.\n filePath = candidates.find((candidate) => isFileSync(path.join(packagePath, candidate)));\n if (filePath) {\n break;\n }\n }\n\n const isNestedPackageDefinition =\n filePath && path.basename(filePath) === 'package.json' && path.basename(originalPath) !== 'package.json';\n const result: FindFileInPackageResult = {};\n\n if (isNestedPackageDefinition) {\n const nestedDefinitionPath = path.dirname(path.join(packagePath, filePath as string));\n const exportsMap = await getExportsMap({ packagePath: nestedDefinitionPath }, context);\n const entryPath = flattenExportsMap(exportsMap)['.'];\n\n if (entryPath) {\n return findFileInPackage(\n {\n packagePath,\n filePath: normalizeRelativePath(path.relative(packagePath, path.join(nestedDefinitionPath, entryPath))),\n resolveWebExtensions: options.resolveWebExtensions,\n },\n context,\n );\n } else {\n // If we can't find an entry, we should not include this in the exports map.\n // This avoids adding a \"./package.json\" value to a \".\" entry.\n return result;\n }\n }\n\n // If the resolved file is a typescript file in an internal package, try to resolve the intermediate.\n if (filePath && sourceExtensions.includes(path.extname(filePath))) {\n sourcePath = filePath;\n filePath = isInternal ? sourceToIntermediatePath(filePath) : undefined;\n }\n\n // If we haven't resolved a sourcePath, try to resolve it from the intermediate.\n if (isInternal && filePath && !sourcePath) {\n const ext = path.extname(filePath);\n const isJavaScriptExt = javascriptExtensions.includes(ext);\n\n if (isJavaScriptExt) {\n // Not a TS file, but a JS file. Try to find the source.\n sourcePath = intermediateToSourcePath(filePath, packagePath);\n\n // If we couldn't find a TS file, clear sourcePath.\n if (sourcePath === filePath) {\n sourcePath = undefined;\n }\n }\n }\n\n if (filePath) {\n result.filePath = normalizeRelativePath(filePath);\n }\n\n if (sourcePath) {\n result.sourcePath = normalizeRelativePath(sourcePath);\n }\n\n return result;\n}\n"]}
1
+ {"version":3,"file":"findFileInPackage.js","sourceRoot":"","sources":["../../src/findFileInPackage/findFileInPackage.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,KAAK,EAAE,MAAM,mCAAmC,CAAC;A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alizeRelativePath, slash } from '@ms-cloudpack/path-string-parsing';\nimport {\n intermediateToSourcePath,\n isExternalPackage,\n isFileSync,\n plainJsRegex,\n sourceToIntermediatePath,\n transpiledSourceRegex,\n} from '@ms-cloudpack/path-utilities';\nimport path from 'path';\nimport { flattenExportsMap } from '../exportsMap/flattenExportsMap.js';\nimport { getCandidates } from './getCandidates.js';\nimport { getExportsMap } from '../exportsMap/getExportsMap.js';\n\nexport type FindFileInPackageOptions = {\n packagePath: string;\n filePath: string;\n resolveWebExtensions: boolean;\n};\n\nexport type FindFileInPackageResult = {\n filePath?: string;\n sourcePath?: string;\n};\n\n/**\n * Given a requested partial filePath, resolves the relative intermediate path if the file exists, with special\n * consideration for internal packages, which may not have intermediate files but only source files. Paths returned\n * are always relative and start with `./`.\n *\n * This helper is used in deriving if the given package.json entries are actual validate candidates when constructing an\n * exports map from existing metadata. For example, a package.json may list `main` as `lib/index.js`. If this file\n * exists, or in internal packages, if `src/index.tsx` exists, then this is a valid candidate. If the file does not\n * exist, then we should not include it in the exports map.\n */\nexport async function findFileInPackage(\n options: FindFileInPackageOptions,\n context: { packages: PackageDefinitionsCache; config: Pick<CloudpackConfig, 'features'> },\n): Promise<FindFileInPackageResult> {\n const { resolveWebExtensions } = options;\n const originalPath = normalizeRelativePath(options.filePath);\n const packagePath = slash(options.packagePath);\n let filePath: string | undefined;\n let sourcePath: string | undefined;\n const isInternal = !isExternalPackage(packagePath);\n const pathsToConsider = [originalPath];\n\n const originalDefinition = await context.packages.tryGet(packagePath, { disableTransforms: true });\n // If the original package.json has an exports map, we should not use main and module as hints.\n if (originalPath === '.' && originalDefinition && !originalDefinition.exports) {\n const { main, module } = originalDefinition;\n if (main) {\n pathsToConsider.unshift(main);\n }\n if (module) {\n pathsToConsider.unshift(module);\n }\n }\n\n if (originalDefinition && originalDefinition.exports) {\n // Pass in packagePath so that we can expand wildcards in the exports map.\n const expandedExportsMap = flattenExportsMap(originalDefinition.exports, { packagePath });\n if (expandedExportsMap[originalPath]) {\n // If the original path is an entry in the exports map, we should use that as a candidate.\n pathsToConsider.unshift(expandedExportsMap[originalPath]);\n }\n }\n\n for (const currentPath of pathsToConsider) {\n const candidates = await getCandidates({ filePath: currentPath, packagePath, resolveWebExtensions }, context);\n\n // Try and resolve a physical file given the candidates.\n filePath = candidates.find((candidate) => isFileSync(path.join(packagePath, candidate)));\n if (filePath) {\n break;\n }\n }\n\n const isNestedPackageDefinition =\n filePath && path.basename(filePath) === 'package.json' && path.basename(originalPath) !== 'package.json';\n const result: FindFileInPackageResult = {};\n\n if (isNestedPackageDefinition) {\n const nestedDefinitionPath = path.dirname(path.join(packagePath, filePath as string));\n const exportsMap = await getExportsMap({ packagePath: nestedDefinitionPath }, context);\n const entryPath = flattenExportsMap(exportsMap)['.'];\n\n if (entryPath) {\n return findFileInPackage(\n {\n packagePath,\n filePath: normalizeRelativePath(path.relative(packagePath, path.join(nestedDefinitionPath, entryPath))),\n resolveWebExtensions: options.resolveWebExtensions,\n },\n context,\n );\n } else {\n // If we can't find an entry, we should not include this in the exports map.\n // This avoids adding a \"./package.json\" value to a \".\" entry.\n return result;\n }\n }\n\n // If the resolved file is a typescript file in an internal package, try to resolve the intermediate.\n if (filePath && transpiledSourceRegex.test(filePath)) {\n sourcePath = filePath;\n filePath = isInternal ? sourceToIntermediatePath(filePath) : undefined;\n }\n\n // If we haven't resolved a sourcePath, try to resolve it from the intermediate.\n if (isInternal && filePath && !sourcePath && plainJsRegex.test(filePath)) {\n // Not a TS file, but a JS file. Try to find the source.\n sourcePath = intermediateToSourcePath(filePath, packagePath);\n\n // If we couldn't find a TS file, clear sourcePath.\n if (sourcePath === filePath) {\n sourcePath = undefined;\n }\n }\n\n if (filePath) {\n result.filePath = normalizeRelativePath(filePath);\n }\n\n if (sourcePath) {\n result.sourcePath = normalizeRelativePath(sourcePath);\n }\n\n return result;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"getCandidates.d.ts","sourceRoot":"","sources":["../../src/findFileInPackage/getCandidates.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,4BAA4B,CAAC;AA4B1E;;;;;;GAMG;AACH,wBAAsB,aAAa,CACjC,OAAO,EAAE;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAC;IAAC,oBAAoB,EAAE,OAAO,CAAA;CAAE,EACjF,OAAO,EAAE;IAAE,QAAQ,EAAE,uBAAuB,CAAA;CAAE,GAC7C,OAAO,CAAC,MAAM,EAAE,CAAC,CA0EnB"}
1
+ {"version":3,"file":"getCandidates.d.ts","sourceRoot":"","sources":["../../src/findFileInPackage/getCandidates.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,4BAA4B,CAAC;AAiC1E;;;;;;GAMG;AACH,wBAAsB,aAAa,CACjC,OAAO,EAAE;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAC;IAAC,oBAAoB,EAAE,OAAO,CAAA;CAAE,EACjF,OAAO,EAAE;IAAE,QAAQ,EAAE,uBAAuB,CAAA;CAAE,GAC7C,OAAO,CAAC,MAAM,EAAE,CAAC,CA0EnB"}
@@ -1,11 +1,14 @@
1
1
  import { normalizeRelativePath } from '@ms-cloudpack/path-string-parsing';
2
- import { isExternalPackage } from '@ms-cloudpack/path-utilities';
2
+ import { isExternalPackage, plainJsExtensions, webExtensions } from '@ms-cloudpack/path-utilities';
3
3
  import path from 'path';
4
4
  import { findPackageOutputPaths } from './findPackageOutputPaths.js';
5
- // Mappings to possible candidate extensions for a given input extension.
6
- const externalExtensions = ['.js', '.mjs', '.cjs'];
5
+ // TODO: not a good assumption if a package ships source
6
+ const externalExtensions = plainJsExtensions;
7
+ // TODO: missing [cm][jt]sx variants
7
8
  const internalExtensions = ['.ts', '.tsx', '.mts', '.cts', '.jsx', '.js', '.mjs', '.cjs'];
9
+ /** Mapping to possible candidate extensions for a given input extension for internal files. */
8
10
  const internalExtensionMap = {
11
+ // TODO: missing some variants
9
12
  '.ts': ['.ts', '.js'],
10
13
  '.tsx': ['.tsx', '.js'],
11
14
  '.mts': ['.mts', '.mjs', '.js'],
@@ -15,6 +18,8 @@ const internalExtensionMap = {
15
18
  '.mjs': ['.mjs', '.js'],
16
19
  '.cjs': ['.cjs', '.js'],
17
20
  };
21
+ /** Mapping to possible candidate extensions for a given input extension for external files. */
22
+ // TODO: these are not good assumptions if a package ships source files...
18
23
  const externalExtensionMap = {
19
24
  '.ts': ['.js'],
20
25
  '.tsx': ['.js'],
@@ -41,7 +46,7 @@ export async function getCandidates(options, context) {
41
46
  const candidates = [];
42
47
  const defaultExtensions = isInternal ? internalExtensions : externalExtensions;
43
48
  const defaultExtensionsWithSuffixes = resolveWebExtensions
44
- ? [...defaultExtensions.map((ext) => `.web${ext}`), ...defaultExtensions]
49
+ ? [...webExtensions, ...defaultExtensions]
45
50
  : defaultExtensions;
46
51
  const extensions = (isInternal ? internalExtensionMap : externalExtensionMap)[originalExt] || defaultExtensionsWithSuffixes;
47
52
  const pathsToAdd = [];
@@ -107,7 +112,7 @@ function expandExtensions(filePath, extensions) {
107
112
  const result = [];
108
113
  const ext = path.extname(filePath);
109
114
  if (extensions.includes(ext)) {
110
- filePath = `${filePath.slice(0, -ext.length)}`;
115
+ filePath = filePath.slice(0, -ext.length);
111
116
  }
112
117
  for (const currentExt of extensions) {
113
118
  result.push(filePath + currentExt);
@@ -1 +1 @@
1
- {"version":3,"file":"getCandidates.js","sourceRoot":"","sources":["../../src/findFileInPackage/getCandidates.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAC1E,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAErE,yEAAyE;AACzE,MAAM,kBAAkB,GAAG,CAA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ED,UAAU,CAAC,IAAI,CAAC,GAAG,gBAAgB,CAAC,WAAW,GAAG,QAAQ,EAAE,UAAU,CAAC,CAAC,CAAC;YACzE,UAAU,CAAC,IAAI,CAAC,WAAW,GAAG,eAAe,CAAC,CAAC;QACjD,CAAC;QAED,yEAAyE;QACzE,IAAI,CAAC,UAAU,IAAI,eAAe,EAAE,CAAC;YACnC,UAAU,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QAC/B,CAAC;IACH,CAAC;IAED,OAAO,UAAU,CAAC;AACpB,CAAC;AAED;;;;;;GAMG;AACH,SAAS,gBAAgB,CAAC,QAAgB,EAAE,UAAoB;IAC9D,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IAEnC,IAAI,UAAU,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QAC7B,QAAQ,GAAG,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC;IACjD,CAAC;IAED,KAAK,MAAM,UAAU,IAAI,UAAU,EAAE,CAAC;QACpC,MAAM,CAAC,IAAI,CAAC,QAAQ,GAAG,UAAU,CAAC,CAAC;IACrC,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import type { PackageDefinitionsCache } from '@ms-cloudpack/common-types';\nimport { normalizeRelativePath } from '@ms-cloudpack/path-string-parsing';\nimport { isExternalPackage } from '@ms-cloudpack/path-utilities';\nimport path from 'path';\nimport { findPackageOutputPaths } from './findPackageOutputPaths.js';\n\n// Mappings to possible candidate extensions for a given input extension.\nconst externalExtensions = ['.js', '.mjs', '.cjs'];\nconst internalExtensions = ['.ts', '.tsx', '.mts', '.cts', '.jsx', '.js', '.mjs', '.cjs'];\nconst internalExtensionMap: Record<string, string[]> = {\n '.ts': ['.ts', '.js'],\n '.tsx': ['.tsx', '.js'],\n '.mts': ['.mts', '.mjs', '.js'],\n '.cts': ['.cts', '.cjs', '.js'],\n '.jsx': ['.jsx', '.js'],\n '.js': ['.ts', '.tsx', '.mts', '.cts', '.jsx', '.js'],\n '.mjs': ['.mjs', '.js'],\n '.cjs': ['.cjs', '.js'],\n};\nconst externalExtensionMap: Record<string, string[]> = {\n '.ts': ['.js'],\n '.tsx': ['.js'],\n '.mts': ['.mjs'],\n '.cts': ['.cjs'],\n '.jsx': ['.js'],\n '.js': ['.js'],\n};\n\n/**\n * Given a packagePath and a filePath from its exports map (or main/module), build candidate paths\n * to look for the physical file in order of priority. For internal packages, we try to discover\n * source files first, and then fallback to the original file name. We also search for index files\n * and expand folder paths as well for ambiguous references. For external packages, we prioritize\n * intermediate paths.\n */\nexport async function getCandidates(\n options: { filePath: string; packagePath: string; resolveWebExtensions: boolean },\n context: { packages: PackageDefinitionsCache },\n): Promise<string[]> {\n const outputPaths = await findPackageOutputPaths(options.packagePath, context);\n const { filePath, packagePath, resolveWebExtensions } = options;\n const isBlankPath = !filePath || filePath === '.';\n const originalPath = isBlankPath ? './index' : normalizeRelativePath(filePath);\n const originalExt = path.extname(originalPath);\n const isInternal = !isExternalPackage(packagePath);\n const endsWithSlash = originalPath.endsWith('/');\n const candidates = [];\n const defaultExtensions = isInternal ? internalExtensions : externalExtensions;\n const defaultExtensionsWithSuffixes = resolveWebExtensions\n ? [...defaultExtensions.map((ext) => `.web${ext}`), ...defaultExtensions]\n : defaultExtensions;\n const extensions =\n (isInternal ? internalExtensionMap : externalExtensionMap)[originalExt] || defaultExtensionsWithSuffixes;\n\n const pathsToAdd: string[] = [];\n\n // For internal packages, we try and resolve the source file name first.\n const { esmPath, cjsPath } = outputPaths || {};\n\n if (isInternal) {\n if (cjsPath && esmPath) {\n if (originalPath.startsWith(esmPath)) {\n pathsToAdd.push(originalPath.replace(esmPath, './src/'));\n } else if (originalPath.startsWith(cjsPath)) {\n pathsToAdd.push(originalPath.replace(cjsPath, './src/'));\n }\n } else if (originalPath.startsWith('./lib/')) {\n pathsToAdd.push(originalPath.replace(/^\\.\\/lib\\//, './src/'));\n }\n }\n\n // If we have both values and the path is not already esm...\n if (esmPath && cjsPath && !originalPath.startsWith(esmPath)) {\n // We have a distinct esm output path. If the original path refers to the cjsPath,\n // refer only to the esm path.\n pathsToAdd.push(originalPath.replace(cjsPath, esmPath));\n } else {\n pathsToAdd.push(originalPath);\n }\n\n for (let currentPath of pathsToAdd) {\n const unrecognizedExt = originalExt && !extensions.includes(path.extname(currentPath));\n\n // For internal packages, we try and resolve the original file name first.\n if (isInternal && unrecognizedExt) {\n candidates.push(currentPath);\n }\n\n // If the path doesn't end with a slash, it could be a file. Add extensions.\n if (!endsWithSlash) {\n candidates.push(...expandExtensions(currentPath, extensions));\n }\n\n // For non-extension references, we might be referring to a folder, or a barrel file within a folder. Add the\n // appropriate extensions for the barrel file, and fall back to a package.json in the case of nested definitions.\n if (!originalExt && !isBlankPath) {\n // Trim trailing slash\n if (endsWithSlash) {\n currentPath = currentPath.slice(0, -1);\n }\n\n candidates.push(...expandExtensions(currentPath + '/index', extensions));\n candidates.push(currentPath + '/package.json');\n }\n\n // For external packages, we try and resolve the original file name last.\n if (!isInternal && unrecognizedExt) {\n candidates.push(currentPath);\n }\n }\n\n return candidates;\n}\n\n/**\n * Given a filepath and list of extensions, maps extensions to prepend the filepath. In the case that\n * the filepath has an extension already in the list, avoids appending the extension twice.\n *\n * For example, `filePath = './foo/bar.js'` with extensions `['.ts', '.js']` would result in:\n * `['./foo/bar.ts.js', './foo/bar.js']`\n */\nfunction expandExtensions(filePath: string, extensions: string[]): string[] {\n const result: string[] = [];\n const ext = path.extname(filePath);\n\n if (extensions.includes(ext)) {\n filePath = `${filePath.slice(0, -ext.length)}`;\n }\n\n for (const currentExt of extensions) {\n result.push(filePath + currentExt);\n }\n\n return result;\n}\n"]}
1
+ {"version":3,"file":"getCandidates.js","sourceRoot":"","sources":["../../src/findFileInPackage/getCandidates.ts"],"names":[],"mappings":"AACA,OA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E,CAAC;QAED,6GAA6G;QAC7G,iHAAiH;QACjH,IAAI,CAAC,WAAW,IAAI,CAAC,WAAW,EAAE,CAAC;YACjC,sBAAsB;YACtB,IAAI,aAAa,EAAE,CAAC;gBAClB,WAAW,GAAG,WAAW,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;YACzC,CAAC;YAED,UAAU,CAAC,IAAI,CAAC,GAAG,gBAAgB,CAAC,WAAW,GAAG,QAAQ,EAAE,UAAU,CAAC,CAAC,CAAC;YACzE,UAAU,CAAC,IAAI,CAAC,WAAW,GAAG,eAAe,CAAC,CAAC;QACjD,CAAC;QAED,yEAAyE;QACzE,IAAI,CAAC,UAAU,IAAI,eAAe,EAAE,CAAC;YACnC,UAAU,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QAC/B,CAAC;IACH,CAAC;IAED,OAAO,UAAU,CAAC;AACpB,CAAC;AAED;;;;;;GAMG;AACH,SAAS,gBAAgB,CAAC,QAAgB,EAAE,UAAoB;IAC9D,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IAEnC,IAAI,UAAU,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QAC7B,QAAQ,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAC5C,CAAC;IAED,KAAK,MAAM,UAAU,IAAI,UAAU,EAAE,CAAC;QACpC,MAAM,CAAC,IAAI,CAAC,QAAQ,GAAG,UAAU,CAAC,CAAC;IACrC,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import type { PackageDefinitionsCache } from '@ms-cloudpack/common-types';\nimport { normalizeRelativePath } from '@ms-cloudpack/path-string-parsing';\nimport { isExternalPackage, plainJsExtensions, webExtensions } from '@ms-cloudpack/path-utilities';\nimport path from 'path';\nimport { findPackageOutputPaths } from './findPackageOutputPaths.js';\n\n// TODO: not a good assumption if a package ships source\nconst externalExtensions = plainJsExtensions;\n// TODO: missing [cm][jt]sx variants\nconst internalExtensions = ['.ts', '.tsx', '.mts', '.cts', '.jsx', '.js', '.mjs', '.cjs'];\n/** Mapping to possible candidate extensions for a given input extension for internal files. */\nconst internalExtensionMap: Record<string, string[]> = {\n // TODO: missing some variants\n '.ts': ['.ts', '.js'],\n '.tsx': ['.tsx', '.js'],\n '.mts': ['.mts', '.mjs', '.js'],\n '.cts': ['.cts', '.cjs', '.js'],\n '.jsx': ['.jsx', '.js'],\n '.js': ['.ts', '.tsx', '.mts', '.cts', '.jsx', '.js'],\n '.mjs': ['.mjs', '.js'],\n '.cjs': ['.cjs', '.js'],\n};\n/** Mapping to possible candidate extensions for a given input extension for external files. */\n// TODO: these are not good assumptions if a package ships source files...\nconst externalExtensionMap: Record<string, string[]> = {\n '.ts': ['.js'],\n '.tsx': ['.js'],\n '.mts': ['.mjs'],\n '.cts': ['.cjs'],\n '.jsx': ['.js'],\n '.js': ['.js'],\n};\n\n/**\n * Given a packagePath and a filePath from its exports map (or main/module), build candidate paths\n * to look for the physical file in order of priority. For internal packages, we try to discover\n * source files first, and then fallback to the original file name. We also search for index files\n * and expand folder paths as well for ambiguous references. For external packages, we prioritize\n * intermediate paths.\n */\nexport async function getCandidates(\n options: { filePath: string; packagePath: string; resolveWebExtensions: boolean },\n context: { packages: PackageDefinitionsCache },\n): Promise<string[]> {\n const outputPaths = await findPackageOutputPaths(options.packagePath, context);\n const { filePath, packagePath, resolveWebExtensions } = options;\n const isBlankPath = !filePath || filePath === '.';\n const originalPath = isBlankPath ? './index' : normalizeRelativePath(filePath);\n const originalExt = path.extname(originalPath);\n const isInternal = !isExternalPackage(packagePath);\n const endsWithSlash = originalPath.endsWith('/');\n const candidates = [];\n const defaultExtensions = isInternal ? internalExtensions : externalExtensions;\n const defaultExtensionsWithSuffixes = resolveWebExtensions\n ? [...webExtensions, ...defaultExtensions]\n : defaultExtensions;\n const extensions =\n (isInternal ? internalExtensionMap : externalExtensionMap)[originalExt] || defaultExtensionsWithSuffixes;\n\n const pathsToAdd: string[] = [];\n\n // For internal packages, we try and resolve the source file name first.\n const { esmPath, cjsPath } = outputPaths || {};\n\n if (isInternal) {\n if (cjsPath && esmPath) {\n if (originalPath.startsWith(esmPath)) {\n pathsToAdd.push(originalPath.replace(esmPath, './src/'));\n } else if (originalPath.startsWith(cjsPath)) {\n pathsToAdd.push(originalPath.replace(cjsPath, './src/'));\n }\n } else if (originalPath.startsWith('./lib/')) {\n pathsToAdd.push(originalPath.replace(/^\\.\\/lib\\//, './src/'));\n }\n }\n\n // If we have both values and the path is not already esm...\n if (esmPath && cjsPath && !originalPath.startsWith(esmPath)) {\n // We have a distinct esm output path. If the original path refers to the cjsPath,\n // refer only to the esm path.\n pathsToAdd.push(originalPath.replace(cjsPath, esmPath));\n } else {\n pathsToAdd.push(originalPath);\n }\n\n for (let currentPath of pathsToAdd) {\n const unrecognizedExt = originalExt && !extensions.includes(path.extname(currentPath));\n\n // For internal packages, we try and resolve the original file name first.\n if (isInternal && unrecognizedExt) {\n candidates.push(currentPath);\n }\n\n // If the path doesn't end with a slash, it could be a file. Add extensions.\n if (!endsWithSlash) {\n candidates.push(...expandExtensions(currentPath, extensions));\n }\n\n // For non-extension references, we might be referring to a folder, or a barrel file within a folder. Add the\n // appropriate extensions for the barrel file, and fall back to a package.json in the case of nested definitions.\n if (!originalExt && !isBlankPath) {\n // Trim trailing slash\n if (endsWithSlash) {\n currentPath = currentPath.slice(0, -1);\n }\n\n candidates.push(...expandExtensions(currentPath + '/index', extensions));\n candidates.push(currentPath + '/package.json');\n }\n\n // For external packages, we try and resolve the original file name last.\n if (!isInternal && unrecognizedExt) {\n candidates.push(currentPath);\n }\n }\n\n return candidates;\n}\n\n/**\n * Given a filepath and list of extensions, maps extensions to prepend the filepath. In the case that\n * the filepath has an extension already in the list, avoids appending the extension twice.\n *\n * For example, `filePath = './foo/bar.js'` with extensions `['.ts', '.js']` would result in:\n * `['./foo/bar.ts.js', './foo/bar.js']`\n */\nfunction expandExtensions(filePath: string, extensions: string[]): string[] {\n const result: string[] = [];\n const ext = path.extname(filePath);\n\n if (extensions.includes(ext)) {\n filePath = filePath.slice(0, -ext.length);\n }\n\n for (const currentExt of extensions) {\n result.push(filePath + currentExt);\n }\n\n return result;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ms-cloudpack/package-utilities",
3
- "version": "13.2.4",
3
+ "version": "13.2.5",
4
4
  "description": "Utilities for resolving/parsing packages and their imports in Cloudpack",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -25,10 +25,10 @@
25
25
  "test": "cloudpack-scripts test"
26
26
  },
27
27
  "dependencies": {
28
- "@ms-cloudpack/common-types": "^0.33.0",
28
+ "@ms-cloudpack/common-types": "^0.33.1",
29
29
  "@ms-cloudpack/json-utilities": "^0.1.11",
30
30
  "@ms-cloudpack/path-string-parsing": "^1.2.7",
31
- "@ms-cloudpack/path-utilities": "^3.2.1",
31
+ "@ms-cloudpack/path-utilities": "^3.2.2",
32
32
  "@ms-cloudpack/task-reporter": "^0.17.4",
33
33
  "acorn": "^8.11.2",
34
34
  "acorn-walk": "^8.2.1",