@ms-cloudpack/package-utilities 5.1.7 → 5.1.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -68,31 +68,26 @@ async function visitPackage(options, context) {
68
68
  };
69
69
  const dependencyPaths = [];
70
70
  for (const [dependencyName, versionRequirement] of Object.entries(dependencies)) {
71
- const isPeerDependency = !!packageDefinition.peerDependencies?.[dependencyName];
72
- const { packagePath: dependencyPath, definition: dependencyDefinition } = (await findPackage({
73
- dependencyName,
74
- startPath: packagePath,
75
- gitRootPath,
76
- }, context)) || {};
77
- if (dependencyPath && dependencyDefinition) {
78
- if (dependencyDefinition.name && dependencyDefinition.version) {
79
- const dependencyEntry = ensurePackageEntry({
80
- packagePath: dependencyPath,
81
- packageMap,
82
- definition: dependencyDefinition,
83
- });
84
- entry.dependencies[dependencyDefinition.name] = dependencyDefinition.version;
85
- dependencyEntry.requiredBy[`${name}@${version}`] = versionRequirement;
86
- dependencyPaths.push(dependencyPath);
71
+ const dependencyPackage = await findPackage({ dependencyName, startPath: packagePath, gitRootPath }, context);
72
+ if (!dependencyPackage) {
73
+ if (packageDefinition.peerDependencies?.[dependencyName]) {
74
+ // Ignore missing peer dependencies
75
+ continue;
87
76
  }
88
- else {
89
- throw new Error(`"${dependencyPath}/package.json" is missing a name or version.`);
90
- }
91
- }
92
- else if (!isPeerDependency) {
93
77
  throw new Error(`Could not find dependency "${dependencyName}" at "${packagePath}".`);
94
78
  }
95
- // Ignore missing peer dependencies
79
+ const { packagePath: dependencyPath, definition: dependencyDefinition } = dependencyPackage;
80
+ if (!(dependencyDefinition.name && dependencyDefinition.version)) {
81
+ throw new Error(`"${dependencyPath}/package.json" is missing a name or version.`);
82
+ }
83
+ const dependencyEntry = ensurePackageEntry({
84
+ packagePath: dependencyPath,
85
+ packageMap,
86
+ definition: dependencyDefinition,
87
+ });
88
+ entry.dependencies[dependencyDefinition.name] = dependencyDefinition.version;
89
+ dependencyEntry.requiredBy[`${name}@${version}`] = versionRequirement;
90
+ dependencyPaths.push(dependencyPath);
96
91
  }
97
92
  return dependencyPaths;
98
93
  }
@@ -1 +1 @@
1
- {"version":3,"file":"findPackagesFromPath.js","sourceRoot":"","sources":["../../src/createResolveMap/findPackagesFromPath.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AACxD,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAI5D;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,OAgBC,EACD,OAKC;IAED,MAAM,EAAE,WAAW,EAAE,gBAAgB,EAAE,GAAG,OAAO,CAAC;IAClD,MAAM,UAAU,GAAe,EAAE,CAAC;IAClC,MAAM,YAAY,GAAG,IAAI,GAAG,EAAU,CAAC;IAEvC,KAAK,MAAM,UAAU,IAAI,WAAW,EAAE;QACpC,IAAI,CAAC,CAAC,MAAM,QAAQ,CAAC,UAAU,CAAC,CAAC,EAAE;YACjC,MAAM,IAAI,KAAK,CAAC,QAAQ,UAAU,mBAAmB,CAAC,CAAC;SACxD;QAED,IAAI,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC;QAC9B,IAAI,CAAC,WAAW,EAAE;YAChB,IAAI;gBACF,WAAW,GAAG,WAAW,CAAC,UAAU,CAAC,CAAC;aACvC;YAAC,OAAO,CAAC,EAAE;gBACV,YAAY;aACb;SACF;QAED,MAAM,YAAY,GAAa,EAAE,CAAC;QAElC,IAAI,gBAAgB,EAAE;YACpB,MAAM,YAAY,GAAG,MAAM,IAAI,CAAC,iBAAiB,EAAE,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM,EAAE,CAAC,oBA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IAAI,cAAc,8CAA8C,CAAC,CAAC;aACnF;SACF;aAAM,IAAI,CAAC,gBAAgB,EAAE;YAC5B,MAAM,IAAI,KAAK,CAAC,8BAA8B,cAAc,SAAS,WAAW,IAAI,CAAC,CAAC;SACvF;QACD,mCAAmC;KACpC;IAED,OAAO,eAAe,CAAC;AACzB,CAAC;AAED;;;GAGG;AACH,SAAS,kBAAkB,CAAC,OAI3B;IACC,MAAM,EAAE,WAAW,GAAG,EAAE,EAAE,UAAU,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC;IAC7D,MAAM,EAAE,IAAI,GAAG,WAAW,EAAE,OAAO,GAAG,GAAG,EAAE,GAAG,UAAU,CAAC;IAEzD,UAAU,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;IAExB,IAAI,KAAK,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC;IACtC,IAAI,CAAC,KAAK,EAAE;QACV,KAAK,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,GAAG;YAClC,IAAI;YACJ,OAAO;YACP,IAAI,EAAE,WAAW;YACjB,YAAY,EAAE,EAAE;YAChB,UAAU,EAAE,EAAE;SACf,CAAC;QAEF,IAAI,iBAAiB,CAAC,WAAW,CAAC,EAAE;YAClC,KAAK,CAAC,UAAU,GAAG,IAAI,CAAC;SACzB;KACF;IAED,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["import type { PackageDefinitionsCache, PackageJson } from '@ms-cloudpack/bundler-types';\nimport { isFolder } from '@ms-cloudpack/path-utilities';\nimport glob from 'fast-glob';\nimport path from 'path';\nimport { findGitRoot } from 'workspace-tools';\nimport { findPackage } from '../findPackage.js';\nimport { isExternalPackage } from '../isExternalPackage.js';\nimport type { PackageMap } from '../types/PackageMap.js';\nimport type { ResolveMapEntry } from '../types/ResolveMapEntry.js';\n\n/**\n * Find all packages from a given path. We do this by walking the dependency tree\n * of the app to build a map of all packages and their dependencies.\n */\nexport async function findPackagesFromPath(\n options: {\n /**\n * Paths to search for package.json files and traverse their dependencies to build a PackageMap.\n */\n searchPaths: string[];\n\n /**\n * Where to stop looking for packages. If not specified, will look for a git root. If one is not\n * found, will use the first path in the paths array.\n */\n gitRootPath?: string;\n\n /**\n * If true will glob for all package.json files in the path and add them to the map.\n */\n discoverPackages?: boolean;\n },\n context: {\n /**\n * Package cache.\n */\n packages: PackageDefinitionsCache;\n },\n): Promise<PackageMap> {\n const { searchPaths, discoverPackages } = options;\n const packageMap: PackageMap = {};\n const visitedPaths = new Set<string>();\n\n for (const searchPath of searchPaths) {\n if (!(await isFolder(searchPath))) {\n throw new Error(`Path ${searchPath} is not a folder.`);\n }\n\n let { gitRootPath } = options;\n if (!gitRootPath) {\n try {\n gitRootPath = findGitRoot(searchPath);\n } catch (e) {\n /* ignore */\n }\n }\n\n const pathsToVisit: string[] = [];\n\n if (discoverPackages) {\n const packagePaths = await glob('**/package.json', { cwd: searchPath, ignore: ['**/node_modules/**'] });\n\n pathsToVisit.push(...packagePaths.map((p) => path.dirname(path.join(searchPath, p))));\n } else {\n pathsToVisit.push(searchPath);\n }\n\n while (pathsToVisit.length) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- already checked length\n const packagePath = pathsToVisit.shift()!;\n if (!visitedPaths.has(packagePath)) {\n visitedPaths.add(packagePath);\n\n const dependencyPaths = await visitPackage({ packagePath, packageMap, gitRootPath }, context);\n pathsToVisit.push(...dependencyPaths);\n }\n }\n }\n\n return packageMap;\n}\n\n/**\n * Visit a package path, and add entries for the package and its dependencies to `packageMap`.\n * Returns a list of additional dependency paths to visit.\n */\nasync function visitPackage(\n options: {\n packagePath: string;\n packageMap: PackageMap;\n gitRootPath: string | undefined;\n },\n context: Parameters<typeof findPackage>[1],\n) {\n const { packagePath, packageMap, gitRootPath } = options;\n const { packages } = context;\n\n const packageDefinition = await packages.get(packagePath);\n if (!packageDefinition) {\n throw new Error(`Could not find package definition at \"${packagePath}\".`);\n }\n if (!(packageDefinition.name && packageDefinition.version)) {\n return [];\n }\n\n const { name, version } = packageDefinition;\n const entry = ensurePackageEntry({ packagePath: packagePath, packageMap, definition: packageDefinition });\n\n // Add all dependencies to the list of paths to visit.\n const dependencies = {\n ...(packageDefinition.dependencies || {}),\n ...(packageDefinition.peerDependencies || {}),\n } as Record<string, string>;\n\n const dependencyPaths: string[] = [];\n\n for (const [dependencyName, versionRequirement] of Object.entries(dependencies)) {\n const isPeerDependency = !!packageDefinition.peerDependencies?.[dependencyName];\n\n const { packagePath: dependencyPath, definition: dependencyDefinition } =\n (await findPackage(\n {\n dependencyName,\n startPath: packagePath,\n gitRootPath,\n },\n context,\n )) || {};\n\n if (dependencyPath && dependencyDefinition) {\n if (dependencyDefinition.name && dependencyDefinition.version) {\n const dependencyEntry = ensurePackageEntry({\n packagePath: dependencyPath,\n packageMap,\n definition: dependencyDefinition,\n });\n\n entry.dependencies[dependencyDefinition.name] = dependencyDefinition.version;\n dependencyEntry.requiredBy[`${name}@${version}`] = versionRequirement;\n\n dependencyPaths.push(dependencyPath);\n } else {\n throw new Error(`\"${dependencyPath}/package.json\" is missing a name or version.`);\n }\n } else if (!isPeerDependency) {\n throw new Error(`Could not find dependency \"${dependencyName}\" at \"${packagePath}\".`);\n }\n // Ignore missing peer dependencies\n }\n\n return dependencyPaths;\n}\n\n/**\n * If `packageMap` doesn't already have an entry for this package name and version, create one\n * and add it to `packageMap`. Returns the entry.\n */\nfunction ensurePackageEntry(options: {\n packagePath: string;\n packageMap: PackageMap;\n definition: PackageJson;\n}): ResolveMapEntry {\n const { packagePath = '', packageMap, definition } = options;\n const { name = '_no_name_', version = '*' } = definition;\n\n packageMap[name] ??= {};\n\n let entry = packageMap[name][version];\n if (!entry) {\n entry = packageMap[name][version] = {\n name,\n version,\n path: packagePath,\n dependencies: {},\n requiredBy: {},\n };\n\n if (isExternalPackage(packagePath)) {\n entry.isExternal = true;\n }\n }\n\n return entry;\n}\n"]}
1
+ {"version":3,"file":"findPackagesFromPath.js","s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KACtC;IAED,OAAO,eAAe,CAAC;AACzB,CAAC;AAED;;;GAGG;AACH,SAAS,kBAAkB,CAAC,OAI3B;IACC,MAAM,EAAE,WAAW,GAAG,EAAE,EAAE,UAAU,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC;IAC7D,MAAM,EAAE,IAAI,GAAG,WAAW,EAAE,OAAO,GAAG,GAAG,EAAE,GAAG,UAAU,CAAC;IAEzD,UAAU,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;IAExB,IAAI,KAAK,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC;IACtC,IAAI,CAAC,KAAK,EAAE;QACV,KAAK,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,GAAG;YAClC,IAAI;YACJ,OAAO;YACP,IAAI,EAAE,WAAW;YACjB,YAAY,EAAE,EAAE;YAChB,UAAU,EAAE,EAAE;SACf,CAAC;QAEF,IAAI,iBAAiB,CAAC,WAAW,CAAC,EAAE;YAClC,KAAK,CAAC,UAAU,GAAG,IAAI,CAAC;SACzB;KACF;IAED,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["import type { PackageDefinitionsCache, PackageJson } from '@ms-cloudpack/bundler-types';\nimport { isFolder } from '@ms-cloudpack/path-utilities';\nimport glob from 'fast-glob';\nimport path from 'path';\nimport { findGitRoot } from 'workspace-tools';\nimport { findPackage } from '../findPackage.js';\nimport { isExternalPackage } from '../isExternalPackage.js';\nimport type { PackageMap } from '../types/PackageMap.js';\nimport type { ResolveMapEntry } from '../types/ResolveMapEntry.js';\n\n/**\n * Find all packages from a given path. We do this by walking the dependency tree\n * of the app to build a map of all packages and their dependencies.\n */\nexport async function findPackagesFromPath(\n options: {\n /**\n * Paths to search for package.json files and traverse their dependencies to build a PackageMap.\n */\n searchPaths: string[];\n\n /**\n * Where to stop looking for packages. If not specified, will look for a git root. If one is not\n * found, will use the first path in the paths array.\n */\n gitRootPath?: string;\n\n /**\n * If true will glob for all package.json files in the path and add them to the map.\n */\n discoverPackages?: boolean;\n },\n context: {\n /**\n * Package cache.\n */\n packages: PackageDefinitionsCache;\n },\n): Promise<PackageMap> {\n const { searchPaths, discoverPackages } = options;\n const packageMap: PackageMap = {};\n const visitedPaths = new Set<string>();\n\n for (const searchPath of searchPaths) {\n if (!(await isFolder(searchPath))) {\n throw new Error(`Path ${searchPath} is not a folder.`);\n }\n\n let { gitRootPath } = options;\n if (!gitRootPath) {\n try {\n gitRootPath = findGitRoot(searchPath);\n } catch (e) {\n /* ignore */\n }\n }\n\n const pathsToVisit: string[] = [];\n\n if (discoverPackages) {\n const packagePaths = await glob('**/package.json', { cwd: searchPath, ignore: ['**/node_modules/**'] });\n\n pathsToVisit.push(...packagePaths.map((p) => path.dirname(path.join(searchPath, p))));\n } else {\n pathsToVisit.push(searchPath);\n }\n\n while (pathsToVisit.length) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- already checked length\n const packagePath = pathsToVisit.shift()!;\n if (!visitedPaths.has(packagePath)) {\n visitedPaths.add(packagePath);\n\n const dependencyPaths = await visitPackage({ packagePath, packageMap, gitRootPath }, context);\n pathsToVisit.push(...dependencyPaths);\n }\n }\n }\n\n return packageMap;\n}\n\n/**\n * Visit a package path, and add entries for the package and its dependencies to `packageMap`.\n * Returns a list of additional dependency paths to visit.\n */\nasync function visitPackage(\n options: {\n packagePath: string;\n packageMap: PackageMap;\n gitRootPath: string | undefined;\n },\n context: Parameters<typeof findPackage>[1],\n) {\n const { packagePath, packageMap, gitRootPath } = options;\n const { packages } = context;\n\n const packageDefinition = await packages.get(packagePath);\n if (!packageDefinition) {\n throw new Error(`Could not find package definition at \"${packagePath}\".`);\n }\n if (!(packageDefinition.name && packageDefinition.version)) {\n return [];\n }\n\n const { name, version } = packageDefinition;\n const entry = ensurePackageEntry({ packagePath: packagePath, packageMap, definition: packageDefinition });\n\n // Add all dependencies to the list of paths to visit.\n const dependencies = {\n ...(packageDefinition.dependencies || {}),\n ...(packageDefinition.peerDependencies || {}),\n } as Record<string, string>;\n\n const dependencyPaths: string[] = [];\n\n for (const [dependencyName, versionRequirement] of Object.entries(dependencies)) {\n const dependencyPackage = await findPackage({ dependencyName, startPath: packagePath, gitRootPath }, context);\n if (!dependencyPackage) {\n if (packageDefinition.peerDependencies?.[dependencyName]) {\n // Ignore missing peer dependencies\n continue;\n }\n throw new Error(`Could not find dependency \"${dependencyName}\" at \"${packagePath}\".`);\n }\n\n const { packagePath: dependencyPath, definition: dependencyDefinition } = dependencyPackage;\n\n if (!(dependencyDefinition.name && dependencyDefinition.version)) {\n throw new Error(`\"${dependencyPath}/package.json\" is missing a name or version.`);\n }\n\n const dependencyEntry = ensurePackageEntry({\n packagePath: dependencyPath,\n packageMap,\n definition: dependencyDefinition,\n });\n\n entry.dependencies[dependencyDefinition.name] = dependencyDefinition.version;\n dependencyEntry.requiredBy[`${name}@${version}`] = versionRequirement;\n\n dependencyPaths.push(dependencyPath);\n }\n\n return dependencyPaths;\n}\n\n/**\n * If `packageMap` doesn't already have an entry for this package name and version, create one\n * and add it to `packageMap`. Returns the entry.\n */\nfunction ensurePackageEntry(options: {\n packagePath: string;\n packageMap: PackageMap;\n definition: PackageJson;\n}): ResolveMapEntry {\n const { packagePath = '', packageMap, definition } = options;\n const { name = '_no_name_', version = '*' } = definition;\n\n packageMap[name] ??= {};\n\n let entry = packageMap[name][version];\n if (!entry) {\n entry = packageMap[name][version] = {\n name,\n version,\n path: packagePath,\n dependencies: {},\n requiredBy: {},\n };\n\n if (isExternalPackage(packagePath)) {\n entry.isExternal = true;\n }\n }\n\n return entry;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"detectModuleType.d.ts","sourceRoot":"","sources":["../src/detectModuleType.ts"],"names":[],"mappings":"AAOA,MAAM,MAAM,UAAU,GAAG,KAAK,GAAG,KAAK,CAAC;AAEvC;;;GAGG;AACH,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS,CAgBjF;AAED;;;GAGG;AACH,wBAAsB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,CAUxF"}
1
+ {"version":3,"file":"detectModuleType.d.ts","sourceRoot":"","sources":["../src/detectModuleType.ts"],"names":[],"mappings":"AAOA,MAAM,MAAM,UAAU,GAAG,KAAK,GAAG,KAAK,CAAC;AAEvC;;;GAGG;AACH,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS,CAYjF;AAED;;;GAGG;AACH,wBAAsB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,CAUxF"}
@@ -10,7 +10,7 @@ function removeComments(source) {
10
10
  export function detectModuleTypeFromSource(source) {
11
11
  let result;
12
12
  const content = removeComments(source);
13
- if (content.match(/(import *)|(import {)|(export {)|(export \*)|(export (default )?[_a-zA-Z0-9]+)|(export [a-zA-Z]+ from)/)) {
13
+ if (content.match(/\b(?:import|export)\s+[*{_$a-zA-Z]/)) {
14
14
  result = 'esm';
15
15
  }
16
16
  else if (content.match(/module\.exports[ =]+|exports\.|typeof exports|require\(['"]+/)) {
@@ -30,6 +30,6 @@ export async function detectModuleType(filePath) {
30
30
  catch (e) {
31
31
  return undefined;
32
32
  }
33
- return detectModuleTypeFromSource(removeComments(source));
33
+ return detectModuleTypeFromSource(source);
34
34
  }
35
35
  //# sourceMappingURL=detectModuleType.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"detectModuleType.js","sourceRoot":"","sources":["../src/detectModuleType.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,aAAa,CAAC;AAErC,SAAS,cAAc,CAAC,MAAc;IACpC,kDAAkD;IAClD,OAAO,MAAM,CAAC,OAAO,CAAC,0BAA0B,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,iBAAiB;AACjF,CAAC;AAID;;;GAGG;AACH,MAAM,UAAU,0BAA0B,CAAC,MAAc;IACvD,IAAI,MAA8B,CAAC;IAEnC,MAAM,OAAO,GAAG,cAAc,CAAC,MAAM,CAAC,CAAC;IAEvC,IACE,OAAO,CAAC,KAAK,CACX,wGAAwG,CACzG,EACD;QACA,MAAM,GAAG,KAAK,CAAC;KAChB;SAAM,IAAI,OAAO,CAAC,KAAK,CAAC,8DAA8D,CAAC,EAAE;QACxF,MAAM,GAAG,KAAK,CAAC;KAChB;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,QAAgB;IACrD,IAAI,MAAc,CAAC;IAEnB,IAAI;QACF,MAAM,GAAG,CAAC,MAAM,UAAU,CAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC;KACnE;IAAC,OAAO,CAAC,EAAE;QACV,OAAO,SAAS,CAAC;KAClB;IAED,OAAO,0BAA0B,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC;AAC5D,CAAC","sourcesContent":["import fsPromises from 'fs/promises';\n\nfunction removeComments(source: string) {\n // Takes a string of code, not an actual function.\n return source.replace(/\\/\\*[\\s\\S]*?\\*\\/|\\/\\/.*/g, '').trim(); // Strip comments\n}\n\nexport type ModuleType = 'esm' | 'cjs';\n\n/**\n * Determines if the given source is commonjs or esm.\n * @returns \"esm\" | \"cjs\" | undefined\n */\nexport function detectModuleTypeFromSource(source: string): ModuleType | undefined {\n let result: ModuleType | undefined;\n\n const content = removeComments(source);\n\n if (\n content.match(\n /(import *)|(import {)|(export {)|(export \\*)|(export (default )?[_a-zA-Z0-9]+)|(export [a-zA-Z]+ from)/,\n )\n ) {\n result = 'esm';\n } else if (content.match(/module\\.exports[ =]+|exports\\.|typeof exports|require\\(['\"]+/)) {\n result = 'cjs';\n }\n\n return result;\n}\n\n/**\n * Determines if the given file is commonjs or esm.\n * @returns \"esm\" | \"cjs\" | undefined\n */\nexport async function detectModuleType(filePath: string): Promise<ModuleType | undefined> {\n let source: string;\n\n try {\n source = (await fsPromises.readFile(filePath, 'utf8')).toString();\n } catch (e) {\n return undefined;\n }\n\n return detectModuleTypeFromSource(removeComments(source));\n}\n"]}
1
+ {"version":3,"file":"detectModuleType.js","sourceRoot":"","sources":["../src/detectModuleType.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,aAAa,CAAC;AAErC,SAAS,cAAc,CAAC,MAAc;IACpC,kDAAkD;IAClD,OAAO,MAAM,CAAC,OAAO,CAAC,0BAA0B,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,iBAAiB;AACjF,CAAC;AAID;;;GAGG;AACH,MAAM,UAAU,0BAA0B,CAAC,MAAc;IACvD,IAAI,MAA8B,CAAC;IAEnC,MAAM,OAAO,GAAG,cAAc,CAAC,MAAM,CAAC,CAAC;IAEvC,IAAI,OAAO,CAAC,KAAK,CAAC,oCAAoC,CAAC,EAAE;QACvD,MAAM,GAAG,KAAK,CAAC;KAChB;SAAM,IAAI,OAAO,CAAC,KAAK,CAAC,8DAA8D,CAAC,EAAE;QACxF,MAAM,GAAG,KAAK,CAAC;KAChB;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,QAAgB;IACrD,IAAI,MAAc,CAAC;IAEnB,IAAI;QACF,MAAM,GAAG,CAAC,MAAM,UAAU,CAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC;KACnE;IAAC,OAAO,CAAC,EAAE;QACV,OAAO,SAAS,CAAC;KAClB;IAED,OAAO,0BAA0B,CAAC,MAAM,CAAC,CAAC;AAC5C,CAAC","sourcesContent":["import fsPromises from 'fs/promises';\n\nfunction removeComments(source: string) {\n // Takes a string of code, not an actual function.\n return source.replace(/\\/\\*[\\s\\S]*?\\*\\/|\\/\\/.*/g, '').trim(); // Strip comments\n}\n\nexport type ModuleType = 'esm' | 'cjs';\n\n/**\n * Determines if the given source is commonjs or esm.\n * @returns \"esm\" | \"cjs\" | undefined\n */\nexport function detectModuleTypeFromSource(source: string): ModuleType | undefined {\n let result: ModuleType | undefined;\n\n const content = removeComments(source);\n\n if (content.match(/\\b(?:import|export)\\s+[*{_$a-zA-Z]/)) {\n result = 'esm';\n } else if (content.match(/module\\.exports[ =]+|exports\\.|typeof exports|require\\(['\"]+/)) {\n result = 'cjs';\n }\n\n return result;\n}\n\n/**\n * Determines if the given file is commonjs or esm.\n * @returns \"esm\" | \"cjs\" | undefined\n */\nexport async function detectModuleType(filePath: string): Promise<ModuleType | undefined> {\n let source: string;\n\n try {\n source = (await fsPromises.readFile(filePath, 'utf8')).toString();\n } catch (e) {\n return undefined;\n }\n\n return detectModuleTypeFromSource(source);\n}\n"]}
@@ -9,7 +9,7 @@ export type FindFileInPackageResult = {
9
9
  sourcePath?: string;
10
10
  };
11
11
  /**
12
- * Given a requested partial filePath, resolves the relative path intermediate path if the file exists, with special
12
+ * Given a requested partial filePath, resolves the relative intermediate path if the file exists, with special
13
13
  * consideration for internal packages, which may not have intermediate files but only source files. Paths returned
14
14
  * are always relative and start with `./`.
15
15
  *
@@ -1 +1 @@
1
- {"version":3,"file":"findFileInPackage.d.ts","sourceRoot":"","sources":["../src/findFileInPackage.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAE3E,MAAM,MAAM,wBAAwB,GAAG;IACrC,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG;IACpC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF;;;;;;;;;GASG;AAEH,wBAAsB,iBAAiB,CACrC,OAAO,EAAE,wBAAwB,EACjC,OAAO,EAAE;IAAE,QAAQ,EAAE,uBAAuB,CAAA;CAAE,GAC7C,OAAO,CAAC,uBAAuB,CAAC,CAmFlC"}
1
+ {"version":3,"file":"findFileInPackage.d.ts","sourceRoot":"","sources":["../src/findFileInPackage.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAI3E,MAAM,MAAM,wBAAwB,GAAG;IACrC,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG;IACpC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF;;;;;;;;;GASG;AAEH,wBAAsB,iBAAiB,CACrC,OAAO,EAAE,wBAAwB,EACjC,OAAO,EAAE;IAAE,QAAQ,EAAE,uBAAuB,CAAA;CAAE,GAC7C,OAAO,CAAC,uBAAuB,CAAC,CAuFlC"}
@@ -4,8 +4,9 @@ import { isExternalPackage } from './isExternalPackage.js';
4
4
  import { safeRelativePath } from '@ms-cloudpack/path-string-parsing';
5
5
  import { getExportsMap } from './getExportsMap.js';
6
6
  import { flattenExportsMap } from './flattenExportsMap.js';
7
+ const typescriptExtensions = ['.ts', '.tsx', '.cts', '.mts'];
7
8
  /**
8
- * Given a requested partial filePath, resolves the relative path intermediate path if the file exists, with special
9
+ * Given a requested partial filePath, resolves the relative intermediate path if the file exists, with special
9
10
  * consideration for internal packages, which may not have intermediate files but only source files. Paths returned
10
11
  * are always relative and start with `./`.
11
12
  *
@@ -23,6 +24,8 @@ export async function findFileInPackage(options, context) {
23
24
  const candidates = [
24
25
  filePath,
25
26
  filePath + '.js',
27
+ filePath + '.mjs',
28
+ filePath + '.cjs',
26
29
  safeRelativePath(path.join(filePath, 'index.js')),
27
30
  safeRelativePath(path.join(filePath, 'package.json')),
28
31
  ];
@@ -36,18 +39,21 @@ export async function findFileInPackage(options, context) {
36
39
  // For internal packages, try and find source/typings and convert to intermediate (which may be missing.)
37
40
  if (isInternal) {
38
41
  for (const candidate of candidates) {
39
- const intermediateCandidate = intermediateToSourcePath(candidate, packagePath);
40
- if (intermediateCandidate && (await isFile(path.join(packagePath, intermediateCandidate)))) {
41
- sourcePath = intermediateCandidate;
42
+ sourcePath = intermediateToSourcePath(candidate, packagePath);
43
+ if (sourcePath) {
42
44
  break;
43
45
  }
44
46
  }
45
- // If we couldn't find a unique source file, stick with the resolved intermediate file as the only known truth.
46
- if (filePath && sourcePath === filePath) {
47
+ // If the discovered source file is the same as the provided file, resolve the intermediate path.
48
+ if (sourcePath && (!filePath || sourcePath === filePath)) {
49
+ filePath = sourceToIntermediatePath(sourcePath);
50
+ }
51
+ // If the sourcePath is the same as the filePath, clear it. By this point we should have resolved
52
+ // the true intermediate path.
53
+ if (sourcePath === filePath) {
47
54
  sourcePath = undefined;
48
55
  }
49
- if (sourcePath) {
50
- filePath ??= sourceToIntermediatePath(sourcePath);
56
+ if (sourcePath && typescriptExtensions.includes(path.extname(sourcePath))) {
51
57
  typesPath = filePath && path.extname(filePath) === '.js' ? filePath.replace(/\.js$/, '.d.ts') : undefined;
52
58
  }
53
59
  }
@@ -1 +1 @@
1
- {"version":3,"file":"findFileInPackage.js","sourceRoot":"","sources":["../src/findFileInPackage.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,wBAAwB,EAAE,wBAAwB,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAC;AAC1G,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AACrE,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAA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AE,SAAS,CAAC,CAAC,CAAC;aACxG,CAAC;SACH;KACF;IAED,IAAI,SAAS,EAAE;QACb,MAAM,CAAC,SAAS,GAAG,gBAAgB,CAAC,SAAS,CAAC,CAAC;KAChD;IAED,IAAI,QAAQ,EAAE;QACZ,MAAM,CAAC,QAAQ,GAAG,gBAAgB,CAAC,QAAQ,CAAC,CAAC;KAC9C;IAED,IAAI,UAAU,EAAE;QACd,MAAM,CAAC,UAAU,GAAG,gBAAgB,CAAC,UAAU,CAAC,CAAC;KAClD;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import path from 'path';\nimport { intermediateToSourcePath, sourceToIntermediatePath, isFile } from '@ms-cloudpack/path-utilities';\nimport { isExternalPackage } from './isExternalPackage.js';\nimport { safeRelativePath } from '@ms-cloudpack/path-string-parsing';\nimport { getExportsMap } from './getExportsMap.js';\nimport { flattenExportsMap } from './flattenExportsMap.js';\nimport type { PackageDefinitionsCache } from '@ms-cloudpack/bundler-types';\n\nexport type FindFileInPackageOptions = {\n packagePath: string;\n filePath: string;\n};\n\nexport type FindFileInPackageResult = {\n filePath?: string;\n typesPath?: string;\n sourcePath?: string;\n};\n\n/**\n * Given a requested partial filePath, resolves the relative path 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 */\n\nexport async function findFileInPackage(\n options: FindFileInPackageOptions,\n context: { packages: PackageDefinitionsCache },\n): Promise<FindFileInPackageResult> {\n const { packagePath } = options;\n let filePath: string | undefined = safeRelativePath(options.filePath);\n let sourcePath: string | undefined;\n let typesPath: string | undefined;\n const isInternal = !isExternalPackage(packagePath);\n\n const candidates = [\n filePath,\n filePath + '.js',\n safeRelativePath(path.join(filePath, 'index.js')),\n safeRelativePath(path.join(filePath, 'package.json')),\n ];\n\n filePath = undefined;\n for (const candidate of candidates) {\n if (await isFile(path.join(packagePath, candidate))) {\n filePath = candidate;\n break;\n }\n }\n\n // For internal packages, try and find source/typings and convert to intermediate (which may be missing.)\n if (isInternal) {\n for (const candidate of candidates) {\n const intermediateCandidate = intermediateToSourcePath(candidate, packagePath);\n if (intermediateCandidate && (await isFile(path.join(packagePath, intermediateCandidate)))) {\n sourcePath = intermediateCandidate;\n break;\n }\n }\n\n // If we couldn't find a unique source file, stick with the resolved intermediate file as the only known truth.\n if (filePath && sourcePath === filePath) {\n sourcePath = undefined;\n }\n\n if (sourcePath) {\n filePath ??= sourceToIntermediatePath(sourcePath);\n\n typesPath = filePath && path.extname(filePath) === '.js' ? filePath.replace(/\\.js$/, '.d.ts') : undefined;\n }\n }\n\n const isNestedPackageDefinition =\n filePath && path.basename(filePath) === 'package.json' && path.basename(options.filePath) !== '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 typesPath = flattenExportsMap(exportsMap, { conditions: ['types'] })['.'];\n\n return {\n ...(await findFileInPackage(\n {\n packagePath,\n filePath: safeRelativePath(path.relative(packagePath, path.join(nestedDefinitionPath, entryPath))),\n },\n context,\n )),\n typesPath:\n typesPath && safeRelativePath(path.relative(packagePath, path.join(nestedDefinitionPath, typesPath))),\n };\n }\n }\n\n if (typesPath) {\n result.typesPath = safeRelativePath(typesPath);\n }\n\n if (filePath) {\n result.filePath = safeRelativePath(filePath);\n }\n\n if (sourcePath) {\n result.sourcePath = safeRelativePath(sourcePath);\n }\n\n return result;\n}\n"]}
1
+ {"version":3,"file":"findFileInPackage.js","sourceRoot":"","sources":["../src/findFileInPackage.ts"],"names":[],"mappings":"AAAA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C,CAAC;QAErD,IAAI,SAAS,EAAE;YACb,SAAS,GAAG,iBAAiB,CAAC,UAAU,EAAE,EAAE,UAAU,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC;YAE1E,OAAO;gBACL,GAAG,CAAC,MAAM,iBAAiB,CACzB;oBACE,WAAW;oBACX,QAAQ,EAAE,gBAAgB,CAAC,IAAI,CAAC,QAAQ,CAAC,WAAW,EAAE,IAAI,CAAC,IAAI,CAAC,oBAAoB,EAAE,SAAS,CAAC,CAAC,CAAC;iBACnG,EACD,OAAO,CACR,CAAC;gBACF,SAAS,EACP,SAAS,IAAI,gBAAgB,CAAC,IAAI,CAAC,QAAQ,CAAC,WAAW,EAAE,IAAI,CAAC,IAAI,CAAC,oBAAoB,EAAE,SAAS,CAAC,CAAC,CAAC;aACxG,CAAC;SACH;KACF;IAED,IAAI,SAAS,EAAE;QACb,MAAM,CAAC,SAAS,GAAG,gBAAgB,CAAC,SAAS,CAAC,CAAC;KAChD;IAED,IAAI,QAAQ,EAAE;QACZ,MAAM,CAAC,QAAQ,GAAG,gBAAgB,CAAC,QAAQ,CAAC,CAAC;KAC9C;IAED,IAAI,UAAU,EAAE;QACd,MAAM,CAAC,UAAU,GAAG,gBAAgB,CAAC,UAAU,CAAC,CAAC;KAClD;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import path from 'path';\nimport { intermediateToSourcePath, sourceToIntermediatePath, isFile } from '@ms-cloudpack/path-utilities';\nimport { isExternalPackage } from './isExternalPackage.js';\nimport { safeRelativePath } from '@ms-cloudpack/path-string-parsing';\nimport { getExportsMap } from './getExportsMap.js';\nimport { flattenExportsMap } from './flattenExportsMap.js';\nimport type { PackageDefinitionsCache } from '@ms-cloudpack/bundler-types';\n\nconst typescriptExtensions = ['.ts', '.tsx', '.cts', '.mts'];\n\nexport type FindFileInPackageOptions = {\n packagePath: string;\n filePath: string;\n};\n\nexport type FindFileInPackageResult = {\n filePath?: string;\n typesPath?: 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 */\n\nexport async function findFileInPackage(\n options: FindFileInPackageOptions,\n context: { packages: PackageDefinitionsCache },\n): Promise<FindFileInPackageResult> {\n const { packagePath } = options;\n let filePath: string | undefined = safeRelativePath(options.filePath);\n let sourcePath: string | undefined;\n let typesPath: string | undefined;\n const isInternal = !isExternalPackage(packagePath);\n const candidates = [\n filePath,\n filePath + '.js',\n filePath + '.mjs',\n filePath + '.cjs',\n safeRelativePath(path.join(filePath, 'index.js')),\n safeRelativePath(path.join(filePath, 'package.json')),\n ];\n\n filePath = undefined;\n for (const candidate of candidates) {\n if (await isFile(path.join(packagePath, candidate))) {\n filePath = candidate;\n break;\n }\n }\n\n // For internal packages, try and find source/typings and convert to intermediate (which may be missing.)\n if (isInternal) {\n for (const candidate of candidates) {\n sourcePath = intermediateToSourcePath(candidate, packagePath);\n if (sourcePath) {\n break;\n }\n }\n\n // If the discovered source file is the same as the provided file, resolve the intermediate path.\n if (sourcePath && (!filePath || sourcePath === filePath)) {\n filePath = sourceToIntermediatePath(sourcePath);\n }\n\n // If the sourcePath is the same as the filePath, clear it. By this point we should have resolved\n // the true intermediate path.\n if (sourcePath === filePath) {\n sourcePath = undefined;\n }\n\n if (sourcePath && typescriptExtensions.includes(path.extname(sourcePath))) {\n typesPath = filePath && path.extname(filePath) === '.js' ? filePath.replace(/\\.js$/, '.d.ts') : undefined;\n }\n }\n\n const isNestedPackageDefinition =\n filePath && path.basename(filePath) === 'package.json' && path.basename(options.filePath) !== '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 typesPath = flattenExportsMap(exportsMap, { conditions: ['types'] })['.'];\n\n return {\n ...(await findFileInPackage(\n {\n packagePath,\n filePath: safeRelativePath(path.relative(packagePath, path.join(nestedDefinitionPath, entryPath))),\n },\n context,\n )),\n typesPath:\n typesPath && safeRelativePath(path.relative(packagePath, path.join(nestedDefinitionPath, typesPath))),\n };\n }\n }\n\n if (typesPath) {\n result.typesPath = safeRelativePath(typesPath);\n }\n\n if (filePath) {\n result.filePath = safeRelativePath(filePath);\n }\n\n if (sourcePath) {\n result.sourcePath = safeRelativePath(sourcePath);\n }\n\n return result;\n}\n"]}
@@ -4,7 +4,7 @@ import type { PackageJson } from '@ms-cloudpack/bundler-types';
4
4
  /**
5
5
  * Helper which, given a definition/resolveMap/dependency name, returns the resolve map entry for the dependency.
6
6
  */
7
- export declare function findResolveMapEntry({ packageName, resolveMap, definition, version, }: {
7
+ export declare function findResolveMapEntry(params: {
8
8
  packageName: string;
9
9
  resolveMap: ResolveMap;
10
10
  version?: string;
@@ -1 +1 @@
1
- {"version":3,"file":"findResolveMapEntry.d.ts","sourceRoot":"","sources":["../src/findResolveMapEntry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAClE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAE/D;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,EAClC,WAAW,EACX,UAAU,EACV,UAAU,EACV,OAAO,GACR,EAAE;IACD,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,UAAU,CAAC;IACvB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,WAAW,CAAC;CAC1B,GAAG,eAAe,GAAG,SAAS,CA2B9B"}
1
+ {"version":3,"file":"findResolveMapEntry.d.ts","sourceRoot":"","sources":["../src/findResolveMapEntry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAClE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAE/D;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE;IAC1C,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,UAAU,CAAC;IACvB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,WAAW,CAAC;CAC1B,GAAG,eAAe,GAAG,SAAS,CAgC9B"}
@@ -1,7 +1,11 @@
1
1
  /**
2
2
  * Helper which, given a definition/resolveMap/dependency name, returns the resolve map entry for the dependency.
3
3
  */
4
- export function findResolveMapEntry({ packageName, resolveMap, definition, version, }) {
4
+ export function findResolveMapEntry(params) {
5
+ const { packageName, resolveMap, definition, version } = params;
6
+ if (!packageName) {
7
+ return undefined;
8
+ }
5
9
  const resolveEntry = resolveMap[packageName];
6
10
  if (!resolveEntry) {
7
11
  return undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"findResolveMapEntry.js","sourceRoot":"","sources":["../src/findResolveMapEntry.ts"],"names":[],"mappings":"AAIA;;GAEG;AACH,MAAM,UAAU,mBAAmB,CAAC,EAClC,WAAW,EACX,UAAU,EACV,UAAU,EACV,OAAO,GAMR;IACC,MAAM,YAAY,GAAG,UAAU,CAAC,WAAW,CAAC,CAAC;IAE7C,IAAI,CAAC,YAAY,EAAE;QACjB,OAAO,SAAS,CAAC;KAClB;IAED,IAAI,CAAC,UAAU,IAAI,CAAC,OAAO,EAAE;QAC3B,OAAO,YAAY,CAAC;KACrB;IAED,IAAI,OAAO,EAAE;QACX,IAAI,YAAY,CAAC,OAAO,KAAK,OAAO,EAAE;YACpC,OAAO,YAAY,CAAC;SACrB;QAED,OAAO,YAAY,CAAC,cAAc,EAAE,CAAC,OAAO,CAAC,CAAC;KAC/C;IAED,IAAI,UAAU,EAAE;QACd,MAAM,YAAY,GAA0B,GAAG,UAAU,CAAC,IAAI,IAAI,UAAU,CAAC,OAAO,EAAE,CAAC;QACvF,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC,cAAc,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC,CAAC;QAE/G,OAAO,WAAW,IAAI,YAAY,CAAC;KACpC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["import type { ResolveMap } from './types/ResolveMap.js';\nimport type { ResolveMapEntry } from './types/ResolveMapEntry.js';\nimport type { PackageJson } from '@ms-cloudpack/bundler-types';\n\n/**\n * Helper which, given a definition/resolveMap/dependency name, returns the resolve map entry for the dependency.\n */\nexport function findResolveMapEntry({\n packageName,\n resolveMap,\n definition,\n version,\n}: {\n packageName: string;\n resolveMap: ResolveMap;\n version?: string;\n definition?: PackageJson;\n}): ResolveMapEntry | undefined {\n const resolveEntry = resolveMap[packageName];\n\n if (!resolveEntry) {\n return undefined;\n }\n\n if (!definition && !version) {\n return resolveEntry;\n }\n\n if (version) {\n if (resolveEntry.version === version) {\n return resolveEntry;\n }\n\n return resolveEntry.scopedVersions?.[version];\n }\n\n if (definition) {\n const requiredById: `${string}@${string}` = `${definition.name}@${definition.version}`;\n const scopedEntry = Object.values(resolveEntry.scopedVersions || {}).find((e) => !!e.requiredBy[requiredById]);\n\n return scopedEntry || resolveEntry;\n }\n\n return undefined;\n}\n"]}
1
+ {"version":3,"file":"findResolveMapEntry.js","sourceRoot":"","sources":["../src/findResolveMapEntry.ts"],"names":[],"mappings":"AAIA;;GAEG;AACH,MAAM,UAAU,mBAAmB,CAAC,MAKnC;IACC,MAAM,EAAE,WAAW,EAAE,UAAU,EAAE,UAAU,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC;IAChE,IAAI,CAAC,WAAW,EAAE;QAChB,OAAO,SAAS,CAAC;KAClB;IAED,MAAM,YAAY,GAAG,UAAU,CAAC,WAAW,CAAC,CAAC;IAE7C,IAAI,CAAC,YAAY,EAAE;QACjB,OAAO,SAAS,CAAC;KAClB;IAED,IAAI,CAAC,UAAU,IAAI,CAAC,OAAO,EAAE;QAC3B,OAAO,YAAY,CAAC;KACrB;IAED,IAAI,OAAO,EAAE;QACX,IAAI,YAAY,CAAC,OAAO,KAAK,OAAO,EAAE;YACpC,OAAO,YAAY,CAAC;SACrB;QAED,OAAO,YAAY,CAAC,cAAc,EAAE,CAAC,OAAO,CAAC,CAAC;KAC/C;IAED,IAAI,UAAU,EAAE;QACd,MAAM,YAAY,GAA0B,GAAG,UAAU,CAAC,IAAI,IAAI,UAAU,CAAC,OAAO,EAAE,CAAC;QACvF,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC,cAAc,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC,CAAC;QAE/G,OAAO,WAAW,IAAI,YAAY,CAAC;KACpC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["import type { ResolveMap } from './types/ResolveMap.js';\nimport type { ResolveMapEntry } from './types/ResolveMapEntry.js';\nimport type { PackageJson } from '@ms-cloudpack/bundler-types';\n\n/**\n * Helper which, given a definition/resolveMap/dependency name, returns the resolve map entry for the dependency.\n */\nexport function findResolveMapEntry(params: {\n packageName: string;\n resolveMap: ResolveMap;\n version?: string;\n definition?: PackageJson;\n}): ResolveMapEntry | undefined {\n const { packageName, resolveMap, definition, version } = params;\n if (!packageName) {\n return undefined;\n }\n\n const resolveEntry = resolveMap[packageName];\n\n if (!resolveEntry) {\n return undefined;\n }\n\n if (!definition && !version) {\n return resolveEntry;\n }\n\n if (version) {\n if (resolveEntry.version === version) {\n return resolveEntry;\n }\n\n return resolveEntry.scopedVersions?.[version];\n }\n\n if (definition) {\n const requiredById: `${string}@${string}` = `${definition.name}@${definition.version}`;\n const scopedEntry = Object.values(resolveEntry.scopedVersions || {}).find((e) => !!e.requiredBy[requiredById]);\n\n return scopedEntry || resolveEntry;\n }\n\n return undefined;\n}\n"]}
package/lib/getVersion.js CHANGED
@@ -15,7 +15,7 @@ export function getVersion(importUrl) {
15
15
  let version = `0.0.0-local ${packagePath}`;
16
16
  if (packagePath && isExternalPackage(packagePath)) {
17
17
  const packageJSONpath = path.join(packagePath, 'package.json');
18
- // eslint-disable-next-line no-restricted-syntax
18
+ // eslint-disable-next-line @ms-cloudpack/internal/no-sync-filesystem
19
19
  version = readJsonSync(packageJSONpath).version || version;
20
20
  }
21
21
  return version;
@@ -1 +1 @@
1
- {"version":3,"file":"getVersion.js","sourceRoot":"","sources":["../src/getVersion.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AACpC,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAE3D;;;;;;GAMG;AACH,MAAM,UAAU,UAAU,CAAC,SAAiB;IAC1C,MAAM,WAAW,GAAG,eAAe,CAAC,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;IAC5E,IAAI,OAAO,GAAG,eAAe,WAAW,EAAE,CAAC;IAE3C,IAAI,WAAW,IAAI,iBAAiB,CAAC,WAAW,CAAC,EAAE;QACjD,MAAM,eAAe,GAAG,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,cAAc,CAAC,CAAC;QAE/D,gDAAgD;QAChD,OAAO,GAAI,YAAY,CAAC,eAAe,CAAiB,CAAC,OAAO,IAAI,OAAO,CAAC;KAC7E;IAED,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import type { PackageJson } from '@ms-cloudpack/bundler-types';\nimport { readJsonSync } from '@ms-cloudpack/json-utilities';\nimport { findPackageRoot } from '@ms-cloudpack/path-utilities';\nimport path from 'path';\nimport { fileURLToPath } from 'url';\nimport { isExternalPackage } from './isExternalPackage.js';\n\n/**\n * Returns the displayable version of the package which contains the import url provided. If the package\n * is a local package rather than a node_modules external package, we display the version as \"0.0.0-local\"\n * with the path following it.\n * @param importUrl - import.meta.url\n * @returns - the version of the package. If the package is not in node_modules, it returns \"0.0.0-local\".\n */\nexport function getVersion(importUrl: string): string {\n const packagePath = findPackageRoot(path.dirname(fileURLToPath(importUrl)));\n let version = `0.0.0-local ${packagePath}`;\n\n if (packagePath && isExternalPackage(packagePath)) {\n const packageJSONpath = path.join(packagePath, 'package.json');\n\n // eslint-disable-next-line no-restricted-syntax\n version = (readJsonSync(packageJSONpath) as PackageJson).version || version;\n }\n\n return version;\n}\n"]}
1
+ {"version":3,"file":"getVersion.js","sourceRoot":"","sources":["../src/getVersion.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AACpC,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAE3D;;;;;;GAMG;AACH,MAAM,UAAU,UAAU,CAAC,SAAiB;IAC1C,MAAM,WAAW,GAAG,eAAe,CAAC,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;IAC5E,IAAI,OAAO,GAAG,eAAe,WAAW,EAAE,CAAC;IAE3C,IAAI,WAAW,IAAI,iBAAiB,CAAC,WAAW,CAAC,EAAE;QACjD,MAAM,eAAe,GAAG,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,cAAc,CAAC,CAAC;QAE/D,qEAAqE;QACrE,OAAO,GAAI,YAAY,CAAC,eAAe,CAAiB,CAAC,OAAO,IAAI,OAAO,CAAC;KAC7E;IAED,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import type { PackageJson } from '@ms-cloudpack/bundler-types';\nimport { readJsonSync } from '@ms-cloudpack/json-utilities';\nimport { findPackageRoot } from '@ms-cloudpack/path-utilities';\nimport path from 'path';\nimport { fileURLToPath } from 'url';\nimport { isExternalPackage } from './isExternalPackage.js';\n\n/**\n * Returns the displayable version of the package which contains the import url provided. If the package\n * is a local package rather than a node_modules external package, we display the version as \"0.0.0-local\"\n * with the path following it.\n * @param importUrl - import.meta.url\n * @returns - the version of the package. If the package is not in node_modules, it returns \"0.0.0-local\".\n */\nexport function getVersion(importUrl: string): string {\n const packagePath = findPackageRoot(path.dirname(fileURLToPath(importUrl)));\n let version = `0.0.0-local ${packagePath}`;\n\n if (packagePath && isExternalPackage(packagePath)) {\n const packageJSONpath = path.join(packagePath, 'package.json');\n\n // eslint-disable-next-line @ms-cloudpack/internal/no-sync-filesystem\n version = (readJsonSync(packageJSONpath) as PackageJson).version || version;\n }\n\n return version;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ms-cloudpack/package-utilities",
3
- "version": "5.1.7",
3
+ "version": "5.1.9",
4
4
  "description": "Utilities for resolving/parsing packages and their imports.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -16,13 +16,13 @@
16
16
  "@ms-cloudpack/bundler-types": "^0.19.1",
17
17
  "@ms-cloudpack/json-utilities": "^0.0.7",
18
18
  "@ms-cloudpack/package-overrides": "^0.4.4",
19
- "@ms-cloudpack/path-utilities": "^2.3.2",
20
- "@ms-cloudpack/path-string-parsing": "^1.0.3",
19
+ "@ms-cloudpack/path-utilities": "^2.3.4",
20
+ "@ms-cloudpack/path-string-parsing": "^1.1.0",
21
21
  "fast-glob": "^3.2.12",
22
22
  "merge": "^2.1.1",
23
23
  "resolve": "^1.22.0",
24
24
  "semver": "^7.3.7",
25
- "workspace-tools": "^0.35.1"
25
+ "workspace-tools": "^0.35.2"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@ms-cloudpack/eslint-plugin-internal": "*",