diff --git a/package.json b/package.json index e08a1151..a2621ece 100644 --- a/package.json +++ b/package.json @@ -53,15 +53,15 @@ "babel-plugin-module-resolver": "^4.0.0", "babel-plugin-transform-inline-environment-variables": "^0.4.3", "babel-plugin-transform-react-remove-prop-types": "^0.4.24", - "browserslist": "^4.14.6", + "browserslist": "^4.14.7", "chalk": "^4.1.0", "concurrently": "^5.3.0", "cosmiconfig": "^7.0.0", "cross-env": "^7.0.2", "cross-spawn": "^7.0.3", "doctoc": "^1.4.0", - "eslint": "^7.12.1", - "eslint-config-kentcdodds": "^16.1.0", + "eslint": "^7.13.0", + "eslint-config-kentcdodds": "^17.0.0", "eslint-config-prettier": "^6.15.0", "glob": "^7.1.6", "husky": "^4.3.0", @@ -84,7 +84,7 @@ "rollup-plugin-terser": "^7.0.2", "semver": "^7.3.2", "which": "^2.0.2", - "yargs-parser": "^20.2.3" + "yargs-parser": "^20.2.4" }, "eslintConfig": { "extends": [ diff --git a/src/__tests__/__snapshots__/index.js.snap b/src/__tests__/__snapshots__/index.js.snap index 6bb53caf..7aaeafb0 100644 --- a/src/__tests__/__snapshots__/index.js.snap +++ b/src/__tests__/__snapshots__/index.js.snap @@ -34,8 +34,6 @@ Available Scripts: lint pre-commit test - travis-after-success - travis-release validate Options: diff --git a/src/run-script.js b/src/run-script.js index f0462573..49bdf9b5 100755 --- a/src/run-script.js +++ b/src/run-script.js @@ -4,7 +4,7 @@ const glob = require('glob') const [executor, ignoredBin, script] = process.argv -if (script) { +if (script && script !== '--help' && script !== 'help') { spawnScript() } else { const scriptsPath = path.join(__dirname, 'scripts/') diff --git a/src/scripts/__tests__/__snapshots__/lint.js.snap b/src/scripts/__tests__/__snapshots__/lint.js.snap index 211f9d07..03ae938d 100644 --- a/src/scripts/__tests__/__snapshots__/lint.js.snap +++ b/src/scripts/__tests__/__snapshots__/lint.js.snap @@ -1,21 +1,23 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`lint --no-cache will disable caching 1`] = `eslint --config ./src/config/eslintrc.js --ignore-path ./src/config/eslintignore --no-cache .`; +exports[`lint --no-cache will disable caching 1`] = `eslint --config ./src/config/eslintrc.js --ext js,ts,tsx --ignore-path ./src/config/eslintignore --no-cache .`; -exports[`lint calls eslint CLI with default args 1`] = `eslint --config ./src/config/eslintrc.js --ignore-path ./src/config/eslintignore --cache --cache-location /node_modules/.cache/.eslintcache .`; +exports[`lint calls eslint CLI with default args 1`] = `eslint --config ./src/config/eslintrc.js --ext js,ts,tsx --ignore-path ./src/config/eslintignore --cache --cache-location /node_modules/.cache/.eslintcache .`; -exports[`lint does not use built-in config with .eslintrc file 1`] = `eslint --ignore-path ./src/config/eslintignore --cache --cache-location /node_modules/.cache/.eslintcache .`; +exports[`lint does not use built-in config with .eslintrc file 1`] = `eslint --ext js,ts,tsx --ignore-path ./src/config/eslintignore --cache --cache-location /node_modules/.cache/.eslintcache .`; -exports[`lint does not use built-in config with .eslintrc.js file 1`] = `eslint --ignore-path ./src/config/eslintignore --cache --cache-location /node_modules/.cache/.eslintcache .`; +exports[`lint does not use built-in config with .eslintrc.js file 1`] = `eslint --ext js,ts,tsx --ignore-path ./src/config/eslintignore --cache --cache-location /node_modules/.cache/.eslintcache .`; -exports[`lint does not use built-in config with --config 1`] = `eslint --ignore-path ./src/config/eslintignore --cache --cache-location /node_modules/.cache/.eslintcache --config ./custom-config.js .`; +exports[`lint does not use built-in config with --config 1`] = `eslint --ext js,ts,tsx --ignore-path ./src/config/eslintignore --cache --cache-location /node_modules/.cache/.eslintcache --config ./custom-config.js .`; -exports[`lint does not use built-in config with eslintConfig pkg prop 1`] = `eslint --ignore-path ./src/config/eslintignore --cache --cache-location /node_modules/.cache/.eslintcache .`; +exports[`lint does not use built-in config with eslintConfig pkg prop 1`] = `eslint --ext js,ts,tsx --ignore-path ./src/config/eslintignore --cache --cache-location /node_modules/.cache/.eslintcache .`; -exports[`lint does not use built-in ignore with .eslintignore file 1`] = `eslint --config ./src/config/eslintrc.js --cache --cache-location /node_modules/.cache/.eslintcache .`; +exports[`lint does not use built-in ignore with .eslintignore file 1`] = `eslint --config ./src/config/eslintrc.js --ext js,ts,tsx --cache --cache-location /node_modules/.cache/.eslintcache .`; -exports[`lint does not use built-in ignore with --ignore-path 1`] = `eslint --config ./src/config/eslintrc.js --cache --cache-location /node_modules/.cache/.eslintcache --ignore-path ./my-ignore .`; +exports[`lint does not use built-in ignore with --ignore-path 1`] = `eslint --config ./src/config/eslintrc.js --ext js,ts,tsx --cache --cache-location /node_modules/.cache/.eslintcache --ignore-path ./my-ignore .`; -exports[`lint does not use built-in ignore with eslintIgnore pkg prop 1`] = `eslint --config ./src/config/eslintrc.js --cache --cache-location /node_modules/.cache/.eslintcache .`; +exports[`lint does not use built-in ignore with eslintIgnore pkg prop 1`] = `eslint --config ./src/config/eslintrc.js --ext js,ts,tsx --cache --cache-location /node_modules/.cache/.eslintcache .`; -exports[`lint runs on given files, but only js files 1`] = `eslint --config ./src/config/eslintrc.js --ignore-path ./src/config/eslintignore --cache --cache-location /node_modules/.cache/.eslintcache ./src/index.js ./src/component.js`; +exports[`lint runs on given files, but only js files 1`] = `eslint --config ./src/config/eslintrc.js --ext js,ts,tsx --ignore-path ./src/config/eslintignore --cache --cache-location /node_modules/.cache/.eslintcache ./src/index.js ./src/thing.ts ./src/lib.tsx ./src/component.js`; + +exports[`lint supports custom --ext 1`] = `eslint --config ./src/config/eslintrc.js --ignore-path ./src/config/eslintignore --cache --cache-location /node_modules/.cache/.eslintcache --ext js .`; diff --git a/src/scripts/__tests__/__snapshots__/travis-after-success.js.snap b/src/scripts/__tests__/__snapshots__/travis-after-success.js.snap deleted file mode 100644 index 7609f581..00000000 --- a/src/scripts/__tests__/__snapshots__/travis-after-success.js.snap +++ /dev/null @@ -1,72 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`travis-after-success calls concurrently with both scripts when on travis 1`] = ` -Array [ - Array [ - installing and running travis-deploy-once, - ], -] -`; - -exports[`travis-after-success calls concurrently with both scripts when on travis 2`] = ` -Array [ - npx travis-deploy-once@5, - concurrently --prefix [{name}] --names codecov,release --prefix-colors bgBlue.bold.reset,bgGreen.bold.reset "echo installing codecov && npx -p codecov@3 -c 'echo running codecov && codecov'" "echo installing semantic-release && npx -p semantic-release@17 -c 'echo running semantic-release && semantic-release'", -] -`; - -exports[`travis-after-success does not do autorelease script when running on travis but in a pull request 1`] = `Array []`; - -exports[`travis-after-success does not do autorelease script when running on travis but in a pull request 2`] = ` -Array [ - concurrently --prefix [{name}] --names codecov --prefix-colors bgBlue.bold.reset "echo installing codecov && npx -p codecov@3 -c 'echo running codecov && codecov'", -] -`; - -exports[`travis-after-success does not do the autorelease script when the version is different 1`] = `Array []`; - -exports[`travis-after-success does not do the autorelease script when the version is different 2`] = ` -Array [ - concurrently --prefix [{name}] --names codecov --prefix-colors bgBlue.bold.reset "echo installing codecov && npx -p codecov@3 -c 'echo running codecov && codecov'", -] -`; - -exports[`travis-after-success does not do the codecov script when opted out 1`] = ` -Array [ - Array [ - installing and running travis-deploy-once, - ], -] -`; - -exports[`travis-after-success does not do the codecov script when opted out 2`] = ` -Array [ - npx travis-deploy-once@5, - concurrently --prefix [{name}] --names release --prefix-colors bgBlue.bold.reset "echo installing semantic-release && npx -p semantic-release@17 -c 'echo running semantic-release && semantic-release'", -] -`; - -exports[`travis-after-success does not do the codecov script when there is no coverage directory 1`] = ` -Array [ - Array [ - installing and running travis-deploy-once, - ], -] -`; - -exports[`travis-after-success does not do the codecov script when there is no coverage directory 2`] = ` -Array [ - npx travis-deploy-once@5, - concurrently --prefix [{name}] --names release --prefix-colors bgBlue.bold.reset "echo installing semantic-release && npx -p semantic-release@17 -c 'echo running semantic-release && semantic-release'", -] -`; - -exports[`travis-after-success does not run either script when no coverage dir and not the right version 1`] = ` -Array [ - Array [ - No need to autorelease or report coverage. Skipping travis-after-success script..., - ], -] -`; - -exports[`travis-after-success does not run either script when no coverage dir and not the right version 2`] = `Array []`; diff --git a/src/scripts/__tests__/lint.js b/src/scripts/__tests__/lint.js index 6f6022e2..d3c0c3bf 100644 --- a/src/scripts/__tests__/lint.js +++ b/src/scripts/__tests__/lint.js @@ -75,11 +75,16 @@ cases( '--no-cache will disable caching': { args: ['--no-cache'], }, + 'supports custom --ext': { + args: ['--ext', 'js'], + }, 'runs on given files, but only js files': { args: [ './src/index.js', './package.json', './src/index.css', + './src/thing.ts', + './src/lib.tsx', './src/component.js', ], }, diff --git a/src/scripts/__tests__/travis-after-success.js b/src/scripts/__tests__/travis-after-success.js deleted file mode 100644 index 4f4031e2..00000000 --- a/src/scripts/__tests__/travis-after-success.js +++ /dev/null @@ -1,77 +0,0 @@ -import cases from 'jest-in-case' -import {unquoteSerializer} from './helpers/serializers' - -expect.addSnapshotSerializer(unquoteSerializer) - -cases( - 'travis-after-success', - ({ - version = '0.0.0-semantically-released', - hasCoverageDir = true, - isOptedOutOfCoverage = false, - env = { - TRAVIS: 'true', - TRAVIS_BRANCH: 'master', - TRAVIS_PULL_REQUEST: 'false', - }, - }) => { - // beforeEach - const {sync: crossSpawnSyncMock} = require('cross-spawn') - const utils = require('../../utils') - utils.resolveBin = (modName, {executable = modName} = {}) => executable - const originalEnvs = Object.keys(env).map(envKey => { - const orig = process.env[envKey] - process.env[envKey] = env[envKey] - return orig - }) - const originalLog = console.log - const originalExit = process.exit - process.exit = jest.fn() - console.log = jest.fn() - - // tests - if (version) { - utils.pkg.version = version - } - utils.hasFile = () => hasCoverageDir - process.env.SKIP_CODECOV = isOptedOutOfCoverage - require('../travis-after-success') - - expect(console.log.mock.calls).toMatchSnapshot() - const commands = crossSpawnSyncMock.mock.calls.map( - call => `${call[0]} ${call[1].join(' ')}`, - ) - expect(commands).toMatchSnapshot() - - // afterEach - process.exit = originalExit - console.log = originalLog - Object.keys(originalEnvs).forEach(envKey => { - process.env[envKey] = env[envKey] - }) - jest.resetModules() - }, - { - 'calls concurrently with both scripts when on travis': {}, - 'does not do the autorelease script when the version is different': { - version: '1.2.3', - }, - 'does not do the codecov script when there is no coverage directory': { - hasCoverageDir: false, - }, - 'does not do the codecov script when opted out': { - isOptedOutOfCoverage: true, - }, - 'does not do autorelease script when running on travis but in a pull request': { - env: { - TRAVIS: 'true', - TRAVIS_BRANCH: 'master', - TRAVIS_PULL_REQUEST: 'true', - }, - }, - 'does not run either script when no coverage dir and not the right version': { - hasCoverageDir: false, - version: '1.2.3', - }, - }, -) diff --git a/src/scripts/lint.js b/src/scripts/lint.js index 2a3be2b0..93aadc3d 100644 --- a/src/scripts/lint.js +++ b/src/scripts/lint.js @@ -18,6 +18,10 @@ const config = useBuiltinConfig ? ['--config', hereRelative('../config/eslintrc.js')] : [] +const defaultExtensions = 'js,ts,tsx' +const ext = args.includes('--ext') ? [] : ['--ext', defaultExtensions] +const extensions = (parsedArgs.ext || defaultExtensions).split(',') + const useBuiltinIgnore = !args.includes('--ignore-path') && !hasFile('.eslintignore') && @@ -43,12 +47,14 @@ if (filesGiven) { // we need to take all the flag-less arguments (the files that should be linted) // and filter out the ones that aren't js files. Otherwise json or css files // may be passed through - args = args.filter(a => !parsedArgs._.includes(a) || /\.jsx?$/.test(a)) + args = args.filter( + a => !parsedArgs._.includes(a) || extensions.some(e => a.endsWith(e)), + ) } const result = spawn.sync( resolveBin('eslint'), - [...config, ...ignore, ...cache, ...args, ...filesToApply], + [...config, ...ext, ...ignore, ...cache, ...args, ...filesToApply], {stdio: 'inherit'}, ) diff --git a/src/scripts/travis-after-success.js b/src/scripts/travis-after-success.js deleted file mode 100644 index 8cc57394..00000000 --- a/src/scripts/travis-after-success.js +++ /dev/null @@ -1,64 +0,0 @@ -const spawn = require('cross-spawn') -const { - resolveBin, - getConcurrentlyArgs, - hasFile, - pkg, - parseEnv, -} = require('../utils') - -const releaseBranches = ['master', 'next', 'next-major', 'beta', 'alpha'] - -const autorelease = - pkg.version === '0.0.0-semantically-released' && - parseEnv('TRAVIS', false) && - releaseBranches.includes(process.env.TRAVIS_BRANCH) && - !parseEnv('TRAVIS_PULL_REQUEST', false) - -if (autorelease) { - // we only need deploy once for releases - console.log('installing and running travis-deploy-once') - const deployOnceResults = spawn.sync('npx', ['travis-deploy-once@5'], { - stdio: 'inherit', - }) - if (deployOnceResults.status === 0) { - runAfterSuccessScripts() - } else { - console.log( - 'travis-deploy-once exited with a non-zero exit code', - deployOnceResults.status, - ) - process.exit(deployOnceResults.status) - } -} else { - runAfterSuccessScripts() -} - -// eslint-disable-next-line complexity -function runAfterSuccessScripts() { - const reportCoverage = hasFile('coverage') && !parseEnv('SKIP_CODECOV', false) - - if (!autorelease && !reportCoverage) { - console.log( - 'No need to autorelease or report coverage. Skipping travis-after-success script...', - ) - } else { - const result = spawn.sync( - resolveBin('concurrently'), - getConcurrentlyArgs( - { - codecov: reportCoverage - ? `echo installing codecov && npx -p codecov@3 -c 'echo running codecov && codecov'` - : null, - release: autorelease - ? `echo installing semantic-release && npx -p semantic-release@17 -c 'echo running semantic-release && semantic-release'` - : null, - }, - {killOthers: false}, - ), - {stdio: 'inherit'}, - ) - - process.exit(result.status) - } -} diff --git a/src/scripts/travis-release.js b/src/scripts/travis-release.js deleted file mode 100644 index 5bba415a..00000000 --- a/src/scripts/travis-release.js +++ /dev/null @@ -1,50 +0,0 @@ -const chalk = require('chalk') -const spawn = require('cross-spawn') -const glob = require('glob') -const {pkg, parseEnv, hasScript} = require('../utils') - -const releaseBranches = ['master', 'next', 'next-major', 'beta', 'alpha'] - -const autorelease = - pkg.version === '0.0.0-semantically-released' && - parseEnv('TRAVIS', false) && - releaseBranches.includes(process.env.TRAVIS_BRANCH) && - !parseEnv('TRAVIS_PULL_REQUEST', false) - -function main() { - if (autorelease) { - if (hasScript('build') && pkg.files) { - let needToBuild = pkg.files.filter( - fileGlob => glob.sync(fileGlob).length < 1, - ) - if (needToBuild.length) { - const buildResult = spawn.sync('npm', ['run', 'build'], { - stdio: 'inherit', - }) - if (buildResult.status !== 0) { - process.exit(buildResult.status) - return - } - needToBuild = pkg.files.filter( - fileGlob => glob.sync(fileGlob).length < 1, - ) - if (needToBuild.length) { - const list = needToBuild.join(', ') - throw new Error( - chalk.red( - `🚨 The following listings in package.json#files do not match any files even after the build: ${list}`, - ), - ) - } - } - } - - const result = spawn.sync('npx', ['semantic-release@17'], { - stdio: 'inherit', - }) - - process.exit(result.status) - } -} - -main()