From 588fd878e131c1a21d0c4ddb3318618438cf531e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20De=20Boey?= Date: Mon, 6 Jun 2022 21:07:15 +0200 Subject: [PATCH 1/6] feat: update dependencies BREAKING CHANGE: Use Jest v28 --- .github/workflows/validate.yml | 2 +- package.json | 148 ++++++++++++++--------------- src/__tests__/index.js | 4 +- src/config/jest.config.js | 5 +- src/config/prettierrc.js | 4 +- src/config/rollup.config.js | 9 +- src/scripts/__tests__/precommit.js | 8 +- 7 files changed, 95 insertions(+), 85 deletions(-) diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index bb20ea86..407836b7 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -17,7 +17,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, windows-latest] - node: [12, 14, 16] + node: [12.22.0, 12, 14.17.0, 14, 16.10.0, 16, 18] runs-on: ${{ matrix.os }} steps: - name: 🛑 Cancel Previous Runs diff --git a/package.json b/package.json index 9cd76b32..b20c657a 100644 --- a/package.json +++ b/package.json @@ -2,21 +2,20 @@ "name": "kcd-scripts", "version": "0.0.0-semantically-released", "description": "CLI for common scripts for my projects", - "engines": { - "node": "^12.22.0 || ^14.17.0 || >=16.0.0", - "npm": ">=6" + "keywords": [], + "homepage": "https://github.com/kentcdodds/kcd-scripts#readme", + "bugs": { + "url": "https://github.com/kentcdodds/kcd-scripts/issues" }, + "repository": { + "type": "git", + "url": "https://github.com/kentcdodds/kcd-scripts" + }, + "license": "MIT", + "author": "Kent C. Dodds (https://kentcdodds.com)", "bin": { "kcd-scripts": "dist/index.js" }, - "scripts": { - "test": "node src test", - "test:update": "node src test --updateSnapshot", - "build": "node src build", - "lint": "node src lint", - "format": "node src format", - "validate": "node src validate" - }, "files": [ "dist", "babel.js", @@ -27,64 +26,90 @@ "prettier.js", "shared-tsconfig.json" ], - "keywords": [], - "author": "Kent C. Dodds (https://kentcdodds.com)", - "license": "MIT", + "scripts": { + "build": "node src build", + "format": "node src format", + "lint": "node src lint", + "test": "node src test", + "test:update": "node src test --updateSnapshot", + "validate": "node src validate" + }, + "eslintConfig": { + "extends": [ + "kentcdodds", + "kentcdodds/jest" + ], + "rules": { + "no-console": "off", + "no-nested-ternary": "off", + "no-process-exit": "off", + "no-useless-catch": "off", + "import/extensions": "off", + "import/no-dynamic-require": "off", + "import/no-import-module-exports": "off", + "import/no-unassigned-import": "off" + } + }, + "eslintIgnore": [ + "node_modules", + "coverage", + "dist" + ], "dependencies": { - "@babel/cli": "^7.17.6", - "@babel/core": "^7.17.8", - "@babel/plugin-proposal-class-properties": "^7.16.7", - "@babel/plugin-transform-modules-commonjs": "^7.17.7", - "@babel/plugin-transform-runtime": "^7.17.0", - "@babel/preset-env": "^7.16.11", - "@babel/preset-react": "^7.16.7", - "@babel/preset-typescript": "^7.16.7", - "@babel/runtime": "^7.17.8", + "@babel/cli": "^7.18.6", + "@babel/core": "^7.18.6", + "@babel/plugin-proposal-class-properties": "^7.18.6", + "@babel/plugin-transform-modules-commonjs": "^7.18.6", + "@babel/plugin-transform-runtime": "^7.18.6", + "@babel/preset-env": "^7.18.6", + "@babel/preset-react": "^7.18.6", + "@babel/preset-typescript": "^7.18.6", + "@babel/runtime": "^7.18.6", "@rollup/plugin-babel": "^5.3.1", - "@rollup/plugin-commonjs": "^21.0.3", + "@rollup/plugin-commonjs": "^22.0.1", "@rollup/plugin-json": "^4.1.0", - "@rollup/plugin-node-resolve": "^13.1.3", + "@rollup/plugin-node-resolve": "^13.3.0", "@rollup/plugin-replace": "^4.0.0", - "@types/jest": "^27.4.1", + "@types/jest": "^27.5.2", "arrify": "^2.0.1", - "babel-jest": "^27.5.1", + "babel-jest": "^28.1.2", "babel-plugin-macros": "^3.1.0", - "babel-plugin-minify-dead-code-elimination": "^0.5.1", + "babel-plugin-minify-dead-code-elimination": "^0.5.2", "babel-plugin-module-resolver": "^4.1.0", - "babel-plugin-transform-inline-environment-variables": "^0.4.3", + "babel-plugin-transform-inline-environment-variables": "^0.4.4", "babel-plugin-transform-react-remove-prop-types": "^0.4.24", - "browserslist": "^4.20.2", - "builtin-modules": "^3.2.0", + "browserslist": "^4.21.1", + "builtin-modules": "^3.3.0", "chalk": "^4.1.2", - "concurrently": "^7.1.0", + "concurrently": "^7.2.2", "cosmiconfig": "^7.0.1", "cpy": "^8.1.2", "cross-env": "^7.0.3", "cross-spawn": "^7.0.3", - "doctoc": "^2.1.0", - "eslint": "^8.12.0", - "eslint-config-kentcdodds": "^20.2.0", - "glob": "^7.2.0", + "doctoc": "^2.2.0", + "eslint": "^8.18.0", + "eslint-config-kentcdodds": "^20.3.1", + "glob": "^8.0.3", "husky": "^4.3.8", "is-ci": "^3.0.1", - "jest": "^27.5.1", + "jest": "^28.1.2", + "jest-environment-jsdom": "^28.1.2", "jest-serializer-path": "^0.1.15", "jest-snapshot-serializer-raw": "^1.2.0", - "jest-watch-typeahead": "^1.0.0", - "lint-staged": "^12.3.7", + "jest-watch-typeahead": "^1.1.0", + "lint-staged": "^12.5.0", "lodash.camelcase": "^4.3.0", "lodash.has": "^4.5.2", "lodash.omit": "^4.5.0", "mkdirp": "^1.0.4", - "prettier": "2.6.2", + "prettier": "2.7.1", "read-pkg-up": "^7.0.1", - "resolve": "^1.22.0", + "resolve": "^1.22.1", "rimraf": "^3.0.2", - "rollup": "^2.70.1", - "rollup-plugin-node-builtins": "^2.1.2", - "rollup-plugin-node-globals": "^1.4.0", + "rollup": "^2.75.7", + "rollup-plugin-polyfill-node": "^0.9.0", "rollup-plugin-terser": "^7.0.2", - "semver": "^7.3.5", + "semver": "^7.3.7", "which": "^2.0.2", "yargs-parser": "^21.0.1" }, @@ -92,33 +117,8 @@ "jest-in-case": "^1.0.2", "slash": "^3.0.0" }, - "eslintConfig": { - "extends": [ - "kentcdodds", - "kentcdodds/jest" - ], - "rules": { - "no-process-exit": "off", - "import/no-dynamic-require": "off", - "import/no-import-module-exports": "off", - "import/no-unassigned-import": "off", - "import/extensions": "off", - "no-console": "off", - "no-nested-ternary": "off", - "no-useless-catch": "off" - } - }, - "eslintIgnore": [ - "node_modules", - "coverage", - "dist" - ], - "repository": { - "type": "git", - "url": "https://github.com/kentcdodds/kcd-scripts" - }, - "bugs": { - "url": "https://github.com/kentcdodds/kcd-scripts/issues" - }, - "homepage": "https://github.com/kentcdodds/kcd-scripts#readme" + "engines": { + "node": "^12.22.0 || ^14.17.0 || ^16.10.0 || >=17.0.0", + "npm": ">=6" + } } diff --git a/src/__tests__/index.js b/src/__tests__/index.js index 91325e86..f1227bd3 100644 --- a/src/__tests__/index.js +++ b/src/__tests__/index.js @@ -37,7 +37,9 @@ cases( expect(crossSpawnSyncMock).toHaveBeenCalledTimes(1) const [firstCall] = crossSpawnSyncMock.mock.calls const [script, calledArgs] = firstCall - expect([script, ...calledArgs].join(' ')).toMatchSnapshot('format script') + expect([script, ...calledArgs].join(' ')).toMatchSnapshot( + 'format script', + ) } } catch (error) { if (throws) { diff --git a/src/config/jest.config.js b/src/config/jest.config.js index 222ea890..4f992a9c 100644 --- a/src/config/jest.config.js +++ b/src/config/jest.config.js @@ -14,6 +14,7 @@ const ignores = [ '__mocks__', ] +/** @type {import('@jest/types').Config.InitialOptions} */ const jestConfig = { roots: ['/src'], testEnvironment: ifAnyDep( @@ -21,7 +22,9 @@ const jestConfig = { 'jsdom', 'node', ), - testURL: 'http://localhost', + testEnvironmentOptions: { + url: 'http://localhost', + }, moduleFileExtensions: ['js', 'jsx', 'json', 'ts', 'tsx'], modulePaths: ['/src', 'shared', '/tests'], collectCoverageFrom: ['src/**/*.+(js|jsx|ts|tsx)'], diff --git a/src/config/prettierrc.js b/src/config/prettierrc.js index 88af7683..03add38f 100644 --- a/src/config/prettierrc.js +++ b/src/config/prettierrc.js @@ -1,17 +1,19 @@ +/** @type {import('prettier').Options} */ module.exports = { arrowParens: 'avoid', + bracketSameLine: false, bracketSpacing: false, embeddedLanguageFormatting: 'auto', endOfLine: 'lf', htmlWhitespaceSensitivity: 'css', insertPragma: false, - jsxBracketSameLine: false, jsxSingleQuote: false, printWidth: 80, proseWrap: 'always', quoteProps: 'as-needed', requirePragma: false, semi: false, + singleAttributePerLine: false, singleQuote: true, tabWidth: 2, trailingComma: 'all', diff --git a/src/config/rollup.config.js b/src/config/rollup.config.js index 5ccd06c2..fba89136 100644 --- a/src/config/rollup.config.js +++ b/src/config/rollup.config.js @@ -9,10 +9,9 @@ const { } = require('@rollup/plugin-node-resolve') const replace = require('@rollup/plugin-replace') const camelcase = require('lodash.camelcase') -const {terser} = require('rollup-plugin-terser') -const nodeBuiltIns = require('rollup-plugin-node-builtins') -const nodeGlobals = require('rollup-plugin-node-globals') const omit = require('lodash.omit') +const nodePolyfills = require('rollup-plugin-polyfill-node') +const {terser} = require('rollup-plugin-terser') const { pkg, hasFile, @@ -133,13 +132,13 @@ const output = [ }, ] +/** @returns {import("rollup").RollupOptions} */ module.exports = { input: codeSplitting ? input : input[0], output, external: externalPredicate, plugins: [ - isNode ? nodeBuiltIns() : null, - isNode ? nodeGlobals() : null, + isNode ? nodePolyfills() : null, nodeResolve({ preferBuiltins: isNode, mainFields: ['module', 'main', 'jsnext', 'browser'], diff --git a/src/scripts/__tests__/precommit.js b/src/scripts/__tests__/precommit.js index fd5d0460..e59718c8 100644 --- a/src/scripts/__tests__/precommit.js +++ b/src/scripts/__tests__/precommit.js @@ -31,9 +31,13 @@ cases( expect(crossSpawnSyncMock).toHaveBeenCalledTimes(2) const [firstCall, secondCall] = crossSpawnSyncMock.mock.calls const [scriptOne, calledArgsOne] = firstCall - expect([scriptOne, ...calledArgsOne].join(' ')).toMatchSnapshot('pre-commit scriptOne') + expect([scriptOne, ...calledArgsOne].join(' ')).toMatchSnapshot( + 'pre-commit scriptOne', + ) const [scriptTwo, calledArgsTwo] = secondCall - expect([scriptTwo, ...calledArgsTwo].join(' ')).toMatchSnapshot('pre-commit scriptTwo') + expect([scriptTwo, ...calledArgsTwo].join(' ')).toMatchSnapshot( + 'pre-commit scriptTwo', + ) } catch (error) { throw error } finally { From 08585ab688445451d506552d7500f268b584eeeb Mon Sep 17 00:00:00 2001 From: Nick McCurdy Date: Tue, 30 Aug 2022 01:13:36 -0400 Subject: [PATCH 2/6] fix: use POSIX paths with glob 8 on Windows --- src/run-script.js | 2 +- src/scripts/build/rollup.js | 2 +- src/utils.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/run-script.js b/src/run-script.js index 43769ba1..8ec4aaf7 100755 --- a/src/run-script.js +++ b/src/run-script.js @@ -8,7 +8,7 @@ if (script && script !== '--help' && script !== 'help') { spawnScript() } else { const scriptsPath = path.join(__dirname, 'scripts/') - const scriptsAvailable = glob.sync(path.join(__dirname, 'scripts', '*')) + const scriptsAvailable = glob.sync(`${__dirname}/scripts/*`) // `glob.sync` returns paths with unix style path separators even on Windows. // So we normalize it before attempting to strip out the scripts path. const scriptsAvailableMessage = scriptsAvailable diff --git a/src/scripts/build/rollup.js b/src/scripts/build/rollup.js index 6ac88a6f..7867f1d6 100644 --- a/src/scripts/build/rollup.js +++ b/src/scripts/build/rollup.js @@ -101,7 +101,7 @@ function go() { const isCodesplitting = rollupInputs.length > 1 const outputs = isCodesplitting - ? glob.sync(fromRoot(path.join(dirpath, format, '*.js'))) + ? glob.sync(fromRoot(path.posix.join(dirpath, format, '*.js'))) : [fromRoot(path.join(dirpath, filename))] for (const output of outputs) { diff --git a/src/utils.js b/src/utils.js index 484ce2df..aecd0508 100644 --- a/src/utils.js +++ b/src/utils.js @@ -54,7 +54,7 @@ function resolveBin(modName, {executable = modName, cwd = process.cwd()} = {}) { } } -const fromRoot = (...p) => path.join(appDirectory, ...p) +const fromRoot = (...p) => path.posix.join(appDirectory, ...p) const hasFile = (...p) => fs.existsSync(fromRoot(...p)) const ifFile = (files, t, f) => arrify(files).some(file => hasFile(file)) ? t : f From 3e130f557c99b6fe38da40375b0ca82f2f509bd6 Mon Sep 17 00:00:00 2001 From: Nick McCurdy Date: Tue, 30 Aug 2022 05:50:50 -0400 Subject: [PATCH 3/6] Fix `__dirname` usage --- src/run-script.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/run-script.js b/src/run-script.js index 8ec4aaf7..63fe60a0 100755 --- a/src/run-script.js +++ b/src/run-script.js @@ -8,7 +8,7 @@ if (script && script !== '--help' && script !== 'help') { spawnScript() } else { const scriptsPath = path.join(__dirname, 'scripts/') - const scriptsAvailable = glob.sync(`${__dirname}/scripts/*`) + const scriptsAvailable = glob.sync(path.posix.join(__dirname, 'scripts', '*')) // `glob.sync` returns paths with unix style path separators even on Windows. // So we normalize it before attempting to strip out the scripts path. const scriptsAvailableMessage = scriptsAvailable From b2bcc1a346829a43d0db59a0dfb02725151a846d Mon Sep 17 00:00:00 2001 From: Nick McCurdy Date: Tue, 30 Aug 2022 06:01:58 -0400 Subject: [PATCH 4/6] Implement `toPOSIX` function --- src/run-script.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/run-script.js b/src/run-script.js index 63fe60a0..caf97b13 100755 --- a/src/run-script.js +++ b/src/run-script.js @@ -2,13 +2,19 @@ const path = require('path') const spawn = require('cross-spawn') const glob = require('glob') +function toPOSIX(file) { + return file.split(path.sep).join(path.posix.sep) +} + const [executor, ignoredBin, script] = process.argv if (script && script !== '--help' && script !== 'help') { spawnScript() } else { const scriptsPath = path.join(__dirname, 'scripts/') - const scriptsAvailable = glob.sync(path.posix.join(__dirname, 'scripts', '*')) + const scriptsAvailable = glob.sync( + toPOSIX(path.join(__dirname, 'scripts', '*')), + ) // `glob.sync` returns paths with unix style path separators even on Windows. // So we normalize it before attempting to strip out the scripts path. const scriptsAvailableMessage = scriptsAvailable From c91ec8f69f3e2062095af0e7729fcda442eba61f Mon Sep 17 00:00:00 2001 From: Nick McCurdy Date: Tue, 30 Aug 2022 06:36:31 -0400 Subject: [PATCH 5/6] Move `toPOSIX` to utils --- src/run-script.js | 5 +---- src/utils.js | 2 ++ 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/run-script.js b/src/run-script.js index caf97b13..d4befd9d 100755 --- a/src/run-script.js +++ b/src/run-script.js @@ -1,10 +1,7 @@ const path = require('path') const spawn = require('cross-spawn') const glob = require('glob') - -function toPOSIX(file) { - return file.split(path.sep).join(path.posix.sep) -} +const {toPOSIX} = require('./utils') const [executor, ignoredBin, script] = process.argv diff --git a/src/utils.js b/src/utils.js index aecd0508..ccfafaac 100644 --- a/src/utils.js +++ b/src/utils.js @@ -55,6 +55,7 @@ function resolveBin(modName, {executable = modName, cwd = process.cwd()} = {}) { } const fromRoot = (...p) => path.posix.join(appDirectory, ...p) +const toPOSIX = p => p.split(path.sep).join(path.posix.sep) const hasFile = (...p) => fs.existsSync(fromRoot(...p)) const ifFile = (files, t, f) => arrify(files).some(file => hasFile(file)) ? t : f @@ -222,6 +223,7 @@ function getRollupOutput(format = process.env.BUILD_FORMAT) { module.exports = { appDirectory, fromRoot, + toPOSIX, getConcurrentlyArgs, hasFile, hasLocalConfig, From 7c379c01b38283db071deaecc508dc9b9f222a64 Mon Sep 17 00:00:00 2001 From: Nick McCurdy Date: Tue, 30 Aug 2022 06:38:49 -0400 Subject: [PATCH 6/6] Only use POSIX when using `glob` --- src/scripts/build/rollup.js | 11 ++++++----- src/utils.js | 4 ++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/scripts/build/rollup.js b/src/scripts/build/rollup.js index 7867f1d6..82415b07 100644 --- a/src/scripts/build/rollup.js +++ b/src/scripts/build/rollup.js @@ -8,6 +8,7 @@ const { hasFile, resolveBin, fromRoot, + toPOSIX, getConcurrentlyArgs, writeExtraEntry, hasTypescript, @@ -76,8 +77,8 @@ function go() { writeExtraEntry( 'preact', { - cjs: glob.sync(fromRoot('preact/**/*.cjs.js'))[0], - esm: glob.sync(fromRoot('preact/**/*.esm.js'))[0], + cjs: glob.sync(toPOSIX(fromRoot('preact/**/*.cjs.js')))[0], + esm: glob.sync(toPOSIX(fromRoot('preact/**/*.esm.js')))[0], }, false, ) @@ -101,7 +102,7 @@ function go() { const isCodesplitting = rollupInputs.length > 1 const outputs = isCodesplitting - ? glob.sync(fromRoot(path.posix.join(dirpath, format, '*.js'))) + ? glob.sync(toPOSIX(fromRoot(path.posix.join(dirpath, format, '*.js')))) : [fromRoot(path.join(dirpath, filename))] for (const output of outputs) { @@ -123,8 +124,8 @@ function go() { // because typescript generates type defs for ignored files, we need to // remove the ignored files const ignoredFiles = [ - ...glob.sync(fromRoot('dist', '**/__tests__/**')), - ...glob.sync(fromRoot('dist', '**/__mocks__/**')), + ...glob.sync(toPOSIX(fromRoot('dist', '**/__tests__/**'))), + ...glob.sync(toPOSIX(fromRoot('dist', '**/__mocks__/**'))), ] ignoredFiles.forEach(ignoredFile => { rimraf.sync(ignoredFile) diff --git a/src/utils.js b/src/utils.js index ccfafaac..973ce844 100644 --- a/src/utils.js +++ b/src/utils.js @@ -54,7 +54,7 @@ function resolveBin(modName, {executable = modName, cwd = process.cwd()} = {}) { } } -const fromRoot = (...p) => path.posix.join(appDirectory, ...p) +const fromRoot = (...p) => path.join(appDirectory, ...p) const toPOSIX = p => p.split(path.sep).join(path.posix.sep) const hasFile = (...p) => fs.existsSync(fromRoot(...p)) const ifFile = (files, t, f) => @@ -193,7 +193,7 @@ function getRollupInputs() { const buildInputGlob = process.env.BUILD_INPUT || (hasTypescript ? 'src/index.{js,ts,tsx}' : 'src/index.js') - const input = glob.sync(fromRoot(buildInputGlob)) + const input = glob.sync(toPOSIX(fromRoot(buildInputGlob))) if (!input.length) { throw new Error(`Unable to find files with this glob: ${buildInputGlob}`) }