Skip to content

πŸ”– 7.0 #860

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 28 commits into from
Jan 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
6cb2101
fix(config/jest): set `ts-jest` transform unconditionally
jrolfs Feb 5, 2022
3fc2d38
build: set `skipLibCheck`... ts-jest and jest aren't playing nicely
jrolfs Feb 5, 2022
11ec6d7
build(deps): upgrade Jest to 27.4
jrolfs Feb 5, 2022
b6514fe
fix(api/test): forward ts-jest utils from `ts-jest`, remove `mocked`
jrolfs Feb 5, 2022
01ce1dd
feat(config/eslint): dissallow default exports in strict configuration
jrolfs Feb 5, 2022
a47f8c1
feat(scripts/test): upgrade Jest to 28.x
jrolfs Jul 3, 2022
aadf707
feat(scripts/ci-after-success): use Semantic Release 19
jrolfs Jul 6, 2022
30bafa4
feat(scripts/test): upgrade Jest to 29.x
jrolfs Sep 7, 2022
5c72dc1
ci(actions): release on Node 16
jrolfs Sep 7, 2022
ed10caf
build: deduplicate lockfile
jrolfs Sep 7, 2022
f3094ed
feat(config/test): use **@swc/jest** as default Jest transform
jrolfs Sep 7, 2022
edde0ac
fix: remove `skipLibCheck` as it's no longer necessary
jrolfs Sep 7, 2022
9a87c5c
build: use latest Node 16
jrolfs Sep 25, 2022
1564ef8
fix(config/jest): add jest-environment-jsdom as a dependency
jrolfs Sep 29, 2022
f0c1e3c
feat(config/jest): `@swc/jest` β†’ `@swc-node/jest` (supports tsconfig)
jrolfs Sep 29, 2022
86e7431
build: use Node 18
jrolfs Dec 9, 2022
7f5d34c
feat(api/commit): add support for excluding directories in `ls.dirs()`
jrolfs Dec 9, 2022
b25f9f5
feat(deps): upgrade `@swc-node/jest` and `@swc/core`
jrolfs Dec 9, 2022
29eb689
fix(scripts/pre-commit): don't fail when no related tests are found
jrolfs Dec 9, 2022
cf62ca6
feat(deps): upgrade commitlint
jrolfs Dec 9, 2022
964bb97
build: move shared TypeScript configuration to project root instead o…
jrolfs Dec 9, 2022
45b340c
feat(deps): update eslint
renovate[bot] Dec 5, 2022
9d495fe
feat(deps): upgrade Prettier to 2.8.1
jrolfs Dec 10, 2022
c9a91eb
build(deps): deduplicate dependencies
jrolfs Dec 10, 2022
e580724
build(deps-dev): add latest `@types/node`
jrolfs Dec 10, 2022
20458b6
fix(test): add `@swc/helpers`
jrolfs Jan 10, 2023
8b1f5ac
refactor(deps): remove direct dependency on arrify
jrolfs Jan 18, 2023
f6a8c15
feat(deps): upgrade all dependencies to latest
jrolfs Jan 18, 2023
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
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
if: ${{ needs.deduplicate.outputs.should_skip != 'true' }}
strategy:
matrix:
node: ['12', '14', '16']
node: ['14', '16', '18']

steps:
- name: Get Yarn cache path
Expand Down Expand Up @@ -59,7 +59,7 @@ jobs:

- name: Upload Coverage / Release
run: yarn ci-after-success
if: ${{ matrix.node == '14' }}
if: ${{ matrix.node == '16' }}
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
2 changes: 1 addition & 1 deletion .node-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
16.13.0
18.12.1
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ This project is actively maintained by engineers at
[license-badge]: https://img.shields.io/npm/l/@hover/javascript.svg
[license-link]: https://github.com/hoverinc/hover-javascript/blob/master/LICENSE
[node-link]: https://nodejs.org/en/download/
[node-badge]: https://img.shields.io/badge/node-v16.13.0-green
[node-badge]: https://img.shields.io/badge/node-v18.12.1-green
[prettier-badge]:
https://img.shields.io/badge/code_style-prettier-ff69b4.svg?logo=prettier
[prettier-link]: https://prettierjs.org/en/download/
Expand Down
10 changes: 0 additions & 10 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,4 @@ module.exports = {
roots: ['<rootDir>/src'],
coverageThreshold: null,
transformIgnorePatterns: [...transformIgnorePatterns, '.prettierrc.js'],
globals: {
'ts-jest': {
...globals['ts-jest'],
tsconfig: './src/tsconfig.json',
diagnostics: {
warnOnly: true,
exclude: ['**/*'],
},
},
},
}
84 changes: 47 additions & 37 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"start": "run-p start:*",
"start:source": "yarn build:source --watch",
"start:types": "tsc -b -w --preserveWatchOutput src/",
"test": "node src test",
"test": "SWC_NODE_PROJECT=src/tsconfig.json node src test",
"test:update": "node src test --updateSnapshot",
"validate": "node src validate",
"prepare": "husky install"
Expand All @@ -50,51 +50,53 @@
"author": "Jamie Rolfs <jamie.rolfs@hover.to>",
"license": "MIT",
"dependencies": {
"@commitlint/cli": "^16.1.0",
"@commitlint/config-conventional": "^16.2.1",
"@commitlint/prompt": "^16.1.0",
"@types/jest": "^27.0.2",
"@commitlint/cli": "^17.4.2",
"@commitlint/config-conventional": "^17.4.2",
"@commitlint/prompt": "^17.4.2",
"@swc-node/jest": "^1.5.6",
"@swc/core": "^1.3.27",
"@swc/helpers": "^0.4.14",
"@types/jest": "^29.2.5",
"@types/lodash.has": "^4.5.7",
"@types/mkdirp": "^1.0.2",
"@types/node": ">=17.x",
"@types/node": "^18.11.18",
"@types/rimraf": "^3.0.2",
"@types/which": "^2.0.1",
"@typescript-eslint/eslint-plugin": "^5.45.1",
"@typescript-eslint/parser": "^5.45.1",
"arrify": "^2.0.1",
"@typescript-eslint/eslint-plugin": "^5.48.2",
"@typescript-eslint/parser": "^5.48.2",
"commitizen": "^4.2.6",
"concurrently": "^7.0.0",
"cosmiconfig": "^7.0.1",
"concurrently": "^7.6.0",
"cosmiconfig": "^8.0.0",
"cross-env": "^7.0.3",
"cross-spawn": "^7.0.3",
"cross-spawn": "^7.0.1",
"depcheck": "^1.4.3",
"doctoc": "^2.1.0",
"eslint": "^8.29.0",
"doctoc": "^2.2.1",
"eslint": "^8.32.0",
"eslint-config-airbnb": "19.0.4",
"eslint-config-airbnb-typescript": "^17.0.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-jest": "^26.9.0",
"eslint-plugin-jsx-a11y": "^6.6.1",
"eslint-config-prettier": "^8.6.0",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-jest": "^27.2.1",
"eslint-plugin-jsx-a11y": "^6.7.1",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-react": "^7.31.11",
"eslint-plugin-react": "^7.32.1",
"eslint-plugin-react-hooks": "^4.6.0",
"glob": "^8.0.3",
"glob": "^8.1.0",
"is-ci": "^3.0.1",
"jest": "^27.5.1",
"jest": "^29.3.1",
"jest-environment-jsdom": "^29.3.1",
"jest-github-actions-reporter": "^1.0.3",
"jest-watch-typeahead": "^1.0.0",
"lint-staged": "^12.3.4",
"jest-watch-typeahead": "^2.2.1",
"lint-staged": "^13.1.0",
"lodash.has": "^4.5.2",
"mkdirp": "^1.0.4",
"prettier": "^2.5.1",
"mkdirp": "^2.1.3",
"prettier": "^2.8.3",
"read-pkg-up": "^7.0.1",
"rimraf": "^3.0.2",
"ts-jest": "^27.1.3",
"tslib": "^2.4.0",
"rimraf": "^4.1.1",
"tslib": "^2.4.1",
"typescript": "^4",
"which": "^2.0.2",
"yargs-parser": "^21.0.1"
"which": "^3.0.0",
"yargs-parser": "^21.1.1"
},
"eslintConfig": {
"parserOptions": {
Expand All @@ -110,7 +112,8 @@
"import/no-unassigned-import": "off",
"no-console": "off",
"no-nested-ternary": "off",
"no-useless-catch": "off"
"no-useless-catch": "off",
"jest/prefer-snapshot-hint": "off"
}
},
"eslintIgnore": [
Expand All @@ -127,15 +130,22 @@
},
"homepage": "https://github.com/hoverinc/hover-javascript#readme",
"devDependencies": {
"@babel/cli": "^7.17.10",
"@babel/core": "^7.17.2",
"@babel/preset-env": "^7.16.11",
"@babel/cli": "^7.20.7",
"@babel/core": "^7.20.12",
"@babel/preset-env": "^7.20.2",
"@types/cross-spawn": "^6.0.2",
"babel-jest": "^28.1.0",
"eslint-config-kentcdodds": "^20.0.1",
"husky": "^7.0.4",
"eslint-config-kentcdodds": "^20.4.0",
"husky": "^8.0.3",
"jest-in-case": "^1.0.2",
"npm-run-all": "^4.1.5",
"slash": "^3.0.0"
},
"peerDependencies": {
"ts-jest": "^29.0.0"
},
"peerDependenciesMeta": {
"ts-jest": {
"optional": true
}
}
}
1 change: 1 addition & 0 deletions src/api/__tests__/__fixtures__/ls/dirs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
!node_modules
Empty file.
20 changes: 19 additions & 1 deletion src/api/__tests__/commit.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,29 @@ describe('ls', () => {
})

test('with prefix', () => {
const result = ls.dirs(`${fixtures}/ls/dirs`, 'prefix')
const result = ls.dirs(`${fixtures}/ls/dirs`, {prefix: 'prefix'})

const expected = ['prefix/.baz', 'prefix/bar', 'prefix/foo']

expect(result.sort()).toEqual(expected.sort())
})

test('with custom exclude (string)', () => {
const result = ls.dirs(`${fixtures}/ls/dirs`, {exclude: 'foo'})

const expected = ['.baz', 'bar', 'node_modules']

expect(result.sort()).toEqual(expected.sort())
})

test('with custom exclude (RegExp)', () => {
const result = ls.dirs(`${fixtures}/ls/dirs`, {
exclude: /(^node_modules|^bar)/,
})

const expected = ['.baz', 'foo']

expect(result.sort()).toEqual(expected.sort())
})
})
})
11 changes: 0 additions & 11 deletions src/api/__tests__/test.js

This file was deleted.

30 changes: 26 additions & 4 deletions src/api/commit.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,39 @@ const configs = path =>
)}`,
)

/**
* @typedef DirsOptions
* @property {string} [prefix] prefix to prepend to each scope entry (e.g:
* `{ prefix: 'prefix' }` becomes `type(prefix/scope)`)
* @property {RegExp | string | null} [exclude] expression for excluding
* directories, defaults to `^node_modules`
*/

/**
* Enumerate one level of directories
*
* @param {string} path - directory to enumerate
* @param {string} [prefix] - prefix for each scope entry (e.g: `prefix/entry`)
* @param {DirsOptions} options -
*/
const dirs = (path, prefix) =>
readdirSync(path)
.filter(f => statSync(join(path, f)).isDirectory())
const dirs = (path, options) => {
const {exclude, prefix} = {exclude: /^node_modules/, ...options}

/**
* @param {string} f filename
*/
const test = f => {
if (!exclude) return true

return !(typeof exclude === 'string'
? f.includes(exclude)
: exclude.test(f))
}

return readdirSync(path)
.filter(f => statSync(join(path, f)).isDirectory() && test(f))
.map(item => (prefix ? `${prefix}/${item}` : item))
.map(item => item.toLowerCase())
}

const ls = {configs, dirs}

Expand Down
2 changes: 1 addition & 1 deletion src/api/depcheck/depcheck.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const fs = require('fs')
const depcheck = require('depcheck')
const hoverSpecials = require('./specials')
const {hasFile, uniq} = require('../../utils')
const hoverSpecials = require('./specials')

/**
* @typedef Config
Expand Down
1 change: 0 additions & 1 deletion src/api/test.js

This file was deleted.

3 changes: 3 additions & 0 deletions src/config/__tests__/__snapshots__/eslintrc.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ Object {
},
],
"import/prefer-default-export": "off",
"jest/prefer-snapshot-hint": "off",
"no-implied-eval": "error",
"no-throw-literal": "error",
"no-void": Array [
Expand Down Expand Up @@ -251,6 +252,7 @@ Object {
},
],
"import/prefer-default-export": "off",
"jest/prefer-snapshot-hint": "off",
"no-implied-eval": "error",
"no-throw-literal": "error",
"no-void": Array [
Expand Down Expand Up @@ -287,6 +289,7 @@ Object {
exports[`Strict ESLint configuration 1`] = `
Object {
"rules": Object {
"import/no-default-export": "error",
"import/order": Array [
"error",
Object {
Expand Down
1 change: 1 addition & 0 deletions src/config/eslintrc-strict.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module.exports = {
rules: {
'import/no-default-export': 'error',
'import/order': [
'error',
{
Expand Down
2 changes: 2 additions & 0 deletions src/config/helpers/build-eslint.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ const buildConfig = ({withReact = false} = {}) => {
],
'no-void': ['error', {allowAsStatement: true}],
'prettier/prettier': 'error',
// TODO: consider enabling this as a warning?
'jest/prefer-snapshot-hint': 'off',
...parserRules(false, isReact),
},
overrides: [
Expand Down
2 changes: 1 addition & 1 deletion src/config/helpers/build-lint-staged.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const {resolveHoverScripts, resolveBin} = require('../../utils')
const hoverScripts = resolveHoverScripts()
const doctoc = resolveBin('doctoc')

const defaultTestCommand = `${hoverScripts} test --findRelatedTests`
const defaultTestCommand = `${hoverScripts} test --findRelatedTests --passWithNoTests`

const sourceExtensions = ['js', 'jsx', 'ts', 'tsx']

Expand Down
49 changes: 23 additions & 26 deletions src/config/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
/** @typedef {import('@jest/types').Config.InitialOptions} JestConfig */

const {jsWithTs: preset} = require('ts-jest/presets')

const {ifAnyDep, hasAnyDep, hasFile, fromRoot} = require('../utils')
const {ifAnyDep, hasFile, fromRoot, hasDevDep} = require('../utils')

const {
testMatch,
Expand All @@ -22,13 +20,31 @@ const ignores = [
/** @type JestConfig */
const jestConfig = {
roots: [fromRoot('.')],
// Here we're preserving Jest <= 28 snapshot format to prevent the need
// to update snapshots when upgrading Jest via @hover/javascript, see:
// https://jestjs.io/docs/upgrading-to-jest29#snapshot-format
snapshotFormat: {escapeString: true, printBasicPrototype: true},
testEnvironment: ifAnyDep(['webpack', 'rollup', 'react'], 'jsdom', 'node'),
testURL: 'http://localhost',
testEnvironmentOptions: {url: 'http://localhost'},
moduleFileExtensions: testMatchExtensions.concat('json'),
collectCoverageFrom: [`**/${testMatchGlob}`],
testMatch,
testPathIgnorePatterns: [...ignores, '<rootDir>/dist'],
testLocationInResults: true,
// The default transform is now SWC, however, `ts-jest` will
// still be used if it is installed in the host project
transform: hasDevDep('ts-jest')
? Object.fromEntries(
// Ensure we can resolve the preset even when
// it's in a nested `node_modules` installation
Object.entries(require('ts-jest/presets').transform).map(
([glob, transformer]) => [
glob,
[require.resolve(transformer), {diagnostics: {warnOnly: true}}],
],
),
)
: {'^.+\\.(t|j)sx?$': ['@swc-node/jest']},
coveragePathIgnorePatterns: [
...ignores,
'src/(umd|cjs|esm)-entry.js$',
Expand All @@ -51,28 +67,9 @@ const jestConfig = {
require.resolve('jest-watch-typeahead/filename'),
require.resolve('jest-watch-typeahead/testname'),
],
globals: {},
}

if (hasAnyDep('ts-jest') || hasFile('tsconfig.json')) {
jestConfig.transform = Object.fromEntries(
// Ensure we can resolve the preset even when
// it's in a nested `node_modules` installation
Object.entries(preset.transform).map(([key, value]) => [
key,
require.resolve(value),
]),
)

jestConfig.globals['ts-jest'] = {
diagnostics: {
warnOnly: true,
},
}
}

if (hasFile('tests/setup-env.js')) {
jestConfig.setupFilesAfterEnv = [fromRoot('tests/setup-env.js')]
setupFilesAfterEnv: hasFile('tests/setup-env.js')
? [fromRoot('tests/setup-env.js')]
: undefined,
}

module.exports = jestConfig
Loading