Skip to content

Commit

Permalink
fix: adapt @rspack/core 1.1.9 (#602)
Browse files Browse the repository at this point in the history
  • Loading branch information
fi3ework authored and Timeless0911 committed Dec 30, 2024
1 parent d637e02 commit 57fb181
Show file tree
Hide file tree
Showing 19 changed files with 224 additions and 219 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
},
"pnpm": {
"overrides": {
"@rspack/core": "npm:@rspack-canary/core@1.1.7-canary-10025e2e-20241225045751",
"zx>@types/node": "-"
}
}
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,7 @@ const composeFormatConfig = ({
optimization: {
concatenateModules: true,
sideEffects: 'flag',
avoidEntryIife: true,
},
output: {
module: true,
Expand Down
1 change: 1 addition & 0 deletions packages/core/tests/__snapshots__/config.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ exports[`Should compose create Rsbuild config correctly > Merge Rsbuild config i
"__filename": false,
},
"optimization": {
"avoidEntryIife": true,
"concatenateModules": true,
"sideEffects": "flag",
},
Expand Down
200 changes: 106 additions & 94 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions tests/integration/alias/__snapshots__/index.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ if (__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_targe
`;

exports[`source.alias 3`] = `
"import * as __WEBPACK_EXTERNAL_MODULE__a_js__ from "./a.js";
console.info(__WEBPACK_EXTERNAL_MODULE__a_js__.a);
"import * as __WEBPACK_EXTERNAL_MODULE__a_js_256e6de1__ from "./a.js";
console.info(__WEBPACK_EXTERNAL_MODULE__a_js_256e6de1__.a);
"
`;

Expand Down
2 changes: 1 addition & 1 deletion tests/integration/alias/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ test('source.alias', async () => {

// bundleless mode
expect(indexBundlelessEsmContent).toContain(
'import * as __WEBPACK_EXTERNAL_MODULE__a_js__ from "./a.js";',
'import * as __WEBPACK_EXTERNAL_MODULE__a_js_256e6de1__ from "./a.js";',
);
expect(indexBundlelessCjsContent).toContain(
'const external_a_cjs_namespaceObject = require("./a.cjs");',
Expand Down
48 changes: 24 additions & 24 deletions tests/integration/asset/__snapshots__/index.test.ts.snap

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tests/integration/auto-external/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ test('auto external sub path should works', async () => {
'import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react"',
);
expect(entries.esm).toContain(
'import * as __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__ from "react/jsx-runtime"',
'import * as __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__ from "react/jsx-runtime"',
);

expect(entries.cjs).toContain(
Expand Down
12 changes: 6 additions & 6 deletions tests/integration/bundle-false/__snapshots__/index.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`svgr in bundleless 1`] = `
"import * as __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__ from "react/jsx-runtime";
"import * as __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__ from "react/jsx-runtime";
import "react";
const SvgLogo = (props)=>/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("svg", {
const SvgLogo = (props)=>/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)("svg", {
xmlns: "http://www.w3.org/2000/svg",
viewBox: "0 0 841.9 595.3",
...props,
children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsxs)("g", {
children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsxs)("g", {
fill: "#61DAFB",
children: [
/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("path", {
/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)("path", {
d: "M666.3 296.5c0-32.5-40.7-63.3-103.1-82.4 14.4-63.6 8-114.2-20.2-130.4-6.5-3.8-14.1-5.6-22.4-5.6v22.3c4.6 0 8.3.9 11.4 2.6 13.6 7.8 19.5 37.5 14.9 75.7-1.1 9.4-2.9 19.3-5.1 29.4-19.6-4.8-41-8.5-63.5-10.9-13.5-18.5-27.5-35.3-41.6-50 32.6-30.3 63.2-46.9 84-46.9V78c-27.5 0-63.5 19.6-99.9 53.6-36.4-33.8-72.4-53.2-99.9-53.2v22.3c20.7 0 51.4 16.5 84 46.6-14 14.7-28 31.4-41.3 49.9-22.6 2.4-44 6.1-63.6 11-2.3-10-4-19.7-5.2-29-4.7-38.2 1.1-67.9 14.6-75.8 3-1.8 6.9-2.6 11.5-2.6V78.5c-8.4 0-16 1.8-22.6 5.6-28.1 16.2-34.4 66.7-19.9 130.1-62.2 19.2-102.7 49.9-102.7 82.3 0 32.5 40.7 63.3 103.1 82.4-14.4 63.6-8 114.2 20.2 130.4 6.5 3.8 14.1 5.6 22.5 5.6 27.5 0 63.5-19.6 99.9-53.6 36.4 33.8 72.4 53.2 99.9 53.2 8.4 0 16-1.8 22.6-5.6 28.1-16.2 34.4-66.7 19.9-130.1 62-19.1 102.5-49.9 102.5-82.3m-130.2-66.7c-3.7 12.9-8.3 26.2-13.5 39.5-4.1-8-8.4-16-13.1-24-4.6-8-9.5-15.8-14.4-23.4 14.2 2.1 27.9 4.7 41 7.9m-45.8 106.5c-7.8 13.5-15.8 26.3-24.1 38.2-14.9 1.3-30 2-45.2 2-15.1 0-30.2-.7-45-1.9-8.3-11.9-16.4-24.6-24.2-38-7.6-13.1-14.5-26.4-20.8-39.8 6.2-13.4 13.2-26.8 20.7-39.9 7.8-13.5 15.8-26.3 24.1-38.2 14.9-1.3 30-2 45.2-2 15.1 0 30.2.7 45 1.9 8.3 11.9 16.4 24.6 24.2 38 7.6 13.1 14.5 26.4 20.8 39.8-6.3 13.4-13.2 26.8-20.7 39.9m32.3-13c5.4 13.4 10 26.8 13.8 39.8-13.1 3.2-26.9 5.9-41.2 8 4.9-7.7 9.8-15.6 14.4-23.7 4.6-8 8.9-16.1 13-24.1M421.2 430c-9.3-9.6-18.6-20.3-27.8-32 9 .4 18.2.7 27.5.7 9.4 0 18.7-.2 27.8-.7-9 11.7-18.3 22.4-27.5 32m-74.4-58.9c-14.2-2.1-27.9-4.7-41-7.9 3.7-12.9 8.3-26.2 13.5-39.5 4.1 8 8.4 16 13.1 24q7.05 12 14.4 23.4M420.7 163c9.3 9.6 18.6 20.3 27.8 32-9-.4-18.2-.7-27.5-.7-9.4 0-18.7.2-27.8.7 9-11.7 18.3-22.4 27.5-32m-74 58.9c-4.9 7.7-9.8 15.6-14.4 23.7-4.6 8-8.9 16-13 24-5.4-13.4-10-26.8-13.8-39.8 13.1-3.1 26.9-5.8 41.2-7.9m-90.5 125.2c-35.4-15.1-58.3-34.9-58.3-50.6s22.9-35.6 58.3-50.6c8.6-3.7 18-7 27.7-10.1 5.7 19.6 13.2 40 22.5 60.9-9.2 20.8-16.6 41.1-22.2 60.6-9.9-3.1-19.3-6.5-28-10.2M310 490c-13.6-7.8-19.5-37.5-14.9-75.7 1.1-9.4 2.9-19.3 5.1-29.4 19.6 4.8 41 8.5 63.5 10.9 13.5 18.5 27.5 35.3 41.6 50-32.6 30.3-63.2 46.9-84 46.9-4.5-.1-8.3-1-11.3-2.7m237.2-76.2c4.7 38.2-1.1 67.9-14.6 75.8-3 1.8-6.9 2.6-11.5 2.6-20.7 0-51.4-16.5-84-46.6 14-14.7 28-31.4 41.3-49.9 22.6-2.4 44-6.1 63.6-11 2.3 10.1 4.1 19.8 5.2 29.1m38.5-66.7c-8.6 3.7-18 7-27.7 10.1-5.7-19.6-13.2-40-22.5-60.9 9.2-20.8 16.6-41.1 22.2-60.6 9.9 3.1 19.3 6.5 28.1 10.2 35.4 15.1 58.3 34.9 58.3 50.6-.1 15.7-23 35.6-58.4 50.6M320.8 78.4"
}),
/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("circle", {
/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)("circle", {
cx: 420.9,
cy: 296.5,
r: 45.7
}),
/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("path", {
/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)("path", {
d: "M520.5 78.1"
})
]
Expand Down
16 changes: 8 additions & 8 deletions tests/integration/bundle-false/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ test('auto add js extension for relative import', async () => {

// basic esm
for (const importer of [
'import * as __WEBPACK_EXTERNAL_MODULE__bar_js__ from "./bar.js";',
'import * as __WEBPACK_EXTERNAL_MODULE__baz_js_js__ from "./baz.js.js";',
'import * as __WEBPACK_EXTERNAL_MODULE__foo_js__ from "./foo.js";',
'import * as __WEBPACK_EXTERNAL_MODULE__qux_js__ from "./qux.js";',
'import * as __WEBPACK_EXTERNAL_MODULE__bar_js_69b41beb__ from "./bar.js";',
'import * as __WEBPACK_EXTERNAL_MODULE__baz_js_js_7d4e15b7__ from "./baz.js.js";',
'import * as __WEBPACK_EXTERNAL_MODULE__foo_js_fdf5aa2d__ from "./foo.js";',
'import * as __WEBPACK_EXTERNAL_MODULE__qux_js_3d9e4fc9__ from "./qux.js";',
]) {
expect(Object.values(contents.esm0!)[3]).toContain(importer);
}
Expand All @@ -109,10 +109,10 @@ test('auto add js extension for relative import', async () => {

// using `autoExtension: false` along with `output.filename.js` - esm
for (const importer of [
'import * as __WEBPACK_EXTERNAL_MODULE__bar_mjs__ from "./bar.mjs";',
'import * as __WEBPACK_EXTERNAL_MODULE__baz_js_mjs__ from "./baz.js.mjs";',
'import * as __WEBPACK_EXTERNAL_MODULE__foo_mjs__ from "./foo.mjs";',
'import * as __WEBPACK_EXTERNAL_MODULE__qux_mjs__ from "./qux.mjs";',
'import * as __WEBPACK_EXTERNAL_MODULE__bar_mjs_89c909f2__ from "./bar.mjs";',
'import * as __WEBPACK_EXTERNAL_MODULE__baz_js_mjs_09565ba6__ from "./baz.js.mjs";',
'import * as __WEBPACK_EXTERNAL_MODULE__foo_mjs_ccdcdd01__ from "./foo.mjs";',
'import * as __WEBPACK_EXTERNAL_MODULE__qux_mjs_83952e37__ from "./qux.mjs";',
]) {
expect(Object.values(contents.esm1!)[3]).toContain(importer);
}
Expand Down
24 changes: 12 additions & 12 deletions tests/integration/external-helpers/__snapshots__/index.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`should external @swc/helpers when externalHelpers is true 1`] = `
"import * as __WEBPACK_EXTERNAL_MODULE__swc_helpers_class_call_check__ from "@swc/helpers/_/_class_call_check";
import * as __WEBPACK_EXTERNAL_MODULE__swc_helpers_create_class__ from "@swc/helpers/_/_create_class";
"import * as __WEBPACK_EXTERNAL_MODULE__swc_helpers_class_call_check_f500f6c3__ from "@swc/helpers/_/_class_call_check";
import * as __WEBPACK_EXTERNAL_MODULE__swc_helpers_create_class_63e94838__ from "@swc/helpers/_/_create_class";
var src_rslib_entry_FOO = /*#__PURE__*/ function() {
"use strict";
function FOO() {
(0, __WEBPACK_EXTERNAL_MODULE__swc_helpers_class_call_check__._)(this, FOO);
(0, __WEBPACK_EXTERNAL_MODULE__swc_helpers_class_call_check_f500f6c3__._)(this, FOO);
}
(0, __WEBPACK_EXTERNAL_MODULE__swc_helpers_create_class__._)(FOO, [
(0, __WEBPACK_EXTERNAL_MODULE__swc_helpers_create_class_63e94838__._)(FOO, [
{
key: "bar",
get: function() {}
Expand All @@ -21,14 +21,14 @@ export { src_rslib_entry_FOO as default };
`;

exports[`should external @swc/helpers when externalHelpers is true 2`] = `
"import * as __WEBPACK_EXTERNAL_MODULE__swc_helpers_class_call_check__ from "@swc/helpers/_/_class_call_check";
import * as __WEBPACK_EXTERNAL_MODULE__swc_helpers_create_class__ from "@swc/helpers/_/_create_class";
"import * as __WEBPACK_EXTERNAL_MODULE__swc_helpers_class_call_check_f500f6c3__ from "@swc/helpers/_/_class_call_check";
import * as __WEBPACK_EXTERNAL_MODULE__swc_helpers_create_class_63e94838__ from "@swc/helpers/_/_create_class";
var src_rslib_entry_FOO = /*#__PURE__*/ function() {
"use strict";
function FOO() {
(0, __WEBPACK_EXTERNAL_MODULE__swc_helpers_class_call_check__._)(this, FOO);
(0, __WEBPACK_EXTERNAL_MODULE__swc_helpers_class_call_check_f500f6c3__._)(this, FOO);
}
(0, __WEBPACK_EXTERNAL_MODULE__swc_helpers_create_class__._)(FOO, [
(0, __WEBPACK_EXTERNAL_MODULE__swc_helpers_create_class_63e94838__._)(FOO, [
{
key: "bar",
get: function() {}
Expand Down Expand Up @@ -111,14 +111,14 @@ export { src_rslib_entry_FOO as default };
`;

exports[`should respect user override externalHelpers config 2`] = `
"import * as __WEBPACK_EXTERNAL_MODULE__swc_helpers_class_call_check__ from "@swc/helpers/_/_class_call_check";
import * as __WEBPACK_EXTERNAL_MODULE__swc_helpers_create_class__ from "@swc/helpers/_/_create_class";
"import * as __WEBPACK_EXTERNAL_MODULE__swc_helpers_class_call_check_f500f6c3__ from "@swc/helpers/_/_class_call_check";
import * as __WEBPACK_EXTERNAL_MODULE__swc_helpers_create_class_63e94838__ from "@swc/helpers/_/_create_class";
var src_rslib_entry_FOO = /*#__PURE__*/ function() {
"use strict";
function FOO() {
(0, __WEBPACK_EXTERNAL_MODULE__swc_helpers_class_call_check__._)(this, FOO);
(0, __WEBPACK_EXTERNAL_MODULE__swc_helpers_class_call_check_f500f6c3__._)(this, FOO);
}
(0, __WEBPACK_EXTERNAL_MODULE__swc_helpers_create_class__._)(FOO, [
(0, __WEBPACK_EXTERNAL_MODULE__swc_helpers_create_class_63e94838__._)(FOO, [
{
key: "bar",
get: function() {}
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/externals/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ test('auto externalize Node.js built-in modules when `output.target` is "node"',

for (const external of [
'import * as __WEBPACK_EXTERNAL_MODULE_fs__ from "fs"',
'import * as __WEBPACK_EXTERNAL_MODULE_node_assert__ from "node:assert"',
'import * as __WEBPACK_EXTERNAL_MODULE_node_assert_3e74d44e__ from "node:assert"',
'import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react"',
'import * as __WEBPACK_EXTERNAL_MODULE_bar__ from "bar"',
'module.exports = __WEBPACK_EXTERNAL_createRequire(import.meta.url)("foo");',
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/format/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ test('esm', async () => {
}
`);
expect(entries.esm).toMatchInlineSnapshot(`
"import * as __WEBPACK_EXTERNAL_MODULE_node_url__ from "node:url";
const packageDirectory = __WEBPACK_EXTERNAL_MODULE_node_url__["default"].fileURLToPath(new URL('.', import.meta.url));
"import * as __WEBPACK_EXTERNAL_MODULE_node_url_e96de089__ from "node:url";
const packageDirectory = __WEBPACK_EXTERNAL_MODULE_node_url_e96de089__["default"].fileURLToPath(new URL('.', import.meta.url));
const foo = 'foo';
export { foo, packageDirectory };
"
Expand Down
42 changes: 21 additions & 21 deletions tests/integration/minify/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,36 @@ describe('minify config', () => {
const fixturePath = join(__dirname, 'default');
const { entries } = await buildAndGetResults({ fixturePath });
expect(entries.esm).toMatchInlineSnapshot(`
"/*! For license information please see index.js.LICENSE.txt */
import * as __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__ from "react/jsx-runtime";
/*! Legal Comment */ const foo = ()=>{};
const Button = ()=>/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)('button', {});
export { Button, foo };
"
`);
"/*! For license information please see index.js.LICENSE.txt */
import * as __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__ from "react/jsx-runtime";
/*! Legal Comment */ const foo = ()=>{};
const Button = ()=>/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)('button', {});
export { Button, foo };
"
`);
});

test('minify is disabled, nothing will be stripped', async () => {
const fixturePath = join(__dirname, 'config/disabled');
const { entries } = await buildAndGetResults({ fixturePath });
expect(entries.esm).toMatchInlineSnapshot(`
"import * as __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__ from "react/jsx-runtime";
"import * as __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__ from "react/jsx-runtime";
;// CONCATENATED MODULE: external "react/jsx-runtime"
;// CONCATENATED MODULE: external "react/jsx-runtime"
;// CONCATENATED MODULE: ../../__fixtures__/src/index.ts?__rslib_entry__
/*! Legal Comment */
const foo = ()=>{};
const bar = ()=>{};
const baz = ()=>{
return bar();
};
// normal comment
const Button = ()=>/*#__PURE__*/ (0,__WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)('button', {});
;// CONCATENATED MODULE: ../../__fixtures__/src/index.ts?__rslib_entry__
/*! Legal Comment */
const foo = ()=>{};
const bar = ()=>{};
const baz = ()=>{
return bar();
};
// normal comment
const Button = ()=>/*#__PURE__*/ (0,__WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)('button', {});
export { Button, foo };
"
`);
export { Button, foo };
"
`);
});

test('minify is enabled, only preserve some comments and annotations', async () => {
Expand Down
Loading

0 comments on commit 57fb181

Please sign in to comment.