core-js-builder 3.21.1 → 3.22.2

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 +9 -9
  2. package/index.js +13 -37
  3. package/package.json +4 -4
package/README.md CHANGED
@@ -1,18 +1,18 @@
1
1
  ![logo](https://user-images.githubusercontent.com/2213682/146607186-8e13ddef-26a4-4ebf-befd-5aac9d77c090.png)
2
2
 
3
- For some cases could be useful to exclude some `core-js` features or generate a polyfill for target engines. This API helps conditionally include or exclude certain parts of [`core-js`](https://github.com/zloirock/core-js), build for targets [specified in `core-js-compat` format](https://github.com/zloirock/core-js/tree/master/packages/core-js-compat#targets-option).
3
+ For some cases could be useful to exclude some `core-js` features or generate a polyfill for target engines. This API helps conditionally include or exclude certain parts of [`core-js`](https://github.com/zloirock/core-js) and build for targets. `modules`, `exclude` and `targets` options are specified in [the `core-js-compat` format](https://github.com/zloirock/core-js/tree/master/packages/core-js-compat).
4
4
 
5
5
  ```js
6
- const builder = require('core-js-builder');
6
+ import builder from 'core-js-builder';
7
7
 
8
8
  const bundle = await builder({
9
- modules: ['es', 'esnext.reflect', 'web'], // modules / namespaces, by default - all `core-js` modules
10
- exclude: ['es.math', 'es.number.constructor'], // a blacklist of modules / namespaces, by default - empty list
11
- targets: '> 0.5%, not dead, ie 9-11', // optional browserslist or core-js-compat format query
12
- summary: { // shows summary for the bundle, disabled by default:
13
- console: { size: true, modules: false }, // in the console, you could specify required parts or set `true` for enable all of them
14
- comment: { size: false, modules: true }, // in the comment in the target file, similarly to `summary.console`
9
+ modules: ['core-js/actual', 'esnext.reflect'], // entries / modules / namespaces, by default - all `core-js` modules
10
+ exclude: [/^es\.math\./, 'es.number.constructor'], // a blacklist of entries / modules / namespaces, by default - empty list
11
+ targets: '> 0.5%, not dead, ie 9-11', // optional browserslist or core-js-compat format query
12
+ summary: { // shows summary for the bundle, disabled by default:
13
+ console: { size: true, modules: false }, // in the console, you could specify required parts or set `true` for enable all of them
14
+ comment: { size: false, modules: true }, // in the comment in the target file, similarly to `summary.console`
15
15
  },
16
- filename: './my-core-js-bundle.js', // optional target filename, if it's missed a file will not be created
16
+ filename: PATH_TO_MY_COREJS_BUNDLE, // optional target filename, if it's missed a file will not be created
17
17
  });
18
18
  ```
package/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  'use strict';
2
+ /* eslint-disable no-console -- output */
2
3
  const { promisify } = require('util');
3
4
  const fs = require('fs');
4
5
  // TODO: replace by `fs.promises` after dropping NodeJS < 10 support
@@ -11,7 +12,6 @@ const tmpdir = require('os').tmpdir();
11
12
  const mkdirp = promisify(require('mkdirp'));
12
13
  const webpack = promisify(require('webpack'));
13
14
  const compat = require('core-js-compat/compat');
14
- const modulesList = require('core-js-compat/modules');
15
15
  const { banner } = require('./config');
16
16
 
17
17
  function normalizeSummary(unit = {}) {
@@ -25,45 +25,22 @@ function normalizeSummary(unit = {}) {
25
25
  }
26
26
 
27
27
  module.exports = async function ({
28
- blacklist, // TODO: Remove from `core-js@4`
28
+ modules = null,
29
+ blacklist = null, // TODO: Obsolete, remove from `core-js@4`
29
30
  exclude = [],
30
- modules = modulesList.slice(),
31
- targets,
32
- filename,
31
+ targets = null,
32
+ filename = null,
33
33
  summary = {},
34
34
  } = {}) {
35
35
  summary = { comment: normalizeSummary(summary.comment), console: normalizeSummary(summary.console) };
36
36
 
37
37
  const TITLE = filename != null ? filename : '`core-js`';
38
- const set = new Set();
39
38
  let script = banner;
40
39
  let code = '';
41
- let modulesWithTargets;
42
40
 
43
- function filter(method, list) {
44
- for (const ns of list) {
45
- for (const name of modulesList) {
46
- if (name === ns || name.startsWith(`${ ns }.`)) {
47
- // eslint-disable-next-line sonarjs/no-empty-collection -- false positive
48
- set[method](name);
49
- }
50
- }
51
- }
52
- }
53
-
54
- filter('add', modules);
55
- filter('delete', blacklist || exclude);
56
-
57
- // eslint-disable-next-line sonarjs/no-empty-collection -- false positive
58
- modules = modulesList.filter(it => set.has(it));
41
+ const { list, targets: compatTargets } = compat({ targets, modules, exclude: exclude || blacklist });
59
42
 
60
- if (targets) {
61
- const compatResult = compat({ targets, filter: modules });
62
- modules = compatResult.list;
63
- modulesWithTargets = compatResult.targets;
64
- }
65
-
66
- if (modules.length) {
43
+ if (list.length) {
67
44
  const tempFileName = `core-js-${ Math.random().toString(36).slice(2) }.js`;
68
45
  const tempFile = join(tmpdir, tempFileName);
69
46
 
@@ -74,7 +51,7 @@ module.exports = async function ({
74
51
  process: false,
75
52
  setImmediate: false,
76
53
  },
77
- entry: modules.map(it => require.resolve(`core-js/modules/${ it }`)),
54
+ entry: list.map(it => require.resolve(`core-js/modules/${ it }`)),
78
55
  output: {
79
56
  filename: tempFileName,
80
57
  hashFunction: 'md5',
@@ -93,24 +70,23 @@ module.exports = async function ({
93
70
  }
94
71
 
95
72
  if (summary.comment.size) script += `/*\n * size: ${ (code.length / 1024).toFixed(2) }KB w/o comments\n */`;
96
- if (summary.comment.modules) script += `/*\n * modules:\n${ modules.map(it => ` * ${ it }\n`).join('') } */`;
73
+ if (summary.comment.modules) script += `/*\n * modules:\n${ list.map(it => ` * ${ it }\n`).join('') } */`;
97
74
  if (code) script += `\n${ code }`;
98
75
 
99
76
  if (summary.console.size) {
100
- // eslint-disable-next-line no-console -- output
101
77
  console.log(`\u001B[32mbundling \u001B[36m${ TITLE }\u001B[32m, size: \u001B[36m${
102
78
  (script.length / 1024).toFixed(2)
103
79
  }KB\u001B[0m`);
104
80
  }
105
81
 
106
82
  if (summary.console.modules) {
107
- // eslint-disable-next-line no-console -- output
108
83
  console.log(`\u001B[32mbundling \u001B[36m${ TITLE }\u001B[32m, modules:\u001B[0m`);
109
- // eslint-disable-next-line no-console -- output
110
- console.log(JSON.stringify(modulesWithTargets || modules, null, ' '));
84
+ for (const it of list) {
85
+ console.log(`\u001B[36m${ it + (targets ? ` \u001B[32mfor \u001B[36m${ JSON.stringify(compatTargets[it]) }` : '') }\u001B[0m`);
86
+ }
111
87
  }
112
88
 
113
- if (typeof filename != 'undefined') {
89
+ if (filename != null) {
114
90
  await mkdirp(dirname(filename));
115
91
  await writeFile(filename, script);
116
92
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "core-js-builder",
3
3
  "description": "core-js builder",
4
- "version": "3.21.1",
4
+ "version": "3.22.2",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://github.com/zloirock/core-js.git",
@@ -9,8 +9,8 @@
9
9
  },
10
10
  "main": "index.js",
11
11
  "dependencies": {
12
- "core-js": "3.21.1",
13
- "core-js-compat": "3.21.1",
12
+ "core-js": "3.22.2",
13
+ "core-js-compat": "3.22.2",
14
14
  "mkdirp": ">=0.5.5 <1",
15
15
  "webpack": ">=4.46.0 <5"
16
16
  },
@@ -22,5 +22,5 @@
22
22
  "url": "https://opencollective.com/core-js"
23
23
  },
24
24
  "license": "MIT",
25
- "gitHead": "eb9229ae88428edea6b2be250c98a518fd2c22e3"
25
+ "gitHead": "c949d92f76531a2fc31f0fdf7fda6c86e258d9b1"
26
26
  }