Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ module.exports = Object.assign({}, prettierConfig, {
printWidth: 80,
semi: false,
bracketSpacing: false,
arrowParens: 'avoid',
})
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
192 changes: 91 additions & 101 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]> (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",
Expand All @@ -29,76 +27,14 @@
"prettier.js",
"shared-tsconfig.json"
],
"keywords": [],
"author": "Chris O'Donnell <[email protected]> (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": [
Expand Down Expand Up @@ -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"
}
}
14 changes: 7 additions & 7 deletions src/__tests__/__snapshots__/index.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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 <PROJECT_ROOT>/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]

Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/__snapshots__/utils.js.snap
Original file line number Diff line number Diff line change
@@ -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}],
Expand Down
5 changes: 4 additions & 1 deletion src/config/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,17 @@ const ignores = [
'__mocks__',
]

/** @type {import('@jest/types').Config.InitialOptions} */
const jestConfig = {
roots: [hasFile('src') ? '<rootDir>/src' : '<rootDir>'],
testEnvironment: ifAnyDep(
['webpack', 'rollup', 'react', 'preact'],
'jsdom',
'node',
),
testURL: 'http://localhost',
testEnvironmentOptions: {
url: 'http://localhost',
},
moduleFileExtensions: ['js', 'jsx', 'json', 'ts', 'tsx'],
modulePaths: ['<rootDir>/src', 'shared', '<rootDir>/tests'],
collectCoverageFrom: ['src/**/*.+(js|jsx|ts|tsx)'],
Expand Down
18 changes: 10 additions & 8 deletions src/config/prettierrc.js
Original file line number Diff line number Diff line change
@@ -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,
}
9 changes: 4 additions & 5 deletions src/config/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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'],
Expand Down
5 changes: 4 additions & 1 deletion src/run-script.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
const path = require('path')
const spawn = require('cross-spawn')
const glob = require('glob')
const {toPOSIX} = require('./utils')

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.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
Expand Down
Loading