@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 +1 @@
1
- {"version":3,"file":"addExportsMapEntry.d.ts","sourceRoot":"","sources":["../src/addExportsMapEntry.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AAG/F;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACxC;;OAEG;IACH,OAAO,EAAE,kBAAkB,CAAC;IAE5B;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IAEpB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,wBAAsB,kBAAkB,CACtC,OAAO,EAAE,yBAAyB,EAClC,OAAO,EAAE;IAAE,QAAQ,EAAE,uBAAuB,CAAA;CAAE,GAC7C,OAAO,CAAC,OAAO,CAAC,CAkDlB"}
1
+ {"version":3,"file":"addExportsMapEntry.d.ts","sourceRoot":"","sources":["../src/addExportsMapEntry.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AAG/F;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACxC;;OAEG;IACH,OAAO,EAAE,kBAAkB,CAAC;IAE5B;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IAEpB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,wBAAsB,kBAAkB,CACtC,OAAO,EAAE,yBAAyB,EAClC,OAAO,EAAE;IAAE,QAAQ,EAAE,uBAAuB,CAAA;CAAE,GAC7C,OAAO,CAAC,OAAO,CAAC,CAoDlB"}
@@ -10,34 +10,35 @@ export async function addExportsMapEntry(options, context) {
10
10
  packagePath,
11
11
  filePath: options.filePath || options.importPath || '',
12
12
  }, context);
13
+ // Only do work if a file path was found.
14
+ if (!filePath) {
15
+ return false;
16
+ }
13
17
  // Create a local for casting.
14
18
  const localExports = exports;
15
- // Only do work if a file path was provided.
16
- if (filePath) {
17
- // If this is the only entry we're adding, set it to a string to minimize the exports map.
18
- if (!typesPath &&
19
- !sourcePath &&
20
- condition === 'default' &&
21
- (!localExports[importPath] || typeof localExports[importPath] === 'string')) {
22
- localExports[importPath] = filePath;
19
+ // If this is the only entry we're adding, set it to a string to minimize the exports map.
20
+ if (!typesPath &&
21
+ !sourcePath &&
22
+ condition === 'default' &&
23
+ (!localExports[importPath] || typeof localExports[importPath] === 'string')) {
24
+ localExports[importPath] = filePath;
25
+ }
26
+ else {
27
+ let exportsEntry = (localExports[importPath] ??= {});
28
+ // Promote string-based exports into objects with default conditions.
29
+ if (typeof exportsEntry === 'string') {
30
+ exportsEntry = exports[importPath] = { default: exportsEntry };
31
+ }
32
+ if (typesPath) {
33
+ exportsEntry['types'] = typesPath;
23
34
  }
24
- else {
25
- let exportsEntry = (localExports[importPath] ??= {});
26
- // Promote string-based exports into objects with default conditions.
27
- if (typeof exportsEntry === 'string') {
28
- exportsEntry = exports[importPath] = { default: exportsEntry };
29
- }
30
- if (typesPath) {
31
- exportsEntry['types'] = typesPath;
32
- }
33
- if (sourcePath) {
34
- exportsEntry['source'] = sourcePath;
35
- }
36
- // Add the entry for the condition.
37
- exportsEntry[condition] = filePath;
35
+ if (sourcePath) {
36
+ exportsEntry['source'] = sourcePath;
38
37
  }
38
+ // Add the entry for the condition.
39
+ exportsEntry[condition] = filePath;
39
40
  }
40
- return !!filePath;
41
+ return true;
41
42
  }
42
43
  function makeSafeImportKey(key) {
43
44
  if (!key || key === '' || key === '.') {
@@ -1 +1 @@
1
- {"version":3,"file":"addExportsMapEntry.js","sourceRoot":"","sources":["../src/addExportsMapEntry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAE3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AAyCrE;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,OAAkC,EAClC,OAA8C;IAE9C,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,SAAS,GAAG,SAAS,EAAE,GAAG,OAAO,CAAC;IAChE,MAAM,UAAU,GAAG,iBAAiB,CAAC,OAAO,CAAC,UAAU,IAAI,GAAG,CAAC,CAAC;IAChE,MAAM,EACJ,QAAQ,E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O,GAAG,CAAC;KACZ;IAED,4CAA4C;IAC5C,IAAI,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE;QACvB,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC;KACjB;IAED,6CAA6C;IAC7C,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE;QACzB,GAAG,GAAG,IAAI,GAAG,GAAG,CAAC;KAClB;IAED,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["import { findFileInPackage } from './findFileInPackage.js';\nimport type { PackageDefinitionsCache, PackageJsonExports } from '@ms-cloudpack/bundler-types';\nimport { safeRelativePath } from '@ms-cloudpack/path-string-parsing';\n\n/**\n * Options fo addExportsMapEntry.\n */\nexport interface AddExportsMapEntryOptions {\n /**\n * The exports map to add the entry to.\n */\n exports: PackageJsonExports;\n\n /**\n * The package path to add the entry for. This is used to resolve relative paths.\n */\n packagePath: string;\n\n /**\n * The import path to add the entry for. This is used as the key in the exports map. Defaults\n * to \".\" being the package import.\n */\n importPath?: string;\n\n /**\n * The relative path to the physical file location, representing the \"key\" in the exports map. Can be a partial\n * location, in which case we will attempt to search for the file and associated source/d.ts files. Defaults to\n * assuming `index.js`.\n */\n filePath?: string;\n\n /**\n * Optional types path. If not provided, types will be discovered for internal packages that have source files.\n * This is useful mainly when converting the default import from a package.json that has explicit typings listed.\n */\n typesPath?: string;\n\n /**\n * The condition to add the entry for. (Example: \"import\", \"require\", \"browser\", \"types\") Defaults to \"default\"\n */\n condition?: string;\n}\n\n/**\n * Given an exports map and details about an import path, adds the entry.\n */\nexport async function addExportsMapEntry(\n options: AddExportsMapEntryOptions,\n context: { packages: PackageDefinitionsCache },\n): Promise<boolean> {\n const { exports, packagePath, condition = 'default' } = options;\n const importPath = makeSafeImportKey(options.importPath || '.');\n const {\n filePath,\n sourcePath,\n typesPath = options.typesPath ? safeRelativePath(options.typesPath) : undefined,\n } = await findFileInPackage(\n {\n packagePath,\n filePath: options.filePath || options.importPath || '',\n },\n context,\n );\n\n // Create a local for casting.\n const localExports = exports as Record<string, string | Record<string, string>>;\n\n // Only do work if a file path was provided.\n if (filePath) {\n // If this is the only entry we're adding, set it to a string to minimize the exports map.\n if (\n !typesPath &&\n !sourcePath &&\n condition === 'default' &&\n (!localExports[importPath] || typeof localExports[importPath] === 'string')\n ) {\n localExports[importPath] = filePath;\n } else {\n let exportsEntry = (localExports[importPath] ??= {});\n\n // Promote string-based exports into objects with default conditions.\n if (typeof exportsEntry === 'string') {\n exportsEntry = (exports as Record<string, Record<string, string>>)[importPath] = { default: exportsEntry };\n }\n\n if (typesPath) {\n exportsEntry['types'] = typesPath;\n }\n\n if (sourcePath) {\n exportsEntry['source'] = sourcePath;\n }\n\n // Add the entry for the condition.\n exportsEntry[condition] = filePath;\n }\n }\n\n return !!filePath;\n}\n\nfunction makeSafeImportKey(key: string) {\n if (!key || key === '' || key === '.') {\n return '.';\n }\n\n // if the key starts with a slash, add a dot\n if (key.startsWith('/')) {\n key = '.' + key;\n }\n\n // if the key doesn't start with \"./\", add it\n if (!key.startsWith('./')) {\n key = './' + key;\n }\n\n return key;\n}\n"]}
1
+ {"version":3,"file":"addExportsMapEntry.js","sourceRoot":"","sources":["../src/addExportsMapEntry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAE3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AAyCrE;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,OAAkC,EAClC,OAA8C;IAE9C,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,SAAS,GAAG,SAAS,EAAE,GAAG,OAAO,CAAC;IAChE,MAAM,UAAU,GAAG,iBAAiB,CAAC,OAAO,CAAC,UAAU,IAAI,GAAG,CAAC,CAAC;IAChE,MAAM,EACJ,QAAQ,EACR,UAAU,EACV,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,gBAAgB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AU,CAAC,GAAG,CAAC,EAAE;QACvB,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC;KACjB;IAED,6CAA6C;IAC7C,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE;QACzB,GAAG,GAAG,IAAI,GAAG,GAAG,CAAC;KAClB;IAED,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["import { findFileInPackage } from './findFileInPackage.js';\nimport type { PackageDefinitionsCache, PackageJsonExports } from '@ms-cloudpack/bundler-types';\nimport { safeRelativePath } from '@ms-cloudpack/path-string-parsing';\n\n/**\n * Options fo addExportsMapEntry.\n */\nexport interface AddExportsMapEntryOptions {\n /**\n * The exports map to add the entry to.\n */\n exports: PackageJsonExports;\n\n /**\n * The package path to add the entry for. This is used to resolve relative paths.\n */\n packagePath: string;\n\n /**\n * The import path to add the entry for. This is used as the key in the exports map. Defaults\n * to \".\" being the package import.\n */\n importPath?: string;\n\n /**\n * The relative path to the physical file location, representing the \"key\" in the exports map. Can be a partial\n * location, in which case we will attempt to search for the file and associated source/d.ts files. Defaults to\n * assuming `index.js`.\n */\n filePath?: string;\n\n /**\n * Optional types path. If not provided, types will be discovered for internal packages that have source files.\n * This is useful mainly when converting the default import from a package.json that has explicit typings listed.\n */\n typesPath?: string;\n\n /**\n * The condition to add the entry for. (Example: \"import\", \"require\", \"browser\", \"types\") Defaults to \"default\"\n */\n condition?: string;\n}\n\n/**\n * Given an exports map and details about an import path, adds the entry.\n */\nexport async function addExportsMapEntry(\n options: AddExportsMapEntryOptions,\n context: { packages: PackageDefinitionsCache },\n): Promise<boolean> {\n const { exports, packagePath, condition = 'default' } = options;\n const importPath = makeSafeImportKey(options.importPath || '.');\n const {\n filePath,\n sourcePath,\n typesPath = options.typesPath ? safeRelativePath(options.typesPath) : undefined,\n } = await findFileInPackage(\n {\n packagePath,\n filePath: options.filePath || options.importPath || '',\n },\n context,\n );\n\n // Only do work if a file path was found.\n if (!filePath) {\n return false;\n }\n\n // Create a local for casting.\n const localExports = exports as Record<string, string | Record<string, string>>;\n\n // If this is the only entry we're adding, set it to a string to minimize the exports map.\n if (\n !typesPath &&\n !sourcePath &&\n condition === 'default' &&\n (!localExports[importPath] || typeof localExports[importPath] === 'string')\n ) {\n localExports[importPath] = filePath;\n } else {\n let exportsEntry = (localExports[importPath] ??= {});\n\n // Promote string-based exports into objects with default conditions.\n if (typeof exportsEntry === 'string') {\n exportsEntry = (exports as Record<string, Record<string, string>>)[importPath] = { default: exportsEntry };\n }\n\n if (typesPath) {\n exportsEntry['types'] = typesPath;\n }\n\n if (sourcePath) {\n exportsEntry['source'] = sourcePath;\n }\n\n // Add the entry for the condition.\n exportsEntry[condition] = filePath;\n }\n\n return true;\n}\n\nfunction makeSafeImportKey(key: string) {\n if (!key || key === '' || key === '.') {\n return '.';\n }\n\n // if the key starts with a slash, add a dot\n if (key.startsWith('/')) {\n key = '.' + key;\n }\n\n // if the key doesn't start with \"./\", add it\n if (!key.startsWith('./')) {\n key = './' + key;\n }\n\n return key;\n}\n"]}
@@ -4,7 +4,6 @@ import type { ResolveMapEntry } from '../types/ResolveMapEntry.js';
4
4
  /**
5
5
  * Given a linkedEntry, iterates through dependencies to ensure they are added to the packageMap,
6
6
  * preferring packageMap dependencies over linkedMap dependencies.
7
- * @param options
8
7
  */
9
8
  export declare function addLinkedEntryDependencies(options: {
10
9
  appMap: PackageMap;
@@ -1 +1 @@
1
- {"version":3,"file":"addLinkedEntryDependencies.d.ts","sourceRoot":"","sources":["../../src/createResolveMap/addLinkedEntryDependencies.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAE3E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAEnE;;;;GAIG;AAEH,wBAAsB,0BAA0B,CAC9C,OAAO,EAAE;IACP,MAAM,EAAE,UAAU,CAAC;IACnB,OAAO,EAAE,UAAU,CAAC;IACpB,WAAW,EAAE,eAAe,CAAC;CAC9B,EACD,OAAO,EAAE;IACP,QAAQ,EAAE,uBAAuB,CAAC;CACnC,iBAsFF"}
1
+ {"version":3,"file":"addLinkedEntryDependencies.d.ts","sourceRoot":"","sources":["../../src/createResolveMap/addLinkedEntryDependencies.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAE3E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAEnE;;;GAGG;AACH,wBAAsB,0BAA0B,CAC9C,OAAO,EAAE;IACP,MAAM,EAAE,UAAU,CAAC;IACnB,OAAO,EAAE,UAAU,CAAC;IACpB,WAAW,EAAE,eAAe,CAAC;CAC9B,EACD,OAAO,EAAE;IACP,QAAQ,EAAE,uBAAuB,CAAC;CACnC,iBAoFF"}
@@ -2,7 +2,6 @@ import { satisfies } from 'semver';
2
2
  /**
3
3
  * Given a linkedEntry, iterates through dependencies to ensure they are added to the packageMap,
4
4
  * preferring packageMap dependencies over linkedMap dependencies.
5
- * @param options
6
5
  */
7
6
  export async function addLinkedEntryDependencies(options, context) {
8
7
  const { appMap, linkMap, linkedEntry } = options;
@@ -16,63 +15,58 @@ export async function addLinkedEntryDependencies(options, context) {
16
15
  }
17
16
  }
18
17
  while (entriesToVisit.length) {
18
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- already checked the length
19
19
  const entry = entriesToVisit.pop();
20
- if (entry) {
21
- const { name, version, dependencies } = entry;
22
- const linkDefinition = await packages.get(entry.path);
23
- const versionRequirements = {
24
- ...(linkDefinition?.dependencies || {}),
25
- ...(linkDefinition?.peerDependencies || {}),
26
- };
27
- // Iterate through the dependencies of the linked package.
28
- if (dependencies) {
29
- for (const [dependencyName, linkedDependencyVersion] of Object.entries(dependencies)) {
30
- const appVersions = appMap[dependencyName];
31
- const versionRequirement = versionRequirements[dependencyName];
32
- let isSatisfied = false;
33
- if (!appVersions) {
34
- // The app does not have any version of this dependency, we need to bring over the version
35
- // used by the linkedEntry.
36
- const dependencyEntry = linkMap[dependencyName]?.[linkedDependencyVersion];
37
- appMap[dependencyName] = { [linkedDependencyVersion]: dependencyEntry };
20
+ const { name, version, dependencies } = entry;
21
+ const linkDefinition = await packages.get(entry.path);
22
+ const versionRequirements = {
23
+ ...(linkDefinition?.dependencies || {}),
24
+ ...(linkDefinition?.peerDependencies || {}),
25
+ };
26
+ // Iterate through the dependencies of the linked package.
27
+ for (const [dependencyName, linkedDependencyVersion] of Object.entries(dependencies)) {
28
+ const versionRequirement = versionRequirements[dependencyName];
29
+ if (!versionRequirement) {
30
+ continue;
31
+ }
32
+ const appVersions = appMap[dependencyName];
33
+ if (!appVersions) {
34
+ // The app does not have any version of this dependency, so we need to bring over the version
35
+ // used by the linkedEntry.
36
+ const dependencyEntry = linkMap[dependencyName]?.[linkedDependencyVersion];
37
+ if (dependencyEntry) {
38
+ appMap[dependencyName] = { [linkedDependencyVersion]: dependencyEntry };
39
+ dependencyEntry.requiredBy = { [`${name}@${version}`]: versionRequirement };
40
+ // Recurse through the dependency's dependencies.
41
+ enqueue(dependencyEntry);
42
+ }
43
+ }
44
+ else {
45
+ // We have one or more versions of this dependency already. If a sufficient version
46
+ // of the dependency is already in the appMap, we we just need to update the linkedEntry's
47
+ // dependency and the dependency's requiredBy record for the parent.
48
+ const appDependencyVersions = Object.values(appVersions);
49
+ if (appDependencyVersions.length === 1 && !appDependencyVersions[0]?.isExternal) {
50
+ continue;
51
+ }
52
+ // See if an existing version of the dependency satisfies the semver.
53
+ const appDependencyEntry = appDependencyVersions.find((e) => e.isLinked || satisfies(e.version, versionRequirement));
54
+ if (appDependencyEntry) {
55
+ // If the dependency satisfies the semver, use that!
56
+ entry.dependencies[dependencyName] = appDependencyEntry.version;
57
+ appDependencyEntry.requiredBy[`${name}@${version}`] = versionRequirement;
58
+ enqueue(appDependencyEntry);
59
+ }
60
+ else {
61
+ // We have at least one version of this dependency but nothing satisfies the requirement.
62
+ // We need to introduce a duplicate. During the final pass, we will remove non-required deps.
63
+ const dependencyEntry = Object.values(linkMap[dependencyName] || {}).find((e) => satisfies(e.version, versionRequirement));
64
+ if (dependencyEntry) {
65
+ appVersions[dependencyEntry.version] = dependencyEntry;
66
+ entry.dependencies[dependencyName] = linkedDependencyVersion;
38
67
  dependencyEntry.requiredBy = { [`${name}@${version}`]: versionRequirement };
39
68
  // Recursive through the dependency's dependencies.
40
69
  enqueue(dependencyEntry);
41
- isSatisfied = true;
42
- }
43
- else {
44
- // We have at least 1 or more versions of this dependency already. If a sufficient version
45
- // of the dependency is already in the appMap, we we just need to update the linkedEntry's
46
- // dependency and the dependency's requiredBy record for the parent.
47
- const appDependencyVersions = Object.values(appMap[dependencyName]);
48
- if (appDependencyVersions.length === 1 && !appDependencyVersions[0].isExternal) {
49
- continue;
50
- }
51
- for (const appDependencyEntry of appDependencyVersions) {
52
- // If the dependency satisfies the semver, use that!
53
- if (appDependencyEntry.isLinked || satisfies(appDependencyEntry.version, versionRequirement)) {
54
- entry.dependencies[dependencyName] = appDependencyEntry.version;
55
- appDependencyEntry.requiredBy[`${name}@${version}`] = versionRequirement;
56
- enqueue(appDependencyEntry);
57
- isSatisfied = true;
58
- break;
59
- }
60
- }
61
- }
62
- if (!isSatisfied) {
63
- // We have at least 1 version of this dependency but nothing satisfies the requirement. We
64
- // need to introduce a duplicate. During the final pass, we will remove non-required deps.
65
- const dependencyEntries = linkMap[dependencyName];
66
- for (const dependencyEntry of Object.values(dependencyEntries)) {
67
- if (satisfies(dependencyEntry.version, versionRequirement)) {
68
- appMap[dependencyName][dependencyEntry.version] = dependencyEntry;
69
- entry.dependencies[dependencyName] = linkedDependencyVersion;
70
- dependencyEntry.requiredBy = { [`${name}@${version}`]: versionRequirement };
71
- // Recursive through the dependency's dependencies.
72
- enqueue(dependencyEntry);
73
- break;
74
- }
75
- }
76
70
  }
77
71
  }
78
72
  }
@@ -1 +1 @@
1
- {"version":3,"file":"addLinkedEntryDependencies.js","sourceRoot":"","sources":["../../src/createResolveMap/addLinkedEntryDependencies.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAInC;;;;GAIG;AAEH,MAAM,CAAC,KAAK,UAAU,0BAA0B,CAC9C,OAIC,EACD,OAEC;IAED,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC;IACjD,MAAM,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC;IAC7B,MAAM,iBAAiB,GAAG,IAAI,GAAG,CAAS,WAAW,CAAC,IAAI,CAAC,CAAC;IAC5D,MAAM,cAAc,GAAsB,CAAC,WAAW,CAAC,CAAC;IAExD,SAAS,OAAO,CAAC,QAAyB;QACxC,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE;YACzC,iBAAiB,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;YACrC,cAAc,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;SAC/B;IACH,CAAC;IAED,OAAO,cAAc,CAAC,MAAM,EAAE;QAC5B,MAAM,KAAK,GAAG,cAAc,CAAC,GAAG,EAAE,CAAC;QAEnC,IAAI,KAAK,EAAE;YACT,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,YAAY,EAAE,GAAG,KAAK,CAAC;YAE9C,MAAM,cAAc,GAAG,MAAM,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YACtD,MAAM,mBAAmB,GAAG;gBAC1B,GAAG,CAAC,cAAc,EAAE,YAAY,IAAI,EAAE,CAAC;gBACvC,GAAG,CAAC,cAAc,EAAE,gBAAgB,IAAI,EAAE,CAAC;aAC5C,CAAC;YAEF,0DAA0D;YAC1D,IAAI,YAAY,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C,GAAG,IAAI,IAAI,OAAO,EAAE,CAAC,GAAG,kBAAkB,CAAC;gCAEzE,OAAO,CAAC,kBAAkB,CAAC,CAAC;gCAC5B,WAAW,GAAG,IAAI,CAAC;gCACnB,MAAM;6BACP;yBACF;qBACF;oBAED,IAAI,CAAC,WAAW,EAAE;wBAChB,0FAA0F;wBAC1F,0FAA0F;wBAC1F,MAAM,iBAAiB,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;wBAElD,KAAK,MAAM,eAAe,IAAI,MAAM,CAAC,MAAM,CAAC,iBAAiB,CAAC,EAAE;4BAC9D,IAAI,SAAS,CAAC,eAAe,CAAC,OAAO,EAAE,kBAAkB,CAAC,EAAE;gCAC1D,MAAM,CAAC,cAAc,CAAC,CAAC,eAAe,CAAC,OAAO,CAAC,GAAG,eAAe,CAAC;gCAClE,KAAK,CAAC,YAAY,CAAC,cAAc,CAAC,GAAG,uBAAuB,CAAC;gCAC7D,eAAe,CAAC,UAAU,GAAG,EAAE,CAAC,GAAG,IAAI,IAAI,OAAO,EAAE,CAAC,EAAE,kBAAkB,EAAE,CAAC;gCAC5E,mDAAmD;gCACnD,OAAO,CAAC,eAAe,CAAC,CAAC;gCACzB,MAAM;6BACP;yBACF;qBACF;iBACF;aACF;SACF;KACF;AACH,CAAC","sourcesContent":["import type { PackageDefinitionsCache } from '@ms-cloudpack/bundler-types';\nimport { satisfies } from 'semver';\nimport type { PackageMap } from '../types/PackageMap.js';\nimport type { ResolveMapEntry } from '../types/ResolveMapEntry.js';\n\n/**\n * Given a linkedEntry, iterates through dependencies to ensure they are added to the packageMap,\n * preferring packageMap dependencies over linkedMap dependencies.\n * @param options\n */\n\nexport async function addLinkedEntryDependencies(\n options: {\n appMap: PackageMap;\n linkMap: PackageMap;\n linkedEntry: ResolveMapEntry;\n },\n context: {\n packages: PackageDefinitionsCache;\n },\n) {\n const { appMap, linkMap, linkedEntry } = options;\n const { packages } = context;\n const visitedEntryPaths = new Set<string>(linkedEntry.path);\n const entriesToVisit: ResolveMapEntry[] = [linkedEntry];\n\n function enqueue(newEntry: ResolveMapEntry) {\n if (!visitedEntryPaths.has(newEntry.path)) {\n visitedEntryPaths.add(newEntry.path);\n entriesToVisit.push(newEntry);\n }\n }\n\n while (entriesToVisit.length) {\n const entry = entriesToVisit.pop();\n\n if (entry) {\n const { name, version, dependencies } = entry;\n\n const linkDefinition = await packages.get(entry.path);\n const versionRequirements = {\n ...(linkDefinition?.dependencies || {}),\n ...(linkDefinition?.peerDependencies || {}),\n };\n\n // Iterate through the dependencies of the linked package.\n if (dependencies) {\n for (const [dependencyName, linkedDependencyVersion] of Object.entries(dependencies)) {\n const appVersions = appMap[dependencyName];\n const versionRequirement = versionRequirements[dependencyName] as string;\n let isSatisfied = false;\n\n if (!appVersions) {\n // The app does not have any version of this dependency, we need to bring over the version\n // used by the linkedEntry.\n const dependencyEntry = linkMap[dependencyName]?.[linkedDependencyVersion];\n appMap[dependencyName] = { [linkedDependencyVersion]: dependencyEntry };\n dependencyEntry.requiredBy = { [`${name}@${version}`]: versionRequirement };\n\n // Recursive through the dependency's dependencies.\n enqueue(dependencyEntry);\n isSatisfied = true;\n } else {\n // We have at least 1 or more versions of this dependency already. If a sufficient version\n // of the dependency is already in the appMap, we we just need to update the linkedEntry's\n // dependency and the dependency's requiredBy record for the parent.\n const appDependencyVersions = Object.values(appMap[dependencyName]);\n\n if (appDependencyVersions.length === 1 && !appDependencyVersions[0].isExternal) {\n continue;\n }\n\n for (const appDependencyEntry of appDependencyVersions) {\n // If the dependency satisfies the semver, use that!\n if (appDependencyEntry.isLinked || satisfies(appDependencyEntry.version, versionRequirement)) {\n entry.dependencies[dependencyName] = appDependencyEntry.version;\n appDependencyEntry.requiredBy[`${name}@${version}`] = versionRequirement;\n\n enqueue(appDependencyEntry);\n isSatisfied = true;\n break;\n }\n }\n }\n\n if (!isSatisfied) {\n // We have at least 1 version of this dependency but nothing satisfies the requirement. We\n // need to introduce a duplicate. During the final pass, we will remove non-required deps.\n const dependencyEntries = linkMap[dependencyName];\n\n for (const dependencyEntry of Object.values(dependencyEntries)) {\n if (satisfies(dependencyEntry.version, versionRequirement)) {\n appMap[dependencyName][dependencyEntry.version] = dependencyEntry;\n entry.dependencies[dependencyName] = linkedDependencyVersion;\n dependencyEntry.requiredBy = { [`${name}@${version}`]: versionRequirement };\n // Recursive through the dependency's dependencies.\n enqueue(dependencyEntry);\n break;\n }\n }\n }\n }\n }\n }\n }\n}\n"]}
1
+ {"version":3,"file":"addLinkedEntryDependencies.js","sourceRoot":"","sources":["../../src/createResolveMap/addLinkedEntryDependencies.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAInC;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,0BAA0B,CAC9C,OAIC,EACD,OAEC;IAED,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC;IACjD,MAAM,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC;IAC7B,MAAM,iBAAiB,GAAG,IAAI,GAAG,CAAS,WAAW,CAAC,IAAI,CAAC,CAAC;IAC5D,MAAM,cAAc,GAAsB,CAAC,WAAW,CAAC,CAAC;IAExD,SAAS,OAAO,CAAC,QAAyB;QACxC,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE;YACzC,iBAAiB,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;YACrC,cAAc,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;SAC/B;IACH,CAAC;IAED,OAAO,cAAc,CAAC,MAAM,EAAE;QAC5B,kGAAkG;QAClG,MAAM,KAAK,GAAG,cAAc,CAAC,GAAG,EAAG,CAAC;QAEpC,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,YAAY,EAAE,GAAG,KAAK,CAAC;QAE9C,MAAM,cAAc,GAAG,MAAM,QAAQ,CAAC,GAAG,CAAC,KAAK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AC,CAAC,CAAC,QAAQ,IAAI,SAAS,CAAC,CAAC,CAAC,OAAO,EAAE,kBAAkB,CAAC,CAC9D,CAAC;gBAEF,IAAI,kBAAkB,EAAE;oBACtB,oDAAoD;oBACpD,KAAK,CAAC,YAAY,CAAC,cAAc,CAAC,GAAG,kBAAkB,CAAC,OAAO,CAAC;oBAChE,kBAAkB,CAAC,UAAU,CAAC,GAAG,IAAI,IAAI,OAAO,EAAE,CAAC,GAAG,kBAAkB,CAAC;oBAEzE,OAAO,CAAC,kBAAkB,CAAC,CAAC;iBAC7B;qBAAM;oBACL,yFAAyF;oBACzF,6FAA6F;oBAC7F,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,cAAc,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAC9E,SAAS,CAAC,CAAC,CAAC,OAAO,EAAE,kBAAkB,CAAC,CACzC,CAAC;oBACF,IAAI,eAAe,EAAE;wBACnB,WAAW,CAAC,eAAe,CAAC,OAAO,CAAC,GAAG,eAAe,CAAC;wBACvD,KAAK,CAAC,YAAY,CAAC,cAAc,CAAC,GAAG,uBAAuB,CAAC;wBAC7D,eAAe,CAAC,UAAU,GAAG,EAAE,CAAC,GAAG,IAAI,IAAI,OAAO,EAAE,CAAC,EAAE,kBAAkB,EAAE,CAAC;wBAC5E,mDAAmD;wBACnD,OAAO,CAAC,eAAe,CAAC,CAAC;qBAC1B;iBACF;aACF;SACF;KACF;AACH,CAAC","sourcesContent":["import type { PackageDefinitionsCache } from '@ms-cloudpack/bundler-types';\nimport { satisfies } from 'semver';\nimport type { PackageMap } from '../types/PackageMap.js';\nimport type { ResolveMapEntry } from '../types/ResolveMapEntry.js';\n\n/**\n * Given a linkedEntry, iterates through dependencies to ensure they are added to the packageMap,\n * preferring packageMap dependencies over linkedMap dependencies.\n */\nexport async function addLinkedEntryDependencies(\n options: {\n appMap: PackageMap;\n linkMap: PackageMap;\n linkedEntry: ResolveMapEntry;\n },\n context: {\n packages: PackageDefinitionsCache;\n },\n) {\n const { appMap, linkMap, linkedEntry } = options;\n const { packages } = context;\n const visitedEntryPaths = new Set<string>(linkedEntry.path);\n const entriesToVisit: ResolveMapEntry[] = [linkedEntry];\n\n function enqueue(newEntry: ResolveMapEntry) {\n if (!visitedEntryPaths.has(newEntry.path)) {\n visitedEntryPaths.add(newEntry.path);\n entriesToVisit.push(newEntry);\n }\n }\n\n while (entriesToVisit.length) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- already checked the length\n const entry = entriesToVisit.pop()!;\n\n const { name, version, dependencies } = entry;\n\n const linkDefinition = await packages.get(entry.path);\n const versionRequirements = {\n ...(linkDefinition?.dependencies || {}),\n ...(linkDefinition?.peerDependencies || {}),\n };\n\n // Iterate through the dependencies of the linked package.\n for (const [dependencyName, linkedDependencyVersion] of Object.entries(dependencies)) {\n const versionRequirement = versionRequirements[dependencyName];\n if (!versionRequirement) {\n continue;\n }\n\n const appVersions = appMap[dependencyName];\n\n if (!appVersions) {\n // The app does not have any version of this dependency, so we need to bring over the version\n // used by the linkedEntry.\n const dependencyEntry = linkMap[dependencyName]?.[linkedDependencyVersion];\n if (dependencyEntry) {\n appMap[dependencyName] = { [linkedDependencyVersion]: dependencyEntry };\n dependencyEntry.requiredBy = { [`${name}@${version}`]: versionRequirement };\n\n // Recurse through the dependency's dependencies.\n enqueue(dependencyEntry);\n }\n } else {\n // We have one or more versions of this dependency already. If a sufficient version\n // of the dependency is already in the appMap, we we just need to update the linkedEntry's\n // dependency and the dependency's requiredBy record for the parent.\n const appDependencyVersions = Object.values(appVersions);\n\n if (appDependencyVersions.length === 1 && !appDependencyVersions[0]?.isExternal) {\n continue;\n }\n\n // See if an existing version of the dependency satisfies the semver.\n const appDependencyEntry = appDependencyVersions.find(\n (e) => e.isLinked || satisfies(e.version, versionRequirement),\n );\n\n if (appDependencyEntry) {\n // If the dependency satisfies the semver, use that!\n entry.dependencies[dependencyName] = appDependencyEntry.version;\n appDependencyEntry.requiredBy[`${name}@${version}`] = versionRequirement;\n\n enqueue(appDependencyEntry);\n } else {\n // We have at least one version of this dependency but nothing satisfies the requirement.\n // We need to introduce a duplicate. During the final pass, we will remove non-required deps.\n const dependencyEntry = Object.values(linkMap[dependencyName] || {}).find((e) =>\n satisfies(e.version, versionRequirement),\n );\n if (dependencyEntry) {\n appVersions[dependencyEntry.version] = dependencyEntry;\n entry.dependencies[dependencyName] = linkedDependencyVersion;\n dependencyEntry.requiredBy = { [`${name}@${version}`]: versionRequirement };\n // Recursive through the dependency's dependencies.\n enqueue(dependencyEntry);\n }\n }\n }\n }\n }\n}\n"]}
@@ -5,6 +5,6 @@ import type { PackageMap } from '../types/PackageMap.js';
5
5
  */
6
6
  export declare function convertToResolveMap(options: {
7
7
  appMap: PackageMap;
8
- paths: string[];
8
+ rootPaths: string[];
9
9
  }): ResolveMap;
10
10
  //# sourceMappingURL=convertToResolveMap.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"convertToResolveMap.d.ts","sourceRoot":"","sources":["../../src/createResolveMap/convertToResolveMap.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAGzD;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE;IAAE,MAAM,EAAE,UAAU,CAAC;IAAC,KAAK,EAAE,MAAM,EAAE,CAAA;CAAE,GAAG,UAAU,CAsBhG"}
1
+ {"version":3,"file":"convertToResolveMap.d.ts","sourceRoot":"","sources":["../../src/createResolveMap/convertToResolveMap.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAGzD;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE;IAAE,MAAM,EAAE,UAAU,CAAC;IAAC,SAAS,EAAE,MAAM,EAAE,CAAA;CAAE,GAAG,UAAU,CAuBpG"}
@@ -3,12 +3,12 @@ import { entrySorter } from './entrySorter.js';
3
3
  * Given a PackageMap and all root paths (appPath and linked paths), returns a ResolveMap.
4
4
  */
5
5
  export function convertToResolveMap(options) {
6
- const { paths, appMap } = options;
6
+ const { rootPaths, appMap } = options;
7
7
  const resolveMap = {};
8
8
  for (const [packageName, packageEntries] of Object.entries(appMap)) {
9
9
  // Filter to root packages and packages which are required by other packages.
10
10
  const sortedPackageEntries = Object.values(packageEntries)
11
- .filter((e) => paths.indexOf(e.path) >= 0 || Object.keys(e.requiredBy).length)
11
+ .filter((e) => rootPaths.includes(e.path) || Object.keys(e.requiredBy).length)
12
12
  .sort(entrySorter);
13
13
  // Get the sorted package entries based on the most to least requiredBy references. This
14
14
  // ends up reducing the size of the resolve map by minimizing scoped cases.
@@ -1 +1 @@
1
- {"version":3,"file":"convertToResolveMap.js","sourceRoot":"","sources":["../../src/createResolveMap/convertToResolveMap.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C;;GAEG;AACH,MAAM,UAAU,mBAAmB,CAAC,OAAgD;IAClF,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;IAClC,MAAM,UAAU,GAAe,EAAE,CAAC;IAElC,KAAK,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;QAClE,6EAA6E;QAC7E,MAAM,oBAAoB,GAAG,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC;aACvD,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC;aAC7E,IAAI,CAAC,WAAW,CAAC,CAAC;QACrB,wFAAwF;QACxF,2EAA2E;QAC3E,IAAI,oBAAoB,CAAC,MAAM,EAAE;YAC/B,MAAM,KAAK,GAAG,CAAC,UAAU,CAAC,WAAW,CAAC,GAAG,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAC;YAElE,wDAAwD;YACxD,IAAI,oBAAoB,CAAC,MAAM,GAAG,CAAC,EAAE;gBACnC,KAAK,CAAC,cAAc,GAAG,MAAM,CAAC,WAAW,CAAC,oBAAoB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;aACrG;SACF;KACF;IAED,OAAO,UAAU,CAAC;AACpB,CAAC","sourcesContent":["import type { ResolveMap } from '../types/ResolveMap.js';\nimport type { PackageMap } from '../types/PackageMap.js';\nimport { entrySorter } from './entrySorter.js';\n\n/**\n * Given a PackageMap and all root paths (appPath and linked paths), returns a ResolveMap.\n */\nexport function convertToResolveMap(options: { appMap: PackageMap; paths: string[] }): ResolveMap {\n const { paths, appMap } = options;\n const resolveMap: ResolveMap = {};\n\n for (const [packageName, packageEntries] of Object.entries(appMap)) {\n // Filter to root packages and packages which are required by other packages.\n const sortedPackageEntries = Object.values(packageEntries)\n .filter((e) => paths.indexOf(e.path) >= 0 || Object.keys(e.requiredBy).length)\n .sort(entrySorter);\n // Get the sorted package entries based on the most to least requiredBy references. This\n // ends up reducing the size of the resolve map by minimizing scoped cases.\n if (sortedPackageEntries.length) {\n const entry = (resolveMap[packageName] = sortedPackageEntries[0]);\n\n // Update scoped versions (version to resolve map entry)\n if (sortedPackageEntries.length > 1) {\n entry.scopedVersions = Object.fromEntries(sortedPackageEntries.slice(1).map((e) => [e.version, e]));\n }\n }\n }\n\n return resolveMap;\n}\n"]}
1
+ {"version":3,"file":"convertToResolveMap.js","sourceRoot":"","sources":["../../src/createResolveMap/convertToResolveMap.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C;;GAEG;AACH,MAAM,UAAU,mBAAmB,CAAC,OAAoD;IACtF,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;IACtC,MAAM,UAAU,GAAe,EAAE,CAAC;IAElC,KAAK,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;QAClE,6EAA6E;QAC7E,MAAM,oBAAoB,GAAG,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC;aACvD,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC;aAC7E,IAAI,CAAC,WAAW,CAAC,CAAC;QAErB,wFAAwF;QACxF,2EAA2E;QAC3E,IAAI,oBAAoB,CAAC,MAAM,EAAE;YAC/B,MAAM,KAAK,GAAG,CAAC,UAAU,CAAC,WAAW,CAAC,GAAG,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAC;YAElE,wDAAwD;YACxD,IAAI,oBAAoB,CAAC,MAAM,GAAG,CAAC,EAAE;gBACnC,KAAK,CAAC,cAAc,GAAG,MAAM,CAAC,WAAW,CAAC,oBAAoB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;aACrG;SACF;KACF;IAED,OAAO,UAAU,CAAC;AACpB,CAAC","sourcesContent":["import type { ResolveMap } from '../types/ResolveMap.js';\nimport type { PackageMap } from '../types/PackageMap.js';\nimport { entrySorter } from './entrySorter.js';\n\n/**\n * Given a PackageMap and all root paths (appPath and linked paths), returns a ResolveMap.\n */\nexport function convertToResolveMap(options: { appMap: PackageMap; rootPaths: string[] }): ResolveMap {\n const { rootPaths, appMap } = options;\n const resolveMap: ResolveMap = {};\n\n for (const [packageName, packageEntries] of Object.entries(appMap)) {\n // Filter to root packages and packages which are required by other packages.\n const sortedPackageEntries = Object.values(packageEntries)\n .filter((e) => rootPaths.includes(e.path) || Object.keys(e.requiredBy).length)\n .sort(entrySorter);\n\n // Get the sorted package entries based on the most to least requiredBy references. This\n // ends up reducing the size of the resolve map by minimizing scoped cases.\n if (sortedPackageEntries.length) {\n const entry = (resolveMap[packageName] = sortedPackageEntries[0]);\n\n // Update scoped versions (version to resolve map entry)\n if (sortedPackageEntries.length > 1) {\n entry.scopedVersions = Object.fromEntries(sortedPackageEntries.slice(1).map((e) => [e.version, e]));\n }\n }\n }\n\n return resolveMap;\n}\n"]}
@@ -2,14 +2,15 @@ import type { LinkedPath } from '../types/LinkedPath.js';
2
2
  import type { ResolveMap } from '../types/ResolveMap.js';
3
3
  import type { PackageDefinitionsCache } from '@ms-cloudpack/bundler-types';
4
4
  /**
5
- * Create a resolve map for a given app path. We do this by walking the dependency tree
6
- * of the app to build a map of all packages and their dependencies. We then sort the
7
- * dependencies by the number of other packages that depend on them. The package with the
8
- * most dependencies is considered the dominant version and is the one that will be used
9
- * by the bundler. Once this has been resolved, linkedPaths are evaluated separately by
10
- * discovering their dependencies and redirecting any existing dependencies to the linked
11
- * package. Transitive dependencies of the linked package are validated and any dependencies
12
- * which aren't already in the resolve map are added as scoped versions.
5
+ * Create a resolve map for a given `appPath`.
6
+ * 1. Walk the dependency tree to build a map of all packages and their dependencies.
7
+ * 2. If `linkedPaths` are provided, for each one:
8
+ * 1. Walk its dependency tree to build a map as above.
9
+ * 2. Redirect any existing dependencies to the linked package.
10
+ * 3. Ensure that any transitive dependencies of the linked package which aren't already
11
+ * satisfied in the resolve map are added as scoped versions.
12
+ * 3. For each dependency, sort the versions by the number of packages that depend on that version.
13
+ * The most popular version will be considered the "default", to reduce the size of scoped versions.
13
14
  */
14
15
  export declare function createResolveMap(options: {
15
16
  appPath: string;
@@ -1 +1 @@
1
- {"version":3,"file":"createResolveMap.d.ts","sourceRoot":"","sources":["../../src/createResolveMap/createResolveMap.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAIzD,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAE3E;;;;;;;;;GASG;AACH,wBAAsB,gBAAgB,CACpC,OAAO,EAAE;IACP,OAAO,EAAE,MAAM,CAAC;IAChB,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAC3B,WAAW,CAAC,EAAE,UAAU,EAAE,CAAC;IAC3B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,2BAA2B;IAC3B,mBAAmB,CAAC,EAAE,OAAO,CAAC;CAC/B,EACD,OAAO,EAAE;IACP,QAAQ,EAAE,uBAAuB,CAAC;CACnC,GACA,OAAO,CAAC,UAAU,CAAC,CAmBrB"}
1
+ {"version":3,"file":"createResolveMap.d.ts","sourceRoot":"","sources":["../../src/createResolveMap/createResolveMap.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAIzD,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAE3E;;;;;;;;;;GAUG;AACH,wBAAsB,gBAAgB,CACpC,OAAO,EAAE;IACP,OAAO,EAAE,MAAM,CAAC;IAChB,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAC3B,WAAW,CAAC,EAAE,UAAU,EAAE,CAAC;IAC3B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,2BAA2B;IAC3B,mBAAmB,CAAC,EAAE,OAAO,CAAC;CAC/B,EACD,OAAO,EAAE;IACP,QAAQ,EAAE,uBAAuB,CAAC;CACnC,GACA,OAAO,CAAC,UAAU,CAAC,CAmBrB"}
@@ -2,20 +2,21 @@ import { convertToResolveMap } from './convertToResolveMap.js';
2
2
  import { findPackagesFromPath } from './findPackagesFromPath.js';
3
3
  import { linkPath } from './linkPath.js';
4
4
  /**
5
- * Create a resolve map for a given app path. We do this by walking the dependency tree
6
- * of the app to build a map of all packages and their dependencies. We then sort the
7
- * dependencies by the number of other packages that depend on them. The package with the
8
- * most dependencies is considered the dominant version and is the one that will be used
9
- * by the bundler. Once this has been resolved, linkedPaths are evaluated separately by
10
- * discovering their dependencies and redirecting any existing dependencies to the linked
11
- * package. Transitive dependencies of the linked package are validated and any dependencies
12
- * which aren't already in the resolve map are added as scoped versions.
5
+ * Create a resolve map for a given `appPath`.
6
+ * 1. Walk the dependency tree to build a map of all packages and their dependencies.
7
+ * 2. If `linkedPaths` are provided, for each one:
8
+ * 1. Walk its dependency tree to build a map as above.
9
+ * 2. Redirect any existing dependencies to the linked package.
10
+ * 3. Ensure that any transitive dependencies of the linked package which aren't already
11
+ * satisfied in the resolve map are added as scoped versions.
12
+ * 3. For each dependency, sort the versions by the number of packages that depend on that version.
13
+ * The most popular version will be considered the "default", to reduce the size of scoped versions.
13
14
  */
14
15
  export async function createResolveMap(options, context) {
15
16
  const { appPath, additionalPaths = [], linkedPaths = [], gitRootPath } = options;
16
17
  // First we discover the dependencies for the app.
17
18
  const appMap = await findPackagesFromPath({
18
- paths: [appPath, ...additionalPaths],
19
+ searchPaths: [appPath, ...additionalPaths],
19
20
  gitRootPath,
20
21
  }, context);
21
22
  // Next, we iterate through linked paths to inject them into the packageMap.
@@ -23,6 +24,6 @@ export async function createResolveMap(options, context) {
23
24
  await linkPath({ linkedPath, appMap }, context);
24
25
  }
25
26
  // Finally we condense into a resolve map.
26
- return convertToResolveMap({ appMap, paths: [appPath, ...additionalPaths] });
27
+ return convertToResolveMap({ appMap, rootPaths: [appPath, ...additionalPaths] });
27
28
  }
28
29
  //# sourceMappingURL=createResolveMap.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"createResolveMap.js","sourceRoot":"","sources":["../../src/createResolveMap/createResolveMap.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAGzC;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,OAOC,EACD,OAEC;IAED,MAAM,EAAE,OAAO,EAAE,eAAe,GAAG,EAAE,EAAE,WAAW,GAAG,EAAE,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC;IAEjF,kDAAkD;IAClD,MAAM,MAAM,GAAG,MAAM,oBAAoB,CACvC;QACE,KAAK,EAAE,CAAC,OAAO,EAAE,GAAG,eAAe,CAAC;QACpC,WAAW;KACZ,EACD,OAAO,CACR,CAAC;IAEF,4EAA4E;IAC5E,KAAK,MAAM,UAAU,IAAI,WAAW,EAAE;QACpC,MAAM,QAAQ,CAAC,EAAE,UAAU,EAAE,MAAM,EAAE,EAAE,OAAO,CAAC,CAAC;KACjD;IAED,0CAA0C;IAC1C,OAAO,mBAAmB,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,OAAO,EAAE,GAAG,eAAe,CAAC,EAAE,CAAC,CAAC;AAC/E,CAAC","sourcesContent":["import type { LinkedPath } from '../types/LinkedPath.js';\nimport type { ResolveMap } from '../types/ResolveMap.js';\nimport { convertToResolveMap } from './convertToResolveMap.js';\nimport { findPackagesFromPath } from './findPackagesFromPath.js';\nimport { linkPath } from './linkPath.js';\nimport type { PackageDefinitionsCache } from '@ms-cloudpack/bundler-types';\n\n/**\n * Create a resolve map for a given app path. We do this by walking the dependency tree\n * of the app to build a map of all packages and their dependencies. We then sort the\n * dependencies by the number of other packages that depend on them. The package with the\n * most dependencies is considered the dominant version and is the one that will be used\n * by the bundler. Once this has been resolved, linkedPaths are evaluated separately by\n * discovering their dependencies and redirecting any existing dependencies to the linked\n * package. Transitive dependencies of the linked package are validated and any dependencies\n * which aren't already in the resolve map are added as scoped versions.\n */\nexport async function createResolveMap(\n options: {\n appPath: string;\n additionalPaths?: string[];\n linkedPaths?: LinkedPath[];\n gitRootPath?: string;\n /** @deprecated Not used */\n useStrictVersioning?: boolean;\n },\n context: {\n packages: PackageDefinitionsCache;\n },\n): Promise<ResolveMap> {\n const { appPath, additionalPaths = [], linkedPaths = [], gitRootPath } = options;\n\n // First we discover the dependencies for the app.\n const appMap = await findPackagesFromPath(\n {\n paths: [appPath, ...additionalPaths],\n gitRootPath,\n },\n context,\n );\n\n // Next, we iterate through linked paths to inject them into the packageMap.\n for (const linkedPath of linkedPaths) {\n await linkPath({ linkedPath, appMap }, context);\n }\n\n // Finally we condense into a resolve map.\n return convertToResolveMap({ appMap, paths: [appPath, ...additionalPaths] });\n}\n"]}
1
+ {"version":3,"file":"createResolveMap.js","sourceRoot":"","sources":["../../src/createResolveMap/createResolveMap.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAGzC;;;;;;;;;;GAUG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,OAOC,EACD,OAEC;IAED,MAAM,EAAE,OAAO,EAAE,eAAe,GAAG,EAAE,EAAE,WAAW,GAAG,EAAE,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC;IAEjF,kDAAkD;IAClD,MAAM,MAAM,GAAG,MAAM,oBAAoB,CACvC;QACE,WAAW,EAAE,CAAC,OAAO,EAAE,GAAG,eAAe,CAAC;QAC1C,WAAW;KACZ,EACD,OAAO,CACR,CAAC;IAEF,4EAA4E;IAC5E,KAAK,MAAM,UAAU,IAAI,WAAW,EAAE;QACpC,MAAM,QAAQ,CAAC,EAAE,UAAU,EAAE,MAAM,EAAE,EAAE,OAAO,CAAC,CAAC;KACjD;IAED,0CAA0C;IAC1C,OAAO,mBAAmB,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC,OAAO,EAAE,GAAG,eAAe,CAAC,EAAE,CAAC,CAAC;AACnF,CAAC","sourcesContent":["import type { LinkedPath } from '../types/LinkedPath.js';\nimport type { ResolveMap } from '../types/ResolveMap.js';\nimport { convertToResolveMap } from './convertToResolveMap.js';\nimport { findPackagesFromPath } from './findPackagesFromPath.js';\nimport { linkPath } from './linkPath.js';\nimport type { PackageDefinitionsCache } from '@ms-cloudpack/bundler-types';\n\n/**\n * Create a resolve map for a given `appPath`.\n * 1. Walk the dependency tree to build a map of all packages and their dependencies.\n * 2. If `linkedPaths` are provided, for each one:\n * 1. Walk its dependency tree to build a map as above.\n * 2. Redirect any existing dependencies to the linked package.\n * 3. Ensure that any transitive dependencies of the linked package which aren't already\n * satisfied in the resolve map are added as scoped versions.\n * 3. For each dependency, sort the versions by the number of packages that depend on that version.\n * The most popular version will be considered the \"default\", to reduce the size of scoped versions.\n */\nexport async function createResolveMap(\n options: {\n appPath: string;\n additionalPaths?: string[];\n linkedPaths?: LinkedPath[];\n gitRootPath?: string;\n /** @deprecated Not used */\n useStrictVersioning?: boolean;\n },\n context: {\n packages: PackageDefinitionsCache;\n },\n): Promise<ResolveMap> {\n const { appPath, additionalPaths = [], linkedPaths = [], gitRootPath } = options;\n\n // First we discover the dependencies for the app.\n const appMap = await findPackagesFromPath(\n {\n searchPaths: [appPath, ...additionalPaths],\n gitRootPath,\n },\n context,\n );\n\n // Next, we iterate through linked paths to inject them into the packageMap.\n for (const linkedPath of linkedPaths) {\n await linkPath({ linkedPath, appMap }, context);\n }\n\n // Finally we condense into a resolve map.\n return convertToResolveMap({ appMap, rootPaths: [appPath, ...additionalPaths] });\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"detachEntry.d.ts","sourceRoot":"","sources":["../../src/createResolveMap/detachEntry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAGzD;;GAEG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE;IAAE,MAAM,EAAE,UAAU,CAAC;IAAC,KAAK,EAAE,eAAe,CAAA;CAAE,QAkClF"}
1
+ {"version":3,"file":"detachEntry.d.ts","sourceRoot":"","sources":["../../src/createResolveMap/detachEntry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAGzD;;GAEG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE;IAAE,MAAM,EAAE,UAAU,CAAC;IAAC,KAAK,EAAE,eAAe,CAAA;CAAE,QAmClF"}
@@ -3,30 +3,30 @@ import { parseRequiredBy } from './parseRequiredBy.js';
3
3
  * Removes requiredBy references for an entry being removed.
4
4
  */
5
5
  export function detachEntry(options) {
6
- const { appMap, entry: entryToRemove } = options;
7
- const dependenciesToDetach = [entryToRemove];
6
+ const { appMap } = options;
7
+ const dependenciesToDetach = [options.entry];
8
8
  while (dependenciesToDetach.length) {
9
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- already checked length
9
10
  const entry = dependenciesToDetach.pop();
10
11
  const { name, version, requiredBy } = entry;
11
- if (!entry.isLinked) {
12
- if (appMap[name]?.[version]) {
13
- // Disconnect the entry from consumers.
14
- for (const requiredByName of Object.keys(requiredBy)) {
15
- const [parentName, parentVersion] = parseRequiredBy(requiredByName);
16
- const parentEntry = appMap[parentName]?.[parentVersion];
17
- if (parentEntry) {
18
- delete parentEntry.dependencies[name];
19
- }
20
- }
21
- // Disconnect dependencies from the entry.
22
- for (const [dependencyName, dependencyVersion] of Object.entries(entry.dependencies)) {
23
- const dependencyEntry = appMap[dependencyName]?.[dependencyVersion];
24
- if (dependencyEntry) {
25
- delete dependencyEntry.requiredBy[`${name}@${version}`];
26
- if (Object.keys(dependencyEntry.requiredBy).length === 0) {
27
- dependenciesToDetach.push(dependencyEntry);
28
- }
29
- }
12
+ if (entry.isLinked || !appMap[name]?.[version]) {
13
+ continue;
14
+ }
15
+ // Disconnect the entry from consumers.
16
+ for (const requiredByName of Object.keys(requiredBy)) {
17
+ const { name: parentName, version: parentVersion } = parseRequiredBy(requiredByName);
18
+ const parentEntry = appMap[parentName]?.[parentVersion];
19
+ if (parentEntry) {
20
+ delete parentEntry.dependencies[name];
21
+ }
22
+ }
23
+ // Disconnect dependencies from the entry.
24
+ for (const [dependencyName, dependencyVersion] of Object.entries(entry.dependencies)) {
25
+ const dependencyEntry = appMap[dependencyName]?.[dependencyVersion];
26
+ if (dependencyEntry) {
27
+ delete dependencyEntry.requiredBy[`${name}@${version}`];
28
+ if (Object.keys(dependencyEntry.requiredBy).length === 0) {
29
+ dependenciesToDetach.push(dependencyEntry);
30
30
  }
31
31
  }
32
32
  }
@@ -1 +1 @@
1
- {"version":3,"file":"detachEntry.js","sourceRoot":"","sources":["../../src/createResolveMap/detachEntry.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD;;GAEG;AACH,MAAM,UAAU,WAAW,CAAC,OAAuD;IACjF,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,aAAa,EAAE,GAAG,OAAO,CAAC;IACjD,MAAM,oBAAoB,GAAsB,CAAC,aAAa,CAAC,CAAC;IAEhE,OAAO,oBAAoB,CAAC,MAAM,EAAE;QAClC,MAAM,KAAK,GAAG,oBAAoB,CAAC,GAAG,EAAqB,CAAC;QAC5D,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,UAAU,EAAE,GAAG,KAAK,CAAC;QAE5C,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE;YACnB,IAAI,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,CAAC,EAAE;gBAC3B,uCAAuC;gBACvC,KAAK,MAAM,cAAc,IAAI,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE;oBACpD,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAAG,eAAe,CAAC,cAAc,CAAC,CAAC;oBACpE,MAAM,WAAW,GAAG,MAAM,CAAC,UAAU,CAAC,EAAE,CAAC,aAAa,CAAC,CAAC;oBAExD,IAAI,WAAW,EAAE;wBACf,OAAO,WAAW,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;qBACvC;iBACF;gBAED,0CAA0C;gBAC1C,KAAK,MAAM,CAAC,cAAc,EAAE,iBAAiB,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,YAAY,CAAC,EAAE;oBACpF,MAAM,eAAe,GAAG,MAAM,CAAC,cAAc,CAAC,EAAE,CAAC,iBAAiB,CAAC,CAAC;oBAEpE,IAAI,eAAe,EAAE;wBACnB,OAAO,eAAe,CAAC,UAAU,CAAC,GAAG,IAAI,IAAI,OAAO,EAAE,CAAC,CAAC;wBACxD,IAAI,MAAM,CAAC,IAAI,CAAC,eAAe,CAAC,UAAU,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE;4BACxD,oBAAoB,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;yBAC5C;qBACF;iBACF;aACF;SACF;KACF;AACH,CAAC","sourcesContent":["import type { ResolveMapEntry } from '../types/ResolveMapEntry.js';\nimport type { PackageMap } from '../types/PackageMap.js';\nimport { parseRequiredBy } from './parseRequiredBy.js';\n\n/**\n * Removes requiredBy references for an entry being removed.\n */\nexport function detachEntry(options: { appMap: PackageMap; entry: ResolveMapEntry }) {\n const { appMap, entry: entryToRemove } = options;\n const dependenciesToDetach: ResolveMapEntry[] = [entryToRemove];\n\n while (dependenciesToDetach.length) {\n const entry = dependenciesToDetach.pop() as ResolveMapEntry;\n const { name, version, requiredBy } = entry;\n\n if (!entry.isLinked) {\n if (appMap[name]?.[version]) {\n // Disconnect the entry from consumers.\n for (const requiredByName of Object.keys(requiredBy)) {\n const [parentName, parentVersion] = parseRequiredBy(requiredByName);\n const parentEntry = appMap[parentName]?.[parentVersion];\n\n if (parentEntry) {\n delete parentEntry.dependencies[name];\n }\n }\n\n // Disconnect dependencies from the entry.\n for (const [dependencyName, dependencyVersion] of Object.entries(entry.dependencies)) {\n const dependencyEntry = appMap[dependencyName]?.[dependencyVersion];\n\n if (dependencyEntry) {\n delete dependencyEntry.requiredBy[`${name}@${version}`];\n if (Object.keys(dependencyEntry.requiredBy).length === 0) {\n dependenciesToDetach.push(dependencyEntry);\n }\n }\n }\n }\n }\n }\n}\n"]}
1
+ {"version":3,"file":"detachEntry.js","sourceRoot":"","sources":["../../src/createResolveMap/detachEntry.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD;;GAEG;AACH,MAAM,UAAU,WAAW,CAAC,OAAuD;IACjF,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;IAC3B,MAAM,oBAAoB,GAAsB,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAEhE,OAAO,oBAAoB,CAAC,MAAM,EAAE;QAClC,8FAA8F;QAC9F,MAAM,KAAK,GAAG,oBAAoB,CAAC,GAAG,EAAG,CAAC;QAC1C,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,UAAU,EAAE,GAAG,KAAK,CAAC;QAE5C,IAAI,KAAK,CAAC,QAAQ,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,CAAC,EAAE;YAC9C,SAAS;SACV;QAED,uCAAuC;QACvC,KAAK,MAAM,cAAc,IAAI,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE;YACpD,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,aAAa,EAAE,GAAG,eAAe,CAAC,cAAc,CAAC,CAAC;YACrF,MAAM,WAAW,GAAG,MAAM,CAAC,UAAU,CAAC,EAAE,CAAC,aAAa,CAAC,CAAC;YAExD,IAAI,WAAW,EAAE;gBACf,OAAO,WAAW,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;aACvC;SACF;QAED,0CAA0C;QAC1C,KAAK,MAAM,CAAC,cAAc,EAAE,iBAAiB,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,YAAY,CAAC,EAAE;YACpF,MAAM,eAAe,GAAG,MAAM,CAAC,cAAc,CAAC,EAAE,CAAC,iBAAiB,CAAC,CAAC;YAEpE,IAAI,eAAe,EAAE;gBACnB,OAAO,eAAe,CAAC,UAAU,CAAC,GAAG,IAAI,IAAI,OAAO,EAAE,CAAC,CAAC;gBACxD,IAAI,MAAM,CAAC,IAAI,CAAC,eAAe,CAAC,UAAU,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE;oBACxD,oBAAoB,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;iBAC5C;aACF;SACF;KACF;AACH,CAAC","sourcesContent":["import type { ResolveMapEntry } from '../types/ResolveMapEntry.js';\nimport type { PackageMap } from '../types/PackageMap.js';\nimport { parseRequiredBy } from './parseRequiredBy.js';\n\n/**\n * Removes requiredBy references for an entry being removed.\n */\nexport function detachEntry(options: { appMap: PackageMap; entry: ResolveMapEntry }) {\n const { appMap } = options;\n const dependenciesToDetach: ResolveMapEntry[] = [options.entry];\n\n while (dependenciesToDetach.length) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- already checked length\n const entry = dependenciesToDetach.pop()!;\n const { name, version, requiredBy } = entry;\n\n if (entry.isLinked || !appMap[name]?.[version]) {\n continue;\n }\n\n // Disconnect the entry from consumers.\n for (const requiredByName of Object.keys(requiredBy)) {\n const { name: parentName, version: parentVersion } = parseRequiredBy(requiredByName);\n const parentEntry = appMap[parentName]?.[parentVersion];\n\n if (parentEntry) {\n delete parentEntry.dependencies[name];\n }\n }\n\n // Disconnect dependencies from the entry.\n for (const [dependencyName, dependencyVersion] of Object.entries(entry.dependencies)) {\n const dependencyEntry = appMap[dependencyName]?.[dependencyVersion];\n\n if (dependencyEntry) {\n delete dependencyEntry.requiredBy[`${name}@${version}`];\n if (Object.keys(dependencyEntry.requiredBy).length === 0) {\n dependenciesToDetach.push(dependencyEntry);\n }\n }\n }\n }\n}\n"]}
@@ -8,7 +8,7 @@ export declare function findPackagesFromPath(options: {
8
8
  /**
9
9
  * Paths to search for package.json files and traverse their dependencies to build a PackageMap.
10
10
  */
11
- paths: string[];
11
+ searchPaths: string[];
12
12
  /**
13
13
  * Where to stop looking for packages. If not specified, will look for a git root. If one is not
14
14
  * found, will use the first path in the paths array.
@@ -1 +1 @@
1
- {"version":3,"file":"findPackagesFromPath.d.ts","sourceRoot":"","sources":["../../src/createResolveMap/findPackagesFromPath.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAe,MAAM,6BAA6B,CAAC;AAOxF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAGzD;;;GAGG;AACH,wBAAsB,oBAAoB,CACxC,OAAO,EAAE;IACP;;OAEG;IACH,KAAK,EAAE,MAAM,EAAE,CAAC;IAEhB;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;OAEG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B,EACD,OAAO,EAAE;IACP;;OAEG;IACH,QAAQ,EAAE,uBAAuB,CAAC;CACnC,GACA,OAAO,CAAC,UAAU,CAAC,CA0FrB"}
1
+ {"version":3,"file":"findPackagesFromPath.d.ts","sourceRoot":"","sources":["../../src/createResolveMap/findPackagesFromPath.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAe,MAAM,6BAA6B,CAAC;AAOxF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAGzD;;;GAGG;AACH,wBAAsB,oBAAoB,CACxC,OAAO,EAAE;IACP;;OAEG;IACH,WAAW,EAAE,MAAM,EAAE,CAAC;IAEtB;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;OAEG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B,EACD,OAAO,EAAE;IACP;;OAEG;IACH,QAAQ,EAAE,uBAAuB,CAAC;CACnC,GACA,OAAO,CAAC,UAAU,CAAC,CA0CrB"}