@ms-cloudpack/bundler-utilities 0.2.19 → 0.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.
|
@@ -1,12 +1,54 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Determines if a package should be externalized from the bundle.
|
|
3
|
-
* Don't externalize inlined packages, node builtins, absolute paths,
|
|
3
|
+
* Don't externalize inlined packages, node builtins, absolute paths, relative paths,
|
|
4
|
+
* or dependencies of inlined dependencies except if they are explicitly marked as external.
|
|
5
|
+
*
|
|
6
|
+
* @param params - The parameters for the externalization check, e.g.
|
|
7
|
+
* `{
|
|
8
|
+
* inputPath: "/app",
|
|
9
|
+
* id: "/app/src/about.tsx",
|
|
10
|
+
* parent: "/app",
|
|
11
|
+
* inlined: ["foo"],
|
|
12
|
+
* external: ["bar", "baz"],
|
|
13
|
+
* polyfills: new Set(["global"]),
|
|
14
|
+
* shouldInlineNodeBuiltins: false,
|
|
15
|
+
* };`
|
|
4
16
|
*/
|
|
5
17
|
export declare function shouldExternalizePackage(params: {
|
|
18
|
+
/**
|
|
19
|
+
* The absolute input path for the entry points to be bundled.
|
|
20
|
+
*/
|
|
21
|
+
inputPath: string;
|
|
22
|
+
/**
|
|
23
|
+
* The module ID (import path) being evaluated for externalization.
|
|
24
|
+
* This can be a package name or a relative/absolute path.
|
|
25
|
+
*/
|
|
6
26
|
id: string;
|
|
27
|
+
/**
|
|
28
|
+
* The absolute file path of the module importing this dependency.
|
|
29
|
+
* Used to determine if the import is coming from outside the package.
|
|
30
|
+
* If it is undefined, the import is considered to be from the same package (this is common in Rollup).
|
|
31
|
+
*/
|
|
32
|
+
parent?: string;
|
|
33
|
+
/**
|
|
34
|
+
* List of dependencies which should be explicitly inlined rather than externalized.
|
|
35
|
+
* These will always be bundled with the package regardless of other settings.
|
|
36
|
+
*/
|
|
7
37
|
inlined?: string[];
|
|
38
|
+
/**
|
|
39
|
+
* List of dependencies which should be explicitly externalized.
|
|
40
|
+
* These will never be bundled with the package.
|
|
41
|
+
*/
|
|
8
42
|
external?: string[];
|
|
43
|
+
/**
|
|
44
|
+
* Set of polyfill package names that should be inlined instead of externalized
|
|
45
|
+
* when used as replacements for Node.js built-in modules in browser bundles.
|
|
46
|
+
*/
|
|
9
47
|
polyfills?: Set<string>;
|
|
48
|
+
/**
|
|
49
|
+
* Whether Node.js built-in modules should be inlined (with polyfills) rather than externalized.
|
|
50
|
+
* When true, modules like 'fs' or 'path' will be replaced with browser-compatible versions.
|
|
51
|
+
*/
|
|
10
52
|
shouldInlineNodeBuiltins: boolean;
|
|
11
53
|
}): boolean;
|
|
12
54
|
//# sourceMappingURL=shouldExternalizePackage.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shouldExternalizePackage.d.ts","sourceRoot":"","sources":["../src/shouldExternalizePackage.ts"],"names":[],"mappings":"AAIA
|
|
1
|
+
{"version":3,"file":"shouldExternalizePackage.d.ts","sourceRoot":"","sources":["../src/shouldExternalizePackage.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE;IAC/C;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAClB;;;OAGG;IACH,EAAE,EAAE,MAAM,CAAC;IACX;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB;;;OAGG;IACH,SAAS,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IACxB;;;OAGG;IACH,wBAAwB,EAAE,OAAO,CAAC;CACnC,GAAG,OAAO,CAmBV"}
|
|
@@ -3,22 +3,47 @@ import { isBuiltin } from 'module';
|
|
|
3
3
|
import path from 'path';
|
|
4
4
|
/**
|
|
5
5
|
* Determines if a package should be externalized from the bundle.
|
|
6
|
-
* Don't externalize inlined packages, node builtins, absolute paths,
|
|
6
|
+
* Don't externalize inlined packages, node builtins, absolute paths, relative paths,
|
|
7
|
+
* or dependencies of inlined dependencies except if they are explicitly marked as external.
|
|
8
|
+
*
|
|
9
|
+
* @param params - The parameters for the externalization check, e.g.
|
|
10
|
+
* `{
|
|
11
|
+
* inputPath: "/app",
|
|
12
|
+
* id: "/app/src/about.tsx",
|
|
13
|
+
* parent: "/app",
|
|
14
|
+
* inlined: ["foo"],
|
|
15
|
+
* external: ["bar", "baz"],
|
|
16
|
+
* polyfills: new Set(["global"]),
|
|
17
|
+
* shouldInlineNodeBuiltins: false,
|
|
18
|
+
* };`
|
|
7
19
|
*/
|
|
8
20
|
export function shouldExternalizePackage(params) {
|
|
9
|
-
const { id, inlined, external, polyfills, shouldInlineNodeBuiltins } = params;
|
|
10
|
-
|
|
21
|
+
const { inputPath, id, parent, inlined, external, polyfills, shouldInlineNodeBuiltins } = params;
|
|
22
|
+
const isExternalPackage = isExternal(id, external);
|
|
23
|
+
return !(
|
|
24
|
+
// We should inline node builtins that are handled by the nodePolyfills plugin.
|
|
25
|
+
// Except if the dependency is listed as external.
|
|
26
|
+
((shouldInlineNodeBuiltins && isInlinedNodeBuiltin(id, polyfills) && !isExternalPackage) ||
|
|
11
27
|
path.isAbsolute(id) ||
|
|
12
28
|
isRelative(id) ||
|
|
13
29
|
// The length check ensures that parseImportString is only called when there are inlined deps
|
|
14
|
-
(inlined?.length && inlined.includes(parseImportString(id).packageName))
|
|
30
|
+
(inlined?.length && inlined.includes(parseImportString(id).packageName)) ||
|
|
31
|
+
// A file outside of the package is doing this import, so we should inline the nested dependencies.
|
|
32
|
+
// Except if the dependency is listed as external.
|
|
33
|
+
(isNestedDependency(inputPath, parent) && !isExternalPackage)));
|
|
15
34
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
function isInlinedNodeBuiltin(id, external, polyfills) {
|
|
19
|
-
return (isBuiltin(id) || !!polyfills?.has(id)) && !external?.find((ex) => id.startsWith(ex));
|
|
35
|
+
function isInlinedNodeBuiltin(id, polyfills) {
|
|
36
|
+
return isBuiltin(id) || !!polyfills?.has(id);
|
|
20
37
|
}
|
|
21
38
|
function isRelative(id) {
|
|
22
39
|
return id.startsWith('/') || id.startsWith('./') || id.startsWith('../') || id === '.' || id === '..';
|
|
23
40
|
}
|
|
41
|
+
// Check if the import comes from an inlined dependency.
|
|
42
|
+
function isNestedDependency(inputPath, parent) {
|
|
43
|
+
const relativeParentPath = parent ? path.relative(inputPath, parent) : undefined;
|
|
44
|
+
return !!(relativeParentPath?.startsWith('..') || relativeParentPath?.includes('node_modules'));
|
|
45
|
+
}
|
|
46
|
+
function isExternal(id, external) {
|
|
47
|
+
return !!external?.find((ex) => id.startsWith(ex));
|
|
48
|
+
}
|
|
24
49
|
//# sourceMappingURL=shouldExternalizePackage.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shouldExternalizePackage.js","sourceRoot":"","sources":["../src/shouldExternalizePackage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AACtE,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACnC,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB
|
|
1
|
+
{"version":3,"file":"shouldExternalizePackage.js","sourceRoot":"","sources":["../src/shouldExternalizePackage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AACtE,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACnC,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,wBAAwB,CAAC,MAoCxC;IACC,MAAM,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,wBAAwB,EAAE,GAAG,MAAM,CAAC;IAEjG,MAAM,iBA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;AAClG,CAAC;AAED,SAAS,UAAU,CAAC,EAAU,EAAE,QAA8B;IAC5D,OAAO,CAAC,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC,CAAC;AACrD,CAAC","sourcesContent":["import { parseImportString } from '@ms-cloudpack/path-string-parsing';\nimport { isBuiltin } from 'module';\nimport path from 'path';\n\n/**\n * Determines if a package should be externalized from the bundle.\n * Don't externalize inlined packages, node builtins, absolute paths, relative paths,\n * or dependencies of inlined dependencies except if they are explicitly marked as external.\n *\n * @param params - The parameters for the externalization check, e.g.\n * `{\n * inputPath: \"/app\",\n * id: \"/app/src/about.tsx\",\n * parent: \"/app\",\n * inlined: [\"foo\"],\n * external: [\"bar\", \"baz\"],\n * polyfills: new Set([\"global\"]),\n * shouldInlineNodeBuiltins: false,\n * };`\n */\nexport function shouldExternalizePackage(params: {\n /**\n * The absolute input path for the entry points to be bundled.\n */\n inputPath: string;\n /**\n * The module ID (import path) being evaluated for externalization.\n * This can be a package name or a relative/absolute path.\n */\n id: string;\n /**\n * The absolute file path of the module importing this dependency.\n * Used to determine if the import is coming from outside the package.\n * If it is undefined, the import is considered to be from the same package (this is common in Rollup).\n */\n parent?: string;\n /**\n * List of dependencies which should be explicitly inlined rather than externalized.\n * These will always be bundled with the package regardless of other settings.\n */\n inlined?: string[];\n /**\n * List of dependencies which should be explicitly externalized.\n * These will never be bundled with the package.\n */\n external?: string[];\n /**\n * Set of polyfill package names that should be inlined instead of externalized\n * when used as replacements for Node.js built-in modules in browser bundles.\n */\n polyfills?: Set<string>;\n /**\n * Whether Node.js built-in modules should be inlined (with polyfills) rather than externalized.\n * When true, modules like 'fs' or 'path' will be replaced with browser-compatible versions.\n */\n shouldInlineNodeBuiltins: boolean;\n}): boolean {\n const { inputPath, id, parent, inlined, external, polyfills, shouldInlineNodeBuiltins } = params;\n\n const isExternalPackage = isExternal(id, external);\n\n return !(\n // We should inline node builtins that are handled by the nodePolyfills plugin.\n // Except if the dependency is listed as external.\n (\n (shouldInlineNodeBuiltins && isInlinedNodeBuiltin(id, polyfills) && !isExternalPackage) ||\n path.isAbsolute(id) ||\n isRelative(id) ||\n // The length check ensures that parseImportString is only called when there are inlined deps\n (inlined?.length && inlined.includes(parseImportString(id).packageName)) ||\n // A file outside of the package is doing this import, so we should inline the nested dependencies.\n // Except if the dependency is listed as external.\n (isNestedDependency(inputPath, parent) && !isExternalPackage)\n )\n );\n}\n\nfunction isInlinedNodeBuiltin(id: string, polyfills: Set<string> | undefined): boolean {\n return isBuiltin(id) || !!polyfills?.has(id);\n}\n\nfunction isRelative(id: string): boolean {\n return id.startsWith('/') || id.startsWith('./') || id.startsWith('../') || id === '.' || id === '..';\n}\n\n// Check if the import comes from an inlined dependency.\nfunction isNestedDependency(inputPath: string, parent: string | undefined): boolean {\n const relativeParentPath = parent ? path.relative(inputPath, parent) : undefined;\n return !!(relativeParentPath?.startsWith('..') || relativeParentPath?.includes('node_modules'));\n}\n\nfunction isExternal(id: string, external: string[] | undefined): boolean {\n return !!external?.find((ex) => id.startsWith(ex));\n}\n"]}
|