@ms-cloudpack/bundler-utilities 0.4.2 → 0.5.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/getCssRule.d.ts +13 -0
- package/lib/getCssRule.d.ts.map +1 -0
- package/lib/getCssRule.js +48 -0
- package/lib/getCssRule.js.map +1 -0
- package/lib/getModuleSearchPaths.d.ts +2 -2
- package/lib/getModuleSearchPaths.d.ts.map +1 -1
- package/lib/getModuleSearchPaths.js +10 -3
- package/lib/getModuleSearchPaths.js.map +1 -1
- package/lib/getSwcConfig.d.ts +7 -8
- package/lib/getSwcConfig.d.ts.map +1 -1
- package/lib/getSwcConfig.js +6 -13
- package/lib/getSwcConfig.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/package.json +4 -4
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get a webpack/rspack `RuleSetRule` for handling css/sass files.
|
|
3
|
+
*/
|
|
4
|
+
export declare function getCssRule(fileType: 'css' | 'sass'): {
|
|
5
|
+
oneOf: Array<{
|
|
6
|
+
test: RegExp;
|
|
7
|
+
use: Array<string | {
|
|
8
|
+
loader: string;
|
|
9
|
+
options: Record<string, any>;
|
|
10
|
+
}>;
|
|
11
|
+
}>;
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=getCssRule.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getCssRule.d.ts","sourceRoot":"","sources":["../src/getCssRule.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,wBAAgB,UAAU,CAAC,QAAQ,EAAE,KAAK,GAAG,MAAM,GAAG;IACpD,KAAK,EAAE,KAAK,CAAC;QACX,IAAI,EAAE,MAAM,CAAC;QAEb,GAAG,EAAE,KAAK,CAAC,MAAM,GAAG;YAAE,MAAM,EAAE,MAAM,CAAC;YAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;SAAE,CAAC,CAAC;KACvE,CAAC,CAAC;CACJ,CA2CA"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get a webpack/rspack `RuleSetRule` for handling css/sass files.
|
|
3
|
+
*/
|
|
4
|
+
export function getCssRule(fileType) {
|
|
5
|
+
return {
|
|
6
|
+
oneOf: ['global', 'module', 'plain'].map((type) => ({
|
|
7
|
+
// These are used within oneOf (pick first matching rule), so we don't need `exclude`
|
|
8
|
+
test: new RegExp(`${type === 'plain' ? '' : `\\.${type}`}\\.${fileType === 'sass' ? 's[ac]ss' : 'css'}$`, 'i'),
|
|
9
|
+
// With webpack/rspack, it's possible to set sideEffects: true to force all CSS imports to be
|
|
10
|
+
// treated as having side effects regardless of sideEffects in package.json. However, ori
|
|
11
|
+
// doesn't seem to have an equivalent setting, so we skip it here for consistency.
|
|
12
|
+
use: [
|
|
13
|
+
'style-loader',
|
|
14
|
+
{
|
|
15
|
+
loader: 'css-loader',
|
|
16
|
+
options: {
|
|
17
|
+
modules: {
|
|
18
|
+
mode: type === 'module' ? 'local' : 'global',
|
|
19
|
+
// this could be changed for production bundling if needed
|
|
20
|
+
localIdentName: '[local]__[hash:base64]',
|
|
21
|
+
// Include global classes/IDs in exports
|
|
22
|
+
exportGlobals: true,
|
|
23
|
+
// Use original class names as keys in the default export, even if they're
|
|
24
|
+
// not valid identifiers
|
|
25
|
+
exportLocalsConvention: 'as-is',
|
|
26
|
+
// Unfortunately, css-loader explicitly refuses to support both named exports
|
|
27
|
+
// and a default object... https://github.com/webpack-contrib/css-loader/issues/1184
|
|
28
|
+
// For now prefer the default export, but we can re-evaluate if needed.
|
|
29
|
+
namedExport: false,
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
...(fileType === 'sass'
|
|
34
|
+
? [
|
|
35
|
+
{
|
|
36
|
+
loader: 'sass-loader',
|
|
37
|
+
options: {
|
|
38
|
+
// spammy, non-actionable warning
|
|
39
|
+
sassOptions: { silenceDeprecations: ['legacy-js-api'] },
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
]
|
|
43
|
+
: []),
|
|
44
|
+
],
|
|
45
|
+
})),
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=getCssRule.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getCssRule.js","sourceRoot":"","sources":["../src/getCssRule.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,UAAU,UAAU,CAAC,QAAwB;IAOjD,OAAO;QACL,KAAK,EAAE,CAAC,QAAQ,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;YAClD,qFAAqF;YACrF,IAAI,EAAE,IAAI,MAAM,CAAC,GAAG,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,IAAI,EAAE,MAAM,QAAQ,KAAK,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE,GAAG,CAAC;YAC9G,6FAA6F;YAC7F,yFAAyF;YACzF,kFAAkF;YAClF,GAAG,EAAE;gBACH,cAAc;gBACd;oBACE,MAAM,EAAE,YAAY;oBACpB,OAAO,EAAE;wBACP,OAAO,EAAE;4BACP,IAAI,EAAE,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ;4BAC5C,0DAA0D;4BAC1D,cAAc,EAAE,wBAAwB;4BACxC,wCAAwC;4BACxC,aAAa,EAAE,IAAI;4BACnB,0EAA0E;4BAC1E,wBAAwB;4BACxB,sBAAsB,EAAE,OAAO;4BAC/B,6EAA6E;4BAC7E,oFAAoF;4BACpF,uEAAuE;4BACvE,WAAW,EAAE,KAAK;yBACnB;qBACF;iBACF;gBACD,GAAG,CAAC,QAAQ,KAAK,MAAM;oBACrB,CAAC,CAAC;wBACE;4BACE,MAAM,EAAE,aAAa;4BACrB,OAAO,EAAE;gCACP,iCAAiC;gCACjC,WAAW,EAAE,EAAE,mBAAmB,EAAE,CAAC,eAAe,CAAC,EAAE;6BACxD;yBACF;qBACF;oBACH,CAAC,CAAC,EAAE,CAAC;aACR;SACF,CAAC,CAAC;KACJ,CAAC;AACJ,CAAC","sourcesContent":["/**\n * Get a webpack/rspack `RuleSetRule` for handling css/sass files.\n */\nexport function getCssRule(fileType: 'css' | 'sass'): {\n oneOf: Array<{\n test: RegExp;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any -- matching webpack RuleSetRule\n use: Array<string | { loader: string; options: Record<string, any> }>;\n }>;\n} {\n return {\n oneOf: ['global', 'module', 'plain'].map((type) => ({\n // These are used within oneOf (pick first matching rule), so we don't need `exclude`\n test: new RegExp(`${type === 'plain' ? '' : `\\\\.${type}`}\\\\.${fileType === 'sass' ? 's[ac]ss' : 'css'}$`, 'i'),\n // With webpack/rspack, it's possible to set sideEffects: true to force all CSS imports to be\n // treated as having side effects regardless of sideEffects in package.json. However, ori\n // doesn't seem to have an equivalent setting, so we skip it here for consistency.\n use: [\n 'style-loader',\n {\n loader: 'css-loader',\n options: {\n modules: {\n mode: type === 'module' ? 'local' : 'global',\n // this could be changed for production bundling if needed\n localIdentName: '[local]__[hash:base64]',\n // Include global classes/IDs in exports\n exportGlobals: true,\n // Use original class names as keys in the default export, even if they're\n // not valid identifiers\n exportLocalsConvention: 'as-is',\n // Unfortunately, css-loader explicitly refuses to support both named exports\n // and a default object... https://github.com/webpack-contrib/css-loader/issues/1184\n // For now prefer the default export, but we can re-evaluate if needed.\n namedExport: false,\n },\n },\n },\n ...(fileType === 'sass'\n ? [\n {\n loader: 'sass-loader',\n options: {\n // spammy, non-actionable warning\n sassOptions: { silenceDeprecations: ['legacy-js-api'] },\n },\n },\n ]\n : []),\n ],\n })),\n };\n}\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Resolve the given modules relative to the calling package, and return a list of unique
|
|
3
|
-
* containing
|
|
4
|
-
*
|
|
3
|
+
* containing `node_modules` folders which webpack/rspack can use as module search paths in
|
|
4
|
+
* `config.resolveLoader.modules`. (Results are cached per `import.meta.url`.)
|
|
5
5
|
* @param modules - The modules to resolve. Must be dependencies of this package.
|
|
6
6
|
* @param resolveFromImportMetaUrl - The `import.meta.url` of the calling file.
|
|
7
7
|
* @returns Containing folders of the modules. (ie: `/path/to/node_modules/`)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getModuleSearchPaths.d.ts","sourceRoot":"","sources":["../src/getModuleSearchPaths.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"getModuleSearchPaths.d.ts","sourceRoot":"","sources":["../src/getModuleSearchPaths.ts"],"names":[],"mappings":"AAOA;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,wBAAwB,EAAE,MAAM,GAAG,MAAM,EAAE,CAwBlG"}
|
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
import { findPackageRoot, resolveModule } from '@ms-cloudpack/path-utilities';
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import { fileURLToPath } from 'url';
|
|
4
|
+
/** Mapping from `resolveFromImportMetaUrl` to paths */
|
|
5
|
+
const cachedSearchPaths = {};
|
|
4
6
|
/**
|
|
5
7
|
* Resolve the given modules relative to the calling package, and return a list of unique
|
|
6
|
-
* containing
|
|
7
|
-
*
|
|
8
|
+
* containing `node_modules` folders which webpack/rspack can use as module search paths in
|
|
9
|
+
* `config.resolveLoader.modules`. (Results are cached per `import.meta.url`.)
|
|
8
10
|
* @param modules - The modules to resolve. Must be dependencies of this package.
|
|
9
11
|
* @param resolveFromImportMetaUrl - The `import.meta.url` of the calling file.
|
|
10
12
|
* @returns Containing folders of the modules. (ie: `/path/to/node_modules/`)
|
|
11
13
|
*/
|
|
12
14
|
export function getModuleSearchPaths(modules, resolveFromImportMetaUrl) {
|
|
15
|
+
if (cachedSearchPaths[resolveFromImportMetaUrl]) {
|
|
16
|
+
return cachedSearchPaths[resolveFromImportMetaUrl];
|
|
17
|
+
}
|
|
13
18
|
const paths = new Set();
|
|
14
19
|
for (const moduleName of modules) {
|
|
15
20
|
// Resolve the module path and find the package root from there.
|
|
@@ -21,9 +26,11 @@ export function getModuleSearchPaths(modules, resolveFromImportMetaUrl) {
|
|
|
21
26
|
});
|
|
22
27
|
const packageRoot = findPackageRoot(fileURLToPath(moduleUrl));
|
|
23
28
|
if (packageRoot) {
|
|
29
|
+
// Walk up to the node_modules folder above the package root
|
|
24
30
|
paths.add(path.dirname(packageRoot));
|
|
25
31
|
}
|
|
26
32
|
}
|
|
27
|
-
|
|
33
|
+
cachedSearchPaths[resolveFromImportMetaUrl] = Array.from(paths);
|
|
34
|
+
return cachedSearchPaths[resolveFromImportMetaUrl];
|
|
28
35
|
}
|
|
29
36
|
//# sourceMappingURL=getModuleSearchPaths.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getModuleSearchPaths.js","sourceRoot":"","sources":["../src/getModuleSearchPaths.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAC9E,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AAEpC;;;;;;;GAOG;AACH,MAAM,UAAU,oBAAoB,CAAC,OAAiB,EAAE,wBAAgC;IACtF,MAAM,KAAK,GAAG,IAAI,GAAG,EAAU,CAAC;IAEhC,KAAK,MAAM,UAAU,IAAI,OAAO,EAAE,CAAC;QACjC,gEAAgE;QAChE,qGAAqG;QACrG,MAAM,SAAS,GAAG,aAAa,CAAC;YAC9B,eAAe,EAAE,UAAU;YAC3B,SAAS,EAAE,wBAAwB;YACnC,gBAAgB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AAG,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAChE,OAAO,iBAAiB,CAAC,wBAAwB,CAAC,CAAC;AACrD,CAAC","sourcesContent":["import { findPackageRoot, resolveModule } from '@ms-cloudpack/path-utilities';\nimport path from 'path';\nimport { fileURLToPath } from 'url';\n\n/** Mapping from `resolveFromImportMetaUrl` to paths */\nconst cachedSearchPaths: Record<string, string[]> = {};\n\n/**\n * Resolve the given modules relative to the calling package, and return a list of unique\n * containing `node_modules` folders which webpack/rspack can use as module search paths in\n * `config.resolveLoader.modules`. (Results are cached per `import.meta.url`.)\n * @param modules - The modules to resolve. Must be dependencies of this package.\n * @param resolveFromImportMetaUrl - The `import.meta.url` of the calling file.\n * @returns Containing folders of the modules. (ie: `/path/to/node_modules/`)\n */\nexport function getModuleSearchPaths(modules: string[], resolveFromImportMetaUrl: string): string[] {\n if (cachedSearchPaths[resolveFromImportMetaUrl]) {\n return cachedSearchPaths[resolveFromImportMetaUrl];\n }\n\n const paths = new Set<string>();\n\n for (const moduleName of modules) {\n // Resolve the module path and find the package root from there.\n // preserveSymlinks ensures we get the path where it's installed as a dependency, not from the store.\n const moduleUrl = resolveModule({\n importSpecifier: moduleName,\n parentUrl: resolveFromImportMetaUrl,\n preserveSymlinks: true,\n });\n const packageRoot = findPackageRoot(fileURLToPath(moduleUrl));\n if (packageRoot) {\n // Walk up to the node_modules folder above the package root\n paths.add(path.dirname(packageRoot));\n }\n }\n\n cachedSearchPaths[resolveFromImportMetaUrl] = Array.from(paths);\n return cachedSearchPaths[resolveFromImportMetaUrl];\n}\n"]}
|
package/lib/getSwcConfig.d.ts
CHANGED
|
@@ -8,22 +8,21 @@ interface GetSwcConfigParams {
|
|
|
8
8
|
/**
|
|
9
9
|
* Gets the SWC configuration for a package, either from `.swcrc`(`.json`), by converting
|
|
10
10
|
* `tsconfig.json`, or using some basic default options.
|
|
11
|
+
* (Any unset options will use [swc defaults](https://swc.rs/docs/configuration/swcrc).)
|
|
11
12
|
*
|
|
12
13
|
* Notably, this will use a higher default target level than the default SWC config to reduce
|
|
13
14
|
* unnecessary downleveling, and override various options that are required for how cloudpack works.
|
|
14
15
|
*
|
|
15
|
-
* (
|
|
16
|
+
* (ori/esbuild has similar behavior of implicitly reading `tsconfig.json` and using that for
|
|
17
|
+
* certain transpilation settings.)
|
|
16
18
|
*
|
|
17
|
-
* @returns JS/TS
|
|
18
|
-
* (Properties are getters which do the appropriate merging on demand.)
|
|
19
|
+
* @returns JS/TS variants of the config, to avoid processing any config files twice.
|
|
19
20
|
*/
|
|
20
21
|
export declare function getSwcConfig(params: GetSwcConfigParams): {
|
|
21
22
|
/** Config for `.js` and `.jsx` files */
|
|
22
|
-
|
|
23
|
-
/** Config for `.ts`
|
|
24
|
-
|
|
25
|
-
/** Config for `.tsx` files */
|
|
26
|
-
get tsx(): SwcConfig;
|
|
23
|
+
jsx: SwcConfig;
|
|
24
|
+
/** Config for `.ts` and `.tsx` files */
|
|
25
|
+
tsx: SwcConfig;
|
|
27
26
|
};
|
|
28
27
|
export {};
|
|
29
28
|
//# sourceMappingURL=getSwcConfig.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getSwcConfig.d.ts","sourceRoot":"","sources":["../src/getSwcConfig.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAkB,MAAM,IAAI,SAAS,EAAkB,MAAM,WAAW,CAAC;AAOrF,UAAU,kBAAkB;IAC1B,iDAAiD;IACjD,WAAW,EAAE,MAAM,CAAC;IACpB,qCAAqC;IACrC,SAAS,EAAE,OAAO,GAAG,SAAS,CAAC;CAChC;
|
|
1
|
+
{"version":3,"file":"getSwcConfig.d.ts","sourceRoot":"","sources":["../src/getSwcConfig.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAkB,MAAM,IAAI,SAAS,EAAkB,MAAM,WAAW,CAAC;AAOrF,UAAU,kBAAkB;IAC1B,iDAAiD;IACjD,WAAW,EAAE,MAAM,CAAC;IACpB,qCAAqC;IACrC,SAAS,EAAE,OAAO,GAAG,SAAS,CAAC;CAChC;AAkBD;;;;;;;;;;;;GAYG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,kBAAkB,GAAG;IACxD,wCAAwC;IACxC,GAAG,EAAE,SAAS,CAAC;IACf,wCAAwC;IACxC,GAAG,EAAE,SAAS,CAAC;CAChB,CA0DA"}
|
package/lib/getSwcConfig.js
CHANGED
|
@@ -19,18 +19,18 @@ const getUniversalConfig = (params) => ({
|
|
|
19
19
|
});
|
|
20
20
|
const jsxParserConfig = { jsc: { parser: { syntax: 'ecmascript', jsx: true } } };
|
|
21
21
|
const tsxParserConfig = { jsc: { parser: { syntax: 'typescript', tsx: true } } };
|
|
22
|
-
const tsOnlyParserConfig = { jsc: { parser: { syntax: 'typescript', tsx: false } } };
|
|
23
22
|
/**
|
|
24
23
|
* Gets the SWC configuration for a package, either from `.swcrc`(`.json`), by converting
|
|
25
24
|
* `tsconfig.json`, or using some basic default options.
|
|
25
|
+
* (Any unset options will use [swc defaults](https://swc.rs/docs/configuration/swcrc).)
|
|
26
26
|
*
|
|
27
27
|
* Notably, this will use a higher default target level than the default SWC config to reduce
|
|
28
28
|
* unnecessary downleveling, and override various options that are required for how cloudpack works.
|
|
29
29
|
*
|
|
30
|
-
* (
|
|
30
|
+
* (ori/esbuild has similar behavior of implicitly reading `tsconfig.json` and using that for
|
|
31
|
+
* certain transpilation settings.)
|
|
31
32
|
*
|
|
32
|
-
* @returns JS/TS
|
|
33
|
-
* (Properties are getters which do the appropriate merging on demand.)
|
|
33
|
+
* @returns JS/TS variants of the config, to avoid processing any config files twice.
|
|
34
34
|
*/
|
|
35
35
|
export function getSwcConfig(params) {
|
|
36
36
|
const { packagePath } = params;
|
|
@@ -79,15 +79,8 @@ export function getSwcConfig(params) {
|
|
|
79
79
|
delete result.jsc?.parser?.tsx;
|
|
80
80
|
delete result.jsc?.parser?.jsx;
|
|
81
81
|
return {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
},
|
|
85
|
-
get tsx() {
|
|
86
|
-
return mergeObjects([result, tsxParserConfig], { arrayMerge: 'overwrite' });
|
|
87
|
-
},
|
|
88
|
-
get tsOnly() {
|
|
89
|
-
return mergeObjects([result, tsOnlyParserConfig], { arrayMerge: 'overwrite' });
|
|
90
|
-
},
|
|
82
|
+
jsx: mergeObjects([result, jsxParserConfig], { arrayMerge: 'overwrite' }),
|
|
83
|
+
tsx: mergeObjects([result, tsxParserConfig], { arrayMerge: 'overwrite' }),
|
|
91
84
|
};
|
|
92
85
|
}
|
|
93
86
|
//# sourceMappingURL=getSwcConfig.js.map
|
package/lib/getSwcConfig.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getSwcConfig.js","sourceRoot":"","sources":["../src/getSwcConfig.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAE/D,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AASrD,kCAAkC;AAClC,MAAM,kBAAkB,GAAG,CAAC,MAA6C,EAAa,EAAE,CAAC,CAAC;IACxF,GAAG,EAAE;QACH,MAAM,EAAE,mBAAmB;QAC3B,oEAAoE;QACpE,eAAe,EAAE,KAAK;KACvB;IACD,MAAM,EAAE;QACN,IAAI,EAAE,KAAK;KACZ;IACD,UAAU,EAAE,MAAM,CAAC,SAAS;CAC7B,CAAC,CAAC;AAEH,MAAM,eAAe,GAAc,EAAE,GAAG,EAAE,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,YAAY,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE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G,EAAE,OAAO,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC;QAC9E,MAAM,CAAC,GAAG,CAAC,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IAClE,CAAC;IAED,wCAAwC;IACxC,OAAO,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC;IAC1B,gEAAgE;IAChE,oDAAoD;IACpD,OAAO,MAAM,CAAC,GAAG,CAAC;IAClB,uEAAuE;IACvE,OAAQ,MAAM,CAAC,GAAG,EAAE,MAAyB,EAAE,GAAG,CAAC;IACnD,OAAQ,MAAM,CAAC,GAAG,EAAE,MAAyB,EAAE,GAAG,CAAC;IAEnD,OAAO;QACL,GAAG,EAAE,YAAY,CAAC,CAAC,MAAM,EAAE,eAAe,CAAC,EAAE,EAAE,UAAU,EAAE,WAAW,EAAE,CAAC;QACzE,GAAG,EAAE,YAAY,CAAC,CAAC,MAAM,EAAE,eAAe,CAAC,EAAE,EAAE,UAAU,EAAE,WAAW,EAAE,CAAC;KAC1E,CAAC;AACJ,CAAC","sourcesContent":["import { readJsonSync } from '@ms-cloudpack/json-utilities';\nimport { mergeObjects } from '@ms-cloudpack/package-utilities';\nimport type { EsParserConfig, Config as SwcConfig, TsParserConfig } from '@swc/core';\nimport fs from 'fs';\nimport { parseTsconfig } from 'get-tsconfig';\nimport path from 'path';\nimport { convertTsConfig } from 'tsconfig-to-swcconfig';\nimport { defaultTargetSyntax } from './constants.js';\n\ninterface GetSwcConfigParams {\n /** Absolute path to the package (`inputPath`) */\n packagePath: string;\n /** Whether to generate sourcemaps */\n sourcemap: boolean | undefined;\n}\n\n/** Overrides all other configs */\nconst getUniversalConfig = (params: Pick<GetSwcConfigParams, 'sourcemap'>): SwcConfig => ({\n jsc: {\n target: defaultTargetSyntax,\n // We can't reference the separate @swc/helpers package from bundles\n externalHelpers: false,\n },\n module: {\n type: 'es6',\n },\n sourceMaps: params.sourcemap,\n});\n\nconst jsxParserConfig: SwcConfig = { jsc: { parser: { syntax: 'ecmascript', jsx: true } } };\nconst tsxParserConfig: SwcConfig = { jsc: { parser: { syntax: 'typescript', tsx: true } } };\n\n/**\n * Gets the SWC configuration for a package, either from `.swcrc`(`.json`), by converting\n * `tsconfig.json`, or using some basic default options.\n * (Any unset options will use [swc defaults](https://swc.rs/docs/configuration/swcrc).)\n *\n * Notably, this will use a higher default target level than the default SWC config to reduce\n * unnecessary downleveling, and override various options that are required for how cloudpack works.\n *\n * (ori/esbuild has similar behavior of implicitly reading `tsconfig.json` and using that for\n * certain transpilation settings.)\n *\n * @returns JS/TS variants of the config, to avoid processing any config files twice.\n */\nexport function getSwcConfig(params: GetSwcConfigParams): {\n /** Config for `.js` and `.jsx` files */\n jsx: SwcConfig;\n /** Config for `.ts` and `.tsx` files */\n tsx: SwcConfig;\n} {\n const { packagePath } = params;\n\n // First try reading .swcrc(.json).\n // (It might have comments but doesn't have config extension, at least in v1.)\n const swcrc: SwcConfig | SwcConfig[] | undefined =\n readJsonSync(path.join(packagePath, '.swcrc'), { mode: 'permissive' }) ||\n readJsonSync(path.join(packagePath, '.swcrc.json'), { mode: 'permissive' });\n\n let packageConfig: SwcConfig | undefined;\n // .swcrc can have either a single object or an array with `test`.\n // Possibly we could add some logic to handle the array based on file extensions\n // https://swc.rs/docs/configuration/compilation#multiple-entries\n if (Array.isArray(swcrc)) {\n console.warn(\n `Found array in .swcrc at ${packagePath} - this is not currently supported, so default settings will be used instead.`,\n );\n } else if (swcrc) {\n console.debug(`Found .swcrc at ${packagePath}`);\n packageConfig = swcrc;\n }\n\n const tsconfigPath = path.join(packagePath, 'tsconfig.json');\n if (!packageConfig && fs.existsSync(tsconfigPath)) {\n // Read tsconfig.json from the package path if present, and convert it to swc config.\n // (We use a separate read step instead of calling all-in-one tsconfig-to-swcconfig `convert()`\n // because that searches up parent dirs for a tsconfig.json, which is worse for perf.)\n try {\n const tsconfig = parseTsconfig(tsconfigPath);\n packageConfig = convertTsConfig(tsconfig.compilerOptions || {}, undefined, packagePath);\n } catch {\n // ignore\n }\n }\n\n const result = mergeObjects([packageConfig || {}, getUniversalConfig(params)], { arrayMerge: 'overwrite' });\n\n /**\n * Check if baseUrl is relative and convert it to absolute path\n * Swc doesn't support relative baseUrl paths\n */\n if (result.jsc && result.jsc?.baseUrl && !path.isAbsolute(result.jsc.baseUrl)) {\n result.jsc.baseUrl = path.join(packagePath, result.jsc.baseUrl);\n }\n\n // minifying should be up to the bundler\n delete result.jsc?.minify;\n // env conflicts with jsc.target -- currently we only use target\n // https://swc.rs/docs/configuration/compilation#env\n delete result.env;\n // delete jsx/tsx options (will apply the correct one in the last step)\n delete (result.jsc?.parser as TsParserConfig)?.tsx;\n delete (result.jsc?.parser as EsParserConfig)?.jsx;\n\n return {\n jsx: mergeObjects([result, jsxParserConfig], { arrayMerge: 'overwrite' }),\n tsx: mergeObjects([result, tsxParserConfig], { arrayMerge: 'overwrite' }),\n };\n}\n"]}
|
package/lib/index.d.ts
CHANGED
|
@@ -2,4 +2,5 @@ export { defaultTargetSyntax, base64AssetExtensions } from './constants.js';
|
|
|
2
2
|
export { getModuleSearchPaths } from './getModuleSearchPaths.js';
|
|
3
3
|
export { getSwcConfig } from './getSwcConfig.js';
|
|
4
4
|
export { shouldExternalizePackage } from './shouldExternalizePackage.js';
|
|
5
|
+
export { getCssRule } from './getCssRule.js';
|
|
5
6
|
//# 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"}
|
|
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"}
|
package/lib/index.js
CHANGED
|
@@ -2,4 +2,5 @@ export { defaultTargetSyntax, base64AssetExtensions } from './constants.js';
|
|
|
2
2
|
export { getModuleSearchPaths } from './getModuleSearchPaths.js';
|
|
3
3
|
export { getSwcConfig } from './getSwcConfig.js';
|
|
4
4
|
export { shouldExternalizePackage } from './shouldExternalizePackage.js';
|
|
5
|
+
export { getCssRule } from './getCssRule.js';
|
|
5
6
|
//# 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","sourcesContent":["export { defaultTargetSyntax, base64AssetExtensions } from './constants.js';\nexport { getModuleSearchPaths } from './getModuleSearchPaths.js';\nexport { getSwcConfig } from './getSwcConfig.js';\nexport { shouldExternalizePackage } from './shouldExternalizePackage.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","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"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ms-cloudpack/bundler-utilities",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Utilities used by multiple bundlers.",
|
|
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.10",
|
|
18
|
-
"@ms-cloudpack/package-utilities": "^12.3.
|
|
18
|
+
"@ms-cloudpack/package-utilities": "^12.3.19",
|
|
19
19
|
"@ms-cloudpack/path-string-parsing": "^1.2.7",
|
|
20
|
-
"@ms-cloudpack/path-utilities": "^3.1.
|
|
20
|
+
"@ms-cloudpack/path-utilities": "^3.1.13",
|
|
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.26.
|
|
25
|
+
"@ms-cloudpack/common-types": "^0.26.3",
|
|
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",
|