Skip to content

Commit d6df11f

Browse files
committed
replace webpack with rolldown in builder
1 parent 5c6db9d commit d6df11f

File tree

12 files changed

+560
-719
lines changed

12 files changed

+560
-719
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,8 @@ jobs:
5050
strategy:
5151
matrix:
5252
node:
53-
- 20.9
54-
- 21
55-
- ^22.5.1
53+
- ^20.19
54+
- ^22.12
5655
- 23
5756
- 24
5857
- 25
@@ -74,9 +73,8 @@ jobs:
7473
- windows-latest
7574
- macos-latest
7675
node:
77-
- 20.9
78-
- 21
79-
- ^22.5.1
76+
- ^20.19
77+
- ^22.12
8078
- 23
8179
- 24
8280
- 25

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ node_modules/
2424
/packages/core-js/LICENSE
2525
/packages/core-js-babel-plugin/LICENSE
2626
/packages/core-js-builder/LICENSE
27+
/packages/core-js-builder/__tmp__/
2728
/packages/core-js-bundle/LICENSE
2829
/packages/core-js-bundle/index.js
2930
/packages/core-js-bundle/minified.js

package-lock.json

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

packages/core-js-babel-plugin/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,6 @@
3232
"@core-js/compat": "4.0.0-alpha.0"
3333
},
3434
"engines": {
35-
"node": ">=20.19.0"
35+
"node": "^20.19.0 || >=22.12.0"
3636
}
3737
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
node_modules/
2+
__tmp__/
23
*.log
34
.*

packages/core-js-builder/config.js

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const version = '4.0.0-alpha.0';
2+
3+
/* eslint-disable prefer-template -- for better formatting */
4+
export default '/**\n' +
5+
' * core-js ' + version + '\n' +
6+
' * © 2013–2025 Denis Pushkarev (zloirock.ru), 2025–2026 CoreJS Company (core-js.io). All rights reserved.\n' +
7+
' * license: https://github.com/zloirock/core-js/blob/v' + version + '/LICENSE\n' +
8+
' * source: https://github.com/zloirock/core-js\n' +
9+
' */';
10+
/* eslint-enable prefer-template -- for better formatting */
Lines changed: 57 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
'use strict';
21
/* eslint-disable no-console -- output */
3-
const { promisify } = require('node:util');
4-
const { mkdir, readFile, unlink, writeFile } = require('node:fs/promises');
5-
const { dirname, join } = require('node:path');
6-
const tmpdir = require('node:os').tmpdir();
7-
const webpack = promisify(require('webpack'));
8-
const compat = require('@core-js/compat/compat');
9-
const { banner } = require('./config');
2+
import { mkdir, readFile, rm, writeFile } from 'node:fs/promises';
3+
import { dirname, join } from 'node:path';
4+
import { fileURLToPath } from 'node:url';
5+
import { build } from 'rolldown';
6+
import { transform } from '@swc/core';
7+
import compat from '@core-js/compat/compat.js';
8+
import banner from './config.mjs';
109

1110
function normalizeSummary(unit = {}) {
1211
let size, modules;
@@ -18,7 +17,19 @@ function normalizeSummary(unit = {}) {
1817
} return { size, modules };
1918
}
2019

21-
module.exports = async function ({
20+
function importIt(it) {
21+
return `import 'core-js/modules/${ it }.js';\n`;
22+
}
23+
24+
function requireIt(it) {
25+
return `require('core-js/modules/${ it }');\n`;
26+
}
27+
28+
function importModules(modules, format = 'esm') {
29+
return modules.map(format === 'esm' ? importIt : requireIt).join('');
30+
}
31+
32+
export default async function ({
2233
modules = null,
2334
exclude = [],
2435
targets = null,
@@ -37,33 +48,46 @@ module.exports = async function ({
3748

3849
if (list.length) {
3950
if (format === 'bundle') {
40-
const tempFileName = `core-js-${ Math.random().toString(36).slice(2) }.js`;
41-
const tempFile = join(tmpdir, tempFileName);
42-
43-
await webpack({
44-
mode: 'none',
45-
node: false,
46-
target: ['es5', 'node'],
47-
entry: list.map(it => require.resolve(`core-js/modules/${ it }`)),
48-
output: {
49-
filename: tempFileName,
50-
path: tmpdir,
51-
},
52-
});
51+
const tempDir = join(dirname(fileURLToPath(import.meta.url)), '__tmp__');
52+
const tempFile = join(tempDir, `core-js-${ Math.random().toString(36).slice(2) }.js`);
53+
const templateFile = `${ tempFile }-template.js`;
54+
55+
try {
56+
await mkdir(tempDir, { recursive: true });
57+
await writeFile(templateFile, importModules(list));
5358

54-
const file = await readFile(tempFile);
59+
await build({
60+
input: templateFile,
61+
platform: 'neutral',
62+
treeshake: false,
63+
output: {
64+
externalLiveBindings: false,
65+
format: 'iife',
66+
file: tempFile,
67+
keepNames: true,
68+
minifyInternalExports: true,
69+
},
70+
});
5571

56-
await unlink(tempFile);
72+
code = String(await readFile(tempFile, 'utf8'));
73+
} finally {
74+
await rm(templateFile, { force: true });
75+
await rm(tempFile, { force: true });
76+
}
5777

58-
code = `!function (undefined) { 'use strict'; ${
59-
// compress `__webpack_require__` with `keep_fnames` option
60-
String(file).replace(/function __webpack_require__/, 'var __webpack_require__ = function ')
61-
} }();\n`;
78+
// rolldown helpers / wrappers contain arrows
79+
code = (await transform(code, {
80+
env: {
81+
include: [
82+
'transform-arrow-functions',
83+
'transform-shorthand-properties',
84+
],
85+
},
86+
})).code;
87+
88+
code = `!function (undefined) { 'use strict'; ${ code } }();\n`;
6289
} else {
63-
const template = it => format === 'esm'
64-
? `import 'core-js/modules/${ it }.js';\n`
65-
: `require('core-js/modules/${ it }');\n`;
66-
code = list.map(template).join('');
90+
code = importModules(list, format);
6791
}
6892
}
6993

@@ -90,4 +114,4 @@ module.exports = async function ({
90114
}
91115

92116
return { script };
93-
};
117+
}

packages/core-js-builder/package.json

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"publishConfig": {
55
"access": "public"
66
},
7-
"type": "commonjs",
7+
"type": "module",
88
"description": "core-js builder",
99
"repository": {
1010
"type": "git",
@@ -26,14 +26,26 @@
2626
"url": "http://zloirock.ru"
2727
},
2828
"sideEffects": false,
29-
"main": "index.js",
29+
"main": "index.mjs",
30+
"exports": {
31+
".": {
32+
"types": "./index.d.ts",
33+
"default": "./index.mjs"
34+
},
35+
"./index.mjs": {
36+
"types": "./index.d.ts",
37+
"default": "./index.mjs"
38+
},
39+
"./config.mjs": "./config.mjs"
40+
},
3041
"types": "index.d.ts",
3142
"dependencies": {
32-
"core-js": "4.0.0-alpha.0",
3343
"@core-js/compat": "4.0.0-alpha.0",
34-
"webpack": "^5.104.1"
44+
"@swc/core": "^1.15.11",
45+
"core-js": "4.0.0-alpha.0",
46+
"rolldown": "^1.0.0-rc.2"
3547
},
3648
"engines": {
37-
"node": ">=20.19.0"
49+
"node": "^20.19.0 || >=22.12.0"
3850
}
3951
}

scripts/bundle-package/bundle-package.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { minify } from 'terser';
22
import builder from '@core-js/builder';
3-
import config from '@core-js/builder/config.js';
3+
import config from '@core-js/builder/config.mjs';
44

55
const { cyan, green } = chalk;
66
const ESMODULES = argv._.includes('esmodules');

0 commit comments

Comments
 (0)