@ms-cloudpack/bundler-webpack 0.5.8 → 0.5.12
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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getWebpackCapabilities.d.ts","sourceRoot":"","sources":["../src/getWebpackCapabilities.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,wCAAwC,EAAE,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"getWebpackCapabilities.d.ts","sourceRoot":"","sources":["../src/getWebpackCapabilities.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,wCAAwC,EAAE,MAAM,4BAA4B,CAAC;AAGtH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAG7C,eAAO,MAAM,sBAAsB,GACjC,QAAQ;IAAE,aAAa,EAAE,UAAU,CAAA;CAAE,EACrC,SAAS,IAAI,CAAC,aAAa,EAAE,QAAQ,CAAC,KACrC,wCAAwC,CAAC,aAAa,CA0EvD,CAAC"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { processAssetInlineExtensions } from '@ms-cloudpack/bundler-utilities';
|
|
1
|
+
import { getSwcRelayPluginConfig, processAssetInlineExtensions } from '@ms-cloudpack/bundler-utilities';
|
|
2
|
+
import { webExtensions } from '@ms-cloudpack/path-utilities';
|
|
2
3
|
import webpack from 'webpack';
|
|
3
|
-
import { fileURLToPath } from 'url';
|
|
4
|
-
import { resolveModule, webExtensions } from '@ms-cloudpack/path-utilities';
|
|
5
4
|
export const getWebpackCapabilities = (params, context) => ({
|
|
6
5
|
'asset-inline': (config, options) => {
|
|
7
6
|
// Process extensions based on format (array or object)
|
|
@@ -46,20 +45,9 @@ export const getWebpackCapabilities = (params, context) => ({
|
|
|
46
45
|
relay: (config, options) => {
|
|
47
46
|
config.module ??= {};
|
|
48
47
|
config.module.rules ??= [];
|
|
49
|
-
|
|
50
|
-
const safeOptions = options && typeof options === 'object' ? options : {};
|
|
51
|
-
if (!safeOptions.rootDir) {
|
|
52
|
-
throw new Error('The relay capability requires a rootDir option to be set.');
|
|
53
|
-
}
|
|
54
|
-
// Base plugin options. "eagerEsModules" needs to be set or bundlers may default to "require" instead of inlining
|
|
55
|
-
const relayPluginOptions = { eagerEsModules: true, ...safeOptions, language: 'typescript' };
|
|
56
|
-
// Configuration for ts and js files
|
|
57
|
-
const loaderConfigs = [
|
|
58
|
-
{ syntax: 'typescript', pluginOptions: relayPluginOptions },
|
|
59
|
-
{ syntax: 'ecmascript', pluginOptions: { ...relayPluginOptions, language: 'javascript' } },
|
|
60
|
-
];
|
|
48
|
+
const addRelayConfig = getSwcRelayPluginConfig({ options, parentUrl: import.meta.url });
|
|
61
49
|
// Apply relay plugin to existing SWC loaders
|
|
62
|
-
for (const
|
|
50
|
+
for (const syntax of ['typescript', 'ecmascript']) {
|
|
63
51
|
// Find the existing SWC loader for the current syntax
|
|
64
52
|
const swcLoader = config.module.rules.find((rule) => typeof rule === 'object' &&
|
|
65
53
|
rule?.loader === 'swc-loader' &&
|
|
@@ -68,13 +56,8 @@ export const getWebpackCapabilities = (params, context) => ({
|
|
|
68
56
|
if (!swcLoader || typeof swcLoader !== 'object') {
|
|
69
57
|
throw new Error(`Could not find existing SWC loader for syntax ${syntax}`);
|
|
70
58
|
}
|
|
71
|
-
const relayPlugin = fileURLToPath(resolveModule({ importSpecifier: '@swc/plugin-relay', parentUrl: import.meta.url }));
|
|
72
59
|
// Update the existing loader with relay plugin
|
|
73
|
-
|
|
74
|
-
swcOptions.jsc ??= {};
|
|
75
|
-
swcOptions.jsc.experimental ??= {};
|
|
76
|
-
swcOptions.jsc.experimental.plugins ??= [];
|
|
77
|
-
swcOptions.jsc.experimental.plugins.push([relayPlugin, pluginOptions]);
|
|
60
|
+
addRelayConfig(swcLoader.options, syntax);
|
|
78
61
|
}
|
|
79
62
|
return config;
|
|
80
63
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getWebpackCapabilities.js","sourceRoot":"","sources":["../src/getWebpackCapabilities.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,MAAM,iCAAiC,CAAC;
|
|
1
|
+
{"version":3,"file":"getWebpackCapabilities.js","sourceRoot":"","sources":["../src/getWebpackCapabilities.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,4BAA4B,EAAE,MAAM,iCAAiC,CAAC;AAExG,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAG7D,OAAO,OAAO,MAAM,SAAS,CAAC;AAE9B,MAAM,CAAC,MAAM,sBAAsB,GAAG,CACpC,MAAqC,EACrC,OAAsC,EACmB,EAAE,CAAC,CAAC;IAC7D,cAAc,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,EAAE;QAClC,uDAAuD;QACvD,MAAM,mBAAmB,GAAG,4BAA4B,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;QAE7E,6CAA6C;QAC7C,MAAM,UAAU,GAAG,mBAAmB,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;QAChG,MAAM,CAAC,MAAM,KAAK,EAAE,CAAC;QACrB,MAAM,CAAC,MAAM,CAAC,KAAK,KAAK,EAAE,CAAC;QAC3B,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC;YACvB,IAAI,EAAE,IAAI,MAAM,CAAC,OAAO,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC;YACtD,IAAI,EAAE,cAAc;SACrB,CAAC,CAAC;QACH,OAAO,MAAM,CAAC;IAChB,CAAC;I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AAM,cAAc,GAAG,uBAAuB,CAAC,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;QAExF,6CAA6C;QAC7C,KAAK,MAAM,MAAM,IAAI,CAAC,YAAY,EAAE,YAAY,CAAU,EAAE,CAAC;YAC3D,sDAAsD;YACtD,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CACxC,CAAC,IAAI,EAAE,EAAE,CACP,OAAO,IAAI,KAAK,QAAQ;gBACxB,IAAI,EAAE,MAAM,KAAK,YAAY;gBAC5B,IAAI,CAAC,OAAqB,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,KAAK,MAAM,CAC9D,CAAC;YAEF,gDAAgD;YAChD,IAAI,CAAC,SAAS,IAAI,OAAO,SAAS,KAAK,QAAQ,EAAE,CAAC;gBAChD,MAAM,IAAI,KAAK,CAAC,iDAAiD,MAAM,EAAE,CAAC,CAAC;YAC7E,CAAC;YAED,+CAA+C;YAC/C,cAAc,CAAC,SAAS,CAAC,OAAoB,EAAE,MAAM,CAAC,CAAC;QACzD,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,2FAA2F;IAC3F,qGAAqG;IACrG,OAAO,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM;CAC5B,CAAC,CAAC","sourcesContent":["import { getSwcRelayPluginConfig, processAssetInlineExtensions } from '@ms-cloudpack/bundler-utilities';\nimport type { BundleContext, BundleMode, InternalBundlerCapabilityImplementations } from '@ms-cloudpack/common-types';\nimport { webExtensions } from '@ms-cloudpack/path-utilities';\nimport type { Config as SwcConfig } from '@swc/core';\nimport type { Configuration } from 'webpack';\nimport webpack from 'webpack';\n\nexport const getWebpackCapabilities = (\n params: { effectiveMode: BundleMode },\n context: Pick<BundleContext, 'config'>,\n): InternalBundlerCapabilityImplementations<Configuration> => ({\n 'asset-inline': (config, options) => {\n // Process extensions based on format (array or object)\n const processedExtensions = processAssetInlineExtensions(options.extensions);\n\n // Remove the leading dot from the extensions\n const extensions = processedExtensions.map((ext) => (ext.startsWith('.') ? ext.slice(1) : ext));\n config.module ??= {};\n config.module.rules ??= [];\n config.module.rules.push({\n test: new RegExp(`\\\\.(${extensions.join('|')})$`, 'i'),\n type: 'asset/inline',\n });\n return config;\n },\n alias: (config, options) => {\n // Add aliases for externalized packages to the webpack configuration\n if (!config.externals) {\n config.externals = [];\n } else if (!Array.isArray(config.externals)) {\n config.externals = [config.externals];\n }\n // The aliased packaged must be the first element in the array,\n // so that it is resolved before all other packages are externalized.\n config.externals.unshift(options);\n return config;\n },\n 'resolve-web-extensions': (config) => {\n config.resolve ??= {};\n config.resolve.extensions ??= [];\n config.resolve.extensions.unshift(...webExtensions);\n return config;\n },\n define: (config, options) => {\n config.plugins ??= [];\n config.plugins.push(\n new webpack.DefinePlugin({\n ...(params.effectiveMode === 'production' ? context.config.define : {}),\n ...options,\n }),\n );\n return config;\n },\n relay: (config, options) => {\n config.module ??= {};\n config.module.rules ??= [];\n\n const addRelayConfig = getSwcRelayPluginConfig({ options, parentUrl: import.meta.url });\n\n // Apply relay plugin to existing SWC loaders\n for (const syntax of ['typescript', 'ecmascript'] as const) {\n // Find the existing SWC loader for the current syntax\n const swcLoader = config.module.rules.find(\n (rule) =>\n typeof rule === 'object' &&\n rule?.loader === 'swc-loader' &&\n (rule.options as SwcConfig)?.jsc?.parser?.syntax === syntax,\n );\n\n // Type guard, we shouldn't be hitting this case\n if (!swcLoader || typeof swcLoader !== 'object') {\n throw new Error(`Could not find existing SWC loader for syntax ${syntax}`);\n }\n\n // Update the existing loader with relay plugin\n addRelayConfig(swcLoader.options as SwcConfig, syntax);\n }\n\n return config;\n },\n\n // This is a placeholder for the density capability. It doesn't do anything in the bundler.\n // It's just a workaround for a post-bundle task. This will be replaced with 'plugins' in the future.\n density: (config) => config,\n});\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ms-cloudpack/bundler-webpack",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.12",
|
|
4
4
|
"description": "Cloudpack's wrapper for the Webpack bundler",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -25,9 +25,9 @@
|
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"@ms-cloudpack/bundler-capabilities": "^0.5.1",
|
|
28
|
-
"@ms-cloudpack/bundler-utilities": "^0.9.
|
|
28
|
+
"@ms-cloudpack/bundler-utilities": "^0.9.7",
|
|
29
29
|
"@ms-cloudpack/common-types": "^0.33.2",
|
|
30
|
-
"@ms-cloudpack/esm-stub-utilities": "^0.15.
|
|
30
|
+
"@ms-cloudpack/esm-stub-utilities": "^0.15.43",
|
|
31
31
|
"@ms-cloudpack/path-string-parsing": "^1.3.0",
|
|
32
32
|
"@ms-cloudpack/path-utilities": "^3.2.5",
|
|
33
33
|
"@swc/core": "^1.3.0",
|