Skip to content

Commit ad6df53

Browse files
authored
Merge pull request #782 from hoverinc/beta
🔖 Beta
2 parents 5e94f75 + 17ce718 commit ad6df53

25 files changed

+3434
-3261
lines changed

.github/workflows/build.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
if: ${{ needs.deduplicate.outputs.should_skip != 'true' }}
3030
strategy:
3131
matrix:
32-
node: ['12', '14', '16']
32+
node: ['14', '16', '18']
3333

3434
steps:
3535
- name: Get Yarn cache path
@@ -59,7 +59,7 @@ jobs:
5959

6060
- name: Upload Coverage / Release
6161
run: yarn ci-after-success
62-
if: ${{ matrix.node == '14' }}
62+
if: ${{ matrix.node == '16' }}
6363
env:
6464
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
6565
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.node-version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
16.13.0
1+
18.12.1

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ This project is actively maintained by engineers at
294294
[license-badge]: https://img.shields.io/npm/l/@hover/javascript.svg
295295
[license-link]: https://github.com/hoverinc/hover-javascript/blob/master/LICENSE
296296
[node-link]: https://nodejs.org/en/download/
297-
[node-badge]: https://img.shields.io/badge/node-v16.13.0-green
297+
[node-badge]: https://img.shields.io/badge/node-v18.12.1-green
298298
[prettier-badge]:
299299
https://img.shields.io/badge/code_style-prettier-ff69b4.svg?logo=prettier
300300
[prettier-link]: https://prettierjs.org/en/download/

jest.config.js

-10
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,4 @@ module.exports = {
1010
roots: ['<rootDir>/src'],
1111
coverageThreshold: null,
1212
transformIgnorePatterns: [...transformIgnorePatterns, '.prettierrc.js'],
13-
globals: {
14-
'ts-jest': {
15-
...globals['ts-jest'],
16-
tsconfig: './src/tsconfig.json',
17-
diagnostics: {
18-
warnOnly: true,
19-
exclude: ['**/*'],
20-
},
21-
},
22-
},
2313
}

package.json

+47-37
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"start": "run-p start:*",
2727
"start:source": "yarn build:source --watch",
2828
"start:types": "tsc -b -w --preserveWatchOutput src/",
29-
"test": "node src test",
29+
"test": "SWC_NODE_PROJECT=src/tsconfig.json node src test",
3030
"test:update": "node src test --updateSnapshot",
3131
"validate": "node src validate",
3232
"prepare": "husky install"
@@ -50,51 +50,52 @@
5050
"author": "Jamie Rolfs <[email protected]>",
5151
"license": "MIT",
5252
"dependencies": {
53-
"@commitlint/cli": "^16.1.0",
54-
"@commitlint/config-conventional": "^16.2.1",
55-
"@commitlint/prompt": "^16.1.0",
56-
"@types/jest": "^27.0.2",
53+
"@commitlint/cli": "^17.4.2",
54+
"@commitlint/config-conventional": "^17.4.2",
55+
"@commitlint/prompt": "^17.4.2",
56+
"@swc-node/jest": "^1.5.6",
57+
"@swc/core": "^1.3.27",
58+
"@swc/helpers": "^0.4.14",
59+
"@types/jest": "^29.2.5",
5760
"@types/lodash.has": "^4.5.7",
5861
"@types/mkdirp": "^1.0.2",
59-
"@types/node": ">=17.x",
62+
"@types/node": "^18.11.18",
6063
"@types/rimraf": "^3.0.2",
6164
"@types/which": "^2.0.1",
62-
"@typescript-eslint/eslint-plugin": "^5.45.1",
63-
"@typescript-eslint/parser": "^5.45.1",
64-
"arrify": "^2.0.1",
65+
"@typescript-eslint/eslint-plugin": "^5.48.2",
66+
"@typescript-eslint/parser": "^5.48.2",
6567
"commitizen": "^4.2.6",
66-
"concurrently": "^7.0.0",
67-
"cosmiconfig": "^7.0.1",
68+
"concurrently": "^7.6.0",
69+
"cosmiconfig": "^8.0.0",
6870
"cross-env": "^7.0.3",
6971
"cross-spawn": "^7.0.3",
70-
"depcheck": "^1.4.3",
71-
"doctoc": "^2.1.0",
72-
"eslint": "^8.29.0",
72+
"doctoc": "^2.2.1",
73+
"eslint": "^8.32.0",
7374
"eslint-config-airbnb": "19.0.4",
7475
"eslint-config-airbnb-typescript": "^17.0.0",
75-
"eslint-config-prettier": "^8.5.0",
76-
"eslint-plugin-import": "^2.26.0",
77-
"eslint-plugin-jest": "^26.9.0",
78-
"eslint-plugin-jsx-a11y": "^6.6.1",
76+
"eslint-config-prettier": "^8.6.0",
77+
"eslint-plugin-import": "^2.27.5",
78+
"eslint-plugin-jest": "^27.2.1",
79+
"eslint-plugin-jsx-a11y": "^6.7.1",
7980
"eslint-plugin-prettier": "^4.2.1",
80-
"eslint-plugin-react": "^7.31.11",
81+
"eslint-plugin-react": "^7.32.1",
8182
"eslint-plugin-react-hooks": "^4.6.0",
82-
"glob": "^8.0.3",
83+
"glob": "^8.1.0",
8384
"is-ci": "^3.0.1",
84-
"jest": "^27.5.1",
85+
"jest": "^29.3.1",
86+
"jest-environment-jsdom": "^29.3.1",
8587
"jest-github-actions-reporter": "^1.0.3",
86-
"jest-watch-typeahead": "^1.0.0",
87-
"lint-staged": "^12.3.4",
88+
"jest-watch-typeahead": "^2.2.1",
89+
"lint-staged": "^13.1.0",
8890
"lodash.has": "^4.5.2",
89-
"mkdirp": "^1.0.4",
90-
"prettier": "^2.5.1",
91+
"mkdirp": "^2.1.3",
92+
"prettier": "^2.8.3",
9193
"read-pkg-up": "^7.0.1",
92-
"rimraf": "^3.0.2",
93-
"ts-jest": "^27.1.3",
94-
"tslib": "^2.4.0",
94+
"rimraf": "^4.1.1",
95+
"tslib": "^2.4.1",
9596
"typescript": "^4",
96-
"which": "^2.0.2",
97-
"yargs-parser": "^21.0.1"
97+
"which": "^3.0.0",
98+
"yargs-parser": "^21.1.1"
9899
},
99100
"eslintConfig": {
100101
"parserOptions": {
@@ -110,7 +111,8 @@
110111
"import/no-unassigned-import": "off",
111112
"no-console": "off",
112113
"no-nested-ternary": "off",
113-
"no-useless-catch": "off"
114+
"no-useless-catch": "off",
115+
"jest/prefer-snapshot-hint": "off"
114116
}
115117
},
116118
"eslintIgnore": [
@@ -127,15 +129,23 @@
127129
},
128130
"homepage": "https://github.com/hoverinc/hover-javascript#readme",
129131
"devDependencies": {
130-
"@babel/cli": "^7.17.10",
131-
"@babel/core": "^7.17.2",
132-
"@babel/preset-env": "^7.16.11",
132+
"@babel/cli": "^7.20.7",
133+
"@babel/core": "^7.20.12",
134+
"@babel/preset-env": "^7.20.2",
133135
"@types/cross-spawn": "^6.0.2",
134-
"babel-jest": "^28.1.0",
135-
"eslint-config-kentcdodds": "^20.0.1",
136-
"husky": "^7.0.4",
136+
"depcheck": "^1.4.3",
137+
"eslint-config-kentcdodds": "^20.4.0",
138+
"husky": "^8.0.3",
137139
"jest-in-case": "^1.0.2",
138140
"npm-run-all": "^4.1.5",
139141
"slash": "^3.0.0"
142+
},
143+
"peerDependencies": {
144+
"ts-jest": "^29.0.0"
145+
},
146+
"peerDependenciesMeta": {
147+
"ts-jest": {
148+
"optional": true
149+
}
140150
}
141151
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
!node_modules

src/api/__tests__/__fixtures__/ls/dirs/node_modules/.gitkeep

Whitespace-only changes.

src/api/__tests__/commit.js

+19-1
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,29 @@ describe('ls', () => {
2626
})
2727

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

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

3333
expect(result.sort()).toEqual(expected.sort())
3434
})
35+
36+
test('with custom exclude (string)', () => {
37+
const result = ls.dirs(`${fixtures}/ls/dirs`, {exclude: 'foo'})
38+
39+
const expected = ['.baz', 'bar', 'node_modules']
40+
41+
expect(result.sort()).toEqual(expected.sort())
42+
})
43+
44+
test('with custom exclude (RegExp)', () => {
45+
const result = ls.dirs(`${fixtures}/ls/dirs`, {
46+
exclude: /(^node_modules|^bar)/,
47+
})
48+
49+
const expected = ['.baz', 'foo']
50+
51+
expect(result.sort()).toEqual(expected.sort())
52+
})
3553
})
3654
})

src/api/__tests__/test.js

-11
This file was deleted.

src/api/commit.js

+26-4
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,39 @@ const configs = path =>
4444
)}`,
4545
)
4646

47+
/**
48+
* @typedef DirsOptions
49+
* @property {string} [prefix] prefix to prepend to each scope entry (e.g:
50+
* `{ prefix: 'prefix' }` becomes `type(prefix/scope)`)
51+
* @property {RegExp | string | null} [exclude] expression for excluding
52+
* directories, defaults to `^node_modules`
53+
*/
54+
4755
/**
4856
* Enumerate one level of directories
4957
*
5058
* @param {string} path - directory to enumerate
51-
* @param {string} [prefix] - prefix for each scope entry (e.g: `prefix/entry`)
59+
* @param {DirsOptions} options -
5260
*/
53-
const dirs = (path, prefix) =>
54-
readdirSync(path)
55-
.filter(f => statSync(join(path, f)).isDirectory())
61+
const dirs = (path, options) => {
62+
const {exclude, prefix} = {exclude: /^node_modules/, ...options}
63+
64+
/**
65+
* @param {string} f filename
66+
*/
67+
const test = f => {
68+
if (!exclude) return true
69+
70+
return !(typeof exclude === 'string'
71+
? f.includes(exclude)
72+
: exclude.test(f))
73+
}
74+
75+
return readdirSync(path)
76+
.filter(f => statSync(join(path, f)).isDirectory() && test(f))
5677
.map(item => (prefix ? `${prefix}/${item}` : item))
5778
.map(item => item.toLowerCase())
79+
}
5880

5981
const ls = {configs, dirs}
6082

src/api/depcheck/depcheck.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const fs = require('fs')
22
const depcheck = require('depcheck')
3-
const hoverSpecials = require('./specials')
43
const {hasFile, uniq} = require('../../utils')
4+
const hoverSpecials = require('./specials')
55

66
/**
77
* @typedef Config

src/api/test.js

-1
This file was deleted.

src/config/__tests__/__snapshots__/eslintrc.js.snap

+3
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ Object {
119119
},
120120
],
121121
"import/prefer-default-export": "off",
122+
"jest/prefer-snapshot-hint": "off",
122123
"no-implied-eval": "error",
123124
"no-throw-literal": "error",
124125
"no-void": Array [
@@ -251,6 +252,7 @@ Object {
251252
},
252253
],
253254
"import/prefer-default-export": "off",
255+
"jest/prefer-snapshot-hint": "off",
254256
"no-implied-eval": "error",
255257
"no-throw-literal": "error",
256258
"no-void": Array [
@@ -287,6 +289,7 @@ Object {
287289
exports[`Strict ESLint configuration 1`] = `
288290
Object {
289291
"rules": Object {
292+
"import/no-default-export": "error",
290293
"import/order": Array [
291294
"error",
292295
Object {

src/config/eslintrc-strict.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
module.exports = {
22
rules: {
3+
'import/no-default-export': 'error',
34
'import/order': [
45
'error',
56
{

src/config/helpers/build-eslint.js

+2
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ const buildConfig = ({withReact = false} = {}) => {
6969
],
7070
'no-void': ['error', {allowAsStatement: true}],
7171
'prettier/prettier': 'error',
72+
// TODO: consider enabling this as a warning?
73+
'jest/prefer-snapshot-hint': 'off',
7274
...parserRules(false, isReact),
7375
},
7476
overrides: [

src/config/helpers/build-lint-staged.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const {resolveHoverScripts, resolveBin} = require('../../utils')
33
const hoverScripts = resolveHoverScripts()
44
const doctoc = resolveBin('doctoc')
55

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

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

src/config/jest.config.js

+23-26
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
/** @typedef {import('@jest/types').Config.InitialOptions} JestConfig */
22

3-
const {jsWithTs: preset} = require('ts-jest/presets')
4-
5-
const {ifAnyDep, hasAnyDep, hasFile, fromRoot} = require('../utils')
3+
const {ifAnyDep, hasFile, fromRoot, hasDevDep} = require('../utils')
64

75
const {
86
testMatch,
@@ -22,13 +20,31 @@ const ignores = [
2220
/** @type JestConfig */
2321
const jestConfig = {
2422
roots: [fromRoot('.')],
23+
// Here we're preserving Jest <= 28 snapshot format to prevent the need
24+
// to update snapshots when upgrading Jest via @hover/javascript, see:
25+
// https://jestjs.io/docs/upgrading-to-jest29#snapshot-format
26+
snapshotFormat: {escapeString: true, printBasicPrototype: true},
2527
testEnvironment: ifAnyDep(['webpack', 'rollup', 'react'], 'jsdom', 'node'),
26-
testURL: 'http://localhost',
28+
testEnvironmentOptions: {url: 'http://localhost'},
2729
moduleFileExtensions: testMatchExtensions.concat('json'),
2830
collectCoverageFrom: [`**/${testMatchGlob}`],
2931
testMatch,
3032
testPathIgnorePatterns: [...ignores, '<rootDir>/dist'],
3133
testLocationInResults: true,
34+
// The default transform is now SWC, however, `ts-jest` will
35+
// still be used if it is installed in the host project
36+
transform: hasDevDep('ts-jest')
37+
? Object.fromEntries(
38+
// Ensure we can resolve the preset even when
39+
// it's in a nested `node_modules` installation
40+
Object.entries(require('ts-jest/presets').transform).map(
41+
([glob, transformer]) => [
42+
glob,
43+
[require.resolve(transformer), {diagnostics: {warnOnly: true}}],
44+
],
45+
),
46+
)
47+
: {'^.+\\.(t|j)sx?$': ['@swc-node/jest']},
3248
coveragePathIgnorePatterns: [
3349
...ignores,
3450
'src/(umd|cjs|esm)-entry.js$',
@@ -51,28 +67,9 @@ const jestConfig = {
5167
require.resolve('jest-watch-typeahead/filename'),
5268
require.resolve('jest-watch-typeahead/testname'),
5369
],
54-
globals: {},
55-
}
56-
57-
if (hasAnyDep('ts-jest') || hasFile('tsconfig.json')) {
58-
jestConfig.transform = Object.fromEntries(
59-
// Ensure we can resolve the preset even when
60-
// it's in a nested `node_modules` installation
61-
Object.entries(preset.transform).map(([key, value]) => [
62-
key,
63-
require.resolve(value),
64-
]),
65-
)
66-
67-
jestConfig.globals['ts-jest'] = {
68-
diagnostics: {
69-
warnOnly: true,
70-
},
71-
}
72-
}
73-
74-
if (hasFile('tests/setup-env.js')) {
75-
jestConfig.setupFilesAfterEnv = [fromRoot('tests/setup-env.js')]
70+
setupFilesAfterEnv: hasFile('tests/setup-env.js')
71+
? [fromRoot('tests/setup-env.js')]
72+
: undefined,
7673
}
7774

7875
module.exports = jestConfig

0 commit comments

Comments
 (0)