@ms-cloudpack/package-utilities 12.3.25 → 12.5.0
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.
- package/lib/exportsMap/computePatternMatches.d.ts +14 -0
- package/lib/exportsMap/computePatternMatches.d.ts.map +1 -0
- package/lib/exportsMap/computePatternMatches.js +69 -0
- package/lib/exportsMap/computePatternMatches.js.map +1 -0
- package/lib/exportsMap/expandExportsMap.d.ts +7 -0
- package/lib/exportsMap/expandExportsMap.d.ts.map +1 -0
- package/lib/exportsMap/expandExportsMap.js +40 -0
- package/lib/exportsMap/expandExportsMap.js.map +1 -0
- package/lib/exportsMap/flattenExportsMap.d.ts.map +1 -1
- package/lib/exportsMap/flattenExportsMap.js +4 -58
- package/lib/exportsMap/flattenExportsMap.js.map +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/packageDefinitions/PackageDefinitions.d.ts.map +1 -1
- package/lib/packageDefinitions/PackageDefinitions.js +5 -2
- package/lib/packageDefinitions/PackageDefinitions.js.map +1 -1
- package/lib/resolveMap/createHelpers/{addLinkedEntryDependencies.d.ts → link/addLinkedEntryDependencies.d.ts} +1 -1
- package/lib/resolveMap/createHelpers/link/addLinkedEntryDependencies.d.ts.map +1 -0
- package/lib/resolveMap/createHelpers/{addLinkedEntryDependencies.js → link/addLinkedEntryDependencies.js} +1 -1
- package/lib/resolveMap/createHelpers/link/addLinkedEntryDependencies.js.map +1 -0
- package/lib/resolveMap/createHelpers/{convertToLinkResolveMap.d.ts → link/convertToLinkResolveMap.d.ts} +1 -1
- package/lib/resolveMap/createHelpers/link/convertToLinkResolveMap.d.ts.map +1 -0
- package/lib/resolveMap/createHelpers/{convertToLinkResolveMap.js → link/convertToLinkResolveMap.js} +1 -1
- package/lib/resolveMap/createHelpers/link/convertToLinkResolveMap.js.map +1 -0
- package/lib/resolveMap/createHelpers/{dedupeLinkedPackages.d.ts → link/dedupeLinkedPackages.d.ts} +2 -2
- package/lib/resolveMap/createHelpers/link/dedupeLinkedPackages.d.ts.map +1 -0
- package/lib/resolveMap/createHelpers/{dedupeLinkedPackages.js → link/dedupeLinkedPackages.js} +5 -9
- package/lib/resolveMap/createHelpers/link/dedupeLinkedPackages.js.map +1 -0
- package/lib/resolveMap/createHelpers/{detachEntry.d.ts → link/detachEntry.d.ts} +1 -1
- package/lib/resolveMap/createHelpers/link/detachEntry.d.ts.map +1 -0
- package/lib/resolveMap/createHelpers/{detachEntry.js → link/detachEntry.js} +1 -1
- package/lib/resolveMap/createHelpers/link/detachEntry.js.map +1 -0
- package/lib/resolveMap/createHelpers/{flattenResolveMap.d.ts → link/flattenResolveMap.d.ts} +1 -1
- package/lib/resolveMap/createHelpers/link/flattenResolveMap.d.ts.map +1 -0
- package/lib/resolveMap/createHelpers/link/flattenResolveMap.js.map +1 -0
- package/lib/resolveMap/createHelpers/link/getEffectiveResolutions.d.ts +9 -0
- package/lib/resolveMap/createHelpers/link/getEffectiveResolutions.d.ts.map +1 -0
- package/lib/resolveMap/createHelpers/link/getEffectiveResolutions.js +20 -0
- package/lib/resolveMap/createHelpers/link/getEffectiveResolutions.js.map +1 -0
- package/lib/resolveMap/createHelpers/{linkPath.d.ts → link/linkPath.d.ts} +1 -1
- package/lib/resolveMap/createHelpers/link/linkPath.d.ts.map +1 -0
- package/lib/resolveMap/createHelpers/{linkPath.js → link/linkPath.js} +5 -4
- package/lib/resolveMap/createHelpers/link/linkPath.js.map +1 -0
- package/lib/resolveMap/createLinkResolveMap.js +1 -1
- package/lib/resolveMap/createLinkResolveMap.js.map +1 -1
- package/lib/resolveMap/createResolveMap.js +1 -1
- package/lib/resolveMap/createResolveMap.js.map +1 -1
- package/package.json +5 -5
- package/lib/resolveMap/createHelpers/addLinkedEntryDependencies.d.ts.map +0 -1
- package/lib/resolveMap/createHelpers/addLinkedEntryDependencies.js.map +0 -1
- package/lib/resolveMap/createHelpers/convertToLinkResolveMap.d.ts.map +0 -1
- package/lib/resolveMap/createHelpers/convertToLinkResolveMap.js.map +0 -1
- package/lib/resolveMap/createHelpers/dedupeLinkedPackages.d.ts.map +0 -1
- package/lib/resolveMap/createHelpers/dedupeLinkedPackages.js.map +0 -1
- package/lib/resolveMap/createHelpers/detachEntry.d.ts.map +0 -1
- package/lib/resolveMap/createHelpers/detachEntry.js.map +0 -1
- package/lib/resolveMap/createHelpers/flattenResolveMap.d.ts.map +0 -1
- package/lib/resolveMap/createHelpers/flattenResolveMap.js.map +0 -1
- package/lib/resolveMap/createHelpers/linkPath.d.ts.map +0 -1
- package/lib/resolveMap/createHelpers/linkPath.js.map +0 -1
- /package/lib/resolveMap/createHelpers/{flattenResolveMap.js → link/flattenResolveMap.js} +0 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface PatternMatch {
|
|
2
|
+
key: string;
|
|
3
|
+
match: string;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Compute concrete (key, physical file) pairs for a wildcard or directory style export pattern.
|
|
7
|
+
* Returns an empty array if the key/value are not a supported pattern pair.
|
|
8
|
+
*/
|
|
9
|
+
export declare function computePatternMatches(params: {
|
|
10
|
+
key: string;
|
|
11
|
+
value: string;
|
|
12
|
+
packagePath: string;
|
|
13
|
+
}): PatternMatch[];
|
|
14
|
+
//# sourceMappingURL=computePatternMatches.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"computePatternMatches.d.ts","sourceRoot":"","sources":["../../src/exportsMap/computePatternMatches.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,YAAY;IAC3B,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,GAAG,YAAY,EAAE,CAwBjH"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { globSync } from 'tinyglobby';
|
|
2
|
+
import { normalizeRelativePath } from '@ms-cloudpack/path-string-parsing';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
/**
|
|
5
|
+
* Compute concrete (key, physical file) pairs for a wildcard or directory style export pattern.
|
|
6
|
+
* Returns an empty array if the key/value are not a supported pattern pair.
|
|
7
|
+
*/
|
|
8
|
+
export function computePatternMatches(params) {
|
|
9
|
+
const { key, value, packagePath } = params;
|
|
10
|
+
const keyWildcard = key.indexOf('*', 1);
|
|
11
|
+
const valueWildcard = value.indexOf('*', 1);
|
|
12
|
+
if (!((key.endsWith('/') && value.endsWith('/')) || (keyWildcard !== -1 && valueWildcard !== -1)))
|
|
13
|
+
return [];
|
|
14
|
+
const searchGlob = valueToGlob(value, valueWildcard);
|
|
15
|
+
const keySplit = splitByGlob(key, keyWildcard);
|
|
16
|
+
const valueSplit = splitByGlob(value, valueWildcard);
|
|
17
|
+
if (!searchGlob || !keySplit || !valueSplit)
|
|
18
|
+
return [];
|
|
19
|
+
const rawMatches = globSync(searchGlob, { cwd: packagePath, onlyFiles: true }).map((m) => normalizeRelativePath(m));
|
|
20
|
+
const results = [];
|
|
21
|
+
for (const match of rawMatches) {
|
|
22
|
+
// Skip files that don't have an extension or have a `.` extension only.
|
|
23
|
+
if (path.extname(match).length <= 1)
|
|
24
|
+
continue;
|
|
25
|
+
// Get the glob match shared between the key and value.
|
|
26
|
+
const globMatch = match.substring(valueSplit.start.length, match.length - valueSplit.end.length);
|
|
27
|
+
// Replace the glob match in the key with the resolved glob match in the value.
|
|
28
|
+
const matchKey = keySplit.start + globMatch + keySplit.end;
|
|
29
|
+
results.push({ key: matchKey, match });
|
|
30
|
+
}
|
|
31
|
+
return results;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Convert a value (an export target) to a glob pattern if it contains a wildcard or ends with a slash.
|
|
35
|
+
*
|
|
36
|
+
* Examples (asterisks shown with spacing to avoid comment terminator):
|
|
37
|
+
* ./dist/* -> ./dist/* *
|
|
38
|
+
* ./dist/ -> ./dist/* *
|
|
39
|
+
*
|
|
40
|
+
* @param value The value to convert.
|
|
41
|
+
* @param valueWildcard The index of the wildcard in the value.
|
|
42
|
+
* @returns A value converted to a glob pattern.
|
|
43
|
+
*/
|
|
44
|
+
function valueToGlob(value, valueWildcard = value.indexOf('*', 1)) {
|
|
45
|
+
if (value.endsWith('/')) {
|
|
46
|
+
return value + '**/*';
|
|
47
|
+
}
|
|
48
|
+
else if (valueWildcard !== -1) {
|
|
49
|
+
// Use a brace expansion that matches either a single path segment (no slash) or any nested path (with slashes).
|
|
50
|
+
return value.substring(0, valueWildcard) + '{*,**/*}' + value.substring(valueWildcard + 1);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Split a pattern value into the start and end pieces around the wildcard (or trailing slash).
|
|
55
|
+
* Returned { start, end } segments are used to extract the dynamic portion from matched file paths.
|
|
56
|
+
*
|
|
57
|
+
* @param value The value to split.
|
|
58
|
+
* @param valueWildcard The index of the wildcard in the value.
|
|
59
|
+
* @returns An object with the start and end substring of the split value.
|
|
60
|
+
*/
|
|
61
|
+
function splitByGlob(value, valueWildcard = value.indexOf('*', 1)) {
|
|
62
|
+
if (value.endsWith('/')) {
|
|
63
|
+
return { start: value, end: '' };
|
|
64
|
+
}
|
|
65
|
+
else if (valueWildcard !== -1) {
|
|
66
|
+
return { start: value.substring(0, valueWildcard), end: value.substring(valueWildcard + 1) };
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=computePatternMatches.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"computePatternMatches.js","sourceRoot":"","sources":["../../src/exportsMap/computePatternMatches.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,qBA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,CAAC,EAAE,GAAG,EAAE,KAAK,CAAC,SAAS,CAAC,aAAa,GAAG,CAAC,CAAC,EAAE,CAAC;IAC/F,CAAC;AACH,CAAC","sourcesContent":["import { globSync } from 'tinyglobby';\nimport { normalizeRelativePath } from '@ms-cloudpack/path-string-parsing';\nimport path from 'path';\n\nexport interface PatternMatch {\n key: string;\n match: string;\n}\n\n/**\n * Compute concrete (key, physical file) pairs for a wildcard or directory style export pattern.\n * Returns an empty array if the key/value are not a supported pattern pair.\n */\nexport function computePatternMatches(params: { key: string; value: string; packagePath: string }): PatternMatch[] {\n const { key, value, packagePath } = params;\n\n const keyWildcard = key.indexOf('*', 1);\n const valueWildcard = value.indexOf('*', 1);\n if (!((key.endsWith('/') && value.endsWith('/')) || (keyWildcard !== -1 && valueWildcard !== -1))) return [];\n\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\n const rawMatches = globSync(searchGlob, { cwd: packagePath, onlyFiles: true }).map((m) => normalizeRelativePath(m));\n const results: PatternMatch[] = [];\n for (const match of rawMatches) {\n // Skip files that don't have an extension or have a `.` extension only.\n if (path.extname(match).length <= 1) continue;\n // Get the glob match shared between the key and value.\n const globMatch = match.substring(valueSplit.start.length, match.length - valueSplit.end.length);\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 results.push({ key: matchKey, match });\n }\n return results;\n}\n\n/**\n * Convert a value (an export target) to a glob pattern if it contains a wildcard or ends with a slash.\n *\n * Examples (asterisks shown with spacing to avoid comment terminator):\n * ./dist/* -> ./dist/* *\n * ./dist/ -> ./dist/* *\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)): string | undefined {\n if (value.endsWith('/')) {\n return value + '**/*';\n } else if (valueWildcard !== -1) {\n // Use a brace expansion that matches either a single path segment (no slash) or any nested path (with slashes).\n return value.substring(0, valueWildcard) + '{*,**/*}' + value.substring(valueWildcard + 1);\n }\n}\n\n/**\n * Split a pattern value into the start and end pieces around the wildcard (or trailing slash).\n * Returned { start, end } segments are used to extract the dynamic portion from matched file paths.\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(\n value: string,\n valueWildcard: number = value.indexOf('*', 1),\n): { start: string; end: string } | undefined {\n if (value.endsWith('/')) {\n return { start: value, end: '' };\n } else if (valueWildcard !== -1) {\n return { start: value.substring(0, valueWildcard), end: value.substring(valueWildcard + 1) };\n }\n}\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { PackageJsonExports } from '@ms-cloudpack/common-types';
|
|
2
|
+
/**
|
|
3
|
+
* Expand pattern / directory style entries in a package exports map into explicit file entries.
|
|
4
|
+
* Original pattern keys are removed; conditional pattern entries produce concrete condition objects.
|
|
5
|
+
*/
|
|
6
|
+
export declare function expandExportsMap(exportsMap: PackageJsonExports, packagePath: string): PackageJsonExports;
|
|
7
|
+
//# sourceMappingURL=expandExportsMap.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expandExportsMap.d.ts","sourceRoot":"","sources":["../../src/exportsMap/expandExportsMap.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAA4B,MAAM,4BAA4B,CAAC;AAG/F;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,UAAU,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,GAAG,kBAAkB,CAkCxG"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { computePatternMatches } from './computePatternMatches.js';
|
|
2
|
+
/**
|
|
3
|
+
* Expand pattern / directory style entries in a package exports map into explicit file entries.
|
|
4
|
+
* Original pattern keys are removed; conditional pattern entries produce concrete condition objects.
|
|
5
|
+
*/
|
|
6
|
+
export function expandExportsMap(exportsMap, packagePath) {
|
|
7
|
+
if (!exportsMap || typeof exportsMap === 'string' || Array.isArray(exportsMap))
|
|
8
|
+
return exportsMap;
|
|
9
|
+
const clone = {};
|
|
10
|
+
for (const [key, value] of Object.entries(exportsMap)) {
|
|
11
|
+
const isPattern = key.endsWith('/') || key.includes('*');
|
|
12
|
+
if (!isPattern) {
|
|
13
|
+
clone[key] = value;
|
|
14
|
+
continue;
|
|
15
|
+
}
|
|
16
|
+
if (typeof value === 'string') {
|
|
17
|
+
for (const m of computePatternMatches({ key, value, packagePath })) {
|
|
18
|
+
if (!clone[m.key]) {
|
|
19
|
+
clone[m.key] = m.match;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
if (value && typeof value === 'object' && !Array.isArray(value)) {
|
|
25
|
+
const aggregated = {};
|
|
26
|
+
for (const [cond, target] of Object.entries(value)) {
|
|
27
|
+
if (typeof target !== 'string')
|
|
28
|
+
continue; // skip nested objects/arrays
|
|
29
|
+
for (const m of computePatternMatches({ key, value: target, packagePath })) {
|
|
30
|
+
(aggregated[m.key] ||= {})[cond] = m.match;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
for (const [matchKey, condMap] of Object.entries(aggregated))
|
|
34
|
+
if (!clone[matchKey])
|
|
35
|
+
clone[matchKey] = condMap;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return clone;
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=expandExportsMap.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expandExportsMap.js","sourceRoot":"","sources":["../../src/exportsMap/expandExportsMap.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAEnE;;;GAGG;AACH,MAAM,UAAU,gBAAgB,CAAC,UAA8B,EAAE,WAAmB;IAClF,IAA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EAAE,CAAC;oBAC3E,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC;gBAC7C,CAAC;YACH,CAAC;YACD,KAAK,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC;gBAAE,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC;oBAAE,KAAK,CAAC,QAAQ,CAAC,GAAG,OAAO,CAAC;QAChH,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["import type { PackageJsonExports, PackageJsonExportsObject } from '@ms-cloudpack/common-types';\nimport { computePatternMatches } from './computePatternMatches.js';\n\n/**\n * Expand pattern / directory style entries in a package exports map into explicit file entries.\n * Original pattern keys are removed; conditional pattern entries produce concrete condition objects.\n */\nexport function expandExportsMap(exportsMap: PackageJsonExports, packagePath: string): PackageJsonExports {\n if (!exportsMap || typeof exportsMap === 'string' || Array.isArray(exportsMap)) return exportsMap;\n\n const clone: PackageJsonExportsObject = {};\n\n for (const [key, value] of Object.entries(exportsMap)) {\n const isPattern = key.endsWith('/') || key.includes('*');\n if (!isPattern) {\n clone[key] = value as PackageJsonExports;\n continue;\n }\n\n if (typeof value === 'string') {\n for (const m of computePatternMatches({ key, value, packagePath })) {\n if (!clone[m.key]) {\n clone[m.key] = m.match;\n }\n }\n continue;\n }\n\n if (value && typeof value === 'object' && !Array.isArray(value)) {\n const aggregated: Record<string, Record<string, string>> = {};\n for (const [cond, target] of Object.entries(value)) {\n if (typeof target !== 'string') continue; // skip nested objects/arrays\n for (const m of computePatternMatches({ key, value: target, packagePath })) {\n (aggregated[m.key] ||= {})[cond] = m.match;\n }\n }\n for (const [matchKey, condMap] of Object.entries(aggregated)) if (!clone[matchKey]) clone[matchKey] = condMap;\n }\n }\n\n return clone;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flattenExportsMap.d.ts","sourceRoot":"","sources":["../../src/exportsMap/flattenExportsMap.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAA4B,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"flattenExportsMap.d.ts","sourceRoot":"","sources":["../../src/exportsMap/flattenExportsMap.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAA4B,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAc/F;;;;;;;;;;;GAWG;AACH,wBAAgB,iBAAiB,CAC/B,UAAU,EAAE,kBAAkB,EAC9B,OAAO,GAAE;IACP;;;;;;OAMG;IACH,UAAU,CAAC,EAAE,eAAe,GAAG,kBAAkB,GAAG,MAAM,EAAE,CAAC;IAC7D,6DAA6D;IAC7D,kBAAkB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC9B,sGAAsG;IACtG,WAAW,CAAC,EAAE,MAAM,CAAC;CACjB,GACL,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAyBxB"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
|
-
import { globSync } from 'tinyglobby';
|
|
3
2
|
import { mergeArrayDefaults } from '../object/mergeArrayDefaults.js';
|
|
4
|
-
import {
|
|
3
|
+
import { computePatternMatches } from './computePatternMatches.js';
|
|
5
4
|
// The 'module' condition may be a webpack-ism, explained on this page:
|
|
6
5
|
// https://webpack.js.org/guides/package-exports/#conditions
|
|
7
6
|
// With that approach (used by @emotion/styled ^11.11.0), the 'module' key indicates actual ESM,
|
|
@@ -128,65 +127,12 @@ function addExportsEntry(params) {
|
|
|
128
127
|
// A package path is required to resolve entries and values that end in `/` or that include a wildcard `*`.
|
|
129
128
|
if (!packagePath)
|
|
130
129
|
return;
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
const valueWildcard = value.indexOf('*', 1);
|
|
135
|
-
if ((key.endsWith('/') && value.endsWith('/')) || (keyWildcard !== -1 && valueWildcard !== -1)) {
|
|
136
|
-
const searchGlob = valueToGlob(value, valueWildcard);
|
|
137
|
-
const keySplit = splitByGlob(key, keyWildcard);
|
|
138
|
-
const valueSplit = splitByGlob(value, valueWildcard);
|
|
139
|
-
if (!searchGlob || !keySplit || !valueSplit)
|
|
140
|
-
return;
|
|
141
|
-
// We only want to search for files.
|
|
142
|
-
const matches = globSync(searchGlob, { cwd: packagePath, onlyFiles: true }).map((match) => normalizeRelativePath(match));
|
|
143
|
-
for (const match of matches) {
|
|
144
|
-
// Skip files that don't have an extension or have a `.` extension.
|
|
145
|
-
if (path.extname(match).length <= 1)
|
|
146
|
-
continue;
|
|
147
|
-
// Get the glob match shared between the key and value.
|
|
148
|
-
const globMatch = match.substring(valueSplit.start.length, match.length - valueSplit.end.length);
|
|
149
|
-
// Replace the glob match in the key with the resolved glob match in the value.
|
|
150
|
-
const matchKey = keySplit.start + globMatch + keySplit.end;
|
|
151
|
-
if (!flatExports[matchKey]) {
|
|
152
|
-
flatExports[matchKey] = cleanEntry(match);
|
|
153
|
-
}
|
|
130
|
+
for (const m of computePatternMatches({ key, value, packagePath })) {
|
|
131
|
+
if (!flatExports[m.key]) {
|
|
132
|
+
flatExports[m.key] = cleanEntry(m.match);
|
|
154
133
|
}
|
|
155
134
|
}
|
|
156
135
|
}
|
|
157
|
-
/**
|
|
158
|
-
* Convert a value to a glob pattern.
|
|
159
|
-
*
|
|
160
|
-
* @param value The value to convert.
|
|
161
|
-
* @param valueWildcard The index of the wildcard in the value.
|
|
162
|
-
* @returns A value converted to a glob pattern.
|
|
163
|
-
*/
|
|
164
|
-
function valueToGlob(value, valueWildcard = value.indexOf('*', 1)) {
|
|
165
|
-
if (value.endsWith('/')) {
|
|
166
|
-
return value + '**/*';
|
|
167
|
-
}
|
|
168
|
-
else if (valueWildcard !== -1) {
|
|
169
|
-
return value.substring(0, valueWildcard) + '**/*' + value.substring(valueWildcard + 1);
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
/**
|
|
173
|
-
* Split a value by the location of the trailing slash or wildcard.
|
|
174
|
-
*
|
|
175
|
-
* @param value The value to split.
|
|
176
|
-
* @param valueWildcard The index of the wildcard in the value.
|
|
177
|
-
* @returns An object with the start and end substring of the split value.
|
|
178
|
-
*/
|
|
179
|
-
function splitByGlob(value, valueWildcard = value.indexOf('*', 1)) {
|
|
180
|
-
if (value.endsWith('/')) {
|
|
181
|
-
return { start: value, end: '' };
|
|
182
|
-
}
|
|
183
|
-
else if (valueWildcard !== -1) {
|
|
184
|
-
return {
|
|
185
|
-
start: value.substring(0, valueWildcard),
|
|
186
|
-
end: value.substring(valueWildcard + 1),
|
|
187
|
-
};
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
136
|
function cleanEntry(entryName) {
|
|
191
137
|
if (path.extname(entryName) === '') {
|
|
192
138
|
entryName += '.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flattenExportsMap.js","sourceRoot":"","sources":["../../src/exportsMap/flattenExportsMap.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AACrE,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAE1E,uEAAuE;AACvE,4DAA4D;AAC5D,gGAAgG;AAChG,oGAAoG;AACpG,+FAA+F;AAC/F,yEAAyE;AACzE,mFAAmF;AACnF,MAAM,eAAe,GAAG,CAAC,SAAS,EAAE,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC;AAC9E,MAAM,YAAY,GAAG,CAAC,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC;AAExE;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,iBAAiB,CAC/B,UAA8B,EAC9B,UAaI,EA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CAAC,SAAS,CAAC,KAAK,EAAE,EAAE,CAAC;QACnC,SAAS,IAAI,KAAK,CAAC;IACrB,CAAC;IAED,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;QAChC,SAAS,GAAG,KAAK,SAAS,EAAE,CAAC;IAC/B,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["import path from 'path';\nimport type { PackageJsonExportsObject, PackageJsonExports } from '@ms-cloudpack/common-types';\nimport { globSync } from 'tinyglobby';\nimport { mergeArrayDefaults } from '../object/mergeArrayDefaults.js';\nimport { normalizeRelativePath } from '@ms-cloudpack/path-string-parsing';\n\n// The 'module' condition may be a webpack-ism, explained on this page:\n// https://webpack.js.org/guides/package-exports/#conditions\n// With that approach (used by @emotion/styled ^11.11.0), the 'module' key indicates actual ESM,\n// whereas 'import' may indicate a wrapper around a CJS module. The proper way to specify precedence\n// is by key order in the exports map, but flattenExportsMap doesn't currently respect that, so\n// instead we have to ensure 'module' comes before other conditions here.\n// (emotion issue was found here: https://github.com/microsoft/cloudpack/pull/1088)\nconst browserDefaults = ['browser', 'module', 'import', 'density', 'default'];\nconst nodeDefaults = ['node', 'module', 'import', 'default', 'require'];\n\n/**\n * Given a package definition and applicable conditions, return a flat map of package import to physical (relative) path.\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 /**\n * The conditions to check for in the exports object.\n * - `'browser-defaults'` uses the default browser-appropriate conditions.\n * - `'node-defaults'` uses the default Node-appropriate conditions.\n * - An array is a custom list of conditions. Use `'...'` to include the default browser conditions.\n * @default 'browser-defaults'\n */\n conditions?: 'node-defaults' | 'browser-defaults' | string[];\n /** The conditions that must be matched to add the export. */\n requiredConditions?: string[];\n /** Path to the package, used to resolve entries and values that end in `/` and with wildcards `*`. */\n packagePath?: string;\n } = {},\n): Record<string, string> {\n const { requiredConditions, packagePath, conditions: rawConditions = 'browser-defaults' } = options;\n\n const conditions =\n rawConditions === 'browser-defaults'\n ? browserDefaults\n : rawConditions === 'node-defaults'\n ? nodeDefaults\n : mergeArrayDefaults(rawConditions, browserDefaults);\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(params: {\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: ReadonlyArray<string>;\n /** The conditions that must be matched to add the export. */\n requiredConditions?: ReadonlyArray<string>;\n /** The cumulative flat exports map to add the exports to. */\n flatExports: Record<string, string>;\n /** The import path to match */\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}): Record<string, string> {\n const { exports, conditions, requiredConditions, flatExports, matchedConditions, packagePath, importMatch } = params;\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({ ...params, exports: exportEntry });\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 conditionExports = (exports as PackageJsonExportsObject)[condition];\n\n if (conditionExports) {\n extractExports({\n ...params,\n exports: conditionExports,\n matchedConditions: matchedConditions.concat(condition),\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 continue; // not a path\n }\n\n if (typeof value === 'string') {\n if (!flatExports[key] && (!requiredConditions || requiredConditions?.includes(key))) {\n addExportsEntry({ flatExports, key, value, packagePath });\n }\n } else if (value) {\n extractExports({\n ...params,\n exports: value,\n importMatch: key,\n matchedConditions: [...matchedConditions, key],\n });\n } else {\n delete flatExports[key];\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(params: {\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}): void {\n const { flatExports, key, value, packagePath } = params;\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 = globSync(searchGlob, { cwd: packagePath, onlyFiles: true }).map((match) =>\n normalizeRelativePath(match),\n );\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(valueSplit.start.length, match.length - valueSplit.end.length);\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)): string | undefined {\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(\n value: string,\n valueWildcard: number = value.indexOf('*', 1),\n): { start: string; end: string } | undefined {\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\nfunction cleanEntry(entryName: string) {\n if (path.extname(entryName) === '') {\n entryName += '.js';\n }\n\n if (!entryName.startsWith('./')) {\n entryName = `./${entryName}`;\n }\n\n return entryName;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"flattenExportsMap.js","sourceRoot":"","sources":["../../src/exportsMap/flattenExportsMap.ts"],"names":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ms-cloudpack/common-types';\nimport { mergeArrayDefaults } from '../object/mergeArrayDefaults.js';\nimport { computePatternMatches } from './computePatternMatches.js';\n\n// The 'module' condition may be a webpack-ism, explained on this page:\n// https://webpack.js.org/guides/package-exports/#conditions\n// With that approach (used by @emotion/styled ^11.11.0), the 'module' key indicates actual ESM,\n// whereas 'import' may indicate a wrapper around a CJS module. The proper way to specify precedence\n// is by key order in the exports map, but flattenExportsMap doesn't currently respect that, so\n// instead we have to ensure 'module' comes before other conditions here.\n// (emotion issue was found here: https://github.com/microsoft/cloudpack/pull/1088)\nconst browserDefaults = ['browser', 'module', 'import', 'density', 'default'];\nconst nodeDefaults = ['node', 'module', 'import', 'default', 'require'];\n\n/**\n * Given a package definition and applicable conditions, return a flat map of package import to physical (relative) path.\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 /**\n * The conditions to check for in the exports object.\n * - `'browser-defaults'` uses the default browser-appropriate conditions.\n * - `'node-defaults'` uses the default Node-appropriate conditions.\n * - An array is a custom list of conditions. Use `'...'` to include the default browser conditions.\n * @default 'browser-defaults'\n */\n conditions?: 'node-defaults' | 'browser-defaults' | string[];\n /** The conditions that must be matched to add the export. */\n requiredConditions?: string[];\n /** Path to the package, used to resolve entries and values that end in `/` and with wildcards `*`. */\n packagePath?: string;\n } = {},\n): Record<string, string> {\n const { requiredConditions, packagePath, conditions: rawConditions = 'browser-defaults' } = options;\n\n const conditions =\n rawConditions === 'browser-defaults'\n ? browserDefaults\n : rawConditions === 'node-defaults'\n ? nodeDefaults\n : mergeArrayDefaults(rawConditions, browserDefaults);\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(params: {\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: ReadonlyArray<string>;\n /** The conditions that must be matched to add the export. */\n requiredConditions?: ReadonlyArray<string>;\n /** The cumulative flat exports map to add the exports to. */\n flatExports: Record<string, string>;\n /** The import path to match */\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}): Record<string, string> {\n const { exports, conditions, requiredConditions, flatExports, matchedConditions, packagePath, importMatch } = params;\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({ ...params, exports: exportEntry });\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 conditionExports = (exports as PackageJsonExportsObject)[condition];\n\n if (conditionExports) {\n extractExports({\n ...params,\n exports: conditionExports,\n matchedConditions: matchedConditions.concat(condition),\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 continue; // not a path\n }\n\n if (typeof value === 'string') {\n if (!flatExports[key] && (!requiredConditions || requiredConditions?.includes(key))) {\n addExportsEntry({ flatExports, key, value, packagePath });\n }\n } else if (value) {\n extractExports({\n ...params,\n exports: value,\n importMatch: key,\n matchedConditions: [...matchedConditions, key],\n });\n } else {\n delete flatExports[key];\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(params: {\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}): void {\n const { flatExports, key, value, packagePath } = params;\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 for (const m of computePatternMatches({ key, value, packagePath })) {\n if (!flatExports[m.key]) {\n flatExports[m.key] = cleanEntry(m.match);\n }\n }\n}\n\nfunction cleanEntry(entryName: string) {\n if (path.extname(entryName) === '') {\n entryName += '.js';\n }\n\n if (!entryName.startsWith('./')) {\n entryName = `./${entryName}`;\n }\n\n return entryName;\n}\n"]}
|
package/lib/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export type { DiffResolveMapsChanges, DiffResolveMapsStats } from './resolveMap/
|
|
|
7
7
|
export { diffResolveMaps } from './resolveMap/diffResolveMaps.js';
|
|
8
8
|
export { ensureResolveMapEntry } from './resolveMap/ensureResolveMapEntry.js';
|
|
9
9
|
export { flattenExportsMap } from './exportsMap/flattenExportsMap.js';
|
|
10
|
+
export { expandExportsMap } from './exportsMap/expandExportsMap.js';
|
|
10
11
|
export { addExportsMapEntry, type AddExportsMapEntryOptions } from './exportsMap/addExportsMapEntry.js';
|
|
11
12
|
export { getExportsMap } from './exportsMap/getExportsMap.js';
|
|
12
13
|
export { getSourceEntry } from './exportsMap/getSourceEntry.js';
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,4CAA4C,CAAC;AAChF,OAAO,EAAE,sBAAsB,EAAE,MAAM,gDAAgD,CAAC;AAGxF,OAAO,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,sCAAsC,CAAC;AAC5E,OAAO,EAAE,mBAAmB,EAAE,MAAM,qCAAqC,CAAC;AAC1E,YAAY,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AACpG,OAAO,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAClE,OAAO,EAAE,qBAAqB,EAAE,MAAM,uCAAuC,CAAC;AAG9E,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AACtE,OAAO,EAAE,kBAAkB,EAAE,KAAK,yBAAyB,EAAE,MAAM,oCAAoC,CAAC;AACxG,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAGhE,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EACL,iBAAiB,EACjB,KAAK,wBAAwB,EAC7B,KAAK,uBAAuB,GAC7B,MAAM,0CAA0C,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAC5E,OAAO,EAAE,e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AM,kCAAkC,CAAC;AACnE,OAAO,EAAE,qBAAqB,EAAE,MAAM,wCAAwC,CAAC;AAG/E,OAAO,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AACpE,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC"}
|
package/lib/index.js
CHANGED
|
@@ -9,6 +9,7 @@ export { diffResolveMaps } from './resolveMap/diffResolveMaps.js';
|
|
|
9
9
|
export { ensureResolveMapEntry } from './resolveMap/ensureResolveMapEntry.js';
|
|
10
10
|
// ExportsMap parsing and creation
|
|
11
11
|
export { flattenExportsMap } from './exportsMap/flattenExportsMap.js';
|
|
12
|
+
export { expandExportsMap } from './exportsMap/expandExportsMap.js';
|
|
12
13
|
export { addExportsMapEntry } from './exportsMap/addExportsMapEntry.js';
|
|
13
14
|
export { getExportsMap } from './exportsMap/getExportsMap.js';
|
|
14
15
|
export { getSourceEntry } from './exportsMap/getSourceEntry.js';
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,6BAA6B;AAC7B,OAAO,EAAE,kBAAkB,EAAE,MAAM,4CAA4C,CAAC;AAChF,OAAO,EAAE,sBAAsB,EAAE,MAAM,gDAAgD,CAAC;AAExF,cAAc;AACd,OAAO,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,sCAAsC,CAAC;AAC5E,OAAO,EAAE,mBAAmB,EAAE,MAAM,qCAAqC,CAAC;AAE1E,OAAO,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAClE,OAAO,EAAE,qBAAqB,EAAE,MAAM,uCAAuC,CAAC;AAE9E,kCAAkC;AAClC,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AACtE,OAAO,EAAE,kBAAkB,EAAkC,MAAM,oCAAoC,CAAC;AACxG,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAEhE,0BAA0B;AAC1B,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EACL,iBAAiB,GAGlB,MAAM,0CAA0C,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAC5E,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AACnE,OAAO,EAAE,qBAAqB,EAAE,MAAM,wCAAwC,CAAC;AAE/E,qFAAqF;AACrF,OAAO,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AACpE,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC","sourcesContent":["// Package definition parsing\nexport { PackageDefinitions } from './packageDefinitions/PackageDefinitions.js';\nexport { MockPackageDefinitions } from './packageDefinitions/MockPackageDefinitions.js';\n\n// ResolveMaps\nexport { createResolveMap } from './resolveMap/createResolveMap.js';\nexport { createLinkResolveMap } from './resolveMap/createLinkResolveMap.js';\nexport { findResolveMapEntry } from './resolveMap/findResolveMapEntry.js';\nexport type { DiffResolveMapsChanges, DiffResolveMapsStats } from './resolveMap/diffResolveMaps.js';\nexport { diffResolveMaps } from './resolveMap/diffResolveMaps.js';\nexport { ensureResolveMapEntry } from './resolveMap/ensureResolveMapEntry.js';\n\n// ExportsMap parsing and creation\nexport { flattenExportsMap } from './exportsMap/flattenExportsMap.js';\nexport { addExportsMapEntry, type AddExportsMapEntryOptions } from './exportsMap/addExportsMapEntry.js';\nexport { getExportsMap } from './exportsMap/getExportsMap.js';\nexport { getSourceEntry } from './exportsMap/getSourceEntry.js';\n\n// Other package utilities\nexport { detectModuleType } from './detectModuleType.js';\nexport {\n findFileInPackage,\n type FindFileInPackageOptions,\n type FindFileInPackageResult,\n} from './findFileInPackage/findFileInPackage.js';\nexport { getVersion, getDisplayVersion } from './packageJson/getVersion.js';\nexport { getDependencies } from './packageJson/getDependencies.js';\nexport { getUnusedDependencies } from './packageJson/getUnusedDependencies.js';\n\n// Object utilities which could be moved to a separate package if we add more of them\nexport { mergeArrayDefaults } from './object/mergeArrayDefaults.js';\nexport { mergeObjects } from './object/mergeObjects.js';\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,6BAA6B;AAC7B,OAAO,EAAE,kBAAkB,EAAE,MAAM,4CAA4C,CAAC;AAChF,OAAO,EAAE,sBAAsB,EAAE,MAAM,gDAAgD,CAAC;AAExF,cAAc;AACd,OAAO,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,sCAAsC,CAAC;AAC5E,OAAO,EAAE,mBAAmB,EAAE,MAAM,qCAAqC,CAAC;AAE1E,OAAO,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAClE,OAAO,EAAE,qBAAqB,EAAE,MAAM,uCAAuC,CAAC;AAE9E,kCAAkC;AAClC,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AACtE,OAAO,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AACpE,OAAO,EAAE,kBAAkB,EAAkC,MAAM,oCAAoC,CAAC;AACxG,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAEhE,0BAA0B;AAC1B,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EACL,iBAAiB,GAGlB,MAAM,0CAA0C,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAC5E,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AACnE,OAAO,EAAE,qBAAqB,EAAE,MAAM,wCAAwC,CAAC;AAE/E,qFAAqF;AACrF,OAAO,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AACpE,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC","sourcesContent":["// Package definition parsing\nexport { PackageDefinitions } from './packageDefinitions/PackageDefinitions.js';\nexport { MockPackageDefinitions } from './packageDefinitions/MockPackageDefinitions.js';\n\n// ResolveMaps\nexport { createResolveMap } from './resolveMap/createResolveMap.js';\nexport { createLinkResolveMap } from './resolveMap/createLinkResolveMap.js';\nexport { findResolveMapEntry } from './resolveMap/findResolveMapEntry.js';\nexport type { DiffResolveMapsChanges, DiffResolveMapsStats } from './resolveMap/diffResolveMaps.js';\nexport { diffResolveMaps } from './resolveMap/diffResolveMaps.js';\nexport { ensureResolveMapEntry } from './resolveMap/ensureResolveMapEntry.js';\n\n// ExportsMap parsing and creation\nexport { flattenExportsMap } from './exportsMap/flattenExportsMap.js';\nexport { expandExportsMap } from './exportsMap/expandExportsMap.js';\nexport { addExportsMapEntry, type AddExportsMapEntryOptions } from './exportsMap/addExportsMapEntry.js';\nexport { getExportsMap } from './exportsMap/getExportsMap.js';\nexport { getSourceEntry } from './exportsMap/getSourceEntry.js';\n\n// Other package utilities\nexport { detectModuleType } from './detectModuleType.js';\nexport {\n findFileInPackage,\n type FindFileInPackageOptions,\n type FindFileInPackageResult,\n} from './findFileInPackage/findFileInPackage.js';\nexport { getVersion, getDisplayVersion } from './packageJson/getVersion.js';\nexport { getDependencies } from './packageJson/getDependencies.js';\nexport { getUnusedDependencies } from './packageJson/getUnusedDependencies.js';\n\n// Object utilities which could be moved to a separate package if we add more of them\nexport { mergeArrayDefaults } from './object/mergeArrayDefaults.js';\nexport { mergeObjects } from './object/mergeObjects.js';\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PackageDefinitions.d.ts","sourceRoot":"","sources":["../../src/packageDefinitions/PackageDefinitions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,eAAe,EACf,2BAA2B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GAAG,CACD,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,WAAW,EACvB,OAAO,CAAC,EAAE,IAAI,CAAC,2BAA2B,EAAE,mBAAmB,CAAC,GAC/D,IAAI;IAYP,MAAM,CAAC,KAAK,EAAE,mCAAmC,GAAG,IAAI;IAKxD,cAAc,IAAI,mCAAmC;cAOrC,YAAY,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC;CAIvF"}
|
|
@@ -9,7 +9,8 @@ import { getTypesTransform } from './getTypesTransform.js';
|
|
|
9
9
|
*/
|
|
10
10
|
const getDefaultTransforms = () => [getTypesTransform(), getNonSemverTransform()];
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
12
|
+
* Defines which keys from package.json are allowed to be cloned.
|
|
13
|
+
* Keys with true values are cloned, keys with false values are not cloned.
|
|
13
14
|
* (It's an object for better typings and faster access.)
|
|
14
15
|
*
|
|
15
16
|
* NOTE: If you add any new keys to PackageJson, they must be added here too.
|
|
@@ -32,6 +33,8 @@ const copyPackageJsonKeys = {
|
|
|
32
33
|
exports: true,
|
|
33
34
|
resolutions: true,
|
|
34
35
|
cloudpack: true,
|
|
36
|
+
/** Engines are used to check Node version compatibility between process and Cloudpack, not for packages bundled by Cloudpack */
|
|
37
|
+
engines: false,
|
|
35
38
|
};
|
|
36
39
|
export class PackageDefinitions {
|
|
37
40
|
_definitions = {};
|
|
@@ -82,7 +85,7 @@ export class PackageDefinitions {
|
|
|
82
85
|
let transformedDefinition = this._transformedDefinitions[normalizedPath];
|
|
83
86
|
if (!transformedDefinition) {
|
|
84
87
|
// Clone the definition (only keys we care about) so we don't accidentally modify the original.
|
|
85
|
-
transformedDefinition = cloneJson(definition, {
|
|
88
|
+
transformedDefinition = cloneJson(definition, { keys: copyPackageJsonKeys });
|
|
86
89
|
for (const transform of this._transforms) {
|
|
87
90
|
transformedDefinition =
|
|
88
91
|
(await transform({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{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ackageDefinitionOptions,\n PackageDefinitionTransform,\n PackageDefinitionTransformFactory,\n PackageDefinitionsCache,\n PackageJson,\n SerializablePackageDefinitionsCache,\n} from '@ms-cloudpack/common-types';\nimport { cloneJson, readJson } from '@ms-cloudpack/json-utilities';\nimport { getNonSemverTransform } from './getNonSemverTransform.js';\nimport { slash } from '@ms-cloudpack/path-string-parsing';\nimport { getTypesTransform } from './getTypesTransform.js';\n\nexport interface PackageDefinitionsOptions {\n /**\n * Config object to pass to transforms. When `reset` is called with a new value, the transforms\n * will be transforms will be re-created using the new config.\n */\n config?: CloudpackConfig;\n /**\n * Transform factories to register on initialization.\n */\n transformFactories?: PackageDefinitionTransformFactory[];\n}\n\n/**\n * `nonSemverTransform` has state defined when the function is called, so we need a wrapper function\n * which returns new transforms to ensure that state is cleared when resetting.\n */\nconst getDefaultTransforms = () => [getTypesTransform(), getNonSemverTransform()];\n\n/**\n * Only copy these keys from package.json, to reduce the amount cloned before applying transforms.\n * (It's an object for better typings and faster access.)\n *\n * NOTE: If you add any new keys to PackageJson, they must be added here too.\n */\nconst copyPackageJsonKeys: Record<keyof PackageJson, true> = {\n name: true,\n version: true,\n description: true,\n dependencies: true,\n devDependencies: true,\n peerDependencies: true,\n peerDependenciesMeta: true,\n optionalDependencies: true,\n bundledDependencies: true,\n bundleDependencies: true,\n type: true,\n main: true,\n module: true,\n browser: true,\n exports: true,\n resolutions: true,\n cloudpack: true,\n};\n\nexport class PackageDefinitions implements PackageDefinitionsCache {\n private _definitions: Record<string, PackageJson | undefined> = {};\n private _transformedDefinitions: Record<string, PackageJson> = {};\n private _config: CloudpackConfig | undefined;\n private _transforms: PackageDefinitionTransform[] = [];\n private _transformFactories: PackageDefinitionTransformFactory[] = [];\n\n /**\n * **WARNING**: Cloudpack code (including tests) outside of `@ms-cloudpack/package-utilities`\n * should use `createPackageDefinitions` from `@ms-cloudpack/config` instead. That wrapper adds\n * some transforms which are essential for applying settings from the cloudpack config.\n */\n constructor(options: PackageDefinitionsOptions = {}) {\n const { config, transformFactories } = options;\n this._transformFactories = transformFactories || [];\n\n this.reset({ newConfig: config, force: true });\n }\n\n async get(packagePath: string, options?: GetPackageDefinitionOptions): Promise<PackageJson> {\n const definition = await this.tryGet(packagePath, options);\n if (!definition) {\n throw new Error(`package.json not found at \"${packagePath}\"`);\n }\n return definition;\n }\n\n async tryGet(packagePath: string, options: GetPackageDefinitionOptions = {}): Promise<PackageJson | undefined> {\n const { refresh, disableTransforms, importerContext } = options;\n\n // Normalize the path used for caching to ensure consistency and avoid duplicates.\n const normalizedPath = slash(packagePath);\n\n if (refresh) {\n delete this._definitions[normalizedPath];\n delete this._transformedDefinitions[normalizedPath];\n }\n\n // If the definition is not in the cache, read it from disk (or from the fixture).\n // (If the definition was invalid JSON or not found, undefined is cached.)\n let definition = this._definitions[normalizedPath];\n if (!(normalizedPath in this._definitions)) {\n definition = await this._readPackage(normalizedPath);\n this._definitions[normalizedPath] = definition;\n\n if (definition) {\n definition.name ??= `unknown-${packagePath.replace(/[^\\w-]/g, '-')}`;\n definition.version ??= '0.0.0-unknown';\n }\n }\n\n if (disableTransforms || !definition) {\n return definition;\n }\n\n // If we don't want to skip the transform, transform the definition.\n let transformedDefinition = this._transformedDefinitions[normalizedPath];\n if (!transformedDefinition) {\n // Clone the definition (only keys we care about) so we don't accidentally modify the original.\n transformedDefinition = cloneJson(definition, { onlyKeys: copyPackageJsonKeys });\n\n for (const transform of this._transforms) {\n transformedDefinition =\n (await transform({\n definition: transformedDefinition,\n packagePath: normalizedPath,\n packages: this,\n importerContext,\n })) || transformedDefinition;\n }\n\n this._transformedDefinitions[normalizedPath] = transformedDefinition;\n }\n\n return transformedDefinition;\n }\n\n registerTransform(factory: PackageDefinitionTransformFactory): void {\n this._transformFactories.push(factory);\n this._transforms.push(factory(this._config));\n\n this.reset();\n }\n\n reset(options?: { newConfig?: CloudpackConfig; force?: boolean }): void {\n this._definitions = {};\n this._transformedDefinitions = {};\n\n const { newConfig, force } = options || {};\n\n if (newConfig || force) {\n this._config = newConfig;\n this._transforms = [...getDefaultTransforms(), ...this._transformFactories.map((factory) => factory(newConfig))];\n }\n }\n\n set(\n packagePath: string,\n definition: PackageJson,\n options?: Pick<GetPackageDefinitionOptions, 'disableTransforms'>,\n ): void {\n const { disableTransforms } = options || {};\n // Normalize the path used for caching to ensure consistency.\n const normalizedPath = slash(packagePath);\n // Delete the transformed definition if it exists, so we don't have stale data.\n if (disableTransforms) {\n delete this._transformedDefinitions[normalizedPath];\n }\n const record = disableTransforms ? this._definitions : this._transformedDefinitions;\n record[normalizedPath] = definition;\n }\n\n extend(input: SerializablePackageDefinitionsCache): void {\n Object.assign(this._definitions, input.definitions);\n Object.assign(this._transformedDefinitions, input.transformedDefinitions);\n }\n\n toSerializable(): SerializablePackageDefinitionsCache {\n return {\n definitions: this._definitions,\n transformedDefinitions: this._transformedDefinitions,\n };\n }\n\n protected async _readPackage(normalizedPath: string): Promise<PackageJson | undefined> {\n // `verbose` logs if the file exists but isn't valid JSON (or can't be read for some reason)\n return readJson<PackageJson>(path.join(normalizedPath, 'package.json'), { verbose: true });\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"PackageDefinitions.js","sourceRoot":"","sources":["../../src/packageDefinitions/PackageDefinitions.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AAUxB,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,EAAE,KAAK,EAAE,MAAM,mCAAmC,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAc3D;;;GAGG;AACH,MAAM,oBAAoB,GAAG,GAAG,EAAE,CAAC,CAAC,iBAAiB,EAAE,EAAE,qBAAqB,EAAE,CAAC,CAAC;AAElF;;;;;;GAMG;AACH,MAAM,mBAAmB,GAAuC;IAC9D,IAAI,EAAE,IAAI;IAC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QACD,MAAM,MAAM,GAAG,iBAAiB,CAAC,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,IAAI,CAAC,uBAAuB,CAAC;QACpF,MAAM,CAAC,cAAc,CAAC,GAAG,UAAU,CAAC;IACtC,CAAC;IAED,MAAM,CAAC,KAA0C;QAC/C,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,YAAY,EAAE,KAAK,CAAC,WAAW,CAAC,CAAC;QACpD,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,uBAAuB,EAAE,KAAK,CAAC,sBAAsB,CAAC,CAAC;IAC5E,CAAC;IAED,cAAc;QACZ,OAAO;YACL,WAAW,EAAE,IAAI,CAAC,YAAY;YAC9B,sBAAsB,EAAE,IAAI,CAAC,uBAAuB;SACrD,CAAC;IACJ,CAAC;IAES,KAAK,CAAC,YAAY,CAAC,cAAsB;QACjD,4FAA4F;QAC5F,OAAO,QAAQ,CAAc,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,cAAc,CAAC,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;IAC7F,CAAC;CACF","sourcesContent":["import path from 'path';\nimport type {\n CloudpackConfig,\n GetPackageDefinitionOptions,\n PackageDefinitionTransform,\n PackageDefinitionTransformFactory,\n PackageDefinitionsCache,\n PackageJson,\n SerializablePackageDefinitionsCache,\n} from '@ms-cloudpack/common-types';\nimport { cloneJson, readJson } from '@ms-cloudpack/json-utilities';\nimport { getNonSemverTransform } from './getNonSemverTransform.js';\nimport { slash } from '@ms-cloudpack/path-string-parsing';\nimport { getTypesTransform } from './getTypesTransform.js';\n\nexport interface PackageDefinitionsOptions {\n /**\n * Config object to pass to transforms. When `reset` is called with a new value, the transforms\n * will be transforms will be re-created using the new config.\n */\n config?: CloudpackConfig;\n /**\n * Transform factories to register on initialization.\n */\n transformFactories?: PackageDefinitionTransformFactory[];\n}\n\n/**\n * `nonSemverTransform` has state defined when the function is called, so we need a wrapper function\n * which returns new transforms to ensure that state is cleared when resetting.\n */\nconst getDefaultTransforms = () => [getTypesTransform(), getNonSemverTransform()];\n\n/**\n * Defines which keys from package.json are allowed to be cloned.\n * Keys with true values are cloned, keys with false values are not cloned.\n * (It's an object for better typings and faster access.)\n *\n * NOTE: If you add any new keys to PackageJson, they must be added here too.\n */\nconst copyPackageJsonKeys: Record<keyof PackageJson, boolean> = {\n name: true,\n version: true,\n description: true,\n dependencies: true,\n devDependencies: true,\n peerDependencies: true,\n peerDependenciesMeta: true,\n optionalDependencies: true,\n bundledDependencies: true,\n bundleDependencies: true,\n type: true,\n main: true,\n module: true,\n browser: true,\n exports: true,\n resolutions: true,\n cloudpack: true,\n\n /** Engines are used to check Node version compatibility between process and Cloudpack, not for packages bundled by Cloudpack */\n engines: false,\n};\n\nexport class PackageDefinitions implements PackageDefinitionsCache {\n private _definitions: Record<string, PackageJson | undefined> = {};\n private _transformedDefinitions: Record<string, PackageJson> = {};\n private _config: CloudpackConfig | undefined;\n private _transforms: PackageDefinitionTransform[] = [];\n private _transformFactories: PackageDefinitionTransformFactory[] = [];\n\n /**\n * **WARNING**: Cloudpack code (including tests) outside of `@ms-cloudpack/package-utilities`\n * should use `createPackageDefinitions` from `@ms-cloudpack/config` instead. That wrapper adds\n * some transforms which are essential for applying settings from the cloudpack config.\n */\n constructor(options: PackageDefinitionsOptions = {}) {\n const { config, transformFactories } = options;\n this._transformFactories = transformFactories || [];\n\n this.reset({ newConfig: config, force: true });\n }\n\n async get(packagePath: string, options?: GetPackageDefinitionOptions): Promise<PackageJson> {\n const definition = await this.tryGet(packagePath, options);\n if (!definition) {\n throw new Error(`package.json not found at \"${packagePath}\"`);\n }\n return definition;\n }\n\n async tryGet(packagePath: string, options: GetPackageDefinitionOptions = {}): Promise<PackageJson | undefined> {\n const { refresh, disableTransforms, importerContext } = options;\n\n // Normalize the path used for caching to ensure consistency and avoid duplicates.\n const normalizedPath = slash(packagePath);\n\n if (refresh) {\n delete this._definitions[normalizedPath];\n delete this._transformedDefinitions[normalizedPath];\n }\n\n // If the definition is not in the cache, read it from disk (or from the fixture).\n // (If the definition was invalid JSON or not found, undefined is cached.)\n let definition = this._definitions[normalizedPath];\n if (!(normalizedPath in this._definitions)) {\n definition = await this._readPackage(normalizedPath);\n this._definitions[normalizedPath] = definition;\n\n if (definition) {\n definition.name ??= `unknown-${packagePath.replace(/[^\\w-]/g, '-')}`;\n definition.version ??= '0.0.0-unknown';\n }\n }\n\n if (disableTransforms || !definition) {\n return definition;\n }\n\n // If we don't want to skip the transform, transform the definition.\n let transformedDefinition = this._transformedDefinitions[normalizedPath];\n if (!transformedDefinition) {\n // Clone the definition (only keys we care about) so we don't accidentally modify the original.\n transformedDefinition = cloneJson(definition, { keys: copyPackageJsonKeys });\n\n for (const transform of this._transforms) {\n transformedDefinition =\n (await transform({\n definition: transformedDefinition,\n packagePath: normalizedPath,\n packages: this,\n importerContext,\n })) || transformedDefinition;\n }\n\n this._transformedDefinitions[normalizedPath] = transformedDefinition;\n }\n\n return transformedDefinition;\n }\n\n registerTransform(factory: PackageDefinitionTransformFactory): void {\n this._transformFactories.push(factory);\n this._transforms.push(factory(this._config));\n\n this.reset();\n }\n\n reset(options?: { newConfig?: CloudpackConfig; force?: boolean }): void {\n this._definitions = {};\n this._transformedDefinitions = {};\n\n const { newConfig, force } = options || {};\n\n if (newConfig || force) {\n this._config = newConfig;\n this._transforms = [...getDefaultTransforms(), ...this._transformFactories.map((factory) => factory(newConfig))];\n }\n }\n\n set(\n packagePath: string,\n definition: PackageJson,\n options?: Pick<GetPackageDefinitionOptions, 'disableTransforms'>,\n ): void {\n const { disableTransforms } = options || {};\n // Normalize the path used for caching to ensure consistency.\n const normalizedPath = slash(packagePath);\n // Delete the transformed definition if it exists, so we don't have stale data.\n if (disableTransforms) {\n delete this._transformedDefinitions[normalizedPath];\n }\n const record = disableTransforms ? this._definitions : this._transformedDefinitions;\n record[normalizedPath] = definition;\n }\n\n extend(input: SerializablePackageDefinitionsCache): void {\n Object.assign(this._definitions, input.definitions);\n Object.assign(this._transformedDefinitions, input.transformedDefinitions);\n }\n\n toSerializable(): SerializablePackageDefinitionsCache {\n return {\n definitions: this._definitions,\n transformedDefinitions: this._transformedDefinitions,\n };\n }\n\n protected async _readPackage(normalizedPath: string): Promise<PackageJson | undefined> {\n // `verbose` logs if the file exists but isn't valid JSON (or can't be read for some reason)\n return readJson<PackageJson>(path.join(normalizedPath, 'package.json'), { verbose: true });\n }\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { PackageDefinitionsCache, PackageJson, ResolveMapEntry } from '@ms-cloudpack/common-types';
|
|
2
|
-
import type { PackageMap } from '
|
|
2
|
+
import type { PackageMap } from '../types/PackageMap.js';
|
|
3
3
|
/**
|
|
4
4
|
* Given a linkedEntry, iterates through dependencies to ensure they are added to the packageMap,
|
|
5
5
|
* preferring packageMap dependencies over linkedMap dependencies.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"addLinkedEntryDependencies.d.ts","sourceRoot":"","sources":["../../../../src/resolveMap/createHelpers/link/addLinkedEntryDependencies.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAExG,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAGzD;;;;GAIG;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,GACA,OAAO,CAAC;IAAE,UAAU,EAAE,MAAM,EAAE,CAAA;CAAE,CAAC,CA8FnC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { satisfies } from 'semver';
|
|
2
|
-
import { getDependencies } from '
|
|
2
|
+
import { getDependencies } from '../../../packageJson/getDependencies.js';
|
|
3
3
|
/**
|
|
4
4
|
* Given a linkedEntry, iterates through dependencies to ensure they are added to the packageMap,
|
|
5
5
|
* preferring packageMap dependencies over linkedMap dependencies.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"addLinkedEntryDependencies.js","sourceRoot":"","sources":["../../../../src/resolveMap/createHelpers/link/addLinkedEntryDependencies.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAEnC,OAAO,EAAE,eAAe,EAAE,MAAM,yCAAyC,CAAC;AAE1E;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,0BAA0B,CAC9C,OAKC,EACD,OAEC;IAED,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC;IAC9D,MAAM,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC;IAC7B,MAAM,iBAAiB,GAAG,IAAI,GAAG,CAAS,WAAW,CAAC,IAAI,CAAC,CAAC;IAC5D,MAAM,UAAU,GAAa,EAAE,CAAC;IAChC,MAAM,cAAc,GAAsB,CAAC,WAAW,CAAC,CAAC;IAExD,SAAS,OAAO,CAAC,QAAyB;QACxC,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;YAC1C,iBAAiB,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;YACrC,cAAc,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAChC,CAAC;IACH,CAAC;IAED,OAAO,cAAc,CAAC,MAAM,EAAE,CAAC;QAC7B,kGAAkG;QAClG,MAAM,KAAK,GAAG,cAAc,CAAC,GAAG,EAAG,CAAC;QAEpC,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,YAAY,EAAE,GAAG,KAAK,CAAC;QA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H,CAAC;IAED,OAAO,EAAE,UAAU,EAAE,CAAC;AACxB,CAAC","sourcesContent":["import type { PackageDefinitionsCache, PackageJson, ResolveMapEntry } from '@ms-cloudpack/common-types';\nimport { satisfies } from 'semver';\nimport type { PackageMap } from '../types/PackageMap.js';\nimport { getDependencies } from '../../../packageJson/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 * Returns a list of duplicated packages that were added to the packageMap.\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): Promise<{ duplicates: string[] }> {\n const { appMap, linkMap, linkedEntry, resolutions } = options;\n const { packages } = context;\n const visitedEntryPaths = new Set<string>(linkedEntry.path);\n const duplicates: string[] = [];\n const entriesToVisit: ResolveMapEntry[] = [linkedEntry];\n\n function enqueue(newEntry: ResolveMapEntry): void {\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.tryGet(entry.path);\n if (!linkDefinition) {\n continue;\n }\n\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 duplicates.push(`${dependencyName}@${dependencyEntry.version}`);\n // Recursive through the dependency's dependencies.\n enqueue(dependencyEntry);\n }\n }\n }\n }\n }\n\n return { duplicates };\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convertToLinkResolveMap.d.ts","sourceRoot":"","sources":["../../../../src/resolveMap/createHelpers/link/convertToLinkResolveMap.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAE7D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEzD;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE;IAAE,MAAM,EAAE,UAAU,CAAA;CAAE,GAAG,UAAU,CAoBnF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convertToLinkResolveMap.js","sourceRoot":"","sources":["../../../../src/resolveMap/createHelpers/link/convertToLinkResolveMap.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGhD;;GAEG;AACH,MAAM,UAAU,uBAAuB,CAAC,OAA+B;IACrE,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;IAC3B,MAAM,UAAU,GAAe,EAAE,CAAC;IAElC,KAAK,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QACnE,MAAM,oBAAoB,GAAG,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QAE7E,wFAAwF;QACxF,2EAA2E;QAC3E,IAAI,oBAAoB,CAAC,MAAM,EAAE,CAAC;YAChC,MAAM,KAAK,GAAG,CAAC,UAAU,CAAC,WAAW,CAAC,GAAG,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAC;YAElE,wDAAwD;YACxD,IAAI,oBAAoB,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBACpC,KAAK,CAAC,cAAc,GAAG,MAAM,CAAC,WAAW,CAAC,oBAAoB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;YACtG,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,UAAU,CAAC;AACpB,CAAC","sourcesContent":["import type { ResolveMap } from '@ms-cloudpack/common-types';\nimport { entrySorter } from '../entrySorter.js';\nimport type { PackageMap } from '../types/PackageMap.js';\n\n/**\n * Given a PackageMap returns a ResolveMap.\n */\nexport function convertToLinkResolveMap(options: { appMap: PackageMap }): ResolveMap {\n const { appMap } = options;\n const resolveMap: ResolveMap = {};\n\n for (const [packageName, packageEntries] of Object.entries(appMap)) {\n const sortedPackageEntries = Object.values(packageEntries).sort(entrySorter);\n\n // Get the sorted package entries based on the most to least requiredBy references. This\n // ends up reducing the size of the resolve map by minimizing scoped cases.\n if (sortedPackageEntries.length) {\n const entry = (resolveMap[packageName] = sortedPackageEntries[0]);\n\n // Update scoped versions (version to resolve map entry)\n if (sortedPackageEntries.length > 1) {\n entry.scopedVersions = Object.fromEntries(sortedPackageEntries.slice(1).map((e) => [e.version, e]));\n }\n }\n }\n\n return resolveMap;\n}\n"]}
|
package/lib/resolveMap/createHelpers/{dedupeLinkedPackages.d.ts → link/dedupeLinkedPackages.d.ts}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { PackageMap } from '
|
|
1
|
+
import type { PackageMap } from '../types/PackageMap.js';
|
|
2
2
|
import type { PackageDefinitionsCache } from '@ms-cloudpack/common-types';
|
|
3
3
|
/**
|
|
4
4
|
* Deduplicates linked packages by removing all but the highest version,
|
|
@@ -7,7 +7,7 @@ import type { PackageDefinitionsCache } from '@ms-cloudpack/common-types';
|
|
|
7
7
|
export declare function dedupeLinkedPackages(options: {
|
|
8
8
|
appMap: PackageMap;
|
|
9
9
|
allDuplicates: Set<string>;
|
|
10
|
-
|
|
10
|
+
linkMap: PackageMap;
|
|
11
11
|
rootPath?: string;
|
|
12
12
|
}, context: {
|
|
13
13
|
packages: PackageDefinitionsCache;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dedupeLinkedPackages.d.ts","sourceRoot":"","sources":["../../../../src/resolveMap/createHelpers/link/dedupeLinkedPackages.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAGzD,OAAO,KAAK,EAAE,uBAAuB,EAAgC,MAAM,4BAA4B,CAAC;AAKxG;;;GAGG;AACH,wBAAsB,oBAAoB,CACxC,OAAO,EAAE;IAAE,MAAM,EAAE,UAAU,CAAC;IAAC,aAAa,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAAC,OAAO,EAAE,UAAU,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAE,EACnG,OAAO,EAAE;IAAE,QAAQ,EAAE,uBAAuB,CAAA;CAAE,GAC7C,OAAO,CAAC,IAAI,CAAC,CA4Gf"}
|
package/lib/resolveMap/createHelpers/{dedupeLinkedPackages.js → link/dedupeLinkedPackages.js}
RENAMED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { satisfies, rcompare as semverReverseCompare } from 'semver';
|
|
2
|
-
import { parseRequiredBy } from '
|
|
2
|
+
import { parseRequiredBy } from '../parseRequiredBy.js';
|
|
3
3
|
import { detachEntry } from './detachEntry.js';
|
|
4
4
|
import { slash } from '@ms-cloudpack/path-string-parsing';
|
|
5
5
|
/**
|
|
@@ -7,7 +7,7 @@ import { slash } from '@ms-cloudpack/path-string-parsing';
|
|
|
7
7
|
* that satisfies the semver requirements of all the requiredBy entries.
|
|
8
8
|
*/
|
|
9
9
|
export async function dedupeLinkedPackages(options, context) {
|
|
10
|
-
const { rootPath, appMap, allDuplicates,
|
|
10
|
+
const { rootPath, appMap, allDuplicates, linkMap } = options;
|
|
11
11
|
const { packages } = context;
|
|
12
12
|
console.debug(`The following packages were duplicated by linking:\n ${Array.from(allDuplicates).join(', ')}`);
|
|
13
13
|
for (const duplicate of allDuplicates) {
|
|
@@ -53,22 +53,18 @@ export async function dedupeLinkedPackages(options, context) {
|
|
|
53
53
|
// We assume that the host has a single version of the package.
|
|
54
54
|
const hostVersion = availableVersions.find((v) => slash(entries[v].path).startsWith(slash(rootPath)));
|
|
55
55
|
if (!hostVersion) {
|
|
56
|
-
console.error(`Could not find a version of "${packageName}" that
|
|
56
|
+
console.error(`Could not find a version of "${packageName}" that belongs to the host.`);
|
|
57
57
|
continue;
|
|
58
58
|
}
|
|
59
59
|
satisfiedVersion = hostVersion;
|
|
60
60
|
}
|
|
61
61
|
else if (dedupeStrategy === 'force-remote-version') {
|
|
62
|
-
if (!remotePath) {
|
|
63
|
-
console.error('Root path for project not found and is required when using the "force-remote-version" dedupe strategy.');
|
|
64
|
-
continue;
|
|
65
|
-
}
|
|
66
62
|
// Use the version of the package that is the remote.
|
|
67
63
|
// Find the version of the package that does not belong to the host.
|
|
68
64
|
// We assume that the remote has a single version of the package.
|
|
69
|
-
const remoteVersion = availableVersions.find((v) =>
|
|
65
|
+
const remoteVersion = availableVersions.find((v) => entries[v].path === linkMap[packageName]?.[v]?.path);
|
|
70
66
|
if (!remoteVersion) {
|
|
71
|
-
console.error(`Could not find a version of "${packageName}" that
|
|
67
|
+
console.error(`Could not find a version of "${packageName}" that belongs to the remote.`);
|
|
72
68
|
continue;
|
|
73
69
|
}
|
|
74
70
|
satisfiedVersion = remoteVersion;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dedupeLinkedPackages.js","sourceRoot":"","sources":["../../../../src/resolveMap/createHelpers/link/dedupeLinkedPackages.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,IAAI,oBAAoB,EAAE,MAAM,QAAQ,CAAC;AAErE,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,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,OAAmG,EACnG,OAA8C;IAE9C,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,aAAa,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;IAC7D,MAAM,EAAE,QAAQ,EAAE,GAAG,O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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, rcompare as semverReverseCompare } from 'semver';\nimport type { PackageMap } from '../types/PackageMap.js';\nimport { parseRequiredBy } from '../parseRequiredBy.js';\nimport { detachEntry } from './detachEntry.js';\nimport type { PackageDefinitionsCache, ResolveMapEntry, LinkOptions } from '@ms-cloudpack/common-types';\nimport { slash } from '@ms-cloudpack/path-string-parsing';\n\ntype DuplicatedDependencyBehavior = NonNullable<LinkOptions['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>; linkMap: PackageMap; rootPath?: string },\n context: { packages: PackageDefinitionsCache },\n): Promise<void> {\n const { rootPath, appMap, allDuplicates, linkMap } = 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 // Find the versions that satisfy the semver requirements of all the requiredBy entries.\n // Sort the versions in descending order.\n const satisfiedVersions = availableVersions\n .filter((v) => [...versionRequirements].every((range) => satisfies(v, range)))\n .sort(semverReverseCompare);\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 belongs to the host.`);\n continue;\n }\n\n satisfiedVersion = hostVersion;\n } else if (dedupeStrategy === 'force-remote-version') {\n // Use the version of the package that is the remote.\n // Find the version of the package that does not belong to the host.\n // We assume that the remote has a single version of the package.\n const remoteVersion = availableVersions.find((v) => entries[v].path === linkMap[packageName]?.[v]?.path);\n\n if (!remoteVersion) {\n console.error(`Could not find a version of \"${packageName}\" that belongs to the remote.`);\n continue;\n }\n\n satisfiedVersion = remoteVersion;\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 satisfiedVersion = satisfiedVersions[0];\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"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"detachEntry.d.ts","sourceRoot":"","sources":["../../../../src/resolveMap/createHelpers/link/detachEntry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAClE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAGzD;;GAEG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE;IAAE,MAAM,EAAE,UAAU,CAAC;IAAC,KAAK,EAAE,eAAe,CAAA;CAAE,GAAG,IAAI,CAmCzF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"detachEntry.js","sourceRoot":"","sources":["../../../../src/resolveMap/createHelpers/link/detachEntry.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAExD;;GAEG;AACH,MAAM,UAAU,WAAW,CAAC,OAAuD;IACjF,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;IAC3B,MAAM,oBAAoB,GAAsB,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAEhE,OAAO,oBAAoB,CAAC,MAAM,EAAE,CAAC;QACnC,8FAA8F;QAC9F,MAAM,KAAK,GAAG,oBAAoB,CAAC,GAAG,EAAG,CAAC;QAC1C,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,UAAU,EAAE,GAAG,KAAK,CAAC;QAE5C,IAAI,KAAK,CAAC,QAAQ,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC;YAC/C,SAAS;QACX,CAAC;QAED,uCAAuC;QACvC,KAAK,MAAM,cAAc,IAAI,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC;YACrD,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,aAAa,EAAE,GAAG,eAAe,CAAC,cAAc,CAAC,CAAC;YACrF,MAAM,WAAW,GAAG,MAAM,CAAC,UAAU,CAAC,EAAE,CAAC,aAAa,CAAC,CAAC;YAExD,IAAI,WAAW,EAAE,CAAC;gBAChB,OAAO,WAAW,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;YACxC,CAAC;QACH,CAAC;QAED,0CAA0C;QAC1C,KAAK,MAAM,CAAC,cAAc,EAAE,iBAAiB,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,YAAY,CAAC,EAAE,CAAC;YACrF,MAAM,eAAe,GAAG,MAAM,CAAC,cAAc,CAAC,EAAE,CAAC,iBAAiB,CAAC,CAAC;YAEpE,IAAI,eAAe,EAAE,CAAC;gBACpB,OAAO,eAAe,CAAC,UAAU,CAAC,GAAG,IAAI,IAAI,OAAO,EAAE,CAAC,CAAC;gBACxD,IAAI,MAAM,CAAC,IAAI,CAAC,eAAe,CAAC,UAAU,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;oBACzD,oBAAoB,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;gBAC7C,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["import type { ResolveMapEntry } from '@ms-cloudpack/common-types';\nimport type { PackageMap } from '../types/PackageMap.js';\nimport { parseRequiredBy } from '../parseRequiredBy.js';\n\n/**\n * Removes requiredBy references for an entry being removed.\n */\nexport function detachEntry(options: { appMap: PackageMap; entry: ResolveMapEntry }): void {\n const { appMap } = options;\n const dependenciesToDetach: ResolveMapEntry[] = [options.entry];\n\n while (dependenciesToDetach.length) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- already checked length\n const entry = dependenciesToDetach.pop()!;\n const { name, version, requiredBy } = entry;\n\n if (entry.isLinked || !appMap[name]?.[version]) {\n continue;\n }\n\n // Disconnect the entry from consumers.\n for (const requiredByName of Object.keys(requiredBy)) {\n const { name: parentName, version: parentVersion } = parseRequiredBy(requiredByName);\n const parentEntry = appMap[parentName]?.[parentVersion];\n\n if (parentEntry) {\n delete parentEntry.dependencies[name];\n }\n }\n\n // Disconnect dependencies from the entry.\n for (const [dependencyName, dependencyVersion] of Object.entries(entry.dependencies)) {\n const dependencyEntry = appMap[dependencyName]?.[dependencyVersion];\n\n if (dependencyEntry) {\n delete dependencyEntry.requiredBy[`${name}@${version}`];\n if (Object.keys(dependencyEntry.requiredBy).length === 0) {\n dependenciesToDetach.push(dependencyEntry);\n }\n }\n }\n }\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ResolveMap } from '@ms-cloudpack/common-types';
|
|
2
|
-
import type { PackageMap } from '
|
|
2
|
+
import type { PackageMap } from '../types/PackageMap.js';
|
|
3
3
|
/**
|
|
4
4
|
* Flatten a ResolveMap into a PackageMap.
|
|
5
5
|
* This is useful for converting a ResolveMap into a format that can be easily consumed by other parts of the system.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flattenResolveMap.d.ts","sourceRoot":"","sources":["../../../../src/resolveMap/createHelpers/link/flattenResolveMap.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEzD;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE;IAAE,UAAU,EAAE,UAAU,CAAA;CAAE,GAAG,UAAU,CAqBjF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flattenResolveMap.js","sourceRoot":"","sources":["../../../../src/resolveMap/createHelpers/link/flattenResolveMap.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,MAAM,UAAU,iBAAiB,CAAC,OAAmC;IACnE,MAAM,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC;IAC/B,MAAM,UAAU,GAAe,EAAE,CAAC;IAElC,KAAK,MAAM,CAAC,WAAW,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;QAC9D,mDAAmD;QACnD,UAAU,CAAC,WAAW,CAAC,KAAK,EAAE,CAAC;QAE/B,qBAAqB;QACrB,MAAM,EAAE,cAAc,EAAE,GAAG,0BAA0B,EAAE,GAAG,KAAK,CAAC;QAEhE,gEAAgE;QAChE,UAAU,CAAC,WAAW,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,0BAA0B,EAAE,CAAC;QAE3E,0BAA0B;QAC1B,KAAK,MAAM,CAAC,OAAO,EAAE,WAAW,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,cAAc,IAAI,EAAE,CAAC,EAAE,CAAC;YAC1E,UAAU,CAAC,WAAW,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,WAAW,EAAE,CAAC;QACxD,CAAC;IACH,CAAC;IAED,OAAO,UAAU,CAAC;AACpB,CAAC","sourcesContent":["import type { ResolveMap } from '@ms-cloudpack/common-types';\nimport type { PackageMap } from '../types/PackageMap.js';\n\n/**\n * Flatten a ResolveMap into a PackageMap.\n * This is useful for converting a ResolveMap into a format that can be easily consumed by other parts of the system.\n * The main entry is added to the package map, and any scoped versions are added as well.\n */\nexport function flattenResolveMap(options: { resolveMap: ResolveMap }): PackageMap {\n const { resolveMap } = options;\n const packageMap: PackageMap = {};\n\n for (const [packageName, entry] of Object.entries(resolveMap)) {\n // Initialize the package entry if it doesn't exist\n packageMap[packageName] ??= {};\n\n // Add the main entry\n const { scopedVersions, ...entryWithoutScopedVersions } = entry;\n\n // Remove scopedVersions from the main entry to avoid redundancy\n packageMap[packageName][entry.version] = { ...entryWithoutScopedVersions };\n\n // Add any scoped versions\n for (const [version, scopedEntry] of Object.entries(scopedVersions || {})) {\n packageMap[packageName][version] = { ...scopedEntry };\n }\n }\n\n return packageMap;\n}\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { LinkedPath, PackageJson } from '@ms-cloudpack/common-types';
|
|
2
|
+
/**
|
|
3
|
+
* Compute the effective resolutions to apply based on ignoreResolutions setting.
|
|
4
|
+
* - ignoreResolutions === true -> ignore all host resolutions (return undefined)
|
|
5
|
+
* - ignoreResolutions is string[] -> ignore only those package entries
|
|
6
|
+
* - otherwise apply all host resolutions
|
|
7
|
+
*/
|
|
8
|
+
export declare function getEffectiveResolutions(appRepoDefinition: PackageJson | undefined, ignoreResolutions: LinkedPath['ignoreResolutions']): PackageJson['resolutions'] | undefined;
|
|
9
|
+
//# sourceMappingURL=getEffectiveResolutions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getEffectiveResolutions.d.ts","sourceRoot":"","sources":["../../../../src/resolveMap/createHelpers/link/getEffectiveResolutions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAE1E;;;;;GAKG;AACH,wBAAgB,uBAAuB,CACrC,iBAAiB,EAAE,WAAW,GAAG,SAAS,EAC1C,iBAAiB,EAAE,UAAU,CAAC,mBAAmB,CAAC,GACjD,WAAW,CAAC,aAAa,CAAC,GAAG,SAAS,CAgBxC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compute the effective resolutions to apply based on ignoreResolutions setting.
|
|
3
|
+
* - ignoreResolutions === true -> ignore all host resolutions (return undefined)
|
|
4
|
+
* - ignoreResolutions is string[] -> ignore only those package entries
|
|
5
|
+
* - otherwise apply all host resolutions
|
|
6
|
+
*/
|
|
7
|
+
export function getEffectiveResolutions(appRepoDefinition, ignoreResolutions) {
|
|
8
|
+
if (!appRepoDefinition?.resolutions)
|
|
9
|
+
return undefined;
|
|
10
|
+
const hostResolutions = appRepoDefinition.resolutions;
|
|
11
|
+
if (ignoreResolutions === true) {
|
|
12
|
+
return undefined;
|
|
13
|
+
}
|
|
14
|
+
if (Array.isArray(ignoreResolutions) && ignoreResolutions.length) {
|
|
15
|
+
const filtered = Object.fromEntries(Object.entries(hostResolutions).filter(([pkgName]) => !ignoreResolutions.includes(pkgName)));
|
|
16
|
+
return Object.keys(filtered).length ? filtered : undefined;
|
|
17
|
+
}
|
|
18
|
+
return hostResolutions;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=getEffectiveResolutions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getEffectiveResolutions.js","sourceRoot":"","sources":["../../../../src/resolveMap/createHelpers/link/getEffectiveResolutions.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,MAAM,UAAU,uBAAuB,CACrC,iBAA0C,EAC1C,iBAAkD;IAElD,IAAI,CAAC,iBAAiB,EAAE,WAAW;QAAE,OAAO,SAAS,CAAC;IACtD,MAAM,eAAe,GAAG,iBAAiB,CAAC,WAAW,CAAC;IAEtD,IAAI,iBAAiB,KAAK,IAAI,EAAE,CAAC;QAC/B,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,IAAI,KAAK,CAAC,OAAO,CAAC,iBAAiB,CAAC,IAAI,iBAAiB,CAAC,MAAM,EAAE,CAAC;QACjE,MAAM,QAAQ,GAAG,MAAM,CAAC,WAAW,CACjC,MAAM,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE,EAAE,CAAC,CAAC,iBAAiB,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAC5F,CAAC;QACF,OAAO,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC,CAAE,QAAmC,CAAC,CAAC,CAAC,SAAS,CAAC;IACzF,CAAC;IAED,OAAO,eAAe,CAAC;AACzB,CAAC","sourcesContent":["import type { LinkedPath, PackageJson } from '@ms-cloudpack/common-types';\n\n/**\n * Compute the effective resolutions to apply based on ignoreResolutions setting.\n * - ignoreResolutions === true -> ignore all host resolutions (return undefined)\n * - ignoreResolutions is string[] -> ignore only those package entries\n * - otherwise apply all host resolutions\n */\nexport function getEffectiveResolutions(\n appRepoDefinition: PackageJson | undefined,\n ignoreResolutions: LinkedPath['ignoreResolutions'],\n): PackageJson['resolutions'] | undefined {\n if (!appRepoDefinition?.resolutions) return undefined;\n const hostResolutions = appRepoDefinition.resolutions;\n\n if (ignoreResolutions === true) {\n return undefined;\n }\n\n if (Array.isArray(ignoreResolutions) && ignoreResolutions.length) {\n const filtered = Object.fromEntries(\n Object.entries(hostResolutions).filter(([pkgName]) => !ignoreResolutions.includes(pkgName)),\n );\n return Object.keys(filtered).length ? (filtered as typeof hostResolutions) : undefined;\n }\n\n return hostResolutions;\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { PackageMap } from '
|
|
1
|
+
import type { PackageMap } from '../types/PackageMap.js';
|
|
2
2
|
import type { LinkedPath, PackageDefinitionsCache, PackageJson } from '@ms-cloudpack/common-types';
|
|
3
3
|
/**
|
|
4
4
|
* Find packages from `linkedPath` and add them to the `appMap`.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"linkPath.d.ts","sourceRoot":"","sources":["../../../../src/resolveMap/createHelpers/link/linkPath.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAMzD,OAAO,KAAK,EAAE,UAAU,EAAmB,uBAAuB,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAMpH;;GAEG;AACH,wBAAsB,QAAQ,CAC5B,OAAO,EAAE;IACP,UAAU,EAAE,UAAU,CAAC;IACvB,MAAM,EAAE,UAAU,CAAC;IACnB,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,iBAAiB,EAAE,WAAW,GAAG,SAAS,CAAC;CAC5C,EACD,OAAO,EAAE;IACP,QAAQ,EAAE,uBAAuB,CAAC;CACnC,GACA,OAAO,CAAC,IAAI,CAAC,CA8Gf"}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { addLinkedEntryDependencies } from './addLinkedEntryDependencies.js';
|
|
2
2
|
import { detachEntry } from './detachEntry.js';
|
|
3
|
-
import { findPackagesFromPath } from '
|
|
4
|
-
import { parseRequiredBy } from '
|
|
3
|
+
import { findPackagesFromPath } from '../findPackagesFromPath.js';
|
|
4
|
+
import { parseRequiredBy } from '../parseRequiredBy.js';
|
|
5
5
|
import { slash } from '@ms-cloudpack/path-string-parsing';
|
|
6
6
|
import { dedupeLinkedPackages } from './dedupeLinkedPackages.js';
|
|
7
7
|
import { findProjectRoot } from '@ms-cloudpack/path-utilities';
|
|
8
8
|
import { flattenResolveMap } from './flattenResolveMap.js';
|
|
9
|
+
import { getEffectiveResolutions } from './getEffectiveResolutions.js';
|
|
9
10
|
/**
|
|
10
11
|
* Find packages from `linkedPath` and add them to the `appMap`.
|
|
11
12
|
*/
|
|
@@ -21,7 +22,7 @@ export async function linkPath(options, context) {
|
|
|
21
22
|
}, context);
|
|
22
23
|
const entriesToLink = [];
|
|
23
24
|
const { path, ignoredPackages = [], includeAll } = linkedPath;
|
|
24
|
-
const resolutions = linkedPath.ignoreResolutions
|
|
25
|
+
const resolutions = getEffectiveResolutions(appRepoDefinition, linkedPath.ignoreResolutions);
|
|
25
26
|
// Iterate through the linkMap, looking for internal packages to link to the appMap.
|
|
26
27
|
for (const [packageName, packageVersions] of Object.entries(linkMap)) {
|
|
27
28
|
const appEntries = Object.values(appMap[packageName] || {});
|
|
@@ -88,7 +89,7 @@ export async function linkPath(options, context) {
|
|
|
88
89
|
allDuplicates.push(...duplicates);
|
|
89
90
|
}
|
|
90
91
|
if (linkedPath.resolveStrategy !== 'duplicate') {
|
|
91
|
-
await dedupeLinkedPackages({ appMap, allDuplicates: new Set(allDuplicates), rootPath: appRootPath,
|
|
92
|
+
await dedupeLinkedPackages({ appMap, allDuplicates: new Set(allDuplicates), rootPath: appRootPath, linkMap }, context);
|
|
92
93
|
}
|
|
93
94
|
}
|
|
94
95
|
function isContainedInPath(path, basePath) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"linkPath.js","sourceRoot":"","sources":["../../../../src/resolveMap/createHelpers/link/linkPath.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,0BAA0B,EAAE,MAAM,iCAAiC,CAAC;AAC7E,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAClE,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,KAAK,EAAE,MAAM,mCAAmC,CAAC;AAE1D,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AAEvE;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,QAAQ,CAC5B,OAKC,EACD,OAEC;IAED,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,WAAW,EAAE,iBAAiB,EAAE,GAAG,OAAO,CAAC;IAEvE,MAAM,cAAc,GAAG,UAAU,CAAC,QAAQ,IAAI,eAAe,CAAC,UAAU,CAAC,IAAI,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC;IAExG,MAAM,OAAO,GAAG,UAAU,EAAE,MAAM;QAChC,CAAC,CAAC,iBAAiB,CAAC,EAAE,UAAU,EAAE,UAAU,CAAC,MAAM,CAAC,UAAU,EAAE,C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AE,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 { PackageMap } from '../types/PackageMap.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 { LinkedPath, ResolveMapEntry, PackageDefinitionsCache, PackageJson } from '@ms-cloudpack/common-types';\nimport { dedupeLinkedPackages } from './dedupeLinkedPackages.js';\nimport { findProjectRoot } from '@ms-cloudpack/path-utilities';\nimport { flattenResolveMap } from './flattenResolveMap.js';\nimport { getEffectiveResolutions } from './getEffectiveResolutions.js';\n\n/**\n * Find packages from `linkedPath` and add them to the `appMap`.\n */\nexport async function linkPath(\n options: {\n linkedPath: LinkedPath;\n appMap: PackageMap;\n appRootPath: string | undefined;\n appRepoDefinition: PackageJson | undefined;\n },\n context: {\n packages: PackageDefinitionsCache;\n },\n): Promise<void> {\n const { linkedPath, appMap, appRootPath, appRepoDefinition } = options;\n\n const linkedRootPath = linkedPath.rootPath || findProjectRoot(linkedPath.path, { noPackageRoot: true });\n\n const linkMap = linkedPath?.remote\n ? flattenResolveMap({ resolveMap: linkedPath.remote.resolveMap })\n : await findPackagesFromPath(\n {\n searchPaths: [linkedPath.path],\n discoverPackages: true,\n rootPath: linkedRootPath,\n },\n context,\n );\n const entriesToLink: ResolveMapEntry[] = [];\n const { path, ignoredPackages = [], includeAll } = linkedPath;\n const resolutions = getEffectiveResolutions(appRepoDefinition, linkedPath.ignoreResolutions);\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(\n { appMap, allDuplicates: new Set(allDuplicates), rootPath: appRootPath, linkMap },\n context,\n );\n }\n}\n\nfunction isContainedInPath(path: string, basePath: string): boolean {\n path = normalizePath(path);\n basePath = normalizePath(basePath);\n\n return path.startsWith(basePath);\n}\n\nfunction normalizePath(path: string): string {\n let normalizedPath = slash(path);\n\n if (!normalizedPath.endsWith('/')) {\n normalizedPath += '/';\n }\n\n return normalizedPath;\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { findProjectRoot } from '@ms-cloudpack/path-utilities';
|
|
2
2
|
import { findPackagesFromPath } from './createHelpers/findPackagesFromPath.js';
|
|
3
|
-
import { convertToLinkResolveMap } from './createHelpers/convertToLinkResolveMap.js';
|
|
3
|
+
import { convertToLinkResolveMap } from './createHelpers/link/convertToLinkResolveMap.js';
|
|
4
4
|
/**
|
|
5
5
|
* Create a link resolve map for a given `appPath`.
|
|
6
6
|
* 1. Discover through the dependency tree to build a map of all packages and their dependencies.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createLinkResolveMap.js","sourceRoot":"","sources":["../../src/resolveMap/createLinkResolveMap.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,EAAE,oBAAoB,EAAE,MAAM,yCAAyC,CAAC;AAC/E,OAAO,EAAE,uBAAuB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"createLinkResolveMap.js","sourceRoot":"","sources":["../../src/resolveMap/createLinkResolveMap.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,EAAE,oBAAoB,EAAE,MAAM,yCAAyC,CAAC;AAC/E,OAAO,EAAE,uBAAuB,EAAE,MAAM,iDAAiD,CAAC;AAE1F;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,OAYC,EACD,OAEC;IAED,MAAM,EAAE,OAAO,EAAE,eAAe,GAAG,EAAE,EAAE,GAAG,OAAO,CAAC;IAElD,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,eAAe,CAAC,OAAO,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC;IAEvF,kDAAkD;IAClD,MAAM,MAAM,GAAG,MAAM,oBAAoB,CACvC;QACE,WAAW,EAAE,CAAC,OAAO,EAAE,GAAG,eAAe,CAAC;QAC1C,gBAAgB,EAAE,IAAI;QACtB,QAAQ;KACT,EACD,OAAO,CACR,CAAC;IAEF,OAAO,uBAAuB,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;AAC7C,CAAC","sourcesContent":["import type { PackageDefinitionsCache, ResolveMap } from '@ms-cloudpack/common-types';\nimport { findProjectRoot } from '@ms-cloudpack/path-utilities';\nimport { findPackagesFromPath } from './createHelpers/findPackagesFromPath.js';\nimport { convertToLinkResolveMap } from './createHelpers/link/convertToLinkResolveMap.js';\n\n/**\n * Create a link resolve map for a given `appPath`.\n * 1. Discover through the dependency tree to build a map of all packages and their dependencies.\n * 2. 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 createLinkResolveMap(\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 /**\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 context: {\n packages: PackageDefinitionsCache;\n },\n): Promise<ResolveMap> {\n const { appPath, additionalPaths = [] } = options;\n\n const rootPath = options.rootPath || findProjectRoot(appPath, { noPackageRoot: true });\n\n // First we discover the dependencies for the app.\n const appMap = await findPackagesFromPath(\n {\n searchPaths: [appPath, ...additionalPaths],\n discoverPackages: true,\n rootPath,\n },\n context,\n );\n\n return convertToLinkResolveMap({ appMap });\n}\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { findProjectRoot } from '@ms-cloudpack/path-utilities';
|
|
2
2
|
import { convertToResolveMap } from './createHelpers/convertToResolveMap.js';
|
|
3
3
|
import { findPackagesFromPath } from './createHelpers/findPackagesFromPath.js';
|
|
4
|
-
import { linkPath } from './createHelpers/linkPath.js';
|
|
4
|
+
import { linkPath } from './createHelpers/link/linkPath.js';
|
|
5
5
|
/**
|
|
6
6
|
* Create a resolve map for a given `appPath`.
|
|
7
7
|
* 1. Walk the dependency tree to build a map of all packages and their dependencies.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createResolveMap.js","sourceRoot":"","sources":["../../src/resolveMap/createResolveMap.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,EAAE,mBAAmB,EAAE,MAAM,wCAAwC,CAAC;AAC7E,OAAO,EAAE,oBAAoB,EAAE,MAAM,yCAAyC,CAAC;AAC/E,OAAO,EAAE,QAAQ,EAAE,MAAM,
|
|
1
|
+
{"version":3,"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M,EAAE,iBAAiB,EAAE,cAAc,EAAE,EAAE,OAAO,CAAC,CAAC;IAC5G,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, PackageDefinitionsCache, ResolveMap } from '@ms-cloudpack/common-types';\nimport { findProjectRoot } from '@ms-cloudpack/path-utilities';\nimport { convertToResolveMap } from './createHelpers/convertToResolveMap.js';\nimport { findPackagesFromPath } from './createHelpers/findPackagesFromPath.js';\nimport { linkPath } from './createHelpers/link/linkPath.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 /**\n * Skip the actual resolution of dependencies. The returned resolve map will only contain\n * the package(s) from the given path(s). Not compatible with `linkedPaths`.\n */\n skipResolveDependencies?: boolean;\n },\n context: {\n packages: PackageDefinitionsCache;\n },\n): Promise<ResolveMap> {\n const { appPath, additionalPaths = [], linkedPaths = [], skipResolveDependencies } = options;\n\n if (skipResolveDependencies && linkedPaths.length) {\n throw new Error('Cannot use `linkedPaths` with `skipResolveDependencies`');\n }\n\n // rootPath is only used as the place to stop searching up for dependencies, so we can skip the\n // calculation if we're not resolving dependencies.\n const rootPath = skipResolveDependencies\n ? undefined\n : options.rootPath || findProjectRoot(appPath, { noPackageRoot: true });\n\n const repoDefinition = rootPath ? await context.packages.tryGet(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 skipResolveDependencies,\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, appRootPath: rootPath, appMap, appRepoDefinition: repoDefinition }, context);\n }\n\n // Finally we condense into a resolve map.\n return convertToResolveMap({ appMap, rootPaths: [appPath, ...additionalPaths] });\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ms-cloudpack/package-utilities",
|
|
3
|
-
"version": "12.
|
|
3
|
+
"version": "12.5.0",
|
|
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.27.
|
|
18
|
-
"@ms-cloudpack/json-utilities": "^0.1.
|
|
17
|
+
"@ms-cloudpack/common-types": "^0.27.6",
|
|
18
|
+
"@ms-cloudpack/json-utilities": "^0.1.11",
|
|
19
19
|
"@ms-cloudpack/path-string-parsing": "^1.2.7",
|
|
20
|
-
"@ms-cloudpack/path-utilities": "^3.1.
|
|
21
|
-
"@ms-cloudpack/task-reporter": "^0.17.
|
|
20
|
+
"@ms-cloudpack/path-utilities": "^3.1.21",
|
|
21
|
+
"@ms-cloudpack/task-reporter": "^0.17.3",
|
|
22
22
|
"acorn": "^8.11.2",
|
|
23
23
|
"acorn-walk": "^8.2.1",
|
|
24
24
|
"semver": "^7.6.0",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"addLinkedEntryDependencies.d.ts","sourceRoot":"","sources":["../../../src/resolveMap/createHelpers/addLinkedEntryDependencies.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAExG,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAGxD;;;;GAIG;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,GACA,OAAO,CAAC;IAAE,UAAU,EAAE,MAAM,EAAE,CAAA;CAAE,CAAC,CA8FnC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"addLinkedEntryDependencies.js","sourceRoot":"","sources":["../../../src/resolveMap/createHelpers/addLinkedEntryDependencies.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAEnC,OAAO,EAAE,eAAe,EAAE,MAAM,sCAAsC,CAAC;AAEvE;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,0BAA0B,CAC9C,OAKC,EACD,OAEC;IAED,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC;IAC9D,MAAM,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC;IAC7B,MAAM,iBAAiB,GAAG,IAAI,GAAG,CAAS,WAAW,CAAC,IAAI,CAAC,CAAC;IAC5D,MAAM,UAAU,GAAa,EAAE,CAAC;IAChC,MAAM,cAAc,GAAsB,CAAC,WAAW,CAAC,CAAC;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e,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,UAAU,CAAC,IAAI,CAAC,GAAG,cAAc,IAAI,eAAe,CAAC,OAAO,EAAE,CAAC,CAAC;wBAChE,mDAAmD;wBACnD,OAAO,CAAC,eAAe,CAAC,CAAC;oBAC3B,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,EAAE,UAAU,EAAE,CAAC;AACxB,CAAC","sourcesContent":["import type { PackageDefinitionsCache, PackageJson, ResolveMapEntry } from '@ms-cloudpack/common-types';\nimport { satisfies } from 'semver';\nimport type { PackageMap } from './types/PackageMap.js';\nimport { getDependencies } from '../../packageJson/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 * Returns a list of duplicated packages that were added to the packageMap.\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): Promise<{ duplicates: string[] }> {\n const { appMap, linkMap, linkedEntry, resolutions } = options;\n const { packages } = context;\n const visitedEntryPaths = new Set<string>(linkedEntry.path);\n const duplicates: string[] = [];\n const entriesToVisit: ResolveMapEntry[] = [linkedEntry];\n\n function enqueue(newEntry: ResolveMapEntry): void {\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.tryGet(entry.path);\n if (!linkDefinition) {\n continue;\n }\n\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 duplicates.push(`${dependencyName}@${dependencyEntry.version}`);\n // Recursive through the dependency's dependencies.\n enqueue(dependencyEntry);\n }\n }\n }\n }\n }\n\n return { duplicates };\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"convertToLinkResolveMap.d.ts","sourceRoot":"","sources":["../../../src/resolveMap/createHelpers/convertToLinkResolveMap.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAE7D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAExD;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE;IAAE,MAAM,EAAE,UAAU,CAAA;CAAE,GAAG,UAAU,CAoBnF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"convertToLinkResolveMap.js","sourceRoot":"","sources":["../../../src/resolveMap/createHelpers/convertToLinkResolveMap.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAG/C;;GAEG;AACH,MAAM,UAAU,uBAAuB,CAAC,OAA+B;IACrE,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;IAC3B,MAAM,UAAU,GAAe,EAAE,CAAC;IAElC,KAAK,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QACnE,MAAM,oBAAoB,GAAG,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QAE7E,wFAAwF;QACxF,2EAA2E;QAC3E,IAAI,oBAAoB,CAAC,MAAM,EAAE,CAAC;YAChC,MAAM,KAAK,GAAG,CAAC,UAAU,CAAC,WAAW,CAAC,GAAG,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAC;YAElE,wDAAwD;YACxD,IAAI,oBAAoB,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBACpC,KAAK,CAAC,cAAc,GAAG,MAAM,CAAC,WAAW,CAAC,oBAAoB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;YACtG,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,UAAU,CAAC;AACpB,CAAC","sourcesContent":["import type { ResolveMap } from '@ms-cloudpack/common-types';\nimport { entrySorter } from './entrySorter.js';\nimport type { PackageMap } from './types/PackageMap.js';\n\n/**\n * Given a PackageMap returns a ResolveMap.\n */\nexport function convertToLinkResolveMap(options: { appMap: PackageMap }): ResolveMap {\n const { appMap } = options;\n const resolveMap: ResolveMap = {};\n\n for (const [packageName, packageEntries] of Object.entries(appMap)) {\n const sortedPackageEntries = Object.values(packageEntries).sort(entrySorter);\n\n // Get the sorted package entries based on the most to least requiredBy references. This\n // ends up reducing the size of the resolve map by minimizing scoped cases.\n if (sortedPackageEntries.length) {\n const entry = (resolveMap[packageName] = sortedPackageEntries[0]);\n\n // Update scoped versions (version to resolve map entry)\n if (sortedPackageEntries.length > 1) {\n entry.scopedVersions = Object.fromEntries(sortedPackageEntries.slice(1).map((e) => [e.version, e]));\n }\n }\n }\n\n return resolveMap;\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"dedupeLinkedPackages.d.ts","sourceRoot":"","sources":["../../../src/resolveMap/createHelpers/dedupeLinkedPackages.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAGxD,OAAO,KAAK,EAAE,uBAAuB,EAAgC,MAAM,4BAA4B,CAAC;AAKxG;;;GAGG;AACH,wBAAsB,oBAAoB,CACxC,OAAO,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,IAAI,iBAAiB,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAClF,mGAAmG;YACnG,gBAAgB,GAAG,iBAAiB,CAAC,CAAC,CAAC,CAAC;YACxC,OAAO,CAAC,KAAK,CACX,YAAY,gBAAgB,SAAS,WAAW,oEAAoE,CACrH,CAAC;QACJ,CAAC;aAAM,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, rcompare as semverReverseCompare } from 'semver';\nimport type { PackageMap } from './types/PackageMap.js';\nimport { parseRequiredBy } from './parseRequiredBy.js';\nimport { detachEntry } from './detachEntry.js';\nimport type { PackageDefinitionsCache, ResolveMapEntry, LinkOptions } from '@ms-cloudpack/common-types';\nimport { slash } from '@ms-cloudpack/path-string-parsing';\n\ntype DuplicatedDependencyBehavior = NonNullable<LinkOptions['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>; remotePath?: string; rootPath?: string },\n context: { packages: PackageDefinitionsCache },\n): Promise<void> {\n const { rootPath, appMap, allDuplicates, remotePath } = 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 // Find the versions that satisfy the semver requirements of all the requiredBy entries.\n // Sort the versions in descending order.\n const satisfiedVersions = availableVersions\n .filter((v) => [...versionRequirements].every((range) => satisfies(v, range)))\n .sort(semverReverseCompare);\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 === 'force-remote-version') {\n if (!remotePath) {\n console.error(\n 'Root path for project not found and is required when using the \"force-remote-version\" dedupe strategy.',\n );\n continue;\n }\n\n // Use the version of the package that is the remote.\n // Find the version of the package that does not belong to the host.\n // We assume that the remote has a single version of the package.\n const remoteVersion = availableVersions.find((v) => slash(entries[v].path).startsWith(slash(remotePath)));\n\n if (!remoteVersion) {\n console.error(`Could not find a version of \"${packageName}\" that is belongs to the remote.`);\n continue;\n }\n\n satisfiedVersion = remoteVersion;\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 satisfiedVersion = satisfiedVersions[0];\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"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"detachEntry.d.ts","sourceRoot":"","sources":["../../../src/resolveMap/createHelpers/detachEntry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAClE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAGxD;;GAEG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE;IAAE,MAAM,EAAE,UAAU,CAAC;IAAC,KAAK,EAAE,eAAe,CAAA;CAAE,GAAG,IAAI,CAmCzF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"detachEntry.js","sourceRoot":"","sources":["../../../src/resolveMap/createHelpers/detachEntry.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD;;GAEG;AACH,MAAM,UAAU,WAAW,CAAC,OAAuD;IACjF,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;IAC3B,MAAM,oBAAoB,GAAsB,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAEhE,OAAO,oBAAoB,CAAC,MAAM,EAAE,CAAC;QACnC,8FAA8F;QAC9F,MAAM,KAAK,GAAG,oBAAoB,CAAC,GAAG,EAAG,CAAC;QAC1C,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,UAAU,EAAE,GAAG,KAAK,CAAC;QAE5C,IAAI,KAAK,CAAC,QAAQ,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC;YAC/C,SAAS;QACX,CAAC;QAED,uCAAuC;QACvC,KAAK,MAAM,cAAc,IAAI,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC;YACrD,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,aAAa,EAAE,GAAG,eAAe,CAAC,cAAc,CAAC,CAAC;YACrF,MAAM,WAAW,GAAG,MAAM,CAAC,UAAU,CAAC,EAAE,CAAC,aAAa,CAAC,CAAC;YAExD,IAAI,WAAW,EAAE,CAAC;gBAChB,OAAO,WAAW,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;YACxC,CAAC;QACH,CAAC;QAED,0CAA0C;QAC1C,KAAK,MAAM,CAAC,cAAc,EAAE,iBAAiB,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,YAAY,CAAC,EAAE,CAAC;YACrF,MAAM,eAAe,GAAG,MAAM,CAAC,cAAc,CAAC,EAAE,CAAC,iBAAiB,CAAC,CAAC;YAEpE,IAAI,eAAe,EAAE,CAAC;gBACpB,OAAO,eAAe,CAAC,UAAU,CAAC,GAAG,IAAI,IAAI,OAAO,EAAE,CAAC,CAAC;gBACxD,IAAI,MAAM,CAAC,IAAI,CAAC,eAAe,CAAC,UAAU,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;oBACzD,oBAAoB,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;gBAC7C,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["import type { ResolveMapEntry } from '@ms-cloudpack/common-types';\nimport type { PackageMap } from './types/PackageMap.js';\nimport { parseRequiredBy } from './parseRequiredBy.js';\n\n/**\n * Removes requiredBy references for an entry being removed.\n */\nexport function detachEntry(options: { appMap: PackageMap; entry: ResolveMapEntry }): void {\n const { appMap } = options;\n const dependenciesToDetach: ResolveMapEntry[] = [options.entry];\n\n while (dependenciesToDetach.length) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- already checked length\n const entry = dependenciesToDetach.pop()!;\n const { name, version, requiredBy } = entry;\n\n if (entry.isLinked || !appMap[name]?.[version]) {\n continue;\n }\n\n // Disconnect the entry from consumers.\n for (const requiredByName of Object.keys(requiredBy)) {\n const { name: parentName, version: parentVersion } = parseRequiredBy(requiredByName);\n const parentEntry = appMap[parentName]?.[parentVersion];\n\n if (parentEntry) {\n delete parentEntry.dependencies[name];\n }\n }\n\n // Disconnect dependencies from the entry.\n for (const [dependencyName, dependencyVersion] of Object.entries(entry.dependencies)) {\n const dependencyEntry = appMap[dependencyName]?.[dependencyVersion];\n\n if (dependencyEntry) {\n delete dependencyEntry.requiredBy[`${name}@${version}`];\n if (Object.keys(dependencyEntry.requiredBy).length === 0) {\n dependenciesToDetach.push(dependencyEntry);\n }\n }\n }\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"flattenResolveMap.d.ts","sourceRoot":"","sources":["../../../src/resolveMap/createHelpers/flattenResolveMap.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAExD;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE;IAAE,UAAU,EAAE,UAAU,CAAA;CAAE,GAAG,UAAU,CAqBjF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"flattenResolveMap.js","sourceRoot":"","sources":["../../../src/resolveMap/createHelpers/flattenResolveMap.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,MAAM,UAAU,iBAAiB,CAAC,OAAmC;IACnE,MAAM,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC;IAC/B,MAAM,UAAU,GAAe,EAAE,CAAC;IAElC,KAAK,MAAM,CAAC,WAAW,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;QAC9D,mDAAmD;QACnD,UAAU,CAAC,WAAW,CAAC,KAAK,EAAE,CAAC;QAE/B,qBAAqB;QACrB,MAAM,EAAE,cAAc,EAAE,GAAG,0BAA0B,EAAE,GAAG,KAAK,CAAC;QAEhE,gEAAgE;QAChE,UAAU,CAAC,WAAW,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,0BAA0B,EAAE,CAAC;QAE3E,0BAA0B;QAC1B,KAAK,MAAM,CAAC,OAAO,EAAE,WAAW,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,cAAc,IAAI,EAAE,CAAC,EAAE,CAAC;YAC1E,UAAU,CAAC,WAAW,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,WAAW,EAAE,CAAC;QACxD,CAAC;IACH,CAAC;IAED,OAAO,UAAU,CAAC;AACpB,CAAC","sourcesContent":["import type { ResolveMap } from '@ms-cloudpack/common-types';\nimport type { PackageMap } from './types/PackageMap.js';\n\n/**\n * Flatten a ResolveMap into a PackageMap.\n * This is useful for converting a ResolveMap into a format that can be easily consumed by other parts of the system.\n * The main entry is added to the package map, and any scoped versions are added as well.\n */\nexport function flattenResolveMap(options: { resolveMap: ResolveMap }): PackageMap {\n const { resolveMap } = options;\n const packageMap: PackageMap = {};\n\n for (const [packageName, entry] of Object.entries(resolveMap)) {\n // Initialize the package entry if it doesn't exist\n packageMap[packageName] ??= {};\n\n // Add the main entry\n const { scopedVersions, ...entryWithoutScopedVersions } = entry;\n\n // Remove scopedVersions from the main entry to avoid redundancy\n packageMap[packageName][entry.version] = { ...entryWithoutScopedVersions };\n\n // Add any scoped versions\n for (const [version, scopedEntry] of Object.entries(scopedVersions || {})) {\n packageMap[packageName][version] = { ...scopedEntry };\n }\n }\n\n return packageMap;\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"linkPath.d.ts","sourceRoot":"","sources":["../../../src/resolveMap/createHelpers/linkPath.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAMxD,OAAO,KAAK,EAAE,UAAU,EAAmB,uBAAuB,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAKpH;;GAEG;AACH,wBAAsB,QAAQ,CAC5B,OAAO,EAAE;IACP,UAAU,EAA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AY,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 { PackageMap } from './types/PackageMap.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 { LinkedPath, ResolveMapEntry, PackageDefinitionsCache, PackageJson } from '@ms-cloudpack/common-types';\nimport { dedupeLinkedPackages } from './dedupeLinkedPackages.js';\nimport { findProjectRoot } from '@ms-cloudpack/path-utilities';\nimport { flattenResolveMap } from './flattenResolveMap.js';\n\n/**\n * Find packages from `linkedPath` and add them to the `appMap`.\n */\nexport async function linkPath(\n options: {\n linkedPath: LinkedPath;\n appMap: PackageMap;\n appRootPath: string | undefined;\n appRepoDefinition: PackageJson | undefined;\n },\n context: {\n packages: PackageDefinitionsCache;\n },\n): Promise<void> {\n const { linkedPath, appMap, appRootPath, appRepoDefinition } = options;\n\n const linkedRootPath = linkedPath.rootPath || findProjectRoot(linkedPath.path, { noPackageRoot: true });\n\n const linkMap = linkedPath?.remote\n ? flattenResolveMap({ resolveMap: linkedPath.remote.resolveMap })\n : await findPackagesFromPath(\n {\n searchPaths: [linkedPath.path],\n discoverPackages: true,\n rootPath: linkedRootPath,\n },\n context,\n );\n const entriesToLink: ResolveMapEntry[] = [];\n const { path, ignoredPackages = [], includeAll } = linkedPath;\n const resolutions = linkedPath.ignoreResolutions ? undefined : appRepoDefinition?.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(\n { appMap, allDuplicates: new Set(allDuplicates), rootPath: appRootPath, remotePath: linkedPath.path },\n context,\n );\n }\n}\n\nfunction isContainedInPath(path: string, basePath: string): boolean {\n path = normalizePath(path);\n basePath = normalizePath(basePath);\n\n return path.startsWith(basePath);\n}\n\nfunction normalizePath(path: string): string {\n let normalizedPath = slash(path);\n\n if (!normalizedPath.endsWith('/')) {\n normalizedPath += '/';\n }\n\n return normalizedPath;\n}\n"]}
|
|
File without changes
|