Skip to content
Merged

Deps #184

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
ad47578
feat: update deps
kentcdodds Mar 1, 2021
b10bbda
fix(lint): update eslint-config-kentcdodds
kentcdodds Mar 1, 2021
5d34c54
fix(husky): husky 5 is alpha
kentcdodds Mar 1, 2021
3b4b884
feat: improve workspaces support (#193)
weyert Mar 8, 2021
9539ba2
fix: remove dash from environment variables (#195)
AriPerkkio Mar 16, 2021
5c69945
docs: add AriPerkkio as a contributor (#196)
allcontributors[bot] Mar 16, 2021
3f315a7
feat: copy .d.ts files
kentcdodds Apr 8, 2021
d1b2c74
chore: drop node 10 in workflow
kentcdodds Apr 8, 2021
fc3a43f
chore: make test work on windows
kentcdodds Apr 8, 2021
e507091
fix(build): wait for build to finish before exiting
kentcdodds Apr 8, 2021
b4bbe72
feat: add .gql files in lintstagedrc (#198)
MichaelDeBoey Apr 9, 2021
6dda70c
feat: add all file extensions from lintstagedrc as default for format…
MichaelDeBoey Apr 9, 2021
1ca348c
feat: update dependencies (#201)
MichaelDeBoey Apr 12, 2021
59ef5c4
feat: add tests for Node 16 (#202)
MichaelDeBoey Apr 21, 2021
fc14169
feat: bump deps
codfish Apr 24, 2021
904d76e
ci: update branch patterns for release workflow
codfish Apr 24, 2021
f205e80
ci: use semantic-release to speed up releases
codfish Apr 24, 2021
c4298f4
feat: update node engine requirement to >=12.0.0
codfish Apr 24, 2021
66b8ad0
Merge branch 'main' of https://github.com/kentcdodds/kcd-scripts into…
codfish Apr 25, 2021
92a123b
feat: bump deps
codfish Apr 24, 2021
064acfa
feat: update node engine requirement to >=12.0.0
codfish Apr 24, 2021
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
8 changes: 7 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ on:
push:
branches:
- master
- main
- alpha
- beta
- next
- 'next-major'
- '+([0-9])?(.{+([0-9]),x}).x'

jobs:
release:
Expand All @@ -27,7 +33,7 @@ jobs:
CI: true

- name: semantic release
uses: codfish/semantic-release-action@v1
uses: docker://ghcr.io/codfish/semantic-release-action:v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
48 changes: 25 additions & 23 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.0.0-semantically-released",
"description": "CLI for common scripts for my projects",
"engines": {
"node": ">=10.18",
"node": ">=12",
"npm": ">=6",
"yarn": ">=1"
},
Expand Down Expand Up @@ -35,46 +35,47 @@
"author": "Chris O'Donnell <[email protected]> (http://codfish.io/)",
"license": "MIT",
"dependencies": {
"@babel/cli": "^7.13.0",
"@babel/core": "^7.13.1",
"@babel/cli": "^7.13.16",
"@babel/core": "^7.13.16",
"@babel/plugin-proposal-class-properties": "^7.13.0",
"@babel/plugin-transform-modules-commonjs": "^7.13.0",
"@babel/plugin-transform-runtime": "^7.13.7",
"@babel/preset-env": "^7.13.5",
"@babel/preset-react": "^7.12.13",
"@babel/plugin-transform-runtime": "^7.13.15",
"@babel/preset-env": "^7.13.15",
"@babel/preset-react": "^7.13.13",
"@babel/preset-typescript": "^7.13.0",
"@babel/runtime": "^7.13.7",
"@commitlint/cli": "^12.0.0",
"@commitlint/config-conventional": "^12.0.0",
"@babel/runtime": "^7.13.17",
"@commitlint/cli": "^12.1.1",
"@commitlint/config-conventional": "^12.1.1",
"@rollup/plugin-babel": "^5.3.0",
"@rollup/plugin-commonjs": "^17.1.0",
"@rollup/plugin-commonjs": "^18.0.0",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^11.2.0",
"@rollup/plugin-replace": "^2.4.1",
"@types/jest": "^26.0.20",
"@rollup/plugin-node-resolve": "^11.2.1",
"@rollup/plugin-replace": "^2.4.2",
"@types/jest": "^26.0.22",
"arrify": "^2.0.1",
"babel-jest": "^26.6.3",
"babel-plugin-macros": "^3.0.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.16.3",
"browserslist": "^4.16.5",
"builtin-modules": "^3.2.0",
"chalk": "^4.1.0",
"concurrently": "^6.0.0",
"chalk": "^4.1.1",
"concurrently": "^6.0.2",
"cosmiconfig": "^7.0.0",
"cpy": "^8.1.2",
"cross-env": "^7.0.3",
"cross-spawn": "^7.0.3",
"doctoc": "^2.0.0",
"eslint": "^7.20.0",
"eslint-config-codfish": "^9.0.0",
"eslint": "^7.25.0",
"eslint-config-codfish": "^10.0.0",
"glob": "^7.1.5",
"husky": "^5.1.1",
"husky": "^6.0.0",
"is-ci": "^3.0.0",
"jest": "^26.6.1",
"jest-serializer-path": "^0.1.15",
"jest-watch-typeahead": "^0.6.1",
"jest-watch-typeahead": "^0.6.3",
"lint-staged": "^10.5.4",
"lodash.camelcase": "^4.3.0",
"lodash.has": "^4.5.2",
Expand All @@ -85,14 +86,14 @@
"read-pkg-up": "^7.0.1",
"resolve": "^1.20.0",
"rimraf": "^3.0.2",
"rollup": "^2.39.1",
"rollup": "^2.45.2",
"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.4",
"semver": "^7.3.5",
"which": "^2.0.2",
"yargs-parser": "^20.2.6"
"yargs-parser": "^20.2.7"
},
"eslintConfig": {
"extends": [
Expand All @@ -114,6 +115,7 @@
"no-use-before-define": "off",
"no-restricted-syntax": "off",
"no-param-reassign": "off",
"one-var": "off",
"max-len": [
"error",
80,
Expand Down
17 changes: 13 additions & 4 deletions src/__tests__/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@ jest.mock('cosmiconfig', () => {
return {...cosmiconfigExports, cosmiconfigSync: jest.fn()}
})

let whichSyncMock
let readPkgUpSyncMock
jest.mock('cpy')

let whichSyncMock, readPkgUpSyncMock, cpy, nodePath

beforeEach(() => {
jest.resetModules()
nodePath = require('path')
whichSyncMock = require('which').sync
readPkgUpSyncMock = require('read-pkg-up').sync
cpy = require('cpy')
})

test('package is the package.json', () => {
Expand Down Expand Up @@ -162,15 +165,21 @@ test('hasLocalConfiguration returns true if a local config found and it is empty
expect(require('../utils').hasLocalConfig('module')).toBe(true)
})

test('should generate typescript definitions into provided folder', () => {
test('should generate typescript definitions into provided folder', async () => {
whichSyncMock.mockImplementationOnce(() => require.resolve('../'))
const {sync: crossSpawnSyncMock} = require('cross-spawn')
require('../utils').generateTypeDefs('destination folder')
await require('../utils').generateTypeDefs('destination folder')
expect(crossSpawnSyncMock).toHaveBeenCalledTimes(1)
const args = crossSpawnSyncMock.mock.calls[0][1]
const outDirIndex = args.findIndex(arg => arg === '--outDir') + 1

expect(args[outDirIndex]).toBe('destination folder')

expect(cpy).toHaveBeenCalledTimes(1)
expect(cpy).toHaveBeenCalledWith('**/*.d.ts', '../dist', {
cwd: `${nodePath.sep}blah${nodePath.sep}src`,
parents: true,
})
})

function mockPkg({package: pkg = {}, path = '/blah/package.json'}) {
Expand Down
2 changes: 1 addition & 1 deletion src/config/lintstagedrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const doctoc = resolveBin('doctoc')
// than js first, then format + lint js using eslint with prettier plugin
module.exports = {
'README.md': [`${doctoc} --maxlevel 3 --notitle`],
'*.+(json|yml|yaml|css|less|scss|ts|tsx|md|graphql|mdx|vue)': [
'*.+(json|yml|yaml|css|less|scss|ts|tsx|md|gql|graphql|mdx|vue)': [
`${codScripts} format --no-eslint`,
].filter(Boolean),
'*.js': [
Expand Down
5 changes: 1 addition & 4 deletions src/config/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ 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 {sizeSnapshot} = require('rollup-plugin-size-snapshot')
const omit = require('lodash.omit')
const {
pkg,
Expand All @@ -35,7 +34,6 @@ const format = process.env.BUILD_FORMAT
const isPreact = parseEnv('BUILD_PREACT', false)
const isNode = parseEnv('BUILD_NODE', false)
const name = process.env.BUILD_NAME || capitalize(camelcase(pkg.name))
const useSizeSnapshot = parseEnv('BUILD_SIZE_SNAPSHOT', false)

const esm = format === 'esm'
const umd = format === 'umd'
Expand Down Expand Up @@ -148,7 +146,7 @@ module.exports = {
mainFields: ['module', 'main', 'jsnext', 'browser'],
extensions,
}),
commonjs({include: 'node_modules/**'}),
commonjs({include: /node_modules/i}),
json(),
rollupBabel({
presets: babelPresets,
Expand All @@ -157,7 +155,6 @@ module.exports = {
extensions,
}),
replace(replacements),
useSizeSnapshot ? sizeSnapshot({printInfo: false}) : null,
minify ? terser() : null,
codeSplitting &&
((writes = 0) => ({
Expand Down
12 changes: 9 additions & 3 deletions src/run-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,15 @@ function getEnv() {
// https://github.com/kentcdodds/kcd-scripts/issues/4
return Object.keys(process.env)
.filter(key => process.env[key] !== undefined)
.reduce((envCopy, key) => ({...envCopy, [key]: process.env[key]}), {
[`SCRIPTS_${script.toUpperCase()}`]: true,
})
.reduce(
(envCopy, key) => {
envCopy[key] = process.env[key]
return envCopy
},
{
[`SCRIPTS_${script.toUpperCase().replace(/-/g, '_')}`]: true,
},
)
}

function handleSignal(result) {
Expand Down
12 changes: 6 additions & 6 deletions src/scripts/__tests__/__snapshots__/format.js.snap
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`format --config arg can be used for a custom config 1`] = `prettier --ignore-path ./src/config/prettierignore --write **/*.+(md|json|yml|yaml|css|less|scss|sass|graphql|ts|tsx) --config ./my-config.js`;
exports[`format --config arg can be used for a custom config 1`] = `prettier --ignore-path ./src/config/prettierignore --write **/*.+(json|yml|yaml|css|less|scss|ts|tsx|md|gql|graphql|mdx|vue) --config ./my-config.js`;

exports[`format --config arg can be used for a custom config 2`] = `prettier --ignore-path ./src/config/prettierignore --write **/*.+(md|json|yml|yaml|css|less|scss|sass|graphql|ts|tsx) --config ./my-config.js`;
exports[`format --config arg can be used for a custom config 2`] = `prettier --ignore-path ./src/config/prettierignore --write **/*.+(json|yml|yaml|css|less|scss|ts|tsx|md|gql|graphql|mdx|vue) --config ./my-config.js`;

exports[`format --ignore-path arg can be used for a custom ignore file 1`] = `prettier --write **/*.+(md|json|yml|yaml|css|less|scss|sass|graphql|ts|tsx) --ignore-path ./.myignore`;
exports[`format --ignore-path arg can be used for a custom ignore file 1`] = `prettier --write **/*.+(json|yml|yaml|css|less|scss|ts|tsx|md|gql|graphql|mdx|vue) --ignore-path ./.myignore`;

exports[`format --ignore-path arg can be used for a custom ignore file 2`] = `prettier --write **/*.+(md|json|yml|yaml|css|less|scss|sass|graphql|ts|tsx) --ignore-path ./.myignore`;
exports[`format --ignore-path arg can be used for a custom ignore file 2`] = `prettier --write **/*.+(json|yml|yaml|css|less|scss|ts|tsx|md|gql|graphql|mdx|vue) --ignore-path ./.myignore`;

exports[`format --no-write prevents --write argument from being added 1`] = `prettier --ignore-path ./src/config/prettierignore **/*.+(md|json|yml|yaml|css|less|scss|sass|graphql|ts|tsx) --no-write`;
exports[`format --no-write prevents --write argument from being added 1`] = `prettier --ignore-path ./src/config/prettierignore **/*.+(json|yml|yaml|css|less|scss|ts|tsx|md|gql|graphql|mdx|vue) --no-write`;

exports[`format --no-write prevents --write argument from being added 2`] = `prettier --ignore-path ./src/config/prettierignore **/*.+(md|json|yml|yaml|css|less|scss|sass|graphql|ts|tsx) --no-write`;
exports[`format --no-write prevents --write argument from being added 2`] = `prettier --ignore-path ./src/config/prettierignore **/*.+(json|yml|yaml|css|less|scss|ts|tsx|md|gql|graphql|mdx|vue) --no-write`;

exports[`format calls prettier CLI with args 1`] = `prettier --ignore-path ./src/config/prettierignore --write my-src/**/*.js`;

Expand Down
2 changes: 1 addition & 1 deletion src/scripts/__tests__/__snapshots__/test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ exports[`test does not watch --updateSnapshot 1`] = `--config {"builtInConfig":t

exports[`test does not watch on CI 1`] = `--config {"builtInConfig":true}`;

exports[`test does not watch on SCRIPTS_PRE-COMMIT 1`] = `--config {"builtInConfig":true}`;
exports[`test does not watch on SCRIPTS_PRE_COMMIT 1`] = `--config {"builtInConfig":true}`;

exports[`test does not watch with --coverage 1`] = `--config {"builtInConfig":true} --coverage`;

Expand Down
8 changes: 4 additions & 4 deletions src/scripts/__tests__/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ cases(
const {run: jestRunMock} = require('jest')
const originalArgv = process.argv
const prevCI = mockIsCI
const prevPreCommit = process.env['SCRIPTS_PRE-COMMIT']
const prevPreCommit = process.env.SCRIPTS_PRE_COMMIT
mockIsCI = ci
process.env['SCRIPTS_PRE-COMMIT'] = preCommit
process.env.SCRIPTS_PRE_COMMIT = preCommit
Object.assign(utils, {
hasPkgProp: () => pkgHasJestProp,
hasFile: () => hasJestConfigFile,
Expand All @@ -50,7 +50,7 @@ cases(
// afterEach
process.argv = originalArgv
mockIsCI = prevCI
process.env['SCRIPTS_PRE-COMMIT'] = prevPreCommit
process.env.SCRIPTS_PRE_COMMIT = prevPreCommit
jest.resetModules()
}
},
Expand All @@ -59,7 +59,7 @@ cases(
'does not watch on CI': {
ci: true,
},
'does not watch on SCRIPTS_PRE-COMMIT': {
'does not watch on SCRIPTS_PRE_COMMIT': {
preCommit: 'true',
},
'does not watch with --no-watch': {
Expand Down
8 changes: 4 additions & 4 deletions src/scripts/__tests__/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ cases(
const {sync: crossSpawnSyncMock} = require('cross-spawn')
const originalExit = process.exit
process.exit = jest.fn()
process.env['SCRIPTS_PRE-COMMIT'] = 'false'
process.env.SCRIPTS_PRE_COMMIT = 'false'
const teardown = setup()

try {
Expand Down Expand Up @@ -90,10 +90,10 @@ cases(
},
[`doesn't use test or lint if it's in pre-commit`]: {
setup: withDefaultSetup(() => {
const previousVal = process.env['SCRIPTS_PRE-COMMIT']
process.env['SCRIPTS_PRE-COMMIT'] = 'true'
const previousVal = process.env.SCRIPTS_PRE_COMMIT
process.env.SCRIPTS_PRE_COMMIT = 'true'
return function teardown() {
process.env['SCRIPTS_PRE-COMMIT'] = previousVal
process.env.SCRIPTS_PRE_COMMIT = previousVal
}
}),
},
Expand Down
14 changes: 9 additions & 5 deletions src/scripts/build/babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ if (noTypeDefinitions) {
args = args.filter(a => a !== '--no-ts-defs')
}

function go() {
async function go() {
let result = spawn.sync(
resolveBin('@babel/cli', {executable: 'babel'}),
[
Expand All @@ -73,18 +73,22 @@ function go() {

if (hasTypescript && !noTypeDefinitions) {
console.log('Generating TypeScript definitions')
result = generateTypeDefs(pathToOutDir)
console.log('TypeScript definitions generated')
result = await generateTypeDefs(pathToOutDir)
if (result.status !== 0) return result.status
console.log('TypeScript definitions generated')
}

// because babel will copy even ignored files, we need to remove the ignored files
const ignoredPatterns = (parsedArgs.ignore || builtInIgnore)
.split(',')
.map(pattern => path.join(pathToOutDir, pattern))

// type def files are compiled to an empty file and they're useless
// so we'll get rid of those too.
const typeDefCompiledFiles = path.join(pathToOutDir, '**/*.d.js')
const ignoredFiles = ignoredPatterns.reduce(
(all, pattern) => [...all, ...glob.sync(pattern)],
[],
[typeDefCompiledFiles],
)
ignoredFiles.forEach(ignoredFile => {
rimraf.sync(ignoredFile)
Expand All @@ -93,4 +97,4 @@ function go() {
return result.status
}

process.exit(go())
go().then(process.exit)
2 changes: 1 addition & 1 deletion src/scripts/format.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const write = args.includes('--no-write') ? [] : ['--write']
const relativeArgs = args.map(a => a.replace(`${process.cwd()}/`, ''))
const filesToApply = parsedArgs._.length
? []
: ['**/*.+(md|json|yml|yaml|css|less|scss|sass|graphql|ts|tsx)']
: ['**/*.+(json|yml|yaml|css|less|scss|ts|tsx|md|gql|graphql|mdx|vue)']

// run prettier on all non-js files
const prettierResult = spawn.sync(
Expand Down
2 changes: 1 addition & 1 deletion src/scripts/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const args = process.argv.slice(2)

const watch =
!isCI &&
!parseEnv('SCRIPTS_PRE-COMMIT', false) &&
!parseEnv('SCRIPTS_PRE_COMMIT', false) &&
!args.includes('--no-watch') &&
!args.includes('--coverage') &&
!args.includes('--updateSnapshot')
Expand Down
2 changes: 1 addition & 1 deletion src/scripts/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const {
// pre-commit runs linting and tests on the relevant files
// so those scripts don't need to be run if we're running
// this in the context of a pre-commit hook.
const preCommit = parseEnv('SCRIPTS_PRE-COMMIT', false)
const preCommit = parseEnv('SCRIPTS_PRE_COMMIT', false)

const validateScripts = process.argv[2]

Expand Down
Loading