From 07128c867da5e8d9084ad530ed2f3aa7bd0b3f5f Mon Sep 17 00:00:00 2001 From: Denis Pushkarev Date: Thu, 22 Mar 2018 17:56:19 +0700 Subject: [PATCH] move `core-js` bundle to a separate package --- .eslintignore | 2 +- .gitignore | 5 +++- Gruntfile.js | 18 ++++++++++--- README.md | 4 +-- packages/core-js-bundle/.npmignore | 5 ++++ packages/core-js-bundle/README.md | 38 ++++++++++++++++++++++++++ packages/core-js-bundle/package.json | 40 ++++++++++++++++++++++++++++ tests/promises-aplus.html | 2 +- tests/tests.html | 2 +- tests/worker/runner.js | 2 +- 10 files changed, 108 insertions(+), 10 deletions(-) create mode 100644 packages/core-js-bundle/.npmignore create mode 100644 packages/core-js-bundle/README.md create mode 100644 packages/core-js-bundle/package.json diff --git a/.eslintignore b/.eslintignore index 0190f8ec86a5..42150e1a2c55 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,5 +1,5 @@ node_modules/ -/packages/core-js/bundles/ +/packages/core-js-bundle/ /packages/core-js-pure/override/ /tests/bundles/ !**/.eslintrc.js diff --git a/.gitignore b/.gitignore index 7f2d37e8f2b5..a1b31c2351ba 100644 --- a/.gitignore +++ b/.gitignore @@ -4,7 +4,10 @@ node_modules/ *.bak *.swp -/packages/core-js/bundles/ +/packages/core-js-bundle/LICENSE +/packages/core-js-bundle/index.js +/packages/core-js-bundle/minified.js +/packages/core-js-bundle/minified.js.map /packages/core-js/LICENSE /packages/core-js-pure/es/ /packages/core-js-pure/features/ diff --git a/Gruntfile.js b/Gruntfile.js index fbbf4837c490..d82f5747c832 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -16,7 +16,7 @@ module.exports = grunt => { uglify: { build: { files: { - './packages/core-js/bundles/core.js.min.js': './packages/core-js/bundles/core.js', + './packages/core-js-bundle/minified.js': './packages/core-js-bundle/index.js', }, options: { mangle: { @@ -50,6 +50,9 @@ module.exports = grunt => { 'core-js-builder': [ './packages/core-js-builder/LICENSE', ], + 'core-js-bundle': [ + './packages/core-js/LICENSE', + ], tests: [ './tests/bundles/*', ], @@ -92,6 +95,15 @@ module.exports = grunt => { }, ], }, + 'core-js-bundle': { + files: [ + { + expand: true, + src: ['LICENSE'], + dest: './packages/core-js-builder/', + }, + ], + }, }, karma: { options: { @@ -102,7 +114,7 @@ module.exports = grunt => { }, tests: { files: [ - 'packages/core-js/bundles/core.js', + 'packages/core-js-bundle/index.js', 'tests/bundles/qunit-helpers.js', 'tests/bundles/tests.js', ].map(it => ({ src: it })), @@ -121,7 +133,7 @@ module.exports = grunt => { build({ modules: ['es', 'esnext', 'web'], }).then(it => { - const filename = './packages/core-js/bundles/core.js'; + const filename = './packages/core-js-bundle/index.js'; mkdirp.sync(path.dirname(filename)); fs.writeFile(filename, it, done); }).catch(it => { diff --git a/README.md b/README.md index 52974a7c7aac..5bae703c4851 100644 --- a/README.md +++ b/README.md @@ -92,9 +92,9 @@ npm i core-js // Include all polyfills require('core-js'); ``` -If you need already bundled version of `core-js`, use `core-js/bundles/core.js` or `core-js/bundles/core.min.js` from `npm` package. +If you need already bundled version of `core-js`, use `core-js-bundle` `npm` package or a [version of this package from CDN](https://unpkg.com/core-js-bundle@3.0.0-alpha.1) ([minified version](https://unpkg.com/core-js-bundle@3.0.0-alpha.1/minified.js)). -Warning: if you use `core-js` with the extension of native objects, require all needed `core-js` modules at the top of entry point of your application, otherwise, you can have conflicts. +Warning: if you use `core-js` with the extension of native objects, load all `core-js` modules at the top of entry point of your application, otherwise, you can have conflicts. ### CommonJS You can require only needed modules, like in examples in examples at the top of `README.md`. Available entry points for methods / constructors and namespaces: for example, `core-js/es/array` (`core-js-pure/es/array`) contains all [ES `Array` features](#ecmascript-array), `core-js/es` (`core-js-pure/es`) contains all ES features. diff --git a/packages/core-js-bundle/.npmignore b/packages/core-js-bundle/.npmignore new file mode 100644 index 000000000000..93d04964174a --- /dev/null +++ b/packages/core-js-bundle/.npmignore @@ -0,0 +1,5 @@ +index.js +minified.js +minified.js,map +*.log +.* diff --git a/packages/core-js-bundle/README.md b/packages/core-js-bundle/README.md new file mode 100644 index 000000000000..3241bb50a4e9 --- /dev/null +++ b/packages/core-js-bundle/README.md @@ -0,0 +1,38 @@ +# core-js + +Modular standard library for JavaScript. Includes polyfills for [ECMAScript 5, 2015, 2016, 2017](https://github.com/zloirock/core-js#ecmascript): [promises](https://github.com/zloirock/core-js#ecmascript-promise), [symbols](https://github.com/zloirock/core-js#ecmascript-symbol), [collections](https://github.com/zloirock/core-js#ecmascript-collections), iterators, [typed arrays](https://github.com/zloirock/core-js#ecmascript-typed-arrays), many other features, [ECMAScript proposals](https://github.com/zloirock/core-js#ecmascript-proposals), [some cross-platform WHATWG / W3C ECMAScript-related features and proposals](https://github.com/zloirock/core-js#web-standards) like [setImmediate](https://github.com/zloirock/core-js#setimmediate). You can load only required features or use it without global namespace pollution. + +[*Example*](http://goo.gl/a2xexl): +```js +import 'core-js'; // <- at the top of your entry point + +Array.from(new Set([1, 2, 3, 2, 1])); // => [1, 2, 3] +[1, [2, 3], [4, [5]]].flatten(2); // => [1, 2, 3, 4, 5] +Promise.resolve(32).then(x => console.log(x)); // => 32 +``` + +*You can load only required features*: +```js +import 'core-js/features/array/from'; // <- at the top of your entry point +import 'core-js/features/array/flatten'; // <- at the top of your entry point +import 'core-js/features/set'; // <- at the top of your entry point +import 'core-js/features/promise'; // <- at the top of your entry point + +Array.from(new Set([1, 2, 3, 2, 1])); // => [1, 2, 3] +[1, [2, 3], [4, [5]]].flatten(2); // => [1, 2, 3, 4, 5] +Promise.resolve(32).then(x => console.log(x)); // => 32 +``` + +*Or use it without global namespace pollution*: +```js +import from from 'core-js-pure/features/array/from'; +import flatten from 'core-js-pure/features/array/flatten'; +import Set from 'core-js-pure/features/set'; +import Promise from 'core-js-pure/features/promise'; + +from(new Set([1, 2, 3, 2, 1])); // => [1, 2, 3] +flatten([1, [2, 3], [4, [5]]], 2); // => [1, 2, 3, 4, 5] +Promise.resolve(32).then(x => console.log(x)); // => 32 +``` + +**It's a bundled global version, for more info see [`core-js` documentation](https://github.com/zloirock/core-js/blob/v3/README.md).** diff --git a/packages/core-js-bundle/package.json b/packages/core-js-bundle/package.json new file mode 100644 index 000000000000..f5bea495c1b8 --- /dev/null +++ b/packages/core-js-bundle/package.json @@ -0,0 +1,40 @@ +{ + "name": "core-js-bundle", + "description": "Standard library", + "version": "3.0.0-alpha.1", + "repository": { + "type": "git", + "url": "https://github.com/zloirock/core-js.git" + }, + "main": "index.js", + "license": "MIT", + "keywords": [ + "ES3", + "ES5", + "ES6", + "ES7", + "ES2015", + "ES2016", + "ES2017", + "ECMAScript 3", + "ECMAScript 5", + "ECMAScript 6", + "ECMAScript 7", + "ECMAScript 2015", + "ECMAScript 2016", + "ECMAScript 2017", + "Harmony", + "Strawman", + "Map", + "Set", + "WeakMap", + "WeakSet", + "Promise", + "Symbol", + "TypedArray", + "setImmediate", + "Dict", + "polyfill", + "shim" + ] +} diff --git a/tests/promises-aplus.html b/tests/promises-aplus.html index a18c7d41b950..7b5a18bac7d6 100644 --- a/tests/promises-aplus.html +++ b/tests/promises-aplus.html @@ -7,7 +7,7 @@
- + - + \ No newline at end of file diff --git a/tests/worker/runner.js b/tests/worker/runner.js index 2e742db5d810..301e45b30ed2 100644 --- a/tests/worker/runner.js +++ b/tests/worker/runner.js @@ -1,5 +1,5 @@ 'use strict'; -importScripts('../../packages/core-js/bundles/core.js'); +importScripts('../../packages/core-js-bundle/index.js'); postMessage(typeof core !== 'undefined');