Skip to content

Commit

Permalink
Merge pull request #782 from hoverinc/beta
Browse files Browse the repository at this point in the history
🔖 Beta
  • Loading branch information
jrolfs authored Jan 19, 2023
2 parents 5e94f75 + 17ce718 commit ad6df53
Show file tree
Hide file tree
Showing 25 changed files with 3,434 additions and 3,261 deletions.
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,52 @@
"author": "Jamie Rolfs <[email protected]>",
"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",
"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 +111,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 +129,23 @@
},
"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",
"depcheck": "^1.4.3",
"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

0 comments on commit ad6df53

Please sign in to comment.