From 8337bbd16fa4f964f688975f3c510d4705c94932 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Thu, 11 Oct 2018 18:45:49 +0200 Subject: [PATCH 1/3] feat: use @babel/runtime helpers instead of bundled ones (#71) Main focus of this PR is to use @babel/runtime helpers instead of including their copy in distributed sources. **Motivation** Shipping less code - by using @babel/runtime helpers we are able to deduplicate their code across all dependencies using them. --- package.json | 2 ++ src/config/babelrc.js | 16 ++++++++++++++-- src/config/rollup.config.js | 5 +++-- src/scripts/build/babel.js | 2 +- 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 9e7789cd..fe5019c8 100644 --- a/package.json +++ b/package.json @@ -35,8 +35,10 @@ "@babel/core": "^7.0.0", "@babel/plugin-proposal-class-properties": "^7.0.0", "@babel/plugin-transform-modules-commonjs": "^7.0.0", + "@babel/plugin-transform-runtime": "^7.1.0", "@babel/preset-env": "^7.0.0", "@babel/preset-react": "^7.0.0", + "@babel/runtime": "^7.1.2", "all-contributors-cli": "^5.0.0", "arrify": "^1.0.1", "babel-core": "^7.0.0-0", diff --git a/src/config/babelrc.js b/src/config/babelrc.js index 46a8011e..30fb764d 100644 --- a/src/config/babelrc.js +++ b/src/config/babelrc.js @@ -3,14 +3,25 @@ const semver = require('semver') const {ifAnyDep, parseEnv, appDirectory, pkg} = require('../utils') -const isTest = (process.env.BABEL_ENV || process.env.NODE_ENV) === 'test' +const {BABEL_ENV, NODE_ENV, BUILD_FORMAT} = process.env +const isTest = (BABEL_ENV || NODE_ENV) === 'test' const isPreact = parseEnv('BUILD_PREACT', false) const isRollup = parseEnv('BUILD_ROLLUP', false) -const isUMD = process.env.BUILD_FORMAT === 'umd' +const isUMD = BUILD_FORMAT === 'umd' +const isCJS = BUILD_FORMAT === 'cjs' const isWebpack = parseEnv('BUILD_WEBPACK', false) const treeshake = parseEnv('BUILD_TREESHAKE', isRollup || isWebpack) const alias = parseEnv('BUILD_ALIAS', isPreact ? {react: 'preact'} : null) +const hasBabelRuntimeDep = Boolean(pkg.dependencies && pkg.dependencies['@babel/runtime']) +const RUNTIME_HELPERS_WARN = 'You should add @babel/runtime as dependency to your package. It will allow reusing so-called babel helpers from npm rather than bundling their copies into your files.' + +if (!treeshake && !hasBabelRuntimeDep) { + throw new Error(RUNTIME_HELPERS_WARN) +} else if (treeshake && !isUMD && !hasBabelRuntimeDep) { + console.warn(RUNTIME_HELPERS_WARN) +} + /** * use the strategy declared by browserslist to load browsers configuration. * fallback to the default if don't found custom configuration @@ -40,6 +51,7 @@ module.exports = () => ({ ), ].filter(Boolean), plugins: [ + [require.resolve('@babel/plugin-transform-runtime'), { useESModules: treeshake && !isCJS }], require.resolve('babel-plugin-macros'), alias ? [ diff --git a/src/config/rollup.config.js b/src/config/rollup.config.js index a7fd7f20..2d732e96 100644 --- a/src/config/rollup.config.js +++ b/src/config/rollup.config.js @@ -115,7 +115,7 @@ const output = [ }, ] -const useBuiltinConfig = !hasFile('.babelrc') && !hasPkgProp('babel') +const useBuiltinConfig = !hasFile('.babelrc') && !hasFile('.babelrc.js') && !hasPkgProp('babel') const babelPresets = useBuiltinConfig ? [here('../config/babelrc.js')] : [] const replacements = Object.entries( @@ -145,7 +145,8 @@ module.exports = { rollupBabel({ exclude: 'node_modules/**', presets: babelPresets, - babelrc: true, + babelrc: !useBuiltinConfig, + runtimeHelpers: useBuiltinConfig, }), replace(replacements), useSizeSnapshot ? sizeSnapshot({printInfo: false}) : null, diff --git a/src/scripts/build/babel.js b/src/scripts/build/babel.js index 92a3783a..67d32e46 100644 --- a/src/scripts/build/babel.js +++ b/src/scripts/build/babel.js @@ -7,7 +7,7 @@ const args = process.argv.slice(2) const here = p => path.join(__dirname, p) const useBuiltinConfig = - !args.includes('--presets') && !hasFile('.babelrc') && !hasPkgProp('babel') + !args.includes('--presets') && !hasFile('.babelrc') && !hasFile('.babelrc.js') && !hasPkgProp('babel') const config = useBuiltinConfig ? ['--presets', here('../../config/babelrc.js')] : [] From 94bc4767a0869befafb53e535f91176b2829c6cd Mon Sep 17 00:00:00 2001 From: Jonathan Dierckens Date: Mon, 19 Nov 2018 12:42:18 +0100 Subject: [PATCH 2/3] =?UTF-8?q?fix:=20=F0=9F=90=9B=20remove=20vulnerabilit?= =?UTF-8?q?ies?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit related to the merge npm package --- package.json | 12 +++++------- src/config/eslintignore | 3 ++- src/config/lintstagedrc.js | 7 ++++++- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index a2e9f865..7b8b41ac 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "CLI for common scripts for my projects", "engines": { "node": ">= 8", - "npm": ">= 5" + "npm": ">= 5.2" }, "bin": { "itp-react-scripts": "dist/index.js" @@ -18,7 +18,7 @@ "format": "node src format", "validate": "node src validate", "precommit": "node src precommit", - "commit": "git-cz" + "commit": "npx git-cz@1.7.1" }, "files": [ "dist", @@ -43,8 +43,8 @@ "all-contributors-cli": "^5.0.0", "arrify": "^1.0.1", "babel-cli": "^7.0.0-0", - "babel-eslint": "^9.0.0", "babel-core": "^7.0.0-0", + "babel-eslint": "^9.0.0", "babel-jest": "^23.4.2", "babel-plugin-macros": "^2.3.0", "babel-plugin-minify-dead-code-elimination": "^0.4.0", @@ -69,7 +69,7 @@ "glob": "^7.1.2", "husky": "^1.0.0-rc.13", "is-ci": "^1.1.0", - "jest": "^23.4.2", + "jest": "^23.6.0", "lint-staged": "^7.0.4", "lodash.camelcase": "^4.3.0", "lodash.has": "^4.5.2", @@ -102,8 +102,6 @@ }, "homepage": "https://github.com/inthepocket/itp-react-scripts#readme", "devDependencies": { - "commitizen": "^2.10.1", - "cz-conventional-changelog": "^2.1.0", "jest-in-case": "^1.0.2", "slash": "^2.0.0" }, @@ -117,7 +115,7 @@ }, "config": { "commitizen": { - "path": "node_modules/cz-conventional-changelog" + "path": "npx cz-conventional-changelog@2.1.0" } } } diff --git a/src/config/eslintignore b/src/config/eslintignore index 98aa5318..03b79caa 100644 --- a/src/config/eslintignore +++ b/src/config/eslintignore @@ -3,4 +3,5 @@ coverage/ dist/ build/ out/ -.next/ \ No newline at end of file +.next/ +*.json \ No newline at end of file diff --git a/src/config/lintstagedrc.js b/src/config/lintstagedrc.js index ff4ea21b..9d737cd5 100644 --- a/src/config/lintstagedrc.js +++ b/src/config/lintstagedrc.js @@ -8,11 +8,16 @@ module.exports = { linters: { 'README.md': [`${doctoc} --maxlevel 3 --notitle`, 'git add'], '.all-contributorsrc': [`${itpScripts} contributors generate`, 'git add README.md'], - '**/*.+(js|json|less|css|ts|tsx|md)': [ + '**/*.+(js|jsx)': [ isOptedOut('autoformat', null, `${itpScripts} format`), `${itpScripts} lint --fix`, `${itpScripts} test --findRelatedTests --passWithNoTests`, isOptedOut('autoformat', null, 'git add'), ].filter(Boolean), + '**/*.+(json|less|css|ts|tsx|md)': [ + isOptedOut('autoformat', null, `${itpScripts} format`), + `${itpScripts} test --findRelatedTests --passWithNoTests`, + isOptedOut('autoformat', null, 'git add'), + ].filter(Boolean), }, }; From 90562c7c94f26f14cbd895d85bb34375815424d4 Mon Sep 17 00:00:00 2001 From: Jonathan Dierckens Date: Mon, 19 Nov 2018 13:33:07 +0100 Subject: [PATCH 3/3] =?UTF-8?q?fix:=20=F0=9F=90=9B=20package.json?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fix typo --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index eee088c4..65900bad 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "format": "node src format", "validate": "node src validate", "precommit": "node src precommit", - "commit": "npx git-cz@1.7.1" + "commit": "npx git-cz@1.7.1", "postinstall": "./postinstall.sh" }, "files": [