diff --git a/package.json b/package.json index d88efa9f..65900bad 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", "postinstall": "./postinstall.sh" }, "files": [ @@ -38,8 +38,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-cli": "^7.0.0-0", @@ -69,7 +71,7 @@ "glob": "^7.1.2", "husky": "^1.1.2", "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 +104,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 +117,7 @@ }, "config": { "commitizen": { - "path": "node_modules/cz-conventional-changelog" + "path": "npx cz-conventional-changelog@2.1.0" } } } diff --git a/src/config/babelrc.js b/src/config/babelrc.js index c9ce1dad..6ac866bb 100644 --- a/src/config/babelrc.js +++ b/src/config/babelrc.js @@ -3,14 +3,26 @@ 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 @@ -34,6 +46,7 @@ module.exports = () => ({ ), ].filter(Boolean), plugins: [ + [require.resolve('@babel/plugin-transform-runtime'), { useESModules: treeshake && !isCJS }], require.resolve('babel-plugin-macros'), alias ? [require.resolve('babel-plugin-module-resolver'), { root: ['./src'], alias }] : null, [ 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), }, }; diff --git a/src/config/rollup.config.js b/src/config/rollup.config.js index 3ed621d6..ce5c5089 100644 --- a/src/config/rollup.config.js +++ b/src/config/rollup.config.js @@ -97,7 +97,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(umd ? process.env : omit(process.env, ['NODE_ENV'])).reduce( @@ -128,7 +128,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 1a2020d8..24b96d15 100644 --- a/src/scripts/build/babel.js +++ b/src/scripts/build/babel.js @@ -7,7 +7,10 @@ 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')] : []; const ignore = args.includes('--ignore') ? [] : ['--ignore', '__tests__,__mocks__'];