Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable corejs option for core bundle bin-prettier.js and third-party.js #6893

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions cspell.json
Expand Up @@ -61,6 +61,7 @@
"codemirror",
"codemod",
"codemods",
"corejs",
"combinator",
"commonmark",
"concating",
Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -82,6 +82,7 @@
"benchmark": "2.1.4",
"builtin-modules": "3.1.0",
"codecov": "3.6.1",
"core-js": "3.4.0",
"cross-env": "6.0.3",
"eslint": "6.6.0",
"eslint-config-prettier": "6.5.0",
Expand Down
33 changes: 28 additions & 5 deletions scripts/build/bundler.js
Expand Up @@ -40,21 +40,40 @@ function getBabelConfig(bundle) {
const config = {
babelrc: false,
plugins: bundle.babelPlugins || [],
exclude: [],
compact: bundle.type === "plugin" ? false : "auto"
};
const presetEnvConfig = {
targets: {
node: "4"
},
modules: false
};
if (bundle.type === "core") {
config.plugins.push(
require.resolve("./babel-plugins/transform-custom-require")
);

if (bundle.corejs) {
Object.assign(presetEnvConfig, {
useBuiltIns: "usage",
corejs: {
version: 3,
proposals: true
}
});
config.exclude.push(/\/core-js\//);
}
}
const targets = { node: 4 };
if (bundle.target === "universal") {
// From https://jamie.build/last-2-versions
targets.browsers = [">0.25%", "not ie 11", "not op_mini all"];
presetEnvConfig.targets.browsers = [
">0.25%",
"not ie 11",
"not op_mini all"
];
}
config.presets = [
[require.resolve("@babel/preset-env"), { targets, modules: false }]
];
config.presets = [[require.resolve("@babel/preset-env"), presetEnvConfig]];
return config;
}

Expand Down Expand Up @@ -206,6 +225,10 @@ function runWebpack(config) {
}

module.exports = async function createBundle(bundle, cache) {
if (bundle.corejs && bundle.type !== "core") {
throw new Error("Only core bundles can use corejs");
}

const inputOptions = getRollupConfig(bundle);
const outputOptions = getRollupOutputOptions(bundle);

Expand Down
3 changes: 3 additions & 0 deletions scripts/build/config.js
Expand Up @@ -19,6 +19,7 @@ const babelReplaceArrayIncludesWithIndexof = require.resolve(
* @property {Object.<string, string>} replace - map of strings to replace when processing the bundle
* @property {string[]} babelPlugins - babel plugins
* @property {Object?} terserOptions - options for `terser`
* @property {boolean?} corejs - use corejs for `@babel/preset-env`

* @typedef {Object} CommonJSConfig
* @property {Object} namedExports - for cases where rollup can't infer what's exported
Expand Down Expand Up @@ -172,12 +173,14 @@ const coreBundles = [
input: "bin/prettier.js",
type: "core",
output: "bin-prettier.js",
corejs: true,
target: "node",
externals: [path.resolve("src/common/third-party.js")]
},
{
input: "src/common/third-party.js",
type: "core",
corejs: true,
target: "node",
replace: {
// cosmiconfig@5 -> import-fresh uses `require` to resolve js config, which caused Error:
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Expand Up @@ -1991,6 +1991,11 @@ core-js-pure@3.1.3:
resolved "https://registry.yarnpkg.com/core-js-pure/-/core-js-pure-3.1.3.tgz#4c90752d5b9471f641514f3728f51c1e0783d0b5"
integrity sha512-k3JWTrcQBKqjkjI0bkfXS0lbpWPxYuHWfMMjC1VDmzU4Q58IwSbuXSo99YO/hUHlw/EB4AlfA2PVxOGkrIq6dA==

core-js@3.4.0:
version "3.4.0"
resolved "https://registry.yarnpkg.com/core-js/-/core-js-3.4.0.tgz#29ea478601789c72f2978e9bb98f43546f89d3aa"
integrity sha512-lQxb4HScV71YugF/X28LtePZj9AB7WqOpcB+YztYxusvhrgZiQXPmCYfPC5LHsw/+ScEtDbXU3xbqH3CjBRmYA==

core-js@^2.4.0, core-js@^2.5.0:
version "2.5.1"
resolved "https://registry.yarnpkg.com/core-js/-/core-js-2.5.1.tgz#ae6874dc66937789b80754ff5428df66819ca50b"
Expand Down