@ms-cloudpack/bundler-utilities 0.6.6 → 0.7.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/constants.d.ts.map +1 -1
- package/lib/constants.js +1 -0
- package/lib/constants.js.map +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/processAssetInlineExtensions.d.ts +10 -0
- package/lib/processAssetInlineExtensions.d.ts.map +1 -0
- package/lib/processAssetInlineExtensions.js +36 -0
- package/lib/processAssetInlineExtensions.js.map +1 -0
- package/lib/shouldExternalizePackage.d.ts +4 -0
- package/lib/shouldExternalizePackage.d.ts.map +1 -1
- package/lib/shouldExternalizePackage.js +38 -14
- package/lib/shouldExternalizePackage.js.map +1 -1
- package/package.json +4 -4
package/lib/constants.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB,WAAW,CAAC;AAE5C,eAAO,MAAM,qBAAqB,
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB,WAAW,CAAC;AAE5C,eAAO,MAAM,qBAAqB,UAmBjC,CAAC"}
|
package/lib/constants.js
CHANGED
package/lib/constants.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,QAAQ,CAAC;AAE5C,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACnC,MAAM;IACN,MAAM;IACN,MAAM;IACN,OAAO;IACP,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,OAAO;IACP,OAAO;IACP,QAAQ;IACR,MAAM;
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,QAAQ,CAAC;AAE5C,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACnC,MAAM;IACN,MAAM;IACN,MAAM;IACN,OAAO;IACP,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,OAAO;IACP,OAAO;IACP,QAAQ;IACR,MAAM;IACN,OAAO;CACR,CAAC","sourcesContent":["/**\n * Default ES syntax level. 2022 is the minimum for top-level await.\n *\n * ES2023 is probably fine for browsers (definitely for development), and Node 20 also supports it.\n * But for some reason, rspack only lists up to ES2022 in its valid targets (and none of the\n * ES2023 features are obviously relevant for a bundler), so stick with ES2022 for now.\n */\nexport const defaultTargetSyntax = 'es2022';\n\nexport const base64AssetExtensions = [\n '.aac',\n '.bmp',\n '.gif',\n '.jpeg',\n '.jpg',\n '.mp3',\n '.mp4',\n '.ogg',\n '.otf',\n '.png',\n '.svg',\n '.ttf',\n '.wav',\n '.webp',\n '.woff',\n '.woff2',\n '.eot',\n '.avif',\n];\n"]}
|
package/lib/index.d.ts
CHANGED
|
@@ -3,4 +3,5 @@ export { getModuleSearchPaths } from './getModuleSearchPaths.js';
|
|
|
3
3
|
export { getSwcConfig } from './getSwcConfig.js';
|
|
4
4
|
export { shouldExternalizePackage } from './shouldExternalizePackage.js';
|
|
5
5
|
export { getCssRule } from './getCssRule.js';
|
|
6
|
+
export { processAssetInlineExtensions } from './processAssetInlineExtensions.js';
|
|
6
7
|
//# 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":"AAAA,OAAO,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AAC5E,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AACzE,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AAC5E,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AACzE,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,4BAA4B,EAAE,MAAM,mCAAmC,CAAC"}
|
package/lib/index.js
CHANGED
|
@@ -3,4 +3,5 @@ export { getModuleSearchPaths } from './getModuleSearchPaths.js';
|
|
|
3
3
|
export { getSwcConfig } from './getSwcConfig.js';
|
|
4
4
|
export { shouldExternalizePackage } from './shouldExternalizePackage.js';
|
|
5
5
|
export { getCssRule } from './getCssRule.js';
|
|
6
|
+
export { processAssetInlineExtensions } from './processAssetInlineExtensions.js';
|
|
6
7
|
//# 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,OAAO,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AAC5E,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AACzE,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC","sourcesContent":["export { defaultTargetSyntax, base64AssetExtensions } from './constants.js';\nexport { getModuleSearchPaths } from './getModuleSearchPaths.js';\nexport { getSwcConfig } from './getSwcConfig.js';\nexport { shouldExternalizePackage } from './shouldExternalizePackage.js';\nexport { getCssRule } from './getCssRule.js';\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AAC5E,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AACzE,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,4BAA4B,EAAE,MAAM,mCAAmC,CAAC","sourcesContent":["export { defaultTargetSyntax, base64AssetExtensions } from './constants.js';\nexport { getModuleSearchPaths } from './getModuleSearchPaths.js';\nexport { getSwcConfig } from './getSwcConfig.js';\nexport { shouldExternalizePackage } from './shouldExternalizePackage.js';\nexport { getCssRule } from './getCssRule.js';\nexport { processAssetInlineExtensions } from './processAssetInlineExtensions.js';\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Process asset inline extensions based on the input format.
|
|
3
|
+
*
|
|
4
|
+
* @param extensions - Can be either:
|
|
5
|
+
* - Array: Replace default list with these extensions (without leading dots per documentation)
|
|
6
|
+
* - Object: Modify default list (false removes, true adds extensions, without leading dots per documentation)
|
|
7
|
+
* @returns Processed array of extensions (with leading dots, matching base64AssetExtensions format)
|
|
8
|
+
*/
|
|
9
|
+
export declare function processAssetInlineExtensions(extensions: string[] | Record<string, boolean>): string[];
|
|
10
|
+
//# sourceMappingURL=processAssetInlineExtensions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"processAssetInlineExtensions.d.ts","sourceRoot":"","sources":["../src/processAssetInlineExtensions.ts"],"names":[],"mappings":"AAWA;;;;;;;GAOG;AACH,wBAAgB,4BAA4B,CAAC,UAAU,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,EAAE,CAoBrG"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { base64AssetExtensions } from './constants.js';
|
|
2
|
+
/**
|
|
3
|
+
* Normalize extension by ensuring it has a leading dot (matching base64AssetExtensions format).
|
|
4
|
+
* Strips the dot if present in input and adds it back for consistency.
|
|
5
|
+
*/
|
|
6
|
+
function normalizeExtension(ext) {
|
|
7
|
+
const stripped = ext.startsWith('.') ? ext.slice(1) : ext;
|
|
8
|
+
return `.${stripped}`;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Process asset inline extensions based on the input format.
|
|
12
|
+
*
|
|
13
|
+
* @param extensions - Can be either:
|
|
14
|
+
* - Array: Replace default list with these extensions (without leading dots per documentation)
|
|
15
|
+
* - Object: Modify default list (false removes, true adds extensions, without leading dots per documentation)
|
|
16
|
+
* @returns Processed array of extensions (with leading dots, matching base64AssetExtensions format)
|
|
17
|
+
*/
|
|
18
|
+
export function processAssetInlineExtensions(extensions) {
|
|
19
|
+
// Array format: replace the entire default list
|
|
20
|
+
if (Array.isArray(extensions)) {
|
|
21
|
+
return extensions.map(normalizeExtension);
|
|
22
|
+
}
|
|
23
|
+
// Object format: modify the default list
|
|
24
|
+
const result = new Set(base64AssetExtensions);
|
|
25
|
+
for (const [ext, include] of Object.entries(extensions)) {
|
|
26
|
+
const normalizedExt = normalizeExtension(ext);
|
|
27
|
+
if (include) {
|
|
28
|
+
result.add(normalizedExt);
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
result.delete(normalizedExt);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return Array.from(result);
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=processAssetInlineExtensions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"processAssetInlineExtensions.js","sourceRoot":"","sources":["../src/processAssetInlineExtensions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AAEvD;;;GAGG;AACH,SAAS,kBAAkB,CAAC,GAAW;IACrC,MAAM,QAAQ,GAAG,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;IAC1D,OAAO,IAAI,QAAQ,EAAE,CAAC;AACxB,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,4BAA4B,CAAC,UAA8C;IACzF,gDAAgD;IAChD,IAAI,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;QAC9B,OAAO,UAAU,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC;IAC5C,CAAC;IAED,yCAAyC;IACzC,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,qBAAqB,CAAC,CAAC;IAE9C,KAAK,MAAM,CAAC,GAAG,EAAE,OAAO,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;QACxD,MAAM,aAAa,GAAG,kBAAkB,CAAC,GAAG,CAAC,CAAC;QAE9C,IAAI,OAAO,EAAE,CAAC;YACZ,MAAM,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;QAC5B,CAAC;aAAM,CAAC;YACN,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC;QAC/B,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AAC5B,CAAC","sourcesContent":["import { base64AssetExtensions } from './constants.js';\n\n/**\n * Normalize extension by ensuring it has a leading dot (matching base64AssetExtensions format).\n * Strips the dot if present in input and adds it back for consistency.\n */\nfunction normalizeExtension(ext: string): string {\n const stripped = ext.startsWith('.') ? ext.slice(1) : ext;\n return `.${stripped}`;\n}\n\n/**\n * Process asset inline extensions based on the input format.\n *\n * @param extensions - Can be either:\n * - Array: Replace default list with these extensions (without leading dots per documentation)\n * - Object: Modify default list (false removes, true adds extensions, without leading dots per documentation)\n * @returns Processed array of extensions (with leading dots, matching base64AssetExtensions format)\n */\nexport function processAssetInlineExtensions(extensions: string[] | Record<string, boolean>): string[] {\n // Array format: replace the entire default list\n if (Array.isArray(extensions)) {\n return extensions.map(normalizeExtension);\n }\n\n // Object format: modify the default list\n const result = new Set(base64AssetExtensions);\n\n for (const [ext, include] of Object.entries(extensions)) {\n const normalizedExt = normalizeExtension(ext);\n\n if (include) {\n result.add(normalizedExt);\n } else {\n result.delete(normalizedExt);\n }\n }\n\n return Array.from(result);\n}\n"]}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import type { BundleMode, TargetEnvironment } from '@ms-cloudpack/common-types';
|
|
2
2
|
export interface ShouldExternalizePackageOptions {
|
|
3
|
+
/**
|
|
4
|
+
* Name of the package being bundled.
|
|
5
|
+
*/
|
|
6
|
+
packageName: string;
|
|
3
7
|
/**
|
|
4
8
|
* The absolute input path for the entry points to be bundled.
|
|
5
9
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shouldExternalizePackage.d.ts","sourceRoot":"","sources":["../src/shouldExternalizePackage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAKhF,MAAM,WAAW,+BAA+B;IAC9C;;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;;;;;OAKG;IACH,wBAAwB,EAAE,OAAO,CAAC;IAClC;;OAEG;IACH,iBAAiB,EAAE,iBAAiB,CAAC;IACrC;;;;OAIG;IACH,IAAI,EAAE,UAAU,CAAC;CAClB;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,+BAA+B,GAAG,OAAO,
|
|
1
|
+
{"version":3,"file":"shouldExternalizePackage.d.ts","sourceRoot":"","sources":["../src/shouldExternalizePackage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAKhF,MAAM,WAAW,+BAA+B;IAC9C;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IACpB;;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;;;;;OAKG;IACH,wBAAwB,EAAE,OAAO,CAAC;IAClC;;OAEG;IACH,iBAAiB,EAAE,iBAAiB,CAAC;IACrC;;;;OAIG;IACH,IAAI,EAAE,UAAU,CAAC;CAClB;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,+BAA+B,GAAG,OAAO,CAkEzF"}
|
|
@@ -22,7 +22,7 @@ import path from 'path';
|
|
|
22
22
|
* ```
|
|
23
23
|
*/
|
|
24
24
|
export function shouldExternalizePackage(params) {
|
|
25
|
-
const { inputPath, id, parent, inlined, external, polyfills, shouldInlineNodeBuiltins, targetEnvironment, mode } = params;
|
|
25
|
+
const { packageName, inputPath, id, parent, inlined, external, polyfills, shouldInlineNodeBuiltins, targetEnvironment, mode, } = params;
|
|
26
26
|
if (targetEnvironment === 'node' && isBuiltin(id)) {
|
|
27
27
|
// For Node.js, always externalize built-in modules, even in production mode.
|
|
28
28
|
return true;
|
|
@@ -32,19 +32,39 @@ export function shouldExternalizePackage(params) {
|
|
|
32
32
|
return false;
|
|
33
33
|
}
|
|
34
34
|
const isExternalPackage = isExternal(id, external);
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
let idPackageName;
|
|
36
|
+
// For browser bundles, inline node builtins that are handled by the nodePolyfills plugin,
|
|
37
|
+
// except if the dependency is explicitly listed as external.
|
|
38
|
+
if (targetEnvironment === 'browser' &&
|
|
38
39
|
!isExternalPackage &&
|
|
39
40
|
shouldInlineNodeBuiltins &&
|
|
40
|
-
isInlinedNodeBuiltin(id, polyfills))
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
41
|
+
isInlinedNodeBuiltin(id, polyfills)) {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
// Early checks that don't require parsing the package name
|
|
45
|
+
if (path.isAbsolute(id) || isRelative(id)) {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
// Check if this is an explicitly inlined dependency
|
|
49
|
+
// The length check ensures parseImportString is only called when there are inlined deps
|
|
50
|
+
if (inlined?.length) {
|
|
51
|
+
idPackageName = parseImportString(id).packageName;
|
|
52
|
+
if (inlined.includes(idPackageName)) {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
// A file outside of the package is doing this import, so we should inline the nested dependencies,
|
|
57
|
+
// except if the dependency is explicitly listed as external.
|
|
58
|
+
if (isNestedDependency(inputPath, parent) && !isExternalPackage && !isRelayArtifact(parent)) {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
// Check for self-imports (same package importing itself)
|
|
62
|
+
idPackageName ??= parseImportString(id).packageName;
|
|
63
|
+
if (packageName === idPackageName) {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
// Default: externalize the package
|
|
67
|
+
return true;
|
|
48
68
|
}
|
|
49
69
|
function isInlinedNodeBuiltin(id, polyfills) {
|
|
50
70
|
return isBuiltin(id) || !!polyfills?.has(id);
|
|
@@ -54,8 +74,12 @@ function isRelative(id) {
|
|
|
54
74
|
}
|
|
55
75
|
// Check if the import comes from an inlined dependency.
|
|
56
76
|
function isNestedDependency(inputPath, parent) {
|
|
57
|
-
|
|
58
|
-
|
|
77
|
+
if (!parent)
|
|
78
|
+
return false;
|
|
79
|
+
const relativeParentPath = path.relative(inputPath, parent);
|
|
80
|
+
return !!(relativeParentPath.startsWith('..') || // The import comes from an inlined internal package.
|
|
81
|
+
relativeParentPath.includes('node_modules') // The import comes from an inlined external package.
|
|
82
|
+
);
|
|
59
83
|
}
|
|
60
84
|
function isExternal(id, external) {
|
|
61
85
|
return !!external?.find((ex) => id.startsWith(ex));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shouldExternalizePackage.js","sourceRoot":"","sources":["../src/shouldExternalizePackage.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AACtE,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACnC,OAAO,IAAI,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"sh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AAU,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;AAED,kFAAkF;AAClF,gEAAgE;AAChE,+DAA+D;AAC/D,SAAS,eAAe,CAAC,MAAe;IACtC,OAAO,CAAC,CAAC,MAAM,EAAE,QAAQ,CAAC,eAAe,CAAC,CAAC;AAC7C,CAAC","sourcesContent":["import type { BundleMode, TargetEnvironment } from '@ms-cloudpack/common-types';\nimport { parseImportString } from '@ms-cloudpack/path-string-parsing';\nimport { isBuiltin } from 'module';\nimport path from 'path';\n\nexport interface ShouldExternalizePackageOptions {\n /**\n * Name of the package being bundled.\n */\n packageName: string;\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 * Additional polyfill package names that should be inlined instead of externalized\n * if `shouldInlineNodeBuiltins` is true. This does NOT need to include Node.js built-ins.\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 * If `targetEnvironment` is `'node'`, this will always be ignored since built-ins should always be externalized.\n */\n shouldInlineNodeBuiltins: boolean;\n /**\n * Where the bundled code will run.\n */\n targetEnvironment: TargetEnvironment;\n /**\n * Bundle mode. In production/development mode, all packages will be inlined, except Node built-ins if\n * `targetEnvironment` is `'node'`. (You can skip calling this function and just inline everything for\n * `targetEnvironment: 'browser'`.)\n */\n mode: BundleMode;\n}\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 * Example params (`<root>` is the absolute repo root path):\n * ```ts\n * {\n * inputPath: \"<root>/app\",\n * id: \"<root>/app/src/about.tsx\",\n * parent: \"<root>/app/src/index.tsx\",\n * inlined: [\"foo\"],\n * external: [\"bar\", \"baz\"],\n * polyfills: new Set([\"global\"]),\n * shouldInlineNodeBuiltins: false,\n * targetEnvironment: \"browser\",\n * mode: \"library\"\n * )\n * ```\n */\nexport function shouldExternalizePackage(params: ShouldExternalizePackageOptions): boolean {\n const {\n packageName,\n inputPath,\n id,\n parent,\n inlined,\n external,\n polyfills,\n shouldInlineNodeBuiltins,\n targetEnvironment,\n mode,\n } = params;\n\n if (targetEnvironment === 'node' && isBuiltin(id)) {\n // For Node.js, always externalize built-in modules, even in production mode.\n return true;\n }\n\n if (mode !== 'library') {\n // For production/development mode, don't externalize anything (except as above).\n return false;\n }\n\n const isExternalPackage = isExternal(id, external);\n let idPackageName: string | undefined;\n\n // For browser bundles, inline node builtins that are handled by the nodePolyfills plugin,\n // except if the dependency is explicitly listed as external.\n if (\n targetEnvironment === 'browser' &&\n !isExternalPackage &&\n shouldInlineNodeBuiltins &&\n isInlinedNodeBuiltin(id, polyfills)\n ) {\n return false;\n }\n\n // Early checks that don't require parsing the package name\n if (path.isAbsolute(id) || isRelative(id)) {\n return false;\n }\n\n // Check if this is an explicitly inlined dependency\n // The length check ensures parseImportString is only called when there are inlined deps\n if (inlined?.length) {\n idPackageName = parseImportString(id).packageName;\n if (inlined.includes(idPackageName)) {\n return false;\n }\n }\n\n // A file outside of the package is doing this import, so we should inline the nested dependencies,\n // except if the dependency is explicitly listed as external.\n if (isNestedDependency(inputPath, parent) && !isExternalPackage && !isRelayArtifact(parent)) {\n return false;\n }\n\n // Check for self-imports (same package importing itself)\n idPackageName ??= parseImportString(id).packageName;\n if (packageName === idPackageName) {\n return false;\n }\n\n // Default: externalize the package\n return true;\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 if (!parent) return false;\n const relativeParentPath = path.relative(inputPath, parent);\n return !!(\n relativeParentPath.startsWith('..') || // The import comes from an inlined internal package.\n relativeParentPath.includes('node_modules') // The import comes from an inlined external package.\n );\n}\n\nfunction isExternal(id: string, external: string[] | undefined): boolean {\n return !!external?.find((ex) => id.startsWith(ex));\n}\n\n// Check if the importer is an artifact as it might be in a grandparent directory.\n// Rollup parent is the filename ../__generated__/foo.graphql.ts\n// while webpack/rspack parent is the dirname ../__generated__/\nfunction isRelayArtifact(parent?: string): boolean {\n return !!parent?.includes('__generated__');\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ms-cloudpack/bundler-utilities",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "Utilities used by multiple Cloudpack bundlers implementations",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -15,14 +15,14 @@
|
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"@ms-cloudpack/json-utilities": "^0.1.11",
|
|
18
|
-
"@ms-cloudpack/package-utilities": "^13.
|
|
18
|
+
"@ms-cloudpack/package-utilities": "^13.2.0",
|
|
19
19
|
"@ms-cloudpack/path-string-parsing": "^1.2.7",
|
|
20
|
-
"@ms-cloudpack/path-utilities": "^3.1.
|
|
20
|
+
"@ms-cloudpack/path-utilities": "^3.1.32",
|
|
21
21
|
"get-tsconfig": "^4.7.2",
|
|
22
22
|
"tsconfig-to-swcconfig": "^2.7.0"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@ms-cloudpack/common-types": "^0.
|
|
25
|
+
"@ms-cloudpack/common-types": "^0.32.0",
|
|
26
26
|
"@ms-cloudpack/eslint-plugin-internal": "^0.0.1",
|
|
27
27
|
"@ms-cloudpack/scripts": "^0.0.1",
|
|
28
28
|
"@ms-cloudpack/test-utilities": "^0.5.0",
|