Skip to content

Commit afd4ee3

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

File tree

10 files changed

+554
-711
lines changed

10 files changed

+554
-711
lines changed

.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.
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: 16 additions & 4 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,12 +26,24 @@
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": {
3749
"node": ">=20.19.0"

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');

scripts/update-version.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ const shared = await readFile(SHARED, 'utf8');
3838
await writeFile(SHARED, shared.replaceAll(PREV_VERSION, NEW_VERSION).replaceAll(OLD_YEAR, CURRENT_YEAR));
3939

4040
const builderConfig = await readFile(BUILDER_CONFIG, 'utf8');
41-
await writeFile(BUILDER_CONFIG, builderConfig.replaceAll(OLD_YEAR, CURRENT_YEAR));
41+
await writeFile(BUILDER_CONFIG, builderConfig.replaceAll(PREV_VERSION, NEW_VERSION).replaceAll(OLD_YEAR, CURRENT_YEAR));
4242

4343
const usage = await readFile(USAGE, 'utf8');
4444
await writeFile(USAGE, usage.replaceAll(PREV_VERSION, NEW_VERSION).replaceAll(PREV_VERSION_MINOR, NEW_VERSION_MINOR));

tests/eslint/eslint.config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2170,6 +2170,7 @@ export default [
21702170
ignores: [
21712171
'deno/corejs/**',
21722172
'docs/**',
2173+
'packages/core-js-builder/__tmp__/**',
21732174
'packages/core-js-bundle/!(package.json)',
21742175
'packages/core-js-compat/!(package).json',
21752176
'packages/core-js-pure/override/**',
@@ -2233,6 +2234,7 @@ export default [
22332234
{
22342235
files: [
22352236
'**/*.mjs',
2237+
'packages/core-js-builder/**',
22362238
'tests/eslint/**',
22372239
],
22382240
languageOptions: {

0 commit comments

Comments
 (0)