core-js-builder 3.25.5 → 3.26.1

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.
Files changed (3) hide show
  1. package/README.md +18 -8
  2. package/index.js +34 -25
  3. package/package.json +15 -10
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  <div align="center">
4
4
 
5
- [![fundraising](https://opencollective.com/core-js/all/badge.svg?label=fundraising)](https://opencollective.com/core-js) [![PRs welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/zloirock/core-js/blob/master/CONTRIBUTING.md) [![version](https://img.shields.io/npm/v/core-js-builder.svg)](https://www.npmjs.com/package/core-js-builder) [![tests](https://github.com/zloirock/core-js/workflows/tests/badge.svg)](https://github.com/zloirock/core-js/actions) [![eslint](https://github.com/zloirock/core-js/workflows/eslint/badge.svg)](https://github.com/zloirock/core-js/actions)
5
+ [![fundraising](https://opencollective.com/core-js/all/badge.svg?label=fundraising)](https://opencollective.com/core-js) [![PRs welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/zloirock/core-js/blob/master/CONTRIBUTING.md) [![version](https://img.shields.io/npm/v/core-js-builder.svg)](https://www.npmjs.com/package/core-js-builder)
6
6
 
7
7
  </div>
8
8
 
@@ -12,13 +12,23 @@ For some cases could be useful to exclude some `core-js` features or generate a
12
12
  import builder from 'core-js-builder';
13
13
 
14
14
  const bundle = await builder({
15
- modules: ['core-js/actual', 'esnext.reflect'], // entries / modules / namespaces, by default - all `core-js` modules
16
- exclude: [/^es\.math\./, 'es.number.constructor'], // a blacklist of entries / modules / namespaces, by default - empty list
17
- targets: '> 0.5%, not dead, ie 9-11', // optional browserslist or core-js-compat format query
18
- summary: { // shows summary for the bundle, disabled by default:
19
- console: { size: true, modules: false }, // in the console, you could specify required parts or set `true` for enable all of them
20
- comment: { size: false, modules: true }, // in the comment in the target file, similarly to `summary.console`
15
+ // entry / module / namespace / an array of them, by default - all `core-js` modules
16
+ modules: ['core-js/actual', /^esnext\.reflect\./],
17
+ // a blacklist of entries / modules / namespaces, by default - empty list
18
+ exclude: [/^es\.math\./, 'es.number.constructor'],
19
+ // optional browserslist or core-js-compat format query
20
+ targets: '> 0.5%, not dead, ie 9-11',
21
+ // shows summary for the bundle, disabled by default
22
+ summary: {
23
+ // in the console, you could specify required parts or set `true` for enable all of them
24
+ console: { size: true, modules: false },
25
+ // in the comment in the target file, similarly to `summary.console`
26
+ comment: { size: false, modules: true },
21
27
  },
22
- filename: PATH_TO_MY_COREJS_BUNDLE, // optional target filename, if it's missed a file will not be created
28
+ // output format, 'bundle' by default, can be 'cjs' or 'esm', and in this case
29
+ // the result will not be bundled and will contain imports of required modules
30
+ format: 'bundle',
31
+ // optional target filename, if it's missed a file will not be created
32
+ filename: PATH_TO_MY_COREJS_BUNDLE,
23
33
  });
24
34
  ```
package/index.js CHANGED
@@ -29,44 +29,53 @@ module.exports = async function ({
29
29
  blacklist = null, // TODO: Obsolete, remove from `core-js@4`
30
30
  exclude = [],
31
31
  targets = null,
32
+ format = 'bundle',
32
33
  filename = null,
33
34
  summary = {},
34
35
  } = {}) {
36
+ if (!['bundle', 'cjs', 'esm'].includes(format)) throw TypeError('Incorrect output type');
35
37
  summary = { comment: normalizeSummary(summary.comment), console: normalizeSummary(summary.console) };
36
38
 
37
39
  const TITLE = filename != null ? filename : '`core-js`';
38
40
  let script = banner;
39
- let code = '';
41
+ let code = '\n';
40
42
 
41
43
  const { list, targets: compatTargets } = compat({ targets, modules, exclude: exclude || blacklist });
42
44
 
43
45
  if (list.length) {
44
- const tempFileName = `core-js-${ Math.random().toString(36).slice(2) }.js`;
45
- const tempFile = join(tmpdir, tempFileName);
46
+ if (format === 'bundle') {
47
+ const tempFileName = `core-js-${ Math.random().toString(36).slice(2) }.js`;
48
+ const tempFile = join(tmpdir, tempFileName);
46
49
 
47
- await webpack({
48
- mode: 'none',
49
- node: {
50
- global: false,
51
- process: false,
52
- setImmediate: false,
53
- },
54
- entry: list.map(it => require.resolve(`core-js/modules/${ it }`)),
55
- output: {
56
- filename: tempFileName,
57
- hashFunction: 'md5',
58
- path: tmpdir,
59
- },
60
- });
50
+ await webpack({
51
+ mode: 'none',
52
+ node: {
53
+ global: false,
54
+ process: false,
55
+ setImmediate: false,
56
+ },
57
+ entry: list.map(it => require.resolve(`core-js/modules/${ it }`)),
58
+ output: {
59
+ filename: tempFileName,
60
+ hashFunction: 'md5',
61
+ path: tmpdir,
62
+ },
63
+ });
61
64
 
62
- const file = await readFile(tempFile);
65
+ const file = await readFile(tempFile);
63
66
 
64
- await unlink(tempFile);
67
+ await unlink(tempFile);
65
68
 
66
- code = `!function (undefined) { 'use strict'; ${
67
- // compress `__webpack_require__` with `keep_fnames` option
68
- String(file).replace(/function __webpack_require__/, 'var __webpack_require__ = function ')
69
- } }();`;
69
+ code = `!function (undefined) { 'use strict'; ${
70
+ // compress `__webpack_require__` with `keep_fnames` option
71
+ String(file).replace(/function __webpack_require__/, 'var __webpack_require__ = function ')
72
+ } }();\n`;
73
+ } else {
74
+ const template = it => format === 'esm'
75
+ ? `import 'core-js/modules/${ it }.js';\n`
76
+ : `require('core-js/modules/${ it }');\n`;
77
+ code = list.map(template).join('');
78
+ }
70
79
  }
71
80
 
72
81
  if (summary.comment.size) script += `/*\n * size: ${ (code.length / 1024).toFixed(2) }KB w/o comments\n */`;
@@ -81,9 +90,9 @@ module.exports = async function ({
81
90
 
82
91
  if (summary.console.modules) {
83
92
  console.log(`\u001B[32mbundling \u001B[36m${ TITLE }\u001B[32m, modules:\u001B[0m`);
84
- for (const it of list) {
93
+ if (list.length) for (const it of list) {
85
94
  console.log(`\u001B[36m${ it + (targets ? ` \u001B[32mfor \u001B[36m${ JSON.stringify(compatTargets[it]) }` : '') }\u001B[0m`);
86
- }
95
+ } else console.log('\u001B[36mnothing\u001B[0m');
87
96
  }
88
97
 
89
98
  if (filename != null) {
package/package.json CHANGED
@@ -1,26 +1,31 @@
1
1
  {
2
2
  "name": "core-js-builder",
3
+ "version": "3.26.1",
3
4
  "description": "core-js builder",
4
- "version": "3.25.5",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://github.com/zloirock/core-js.git",
8
8
  "directory": "packages/core-js-builder"
9
9
  },
10
- "main": "index.js",
10
+ "funding": {
11
+ "type": "opencollective",
12
+ "url": "https://opencollective.com/core-js"
13
+ },
14
+ "license": "MIT",
15
+ "author": {
16
+ "name": "Denis Pushkarev",
17
+ "email": "zloirock@zloirock.ru",
18
+ "url": "http://zloirock.ru"
19
+ },
11
20
  "sideEffects": false,
21
+ "main": "index.js",
12
22
  "dependencies": {
13
- "core-js": "3.25.5",
14
- "core-js-compat": "3.25.5",
23
+ "core-js": "3.26.1",
24
+ "core-js-compat": "3.26.1",
15
25
  "mkdirp": ">=0.5.5 <1",
16
26
  "webpack": ">=4.46.0 <5"
17
27
  },
18
28
  "engines": {
19
29
  "node": ">=8.9.0"
20
- },
21
- "funding": {
22
- "type": "opencollective",
23
- "url": "https://opencollective.com/core-js"
24
- },
25
- "license": "MIT"
30
+ }
26
31
  }