diff --git a/.prettierrc.js b/.prettierrc.js index f209a68c..4b7a1882 100644 --- a/.prettierrc.js +++ b/.prettierrc.js @@ -6,4 +6,5 @@ module.exports = Object.assign({}, prettierConfig, { printWidth: 80, semi: false, bracketSpacing: false, + arrowParens: 'avoid', }) diff --git a/README.md b/README.md index f2ef2211..c0149a4a 100644 --- a/README.md +++ b/README.md @@ -192,10 +192,13 @@ module.exports = { ### ES Module Support with jest (`cod-scripts test`) -As of this writing, jest esmodule support is still a [WIP](https://github.com/facebook/jest/issues/12270). If you're testing a nodejs esmodule, you need to pass -the `--experimental-vm-modules` flag to node. For example: +As of this writing, jest esmodule support is still a +[WIP](https://github.com/facebook/jest/issues/12270). If you're testing a nodejs +esmodule, you need to pass the `--experimental-vm-modules` flag to node. For +example: **package.json** + ```json "scripts": { "test": "NODE_OPTIONS=--experimental-vm-modules cod-scripts test" diff --git a/package.json b/package.json index 475656aa..dd907508 100644 --- a/package.json +++ b/package.json @@ -2,22 +2,20 @@ "name": "cod-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/codfish/cod-scripts#readme", + "bugs": { + "url": "https://github.com/codfish/cod-scripts/issues" }, + "repository": { + "type": "git", + "url": "https://github.com/codfish/cod-scripts" + }, + "license": "MIT", + "author": "Chris O'Donnell (http://codfish.io/)", "bin": { "cod-scripts": "dist/index.js" }, - "scripts": { - "test": "node src test", - "test:update": "node src test --updateSnapshot", - "build": "node src build", - "lint": "node src lint", - "commitlint": "node src commitlint", - "format": "node src format", - "validate": "node src validate" - }, "files": [ "dist", "babel.js", @@ -29,76 +27,14 @@ "prettier.js", "shared-tsconfig.json" ], - "keywords": [], - "author": "Chris O'Donnell (http://codfish.io/)", - "license": "MIT", - "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", - "@commitlint/cli": "^17.0.3", - "@commitlint/config-conventional": "^17.0.3", - "@rollup/plugin-babel": "^5.3.1", - "@rollup/plugin-commonjs": "^21.0.3", - "@rollup/plugin-json": "^4.1.0", - "@rollup/plugin-node-resolve": "^13.1.3", - "@rollup/plugin-replace": "^4.0.0", - "@types/jest": "^27.4.1", - "arrify": "^2.0.1", - "babel-jest": "^27.5.1", - "babel-plugin-macros": "^3.1.0", - "babel-plugin-minify-dead-code-elimination": "^0.5.1", - "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.20.2", - "builtin-modules": "^3.2.0", - "chalk": "^5.0.1", - "concurrently": "^7.1.0", - "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-codfish": "^11.1.0", - "eslint-config-kentcdodds": "^20.2.0", - "glob": "^8.0.3", - "husky": "^8.0.1", - "is-ci": "^3.0.1", - "jest": "^27.5.1", - "jest-serializer-path": "^0.1.15", - "jest-snapshot-serializer-raw": "^1.2.0", - "jest-watch-typeahead": "^1.0.0", - "lint-staged": "^13.0.3", - "lodash.camelcase": "^4.3.0", - "lodash.has": "^4.5.2", - "lodash.omit": "^4.5.0", - "mkdirp": "^1.0.4", - "prettier": "^2.7.1", - "react-app-polyfill": "^3.0.0", - "read-pkg-up": "^7.0.1", - "resolve": "^1.22.0", - "rimraf": "^3.0.2", - "rollup": "^2.70.1", - "rollup-plugin-node-builtins": "^2.1.2", - "rollup-plugin-node-globals": "^1.4.0", - "rollup-plugin-size-snapshot": "^0.12.0", - "rollup-plugin-terser": "^7.0.2", - "semver": "^7.3.5", - "which": "^2.0.2", - "yargs-parser": "^21.0.1" - }, - "devDependencies": { - "jest-in-case": "^1.0.2", - "slash": "^3.0.0", - "typescript": "^4.3.2" + "scripts": { + "test": "node src test", + "test:update": "node src test --updateSnapshot", + "build": "node src build", + "lint": "node src lint", + "commitlint": "node src commitlint", + "format": "node src format", + "validate": "node src validate" }, "eslintConfig": { "extends": [ @@ -137,25 +73,79 @@ ] } }, - "commitlint": { - "extends": [ - "./src/config/commitlint.config" - ], - "rules": { - "scope-case": [ - 0 - ], - "subject-case": [ - 0 - ] - } - }, - "repository": { - "type": "git", - "url": "https://github.com/codfish/cod-scripts" + "eslintIgnore": [ + "node_modules", + "coverage", + "dist" + ], + "dependencies": { + "@babel/cli": "^7.18.10", + "@babel/core": "^7.18.13", + "@babel/plugin-proposal-class-properties": "^7.18.6", + "@babel/plugin-transform-modules-commonjs": "^7.18.6", + "@babel/plugin-transform-runtime": "^7.18.10", + "@babel/preset-env": "^7.18.10", + "@babel/preset-react": "^7.18.6", + "@babel/preset-typescript": "^7.18.6", + "@babel/runtime": "^7.18.9", + "@commitlint/cli": "^17.0.3", + "@commitlint/config-conventional": "^17.0.3", + "@rollup/plugin-babel": "^5.3.1", + "@rollup/plugin-commonjs": "^22.0.2", + "@rollup/plugin-json": "^4.1.0", + "@rollup/plugin-node-resolve": "^13.3.0", + "@rollup/plugin-replace": "^4.0.0", + "@types/jest": "^29.4.0", + "arrify": "^2.0.1", + "babel-jest": "^29.4.1", + "babel-plugin-macros": "^3.1.0", + "babel-plugin-minify-dead-code-elimination": "^0.5.2", + "babel-plugin-module-resolver": "^4.1.0", + "babel-plugin-transform-inline-environment-variables": "^0.4.4", + "babel-plugin-transform-react-remove-prop-types": "^0.4.24", + "browserslist": "^4.21.3", + "builtin-modules": "^3.3.0", + "chalk": "^4.1.2", + "concurrently": "^7.3.0", + "cosmiconfig": "^7.0.1", + "cpy": "^8.1.2", + "cross-env": "^7.0.3", + "cross-spawn": "^7.0.3", + "doctoc": "^2.2.0", + "eslint": "^8.23.0", + "eslint-config-codfish": "^11.1.0", + "eslint-config-kentcdodds": "^20.4.0", + "glob": "^8.0.3", + "husky": "^4.3.8", + "is-ci": "^3.0.1", + "jest": "^29.4.1", + "jest-environment-jsdom": "^29.4.1", + "jest-serializer-path": "^0.1.15", + "jest-snapshot-serializer-raw": "^1.2.0", + "jest-watch-typeahead": "^2.2.2", + "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.7.1", + "react-app-polyfill": "^3.0.0", + "read-pkg-up": "^7.0.1", + "resolve": "^1.22.1", + "rimraf": "^3.0.2", + "rollup": "^2.78.1", + "rollup-plugin-polyfill-node": "^0.10.2", + "rollup-plugin-terser": "^7.0.2", + "semver": "^7.3.7", + "which": "^2.0.2", + "yargs-parser": "^21.1.1" }, - "bugs": { - "url": "https://github.com/codfish/cod-scripts/issues" + "devDependencies": { + "jest-in-case": "^1.0.2", + "slash": "^3.0.0" }, - "homepage": "https://github.com/codfish/cod-scripts#readme" + "engines": { + "node": "^14.17.0 || ^16.10.0 || >=17.0.0", + "npm": ">=6" + } } diff --git a/src/__tests__/__snapshots__/index.js.snap b/src/__tests__/__snapshots__/index.js.snap index 5342be99..df6b459a 100644 --- a/src/__tests__/__snapshots__/index.js.snap +++ b/src/__tests__/__snapshots__/index.js.snap @@ -4,27 +4,27 @@ exports[`format calls node with the script path and args including inspect-brk a exports[`format calls node with the script path and args: format script 1`] = `node /src/scripts/test.js --no-watch`; -exports[`format does not log for other signals: format signal 1`] = `Array []`; +exports[`format does not log for other signals: format signal 1`] = `[]`; exports[`format logs for SIGKILL signal: format signal 1`] = ` -Array [ - Array [ +[ + [ The script "lint" failed because the process exited too early. This probably means the system ran out of memory or someone called \`kill -9\` on the process., ], ] `; exports[`format logs for SIGTERM signal: format signal 1`] = ` -Array [ - Array [ +[ + [ The script "build" failed because the process exited too early. Someone might have called \`kill\` or \`killall\`, or the system could be shutting down., ], ] `; exports[`format logs help with no args: format snapshotLog 1`] = ` -Array [ - Array [ +[ + [ Usage: ../ [script] [--flags] diff --git a/src/__tests__/__snapshots__/utils.js.snap b/src/__tests__/__snapshots__/utils.js.snap index 4b27a32e..ce531485 100644 --- a/src/__tests__/__snapshots__/utils.js.snap +++ b/src/__tests__/__snapshots__/utils.js.snap @@ -1,7 +1,7 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`getConcurrentlyArgs gives good args to pass to concurrently 1`] = ` -Array [ +[ --kill-others-on-fail, --prefix, [{name}], diff --git a/src/config/jest.config.js b/src/config/jest.config.js index 73190533..eda37441 100644 --- a/src/config/jest.config.js +++ b/src/config/jest.config.js @@ -22,6 +22,7 @@ const ignores = [ '__mocks__', ] +/** @type {import('@jest/types').Config.InitialOptions} */ const jestConfig = { roots: [hasFile('src') ? '/src' : ''], testEnvironment: ifAnyDep( @@ -29,7 +30,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 69d45fab..98cf7896 100644 --- a/src/config/prettierrc.js +++ b/src/config/prettierrc.js @@ -1,20 +1,22 @@ +/** @type {import('prettier').Options} */ module.exports = { - printWidth: 100, - tabWidth: 2, - useTabs: false, - semi: true, - arrowParens: 'avoid', + arrowParens: 'always', + bracketSameLine: false, bracketSpacing: true, embeddedLanguageFormatting: 'auto', endOfLine: 'lf', htmlWhitespaceSensitivity: 'css', insertPragma: false, jsxSingleQuote: false, + printWidth: 100, + proseWrap: 'always', quoteProps: 'as-needed', requirePragma: false, + semi: true, + singleAttributePerLine: false, singleQuote: true, + tabWidth: 2, trailingComma: 'all', - bracketSameLine: false, - proseWrap: 'always', - vueIndentScriptAndStyle: false, + useTabs: false, + vueIndentScriptAndStyle: true, } diff --git a/src/config/rollup.config.js b/src/config/rollup.config.js index 4c62095c..51275fca 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, @@ -134,13 +133,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/run-script.js b/src/run-script.js index d8767a63..de3561de 100755 --- a/src/run-script.js +++ b/src/run-script.js @@ -1,6 +1,7 @@ const path = require('path') const spawn = require('cross-spawn') const glob = require('glob') +const {toPOSIX} = require('./utils') const [executor, ignoredBin, script] = process.argv @@ -8,7 +9,9 @@ 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( + 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 diff --git a/src/scripts/build/rollup.js b/src/scripts/build/rollup.js index 19b858ed..a90f1e16 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, @@ -77,8 +78,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, ) @@ -102,7 +103,7 @@ function go() { const isCodesplitting = rollupInputs.length > 1 const outputs = isCodesplitting - ? glob.sync(fromRoot(path.join(dirpath, format, '*.js'))) + ? glob.sync(toPOSIX(fromRoot(path.posix.join(dirpath, format, '*.js')))) : [fromRoot(path.join(dirpath, filename))] for (const output of outputs) { @@ -124,8 +125,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 aa3daf26..f99a9ecd 100644 --- a/src/utils.js +++ b/src/utils.js @@ -55,6 +55,7 @@ function resolveCodScripts() { } 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) => arrify(files).some(file => hasFile(file)) ? t : f @@ -195,7 +196,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}`) } @@ -225,6 +226,7 @@ function getRollupOutput(format = process.env.BUILD_FORMAT) { module.exports = { appDirectory, fromRoot, + toPOSIX, getConcurrentlyArgs, hasFile, hasLocalConfig,