Skip to content

Commit

Permalink
feat: version 13
Browse files Browse the repository at this point in the history
BREAKING CHANGE:

see CHANGELOG.md for migration guide.
Most of the commands are now behind `dev-lib`, e.g `yarn dev-lib test`.
  • Loading branch information
kirillgroshkov committed Jul 24, 2024
1 parent 3babad2 commit a713cae
Show file tree
Hide file tree
Showing 53 changed files with 1,002 additions and 881 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
key: npm-v1-${{ runner.os }}

- run: yarn --frozen-lockfile --prefer-offline
- run: yarn build-prod
- run: yarn build

- name: release
env:
Expand Down
2 changes: 1 addition & 1 deletion .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[ -n "$CI" ] && exit 0

yarn commitlint-def $1
yarn dev-lib commitlint $1
# exit 1 # uncomment to debug
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[ -n "$CI" ] && exit 0

yarn lint-staged-def
yarn dev-lib lint-staged
63 changes: 63 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1 +1,64 @@
See [Github Releases](https://github.com/NaturalCycles/dev-lib/releases)

# 13.0 Release notes

`dev-lib` started to expose `dev-lib` command that can be executed like `yarn dev-lib`.

It can work in 2 modes: CLI and interactive.

CLI mode is for command execution, e.g `yarn dev-lib lint` will run all linters, what previously was
`yarn lint-all`.

Interactive mode is for human interactive execution and exploration of available commands.
`yarn dev-lib` gives you an interactive prompt to select one of available commands.

These deprecated commands were removed:

- test-ci
- test-integration-ci
- test-manual

These commands are no longer exposed as commands:

- build-copy

These commands stay as shortcuts/aliases (they kind of make sense there, as they're yarn-related):

- yarn up
- yarn upnc

`build-prod` now falls back to `tsconfig.json` if `tsconfig.prod.json` is absent.

## Migration guide

```
# build commands
yarn bt => yarn dev-lib bt
yarn btl => yarn dev-lib lbt # lbt reflects the order: lint-build-test
yarn build => gone, no replacement
yarn build-copy => gone, no replacement
yarn tsc-prod, tsc-scripts => gone, no replacement
yarn build-prod => yarn dev-lib build
yarn build-prod-esm-cjs => yarn dev-lib build-esm-cjs
# lint commands
yarn commitlint-def => yarn dev-lib commitlint
yarn lint-staged-def => yarn dev-lib lint-staged
yarn lint-all => yarn dev-lib lint
yarn eslint-all => yarn dev-lib eslint
yarn prettier-all => yarn dev-lib prettier
yarn stylelint-all => yarn dev-lib stylelint
# test commands
yarn test-ci, test-integration-ci, test-manual => gone, no replacement
yarn test => yarn dev-lib test
yarn test-integration => yarn dev-lib test-integration
yarn test-leaks => yarn dev-lib test-leaks
# other commands
init-from-dev-lib, update-from-dev-lib => temporary gone, to be re-introduced later
```
4 changes: 0 additions & 4 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
/** @typedef {import('ts-jest/dist/types')} */
module.exports = {
...require('./cfg/jest.config'),
// debug esbuild
// transform: {
// '^.+\\.ts$': './my-transformer.js',
// },
}
60 changes: 14 additions & 46 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,23 @@
"scripts": {
"prepare": "husky",
"tsn-debug": "tsn testScript.ts",
"bt": "tsn ./src/bin/bt.ts && tsn eslintPrintConfig",
"btl": "tsn ./src/bin/btl.ts",
"build": "tsn ./src/bin/build.ts",
"tsc-prod": "tsn ./src/bin/tsc-prod.ts",
"tsc-scripts": "tsn ./src/bin/tsc-scripts.ts",
"build-copy": "tsn ./src/bin/build-copy.ts",
"build-prod": "tsn ./src/bin/build-prod.ts",
"build-prod-esm-cjs": "tsn ./src/bin/build-prod-esm-cjs.ts",
"test": "tsn ./src/bin/test.ts",
"test-ci": "tsn ./src/bin/test-ci.ts",
"test-leaks": "tsn ./src/bin/test-leaks.ts",
"test-integration": "tsn ./src/bin/test-integration.ts",
"test-integration-ci": "tsn ./src/bin/test-integration-ci.ts",
"test-manual": "tsn ./src/bin/test-manual.ts",
"lint-staged-def": "tsn ./src/bin/lint-staged-def.ts",
"commitlint-def": "tsn ./src/bin/commitlint-def.ts",
"prettier-all": "tsn ./src/bin/prettier-all.ts",
"stylelint-all": "tsn ./src/bin/stylelint-all.ts",
"lint-all": "tsn ./src/bin/lint-all.ts",
"eslint-all": "tsn ./src/bin/eslint-all.ts",
"dev-lib": "tsn ./src/bin/dev-lib.ts",
"bt": "tsn ./src/bin/dev-lib.ts bt && tsn eslintPrintConfig",
"lbt": "tsn ./src/bin/dev-lib.ts lbt",
"build": "tsn ./src/bin/dev-lib.ts build",
"build-prod-esm-cjs": "tsn ./src/bin/dev-lib.ts build-esm-cjs",
"test": "tsn ./src/bin/dev-lib.ts test",
"test-leaks": "tsn ./src/bin/dev-lib.ts test-leaks",
"test-integration": "tsn ./src/bin/dev-lib.ts test-integration",
"lint": "tsn ./src/bin/dev-lib.ts lint",
"up": "tsn ./src/bin/up.ts",
"upnc": "tsn ./src/bin/upnc.ts",
"update-from-dev-lib": "tsn ./src/bin/update-from-dev-lib.ts"
"upnc": "tsn ./src/bin/upnc.ts"
},
"dependencies": {
"@commitlint/cli": "^19.0.0",
"@commitlint/config-conventional": "^19.0.0",
"@eslint/js": "^9.7.0",
"@inquirer/prompts": "^5.3.2",
"@naturalcycles/cli": "^1.0.0",
"@naturalcycles/js-lib": "^14.0.0",
"@naturalcycles/nodejs-lib": "^13.0.1",
Expand Down Expand Up @@ -75,33 +64,12 @@
"main": "dist/index.js",
"types": "dist/index.d.ts",
"bin": {
"bt": "dist/bin/bt.js",
"btl": "dist/bin/btl.js",
"build": "dist/bin/build.js",
"build-copy": "dist/bin/build-copy.js",
"build-prod": "dist/bin/build-prod.js",
"build-prod-esm-cjs": "dist/bin/build-prod-esm-cjs.js",
"commitlint-def": "dist/bin/commitlint-def.js",
"eslint-all": "dist/bin/eslint-all.js",
"init-from-dev-lib": "dist/bin/init-from-dev-lib.js",
"lint-all": "dist/bin/lint-all.js",
"lint-staged-def": "dist/bin/lint-staged-def.js",
"prettier-all": "dist/bin/prettier-all.js",
"stylelint-all": "dist/bin/stylelint-all.js",
"test": "dist/bin/test.js",
"test-ci": "dist/bin/test-ci.js",
"test-leaks": "dist/bin/test-leaks.js",
"test-integration": "dist/bin/test-integration.js",
"test-integration-ci": "dist/bin/test-integration-ci.js",
"test-manual": "dist/bin/test-manual.js",
"tsc-prod": "dist/bin/tsc-prod.js",
"tsc-scripts": "dist/bin/tsc-scripts.js",
"dev-lib": "dist/bin/dev-lib.js",
"up": "dist/bin/up.js",
"upnc": "dist/bin/upnc.js",
"update-from-dev-lib": "dist/bin/update-from-dev-lib.js"
"upnc": "dist/bin/upnc.js"
},
"engines": {
"node": ">=18.12.0"
"node": ">=20.12.0"
},
"publishConfig": {
"provenance": true,
Expand Down
62 changes: 33 additions & 29 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,26 @@ Install it:

This unlocks all commands listed below, e.g:

yarn test
yarn lint-all
yarn dev-lib test
yarn dev-lib lint-all

`yarn dev-lib` runs "interactive mode" that lets you explore available commands.

By default, it uses default configs for Prettier, ESLint, Stylelint, that are included in this
package (for convenience). You can override them by putting your own `prettier.config.js`,
`eslint.config.js`, `stylelint.config.json` in the root folder of your project.
`eslint.config.js`, `stylelint.config.js` in the root folder of your project.

UPD: these tools/linters would use default configs if absent:

- commitlint
- lint-staged

These tools require a respective config to run, otherwise they're not run. List of configs:

- `jest.config.js`
- `prettier.config.js`
- `eslint.config.js` (eslint FLAT config)
- `stylelint.config.js`

## Conventions

Expand Down Expand Up @@ -56,23 +70,15 @@ All files are linted and _prettified_ upon commit (using `husky`, `lint-staged`

### Yarn commands

These commands are available to be called as `yarn <command>`, because they are exposed as
`npm scripts` in `node_modules/.bin/`.
These commands are available to be called as `yarn dev-lib <command>`.

#### Build commands

- `tsc-prod`: does `tsc -p tsconfig.prod.ts`
- `tsc-scripts`: does `tsc -p ./scripts/tsconfig.ts --noEmit` (type-checking for `./scripts`)

- `build`: "Development build". Checks that "everything compiles". Does
`del ./dist && tsc && tsc-scripts`
- `build`: "Production build". Does `del ./dist && build-copy && tsc-prod`
- `bt`: "Build & Test". Does `del ./dist && tsc && tsc-scripts && test`
- `btl`: "Build, Test & Lint". Does `lint-all && tsc && test`

- `build-copy`: copies _additional files_ into `dist` folder (e.g `*.json`)
- `build-prod`: "Production build". Does `del ./dist && build-copy && tsc-prod`
- `build-prod-esm-cjs`: "Production build" for browser-lib, will produce CJS output in `./dist` and
ESM output in `./dist-esm`. Will use `./tsconfig.{cjs|esm}.prod.json` if exists, otherwise
- `lbt`: "Lint, Build & Test". Does `lint && tsc && test`
- `build-esm-cjs`: "Production build" for browser-lib, will produce CJS output in `./dist` and ESM
output in `./dist-esm`. Will use `./tsconfig.{cjs|esm}.prod.json` if exists, otherwise
`tsconfig.prod.json`, which allows to override e.g compilation target.

#### Test commands
Expand All @@ -83,7 +89,7 @@ There are 3 categories of tests supported:
- Integration tests `*.integration.test.ts`
- Manual tests `*.manual.test.ts`

Unit tests are default. All tests are run on `yarn test`.
Unit tests are default. All tests are run on `yarn dev-lib test`.

Integration tests (optional) allow to have a setup file (`src/test/setupJest.integration.ts`) where
you can define separate environment settings. You can use it to run so-called "integration tests" -
Expand Down Expand Up @@ -120,11 +126,11 @@ For manual tests:
- `<rootDir>/src/test/setupJest.ts`
- `<rootDir>/src/test/setupJest.manual.ts`

`yarn test` runs tests in alphabetic order by default (internally it points `--testSequencer` to a
pre-defined sequencer file that sorts all filenames alphabetically). Set `JEST_NO_ALPHABETIC` env
variable to disable it.
`yarn dev-lib test` runs tests in alphabetic order by default (internally it points
`--testSequencer` to a pre-defined sequencer file that sorts all filenames alphabetically). Set
`JEST_NO_ALPHABETIC` env variable to disable it.

##### Shard support (experimental)
##### Shard support

Jest 28 introduced [--shard](https://jestjs.io/docs/cli#--shard) feature.

Expand All @@ -137,14 +143,14 @@ If you need to execute shards **in parallel**, you can follow e.g

#### Lint commands

- `lint-all`: runs ESLint, Stylelint, Prettier, actionlint, ktlint in the right order.
- `lint`: runs ESLint, Stylelint, Prettier, actionlint, ktlint in the right order.

- `--commitOnChanges` will commit lint-modified changes and push them
- `--failOnChanges` will exit with status 1 in the end (will fail the command)

- `eslint-all`: runs `eslint` on needed paths
- `stylelint-all`: runs `stylelint` on needed paths
- `prettier-all`: runs just Prettier on needed paths
- `eslint`: runs `eslint` on needed paths
- `stylelint`: runs `stylelint` on needed paths
- `prettier`: runs just Prettier on needed paths

Pass `--no-fix` (or `--fix=false`) to disable the default `--fix` flag on linters. Useful to debug a
linter, or when linter behaves badly and corrupts your files (just happened to me with
Expand All @@ -170,8 +176,6 @@ Install it **locally** in you project by adding

- `up`: shortcut for `yarn upgrade` && `yarn patch-package` (if `patch-package` exists in the
project).
- `init-from-dev-lib`: copy config files from `dev-lib/cfg/init` to the project
- `update-from-dev-lib`: copy config files from `dev-lib/cfg/overwrite` to the project

## Non-extendable config files

Expand All @@ -193,12 +197,12 @@ These files are meant to be extended in target project, so act as _recommended d
- `husky.config.js`
- `lint-staged.config.js`
- `prettier.config.js`
- `eslint.config.json`
- `eslint.config.js`
- `jest.config.js`

## eslint

Presence of `jest` is detected by checking if `node_modules/jest` exists.

If exists - `eslint-plugin-jest` recommended config (plus opinionated `dev-lib`'s rules) are
enabled. Otherwise disabled ( to not cause "jest not found" errors)
enabled. Otherwise disabled ( to not cause "jest not found" errors).
2 changes: 1 addition & 1 deletion scripts/eslintPrintConfig.script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Changes are visible in git diff every time they are observed.

import { _sortObjectDeep } from '@naturalcycles/js-lib'
import { execVoidCommandSync, fs2, runScript } from '@naturalcycles/nodejs-lib'
import { testDir } from '../src/cnst/paths.cnst'
import { testDir } from '../src/paths'

runScript(async () => {
const outputPath = `${testDir}/cfg/eslint.config.dump.json`
Expand Down
13 changes: 0 additions & 13 deletions src/bin/bt.ts

This file was deleted.

16 changes: 0 additions & 16 deletions src/bin/btl.ts

This file was deleted.

6 changes: 0 additions & 6 deletions src/bin/build-copy.ts

This file was deleted.

6 changes: 0 additions & 6 deletions src/bin/build-prod-esm-cjs.ts

This file was deleted.

6 changes: 0 additions & 6 deletions src/bin/build-prod.ts

This file was deleted.

10 changes: 0 additions & 10 deletions src/bin/build.ts

This file was deleted.

Loading

0 comments on commit a713cae

Please sign in to comment.