@ms-cloudpack/bundler-rspack 0.5.33 → 0.6.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/README.md +8 -0
- package/lib/getRspackCapabilities.d.ts.map +1 -1
- package/lib/getRspackCapabilities.js +3 -1
- package/lib/getRspackCapabilities.js.map +1 -1
- package/lib/getRspackConfiguration.d.ts.map +1 -1
- package/lib/getRspackConfiguration.js +12 -5
- package/lib/getRspackConfiguration.js.map +1 -1
- package/lib/getRspackSwcLoader.d.ts +17 -0
- package/lib/getRspackSwcLoader.d.ts.map +1 -0
- package/lib/getRspackSwcLoader.js +17 -0
- package/lib/getRspackSwcLoader.js.map +1 -0
- package/lib/normalizeRspackOutput.d.ts.map +1 -1
- package/lib/normalizeRspackOutput.js +2 -1
- package/lib/normalizeRspackOutput.js.map +1 -1
- package/lib/rspack.d.ts.map +1 -1
- package/lib/rspack.js +14 -1
- package/lib/rspack.js.map +1 -1
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
1
|
# @ms-cloudpack/bundler-rspack
|
|
2
2
|
|
|
3
3
|
Provides a Cloudpack bundler abstraction around the [Rspack](https://rspack.rs/) bundler.
|
|
4
|
+
|
|
5
|
+
## Supported versions
|
|
6
|
+
|
|
7
|
+
As of writing, either `@rspack/core` v1 or v2 is supported, but v1 is on a **best effort basis only** since the Cloudpack repo has been upgraded to v2. (Rspack v1 contains a vendored `tinypool@1.x` affected by known prototype-pollution advisories. The vulnerable path is only hit if a loader explicitly enables `parallel`, which Cloudpack's base configuration does not, but it's still best to prefer Rspack v2.2.2 or newer which includes the fixed `tinypool@>=2.1.2`.)
|
|
8
|
+
|
|
9
|
+
## Relay support
|
|
10
|
+
|
|
11
|
+
If using Relay, you must manually ensure that `@ms-cloudpack/bundler-rspack`'s dependencies on `@swc/plugin-relay` and `@swc/core` are resolved to versions corresponding to the Rust `swc_core` version used by your `@rspack/core` version.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getRspackCapabilities.d.ts","sourceRoot":"","sources":["../src/getRspackCapabilities.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,wCAAwC,EAAE,MAAM,4BAA4B,CAAC;AAEtH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"getRspackCapabilities.d.ts","sourceRoot":"","sources":["../src/getRspackCapabilities.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,wCAAwC,EAAE,MAAM,4BAA4B,CAAC;AAEtH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAKlD,eAAO,MAAM,qBAAqB,WACxB;IAAE,aAAa,EAAE,UAAU,CAAA;CAAE,WAC5B,IAAI,CAAC,aAAa,EAAE,QAAQ,CAAC,KACrC,wCAAwC,CAAC,aAAa,CAyEvD,CAAC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { getSwcRelayPluginConfig, processAssetInlineExtensions } from '@ms-cloudpack/bundler-utilities';
|
|
2
2
|
import { webExtensions } from '@ms-cloudpack/path-utilities';
|
|
3
3
|
import { DefinePlugin } from '@rspack/core';
|
|
4
|
+
import { getRspackSwcLoader } from './getRspackSwcLoader.js';
|
|
4
5
|
export const getRspackCapabilities = (params, context) => ({
|
|
5
6
|
'asset-inline': (config, options) => {
|
|
6
7
|
// Process extensions based on format (array or object)
|
|
@@ -46,11 +47,12 @@ export const getRspackCapabilities = (params, context) => ({
|
|
|
46
47
|
config.module ??= {};
|
|
47
48
|
config.module.rules ??= [];
|
|
48
49
|
const addRelayConfig = getSwcRelayPluginConfig({ options, parentUrl: import.meta.url });
|
|
50
|
+
const swcLoaderName = getRspackSwcLoader({ requiresPluginSupport: true });
|
|
49
51
|
// Apply relay plugin to existing SWC loaders
|
|
50
52
|
for (const syntax of ['typescript', 'ecmascript']) {
|
|
51
53
|
// Find the existing SWC loader for the current syntax
|
|
52
54
|
const swcLoader = config.module.rules.find((rule) => typeof rule === 'object' &&
|
|
53
|
-
rule?.loader ===
|
|
55
|
+
rule?.loader === swcLoaderName &&
|
|
54
56
|
rule.options?.jsc?.parser?.syntax === syntax);
|
|
55
57
|
// Type guard, we shouldn't be hitting this case
|
|
56
58
|
if (!swcLoader || typeof swcLoader !== 'object') {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getRspackCapabilities.js","sourceRoot":"","sources":["../src/getRspackCapabilities.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,4BAA4B,EAAE,MAAM,iCAAiC,CAAC;AAExG,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAE7D,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"getRspackCapabilities.js","sourceRoot":"","sources":["../src/getRspackCapabilities.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,4BAA4B,EAAE,MAAM,iCAAiC,CAAC;AAExG,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAE7D,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE5C,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAE7D,MAAM,CAAC,MAAM,qBAAqB,GAAG,CACnC,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,CAA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F;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 { Configuration } from '@rspack/core';\nimport { DefinePlugin } from '@rspack/core';\nimport type { Config as SwcConfig } from '@swc/core';\nimport { getRspackSwcLoader } from './getRspackSwcLoader.js';\n\nexport const getRspackCapabilities = (\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 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 const swcLoaderName = getRspackSwcLoader({ requiresPluginSupport: true });\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 === swcLoaderName &&\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 addRelayConfig(swcLoader.options as SwcConfig, syntax);\n }\n\n return config;\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"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getRspackConfiguration.d.ts","sourceRoot":"","sources":["../src/getRspackConfiguration.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3F,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AAE5E,OAAO,KAAK,EAAE,aAAa,EAA+C,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"getRspackConfiguration.d.ts","sourceRoot":"","sources":["../src/getRspackConfiguration.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3F,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AAE5E,OAAO,KAAK,EAAE,aAAa,EAA+C,MAAM,cAAc,CAAC;AAO/F,wBAAgB,sBAAsB,CACpC,MAAM,EAAE;IACN,OAAO,EAAE,IAAI,CAAC,aAAa,EAAE,SAAS,GAAG,YAAY,CAAC,CAAC;IACvD,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,EAAE,UAAU,CAAC;CAC3B,GAAG,IAAI,CAAC,mBAAmB,EAAE,YAAY,CAAC,EAC3C,OAAO,EAAE,aAAa,GACrB,aAAa,CAkMf"}
|
|
@@ -4,12 +4,15 @@ import rspack from '@rspack/core';
|
|
|
4
4
|
import semver from 'semver';
|
|
5
5
|
import { fileURLToPath } from 'url';
|
|
6
6
|
import { merge } from 'webpack-merge';
|
|
7
|
+
import { getRspackSwcLoader } from './getRspackSwcLoader.js';
|
|
7
8
|
export function getRspackConfiguration(params, context) {
|
|
8
9
|
const { options, outputPath, newEntries, effectiveMode } = params;
|
|
9
10
|
const { targetEnvironment, dedupeAliases } = options;
|
|
10
11
|
const { unsafeDisableInlineSvg: _, ...bundlerOptions } = options.bundlerOptions || {};
|
|
11
12
|
const outputScriptExtension = targetEnvironment === 'node' ? 'mjs' : 'js';
|
|
13
|
+
const swcLoader = getRspackSwcLoader({ requiresPluginSupport: !!options.bundlerCapabilities?.relay });
|
|
12
14
|
const isLibraryMode = effectiveMode === 'library';
|
|
15
|
+
const isRspackV2 = semver.gte(rspack.rspackVersion, '2.0.0');
|
|
13
16
|
// Only get the SWC config and transform code if needed
|
|
14
17
|
const swcConfig = context.requiresTranspile
|
|
15
18
|
? getSwcConfig({ packagePath: options.inputPath, sourcemap: options.sourcemap, reactRefresh: options.hmr })
|
|
@@ -24,6 +27,8 @@ export function getRspackConfiguration(params, context) {
|
|
|
24
27
|
context: options.inputPath,
|
|
25
28
|
resolve: {
|
|
26
29
|
modules: context.config.resolve?.modules ?? ['node_modules'],
|
|
30
|
+
// V2 defaults roots to []; retain v1's context-relative resolution for requests starting with '/'.
|
|
31
|
+
...(isRspackV2 && { roots: [options.inputPath] }),
|
|
27
32
|
// TODO: Align with other bundlers https://github.com/microsoft/cloudpack/issues/2687
|
|
28
33
|
extensions: ['.ts', '.tsx', '.mjs', '.js', '.jsx', '.json'],
|
|
29
34
|
extensionAlias: {
|
|
@@ -37,7 +42,7 @@ export function getRspackConfiguration(params, context) {
|
|
|
37
42
|
// Resolve loaders from the package's node_modules
|
|
38
43
|
'node_modules',
|
|
39
44
|
// Cloudpack provided loaders
|
|
40
|
-
...getModuleSearchPaths(['css-loader', 'style-loader', 'sass-loader'], import.meta.url),
|
|
45
|
+
...getModuleSearchPaths(['css-loader', 'style-loader', 'sass-loader', ...(swcLoader === 'swc-loader' ? [swcLoader] : [])], import.meta.url),
|
|
41
46
|
],
|
|
42
47
|
alias: {
|
|
43
48
|
// https://rspack.rs/guide/features/web-workers#worker-loader
|
|
@@ -78,6 +83,8 @@ export function getRspackConfiguration(params, context) {
|
|
|
78
83
|
target: [targetEnvironment === 'node' ? 'node18' : 'web', defaultTargetSyntax],
|
|
79
84
|
//plugins: [new rspack.CssExtractRspackPlugin({})],
|
|
80
85
|
module: {
|
|
86
|
+
// V2 disables require aliases by default; preserve v1 behavior for calls like `const load = require; load('pkg')`.
|
|
87
|
+
...(isRspackV2 && { parser: { javascript: { requireAlias: true } } }),
|
|
81
88
|
rules: [
|
|
82
89
|
getCssRule('css'),
|
|
83
90
|
{
|
|
@@ -101,14 +108,14 @@ export function getRspackConfiguration(params, context) {
|
|
|
101
108
|
{
|
|
102
109
|
// transform jsx files
|
|
103
110
|
test: jsxRegex,
|
|
104
|
-
loader:
|
|
111
|
+
loader: swcLoader,
|
|
105
112
|
options: swcConfig.jsx,
|
|
106
113
|
type: 'javascript/auto',
|
|
107
114
|
},
|
|
108
115
|
{
|
|
109
116
|
// transform ts files
|
|
110
117
|
test: typescriptRegex,
|
|
111
|
-
loader:
|
|
118
|
+
loader: swcLoader,
|
|
112
119
|
options: swcConfig.tsx,
|
|
113
120
|
type: 'javascript/auto',
|
|
114
121
|
},
|
|
@@ -141,8 +148,8 @@ export function getRspackConfiguration(params, context) {
|
|
|
141
148
|
chunkFilename: `[id].chunk.${outputScriptExtension}`,
|
|
142
149
|
},
|
|
143
150
|
experiments: {
|
|
144
|
-
|
|
145
|
-
css: false,
|
|
151
|
+
// V2 uses output.module directly and enables native CSS through rule types instead of these experiment flags.
|
|
152
|
+
...(!isRspackV2 && { outputModule: true, css: false }),
|
|
146
153
|
},
|
|
147
154
|
devtool: options.sourcemap ? (isLibraryMode ? 'cheap-module-source-map' : 'source-map') : false,
|
|
148
155
|
optimization: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getRspackConfiguration.js","sourceRoot":"","sources":["../src/getRspackConfiguration.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,UAAU,EACV,oBAAoB,EACpB,YAAY,EACZ,wBAAwB,GACzB,MAAM,iCAAiC,CAAC;AAGzC,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAExF,OAAO,MAAM,MAAM,cAAc,CAAC;AAClC,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AACpC,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAEtC,MAAM,UAAU,sBAAsB,CACpC,MAI2C,EAC3C,OAAsB;IAEtB,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,aAAa,EAAE,GAAG,MAAM,CAAC;IAClE,MAAM,EAAE,iBAAiB,EAAE,aAAa,EAAE,GAAG,OAAO,CAAC;IACrD,MAAM,EAAE,sBAAsB,EAAE,CAAC,EAAE,GAAG,cAAc,EAAE,GAAG,OAAO,CAAC,cAAc,IAAI,EAAE,CAAC;IACtF,MAAM,qBAAqB,GAAG,iBAAiB,KAAK,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;IAE1E,MAAM,aAAa,GAAG,aAAa,KAAK,SAAS,CAAC;IAElD,uDAAuD;IACvD,MAAM,SAAS,GAAG,OAAO,CAAC,iBAAiB;QACzC,CAAC,CAAC,YAAY,CAAC,EAAE,WAAW,EAAE,OAAO,CAAC,SAAS,EAAE,SAAS,EAAE,O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QAC/F,YAAY,EAAE;YACZ,mHAAmH;YACnH,YAAY,EAAE,CAAC,OAAO,CAAC,MAAM,IAAI,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK;YACtF,QAAQ,EAAE,OAAO,CAAC,MAAM;YACxB,aAAa,EAAE,KAAK;YACpB,WAAW,EAAE;gBACX,iFAAiF;gBACjF,YAAY,EAAE,IAAI;gBAElB,mFAAmF;gBACnF,4CAA4C;gBAC5C,wCAAwC;gBACxC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,aAAa,EAAE,cAAc,CAAC,IAAI,EAAE,WAAW,EAAE,CAAC,aAAa,EAAE,CAAC;gBAExF,MAAM,EAAE,KAAK;gBAEb,6CAA6C;gBAC7C,mBAAmB;gBACnB,mDAAmD;gBAEnD,4FAA4F;gBAC5F,OAAO,EAAE,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI;gBAEjC,WAAW,EAAE;oBACX,cAAc,EAAE,KAAK;iBACtB;aACF;SACF;KACF,CAAC;IAEF,IAAI,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,MAAM,EAAE,CAAC;QACvC,OAAO,KAAK,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IACvC,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import {\n defaultTargetSyntax,\n getCssRule,\n getModuleSearchPaths,\n getSwcConfig,\n shouldExternalizePackage,\n} from '@ms-cloudpack/bundler-utilities';\nimport type { BundleContext, BundleMode, BundleOptions } from '@ms-cloudpack/common-types';\nimport type { WriteESMStubsResult } from '@ms-cloudpack/esm-stub-utilities';\nimport { jsxRegex, resolveModule, typescriptRegex } from '@ms-cloudpack/path-utilities';\nimport type { Configuration, ExternalItemFunctionData, ExternalItemValue } from '@rspack/core';\nimport rspack from '@rspack/core';\nimport semver from 'semver';\nimport { fileURLToPath } from 'url';\nimport { merge } from 'webpack-merge';\n\nexport function getRspackConfiguration(\n params: {\n options: Omit<BundleOptions, 'entries' | 'outputPath'>;\n outputPath: string;\n effectiveMode: BundleMode;\n } & Pick<WriteESMStubsResult, 'newEntries'>,\n context: BundleContext,\n): Configuration {\n const { options, outputPath, newEntries, effectiveMode } = params;\n const { targetEnvironment, dedupeAliases } = options;\n const { unsafeDisableInlineSvg: _, ...bundlerOptions } = options.bundlerOptions || {};\n const outputScriptExtension = targetEnvironment === 'node' ? 'mjs' : 'js';\n\n const isLibraryMode = effectiveMode === 'library';\n\n // Only get the SWC config and transform code if needed\n const swcConfig = context.requiresTranspile\n ? getSwcConfig({ packagePath: options.inputPath, sourcemap: options.sourcemap, reactRefresh: options.hmr })\n : undefined;\n\n const config: Configuration = {\n mode: options.minify ? 'production' : 'development',\n // For Rspack, it looks like this following is still needed as unit tests fail without removing the './'.\n // Webpack (at least older versions) expects entry keys without a leading `./`.\n // (The leading `./` seems to be okay with the latest version, but in older versions, it appears\n // to cause the runtime chunk runtime.js to be generated with an incorrect relative path?)\n entry: Object.fromEntries(Object.entries(newEntries).map(([key, value]) => [key.replace(/^\\.\\//, ''), value])),\n context: options.inputPath,\n resolve: {\n modules: context.config.resolve?.modules ?? ['node_modules'],\n // TODO: Align with other bundlers https://github.com/microsoft/cloudpack/issues/2687\n extensions: ['.ts', '.tsx', '.mjs', '.js', '.jsx', '.json'],\n extensionAlias: {\n '.js': ['.ts', '.js', '.tsx', '.jsx'],\n '.mjs': ['.mts', '.mjs'],\n },\n alias: dedupeAliases,\n },\n resolveLoader: {\n modules: [\n // Resolve loaders from the package's node_modules\n 'node_modules',\n\n // Cloudpack provided loaders\n ...getModuleSearchPaths(['css-loader', 'style-loader', 'sass-loader'], import.meta.url),\n ],\n alias: {\n // https://rspack.rs/guide/features/web-workers#worker-loader\n 'worker-loader': fileURLToPath(\n resolveModule({ importSpecifier: 'worker-rspack-loader', parentUrl: import.meta.url }),\n ),\n },\n },\n externals:\n // In production mode for browser bundles, we don't externalize anything.\n // (For Node bundles, built-ins are always externalized with enableSSR feature.)\n !isLibraryMode && targetEnvironment === 'browser'\n ? [] // These types can't be inferred due to use of zod types (which may be slightly incorrect too,\n : // since they don't allow returning undefined from the async version).\n // Issue: https://github.com/web-infra-dev/rspack/issues/7979\n // There's discussion here of moving away from zod types: https://github.com/web-infra-dev/rspack/issues/4241\n // eslint-disable-next-line @typescript-eslint/require-await -- API signature uses a promise\n async (data: ExternalItemFunctionData): Promise<ExternalItemValue | undefined> => {\n const { request } = data;\n // ! is a webpack loader prefix.\n if (!request || request.includes('!')) {\n return;\n }\n\n if (\n shouldExternalizePackage({\n packageName: options.packageName,\n inputPath: options.inputPath,\n id: request,\n parent: data.context,\n inlined: options.inlined,\n external: options.external,\n shouldInlineNodeBuiltins: false,\n targetEnvironment,\n mode: effectiveMode,\n })\n ) {\n // Manually force externals to use `externalsType: 'module-import'` to ensure that\n // async import() statements are preserved (otherwise they'll be hoisted).\n return `module-import ${request}`;\n }\n },\n target: [targetEnvironment === 'node' ? 'node18' : 'web', defaultTargetSyntax],\n //plugins: [new rspack.CssExtractRspackPlugin({})],\n module: {\n rules: [\n getCssRule('css'),\n {\n test: /\\.(json|resjson)$/,\n type: 'json',\n sideEffects: false,\n },\n {\n test: /\\.ejs$/,\n loader: 'ejs-loader',\n options: {\n variable: 'data',\n esModule: true,\n },\n resolve: {\n fullySpecified: false,\n },\n },\n ...(swcConfig\n ? [\n {\n // transform jsx files\n test: jsxRegex,\n loader: 'builtin:swc-loader',\n options: swcConfig.jsx,\n type: 'javascript/auto',\n },\n {\n // transform ts files\n test: typescriptRegex,\n loader: 'builtin:swc-loader',\n options: swcConfig.tsx,\n type: 'javascript/auto',\n },\n ]\n : []),\n getCssRule('sass'),\n {\n test: /\\.worker\\.js$/,\n use: { loader: 'worker-rspack-loader' },\n },\n {\n test: /\\.wasm$/i,\n type: 'asset/resource',\n },\n {\n test: /\\.glsl$/,\n type: 'asset/source',\n },\n ],\n },\n output: {\n library: {\n type: 'module',\n },\n chunkFormat: 'module',\n chunkLoading: 'import',\n path: outputPath,\n module: true,\n filename: `[name].${outputScriptExtension}`,\n chunkFilename: `[id].chunk.${outputScriptExtension}`,\n },\n experiments: {\n outputModule: true,\n css: false,\n },\n devtool: options.sourcemap ? (isLibraryMode ? 'cheap-module-source-map' : 'source-map') : false,\n optimization: {\n // In production, always inline runtime. In development, create a separate runtime chunk only for multiple entries.\n runtimeChunk: !options.minify && Object.keys(newEntries).length > 1 ? 'single' : false,\n minimize: options.minify,\n mangleExports: false,\n splitChunks: {\n // Prevents exposing path info when creating names for parts splitted by maxSize.\n hidePathInfo: true,\n\n // Figure out which exports are used by modules to mangle export names, omit unused\n // exports and generate more efficient code.\n // This option was added in 1.0.0-beta.4\n ...(semver.gte(rspack.rspackVersion, '1.0.0-beta.4') && { usedExports: !isLibraryMode }),\n\n chunks: 'all',\n\n //name: '[id].chunk', //TODO: is this needed?\n // webpack version:\n // filename: `[id].chunk.${outputScriptExtension}`,\n\n // Production chunks should be at least 1000 bytes to prevent large numbers of file requests\n minSize: isLibraryMode ? 0 : 1000,\n\n cacheGroups: {\n defaultVendors: false,\n },\n },\n },\n };\n\n if (Object.keys(bundlerOptions).length) {\n return merge(config, bundlerOptions);\n }\n\n return config;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"getRspackConfiguration.js","sourceRoot":"","sources":["../src/getRspackConfiguration.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,UAAU,EACV,oBAAoB,EACpB,YAAY,EACZ,wBAAwB,GACzB,MAAM,iCAAiC,CAAC;AAGzC,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAExF,OAAO,MAAM,MAAM,cAAc,CAAC;AAClC,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AACpC,OA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,CAAC,yBAAyB,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,KAAK;QAC/F,YAAY,EAAE;YACZ,mHAAmH;YACnH,YAAY,EAAE,CAAC,OAAO,CAAC,MAAM,IAAI,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK;YACtF,QAAQ,EAAE,OAAO,CAAC,MAAM;YACxB,aAAa,EAAE,KAAK;YACpB,WAAW,EAAE;gBACX,iFAAiF;gBACjF,YAAY,EAAE,IAAI;gBAElB,mFAAmF;gBACnF,4CAA4C;gBAC5C,wCAAwC;gBACxC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,aAAa,EAAE,cAAc,CAAC,IAAI,EAAE,WAAW,EAAE,CAAC,aAAa,EAAE,CAAC;gBAExF,MAAM,EAAE,KAAK;gBAEb,6CAA6C;gBAC7C,mBAAmB;gBACnB,mDAAmD;gBAEnD,4FAA4F;gBAC5F,OAAO,EAAE,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI;gBAEjC,WAAW,EAAE;oBACX,cAAc,EAAE,KAAK;iBACtB;aACF;SACF;KACF,CAAC;IAEF,IAAI,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,MAAM,EAAE,CAAC;QACvC,OAAO,KAAK,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IACvC,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import {\n defaultTargetSyntax,\n getCssRule,\n getModuleSearchPaths,\n getSwcConfig,\n shouldExternalizePackage,\n} from '@ms-cloudpack/bundler-utilities';\nimport type { BundleContext, BundleMode, BundleOptions } from '@ms-cloudpack/common-types';\nimport type { WriteESMStubsResult } from '@ms-cloudpack/esm-stub-utilities';\nimport { jsxRegex, resolveModule, typescriptRegex } from '@ms-cloudpack/path-utilities';\nimport type { Configuration, ExternalItemFunctionData, ExternalItemValue } from '@rspack/core';\nimport rspack from '@rspack/core';\nimport semver from 'semver';\nimport { fileURLToPath } from 'url';\nimport { merge } from 'webpack-merge';\nimport { getRspackSwcLoader } from './getRspackSwcLoader.js';\n\nexport function getRspackConfiguration(\n params: {\n options: Omit<BundleOptions, 'entries' | 'outputPath'>;\n outputPath: string;\n effectiveMode: BundleMode;\n } & Pick<WriteESMStubsResult, 'newEntries'>,\n context: BundleContext,\n): Configuration {\n const { options, outputPath, newEntries, effectiveMode } = params;\n const { targetEnvironment, dedupeAliases } = options;\n const { unsafeDisableInlineSvg: _, ...bundlerOptions } = options.bundlerOptions || {};\n const outputScriptExtension = targetEnvironment === 'node' ? 'mjs' : 'js';\n const swcLoader = getRspackSwcLoader({ requiresPluginSupport: !!options.bundlerCapabilities?.relay });\n\n const isLibraryMode = effectiveMode === 'library';\n const isRspackV2 = semver.gte(rspack.rspackVersion, '2.0.0');\n\n // Only get the SWC config and transform code if needed\n const swcConfig = context.requiresTranspile\n ? getSwcConfig({ packagePath: options.inputPath, sourcemap: options.sourcemap, reactRefresh: options.hmr })\n : undefined;\n\n const config: Configuration = {\n mode: options.minify ? 'production' : 'development',\n // For Rspack, it looks like this following is still needed as unit tests fail without removing the './'.\n // Webpack (at least older versions) expects entry keys without a leading `./`.\n // (The leading `./` seems to be okay with the latest version, but in older versions, it appears\n // to cause the runtime chunk runtime.js to be generated with an incorrect relative path?)\n entry: Object.fromEntries(Object.entries(newEntries).map(([key, value]) => [key.replace(/^\\.\\//, ''), value])),\n context: options.inputPath,\n resolve: {\n modules: context.config.resolve?.modules ?? ['node_modules'],\n // V2 defaults roots to []; retain v1's context-relative resolution for requests starting with '/'.\n ...(isRspackV2 && { roots: [options.inputPath] }),\n // TODO: Align with other bundlers https://github.com/microsoft/cloudpack/issues/2687\n extensions: ['.ts', '.tsx', '.mjs', '.js', '.jsx', '.json'],\n extensionAlias: {\n '.js': ['.ts', '.js', '.tsx', '.jsx'],\n '.mjs': ['.mts', '.mjs'],\n },\n alias: dedupeAliases,\n },\n resolveLoader: {\n modules: [\n // Resolve loaders from the package's node_modules\n 'node_modules',\n\n // Cloudpack provided loaders\n ...getModuleSearchPaths(\n ['css-loader', 'style-loader', 'sass-loader', ...(swcLoader === 'swc-loader' ? [swcLoader] : [])],\n import.meta.url,\n ),\n ],\n alias: {\n // https://rspack.rs/guide/features/web-workers#worker-loader\n 'worker-loader': fileURLToPath(\n resolveModule({ importSpecifier: 'worker-rspack-loader', parentUrl: import.meta.url }),\n ),\n },\n },\n externals:\n // In production mode for browser bundles, we don't externalize anything.\n // (For Node bundles, built-ins are always externalized with enableSSR feature.)\n !isLibraryMode && targetEnvironment === 'browser'\n ? [] // These types can't be inferred due to use of zod types (which may be slightly incorrect too,\n : // since they don't allow returning undefined from the async version).\n // Issue: https://github.com/web-infra-dev/rspack/issues/7979\n // There's discussion here of moving away from zod types: https://github.com/web-infra-dev/rspack/issues/4241\n // eslint-disable-next-line @typescript-eslint/require-await -- API signature uses a promise\n async (data: ExternalItemFunctionData): Promise<ExternalItemValue | undefined> => {\n const { request } = data;\n // ! is a webpack loader prefix.\n if (!request || request.includes('!')) {\n return;\n }\n\n if (\n shouldExternalizePackage({\n packageName: options.packageName,\n inputPath: options.inputPath,\n id: request,\n parent: data.context,\n inlined: options.inlined,\n external: options.external,\n shouldInlineNodeBuiltins: false,\n targetEnvironment,\n mode: effectiveMode,\n })\n ) {\n // Manually force externals to use `externalsType: 'module-import'` to ensure that\n // async import() statements are preserved (otherwise they'll be hoisted).\n return `module-import ${request}`;\n }\n },\n target: [targetEnvironment === 'node' ? 'node18' : 'web', defaultTargetSyntax],\n //plugins: [new rspack.CssExtractRspackPlugin({})],\n module: {\n // V2 disables require aliases by default; preserve v1 behavior for calls like `const load = require; load('pkg')`.\n ...(isRspackV2 && { parser: { javascript: { requireAlias: true } } }),\n rules: [\n getCssRule('css'),\n {\n test: /\\.(json|resjson)$/,\n type: 'json',\n sideEffects: false,\n },\n {\n test: /\\.ejs$/,\n loader: 'ejs-loader',\n options: {\n variable: 'data',\n esModule: true,\n },\n resolve: {\n fullySpecified: false,\n },\n },\n ...(swcConfig\n ? [\n {\n // transform jsx files\n test: jsxRegex,\n loader: swcLoader,\n options: swcConfig.jsx,\n type: 'javascript/auto',\n },\n {\n // transform ts files\n test: typescriptRegex,\n loader: swcLoader,\n options: swcConfig.tsx,\n type: 'javascript/auto',\n },\n ]\n : []),\n getCssRule('sass'),\n {\n test: /\\.worker\\.js$/,\n use: { loader: 'worker-rspack-loader' },\n },\n {\n test: /\\.wasm$/i,\n type: 'asset/resource',\n },\n {\n test: /\\.glsl$/,\n type: 'asset/source',\n },\n ],\n },\n output: {\n library: {\n type: 'module',\n },\n chunkFormat: 'module',\n chunkLoading: 'import',\n path: outputPath,\n module: true,\n filename: `[name].${outputScriptExtension}`,\n chunkFilename: `[id].chunk.${outputScriptExtension}`,\n },\n experiments: {\n // V2 uses output.module directly and enables native CSS through rule types instead of these experiment flags.\n ...(!isRspackV2 && { outputModule: true, css: false }),\n },\n devtool: options.sourcemap ? (isLibraryMode ? 'cheap-module-source-map' : 'source-map') : false,\n optimization: {\n // In production, always inline runtime. In development, create a separate runtime chunk only for multiple entries.\n runtimeChunk: !options.minify && Object.keys(newEntries).length > 1 ? 'single' : false,\n minimize: options.minify,\n mangleExports: false,\n splitChunks: {\n // Prevents exposing path info when creating names for parts splitted by maxSize.\n hidePathInfo: true,\n\n // Figure out which exports are used by modules to mangle export names, omit unused\n // exports and generate more efficient code.\n // This option was added in 1.0.0-beta.4\n ...(semver.gte(rspack.rspackVersion, '1.0.0-beta.4') && { usedExports: !isLibraryMode }),\n\n chunks: 'all',\n\n //name: '[id].chunk', //TODO: is this needed?\n // webpack version:\n // filename: `[id].chunk.${outputScriptExtension}`,\n\n // Production chunks should be at least 1000 bytes to prevent large numbers of file requests\n minSize: isLibraryMode ? 0 : 1000,\n\n cacheGroups: {\n defaultVendors: false,\n },\n },\n },\n };\n\n if (Object.keys(bundlerOptions).length) {\n return merge(config, bundlerOptions);\n }\n\n return config;\n}\n"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export type RspackSwcLoader = 'builtin:swc-loader' | 'swc-loader';
|
|
2
|
+
/**
|
|
3
|
+
* Rspack builds its Windows ARM64 binding without SWC WASM plugin support, so use the external
|
|
4
|
+
* SWC loader there when a bundle requires plugins such as Relay.
|
|
5
|
+
*
|
|
6
|
+
* - [Windows ARM64 build sets `DISABLE_PLUGIN=1`](https://github.com/web-infra-dev/rspack/blob/v1.4.11/.github/workflows/reusable-build-build.yml#L153-L155)
|
|
7
|
+
* - [`DISABLE_PLUGIN` prevents enabling the Cargo `plugin` feature](https://github.com/web-infra-dev/rspack/blob/v1.4.11/crates/node_binding/scripts/build.js#L59-L62)
|
|
8
|
+
* - [That feature provides SWC’s native plugin-transform host](https://github.com/web-infra-dev/rspack/blob/v1.4.11/crates/rspack_loader_swc/Cargo.toml#L11-L17)
|
|
9
|
+
* - [`@swc/plugin-relay` declares a `.wasm` file as its entry point](https://unpkg.com/@swc/plugin-relay@9.5.0/package.json)
|
|
10
|
+
* - [Unmerged follow-up PR lists Windows ARM64 as excluded due to limited plugin runtime support](https://github.com/web-infra-dev/rspack/pull/11309)
|
|
11
|
+
*/
|
|
12
|
+
export declare function getRspackSwcLoader(params: {
|
|
13
|
+
requiresPluginSupport: boolean;
|
|
14
|
+
platform?: NodeJS.Platform;
|
|
15
|
+
architecture?: string;
|
|
16
|
+
}): RspackSwcLoader;
|
|
17
|
+
//# sourceMappingURL=getRspackSwcLoader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getRspackSwcLoader.d.ts","sourceRoot":"","sources":["../src/getRspackSwcLoader.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,eAAe,GAAG,oBAAoB,GAAG,YAAY,CAAC;AAElE;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE;IACzC,qBAAqB,EAAE,OAAO,CAAC;IAC/B,QAAQ,CAAC,EAAE,MAAM,CAAC,QAAQ,CAAC;IAC3B,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,GAAG,eAAe,CAKlB"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rspack builds its Windows ARM64 binding without SWC WASM plugin support, so use the external
|
|
3
|
+
* SWC loader there when a bundle requires plugins such as Relay.
|
|
4
|
+
*
|
|
5
|
+
* - [Windows ARM64 build sets `DISABLE_PLUGIN=1`](https://github.com/web-infra-dev/rspack/blob/v1.4.11/.github/workflows/reusable-build-build.yml#L153-L155)
|
|
6
|
+
* - [`DISABLE_PLUGIN` prevents enabling the Cargo `plugin` feature](https://github.com/web-infra-dev/rspack/blob/v1.4.11/crates/node_binding/scripts/build.js#L59-L62)
|
|
7
|
+
* - [That feature provides SWC’s native plugin-transform host](https://github.com/web-infra-dev/rspack/blob/v1.4.11/crates/rspack_loader_swc/Cargo.toml#L11-L17)
|
|
8
|
+
* - [`@swc/plugin-relay` declares a `.wasm` file as its entry point](https://unpkg.com/@swc/plugin-relay@9.5.0/package.json)
|
|
9
|
+
* - [Unmerged follow-up PR lists Windows ARM64 as excluded due to limited plugin runtime support](https://github.com/web-infra-dev/rspack/pull/11309)
|
|
10
|
+
*/
|
|
11
|
+
export function getRspackSwcLoader(params) {
|
|
12
|
+
const { requiresPluginSupport, platform = process.platform, architecture = process.arch } = params;
|
|
13
|
+
return requiresPluginSupport && platform === 'win32' && architecture === 'arm64'
|
|
14
|
+
? 'swc-loader'
|
|
15
|
+
: 'builtin:swc-loader';
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=getRspackSwcLoader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getRspackSwcLoader.js","sourceRoot":"","sources":["../src/getRspackSwcLoader.ts"],"names":[],"mappings":"AAEA;;;;;;;;;GASG;AACH,MAAM,UAAU,kBAAkB,CAAC,MAIlC;IACC,MAAM,EAAE,qBAAqB,EAAE,QAAQ,GAAG,OAAO,CAAC,QAAQ,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,EAAE,GAAG,MAAM,CAAC;IACnG,OAAO,qBAAqB,IAAI,QAAQ,KAAK,OAAO,IAAI,YAAY,KAAK,OAAO;QAC9E,CAAC,CAAC,YAAY;QACd,CAAC,CAAC,oBAAoB,CAAC;AAC3B,CAAC","sourcesContent":["export type RspackSwcLoader = 'builtin:swc-loader' | 'swc-loader';\n\n/**\n * Rspack builds its Windows ARM64 binding without SWC WASM plugin support, so use the external\n * SWC loader there when a bundle requires plugins such as Relay.\n *\n * - [Windows ARM64 build sets `DISABLE_PLUGIN=1`](https://github.com/web-infra-dev/rspack/blob/v1.4.11/.github/workflows/reusable-build-build.yml#L153-L155)\n * - [`DISABLE_PLUGIN` prevents enabling the Cargo `plugin` feature](https://github.com/web-infra-dev/rspack/blob/v1.4.11/crates/node_binding/scripts/build.js#L59-L62)\n * - [That feature provides SWC’s native plugin-transform host](https://github.com/web-infra-dev/rspack/blob/v1.4.11/crates/rspack_loader_swc/Cargo.toml#L11-L17)\n * - [`@swc/plugin-relay` declares a `.wasm` file as its entry point](https://unpkg.com/@swc/plugin-relay@9.5.0/package.json)\n * - [Unmerged follow-up PR lists Windows ARM64 as excluded due to limited plugin runtime support](https://github.com/web-infra-dev/rspack/pull/11309)\n */\nexport function getRspackSwcLoader(params: {\n requiresPluginSupport: boolean;\n platform?: NodeJS.Platform;\n architecture?: string;\n}): RspackSwcLoader {\n const { requiresPluginSupport, platform = process.platform, architecture = process.arch } = params;\n return requiresPluginSupport && platform === 'win32' && architecture === 'arm64'\n ? 'swc-loader'\n : 'builtin:swc-loader';\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"normalizeRspackOutput.d.ts","sourceRoot":"","sources":["../src/normalizeRspackOutput.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAiB,aAAa,EAAoB,aAAa,EAAE,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"normalizeRspackOutput.d.ts","sourceRoot":"","sources":["../src/normalizeRspackOutput.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAiB,aAAa,EAAoB,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAKhH,OAAO,KAAK,EAAE,aAAa,EAAE,gBAAgB,EAAc,MAAM,cAAc,CAAC;AAIhF,wBAAgB,qBAAqB,CAAC,MAAM,EAAE;IAC5C,oBAAoB;IACpB,MAAM,EAAE,aAAa,CAAC;IACtB,uBAAuB;IACvB,OAAO,EAAE,IAAI,CAAC,aAAa,EAAE,SAAS,GAAG,WAAW,CAAC,CAAC;IACtD,2BAA2B;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,iCAAiC;IACjC,KAAK,EAAE,gBAAgB,GAAG,SAAS,CAAC;CACrC,GAAG,aAAa,CAoDhB"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { normalizeRelativePath } from '@ms-cloudpack/path-string-parsing';
|
|
2
2
|
import { normalizedPathRelativeTo } from '@ms-cloudpack/path-utilities';
|
|
3
|
+
import { stripVTControlCharacters } from 'node:util';
|
|
3
4
|
import path from 'path';
|
|
4
5
|
const outExtRegex = /\.m?js$/;
|
|
5
6
|
export function normalizeRspackOutput(params) {
|
|
@@ -70,7 +71,7 @@ function createBundleMessages(rspackErrors, inputPath) {
|
|
|
70
71
|
// · ─
|
|
71
72
|
// ╰────
|
|
72
73
|
// group 1: line number; group 2: length = column number (0-indexed)
|
|
73
|
-
const errorMatch = error.message.match(/(\d+) │ .*\n +· ( *)─/);
|
|
74
|
+
const errorMatch = stripVTControlCharacters(error.message).match(/(\d+) │ .*\n +· ( *)─/);
|
|
74
75
|
if (errorMatch) {
|
|
75
76
|
line = errorMatch[1];
|
|
76
77
|
col = `${errorMatch[2].length}`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"normalizeRspackOutput.js","sourceRo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MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS;aAC1D,CAAC;QACJ,CAAC;QAED,OAAO,aAAa,CAAC;IACvB,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type { BundleMessage, BundleOptions, BundleOutputFile, BundlerResult } from '@ms-cloudpack/common-types';\nimport { normalizeRelativePath } from '@ms-cloudpack/path-string-parsing';\nimport { normalizedPathRelativeTo } from '@ms-cloudpack/path-utilities';\nimport { stripVTControlCharacters } from 'node:util';\nimport path from 'path';\nimport type { Configuration, StatsCompilation, StatsError } from '@rspack/core';\n\nconst outExtRegex = /\\.m?js$/;\n\nexport function normalizeRspackOutput(params: {\n /** Rspack config */\n config: Configuration;\n /** Original options */\n options: Pick<BundleOptions, 'entries' | 'inputPath'>;\n /** Absolute output path */\n outputPath: string;\n /** Stats from rspack callback */\n stats: StatsCompilation | undefined;\n}): BundlerResult {\n const {\n config,\n options: { entries, inputPath },\n outputPath,\n stats,\n } = params;\n\n // Process the errors and warnings from the stats json.\n // This provides more straightforward access to file paths.\n return {\n outputPath,\n outputFiles: (stats?.assets || []).map((asset): BundleOutputFile => {\n const outFile: BundleOutputFile = {\n outputPath: normalizeRelativePath(asset.name),\n };\n\n // Webpack doesn't include entry point info in the output, so add manually if applicable\n if (outExtRegex.test(outFile.outputPath)) {\n const entryPoint = entries[outFile.outputPath.replace(outExtRegex, '')];\n if (entryPoint) {\n outFile.entryPoint = entryPoint;\n }\n\n const [chunkName] = Object.entries(stats?.assetsByChunkName ?? {}).find(([_, value]) =>\n value.includes(asset.name),\n ) ?? [undefined];\n const relatedChunk = chunkName ? stats?.chunks?.find((chunk) => chunk.id === chunkName) : undefined;\n const relatedModule = relatedChunk?.modules?.find((module) => module.id === entryPoint);\n outFile.exports = relatedModule?.providedExports ?? undefined;\n\n for (const chunk of stats?.chunks || []) {\n // We don't have enough info to determine if a file is a worker\n if (!chunk.files || !chunk.modules || !chunk.files.includes(asset.name)) {\n continue;\n }\n\n // Check if the chunk has a worker\n if (chunk.modules.some(({ reasons = [] }) => reasons.some((reason) => reason.type === 'new Worker()'))) {\n // It is a worker!\n outFile.isWorker = true;\n }\n }\n }\n\n return outFile;\n }),\n errors: createBundleMessages(stats?.errors, inputPath),\n warnings: createBundleMessages(stats?.warnings, inputPath),\n rawInput: config,\n rawOutput: stats,\n };\n}\n\n/** Create BundleMessages from rspackErrors */\nfunction createBundleMessages(rspackErrors: StatsError[] | undefined, inputPath: string): BundleMessage[] {\n return (rspackErrors || []).map((error) => {\n const bundleMessage: BundleMessage = {\n text: error.message,\n source: 'rspack',\n };\n\n const filePath = error.file || error.moduleName;\n\n if (filePath) {\n let [, line, col] = error?.loc?.match(/^(\\d+):(\\d+)/) || [];\n if (!line) {\n // look for something like '[<file path>:<line>:<col>]'\n [, line, col] = error.message.match(/:(\\d+):(\\d+)\\]/) || [];\n }\n if (!line) {\n // rspack errors can look like this:\n // × HarmonyLinkingError: export 'foo' (reexported as 'foo') was not found in './bar.js' (possible exports: bar)\n // ╭────\n // 1 │ export { foo } from './bar.js';\n // · ───────────────────────────────\n // ╰────\n\n // × Module parse failed:\n // ╰─▶ × JavaScript parsing error: Expression expected\n // ╭────\n // 1 │ }export default function() { console.log('oops leading closing bracket'); }\n // · ─\n // ╰────\n // group 1: line number; group 2: length = column number (0-indexed)\n const errorMatch = stripVTControlCharacters(error.message).match(/(\\d+) │ .*\\n +· ( *)─/);\n if (errorMatch) {\n line = errorMatch[1];\n col = `${errorMatch[2].length}`;\n }\n }\n\n bundleMessage.location = {\n file: path.isAbsolute(filePath)\n ? normalizedPathRelativeTo(inputPath, filePath)\n : normalizeRelativePath(filePath),\n line: typeof line === 'string' ? Number(line) : undefined,\n column: typeof col === 'string' ? Number(col) : undefined,\n };\n }\n\n return bundleMessage;\n });\n}\n"]}
|
package/lib/rspack.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rspack.d.ts","sourceRoot":"","sources":["../src/rspack.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAGV,OAAO,EAER,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EAA6D,KAAK,aAAa,EAAE,MAAM,cAAc,CAAC;AAS7G,MAAM,MAAM,sBAAsB,GAAG,aAAa,CAAC;AAEnD,eAAO,MAAM,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"rspack.d.ts","sourceRoot":"","sources":["../src/rspack.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAGV,OAAO,EAER,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EAA6D,KAAK,aAAa,EAAE,MAAM,cAAc,CAAC;AAS7G,MAAM,MAAM,sBAAsB,GAAG,aAAa,CAAC;AAEnD,eAAO,MAAM,MAAM,EAAE,OAmEpB,CAAC"}
|
package/lib/rspack.js
CHANGED
|
@@ -34,7 +34,20 @@ export const rspack = {
|
|
|
34
34
|
});
|
|
35
35
|
try {
|
|
36
36
|
const stats = await new Promise((resolve, reject) => {
|
|
37
|
-
runRspack(config, (err, statsResult) =>
|
|
37
|
+
runRspack(config, (err, statsResult) => err
|
|
38
|
+
? reject(err)
|
|
39
|
+
: resolve(statsResult?.toJson({
|
|
40
|
+
all: false,
|
|
41
|
+
assets: true,
|
|
42
|
+
cachedAssets: true,
|
|
43
|
+
chunks: true,
|
|
44
|
+
chunkModules: true,
|
|
45
|
+
reasons: true,
|
|
46
|
+
ids: true,
|
|
47
|
+
providedExports: true,
|
|
48
|
+
errors: true,
|
|
49
|
+
warnings: true,
|
|
50
|
+
})));
|
|
38
51
|
});
|
|
39
52
|
// Normalize the output outside the callback, so if there's an exception it's not swallowed
|
|
40
53
|
return normalizeRspackOutput({ stats, config, outputPath, options });
|
package/lib/rspack.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rspack.js","sourceRoot":"","sources":["../src/rspack.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AAOzE,2FAA2F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,IAAI;wBAClB,MAAM,EAAE,IAAI;wBACZ,YAAY,EAAE,IAAI;wBAClB,OAAO,EAAE,IAAI;wBACb,GAAG,EAAE,IAAI;wBACT,eAAe,EAAE,IAAI;wBACrB,MAAM,EAAE,IAAI;wBACZ,QAAQ,EAAE,IAAI;qBACf,CAAC,CACH,CACN,CAAC;YACJ,CAAC,CAAC,CAAC;YAEH,2FAA2F;YAC3F,OAAO,qBAAqB,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,CAAC,CAAC;QACvE,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,MAAM,YAAY,GAAkB,EAAE,IAAI,EAAG,GAAa,CAAC,OAAO,IAAI,MAAM,CAAC,GAAG,CAAC,EAAE,MAAM,EAAE,WAAW,EAAE,CAAC;YACzG,IAAI,GAAG,YAAY,KAAK,IAAI,GAAG,CAAC,KAAK,EAAE,CAAC;gBACtC,oCAAoC;gBACpC,YAAY,CAAC,KAAK,GAAG,CAAC,EAAE,IAAI,EAAE,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,CAAC;YACjH,CAAC;YACD,OAAO;gBACL,MAAM,EAAE,CAAC,YAAY,CAAC;gBACtB,QAAQ,EAAE,MAAM;aACjB,CAAC;QACJ,CAAC;IACH,CAAC;CACF,CAAC","sourcesContent":["import { processCapabilities } from '@ms-cloudpack/bundler-capabilities';\nimport type {\n BundleMessage,\n BundlerCapabilitiesOptions,\n Bundler,\n InternalBundlerCapabilitiesOptions,\n} from '@ms-cloudpack/common-types';\n// With rspack, `version` is actually the webpack version! We need `rspackVersion` instead.\nimport { rspack as runRspack, type StatsCompilation, rspackVersion, type RspackOptions } from '@rspack/core';\nimport { getRspackCapabilities } from './getRspackCapabilities.js';\nimport { getRspackConfiguration } from './getRspackConfiguration.js';\nimport { writeESMStubsInWorker } from '@ms-cloudpack/esm-stub-utilities';\nimport { normalizeRspackOutput } from './normalizeRspackOutput.js';\nimport { base64AssetExtensions } from '@ms-cloudpack/path-utilities';\n\nconst bundlerName = 'rspack';\n\nexport type RspackCapabilityConfig = RspackOptions;\n\nexport const rspack: Bundler = {\n name: bundlerName,\n version: rspackVersion,\n bundle: async function (options, context) {\n const { errors, newEntries } = await writeESMStubsInWorker(options);\n if (errors?.length) {\n return { errors };\n }\n\n const outputPath = options.outputPath ?? options.inputPath;\n\n const bundlerCapabilitiesOptions: BundlerCapabilitiesOptions = {\n // Enable asset-inline by default for common image types\n 'asset-inline': { extensions: base64AssetExtensions },\n // Enable define capability by default\n define: true,\n ...(options.bundlerCapabilities || {}),\n } satisfies InternalBundlerCapabilitiesOptions;\n\n // If targeting node and full SSR isn't enabled, treat it like production mode.\n const effectiveMode =\n options.targetEnvironment === 'node' && !context.config.features?.enableSSR ? 'production' : context.config.mode;\n\n const config = await processCapabilities<RspackCapabilityConfig>({\n bundlerName,\n baseConfig: getRspackConfiguration({ options, outputPath, newEntries, effectiveMode }, context),\n bundlerCapabilitiesOptions,\n internalCapabilities: getRspackCapabilities({ effectiveMode }, context),\n bundlerCapabilitiesRegistry: context.config.bundlerCapabilitiesRegistry,\n });\n\n try {\n const stats = await new Promise<StatsCompilation | undefined>((resolve, reject) => {\n runRspack(config, (err, statsResult) =>\n err\n ? reject(err)\n : resolve(\n statsResult?.toJson({\n all: false,\n assets: true,\n cachedAssets: true,\n chunks: true,\n chunkModules: true,\n reasons: true,\n ids: true,\n providedExports: true,\n errors: true,\n warnings: true,\n }),\n ),\n );\n });\n\n // Normalize the output outside the callback, so if there's an exception it's not swallowed\n return normalizeRspackOutput({ stats, config, outputPath, options });\n } catch (err) {\n const errorMessage: BundleMessage = { text: (err as Error).message || String(err), source: bundlerName };\n if (err instanceof Error && err.stack) {\n // remove the message from the stack\n errorMessage.notes = [{ text: err.stack.includes(err.message) ? err.stack.split(err.message)[1] : err.stack }];\n }\n return {\n errors: [errorMessage],\n rawInput: config,\n };\n }\n },\n};\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ms-cloudpack/bundler-rspack",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Cloudpack's wrapper for the Rspack bundler",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -27,10 +27,10 @@
|
|
|
27
27
|
"@ms-cloudpack/bundler-capabilities": "^0.5.10",
|
|
28
28
|
"@ms-cloudpack/bundler-utilities": "^0.9.25",
|
|
29
29
|
"@ms-cloudpack/common-types": "^0.34.6",
|
|
30
|
-
"@ms-cloudpack/esm-stub-utilities": "^0.16.
|
|
30
|
+
"@ms-cloudpack/esm-stub-utilities": "^0.16.12",
|
|
31
31
|
"@ms-cloudpack/path-string-parsing": "^1.3.6",
|
|
32
32
|
"@ms-cloudpack/path-utilities": "^3.2.17",
|
|
33
|
-
"@rspack/core": "^1.1.8 || ^1.1.8-beta.0",
|
|
33
|
+
"@rspack/core": "^1.1.8 || ^1.1.8-beta.0 || ^2.2.2",
|
|
34
34
|
"@swc/core": "^1.3.0",
|
|
35
35
|
"@swc/plugin-relay": ">= 6.0.0",
|
|
36
36
|
"css-loader": "^7.0.0",
|
|
@@ -39,6 +39,7 @@
|
|
|
39
39
|
"sass-loader": "^16.0.0",
|
|
40
40
|
"semver": "^7.6.0",
|
|
41
41
|
"style-loader": "^4.0.0",
|
|
42
|
+
"swc-loader": "^0.2.0",
|
|
42
43
|
"webpack": "^5.27.0",
|
|
43
44
|
"webpack-merge": "^6.0.0",
|
|
44
45
|
"worker-rspack-loader": "^3.1.0"
|
|
@@ -47,8 +48,7 @@
|
|
|
47
48
|
"@ms-cloudpack/bundler-tests": "^0.1.0",
|
|
48
49
|
"@ms-cloudpack/eslint-plugin-internal": "^0.0.1",
|
|
49
50
|
"@ms-cloudpack/scripts": "^0.0.1",
|
|
50
|
-
"@ms-cloudpack/test-utilities": "^0.5.0"
|
|
51
|
-
"@swc/plugin-relay": "^9.0.0"
|
|
51
|
+
"@ms-cloudpack/test-utilities": "^0.5.0"
|
|
52
52
|
},
|
|
53
53
|
"files": [
|
|
54
54
|
"lib/**/!(*.test.*)"
|