@ms-cloudpack/package-utilities 7.4.11 → 7.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import type { PackageDefinitionsCache } from '@ms-cloudpack/common-types';
1
+ import type { PackageDefinitionsCache, PackageJson } from '@ms-cloudpack/common-types';
2
2
  import type { PackageMap } from '../types/PackageMap.js';
3
3
  import type { ResolveMapEntry } from '../types/ResolveMapEntry.js';
4
4
  /**
@@ -9,6 +9,7 @@ export declare function addLinkedEntryDependencies(options: {
9
9
  appMap: PackageMap;
10
10
  linkMap: PackageMap;
11
11
  linkedEntry: ResolveMapEntry;
12
+ resolutions?: PackageJson['resolutions'];
12
13
  }, context: {
13
14
  packages: PackageDefinitionsCache;
14
15
  }): Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"addLinkedEntryDependencies.d.ts","sourceRoot":"","sources":["../../src/createResolveMap/addLinkedEntryDependencies.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,4BAA4B,CAAC;AAE1E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAGnE;;;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,iBAiFF"}
1
+ {"version":3,"file":"addLinkedEntryDependencies.d.ts","sourceRoot":"","sources":["../../src/createResolveMap/addLinkedEntryDependencies.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAEvF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAGnE;;;GAGG;AACH,wBAAsB,0BAA0B,CAC9C,OAAO,EAAE;IACP,MAAM,EAAE,UAAU,CAAC;IACnB,OAAO,EAAE,UAAU,CAAC;IACpB,WAAW,EAAE,eAAe,CAAC;IAC7B,WAAW,CAAC,EAAE,WAAW,CAAC,aAAa,CAAC,CAAC;CAC1C,EACD,OAAO,EAAE;IACP,QAAQ,EAAE,uBAAuB,CAAC;CACnC,iBAuFF"}
@@ -5,7 +5,7 @@ import { getDependencies } from '../getDependencies.js';
5
5
  * preferring packageMap dependencies over linkedMap dependencies.
6
6
  */
7
7
  export async function addLinkedEntryDependencies(options, context) {
8
- const { appMap, linkMap, linkedEntry } = options;
8
+ const { appMap, linkMap, linkedEntry, resolutions } = options;
9
9
  const { packages } = context;
10
10
  const visitedEntryPaths = new Set(linkedEntry.path);
11
11
  const entriesToVisit = [linkedEntry];
@@ -48,7 +48,13 @@ export async function addLinkedEntryDependencies(options, context) {
48
48
  continue;
49
49
  }
50
50
  // See if an existing version of the dependency satisfies the semver.
51
- const appDependencyEntry = appDependencyVersions.find((e) => e.isLinked || satisfies(e.version, versionRequirement));
51
+ const appDependencyEntry = appDependencyVersions.find((e) =>
52
+ // If the dependency is linked, use that.
53
+ e.isLinked ||
54
+ // If the dependency version is required as a resolution, use that.
55
+ resolutions?.[dependencyName] ||
56
+ // If the dependency satisfies the semver, use that.
57
+ satisfies(e.version, versionRequirement));
52
58
  if (appDependencyEntry) {
53
59
  // If the dependency satisfies the semver, use that!
54
60
  entry.dependencies[dependencyName] = appDependencyEntry.version;
@@ -1 +1 @@
1
- {"version":3,"file":"addLinkedEntryDependencies.js","sourceRoot":"","sources":["../../src/createResolveMap/addLinkedEntryDependencies.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAGnC,OAAO,EAAE,eAAe,EAAE,MAA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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,CAAC;wBACpB,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;oBAC3B,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["import type { PackageDefinitionsCache } from '@ms-cloudpack/common-types';\nimport { satisfies } from 'semver';\nimport type { PackageMap } from '../types/PackageMap.js';\nimport type { ResolveMapEntry } from '../types/ResolveMapEntry.js';\nimport { getDependencies } from '../getDependencies.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 = getDependencies(linkDefinition || {});\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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kB,EAAE,CAAC;oBACvB,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;gBAC9B,CAAC;qBAAM,CAAC;oBACN,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,CAAC;wBACpB,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;oBAC3B,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["import type { PackageDefinitionsCache, PackageJson } from '@ms-cloudpack/common-types';\nimport { satisfies } from 'semver';\nimport type { PackageMap } from '../types/PackageMap.js';\nimport type { ResolveMapEntry } from '../types/ResolveMapEntry.js';\nimport { getDependencies } from '../getDependencies.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 resolutions?: PackageJson['resolutions'];\n },\n context: {\n packages: PackageDefinitionsCache;\n },\n) {\n const { appMap, linkMap, linkedEntry, resolutions } = 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 = getDependencies(linkDefinition || {});\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) =>\n // If the dependency is linked, use that.\n e.isLinked ||\n // If the dependency version is required as a resolution, use that.\n resolutions?.[dependencyName] ||\n // If the dependency satisfies the semver, use that.\n 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"]}
@@ -1,6 +1,6 @@
1
- import type { LinkedPath } from '../types/LinkedPath.js';
2
1
  import type { ResolveMap } from '../types/ResolveMap.js';
3
2
  import type { PackageDefinitionsCache } from '@ms-cloudpack/common-types';
3
+ import type { LinkedPath } from '../types/LinkedPath.js';
4
4
  /**
5
5
  * Create a resolve map for a given `appPath`.
6
6
  * 1. Walk the dependency tree to build a map of all packages and their dependencies.
@@ -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,4BAA4B,CAAC;AAE1E;;;;;;;;;;GAUG;AACH,wBAAsB,gBAAgB,CACpC,OAAO,EAAE;IACP,6DAA6D;IAC7D,OAAO,EAAE,MAAM,CAAC;IAEhB,qEAAqE;IACrE,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAE3B,sCAAsC;IACtC,WAAW,CAAC,EAAE,UAAU,EAAE,CAAC;IAE3B;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB,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":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAIzD,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,4BAA4B,CAAC;AAC1E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEzD;;;;;;;;;;GAUG;AACH,wBAAsB,gBAAgB,CACpC,OAAO,EAAE;IACP,6DAA6D;IAC7D,OAAO,EAAE,MAAM,CAAC;IAEhB,qEAAqE;IACrE,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAE3B,sCAAsC;IACtC,WAAW,CAAC,EAAE,UAAU,EAAE,CAAC;IAE3B;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB,2BAA2B;IAC3B,mBAAmB,CAAC,EAAE,OAAO,CAAC;CAC/B,EACD,OAAO,EAAE;IACP,QAAQ,EAAE,uBAAuB,CAAC;CACnC,GACA,OAAO,CAAC,UAAU,CAAC,CAuBrB"}
@@ -1,3 +1,4 @@
1
+ import { findProjectRoot } from '../findProjectRoot.js';
1
2
  import { convertToResolveMap } from './convertToResolveMap.js';
2
3
  import { findPackagesFromPath } from './findPackagesFromPath.js';
3
4
  import { linkPath } from './linkPath.js';
@@ -13,7 +14,9 @@ import { linkPath } from './linkPath.js';
13
14
  * The most popular version will be considered the "default", to reduce the size of scoped versions.
14
15
  */
15
16
  export async function createResolveMap(options, context) {
16
- const { appPath, additionalPaths = [], linkedPaths = [], rootPath } = options;
17
+ const { appPath, additionalPaths = [], linkedPaths = [] } = options;
18
+ const rootPath = options.rootPath || findProjectRoot(appPath, { noPackageRoot: true });
19
+ const repoDefinition = rootPath ? await context.packages.get(rootPath) : undefined;
17
20
  // First we discover the dependencies for the app.
18
21
  const appMap = await findPackagesFromPath({
19
22
  searchPaths: [appPath, ...additionalPaths],
@@ -21,7 +24,7 @@ export async function createResolveMap(options, context) {
21
24
  }, context);
22
25
  // Next, we iterate through linked paths to inject them into the packageMap.
23
26
  for (const linkedPath of linkedPaths) {
24
- await linkPath({ linkedPath, appMap }, context);
27
+ await linkPath({ linkedPath, appMap, repoDefinition }, context);
25
28
  }
26
29
  // Finally we condense into a resolve map.
27
30
  return convertToResolveMap({ appMap, rootPaths: [appPath, ...additionalPaths] });
@@ -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;;;;;;;;;;GAUG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,OAkBC,EACD,OAEC;IAED,MAAM,EAAE,OAAO,EAAE,eAAe,GAAG,EAAE,EAAE,WAAW,GAAG,EAAE,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC;IAE9E,kDAAkD;IAClD,MAAM,MAAM,GAAG,MAAM,oBAAoB,CACvC;QACE,WAAW,EAAE,CAAC,OAAO,EAAE,GAAG,eAAe,CAAC;QAC1C,QAAQ;KACT,EACD,OAAO,CACR,CAAC;IAEF,4EAA4E;IAC5E,KAAK,MAAM,UAAU,IAAI,WAAW,EAAE,CAAC;QACrC,MAAM,QAAQ,CAAC,EAAE,UAAU,EAAE,MAAM,EAAE,EAAE,OAAO,CAAC,CAAC;IAClD,CAAC;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/common-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 /** Path to the app whose dependencies we want to resolve. */\n appPath: string;\n\n /** Any additional packages whose dependencies we want to resolve. */\n additionalPaths?: string[];\n\n /** See `createResolveMap` comment. */\n linkedPaths?: LinkedPath[];\n\n /**\n * Where to stop looking for packages (mainly used for testing).\n * If not specified, will look for the project/git root of the `appPath`.\n */\n rootPath?: string;\n\n /** @deprecated Not used */\n useStrictVersioning?: boolean;\n },\n context: {\n packages: PackageDefinitionsCache;\n },\n): Promise<ResolveMap> {\n const { appPath, additionalPaths = [], linkedPaths = [], rootPath } = options;\n\n // First we discover the dependencies for the app.\n const appMap = await findPackagesFromPath(\n {\n searchPaths: [appPath, ...additionalPaths],\n rootPath,\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
+ {"version":3,"file":"createResolveMap.js","sourceRoot":"","sources":["../../src/createResolveMap/createResolveMap.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAExD,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAIzC;;;;;;;;;;GAUG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,OAkBC,EACD,OAEC;IAED,MAAM,EAAE,OAAO,EAAE,eAAe,GAAG,EAAE,EAAE,WAAW,GAAG,EAAE,EAAE,GAAG,OAAO,CAAC;IAEpE,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,eAAe,CAAC,OAAO,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC;IAEvF,MAAM,cAAc,GAAG,QAAQ,CAAC,CAAC,CAAC,MAAM,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAEnF,kDAAkD;IAClD,MAAM,MAAM,GAAG,MAAM,oBAAoB,CACvC;QACE,WAAW,EAAE,CAAC,OAAO,EAAE,GAAG,eAAe,CAAC;QAC1C,QAAQ;KACT,EACD,OAAO,CACR,CAAC;IAEF,4EAA4E;IAC5E,KAAK,MAAM,UAAU,IAAI,WAAW,EAAE,CAAC;QACrC,MAAM,QAAQ,CAAC,EAAE,UAAU,EAAE,MAAM,EAAE,cAAc,EAAE,EAAE,OAAO,CAAC,CAAC;IAClE,CAAC;IAED,0CAA0C;IAC1C,OAAO,mBAAmB,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC,OAAO,EAAE,GAAG,eAAe,CAAC,EAAE,CAAC,CAAC;AACnF,CAAC","sourcesContent":["import { findProjectRoot } from '../findProjectRoot.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/common-types';\nimport type { LinkedPath } from '../types/LinkedPath.js';\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 /** Path to the app whose dependencies we want to resolve. */\n appPath: string;\n\n /** Any additional packages whose dependencies we want to resolve. */\n additionalPaths?: string[];\n\n /** See `createResolveMap` comment. */\n linkedPaths?: LinkedPath[];\n\n /**\n * Where to stop looking for packages (mainly used for testing).\n * If not specified, will look for the project/git root of the `appPath`.\n */\n rootPath?: string;\n\n /** @deprecated Not used */\n useStrictVersioning?: boolean;\n },\n context: {\n packages: PackageDefinitionsCache;\n },\n): Promise<ResolveMap> {\n const { appPath, additionalPaths = [], linkedPaths = [] } = options;\n\n const rootPath = options.rootPath || findProjectRoot(appPath, { noPackageRoot: true });\n\n const repoDefinition = rootPath ? await context.packages.get(rootPath) : undefined;\n\n // First we discover the dependencies for the app.\n const appMap = await findPackagesFromPath(\n {\n searchPaths: [appPath, ...additionalPaths],\n rootPath,\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, repoDefinition }, context);\n }\n\n // Finally we condense into a resolve map.\n return convertToResolveMap({ appMap, rootPaths: [appPath, ...additionalPaths] });\n}\n"]}
@@ -1,12 +1,13 @@
1
1
  import type { LinkedPath } from '../types/LinkedPath.js';
2
2
  import type { PackageMap } from '../types/PackageMap.js';
3
- import type { PackageDefinitionsCache } from '@ms-cloudpack/common-types';
3
+ import type { PackageDefinitionsCache, PackageJson } from '@ms-cloudpack/common-types';
4
4
  /**
5
5
  * Given a linked path, an appMap, find packages from the linked path and add them to the appMap.
6
6
  */
7
7
  export declare function linkPath(options: {
8
8
  linkedPath: LinkedPath;
9
9
  appMap: PackageMap;
10
+ repoDefinition?: PackageJson;
10
11
  }, context: {
11
12
  packages: PackageDefinitionsCache;
12
13
  }): Promise<void>;
@@ -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,4BAA4B,CAAC;AAE1E;;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,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAEvF;;GAEG;AACH,wBAAsB,QAAQ,CAC5B,OAAO,EAAE;IACP,UAAU,EAAE,UAAU,CAAC;IACvB,MAAM,EAAE,UAAU,CAAC;IACnB,cAAc,CAAC,EAAE,WAAW,CAAC;CAC9B,EACD,OAAO,EAAE;IACP,QAAQ,EAAE,uBAAuB,CAAC;CACnC,iBA4FF"}
@@ -7,13 +7,14 @@ import { slash } from '@ms-cloudpack/path-string-parsing';
7
7
  * Given a linked path, an appMap, find packages from the linked path and add them to the appMap.
8
8
  */
9
9
  export async function linkPath(options, context) {
10
- const { linkedPath, appMap } = options;
10
+ const { linkedPath, appMap, repoDefinition } = options;
11
11
  const linkMap = await findPackagesFromPath({
12
12
  searchPaths: [linkedPath.path],
13
13
  discoverPackages: true,
14
14
  }, context);
15
15
  const entriesToLink = [];
16
16
  const { path, ignoredPackages = [], includeAll } = linkedPath;
17
+ const resolutions = linkedPath.ignoreResolutions ? undefined : repoDefinition?.resolutions;
17
18
  // Iterate through the linkMap, looking for internal packages to link to the appMap.
18
19
  for (const [packageName, packageVersions] of Object.entries(linkMap)) {
19
20
  const appEntries = Object.values(appMap[packageName] || {});
@@ -75,7 +76,7 @@ export async function linkPath(options, context) {
75
76
  }
76
77
  // Once all linked entries have been added, ensure their dependencies are resolved.
77
78
  for (const linkedEntry of entriesToLink) {
78
- await addLinkedEntryDependencies({ linkedEntry, appMap: appMap, linkMap }, context);
79
+ await addLinkedEntryDependencies({ linkedEntry, appMap: appMap, linkMap, resolutions }, context);
79
80
  }
80
81
  }
81
82
  function isContainedInPath(path, basePath) {
@@ -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,MA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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/common-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 continue;\n }\n\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 // 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 dependencies. 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
+ {"version":3,"file":"linkPath.js","sourceRoot":"","sources":["../../src/createResolveMap/linkPath.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,0BAA0B,EAAE,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C;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,CAAC;QAClC,cAAc,IAAI,GAAG,CAAC;IACxB,CAAC;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, PackageJson } from '@ms-cloudpack/common-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 repoDefinition?: PackageJson;\n },\n context: {\n packages: PackageDefinitionsCache;\n },\n) {\n const { linkedPath, appMap, repoDefinition } = 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 const resolutions = linkedPath.ignoreResolutions ? undefined : repoDefinition?.resolutions;\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 continue;\n }\n\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 // 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 dependencies. 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, resolutions }, 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"]}
@@ -7,7 +7,8 @@ import type { PackageJsonExports } from '@ms-cloudpack/common-types';
7
7
  * Notes:
8
8
  * - This diverges from the behavior of Node in that conditions are considered in order of
9
9
  * the `conditions` array, NOT in the order keys are defined in the exports map.
10
- * - Null export values are currently not supported.
10
+ * - Null export values are supported only for generated config. A null export signals to Cloudpack
11
+ * that the entry should be completely dropped from the flattened exports map.
11
12
  * - Following the behavior of Node, for perf reasons, we do NOT verify whether any entries
12
13
  * exist on disk except wildcard or trailing slash exports since it is required.
13
14
  * (This differs from the behavior of typescript and webpack.)
@@ -1 +1 @@
1
- {"version":3,"file":"flattenExportsMap.d.ts","sourceRoot":"","sources":["../src/flattenExportsMap.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAA4B,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAM/F;;;;;;;;;;;;GAYG;AACH,wBAAgB,iBAAiB,CAC/B,UAAU,EAAE,kBAAkB,EAC9B,OAAO,GAAE;IACP,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,kBAAkB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC9B,WAAW,CAAC,EAAE,MAAM,CAAC;CACjB,GACL,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CA4BxB"}
1
+ {"version":3,"file":"flattenExportsMap.d.ts","sourceRoot":"","sources":["../src/flattenExportsMap.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAA4B,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAM/F;;;;;;;;;;;;;GAaG;AACH,wBAAgB,iBAAiB,CAC/B,UAAU,EAAE,kBAAkB,EAC9B,OAAO,GAAE;IACP,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,kBAAkB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC9B,WAAW,CAAC,EAAE,MAAM,CAAC;CACjB,GACL,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CA4BxB"}
@@ -10,7 +10,8 @@ const defaultConditions = ['browser', 'module', 'import', 'default'];
10
10
  * Notes:
11
11
  * - This diverges from the behavior of Node in that conditions are considered in order of
12
12
  * the `conditions` array, NOT in the order keys are defined in the exports map.
13
- * - Null export values are currently not supported.
13
+ * - Null export values are supported only for generated config. A null export signals to Cloudpack
14
+ * that the entry should be completely dropped from the flattened exports map.
14
15
  * - Following the behavior of Node, for perf reasons, we do NOT verify whether any entries
15
16
  * exist on disk except wildcard or trailing slash exports since it is required.
16
17
  * (This differs from the behavior of typescript and webpack.)
@@ -103,6 +104,9 @@ function extractExports({ exports, conditions, requiredConditions, flatExports =
103
104
  packagePath,
104
105
  });
105
106
  }
107
+ else {
108
+ delete flatExports[key];
109
+ }
106
110
  }
107
111
  }
108
112
  }
@@ -1 +1 @@
1
- {"version":3,"file":"flattenExportsMap.js","sourceRoot":"","sources":["../src/flattenExportsMap.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,MAAM,iBAAiB,GAAG,CAAC,SAAS,EAAE,QAAQ,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC;AAErE;;;;;;;;;;;;GAYG;AACH,MAAM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KAAK,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC;IACnC,CAAC;SAAM,IAAI,aAAa,KAAK,CAAC,CAAC,EAAE,CAAC;QAChC,OAAO;YACL,KAAK,EAAE,KAAK,CAAC,SAAS,CAAC,CAAC,EAAE,aAAa,CAAC;YACxC,GAAG,EAAE,KAAK,CAAC,SAAS,CAAC,aAAa,GAAG,CAAC,CAAC;SACxC,CAAC;IACJ,CAAC;AACH,CAAC","sourcesContent":["import path from 'path';\nimport type { PackageJsonExportsObject, PackageJsonExports } from '@ms-cloudpack/common-types';\nimport { cleanEntry } from './cleanEntry.js';\nimport glob from 'fast-glob';\n\nconst defaultConditions = ['browser', 'module', 'import', 'default'];\n\n/**\n * Given a package definition and applicable conditions, return a flat map of package import to physical (relative) path.\n * Optionally return the exports map fully qualified with conditions intact using the `fullExports` option.\n * Optionally takes in a `packagePath` to resolve entries and values that end in `/` and with wildcards `*`.\n *\n * Notes:\n * - This diverges from the behavior of Node in that conditions are considered in order of\n * the `conditions` array, NOT in the order keys are defined in the exports map.\n * - Null export values are currently not supported.\n * - Following the behavior of Node, for perf reasons, we do NOT verify whether any entries\n * exist on disk except wildcard or trailing slash exports since it is required.\n * (This differs from the behavior of typescript and webpack.)\n */\nexport function flattenExportsMap(\n exportsMap: PackageJsonExports,\n options: {\n conditions?: string[];\n requiredConditions?: string[];\n packagePath?: string;\n } = {},\n): Record<string, string> {\n const { requiredConditions, packagePath } = options;\n let { conditions } = options;\n\n if (conditions) {\n const defaultIndex = conditions.indexOf('...');\n if (defaultIndex !== -1) {\n conditions = [...conditions.slice(0, defaultIndex), ...defaultConditions, ...conditions.slice(defaultIndex + 1)];\n }\n } else {\n conditions = defaultConditions;\n }\n\n if (typeof exportsMap === 'string' && conditions.includes('default')) {\n return {\n '.': cleanEntry(exportsMap),\n };\n }\n\n return extractExports({\n exports: exportsMap,\n conditions,\n requiredConditions,\n flatExports: {},\n importMatch: '.',\n matchedConditions: [],\n packagePath,\n });\n}\n\n/**\n * Extract the exports from an exports object or sub-object and add them to the flat exports map.\n *\n * @returns The cumulative flat exports map.\n */\nfunction extractExports({\n exports,\n conditions,\n requiredConditions,\n flatExports = {},\n importMatch = '.',\n matchedConditions = [],\n packagePath = undefined,\n}: {\n /** The exports object to extract or a sub-object. */\n exports: PackageJsonExports;\n /** The conditions to check for in the exports object. */\n conditions: string[];\n /** The conditions that must be matched to add the export. */\n requiredConditions?: string[];\n /** The cumulative flat exports map to add the exports to. */\n flatExports?: Record<string, string>;\n /** The import path to match (default `.`). */\n importMatch?: string;\n /** The conditions that have been matched so far. */\n matchedConditions?: string[];\n /** The path to the package. */\n packagePath?: string | undefined;\n}) {\n if (\n typeof exports === 'string' &&\n (!requiredConditions || requiredConditions.every((condition) => matchedConditions.includes(condition)))\n ) {\n addExportsEntry({ flatExports, key: importMatch, value: exports, packagePath });\n } else if (Array.isArray(exports)) {\n for (const exportEntry of exports) {\n extractExports({\n exports: exportEntry,\n conditions,\n requiredConditions,\n flatExports,\n importMatch,\n matchedConditions,\n packagePath,\n });\n }\n } else if (exports && typeof exports === 'object') {\n // Iterate through condition matches and go deeper if a match is found.\n for (const condition of conditions) {\n const exportsObject = (exports as PackageJsonExportsObject)[condition];\n\n if (exportsObject) {\n extractExports({\n exports: exportsObject as PackageJsonExports,\n conditions,\n requiredConditions,\n flatExports,\n importMatch,\n matchedConditions: matchedConditions.concat(condition),\n packagePath,\n });\n // Stop at the first match.\n return flatExports;\n }\n }\n\n // No conditions are available. Check for import entries.\n for (const [key, value] of Object.entries(exports)) {\n if (key.startsWith('.')) {\n importMatch = key;\n\n if (typeof value === 'string') {\n if (!flatExports[importMatch] && (!requiredConditions || requiredConditions?.includes(key))) {\n addExportsEntry({ flatExports, key: importMatch, value, packagePath });\n }\n } else if (value) {\n extractExports({\n exports: value,\n conditions,\n requiredConditions,\n flatExports,\n importMatch,\n matchedConditions: [...matchedConditions, key],\n packagePath,\n });\n }\n }\n }\n }\n\n return flatExports;\n}\n\n/**\n * Add an entry to the flattened exports map if the key and value are valid\n * and the key is not already in the map.\n *\n * Does nothing if the key contains a wildcard or a trailing slash and the value does not, such as it being `null`.\n */\nfunction addExportsEntry({\n flatExports,\n key,\n value,\n packagePath,\n}: {\n /** The path to the package. */\n flatExports: Record<string, string>;\n /** The flattened exports map. */\n key: string;\n /** The key to add to the map. */\n value: string;\n /** The relative physical path to add to the map. */\n packagePath: string | undefined;\n}) {\n const basename = path.basename(value);\n const isValid = basename !== '' && basename !== '.';\n const isMany = value.endsWith('/') || value.indexOf('*') !== -1 || key.indexOf('*') !== -1 || key.endsWith('/');\n\n // Skip if the key is already in the map.\n if (flatExports[key]) return;\n\n if (isValid && !isMany) {\n flatExports[key] = cleanEntry(value);\n return;\n }\n\n if (value === null) {\n // Debug log for null values in the exports map.\n console.debug(`Skipping null value for key \"${key}\" in exports map${packagePath ? ` of \"${packagePath}\"` : ''}.`);\n return;\n }\n\n // Debug log for export patterns found in the exports map.\n console.debug(`Found export patterns in ${packagePath ? `\"${packagePath}\" ` : ''}exports map: \"${key}\": \"${value}\"`);\n\n // A package path is required to resolve entries and values that end in `/` or that include a wildcard `*`.\n if (!packagePath) return;\n\n // Check for wildcards in the key and value.\n // The wildcards\n const keyWildcard = key.indexOf('*', 1);\n const valueWildcard = value.indexOf('*', 1);\n\n if ((key.endsWith('/') && value.endsWith('/')) || (keyWildcard !== -1 && valueWildcard !== -1)) {\n const searchGlob = valueToGlob(value, valueWildcard);\n const keySplit = splitByGlob(key, keyWildcard);\n const valueSplit = splitByGlob(value, valueWildcard);\n if (!searchGlob || !keySplit || !valueSplit) return;\n // We only want to search for files.\n const matches = glob.sync(searchGlob, { cwd: packagePath, onlyFiles: true });\n for (const match of matches) {\n // Skip files that don't have an extension or have a `.` extension.\n if (path.extname(match).length <= 1) continue;\n // Get the glob match shared between the key and value.\n const globMatch = match.substring(\n // Globs that start with `./` don't return matches with `./` in the beginning.\n match.startsWith(valueSplit.start) ? valueSplit.start.length : 0,\n match.length - valueSplit.end.length,\n );\n // Replace the glob match in the key with the resolved glob match in the value.\n const matchKey = keySplit.start + globMatch + keySplit.end;\n if (!flatExports[matchKey]) {\n flatExports[matchKey] = cleanEntry(match);\n }\n }\n }\n}\n\n/**\n * Convert a value to a glob pattern.\n *\n * @param value The value to convert.\n * @param valueWildcard The index of the wildcard in the value.\n * @returns A value converted to a glob pattern.\n */\nfunction valueToGlob(value: string, valueWildcard: number = value.indexOf('*', 1)) {\n if (value.endsWith('/')) {\n return value + '**/*';\n } else if (valueWildcard !== -1) {\n return value.substring(0, valueWildcard) + '**/*' + value.substring(valueWildcard + 1);\n }\n}\n\n/**\n * Split a value by the location of the trailing slash or wildcard.\n *\n * @param value The value to split.\n * @param valueWildcard The index of the wildcard in the value.\n * @returns An object with the start and end substring of the split value.\n */\nfunction splitByGlob(value: string, valueWildcard: number = value.indexOf('*', 1)) {\n if (value.endsWith('/')) {\n return { start: value, end: '' };\n } else if (valueWildcard !== -1) {\n return {\n start: value.substring(0, valueWildcard),\n end: value.substring(valueWildcard + 1),\n };\n }\n}\n"]}
1
+ {"version":3,"file":"flattenExportsMap.js","sourceRoot":"","sources":["../src/flattenExportsMap.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,MAAM,iBAAiB,GAAG,CAAC,SAAS,EAAE,QAAQ,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC;AAErE;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,iBAAiB,CAC/B,UAA8B,EAC9B,UAII,EAAE;IAEN,MAAM,EAAE,kBAAkB,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC;IACpD,IAAI,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC;IAE7B,IAAI,UAAU,EAAE,CAAC;QACf,MAAM,YAAY,GAAG,UAAU,CAAC,OAAO,CAAC,KAAK,CA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AC;YACxC,GAAG,EAAE,KAAK,CAAC,SAAS,CAAC,aAAa,GAAG,CAAC,CAAC;SACxC,CAAC;IACJ,CAAC;AACH,CAAC","sourcesContent":["import path from 'path';\nimport type { PackageJsonExportsObject, PackageJsonExports } from '@ms-cloudpack/common-types';\nimport { cleanEntry } from './cleanEntry.js';\nimport glob from 'fast-glob';\n\nconst defaultConditions = ['browser', 'module', 'import', 'default'];\n\n/**\n * Given a package definition and applicable conditions, return a flat map of package import to physical (relative) path.\n * Optionally return the exports map fully qualified with conditions intact using the `fullExports` option.\n * Optionally takes in a `packagePath` to resolve entries and values that end in `/` and with wildcards `*`.\n *\n * Notes:\n * - This diverges from the behavior of Node in that conditions are considered in order of\n * the `conditions` array, NOT in the order keys are defined in the exports map.\n * - Null export values are supported only for generated config. A null export signals to Cloudpack\n * that the entry should be completely dropped from the flattened exports map.\n * - Following the behavior of Node, for perf reasons, we do NOT verify whether any entries\n * exist on disk except wildcard or trailing slash exports since it is required.\n * (This differs from the behavior of typescript and webpack.)\n */\nexport function flattenExportsMap(\n exportsMap: PackageJsonExports,\n options: {\n conditions?: string[];\n requiredConditions?: string[];\n packagePath?: string;\n } = {},\n): Record<string, string> {\n const { requiredConditions, packagePath } = options;\n let { conditions } = options;\n\n if (conditions) {\n const defaultIndex = conditions.indexOf('...');\n if (defaultIndex !== -1) {\n conditions = [...conditions.slice(0, defaultIndex), ...defaultConditions, ...conditions.slice(defaultIndex + 1)];\n }\n } else {\n conditions = defaultConditions;\n }\n\n if (typeof exportsMap === 'string' && conditions.includes('default')) {\n return {\n '.': cleanEntry(exportsMap),\n };\n }\n\n return extractExports({\n exports: exportsMap,\n conditions,\n requiredConditions,\n flatExports: {},\n importMatch: '.',\n matchedConditions: [],\n packagePath,\n });\n}\n\n/**\n * Extract the exports from an exports object or sub-object and add them to the flat exports map.\n *\n * @returns The cumulative flat exports map.\n */\nfunction extractExports({\n exports,\n conditions,\n requiredConditions,\n flatExports = {},\n importMatch = '.',\n matchedConditions = [],\n packagePath = undefined,\n}: {\n /** The exports object to extract or a sub-object. */\n exports: PackageJsonExports;\n /** The conditions to check for in the exports object. */\n conditions: string[];\n /** The conditions that must be matched to add the export. */\n requiredConditions?: string[];\n /** The cumulative flat exports map to add the exports to. */\n flatExports?: Record<string, string>;\n /** The import path to match (default `.`). */\n importMatch?: string;\n /** The conditions that have been matched so far. */\n matchedConditions?: string[];\n /** The path to the package. */\n packagePath?: string | undefined;\n}) {\n if (\n typeof exports === 'string' &&\n (!requiredConditions || requiredConditions.every((condition) => matchedConditions.includes(condition)))\n ) {\n addExportsEntry({ flatExports, key: importMatch, value: exports, packagePath });\n } else if (Array.isArray(exports)) {\n for (const exportEntry of exports) {\n extractExports({\n exports: exportEntry,\n conditions,\n requiredConditions,\n flatExports,\n importMatch,\n matchedConditions,\n packagePath,\n });\n }\n } else if (exports && typeof exports === 'object') {\n // Iterate through condition matches and go deeper if a match is found.\n for (const condition of conditions) {\n const exportsObject = (exports as PackageJsonExportsObject)[condition];\n\n if (exportsObject) {\n extractExports({\n exports: exportsObject as PackageJsonExports,\n conditions,\n requiredConditions,\n flatExports,\n importMatch,\n matchedConditions: matchedConditions.concat(condition),\n packagePath,\n });\n // Stop at the first match.\n return flatExports;\n }\n }\n\n // No conditions are available. Check for import entries.\n for (const [key, value] of Object.entries(exports)) {\n if (key.startsWith('.')) {\n importMatch = key;\n\n if (typeof value === 'string') {\n if (!flatExports[importMatch] && (!requiredConditions || requiredConditions?.includes(key))) {\n addExportsEntry({ flatExports, key: importMatch, value, packagePath });\n }\n } else if (value) {\n extractExports({\n exports: value,\n conditions,\n requiredConditions,\n flatExports,\n importMatch,\n matchedConditions: [...matchedConditions, key],\n packagePath,\n });\n } else {\n delete flatExports[key];\n }\n }\n }\n }\n\n return flatExports;\n}\n\n/**\n * Add an entry to the flattened exports map if the key and value are valid\n * and the key is not already in the map.\n *\n * Does nothing if the key contains a wildcard or a trailing slash and the value does not, such as it being `null`.\n */\nfunction addExportsEntry({\n flatExports,\n key,\n value,\n packagePath,\n}: {\n /** The path to the package. */\n flatExports: Record<string, string>;\n /** The flattened exports map. */\n key: string;\n /** The key to add to the map. */\n value: string;\n /** The relative physical path to add to the map. */\n packagePath: string | undefined;\n}) {\n const basename = path.basename(value);\n const isValid = basename !== '' && basename !== '.';\n const isMany = value.endsWith('/') || value.indexOf('*') !== -1 || key.indexOf('*') !== -1 || key.endsWith('/');\n\n // Skip if the key is already in the map.\n if (flatExports[key]) return;\n\n if (isValid && !isMany) {\n flatExports[key] = cleanEntry(value);\n return;\n }\n\n if (value === null) {\n // Debug log for null values in the exports map.\n console.debug(`Skipping null value for key \"${key}\" in exports map${packagePath ? ` of \"${packagePath}\"` : ''}.`);\n return;\n }\n\n // Debug log for export patterns found in the exports map.\n console.debug(`Found export patterns in ${packagePath ? `\"${packagePath}\" ` : ''}exports map: \"${key}\": \"${value}\"`);\n\n // A package path is required to resolve entries and values that end in `/` or that include a wildcard `*`.\n if (!packagePath) return;\n\n // Check for wildcards in the key and value.\n // The wildcards\n const keyWildcard = key.indexOf('*', 1);\n const valueWildcard = value.indexOf('*', 1);\n\n if ((key.endsWith('/') && value.endsWith('/')) || (keyWildcard !== -1 && valueWildcard !== -1)) {\n const searchGlob = valueToGlob(value, valueWildcard);\n const keySplit = splitByGlob(key, keyWildcard);\n const valueSplit = splitByGlob(value, valueWildcard);\n if (!searchGlob || !keySplit || !valueSplit) return;\n // We only want to search for files.\n const matches = glob.sync(searchGlob, { cwd: packagePath, onlyFiles: true });\n for (const match of matches) {\n // Skip files that don't have an extension or have a `.` extension.\n if (path.extname(match).length <= 1) continue;\n // Get the glob match shared between the key and value.\n const globMatch = match.substring(\n // Globs that start with `./` don't return matches with `./` in the beginning.\n match.startsWith(valueSplit.start) ? valueSplit.start.length : 0,\n match.length - valueSplit.end.length,\n );\n // Replace the glob match in the key with the resolved glob match in the value.\n const matchKey = keySplit.start + globMatch + keySplit.end;\n if (!flatExports[matchKey]) {\n flatExports[matchKey] = cleanEntry(match);\n }\n }\n }\n}\n\n/**\n * Convert a value to a glob pattern.\n *\n * @param value The value to convert.\n * @param valueWildcard The index of the wildcard in the value.\n * @returns A value converted to a glob pattern.\n */\nfunction valueToGlob(value: string, valueWildcard: number = value.indexOf('*', 1)) {\n if (value.endsWith('/')) {\n return value + '**/*';\n } else if (valueWildcard !== -1) {\n return value.substring(0, valueWildcard) + '**/*' + value.substring(valueWildcard + 1);\n }\n}\n\n/**\n * Split a value by the location of the trailing slash or wildcard.\n *\n * @param value The value to split.\n * @param valueWildcard The index of the wildcard in the value.\n * @returns An object with the start and end substring of the split value.\n */\nfunction splitByGlob(value: string, valueWildcard: number = value.indexOf('*', 1)) {\n if (value.endsWith('/')) {\n return { start: value, end: '' };\n } else if (valueWildcard !== -1) {\n return {\n start: value.substring(0, valueWildcard),\n end: value.substring(valueWildcard + 1),\n };\n }\n}\n"]}
@@ -18,5 +18,9 @@ export interface LinkedPath {
18
18
  * Package matches to ignore when linking.
19
19
  */
20
20
  ignoredPackages?: string[];
21
+ /**
22
+ * If true, ignores resolutions from the host repo definition to the linked packages.
23
+ */
24
+ ignoreResolutions?: boolean;
21
25
  }
22
26
  //# sourceMappingURL=LinkedPath.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"LinkedPath.d.ts","sourceRoot":"","sources":["../../src/types/LinkedPath.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB;;OAEG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IAErB;;OAEG;IACH,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;CAC5B"}
1
+ {"version":3,"file":"LinkedPath.d.ts","sourceRoot":"","sources":["../../src/types/LinkedPath.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB;;OAEG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IAErB;;OAEG;IACH,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAE3B;;OAEG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B"}
@@ -1 +1 @@
1
- {"version":3,"file":"LinkedPath.js","sourceRoot":"","sources":["../../src/types/LinkedPath.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * Represents a path linked to the resolve map.\n */\nexport interface LinkedPath {\n /**\n * Path to where the link originates.\n */\n path: string;\n\n /**\n * Optional git root to limit package resolution discovery.\n */\n rootPath?: string;\n\n /**\n * If true, transitive internal packages will be linked rather than only the matched packages.\n */\n includeAll?: boolean;\n\n /**\n * Package matches to ignore when linking.\n */\n ignoredPackages?: string[];\n}\n"]}
1
+ {"version":3,"file":"LinkedPath.js","sourceRoot":"","sources":["../../src/types/LinkedPath.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * Represents a path linked to the resolve map.\n */\nexport interface LinkedPath {\n /**\n * Path to where the link originates.\n */\n path: string;\n\n /**\n * Optional git root to limit package resolution discovery.\n */\n rootPath?: string;\n\n /**\n * If true, transitive internal packages will be linked rather than only the matched packages.\n */\n includeAll?: boolean;\n\n /**\n * Package matches to ignore when linking.\n */\n ignoredPackages?: string[];\n\n /**\n * If true, ignores resolutions from the host repo definition to the linked packages.\n */\n ignoreResolutions?: boolean;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ms-cloudpack/package-utilities",
3
- "version": "7.4.11",
3
+ "version": "7.5.1",
4
4
  "description": "Utilities for resolving/parsing packages and their imports.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -14,11 +14,11 @@
14
14
  }
15
15
  },
16
16
  "dependencies": {
17
- "@ms-cloudpack/common-types": "^0.6.2",
17
+ "@ms-cloudpack/common-types": "^0.7.0",
18
18
  "@ms-cloudpack/json-utilities": "^0.1.4",
19
- "@ms-cloudpack/package-overrides": "^0.8.9",
20
- "@ms-cloudpack/path-string-parsing": "^1.2.2",
21
- "@ms-cloudpack/path-utilities": "^2.7.14",
19
+ "@ms-cloudpack/package-overrides": "^0.9.0",
20
+ "@ms-cloudpack/path-string-parsing": "^1.2.3",
21
+ "@ms-cloudpack/path-utilities": "^2.7.15",
22
22
  "@ms-cloudpack/task-reporter": "^0.14.1",
23
23
  "acorn": "^8.11.2",
24
24
  "acorn-walk": "^8.2.1",