@ms-cloudpack/package-utilities 5.8.3 → 5.9.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/createImportMap.d.ts +1 -1
- package/lib/createImportMap.d.ts.map +1 -1
- package/lib/createImportMap.js +13 -20
- package/lib/createImportMap.js.map +1 -1
- package/lib/getResolvedFilePath.d.ts +14 -0
- package/lib/getResolvedFilePath.d.ts.map +1 -0
- package/lib/getResolvedFilePath.js +27 -0
- package/lib/getResolvedFilePath.js.map +1 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +2 -0
- package/lib/index.js.map +1 -1
- package/lib/shouldExternalizePackage.d.ts +12 -0
- package/lib/shouldExternalizePackage.d.ts.map +1 -0
- package/lib/shouldExternalizePackage.js +21 -0
- package/lib/shouldExternalizePackage.js.map +1 -0
- package/package.json +1 -1
package/lib/createImportMap.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { PackageDefinitionsCache } from '@ms-cloudpack/bundler-types';
|
|
2
2
|
import { type CloudpackConfig } from '@ms-cloudpack/config-types';
|
|
3
|
-
import type { ResolveMap } from './types/ResolveMap.js';
|
|
4
3
|
import type { PackageImportPaths } from './PackageImportPaths.js';
|
|
4
|
+
import type { ResolveMap } from './types/ResolveMap.js';
|
|
5
5
|
export interface ImportMap {
|
|
6
6
|
imports: Record<string, string>;
|
|
7
7
|
scopes?: Record<string, Record<string, string>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createImportMap.d.ts","sourceRoot":"","sources":["../src/createImportMap.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAC3E,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"createImportMap.d.ts","sourceRoot":"","sources":["../src/createImportMap.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAC3E,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAElE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAKlE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAGxD,MAAM,WAAW,SAAS;IACxB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;CACjD;AAED,MAAM,MAAM,sBAAsB,GAAG;IACnC,QAAQ,EAAE,uBAAuB,CAAC;IAClC,kBAAkB,CAAC,EAAE,kBAAkB,CAAC;IACxC,cAAc,EAAE,CAAC,WAAW,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IACzD,MAAM,EAAE,eAAe,CAAC;CACzB,CAAC;AAEF;;GAEG;AACH,wBAAsB,eAAe,CACnC,OAAO,EAAE;IACP,UAAU,EAAE,UAAU,CAAC;IACvB,eAAe,EAAE,MAAM,CAAC;IACxB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACxC,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB,EACD,OAAO,EAAE,sBAAsB,GAC9B,OAAO,CAAC,SAAS,CAAC,CAqCpB"}
|
package/lib/createImportMap.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {} from '@ms-cloudpack/config-types';
|
|
2
2
|
import { merge } from 'merge';
|
|
3
3
|
import { flattenExportsMap } from './flattenExportsMap.js';
|
|
4
|
-
import path from 'path';
|
|
5
4
|
import { getExportsMap } from './getExportsMap.js';
|
|
5
|
+
import { getResolvedFilePath } from './getResolvedFilePath.js';
|
|
6
6
|
import { isExternalPackage } from './isExternalPackage.js';
|
|
7
7
|
/**
|
|
8
8
|
* Given a resolve map and a bundleServerUrl, returns an import map to be used in the browser.
|
|
@@ -65,26 +65,19 @@ async function getImportMapFromEntry(params) {
|
|
|
65
65
|
const hash = hashPackages ? (isExternal ? `h-${await getPackageHash(entry.path)}/` : 'h-pending/') : '';
|
|
66
66
|
// Add the bundled entries to the import map, but prefer unbundled if the entry exists.
|
|
67
67
|
for (const [importPath, bundledFilePath] of Object.entries(bundledExportsMap)) {
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
resolvedFilePath = path.join(path.dirname(resolvedFilePath), path.basename(resolvedFilePath, ext) + (ext === '.mjs' ? '.js' : ext + '.js'));
|
|
81
|
-
}
|
|
82
|
-
// Plus signs should be replaced with underscores.
|
|
83
|
-
resolvedFilePath = resolvedFilePath.replace(/\+/g, '_');
|
|
68
|
+
const resolvedFilePath = getResolvedFilePath({
|
|
69
|
+
entryPath: importPath,
|
|
70
|
+
isExternal,
|
|
71
|
+
unbundledExportsMap,
|
|
72
|
+
bundledFilePath,
|
|
73
|
+
bundledPrefix: `${hash}${cacheBuster}bundled/`,
|
|
74
|
+
unbundledPrefix: `${hash}${cacheBuster}unbundled/`,
|
|
75
|
+
});
|
|
76
|
+
if (resolvedFilePath !== undefined) {
|
|
77
|
+
const resolvedImportPath = importPath.replace('.', `${name}`);
|
|
78
|
+
packageImportPaths?.add(entry.path, resolvedImportPath);
|
|
79
|
+
importMap[resolvedImportPath] = new URL(resolvedFilePath, baseUrl).href;
|
|
84
80
|
}
|
|
85
|
-
const resolvedImportPath = importPath.replace('.', `${name}`);
|
|
86
|
-
packageImportPaths?.add(entry.path, resolvedImportPath);
|
|
87
|
-
importMap[resolvedImportPath] = new URL(resolvedFilePath, baseUrl).href;
|
|
88
81
|
}
|
|
89
82
|
// Finally add a fallback for all other unexpected bundle entries. (Note, this should point to a script
|
|
90
83
|
// which logs this as an error to the user and offers a way to add the entry to exports overrides.)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createImportMap.js","sourceRoot":"","sources":["../src/createImportMap.ts"],"names":[],"mappings":"AACA,OAAO,EAAwB,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"createImportMap.js","sourceRoot":"","sources":["../src/createImportMap.ts"],"names":[],"mappings":"AACA,OAAO,EAAwB,MAAM,4BAA4B,CAAC;AAClE,OAAO,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AAE9B,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAgB3D;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,OAMC,EACD,OAA+B;IAE/B,MAAM,EAAE,UAAU,EAAE,eAAe,EAAE,cAAc,GAAG,CAAC,EAAE,cAAc,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC;IAClG,MAAM,EAAE,kBAAkB,EAAE,GAAG,OAAO,CAAC;IACvC,MAAM,SAAS,GAAc;QAC3B,OAAO,EAAE,EAAE;KACZ,CAAC;IAEF,kBAAkB,EAAE,KAAK,EAAE,CAAC;IAE5B,KAAK,MAAM,YAAY,IAAI,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE,CAAC;QACrD,KAAK,CACH,SAAS,CAAC,OAAO,EACjB,MAAM,qBAAqB,CAAC;YAC1B,OAAO,EAAE,EAAE,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,cAAc,EAAE,cAAc,EAAE,YAAY,EAAE;YAC/F,OAAO;SACR,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E,CAAC;QAC9E,MAAM,gBAAgB,GAAG,mBAAmB,CAAC;YAC3C,SAAS,EAAE,UAAU;YACrB,UAAU;YACV,mBAAmB;YACnB,eAAe;YACf,aAAa,EAAE,GAAG,IAAI,GAAG,WAAW,UAAU;YAC9C,eAAe,EAAE,GAAG,IAAI,GAAG,WAAW,YAAY;SACnD,CAAC,CAAC;QAEH,IAAI,gBAAgB,KAAK,SAAS,EAAE,CAAC;YACnC,MAAM,kBAAkB,GAAG,UAAU,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,IAAI,EAAE,CAAC,CAAC;YAC9D,kBAAkB,EAAE,GAAG,CAAC,KAAK,CAAC,IAAI,EAAE,kBAAkB,CAAC,CAAC;YACxD,SAAS,CAAC,kBAAkB,CAAC,GAAG,IAAI,GAAG,CAAC,gBAAgB,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC;QAC1E,CAAC;IACH,CAAC;IAED,uGAAuG;IACvG,mGAAmG;IACnG,2DAA2D;IAE3D,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["import type { PackageDefinitionsCache } from '@ms-cloudpack/bundler-types';\nimport { type CloudpackConfig } from '@ms-cloudpack/config-types';\nimport { merge } from 'merge';\nimport type { PackageImportPaths } from './PackageImportPaths.js';\nimport { flattenExportsMap } from './flattenExportsMap.js';\nimport { getExportsMap } from './getExportsMap.js';\nimport { getResolvedFilePath } from './getResolvedFilePath.js';\nimport { isExternalPackage } from './isExternalPackage.js';\nimport type { ResolveMap } from './types/ResolveMap.js';\nimport type { ResolveMapEntry } from './types/ResolveMapEntry.js';\n\nexport interface ImportMap {\n imports: Record<string, string>;\n scopes?: Record<string, Record<string, string>>;\n}\n\nexport type CreateImportMapContext = {\n packages: PackageDefinitionsCache;\n packageImportPaths?: PackageImportPaths;\n getPackageHash: (packagePath: string) => Promise<string>;\n config: CloudpackConfig;\n};\n\n/**\n * Given a resolve map and a bundleServerUrl, returns an import map to be used in the browser.\n */\nexport async function createImportMap(\n options: {\n resolveMap: ResolveMap;\n bundleServerUrl: string;\n sessionVersion?: number;\n targetVersions?: Record<string, number>;\n hashPackages?: boolean;\n },\n context: CreateImportMapContext,\n): Promise<ImportMap> {\n const { resolveMap, bundleServerUrl, sessionVersion = 0, targetVersions, hashPackages } = options;\n const { packageImportPaths } = context;\n const importMap: ImportMap = {\n imports: {},\n };\n\n packageImportPaths?.clear();\n\n for (const resolveEntry of Object.values(resolveMap)) {\n merge(\n importMap.imports,\n await getImportMapFromEntry({\n options: { entry: resolveEntry, bundleServerUrl, targetVersions, sessionVersion, hashPackages },\n context,\n }),\n );\n\n if (resolveEntry.scopedVersions) {\n // Initialize scopes\n importMap.scopes ??= {};\n\n for (const scopedEntry of Object.values(resolveEntry.scopedVersions)) {\n const importMapForEntry = await getImportMapFromEntry({\n options: { entry: scopedEntry, bundleServerUrl, sessionVersion, targetVersions, hashPackages },\n context,\n });\n\n for (const requiredById of Object.keys(scopedEntry.requiredBy)) {\n const scopes = (importMap.scopes[`${bundleServerUrl}/${requiredById}/`] ??= {});\n merge(scopes, importMapForEntry);\n }\n }\n }\n }\n\n return importMap;\n}\n\nasync function getImportMapFromEntry(params: {\n options: {\n entry: ResolveMapEntry;\n bundleServerUrl: string;\n sessionVersion: number;\n targetVersions?: Record<string, number>;\n hashPackages?: boolean;\n };\n context: CreateImportMapContext;\n}): Promise<Record<string, string>> {\n const { options, context } = params;\n const { entry, bundleServerUrl, sessionVersion, targetVersions, hashPackages } = options;\n const { name } = entry;\n const { packages, packageImportPaths, getPackageHash, config } = context;\n const importMap: Record<string, string> = {};\n const definition = await packages.get(entry.path);\n const exportsMap = await getExportsMap({ packagePath: entry.path }, { packages, config });\n\n if (\n !definition ||\n !definition.version ||\n !exportsMap ||\n Object.keys(exportsMap).length === 0 ||\n name.startsWith('@types/')\n ) {\n return importMap;\n }\n\n // Get both the unbundled entries from the exports map\n const unbundledExportsMap = flattenExportsMap(exportsMap, {\n conditions: ['browser-esm'],\n requiredConditions: ['browser-esm'],\n });\n const bundledExportsMap = flattenExportsMap(exportsMap);\n const packagePrefix = `${name}@${entry.version}/`;\n const baseUrl = `${bundleServerUrl}/${packagePrefix}`;\n const isExternal = isExternalPackage(entry.path);\n const targetVersion = targetVersions?.[entry.path];\n const cacheBuster = `v${sessionVersion ?? 0}${targetVersion ? `.${targetVersion}` : ''}/`;\n const hash = hashPackages ? (isExternal ? `h-${await getPackageHash(entry.path)}/` : 'h-pending/') : '';\n\n // Add the bundled entries to the import map, but prefer unbundled if the entry exists.\n for (const [importPath, bundledFilePath] of Object.entries(bundledExportsMap)) {\n const resolvedFilePath = getResolvedFilePath({\n entryPath: importPath,\n isExternal,\n unbundledExportsMap,\n bundledFilePath,\n bundledPrefix: `${hash}${cacheBuster}bundled/`,\n unbundledPrefix: `${hash}${cacheBuster}unbundled/`,\n });\n\n if (resolvedFilePath !== undefined) {\n const resolvedImportPath = importPath.replace('.', `${name}`);\n packageImportPaths?.add(entry.path, resolvedImportPath);\n importMap[resolvedImportPath] = new URL(resolvedFilePath, baseUrl).href;\n }\n }\n\n // Finally add a fallback for all other unexpected bundle entries. (Note, this should point to a script\n // which logs this as an error to the user and offers a way to add the entry to exports overrides.)\n // importMap[definition.name + '/'] = baseUrl + 'missing/';\n\n return importMap;\n}\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get the resolved bundled or unbundled file path as appropriate, with the correct extension.
|
|
3
|
+
* @returns The path, or undefined if a bundled path was requested and the entry is a .d.ts file
|
|
4
|
+
* (which doesn't exist at runtime).
|
|
5
|
+
*/
|
|
6
|
+
export declare function getResolvedFilePath(params: {
|
|
7
|
+
entryPath: string;
|
|
8
|
+
isExternal: boolean;
|
|
9
|
+
unbundledExportsMap: Record<string, string>;
|
|
10
|
+
bundledFilePath: string;
|
|
11
|
+
bundledPrefix?: string;
|
|
12
|
+
unbundledPrefix?: string;
|
|
13
|
+
}): string | undefined;
|
|
14
|
+
//# sourceMappingURL=getResolvedFilePath.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getResolvedFilePath.d.ts","sourceRoot":"","sources":["../src/getResolvedFilePath.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE;IAC1C,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,OAAO,CAAC;IACpB,mBAAmB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC5C,eAAe,EAAE,MAAM,CAAC;IACxB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B,GAAG,MAAM,GAAG,SAAS,CAmCrB"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
/**
|
|
3
|
+
* Get the resolved bundled or unbundled file path as appropriate, with the correct extension.
|
|
4
|
+
* @returns The path, or undefined if a bundled path was requested and the entry is a .d.ts file
|
|
5
|
+
* (which doesn't exist at runtime).
|
|
6
|
+
*/
|
|
7
|
+
export function getResolvedFilePath(params) {
|
|
8
|
+
const { entryPath, isExternal, unbundledExportsMap, bundledFilePath, bundledPrefix = '', unbundledPrefix = '', } = params;
|
|
9
|
+
const unbundledFilePath = isExternal ? unbundledExportsMap[entryPath] : undefined;
|
|
10
|
+
let resolvedFilePath = unbundledFilePath ? unbundledPrefix + unbundledFilePath : bundledPrefix + bundledFilePath;
|
|
11
|
+
const ext = path.extname(resolvedFilePath);
|
|
12
|
+
// For bundled files:
|
|
13
|
+
if (!unbundledFilePath) {
|
|
14
|
+
// Ignore .d.ts entries
|
|
15
|
+
if (resolvedFilePath.endsWith('.d.ts')) {
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
18
|
+
// We always expect responses to come back as javascript (.js extensions.)
|
|
19
|
+
if (ext !== '.js') {
|
|
20
|
+
resolvedFilePath = path.join(path.dirname(resolvedFilePath), path.basename(resolvedFilePath, ext) + (ext === '.mjs' ? '.js' : ext + '.js'));
|
|
21
|
+
}
|
|
22
|
+
// Plus signs should be replaced with underscores.
|
|
23
|
+
resolvedFilePath = resolvedFilePath.replace(/\+/g, '_');
|
|
24
|
+
}
|
|
25
|
+
return resolvedFilePath;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=getResolvedFilePath.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getResolvedFilePath.js","sourceRoot":"","sources":["../src/getResolvedFilePath.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CAAC,MAOnC;IACC,MAAM,EACJ,SAAS,EACT,UAAU,EACV,mBAAmB,EACnB,eAAe,EACf,aAAa,GAAG,EAAE,EAClB,eAAe,GAAG,EAAE,GACrB,GAAG,MAAM,CAAC;IAEX,MAAM,iBAAiB,GAAG,UAAU,CAAC,CAAC,CAAC,mBAAmB,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAClF,IAAI,gBAAgB,GAAG,iBAAiB,CAAC,CAAC,CAAC,eAAe,GAAG,iBAAiB,CAAC,CAAC,CAAC,aAAa,GAAG,eAAe,CAAC;IAEjH,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC;IAE3C,qBAAqB;IACrB,IAAI,CAAC,iBAAiB,EAAE,CAAC;QACvB,uBAAuB;QACvB,IAAI,gBAAgB,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;YACvC,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,0EAA0E;QAC1E,IAAI,GAAG,KAAK,KAAK,EAAE,CAAC;YAClB,gBAAgB,GAAG,IAAI,CAAC,IAAI,CAC1B,IAAI,CAAC,OAAO,CAAC,gBAAgB,CAAC,EAC9B,IAAI,CAAC,QAAQ,CAAC,gBAAgB,EAAE,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,GAAG,KAAK,CAAC,CAC9E,CAAC;QACJ,CAAC;QAED,kDAAkD;QAClD,gBAAgB,GAAG,gBAAgB,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IAC1D,CAAC;IAED,OAAO,gBAAgB,CAAC;AAC1B,CAAC","sourcesContent":["import path from 'path';\n\n/**\n * Get the resolved bundled or unbundled file path as appropriate, with the correct extension.\n * @returns The path, or undefined if a bundled path was requested and the entry is a .d.ts file\n * (which doesn't exist at runtime).\n */\nexport function getResolvedFilePath(params: {\n entryPath: string;\n isExternal: boolean;\n unbundledExportsMap: Record<string, string>;\n bundledFilePath: string;\n bundledPrefix?: string;\n unbundledPrefix?: string;\n}): string | undefined {\n const {\n entryPath,\n isExternal,\n unbundledExportsMap,\n bundledFilePath,\n bundledPrefix = '',\n unbundledPrefix = '',\n } = params;\n\n const unbundledFilePath = isExternal ? unbundledExportsMap[entryPath] : undefined;\n let resolvedFilePath = unbundledFilePath ? unbundledPrefix + unbundledFilePath : bundledPrefix + bundledFilePath;\n\n const ext = path.extname(resolvedFilePath);\n\n // For bundled files:\n if (!unbundledFilePath) {\n // Ignore .d.ts entries\n if (resolvedFilePath.endsWith('.d.ts')) {\n return undefined;\n }\n\n // We always expect responses to come back as javascript (.js extensions.)\n if (ext !== '.js') {\n resolvedFilePath = path.join(\n path.dirname(resolvedFilePath),\n path.basename(resolvedFilePath, ext) + (ext === '.mjs' ? '.js' : ext + '.js'),\n );\n }\n\n // Plus signs should be replaced with underscores.\n resolvedFilePath = resolvedFilePath.replace(/\\+/g, '_');\n }\n\n return resolvedFilePath;\n}\n"]}
|
package/lib/index.d.ts
CHANGED
|
@@ -20,4 +20,6 @@ export { findFileInPackage, type FindFileInPackageOptions, type FindFileInPackag
|
|
|
20
20
|
export { getVersion } from './getVersion.js';
|
|
21
21
|
export { getDependencies } from './getDependencies.js';
|
|
22
22
|
export { findProjectRoot } from './findProjectRoot.js';
|
|
23
|
+
export { shouldExternalizePackage } from './shouldExternalizePackage.js';
|
|
24
|
+
export { getResolvedFilePath } from './getResolvedFilePath.js';
|
|
23
25
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAG7D,OAAO,EAAE,gBAAgB,EAAE,MAAM,wCAAwC,CAAC;AAC1E,YAAY,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACxD,YAAY,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAClE,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,YAAY,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,MAAM,uCAAuC,CAAC;AAC1G,OAAO,EAAE,eAAe,EAAE,MAAM,uCAAuC,CAAC;AACxE,YAAY,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAGxD,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,kBAAkB,EAAE,KAAK,yBAAyB,EAAE,MAAM,yBAAyB,CAAC;AAC7F,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAGnD,OAAO,EAAE,eAAe,EAAE,KAAK,SAAS,EAAE,KAAK,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAGpG,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAGzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAG7D,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAGvC,OAAO,EAAE,gBAAgB,EAAE,KAAK,UAAU,EAAE,M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,EAAE,MAAM,yBAAyB,CAAC;AAG7D,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAGvC,OAAO,EAAE,gBAAgB,EAAE,KAAK,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAC1E,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,iBAAiB,EAAE,KAAK,wBAAwB,EAAE,KAAK,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AACxH,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AACzE,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC"}
|
package/lib/index.js
CHANGED
|
@@ -24,4 +24,6 @@ export { findFileInPackage } from './findFileInPackage.js';
|
|
|
24
24
|
export { getVersion } from './getVersion.js';
|
|
25
25
|
export { getDependencies } from './getDependencies.js';
|
|
26
26
|
export { findProjectRoot } from './findProjectRoot.js';
|
|
27
|
+
export { shouldExternalizePackage } from './shouldExternalizePackage.js';
|
|
28
|
+
export { getResolvedFilePath } from './getResolvedFilePath.js';
|
|
27
29
|
//# sourceMappingURL=index.js.map
|
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,yBAAyB,CAAC;AAE7D,sBAAsB;AACtB,OAAO,EAAE,gBAAgB,EAAE,MAAM,wCAAwC,CAAC;AAG1E,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAE/D,OAAO,EAAE,eAAe,EAAE,MAAM,uCAAuC,CAAC;AAGxE,kCAAkC;AAClC,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,kBAAkB,EAAkC,MAAM,yBAAyB,CAAC;AAC7F,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,qBAAqB;AACrB,OAAO,EAAE,eAAe,EAA+C,MAAM,sBAAsB,CAAC;AAEpG,oBAAoB;AACpB,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEzD,uBAAuB;AACvB,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAE7D,8BAA8B;AAC9B,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,0BAA0B;AAC1B,OAAO,EAAE,gBAAgB,EAAmB,MAAM,uBAAuB,CAAC;AAC1E,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,iBAAiB,EAA+D,MAAM,wBAAwB,CAAC;AACxH,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC","sourcesContent":["// Package definition parsing\nexport { PackageDefinitions } from './PackageDefinitions.js';\n\n// ResolveMap creation\nexport { createResolveMap } from './createResolveMap/createResolveMap.js';\nexport type { ResolveMap } from './types/ResolveMap.js';\nexport type { ResolveMapEntry } from './types/ResolveMapEntry.js';\nexport { findResolveMapEntry } from './findResolveMapEntry.js';\nexport type { DiffResolveMapsChanges, DiffResolveMapsStats } from './createResolveMap/diffResolveMaps.js';\nexport { diffResolveMaps } from './createResolveMap/diffResolveMaps.js';\nexport type { LinkedPath } from './types/LinkedPath.js';\n\n// ExportsMap parsing and creation\nexport { flattenExportsMap } from './flattenExportsMap.js';\nexport { createExportsMap } from './createExportsMap.js';\nexport { addExportsMapEntry, type AddExportsMapEntryOptions } from './addExportsMapEntry.js';\nexport { getExportsMap } from './getExportsMap.js';\n\n// ImportMap creation\nexport { createImportMap, type ImportMap, type CreateImportMapContext } from './createImportMap.js';\n\n// ImportMap hashing\nexport { addImportMapHash } from './addImportMapHash.js';\n\n// Import paths caching\nexport { PackageImportPaths } from './PackageImportPaths.js';\n\n// Import resolution utilities\nexport { resolve } from './resolve.js';\n\n// Other package utilities\nexport { detectModuleType, type ModuleType } from './detectModuleType.js';\nexport { isExternalPackage } from './isExternalPackage.js';\nexport { findFileInPackage, type FindFileInPackageOptions, type FindFileInPackageResult } from './findFileInPackage.js';\nexport { getVersion } from './getVersion.js';\nexport { getDependencies } from './getDependencies.js';\nexport { findProjectRoot } from './findProjectRoot.js';\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,6BAA6B;AAC7B,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAE7D,sBAAsB;AACtB,OAAO,EAAE,gBAAgB,EAAE,MAAM,wCAAwC,CAAC;AAG1E,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAE/D,OAAO,EAAE,eAAe,EAAE,MAAM,uCAAuC,CAAC;AAGxE,kCAAkC;AAClC,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,kBAAkB,EAAkC,MAAM,yBAAyB,CAAC;AAC7F,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,qBAAqB;AACrB,OAAO,EAAE,eAAe,EAA+C,MAAM,sBAAsB,CAAC;AAEpG,oBAAoB;AACpB,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEzD,uBAAuB;AACvB,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAE7D,8BAA8B;AAC9B,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,0BAA0B;AAC1B,OAAO,EAAE,gBAAgB,EAAmB,MAAM,uBAAuB,CAAC;AAC1E,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,iBAAiB,EAA+D,MAAM,wBAAwB,CAAC;AACxH,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AACzE,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC","sourcesContent":["// Package definition parsing\nexport { PackageDefinitions } from './PackageDefinitions.js';\n\n// ResolveMap creation\nexport { createResolveMap } from './createResolveMap/createResolveMap.js';\nexport type { ResolveMap } from './types/ResolveMap.js';\nexport type { ResolveMapEntry } from './types/ResolveMapEntry.js';\nexport { findResolveMapEntry } from './findResolveMapEntry.js';\nexport type { DiffResolveMapsChanges, DiffResolveMapsStats } from './createResolveMap/diffResolveMaps.js';\nexport { diffResolveMaps } from './createResolveMap/diffResolveMaps.js';\nexport type { LinkedPath } from './types/LinkedPath.js';\n\n// ExportsMap parsing and creation\nexport { flattenExportsMap } from './flattenExportsMap.js';\nexport { createExportsMap } from './createExportsMap.js';\nexport { addExportsMapEntry, type AddExportsMapEntryOptions } from './addExportsMapEntry.js';\nexport { getExportsMap } from './getExportsMap.js';\n\n// ImportMap creation\nexport { createImportMap, type ImportMap, type CreateImportMapContext } from './createImportMap.js';\n\n// ImportMap hashing\nexport { addImportMapHash } from './addImportMapHash.js';\n\n// Import paths caching\nexport { PackageImportPaths } from './PackageImportPaths.js';\n\n// Import resolution utilities\nexport { resolve } from './resolve.js';\n\n// Other package utilities\nexport { detectModuleType, type ModuleType } from './detectModuleType.js';\nexport { isExternalPackage } from './isExternalPackage.js';\nexport { findFileInPackage, type FindFileInPackageOptions, type FindFileInPackageResult } from './findFileInPackage.js';\nexport { getVersion } from './getVersion.js';\nexport { getDependencies } from './getDependencies.js';\nexport { findProjectRoot } from './findProjectRoot.js';\nexport { shouldExternalizePackage } from './shouldExternalizePackage.js';\nexport { getResolvedFilePath } from './getResolvedFilePath.js';\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Determines if a package should be externalized from the bundle.
|
|
3
|
+
* Don't externalize inlined packages, or node builtins, or absolute paths, or relative paths.
|
|
4
|
+
*/
|
|
5
|
+
export declare function shouldExternalizePackage({ id, inlined, external, polyfills, shouldInlineNodeBuiltins, }: {
|
|
6
|
+
id: string;
|
|
7
|
+
inlined?: string[];
|
|
8
|
+
external?: string[];
|
|
9
|
+
polyfills?: Set<string>;
|
|
10
|
+
shouldInlineNodeBuiltins: boolean;
|
|
11
|
+
}): boolean;
|
|
12
|
+
//# sourceMappingURL=shouldExternalizePackage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shouldExternalizePackage.d.ts","sourceRoot":"","sources":["../src/shouldExternalizePackage.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,EACvC,EAAE,EACF,OAAO,EACP,QAAQ,EACR,SAAS,EACT,wBAAwB,GACzB,EAAE;IACD,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,SAAS,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IACxB,wBAAwB,EAAE,OAAO,CAAC;CACnC,GAAG,OAAO,CAOV"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import { isBuiltin } from 'module';
|
|
3
|
+
/**
|
|
4
|
+
* Determines if a package should be externalized from the bundle.
|
|
5
|
+
* Don't externalize inlined packages, or node builtins, or absolute paths, or relative paths.
|
|
6
|
+
*/
|
|
7
|
+
export function shouldExternalizePackage({ id, inlined, external, polyfills, shouldInlineNodeBuiltins, }) {
|
|
8
|
+
return !(inlined?.includes(id) ||
|
|
9
|
+
(shouldInlineNodeBuiltins && isInlinedNodeBuiltin(id, external, polyfills)) ||
|
|
10
|
+
path.isAbsolute(id) ||
|
|
11
|
+
isRelative(id));
|
|
12
|
+
}
|
|
13
|
+
// We should inline node builtins that are handled by the nodePolyfills plugin.
|
|
14
|
+
// Except if the dependency is listed as external.
|
|
15
|
+
function isInlinedNodeBuiltin(id, external, polyfills) {
|
|
16
|
+
return (isBuiltin(id) || polyfills?.has(id)) && !external?.find((ex) => id.startsWith(ex));
|
|
17
|
+
}
|
|
18
|
+
function isRelative(id) {
|
|
19
|
+
return id.startsWith('/') || id.startsWith('./') || id.startsWith('../') || id === '.' || id === '..';
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=shouldExternalizePackage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shouldExternalizePackage.js","sourceRoot":"","sources":["../src/shouldExternalizePackage.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAEnC;;;GAGG;AACH,MAAM,UAAU,wBAAwB,CAAC,EACvC,EAAE,EACF,OAAO,EACP,QAAQ,EACR,SAAS,EACT,wBAAwB,GAOzB;IACC,OAAO,CAAC,CACN,OAAO,EAAE,QAAQ,CAAC,EAAE,CAAC;QACrB,CAAC,wBAAwB,IAAI,oBAAoB,CAAC,EAAE,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC;QAC3E,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC;QACnB,UAAU,CAAC,EAAE,CAAC,CACf,CAAC;AACJ,CAAC;AAED,+EAA+E;AAC/E,kDAAkD;AAClD,SAAS,oBAAoB,CAAC,EAAU,EAAE,QAAmB,EAAE,SAAuB;IACpF,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC,IAAI,SAAS,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC,CAAC;AAC7F,CAAC;AAED,SAAS,UAAU,CAAC,EAAU;IAC5B,OAAO,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,GAAG,IAAI,EAAE,KAAK,IAAI,CAAC;AACxG,CAAC","sourcesContent":["import path from 'path';\nimport { isBuiltin } from 'module';\n\n/**\n * Determines if a package should be externalized from the bundle.\n * Don't externalize inlined packages, or node builtins, or absolute paths, or relative paths.\n */\nexport function shouldExternalizePackage({\n id,\n inlined,\n external,\n polyfills,\n shouldInlineNodeBuiltins,\n}: {\n id: string;\n inlined?: string[];\n external?: string[];\n polyfills?: Set<string>;\n shouldInlineNodeBuiltins: boolean;\n}): boolean {\n return !(\n inlined?.includes(id) ||\n (shouldInlineNodeBuiltins && isInlinedNodeBuiltin(id, external, polyfills)) ||\n path.isAbsolute(id) ||\n isRelative(id)\n );\n}\n\n// We should inline node builtins that are handled by the nodePolyfills plugin.\n// Except if the dependency is listed as external.\nfunction isInlinedNodeBuiltin(id: string, external?: string[], polyfills?: Set<string>) {\n return (isBuiltin(id) || polyfills?.has(id)) && !external?.find((ex) => id.startsWith(ex));\n}\n\nfunction isRelative(id: string) {\n return id.startsWith('/') || id.startsWith('./') || id.startsWith('../') || id === '.' || id === '..';\n}\n"]}
|