@adamhl8/configs 3.1.1 → 3.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +316 -76
- package/dist/configs/bunfig.base.toml +2 -2
- package/dist/configs/knip.base.d.ts +1 -1
- package/dist/configs/knip.base.d.ts.map +1 -1
- package/dist/configs/knip.base.js +5 -1
- package/dist/configs/knip.base.js.map +1 -1
- package/dist/configs/oxlint.base.d.ts +7 -0
- package/dist/configs/oxlint.base.d.ts.map +1 -1
- package/dist/configs/oxlint.base.js +8 -0
- package/dist/configs/oxlint.base.js.map +1 -1
- package/dist/test-utils/fixture.d.ts +17 -0
- package/dist/test-utils/fixture.d.ts.map +1 -0
- package/dist/test-utils/fixture.js +20 -0
- package/dist/test-utils/fixture.js.map +1 -0
- package/dist/test-utils/index.d.ts +7 -0
- package/dist/test-utils/index.js +6 -0
- package/dist/test-utils/pack.d.ts +3 -0
- package/dist/test-utils/pack.d.ts.map +1 -0
- package/dist/test-utils/pack.js +16 -0
- package/dist/test-utils/pack.js.map +1 -0
- package/dist/test-utils/preload.d.ts +1 -0
- package/dist/test-utils/preload.js +7 -0
- package/dist/test-utils/preload.js.map +1 -0
- package/dist/test-utils/shell/bin-dirs.js +19 -0
- package/dist/test-utils/shell/bin-dirs.js.map +1 -0
- package/dist/test-utils/shell/command.d.ts +18 -0
- package/dist/test-utils/shell/command.d.ts.map +1 -0
- package/dist/test-utils/shell/command.js +63 -0
- package/dist/test-utils/shell/command.js.map +1 -0
- package/dist/test-utils/shell/env.d.ts +4 -0
- package/dist/test-utils/shell/env.d.ts.map +1 -0
- package/dist/test-utils/shell/env.js +11 -0
- package/dist/test-utils/shell/env.js.map +1 -0
- package/dist/test-utils/shell/node-shim.js +18 -0
- package/dist/test-utils/shell/node-shim.js.map +1 -0
- package/dist/test-utils/shell/shell.d.ts +42 -0
- package/dist/test-utils/shell/shell.d.ts.map +1 -0
- package/dist/test-utils/shell/shell.js +24 -0
- package/dist/test-utils/shell/shell.js.map +1 -0
- package/dist/test-utils/temp-dir.d.ts +3 -0
- package/dist/test-utils/temp-dir.d.ts.map +1 -0
- package/dist/test-utils/temp-dir.js +21 -0
- package/dist/test-utils/temp-dir.js.map +1 -0
- package/package.json +9 -1
package/README.md
CHANGED
|
@@ -1,11 +1,90 @@
|
|
|
1
1
|
# configs
|
|
2
2
|
|
|
3
|
-
Configs
|
|
3
|
+
Configs, tasks, and workflows I use across my TS projects.
|
|
4
|
+
|
|
5
|
+
- Base configs for `tsconfig`, `oxfmt`, `oxlint`, `knip`, `tsdown`, `commitlint`, `release-it`, and `lefthook`, each extended through a typed merge function
|
|
6
|
+
- Shared [bask](https://github.com/adamhl8/bask) tasks for linting, building, testing, and releasing
|
|
7
|
+
- `bunfig.toml` and `.gitignore` entries synced into each project
|
|
8
|
+
- Reusable GitHub Actions workflows for CI, dependency updates, and releases
|
|
9
|
+
- An OpenTofu module for each repo's GitHub settings and Actions secrets
|
|
10
|
+
- Utilities for validated env vars and integration tests
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
<!-- toc -->
|
|
15
|
+
|
|
16
|
+
- [Installation](#installation)
|
|
17
|
+
- [Setup](#setup)
|
|
18
|
+
- [Configs](#configs)
|
|
19
|
+
- [Config merging](#config-merging)
|
|
20
|
+
- [tsconfig](#tsconfig)
|
|
21
|
+
- [oxfmt](#oxfmt)
|
|
22
|
+
- [oxlint](#oxlint)
|
|
23
|
+
- [knip](#knip)
|
|
24
|
+
- [tsdown](#tsdown)
|
|
25
|
+
- [commitlint](#commitlint)
|
|
26
|
+
- [release-it](#release-it)
|
|
27
|
+
- [lefthook](#lefthook)
|
|
28
|
+
- [bask tasks](#bask-tasks)
|
|
29
|
+
- [Synced files](#synced-files)
|
|
30
|
+
- [bunfig](#bunfig)
|
|
31
|
+
- [gitignore](#gitignore)
|
|
32
|
+
- [Utilities](#utilities)
|
|
33
|
+
- [env](#env)
|
|
34
|
+
- [test](#test)
|
|
35
|
+
- [GitHub Actions](#github-actions)
|
|
36
|
+
- [CI](#ci)
|
|
37
|
+
- [Update dependencies](#update-dependencies)
|
|
38
|
+
- [Release](#release)
|
|
39
|
+
- [Secrets](#secrets)
|
|
40
|
+
- [GitHub repo settings](#github-repo-settings)
|
|
41
|
+
- [Developing this repo](#developing-this-repo)
|
|
42
|
+
|
|
43
|
+
<!-- tocstop -->
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
## Installation
|
|
4
48
|
|
|
5
49
|
```sh
|
|
6
50
|
bun add -D @adamhl8/configs
|
|
7
51
|
```
|
|
8
52
|
|
|
53
|
+
The tasks run each tool's bin from the project, so install the tools directly too. With bun's `isolated` linker, a bin that's only a dependency of `@adamhl8/configs` isn't on the project's `PATH`.
|
|
54
|
+
|
|
55
|
+
```sh
|
|
56
|
+
bun add -D @adamhl8/bask @commitlint/cli @commitlint/config-conventional @types/bun knip markdown-toc oxfmt oxlint oxlint-tsgolint typescript
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Some tools are only needed by some projects:
|
|
60
|
+
|
|
61
|
+
- Published packages: `tsdown publint @arethetypeswrong/core`
|
|
62
|
+
- Releases: `release-it release-it-git-cliff` (see [release-it](#release-it))
|
|
63
|
+
- Astro projects that use Tailwind: `tailwint @tailwindcss/language-server` (see [bask tasks](#bask-tasks))
|
|
64
|
+
|
|
65
|
+
## Setup
|
|
66
|
+
|
|
67
|
+
A project using everything here has these files:
|
|
68
|
+
|
|
69
|
+
| File | Section |
|
|
70
|
+
| ------------------------- | --------------------------------------------- |
|
|
71
|
+
| `bask.ts` | [bask tasks](#bask-tasks) |
|
|
72
|
+
| `package.json` `prepare` | [bask tasks](#bask-tasks) |
|
|
73
|
+
| `tsconfig.json` | [tsconfig](#tsconfig) |
|
|
74
|
+
| `oxfmt.config.ts` | [oxfmt](#oxfmt) |
|
|
75
|
+
| `oxlint.config.ts` | [oxlint](#oxlint) |
|
|
76
|
+
| `knip.ts` | [knip](#knip) |
|
|
77
|
+
| `tsdown.config.ts` | [tsdown](#tsdown) |
|
|
78
|
+
| `commitlint.config.ts` | [commitlint](#commitlint) |
|
|
79
|
+
| `.release-it.ts` | [release-it](#release-it) |
|
|
80
|
+
| `lefthook.yaml` | [lefthook](#lefthook) |
|
|
81
|
+
| `.github/workflows/*.yml` | [GitHub Actions](#github-actions) |
|
|
82
|
+
| `github.tofu` | [GitHub repo settings](#github-repo-settings) |
|
|
83
|
+
|
|
84
|
+
`bunfig.toml` and `.gitignore` are kept up to date by the [synced files](#synced-files).
|
|
85
|
+
|
|
86
|
+
## Configs
|
|
87
|
+
|
|
9
88
|
### Config merging
|
|
10
89
|
|
|
11
90
|
Each `fooConfig({ ... })` function deep merges your config into the base config. Arrays are appended to the base array by default. To use arrays as-is instead, put them in a second config object, which is merged the same way except its arrays replace the base array:
|
|
@@ -25,67 +104,23 @@ const config = oxlintConfig(
|
|
|
25
104
|
)
|
|
26
105
|
```
|
|
27
106
|
|
|
28
|
-
The second config works at any depth: only the arrays you provide are replaced, sibling keys still merge normally, and a key in both objects gets the second object's value. Required keys (e.g. `platform` for `tsdownConfig`) must be provided in the first object.
|
|
29
|
-
|
|
30
|
-
### bask
|
|
31
|
-
|
|
32
|
-
Tasks live in a shared [bask](https://github.com/adamhl8/bask) tasks module instead of being copied into every project's `package.json`. Install `@adamhl8/bask` as a dev dependency, then re-export the tasks from your `bask.ts`:
|
|
33
|
-
|
|
34
|
-
```ts
|
|
35
|
-
export * from "@adamhl8/configs/bask"
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
It provides `lint`, `build`, `test`, `bump-deps`, `release`, `release-run` (hidden, run by the release workflow), `tofu-check`, `commit-types`, and `prepare`. Run `bunx bask` to list them along with the allowed commit types. The tasks degrade gracefully so projects can use them as-is: `build` only runs `tsdown` if the project has a `tsdown.config.ts`, `test` (`bun test`) passes when there are no tests, and `tofu-check` (a `tofu plan` drift check, which `build` also runs) skips itself unless run locally in a project with `.tofu` files.
|
|
39
|
-
|
|
40
|
-
In projects that depend on `tailwindcss`, `lint` also runs [tailwint](https://github.com/peterwangsc/tailwint) on `.astro` files, because oxlint can't see Astro markup. It only checks and never fixes, because tailwint resolves a class conflict by deleting a class by position, not by which one wins. Projects with `.astro` files install it:
|
|
41
|
-
|
|
42
|
-
```sh
|
|
43
|
-
bun add -D tailwint @tailwindcss/language-server
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
Both are optional peer dependencies. bask runs `bun tailwint` from the project, so with bun's `isolated` linker the bin has to be installed by the project, not just by `@adamhl8/configs`.
|
|
47
|
-
|
|
48
|
-
To customize a task, add hooks to it from your `bask.ts`. A hook also runs when another base task calls that task, so extending `lint` extends `build` too:
|
|
49
|
-
|
|
50
|
-
```ts
|
|
51
|
-
import { task } from "@adamhl8/bask"
|
|
52
|
-
import { bumpDeps, lint } from "@adamhl8/configs/bask"
|
|
53
|
-
|
|
54
|
-
export * from "@adamhl8/configs/bask"
|
|
55
|
-
|
|
56
|
-
export const astroSync = task(async ({ sh }) => {
|
|
57
|
-
await sh`astro sync`
|
|
58
|
-
})
|
|
59
|
-
|
|
60
|
-
lint.before(astroSync)
|
|
61
|
-
bumpDeps.after(async ({ sh }) => {
|
|
62
|
-
await sh`prisma generate`
|
|
63
|
-
})
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
The only script left in `package.json` is `prepare`, which hands off to bask:
|
|
67
|
-
|
|
68
|
-
```json
|
|
69
|
-
"scripts": {
|
|
70
|
-
"prepare": "bask prepare"
|
|
71
|
-
}
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
The `prepare` script and task `sh` calls run local bins by their bare name, because `bun run` and bask both put `node_modules/.bin` on `PATH`. Git hooks and the workflows run `bunx bask` rather than `bun bask`, because `bun bask` runs `bask.ts` instead of the bask bin.
|
|
107
|
+
The second config works at any depth: only the arrays you provide are replaced, sibling keys still merge normally, and a key in both objects gets the second object's value. Required keys (e.g. `platform` for `tsdownConfig`) must be provided in the first object. A function with no required keys can be called with no arguments to get the base config as-is.
|
|
75
108
|
|
|
76
109
|
### tsconfig
|
|
77
110
|
|
|
78
111
|
```json
|
|
112
|
+
// tsconfig.json
|
|
79
113
|
{
|
|
80
114
|
"extends": "@adamhl8/configs/tsconfig"
|
|
81
115
|
}
|
|
82
116
|
```
|
|
83
117
|
|
|
84
|
-
The base tsconfig sets `types: ["bun"]`, so the project needs `@types/bun` installed.
|
|
118
|
+
The base tsconfig adds stricter checks like `noUncheckedIndexedAccess` and `exactOptionalPropertyTypes`, with no emit and bundler module resolution. It sets `types: ["bun"]`, so the project needs `@types/bun` installed.
|
|
85
119
|
|
|
86
120
|
### oxfmt
|
|
87
121
|
|
|
88
122
|
```ts
|
|
123
|
+
// oxfmt.config.ts
|
|
89
124
|
import { oxfmtConfig } from "@adamhl8/configs"
|
|
90
125
|
import { defineConfig } from "oxfmt"
|
|
91
126
|
|
|
@@ -94,11 +129,14 @@ const config = oxfmtConfig({ ... })
|
|
|
94
129
|
export default defineConfig(config)
|
|
95
130
|
```
|
|
96
131
|
|
|
132
|
+
The base uses a 120 character line width and no semicolons, and sorts imports, `package.json`, and Tailwind classes.
|
|
133
|
+
|
|
97
134
|
In projects that depend on `tailwindcss`, Tailwind classes are sorted against the project's Tailwind stylesheet, so classes from plugins and `@theme` sort correctly. The stylesheet is found the same way the Tailwind language server finds it: the first CSS file, in sorted order, that does `@import "tailwindcss"`. oxfmt has to run from the project root for this to find the file. If it picks the wrong file, set `sortTailwindcss: { stylesheet: "path/to/global.css" }`.
|
|
98
135
|
|
|
99
136
|
### oxlint
|
|
100
137
|
|
|
101
138
|
```ts
|
|
139
|
+
// oxlint.config.ts
|
|
102
140
|
import { oxlintConfig } from "@adamhl8/configs"
|
|
103
141
|
import { defineConfig } from "oxlint"
|
|
104
142
|
|
|
@@ -107,55 +145,81 @@ const config = oxlintConfig({ ... })
|
|
|
107
145
|
export default defineConfig(config)
|
|
108
146
|
```
|
|
109
147
|
|
|
110
|
-
|
|
148
|
+
The base turns on every rule category as an error, with type-aware linting and type checking, then turns off the rules that don't fit. It also loads these JS plugins with every rule on, except the rules a native rule already covers:
|
|
149
|
+
|
|
150
|
+
- Always: [bunisms](https://github.com/himynameisdave/eslint-plugin-bunisms), [clean-modules](https://github.com/adamhl8/eslint-plugin-clean-modules), [directive-comments](https://github.com/tunderadev/oxlint-plugin-directive-comments), [e18e](https://github.com/e18e/eslint-plugin), and [regexp](https://github.com/ota-meshi/eslint-plugin-regexp)
|
|
151
|
+
- When the project depends on `hono`: [hono](https://github.com/ouka-lab/eslint-plugin-hono)
|
|
152
|
+
- When the project depends on `react`: [react-web-api](https://github.com/Rel1cx/eslint-react) and [react-you-might-not-need-an-effect](https://github.com/nickjvandyke/eslint-plugin-react-you-might-not-need-an-effect)
|
|
153
|
+
- When the project has a Tailwind stylesheet: [oxlint-tailwindcss](https://github.com/sergioazoc/oxlint-tailwindcss)
|
|
154
|
+
|
|
155
|
+
The plugins are loaded from `@adamhl8/configs`'s own dependencies, so the project doesn't install them. In a project whose `package.json` has `engines.node`, the bunisms rules are off in `src/` (except in tests), because that code runs on Node.
|
|
156
|
+
|
|
157
|
+
oxlint-tailwindcss runs every rule except `enforce-sort-order` and `enforce-consistent-line-wrapping` (oxfmt handles these), `enforce-logical` (it conflicts with `enforce-physical`), and `max-class-count`. It reads the design system from the same stylesheet oxfmt sorts against. If that's the wrong file, set `settings: { tailwindcss: { entryPoint: "path/to/global.css" } }`, alongside the oxfmt `sortTailwindcss` override.
|
|
111
158
|
|
|
112
159
|
### knip
|
|
113
160
|
|
|
114
161
|
```ts
|
|
162
|
+
// knip.ts
|
|
115
163
|
import { knipConfig } from "@adamhl8/configs"
|
|
116
164
|
|
|
117
|
-
|
|
165
|
+
const config = knipConfig({ ... })
|
|
166
|
+
|
|
167
|
+
export default config
|
|
118
168
|
```
|
|
119
169
|
|
|
170
|
+
The base leaves `fixtures` and `fixture` dirs out of the analysis, at any depth. It adds `**/*.test.ts` and `bask.ts` to the bun plugin's entries rather than the top-level `entry`, so a project's own `entry` doesn't replace knip's default entries. knip doesn't see commands run through bask's `sh`, so a dependency that's only run there goes in `ignoreDependencies`.
|
|
171
|
+
|
|
120
172
|
### tsdown
|
|
121
173
|
|
|
122
174
|
```ts
|
|
175
|
+
// tsdown.config.ts
|
|
123
176
|
import { tsdownConfig } from "@adamhl8/configs"
|
|
124
177
|
import { defineConfig } from "tsdown"
|
|
125
178
|
|
|
126
|
-
const config = tsdownConfig({
|
|
179
|
+
const config = tsdownConfig({ platform: "node" })
|
|
127
180
|
|
|
128
181
|
export default defineConfig(config)
|
|
129
182
|
```
|
|
130
183
|
|
|
184
|
+
The base builds `src/index.ts` as an unbundled ESM library with sourcemaps and type declarations, and checks the package with `attw` and `publint`. Any warning fails the build. `platform` is required.
|
|
185
|
+
|
|
131
186
|
`tsdownBundleConfig` is also exported for single-file bundles that aren't published libraries: everything is bundled, with no type declarations or publish checks. `tsdownBinConfig` builds `package.json` bin executables: the same bundle for node, with an extensionless output file.
|
|
132
187
|
|
|
133
188
|
### commitlint
|
|
134
189
|
|
|
135
190
|
```ts
|
|
191
|
+
// commitlint.config.ts
|
|
136
192
|
import { commitlintConfig } from "@adamhl8/configs"
|
|
137
193
|
|
|
138
|
-
|
|
194
|
+
const config = commitlintConfig({ ... })
|
|
195
|
+
|
|
196
|
+
export default config
|
|
139
197
|
```
|
|
140
198
|
|
|
141
|
-
|
|
199
|
+
The allowed commit types are the conventional types without `test`, `style`, and `build`, plus `improve` and `release`. `bunx bask commit-types` prints them.
|
|
142
200
|
|
|
143
|
-
|
|
201
|
+
<details>
|
|
202
|
+
<summary><i>Why is <code>@commitlint/config-conventional</code> both a dependency and a peer dependency?</i></summary>
|
|
144
203
|
|
|
145
204
|
- Dependency: `commitlint.base.ts` imports it to read the conventional commit types.
|
|
146
205
|
- Peer dependency: `commitlint.base.ts` also sets `extends: ["@commitlint/config-conventional"]`. commitlint resolves that string from the consumer's project root, not from `@adamhl8/configs`.
|
|
147
206
|
|
|
148
207
|
With bun's `isolated` linker, our copy lives only in `@adamhl8/configs`'s own `node_modules` and is never hoisted to the consumer's root. So commitlint can't find it unless the consumer installs it directly, which the peer dependency asks them to do.
|
|
149
208
|
|
|
209
|
+
</details>
|
|
210
|
+
|
|
150
211
|
### release-it
|
|
151
212
|
|
|
152
213
|
```ts
|
|
214
|
+
// .release-it.ts
|
|
153
215
|
import { releaseItConfig } from "@adamhl8/configs"
|
|
154
216
|
|
|
155
|
-
|
|
217
|
+
const config = releaseItConfig({ ... })
|
|
218
|
+
|
|
219
|
+
export default config
|
|
156
220
|
```
|
|
157
221
|
|
|
158
|
-
The release config registers the [`release-it-git-cliff`](https://github.com/adamhl8/release-it-git-cliff) plugin with the bundled git-cliff config (`cliff.base.toml`), so there is no per-project `cliff.toml` to write. git-cliff picks the next version from the commits, and the plugin writes `CHANGELOG.md` (formatted with `oxfmt`) and sets the release notes.
|
|
222
|
+
The release config registers the [`release-it-git-cliff`](https://github.com/adamhl8/release-it-git-cliff) plugin with the bundled git-cliff config (`cliff.base.toml`), so there is no per-project `cliff.toml` to write. git-cliff picks the next version from the commits, and the plugin writes `CHANGELOG.md` (formatted with `oxfmt`) and sets the release notes. A release starts by running `bunx bask build`. The release commit is `release: v${version}`, and the tag is `v${version}`. It publishes with `bun publish --ignore-scripts`.
|
|
159
223
|
|
|
160
224
|
git-cliff must be on `PATH`, and the project needs `release-it-git-cliff` installed directly:
|
|
161
225
|
|
|
@@ -163,15 +227,18 @@ git-cliff must be on `PATH`, and the project needs `release-it-git-cliff` instal
|
|
|
163
227
|
bun add -D release-it release-it-git-cliff
|
|
164
228
|
```
|
|
165
229
|
|
|
166
|
-
|
|
230
|
+
Preview the next version or the unreleased changelog section with `release-it --release-version` or `release-it --changelog`.
|
|
231
|
+
|
|
232
|
+
<details>
|
|
233
|
+
<summary><i>Why does the project install <code>release-it-git-cliff</code>?</i></summary>
|
|
167
234
|
|
|
168
235
|
`release-it-git-cliff` is an optional peer dependency. release-it resolves plugins from its own location or the working directory, so with bun's `isolated` linker it can't find a plugin that's only a dependency of `@adamhl8/configs`.
|
|
169
236
|
|
|
170
|
-
|
|
237
|
+
</details>
|
|
171
238
|
|
|
172
239
|
### lefthook
|
|
173
240
|
|
|
174
|
-
`lefthook.base.yaml` runs `bunx bask build` on pre-commit and `commitlint` on commit-msg. Extend it from your `lefthook.yaml`:
|
|
241
|
+
`lefthook.base.yaml` runs `bunx bask build` on pre-commit and `commitlint` on commit-msg. The pre-commit hook fails when the build changes any files, so you can stage the lint fixes and formatting and commit again. Extend it from your `lefthook.yaml`:
|
|
175
242
|
|
|
176
243
|
```yaml
|
|
177
244
|
# lefthook.yaml
|
|
@@ -179,19 +246,97 @@ extends:
|
|
|
179
246
|
- node_modules/@adamhl8/configs/dist/configs/lefthook.base.yaml
|
|
180
247
|
```
|
|
181
248
|
|
|
182
|
-
`lefthook install` (the
|
|
249
|
+
`lefthook install` (the `prepare` task runs it) sets up the hooks.
|
|
250
|
+
|
|
251
|
+
## bask tasks
|
|
252
|
+
|
|
253
|
+
Tasks live in a shared [bask](https://github.com/adamhl8/bask) tasks module instead of being copied into every project's `package.json`. Re-export them from your `bask.ts`:
|
|
254
|
+
|
|
255
|
+
```ts
|
|
256
|
+
// bask.ts
|
|
257
|
+
export * from "@adamhl8/configs/bask"
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
Run `bunx bask` to list them along with the allowed commit types.
|
|
261
|
+
|
|
262
|
+
| Task | What it does |
|
|
263
|
+
| -------------- | -------------------------------------------------------------------------------------------------------------------------------- |
|
|
264
|
+
| `lint` | Updates the README's table of contents, runs oxlint (with fixes), oxfmt, tailwint, `tofu fmt`, knip, and actionlint, then `test` |
|
|
265
|
+
| `build` | Runs `lint`, `tsdown`, and `tofu-check`. In CI, it fails when lint fixes or formatting changed any files |
|
|
266
|
+
| `test` | Runs `bun test`, which passes when there are no tests |
|
|
267
|
+
| `bump-deps` | Updates every dependency to its latest version, then reinstalls without the lockfile, `node_modules`, or bun's cache |
|
|
268
|
+
| `release` | Starts the [release workflow](#release) (`gh workflow run release.yml`) |
|
|
269
|
+
| `release-run` | Runs `release-it --ci`. It's hidden because only the release workflow runs it |
|
|
270
|
+
| `tofu-check` | Runs `tofu plan` to check the [GitHub repo settings](#github-repo-settings) for drift |
|
|
271
|
+
| `commit-types` | Prints the allowed commit types |
|
|
272
|
+
| `prepare` | Runs `lefthook install`, the [synced files](#synced-files), and `tofu init -upgrade` |
|
|
273
|
+
|
|
274
|
+
The tasks skip the steps a project doesn't need, so projects can use them as-is:
|
|
275
|
+
|
|
276
|
+
- `lint` runs tailwint only when the project has a Tailwind stylesheet and `.astro` files, `tofu fmt` only when it has tofu files, and actionlint only when it has `.github/workflows`. The table of contents only changes in a README with [markdown-toc](https://github.com/jonschlinkert/markdown-toc)'s `toc` and `tocstop` comment markers.
|
|
277
|
+
- `build` runs `tsdown` only when the project has a `tsdown.config.ts`.
|
|
278
|
+
- `tofu-check` and `tofu init` run only outside CI, in a project with a root `.tofu` file, on a machine with the `adamhl8` AWS profile.
|
|
279
|
+
- `prepare` skips `lefthook install` in CI, so commits made by the workflows don't run the hooks.
|
|
280
|
+
|
|
281
|
+
tailwint runs on `.astro` files because oxlint can't see Astro markup. It only checks and never fixes, because tailwint resolves a class conflict by deleting a class by position, not by which one wins. Projects with `.astro` files install it:
|
|
282
|
+
|
|
283
|
+
```sh
|
|
284
|
+
bun add -D tailwint @tailwindcss/language-server
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
Both are optional peer dependencies. bask runs `bun tailwint` from the project, so with bun's `isolated` linker the bin has to be installed by the project, not just by `@adamhl8/configs`.
|
|
288
|
+
|
|
289
|
+
To customize a task, add hooks to it from your `bask.ts`. A hook also runs when another base task calls that task, so extending `lint` extends `build` too:
|
|
290
|
+
|
|
291
|
+
```ts
|
|
292
|
+
// bask.ts
|
|
293
|
+
import { task } from "@adamhl8/bask"
|
|
294
|
+
import { bumpDeps, lint } from "@adamhl8/configs/bask"
|
|
295
|
+
|
|
296
|
+
export * from "@adamhl8/configs/bask"
|
|
297
|
+
|
|
298
|
+
export const astroSync = task(async ({ sh }) => {
|
|
299
|
+
await sh`astro sync`
|
|
300
|
+
})
|
|
301
|
+
|
|
302
|
+
lint.before(astroSync)
|
|
303
|
+
bumpDeps.after(async ({ sh }) => {
|
|
304
|
+
await sh`prisma generate`
|
|
305
|
+
})
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
The only script left in `package.json` is `prepare`, which hands off to bask:
|
|
309
|
+
|
|
310
|
+
```json
|
|
311
|
+
"scripts": {
|
|
312
|
+
"prepare": "bask prepare"
|
|
313
|
+
}
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
The `prepare` script and task `sh` calls run local bins by their bare name, because `bun run` and bask both put `node_modules/.bin` on `PATH`. Git hooks and the workflows run `bunx bask` rather than `bun bask`, because `bun bask` runs `bask.ts` instead of the bask bin.
|
|
317
|
+
|
|
318
|
+
## Synced files
|
|
183
319
|
|
|
184
320
|
### bunfig
|
|
185
321
|
|
|
186
|
-
bun has no extends mechanism for `bunfig.toml`, so shared settings are synced into the project's `bunfig.toml`. The
|
|
322
|
+
bun has no extends mechanism for `bunfig.toml`, so shared settings are synced into the project's `bunfig.toml`. The `prepare` task runs the `adamhl8-bunfig` bin, which merges the shared base config (`bunfig.base.toml`) with the project's `bunfig.toml` and writes the result back. `prepare` then formats it with oxfmt. The project's values win over the base's, arrays merge by index, and a project without a `bunfig.toml` gets the base config as-is.
|
|
323
|
+
|
|
324
|
+
The base config:
|
|
187
325
|
|
|
188
|
-
|
|
326
|
+
- turns on coverage for `bun test`, leaving out test files and `__tests__` dirs
|
|
327
|
+
- only prints failing tests
|
|
328
|
+
- runs `**/*.test.ts` files concurrently
|
|
329
|
+
- skips `fixtures` and `fixture` dirs at any depth
|
|
330
|
+
- uses the isolated install linker
|
|
331
|
+
- makes `bun run` run scripts with bun instead of node
|
|
332
|
+
|
|
333
|
+
Because the merged result is written back, a change to a base value doesn't reach a project that already has that key. Delete the key from the project's `bunfig.toml` and run the sync again to pick it up.
|
|
189
334
|
|
|
190
335
|
Since the file is regenerated from the merged config, comments in `bunfig.toml` don't survive the sync. The sync can also be run manually by running `adamhl8-bunfig`.
|
|
191
336
|
|
|
192
337
|
### gitignore
|
|
193
338
|
|
|
194
|
-
git has no include mechanism for `.gitignore`, so shared entries are synced into the project's `.gitignore`. The
|
|
339
|
+
git has no include mechanism for `.gitignore`, so shared entries are synced into the project's `.gitignore`. The `prepare` task runs the `adamhl8-gitignore` bin, which keeps the shared list at the top of the file above a marker line: the first run prepends it, later runs replace everything above the marker with the current shared list, so changes propagate on package updates:
|
|
195
340
|
|
|
196
341
|
```gitignore
|
|
197
342
|
node_modules/
|
|
@@ -204,6 +349,8 @@ dist/
|
|
|
204
349
|
|
|
205
350
|
Everything below the marker is left untouched. The sync can also be run manually by running `adamhl8-gitignore`.
|
|
206
351
|
|
|
352
|
+
## Utilities
|
|
353
|
+
|
|
207
354
|
### env
|
|
208
355
|
|
|
209
356
|
Utilities for validated environment variables, exported from the `/env` subpath:
|
|
@@ -222,11 +369,55 @@ export const env = parseEnv({
|
|
|
222
369
|
|
|
223
370
|
`parseEnv` is `arkenv` with friendlier failures: invalid env prints the validation message and exits instead of throwing. `requireWhen` makes a var required while its condition is true and optional otherwise. An optional third argument supplies a fallback for when the var is unset (the fallback is exempt from validation, a set value never is).
|
|
224
371
|
|
|
372
|
+
### test
|
|
373
|
+
|
|
374
|
+
Helpers for integration tests that run real commands in temp dirs, exported from the `/test` subpath. They're built on Bun's shell, as a replacement for `execa`:
|
|
375
|
+
|
|
376
|
+
```ts
|
|
377
|
+
import { copyFixture, minimalEnv, packPackage } from "@adamhl8/configs/test"
|
|
378
|
+
|
|
379
|
+
const tarball = await packPackage(ROOT) // once per run, like in a preload's `beforeAll`
|
|
380
|
+
const { dir, run } = await copyFixture(FIXTURE, { shell: { env: minimalEnv() } })
|
|
381
|
+
await run`bun add -d ${tarball}`
|
|
382
|
+
|
|
383
|
+
const { stdout, stderr, exitCode } = await run`my-cli --version`
|
|
384
|
+
// Like Bun's `$`, a command's own settings chain before it's awaited and don't change the shell.
|
|
385
|
+
const { exitCode: failedCode } = await run`my-cli --bad-flag`.nothrow()
|
|
386
|
+
```
|
|
387
|
+
|
|
388
|
+
- `createShell(options)` returns a shell that runs commands quietly. Awaiting a command returns its `stdout` and `stderr` (with one trailing newline stripped) plus its `exitCode`.
|
|
389
|
+
- `cwd` defaults to `process.cwd()`.
|
|
390
|
+
- `env` replaces `process.env` instead of merging into it. It defaults to `process.env` without `FORCE_COLOR`, which `bask` sets in a terminal.
|
|
391
|
+
- `localBins` (default `true`) puts `node_modules/.bin` of the cwd and each of its parents first on `PATH`.
|
|
392
|
+
- `throws` (default `true`) makes a non-zero exit code throw Bun's `ShellError`, which `bun test` prints with its `exitCode`, `stdout`, and `stderr`.
|
|
393
|
+
- Each command can chain `.cwd()`, `.env()` (merged over the shell's), `.localBins()`, and `.nothrow()`.
|
|
394
|
+
- The `node` shims from `bask` and `bun run --bun` are taken off `PATH`, so `node` is always the real Node.
|
|
395
|
+
- Commands read the test runner's stdin, so add `< /dev/null` to a command that might prompt.
|
|
396
|
+
- `copyFixture(fixture, { prefix, shell })` copies a fixture dir into a temp dir and returns the `dir` plus a `run` shell bound to it. `shell` takes the `createShell` options except `cwd`.
|
|
397
|
+
- `packPackage(root)` runs `bun tsdown` when `root` has a `tsdown.config.ts`, then packs it with `bun pm pack --ignore-scripts` into a temp dir, and returns the tarball path.
|
|
398
|
+
- `minimalEnv(extra)` returns just `PATH` and `HOME`, plus `extra`.
|
|
399
|
+
- `makeTempDir(prefix)` makes a temp dir that's removed after the test run. `copyFixture` and `packPackage` use it.
|
|
400
|
+
|
|
401
|
+
The temp dirs are removed by a preload, which each project adds to its `bunfig.toml`:
|
|
402
|
+
|
|
403
|
+
```toml
|
|
404
|
+
[test]
|
|
405
|
+
preload = ["@adamhl8/configs/test/preload"]
|
|
406
|
+
```
|
|
407
|
+
|
|
408
|
+
A project with its own preload imports it at the top of that file instead, so all of its test setup stays in one place:
|
|
409
|
+
|
|
410
|
+
```ts
|
|
411
|
+
import "@adamhl8/configs/test/preload"
|
|
412
|
+
```
|
|
413
|
+
|
|
414
|
+
It isn't in the shared bunfig base because `adamhl8-bunfig` merges arrays by index, so a project's own `preload` would replace it.
|
|
415
|
+
|
|
225
416
|
## GitHub Actions
|
|
226
417
|
|
|
227
|
-
This repo hosts three reusable workflows you can call from other projects instead of copy/pasting them. The calling project must use `bun`, have a `bask.ts` that re-exports the base tasks (see [bask](#bask)), and have a commitlint config (e.g. via these configs). The workflows set up bun themselves.
|
|
418
|
+
This repo hosts three reusable workflows you can call from other projects instead of copy/pasting them. The calling project must use `bun`, have a `bask.ts` that re-exports the base tasks (see [bask tasks](#bask-tasks)), and have a commitlint config (e.g. via these configs). The workflows set up bun, actionlint, and OpenTofu themselves.
|
|
228
419
|
|
|
229
|
-
- `ci.yml`: runs `build`
|
|
420
|
+
- `ci.yml`: runs `build` on pushes and PRs, and lints the commit message on pushes and the PR title on PRs
|
|
230
421
|
- `update-deps.yml`: weekly `bump-deps` run that opens a dependency-update PR
|
|
231
422
|
- `release.yml`: manually dispatched release where git-cliff sets the version, then publishes to npm and cuts a GitHub release (commit and tag signed)
|
|
232
423
|
|
|
@@ -241,11 +432,14 @@ on:
|
|
|
241
432
|
push:
|
|
242
433
|
branches: [main]
|
|
243
434
|
pull_request:
|
|
435
|
+
types: [opened, edited, synchronize, reopened]
|
|
244
436
|
jobs:
|
|
245
437
|
ci:
|
|
246
438
|
uses: adamhl8/configs/.github/workflows/ci.yml@main
|
|
247
439
|
```
|
|
248
440
|
|
|
441
|
+
On a PR, CI lints the PR title instead of the PR's commits, because squash merges (the only merge type the [GitHub repo settings](#github-repo-settings) allow) use the title as the commit message. The `edited` type reruns the title check when the title changes. An edit skips the build, because it only changes the title or body.
|
|
442
|
+
|
|
249
443
|
The `bunx bask build` step runs with `GITHUB_TOKEN` set, for builds that call the GitHub API. It comes from the optional `GH_TOKEN` secret (see [Secrets](#secrets)): the names differ because Actions secrets can't be named `GITHUB_*`, so a build reading `GITHUB_TOKEN` can't be fed by a secret of the same name.
|
|
250
444
|
|
|
251
445
|
When the secret is unset it falls back to the workflow's auto-provisioned token, so fork PRs (which receive no secrets) still build. To supply your own token, pass it. Prefer naming it over `secrets: inherit` here: CI runs on every PR, so it shouldn't be handed the release and deploy secrets it never uses.
|
|
@@ -279,7 +473,7 @@ jobs:
|
|
|
279
473
|
|
|
280
474
|
Manually dispatched. `release-it` uses git-cliff (via `release-it-git-cliff`, see [release-it](#release-it)) to compute the next version from the commits, then bumps `package.json`, regenerates the changelog, commits and tags (both SSH-signed), publishes to npm, and cuts a GitHub release. There is no automatic trigger, so run it when a release is ready (the `release` task just does `gh workflow run release.yml`). A dispatch with no releasable commits fails fast because the plugin finds nothing to release.
|
|
281
475
|
|
|
282
|
-
Needs the `
|
|
476
|
+
Needs the `CI_SIGNING_KEY` secret, and `NPM_CI_TOKEN` to publish to npm (see [Secrets](#secrets)). The workflow installs git-cliff and runs the `release-run` task: `release-it --ci`.
|
|
283
477
|
|
|
284
478
|
```yaml
|
|
285
479
|
# .github/workflows/release.yml
|
|
@@ -294,6 +488,21 @@ jobs:
|
|
|
294
488
|
secrets: inherit
|
|
295
489
|
```
|
|
296
490
|
|
|
491
|
+
Pass `before-release` to run shell commands after the install, just before the release, such as installing system tools the build needs:
|
|
492
|
+
|
|
493
|
+
```yaml
|
|
494
|
+
jobs:
|
|
495
|
+
release:
|
|
496
|
+
permissions:
|
|
497
|
+
contents: write
|
|
498
|
+
uses: adamhl8/configs/.github/workflows/release.yml@main
|
|
499
|
+
with:
|
|
500
|
+
before-release: |
|
|
501
|
+
sudo apt update
|
|
502
|
+
sudo apt install -y fontforge
|
|
503
|
+
secrets: inherit
|
|
504
|
+
```
|
|
505
|
+
|
|
297
506
|
#### Docker
|
|
298
507
|
|
|
299
508
|
Pass `docker-image` to build the repo's `Dockerfile` and push it to `ghcr.io/<owner>/<docker-image>:latest` once the release lands. The image name is separate from the repo name, since they often differ. Omit the input and no image is built.
|
|
@@ -318,19 +527,50 @@ jobs:
|
|
|
318
527
|
|
|
319
528
|
### Secrets
|
|
320
529
|
|
|
321
|
-
|
|
530
|
+
The [GitHub repo settings](#github-repo-settings) module sets these on each repo that uses the workflows. To set them by hand, use Settings -> Secrets and variables -> Actions.
|
|
322
531
|
|
|
323
|
-
| Secret | Used by
|
|
324
|
-
| ---------------- |
|
|
325
|
-
| `CI_TOKEN` | `update-deps.yml`
|
|
326
|
-
| `GH_TOKEN` | `ci.yml`, `release.yml`
|
|
327
|
-
| `NPM_CI_TOKEN` | `release.yml`
|
|
328
|
-
| `CI_SIGNING_KEY` | `release.yml`
|
|
532
|
+
| Secret | Used by | What it is |
|
|
533
|
+
| ---------------- | -------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
534
|
+
| `CI_TOKEN` | `update-deps.yml`, `release.yml` | PAT with `contents` and `pull-requests` write, so the opened PR triggers CI. `release.yml` passes it to the release step as `CI_TOKEN`, for release hooks that need it. |
|
|
535
|
+
| `GH_TOKEN` | `ci.yml`, `release.yml` | Optional. PAT for a build that calls the GitHub API. Reaches a `ci.yml` build as `GITHUB_TOKEN`, and a `release.yml` docker build as the `GH_TOKEN` BuildKit secret. Unset, the `ci.yml` build falls back to the automatic token. |
|
|
536
|
+
| `NPM_CI_TOKEN` | `release.yml` | npm automation token with publish access |
|
|
537
|
+
| `CI_SIGNING_KEY` | `release.yml` | Private SSH key that signs the release commit and tag. Add the matching public key to your GitHub account as a Signing Key so the signature verifies as you. Use a dedicated, passphrase-less key, not your personal auth key. |
|
|
329
538
|
|
|
330
539
|
`GITHUB_TOKEN` is provided automatically. The release wrapper grants it `contents: write` to push the release commit and tag and to create the GitHub release.
|
|
331
540
|
|
|
332
|
-
##
|
|
541
|
+
## GitHub repo settings
|
|
542
|
+
|
|
543
|
+
The `github` OpenTofu module manages a repo's GitHub settings and its Actions [secrets](#secrets). Use it from the project's `github.tofu`:
|
|
544
|
+
|
|
545
|
+
```hcl
|
|
546
|
+
# github.tofu
|
|
547
|
+
terraform {
|
|
548
|
+
backend "s3" {
|
|
549
|
+
profile = "adamhl8"
|
|
550
|
+
bucket = "<state-bucket>"
|
|
551
|
+
key = "adamhl8/<repo>.tfstate"
|
|
552
|
+
region = "<region>"
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
module "github" {
|
|
557
|
+
source = "./node_modules/@adamhl8/configs/dist/tofu/github"
|
|
558
|
+
repo_name = "<repo>"
|
|
559
|
+
actions_secrets = {
|
|
560
|
+
NPM_CI_TOKEN = true
|
|
561
|
+
}
|
|
562
|
+
repo_settings = {
|
|
563
|
+
visibility = "public"
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
```
|
|
567
|
+
|
|
568
|
+
The repo's description, homepage, and topics come from the `description`, `homepage`, and `keywords` in `package.json`. A homepage that points at the repo itself is left out. The repo only allows squash merges, which use the PR title as the commit message, and deletes branches once they're merged. Secret scanning, push protection, and vulnerability alerts are on.
|
|
569
|
+
|
|
570
|
+
`actions_secrets` picks the secrets to set. `CI_SIGNING_KEY` and `CI_TOKEN` are on by default, and `NPM_CI_TOKEN` and `GH_TOKEN` are off. `additional_secrets` adds other secrets by name. Each value is read from `~/homelab/secrets/credentials.yaml` (a sops file) under the secret's lowercased name. A secret on the repo that the module doesn't manage shows up as a warning in `tofu plan`, naming the secrets, and doesn't fail the plan.
|
|
571
|
+
|
|
572
|
+
The `prepare` task runs `tofu init -upgrade`, and the `tofu-check` task (which `build` runs) checks for drift with `tofu plan`. See [bask tasks](#bask-tasks) for when they run.
|
|
333
573
|
|
|
334
|
-
|
|
574
|
+
## Developing this repo
|
|
335
575
|
|
|
336
576
|
bun links a dependency's `package.json` bin executables into the local `node_modules/.bin`, but not the bins of the package being developed itself. This repo depends on itself (`"@adamhl8/configs": "file:."`) so that its own bins can be run directly, e.g. `adamhl8-bunfig` instead of `src/adamhl8-bunfig/index.ts`. That's also why this repo's `bask.ts` runs `tsdown` before the `prepare` task: the bins point at `dist/`, so those builds need to be available.
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
[test]
|
|
2
|
-
pathIgnorePatterns = ["fixtures/**", "fixture/**"]
|
|
2
|
+
pathIgnorePatterns = ["**/fixtures/**", "**/fixture/**"]
|
|
3
3
|
coverage = true
|
|
4
4
|
coverageSkipTestFiles = true
|
|
5
|
-
coveragePathIgnorePatterns = ["
|
|
5
|
+
coveragePathIgnorePatterns = ["**/__tests__/**"]
|
|
6
6
|
concurrentTestGlob = "**/*.test.ts"
|
|
7
7
|
onlyFailures = true
|
|
8
8
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { OptionalMergeConfigFn } from "../merge-config/merge-config.js";
|
|
2
2
|
import { KnipConfig } from "knip";
|
|
3
3
|
export declare const knipConfig: OptionalMergeConfigFn<KnipConfig, {
|
|
4
|
-
readonly project: ["**/*"];
|
|
4
|
+
readonly project: ["**/*", "!**/fixtures/**", "!**/fixture/**"];
|
|
5
5
|
readonly bun: {
|
|
6
6
|
readonly entry: ["**/*.test.ts", "bask.ts"];
|
|
7
7
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"knip.base.d.ts","names":["_$_merge_config_merge_config_ts0.OptionalMergeConfigFn"],"sources":["../../src/configs/knip.base.ts"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"knip.base.d.ts","names":["_$_merge_config_merge_config_ts0.OptionalMergeConfigFn"],"sources":["../../src/configs/knip.base.ts"],"mappings":";;qBAca,YAAUA,sBAAA;;;aAJnB"}
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { createMergeConfigFn } from "../merge-config/merge-config.js";
|
|
2
2
|
const knipConfig = createMergeConfigFn({
|
|
3
|
-
project: [
|
|
3
|
+
project: [
|
|
4
|
+
"**/*",
|
|
5
|
+
"!**/fixtures/**",
|
|
6
|
+
"!**/fixture/**"
|
|
7
|
+
],
|
|
4
8
|
bun: { entry: ["**/*.test.ts", "bask.ts"] }
|
|
5
9
|
});
|
|
6
10
|
export { knipConfig };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"knip.base.js","names":[],"sources":["../../src/configs/knip.base.ts"],"sourcesContent":["import type { KnipConfig } from \"knip\"\n\nimport { createMergeConfigFn } from \"#merge-config/merge-config.ts\"\n\nconst baseConfig = {\n project: [\"**/*\"],\n bun: {\n // List `bask.ts` because bask loads it by path and nothing imports it.\n // Add it here because a top-level `entry` replaces knip's default entries.\n entry: [\"**/*.test.ts\", \"bask.ts\"],\n },\n} as const satisfies KnipConfig\n\nexport const knipConfig = createMergeConfigFn<KnipConfig, typeof baseConfig>(baseConfig)\n"],"mappings":";
|
|
1
|
+
{"version":3,"file":"knip.base.js","names":[],"sources":["../../src/configs/knip.base.ts"],"sourcesContent":["import type { KnipConfig } from \"knip\"\n\nimport { createMergeConfigFn } from \"#merge-config/merge-config.ts\"\n\nconst baseConfig = {\n // Exclude fixtures with negated `project` globs because knip hints to remove an `ignore` glob that hides nothing.\n project: [\"**/*\", \"!**/fixtures/**\", \"!**/fixture/**\"],\n bun: {\n // List `bask.ts` because bask loads it by path and nothing imports it.\n // Add it here because a top-level `entry` replaces knip's default entries.\n entry: [\"**/*.test.ts\", \"bask.ts\"],\n },\n} as const satisfies KnipConfig\n\nexport const knipConfig = createMergeConfigFn<KnipConfig, typeof baseConfig>(baseConfig)\n"],"mappings":";AAcA,MAAa,aAAa,oBAAmD;CAR3E,SAAS;EAAC;EAAQ;EAAmB;CAAgB;CACrD,KAAK,EAGH,OAAO,CAAC,gBAAgB,SAAS,EACnC;AAG2E,CAAU"}
|
|
@@ -41,6 +41,13 @@ export declare const oxlintConfig: OptionalMergeConfigFn<OxlintConfig, {
|
|
|
41
41
|
readonly allowArrowFunctions: true;
|
|
42
42
|
}];
|
|
43
43
|
};
|
|
44
|
+
} | {
|
|
45
|
+
readonly files: ["**/fixtures/**", "**/fixture/**"];
|
|
46
|
+
readonly rules: {
|
|
47
|
+
readonly "clean-modules/require-import-extensions": "off";
|
|
48
|
+
readonly "clean-modules/require-subpath-imports": "off";
|
|
49
|
+
readonly "import/no-default-export": "off";
|
|
50
|
+
};
|
|
44
51
|
} | (Omit<OxlintOverride, "rules"> & {
|
|
45
52
|
rules?: PluginRules;
|
|
46
53
|
}))[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"oxlint.base.d.ts","names":["_$_merge_config_merge_config_ts0.OptionalMergeConfigFn"],"sources":["../../src/configs/oxlint.base.ts"],"mappings":";;KAmBK,cAAc,eAAe;
|
|
1
|
+
{"version":3,"file":"oxlint.base.d.ts","names":["_$_merge_config_merge_config_ts0.OptionalMergeConfigFn"],"sources":["../../src/configs/oxlint.base.ts"],"mappings":";;KAmBK,cAAc,eAAe;qBA4UrB,cAxU4CA,sBAwUhC;;aAhNrB;aACA;aACA;;;aAIA;aACA;aACA;aACA;aACA;aACA;aACA;;;;;;;eA+BI;;;;;eAMA;eACA;;;;;eAMA;;;;;;;;;;;;eAYA;eACA;eACA;;;IA9LiD,QAAA;;;;;;eAwMF;;;eAI9B;eAA2C;;;eAER;eAA4B;eAAiB;;;;iBAKxF;iBAAiB;;;;;;IAON;IACX;IACQ;IACG;IACX;IACa;IACR;IACJ;IACC;IACS;IACF;IACF;IACL;IACI;IACL;IACF;IACI;IACK;IACV;IACA;IACM;IACD;IACH;IAEU;IACC;IACG;IACD;IACE;IACG;IACC;IAET;IACE;IAED;IACD;IACP;IACW;IAEL;IACM;IACK;IAEO;IACR;IACjB;IACI;IACa;IACT;IACE;IACE;IACW;IACV;IACF;IACZ;IAEkB;IACY;IACC;IACC;IACL;IAEF;IACE;IACH;IACX;IACI;IACD;IAEX;IACmB;IACG;IACN;IACO;IACT;IACJ;IACC;IACP;IACQ"}
|
|
@@ -178,6 +178,14 @@ const nativeConfig = {
|
|
|
178
178
|
"declaration",
|
|
179
179
|
{ allowArrowFunctions: true }
|
|
180
180
|
] }
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
files: ["**/fixtures/**", "**/fixture/**"],
|
|
184
|
+
rules: {
|
|
185
|
+
"clean-modules/require-import-extensions": "off",
|
|
186
|
+
"clean-modules/require-subpath-imports": "off",
|
|
187
|
+
"import/no-default-export": "off"
|
|
188
|
+
}
|
|
181
189
|
}
|
|
182
190
|
],
|
|
183
191
|
rules: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"oxlint.base.js","names":["directiveCommentsPluginRules","regexpPluginRules"],"sources":["../../src/configs/oxlint.base.ts"],"sourcesContent":["import cleanModulesPlugin from \"@adamhl8/eslint-plugin-clean-modules\"\nimport e18ePlugin from \"@e18e/eslint-plugin\"\nimport bunismsPlugin from \"eslint-plugin-bunisms\"\nimport honoPlugin from \"eslint-plugin-hono\"\nimport reactWebApiPlugin from \"eslint-plugin-react-web-api\"\nimport reactEffectPlugin from \"eslint-plugin-react-you-might-not-need-an-effect\"\nimport { rules as regexpPluginRules } from \"eslint-plugin-regexp\"\nimport type { DummyRule, OxlintConfig, OxlintOverride } from \"oxlint\"\nimport { rules as directiveCommentsPluginRules } from \"oxlint-plugin-directive-comments\"\nimport tailwindcssPlugin from \"oxlint-tailwindcss\"\n\nimport { createMergeConfigFn } from \"#merge-config/merge-config.ts\"\nimport { readProjectPackageJson, resolvePackagePath, resolveProjectTailwind } from \"#utils.ts\"\n\n/** Sets every rule in a JS plugin to `severity`, because `categories` doesn't apply to JS plugins. */\nconst setAllPluginRules = (name: string, rules: Record<string, unknown>, severity: \"error\" | \"off\") =>\n Object.fromEntries(Object.keys(rules).map((rule) => [`${name}/${rule}`, severity] as const))\n\n// Type plugin rules with oxlint's generic `DummyRule` because its per-rule config types aren't exported, which breaks declaration emit.\ntype PluginRules = Record<string, DummyRule>\n\n/** A JS plugin and the slice of oxlint config that goes with it. Each one is merged into the base config. */\ninterface PluginPart extends Omit<OxlintConfig, \"jsPlugins\" | \"overrides\" | \"rules\"> {\n overrides?: (Omit<OxlintOverride, \"rules\"> & { rules?: PluginRules })[]\n rules?: PluginRules\n /** Loads the plugin only when true. Defaults to true. */\n enabled?: boolean\n package: string\n /** The plugin's rule definitions, used to set every rule to \"error\". The part's own `rules` then take precedence. */\n pluginRules: Record<string, unknown> | undefined\n}\n\nconst { dependencies, engines } = readProjectPackageJson()\nconst tailwindStylesheet = resolveProjectTailwind()\n\n// Key each part by the rule namespace its plugin registers.\nconst plugins: Record<string, PluginPart> = {\n bunisms: {\n overrides: [\n {\n excludeFiles: [\"src/**/__tests__/**\", \"src/**/*.test.{ts,tsx}\", \"src/**/test-setup.ts\", \"src/**/test-utils.ts\"],\n // Turn off Bun suggestions in Node runtime code. Tests and tooling still run on Bun.\n files: engines.has(\"node\") ? [\"src/**\"] : [],\n rules: setAllPluginRules(\"bunisms\", bunismsPlugin.rules, \"off\"),\n },\n ],\n package: \"eslint-plugin-bunisms\",\n pluginRules: bunismsPlugin.rules,\n rules: {\n \"bunisms/prefer-mock-restore-in-after-each\": \"off\", // `test-setup.ts` preloads restore mocks globally\n },\n },\n \"clean-modules\": {\n package: \"@adamhl8/eslint-plugin-clean-modules\",\n pluginRules: cleanModulesPlugin.rules,\n },\n \"directive-comments\": {\n package: \"oxlint-plugin-directive-comments\",\n pluginRules: directiveCommentsPluginRules,\n rules: {\n \"directive-comments/disable-enable-pair\": [\"error\", { allowWholeFile: true }],\n \"directive-comments/no-use\": \"off\", // bans every directive comment\n },\n },\n e18e: {\n package: \"@e18e/eslint-plugin\",\n pluginRules: e18ePlugin.rules,\n rules: {\n \"e18e/no-indexof-equality\": \"off\", // needs type information, which JS plugins don't get\n \"e18e/no-spread-in-reduce\": \"off\", // `oxc/no-accumulating-spread` covers this\n \"e18e/prefer-array-at\": \"off\", // `unicorn/prefer-at` covers this\n \"e18e/prefer-array-some\": \"off\", // `unicorn/prefer-array-some` covers this\n \"e18e/prefer-array-to-reversed\": \"off\", // `unicorn/no-array-reverse` covers this\n \"e18e/prefer-array-to-sorted\": \"off\", // `unicorn/no-array-sort` covers this\n \"e18e/prefer-date-now\": \"off\", // `unicorn/prefer-date-now` covers this\n \"e18e/prefer-exponentiation-operator\": \"off\", // `prefer-exponentiation-operator` covers this\n \"e18e/prefer-flatmap-over-map-flat\": \"off\", // `unicorn/prefer-array-flat-map` covers this\n \"e18e/prefer-includes\": \"off\", // `unicorn/prefer-includes` covers this\n \"e18e/prefer-nullish-coalescing\": \"off\", // `typescript/prefer-nullish-coalescing` covers this\n \"e18e/prefer-object-has-own\": \"off\", // `prefer-object-has-own` covers this\n \"e18e/prefer-slice-over-split-index\": \"off\",\n \"e18e/prefer-spread-syntax\": \"off\", // `unicorn/prefer-spread` and `prefer-object-spread` cover this\n },\n },\n hono: {\n enabled: dependencies.has(\"hono\"),\n package: \"eslint-plugin-hono\",\n pluginRules: honoPlugin.rules,\n rules: {\n \"hono/no-process-env\": \"off\", // tools and tests legitimately read the raw environment\n },\n },\n \"react-web-api\": {\n enabled: dependencies.has(\"react\"),\n package: \"eslint-plugin-react-web-api\",\n pluginRules: reactWebApiPlugin.rules,\n },\n \"react-you-might-not-need-an-effect\": {\n enabled: dependencies.has(\"react\"),\n package: \"eslint-plugin-react-you-might-not-need-an-effect\",\n pluginRules: reactEffectPlugin.rules,\n rules: {\n \"react-you-might-not-need-an-effect/no-adjust-state-on-prop-change\": \"off\", // `react/set-state-in-effect` covers this\n \"react-you-might-not-need-an-effect/no-chain-state-updates\": \"off\", // `react/set-state-in-effect` covers this\n \"react-you-might-not-need-an-effect/no-derived-state\": \"off\", // `react/set-state-in-effect` covers this\n \"react-you-might-not-need-an-effect/no-initialize-state\": \"off\", // `react/set-state-in-effect` covers this\n \"react-you-might-not-need-an-effect/no-reset-all-state-on-prop-change\": \"off\", // `react/set-state-in-effect` covers this\n },\n },\n regexp: {\n package: \"eslint-plugin-regexp\",\n pluginRules: regexpPluginRules,\n rules: {\n \"regexp/letter-case\": [\"error\", { hexadecimalEscape: \"uppercase\", unicodeEscape: \"uppercase\" }], // match `unicorn/escape-case`\n \"regexp/no-control-character\": \"off\", // `no-control-regex` covers this\n \"regexp/no-empty-character-class\": \"off\", // `no-empty-character-class` covers this\n \"regexp/no-invalid-regexp\": \"off\", // `no-invalid-regexp` covers this\n \"regexp/no-super-linear-move\": \"off\",\n \"regexp/no-useless-escape\": \"off\", // `no-useless-escape` covers this\n \"regexp/prefer-named-capture-group\": \"off\", // `prefer-named-capture-group` covers this\n \"regexp/require-unicode-regexp\": \"off\", // `require-unicode-regexp` covers this\n \"regexp/require-unicode-sets-regexp\": \"off\", // `require-unicode-regexp` covers this\n \"regexp/sort-alternatives\": \"off\",\n },\n },\n tailwindcss: {\n // Load the Tailwind plugin only with a stylesheet because it reports every class string without one.\n enabled: Boolean(tailwindStylesheet),\n package: \"oxlint-tailwindcss\",\n pluginRules: tailwindcssPlugin.rules,\n rules: {\n \"tailwindcss/enforce-consistent-line-wrapping\": \"off\", // oxfmt handles line width\n \"tailwindcss/enforce-logical\": \"off\", // conflicts with `tailwindcss/enforce-physical`\n \"tailwindcss/enforce-sort-order\": \"off\", // oxfmt sorts classes\n \"tailwindcss/max-class-count\": \"off\",\n },\n // Keep `entryPoint` relative because the plugin resolves it against the directory of the project's oxlint config.\n settings: { tailwindcss: { entryPoint: tailwindStylesheet } },\n },\n}\n\nconst nativeConfig = {\n options: {\n reportUnusedDisableDirectives: \"error\",\n typeAware: true,\n typeCheck: true,\n },\n\n categories: {\n correctness: \"error\",\n nursery: \"error\",\n pedantic: \"error\",\n perf: \"error\",\n restriction: \"error\",\n style: \"error\",\n suspicious: \"error\",\n },\n\n plugins: [\n \"eslint\",\n \"react\",\n \"unicorn\",\n \"typescript\",\n \"oxc\",\n \"import\",\n \"jsdoc\",\n \"vitest\",\n \"jsx-a11y\",\n \"react-perf\",\n \"promise\",\n \"node\",\n ],\n\n overrides: [\n {\n files: [\n \".release-it.ts\",\n \"astro.config.ts\",\n \"commitlint.config.ts\",\n \"knip.ts\",\n \"oxfmt.config.ts\",\n \"oxlint.config.ts\",\n \"prisma.config.ts\",\n \"tsdown.config.ts\",\n ],\n rules: {\n \"import/no-default-export\": \"off\",\n },\n },\n {\n files: [\"bask.ts\"],\n rules: {\n \"clean-modules/require-direct-exports\": \"off\",\n \"import/export\": \"off\",\n },\n },\n {\n files: [\".release-it.ts\"],\n rules: {\n \"no-template-curly-in-string\": \"off\",\n },\n },\n {\n files: [\"**/*.tsx\"],\n rules: {\n \"func-style\": [\"error\", \"declaration\", { allowArrowFunctions: true }],\n },\n },\n ],\n\n rules: {\n /* Modified rules */\n\n curly: [\"error\", \"multi-or-nest\"],\n \"func-style\": [\"error\", \"expression\"],\n \"require-unicode-regexp\": [\"error\", { requireFlag: \"v\" }],\n\n \"react/function-component-definition\": [\n \"error\",\n { namedComponents: \"function-declaration\", unnamedComponents: \"arrow-function\" },\n ],\n \"react/jsx-curly-brace-presence\": [\"error\", { children: \"never\", propElementValues: \"always\", props: \"never\" }],\n\n \"unicorn/filename-case\": [\n \"error\",\n {\n cases: { kebabCase: true, pascalCase: true },\n },\n ],\n \"unicorn/no-useless-undefined\": [\"error\", { checkArguments: false }],\n\n /* Disabled rules */\n\n \"capitalized-comments\": \"off\",\n \"id-length\": \"off\",\n \"init-declarations\": \"off\",\n \"max-classes-per-file\": \"off\",\n \"max-lines\": \"off\",\n \"max-lines-per-function\": \"off\",\n \"max-statements\": \"off\",\n \"no-console\": \"off\",\n \"no-continue\": \"off\",\n \"no-duplicate-imports\": \"off\",\n \"no-inline-comments\": \"off\",\n \"no-magic-numbers\": \"off\",\n \"no-plusplus\": \"off\",\n \"no-regex-spaces\": \"off\", // `regexp/prefer-quantifier` covers this\n \"no-ternary\": \"off\",\n \"no-undef\": \"off\",\n \"no-undefined\": \"off\",\n \"no-useless-return\": \"off\",\n \"no-void\": \"off\",\n \"one-var\": \"off\",\n \"require-await\": \"off\",\n \"sort-imports\": \"off\",\n \"sort-keys\": \"off\",\n\n \"import/exports-last\": \"off\",\n \"import/group-exports\": \"off\",\n \"import/max-dependencies\": \"off\",\n \"import/no-named-export\": \"off\",\n \"import/no-nodejs-modules\": \"off\",\n \"import/no-unassigned-import\": \"off\",\n \"import/prefer-default-export\": \"off\",\n\n \"jsdoc/require-param\": \"off\",\n \"jsdoc/require-returns\": \"off\",\n\n \"node/callback-return\": \"off\",\n \"node/no-process-env\": \"off\", // tools and tests legitimately read the raw environment\n \"node/no-sync\": \"off\",\n \"node/no-top-level-await\": \"off\",\n\n \"oxc/no-async-await\": \"off\",\n \"oxc/no-optional-chaining\": \"off\",\n \"oxc/no-rest-spread-properties\": \"off\",\n\n \"react/exhaustive-effect-dependencies\": \"off\", // `react/exhaustive-deps` covers this\n \"react/forbid-component-props\": \"off\",\n \"react/hooks\": \"off\", // `react/rules-of-hooks` covers this\n \"react/invariant\": \"off\",\n \"react/jsx-filename-extension\": \"off\",\n \"react/jsx-max-depth\": \"off\",\n \"react/jsx-no-literals\": \"off\",\n \"react/memo-dependencies\": \"off\", // `react/exhaustive-deps` covers this\n \"react/no-deriving-state-in-effects\": \"off\", // `react/set-state-in-effect` covers this\n \"react/react-in-jsx-scope\": \"off\",\n \"react/rule-suppression\": \"off\",\n \"react/todo\": \"off\",\n\n \"typescript/consistent-return\": \"off\",\n \"typescript/explicit-function-return-type\": \"off\",\n \"typescript/explicit-module-boundary-types\": \"off\",\n \"typescript/prefer-readonly-parameter-types\": \"off\",\n \"typescript/strict-boolean-expressions\": \"off\",\n\n \"unicorn/no-array-callback-reference\": \"off\",\n \"unicorn/no-array-method-this-argument\": \"off\",\n \"unicorn/no-await-expression-member\": \"off\",\n \"unicorn/no-process-exit\": \"off\",\n \"unicorn/number-literal-case\": \"off\",\n \"unicorn/switch-case-braces\": \"off\",\n\n \"vitest/no-hooks\": \"off\",\n \"vitest/no-importing-vitest-globals\": \"off\",\n \"vitest/prefer-describe-function-title\": \"off\",\n \"vitest/prefer-expect-assertions\": \"off\",\n \"vitest/prefer-importing-vitest-globals\": \"off\",\n \"vitest/prefer-lowercase-title\": \"off\",\n \"vitest/prefer-to-be-falsy\": \"off\",\n \"vitest/prefer-to-be-truthy\": \"off\",\n \"vitest/require-hook\": \"off\", // reenable when false positives are fixed?\n \"vitest/require-test-timeout\": \"off\",\n },\n} as const satisfies OxlintConfig\n\nconst enabledPluginEntries = Object.entries(plugins).filter(([, plugin]) => plugin.enabled ?? true)\nconst enabledPlugins = enabledPluginEntries.map(([, plugin]) => plugin)\n// Resolve JS plugins to absolute paths so consumers load them from this package's own deps.\nconst resolvedPluginPackages = enabledPlugins.map((plugin) => resolvePackagePath(plugin.package))\nconst pluginOverrides = enabledPlugins.flatMap((plugin) => plugin.overrides ?? [])\nconst pluginSettings = Object.fromEntries(enabledPlugins.flatMap((plugin) => Object.entries(plugin.settings ?? {})))\n\n/** Lists a plugin's rules as entries */\nconst toPluginRuleEntries = ([name, { pluginRules = {}, rules }]: [string, PluginPart]) => {\n const defaultRules = setAllPluginRules(name, pluginRules, \"error\")\n const pluginRuleEntries = Object.entries({ ...defaultRules, ...rules })\n return pluginRuleEntries\n}\n\nconst resolvedPluginRules = Object.fromEntries(enabledPluginEntries.flatMap(toPluginRuleEntries))\n\nconst baseConfig = {\n ...nativeConfig,\n jsPlugins: resolvedPluginPackages,\n overrides: [...nativeConfig.overrides, ...pluginOverrides],\n rules: {\n ...resolvedPluginRules,\n ...nativeConfig.rules,\n },\n settings: pluginSettings,\n} satisfies OxlintConfig\n\nexport const oxlintConfig = createMergeConfigFn<OxlintConfig, typeof baseConfig>(baseConfig)\n"],"mappings":";;;;;;;;;;;;;AAeA,MAAM,qBAAqB,MAAc,OAAgC,aACvE,OAAO,YAAY,OAAO,KAAK,KAAK,CAAC,CAAC,KAAK,SAAS,CAAC,GAAG,KAAK,GAAG,QAAQ,QAAQ,CAAU,CAAC;AAgB7F,MAAM,EAAE,cAAc,YAAY,uBAAuB;AACzD,MAAM,qBAAqB,uBAAu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,iBAAiB,qBAAqB,KAAK,GAAG,YAAY,MAAM;AAEtE,MAAM,yBAAyB,eAAe,KAAK,WAAW,mBAAmB,OAAO,OAAO,CAAC;AAChG,MAAM,kBAAkB,eAAe,SAAS,WAAW,OAAO,aAAa,CAAC,CAAC;AACjF,MAAM,iBAAiB,OAAO,YAAY,eAAe,SAAS,WAAW,OAAO,QAAQ,OAAO,YAAY,CAAC,CAAC,CAAC,CAAC;;AAGnH,MAAM,uBAAuB,CAAC,MAAM,EAAE,cAAc,CAAC,GAAG,aAAmC;CACzF,MAAM,eAAe,kBAAkB,MAAM,aAAa,OAAO;CAEjE,OAD0B,OAAO,QAAQ;EAAE,GAAG;EAAc,GAAG;CAAM,CAC9C;AACzB;AAEA,MAAM,sBAAsB,OAAO,YAAY,qBAAqB,QAAQ,mBAAmB,CAAC;AAEhG,MAAM,aAAa;CACjB,GAAG;CACH,WAAW;CACX,WAAW,CAAC,GAAG,aAAa,WAAW,GAAG,eAAe;CACzD,OAAO;EACL,GAAG;EACH,GAAG,aAAa;CAClB;CACA,UAAU;AACZ;AAEA,MAAa,eAAe,oBAAqD,UAAU"}
|
|
1
|
+
{"version":3,"file":"oxlint.base.js","names":["directiveCommentsPluginRules","regexpPluginRules"],"sources":["../../src/configs/oxlint.base.ts"],"sourcesContent":["import cleanModulesPlugin from \"@adamhl8/eslint-plugin-clean-modules\"\nimport e18ePlugin from \"@e18e/eslint-plugin\"\nimport bunismsPlugin from \"eslint-plugin-bunisms\"\nimport honoPlugin from \"eslint-plugin-hono\"\nimport reactWebApiPlugin from \"eslint-plugin-react-web-api\"\nimport reactEffectPlugin from \"eslint-plugin-react-you-might-not-need-an-effect\"\nimport { rules as regexpPluginRules } from \"eslint-plugin-regexp\"\nimport type { DummyRule, OxlintConfig, OxlintOverride } from \"oxlint\"\nimport { rules as directiveCommentsPluginRules } from \"oxlint-plugin-directive-comments\"\nimport tailwindcssPlugin from \"oxlint-tailwindcss\"\n\nimport { createMergeConfigFn } from \"#merge-config/merge-config.ts\"\nimport { readProjectPackageJson, resolvePackagePath, resolveProjectTailwind } from \"#utils.ts\"\n\n/** Sets every rule in a JS plugin to `severity`, because `categories` doesn't apply to JS plugins. */\nconst setAllPluginRules = (name: string, rules: Record<string, unknown>, severity: \"error\" | \"off\") =>\n Object.fromEntries(Object.keys(rules).map((rule) => [`${name}/${rule}`, severity] as const))\n\n// Type plugin rules with oxlint's generic `DummyRule` because its per-rule config types aren't exported, which breaks declaration emit.\ntype PluginRules = Record<string, DummyRule>\n\n/** A JS plugin and the slice of oxlint config that goes with it. Each one is merged into the base config. */\ninterface PluginPart extends Omit<OxlintConfig, \"jsPlugins\" | \"overrides\" | \"rules\"> {\n overrides?: (Omit<OxlintOverride, \"rules\"> & { rules?: PluginRules })[]\n rules?: PluginRules\n /** Loads the plugin only when true. Defaults to true. */\n enabled?: boolean\n package: string\n /** The plugin's rule definitions, used to set every rule to \"error\". The part's own `rules` then take precedence. */\n pluginRules: Record<string, unknown> | undefined\n}\n\nconst { dependencies, engines } = readProjectPackageJson()\nconst tailwindStylesheet = resolveProjectTailwind()\n\n// Key each part by the rule namespace its plugin registers.\nconst plugins: Record<string, PluginPart> = {\n bunisms: {\n overrides: [\n {\n excludeFiles: [\"src/**/__tests__/**\", \"src/**/*.test.{ts,tsx}\", \"src/**/test-setup.ts\", \"src/**/test-utils.ts\"],\n // Turn off Bun suggestions in Node runtime code. Tests and tooling still run on Bun.\n files: engines.has(\"node\") ? [\"src/**\"] : [],\n rules: setAllPluginRules(\"bunisms\", bunismsPlugin.rules, \"off\"),\n },\n ],\n package: \"eslint-plugin-bunisms\",\n pluginRules: bunismsPlugin.rules,\n rules: {\n \"bunisms/prefer-mock-restore-in-after-each\": \"off\", // `test-setup.ts` preloads restore mocks globally\n },\n },\n \"clean-modules\": {\n package: \"@adamhl8/eslint-plugin-clean-modules\",\n pluginRules: cleanModulesPlugin.rules,\n },\n \"directive-comments\": {\n package: \"oxlint-plugin-directive-comments\",\n pluginRules: directiveCommentsPluginRules,\n rules: {\n \"directive-comments/disable-enable-pair\": [\"error\", { allowWholeFile: true }],\n \"directive-comments/no-use\": \"off\", // bans every directive comment\n },\n },\n e18e: {\n package: \"@e18e/eslint-plugin\",\n pluginRules: e18ePlugin.rules,\n rules: {\n \"e18e/no-indexof-equality\": \"off\", // needs type information, which JS plugins don't get\n \"e18e/no-spread-in-reduce\": \"off\", // `oxc/no-accumulating-spread` covers this\n \"e18e/prefer-array-at\": \"off\", // `unicorn/prefer-at` covers this\n \"e18e/prefer-array-some\": \"off\", // `unicorn/prefer-array-some` covers this\n \"e18e/prefer-array-to-reversed\": \"off\", // `unicorn/no-array-reverse` covers this\n \"e18e/prefer-array-to-sorted\": \"off\", // `unicorn/no-array-sort` covers this\n \"e18e/prefer-date-now\": \"off\", // `unicorn/prefer-date-now` covers this\n \"e18e/prefer-exponentiation-operator\": \"off\", // `prefer-exponentiation-operator` covers this\n \"e18e/prefer-flatmap-over-map-flat\": \"off\", // `unicorn/prefer-array-flat-map` covers this\n \"e18e/prefer-includes\": \"off\", // `unicorn/prefer-includes` covers this\n \"e18e/prefer-nullish-coalescing\": \"off\", // `typescript/prefer-nullish-coalescing` covers this\n \"e18e/prefer-object-has-own\": \"off\", // `prefer-object-has-own` covers this\n \"e18e/prefer-slice-over-split-index\": \"off\",\n \"e18e/prefer-spread-syntax\": \"off\", // `unicorn/prefer-spread` and `prefer-object-spread` cover this\n },\n },\n hono: {\n enabled: dependencies.has(\"hono\"),\n package: \"eslint-plugin-hono\",\n pluginRules: honoPlugin.rules,\n rules: {\n \"hono/no-process-env\": \"off\", // tools and tests legitimately read the raw environment\n },\n },\n \"react-web-api\": {\n enabled: dependencies.has(\"react\"),\n package: \"eslint-plugin-react-web-api\",\n pluginRules: reactWebApiPlugin.rules,\n },\n \"react-you-might-not-need-an-effect\": {\n enabled: dependencies.has(\"react\"),\n package: \"eslint-plugin-react-you-might-not-need-an-effect\",\n pluginRules: reactEffectPlugin.rules,\n rules: {\n \"react-you-might-not-need-an-effect/no-adjust-state-on-prop-change\": \"off\", // `react/set-state-in-effect` covers this\n \"react-you-might-not-need-an-effect/no-chain-state-updates\": \"off\", // `react/set-state-in-effect` covers this\n \"react-you-might-not-need-an-effect/no-derived-state\": \"off\", // `react/set-state-in-effect` covers this\n \"react-you-might-not-need-an-effect/no-initialize-state\": \"off\", // `react/set-state-in-effect` covers this\n \"react-you-might-not-need-an-effect/no-reset-all-state-on-prop-change\": \"off\", // `react/set-state-in-effect` covers this\n },\n },\n regexp: {\n package: \"eslint-plugin-regexp\",\n pluginRules: regexpPluginRules,\n rules: {\n \"regexp/letter-case\": [\"error\", { hexadecimalEscape: \"uppercase\", unicodeEscape: \"uppercase\" }], // match `unicorn/escape-case`\n \"regexp/no-control-character\": \"off\", // `no-control-regex` covers this\n \"regexp/no-empty-character-class\": \"off\", // `no-empty-character-class` covers this\n \"regexp/no-invalid-regexp\": \"off\", // `no-invalid-regexp` covers this\n \"regexp/no-super-linear-move\": \"off\",\n \"regexp/no-useless-escape\": \"off\", // `no-useless-escape` covers this\n \"regexp/prefer-named-capture-group\": \"off\", // `prefer-named-capture-group` covers this\n \"regexp/require-unicode-regexp\": \"off\", // `require-unicode-regexp` covers this\n \"regexp/require-unicode-sets-regexp\": \"off\", // `require-unicode-regexp` covers this\n \"regexp/sort-alternatives\": \"off\",\n },\n },\n tailwindcss: {\n // Load the Tailwind plugin only with a stylesheet because it reports every class string without one.\n enabled: Boolean(tailwindStylesheet),\n package: \"oxlint-tailwindcss\",\n pluginRules: tailwindcssPlugin.rules,\n rules: {\n \"tailwindcss/enforce-consistent-line-wrapping\": \"off\", // oxfmt handles line width\n \"tailwindcss/enforce-logical\": \"off\", // conflicts with `tailwindcss/enforce-physical`\n \"tailwindcss/enforce-sort-order\": \"off\", // oxfmt sorts classes\n \"tailwindcss/max-class-count\": \"off\",\n },\n // Keep `entryPoint` relative because the plugin resolves it against the directory of the project's oxlint config.\n settings: { tailwindcss: { entryPoint: tailwindStylesheet } },\n },\n}\n\nconst nativeConfig = {\n options: {\n reportUnusedDisableDirectives: \"error\",\n typeAware: true,\n typeCheck: true,\n },\n\n categories: {\n correctness: \"error\",\n nursery: \"error\",\n pedantic: \"error\",\n perf: \"error\",\n restriction: \"error\",\n style: \"error\",\n suspicious: \"error\",\n },\n\n plugins: [\n \"eslint\",\n \"react\",\n \"unicorn\",\n \"typescript\",\n \"oxc\",\n \"import\",\n \"jsdoc\",\n \"vitest\",\n \"jsx-a11y\",\n \"react-perf\",\n \"promise\",\n \"node\",\n ],\n\n overrides: [\n {\n files: [\n \".release-it.ts\",\n \"astro.config.ts\",\n \"commitlint.config.ts\",\n \"knip.ts\",\n \"oxfmt.config.ts\",\n \"oxlint.config.ts\",\n \"prisma.config.ts\",\n \"tsdown.config.ts\",\n ],\n rules: {\n \"import/no-default-export\": \"off\",\n },\n },\n {\n files: [\"bask.ts\"],\n rules: {\n \"clean-modules/require-direct-exports\": \"off\",\n \"import/export\": \"off\",\n },\n },\n {\n files: [\".release-it.ts\"],\n rules: {\n \"no-template-curly-in-string\": \"off\",\n },\n },\n {\n files: [\"**/*.tsx\"],\n rules: {\n \"func-style\": [\"error\", \"declaration\", { allowArrowFunctions: true }],\n },\n },\n {\n files: [\"**/fixtures/**\", \"**/fixture/**\"],\n rules: {\n \"clean-modules/require-import-extensions\": \"off\",\n \"clean-modules/require-subpath-imports\": \"off\",\n \"import/no-default-export\": \"off\",\n },\n },\n ],\n\n rules: {\n /* Modified rules */\n\n curly: [\"error\", \"multi-or-nest\"],\n \"func-style\": [\"error\", \"expression\"],\n \"require-unicode-regexp\": [\"error\", { requireFlag: \"v\" }],\n\n \"react/function-component-definition\": [\n \"error\",\n { namedComponents: \"function-declaration\", unnamedComponents: \"arrow-function\" },\n ],\n \"react/jsx-curly-brace-presence\": [\"error\", { children: \"never\", propElementValues: \"always\", props: \"never\" }],\n\n \"unicorn/filename-case\": [\n \"error\",\n {\n cases: { kebabCase: true, pascalCase: true },\n },\n ],\n \"unicorn/no-useless-undefined\": [\"error\", { checkArguments: false }],\n\n /* Disabled rules */\n\n \"capitalized-comments\": \"off\",\n \"id-length\": \"off\",\n \"init-declarations\": \"off\",\n \"max-classes-per-file\": \"off\",\n \"max-lines\": \"off\",\n \"max-lines-per-function\": \"off\",\n \"max-statements\": \"off\",\n \"no-console\": \"off\",\n \"no-continue\": \"off\",\n \"no-duplicate-imports\": \"off\",\n \"no-inline-comments\": \"off\",\n \"no-magic-numbers\": \"off\",\n \"no-plusplus\": \"off\",\n \"no-regex-spaces\": \"off\", // `regexp/prefer-quantifier` covers this\n \"no-ternary\": \"off\",\n \"no-undef\": \"off\",\n \"no-undefined\": \"off\",\n \"no-useless-return\": \"off\",\n \"no-void\": \"off\",\n \"one-var\": \"off\",\n \"require-await\": \"off\",\n \"sort-imports\": \"off\",\n \"sort-keys\": \"off\",\n\n \"import/exports-last\": \"off\",\n \"import/group-exports\": \"off\",\n \"import/max-dependencies\": \"off\",\n \"import/no-named-export\": \"off\",\n \"import/no-nodejs-modules\": \"off\",\n \"import/no-unassigned-import\": \"off\",\n \"import/prefer-default-export\": \"off\",\n\n \"jsdoc/require-param\": \"off\",\n \"jsdoc/require-returns\": \"off\",\n\n \"node/callback-return\": \"off\",\n \"node/no-process-env\": \"off\", // tools and tests legitimately read the raw environment\n \"node/no-sync\": \"off\",\n \"node/no-top-level-await\": \"off\",\n\n \"oxc/no-async-await\": \"off\",\n \"oxc/no-optional-chaining\": \"off\",\n \"oxc/no-rest-spread-properties\": \"off\",\n\n \"react/exhaustive-effect-dependencies\": \"off\", // `react/exhaustive-deps` covers this\n \"react/forbid-component-props\": \"off\",\n \"react/hooks\": \"off\", // `react/rules-of-hooks` covers this\n \"react/invariant\": \"off\",\n \"react/jsx-filename-extension\": \"off\",\n \"react/jsx-max-depth\": \"off\",\n \"react/jsx-no-literals\": \"off\",\n \"react/memo-dependencies\": \"off\", // `react/exhaustive-deps` covers this\n \"react/no-deriving-state-in-effects\": \"off\", // `react/set-state-in-effect` covers this\n \"react/react-in-jsx-scope\": \"off\",\n \"react/rule-suppression\": \"off\",\n \"react/todo\": \"off\",\n\n \"typescript/consistent-return\": \"off\",\n \"typescript/explicit-function-return-type\": \"off\",\n \"typescript/explicit-module-boundary-types\": \"off\",\n \"typescript/prefer-readonly-parameter-types\": \"off\",\n \"typescript/strict-boolean-expressions\": \"off\",\n\n \"unicorn/no-array-callback-reference\": \"off\",\n \"unicorn/no-array-method-this-argument\": \"off\",\n \"unicorn/no-await-expression-member\": \"off\",\n \"unicorn/no-process-exit\": \"off\",\n \"unicorn/number-literal-case\": \"off\",\n \"unicorn/switch-case-braces\": \"off\",\n\n \"vitest/no-hooks\": \"off\",\n \"vitest/no-importing-vitest-globals\": \"off\",\n \"vitest/prefer-describe-function-title\": \"off\",\n \"vitest/prefer-expect-assertions\": \"off\",\n \"vitest/prefer-importing-vitest-globals\": \"off\",\n \"vitest/prefer-lowercase-title\": \"off\",\n \"vitest/prefer-to-be-falsy\": \"off\",\n \"vitest/prefer-to-be-truthy\": \"off\",\n \"vitest/require-hook\": \"off\", // reenable when false positives are fixed?\n \"vitest/require-test-timeout\": \"off\",\n },\n} as const satisfies OxlintConfig\n\nconst enabledPluginEntries = Object.entries(plugins).filter(([, plugin]) => plugin.enabled ?? true)\nconst enabledPlugins = enabledPluginEntries.map(([, plugin]) => plugin)\n// Resolve JS plugins to absolute paths so consumers load them from this package's own deps.\nconst resolvedPluginPackages = enabledPlugins.map((plugin) => resolvePackagePath(plugin.package))\nconst pluginOverrides = enabledPlugins.flatMap((plugin) => plugin.overrides ?? [])\nconst pluginSettings = Object.fromEntries(enabledPlugins.flatMap((plugin) => Object.entries(plugin.settings ?? {})))\n\n/** Lists a plugin's rules as entries */\nconst toPluginRuleEntries = ([name, { pluginRules = {}, rules }]: [string, PluginPart]) => {\n const defaultRules = setAllPluginRules(name, pluginRules, \"error\")\n const pluginRuleEntries = Object.entries({ ...defaultRules, ...rules })\n return pluginRuleEntries\n}\n\nconst resolvedPluginRules = Object.fromEntries(enabledPluginEntries.flatMap(toPluginRuleEntries))\n\nconst baseConfig = {\n ...nativeConfig,\n jsPlugins: resolvedPluginPackages,\n overrides: [...nativeConfig.overrides, ...pluginOverrides],\n rules: {\n ...resolvedPluginRules,\n ...nativeConfig.rules,\n },\n settings: pluginSettings,\n} satisfies OxlintConfig\n\nexport const oxlintConfig = createMergeConfigFn<OxlintConfig, typeof baseConfig>(baseConfig)\n"],"mappings":";;;;;;;;;;;;;AAeA,MAAM,qBAAqB,MAAc,OAAgC,aACvE,OAAO,YAAY,OAAO,KAAK,KAAK,CAAC,CAAC,KAAK,SAAS,CAAC,GAAG,KAAK,GAAG,QAAQ,QAAQ,CAAU,CAAC;AAgB7F,MAAM,EAAE,cAAc,YAAY,uBAAuB;AACzD,MAAM,qBAAqB,uBAAuB;AAGlD,MAAM,UAAsC;CAC1C,SAAS;EACP,WAAW,CACT;GACE,cAAc;IAAC;IAAuB;IAA0B;IAAwB;GAAsB;GAE9G,OAAO,QAAQ,IAAI,MAAM,IAAI,CAAC,QAAQ,IAAI,CAAC;GAC3C,OAAO,kBAAkB,WAAW,cAAc,OAAO,KAAK;EAChE,CACF;EACA,SAAS;EACT,aAAa,cAAc;EAC3B,OAAO,EACL,6CAA6C,MAC/C;CACF;CACA,iBAAiB;EACf,SAAS;EACT,aAAa,mBAAmB;CAClC;CACA,sBAAsB;EACpB,SAAS;EACT,aAAaA;EACb,OAAO;GACL,0CAA0C,CAAC,SAAS,EAAE,gBAAgB,KAAK,CAAC;GAC5E,6BAA6B;EAC/B;CACF;CACA,MAAM;EACJ,SAAS;EACT,aAAa,WAAW;EACxB,OAAO;GACL,4BAA4B;GAC5B,4BAA4B;GAC5B,wBAAwB;GACxB,0BAA0B;GAC1B,iCAAiC;GACjC,+BAA+B;GAC/B,wBAAwB;GACxB,uCAAuC;GACvC,qCAAqC;GACrC,wBAAwB;GACxB,kCAAkC;GAClC,8BAA8B;GAC9B,sCAAsC;GACtC,6BAA6B;EAC/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GAAG;EACH,GAAG,aAAa;CAClB;CACA,UAAU;AACZ;AAEA,MAAa,eAAe,oBAAqD,UAAU"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Shell, ShellOptions } from "./shell/shell.js";
|
|
2
|
+
export interface CopyFixtureOptions {
|
|
3
|
+
/**
|
|
4
|
+
* The start of the temp dir's name.
|
|
5
|
+
*
|
|
6
|
+
* @default `${path.basename(fixture)}-`
|
|
7
|
+
*/
|
|
8
|
+
prefix?: string;
|
|
9
|
+
/** Options for the returned shell, which always runs in the copy. */
|
|
10
|
+
shell?: Omit<ShellOptions, "cwd">;
|
|
11
|
+
}
|
|
12
|
+
/** Copies `fixture` into a new temp dir, and returns the dir and a shell that runs there. */
|
|
13
|
+
export declare const copyFixture: (fixture: string, { prefix, shell }?: CopyFixtureOptions) => Promise<{
|
|
14
|
+
dir: string;
|
|
15
|
+
run: Shell;
|
|
16
|
+
}>;
|
|
17
|
+
//# sourceMappingURL=fixture.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fixture.d.ts","names":["_$_test_utils_shell_shell_ts0.Shell"],"sources":["../../src/test-utils/fixture.ts"],"mappings":";iBAOiB;;;;;;EAMf;;EAEA,QAAQ,KAAK;;;qBAIF,cAAW,mBAAyB,QAAA,UAAqB,uBAAkB;;E,KAAlBA"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { createShell } from "./shell/shell.js";
|
|
2
|
+
import { makeTempDir } from "./temp-dir.js";
|
|
3
|
+
import fs from "node:fs/promises";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
// src/test-utils/fixture.ts
|
|
6
|
+
/** Copies `fixture` into a new temp dir, and returns the dir and a shell that runs there. */
|
|
7
|
+
const copyFixture = async (fixture, { prefix, shell } = {}) => {
|
|
8
|
+
const dir = await makeTempDir(prefix ?? `${path.basename(fixture)}-`);
|
|
9
|
+
await fs.cp(fixture, dir, { recursive: true });
|
|
10
|
+
return {
|
|
11
|
+
dir,
|
|
12
|
+
run: createShell({
|
|
13
|
+
...shell,
|
|
14
|
+
cwd: dir
|
|
15
|
+
})
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
export { copyFixture };
|
|
19
|
+
|
|
20
|
+
//# sourceMappingURL=fixture.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fixture.js","names":[],"sources":["../../src/test-utils/fixture.ts"],"sourcesContent":["import fs from \"node:fs/promises\"\nimport path from \"node:path\"\n\nimport { createShell } from \"#test-utils/shell/shell.ts\"\nimport type { ShellOptions } from \"#test-utils/shell/shell.ts\"\nimport { makeTempDir } from \"#test-utils/temp-dir.ts\"\n\nexport interface CopyFixtureOptions {\n /**\n * The start of the temp dir's name.\n *\n * @default `${path.basename(fixture)}-`\n */\n prefix?: string\n /** Options for the returned shell, which always runs in the copy. */\n shell?: Omit<ShellOptions, \"cwd\">\n}\n\n/** Copies `fixture` into a new temp dir, and returns the dir and a shell that runs there. */\nexport const copyFixture = async (fixture: string, { prefix, shell }: CopyFixtureOptions = {}) => {\n const dir = await makeTempDir(prefix ?? `${path.basename(fixture)}-`)\n await fs.cp(fixture, dir, { recursive: true })\n const run = createShell({ ...shell, cwd: dir })\n return { dir, run }\n}\n"],"mappings":";;;;;;AAmBA,MAAa,cAAc,OAAO,SAAiB,EAAE,QAAQ,UAA8B,CAAC,MAAM;CAChG,MAAM,MAAM,MAAM,YAAY,UAAU,GAAG,KAAK,SAAS,OAAO,EAAE,EAAE;CACpE,MAAM,GAAG,GAAG,SAAS,KAAK,EAAE,WAAW,KAAK,CAAC;CAE7C,OAAO;EAAE;EAAK,KADF,YAAY;GAAE,GAAG;GAAO,KAAK;EAAI,CAC7B;CAAE;AACpB"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ShellCommand } from "./shell/command.js";
|
|
2
|
+
import { Shell, ShellEnv, ShellOptions, ShellResult, createShell } from "./shell/shell.js";
|
|
3
|
+
import { minimalEnv } from "./shell/env.js";
|
|
4
|
+
import { CopyFixtureOptions, copyFixture } from "./fixture.js";
|
|
5
|
+
import { packPackage } from "./pack.js";
|
|
6
|
+
import { makeTempDir } from "./temp-dir.js";
|
|
7
|
+
export { type CopyFixtureOptions, type Shell, type ShellCommand, type ShellEnv, type ShellOptions, type ShellResult, copyFixture, createShell, makeTempDir, minimalEnv, packPackage };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { minimalEnv } from "./shell/env.js";
|
|
2
|
+
import { createShell } from "./shell/shell.js";
|
|
3
|
+
import { makeTempDir } from "./temp-dir.js";
|
|
4
|
+
import { copyFixture } from "./fixture.js";
|
|
5
|
+
import { packPackage } from "./pack.js";
|
|
6
|
+
export { copyFixture, createShell, makeTempDir, minimalEnv, packPackage };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pack.d.ts","names":[],"sources":["../../src/test-utils/pack.ts"],"mappings":";qBAQa,cAAW,iBAAsB"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { createShell } from "./shell/shell.js";
|
|
2
|
+
import { makeTempDir } from "./temp-dir.js";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import bun from "bun";
|
|
5
|
+
// src/test-utils/pack.ts
|
|
6
|
+
/** Builds the package at `root` when it has a tsdown config, packs it into a temp dir, and returns the tarball path. */
|
|
7
|
+
const packPackage = async (root) => {
|
|
8
|
+
const run = createShell({ cwd: root });
|
|
9
|
+
if (await bun.file(path.join(root, "tsdown.config.ts")).exists()) await run`bun tsdown`;
|
|
10
|
+
const destination = await makeTempDir(`${path.basename(root)}-pack-`);
|
|
11
|
+
const { stdout } = await run`bun pm pack --ignore-scripts --quiet --destination ${destination}`;
|
|
12
|
+
return path.resolve(destination, stdout);
|
|
13
|
+
};
|
|
14
|
+
export { packPackage };
|
|
15
|
+
|
|
16
|
+
//# sourceMappingURL=pack.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pack.js","names":[],"sources":["../../src/test-utils/pack.ts"],"sourcesContent":["import path from \"node:path\"\n\nimport bun from \"bun\"\n\nimport { createShell } from \"#test-utils/shell/shell.ts\"\nimport { makeTempDir } from \"#test-utils/temp-dir.ts\"\n\n/** Builds the package at `root` when it has a tsdown config, packs it into a temp dir, and returns the tarball path. */\nexport const packPackage = async (root: string) => {\n const run = createShell({ cwd: root })\n if (await bun.file(path.join(root, \"tsdown.config.ts\")).exists()) await run`bun tsdown`\n\n const destination = await makeTempDir(`${path.basename(root)}-pack-`)\n // Skip lifecycle scripts because a `prepare` script would rebuild and run the package's own tasks.\n const { stdout } = await run`bun pm pack --ignore-scripts --quiet --destination ${destination}`\n return path.resolve(destination, stdout)\n}\n"],"mappings":";;;;;;AAQA,MAAa,cAAc,OAAO,SAAiB;CACjD,MAAM,MAAM,YAAY,EAAE,KAAK,KAAK,CAAC;CACrC,IAAI,MAAM,IAAI,KAAK,KAAK,KAAK,MAAM,kBAAkB,CAAC,CAAC,CAAC,OAAO,GAAG,MAAM,GAAG;CAE3E,MAAM,cAAc,MAAM,YAAY,GAAG,KAAK,SAAS,IAAI,EAAE,OAAO;CAEpE,MAAM,EAAE,WAAW,MAAM,GAAG,sDAAsD;CAClF,OAAO,KAAK,QAAQ,aAAa,MAAM;AACzC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"preload.js","names":[],"sources":["../../src/test-utils/preload.ts"],"sourcesContent":["import { afterAll } from \"bun:test\"\n\nimport { removeTempDirs } from \"#test-utils/temp-dir.ts\"\n\nafterAll(removeTempDirs)\n"],"mappings":";;;AAIA,SAAS,cAAc"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
// src/test-utils/shell/bin-dirs.ts
|
|
3
|
+
/** Lists `node_modules/.bin` for `dir` and each of its parents, nearest first. */
|
|
4
|
+
const getBinDirs = (dir) => {
|
|
5
|
+
const binDir = path.join(dir, "node_modules", ".bin");
|
|
6
|
+
const parent = path.dirname(dir);
|
|
7
|
+
return parent === dir ? [binDir] : [binDir, ...getBinDirs(parent)];
|
|
8
|
+
};
|
|
9
|
+
/** Puts `node_modules/.bin` of `cwd` and each of its parents first on `PATH`. */
|
|
10
|
+
const addBinDirs = (cwd, env) => {
|
|
11
|
+
const PATH = [...getBinDirs(cwd), env["PATH"]].filter(Boolean).join(path.delimiter);
|
|
12
|
+
return {
|
|
13
|
+
...env,
|
|
14
|
+
PATH
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
export { addBinDirs };
|
|
18
|
+
|
|
19
|
+
//# sourceMappingURL=bin-dirs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bin-dirs.js","names":[],"sources":["../../../src/test-utils/shell/bin-dirs.ts"],"sourcesContent":["import path from \"node:path\"\n\nimport type { ShellEnv } from \"#test-utils/shell/shell.ts\"\n\n/** Lists `node_modules/.bin` for `dir` and each of its parents, nearest first. */\nconst getBinDirs = (dir: string): string[] => {\n const binDir = path.join(dir, \"node_modules\", \".bin\")\n const parent = path.dirname(dir)\n return parent === dir ? [binDir] : [binDir, ...getBinDirs(parent)]\n}\n\n/** Puts `node_modules/.bin` of `cwd` and each of its parents first on `PATH`. */\nexport const addBinDirs = (cwd: string, env: ShellEnv): ShellEnv => {\n // Drop an empty `PATH` because the shell reads a trailing empty entry as the cwd.\n const PATH = [...getBinDirs(cwd), env[\"PATH\"]].filter(Boolean).join(path.delimiter)\n\n return { ...env, PATH }\n}\n"],"mappings":";;;AAKA,MAAM,cAAc,QAA0B;CAC5C,MAAM,SAAS,KAAK,KAAK,KAAK,gBAAgB,MAAM;CACpD,MAAM,SAAS,KAAK,QAAQ,GAAG;CAC/B,OAAO,WAAW,MAAM,CAAC,MAAM,IAAI,CAAC,QAAQ,GAAG,WAAW,MAAM,CAAC;AACnE;;AAGA,MAAa,cAAc,KAAa,QAA4B;CAElE,MAAM,OAAO,CAAC,GAAG,WAAW,GAAG,GAAG,IAAI,OAAO,CAAC,CAAC,OAAO,OAAO,CAAC,CAAC,KAAK,KAAK,SAAS;CAElF,OAAO;EAAE,GAAG;EAAK;CAAK;AACxB"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ShellEnv, ShellOptions, ShellResult } from "./shell.js";
|
|
2
|
+
import { $ } from "bun";
|
|
3
|
+
/** Wraps Bun's `ShellPromise` to apply its settings when it runs and return its output as strings. */
|
|
4
|
+
export declare class ShellCommand implements PromiseLike<ShellResult> {
|
|
5
|
+
#private;
|
|
6
|
+
/** Starts from the shell's settings, which the command's own methods can then override. */
|
|
7
|
+
constructor(shellPromise: $.ShellPromise, settings: Required<ShellOptions>);
|
|
8
|
+
/** Change the working directory for the command. Relative paths resolve against `process.cwd()`. */
|
|
9
|
+
cwd(newCwd: string): this;
|
|
10
|
+
/** Add environment variables for the command, on top of the shell's. Set one to `undefined` to remove it. */
|
|
11
|
+
env(newEnv: ShellEnv): this;
|
|
12
|
+
/** Configure whether the command puts `node_modules/.bin` of its cwd and each of its parents first on `PATH`. */
|
|
13
|
+
localBins(useLocalBins: boolean): this;
|
|
14
|
+
/** Configure the command to not throw an exception on a non-zero exit code. */
|
|
15
|
+
nothrow(): this;
|
|
16
|
+
then<TResult1 = ShellResult, TResult2 = never>(onfulfilled?: ((value: ShellResult) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=command.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"command.d.ts","names":["BunShell"],"sources":["../../../src/test-utils/shell/command.ts"],"mappings":";;;qBAca,wBAAwB,YAAY;;;EAM/C,YAAmB,cAAcA,EAAS,cAAc,UAAU,SAAS;;EAOpE,IAAI;;EAMJ,IAAI,QAAQ;;EAMZ,UAAU;;EAMV;EAMM,KAAK,WAAW,aAAa,kBACxC,gBAAgB,OAAO,gBAAgB,WAAW,YAAY,mBAC9D,eAAe,oBAAoB,WAAW,YAAY,oBAAiB,QAAA,WAAA"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { addBinDirs } from "./bin-dirs.js";
|
|
2
|
+
import { removeNodeShims } from "./node-shim.js";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import bun from "bun";
|
|
5
|
+
// src/test-utils/shell/command.ts
|
|
6
|
+
const FINAL_NEWLINE = /\r?\n$/v;
|
|
7
|
+
const stripFinalNewline = (output) => output.toString().replace(FINAL_NEWLINE, "");
|
|
8
|
+
/** Wraps Bun's `ShellPromise` to apply its settings when it runs and return its output as strings. */
|
|
9
|
+
var ShellCommand = class {
|
|
10
|
+
#shellPromise;
|
|
11
|
+
#settings;
|
|
12
|
+
#result;
|
|
13
|
+
/** Starts from the shell's settings, which the command's own methods can then override. */
|
|
14
|
+
constructor(shellPromise, settings) {
|
|
15
|
+
this.#shellPromise = shellPromise;
|
|
16
|
+
this.#settings = { ...settings };
|
|
17
|
+
}
|
|
18
|
+
/** Change the working directory for the command. Relative paths resolve against `process.cwd()`. */
|
|
19
|
+
cwd(newCwd) {
|
|
20
|
+
this.#settings.cwd = newCwd;
|
|
21
|
+
return this;
|
|
22
|
+
}
|
|
23
|
+
/** Add environment variables for the command, on top of the shell's. Set one to `undefined` to remove it. */
|
|
24
|
+
env(newEnv) {
|
|
25
|
+
this.#settings.env = {
|
|
26
|
+
...this.#settings.env,
|
|
27
|
+
...newEnv
|
|
28
|
+
};
|
|
29
|
+
return this;
|
|
30
|
+
}
|
|
31
|
+
/** Configure whether the command puts `node_modules/.bin` of its cwd and each of its parents first on `PATH`. */
|
|
32
|
+
localBins(useLocalBins) {
|
|
33
|
+
this.#settings.localBins = useLocalBins;
|
|
34
|
+
return this;
|
|
35
|
+
}
|
|
36
|
+
/** Configure the command to not throw an exception on a non-zero exit code. */
|
|
37
|
+
nothrow() {
|
|
38
|
+
this.#settings.throws = false;
|
|
39
|
+
return this;
|
|
40
|
+
}
|
|
41
|
+
async then(onfulfilled, onrejected) {
|
|
42
|
+
this.#result ??= this.#run();
|
|
43
|
+
return this.#result.then(onfulfilled, onrejected);
|
|
44
|
+
}
|
|
45
|
+
async #run() {
|
|
46
|
+
const { env, localBins, throws } = this.#settings;
|
|
47
|
+
const cwd = path.resolve(this.#settings.cwd);
|
|
48
|
+
const envWithBins = localBins ? addBinDirs(cwd, env) : env;
|
|
49
|
+
const finalEnv = removeNodeShims(envWithBins);
|
|
50
|
+
const output = await this.#shellPromise.cwd(cwd).env(finalEnv).quiet().throws(throws).catch((error) => {
|
|
51
|
+
if (error instanceof bun.$.ShellError) throw error;
|
|
52
|
+
throw new Error(`Command failed to start (cwd: ${cwd})`, { cause: error });
|
|
53
|
+
});
|
|
54
|
+
return {
|
|
55
|
+
stdout: stripFinalNewline(output.stdout),
|
|
56
|
+
stderr: stripFinalNewline(output.stderr),
|
|
57
|
+
exitCode: output.exitCode
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
export { ShellCommand };
|
|
62
|
+
|
|
63
|
+
//# sourceMappingURL=command.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"command.js","names":[],"sources":["../../../src/test-utils/shell/command.ts"],"sourcesContent":["import path from \"node:path\"\n\nimport bun from \"bun\"\nimport type { $ as BunShell } from \"bun\"\n\nimport { addBinDirs } from \"#test-utils/shell/bin-dirs.ts\"\nimport { removeNodeShims } from \"#test-utils/shell/node-shim.ts\"\nimport type { ShellEnv, ShellOptions, ShellResult } from \"#test-utils/shell/shell.ts\"\n\nconst FINAL_NEWLINE = /\\r?\\n$/v\n\nconst stripFinalNewline = (output: Buffer) => output.toString().replace(FINAL_NEWLINE, \"\")\n\n/** Wraps Bun's `ShellPromise` to apply its settings when it runs and return its output as strings. */\nexport class ShellCommand implements PromiseLike<ShellResult> {\n readonly #shellPromise: BunShell.ShellPromise\n readonly #settings: Required<ShellOptions>\n #result: Promise<ShellResult> | undefined\n\n /** Starts from the shell's settings, which the command's own methods can then override. */\n public constructor(shellPromise: BunShell.ShellPromise, settings: Required<ShellOptions>) {\n this.#shellPromise = shellPromise\n // Copy `settings` so this command's changes don't reach the shell.\n this.#settings = { ...settings }\n }\n\n /** Change the working directory for the command. Relative paths resolve against `process.cwd()`. */\n public cwd(newCwd: string) {\n this.#settings.cwd = newCwd\n return this\n }\n\n /** Add environment variables for the command, on top of the shell's. Set one to `undefined` to remove it. */\n public env(newEnv: ShellEnv) {\n this.#settings.env = { ...this.#settings.env, ...newEnv }\n return this\n }\n\n /** Configure whether the command puts `node_modules/.bin` of its cwd and each of its parents first on `PATH`. */\n public localBins(useLocalBins: boolean) {\n this.#settings.localBins = useLocalBins\n return this\n }\n\n /** Configure the command to not throw an exception on a non-zero exit code. */\n public nothrow() {\n this.#settings.throws = false\n return this\n }\n\n // oxlint-disable-next-line unicorn/no-thenable - awaiting a command runs it, like Bun's `ShellPromise`\n public async then<TResult1 = ShellResult, TResult2 = never>(\n onfulfilled?: ((value: ShellResult) => TResult1 | PromiseLike<TResult1>) | null,\n onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null,\n ) {\n // Keep the first run because Bun rejects settings on a command that already started.\n this.#result ??= this.#run()\n return this.#result.then(onfulfilled, onrejected)\n }\n\n async #run(): Promise<ShellResult> {\n const { env, localBins, throws } = this.#settings\n const cwd = path.resolve(this.#settings.cwd)\n const envWithBins = localBins ? addBinDirs(cwd, env) : env\n const finalEnv = removeNodeShims(envWithBins)\n\n const output = await this.#shellPromise\n .cwd(cwd)\n .env(finalEnv)\n .quiet()\n .throws(throws)\n .catch((error: unknown) => {\n if (error instanceof bun.$.ShellError) throw error\n // Name the cwd because Bun's start errors (like a missing cwd) don't.\n throw new Error(`Command failed to start (cwd: ${cwd})`, { cause: error })\n })\n\n return {\n stdout: stripFinalNewline(output.stdout),\n stderr: stripFinalNew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CACF;AACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env.d.ts","names":[],"sources":["../../../src/test-utils/shell/env.ts"],"mappings":";;qBAKa,aAAU,QAAW,aAAgB"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import process from "node:process";
|
|
2
|
+
// src/test-utils/shell/env.ts
|
|
3
|
+
/** Returns `PATH` and `HOME` from `process.env`, merged with `extra`. */
|
|
4
|
+
const minimalEnv = (extra = {}) => ({
|
|
5
|
+
PATH: process.env["PATH"],
|
|
6
|
+
HOME: process.env["HOME"],
|
|
7
|
+
...extra
|
|
8
|
+
});
|
|
9
|
+
export { minimalEnv };
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=env.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env.js","names":[],"sources":["../../../src/test-utils/shell/env.ts"],"sourcesContent":["import process from \"node:process\"\n\nimport type { ShellEnv } from \"#test-utils/shell/shell.ts\"\n\n/** Returns `PATH` and `HOME` from `process.env`, merged with `extra`. */\nexport const minimalEnv = (extra: ShellEnv = {}): ShellEnv => ({\n PATH: process.env[\"PATH\"],\n HOME: process.env[\"HOME\"],\n ...extra,\n})\n"],"mappings":";;;AAKA,MAAa,cAAc,QAAkB,CAAC,OAAiB;CAC7D,MAAM,QAAQ,IAAI;CAClB,MAAM,QAAQ,IAAI;CAClB,GAAG;AACL"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
// src/test-utils/shell/node-shim.ts
|
|
3
|
+
const NODE_SHIM_DIR = /^(?:bask|bun)-node-/v;
|
|
4
|
+
/** Checks for a folder that `bask` or `bun run --bun` puts on `PATH` so `node` runs Bun. */
|
|
5
|
+
const isNodeShimDir = (dir) => NODE_SHIM_DIR.test(path.basename(dir));
|
|
6
|
+
/** Takes every `node` shim off `PATH` so `node` is the real Node however the tests started. */
|
|
7
|
+
const removeNodeShims = (env) => {
|
|
8
|
+
const currentPath = env["PATH"];
|
|
9
|
+
if (currentPath === void 0) return env;
|
|
10
|
+
const PATH = currentPath.split(path.delimiter).filter((dir) => !isNodeShimDir(dir)).join(path.delimiter);
|
|
11
|
+
return {
|
|
12
|
+
...env,
|
|
13
|
+
PATH
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
export { removeNodeShims };
|
|
17
|
+
|
|
18
|
+
//# sourceMappingURL=node-shim.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node-shim.js","names":[],"sources":["../../../src/test-utils/shell/node-shim.ts"],"sourcesContent":["import path from \"node:path\"\n\nimport type { ShellEnv } from \"#test-utils/shell/shell.ts\"\n\nconst NODE_SHIM_DIR = /^(?:bask|bun)-node-/v\n\n/** Checks for a folder that `bask` or `bun run --bun` puts on `PATH` so `node` runs Bun. */\nconst isNodeShimDir = (dir: string) => NODE_SHIM_DIR.test(path.basename(dir))\n\n/** Takes every `node` shim off `PATH` so `node` is the real Node however the tests started. */\nexport const removeNodeShims = (env: ShellEnv): ShellEnv => {\n const currentPath = env[\"PATH\"]\n if (currentPath === undefined) return env\n\n const pathDirs = currentPath.split(path.delimiter)\n const PATH = pathDirs.filter((dir) => !isNodeShimDir(dir)).join(path.delimiter)\n\n return { ...env, PATH }\n}\n"],"mappings":";;AAIA,MAAM,gBAAgB;;AAGtB,MAAM,iBAAiB,QAAgB,cAAc,KAAK,KAAK,SAAS,GAAG,CAAC;;AAG5E,MAAa,mBAAmB,QAA4B;CAC1D,MAAM,cAAc,IAAI;CACxB,IAAI,gBAAgB,KAAA,GAAW,OAAO;CAGtC,MAAM,OADW,YAAY,MAAM,KAAK,SACpB,CAAC,CAAC,QAAQ,QAAQ,CAAC,cAAc,GAAG,CAAC,CAAC,CAAC,KAAK,KAAK,SAAS;CAE9E,OAAO;EAAE,GAAG;EAAK;CAAK;AACxB"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { ShellCommand } from "./command.js";
|
|
2
|
+
import { ShellExpression } from "bun";
|
|
3
|
+
export type ShellEnv = Record<string, string | undefined>;
|
|
4
|
+
export interface ShellOptions {
|
|
5
|
+
/**
|
|
6
|
+
* The working directory for commands. Relative paths resolve against `process.cwd()`.
|
|
7
|
+
*
|
|
8
|
+
* @default process.cwd()
|
|
9
|
+
*/
|
|
10
|
+
cwd?: string;
|
|
11
|
+
/**
|
|
12
|
+
* The environment for commands. Replaces `process.env`.
|
|
13
|
+
*
|
|
14
|
+
* @default process.env without `FORCE_COLOR`
|
|
15
|
+
*/
|
|
16
|
+
env?: ShellEnv;
|
|
17
|
+
/**
|
|
18
|
+
* Put `node_modules/.bin` of the cwd and each of its parents first on `PATH`.
|
|
19
|
+
*
|
|
20
|
+
* @default true
|
|
21
|
+
*/
|
|
22
|
+
localBins?: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Throw Bun's `ShellError` on a non-zero exit code.
|
|
25
|
+
*
|
|
26
|
+
* @default true
|
|
27
|
+
*/
|
|
28
|
+
throws?: boolean;
|
|
29
|
+
}
|
|
30
|
+
export interface ShellResult {
|
|
31
|
+
stdout: string;
|
|
32
|
+
stderr: string;
|
|
33
|
+
exitCode: number;
|
|
34
|
+
}
|
|
35
|
+
/** Runs commands like Bun's `$`, quietly, starting from the shell's options. */
|
|
36
|
+
export type Shell = (strings: TemplateStringsArray, ...expressions: ShellExpression[]) => ShellCommand;
|
|
37
|
+
/**
|
|
38
|
+
* Creates a shell that runs each command quietly and returns its output with one trailing newline stripped. Commands
|
|
39
|
+
* read the test runner's stdin, so add `< /dev/null` to a command that might prompt.
|
|
40
|
+
*/
|
|
41
|
+
export declare const createShell: (options?: ShellOptions) => Shell;
|
|
42
|
+
//# sourceMappingURL=shell.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shell.d.ts","names":[],"sources":["../../../src/test-utils/shell/shell.ts"],"mappings":";;YAOY,WAAW;iBAEN;;;;;;EAMf;;;;;;EAMA,MAAM;;;;;;EAMN;;;;;;EAMA;;iBAGe;EACf;EACA;EACA;;;YAIU,SAAS,SAAS,yBAAyB,aAAa,sBAAsB;;;;;qBAM7E,cAAW,UAAa,iBAAoB"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { ShellCommand } from "./command.js";
|
|
2
|
+
import process from "node:process";
|
|
3
|
+
import bun from "bun";
|
|
4
|
+
// src/test-utils/shell/shell.ts
|
|
5
|
+
/**
|
|
6
|
+
* Creates a shell that runs each command quietly and returns its output with one trailing newline stripped. Commands
|
|
7
|
+
* read the test runner's stdin, so add `< /dev/null` to a command that might prompt.
|
|
8
|
+
*/
|
|
9
|
+
const createShell = (options = {}) => {
|
|
10
|
+
const bunShell = new bun.$.Shell();
|
|
11
|
+
const settings = {
|
|
12
|
+
cwd: options.cwd ?? process.cwd(),
|
|
13
|
+
env: options.env ?? {
|
|
14
|
+
...process.env,
|
|
15
|
+
FORCE_COLOR: void 0
|
|
16
|
+
},
|
|
17
|
+
localBins: options.localBins ?? true,
|
|
18
|
+
throws: options.throws ?? true
|
|
19
|
+
};
|
|
20
|
+
return (strings, ...expressions) => new ShellCommand(bunShell(strings, ...expressions), settings);
|
|
21
|
+
};
|
|
22
|
+
export { createShell };
|
|
23
|
+
|
|
24
|
+
//# sourceMappingURL=shell.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shell.js","names":[],"sources":["../../../src/test-utils/shell/shell.ts"],"sourcesContent":["import process from \"node:process\"\n\nimport bun from \"bun\"\nimport type { ShellExpression } from \"bun\"\n\nimport { ShellCommand } from \"#test-utils/shell/command.ts\"\n\nexport type ShellEnv = Record<string, string | undefined>\n\nexport interface ShellOptions {\n /**\n * The working directory for commands. Relative paths resolve against `process.cwd()`.\n *\n * @default process.cwd()\n */\n cwd?: string\n /**\n * The environment for commands. Replaces `process.env`.\n *\n * @default process.env without `FORCE_COLOR`\n */\n env?: ShellEnv\n /**\n * Put `node_modules/.bin` of the cwd and each of its parents first on `PATH`.\n *\n * @default true\n */\n localBins?: boolean\n /**\n * Throw Bun's `ShellError` on a non-zero exit code.\n *\n * @default true\n */\n throws?: boolean\n}\n\nexport interface ShellResult {\n stdout: string\n stderr: string\n exitCode: number\n}\n\n/** Runs commands like Bun's `$`, quietly, starting from the shell's options. */\nexport type Shell = (strings: TemplateStringsArray, ...expressions: ShellExpression[]) => ShellCommand\n\n/**\n * Creates a shell that runs each command quietly and returns its output with one trailing newline stripped. Commands\n * read the test runner's stdin, so add `< /dev/null` to a command that might prompt.\n */\nexport const createShell = (options: ShellOptions = {}): Shell => {\n // Use a separate instance so settings on Bun's global `$` don't apply here.\n const bunShell = new bun.$.Shell()\n const settings: Required<ShellOptions> = {\n cwd: options.cwd ?? process.cwd(),\n // Drop `FORCE_COLOR` because `bask` sets it when the tests run in a terminal and CI does not.\n env: options.env ?? { ...process.env, FORCE_COLOR: undefined },\n localBins: options.localBins ?? true,\n throws: options.throws ?? true,\n }\n\n return (strings, ...expressions) => new ShellCommand(bunShell(strings, ...expressions), settings)\n}\n"],"mappings":";;;;;;;;AAiDA,MAAa,eAAe,UAAwB,CAAC,MAAa;CAEhE,MAAM,WAAW,IAAI,IAAI,EAAE,MAAM;CACjC,MAAM,WAAmC;EACvC,KAAK,QAAQ,OAAO,QAAQ,IAAI;EAEhC,KAAK,QAAQ,OAAO;GAAE,GAAG,QAAQ;GAAK,aAAa,KAAA;EAAU;EAC7D,WAAW,QAAQ,aAAa;EAChC,QAAQ,QAAQ,UAAU;CAC5B;CAEA,QAAQ,SAAS,GAAG,gBAAgB,IAAI,aAAa,SAAS,SAAS,GAAG,WAAW,GAAG,QAAQ;AAClG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"temp-dir.d.ts","names":[],"sources":["../../src/test-utils/temp-dir.ts"],"mappings":";qBAOa,cAAW,mBAAwB"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import os from "node:os";
|
|
4
|
+
// src/test-utils/temp-dir.ts
|
|
5
|
+
const tempDirs = [];
|
|
6
|
+
/** Makes a temp dir whose name starts with `prefix`, and records it for `removeTempDirs`. */
|
|
7
|
+
const makeTempDir = async (prefix) => {
|
|
8
|
+
const dir = await fs.mkdtemp(path.join(os.tmpdir(), prefix));
|
|
9
|
+
tempDirs.push(dir);
|
|
10
|
+
return dir;
|
|
11
|
+
};
|
|
12
|
+
/** Removes every dir made by `makeTempDir`. */
|
|
13
|
+
const removeTempDirs = async () => {
|
|
14
|
+
await Promise.all(tempDirs.map(async (dir) => fs.rm(dir, {
|
|
15
|
+
recursive: true,
|
|
16
|
+
force: true
|
|
17
|
+
})));
|
|
18
|
+
};
|
|
19
|
+
export { makeTempDir, removeTempDirs };
|
|
20
|
+
|
|
21
|
+
//# sourceMappingURL=temp-dir.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"temp-dir.js","names":[],"sources":["../../src/test-utils/temp-dir.ts"],"sourcesContent":["import fs from \"node:fs/promises\"\nimport os from \"node:os\"\nimport path from \"node:path\"\n\nconst tempDirs: string[] = []\n\n/** Makes a temp dir whose name starts with `prefix`, and records it for `removeTempDirs`. */\nexport const makeTempDir = async (prefix: string) => {\n const dir = await fs.mkdtemp(path.join(os.tmpdir(), prefix))\n tempDirs.push(dir)\n return dir\n}\n\n/** Removes every dir made by `makeTempDir`. */\nexport const removeTempDirs = async () => {\n await Promise.all(tempDirs.map(async (dir) => fs.rm(dir, { recursive: true, force: true })))\n}\n"],"mappings":";;;;AAIA,MAAM,WAAqB,CAAC;;AAG5B,MAAa,cAAc,OAAO,WAAmB;CACnD,MAAM,MAAM,MAAM,GAAG,QAAQ,KAAK,KAAK,GAAG,OAAO,GAAG,MAAM,CAAC;CAC3D,SAAS,KAAK,GAAG;CACjB,OAAO;AACT;;AAGA,MAAa,iBAAiB,YAAY;CACxC,MAAM,QAAQ,IAAI,SAAS,IAAI,OAAO,QAAQ,GAAG,GAAG,KAAK;EAAE,WAAW;EAAM,OAAO;CAAK,CAAC,CAAC,CAAC;AAC7F"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adamhl8/configs",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.2.1",
|
|
4
4
|
"description": "My shared configs for TS projects",
|
|
5
5
|
"homepage": "https://github.com/adamhl8/configs",
|
|
6
6
|
"bugs": {
|
|
@@ -40,6 +40,14 @@
|
|
|
40
40
|
"./bask": {
|
|
41
41
|
"types": "./dist/configs/bask.base.d.ts",
|
|
42
42
|
"import": "./dist/configs/bask.base.js"
|
|
43
|
+
},
|
|
44
|
+
"./test": {
|
|
45
|
+
"types": "./dist/test-utils/index.d.ts",
|
|
46
|
+
"import": "./dist/test-utils/index.js"
|
|
47
|
+
},
|
|
48
|
+
"./test/preload": {
|
|
49
|
+
"types": "./dist/test-utils/preload.d.ts",
|
|
50
|
+
"import": "./dist/test-utils/preload.js"
|
|
43
51
|
}
|
|
44
52
|
},
|
|
45
53
|
"publishConfig": {
|