Skip to content

Commit

Permalink
Merge pull request #466 from zloirock/compat
Browse files Browse the repository at this point in the history
Provide data about necessity of `core-js` modules for target engines.
  • Loading branch information
zloirock authored Dec 26, 2018
2 parents c9de559 + 7101747 commit 803778a
Show file tree
Hide file tree
Showing 22 changed files with 3,061 additions and 343 deletions.
3 changes: 3 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@ module.exports = {
'packages/core-js/**',
'packages/core-js-pure/**',
'tests/promises-aplus/**',
'tests/compat/**',
],
parserOptions: {
ecmaVersion: 3,
Expand All @@ -468,7 +469,9 @@ module.exports = {
{
files: [
'packages/core-js-builder/**',
'packages/core-js-compat/**',
'tests/tests/**',
'tests/compat/**',
'tests/commonjs.js',
],
env: {
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ node_modules/
/packages/core-js-bundle/index.js
/packages/core-js-bundle/minified.js
/packages/core-js-bundle/minified.js.map
/packages/core-js-compat/data.json
/packages/core-js-compat/LICENSE
/packages/core-js-pure/es/
/packages/core-js-pure/features/
/packages/core-js-pure/internals/
Expand Down
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,16 @@
- `core` object no longer available in the global version, entry points which previously returned it now returns `globalThis` object. Also, don't set global `core` property.
- Add some missing entry points.
- Tools, tests, code quality:
- Add `core-js-compat` package with data about the necessity of `core-js` modules and API for getting a list of required `core-js` modules by `browserslist` query, [#466](https://github.com/zloirock/core-js/issues/466).
- Add `targets` option with `browserslist` query to `core-js-builder`.
- Remove an option for generation bundle of a version without global namespace pollution from `core-js-builder` - now it's an odd use case.
- Remove UMD wrapper from the code, generated by `core-js-builder` bundles - we don't need it for a global polyfill.
- Refactor source code for improving readability.
- **Get rid of LiveScript**, usage another language in JS standard library looks strange and impedes usage of tools like ESLint:
- Rewrite tests to JS.
- Rewrite scripts to JS.
- Use for tests Babel with minimalistic config which should work anywhere.
- Use ESLint on the code of tests and tools.
- Remove an option for generation bundle of a version without global namespace pollution from `core-js-builder` - now it's an odd use case.
- Remove UMD wrapper from the code, generated by `core-js-builder` bundles - we don't need it for a global polyfill.

##### 2.6.1 - 2018.12.18
- Fixed an issue with minified version, [#463](https://github.com/zloirock/core-js/issues/463), [#465](https://github.com/zloirock/core-js/issues/465)
Expand Down
25 changes: 19 additions & 6 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ Contributions are always welcome. If you don't know what how you can help, you c
## How to add a new polyfill

- The polyfill implementation should be added to the [`packages/core-js/modules`](./packages/core-js/modules) directory.
- If the implementation for the `pure` version should differ from the global version, it should be added to [`packages/core-js-pure/override`](./packages/core-js-pure/override) directory. The rest of `core-js-pure` will be copied from `core-js` package.
- For export the polyfill, in almost all cases should be used `_export` helper.
- The polyfill should be added to the [list of polyfills](./packages/core-js-builder/config.js) and to entry points, where it's required: [`packages/core-js/index.js`](./packages/core-js/index.js), directories [`packages/core-js/features`](./packages/core-js/features), [`packages/core-js/es`](./packages/core-js/es), [`packages/core-js/esnext`](./packages/core-js/esnext) and [`packages/core-js/web`](./packages/core-js/web).
- Unit tests for the polyfill should be added to [`tests/tests`](./tests/tests) and [`tests/pure`](./tests/pure).
- All new entry points should be added to [the test of entry points](./tests/commonjs).
- Add it to [README.md](./README.md).
- Any shared helpers should be added to the [`packages/core-js/internals`](./packages/core-js/internals) directory.
- If the implementation for the `pure` version differs from the global version, add it to [`packages/core-js-pure/override`](./packages/core-js-pure/override) directory. The rest parts of `core-js-pure` will be copied from `core-js` package.
- For export the polyfill, in almost all cases use `internals/export` helper.
- Add feature detection of the polyfill to [`tests/compat/tests.js`](./tests/compat/tests.js) and compatibility data to [`packages/core-js-compat/src/data.js`](./packages/core-js-compat/src/data.js) (this data also used for getting default list of polyfills at bundling).
- Add it to entry points where it's required: directories [`packages/core-js/features`](./packages/core-js/features), [`packages/core-js/es`](./packages/core-js/es), [`packages/core-js/proposals`](./packages/core-js/proposals), [`packages/core-js/stage`](./packages/core-js/stage) and [`packages/core-js/web`](./packages/core-js/web).
- Add unit tests to [`tests/tests`](./tests/tests) and [`tests/pure`](./tests/pure).
- Add tests of entry points to [`tests/commonjs.js`](./tests/commonjs).
- Add documentation to [README.md](./README.md).

## Style and standards

Expand Down Expand Up @@ -76,3 +78,14 @@ and after that use this file:
```
tests/promises-aplus.html
```

## Updating `core-js-compat` data

For updating `core-js-compat` data:

- Clone `core-js` repo.
- If you wanna add new data for a browser, run in this browser `tests/compat/index.html` and you will see which `core-js` modules required for this browser.
- If you wanna add new data for Node.js, run `tests/compat/node-runner.js` in required Node.js version and you will see results in the console.
- After getting this data, add it to [`packages/core-js-compat/src/data.js`](./packages/core-js-compat/src/data.js).
- If you wanna add new mapping (for example, add a new iOS Safari version based on Safari or Node.js based on Chrome), add it to [`packages/core-js-compat/src/mapping.js`](./packages/core-js-compat/src/mapping.js).
- Add a pull request to `core-js` repo.
20 changes: 16 additions & 4 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
'use strict';
const build = require('./packages/core-js-builder');
const fs = require('fs');
const mkdirp = require('mkdirp');
const path = require('path');
Expand Down Expand Up @@ -54,6 +53,10 @@ module.exports = grunt => {
'core-js-bundle': [
'./packages/core-js-bundle/LICENSE',
],
'core-js-compat': [
'./packages/core-js-compat/data.json',
'./packages/core-js-compat/LICENSE',
],
tests: [
'./tests/bundles/*',
],
Expand Down Expand Up @@ -115,6 +118,15 @@ module.exports = grunt => {
},
],
},
'core-js-compat': {
files: [
{
expand: true,
src: ['LICENSE'],
dest: './packages/core-js/',
},
],
},
},
karma: {
options: {
Expand Down Expand Up @@ -146,10 +158,10 @@ module.exports = grunt => {
webpack: require('./.webpack.config.js'),
});
grunt.registerTask('bundle', function () {
const builder = require('./packages/core-js-builder');
const done = this.async();
build({
modules: ['es', 'esnext', 'web'],
}).then(it => {

builder().then(it => {
const filename = './packages/core-js-bundle/index.js';
mkdirp.sync(path.dirname(filename));
fs.writeFile(filename, it, done);
Expand Down
17 changes: 6 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ Promise.resolve(32).then(x => console.log(x)); // => 32
- [`@babel/preset-env`](#babelpreset-env)
- [Configurable level of aggressiveness](#configurable-level-of-aggressiveness)
- [Custom build](#custom-build)
- [Compatibility data](#compatibility-data)
- [Supported engines](#supported-engines)
- [Features](#features)
- [ECMAScript](#ecmascript)
Expand Down Expand Up @@ -215,18 +216,12 @@ It does not work with some features. Also, if you change the default behavior, e

### Custom build

For some cases could be useful add a blacklist of features. [`core-js-builder`](https://www.npmjs.com/package/core-js-builder) package exports a function. This will conditionally include or exclude certain parts of `core-js`:
For some cases could be useful adding a blacklist of features or generation a polyfill for target engines. You could use [`core-js-builder`](/packages/core-js-builder) package for that.

### Compatibility data

[`core-js-compat`](/packages/core-js-compat) package contains data about the necessity of `core-js` modules and API for getting a list of required `core-js` modules by `browserslist` query.

```js
require('core-js-builder')({
modules: ['es', 'esnext.reflect', 'web'], // modules / namespaces
blacklist: ['es.math', 'es.number.constructor'], // blacklist of modules / namespaces, by default - empty list
}).then(code => {
// ...
}).catch(error => {
// ...
});
```
## Supported engines
**Tested in:**
- Chrome 26+
Expand Down
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,15 @@
},
"scripts": {
"bootstrap": "lerna bootstrap",
"build": "grunt clean copy && lerna bootstrap && grunt bundle uglify",
"lint": "grunt clean copy && lerna bootstrap && eslint ./",
"unit-tests": "grunt clean copy && lerna bootstrap && grunt bundle webpack:helpers webpack:tests karma:tests",
"unit-tests-pure": "grunt clean copy webpack:helpers webpack:pure karma:pure",
"build": "lerna bootstrap && grunt clean copy && npm run build-compat && grunt bundle uglify",
"build-compat": "node packages/core-js-compat/src/build-data",
"lint": "lerna bootstrap && grunt clean copy && npm run build-compat && eslint ./",
"unit-tests": "lerna bootstrap && grunt clean copy && npm run build-compat && grunt bundle webpack:helpers webpack:tests karma:tests",
"unit-tests-pure": "grunt clean copy && npm run build-compat && grunt webpack:helpers webpack:pure karma:pure",
"bundle-promises-tests": "grunt webpack:promises-aplus-tests",
"promises-tests": "promises-aplus-tests tests/promises-aplus/adapter --timeout 1000",
"observables-tests": "babel node_modules/es-observable/test/ -d tests/bundles/observables-tests/ && node tests/observables/adapter && node tests/observables/adapter-pure",
"commonjs-tests": "node tests/commonjs",
"test": "grunt clean copy && lerna bootstrap && eslint ./ && grunt webpack:helpers webpack:tests bundle uglify karma:tests webpack:helpers webpack:pure karma:pure && npm run promises-tests && npm run observables-tests && npm run commonjs-tests"
"test": "lerna bootstrap && grunt clean copy && npm run build-compat && eslint ./ && grunt webpack:helpers webpack:tests bundle uglify karma:tests webpack:helpers webpack:pure karma:pure && npm run promises-tests && npm run observables-tests && npm run commonjs-tests"
}
}
14 changes: 13 additions & 1 deletion packages/core-js-builder/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,13 @@
[See `core-js` readme](https://github.com/zloirock/core-js#custom-build).
For some cases could be useful adding a blacklist of features or generation a polyfill for target engines. This API helps conditionally include or exclude certain parts of [`core-js`](https://github.com/zloirock/core-js), use `browserslist` queries from [`core-js-compat`](https://github.com/zloirock/core-js/packages/core-js-compat) package.

```js
require('core-js-builder')({
modules: ['es', 'esnext.reflect', 'web'], // modules / namespaces, by default - all `core-js` modules
blacklist: ['es.math', 'es.number.constructor'], // blacklist of modules / namespaces, by default - empty list
targets: '> 0.5%', // optional browserslist query
}).then(code => {
// ...
}).catch(error => {
// ...
});
```
Loading

0 comments on commit 803778a

Please sign in to comment.