@ms-cloudpack/package-utilities 12.4.0 → 12.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAC1E,OAAO,IAAI,MAAM,MAAM,CAAC;AAOxB;;;GAGG;AACH,MAAM,UAAU,qBAAqB,CAAC,MAA2D;IAC/F,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,WAAW,EAAE,GAAG,MAAM,CAAC;IAE3C,MAAM,WAAW,GAAG,GAAG,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;IACxC,MAAM,aAAa,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;IAC5C,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,WAAW,KAAK,CAAC,CAAC,IAAI,aAAa,KAAK,CAAC,CAAC,CAAC,CAAC;QAAE,OAAO,EAAE,CAAC;IAE7G,MAAM,UAAU,GAAG,WAAW,CAAC,KAAK,EAAE,aAAa,CAAC,CAAC;IACrD,MAAM,QAAQ,GAAG,WAAW,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC;IAC/C,MAAM,UAAU,GAAG,WAAW,CAAC,KAAK,EAAE,aAAa,CAAC,CAAC;IACrD,IAAI,CAAC,UAAU,IAAI,CAAC,QAAQ,IAAI,CAAC,UAAU;QAAE,OAAO,EAAE,CAAC;IAEvD,MAAM,UAAU,GAAG,QAAQ,CAAC,UAAU,EAAE,EAAE,GAAG,EAAE,WAAW,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,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C,EAAE,CAAC;QACxB,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC;IACnC,CAAC;SAAM,IAAI,aAAa,KAAK,CAAC,CAAC,EAAE,CAAC;QAChC,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,SAAS,CAAC,CAAC,EAAE,aAAa,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,IAAI,CAAC,UAAU,IAAI,OAAO,UAAU,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC;QAAE,OAAO,UAAU,CAAC;IAElG,MAAM,KAAK,GAA6B,EAAE,CAAC;IAE3C,KAAK,MAAM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AM,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;AAe/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
+ {"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 { normalizeRelativePath } from '@ms-cloudpack/path-string-parsing';
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
- // Check for wildcards in the key and value.
132
- // The wildcards
133
- const keyWildcard = key.indexOf('*', 1);
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,EAAE;IAEN,MAAM,EAAE,kBAAkB,EAAE,WAAW,EAAE,UAAU,EAAE,aAAa,GAAG,kBAAkB,EAAE,GAAG,OAAO,CAAC;IAEpG,MAAM,UAAU,GACd,aAAa,KAAK,kBAAkB;QAClC,CAAC,CAAC,eAAe;QACjB,CAAC,CAAC,aAAa,KAAK,eAAe;YACjC,CAAC,CAAC,YAAY;YACd,CAAC,CAAC,kBAAkB,CAAC,aAAa,EAAE,eAAe,CAAC,CAAC;IAE3D,IAAI,OAAO,UAAU,KAAK,QAAQ,IAAI,UAAU,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC;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I,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QACxB,OAAO,KAAK,GAAG,MAAM,CAAC;IACxB,CAAC;SAAM,IAAI,aAAa,KAAK,CAAC,CAAC,EAAE,CAAC;QAChC,OAAO,KAAK,CAAC,SAAS,CAAC,CAAC,EAAE,aAAa,CAAC,GAAG,MAAM,GAAG,KAAK,CAAC,SAAS,CAAC,aAAa,GAAG,CAAC,CAAC,CAAC;IACzF,CAAC;AACH,CAAC;AAED;;;;;;GAMG;AACH,SAAS,WAAW,CAClB,KAAa,EACb,gBAAwB,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;IAE7C,IAAI,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QACxB,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC;IACnC,CAAC;SAAM,IAAI,aAAa,KAAK,CAAC,CAAC,EAAE,CAAC;QAChC,OAAO;YACL,KAAK,EAAE,KAAK,CAAC,SAAS,CAAC,CAAC,EAAE,aAAa,CAAC;YACxC,GAAG,EAAE,KAAK,CAAC,SAAS,CAAC,aAAa,GAAG,CAAC,CAAC;SACxC,CAAC;IACJ,CAAC;AACH,CAAC;AAED,SAAS,UAAU,CAAC,SAAiB;IACnC,IAAI,IAAI,CAAC,OAAO,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":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AACrE,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAEnE,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,EAA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C,KAAK,CAAC,4BAA4B,WAAW,CAAC,CAAC,CAAC,IAAI,WAAW,IAAI,CAAC,CAAC,CAAC,EAAE,iBAAiB,GAAG,OAAO,KAAK,GAAG,CAAC,CAAC;IAErH,2GAA2G;IAC3G,IAAI,CAAC,WAAW;QAAE,OAAO;IAEzB,KAAK,MAAM,CAAC,IAAI,qBAAqB,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,WAAW,EAAE,CAAC,EAAE,CAAC;QACnE,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC;YACxB,WAAW,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;QAC3C,CAAC;IACH,CAAC;AACH,CAAC;AAED,SAAS,UAAU,CAAC,SAAiB;IACnC,IAAI,IAAI,CAAC,OAAO,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 { 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';
@@ -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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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,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AACpE,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,eAAe,EAAE,MAAM,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,EAE3B,iCAAiC,EACjC,uBAAuB,EACvB,WAAW,EACX,mCAAmC,EACpC,MAAM,4BAA4B,CAAC;AAMpC,MAAM,WAAW,yBAAyB;IACxC;;;OAGG;IACH,MAAM,CAAC,EAAE,eAAe,CAAC;IACzB;;OAEG;IACH,kBAAkB,CAAC,EAAE,iCAAiC,EAAE,CAAC;CAC1D;AAkCD,qBAAa,kBAAmB,YAAW,uBAAuB;IAChE,OAAO,CAAC,YAAY,CAA+C;IACnE,OAAO,CAAC,uBAAuB,CAAmC;IAClE,OAAO,CAAC,OAAO,CAA8B;IAC7C,OAAO,CAAC,WAAW,CAAoC;IACvD,OAAO,CAAC,mBAAmB,CAA2C;IAEtE;;;;OAIG;gBACS,OAAO,GAAE,yBAA8B;IAO7C,GAAG,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,2BAA2B,GAAG,OAAO,CAAC,WAAW,CAAC;IAQrF,MAAM,CAA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C,EAAE,2BAA2B,GAAG,OAAO,CAAC,WAAW,CAAC;IAQrF,MAAM,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,GAAE,2BAAgC,GAAG,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC;IAkD9G,iBAAiB,CAAC,OAAO,EAAE,iCAAiC,GAAG,IAAI;IAOnE,KAAK,CAAC,OAAO,CAAC,EAAE;QAAE,SAAS,CAAC,EAAE,eAAe,CAAC;QAAC,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,IAAI;IAYvE,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
- * Only copy these keys from package.json, to reduce the amount cloned before applying transforms.
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, { onlyKeys: copyPackageJsonKeys });
88
+ transformedDefinition = cloneJson(definition, { keys: copyPackageJsonKeys });
86
89
  for (const transform of this._transforms) {
87
90
  transformedDefinition =
88
91
  (await transform({
@@ -1 +1 @@
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;;;;;GAKG;AACH,MAAM,mBAAmB,GAAoC;IAC3D,IAAI,EAAE,IAAI;IACV,OAAO,EAAE,IAAI;IACb,WAAW,EAAE,IAAI;IACjB,YAAY,EAAE,IAAI;IAClB,eAAe,EAAE,IAAI;IACrB,gBAAgB,EAAE,IAAI;IACtB,oBAAoB,EAAE,IAAI;IAC1B,oBAAoB,EAAE,IAAI;IAC1B,mBAAmB,EAAE,IAAI;IACzB,kBAAkB,EAAE,IAAI;IACxB,IAAI,EAAE,IAAI;IACV,IAAI,EAAE,IAAI;IACV,MAAM,EAAE,IAAI;IACZ,OAAO,EAAE,IAAI;IACb,OAAO,EAAE,IAAI;IACb,WAAW,EAAE,IAAI;IACjB,SAAS,EAAE,IAAI;CAChB,CAAC;AAEF,MAAM,OAAO,kBAAkB;IACrB,YAAY,GAA4C,EAAE,CAAC;IAC3D,uBAAuB,GAAgC,EAAE,CAAC;IAC1D,OAAO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;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 * 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,wBAA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AAC;QAC5C,6DAA6D;QAC7D,MAAM,cAAc,GAAG,KAAK,CAAC,WAAW,CAAC,CAAC;QAC1C,+EAA+E;QAC/E,IAAI,iBAAiB,EAAE,CAAC;YACtB,OAAO,IAAI,CAAC,uBAAuB,CAAC,cAAc,CAAC,CAAC;QACtD,CAAC;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"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ms-cloudpack/package-utilities",
3
- "version": "12.4.0",
3
+ "version": "12.5.1",
4
4
  "description": "Utilities for resolving/parsing packages and their imports.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -14,11 +14,11 @@
14
14
  }
15
15
  },
16
16
  "dependencies": {
17
- "@ms-cloudpack/common-types": "^0.27.5",
18
- "@ms-cloudpack/json-utilities": "^0.1.10",
17
+ "@ms-cloudpack/common-types": "^0.27.7",
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.20",
21
- "@ms-cloudpack/task-reporter": "^0.17.3",
20
+ "@ms-cloudpack/path-utilities": "^3.1.22",
21
+ "@ms-cloudpack/task-reporter": "^0.17.4",
22
22
  "acorn": "^8.11.2",
23
23
  "acorn-walk": "^8.2.1",
24
24
  "semver": "^7.6.0",