@ms-cloudpack/package-utilities 7.0.0 → 7.0.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.
|
@@ -5,7 +5,7 @@ import { findFileInPackage } from './findFileInPackage.js';
|
|
|
5
5
|
*/
|
|
6
6
|
export async function addExportsMapEntry(options, context) {
|
|
7
7
|
const { exports, packagePath, condition = 'default' } = options;
|
|
8
|
-
const importPath =
|
|
8
|
+
const importPath = normalizeRelativePath(options.importPath);
|
|
9
9
|
const { filePath, sourcePath, typesPath = options.typesPath ? normalizeRelativePath(options.typesPath) : undefined, } = await findFileInPackage({
|
|
10
10
|
packagePath,
|
|
11
11
|
filePath: options.filePath || options.importPath || '',
|
|
@@ -40,18 +40,4 @@ export async function addExportsMapEntry(options, context) {
|
|
|
40
40
|
}
|
|
41
41
|
return true;
|
|
42
42
|
}
|
|
43
|
-
function makeSafeImportKey(key) {
|
|
44
|
-
if (!key || key === '' || key === '.') {
|
|
45
|
-
return '.';
|
|
46
|
-
}
|
|
47
|
-
// if the key starts with a slash, add a dot
|
|
48
|
-
if (key.startsWith('/')) {
|
|
49
|
-
key = '.' + key;
|
|
50
|
-
}
|
|
51
|
-
// if the key doesn't start with "./", add it
|
|
52
|
-
if (!key.startsWith('./')) {
|
|
53
|
-
key = './' + key;
|
|
54
|
-
}
|
|
55
|
-
return key;
|
|
56
|
-
}
|
|
57
43
|
//# sourceMappingURL=addExportsMapEntry.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"addExportsMapEntry.js","sourceRoot":"","sources":["../src/addExportsMapEntry.ts"],"names":[],"mappings":"AAEA,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,OAAuE;IAEvE,MAAM,EAAE,OAA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AG,CAAC,YAAY,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC,CAAC;QAErD,qEAAqE;QACrE,IAAI,OAAO,YAAY,KAAK,QAAQ,EAAE,CAAC;YACrC,YAAY,GAAI,OAAkD,CAAC,UAAU,CAAC,GAAG,EAAE,OAAO,EAAE,YAAY,EAAE,CAAC;QAC7G,CAAC;QAED,IAAI,SAAS,EAAE,CAAC;YACd,YAAY,CAAC,OAAO,CAAC,GAAG,SAAS,CAAC;QACpC,CAAC;QAED,IAAI,UAAU,EAAE,CAAC;YACf,YAAY,CAAC,QAAQ,CAAC,GAAG,UAAU,CAAC;QACtC,CAAC;QAED,mCAAmC;QACnC,YAAY,CAAC,SAAS,CAAC,GAAG,QAAQ,CAAC;IACrC,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import type { PackageDefinitionsCache } from '@ms-cloudpack/bundler-types';\nimport type { CloudpackConfig, PackageJsonExports } from '@ms-cloudpack/config-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 * Optional types path. If not provided, types will be discovered for internal packages that have source files.\n * This is useful mainly when converting the default import from a package.json that has explicit typings listed.\n */\n typesPath?: string;\n\n /**\n * The condition to add the entry for. (Example: \"import\", \"require\", \"browser\", \"types\") Defaults to \"default\"\n */\n condition?: string;\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: CloudpackConfig },\n): Promise<boolean> {\n const { exports, packagePath, condition = 'default' } = options;\n const importPath = normalizeRelativePath(options.importPath);\n const {\n filePath,\n sourcePath,\n typesPath = options.typesPath ? normalizeRelativePath(options.typesPath) : undefined,\n } = 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>>;\n\n // If this is the only entry we're adding, set it to a string to minimize the exports map.\n if (\n !typesPath &&\n !sourcePath &&\n condition === 'default' &&\n (!localExports[importPath] || typeof localExports[importPath] === 'string')\n ) {\n localExports[importPath] = filePath;\n } else {\n let exportsEntry = (localExports[importPath] ??= {});\n\n // Promote string-based exports into objects with default conditions.\n if (typeof exportsEntry === 'string') {\n exportsEntry = (exports as Record<string, Record<string, string>>)[importPath] = { default: exportsEntry };\n }\n\n if (typesPath) {\n exportsEntry['types'] = typesPath;\n }\n\n if (sourcePath) {\n exportsEntry['source'] = sourcePath;\n }\n\n // Add the entry for the condition.\n exportsEntry[condition] = filePath;\n }\n\n return true;\n}\n"]}
|