@ms-cloudpack/package-utilities 10.1.3 → 10.2.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/addExportsMapEntry.d.ts +0 -5
- package/lib/addExportsMapEntry.d.ts.map +1 -1
- package/lib/addExportsMapEntry.js +2 -5
- package/lib/addExportsMapEntry.js.map +1 -1
- package/lib/createExportsMap.d.ts.map +1 -1
- package/lib/createExportsMap.js +1 -5
- package/lib/createExportsMap.js.map +1 -1
- package/lib/findFileInPackage.d.ts +0 -1
- package/lib/findFileInPackage.d.ts.map +1 -1
- package/lib/findFileInPackage.js +4 -19
- package/lib/findFileInPackage.js.map +1 -1
- package/package.json +1 -1
|
@@ -22,11 +22,6 @@ export interface AddExportsMapEntryOptions {
|
|
|
22
22
|
* assuming `index.js`.
|
|
23
23
|
*/
|
|
24
24
|
filePath?: string;
|
|
25
|
-
/**
|
|
26
|
-
* Optional types path. If not provided, types will be discovered for internal packages that have source files.
|
|
27
|
-
* This is useful mainly when converting the default import from a package.json that has explicit typings listed.
|
|
28
|
-
*/
|
|
29
|
-
typesPath?: string;
|
|
30
25
|
/**
|
|
31
26
|
* The condition to add the entry for. (Example: "import", "require") Defaults to "default".
|
|
32
27
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"addExportsMapEntry.d.ts","sourceRoot":"","sources":["../src/addExportsMapEntry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAI/G;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACxC;;OAEG;IACH,OAAO,EAAE,kBAAkB,CAAC;IAE5B;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IAEpB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB
|
|
1
|
+
{"version":3,"file":"addExportsMapEntry.d.ts","sourceRoot":"","sources":["../src/addExportsMapEntry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAI/G;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACxC;;OAEG;IACH,OAAO,EAAE,kBAAkB,CAAC;IAE5B;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IAEpB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB;;OAEG;IACH,gBAAgB,CAAC,EAAE,QAAQ,GAAG,SAAS,GAAG,SAAS,CAAC;IAEpD;;;OAGG;IACH,oBAAoB,CAAC,EAAE,SAAS,GAAG,MAAM,CAAC;CAC3C;AAED;;GAEG;AACH,wBAAsB,kBAAkB,CACtC,OAAO,EAAE,yBAAyB,EAClC,OAAO,EAAE;IAAE,QAAQ,EAAE,uBAAuB,CAAC;IAAC,MAAM,EAAE,IAAI,CAAC,eAAe,EAAE,UAAU,CAAC,CAAA;CAAE,GACxF,OAAO,CAAC,OAAO,CAAC,CAqClB"}
|
|
@@ -6,7 +6,7 @@ import { findFileInPackage } from './findFileInPackage.js';
|
|
|
6
6
|
export async function addExportsMapEntry(options, context) {
|
|
7
7
|
const { exports, packagePath, environmentCondition, requestCondition } = options;
|
|
8
8
|
const importPath = normalizeRelativePath(options.importPath);
|
|
9
|
-
const { filePath, sourcePath
|
|
9
|
+
const { filePath, sourcePath } = await findFileInPackage({
|
|
10
10
|
packagePath,
|
|
11
11
|
filePath: options.filePath || options.importPath || '',
|
|
12
12
|
}, context);
|
|
@@ -18,14 +18,11 @@ export async function addExportsMapEntry(options, context) {
|
|
|
18
18
|
const localExports = exports;
|
|
19
19
|
let exportValue;
|
|
20
20
|
// If this is the only entry we're adding, set it to a string to minimize the exports map.
|
|
21
|
-
if (!
|
|
21
|
+
if (!sourcePath && !requestCondition) {
|
|
22
22
|
exportValue = filePath;
|
|
23
23
|
}
|
|
24
24
|
else {
|
|
25
25
|
exportValue = {};
|
|
26
|
-
if (typesPath) {
|
|
27
|
-
exportValue['types'] = typesPath;
|
|
28
|
-
}
|
|
29
26
|
if (sourcePath) {
|
|
30
27
|
exportValue['source'] = sourcePath;
|
|
31
28
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"addExportsMapEntry.js","sourceRoot":"","sources":["../src/addExportsMapEntry.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAC1E,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"addExportsMapEntry.js","sourceRoot":"","sources":["../src/addExportsMapEntry.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAC1E,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAyC3D;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,OAAkC,EAClC,OAAyF;IAEzF,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,GAAG,OAAO,CAAC;IACjF,MAAM,UAAU,GAAG,qBAAqB,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;IAC7D,MAAM,EAAE,QAAQ,EAAE,UAAU,EAAE,GAAG,MAAM,iBAAiB,CACtD;QACE,WAAW;QACX,QAAQ,EAAE,OAAO,CAAC,QAAQ,IAAI,OAAO,CAAC,UAAU,IAAI,EAAE;KACvD,EACD,OAAO,CACR,CAAC;IAEF,yCAAyC;IACzC,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,OAAO,KAAK,CAAC;IACf,CAAC;IAED,8BAA8B;IAC9B,MAAM,YAAY,GAAG,OAAmF,CAAC;IACzG,IAAI,WAA4C,CAAC;IAEjD,0FAA0F;IAC1F,IAAI,CAAC,UAAU,IAAI,CAAC,gBAAgB,EAAE,CAAC;QACrC,WAAW,GAAG,QAAQ,CAAC;IACzB,CAAC;SAAM,CAAC;QACN,WAAW,GAAG,EAAE,CAAC;QAEjB,IAAI,UAAU,EAAE,CAAC;YACf,WAAW,CAAC,QAAQ,CAAC,GAAG,UAAU,CAAC;QACrC,CAAC;QAED,mCAAmC;QACnC,WAAW,CAAC,gBAAgB,IAAI,SAAS,CAAC,GAAG,QAAQ,CAAC;IACxD,CAAC;IAED,YAAY,CAAC,UAAU,CAAC,GAAG,oBAAoB,CAAC,CAAC,CAAC,EAAE,CAAC,oBAAoB,CAAC,EAAE,WAAW,EAAE,CAAC,CAAC,CAAC,WAAW,CAAC;IAExG,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import type { CloudpackConfig, PackageDefinitionsCache, PackageJsonExports } from '@ms-cloudpack/common-types';\nimport { normalizeRelativePath } from '@ms-cloudpack/path-string-parsing';\nimport { findFileInPackage } from './findFileInPackage.js';\n\n/**\n * Options fo addExportsMapEntry.\n */\nexport interface AddExportsMapEntryOptions {\n /**\n * The exports map to add the entry to.\n */\n exports: PackageJsonExports;\n\n /**\n * The package path to add the entry for. This is used to resolve relative paths.\n */\n packagePath: string;\n\n /**\n * The import path to add the entry for. This is used as the key in the exports map. Defaults\n * to \".\" being the package import.\n */\n importPath?: string;\n\n /**\n * The relative path to the physical file location, representing the \"key\" in the exports map. Can be a partial\n * location, in which case we will attempt to search for the file and associated source/d.ts files. Defaults to\n * assuming `index.js`.\n */\n filePath?: string;\n\n /**\n * The condition to add the entry for. (Example: \"import\", \"require\") Defaults to \"default\".\n */\n requestCondition?: 'import' | 'require' | 'browser';\n\n /**\n * The condition that describes the environment the entry is for. (Example: \"browser\", \"node\".)\n * Unspecified implies environmentally agnostic.\n */\n environmentCondition?: 'browser' | 'node';\n}\n\n/**\n * Given an exports map and details about an import path, adds the entry.\n */\nexport async function addExportsMapEntry(\n options: AddExportsMapEntryOptions,\n context: { packages: PackageDefinitionsCache; config: Pick<CloudpackConfig, 'features'> },\n): Promise<boolean> {\n const { exports, packagePath, environmentCondition, requestCondition } = options;\n const importPath = normalizeRelativePath(options.importPath);\n const { filePath, sourcePath } = await findFileInPackage(\n {\n packagePath,\n filePath: options.filePath || options.importPath || '',\n },\n context,\n );\n\n // Only do work if a file path was found.\n if (!filePath) {\n return false;\n }\n\n // Create a local for casting.\n const localExports = exports as Record<string, string | Record<string, string | Record<string, string>>>;\n let exportValue: string | Record<string, string>;\n\n // If this is the only entry we're adding, set it to a string to minimize the exports map.\n if (!sourcePath && !requestCondition) {\n exportValue = filePath;\n } else {\n exportValue = {};\n\n if (sourcePath) {\n exportValue['source'] = sourcePath;\n }\n\n // Add the entry for the condition.\n exportValue[requestCondition || 'default'] = filePath;\n }\n\n localExports[importPath] = environmentCondition ? { [environmentCondition]: exportValue } : exportValue;\n\n return true;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createExportsMap.d.ts","sourceRoot":"","sources":["../src/createExportsMap.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAI/G;;GAEG;AACH,wBAAsB,gBAAgB,CACpC,OAAO,EAAE;IACP,WAAW,EAAE,MAAM,CAAC;IACpB,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B,EACD,OAAO,EAAE;IAAE,QAAQ,EAAE,uBAAuB,CAAC;IAAC,MAAM,EAAE,IAAI,CAAC,eAAe,EAAE,UAAU,CAAC,CAAA;CAAE,GACxF,OAAO,CAAC,kBAAkB,CAAC,
|
|
1
|
+
{"version":3,"file":"createExportsMap.d.ts","sourceRoot":"","sources":["../src/createExportsMap.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAI/G;;GAEG;AACH,wBAAsB,gBAAgB,CACpC,OAAO,EAAE;IACP,WAAW,EAAE,MAAM,CAAC;IACpB,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B,EACD,OAAO,EAAE;IAAE,QAAQ,EAAE,uBAAuB,CAAC;IAAC,MAAM,EAAE,IAAI,CAAC,eAAe,EAAE,UAAU,CAAC,CAAA;CAAE,GACxF,OAAO,CAAC,kBAAkB,CAAC,CAgG7B"}
|
package/lib/createExportsMap.js
CHANGED
|
@@ -11,16 +11,14 @@ export async function createExportsMap(options, context) {
|
|
|
11
11
|
if (definition.exports) {
|
|
12
12
|
return definition.exports;
|
|
13
13
|
}
|
|
14
|
-
const { browser, main, module,
|
|
14
|
+
const { browser, main, module, type } = definition;
|
|
15
15
|
const exports = {};
|
|
16
|
-
const typesPath = types || typings;
|
|
17
16
|
// Only try to add `index.js` as an entry if main/module/browser isn't available.
|
|
18
17
|
if (!(main || module || browser)) {
|
|
19
18
|
await addExportsMapEntry({
|
|
20
19
|
exports,
|
|
21
20
|
packagePath,
|
|
22
21
|
filePath: 'index.js',
|
|
23
|
-
typesPath,
|
|
24
22
|
requestCondition: type === 'module' ? 'import' : undefined,
|
|
25
23
|
}, context);
|
|
26
24
|
}
|
|
@@ -29,7 +27,6 @@ export async function createExportsMap(options, context) {
|
|
|
29
27
|
exports,
|
|
30
28
|
packagePath,
|
|
31
29
|
filePath: main,
|
|
32
|
-
typesPath,
|
|
33
30
|
requestCondition: type === 'module' ? 'import' : undefined,
|
|
34
31
|
}, context);
|
|
35
32
|
}
|
|
@@ -38,7 +35,6 @@ export async function createExportsMap(options, context) {
|
|
|
38
35
|
exports,
|
|
39
36
|
packagePath,
|
|
40
37
|
filePath: module,
|
|
41
|
-
typesPath,
|
|
42
38
|
requestCondition: 'import',
|
|
43
39
|
}, context);
|
|
44
40
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createExportsMap.js","sourceRoot":"","sources":["../src/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PackageDefinitionsCache, PackageJsonExports } from '@ms-cloudpack/common-types';\nimport { normalizeRelativePath } from '@ms-cloudpack/path-string-parsing';\nimport { addExportsMapEntry } from './addExportsMapEntry.js';\n\n/**\n * Given a package path, generates an export map for the package.\n */\nexport async function createExportsMap(\n options: {\n packagePath: string;\n disableTransforms?: boolean;\n },\n context: { packages: PackageDefinitionsCache; config: Pick<CloudpackConfig, 'features'> },\n): Promise<PackageJsonExports> {\n const { packagePath } = options;\n const { packages } = context;\n const definition = await packages.get(packagePath, { disableTransforms: options.disableTransforms });\n\n // Don't create an exports map for a definition that already has one.\n if (definition.exports) {\n return definition.exports;\n }\n\n const { browser, main, module, type } = definition;\n const exports = {};\n\n // Only try to add `index.js` as an entry if main/module/browser isn't available.\n if (!(main || module || browser)) {\n await addExportsMapEntry(\n {\n exports,\n packagePath,\n filePath: 'index.js',\n requestCondition: type === 'module' ? 'import' : undefined,\n },\n context,\n );\n }\n\n if (main) {\n await addExportsMapEntry(\n {\n exports,\n packagePath,\n filePath: main,\n requestCondition: type === 'module' ? 'import' : undefined,\n },\n context,\n );\n }\n\n if (module) {\n await addExportsMapEntry(\n {\n exports,\n packagePath,\n filePath: module,\n requestCondition: 'import',\n },\n context,\n );\n }\n\n if (browser) {\n if (typeof definition.browser === 'string') {\n await addExportsMapEntry(\n { exports, packagePath, filePath: definition.browser, requestCondition: 'browser' },\n context,\n );\n } else if (typeof definition.browser === 'object') {\n for (const [key, value] of Object.entries(definition.browser)) {\n if (!value || typeof value !== 'string') {\n continue;\n }\n\n const isDefaultImport = normalizeRelativePath(module || main) === normalizeRelativePath(key);\n\n const importPaths = isDefaultImport ? ['.'] : [key];\n\n if (!isDefaultImport && key.endsWith('.js')) {\n importPaths.push(key.replace(/\\.js$/, ''));\n }\n\n for (const importPath of importPaths) {\n await addExportsMapEntry(\n {\n exports,\n packagePath,\n importPath,\n filePath: value,\n requestCondition: 'browser',\n },\n context,\n );\n }\n }\n }\n }\n\n // If we couldn't infer the exports map shape from existing metadata,\n // formulate based off inferred file structure.\n // Note: CRA defaults to src/index.js, Vite defaults to src/main.js\n if (Object.keys(exports).length === 0) {\n (await addExportsMapEntry({ exports, packagePath, filePath: './lib/index.js' }, context)) ||\n (await addExportsMapEntry({ exports, packagePath, filePath: './lib/main.js' }, context)) ||\n (await addExportsMapEntry({ exports, packagePath, filePath: './index.js' }, context));\n }\n\n return exports;\n}\n"]}
|
|
@@ -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,
|
|
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,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,IAAI,CAAC,eAAe,EAAE,UAAU,CAAC,CAAA;CAAE,GACxF,OAAO,CAAC,uBAAuB,CAAC,CAqFlC"}
|
package/lib/findFileInPackage.js
CHANGED
|
@@ -22,7 +22,6 @@ export async function findFileInPackage(options, context) {
|
|
|
22
22
|
const packagePath = slash(options.packagePath);
|
|
23
23
|
let filePath;
|
|
24
24
|
let sourcePath;
|
|
25
|
-
let typesPath;
|
|
26
25
|
const isInternal = !isExternalPackage(packagePath);
|
|
27
26
|
const pathsToConsider = [originalPath];
|
|
28
27
|
const definition = await context.packages.tryGet(packagePath, { disableTransforms: true });
|
|
@@ -51,14 +50,10 @@ export async function findFileInPackage(options, context) {
|
|
|
51
50
|
const exportsMap = await getExportsMap({ packagePath: nestedDefinitionPath }, context);
|
|
52
51
|
const entryPath = flattenExportsMap(exportsMap)['.'];
|
|
53
52
|
if (entryPath) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
filePath: normalizeRelativePath(path.relative(packagePath, path.join(nestedDefinitionPath, entryPath))),
|
|
59
|
-
}, context)),
|
|
60
|
-
typesPath: typesPath && normalizeRelativePath(path.relative(packagePath, path.join(nestedDefinitionPath, typesPath))),
|
|
61
|
-
};
|
|
53
|
+
return findFileInPackage({
|
|
54
|
+
packagePath,
|
|
55
|
+
filePath: normalizeRelativePath(path.relative(packagePath, path.join(nestedDefinitionPath, entryPath))),
|
|
56
|
+
}, context);
|
|
62
57
|
}
|
|
63
58
|
else {
|
|
64
59
|
// If we can't find an entry, we should not include this in the exports map.
|
|
@@ -84,16 +79,6 @@ export async function findFileInPackage(options, context) {
|
|
|
84
79
|
}
|
|
85
80
|
}
|
|
86
81
|
}
|
|
87
|
-
// Try to resolve the typesPath
|
|
88
|
-
if (sourcePath && filePath) {
|
|
89
|
-
typesPath = filePath.replace(/\.js$/, '.d.ts');
|
|
90
|
-
if (!isInternal && !isFileSync(path.join(packagePath, typesPath))) {
|
|
91
|
-
typesPath = undefined;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
if (typesPath) {
|
|
95
|
-
result.typesPath = normalizeRelativePath(typesPath);
|
|
96
|
-
}
|
|
97
82
|
if (filePath) {
|
|
98
83
|
result.filePath = normalizeRelativePath(filePath);
|
|
99
84
|
}
|
|
@@ -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;
|
|
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,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C,QAAQ,CAAC,CAAC,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,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 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: Pick<CloudpackConfig, 'features'> },\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 const isInternal = !isExternalPackage(packagePath);\n const pathsToConsider = [originalPath];\n\n const definition = await context.packages.tryGet(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 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 return findFileInPackage(\n {\n packagePath,\n filePath: normalizeRelativePath(path.relative(packagePath, path.join(nestedDefinitionPath, entryPath))),\n },\n context,\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 if (filePath) {\n result.filePath = normalizeRelativePath(filePath);\n }\n\n if (sourcePath) {\n result.sourcePath = normalizeRelativePath(sourcePath);\n }\n\n return result;\n}\n"]}
|