@ms-cloudpack/package-utilities 5.1.2 → 5.1.3

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.
Files changed (52) hide show
  1. package/lib/addExportsMapEntry.d.ts.map +1 -1
  2. package/lib/addExportsMapEntry.js +24 -23
  3. package/lib/addExportsMapEntry.js.map +1 -1
  4. package/lib/createResolveMap/addLinkedEntryDependencies.d.ts +0 -1
  5. package/lib/createResolveMap/addLinkedEntryDependencies.d.ts.map +1 -1
  6. package/lib/createResolveMap/addLinkedEntryDependencies.js +48 -54
  7. package/lib/createResolveMap/addLinkedEntryDependencies.js.map +1 -1
  8. package/lib/createResolveMap/convertToResolveMap.d.ts +1 -1
  9. package/lib/createResolveMap/convertToResolveMap.d.ts.map +1 -1
  10. package/lib/createResolveMap/convertToResolveMap.js +2 -2
  11. package/lib/createResolveMap/convertToResolveMap.js.map +1 -1
  12. package/lib/createResolveMap/createResolveMap.d.ts +9 -8
  13. package/lib/createResolveMap/createResolveMap.d.ts.map +1 -1
  14. package/lib/createResolveMap/createResolveMap.js +11 -10
  15. package/lib/createResolveMap/createResolveMap.js.map +1 -1
  16. package/lib/createResolveMap/detachEntry.d.ts.map +1 -1
  17. package/lib/createResolveMap/detachEntry.js +21 -21
  18. package/lib/createResolveMap/detachEntry.js.map +1 -1
  19. package/lib/createResolveMap/findPackagesFromPath.d.ts +1 -1
  20. package/lib/createResolveMap/findPackagesFromPath.d.ts.map +1 -1
  21. package/lib/createResolveMap/findPackagesFromPath.js +85 -62
  22. package/lib/createResolveMap/findPackagesFromPath.js.map +1 -1
  23. package/lib/createResolveMap/linkPath.d.ts.map +1 -1
  24. package/lib/createResolveMap/linkPath.js +5 -7
  25. package/lib/createResolveMap/linkPath.js.map +1 -1
  26. package/lib/createResolveMap/parseRequiredBy.d.ts +4 -1
  27. package/lib/createResolveMap/parseRequiredBy.d.ts.map +1 -1
  28. package/lib/createResolveMap/parseRequiredBy.js +1 -1
  29. package/lib/createResolveMap/parseRequiredBy.js.map +1 -1
  30. package/lib/findFileInPackage.d.ts.map +1 -1
  31. package/lib/findFileInPackage.js +1 -3
  32. package/lib/findFileInPackage.js.map +1 -1
  33. package/lib/findPackage.d.ts +16 -0
  34. package/lib/findPackage.d.ts.map +1 -0
  35. package/lib/{findPackagePath.js → findPackage.js} +7 -3
  36. package/lib/findPackage.js.map +1 -0
  37. package/lib/getExportPathFromEntry.d.ts.map +1 -1
  38. package/lib/getExportPathFromEntry.js +2 -2
  39. package/lib/getExportPathFromEntry.js.map +1 -1
  40. package/lib/isExternalPackage.js +1 -1
  41. package/lib/isExternalPackage.js.map +1 -1
  42. package/lib/tsdoc-metadata.json +1 -1
  43. package/lib/types/PackageMap.d.ts +4 -0
  44. package/lib/types/PackageMap.d.ts.map +1 -1
  45. package/lib/types/PackageMap.js.map +1 -1
  46. package/lib/types/ResolveMapEntry.d.ts +28 -1
  47. package/lib/types/ResolveMapEntry.d.ts.map +1 -1
  48. package/lib/types/ResolveMapEntry.js.map +1 -1
  49. package/package.json +1 -1
  50. package/lib/findPackagePath.d.ts +0 -9
  51. package/lib/findPackagePath.d.ts.map +0 -1
  52. package/lib/findPackagePath.js.map +0 -1
@@ -1,98 +1,121 @@
1
1
  import { isFolder } from '@ms-cloudpack/path-utilities';
2
2
  import glob from 'fast-glob';
3
- import { dirname, join } from 'path';
3
+ import path from 'path';
4
4
  import { findGitRoot } from 'workspace-tools';
5
- import { findPackagePath } from '../findPackagePath.js';
5
+ import { findPackage } from '../findPackage.js';
6
6
  import { isExternalPackage } from '../isExternalPackage.js';
7
7
  /**
8
8
  * Find all packages from a given path. We do this by walking the dependency tree
9
9
  * of the app to build a map of all packages and their dependencies.
10
10
  */
11
11
  export async function findPackagesFromPath(options, context) {
12
- const { paths, discoverPackages } = options;
13
- const { packages } = context;
12
+ const { searchPaths, discoverPackages } = options;
14
13
  const packageMap = {};
15
14
  const visitedPaths = new Set();
16
- const pathsToVisit = [];
17
- for (const path of paths) {
18
- if (!(await isFolder(path))) {
19
- throw new Error(`Path ${path} is not a folder.`);
15
+ for (const searchPath of searchPaths) {
16
+ if (!(await isFolder(searchPath))) {
17
+ throw new Error(`Path ${searchPath} is not a folder.`);
20
18
  }
21
19
  let { gitRootPath } = options;
22
20
  if (!gitRootPath) {
23
21
  try {
24
- gitRootPath = findGitRoot(path);
22
+ gitRootPath = findGitRoot(searchPath);
25
23
  }
26
24
  catch (e) {
27
25
  /* ignore */
28
26
  }
29
27
  }
28
+ const pathsToVisit = [];
30
29
  if (discoverPackages) {
31
- const packagePaths = await glob('**/package.json', { cwd: path, ignore: ['**/node_modules/**'] });
32
- pathsToVisit.push(...packagePaths.map((p) => dirname(join(path, p))));
30
+ const packagePaths = await glob('**/package.json', { cwd: searchPath, ignore: ['**/node_modules/**'] });
31
+ pathsToVisit.push(...packagePaths.map((p) => path.dirname(path.join(searchPath, p))));
33
32
  }
34
33
  else {
35
- pathsToVisit.push(path);
34
+ pathsToVisit.push(searchPath);
36
35
  }
37
36
  while (pathsToVisit.length) {
37
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- already checked length
38
38
  const packagePath = pathsToVisit.shift();
39
- if (packagePath && !visitedPaths.has(packagePath)) {
39
+ if (!visitedPaths.has(packagePath)) {
40
40
  visitedPaths.add(packagePath);
41
- const packageDefinition = await packages.get(packagePath);
42
- if (!packageDefinition) {
43
- throw new Error(`Could not find package definition at "${packagePath}".`);
44
- }
45
- if (packageDefinition?.name && packageDefinition.version) {
46
- const { name, version } = packageDefinition;
47
- const entry = initPackageEntry({ path: packagePath, packageMap, definition: packageDefinition });
48
- // Add all dependencies to the list of paths to visit.
49
- const dependencies = {
50
- ...(packageDefinition.dependencies || {}),
51
- ...(packageDefinition.peerDependencies || {}),
52
- };
53
- for (const [dependencyName, versionRequirement] of Object.entries(dependencies)) {
54
- const isPeerDependency = !!packageDefinition.peerDependencies?.[dependencyName];
55
- const dependencyPath = await findPackagePath({
56
- dependencyName,
57
- startPath: packagePath,
58
- gitRootPath,
59
- }, context);
60
- if (dependencyPath) {
61
- const dependencyDefinition = await packages.get(dependencyPath);
62
- if (dependencyDefinition?.name && dependencyDefinition.version) {
63
- const dependencyEntry = initPackageEntry({
64
- path: dependencyPath,
65
- packageMap,
66
- definition: dependencyDefinition,
67
- });
68
- entry.dependencies[dependencyDefinition.name] = dependencyDefinition.version;
69
- dependencyEntry.requiredBy[`${name}@${version}`] = versionRequirement;
70
- pathsToVisit.push(dependencyPath);
71
- }
72
- }
73
- else if (!isPeerDependency) {
74
- throw new Error(`Could not find dependency "${dependencyName}" at "${packagePath}" with version requirement "${versionRequirement}".`);
75
- }
76
- }
77
- }
41
+ const dependencyPaths = await visitPackage({ packagePath, packageMap, gitRootPath }, context);
42
+ pathsToVisit.push(...dependencyPaths);
78
43
  }
79
44
  }
80
45
  }
81
46
  return packageMap;
82
47
  }
83
- function initPackageEntry(options) {
84
- const { path = '', packageMap, definition } = options;
48
+ /**
49
+ * Visit a package path, and add entries for the package and its dependencies to `packageMap`.
50
+ * Returns a list of additional dependency paths to visit.
51
+ */
52
+ async function visitPackage(options, context) {
53
+ const { packagePath, packageMap, gitRootPath } = options;
54
+ const { packages } = context;
55
+ const packageDefinition = await packages.get(packagePath);
56
+ if (!packageDefinition) {
57
+ throw new Error(`Could not find package definition at "${packagePath}".`);
58
+ }
59
+ if (!(packageDefinition.name && packageDefinition.version)) {
60
+ return [];
61
+ }
62
+ const { name, version } = packageDefinition;
63
+ const entry = ensurePackageEntry({ packagePath: packagePath, packageMap, definition: packageDefinition });
64
+ // Add all dependencies to the list of paths to visit.
65
+ const dependencies = {
66
+ ...(packageDefinition.dependencies || {}),
67
+ ...(packageDefinition.peerDependencies || {}),
68
+ };
69
+ const dependencyPaths = [];
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);
87
+ }
88
+ else {
89
+ throw new Error(`"${dependencyPath}/package.json" is missing a name or version.`);
90
+ }
91
+ }
92
+ else if (!isPeerDependency) {
93
+ throw new Error(`Could not find dependency "${dependencyName}" at "${packagePath}".`);
94
+ }
95
+ // Ignore missing peer dependencies
96
+ }
97
+ return dependencyPaths;
98
+ }
99
+ /**
100
+ * If `packageMap` doesn't already have an entry for this package name and version, create one
101
+ * and add it to `packageMap`. Returns the entry.
102
+ */
103
+ function ensurePackageEntry(options) {
104
+ const { packagePath = '', packageMap, definition } = options;
85
105
  const { name = '_no_name_', version = '*' } = definition;
86
- const mapEntry = (packageMap[name] ??= {});
87
- const entry = (mapEntry[version] ??= {
88
- name,
89
- version,
90
- path,
91
- dependencies: {},
92
- requiredBy: {},
93
- });
94
- if (isExternalPackage(path)) {
95
- entry.isExternal = true;
106
+ packageMap[name] ??= {};
107
+ let entry = packageMap[name][version];
108
+ if (!entry) {
109
+ entry = packageMap[name][version] = {
110
+ name,
111
+ version,
112
+ path: packagePath,
113
+ dependencies: {},
114
+ requiredBy: {},
115
+ };
116
+ if (isExternalPackage(packagePath)) {
117
+ entry.isExternal = true;
118
+ }
96
119
  }
97
120
  return entry;
98
121
  }
@@ -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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U,GAAG,IAAI,CAAC;KACzB;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 { dirname, join } from 'path';\nimport { findGitRoot } from 'workspace-tools';\nimport { findPackagePath } from '../findPackagePath.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 paths: 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 { paths, discoverPackages } = options;\n const { packages } = context;\n const packageMap: PackageMap = {};\n const visitedPaths = new Set<string>();\n const pathsToVisit: string[] = [];\n\n for (const path of paths) {\n if (!(await isFolder(path))) {\n throw new Error(`Path ${path} is not a folder.`);\n }\n\n let { gitRootPath } = options;\n\n if (!gitRootPath) {\n try {\n gitRootPath = findGitRoot(path);\n } catch (e) {\n /* ignore */\n }\n }\n\n if (discoverPackages) {\n const packagePaths = await glob('**/package.json', { cwd: path, ignore: ['**/node_modules/**'] });\n\n pathsToVisit.push(...packagePaths.map((p) => dirname(join(path, p))));\n } else {\n pathsToVisit.push(path);\n }\n\n while (pathsToVisit.length) {\n const packagePath = pathsToVisit.shift();\n\n if (packagePath && !visitedPaths.has(packagePath)) {\n visitedPaths.add(packagePath);\n\n const packageDefinition = await packages.get(packagePath);\n\n if (!packageDefinition) {\n throw new Error(`Could not find package definition at \"${packagePath}\".`);\n }\n\n if (packageDefinition?.name && packageDefinition.version) {\n const { name, version } = packageDefinition;\n const entry = initPackageEntry({ path: 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 for (const [dependencyName, versionRequirement] of Object.entries(dependencies)) {\n const isPeerDependency = !!packageDefinition.peerDependencies?.[dependencyName];\n\n const dependencyPath = await findPackagePath(\n {\n dependencyName,\n startPath: packagePath,\n gitRootPath,\n },\n context,\n );\n\n if (dependencyPath) {\n const dependencyDefinition = await packages.get(dependencyPath);\n if (dependencyDefinition?.name && dependencyDefinition.version) {\n const dependencyEntry = initPackageEntry({\n path: dependencyPath,\n packageMap,\n definition: dependencyDefinition,\n });\n\n entry.dependencies[dependencyDefinition.name] = dependencyDefinition.version;\n dependencyEntry.requiredBy[`${name}@${version}`] = versionRequirement;\n\n pathsToVisit.push(dependencyPath);\n }\n } else if (!isPeerDependency) {\n throw new Error(\n `Could not find dependency \"${dependencyName}\" at \"${packagePath}\" with version requirement \"${versionRequirement}\".`,\n );\n }\n }\n }\n }\n }\n }\n\n return packageMap;\n}\n\nfunction initPackageEntry(options: { path: string; packageMap: PackageMap; definition: PackageJson }): ResolveMapEntry {\n const { path = '', packageMap, definition } = options;\n const { name = '_no_name_', version = '*' } = definition;\n\n const mapEntry = (packageMap[name] ??= {}) as Record<string, ResolveMapEntry>;\n const entry = (mapEntry[version] ??= {\n name,\n version,\n path,\n dependencies: {},\n requiredBy: {},\n });\n\n if (isExternalPackage(path)) {\n entry.isExternal = true;\n }\n\n return entry;\n}\n"]}
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,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AM,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 +1 @@
1
- {"version":3,"file":"linkPath.d.ts","sourceRoot":"","sources":["../../src/createResolveMap/linkPath.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAOzD,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAE3E;;GAEG;AACH,wBAAsB,QAAQ,CAC5B,OAAO,EAAE;IACP,UAAU,EAAE,UAAU,CAAC;IACvB,MAAM,EAAE,UAAU,CAAC;CACpB,EACD,OAAO,EAAE;IACP,QAAQ,EAAE,uBAAuB,CAAC;CACnC,iBA2FF"}
1
+ {"version":3,"file":"linkPath.d.ts","sourceRoot":"","sources":["../../src/createResolveMap/linkPath.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAOzD,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAE3E;;GAEG;AACH,wBAAsB,QAAQ,CAC5B,OAAO,EAAE;IACP,UAAU,EAAE,UAAU,CAAC;IACvB,MAAM,EAAE,UAAU,CAAC;CACpB,EACD,OAAO,EAAE;IACP,QAAQ,EAAE,uBAAuB,CAAC;CACnC,iBAyFF"}
@@ -9,7 +9,7 @@ import { slash } from '@ms-cloudpack/path-string-parsing';
9
9
  export async function linkPath(options, context) {
10
10
  const { linkedPath, appMap } = options;
11
11
  const linkMap = await findPackagesFromPath({
12
- paths: [linkedPath.path],
12
+ searchPaths: [linkedPath.path],
13
13
  discoverPackages: true,
14
14
  }, context);
15
15
  const entriesToLink = [];
@@ -42,7 +42,7 @@ export async function linkPath(options, context) {
42
42
  linkedEntry.requiredBy = {};
43
43
  for (const entry of existingEntries) {
44
44
  for (const [requiredById, requirement] of Object.entries(entry.requiredBy)) {
45
- const [requiredByName] = parseRequiredBy(requiredById);
45
+ const requiredByName = parseRequiredBy(requiredById).name;
46
46
  const linkedParentEntry = Object.values(linkMap[requiredByName] || {})[0];
47
47
  const requiredByKey = linkedParentEntry?.isLinked
48
48
  ? `${linkedParentEntry.name}@${linkedParentEntry.version}`
@@ -62,13 +62,11 @@ export async function linkPath(options, context) {
62
62
  }
63
63
  // Attach the linked entry to the parents' dependencies.
64
64
  for (const requiredById of Object.keys(linkedEntry.requiredBy)) {
65
- const [requiredByName, requiredByVersion] = parseRequiredBy(requiredById);
65
+ const { name: requiredByName, version: requiredByVersion } = parseRequiredBy(requiredById);
66
66
  let requiredByEntry = appMap[requiredByName][requiredByVersion];
67
67
  // If we can't find the requiredBy entry, it likely means that the entry was already replaced with a linked entry
68
68
  // in the app map. Fall back to the first entry.
69
- if (!requiredByEntry) {
70
- requiredByEntry = Object.values(appMap[requiredByName])[0];
71
- }
69
+ requiredByEntry ??= Object.values(appMap[requiredByName])[0];
72
70
  requiredByEntry.dependencies[name] = linkedEntry.version;
73
71
  }
74
72
  // Add the linked entry
@@ -82,7 +80,7 @@ export async function linkPath(options, context) {
82
80
  function isContainedInPath(path, basePath) {
83
81
  path = normalizePath(path);
84
82
  basePath = normalizePath(basePath);
85
- return path.indexOf(basePath) === 0;
83
+ return path.startsWith(basePath);
86
84
  }
87
85
  function normalizePath(path) {
88
86
  let normalizedPath = slash(path);
@@ -1 +1 @@
1
- {"version":3,"file":"linkPath.js","sourceRoot":"","sources":["../../src/createResolveMap/linkPath.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,0BAA0B,EAAE,MAAM,iCAAiC,CAAC;AAC7E,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,KAAK,EAAE,MAAM,mCAAmC,CAAC;AAG1D;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,QAAQ,CAC5B,OAGC,EACD,OAEC;IAED,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;IACvC,MAAM,OAAO,GAAG,MAAM,oBAAoB,CACxC;QACE,KAAK,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC;QACxB,gBAAgB,EAAE,IAAI;KACvB,EACD,OAAO,CACR,CAAC;IACF,MAAM,aAAa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C,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;aAC5D;YAED,eAAe,CAAC,YAAY,CAAC,IAAI,CAAC,GAAG,WAAW,CAAC,OAAO,CAAC;SAC1D;QAED,uBAAuB;QACvB,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,WAAW,CAAC,OAAO,CAAC,EAAE,WAAW,EAAE,CAAC;KACnE;IAED,mFAAmF;IACnF,KAAK,MAAM,WAAW,IAAI,aAAa,EAAE;QACvC,MAAM,0BAA0B,CAAC,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,OAAO,CAAC,CAAC;KACrF;AACH,CAAC;AAED,SAAS,iBAAiB,CAAC,IAAY,EAAE,QAAgB;IACvD,IAAI,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC;IAC3B,QAAQ,GAAG,aAAa,CAAC,QAAQ,CAAC,CAAC;IAEnC,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AACtC,CAAC;AAED,SAAS,aAAa,CAAC,IAAY;IACjC,IAAI,cAAc,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC;IAEjC,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;QACjC,cAAc,IAAI,GAAG,CAAC;KACvB;IAED,OAAO,cAAc,CAAC;AACxB,CAAC","sourcesContent":["import type { LinkedPath } from '../types/LinkedPath.js';\nimport type { PackageMap } from '../types/PackageMap.js';\nimport type { ResolveMapEntry } from '../types/ResolveMapEntry.js';\nimport { addLinkedEntryDependencies } from './addLinkedEntryDependencies.js';\nimport { detachEntry } from './detachEntry.js';\nimport { findPackagesFromPath } from './findPackagesFromPath.js';\nimport { parseRequiredBy } from './parseRequiredBy.js';\nimport { slash } from '@ms-cloudpack/path-string-parsing';\nimport type { PackageDefinitionsCache } from '@ms-cloudpack/bundler-types';\n\n/**\n * Given a linked path, an appMap, find packages from the linked path and add them to the appMap.\n */\nexport async function linkPath(\n options: {\n linkedPath: LinkedPath;\n appMap: PackageMap;\n },\n context: {\n packages: PackageDefinitionsCache;\n },\n) {\n const { linkedPath, appMap } = options;\n const linkMap = await findPackagesFromPath(\n {\n paths: [linkedPath.path],\n discoverPackages: true,\n },\n context,\n );\n const entriesToLink: ResolveMapEntry[] = [];\n const { path, ignoredPackages = [], includeAll } = linkedPath;\n\n // Iterate through the linkMap, looking for internal packages to link to the appMap.\n for (const [packageName, packageVersions] of Object.entries(linkMap)) {\n const appEntries = Object.values(appMap[packageName] || {});\n\n if (appEntries.length) {\n const linkedEntries = Object.values(packageVersions);\n const linkedEntry = linkedEntries.length === 1 ? linkedEntries[0] : undefined;\n\n // For linked dependencies, we don't want multiple versions referenced. Remove them\n // all and add them in a second pass.\n if (\n linkedEntry &&\n !linkedEntry.isExternal &&\n ignoredPackages.indexOf(packageName) === -1 &&\n (includeAll || isContainedInPath(linkedEntry.path, path))\n ) {\n // Linked packages use an asterisk for the version description. This keeps it semver compatible with\n // anything.\n linkedEntry.version += '-linked';\n linkedEntry.isLinked = true;\n\n entriesToLink.push(linkedEntry);\n }\n }\n }\n\n // We now have a list of paths to link. Iterate through them, add them to the appMap,\n // and ensure their dependencies are satisfied.\n for (const linkedEntry of entriesToLink) {\n const { name } = linkedEntry;\n const existingEntries = Object.values(appMap[name]);\n\n linkedEntry.requiredBy = {};\n for (const entry of existingEntries) {\n for (const [requiredById, requirement] of Object.entries(entry.requiredBy)) {\n const [requiredByName] = parseRequiredBy(requiredById);\n const linkedParentEntry = Object.values(linkMap[requiredByName] || {})[0];\n const requiredByKey = linkedParentEntry?.isLinked\n ? (`${linkedParentEntry.name}@${linkedParentEntry.version}` as const)\n : requiredById;\n linkedEntry.requiredBy[requiredByKey as `${string}@${string}`] = requirement;\n }\n }\n }\n\n for (const linkedEntry of entriesToLink) {\n const { name } = linkedEntry;\n const existingEntries = Object.values(appMap[name]);\n\n // We need to detach all existing entries from the appMap, along with their dependences. Note - detaching just means that\n // we disconnect the entry from its parent and children. If the children have no other parents, we disconnect them as well\n // and recurse through their children.\n for (const existingEntry of existingEntries) {\n detachEntry({ appMap, entry: existingEntry });\n }\n\n // Attach the linked entry to the parents' dependencies.\n for (const requiredById of Object.keys(linkedEntry.requiredBy)) {\n const [requiredByName, requiredByVersion] = parseRequiredBy(requiredById);\n let requiredByEntry = appMap[requiredByName][requiredByVersion];\n\n // If we can't find the requiredBy entry, it likely means that the entry was already replaced with a linked entry\n // in the app map. Fall back to the first entry.\n if (!requiredByEntry) {\n requiredByEntry = Object.values(appMap[requiredByName])[0];\n }\n\n requiredByEntry.dependencies[name] = linkedEntry.version;\n }\n\n // Add the linked entry\n appMap[linkedEntry.name] = { [linkedEntry.version]: linkedEntry };\n }\n\n // Once all linked entries have been added, ensure their dependencies are resolved.\n for (const linkedEntry of entriesToLink) {\n await addLinkedEntryDependencies({ linkedEntry, appMap: appMap, linkMap }, context);\n }\n}\n\nfunction isContainedInPath(path: string, basePath: string) {\n path = normalizePath(path);\n basePath = normalizePath(basePath);\n\n return path.indexOf(basePath) === 0;\n}\n\nfunction normalizePath(path: string) {\n let normalizedPath = slash(path);\n\n if (!normalizedPath.endsWith('/')) {\n normalizedPath += '/';\n }\n\n return normalizedPath;\n}\n"]}
1
+ {"version":3,"file":"linkPath.js","sourceRoot":"","sources":["../../src/createResolveMap/linkPath.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,0BAA0B,EAAE,MAAM,iCAAiC,CAAC;AAC7E,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,KAAK,EAAE,MAAM,mCAAmC,CAAC;AAG1D;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,QAAQ,CAC5B,OAGC,EACD,OAEC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I,EAAE,cAAc,EAAE,OAAO,EAAE,iBAAiB,EAAE,GAAG,eAAe,CAAC,YAAY,CAAC,CAAC;YAC3F,IAAI,eAAe,GAAG,MAAM,CAAC,cAAc,CAAC,CAAC,iBAAiB,CAAC,CAAC;YAEhE,iHAAiH;YACjH,gDAAgD;YAChD,eAAe,KAAK,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YAE7D,eAAe,CAAC,YAAY,CAAC,IAAI,CAAC,GAAG,WAAW,CAAC,OAAO,CAAC;SAC1D;QAED,uBAAuB;QACvB,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,WAAW,CAAC,OAAO,CAAC,EAAE,WAAW,EAAE,CAAC;KACnE;IAED,mFAAmF;IACnF,KAAK,MAAM,WAAW,IAAI,aAAa,EAAE;QACvC,MAAM,0BAA0B,CAAC,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,OAAO,CAAC,CAAC;KACrF;AACH,CAAC;AAED,SAAS,iBAAiB,CAAC,IAAY,EAAE,QAAgB;IACvD,IAAI,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC;IAC3B,QAAQ,GAAG,aAAa,CAAC,QAAQ,CAAC,CAAC;IAEnC,OAAO,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;AACnC,CAAC;AAED,SAAS,aAAa,CAAC,IAAY;IACjC,IAAI,cAAc,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC;IAEjC,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;QACjC,cAAc,IAAI,GAAG,CAAC;KACvB;IAED,OAAO,cAAc,CAAC;AACxB,CAAC","sourcesContent":["import type { LinkedPath } from '../types/LinkedPath.js';\nimport type { PackageMap } from '../types/PackageMap.js';\nimport type { ResolveMapEntry } from '../types/ResolveMapEntry.js';\nimport { addLinkedEntryDependencies } from './addLinkedEntryDependencies.js';\nimport { detachEntry } from './detachEntry.js';\nimport { findPackagesFromPath } from './findPackagesFromPath.js';\nimport { parseRequiredBy } from './parseRequiredBy.js';\nimport { slash } from '@ms-cloudpack/path-string-parsing';\nimport type { PackageDefinitionsCache } from '@ms-cloudpack/bundler-types';\n\n/**\n * Given a linked path, an appMap, find packages from the linked path and add them to the appMap.\n */\nexport async function linkPath(\n options: {\n linkedPath: LinkedPath;\n appMap: PackageMap;\n },\n context: {\n packages: PackageDefinitionsCache;\n },\n) {\n const { linkedPath, appMap } = options;\n const linkMap = await findPackagesFromPath(\n {\n searchPaths: [linkedPath.path],\n discoverPackages: true,\n },\n context,\n );\n const entriesToLink: ResolveMapEntry[] = [];\n const { path, ignoredPackages = [], includeAll } = linkedPath;\n\n // Iterate through the linkMap, looking for internal packages to link to the appMap.\n for (const [packageName, packageVersions] of Object.entries(linkMap)) {\n const appEntries = Object.values(appMap[packageName] || {});\n\n if (appEntries.length) {\n const linkedEntries = Object.values(packageVersions);\n const linkedEntry = linkedEntries.length === 1 ? linkedEntries[0] : undefined;\n\n // For linked dependencies, we don't want multiple versions referenced. Remove them\n // all and add them in a second pass.\n if (\n linkedEntry &&\n !linkedEntry.isExternal &&\n ignoredPackages.indexOf(packageName) === -1 &&\n (includeAll || isContainedInPath(linkedEntry.path, path))\n ) {\n // Linked packages use an asterisk for the version description. This keeps it semver compatible with\n // anything.\n linkedEntry.version += '-linked';\n linkedEntry.isLinked = true;\n\n entriesToLink.push(linkedEntry);\n }\n }\n }\n\n // We now have a list of paths to link. Iterate through them, add them to the appMap,\n // and ensure their dependencies are satisfied.\n for (const linkedEntry of entriesToLink) {\n const { name } = linkedEntry;\n const existingEntries = Object.values(appMap[name]);\n\n linkedEntry.requiredBy = {};\n for (const entry of existingEntries) {\n for (const [requiredById, requirement] of Object.entries(entry.requiredBy)) {\n const requiredByName = parseRequiredBy(requiredById).name;\n const linkedParentEntry = Object.values(linkMap[requiredByName] || {})[0];\n const requiredByKey = linkedParentEntry?.isLinked\n ? (`${linkedParentEntry.name}@${linkedParentEntry.version}` as const)\n : requiredById;\n linkedEntry.requiredBy[requiredByKey as `${string}@${string}`] = requirement;\n }\n }\n }\n\n for (const linkedEntry of entriesToLink) {\n const { name } = linkedEntry;\n const existingEntries = Object.values(appMap[name]);\n\n // We need to detach all existing entries from the appMap, along with their dependences. Note - detaching just means that\n // we disconnect the entry from its parent and children. If the children have no other parents, we disconnect them as well\n // and recurse through their children.\n for (const existingEntry of existingEntries) {\n detachEntry({ appMap, entry: existingEntry });\n }\n\n // Attach the linked entry to the parents' dependencies.\n for (const requiredById of Object.keys(linkedEntry.requiredBy)) {\n const { name: requiredByName, version: requiredByVersion } = parseRequiredBy(requiredById);\n let requiredByEntry = appMap[requiredByName][requiredByVersion];\n\n // If we can't find the requiredBy entry, it likely means that the entry was already replaced with a linked entry\n // in the app map. Fall back to the first entry.\n requiredByEntry ??= Object.values(appMap[requiredByName])[0];\n\n requiredByEntry.dependencies[name] = linkedEntry.version;\n }\n\n // Add the linked entry\n appMap[linkedEntry.name] = { [linkedEntry.version]: linkedEntry };\n }\n\n // Once all linked entries have been added, ensure their dependencies are resolved.\n for (const linkedEntry of entriesToLink) {\n await addLinkedEntryDependencies({ linkedEntry, appMap: appMap, linkMap }, context);\n }\n}\n\nfunction isContainedInPath(path: string, basePath: string) {\n path = normalizePath(path);\n basePath = normalizePath(basePath);\n\n return path.startsWith(basePath);\n}\n\nfunction normalizePath(path: string) {\n let normalizedPath = slash(path);\n\n if (!normalizedPath.endsWith('/')) {\n normalizedPath += '/';\n }\n\n return normalizedPath;\n}\n"]}
@@ -1,5 +1,8 @@
1
1
  /**
2
2
  * Given a requiredBy string (e.g. "@fluentui/react@8.8.8"), return the package name and version.
3
3
  */
4
- export declare function parseRequiredBy(requiredBy: string): string[];
4
+ export declare function parseRequiredBy(requiredBy: string): {
5
+ name: string;
6
+ version: string;
7
+ };
5
8
  //# sourceMappingURL=parseRequiredBy.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"parseRequiredBy.d.ts","sourceRoot":"","sources":["../../src/createResolveMap/parseRequiredBy.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,wBAAgB,eAAe,CAAC,UAAU,EAAE,MAAM,YAMjD"}
1
+ {"version":3,"file":"parseRequiredBy.d.ts","sourceRoot":"","sources":["../../src/createResolveMap/parseRequiredBy.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,wBAAgB,eAAe,CAAC,UAAU,EAAE,MAAM,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAMrF"}
@@ -5,6 +5,6 @@ export function parseRequiredBy(requiredBy) {
5
5
  const divideIndex = requiredBy.lastIndexOf('@');
6
6
  const name = requiredBy.slice(0, divideIndex);
7
7
  const version = requiredBy.slice(divideIndex + 1);
8
- return [name, version];
8
+ return { name, version };
9
9
  }
10
10
  //# sourceMappingURL=parseRequiredBy.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"parseRequiredBy.js","sourceRoot":"","sources":["../../src/createResolveMap/parseRequiredBy.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,UAAU,eAAe,CAAC,UAAkB;IAChD,MAAM,WAAW,GAAG,UAAU,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;IAChD,MAAM,IAAI,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC;IAC9C,MAAM,OAAO,GAAG,UAAU,CAAC,KAAK,CAAC,WAAW,GAAG,CAAC,CAAC,CAAC;IAElD,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;AACzB,CAAC","sourcesContent":["/**\n * Given a requiredBy string (e.g. \"@fluentui/react@8.8.8\"), return the package name and version.\n */\nexport function parseRequiredBy(requiredBy: string) {\n const divideIndex = requiredBy.lastIndexOf('@');\n const name = requiredBy.slice(0, divideIndex);\n const version = requiredBy.slice(divideIndex + 1);\n\n return [name, version];\n}\n"]}
1
+ {"version":3,"file":"parseRequiredBy.js","sourceRoot":"","sources":["../../src/createResolveMap/parseRequiredBy.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,UAAU,eAAe,CAAC,UAAkB;IAChD,MAAM,WAAW,GAAG,UAAU,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;IAChD,MAAM,IAAI,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC;IAC9C,MAAM,OAAO,GAAG,UAAU,CAAC,KAAK,CAAC,WAAW,GAAG,CAAC,CAAC,CAAC;IAElD,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;AAC3B,CAAC","sourcesContent":["/**\n * Given a requiredBy string (e.g. \"@fluentui/react@8.8.8\"), return the package name and version.\n */\nexport function parseRequiredBy(requiredBy: string): { name: string; version: string } {\n const divideIndex = requiredBy.lastIndexOf('@');\n const name = requiredBy.slice(0, divideIndex);\n const version = requiredBy.slice(divideIndex + 1);\n\n return { name, version };\n}\n"]}
@@ -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,CAqFlC"}
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"}
@@ -47,9 +47,7 @@ export async function findFileInPackage(options, context) {
47
47
  sourcePath = undefined;
48
48
  }
49
49
  if (sourcePath) {
50
- if (!filePath) {
51
- filePath = sourceToIntermediatePath(sourcePath);
52
- }
50
+ filePath ??= sourceToIntermediatePath(sourcePath);
53
51
  typesPath = filePath && path.extname(filePath) === '.js' ? filePath.replace(/\.js$/, '.d.ts') : undefined;
54
52
  }
55
53
  }
@@ -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,wBA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E,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\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 if (!filePath) {\n filePath = sourceToIntermediatePath(sourcePath);\n }\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","s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AC,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\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"]}
@@ -0,0 +1,16 @@
1
+ import type { PackageDefinitionsCache, PackageJson } from '@ms-cloudpack/bundler-types';
2
+ /**
3
+ * Find the package.json contents for `dependencyName`, searching up under `node_modules` folders
4
+ * starting at `startPath` and ending at `gitRootPath` or the filesystem root.
5
+ */
6
+ export declare function findPackage(options: {
7
+ dependencyName: string;
8
+ startPath: string;
9
+ gitRootPath?: string;
10
+ }, context: {
11
+ packages: PackageDefinitionsCache;
12
+ }): Promise<{
13
+ packagePath: string;
14
+ definition: PackageJson;
15
+ } | undefined>;
16
+ //# sourceMappingURL=findPackage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"findPackage.d.ts","sourceRoot":"","sources":["../src/findPackage.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,uBAAuB,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAExF;;;GAGG;AACH,wBAAsB,WAAW,CAC/B,OAAO,EAAE;IACP,cAAc,EAAE,MAAM,CAAC;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,EACD,OAAO,EAAE;IACP,QAAQ,EAAE,uBAAuB,CAAC;CACnC,GACA,OAAO,CAAC;IAAE,WAAW,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,WAAW,CAAA;CAAE,GAAG,SAAS,CAAC,CA6BvE"}
@@ -1,6 +1,10 @@
1
1
  import path from 'path';
2
2
  import fsPromises from 'fs/promises';
3
- export async function findPackagePath(options, context) {
3
+ /**
4
+ * Find the package.json contents for `dependencyName`, searching up under `node_modules` folders
5
+ * starting at `startPath` and ending at `gitRootPath` or the filesystem root.
6
+ */
7
+ export async function findPackage(options, context) {
4
8
  const { dependencyName, gitRootPath, startPath } = options;
5
9
  const { packages } = context;
6
10
  let packagePath = startPath;
@@ -8,7 +12,7 @@ export async function findPackagePath(options, context) {
8
12
  const resolvedPath = path.join(packagePath, 'node_modules', dependencyName);
9
13
  const definition = await packages.get(resolvedPath);
10
14
  if (definition) {
11
- return fsPromises.realpath(resolvedPath);
15
+ return { packagePath: await fsPromises.realpath(resolvedPath), definition };
12
16
  }
13
17
  // We haven't found it. Try to move up a directory.
14
18
  packagePath = path.dirname(packagePath);
@@ -23,4 +27,4 @@ export async function findPackagePath(options, context) {
23
27
  } while ((!gitRootPath || packagePath.length >= gitRootPath.length) && path.dirname(packagePath) !== packagePath);
24
28
  return undefined;
25
29
  }
26
- //# sourceMappingURL=findPackagePath.js.map
30
+ //# sourceMappingURL=findPackage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"findPackage.js","sourceRoot":"","sources":["../src/findPackage.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,UAAU,MAAM,aAAa,CAAC;AAGrC;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,OAIC,EACD,OAEC;IAED,MAAM,EAAE,cAAc,EAAE,WAAW,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC;IAC3D,MAAM,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC;IAE7B,IAAI,WAAW,GAAG,SAAS,CAAC;IAE5B,GAAG;QACD,MAAM,YAAY,GAAG,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,cAAc,EAAE,cAAc,CAAC,CAAC;QAC5E,MAAM,UAAU,GAAG,MAAM,QAAQ,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;QAEpD,IAAI,UAAU,EAAE;YACd,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC,QAAQ,CAAC,YAAY,CAAC,EAAE,UAAU,EAAE,CAAC;SAC7E;QAED,mDAAmD;QACnD,WAAW,GAAG,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;QAExC,oDAAoD;QACpD,IAAI,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE;YAC9C,WAAW,GAAG,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;SACzC;QAED,yCAAyC;QACzC,IAAI,WAAW,CAAC,QAAQ,CAAC,cAAc,CAAC,EAAE;YACxC,WAAW,GAAG,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;SACzC;KACF,QAAQ,CAAC,CAAC,WAAW,IAAI,WAAW,CAAC,MAAM,IAAI,WAAW,CAAC,MAAM,CAAC,IAAI,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,KAAK,WAAW,EAAE;IAElH,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["import path from 'path';\nimport fsPromises from 'fs/promises';\nimport type { PackageDefinitionsCache, PackageJson } from '@ms-cloudpack/bundler-types';\n\n/**\n * Find the package.json contents for `dependencyName`, searching up under `node_modules` folders\n * starting at `startPath` and ending at `gitRootPath` or the filesystem root.\n */\nexport async function findPackage(\n options: {\n dependencyName: string;\n startPath: string;\n gitRootPath?: string;\n },\n context: {\n packages: PackageDefinitionsCache;\n },\n): Promise<{ packagePath: string; definition: PackageJson } | undefined> {\n const { dependencyName, gitRootPath, startPath } = options;\n const { packages } = context;\n\n let packagePath = startPath;\n\n do {\n const resolvedPath = path.join(packagePath, 'node_modules', dependencyName);\n const definition = await packages.get(resolvedPath);\n\n if (definition) {\n return { packagePath: await fsPromises.realpath(resolvedPath), definition };\n }\n\n // We haven't found it. Try to move up a directory.\n packagePath = path.dirname(packagePath);\n\n // If we moved up into a scope folder, skip over it.\n if (path.basename(packagePath).startsWith('@')) {\n packagePath = path.dirname(packagePath);\n }\n\n // Skip over nested node_modules folders.\n if (packagePath.endsWith('node_modules')) {\n packagePath = path.dirname(packagePath);\n }\n } while ((!gitRootPath || packagePath.length >= gitRootPath.length) && path.dirname(packagePath) !== packagePath);\n\n return undefined;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"getExportPathFromEntry.d.ts","sourceRoot":"","sources":["../src/getExportPathFromEntry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AAItE;;GAEG;AACH,wBAAgB,sBAAsB,CACpC,WAAW,EAAE,kBAAkB,EAC/B,UAAU,SAAM,EAChB,UAAU,WAAoB,GAC7B,MAAM,GAAG,SAAS,CAwBpB"}
1
+ {"version":3,"file":"getExportPathFromEntry.d.ts","sourceRoot":"","sources":["../src/getExportPathFromEntry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AAItE;;GAEG;AACH,wBAAgB,sBAAsB,CACpC,WAAW,EAAE,kBAAkB,EAC/B,UAAU,SAAM,EAChB,UAAU,WAAoB,GAC7B,MAAM,GAAG,SAAS,CA0BpB"}
@@ -3,11 +3,11 @@ const defaultConditions = ['import', 'module', 'default'];
3
3
  * Given an export map entry, return the esm entry string value. (Parses arrays, maps, has a fallback system.)
4
4
  */
5
5
  export function getExportPathFromEntry(exportEntry, importPath = '.', conditions = defaultConditions) {
6
- let exportPath = undefined;
6
+ let exportPath;
7
7
  if (typeof exportEntry === 'string') {
8
8
  return exportEntry;
9
9
  }
10
- else if (Array.isArray(exportEntry)) {
10
+ if (Array.isArray(exportEntry)) {
11
11
  for (const item of exportEntry) {
12
12
  exportPath = getExportPathFromEntry(item, importPath, conditions);
13
13
  if (exportPath) {
@@ -1 +1 @@
1
- {"version":3,"file":"getExportPathFromEntry.js","sourceRoot":"","sources":["../src/getExportPathFromEntry.ts"],"names":[],"mappings":"AAEA,MAAM,iBAAiB,GAAG,CAAC,QAAQ,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC;AAE1D;;GAEG;AACH,MAAM,UAAU,sBAAsB,CACpC,WAA+B,EAC/B,UAAU,GAAG,GAAG,EAChB,UAAU,GAAG,iBAAiB;IAE9B,IAAI,UAAU,GAAG,SAAS,CAAC;IAE3B,IAAI,OAAO,WAAW,KAAK,QAAQ,EAAE;QACnC,OAAO,WAAW,CAAC;KACpB;SAAM,IAAI,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE;QACrC,KAAK,MAAM,IAAI,IAAI,WAAW,EAAE;YAC9B,UAAU,GAAG,sBAAsB,CAAC,IAAI,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC;YAClE,IAAI,UAAU,EAAE;gBACd,OAAO,UAAU,CAAC;aACnB;SACF;KACF;SAAM,IAAI,WAAW,IAAI,OAAO,WAAW,KAAK,QAAQ,EAAE;QACzD,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE;YACtD,IAAI,KAAK,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,GAAG,KAAK,UAAU,CAAC,EAAE;gBAC7D,UAAU,GAAG,sBAAsB,CAAC,KAAK,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC;gBACnE,IAAI,UAAU,EAAE;oBACd,OAAO,UAAU,CAAC;iBACnB;aACF;SACF;KACF;IAED,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["import type { PackageJsonExports } from '@ms-cloudpack/bundler-types';\n\nconst defaultConditions = ['import', 'module', 'default'];\n\n/**\n * Given an export map entry, return the esm entry string value. (Parses arrays, maps, has a fallback system.)\n */\nexport function getExportPathFromEntry(\n exportEntry: PackageJsonExports,\n importPath = '.',\n conditions = defaultConditions,\n): string | undefined {\n let exportPath = undefined;\n\n if (typeof exportEntry === 'string') {\n return exportEntry;\n } else if (Array.isArray(exportEntry)) {\n for (const item of exportEntry) {\n exportPath = getExportPathFromEntry(item, importPath, conditions);\n if (exportPath) {\n return exportPath;\n }\n }\n } else if (exportEntry && typeof exportEntry === 'object') {\n for (const [key, value] of Object.entries(exportEntry)) {\n if (value && (conditions.includes(key) || key === importPath)) {\n exportPath = getExportPathFromEntry(value, importPath, conditions);\n if (exportPath) {\n return exportPath;\n }\n }\n }\n }\n\n return undefined;\n}\n"]}
1
+ {"version":3,"file":"getExportPathFromEntry.js","sourceRoot":"","sources":["../src/getExportPathFromEntry.ts"],"names":[],"mappings":"AAEA,MAAM,iBAAiB,GAAG,CAAC,QAAQ,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC;AAE1D;;GAEG;AACH,MAAM,UAAU,sBAAsB,CACpC,WAA+B,EAC/B,UAAU,GAAG,GAAG,EAChB,UAAU,GAAG,iBAAiB;IAE9B,IAAI,UAA8B,CAAC;IAEnC,IAAI,OAAO,WAAW,KAAK,QAAQ,EAAE;QACnC,OAAO,WAAW,CAAC;KACpB;IAED,IAAI,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE;QAC9B,KAAK,MAAM,IAAI,IAAI,WAAW,EAAE;YAC9B,UAAU,GAAG,sBAAsB,CAAC,IAAI,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC;YAClE,IAAI,UAAU,EAAE;gBACd,OAAO,UAAU,CAAC;aACnB;SACF;KACF;SAAM,IAAI,WAAW,IAAI,OAAO,WAAW,KAAK,QAAQ,EAAE;QACzD,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE;YACtD,IAAI,KAAK,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,GAAG,KAAK,UAAU,CAAC,EAAE;gBAC7D,UAAU,GAAG,sBAAsB,CAAC,KAAK,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC;gBACnE,IAAI,UAAU,EAAE;oBACd,OAAO,UAAU,CAAC;iBACnB;aACF;SACF;KACF;IAED,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["import type { PackageJsonExports } from '@ms-cloudpack/bundler-types';\n\nconst defaultConditions = ['import', 'module', 'default'];\n\n/**\n * Given an export map entry, return the esm entry string value. (Parses arrays, maps, has a fallback system.)\n */\nexport function getExportPathFromEntry(\n exportEntry: PackageJsonExports,\n importPath = '.',\n conditions = defaultConditions,\n): string | undefined {\n let exportPath: string | undefined;\n\n if (typeof exportEntry === 'string') {\n return exportEntry;\n }\n\n if (Array.isArray(exportEntry)) {\n for (const item of exportEntry) {\n exportPath = getExportPathFromEntry(item, importPath, conditions);\n if (exportPath) {\n return exportPath;\n }\n }\n } else if (exportEntry && typeof exportEntry === 'object') {\n for (const [key, value] of Object.entries(exportEntry)) {\n if (value && (conditions.includes(key) || key === importPath)) {\n exportPath = getExportPathFromEntry(value, importPath, conditions);\n if (exportPath) {\n return exportPath;\n }\n }\n }\n }\n\n return undefined;\n}\n"]}
@@ -2,7 +2,7 @@ import { slash } from '@ms-cloudpack/path-string-parsing';
2
2
  export function isExternalPackage(packagePath) {
3
3
  if (packagePath) {
4
4
  const parts = slash(packagePath).split('/');
5
- return parts.indexOf('node_modules') >= 0;
5
+ return parts.includes('node_modules');
6
6
  }
7
7
  return false;
8
8
  }
@@ -1 +1 @@
1
- {"version":3,"file":"isExternalPackage.js","sourceRoot":"","sources":["../src/isExternalPackage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,mCAAmC,CAAC;AAE1D,MAAM,UAAU,iBAAiB,CAAC,WAAmB;IACnD,IAAI,WAAW,EAAE;QACf,MAAM,KAAK,GAAG,KAAK,CAAC,WAAW,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAE5C,OAAO,KAAK,CAAC,OAAO,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;KAC3C;IAED,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["import { slash } from '@ms-cloudpack/path-string-parsing';\n\nexport function isExternalPackage(packagePath: string): boolean {\n if (packagePath) {\n const parts = slash(packagePath).split('/');\n\n return parts.indexOf('node_modules') >= 0;\n }\n\n return false;\n}\n"]}
1
+ {"version":3,"file":"isExternalPackage.js","sourceRoot":"","sources":["../src/isExternalPackage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,mCAAmC,CAAC;AAE1D,MAAM,UAAU,iBAAiB,CAAC,WAAmB;IACnD,IAAI,WAAW,EAAE;QACf,MAAM,KAAK,GAAG,KAAK,CAAC,WAAW,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAE5C,OAAO,KAAK,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAC;KACvC;IAED,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["import { slash } from '@ms-cloudpack/path-string-parsing';\n\nexport function isExternalPackage(packagePath: string): boolean {\n if (packagePath) {\n const parts = slash(packagePath).split('/');\n\n return parts.includes('node_modules');\n }\n\n return false;\n}\n"]}
@@ -5,7 +5,7 @@
5
5
  "toolPackages": [
6
6
  {
7
7
  "packageName": "@microsoft/api-extractor",
8
- "packageVersion": "7.36.3"
8
+ "packageVersion": "7.36.4"
9
9
  }
10
10
  ]
11
11
  }
@@ -1,4 +1,8 @@
1
1
  import type { ResolveMapEntry } from './ResolveMapEntry.js';
2
+ /**
3
+ * Intermediate type used internally by `createResolveMap` helpers.
4
+ * Contains info about every discovered version of each package.
5
+ */
2
6
  export type PackageMap = {
3
7
  [name: string]: {
4
8
  [version: string]: ResolveMapEntry;
@@ -1 +1 @@
1
- {"version":3,"file":"PackageMap.d.ts","sourceRoot":"","sources":["../../src/types/PackageMap.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAE5D,MAAM,MAAM,UAAU,GAAG;IACvB,CAAC,IAAI,EAAE,MAAM,GAAG;QACd,CAAC,OAAO,EAAE,MAAM,GAAG,eAAe,CAAC;KACpC,CAAC;CACH,CAAC"}
1
+ {"version":3,"file":"PackageMap.d.ts","sourceRoot":"","sources":["../../src/types/PackageMap.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAE5D;;;GAGG;AACH,MAAM,MAAM,UAAU,GAAG;IACvB,CAAC,IAAI,EAAE,MAAM,GAAG;QACd,CAAC,OAAO,EAAE,MAAM,GAAG,eAAe,CAAC;KACpC,CAAC;CACH,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"PackageMap.js","sourceRoot":"","sources":["../../src/types/PackageMap.ts"],"names":[],"mappings":"","sourcesContent":["import type { ResolveMapEntry } from './ResolveMapEntry.js';\n\nexport type PackageMap = {\n [name: string]: {\n [version: string]: ResolveMapEntry;\n };\n};\n"]}
1
+ {"version":3,"file":"PackageMap.js","sourceRoot":"","sources":["../../src/types/PackageMap.ts"],"names":[],"mappings":"","sourcesContent":["import type { ResolveMapEntry } from './ResolveMapEntry.js';\n\n/**\n * Intermediate type used internally by `createResolveMap` helpers.\n * Contains info about every discovered version of each package.\n */\nexport type PackageMap = {\n [name: string]: {\n [version: string]: ResolveMapEntry;\n };\n};\n"]}
@@ -1,11 +1,38 @@
1
1
  export type ResolveMapEntry = {
2
+ /** Package name. */
2
3
  name: string;
4
+ /**
5
+ * Resolved/installed package version. For a linked internal package, this will end in `-linked`.
6
+ * (The docs for `isExternal` explain what "internal" means.)
7
+ */
3
8
  version: string;
9
+ /** Path to the resolved/installed package. */
4
10
  path: string;
11
+ /** Map from dependency name to resolved/installed version. */
5
12
  dependencies: Record<string, string>;
13
+ /**
14
+ * Map from requesting package name `@` the actual version of that package to the original
15
+ * version of this package that it requested.
16
+ *
17
+ * Example: if this entry is for package `bar`, and `foo@1.0.0` depends on `"bar": "^2.0.0"`,
18
+ * this will be `{ "foo@1.0.0": "^2.0.0" }`.
19
+ */
6
20
  requiredBy: Record<`${string}@${string}`, string>;
7
- isLinked?: boolean;
21
+ /**
22
+ * A package is considered "external" if it was installed from a package manager (its realpath
23
+ * contains `node_modules`). This is the opposite of "internal", which means that the package
24
+ * is defined in a local folder/repo.
25
+ */
8
26
  isExternal?: boolean;
27
+ /**
28
+ * Whether this package is linked **AND** is internal to its actual folder/repo.
29
+ * (The docs for `isExternal` explain what "internal" means.)
30
+ */
31
+ isLinked?: boolean;
32
+ /**
33
+ * Additional installed versions of this package, which are required per semver by some other
34
+ * package in the map.
35
+ */
9
36
  scopedVersions?: {
10
37
  [version: string]: ResolveMapEntry;
11
38
  };
@@ -1 +1 @@
1
- {"version":3,"file":"ResolveMapEntry.d.ts","sourceRoot":"","sources":["../../src/types/ResolveMapEntry.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IAEb,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACrC,UAAU,EAAE,MAAM,CAAC,GAAG,MAAM,IAAI,MAAM,EAAE,EAAE,MAAM,CAAC,CAAC;IAElD,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,UAAU,CAAC,EAAE,OAAO,CAAC;IAErB,cAAc,CAAC,EAAE;QACf,CAAC,OAAO,EAAE,MAAM,GAAG,eAAe,CAAC;KACpC,CAAC;CACH,CAAC"}
1
+ {"version":3,"file":"ResolveMapEntry.d.ts","sourceRoot":"","sources":["../../src/types/ResolveMapEntry.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,eAAe,GAAG;IAC5B,oBAAoB;IACpB,IAAI,EAAE,MAAM,CAAC;IAEb;;;OAGG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB,8CAA8C;IAC9C,IAAI,EAAE,MAAM,CAAC;IAEb,8DAA8D;IAC9D,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAErC;;;;;;OAMG;IACH,UAAU,EAAE,MAAM,CAAC,GAAG,MAAM,IAAI,MAAM,EAAE,EAAE,MAAM,CAAC,CAAC;IAElD;;;;OAIG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IAErB;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB;;;OAGG;IACH,cAAc,CAAC,EAAE;QACf,CAAC,OAAO,EAAE,MAAM,GAAG,eAAe,CAAC;KACpC,CAAC;CACH,CAAC"}