@ms-cloudpack/package-utilities 13.0.1 → 13.1.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 +1 @@
1
- {"version":3,"file":"getCandidates.d.ts","sourceRoot":"","sources":["../../src/findFileInPackage/getCandidates.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,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,CAyEnB"}
1
+ {"version":3,"file":"getCandidates.d.ts","sourceRoot":"","sources":["../../src/findFileInPackage/getCandidates.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,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"}
@@ -60,7 +60,8 @@ export async function getCandidates(options, context) {
60
60
  pathsToAdd.push(originalPath.replace(/^\.\/lib\//, './src/'));
61
61
  }
62
62
  }
63
- if (esmPath && cjsPath) {
63
+ // If we have both values and the path is not already esm...
64
+ if (esmPath && cjsPath && !originalPath.startsWith(esmPath)) {
64
65
  // We have a distinct esm output path. If the original path refers to the cjsPath,
65
66
  // refer only to the esm path.
66
67
  pathsToAdd.push(originalPath.replace(cjsPath,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,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC,CAAC;QAChE,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,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 (esmPath && cjsPath) {\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,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,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AACnD,MAAM,kBAAkB,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AAC1F,MAAM,oBAAoB,GAA6B;IACrD,KAAK,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC;IACrB,MAAM,EAAE,CAAC,MAAM,EAAE,KAAK,CAAC;IACvB,MAAM,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC;IAC/B,MAAM,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC;IAC/B,MAAM,EAAE,CAAC,MAAM,EAAE,KAAK,CAAC;IACvB,KAAK,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC;IACrD,MAAM,EAAE,CAAC,MAAM,EAAE,KAAK,CAAC;IACvB,MAAM,EAAE,CAAC,MAAM,EAAE,KAAK,CAAC;CACxB,CAAC;AACF,MAAM,oBAAoB,GAA6B;IACrD,KAAK,EAAE,CAAC,KAAK,CAAC;IACd,MAAM,EAAE,CAAC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AAQ,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,4 +1,4 @@
1
- import type { ModuleResolutionConfig, PackageDefinitionsCache, PackageJson, ResolveMap } from '@ms-cloudpack/common-types';
1
+ import type { ModuleResolutionConfig, PackageDefinitionsCache, PackageImporterContext, PackageJson, ResolveMap } from '@ms-cloudpack/common-types';
2
2
  /**
3
3
  * Ensure that a package is in the resolve map and return the path to the package.
4
4
  */
@@ -8,6 +8,7 @@ export declare function ensureResolveMapEntry(params: {
8
8
  dependencyName: string;
9
9
  resolveMap: ResolveMap;
10
10
  appPath: string;
11
+ importerContext: PackageImporterContext | undefined;
11
12
  moduleResolutionConfig?: ModuleResolutionConfig;
12
13
  }, context: {
13
14
  packages: PackageDefinitionsCache;
@@ -1 +1 @@
1
- {"version":3,"file":"ensureResolveMapEntry.d.ts","sourceRoot":"","sources":["../../src/resolveMap/ensureResolveMapEntry.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,sBAAsB,EACtB,uBAAuB,EACvB,WAAW,EACX,UAAU,EACX,MAAM,4BAA4B,CAAC;AAGpC;;GAEG;AACH,wBAAsB,qBAAqB,CACzC,MAAM,EAAE;IACN,UAAU,EAAE,WAAW,CAAC;IACxB,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,EAAE,MAAM,CAAC;IACvB,UAAU,EAAE,UAAU,CAAC;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,sBAAsB,CAAC,EAAE,sBAAsB,CAAC;CACjD,EACD,OAAO,EAAE;IACP,QAAQ,EAAE,uBAAuB,CAAC;CACnC,GACA,OAAO,CAAC;IAAE,cAAc,CAAC,EAAE,MAAM,CAAC;IAAC,iBAAiB,EAAE,OAAO,CAAA;CAAE,CAAC,CAgFlE"}
1
+ {"version":3,"file":"ensureResolveMapEntry.d.ts","sourceRoot":"","sources":["../../src/resolveMap/ensureResolveMapEntry.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,sBAAsB,EACtB,uBAAuB,EACvB,sBAAsB,EACtB,WAAW,EACX,UAAU,EACX,MAAM,4BAA4B,CAAC;AAGpC;;GAEG;AACH,wBAAsB,qBAAqB,CACzC,MAAM,EAAE;IACN,UAAU,EAAE,WAAW,CAAC;IACxB,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,EAAE,MAAM,CAAC;IACvB,UAAU,EAAE,UAAU,CAAC;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,eAAe,EAAE,sBAAsB,GAAG,SAAS,CAAC;IACpD,sBAAsB,CAAC,EAAE,sBAAsB,CAAC;CACjD,EACD,OAAO,EAAE;IACP,QAAQ,EAAE,uBAAuB,CAAC;CACnC,GACA,OAAO,CAAC;IAAE,cAAc,CAAC,EAAE,MAAM,CAAC;IAAC,iBAAiB,EAAE,OAAO,CAAA;CAAE,CAAC,CAkFlE"}
@@ -5,7 +5,7 @@ import { findPackage } from '../findFileInPackage/findPackage.js';
5
5
  * Ensure that a package is in the resolve map and return the path to the package.
6
6
  */
7
7
  export async function ensureResolveMapEntry(params, context) {
8
- const { dependencyName, resolveMap, packagePath, appPath, definition, moduleResolutionConfig } = params;
8
+ const { dependencyName, resolveMap, packagePath, appPath, definition, importerContext, moduleResolutionConfig } = params;
9
9
  const { packages } = context;
10
10
  const parentEntry = findResolveMapEntry({ packageName: definition.name, version: definition.version, resolveMap });
11
11
  // If we can't find the parent entry, we can't add the dependency.
@@ -24,6 +24,7 @@ export async function ensureResolveMapEntry(params, context) {
24
24
  dependencyName,
25
25
  startPath: packagePath,
26
26
  rootPath,
27
+ importerContext,
27
28
  moduleResolutionConfig,
28
29
  }, context);
29
30
  dependencyPath = dependencyPackage?.packagePath;
@@ -1 +1 @@
1
- {"version":3,"file":"ensureResolveMapEntry.js","sourceRoot":"","sources":["../../src/resolveMap/ensureResolveMapEntry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAClF,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAO/D,OAAO,EAAE,WAAW,EAAE,MAAM,qCAAqC,CAAC;AAElE;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,qBAAqB,CACzC,MAOC,EACD,OAEC;IAED,MAAM,EAAE,cAAc,EAAE,UAAU,EAAE,WAAW,EAAE,OAAO,EAAE,UAAU,EAAE,sBAAsB,EAAE,GAAG,MAAM,CAAC;IACxG,MAAM,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC;IAE7B,MAAM,WAAW,GAAG,mBAAmB,CAAC,EAAE,WAAW,EAAE,UAAU,CAAC,IAAI,EAAE,OAAO,EAAE,UAAU,CAAC,OAAO,EAAE,UAAU,EAAE,CAAC,CAAC;IAEnH,kEAAkE;IAClE,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,OAAO,EAAE,iBAAiB,EAAE,KAAK,EAAE,CAAC;IACtC,CAAC;IAED,MAAM,YAAY,GAAG,mBAAmB,CAAC,EAAE,UAAU,EAAE,WAAW,EAAE,cAAc,EAAE,UAAU,EAAE,CAAC,CAAC;IAClG,IAAI,cAAc,GAAG,YAAY,EAAE,IAAI,CAAC;IACxC,IAAI,oBAAoB,GAAG,cAAc,CAAC,CAAC,CAAC,MAAM,QAAQ,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAE3F,+FAA+F;IAC/F,IAAI,cAAc,IAAI,oBAAoB,IAAI,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A+D;QAC/D,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,eAAe,CAAC,OAAO,KAAK,UAAU,CAAC,cAAc,CAAC,CAAC,OAAO,EAAE,CAAC;IAC/G,CAAC;IAED,iDAAiD;IACjD,eAAe,GAAG;QAChB,IAAI,EAAE,cAAc;QACpB,OAAO;QACP,IAAI,EAAE,cAAc;QACpB,YAAY,EAAE,EAAE;QAChB,UAAU,EAAE;YACV,CAAC,GAAG,UAAU,CAAC,IAAI,IAAI,UAAU,CAAC,OAAO,EAAE,CAAC,EAAE,OAAO;SACtD;KACF,CAAC;IAEF,IAAI,iBAAiB,CAAC,cAAc,CAAC,EAAE,CAAC;QACtC,eAAe,CAAC,UAAU,GAAG,IAAI,CAAC;IACpC,CAAC;IAED,WAAW,CAAC,YAAY,CAAC,cAAc,CAAC,GAAG,OAAO,CAAC;IAEnD,yCAAyC;IACzC,IAAI,CAAC,UAAU,CAAC,cAAc,CAAC,EAAE,CAAC;QAChC,UAAU,CAAC,cAAc,CAAC,GAAG,eAAe,CAAC;IAC/C,CAAC;SAAM,CAAC;QACN,UAAU,CAAC,cAAc,CAAC,CAAC,cAAc,KAAK,EAAE,CAAC;QACjD,UAAU,CAAC,cAAc,CAAC,CAAC,cAAc,CAAC,OAAO,CAAC,GAAG,eAAe,CAAC;IACvE,CAAC;IAED,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,IAAI,EAAE,CAAC;AACrD,CAAC","sourcesContent":["import { findProjectRoot, isExternalPackage } from '@ms-cloudpack/path-utilities';\nimport { findResolveMapEntry } from './findResolveMapEntry.js';\nimport type {\n ModuleResolutionConfig,\n PackageDefinitionsCache,\n PackageJson,\n ResolveMap,\n} from '@ms-cloudpack/common-types';\nimport { findPackage } from '../findFileInPackage/findPackage.js';\n\n/**\n * Ensure that a package is in the resolve map and return the path to the package.\n */\nexport async function ensureResolveMapEntry(\n params: {\n definition: PackageJson;\n packagePath: string;\n dependencyName: string;\n resolveMap: ResolveMap;\n appPath: string;\n moduleResolutionConfig?: ModuleResolutionConfig;\n },\n context: {\n packages: PackageDefinitionsCache;\n },\n): Promise<{ dependencyPath?: string; updatedResolution: boolean }> {\n const { dependencyName, resolveMap, packagePath, appPath, definition, moduleResolutionConfig } = params;\n const { packages } = context;\n\n const parentEntry = findResolveMapEntry({ packageName: definition.name, version: definition.version, resolveMap });\n\n // If we can't find the parent entry, we can't add the dependency.\n if (!parentEntry) {\n return { updatedResolution: false };\n }\n\n const resolveEntry = findResolveMapEntry({ definition, packageName: dependencyName, resolveMap });\n let dependencyPath = resolveEntry?.path;\n let dependencyDefinition = dependencyPath ? await packages.get(dependencyPath) : undefined;\n\n // If the dependency is already in the resolve map and required by the parent, return the path.\n if (dependencyPath && dependencyDefinition && resolveEntry?.requiredBy[`${definition.name}@${definition.version}`]) {\n return { dependencyPath, updatedResolution: false };\n }\n\n const rootPath = findProjectRoot(appPath, { noPackageRoot: true });\n\n const dependencyPackage = await findPackage(\n {\n dependencyName,\n startPath: packagePath,\n rootPath,\n moduleResolutionConfig,\n },\n context,\n );\n\n dependencyPath = dependencyPackage?.packagePath;\n dependencyDefinition = dependencyPackage?.definition;\n const version = dependencyDefinition?.version;\n\n // If we can't find the dependency, we can't add it to the resolve map.\n if (!dependencyPath || !dependencyDefinition || !version) {\n return { updatedResolution: false };\n }\n\n // Check if the dependency is already in the resolve map.\n let dependencyEntry = [resolveMap[dependencyName], ...Object.values(resolveMap[dependencyName]?.scopedVersions || {})]\n .filter(Boolean)\n .find((e) => e.version === version && e.path === dependencyPath);\n\n // If it already exists, add the requiredBy entry and return the path.\n if (dependencyEntry) {\n parentEntry.dependencies[dependencyName] = version;\n dependencyEntry.requiredBy[`${definition.name}@${definition.version}`] = version;\n // If the dependency is scoped, we have changed the resolution.\n return { dependencyPath, updatedResolution: dependencyEntry.version !== resolveMap[dependencyName].version };\n }\n\n // If it is missing from the resolve map, add it.\n dependencyEntry = {\n name: dependencyName,\n version,\n path: dependencyPath,\n dependencies: {},\n requiredBy: {\n [`${definition.name}@${definition.version}`]: version,\n },\n };\n\n if (isExternalPackage(dependencyPath)) {\n dependencyEntry.isExternal = true;\n }\n\n parentEntry.dependencies[dependencyName] = version;\n\n // Add the dependency to the resolve map.\n if (!resolveMap[dependencyName]) {\n resolveMap[dependencyName] = dependencyEntry;\n } else {\n resolveMap[dependencyName].scopedVersions ??= {};\n resolveMap[dependencyName].scopedVersions[version] = dependencyEntry;\n }\n\n return { dependencyPath, updatedResolution: true };\n}\n"]}
1
+ {"version":3,"file":"ensureResolveMapEntry.js","sourceRoot":"","sources":["../../src/resolveMap/ensureResolveMapEntry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAClF,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAQ/D,OAAO,EAAE,WAAW,EAAE,MAAM,qCAAqC,CAAC;AAElE;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,qBAAqB,CACzC,MAQC,EACD,OAEC;IAED,MAAM,EAAE,cAAc,EAAE,UAAU,EAAE,WAAW,EAAE,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,sBAAsB,EAAE,GAC7G,MAAM,CAAC;IACT,MAAM,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC;IAE7B,MAAM,WAAW,GAAG,mBAAmB,CAAC,EAAE,WAAW,EAAE,UAAU,CAAC,IAAI,EAAE,OAAO,EAAE,UAAU,CAAC,OAAO,EAAE,UAAU,EAAE,CAAC,CAAC;IAEnH,kEAAkE;IAClE,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,OAAO,EAAE,iBAAiB,EAAE,KAAK,EAAE,CAAC;IACtC,CAAC;IAED,MAAM,YAAY,GAAG,mBAAmB,CAAC,EAAE,UAAU,EAAE,WAAW,EAAE,cAAc,EAAE,UAAU,EAAE,CAAC,CAAC;IAClG,IAAI,cAAc,GAAG,YAAY,EAAE,IAAI,CAAC;IACxC,I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AAC;QACpB,WAAW,CAAC,YAAY,CAAC,cAAc,CAAC,GAAG,OAAO,CAAC;QACnD,eAAe,CAAC,UAAU,CAAC,GAAG,UAAU,CAAC,IAAI,IAAI,UAAU,CAAC,OAAO,EAAE,CAAC,GAAG,OAAO,CAAC;QACjF,+DAA+D;QAC/D,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,eAAe,CAAC,OAAO,KAAK,UAAU,CAAC,cAAc,CAAC,CAAC,OAAO,EAAE,CAAC;IAC/G,CAAC;IAED,iDAAiD;IACjD,eAAe,GAAG;QAChB,IAAI,EAAE,cAAc;QACpB,OAAO;QACP,IAAI,EAAE,cAAc;QACpB,YAAY,EAAE,EAAE;QAChB,UAAU,EAAE;YACV,CAAC,GAAG,UAAU,CAAC,IAAI,IAAI,UAAU,CAAC,OAAO,EAAE,CAAC,EAAE,OAAO;SACtD;KACF,CAAC;IAEF,IAAI,iBAAiB,CAAC,cAAc,CAAC,EAAE,CAAC;QACtC,eAAe,CAAC,UAAU,GAAG,IAAI,CAAC;IACpC,CAAC;IAED,WAAW,CAAC,YAAY,CAAC,cAAc,CAAC,GAAG,OAAO,CAAC;IAEnD,yCAAyC;IACzC,IAAI,CAAC,UAAU,CAAC,cAAc,CAAC,EAAE,CAAC;QAChC,UAAU,CAAC,cAAc,CAAC,GAAG,eAAe,CAAC;IAC/C,CAAC;SAAM,CAAC;QACN,UAAU,CAAC,cAAc,CAAC,CAAC,cAAc,KAAK,EAAE,CAAC;QACjD,UAAU,CAAC,cAAc,CAAC,CAAC,cAAc,CAAC,OAAO,CAAC,GAAG,eAAe,CAAC;IACvE,CAAC;IAED,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,IAAI,EAAE,CAAC;AACrD,CAAC","sourcesContent":["import { findProjectRoot, isExternalPackage } from '@ms-cloudpack/path-utilities';\nimport { findResolveMapEntry } from './findResolveMapEntry.js';\nimport type {\n ModuleResolutionConfig,\n PackageDefinitionsCache,\n PackageImporterContext,\n PackageJson,\n ResolveMap,\n} from '@ms-cloudpack/common-types';\nimport { findPackage } from '../findFileInPackage/findPackage.js';\n\n/**\n * Ensure that a package is in the resolve map and return the path to the package.\n */\nexport async function ensureResolveMapEntry(\n params: {\n definition: PackageJson;\n packagePath: string;\n dependencyName: string;\n resolveMap: ResolveMap;\n appPath: string;\n importerContext: PackageImporterContext | undefined;\n moduleResolutionConfig?: ModuleResolutionConfig;\n },\n context: {\n packages: PackageDefinitionsCache;\n },\n): Promise<{ dependencyPath?: string; updatedResolution: boolean }> {\n const { dependencyName, resolveMap, packagePath, appPath, definition, importerContext, moduleResolutionConfig } =\n params;\n const { packages } = context;\n\n const parentEntry = findResolveMapEntry({ packageName: definition.name, version: definition.version, resolveMap });\n\n // If we can't find the parent entry, we can't add the dependency.\n if (!parentEntry) {\n return { updatedResolution: false };\n }\n\n const resolveEntry = findResolveMapEntry({ definition, packageName: dependencyName, resolveMap });\n let dependencyPath = resolveEntry?.path;\n let dependencyDefinition = dependencyPath ? await packages.get(dependencyPath) : undefined;\n\n // If the dependency is already in the resolve map and required by the parent, return the path.\n if (dependencyPath && dependencyDefinition && resolveEntry?.requiredBy[`${definition.name}@${definition.version}`]) {\n return { dependencyPath, updatedResolution: false };\n }\n\n const rootPath = findProjectRoot(appPath, { noPackageRoot: true });\n\n const dependencyPackage = await findPackage(\n {\n dependencyName,\n startPath: packagePath,\n rootPath,\n importerContext,\n moduleResolutionConfig,\n },\n context,\n );\n\n dependencyPath = dependencyPackage?.packagePath;\n dependencyDefinition = dependencyPackage?.definition;\n const version = dependencyDefinition?.version;\n\n // If we can't find the dependency, we can't add it to the resolve map.\n if (!dependencyPath || !dependencyDefinition || !version) {\n return { updatedResolution: false };\n }\n\n // Check if the dependency is already in the resolve map.\n let dependencyEntry = [resolveMap[dependencyName], ...Object.values(resolveMap[dependencyName]?.scopedVersions || {})]\n .filter(Boolean)\n .find((e) => e.version === version && e.path === dependencyPath);\n\n // If it already exists, add the requiredBy entry and return the path.\n if (dependencyEntry) {\n parentEntry.dependencies[dependencyName] = version;\n dependencyEntry.requiredBy[`${definition.name}@${definition.version}`] = version;\n // If the dependency is scoped, we have changed the resolution.\n return { dependencyPath, updatedResolution: dependencyEntry.version !== resolveMap[dependencyName].version };\n }\n\n // If it is missing from the resolve map, add it.\n dependencyEntry = {\n name: dependencyName,\n version,\n path: dependencyPath,\n dependencies: {},\n requiredBy: {\n [`${definition.name}@${definition.version}`]: version,\n },\n };\n\n if (isExternalPackage(dependencyPath)) {\n dependencyEntry.isExternal = true;\n }\n\n parentEntry.dependencies[dependencyName] = version;\n\n // Add the dependency to the resolve map.\n if (!resolveMap[dependencyName]) {\n resolveMap[dependencyName] = dependencyEntry;\n } else {\n resolveMap[dependencyName].scopedVersions ??= {};\n resolveMap[dependencyName].scopedVersions[version] = dependencyEntry;\n }\n\n return { dependencyPath, updatedResolution: true };\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ms-cloudpack/package-utilities",
3
- "version": "13.0.1",
3
+ "version": "13.1.0",
4
4
  "description": "Utilities for resolving/parsing packages and their imports in Cloudpack",
5
5
  "license": "MIT",
6
6
  "type": "module",