Skip to content

Commit

Permalink
Merge pull request #11 from inthepocket/feature/keep-up-with-forked-repo
Browse files Browse the repository at this point in the history
Feature/keep up with forked repo
  • Loading branch information
easybird authored Nov 19, 2018
2 parents f60ddbe + 90562c7 commit b46a390
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 13 deletions.
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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": [
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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"
},
Expand All @@ -117,7 +117,7 @@
},
"config": {
"commitizen": {
"path": "node_modules/cz-conventional-changelog"
"path": "npx cz-conventional-changelog@2.1.0"
}
}
}
17 changes: 15 additions & 2 deletions src/config/babelrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
[
Expand Down
3 changes: 2 additions & 1 deletion src/config/eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ coverage/
dist/
build/
out/
.next/
.next/
*.json
7 changes: 6 additions & 1 deletion src/config/lintstagedrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
},
};
5 changes: 3 additions & 2 deletions src/config/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 4 additions & 1 deletion src/scripts/build/babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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__'];
Expand Down

0 comments on commit b46a390

Please sign in to comment.