@ms-cloudpack/package-utilities 7.5.4 → 7.6.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.
@@ -24,7 +24,7 @@ export async function createResolveMap(options, context) {
24
24
  }, context);
25
25
  // Next, we iterate through linked paths to inject them into the packageMap.
26
26
  for (const linkedPath of linkedPaths) {
27
- await linkPath({ linkedPath, appMap, repoDefinition }, context);
27
+ await linkPath({ rootPath, linkedPath, appMap, repoDefinition }, context);
28
28
  }
29
29
  // Finally we condense into a resolve map.
30
30
  return convertToResolveMap({ appMap, rootPaths: [appPath, ...additionalPaths] });
@@ -1 +1 @@
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
+ {"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,QAAQ,EAAE,UAAU,EAAE,MAAM,EAAE,cAAc,EAAE,EAAE,OAAO,CAAC,CAAC;IAC5E,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({ rootPath, linkedPath, appMap, repoDefinition }, context);\n }\n\n // Finally we condense into a resolve map.\n return convertToResolveMap({ appMap, rootPaths: [appPath, ...additionalPaths] });\n}\n"]}
@@ -1,10 +1,14 @@
1
1
  import type { PackageMap } from '../types/PackageMap.js';
2
+ import type { PackageDefinitionsCache } from '@ms-cloudpack/common-types';
2
3
  /**
3
4
  * Deduplicates linked packages by removing all but the highest version,
4
5
  * that satisfies the semver requirements of all the requiredBy entries.
5
6
  */
6
- export declare function dedupeLinkedPackages({ appMap, allDuplicates }: {
7
+ export declare function dedupeLinkedPackages(options: {
7
8
  appMap: PackageMap;
8
9
  allDuplicates: Set<string>;
9
- }): void;
10
+ rootPath?: string;
11
+ }, context: {
12
+ packages: PackageDefinitionsCache;
13
+ }): Promise<void>;
10
14
  //# sourceMappingURL=dedupeLinkedPackages.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"dedupeLinkedPackages.d.ts","sourceRoot":"","sources":["../../src/createResolveMap/dedupeLinkedPackages.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAKzD;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,EAAE,MAAM,EAAE,aAAa,EAAE,EAAE;IAAE,MAAM,EAAE,UAAU,CAAC;IAAC,aAAa,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;CAAE,QA0DjH"}
1
+ {"version":3,"file":"dedupeLinkedPackages.d.ts","sourceRoot":"","sources":["../../src/createResolveMap/dedupeLinkedPackages.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAIzD,OAAO,KAAK,EAAE,uBAAuB,EAAmB,MAAM,4BAA4B,CAAC;AAK3F;;;GAGG;AACH,wBAAsB,oBAAoB,CACxC,OAAO,EAAE;IAAE,MAAM,EAAE,UAAU,CAAC;IAAC,aAAa,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAE,EAC9E,OAAO,EAAE;IAAE,QAAQ,EAAE,uBAAuB,CAAA;CAAE,iBAgG/C"}
@@ -1,11 +1,14 @@
1
1
  import { satisfies, compare as semverCompare } from 'semver';
2
2
  import { parseRequiredBy } from './parseRequiredBy.js';
3
3
  import { detachEntry } from './detachEntry.js';
4
+ import { slash } from '@ms-cloudpack/path-string-parsing';
4
5
  /**
5
6
  * Deduplicates linked packages by removing all but the highest version,
6
7
  * that satisfies the semver requirements of all the requiredBy entries.
7
8
  */
8
- export function dedupeLinkedPackages({ appMap, allDuplicates }) {
9
+ export async function dedupeLinkedPackages(options, context) {
10
+ const { rootPath, appMap, allDuplicates } = options;
11
+ const { packages } = context;
9
12
  console.debug(`The following packages were duplicated by linking:\n ${Array.from(allDuplicates).join(', ')}`);
10
13
  for (const duplicate of allDuplicates) {
11
14
  const packageName = parseRequiredBy(duplicate).name;
@@ -14,6 +17,13 @@ export function dedupeLinkedPackages({ appMap, allDuplicates }) {
14
17
  if (Object.keys(entries).length <= 1) {
15
18
  continue;
16
19
  }
20
+ let dedupeStrategy = 'allow-duplication';
21
+ for (const entry of Object.values(entries)) {
22
+ const packageJson = await packages.get(entry.path);
23
+ if (packageJson?.cloudpack?.link?.duplicatedDependencyBehavior) {
24
+ dedupeStrategy = packageJson.cloudpack.link.duplicatedDependencyBehavior;
25
+ }
26
+ }
17
27
  const availableVersions = Object.keys(entries);
18
28
  const versionRequirements = new Set();
19
29
  // Find if any of the duplicate entries satisfy the semver requirement of all the requiredBy entries.
@@ -30,16 +40,38 @@ export function dedupeLinkedPackages({ appMap, allDuplicates }) {
30
40
  const satisfiedVersions = availableVersions
31
41
  .filter((v) => [...versionRequirements].every((range) => satisfies(v, range)))
32
42
  .sort(semverCompare);
33
- if (satisfiedVersions.length === 0) {
43
+ let satisfiedVersion;
44
+ if (dedupeStrategy === 'force-host-version') {
45
+ if (!rootPath) {
46
+ console.error('Root path for project not found and is required when using the "force-host-version" dedupe strategy.');
47
+ continue;
48
+ }
49
+ // Use the app host's version of the package.
50
+ // Find the version of the package that belongs to the host.
51
+ // We assume that the host has a single version of the package.
52
+ const hostVersion = availableVersions.find((v) => slash(entries[v].path).startsWith(slash(rootPath)));
53
+ if (!hostVersion) {
54
+ console.error(`Could not find a version of "${packageName}" that is belongs to the host.`);
55
+ continue;
56
+ }
57
+ satisfiedVersion = hostVersion;
58
+ }
59
+ else if (dedupeStrategy === 'allow-duplication' && satisfiedVersions.length > 0) {
60
+ // Select the highest version that satisfies the semver requirements of all the requiredBy entries.
61
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
62
+ satisfiedVersion = satisfiedVersions.pop();
63
+ console.debug(`Version "${satisfiedVersion}" of "${packageName}" satisfies the semver requirements of all the requiredBy entries.`);
64
+ }
65
+ else {
66
+ // If the deduplication strategy allows duplicates and
67
+ // no version satisfies the semver requirements for all dependents,
68
+ // then deduplication of this package is not possible.
34
69
  console.debug(`Could not find a version of "${packageName}" that satisfies the semver requirements of all the requiredBy entries.`);
35
70
  continue;
36
71
  }
37
- // Select the highest version that satisfies the semver requirements of all the requiredBy entries.
38
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
39
- const highestSatisfiedVersion = satisfiedVersions.pop();
40
- entries[highestSatisfiedVersion].requiredBy = requiredBy;
72
+ entries[satisfiedVersion].requiredBy = requiredBy;
41
73
  for (const version of availableVersions) {
42
- if (version == highestSatisfiedVersion) {
74
+ if (version == satisfiedVersion) {
43
75
  continue;
44
76
  }
45
77
  detachEntry({ appMap, entry: entries[version] });
@@ -47,9 +79,9 @@ export function dedupeLinkedPackages({ appMap, allDuplicates }) {
47
79
  }
48
80
  for (const requiredById of Object.keys(requiredBy)) {
49
81
  const { name: requiredByName, version: requiredByVersion } = parseRequiredBy(requiredById);
50
- appMap[requiredByName][requiredByVersion].dependencies[packageName] = highestSatisfiedVersion;
82
+ appMap[requiredByName][requiredByVersion].dependencies[packageName] = satisfiedVersion;
51
83
  }
52
- console.debug(`Removed versions of "${packageName}" except for "${highestSatisfiedVersion}".`);
84
+ console.debug(`Removed versions of "${packageName}" except for "${satisfiedVersion}".`);
53
85
  }
54
86
  }
55
87
  //# sourceMappingURL=dedupeLinkedPackages.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"dedupeLinkedPackages.js","sourceRoot":"","sources":["../../src/createResolveMap/dedupeLinkedPackages.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,QAAQ,CAAC;AAG7D,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C;;;GAGG;AACH,MAAM,UAAU,oBAAoB,CAAC,EAAE,MAAM,EAAE,aAAa,EAAsD;IAChH,OAAO,CAAC,KAAK,CAAC,wDAAwD,KAAK,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAC9G,KAAK,MAAM,SAAS,IAAI,aAAa,EAAE,CAAC;QACtC,MAAM,WAAW,GAAG,eAAe,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC;QAEpD,MAAM,OAAO,GAAG,MAAM,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC;QAE1C,iDAAiD;QACjD,IAAI,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,MAAM,IAAI,CAAC,EAAE,CAAC;YACrC,SAAS;QACX,CAAC;QAED,MAAM,iBAAiB,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;Q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CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;YACjD,OAAO,MAAM,CAAC,WAAW,CAAC,CAAC,OAAO,CAAC,CAAC;QACtC,CAAC;QAED,KAAK,MAAM,YAAY,IAAI,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC;YACnD,MAAM,EAAE,IAAI,EAAE,cAAc,EAAE,OAAO,EAAE,iBAAiB,EAAE,GAAG,eAAe,CAAC,YAAY,CAAC,CAAC;YAC3F,MAAM,CAAC,cAAc,CAAC,CAAC,iBAAiB,CAAC,CAAC,YAAY,CAAC,WAAW,CAAC,GAAG,uBAAuB,CAAC;QAChG,CAAC;QAED,OAAO,CAAC,KAAK,CAAC,wBAAwB,WAAW,iBAAiB,uBAAuB,IAAI,CAAC,CAAC;IACjG,CAAC;AACH,CAAC","sourcesContent":["import { satisfies, compare as semverCompare } from 'semver';\nimport type { PackageMap } from '../types/PackageMap.js';\nimport type { ResolveMapEntry } from '../types/ResolveMapEntry.js';\nimport { parseRequiredBy } from './parseRequiredBy.js';\nimport { detachEntry } from './detachEntry.js';\n\n/**\n * Deduplicates linked packages by removing all but the highest version,\n * that satisfies the semver requirements of all the requiredBy entries.\n */\nexport function dedupeLinkedPackages({ appMap, allDuplicates }: { appMap: PackageMap; allDuplicates: Set<string> }) {\n console.debug(`The following packages were duplicated by linking:\\n ${Array.from(allDuplicates).join(', ')}`);\n for (const duplicate of allDuplicates) {\n const packageName = parseRequiredBy(duplicate).name;\n\n const entries = appMap[packageName] || {};\n\n // Sanity check to ensure that it is a duplicate.\n if (Object.keys(entries).length <= 1) {\n continue;\n }\n\n const availableVersions = Object.keys(entries);\n\n const versionRequirements = new Set<string>();\n // Find if any of the duplicate entries satisfy the semver requirement of all the requiredBy entries.\n const requiredBy: ResolveMapEntry['requiredBy'] = {};\n for (const entry of Object.values(entries)) {\n for (const [requiredById, range] of Object.entries(entry.requiredBy) as [`${string}@${string}`, string][]) {\n requiredBy[requiredById] = range;\n // We only care about satisfying version requirements that are already satisfied.\n if (satisfies(entry.version, range)) {\n versionRequirements.add(range);\n }\n }\n }\n\n const satisfiedVersions = availableVersions\n .filter((v) => [...versionRequirements].every((range) => satisfies(v, range)))\n .sort(semverCompare);\n\n if (satisfiedVersions.length === 0) {\n console.debug(\n `Could not find a version of \"${packageName}\" that satisfies the semver requirements of all the requiredBy entries.`,\n );\n continue;\n }\n\n // Select the highest version that satisfies the semver requirements of all the requiredBy entries.\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const highestSatisfiedVersion = satisfiedVersions.pop()!;\n entries[highestSatisfiedVersion].requiredBy = requiredBy;\n\n for (const version of availableVersions) {\n if (version == highestSatisfiedVersion) {\n continue;\n }\n detachEntry({ appMap, entry: entries[version] });\n delete appMap[packageName][version];\n }\n\n for (const requiredById of Object.keys(requiredBy)) {\n const { name: requiredByName, version: requiredByVersion } = parseRequiredBy(requiredById);\n appMap[requiredByName][requiredByVersion].dependencies[packageName] = highestSatisfiedVersion;\n }\n\n console.debug(`Removed versions of \"${packageName}\" except for \"${highestSatisfiedVersion}\".`);\n }\n}\n"]}
1
+ {"version":3,"file":"dedupeLinkedPackages.js","sourceRoot":"","sources":["../../src/createResolveMap/dedupeLinkedPackages.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,QAAQ,CAAC;AAG7D,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,OAAO,EAAE,KAAK,EAAE,MAAM,mCAAmC,CAAC;AAI1D;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,OAA8E,EAC9E,OAA8C;IAE9C,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,aAAa,EAAE,GAAG,OAAO,CAAC;IACpD,MAAM,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC;IAC7B,OAAO,CAAC,KAAK,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CAAC;YACN,sDAAsD;YACtD,mEAAmE;YACnE,sDAAsD;YACtD,OAAO,CAAC,KAAK,CACX,gCAAgC,WAAW,yEAAyE,CACrH,CAAC;YACF,SAAS;QACX,CAAC;QAED,OAAO,CAAC,gBAAgB,CAAC,CAAC,UAAU,GAAG,UAAU,CAAC;QAElD,KAAK,MAAM,OAAO,IAAI,iBAAiB,EAAE,CAAC;YACxC,IAAI,OAAO,IAAI,gBAAgB,EAAE,CAAC;gBAChC,SAAS;YACX,CAAC;YACD,WAAW,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;YACjD,OAAO,MAAM,CAAC,WAAW,CAAC,CAAC,OAAO,CAAC,CAAC;QACtC,CAAC;QAED,KAAK,MAAM,YAAY,IAAI,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC;YACnD,MAAM,EAAE,IAAI,EAAE,cAAc,EAAE,OAAO,EAAE,iBAAiB,EAAE,GAAG,eAAe,CAAC,YAAY,CAAC,CAAC;YAC3F,MAAM,CAAC,cAAc,CAAC,CAAC,iBAAiB,CAAC,CAAC,YAAY,CAAC,WAAW,CAAC,GAAG,gBAAgB,CAAC;QACzF,CAAC;QAED,OAAO,CAAC,KAAK,CAAC,wBAAwB,WAAW,iBAAiB,gBAAgB,IAAI,CAAC,CAAC;IAC1F,CAAC;AACH,CAAC","sourcesContent":["import { satisfies, compare as semverCompare } from 'semver';\nimport type { PackageMap } from '../types/PackageMap.js';\nimport type { ResolveMapEntry } from '../types/ResolveMapEntry.js';\nimport { parseRequiredBy } from './parseRequiredBy.js';\nimport { detachEntry } from './detachEntry.js';\nimport type { PackageDefinitionsCache, PackageSettings } from '@ms-cloudpack/common-types';\nimport { slash } from '@ms-cloudpack/path-string-parsing';\n\ntype DuplicatedDependencyBehavior = NonNullable<NonNullable<PackageSettings['link']>['duplicatedDependencyBehavior']>;\n\n/**\n * Deduplicates linked packages by removing all but the highest version,\n * that satisfies the semver requirements of all the requiredBy entries.\n */\nexport async function dedupeLinkedPackages(\n options: { appMap: PackageMap; allDuplicates: Set<string>; rootPath?: string },\n context: { packages: PackageDefinitionsCache },\n) {\n const { rootPath, appMap, allDuplicates } = options;\n const { packages } = context;\n console.debug(`The following packages were duplicated by linking:\\n ${Array.from(allDuplicates).join(', ')}`);\n for (const duplicate of allDuplicates) {\n const packageName = parseRequiredBy(duplicate).name;\n\n const entries = appMap[packageName] || {};\n\n // Sanity check to ensure that it is a duplicate.\n if (Object.keys(entries).length <= 1) {\n continue;\n }\n\n let dedupeStrategy: DuplicatedDependencyBehavior = 'allow-duplication';\n for (const entry of Object.values(entries)) {\n const packageJson = await packages.get(entry.path);\n if (packageJson?.cloudpack?.link?.duplicatedDependencyBehavior) {\n dedupeStrategy = packageJson.cloudpack.link.duplicatedDependencyBehavior;\n }\n }\n\n const availableVersions = Object.keys(entries);\n\n const versionRequirements = new Set<string>();\n // Find if any of the duplicate entries satisfy the semver requirement of all the requiredBy entries.\n const requiredBy: ResolveMapEntry['requiredBy'] = {};\n for (const entry of Object.values(entries)) {\n for (const [requiredById, range] of Object.entries(entry.requiredBy) as [`${string}@${string}`, string][]) {\n requiredBy[requiredById] = range;\n // We only care about satisfying version requirements that are already satisfied.\n if (satisfies(entry.version, range)) {\n versionRequirements.add(range);\n }\n }\n }\n\n const satisfiedVersions = availableVersions\n .filter((v) => [...versionRequirements].every((range) => satisfies(v, range)))\n .sort(semverCompare);\n\n let satisfiedVersion: string | undefined;\n\n if (dedupeStrategy === 'force-host-version') {\n if (!rootPath) {\n console.error(\n 'Root path for project not found and is required when using the \"force-host-version\" dedupe strategy.',\n );\n continue;\n }\n // Use the app host's version of the package.\n // Find the version of the package that belongs to the host.\n // We assume that the host has a single version of the package.\n const hostVersion = availableVersions.find((v) => slash(entries[v].path).startsWith(slash(rootPath)));\n\n if (!hostVersion) {\n console.error(`Could not find a version of \"${packageName}\" that is belongs to the host.`);\n continue;\n }\n\n satisfiedVersion = hostVersion;\n } else if (dedupeStrategy === 'allow-duplication' && satisfiedVersions.length > 0) {\n // Select the highest version that satisfies the semver requirements of all the requiredBy entries.\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n satisfiedVersion = satisfiedVersions.pop()!;\n console.debug(\n `Version \"${satisfiedVersion}\" of \"${packageName}\" satisfies the semver requirements of all the requiredBy entries.`,\n );\n } else {\n // If the deduplication strategy allows duplicates and\n // no version satisfies the semver requirements for all dependents,\n // then deduplication of this package is not possible.\n console.debug(\n `Could not find a version of \"${packageName}\" that satisfies the semver requirements of all the requiredBy entries.`,\n );\n continue;\n }\n\n entries[satisfiedVersion].requiredBy = requiredBy;\n\n for (const version of availableVersions) {\n if (version == satisfiedVersion) {\n continue;\n }\n detachEntry({ appMap, entry: entries[version] });\n delete appMap[packageName][version];\n }\n\n for (const requiredById of Object.keys(requiredBy)) {\n const { name: requiredByName, version: requiredByVersion } = parseRequiredBy(requiredById);\n appMap[requiredByName][requiredByVersion].dependencies[packageName] = satisfiedVersion;\n }\n\n console.debug(`Removed versions of \"${packageName}\" except for \"${satisfiedVersion}\".`);\n }\n}\n"]}
@@ -7,6 +7,7 @@ import type { PackageDefinitionsCache, PackageJson } from '@ms-cloudpack/common-
7
7
  export declare function linkPath(options: {
8
8
  linkedPath: LinkedPath;
9
9
  appMap: PackageMap;
10
+ rootPath?: string;
10
11
  repoDefinition?: PackageJson;
11
12
  }, context: {
12
13
  packages: PackageDefinitionsCache;
@@ -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,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAGvF;;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,iBAsGF"}
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;AAGvF;;GAEG;AACH,wBAAsB,QAAQ,CAC5B,OAAO,EAAE;IACP,UAAU,EAAE,UAAU,CAAC;IACvB,MAAM,EAAE,UAAU,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,cAAc,CAAC,EAAE,WAAW,CAAC;CAC9B,EACD,OAAO,EAAE;IACP,QAAQ,EAAE,uBAAuB,CAAC;CACnC,iBAsGF"}
@@ -8,7 +8,7 @@ import { dedupeLinkedPackages } from './dedupeLinkedPackages.js';
8
8
  * Given a linked path, an appMap, find packages from the linked path and add them to the appMap.
9
9
  */
10
10
  export async function linkPath(options, context) {
11
- const { linkedPath, appMap, repoDefinition } = options;
11
+ const { linkedPath, appMap, rootPath, repoDefinition } = options;
12
12
  const linkMap = await findPackagesFromPath({
13
13
  searchPaths: [linkedPath.path],
14
14
  discoverPackages: true,
@@ -82,7 +82,7 @@ export async function linkPath(options, context) {
82
82
  allDuplicates.push(...duplicates);
83
83
  }
84
84
  if (linkedPath.resolveStrategy !== 'duplicate') {
85
- dedupeLinkedPackages({ appMap, allDuplicates: new Set(allDuplicates) });
85
+ await dedupeLinkedPackages({ appMap, allDuplicates: new Set(allDuplicates), rootPath }, context);
86
86
  }
87
87
  }
88
88
  function isContainedInPath(path, baseP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,GAAG,EAAE,CAAC;IAEzB,mFAAmF;IACnF,KAAK,MAAM,WAAW,IAAI,aAAa,EAAE,CAAC;QACxC,MAAM,EAAE,UAAU,EAAE,GAAG,MAAM,0BAA0B,CACrD,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,EACrD,OAAO,CACR,CAAC;QACF,aAAa,CAAC,IAAI,CAAC,GAAG,UAAU,CAAC,CAAC;IACpC,CAAC;IAED,IAAI,UAAU,CAAC,eAAe,KAAK,WAAW,EAAE,CAAC;QAC/C,oBAAoB,CAAC,EAAE,MAAM,EAAE,aAAa,EAAE,IAAI,GAAG,CAAC,aAAa,CAAC,EAAE,CAAC,CAAC;IAC1E,CAAC;AACH,CAAC;AAED,SAAS,iBAAiB,CAAC,IAAY,EAAE,QAAgB;IACvD,IAAI,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC;IAC3B,QAAQ,GAAG,aAAa,CAAC,QAAQ,CAAC,CAAC;IAEnC,OAAO,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;AACnC,CAAC;AAED,SAAS,aAAa,CAAC,IAAY;IACjC,IAAI,cAAc,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC;IAEjC,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,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';\nimport { dedupeLinkedPackages } from './dedupeLinkedPackages.js';\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 const allDuplicates = [];\n\n // Once all linked entries have been added, ensure their dependencies are resolved.\n for (const linkedEntry of entriesToLink) {\n const { duplicates } = await addLinkedEntryDependencies(\n { linkedEntry, appMap: appMap, linkMap, resolutions },\n context,\n );\n allDuplicates.push(...duplicates);\n }\n\n if (linkedPath.resolveStrategy !== 'duplicate') {\n dedupeLinkedPackages({ appMap, allDuplicates: new Set(allDuplicates) });\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,MAAM,iCAAiC,CAAC;AAC7E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AE,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,EACrD,OAAO,CACR,CAAC;QACF,aAAa,CAAC,IAAI,CAAC,GAAG,UAAU,CAAC,CAAC;IACpC,CAAC;IAED,IAAI,UAAU,CAAC,eAAe,KAAK,WAAW,EAAE,CAAC;QAC/C,MAAM,oBAAoB,CAAC,EAAE,MAAM,EAAE,aAAa,EAAE,IAAI,GAAG,CAAC,aAAa,CAAC,EAAE,QAAQ,EAAE,EAAE,OAAO,CAAC,CAAC;IACnG,CAAC;AACH,CAAC;AAED,SAAS,iBAAiB,CAAC,IAAY,EAAE,QAAgB;IACvD,IAAI,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC;IAC3B,QAAQ,GAAG,aAAa,CAAC,QAAQ,CAAC,CAAC;IAEnC,OAAO,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;AACnC,CAAC;AAED,SAAS,aAAa,CAAC,IAAY;IACjC,IAAI,cAAc,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC;IAEjC,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,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';\nimport { dedupeLinkedPackages } from './dedupeLinkedPackages.js';\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 rootPath?: string;\n repoDefinition?: PackageJson;\n },\n context: {\n packages: PackageDefinitionsCache;\n },\n) {\n const { linkedPath, appMap, rootPath, 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 const allDuplicates = [];\n\n // Once all linked entries have been added, ensure their dependencies are resolved.\n for (const linkedEntry of entriesToLink) {\n const { duplicates } = await addLinkedEntryDependencies(\n { linkedEntry, appMap: appMap, linkMap, resolutions },\n context,\n );\n allDuplicates.push(...duplicates);\n }\n\n if (linkedPath.resolveStrategy !== 'duplicate') {\n await dedupeLinkedPackages({ appMap, allDuplicates: new Set(allDuplicates), rootPath }, 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 +1 @@
1
- {"version":3,"file":"getNonSemverTransform.d.ts","sourceRoot":"","sources":["../src/getNonSemverTransform.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,0BAA0B,EAAe,MAAM,4BAA4B,CAAC;AAM1F;;;;;;GAMG;AACH,wBAAgB,qBAAqB,IAAI,0BAA0B,CAoFlE"}
1
+ {"version":3,"file":"getNonSemverTransform.d.ts","sourceRoot":"","sources":["../src/getNonSemverTransform.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,0BAA0B,EAAe,MAAM,4BAA4B,CAAC;AAM1F;;;;;;GAMG;AACH,wBAAgB,qBAAqB,IAAI,0BAA0B,CAgFlE"}
@@ -55,10 +55,6 @@ export function getNonSemverTransform() {
55
55
  // package under its real name.
56
56
  result.name = importedName;
57
57
  result.version = versionRequirement;
58
- result.cloudpackRemapped = {
59
- originalName: definition.name || '',
60
- originalVersion: definition.version || '',
61
- };
62
58
  // We have changed the definition, so link the entry in nonSemverDeps to the new name/version.
63
59
  if (nonSemverDeps[`${definition.name}@${definition.version}`]) {
64
60
  nonSemverDeps[`${importedName}@${versionRequirement}`] =
@@ -1 +1 @@
1
- {"version":3,"file":"getNonSemverTransform.js","sourceRoot":"","sources":["../src/getNonSemverTransform.ts"],"names":[],"mappings":"AACA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,4BAA4B,EAAE,MAAM,mCAAmC,CAAC;AAEjF,MAAM,QAAQ,GAAG,CAAC,cAAc,EAAE,kBAAkB,CAAU,CAAC;AAE/D;;;;;;GAMG;AACH,MAAM,UAAU,qBAAqB;IACnC;;;OAGG;IACH,MAAM,aAAa,GAGf,EAAE,CAAC;IAEP,OAAO,CAAC,EAAE,UAAU,EAAE,WAAW,EAAE,eAAe,EAAE,EAAE,EAAE;QACtD,MAAM,MAAM,GAAyB,EAAE,CAAC;QAExC,oCAAoC;QACpC,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;YAC/B,MAAM,IAAI,GAAG,UAAU,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;YAEvC,KAAK,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;gBACzD,IAAI,CAAC,UAAU,IAAI,MAAM,CAAC,UAAU,CAAC,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AI,GAAG,YAAY,CAAC;gBAC3B,MAAM,CAAC,OAAO,GAAG,kBAAkB,CAAC;gBACpC,MAAM,CAAC,iBAAiB,GAAG;oBACzB,YAAY,EAAE,UAAU,CAAC,IAAI,IAAI,EAAE;oBACnC,eAAe,EAAE,UAAU,CAAC,OAAO,IAAI,EAAE;iBAC1C,CAAC;gBAEF,8FAA8F;gBAC9F,IAAI,aAAa,CAAC,GAAG,UAAU,CAAC,IAAI,IAAI,UAAU,CAAC,OAAO,EAAE,CAAC,EAAE,CAAC;oBAC9D,aAAa,CAAC,GAAG,YAAY,IAAI,kBAAkB,EAAE,CAAC;wBACpD,aAAa,CAAC,GAAG,UAAU,CAAC,IAAI,IAAI,UAAU,CAAC,OAAO,EAAE,CAAC,CAAC;gBAC9D,CAAC;gBAED,MAAM;YACR,CAAC;QACH,CAAC;QAED,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,CAAC;YAC/B,OAAO,EAAE,GAAG,UAAU,EAAE,GAAG,MAAM,EAAE,CAAC;QACtC,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import type { PackageDefinitionTransform, PackageJson } from '@ms-cloudpack/common-types';\nimport semver from 'semver';\nimport { generateVersionFromNonSemver } from './generateVersionFromNonSemver.js';\n\nconst depTypes = ['dependencies', 'peerDependencies'] as const;\n\n/**\n * Get a transform which handles non-semver dependencies:\n * - In a parent package, if a dependency is specified with a non-semver version, change the dep\n * to a special `0.0.0-<original-version>` prerelease version.\n * - In a child package, if the package was pulled in as a non-semver dependency by a parent\n * (per the `importerContext`), change its version to the special prerelease version as above.\n */\nexport function getNonSemverTransform(): PackageDefinitionTransform {\n /**\n * Cached info about parent packages with non-semver dependencies:\n * Map from parent name/version => dep type => non-semver dependency names\n */\n const nonSemverDeps: Record<\n `${string}@${string}`,\n Partial<Record<'dependencies' | 'peerDependencies', string[]>>\n > = {};\n\n return ({ definition, packagePath, importerContext }) => {\n const result: Partial<PackageJson> = {};\n\n // Check for non-semver dependencies\n for (const depType of depTypes) {\n const deps = definition[depType] || {};\n\n for (const [depName, depVersion] of Object.entries(deps)) {\n if (!depVersion || semver.validRange(depVersion)) {\n continue;\n }\n\n console.debug(\n `Non-semver dependency found: ${depName}@${depVersion} ` +\n `(in ${definition.name}@${definition.version} at ${packagePath}). ` +\n \"Cloudpack will attempt to handle this, but it's recommended to use semantic versions only if possible.\",\n );\n\n // Update the version in the returned dependencies:\n // \"bar\": \"npm:@custom/bar@^1\" => \"0.0.0-npm--custom-bar--1\"\n const resultDeps = (result[depType] ??= { ...deps });\n resultDeps[depName] = generateVersionFromNonSemver(depVersion);\n\n // Save that this was a non-semver dep\n const record = (nonSemverDeps[`${definition.name}@${definition.version}`] ??= {});\n (record[depType] ??= []).push(depName);\n }\n }\n\n // If this package's parent pulled it in with a non-semver dependency, make some more updates\n // (see below)\n const nonSemverParentInfo =\n importerContext && nonSemverDeps[`${importerContext.parentName}@${importerContext.parentVersion}`];\n\n // TODO: maybe this could also be used for resolutions if we have problems there:\n // adding a check for !semver.satisfies(requiredAs, definition.version) and forcing the package version?\n\n if (nonSemverParentInfo) {\n // Example: the parent depended on this package as \"bar\": \"npm:@custom/bar@^1\"\n // importedName = bar\n // versionRequirement = 0.0.0-npm--custom-bar--1 (was modified when this transform ran on the parent definition)\n const { importedName, versionRequirement } = importerContext;\n\n for (const depType of depTypes) {\n if (!nonSemverParentInfo[depType]?.includes(importedName)) {\n continue;\n }\n\n // To ensure other code handles this package properly, change its name and version to\n // the ones used by the parent (after transforms). This ensures it works properly with\n // the resolve map and isn't accidentally used by other packages which depend on this\n // package under its real name.\n result.name = importedName;\n result.version = versionRequirement;\n result.cloudpackRemapped = {\n originalName: definition.name || '',\n originalVersion: definition.version || '',\n };\n\n // We have changed the definition, so link the entry in nonSemverDeps to the new name/version.\n if (nonSemverDeps[`${definition.name}@${definition.version}`]) {\n nonSemverDeps[`${importedName}@${versionRequirement}`] =\n nonSemverDeps[`${definition.name}@${definition.version}`];\n }\n\n break;\n }\n }\n\n if (Object.keys(result).length) {\n return { ...definition, ...result };\n }\n return undefined;\n };\n}\n"]}
1
+ {"version":3,"file":"getNonSemverTransform.js","sourceRoot":"","sources":["../src/getNonSemverTransform.ts"],"names":[],"mappings":"AACA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,4BAA4B,EAAE,MAAM,mCAAmC,CAAC;AAEjF,MAAM,QAAQ,GAAG,CAAC,cAAc,EAAE,kBAAkB,CAAU,CAAC;AAE/D;;;;;;GAMG;AACH,MAAM,UAAU,qBAAqB;IACnC;;;OAGG;IACH,MAAM,aAAa,GAGf,EAAE,CAAC;IAEP,OAAO,CAAC,EAAE,UAAU,EAAE,WAAW,EAAE,eAAe,EAAE,EAAE,EAAE;QACtD,MAAM,MAAM,GAAyB,EAAE,CAAC;QAExC,oCAAoC;QACpC,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;YAC/B,MAAM,IAAI,GAAG,UAAU,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;YAEvC,KAAK,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;gBACzD,IAAI,CAAC,UAAU,IAAI,MAAM,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;oBACjD,SAAS;gBACX,CAAC;gBAED,OAAO,CAAC,KAAK,CACX,gCAAgC,OAAO,IAAI,UAAU,GAAG;oBACtD,OAAO,UAAU,CAAC,IAAI,IAAI,UAAU,CAAC,OAAO,OAAO,WAAW,KAAK;oBACnE,wGAAwG,CAC3G,CAAC;gBAEF,mDAAmD;gBACnD,gEAAgE;gBAChE,MAAM,UAAU,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,IAAI,EAAE,CAAC,CAAC;gBACrD,UAAU,CAAC,OAAO,CAAC,GAAG,4BAA4B,C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AAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,CAAC;YAC/B,OAAO,EAAE,GAAG,UAAU,EAAE,GAAG,MAAM,EAAE,CAAC;QACtC,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import type { PackageDefinitionTransform, PackageJson } from '@ms-cloudpack/common-types';\nimport semver from 'semver';\nimport { generateVersionFromNonSemver } from './generateVersionFromNonSemver.js';\n\nconst depTypes = ['dependencies', 'peerDependencies'] as const;\n\n/**\n * Get a transform which handles non-semver dependencies:\n * - In a parent package, if a dependency is specified with a non-semver version, change the dep\n * to a special `0.0.0-<original-version>` prerelease version.\n * - In a child package, if the package was pulled in as a non-semver dependency by a parent\n * (per the `importerContext`), change its version to the special prerelease version as above.\n */\nexport function getNonSemverTransform(): PackageDefinitionTransform {\n /**\n * Cached info about parent packages with non-semver dependencies:\n * Map from parent name/version => dep type => non-semver dependency names\n */\n const nonSemverDeps: Record<\n `${string}@${string}`,\n Partial<Record<'dependencies' | 'peerDependencies', string[]>>\n > = {};\n\n return ({ definition, packagePath, importerContext }) => {\n const result: Partial<PackageJson> = {};\n\n // Check for non-semver dependencies\n for (const depType of depTypes) {\n const deps = definition[depType] || {};\n\n for (const [depName, depVersion] of Object.entries(deps)) {\n if (!depVersion || semver.validRange(depVersion)) {\n continue;\n }\n\n console.debug(\n `Non-semver dependency found: ${depName}@${depVersion} ` +\n `(in ${definition.name}@${definition.version} at ${packagePath}). ` +\n \"Cloudpack will attempt to handle this, but it's recommended to use semantic versions only if possible.\",\n );\n\n // Update the version in the returned dependencies:\n // \"bar\": \"npm:@custom/bar@^1\" => \"0.0.0-npm--custom-bar--1\"\n const resultDeps = (result[depType] ??= { ...deps });\n resultDeps[depName] = generateVersionFromNonSemver(depVersion);\n\n // Save that this was a non-semver dep\n const record = (nonSemverDeps[`${definition.name}@${definition.version}`] ??= {});\n (record[depType] ??= []).push(depName);\n }\n }\n\n // If this package's parent pulled it in with a non-semver dependency, make some more updates\n // (see below)\n const nonSemverParentInfo =\n importerContext && nonSemverDeps[`${importerContext.parentName}@${importerContext.parentVersion}`];\n\n // TODO: maybe this could also be used for resolutions if we have problems there:\n // adding a check for !semver.satisfies(requiredAs, definition.version) and forcing the package version?\n\n if (nonSemverParentInfo) {\n // Example: the parent depended on this package as \"bar\": \"npm:@custom/bar@^1\"\n // importedName = bar\n // versionRequirement = 0.0.0-npm--custom-bar--1 (was modified when this transform ran on the parent definition)\n const { importedName, versionRequirement } = importerContext;\n\n for (const depType of depTypes) {\n if (!nonSemverParentInfo[depType]?.includes(importedName)) {\n continue;\n }\n\n // To ensure other code handles this package properly, change its name and version to\n // the ones used by the parent (after transforms). This ensures it works properly with\n // the resolve map and isn't accidentally used by other packages which depend on this\n // package under its real name.\n result.name = importedName;\n result.version = versionRequirement;\n\n // We have changed the definition, so link the entry in nonSemverDeps to the new name/version.\n if (nonSemverDeps[`${definition.name}@${definition.version}`]) {\n nonSemverDeps[`${importedName}@${versionRequirement}`] =\n nonSemverDeps[`${definition.name}@${definition.version}`];\n }\n\n break;\n }\n }\n\n if (Object.keys(result).length) {\n return { ...definition, ...result };\n }\n return undefined;\n };\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ms-cloudpack/package-utilities",
3
- "version": "7.5.4",
3
+ "version": "7.6.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.7.2",
17
+ "@ms-cloudpack/common-types": "^0.8.1",
18
18
  "@ms-cloudpack/json-utilities": "^0.1.4",
19
- "@ms-cloudpack/package-overrides": "^0.9.2",
19
+ "@ms-cloudpack/package-overrides": "^0.9.4",
20
20
  "@ms-cloudpack/path-string-parsing": "^1.2.3",
21
- "@ms-cloudpack/path-utilities": "^2.7.17",
21
+ "@ms-cloudpack/path-utilities": "^2.7.19",
22
22
  "@ms-cloudpack/task-reporter": "^0.14.1",
23
23
  "acorn": "^8.11.2",
24
24
  "acorn-walk": "^8.2.1",