@ms-cloudpack/package-utilities 7.2.0 → 7.3.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/findFileInPackage.d.ts.map +1 -1
- package/lib/findFileInPackage.js +26 -4
- package/lib/findFileInPackage.js.map +1 -1
- package/lib/flattenExportsMap.d.ts +10 -0
- package/lib/flattenExportsMap.d.ts.map +1 -1
- package/lib/flattenExportsMap.js +143 -15
- package/lib/flattenExportsMap.js.map +1 -1
- package/lib/getSourceEntry.d.ts.map +1 -1
- package/lib/getSourceEntry.js +6 -2
- package/lib/getSourceEntry.js.map +1 -1
- package/package.json +4 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"findFileInPackage.d.ts","sourceRoot":"","sources":["../src/findFileInPackage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,uBAAuB,EAAE,MAAM,4BAA4B,CAAC;AAY3F,MAAM,MAAM,wBAAwB,GAAG;IACrC,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG;IACpC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF;;;;;;;;;GASG;AACH,wBAAsB,iBAAiB,CACrC,OAAO,EAAE,wBAAwB,EACjC,OAAO,EAAE;IAAE,QAAQ,EAAE,uBAAuB,CAAC;IAAC,MAAM,EAAE,eAAe,CAAA;CAAE,GACtE,OAAO,CAAC,uBAAuB,CAAC,
|
|
1
|
+
{"version":3,"file":"findFileInPackage.d.ts","sourceRoot":"","sources":["../src/findFileInPackage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,uBAAuB,EAAE,MAAM,4BAA4B,CAAC;AAY3F,MAAM,MAAM,wBAAwB,GAAG;IACrC,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG;IACpC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF;;;;;;;;;GASG;AACH,wBAAsB,iBAAiB,CACrC,OAAO,EAAE,wBAAwB,EACjC,OAAO,EAAE;IAAE,QAAQ,EAAE,uBAAuB,CAAC;IAAC,MAAM,EAAE,eAAe,CAAA;CAAE,GACtE,OAAO,CAAC,uBAAuB,CAAC,CA2GlC"}
|
package/lib/findFileInPackage.js
CHANGED
|
@@ -24,10 +24,27 @@ export async function findFileInPackage(options, context) {
|
|
|
24
24
|
let sourcePath;
|
|
25
25
|
let typesPath;
|
|
26
26
|
const isInternal = !isExternalPackage(packagePath);
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
//
|
|
30
|
-
|
|
27
|
+
const pathsToConsider = [originalPath];
|
|
28
|
+
const definition = await context.packages.get(packagePath, { disableTransforms: true });
|
|
29
|
+
// If the original package.json has an exports map, we should not use main and module as hints.
|
|
30
|
+
if (originalPath === '.' && definition && !definition.exports) {
|
|
31
|
+
const { main, module } = definition;
|
|
32
|
+
if (main) {
|
|
33
|
+
pathsToConsider.unshift(main);
|
|
34
|
+
}
|
|
35
|
+
if (module) {
|
|
36
|
+
pathsToConsider.unshift(module);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
for (const currentPath of pathsToConsider) {
|
|
40
|
+
const candidates = await getCandidates({ filePath: currentPath, packagePath }, context);
|
|
41
|
+
// Try and resolve a physical file given the candidates.
|
|
42
|
+
// eslint-disable-next-line @ms-cloudpack/internal/no-sync-filesystem
|
|
43
|
+
filePath = candidates.find((candidate) => isFileSync(path.join(packagePath, candidate)));
|
|
44
|
+
if (filePath) {
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
31
48
|
const isNestedPackageDefinition = filePath && path.basename(filePath) === 'package.json' && path.basename(originalPath) !== 'package.json';
|
|
32
49
|
const result = {};
|
|
33
50
|
if (isNestedPackageDefinition) {
|
|
@@ -44,6 +61,11 @@ export async function findFileInPackage(options, context) {
|
|
|
44
61
|
typesPath: typesPath && normalizeRelativePath(path.relative(packagePath, path.join(nestedDefinitionPath, typesPath))),
|
|
45
62
|
};
|
|
46
63
|
}
|
|
64
|
+
else {
|
|
65
|
+
// If we can't find an entry, we should not include this in the exports map.
|
|
66
|
+
// This avoids adding a "./package.json" value to a "." entry.
|
|
67
|
+
return result;
|
|
68
|
+
}
|
|
47
69
|
}
|
|
48
70
|
// If the resolved file is a typescript file in an internal package, try to resolve the intermediate.
|
|
49
71
|
if (filePath && sourceExtensions.includes(path.extname(filePath))) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"findFileInPackage.js","sourceRoot":"","sources":["../src/findFileInPackage.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,KAAK,EAAE,MAAM,mCAAmC,CAAC;AACjF,OAAO,EAAE,wBAAwB,EAAE,UAAU,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AAC9G,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAE3D,MAAM,gBAAgB,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AACjE,MAAM,oBAAoB,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AAarD;;;;;;;;;GASG;AACH,MA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C,CAAC,CAAC,SAAS,CAAC;IACzE,CAAC;IAED,gFAAgF;IAChF,IAAI,UAAU,IAAI,QAAQ,IAAI,CAAC,UAAU,EAAE,CAAC;QAC1C,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QACnC,MAAM,eAAe,GAAG,oBAAoB,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;QAE3D,IAAI,eAAe,EAAE,CAAC;YACpB,wDAAwD;YACxD,UAAU,GAAG,wBAAwB,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC;YAE7D,mDAAmD;YACnD,IAAI,UAAU,KAAK,QAAQ,EAAE,CAAC;gBAC5B,UAAU,GAAG,SAAS,CAAC;YACzB,CAAC;QACH,CAAC;IACH,CAAC;IAED,+BAA+B;IAC/B,IAAI,UAAU,IAAI,QAAQ,EAAE,CAAC;QAC3B,SAAS,GAAG,QAAQ,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QAE/C,qEAAqE;QACrE,IAAI,CAAC,UAAU,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,SAAS,CAAC,CAAC,EAAE,CAAC;YAClE,SAAS,GAAG,SAAS,CAAC;QACxB,CAAC;IACH,CAAC;IAED,IAAI,SAAS,EAAE,CAAC;QACd,MAAM,CAAC,SAAS,GAAG,qBAAqB,CAAC,SAAS,CAAC,CAAC;IACtD,CAAC;IAED,IAAI,QAAQ,EAAE,CAAC;QACb,MAAM,CAAC,QAAQ,GAAG,qBAAqB,CAAC,QAAQ,CAAC,CAAC;IACpD,CAAC;IAED,IAAI,UAAU,EAAE,CAAC;QACf,MAAM,CAAC,UAAU,GAAG,qBAAqB,CAAC,UAAU,CAAC,CAAC;IACxD,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import type { CloudpackConfig, PackageDefinitionsCache } from '@ms-cloudpack/common-types';\nimport { normalizeRelativePath, slash } from '@ms-cloudpack/path-string-parsing';\nimport { intermediateToSourcePath, isFileSync, sourceToIntermediatePath } from '@ms-cloudpack/path-utilities';\nimport path from 'path';\nimport { flattenExportsMap } from './flattenExportsMap.js';\nimport { getCandidates } from './getCandidates.js';\nimport { getExportsMap } from './getExportsMap.js';\nimport { isExternalPackage } from './isExternalPackage.js';\n\nconst sourceExtensions = ['.ts', '.tsx', '.cts', '.mts', '.jsx'];\nconst javascriptExtensions = ['.js', '.mjs', '.cjs'];\n\nexport type FindFileInPackageOptions = {\n packagePath: string;\n filePath: string;\n};\n\nexport type FindFileInPackageResult = {\n filePath?: string;\n typesPath?: string;\n sourcePath?: string;\n};\n\n/**\n * Given a requested partial filePath, resolves the relative intermediate path if the file exists, with special\n * consideration for internal packages, which may not have intermediate files but only source files. Paths returned\n * are always relative and start with `./`.\n *\n * This helper is used in deriving if the given package.json entries are actual validate candidates when constructing an\n * exports map from existing metadata. For example, a package.json may list `main` as `lib/index.js`. If this file\n * exists, or in internal packages, if `src/index.tsx` exists, then this is a valid candidate. If the file does not\n * exist, then we should not include it in the exports map.\n */\nexport async function findFileInPackage(\n options: FindFileInPackageOptions,\n context: { packages: PackageDefinitionsCache; config: CloudpackConfig },\n): Promise<FindFileInPackageResult> {\n const originalPath = normalizeRelativePath(options.filePath);\n const packagePath = slash(options.packagePath);\n let filePath: string | undefined;\n let sourcePath: string | undefined;\n let typesPath: string | undefined;\n const isInternal = !isExternalPackage(packagePath);\n const pathsToConsider = [originalPath];\n\n const definition = await context.packages.get(packagePath, { disableTransforms: true });\n // If the original package.json has an exports map, we should not use main and module as hints.\n if (originalPath === '.' && definition && !definition.exports) {\n const { main, module } = definition;\n if (main) {\n pathsToConsider.unshift(main);\n }\n if (module) {\n pathsToConsider.unshift(module);\n }\n }\n\n for (const currentPath of pathsToConsider) {\n const candidates = await getCandidates({ filePath: currentPath, packagePath }, context);\n\n // Try and resolve a physical file given the candidates.\n // eslint-disable-next-line @ms-cloudpack/internal/no-sync-filesystem\n filePath = candidates.find((candidate) => isFileSync(path.join(packagePath, candidate)));\n if (filePath) {\n break;\n }\n }\n\n const isNestedPackageDefinition =\n filePath && path.basename(filePath) === 'package.json' && path.basename(originalPath) !== 'package.json';\n const result: FindFileInPackageResult = {};\n\n if (isNestedPackageDefinition) {\n const nestedDefinitionPath = path.dirname(path.join(packagePath, filePath as string));\n const exportsMap = await getExportsMap({ packagePath: nestedDefinitionPath }, context);\n const entryPath = flattenExportsMap(exportsMap)['.'];\n\n if (entryPath) {\n typesPath = flattenExportsMap(exportsMap, { conditions: ['types'] })['.'];\n\n return {\n ...(await findFileInPackage(\n {\n packagePath,\n filePath: normalizeRelativePath(path.relative(packagePath, path.join(nestedDefinitionPath, entryPath))),\n },\n context,\n )),\n typesPath:\n typesPath && normalizeRelativePath(path.relative(packagePath, path.join(nestedDefinitionPath, typesPath))),\n };\n } else {\n // If we can't find an entry, we should not include this in the exports map.\n // This avoids adding a \"./package.json\" value to a \".\" entry.\n return result;\n }\n }\n\n // If the resolved file is a typescript file in an internal package, try to resolve the intermediate.\n if (filePath && sourceExtensions.includes(path.extname(filePath))) {\n sourcePath = filePath;\n filePath = isInternal ? sourceToIntermediatePath(filePath) : undefined;\n }\n\n // If we haven't resolved a sourcePath, try to resolve it from the intermediate.\n if (isInternal && filePath && !sourcePath) {\n const ext = path.extname(filePath);\n const isJavaScriptExt = javascriptExtensions.includes(ext);\n\n if (isJavaScriptExt) {\n // Not a TS file, but a JS file. Try to find the source.\n sourcePath = intermediateToSourcePath(filePath, packagePath);\n\n // If we couldn't find a TS file, clear sourcePath.\n if (sourcePath === filePath) {\n sourcePath = undefined;\n }\n }\n }\n\n // Try to resolve the typesPath\n if (sourcePath && filePath) {\n typesPath = filePath.replace(/\\.js$/, '.d.ts');\n\n // eslint-disable-next-line @ms-cloudpack/internal/no-sync-filesystem\n if (!isInternal && !isFileSync(path.join(packagePath, typesPath))) {\n typesPath = undefined;\n }\n }\n\n if (typesPath) {\n result.typesPath = normalizeRelativePath(typesPath);\n }\n\n if (filePath) {\n result.filePath = normalizeRelativePath(filePath);\n }\n\n if (sourcePath) {\n result.sourcePath = normalizeRelativePath(sourcePath);\n }\n\n return result;\n}\n"]}
|
|
@@ -2,9 +2,19 @@ import type { PackageJsonExports } from '@ms-cloudpack/common-types';
|
|
|
2
2
|
/**
|
|
3
3
|
* Given a package definition and applicable conditions, return a flat map of package import to physical (relative) path.
|
|
4
4
|
* Optionally return the exports map fully qualified with conditions intact using the `fullExports` option.
|
|
5
|
+
* Optionally takes in a `packagePath` to resolve entries and values that end in `/` and with wildcards `*`.
|
|
6
|
+
*
|
|
7
|
+
* Notes:
|
|
8
|
+
* - This diverges from the behavior of Node in that conditions are considered in order of
|
|
9
|
+
* the `conditions` array, NOT in the order keys are defined in the exports map.
|
|
10
|
+
* - Null export values are currently not supported.
|
|
11
|
+
* - Following the behavior of Node, for perf reasons, we do NOT verify whether any entries
|
|
12
|
+
* exist on disk except wildcard or trailing slash exports since it is required.
|
|
13
|
+
* (This differs from the behavior of typescript and webpack.)
|
|
5
14
|
*/
|
|
6
15
|
export declare function flattenExportsMap(exportsMap: PackageJsonExports, options?: {
|
|
7
16
|
conditions?: string[];
|
|
8
17
|
requiredConditions?: string[];
|
|
18
|
+
packagePath?: string;
|
|
9
19
|
}): Record<string, string>;
|
|
10
20
|
//# sourceMappingURL=flattenExportsMap.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flattenExportsMap.d.ts","sourceRoot":"","sources":["../src/flattenExportsMap.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAA4B,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"flattenExportsMap.d.ts","sourceRoot":"","sources":["../src/flattenExportsMap.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAA4B,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAM/F;;;;;;;;;;;;GAYG;AACH,wBAAgB,iBAAiB,CAC/B,UAAU,EAAE,kBAAkB,EAC9B,OAAO,GAAE;IACP,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,kBAAkB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC9B,WAAW,CAAC,EAAE,MAAM,CAAC;CACjB,GACL,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CA4BxB"}
|
package/lib/flattenExportsMap.js
CHANGED
|
@@ -1,12 +1,22 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
2
|
import { cleanEntry } from './cleanEntry.js';
|
|
3
|
+
import glob from 'fast-glob';
|
|
3
4
|
const defaultConditions = ['browser', 'module', 'import', 'default'];
|
|
4
5
|
/**
|
|
5
6
|
* Given a package definition and applicable conditions, return a flat map of package import to physical (relative) path.
|
|
6
7
|
* Optionally return the exports map fully qualified with conditions intact using the `fullExports` option.
|
|
8
|
+
* Optionally takes in a `packagePath` to resolve entries and values that end in `/` and with wildcards `*`.
|
|
9
|
+
*
|
|
10
|
+
* Notes:
|
|
11
|
+
* - This diverges from the behavior of Node in that conditions are considered in order of
|
|
12
|
+
* the `conditions` array, NOT in the order keys are defined in the exports map.
|
|
13
|
+
* - Null export values are currently not supported.
|
|
14
|
+
* - Following the behavior of Node, for perf reasons, we do NOT verify whether any entries
|
|
15
|
+
* exist on disk except wildcard or trailing slash exports since it is required.
|
|
16
|
+
* (This differs from the behavior of typescript and webpack.)
|
|
7
17
|
*/
|
|
8
18
|
export function flattenExportsMap(exportsMap, options = {}) {
|
|
9
|
-
const { requiredConditions } = options;
|
|
19
|
+
const { requiredConditions, packagePath } = options;
|
|
10
20
|
let { conditions } = options;
|
|
11
21
|
if (conditions) {
|
|
12
22
|
const defaultIndex = conditions.indexOf('...');
|
|
@@ -22,16 +32,37 @@ export function flattenExportsMap(exportsMap, options = {}) {
|
|
|
22
32
|
'.': cleanEntry(exportsMap),
|
|
23
33
|
};
|
|
24
34
|
}
|
|
25
|
-
return extractExports(
|
|
35
|
+
return extractExports({
|
|
36
|
+
exports: exportsMap,
|
|
37
|
+
conditions,
|
|
38
|
+
requiredConditions,
|
|
39
|
+
flatExports: {},
|
|
40
|
+
importMatch: '.',
|
|
41
|
+
matchedConditions: [],
|
|
42
|
+
packagePath,
|
|
43
|
+
});
|
|
26
44
|
}
|
|
27
|
-
|
|
45
|
+
/**
|
|
46
|
+
* Extract the exports from an exports object or sub-object and add them to the flat exports map.
|
|
47
|
+
*
|
|
48
|
+
* @returns The cumulative flat exports map.
|
|
49
|
+
*/
|
|
50
|
+
function extractExports({ exports, conditions, requiredConditions, flatExports = {}, importMatch = '.', matchedConditions = [], packagePath = undefined, }) {
|
|
28
51
|
if (typeof exports === 'string' &&
|
|
29
52
|
(!requiredConditions || requiredConditions.every((condition) => matchedConditions.includes(condition)))) {
|
|
30
|
-
addExportsEntry(
|
|
53
|
+
addExportsEntry({ flatExports, key: importMatch, value: exports, packagePath });
|
|
31
54
|
}
|
|
32
55
|
else if (Array.isArray(exports)) {
|
|
33
56
|
for (const exportEntry of exports) {
|
|
34
|
-
extractExports(
|
|
57
|
+
extractExports({
|
|
58
|
+
exports: exportEntry,
|
|
59
|
+
conditions,
|
|
60
|
+
requiredConditions,
|
|
61
|
+
flatExports,
|
|
62
|
+
importMatch,
|
|
63
|
+
matchedConditions,
|
|
64
|
+
packagePath,
|
|
65
|
+
});
|
|
35
66
|
}
|
|
36
67
|
}
|
|
37
68
|
else if (exports && typeof exports === 'object') {
|
|
@@ -39,9 +70,17 @@ function extractExports(exports, conditions, requiredConditions, exportsMap = {}
|
|
|
39
70
|
for (const condition of conditions) {
|
|
40
71
|
const exportsObject = exports[condition];
|
|
41
72
|
if (exportsObject) {
|
|
42
|
-
extractExports(
|
|
73
|
+
extractExports({
|
|
74
|
+
exports: exportsObject,
|
|
75
|
+
conditions,
|
|
76
|
+
requiredConditions,
|
|
77
|
+
flatExports,
|
|
78
|
+
importMatch,
|
|
79
|
+
matchedConditions: matchedConditions.concat(condition),
|
|
80
|
+
packagePath,
|
|
81
|
+
});
|
|
43
82
|
// Stop at the first match.
|
|
44
|
-
return
|
|
83
|
+
return flatExports;
|
|
45
84
|
}
|
|
46
85
|
}
|
|
47
86
|
// No conditions are available. Check for import entries.
|
|
@@ -49,23 +88,112 @@ function extractExports(exports, conditions, requiredConditions, exportsMap = {}
|
|
|
49
88
|
if (key.startsWith('.')) {
|
|
50
89
|
importMatch = key;
|
|
51
90
|
if (typeof value === 'string') {
|
|
52
|
-
if (!
|
|
53
|
-
addExportsEntry(
|
|
91
|
+
if (!flatExports[importMatch] && (!requiredConditions || requiredConditions?.includes(key))) {
|
|
92
|
+
addExportsEntry({ flatExports, key: importMatch, value, packagePath });
|
|
54
93
|
}
|
|
55
94
|
}
|
|
56
95
|
else if (value) {
|
|
57
|
-
extractExports(
|
|
96
|
+
extractExports({
|
|
97
|
+
exports: value,
|
|
98
|
+
conditions,
|
|
99
|
+
requiredConditions,
|
|
100
|
+
flatExports,
|
|
101
|
+
importMatch,
|
|
102
|
+
matchedConditions: [...matchedConditions, key],
|
|
103
|
+
packagePath,
|
|
104
|
+
});
|
|
58
105
|
}
|
|
59
106
|
}
|
|
60
107
|
}
|
|
61
108
|
}
|
|
62
|
-
return
|
|
109
|
+
return flatExports;
|
|
63
110
|
}
|
|
64
|
-
|
|
111
|
+
/**
|
|
112
|
+
* Add an entry to the flattened exports map if the key and value are valid
|
|
113
|
+
* and the key is not already in the map.
|
|
114
|
+
*
|
|
115
|
+
* Does nothing if the key contains a wildcard or a trailing slash and the value does not, such as it being `null`.
|
|
116
|
+
*/
|
|
117
|
+
function addExportsEntry({ flatExports, key, value, packagePath, }) {
|
|
65
118
|
const basename = path.basename(value);
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
|
|
119
|
+
const isValid = basename !== '' && basename !== '.';
|
|
120
|
+
const isMany = value.endsWith('/') || value.indexOf('*') !== -1 || key.indexOf('*') !== -1 || key.endsWith('/');
|
|
121
|
+
// Skip if the key is already in the map.
|
|
122
|
+
if (flatExports[key])
|
|
123
|
+
return;
|
|
124
|
+
if (isValid && !isMany) {
|
|
125
|
+
flatExports[key] = cleanEntry(value);
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
if (value === null) {
|
|
129
|
+
// Debug log for null values in the exports map.
|
|
130
|
+
console.debug(`Skipping null value for key "${key}" in exports map${packagePath ? ` of "${packagePath}"` : ''}.`);
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
// Debug log for export patterns found in the exports map.
|
|
134
|
+
console.debug(`Found export patterns in ${packagePath ? `"${packagePath}" ` : ''}exports map: "${key}": "${value}"`);
|
|
135
|
+
// A package path is required to resolve entries and values that end in `/` or that include a wildcard `*`.
|
|
136
|
+
if (!packagePath)
|
|
137
|
+
return;
|
|
138
|
+
// Check for wildcards in the key and value.
|
|
139
|
+
// The wildcards
|
|
140
|
+
const keyWildcard = key.indexOf('*', 1);
|
|
141
|
+
const valueWildcard = value.indexOf('*', 1);
|
|
142
|
+
if ((key.endsWith('/') && value.endsWith('/')) || (keyWildcard !== -1 && valueWildcard !== -1)) {
|
|
143
|
+
const searchGlob = valueToGlob(value, valueWildcard);
|
|
144
|
+
const keySplit = splitByGlob(key, keyWildcard);
|
|
145
|
+
const valueSplit = splitByGlob(value, valueWildcard);
|
|
146
|
+
if (!searchGlob || !keySplit || !valueSplit)
|
|
147
|
+
return;
|
|
148
|
+
// We only want to search for files.
|
|
149
|
+
const matches = glob.sync(searchGlob, { cwd: packagePath, onlyFiles: true });
|
|
150
|
+
for (const match of matches) {
|
|
151
|
+
// Skip files that don't have an extension or have a `.` extension.
|
|
152
|
+
if (path.extname(match).length <= 1)
|
|
153
|
+
continue;
|
|
154
|
+
// Get the glob match shared between the key and value.
|
|
155
|
+
const globMatch = match.substring(
|
|
156
|
+
// Globs that start with `./` don't return matches with `./` in the beginning.
|
|
157
|
+
match.startsWith(valueSplit.start) ? valueSplit.start.length : 0, match.length - valueSplit.end.length);
|
|
158
|
+
// Replace the glob match in the key with the resolved glob match in the value.
|
|
159
|
+
const matchKey = keySplit.start + globMatch + keySplit.end;
|
|
160
|
+
if (!flatExports[matchKey]) {
|
|
161
|
+
flatExports[matchKey] = cleanEntry(match);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Convert a value to a glob pattern.
|
|
168
|
+
*
|
|
169
|
+
* @param value The value to convert.
|
|
170
|
+
* @param valueWildcard The index of the wildcard in the value.
|
|
171
|
+
* @returns A value converted to a glob pattern.
|
|
172
|
+
*/
|
|
173
|
+
function valueToGlob(value, valueWildcard = value.indexOf('*', 1)) {
|
|
174
|
+
if (value.endsWith('/')) {
|
|
175
|
+
return value + '**/*';
|
|
176
|
+
}
|
|
177
|
+
else if (valueWildcard !== -1) {
|
|
178
|
+
return value.substring(0, valueWildcard) + '**/*' + value.substring(valueWildcard + 1);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Split a value by the location of the trailing slash or wildcard.
|
|
183
|
+
*
|
|
184
|
+
* @param value The value to split.
|
|
185
|
+
* @param valueWildcard The index of the wildcard in the value.
|
|
186
|
+
* @returns An object with the start and end substring of the split value.
|
|
187
|
+
*/
|
|
188
|
+
function splitByGlob(value, valueWildcard = value.indexOf('*', 1)) {
|
|
189
|
+
if (value.endsWith('/')) {
|
|
190
|
+
return { start: value, end: '' };
|
|
191
|
+
}
|
|
192
|
+
else if (valueWildcard !== -1) {
|
|
193
|
+
return {
|
|
194
|
+
start: value.substring(0, valueWildcard),
|
|
195
|
+
end: value.substring(valueWildcard + 1),
|
|
196
|
+
};
|
|
69
197
|
}
|
|
70
198
|
}
|
|
71
199
|
//# sourceMappingURL=flattenExportsMap.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flattenExportsMap.js","sourceRoot":"","sources":["../src/flattenExportsMap.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,UAA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CAAC;oBACjB,cAAc,CAAC,KAAK,EAAE,UAAU,EAAE,kBAAkB,EAAE,UAAU,EAAE,WAAW,EAAE,CAAC,GAAG,iBAAiB,EAAE,GAAG,CAAC,CAAC,CAAC;gBAC9G,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,UAAU,CAAC;AACpB,CAAC;AAED,SAAS,eAAe,CAAC,UAAkC,EAAE,GAAW,EAAE,KAAa;IACrF,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IACtC,MAAM,UAAU,GAAG,QAAQ,KAAK,EAAE,IAAI,QAAQ,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;IAE/E,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,UAAU,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC;QACjH,UAAU,CAAC,GAAG,CAAC,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC;IACtC,CAAC;AACH,CAAC","sourcesContent":["import path from 'path';\nimport type { PackageJsonExportsObject, PackageJsonExports } from '@ms-cloudpack/common-types';\nimport { cleanEntry } from './cleanEntry.js';\n\nconst defaultConditions = ['browser', 'module', 'import', 'default'];\n\n/**\n * Given a package definition and applicable conditions, return a flat map of package import to physical (relative) path.\n * Optionally return the exports map fully qualified with conditions intact using the `fullExports` option.\n */\nexport function flattenExportsMap(\n exportsMap: PackageJsonExports,\n options: {\n conditions?: string[];\n requiredConditions?: string[];\n } = {},\n): Record<string, string> {\n const { requiredConditions } = options;\n let { conditions } = options;\n\n if (conditions) {\n const defaultIndex = conditions.indexOf('...');\n if (defaultIndex !== -1) {\n conditions = [...conditions.slice(0, defaultIndex), ...defaultConditions, ...conditions.slice(defaultIndex + 1)];\n }\n } else {\n conditions = defaultConditions;\n }\n\n if (typeof exportsMap === 'string' && conditions.includes('default')) {\n return {\n '.': cleanEntry(exportsMap),\n };\n }\n\n return extractExports(exportsMap, conditions, requiredConditions);\n}\n\nfunction extractExports(\n exports: PackageJsonExports,\n conditions: string[],\n requiredConditions?: string[],\n exportsMap: Record<string, string> = {},\n importMatch = '.',\n matchedConditions: string[] = [],\n) {\n if (\n typeof exports === 'string' &&\n (!requiredConditions || requiredConditions.every((condition) => matchedConditions.includes(condition)))\n ) {\n addExportsEntry(exportsMap, importMatch, exports);\n } else if (Array.isArray(exports)) {\n for (const exportEntry of exports) {\n extractExports(exportEntry, conditions, requiredConditions, exportsMap, importMatch, matchedConditions);\n }\n } else if (exports && typeof exports === 'object') {\n // Iterate through condition matches and go deeper if a match is found.\n for (const condition of conditions) {\n const exportsObject = (exports as PackageJsonExportsObject)[condition];\n\n if (exportsObject) {\n extractExports(\n exportsObject as PackageJsonExports,\n conditions,\n requiredConditions,\n exportsMap,\n importMatch,\n matchedConditions.concat(condition),\n );\n // Stop at the first match.\n return exportsMap;\n }\n }\n\n // No conditions are available. Check for import entries.\n for (const [key, value] of Object.entries(exports)) {\n if (key.startsWith('.')) {\n importMatch = key;\n\n if (typeof value === 'string') {\n if (!exportsMap[importMatch] && (!requiredConditions || requiredConditions?.includes(key))) {\n addExportsEntry(exportsMap, importMatch, value);\n }\n } else if (value) {\n extractExports(value, conditions, requiredConditions, exportsMap, importMatch, [...matchedConditions, key]);\n }\n }\n }\n }\n\n return exportsMap;\n}\n\nfunction addExportsEntry(exportsMap: Record<string, string>, key: string, value: string) {\n const basename = path.basename(value);\n const isFilename = basename !== '' && basename !== '.' && !value.endsWith('/');\n\n if (!exportsMap[key] && isFilename && key.indexOf('*') === -1 && !key.endsWith('/') && value.indexOf('*') === -1) {\n exportsMap[key] = cleanEntry(value);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"flattenExportsMap.js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C,GAAG,MAAM,GAAG,KAAK,CAAC,SAAS,CAAC,aAAa,GAAG,CAAC,CAAC,CAAC;IACzF,CAAC;AACH,CAAC;AAED;;;;;;GAMG;AACH,SAAS,WAAW,CAAC,KAAa,EAAE,gBAAwB,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;IAC/E,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","sourcesContent":["import path from 'path';\nimport type { PackageJsonExportsObject, PackageJsonExports } from '@ms-cloudpack/common-types';\nimport { cleanEntry } from './cleanEntry.js';\nimport glob from 'fast-glob';\n\nconst defaultConditions = ['browser', 'module', 'import', 'default'];\n\n/**\n * Given a package definition and applicable conditions, return a flat map of package import to physical (relative) path.\n * Optionally return the exports map fully qualified with conditions intact using the `fullExports` option.\n * Optionally takes in a `packagePath` to resolve entries and values that end in `/` and with wildcards `*`.\n *\n * Notes:\n * - This diverges from the behavior of Node in that conditions are considered in order of\n * the `conditions` array, NOT in the order keys are defined in the exports map.\n * - Null export values are currently not supported.\n * - Following the behavior of Node, for perf reasons, we do NOT verify whether any entries\n * exist on disk except wildcard or trailing slash exports since it is required.\n * (This differs from the behavior of typescript and webpack.)\n */\nexport function flattenExportsMap(\n exportsMap: PackageJsonExports,\n options: {\n conditions?: string[];\n requiredConditions?: string[];\n packagePath?: string;\n } = {},\n): Record<string, string> {\n const { requiredConditions, packagePath } = options;\n let { conditions } = options;\n\n if (conditions) {\n const defaultIndex = conditions.indexOf('...');\n if (defaultIndex !== -1) {\n conditions = [...conditions.slice(0, defaultIndex), ...defaultConditions, ...conditions.slice(defaultIndex + 1)];\n }\n } else {\n conditions = defaultConditions;\n }\n\n if (typeof exportsMap === 'string' && conditions.includes('default')) {\n return {\n '.': cleanEntry(exportsMap),\n };\n }\n\n return extractExports({\n exports: exportsMap,\n conditions,\n requiredConditions,\n flatExports: {},\n importMatch: '.',\n matchedConditions: [],\n packagePath,\n });\n}\n\n/**\n * Extract the exports from an exports object or sub-object and add them to the flat exports map.\n *\n * @returns The cumulative flat exports map.\n */\nfunction extractExports({\n exports,\n conditions,\n requiredConditions,\n flatExports = {},\n importMatch = '.',\n matchedConditions = [],\n packagePath = undefined,\n}: {\n /** The exports object to extract or a sub-object. */\n exports: PackageJsonExports;\n /** The conditions to check for in the exports object. */\n conditions: string[];\n /** The conditions that must be matched to add the export. */\n requiredConditions?: string[];\n /** The cumulative flat exports map to add the exports to. */\n flatExports?: Record<string, string>;\n /** The import path to match (default `.`). */\n importMatch?: string;\n /** The conditions that have been matched so far. */\n matchedConditions?: string[];\n /** The path to the package. */\n packagePath?: string | undefined;\n}) {\n if (\n typeof exports === 'string' &&\n (!requiredConditions || requiredConditions.every((condition) => matchedConditions.includes(condition)))\n ) {\n addExportsEntry({ flatExports, key: importMatch, value: exports, packagePath });\n } else if (Array.isArray(exports)) {\n for (const exportEntry of exports) {\n extractExports({\n exports: exportEntry,\n conditions,\n requiredConditions,\n flatExports,\n importMatch,\n matchedConditions,\n packagePath,\n });\n }\n } else if (exports && typeof exports === 'object') {\n // Iterate through condition matches and go deeper if a match is found.\n for (const condition of conditions) {\n const exportsObject = (exports as PackageJsonExportsObject)[condition];\n\n if (exportsObject) {\n extractExports({\n exports: exportsObject as PackageJsonExports,\n conditions,\n requiredConditions,\n flatExports,\n importMatch,\n matchedConditions: matchedConditions.concat(condition),\n packagePath,\n });\n // Stop at the first match.\n return flatExports;\n }\n }\n\n // No conditions are available. Check for import entries.\n for (const [key, value] of Object.entries(exports)) {\n if (key.startsWith('.')) {\n importMatch = key;\n\n if (typeof value === 'string') {\n if (!flatExports[importMatch] && (!requiredConditions || requiredConditions?.includes(key))) {\n addExportsEntry({ flatExports, key: importMatch, value, packagePath });\n }\n } else if (value) {\n extractExports({\n exports: value,\n conditions,\n requiredConditions,\n flatExports,\n importMatch,\n matchedConditions: [...matchedConditions, key],\n packagePath,\n });\n }\n }\n }\n }\n\n return flatExports;\n}\n\n/**\n * Add an entry to the flattened exports map if the key and value are valid\n * and the key is not already in the map.\n *\n * Does nothing if the key contains a wildcard or a trailing slash and the value does not, such as it being `null`.\n */\nfunction addExportsEntry({\n flatExports,\n key,\n value,\n packagePath,\n}: {\n /** The path to the package. */\n flatExports: Record<string, string>;\n /** The flattened exports map. */\n key: string;\n /** The key to add to the map. */\n value: string;\n /** The relative physical path to add to the map. */\n packagePath: string | undefined;\n}) {\n const basename = path.basename(value);\n const isValid = basename !== '' && basename !== '.';\n const isMany = value.endsWith('/') || value.indexOf('*') !== -1 || key.indexOf('*') !== -1 || key.endsWith('/');\n\n // Skip if the key is already in the map.\n if (flatExports[key]) return;\n\n if (isValid && !isMany) {\n flatExports[key] = cleanEntry(value);\n return;\n }\n\n if (value === null) {\n // Debug log for null values in the exports map.\n console.debug(`Skipping null value for key \"${key}\" in exports map${packagePath ? ` of \"${packagePath}\"` : ''}.`);\n return;\n }\n\n // Debug log for export patterns found in the exports map.\n console.debug(`Found export patterns in ${packagePath ? `\"${packagePath}\" ` : ''}exports map: \"${key}\": \"${value}\"`);\n\n // A package path is required to resolve entries and values that end in `/` or that include a wildcard `*`.\n if (!packagePath) return;\n\n // Check for wildcards in the key and value.\n // The wildcards\n const keyWildcard = key.indexOf('*', 1);\n const valueWildcard = value.indexOf('*', 1);\n\n if ((key.endsWith('/') && value.endsWith('/')) || (keyWildcard !== -1 && valueWildcard !== -1)) {\n const searchGlob = valueToGlob(value, valueWildcard);\n const keySplit = splitByGlob(key, keyWildcard);\n const valueSplit = splitByGlob(value, valueWildcard);\n if (!searchGlob || !keySplit || !valueSplit) return;\n // We only want to search for files.\n const matches = glob.sync(searchGlob, { cwd: packagePath, onlyFiles: true });\n for (const match of matches) {\n // Skip files that don't have an extension or have a `.` extension.\n if (path.extname(match).length <= 1) continue;\n // Get the glob match shared between the key and value.\n const globMatch = match.substring(\n // Globs that start with `./` don't return matches with `./` in the beginning.\n match.startsWith(valueSplit.start) ? valueSplit.start.length : 0,\n match.length - valueSplit.end.length,\n );\n // Replace the glob match in the key with the resolved glob match in the value.\n const matchKey = keySplit.start + globMatch + keySplit.end;\n if (!flatExports[matchKey]) {\n flatExports[matchKey] = cleanEntry(match);\n }\n }\n }\n}\n\n/**\n * Convert a value to a glob pattern.\n *\n * @param value The value to convert.\n * @param valueWildcard The index of the wildcard in the value.\n * @returns A value converted to a glob pattern.\n */\nfunction valueToGlob(value: string, valueWildcard: number = value.indexOf('*', 1)) {\n if (value.endsWith('/')) {\n return value + '**/*';\n } else if (valueWildcard !== -1) {\n return value.substring(0, valueWildcard) + '**/*' + value.substring(valueWildcard + 1);\n }\n}\n\n/**\n * Split a value by the location of the trailing slash or wildcard.\n *\n * @param value The value to split.\n * @param valueWildcard The index of the wildcard in the value.\n * @returns An object with the start and end substring of the split value.\n */\nfunction splitByGlob(value: string, valueWildcard: number = value.indexOf('*', 1)) {\n if (value.endsWith('/')) {\n return { start: value, end: '' };\n } else if (valueWildcard !== -1) {\n return {\n start: value.substring(0, valueWildcard),\n end: value.substring(valueWildcard + 1),\n };\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getSourceEntry.d.ts","sourceRoot":"","sources":["../src/getSourceEntry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,uBAAuB,EAAE,MAAM,4BAA4B,CAAC;AAM3F;;GAEG;AACH,wBAAsB,cAAc,CAClC,OAAO,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,EAC7C,OAAO,EAAE;IAAE,QAAQ,EAAE,uBAAuB,CAAC;IAAC,MAAM,EAAE,eAAe,CAAA;CAAE,
|
|
1
|
+
{"version":3,"file":"getSourceEntry.d.ts","sourceRoot":"","sources":["../src/getSourceEntry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,uBAAuB,EAAE,MAAM,4BAA4B,CAAC;AAM3F;;GAEG;AACH,wBAAsB,cAAc,CAClC,OAAO,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,EAC7C,OAAO,EAAE;IAAE,QAAQ,EAAE,uBAAuB,CAAC;IAAC,MAAM,EAAE,eAAe,CAAA;CAAE,mBAkBxE"}
|
package/lib/getSourceEntry.js
CHANGED
|
@@ -8,12 +8,16 @@ import { isExternalPackage } from './isExternalPackage.js';
|
|
|
8
8
|
export async function getSourceEntry(options, context) {
|
|
9
9
|
const { entry, inputPath } = options;
|
|
10
10
|
const exportsMap = await getExportsMap({ packagePath: inputPath }, context);
|
|
11
|
-
const flattenedExportsMap = flattenExportsMap(exportsMap);
|
|
11
|
+
const flattenedExportsMap = flattenExportsMap(exportsMap, { packagePath: inputPath });
|
|
12
12
|
if (isExternalPackage(inputPath)) {
|
|
13
13
|
return flattenedExportsMap[entry];
|
|
14
14
|
}
|
|
15
15
|
// If it is internal...
|
|
16
|
-
const sourceExportsMap = flattenExportsMap(exportsMap, {
|
|
16
|
+
const sourceExportsMap = flattenExportsMap(exportsMap, {
|
|
17
|
+
conditions: ['source'],
|
|
18
|
+
requiredConditions: ['source'],
|
|
19
|
+
packagePath: inputPath,
|
|
20
|
+
});
|
|
17
21
|
const value = flattenedExportsMap[entry];
|
|
18
22
|
// Prefer source exports if available, otherwise derive from intermediate paths,
|
|
19
23
|
// and default to the flattened map value.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getSourceEntry.js","sourceRoot":"","sources":["../src/getSourceEntry.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AACxE,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAE3D;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,OAA6C,EAC7C,OAAuE;IAEvE,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC;IACrC,MAAM,UAAU,GAAG,MAAM,aAAa,CAAC,EAAE,WAAW,EAAE,SAAS,EAAE,EAAE,OAAO,CAAC,CAAC;IAC5E,MAAM,mBAAmB,GAAG,iBAAiB,CAAC,UAAU,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"getSourceEntry.js","sourceRoot":"","sources":["../src/getSourceEntry.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AACxE,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAE3D;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,OAA6C,EAC7C,OAAuE;IAEvE,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC;IACrC,MAAM,UAAU,GAAG,MAAM,aAAa,CAAC,EAAE,WAAW,EAAE,SAAS,EAAE,EAAE,OAAO,CAAC,CAAC;IAC5E,MAAM,mBAAmB,GAAG,iBAAiB,CAAC,UAAU,EAAE,EAAE,WAAW,EAAE,SAAS,EAAE,CAAC,CAAC;IACtF,IAAI,iBAAiB,CAAC,SAAS,CAAC,EAAE,CAAC;QACjC,OAAO,mBAAmB,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC;IACD,uBAAuB;IACvB,MAAM,gBAAgB,GAAG,iBAAiB,CAAC,UAAU,EAAE;QACrD,UAAU,EAAE,CAAC,QAAQ,CAAC;QACtB,kBAAkB,EAAE,CAAC,QAAQ,CAAC;QAC9B,WAAW,EAAE,SAAS;KACvB,CAAC,CAAC;IACH,MAAM,KAAK,GAAG,mBAAmB,CAAC,KAAK,CAAC,CAAC;IACzC,gFAAgF;IAChF,0CAA0C;IAC1C,OAAO,gBAAgB,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,IAAI,wBAAwB,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC,IAAI,KAAK,CAAC;AACnG,CAAC","sourcesContent":["import type { CloudpackConfig, PackageDefinitionsCache } from '@ms-cloudpack/common-types';\nimport { intermediateToSourcePath } from '@ms-cloudpack/path-utilities';\nimport { getExportsMap } from './getExportsMap.js';\nimport { flattenExportsMap } from './flattenExportsMap.js';\nimport { isExternalPackage } from './isExternalPackage.js';\n\n/**\n * Attempts to find the source path for a given entry in a package.\n */\nexport async function getSourceEntry(\n options: { entry: string; inputPath: string },\n context: { packages: PackageDefinitionsCache; config: CloudpackConfig },\n) {\n const { entry, inputPath } = options;\n const exportsMap = await getExportsMap({ packagePath: inputPath }, context);\n const flattenedExportsMap = flattenExportsMap(exportsMap, { packagePath: inputPath });\n if (isExternalPackage(inputPath)) {\n return flattenedExportsMap[entry];\n }\n // If it is internal...\n const sourceExportsMap = flattenExportsMap(exportsMap, {\n conditions: ['source'],\n requiredConditions: ['source'],\n packagePath: inputPath,\n });\n const value = flattenedExportsMap[entry];\n // Prefer source exports if available, otherwise derive from intermediate paths,\n // and default to the flattened map value.\n return sourceExportsMap[entry] || (value && intermediateToSourcePath(value, inputPath)) || value;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ms-cloudpack/package-utilities",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.3.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.
|
|
17
|
+
"@ms-cloudpack/common-types": "^0.3.0",
|
|
18
18
|
"@ms-cloudpack/json-utilities": "^0.1.4",
|
|
19
|
-
"@ms-cloudpack/package-overrides": "^0.
|
|
19
|
+
"@ms-cloudpack/package-overrides": "^0.8.0",
|
|
20
20
|
"@ms-cloudpack/path-string-parsing": "^1.2.1",
|
|
21
|
-
"@ms-cloudpack/path-utilities": "^2.7.
|
|
21
|
+
"@ms-cloudpack/path-utilities": "^2.7.4",
|
|
22
22
|
"acorn": "^8.11.2",
|
|
23
23
|
"acorn-walk": "^8.2.1",
|
|
24
24
|
"fast-glob": "^3.2.12",
|