Skip to content

Commit 6e197c1

Browse files
committed
advanced esm test
1 parent 8008ce8 commit 6e197c1

File tree

24 files changed

+745
-169
lines changed

24 files changed

+745
-169
lines changed

.github/workflows/preview.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@ name: Preview Release
33

44
on:
55
push:
6-
branches:
7-
- main
8-
- beta
6+
branches: [main]
97
workflow_dispatch:
8+
inputs:
9+
branch:
10+
description: 'Branch to release'
11+
required: true
12+
default: 'main'
1013

1114
permissions:
1215
contents: read
@@ -21,6 +24,7 @@ jobs:
2124
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5
2225
with:
2326
fetch-depth: 1
27+
ref: ${{ github.event.inputs.branch }}
2428

2529
- name: Install pnpm
2630
run: |

packages/core/src/config.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,9 @@ const composeFormatConfig = ({
675675
module: true,
676676
chunkFormat: experimentalEsmOutput ? false : 'module',
677677
library: experimentalEsmOutput
678-
? undefined
678+
? {
679+
type: 'advanced-esm',
680+
}
679681
: {
680682
type: 'modern-module',
681683
},

packages/core/tests/__snapshots__/config.test.ts.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ exports[`Should compose create Rsbuild config correctly > Enable experiment.adva
104104
pathinfo: false,
105105
hashFunction: 'xxhash64',
106106
library: {
107-
type: 'commonjs2'
107+
type: 'advanced-esm'
108108
},
109109
assetModuleFilename: 'static/assets/[name][ext]',
110110
webassemblyModuleFilename: 'static/wasm/[contenthash:8].module.wasm',
@@ -3726,7 +3726,7 @@ exports[`Should compose create Rsbuild config correctly > Merge Rsbuild config i
37263726
use: [
37273727
/* config.module.rule('css').use('mini-css-extract') */
37283728
{
3729-
loader: '<ROOT>/node_modules/<PNPM_INNER>/@rspack-canary/core/dist/cssExtractLoader.js'
3729+
loader: '/Users/bytedance/codes/rspack/packages/rspack/dist/cssExtractLoader.js'
37303730
},
37313731
/* config.module.rule('css').use('css') */
37323732
{

pnpm-lock.yaml

Lines changed: 55 additions & 55 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pnpm-workspace.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ onlyBuiltDependencies:
1818

1919
overrides:
2020
'zx>@types/node': '-'
21-
'@rspack/core': 'npm:@rspack-canary/[email protected]6cd722f4-20251022123039'
21+
'@rspack/core': 'npm:@rspack-canary/[email protected]cf832f72-20251028084837'
2222

2323
strictPeerDependencies: false
2424
autoInstallPeers: false

tests/integration/asset/index.test.ts

Lines changed: 52 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -218,25 +218,58 @@ test('set the assets public path', async () => {
218218
// 2. bundle
219219
// esm
220220
const { content: indexJs } = queryContent(contents.esm0!, /index\.js/);
221-
expect(indexJs).toMatchInlineSnapshot(`
222-
"var __webpack_module_cache__ = {};
223-
function __webpack_require__(moduleId) {
224-
var cachedModule = __webpack_module_cache__[moduleId];
225-
if (void 0 !== cachedModule) return cachedModule.exports;
226-
var module = __webpack_module_cache__[moduleId] = {
227-
exports: {}
228-
};
229-
__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
230-
return module.exports;
231-
}
232-
(()=>{
233-
__webpack_require__.p = "/public/path/";
234-
})();
235-
const image_namespaceObject = __webpack_require__.p + "static/image/image.png";
236-
const src = image_namespaceObject;
237-
export { src as default };
238-
"
239-
`);
221+
if (process.env.ADVANCED_ESM) {
222+
const { content: runtimeJs } = queryContent(contents.esm0!, /runtime\.js/);
223+
expect(indexJs).toMatchInlineSnapshot(`
224+
"import { __webpack_require__ } from "./runtime.js";
225+
const image_namespaceObject = __webpack_require__.p + "static/image/image.png";
226+
const src = image_namespaceObject;
227+
export default src;
228+
"
229+
`);
230+
expect(runtimeJs).toMatchInlineSnapshot(`
231+
"var __webpack_module_cache__ = {};
232+
function __webpack_require__(moduleId) {
233+
var cachedModule = __webpack_module_cache__[moduleId];
234+
if (void 0 !== cachedModule) return cachedModule.exports;
235+
var module = __webpack_module_cache__[moduleId] = {
236+
exports: {}
237+
};
238+
__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
239+
return module.exports;
240+
}
241+
(()=>{
242+
__webpack_require__.add = function(modules) {
243+
Object.assign(__webpack_require__.m, modules);
244+
};
245+
})();
246+
(()=>{
247+
__webpack_require__.p = "/public/path/";
248+
})();
249+
export { __webpack_require__ };
250+
"
251+
`);
252+
} else {
253+
expect(indexJs).toMatchInlineSnapshot(`
254+
"var __webpack_module_cache__ = {};
255+
function __webpack_require__(moduleId) {
256+
var cachedModule = __webpack_module_cache__[moduleId];
257+
if (void 0 !== cachedModule) return cachedModule.exports;
258+
var module = __webpack_module_cache__[moduleId] = {
259+
exports: {}
260+
};
261+
__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
262+
return module.exports;
263+
}
264+
(()=>{
265+
__webpack_require__.p = "/public/path/";
266+
})();
267+
const image_namespaceObject = __webpack_require__.p + "static/image/image.png";
268+
const src = image_namespaceObject;
269+
export { src as default };
270+
"
271+
`);
272+
}
240273

241274
// 3. bundleless
242275
// esm

0 commit comments

Comments
 (0)