From e44c360c62e0bf8c5896804fd54e6f25253fbc8b Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Thu, 14 Nov 2019 01:08:40 +0800 Subject: [PATCH] Update build scripts to target Node.js 10 (#6908) --- package.json | 2 +- .../replace-array-includes-with-indexof.js | 32 ------------------- scripts/build/build.js | 3 +- scripts/build/bundler.js | 2 +- scripts/build/config.js | 10 ++---- 5 files changed, 5 insertions(+), 44 deletions(-) delete mode 100644 scripts/build/babel-plugins/replace-array-includes-with-indexof.js diff --git a/package.json b/package.json index 7536c355f..b79cab194 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "license": "MIT", "main": "./index.js", "engines": { - "node": ">=8" + "node": ">=10" }, "dependencies": { "@angular/compiler": "8.2.13", diff --git a/scripts/build/babel-plugins/replace-array-includes-with-indexof.js b/scripts/build/babel-plugins/replace-array-includes-with-indexof.js deleted file mode 100644 index 18514344b..000000000 --- a/scripts/build/babel-plugins/replace-array-includes-with-indexof.js +++ /dev/null @@ -1,32 +0,0 @@ -"use strict"; - -// -// BEFORE: -// [__something__].includes(__something__) -// CONSTANT_CASE.includes(__something__) -// -// AFTER: -// [__something__].indexOf(__something__) !== -1 -// CONSTANT_CASE.indexOf(__something__) !== -1 -// - -module.exports = ({ types: t }) => ({ - visitor: { - CallExpression(path) { - const node = path.node; - const callee = node.callee; - if ( - t.isMemberExpression(callee, { computed: false }) && - (t.isArrayExpression(callee.object) || - (t.isIdentifier(callee.object) && - (/^[A-Z_]+$/.test(callee.object.name) || - // https://github.com/eemeli/yaml/blob/1005d01/src/Anchors.js#L45 - callee.object.name === "names"))) && - t.isIdentifier(callee.property, { name: "includes" }) - ) { - callee.property.name = "indexOf"; - path.replaceWith(t.binaryExpression("!==", node, t.numericLiteral(-1))); - } - } - } -}); diff --git a/scripts/build/build.js b/scripts/build/build.js index ad5c9fca8..e775029fb 100644 --- a/scripts/build/build.js +++ b/scripts/build/build.js @@ -77,7 +77,6 @@ async function cacheFiles() { async function preparePackage() { const pkg = await util.readJson("package.json"); pkg.bin = "./bin-prettier.js"; - pkg.engines.node = ">=4"; delete pkg.dependencies; delete pkg.devDependencies; pkg.scripts = { @@ -99,7 +98,7 @@ async function run(params) { await execa("rm", ["-rf", ".cache"]); } - const bundleCache = new Cache(".cache/", "v19"); + const bundleCache = new Cache(".cache/", "v20"); await bundleCache.load(); console.log(chalk.inverse(" Building packages ")); diff --git a/scripts/build/bundler.js b/scripts/build/bundler.js index 7cdc86387..8af0ef60e 100644 --- a/scripts/build/bundler.js +++ b/scripts/build/bundler.js @@ -47,7 +47,7 @@ function getBabelConfig(bundle) { require.resolve("./babel-plugins/transform-custom-require") ); } - const targets = { node: 4 }; + const targets = { node: "10" }; if (bundle.target === "universal") { // From https://jamie.build/last-2-versions targets.browsers = [">0.25%", "not ie 11", "not op_mini all"]; diff --git a/scripts/build/config.js b/scripts/build/config.js index bacf93787..301aadab3 100644 --- a/scripts/build/config.js +++ b/scripts/build/config.js @@ -2,9 +2,6 @@ const path = require("path"); const PROJECT_ROOT = path.resolve(__dirname, "../.."); -const babelReplaceArrayIncludesWithIndexof = require.resolve( - "./babel-plugins/replace-array-includes-with-indexof" -); /** * @typedef {Object} Bundle @@ -29,8 +26,7 @@ const babelReplaceArrayIncludesWithIndexof = require.resolve( const parsers = [ { input: "src/language-js/parser-babylon.js", - target: "universal", - babelPlugins: [babelReplaceArrayIncludesWithIndexof] + target: "universal" }, { input: "src/language-js/parser-flow.js", @@ -40,7 +36,6 @@ const parsers = [ { input: "src/language-js/parser-typescript.js", target: "universal", - babelPlugins: [babelReplaceArrayIncludesWithIndexof], commonjs: { ignore: [ // Optional package for TypeScript that logs ETW events (a Windows-only technology). @@ -133,8 +128,7 @@ const parsers = [ replacement: require.resolve("lines-and-columns") } ] - }, - babelPlugins: [babelReplaceArrayIncludesWithIndexof] + } } ].map(parser => { const name = getFileOutput(parser)