@adamhl8/configs 3.5.0 → 4.0.0
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 +34 -58
- package/dist/adamhl8-tsconfig/index +43 -0
- package/dist/configs/bask.base.js +13 -11
- package/dist/configs/bask.base.js.map +1 -1
- package/dist/configs/commitlint.base.js.map +1 -1
- package/dist/configs/gitignore.base +0 -1
- package/dist/configs/oxlint.base.d.ts +1 -1
- package/dist/configs/oxlint.base.js +1 -1
- package/dist/configs/oxlint.base.js.map +1 -1
- package/dist/configs/tsconfig.base.json +0 -1
- package/dist/configs/tsconfig.no-dts.base.json +7 -0
- package/dist/configs/tsdown.base.js.map +1 -1
- package/dist/test-utils/fixture.d.ts +1 -7
- package/dist/test-utils/fixture.js +2 -3
- package/dist/test-utils/fixture.js.map +1 -1
- package/dist/test-utils/index.d.ts +3 -4
- package/dist/test-utils/index.js +3 -4
- package/dist/test-utils/pack.d.ts +4 -1
- package/dist/test-utils/pack.js +16 -4
- package/dist/test-utils/pack.js.map +1 -1
- package/dist/test-utils/shell/command.js +1 -1
- package/dist/test-utils/temp-dir.d.ts +2 -2
- package/dist/test-utils/temp-dir.js +5 -3
- package/dist/test-utils/temp-dir.js.map +1 -1
- package/dist/utils.js +11 -2
- package/dist/utils.js.map +1 -1
- package/package.json +21 -43
- package/dist/configs/bask.base.d.ts.map +0 -1
- package/dist/configs/commitlint.base.d.ts.map +0 -1
- package/dist/configs/knip.base.d.ts.map +0 -1
- package/dist/configs/oxfmt.base.d.ts.map +0 -1
- package/dist/configs/oxlint.base.d.ts.map +0 -1
- package/dist/configs/release-it.base.d.ts.map +0 -1
- package/dist/configs/tsdown.base.d.ts.map +0 -1
- package/dist/env/index.d.ts.map +0 -1
- package/dist/env/utils.d.ts.map +0 -1
- package/dist/merge-config/merge-config.d.ts.map +0 -1
- package/dist/merge-config/merge.types.d.ts.map +0 -1
- package/dist/test-utils/fixture.d.ts.map +0 -1
- package/dist/test-utils/pack.d.ts.map +0 -1
- package/dist/test-utils/shell/command.d.ts.map +0 -1
- package/dist/test-utils/shell/env.d.ts.map +0 -1
- package/dist/test-utils/shell/shell.d.ts.map +0 -1
- package/dist/test-utils/subprocess-coverage/child-preload.d.ts +0 -1
- package/dist/test-utils/subprocess-coverage/child-preload.js +0 -68
- package/dist/test-utils/subprocess-coverage/child-preload.js.map +0 -1
- package/dist/test-utils/subprocess-coverage/env.d.ts +0 -7
- package/dist/test-utils/subprocess-coverage/env.d.ts.map +0 -1
- package/dist/test-utils/subprocess-coverage/env.js +0 -19
- package/dist/test-utils/subprocess-coverage/env.js.map +0 -1
- package/dist/test-utils/subprocess-coverage/preload.d.ts +0 -1
- package/dist/test-utils/subprocess-coverage/preload.js +0 -43
- package/dist/test-utils/subprocess-coverage/preload.js.map +0 -1
- package/dist/test-utils/subprocess-coverage/report.js +0 -35
- package/dist/test-utils/subprocess-coverage/report.js.map +0 -1
- package/dist/test-utils/temp-dir.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -29,6 +29,7 @@ Configs, tasks, and workflows I use across my TS projects.
|
|
|
29
29
|
- [Synced files](#synced-files)
|
|
30
30
|
- [bunfig](#bunfig)
|
|
31
31
|
- [gitignore](#gitignore)
|
|
32
|
+
- [tsconfig extends](#tsconfig-extends)
|
|
32
33
|
- [Utilities](#utilities)
|
|
33
34
|
- [env](#env)
|
|
34
35
|
- [test](#test)
|
|
@@ -61,7 +62,6 @@ Some tools are only needed by some projects:
|
|
|
61
62
|
- Published packages: `tsdown publint @arethetypeswrong/core`
|
|
62
63
|
- Releases: `release-it release-it-git-cliff` (see [release-it](#release-it))
|
|
63
64
|
- Astro projects that use Tailwind: `tailwint @tailwindcss/language-server` (see [bask tasks](#bask-tasks))
|
|
64
|
-
- Subprocess test coverage: `@vitest/istanbul-lib-coverage @vitest/istanbul-lib-instrument @vitest/istanbul-lib-report @vitest/istanbul-lib-source-maps` (see [Subprocess coverage](#subprocess-coverage))
|
|
65
65
|
|
|
66
66
|
## Setup
|
|
67
67
|
|
|
@@ -82,7 +82,7 @@ A project using everything here has these files:
|
|
|
82
82
|
| `.github/workflows/*.yml` | [GitHub Actions](#github-actions) |
|
|
83
83
|
| `github.tofu` | [GitHub repo settings](#github-repo-settings) |
|
|
84
84
|
|
|
85
|
-
`bunfig.toml
|
|
85
|
+
`bunfig.toml`, `.gitignore`, and the `extends` in `tsconfig.json` are kept up to date by the [synced files](#synced-files).
|
|
86
86
|
|
|
87
87
|
## Configs
|
|
88
88
|
|
|
@@ -118,6 +118,10 @@ The second config works at any depth: only the arrays you provide are replaced,
|
|
|
118
118
|
|
|
119
119
|
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.
|
|
120
120
|
|
|
121
|
+
The base sets `declaration: true` so `tsc` fails on an export whose type can't be named. tsdown doesn't catch this: with Bun's isolated linker, it silently publishes that export as `any`.
|
|
122
|
+
|
|
123
|
+
`@adamhl8/configs/tsconfig/no-dts` is the same config with `declaration` off, so `tsc` doesn't report these errors in a project that never publishes a `.d.ts`. You don't need to choose between them because the [tsconfig sync](#tsconfig-extends) sets `extends` for you.
|
|
124
|
+
|
|
121
125
|
### oxfmt
|
|
122
126
|
|
|
123
127
|
```ts
|
|
@@ -260,17 +264,17 @@ export * from "@adamhl8/configs/bask"
|
|
|
260
264
|
|
|
261
265
|
Run `bunx bask` to list them along with the allowed commit types.
|
|
262
266
|
|
|
263
|
-
| Task | What it does
|
|
264
|
-
| -------------- |
|
|
265
|
-
| `lint` | Updates the README's table of contents, runs oxlint (with fixes), oxfmt, tailwint, `tofu fmt`, knip, and actionlint, then `test` |
|
|
266
|
-
| `build` | Runs `lint`, `tsdown`, and `tofu-check`. In CI, it fails when lint fixes or formatting changed any files
|
|
267
|
-
| `test` | Runs `bun test`, which passes when there are no tests
|
|
268
|
-
| `bump-deps` | Updates every dependency to its latest version, then reinstalls without the lockfile, `node_modules`, or bun's cache
|
|
269
|
-
| `release` | Starts the [release workflow](#release) (`gh workflow run release.yml`)
|
|
270
|
-
| `release-run` | Runs `release-it --ci`. It's hidden because only the release workflow runs it
|
|
271
|
-
| `tofu-check` | Runs `tofu plan` to check the [GitHub repo settings](#github-repo-settings) for drift
|
|
272
|
-
| `commit-types` | Prints the allowed commit types
|
|
273
|
-
| `prepare` | Runs `lefthook install`, the [synced files](#synced-files), and `tofu init -upgrade`
|
|
267
|
+
| Task | What it does |
|
|
268
|
+
| -------------- | --------------------------------------------------------------------------------------------------------------------------------------- |
|
|
269
|
+
| `lint` | Updates the README's table of contents, runs oxlint (with fixes), oxfmt, tailwint, `tofu fmt`, `tsc`, knip, and actionlint, then `test` |
|
|
270
|
+
| `build` | Runs `lint`, `tsdown`, and `tofu-check`. In CI, it fails when lint fixes or formatting changed any files |
|
|
271
|
+
| `test` | Runs `bun test`, which passes when there are no tests |
|
|
272
|
+
| `bump-deps` | Updates every dependency to its latest version, then reinstalls without the lockfile, `node_modules`, or bun's cache |
|
|
273
|
+
| `release` | Starts the [release workflow](#release) (`gh workflow run release.yml`) |
|
|
274
|
+
| `release-run` | Runs `release-it --ci`. It's hidden because only the release workflow runs it |
|
|
275
|
+
| `tofu-check` | Runs `tofu plan` to check the [GitHub repo settings](#github-repo-settings) for drift |
|
|
276
|
+
| `commit-types` | Prints the allowed commit types |
|
|
277
|
+
| `prepare` | Runs `lefthook install`, the [synced files](#synced-files), and `tofu init -upgrade` |
|
|
274
278
|
|
|
275
279
|
The tasks skip the steps a project doesn't need, so projects can use them as-is:
|
|
276
280
|
|
|
@@ -350,6 +354,17 @@ dist/
|
|
|
350
354
|
|
|
351
355
|
Everything below the marker is left untouched. The sync can also be run manually by running `adamhl8-gitignore`.
|
|
352
356
|
|
|
357
|
+
### tsconfig extends
|
|
358
|
+
|
|
359
|
+
A tsconfig can't branch on the project, so the right base config is synced into the project's `tsconfig.json`. The `prepare` task runs the `adamhl8-tsconfig` bin, which sets `extends` based on whether the `package.json` declares types:
|
|
360
|
+
|
|
361
|
+
- `@adamhl8/configs/tsconfig` when it has a top-level `types` or `typings` field, or a `types` condition or declaration file path anywhere in `exports`
|
|
362
|
+
- `@adamhl8/configs/tsconfig/no-dts` otherwise
|
|
363
|
+
|
|
364
|
+
A package that publishes types has to declare them for this to work. TypeScript also finds a `.d.ts` next to its `.js` without one, but this sync would then turn off the `declaration` check that protects those types.
|
|
365
|
+
|
|
366
|
+
Only the `extends` value changes, so comments, formatting, and other options are left untouched. To opt out, extend anything other than these two configs, or set `declaration` in the project's own `compilerOptions`. The sync can also be run manually by running `adamhl8-tsconfig`.
|
|
367
|
+
|
|
353
368
|
## Utilities
|
|
354
369
|
|
|
355
370
|
### env
|
|
@@ -377,7 +392,7 @@ Helpers for integration tests that run real commands in temp dirs, exported from
|
|
|
377
392
|
```ts
|
|
378
393
|
import { copyFixture, minimalEnv, packPackage } from "@adamhl8/configs/test"
|
|
379
394
|
|
|
380
|
-
const tarball = await packPackage(ROOT)
|
|
395
|
+
const tarball = await packPackage(ROOT)
|
|
381
396
|
const { dir, run } = await copyFixture(FIXTURE, { shell: { env: minimalEnv() } })
|
|
382
397
|
await run`bun add -d ${tarball}`
|
|
383
398
|
|
|
@@ -394,11 +409,10 @@ const { exitCode: failedCode } = await run`my-cli --bad-flag`.nothrow()
|
|
|
394
409
|
- Each command can chain `.cwd()`, `.env()` (merged over the shell's), `.localBins()`, and `.nothrow()`.
|
|
395
410
|
- The `node` shims from `bask` and `bun run --bun` are taken off `PATH`, so `node` is always the real Node.
|
|
396
411
|
- Commands read the test runner's stdin, so add `< /dev/null` to a command that might prompt.
|
|
397
|
-
- `copyFixture(fixture, {
|
|
398
|
-
- `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.
|
|
412
|
+
- `copyFixture(fixture, { 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`.
|
|
413
|
+
- `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. It runs once per resolved `root` for the life of the test process, so call it wherever a test needs the tarball. Concurrent callers share one build, and a failed pack fails every caller the same way.
|
|
399
414
|
- `minimalEnv(extra)` returns just `PATH` and `HOME`, plus `extra`.
|
|
400
|
-
- `makeTempDir(
|
|
401
|
-
- `subprocessCoverageEnv()` returns the variables that turn on [subprocess coverage](#subprocess-coverage) for a shell's `env`, or nothing when it's off.
|
|
415
|
+
- `makeTempDir()` makes a temp dir that's removed after the test run. Its name starts with the name of the current working directory, so a dir left behind by a killed run shows which project it came from. `copyFixture` and `packPackage` use it.
|
|
402
416
|
|
|
403
417
|
The temp dirs are removed by a preload, which each project adds to its `bunfig.toml`:
|
|
404
418
|
|
|
@@ -415,46 +429,6 @@ import "@adamhl8/configs/test/preload"
|
|
|
415
429
|
|
|
416
430
|
It isn't in the shared bunfig base because `adamhl8-bunfig` merges arrays by index, so a project's own `preload` would replace it.
|
|
417
431
|
|
|
418
|
-
#### Subprocess coverage
|
|
419
|
-
|
|
420
|
-
Bun's coverage only measures the test process, so it misses a package's own code when tests run it from the packed tarball in child processes. A second preload covers that code, imported after the first at the top of the project's own preload:
|
|
421
|
-
|
|
422
|
-
```ts
|
|
423
|
-
import "@adamhl8/configs/test/preload"
|
|
424
|
-
import "@adamhl8/configs/test/subprocess-coverage"
|
|
425
|
-
```
|
|
426
|
-
|
|
427
|
-
A project without its own preload can list both in `bunfig.toml` instead:
|
|
428
|
-
|
|
429
|
-
```toml
|
|
430
|
-
[test]
|
|
431
|
-
preload = ["@adamhl8/configs/test/preload", "@adamhl8/configs/test/subprocess-coverage"]
|
|
432
|
-
```
|
|
433
|
-
|
|
434
|
-
- It sets `BUN_OPTIONS` and a settings variable on `process.env`. Every Bun process started with them loads a preload that instruments the installed package's `dist/` with Istanbul (the package named in the project's `package.json`).
|
|
435
|
-
- A shell that inherits `process.env` passes the variables on as is. A shell that replaces it, like one built on `minimalEnv()`, adds them with `subprocessCoverageEnv()`:
|
|
436
|
-
|
|
437
|
-
```ts
|
|
438
|
-
import { copyFixture, minimalEnv, subprocessCoverageEnv } from "@adamhl8/configs/test"
|
|
439
|
-
|
|
440
|
-
const { run } = await copyFixture(FIXTURE, { shell: { env: minimalEnv(subprocessCoverageEnv()) } })
|
|
441
|
-
```
|
|
442
|
-
|
|
443
|
-
- After the run, the coverage from every process is merged, mapped back to `src/` through the package's source maps, printed as a table (statements, branches, functions, lines), and written to `coverage/subprocess/lcov.info`, which keeps it apart from the `coverage/lcov.info` that Bun writes.
|
|
444
|
-
- To keep Bun's own coverage for code that tests import directly, leave `coverage = true` under `[test]` and list the files that subprocess coverage owns in `coveragePathIgnorePatterns`. Bun then skips those files, and the subprocess report keeps only them, so each file appears in one of the two tables. A file you don't list is left to Bun, so a file that only child processes load shows up in neither table. With `coverage = false`, the subprocess report keeps every file.
|
|
445
|
-
|
|
446
|
-
```toml
|
|
447
|
-
[test]
|
|
448
|
-
coverage = true
|
|
449
|
-
coveragePathIgnorePatterns = ["**/__tests__/**", "src/cli/**"]
|
|
450
|
-
```
|
|
451
|
-
|
|
452
|
-
- This reads `bunfig.toml` from the project root, so turning on Bun's coverage with `--coverage` instead leaves the subprocess report unfiltered.
|
|
453
|
-
- The project needs the optional peer dependencies listed under [Installation](#installation) and a build with source maps, which `tsdownConfig` produces. Tests have to install the packed tarball, as with `packPackage`, because only the installed `dist/` is instrumented.
|
|
454
|
-
- A process killed by a signal writes no coverage. An `exit` listener that the package adds in the same tick as a synchronous `process.exit()` isn't counted.
|
|
455
|
-
|
|
456
|
-
Import it only from a preload. Imported from a test file, its `afterAll` would be scoped to that file, so the report would run after that file instead of after the whole run.
|
|
457
|
-
|
|
458
432
|
## GitHub Actions
|
|
459
433
|
|
|
460
434
|
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.
|
|
@@ -618,3 +592,5 @@ The `prepare` task runs `tofu init -upgrade`, and the `tofu-check` task (which `
|
|
|
618
592
|
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.
|
|
619
593
|
|
|
620
594
|
With bun's `isolated` linker, the self-dependency is a copy made at install time. After adding or moving an export, run `bun install --force` to refresh the copy, or type checks of code that imports the new export fail.
|
|
595
|
+
|
|
596
|
+
`bun.lock` records this repo's bins on the self-dependency's entry, and `bun install` doesn't update an existing entry. After adding a bin, add it to that entry by hand, or `bun install` fails in the `prepare` task with `Script not found`. Running `rm bun.lock && bun install` also updates the entry, but it can pick up newer dependency versions.
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
import bun from "bun";
|
|
3
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
4
|
+
import { isPlainObject } from "es-toolkit/predicate";
|
|
5
|
+
const keysOf = (value) => isPlainObject(value) ? Object.keys(value) : [];
|
|
6
|
+
const DECLARATION_FILE = /\.d\.[cm]?ts$/v;
|
|
7
|
+
/** Checks an `exports` value, at any depth, for a `types` condition or a path to a declaration file. */
|
|
8
|
+
const exportsDeclareTypes = (value) => {
|
|
9
|
+
if (typeof value === "string") return DECLARATION_FILE.test(value);
|
|
10
|
+
if (Array.isArray(value)) return value.some(exportsDeclareTypes);
|
|
11
|
+
if (!isPlainObject(value)) return false;
|
|
12
|
+
return "types" in value || Object.values(value).some(exportsDeclareTypes);
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Reads the project's `package.json` fields that the base configs branch on. `dependencies` merges the regular, dev,
|
|
16
|
+
* and peer dependency names. `publishesTypes` is true when the `package.json` declares types.
|
|
17
|
+
*/
|
|
18
|
+
const readProjectPackageJson = () => {
|
|
19
|
+
const packageJson = existsSync("package.json") ? JSON.parse(readFileSync("package.json", "utf8")) : {};
|
|
20
|
+
const fields = isPlainObject(packageJson) ? packageJson : {};
|
|
21
|
+
return {
|
|
22
|
+
dependencies: new Set([
|
|
23
|
+
"dependencies",
|
|
24
|
+
"devDependencies",
|
|
25
|
+
"peerDependencies"
|
|
26
|
+
].flatMap((field) => keysOf(fields[field]))),
|
|
27
|
+
engines: new Set(keysOf(fields["engines"])),
|
|
28
|
+
publishesTypes: "types" in fields || "typings" in fields || exportsDeclareTypes(fields["exports"])
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
const TSCONFIG_PATH = "tsconfig.json";
|
|
32
|
+
const DTS_CONFIG = "@adamhl8/configs/tsconfig";
|
|
33
|
+
const NO_DTS_CONFIG = "@adamhl8/configs/tsconfig/no-dts";
|
|
34
|
+
const MANAGED_EXTENDS = /(?<key>"extends"\s*:\s*)"@adamhl8\/configs\/tsconfig(?:\/no-dts)?"/v;
|
|
35
|
+
const tsconfigFile = bun.file(TSCONFIG_PATH);
|
|
36
|
+
if (await tsconfigFile.exists()) {
|
|
37
|
+
const { publishesTypes } = readProjectPackageJson();
|
|
38
|
+
const config = publishesTypes ? DTS_CONFIG : NO_DTS_CONFIG;
|
|
39
|
+
const current = await tsconfigFile.text();
|
|
40
|
+
const updated = current.replace(MANAGED_EXTENDS, `$<key>"${config}"`);
|
|
41
|
+
if (updated !== current) await bun.write(TSCONFIG_PATH, updated);
|
|
42
|
+
}
|
|
43
|
+
export {};
|
|
@@ -19,9 +19,10 @@ const tofuCheck = task(async ({ sh }) => {
|
|
|
19
19
|
});
|
|
20
20
|
const prepare = task(async ({ sh }) => {
|
|
21
21
|
if (!inCi) await sh`lefthook install`;
|
|
22
|
-
await sh`
|
|
23
|
-
await sh`
|
|
24
|
-
await sh`
|
|
22
|
+
await sh`adamhl8-gitignore`;
|
|
23
|
+
await sh`adamhl8-bunfig`;
|
|
24
|
+
await sh`adamhl8-tsconfig`;
|
|
25
|
+
await sh`oxfmt bunfig.toml`;
|
|
25
26
|
if (await canRunTofu()) await sh`tofu init -upgrade`;
|
|
26
27
|
});
|
|
27
28
|
const bumpDeps = task(async ({ sh }) => {
|
|
@@ -34,11 +35,11 @@ const test = task(async ({ sh }) => {
|
|
|
34
35
|
await sh`bun test --pass-with-no-tests`.echo(false);
|
|
35
36
|
});
|
|
36
37
|
const lint = task(async ({ sh }) => {
|
|
37
|
-
await sh`
|
|
38
|
-
await sh`
|
|
39
|
-
await sh`
|
|
38
|
+
await sh`markdown-toc -i --bullets - --maxdepth 3 ./README.md`;
|
|
39
|
+
await sh`oxlint --fix --fix-suggestions --fix-dangerously`;
|
|
40
|
+
await sh`oxfmt`;
|
|
40
41
|
if (resolveProjectTailwind()) {
|
|
41
|
-
if ((await lsFiles([":(glob)**/*.astro"])).length > 0) await sh`
|
|
42
|
+
if ((await lsFiles([":(glob)**/*.astro"])).length > 0) await sh`tailwint "**/*.astro"`;
|
|
42
43
|
}
|
|
43
44
|
const tofuFiles = await lsFiles([
|
|
44
45
|
":(glob)**/*.tf",
|
|
@@ -48,13 +49,14 @@ const lint = task(async ({ sh }) => {
|
|
|
48
49
|
":(glob)**/*.tofutest.hcl"
|
|
49
50
|
]);
|
|
50
51
|
if (tofuFiles.length > 0) await sh`tofu fmt ${tofuFiles}`;
|
|
51
|
-
await sh`
|
|
52
|
+
await sh`tsc`;
|
|
53
|
+
await sh`knip-bun`;
|
|
52
54
|
if (existsSync(".github/workflows")) await sh`actionlint`;
|
|
53
55
|
await test();
|
|
54
56
|
});
|
|
55
57
|
const build = task(async ({ sh }) => {
|
|
56
58
|
await lint();
|
|
57
|
-
if (await bun.file("tsdown.config.ts").exists()) await sh`
|
|
59
|
+
if (await bun.file("tsdown.config.ts").exists()) await sh`tsdown`;
|
|
58
60
|
if (inCi) {
|
|
59
61
|
await sh`git add --intent-to-add --all`;
|
|
60
62
|
await sh`git diff --exit-code`;
|
|
@@ -65,10 +67,10 @@ const release = task(async ({ sh }) => {
|
|
|
65
67
|
await sh`gh workflow run release.yml`;
|
|
66
68
|
});
|
|
67
69
|
const releaseRun = task({ hidden: true }, async ({ sh }) => {
|
|
68
|
-
await sh`
|
|
70
|
+
await sh`release-it -VV --ci`;
|
|
69
71
|
});
|
|
70
72
|
const commitTypes = task(async ({ sh }) => {
|
|
71
|
-
const { 2: types } = (await sh`
|
|
73
|
+
const { 2: types } = (await sh`commitlint --print-config json`.echo(false).json()).rules["type-enum"];
|
|
72
74
|
console.log(`Commit types:\n ${types.join("\n ")}`);
|
|
73
75
|
});
|
|
74
76
|
list.after(async () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bask.base.js","names":[],"sources":["../../src/configs/bask.base.ts"],"sourcesContent":["import { existsSync } from \"node:fs\"\n\nimport { list, task } from \"@adamhl8/bask\"\nimport bun, { $, Glob } from \"bun\"\n\nimport { resolveProjectTailwind } from \"#utils.ts\"\n\nconst inCi = Boolean(process.env[\"CI\"])\n\n/** Lists tracked and untracked files matching the pathspecs, skipping gitignored ones. */\nconst lsFiles = async (pathspecs: string[]) => {\n const output = await $`git ls-files -z --cached --others --exclude-standard -- ${pathspecs}`.quiet().text()\n return output.split(\"\\0\").filter(Boolean)\n}\n\n/** Checks that we're not in CI, the repo has a root tofu module, and the aws profile exists on this machine. */\nconst canRunTofu = async () => {\n if (inCi) return false\n const tofuFiles = await Array.fromAsync(new Glob(\"*.tofu\").scan())\n if (tofuFiles.length === 0) return false\n const profiles = await $`aws configure list-profiles`.nothrow().quiet().text()\n return profiles.split(\"\\n\").includes(\"adamhl8\")\n}\n\nexport const tofuCheck = task(async ({ sh }) => {\n if (await canRunTofu()) await sh`tofu plan -detailed-exitcode -concise -compact-warnings`\n})\n\nexport const prepare = task(async ({ sh }) => {\n // Skip `lefthook install` in CI so commits made by the workflows don't run the hooks.\n if (!inCi) await sh`lefthook install`\n await sh`
|
|
1
|
+
{"version":3,"file":"bask.base.js","names":[],"sources":["../../src/configs/bask.base.ts"],"sourcesContent":["import { existsSync } from \"node:fs\"\n\nimport { list, task } from \"@adamhl8/bask\"\nimport bun, { $, Glob } from \"bun\"\n\nimport { resolveProjectTailwind } from \"#utils.ts\"\n\nconst inCi = Boolean(process.env[\"CI\"])\n\n/** Lists tracked and untracked files matching the pathspecs, skipping gitignored ones. */\nconst lsFiles = async (pathspecs: string[]) => {\n const output = await $`git ls-files -z --cached --others --exclude-standard -- ${pathspecs}`.quiet().text()\n return output.split(\"\\0\").filter(Boolean)\n}\n\n/** Checks that we're not in CI, the repo has a root tofu module, and the aws profile exists on this machine. */\nconst canRunTofu = async () => {\n if (inCi) return false\n const tofuFiles = await Array.fromAsync(new Glob(\"*.tofu\").scan())\n if (tofuFiles.length === 0) return false\n const profiles = await $`aws configure list-profiles`.nothrow().quiet().text()\n return profiles.split(\"\\n\").includes(\"adamhl8\")\n}\n\nexport const tofuCheck = task(async ({ sh }) => {\n if (await canRunTofu()) await sh`tofu plan -detailed-exitcode -concise -compact-warnings`\n})\n\nexport const prepare = task(async ({ sh }) => {\n // Skip `lefthook install` in CI so commits made by the workflows don't run the hooks.\n if (!inCi) await sh`lefthook install`\n await sh`adamhl8-gitignore`\n await sh`adamhl8-bunfig`\n await sh`adamhl8-tsconfig`\n await sh`oxfmt bunfig.toml`\n if (await canRunTofu()) await sh`tofu init -upgrade`\n})\n\nexport const bumpDeps = task(async ({ sh }) => {\n await sh`bunx npm-check-updates --upgrade --format group`\n await sh`rm -f bun.lock`\n await sh`rm -rf node_modules/`\n await sh`bun install --no-summary --no-cache`\n})\n\nexport const test = task(async ({ sh }) => {\n await sh`bun test --pass-with-no-tests`.echo(false)\n})\n\nexport const lint = task(async ({ sh }) => {\n await sh`markdown-toc -i --bullets - --maxdepth 3 ./README.md`\n await sh`oxlint --fix --fix-suggestions --fix-dangerously`\n await sh`oxfmt`\n\n if (resolveProjectTailwind()) {\n // Check for `.astro` files first so projects without them don't need tailwint installed.\n const astroFiles = await lsFiles([\":(glob)**/*.astro\"])\n // Skip `--fix` because tailwint resolves a class conflict by deleting a class by position, not by which one wins.\n if (astroFiles.length > 0) await sh`tailwint \"**/*.astro\"`\n }\n\n const tofuFiles = await lsFiles([\n \":(glob)**/*.tf\",\n \":(glob)**/*.tofu\",\n \":(glob)**/*.tfvars\",\n \":(glob)**/*.tftest.hcl\",\n \":(glob)**/*.tofutest.hcl\",\n ])\n if (tofuFiles.length > 0) await sh`tofu fmt ${tofuFiles}`\n\n await sh`tsc`\n await sh`knip-bun`\n if (existsSync(\".github/workflows\")) await sh`actionlint`\n await test()\n})\n\nexport const build = task(async ({ sh }) => {\n await lint()\n if (await bun.file(\"tsdown.config.ts\").exists()) await sh`tsdown`\n // Fail in CI if the build changed or created any files, because lint fixes and formatting are applied in place.\n // `--intent-to-add` makes untracked files show up in the diff.\n if (inCi) {\n await sh`git add --intent-to-add --all`\n await sh`git diff --exit-code`\n }\n await tofuCheck()\n})\n\nexport const release = task(async ({ sh }) => {\n await sh`gh workflow run release.yml`\n})\n\nexport const releaseRun = task({ hidden: true }, async ({ sh }) => {\n await sh`release-it -VV --ci`\n})\n\nexport const commitTypes = task(async ({ sh }) => {\n // oxlint-disable-next-line typescript/no-unsafe-type-assertion - trust the shape that `commitlint --print-config json` prints\n const config = (await sh`commitlint --print-config json`.echo(false).json()) as {\n rules: { \"type-enum\": [number, string, string[]] }\n }\n const { 2: types } = config.rules[\"type-enum\"]\n console.log(`Commit types:\\n ${types.join(\"\\n \")}`)\n})\n\nlist.after(async () => {\n console.log()\n await commitTypes()\n})\n"],"mappings":";;;;;AAOA,MAAM,OAAO,QAAQ,QAAQ,IAAI,KAAK;;AAGtC,MAAM,UAAU,OAAO,cAAwB;CAE7C,QAAO,MADc,CAAC,2DAA2D,YAAY,MAAM,CAAC,CAA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AW,mBAAmB,GAAG,MAAM,EAAE;CAC7C,MAAM,KAAK;AACb,CAAC;AAED,MAAa,QAAQ,KAAK,OAAO,EAAE,SAAS;CAC1C,MAAM,KAAK;CACX,IAAI,MAAM,IAAI,KAAK,kBAAkB,CAAC,CAAC,OAAO,GAAG,MAAM,EAAE;CAGzD,IAAI,MAAM;EACR,MAAM,EAAE;EACR,MAAM,EAAE;CACV;CACA,MAAM,UAAU;AAClB,CAAC;AAED,MAAa,UAAU,KAAK,OAAO,EAAE,SAAS;CAC5C,MAAM,EAAE;AACV,CAAC;AAED,MAAa,aAAa,KAAK,EAAE,QAAQ,KAAK,GAAG,OAAO,EAAE,SAAS;CACjE,MAAM,EAAE;AACV,CAAC;AAED,MAAa,cAAc,KAAK,OAAO,EAAE,SAAS;CAKhD,MAAM,EAAE,GAAG,WAAU,MAHC,EAAE,iCAAiC,KAAK,KAAK,CAAC,CAAC,KAAK,EAAA,CAG9C,MAAM;CAClC,QAAQ,IAAI,sBAAsB,MAAM,KAAK,QAAQ,GAAG;AAC1D,CAAC;AAED,KAAK,MAAM,YAAY;CACrB,QAAQ,IAAI;CACZ,MAAM,YAAY;AACpB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"commitlint.base.js","names":[],"sources":["../../src/configs/commitlint.base.ts"],"sourcesContent":["import conventional from \"@commitlint/config-conventional\"\nimport type { UserConfig } from \"@commitlint/types\"\n\nimport { createMergeConfigFn } from \"#merge-config/merge-config.ts\"\n\nconst [_severity, _condition, conventionalTypes] = conventional.rules[\"type-enum\"]\n\nconst EXCLUDED_TYPES = new Set([\"test\", \"style\", \"build\"])\nconst filteredTypes = conventionalTypes.filter((type) => !EXCLUDED_TYPES.has(type))\nconst commitTypes = [...filteredTypes, \"improve\", \"release\"]\n\nconst baseConfig = {\n extends: [\"@commitlint/config-conventional\"],\n rules: {\n \"type-enum\": [2, \"always\", commitTypes],\n },\n} as const satisfies UserConfig\n\nexport const commitlintConfig = createMergeConfigFn<UserConfig, typeof baseConfig>(baseConfig)\n"],"mappings":";;;AAKA,MAAM,CAAC,WAAW,YAAY,qBAAqB,aAAa,MAAM;AAEtE,MAAM,iCAAiB,IAAI,IAAI;CAAC;CAAQ;CAAS;AAAO,CAAC;AAIzD,MAAM,aAAa;CACjB,SAAS,CAAC,iCAAiC;CAC3C,OAAO,
|
|
1
|
+
{"version":3,"file":"commitlint.base.js","names":[],"sources":["../../src/configs/commitlint.base.ts"],"sourcesContent":["import conventional from \"@commitlint/config-conventional\"\nimport type { UserConfig } from \"@commitlint/types\"\n\nimport { createMergeConfigFn } from \"#merge-config/merge-config.ts\"\n\nconst [_severity, _condition, conventionalTypes] = conventional.rules[\"type-enum\"]\n\nconst EXCLUDED_TYPES = new Set([\"test\", \"style\", \"build\"])\nconst filteredTypes = conventionalTypes.filter((type) => !EXCLUDED_TYPES.has(type))\nconst commitTypes = [...filteredTypes, \"improve\", \"release\"]\n\nconst baseConfig = {\n extends: [\"@commitlint/config-conventional\"],\n rules: {\n // oxlint-disable-next-line typescript/no-unsafe-enum-assignment - use `2` because the enum leaks into consumer types\n \"type-enum\": [2, \"always\", commitTypes],\n },\n} as const satisfies UserConfig\n\nexport const commitlintConfig = createMergeConfigFn<UserConfig, typeof baseConfig>(baseConfig)\n"],"mappings":";;;AAKA,MAAM,CAAC,WAAW,YAAY,qBAAqB,aAAa,MAAM;AAEtE,MAAM,iCAAiB,IAAI,IAAI;CAAC;CAAQ;CAAS;AAAO,CAAC;AAIzD,MAAM,aAAa;CACjB,SAAS,CAAC,iCAAiC;CAC3C,OAAO,EAEL,aAAa;EAAC;EAAG;EAAU;GANV,GADC,kBAAkB,QAAQ,SAAS,CAAC,eAAe,IAAI,IAAI,CAC7C;GAAG;GAAW;EAMT;CAAC,EACxC;AACF;AAEA,MAAa,mBAAmB,oBAAmD,UAAU"}
|
|
@@ -5,7 +5,7 @@ export declare const oxlintConfig: OptionalMergeConfigFn<OxlintConfig, {
|
|
|
5
5
|
options: {
|
|
6
6
|
readonly reportUnusedDisableDirectives: "error";
|
|
7
7
|
readonly typeAware: true;
|
|
8
|
-
readonly typeCheck:
|
|
8
|
+
readonly typeCheck: false;
|
|
9
9
|
};
|
|
10
10
|
categories: {
|
|
11
11
|
readonly correctness: "error";
|
|
@@ -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 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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F;AAEA,MAAM,uBAAuB,OAAO,QAAQ,OAAO,CAAC,CAAC,QAAQ,GAAG,YAAY,OAAO,WAAW,IAAI;AAClG,MAAM,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 // Leave `typeCheck` off because `bask lint` runs `tsc`, which also reports declaration errors.\n typeCheck: false,\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;GAC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B,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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tsdown.base.js","names":[],"sources":["../../src/configs/tsdown.base.ts"],"sourcesContent":["import type { UserConfig } from \"tsdown\"\nimport type { SetRequired } from \"type-fest\"\n\nimport type { MergeConfigFn } from \"#merge-config/merge-config.ts\"\nimport { createMergeConfigFn } from \"#merge-config/merge-config.ts\"\n\n// Force projects to specify platform\ntype StrictConfig = SetRequired<UserConfig, \"platform\">\n\nconst baseConfig = {\n entry: [\"./src/index.ts\"],\n platform: \"neutral\",\n target: false,\n unbundle: true,\n sourcemap: true,\n minify: \"dce-only\",\n fixedExtension: false,\n hash: false,\n dts: {\n generator: \"tsgo\",\n },\n deps: {\n neverBundle: [\"bun\"],\n },\n attw: {\n level: \"error\",\n profile: \"esm-only\",\n },\n publint: true,\n failOnWarn: true,\n suppressWarnings: [\"TypeScript Go is experimental\"],\n} as const satisfies StrictConfig\n\n// Force projects to specify platform and entry\ntype StrictBundleConfig = SetRequired<UserConfig, \"platform\" | \"entry\">\n\n// Single-file bundle (not a published library): bundle everything, drop types/lint/sourcemap.\nconst bundleConfig = {\n ...baseConfig,\n entry: [],\n unbundle: false,\n sourcemap: false,\n dts: false,\n attw: false,\n publint: false,\n inputOptions: {\n experimental: {\n attachDebugInfo: \"none\", // remove region comments from bundled output\n },\n },\n} as const satisfies StrictBundleConfig\n\n// Force projects to specify platform and entry\ntype StrictBinConfig = SetRequired<UserConfig, \"entry\">\n\n// A bin is a node bundle with no output file extension.\nconst binConfig = {\n ...bundleConfig,\n platform: \"node\",\n outExtensions: () => ({ js: \"\" }) as const,\n} as const satisfies StrictBinConfig\n\n// The export annotations forbid the no-arg call
|
|
1
|
+
{"version":3,"file":"tsdown.base.js","names":[],"sources":["../../src/configs/tsdown.base.ts"],"sourcesContent":["import type { UserConfig } from \"tsdown\"\nimport type { SetRequired } from \"type-fest\"\n\nimport type { MergeConfigFn } from \"#merge-config/merge-config.ts\"\nimport { createMergeConfigFn } from \"#merge-config/merge-config.ts\"\n\n// Force projects to specify platform\ntype StrictConfig = SetRequired<UserConfig, \"platform\">\n\nconst baseConfig = {\n entry: [\"./src/index.ts\"],\n platform: \"neutral\",\n target: false,\n unbundle: true,\n sourcemap: true,\n minify: \"dce-only\",\n fixedExtension: false,\n hash: false,\n dts: {\n generator: \"tsgo\",\n },\n deps: {\n neverBundle: [\"bun\"],\n },\n attw: {\n level: \"error\",\n profile: \"esm-only\",\n },\n publint: true,\n failOnWarn: true,\n suppressWarnings: [\"TypeScript Go is experimental\"],\n} as const satisfies StrictConfig\n\n// Force projects to specify platform and entry\ntype StrictBundleConfig = SetRequired<UserConfig, \"platform\" | \"entry\">\n\n// Single-file bundle (not a published library): bundle everything, drop types/lint/sourcemap.\nconst bundleConfig = {\n ...baseConfig,\n entry: [],\n unbundle: false,\n sourcemap: false,\n dts: false,\n attw: false,\n publint: false,\n inputOptions: {\n experimental: {\n attachDebugInfo: \"none\", // remove region comments from bundled output\n },\n },\n} as const satisfies StrictBundleConfig\n\n// Force projects to specify platform and entry\ntype StrictBinConfig = SetRequired<UserConfig, \"entry\">\n\n// A bin is a node bundle with no output file extension.\nconst binConfig = {\n ...bundleConfig,\n platform: \"node\",\n outExtensions: () => ({ js: \"\" }) as const,\n} as const satisfies StrictBinConfig\n\n// The export annotations forbid the no-arg call because `platform` and `entry` must be provided.\n// They also keep the published types correct.\n// Without one, `tsc` fails with TS2883 on tsdown's non-exported internals and the build silently emits `any`.\nexport const tsdownConfig: MergeConfigFn<StrictConfig, typeof baseConfig> = createMergeConfigFn<\n StrictConfig,\n typeof baseConfig\n>(baseConfig)\n\nexport const tsdownBundleConfig: MergeConfigFn<StrictBundleConfig, typeof bundleConfig> = createMergeConfigFn<\n StrictBundleConfig,\n typeof bundleConfig\n>(bundleConfig)\n\nexport const tsdownBinConfig: MergeConfigFn<StrictBinConfig, typeof binConfig> = createMergeConfigFn<\n StrictBinConfig,\n typeof binConfig\n>(binConfig)\n"],"mappings":";;AASA,MAAM,aAAa;CACjB,OAAO,CAAC,gBAAgB;CACxB,UAAU;CACV,QAAQ;CACR,UAAU;CACV,WAAW;CACX,QAAQ;CACR,gBAAgB;CAChB,MAAM;CACN,KAAK,EACH,WAAW,OACb;CACA,MAAM,EACJ,aAAa,CAAC,KAAK,EACrB;CACA,MAAM;EACJ,OAAO;EACP,SAAS;CACX;CACA,SAAS;CACT,YAAY;CACZ,kBAAkB,CAAC,+BAA+B;AACpD;AAMA,MAAM,eAAe;CACnB,GAAG;CACH,OAAO,CAAC;CACR,UAAU;CACV,WAAW;CACX,KAAK;CACL,MAAM;CACN,SAAS;CACT,cAAc,EACZ,cAAc,EACZ,iBAAiB,OACnB,EACF;AACF;AAMA,MAAM,YAAY;CAChB,GAAG;CACH,UAAU;CACV,sBAAsB,EAAE,IAAI,GAAG;AACjC;AAKA,MAAa,eAA+D,oBAG1E,UAAU;AAEZ,MAAa,qBAA6E,oBAGxF,YAAY;AAEd,MAAa,kBAAoE,oBAG/E,SAAS"}
|
|
@@ -1,16 +1,10 @@
|
|
|
1
1
|
import { Shell, ShellOptions } from "./shell/shell.js";
|
|
2
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
3
|
/** Options for the returned shell, which always runs in the copy. */
|
|
10
4
|
shell?: Omit<ShellOptions, "cwd">;
|
|
11
5
|
}
|
|
12
6
|
/** Copies `fixture` into a new temp dir, and returns the dir and a shell that runs there. */
|
|
13
|
-
export declare const copyFixture: (fixture: string, {
|
|
7
|
+
export declare const copyFixture: (fixture: string, { shell }?: CopyFixtureOptions) => Promise<{
|
|
14
8
|
dir: string;
|
|
15
9
|
run: Shell;
|
|
16
10
|
}>;
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { createShell } from "./shell/shell.js";
|
|
2
2
|
import { makeTempDir } from "./temp-dir.js";
|
|
3
3
|
import fs from "node:fs/promises";
|
|
4
|
-
import path from "node:path";
|
|
5
4
|
// src/test-utils/fixture.ts
|
|
6
5
|
/** Copies `fixture` into a new temp dir, and returns the dir and a shell that runs there. */
|
|
7
|
-
const copyFixture = async (fixture, {
|
|
8
|
-
const dir = await makeTempDir(
|
|
6
|
+
const copyFixture = async (fixture, { shell } = {}) => {
|
|
7
|
+
const dir = await makeTempDir();
|
|
9
8
|
await fs.cp(fixture, dir, { recursive: true });
|
|
10
9
|
return {
|
|
11
10
|
dir,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fixture.js","names":[],"sources":["../../src/test-utils/fixture.ts"],"sourcesContent":["import fs from \"node:fs/promises\"\
|
|
1
|
+
{"version":3,"file":"fixture.js","names":[],"sources":["../../src/test-utils/fixture.ts"],"sourcesContent":["import fs from \"node:fs/promises\"\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 /** 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, { shell }: CopyFixtureOptions = {}) => {\n const dir = await makeTempDir()\n await fs.cp(fixture, dir, { recursive: true })\n const run = createShell({ ...shell, cwd: dir })\n return { dir, run }\n}\n"],"mappings":";;;;;AAYA,MAAa,cAAc,OAAO,SAAiB,EAAE,UAA8B,CAAC,MAAM;CACxF,MAAM,MAAM,MAAM,YAAY;CAC9B,MAAM,GAAG,GAAG,SAAS,KAAK,EAAE,WAAW,KAAK,CAAC;CAE7C,OAAO;EAAE;EAAK,KADF,YAAY;GAAE,GAAG;GAAO,KAAK;EAAI,CAC7B;CAAE;AACpB"}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { ShellCommand } from "./shell/command.js";
|
|
2
|
-
import { Shell, ShellEnv, ShellOptions, ShellResult, createShell } from "./shell/shell.js";
|
|
3
1
|
import { minimalEnv } from "./shell/env.js";
|
|
4
2
|
import { CopyFixtureOptions, copyFixture } from "./fixture.js";
|
|
5
3
|
import { packPackage } from "./pack.js";
|
|
6
|
-
import {
|
|
4
|
+
import { ShellCommand } from "./shell/command.js";
|
|
5
|
+
import { Shell, ShellEnv, ShellOptions, ShellResult, createShell } from "./shell/shell.js";
|
|
7
6
|
import { makeTempDir } from "./temp-dir.js";
|
|
8
|
-
export { type CopyFixtureOptions, type Shell, type ShellCommand, type ShellEnv, type ShellOptions, type ShellResult, copyFixture, createShell, makeTempDir, minimalEnv, packPackage
|
|
7
|
+
export { type CopyFixtureOptions, type Shell, type ShellCommand, type ShellEnv, type ShellOptions, type ShellResult, copyFixture, createShell, makeTempDir, minimalEnv, packPackage };
|
package/dist/test-utils/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { minimalEnv } from "./shell/env.js";
|
|
2
|
-
import { createShell } from "./shell/shell.js";
|
|
3
|
-
import { makeTempDir } from "./temp-dir.js";
|
|
4
2
|
import { copyFixture } from "./fixture.js";
|
|
5
3
|
import { packPackage } from "./pack.js";
|
|
6
|
-
import {
|
|
7
|
-
|
|
4
|
+
import { createShell } from "./shell/shell.js";
|
|
5
|
+
import { makeTempDir } from "./temp-dir.js";
|
|
6
|
+
export { copyFixture, createShell, makeTempDir, minimalEnv, packPackage };
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* Builds the package at `root` when it has a tsdown config, packs it into a temp dir, and returns the tarball path.
|
|
3
|
+
* Runs once per resolved root for the life of the test process.
|
|
4
|
+
*/
|
|
2
5
|
export declare const packPackage: (root: string) => Promise<string>;
|
|
3
6
|
//# sourceMappingURL=pack.d.ts.map
|
package/dist/test-utils/pack.js
CHANGED
|
@@ -1,16 +1,28 @@
|
|
|
1
1
|
import { createShell } from "./shell/shell.js";
|
|
2
2
|
import { makeTempDir } from "./temp-dir.js";
|
|
3
|
-
import path from "node:path";
|
|
4
3
|
import bun from "bun";
|
|
4
|
+
import path from "node:path";
|
|
5
5
|
// src/test-utils/pack.ts
|
|
6
|
-
|
|
7
|
-
const
|
|
6
|
+
const packs = /* @__PURE__ */ new Map();
|
|
7
|
+
const buildAndPack = async (root) => {
|
|
8
8
|
const run = createShell({ cwd: root });
|
|
9
9
|
if (await bun.file(path.join(root, "tsdown.config.ts")).exists()) await run`bun tsdown`;
|
|
10
|
-
const destination = await makeTempDir(
|
|
10
|
+
const destination = await makeTempDir();
|
|
11
11
|
const { stdout } = await run`bun pm pack --ignore-scripts --quiet --destination ${destination}`;
|
|
12
12
|
return path.resolve(destination, stdout);
|
|
13
13
|
};
|
|
14
|
+
/**
|
|
15
|
+
* Builds the package at `root` when it has a tsdown config, packs it into a temp dir, and returns the tarball path.
|
|
16
|
+
* Runs once per resolved root for the life of the test process.
|
|
17
|
+
*/
|
|
18
|
+
const packPackage = async (root) => {
|
|
19
|
+
const resolvedRoot = path.resolve(root);
|
|
20
|
+
const existingPack = packs.get(resolvedRoot);
|
|
21
|
+
if (existingPack) return existingPack;
|
|
22
|
+
const pack = buildAndPack(resolvedRoot);
|
|
23
|
+
packs.set(resolvedRoot, pack);
|
|
24
|
+
return pack;
|
|
25
|
+
};
|
|
14
26
|
export { packPackage };
|
|
15
27
|
|
|
16
28
|
//# sourceMappingURL=pack.js.map
|
|
@@ -1 +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\
|
|
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\nconst packs = new Map<string, Promise<string>>()\n\nconst buildAndPack = 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()\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\n/**\n * Builds the package at `root` when it has a tsdown config, packs it into a temp dir, and returns the tarball path.\n * Runs once per resolved root for the life of the test process.\n */\nexport const packPackage = async (root: string) => {\n const resolvedRoot = path.resolve(root)\n const existingPack = packs.get(resolvedRoot)\n if (existingPack) return existingPack\n\n // Cache the promise so concurrent callers share one build.\n const pack = buildAndPack(resolvedRoot)\n packs.set(resolvedRoot, pack)\n return pack\n}\n"],"mappings":";;;;;AAOA,MAAM,wBAAQ,IAAI,IAA6B;AAE/C,MAAM,eAAe,OAAO,SAAiB;CAC3C,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;CAEtC,MAAM,EAAE,WAAW,MAAM,GAAG,sDAAsD;CAClF,OAAO,KAAK,QAAQ,aAAa,MAAM;AACzC;;;;;AAMA,MAAa,cAAc,OAAO,SAAiB;CACjD,MAAM,eAAe,KAAK,QAAQ,IAAI;CACtC,MAAM,eAAe,MAAM,IAAI,YAAY;CAC3C,IAAI,cAAc,OAAO;CAGzB,MAAM,OAAO,aAAa,YAAY;CACtC,MAAM,IAAI,cAAc,IAAI;CAC5B,OAAO;AACT"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { addBinDirs } from "./bin-dirs.js";
|
|
2
2
|
import { removeNodeShims } from "./node-shim.js";
|
|
3
|
-
import path from "node:path";
|
|
4
3
|
import bun from "bun";
|
|
4
|
+
import path from "node:path";
|
|
5
5
|
// src/test-utils/shell/command.ts
|
|
6
6
|
const FINAL_NEWLINE = /\r?\n$/v;
|
|
7
7
|
const stripFinalNewline = (output) => output.toString().replace(FINAL_NEWLINE, "");
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
/** Makes a temp dir
|
|
2
|
-
export declare const makeTempDir: (
|
|
1
|
+
/** Makes a temp dir named after the current project, and records it for `removeTempDirs`. */
|
|
2
|
+
export declare const makeTempDir: () => Promise<string>;
|
|
3
3
|
//# sourceMappingURL=temp-dir.d.ts.map
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
+
import process from "node:process";
|
|
1
2
|
import fs from "node:fs/promises";
|
|
2
3
|
import path from "node:path";
|
|
3
4
|
import os from "node:os";
|
|
4
5
|
// src/test-utils/temp-dir.ts
|
|
5
6
|
const tempDirs = [];
|
|
6
|
-
/** Makes a temp dir
|
|
7
|
-
const makeTempDir = async (
|
|
8
|
-
const
|
|
7
|
+
/** Makes a temp dir named after the current project, and records it for `removeTempDirs`. */
|
|
8
|
+
const makeTempDir = async () => {
|
|
9
|
+
const projectName = path.basename(process.cwd());
|
|
10
|
+
const dir = await fs.mkdtemp(path.join(os.tmpdir(), `${projectName}-`));
|
|
9
11
|
tempDirs.push(dir);
|
|
10
12
|
return dir;
|
|
11
13
|
};
|
|
@@ -1 +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
|
|
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\"\nimport process from \"node:process\"\n\nconst tempDirs: string[] = []\n\n/** Makes a temp dir named after the current project, and records it for `removeTempDirs`. */\nexport const makeTempDir = async () => {\n // Start the name with the project so a dir left behind by a killed run shows where it came from.\n const projectName = path.basename(process.cwd())\n const dir = await fs.mkdtemp(path.join(os.tmpdir(), `${projectName}-`))\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":";;;;;AAKA,MAAM,WAAqB,CAAC;;AAG5B,MAAa,cAAc,YAAY;CAErC,MAAM,cAAc,KAAK,SAAS,QAAQ,IAAI,CAAC;CAC/C,MAAM,MAAM,MAAM,GAAG,QAAQ,KAAK,KAAK,GAAG,OAAO,GAAG,GAAG,YAAY,EAAE,CAAC;CACtE,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/dist/utils.js
CHANGED
|
@@ -14,9 +14,17 @@ const configFilePath = (name) => {
|
|
|
14
14
|
/** Returns the absolute path of a package's entry file, resolved from this package's dependencies. */
|
|
15
15
|
const resolvePackagePath = (specifier) => fileURLToPath(import.meta.resolve(specifier));
|
|
16
16
|
const keysOf = (value) => isPlainObject(value) ? Object.keys(value) : [];
|
|
17
|
+
const DECLARATION_FILE = /\.d\.[cm]?ts$/v;
|
|
18
|
+
/** Checks an `exports` value, at any depth, for a `types` condition or a path to a declaration file. */
|
|
19
|
+
const exportsDeclareTypes = (value) => {
|
|
20
|
+
if (typeof value === "string") return DECLARATION_FILE.test(value);
|
|
21
|
+
if (Array.isArray(value)) return value.some(exportsDeclareTypes);
|
|
22
|
+
if (!isPlainObject(value)) return false;
|
|
23
|
+
return "types" in value || Object.values(value).some(exportsDeclareTypes);
|
|
24
|
+
};
|
|
17
25
|
/**
|
|
18
26
|
* Reads the project's `package.json` fields that the base configs branch on. `dependencies` merges the regular, dev,
|
|
19
|
-
* and peer dependency names.
|
|
27
|
+
* and peer dependency names. `publishesTypes` is true when the `package.json` declares types.
|
|
20
28
|
*/
|
|
21
29
|
const readProjectPackageJson = () => {
|
|
22
30
|
const packageJson = existsSync("package.json") ? JSON.parse(readFileSync("package.json", "utf8")) : {};
|
|
@@ -27,7 +35,8 @@ const readProjectPackageJson = () => {
|
|
|
27
35
|
"devDependencies",
|
|
28
36
|
"peerDependencies"
|
|
29
37
|
].flatMap((field) => keysOf(fields[field]))),
|
|
30
|
-
engines: new Set(keysOf(fields["engines"]))
|
|
38
|
+
engines: new Set(keysOf(fields["engines"])),
|
|
39
|
+
publishesTypes: "types" in fields || "typings" in fields || exportsDeclareTypes(fields["exports"])
|
|
31
40
|
};
|
|
32
41
|
};
|
|
33
42
|
const TAILWIND_IMPORT = /@import\s*["']tailwindcss(?:\/[^"']+)?["']/v;
|
package/dist/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","names":[],"sources":["../src/utils.ts"],"sourcesContent":["import { existsSync, globSync, readFileSync } from \"node:fs\"\nimport path from \"node:path\"\nimport { fileURLToPath } from \"node:url\"\n\nimport { isPlainObject } from \"es-toolkit/predicate\"\n\n// Check both folders because a bin bundles this file into `<bin>/index`, one level below `configs`.\nconst CONFIG_DIRS = [\"./configs/\", \"../configs/\"] as const\n\n/** Returns the absolute path of a file in this package's `configs` folder. */\nexport const configFilePath = (name: string) => {\n const filePaths = CONFIG_DIRS.map((dir) => fileURLToPath(new URL(`${dir}${name}`, import.meta.url)))\n const filePath = filePaths.find((candidate) => existsSync(candidate))\n if (!filePath) throw new Error(`Couldn't find config file \"${name}\" in:\\n${filePaths.join(\"\\n\")}`)\n return filePath\n}\n\n/** Returns the absolute path of a package's entry file, resolved from this package's dependencies. */\nexport const resolvePackagePath = (specifier: string) => fileURLToPath(import.meta.resolve(specifier))\n\nconst keysOf = (value: unknown) => (isPlainObject(value) ? Object.keys(value) : [])\n\n/**\n * Reads the project's `package.json` fields that the base configs branch on. `dependencies` merges the regular, dev,\n * and peer dependency names.\n */\nexport const readProjectPackageJson = () => {\n const packageJson: unknown = existsSync(\"package.json\") ? JSON.parse(readFileSync(\"package.json\", \"utf8\")) : {}\n const fields = isPlainObject(packageJson) ? packageJson : {}\n\n const dependencyFields = [\"dependencies\", \"devDependencies\", \"peerDependencies\"]\n const dependencies = new Set(dependencyFields.flatMap((field) => keysOf(fields[field])))\n const engines = new Set(keysOf(fields[\"engines\"]))\n\n return { dependencies, engines }\n}\n\n// Match entry stylesheets the same way `@tailwindcss/language-server` does.\nconst TAILWIND_IMPORT = /@import\\s*[\"']tailwindcss(?:\\/[^\"']+)?[\"']/v\n\n/**\n * Returns the project's Tailwind stylesheet relative to the project root, or `false` when the project doesn't use\n * Tailwind. The stylesheet is the first CSS file, in sorted order, that imports `tailwindcss`.\n */\nexport const resolveProjectTailwind = () => {\n const { dependencies } = readProjectPackageJson()\n if (!dependencies.has(\"tailwindcss\")) return false\n\n const stylesheets = globSync(\"**/*.{css,scss,sass,less,pcss}\", {\n exclude: (filePath) => [\"node_modules\", \".git\"].includes(path.basename(filePath)),\n }).toSorted()\n\n return stylesheets.find((file) => TAILWIND_IMPORT.test(readFileSync(file, \"utf8\"))) ?? false\n}\n"],"mappings":";;;;;AAOA,MAAM,cAAc,CAAC,cAAc,aAAa;;AAGhD,MAAa,kBAAkB,SAAiB;CAC9C,MAAM,YAAY,YAAY,KAAK,QAAQ,cAAc,IAAI,IAAI,GAAG,MAAM,QAAQ,YAAY,GAAG,CAAC,CAAC;CACnG,MAAM,WAAW,UAAU,MAAM,cAAc,WAAW,SAAS,CAAC;CACpE,IAAI,CAAC,UAAU,MAAM,IAAI,MAAM,8BAA8B,KAAK,SAAS,UAAU,KAAK,IAAI,GAAG;CACjG,OAAO;AACT;;AAGA,MAAa,sBAAsB,cAAsB,cAAc,YAAY,QAAQ,SAAS,CAAC;AAErG,MAAM,UAAU,UAAoB,cAAc,KAAK,IAAI,OAAO,KAAK,KAAK,IAAI,CAAC;;;;;
|
|
1
|
+
{"version":3,"file":"utils.js","names":[],"sources":["../src/utils.ts"],"sourcesContent":["import { existsSync, globSync, readFileSync } from \"node:fs\"\nimport path from \"node:path\"\nimport { fileURLToPath } from \"node:url\"\n\nimport { isPlainObject } from \"es-toolkit/predicate\"\n\n// Check both folders because a bin bundles this file into `<bin>/index`, one level below `configs`.\nconst CONFIG_DIRS = [\"./configs/\", \"../configs/\"] as const\n\n/** Returns the absolute path of a file in this package's `configs` folder. */\nexport const configFilePath = (name: string) => {\n const filePaths = CONFIG_DIRS.map((dir) => fileURLToPath(new URL(`${dir}${name}`, import.meta.url)))\n const filePath = filePaths.find((candidate) => existsSync(candidate))\n if (!filePath) throw new Error(`Couldn't find config file \"${name}\" in:\\n${filePaths.join(\"\\n\")}`)\n return filePath\n}\n\n/** Returns the absolute path of a package's entry file, resolved from this package's dependencies. */\nexport const resolvePackagePath = (specifier: string) => fileURLToPath(import.meta.resolve(specifier))\n\nconst keysOf = (value: unknown) => (isPlainObject(value) ? Object.keys(value) : [])\n\nconst DECLARATION_FILE = /\\.d\\.[cm]?ts$/v\n\n/** Checks an `exports` value, at any depth, for a `types` condition or a path to a declaration file. */\nconst exportsDeclareTypes = (value: unknown): boolean => {\n if (typeof value === \"string\") return DECLARATION_FILE.test(value)\n if (Array.isArray(value)) return value.some(exportsDeclareTypes)\n if (!isPlainObject(value)) return false\n return \"types\" in value || Object.values(value).some(exportsDeclareTypes)\n}\n\n/**\n * Reads the project's `package.json` fields that the base configs branch on. `dependencies` merges the regular, dev,\n * and peer dependency names. `publishesTypes` is true when the `package.json` declares types.\n */\nexport const readProjectPackageJson = () => {\n const packageJson: unknown = existsSync(\"package.json\") ? JSON.parse(readFileSync(\"package.json\", \"utf8\")) : {}\n const fields = isPlainObject(packageJson) ? packageJson : {}\n\n const dependencyFields = [\"dependencies\", \"devDependencies\", \"peerDependencies\"]\n const dependencies = new Set(dependencyFields.flatMap((field) => keysOf(fields[field])))\n const engines = new Set(keysOf(fields[\"engines\"]))\n const publishesTypes = \"types\" in fields || \"typings\" in fields || exportsDeclareTypes(fields[\"exports\"])\n\n return { dependencies, engines, publishesTypes }\n}\n\n// Match entry stylesheets the same way `@tailwindcss/language-server` does.\nconst TAILWIND_IMPORT = /@import\\s*[\"']tailwindcss(?:\\/[^\"']+)?[\"']/v\n\n/**\n * Returns the project's Tailwind stylesheet relative to the project root, or `false` when the project doesn't use\n * Tailwind. The stylesheet is the first CSS file, in sorted order, that imports `tailwindcss`.\n */\nexport const resolveProjectTailwind = () => {\n const { dependencies } = readProjectPackageJson()\n if (!dependencies.has(\"tailwindcss\")) return false\n\n const stylesheets = globSync(\"**/*.{css,scss,sass,less,pcss}\", {\n exclude: (filePath) => [\"node_modules\", \".git\"].includes(path.basename(filePath)),\n }).toSorted()\n\n return stylesheets.find((file) => TAILWIND_IMPORT.test(readFileSync(file, \"utf8\"))) ?? false\n}\n"],"mappings":";;;;;AAOA,MAAM,cAAc,CAAC,cAAc,aAAa;;AAGhD,MAAa,kBAAkB,SAAiB;CAC9C,MAAM,YAAY,YAAY,KAAK,QAAQ,cAAc,IAAI,IAAI,GAAG,MAAM,QAAQ,YAAY,GAAG,CAAC,CAAC;CACnG,MAAM,WAAW,UAAU,MAAM,cAAc,WAAW,SAAS,CAAC;CACpE,IAAI,CAAC,UAAU,MAAM,IAAI,MAAM,8BAA8B,KAAK,SAAS,UAAU,KAAK,IAAI,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,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adamhl8/configs",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "My shared configs for TS projects",
|
|
5
5
|
"homepage": "https://github.com/adamhl8/configs",
|
|
6
6
|
"bugs": {
|
|
@@ -18,7 +18,8 @@
|
|
|
18
18
|
},
|
|
19
19
|
"bin": {
|
|
20
20
|
"adamhl8-bunfig": "./dist/adamhl8-bunfig/index",
|
|
21
|
-
"adamhl8-gitignore": "./dist/adamhl8-gitignore/index"
|
|
21
|
+
"adamhl8-gitignore": "./dist/adamhl8-gitignore/index",
|
|
22
|
+
"adamhl8-tsconfig": "./dist/adamhl8-tsconfig/index"
|
|
22
23
|
},
|
|
23
24
|
"files": [
|
|
24
25
|
"dist/"
|
|
@@ -29,6 +30,7 @@
|
|
|
29
30
|
},
|
|
30
31
|
"exports": {
|
|
31
32
|
"./tsconfig": "./dist/configs/tsconfig.base.json",
|
|
33
|
+
"./tsconfig/no-dts": "./dist/configs/tsconfig.no-dts.base.json",
|
|
32
34
|
".": {
|
|
33
35
|
"types": "./dist/index.d.ts",
|
|
34
36
|
"import": "./dist/index.js"
|
|
@@ -48,10 +50,6 @@
|
|
|
48
50
|
"./test/preload": {
|
|
49
51
|
"types": "./dist/test-utils/preload.d.ts",
|
|
50
52
|
"import": "./dist/test-utils/preload.js"
|
|
51
|
-
},
|
|
52
|
-
"./test/subprocess-coverage": {
|
|
53
|
-
"types": "./dist/test-utils/subprocess-coverage/preload.d.ts",
|
|
54
|
-
"import": "./dist/test-utils/subprocess-coverage/preload.js"
|
|
55
53
|
}
|
|
56
54
|
},
|
|
57
55
|
"publishConfig": {
|
|
@@ -61,21 +59,21 @@
|
|
|
61
59
|
"prepare": "bask prepare"
|
|
62
60
|
},
|
|
63
61
|
"dependencies": {
|
|
64
|
-
"@adamhl8/eslint-plugin-clean-modules": "^0.1.
|
|
62
|
+
"@adamhl8/eslint-plugin-clean-modules": "^0.1.6",
|
|
65
63
|
"@commitlint/config-conventional": "^21.2.4",
|
|
66
64
|
"@commitlint/types": "^21.2.3",
|
|
67
65
|
"@e18e/eslint-plugin": "^0.8.1",
|
|
68
66
|
"arkenv": "^0.12.3",
|
|
69
67
|
"arktype": "^2.2.9",
|
|
70
|
-
"es-toolkit": "^1.53.
|
|
68
|
+
"es-toolkit": "^1.53.1",
|
|
71
69
|
"eslint-plugin-bunisms": "^0.11.0",
|
|
72
|
-
"eslint-plugin-hono": "^1.
|
|
70
|
+
"eslint-plugin-hono": "^1.2.1",
|
|
73
71
|
"eslint-plugin-react-web-api": "^5.28.8",
|
|
74
|
-
"eslint-plugin-react-you-might-not-need-an-effect": "^1.0
|
|
75
|
-
"eslint-plugin-regexp": "^3.3.
|
|
72
|
+
"eslint-plugin-react-you-might-not-need-an-effect": "^1.1.0",
|
|
73
|
+
"eslint-plugin-regexp": "^3.3.3",
|
|
76
74
|
"oxlint-plugin-directive-comments": "^0.1.0",
|
|
77
|
-
"oxlint-tailwindcss": "^1.
|
|
78
|
-
"ts-explicit-errors": "^5.0.
|
|
75
|
+
"oxlint-tailwindcss": "^1.17.1",
|
|
76
|
+
"ts-explicit-errors": "^5.0.1",
|
|
79
77
|
"type-fest": "^5.10.0"
|
|
80
78
|
},
|
|
81
79
|
"devDependencies": {
|
|
@@ -84,19 +82,15 @@
|
|
|
84
82
|
"@arethetypeswrong/core": "^0.18.5",
|
|
85
83
|
"@commitlint/cli": "^21.2.4",
|
|
86
84
|
"@types/bun": "^1.4.4",
|
|
87
|
-
"
|
|
88
|
-
"@vitest/istanbul-lib-instrument": "^2.0.0",
|
|
89
|
-
"@vitest/istanbul-lib-report": "^2.0.0",
|
|
90
|
-
"@vitest/istanbul-lib-source-maps": "^2.0.0",
|
|
91
|
-
"knip": "^6.43.0",
|
|
85
|
+
"knip": "^6.44.1",
|
|
92
86
|
"markdown-toc": "^1.2.0",
|
|
93
|
-
"oxfmt": "^0.
|
|
94
|
-
"oxlint": "^1.
|
|
87
|
+
"oxfmt": "^0.76.0",
|
|
88
|
+
"oxlint": "^1.91.0",
|
|
95
89
|
"oxlint-tsgolint": "^7.0.2005",
|
|
96
90
|
"publint": "^0.3.25",
|
|
97
|
-
"release-it": "^21.1.
|
|
98
|
-
"release-it-git-cliff": "^0.2.
|
|
99
|
-
"tsdown": "^0.23.
|
|
91
|
+
"release-it": "^21.1.2",
|
|
92
|
+
"release-it-git-cliff": "^0.2.1",
|
|
93
|
+
"tsdown": "^0.23.5",
|
|
100
94
|
"typescript": "7.1.0-beta"
|
|
101
95
|
},
|
|
102
96
|
"peerDependencies": {
|
|
@@ -105,20 +99,16 @@
|
|
|
105
99
|
"@commitlint/cli": ">=21.2",
|
|
106
100
|
"@commitlint/config-conventional": ">=21.2",
|
|
107
101
|
"@tailwindcss/language-server": ">=0.16",
|
|
108
|
-
"
|
|
109
|
-
"@vitest/istanbul-lib-instrument": ">=2.0",
|
|
110
|
-
"@vitest/istanbul-lib-report": ">=2.0",
|
|
111
|
-
"@vitest/istanbul-lib-source-maps": ">=2.0",
|
|
112
|
-
"knip": ">=6.43",
|
|
102
|
+
"knip": ">=6.44",
|
|
113
103
|
"markdown-toc": ">=1.2",
|
|
114
|
-
"oxfmt": ">=0.
|
|
115
|
-
"oxlint": ">=1.
|
|
104
|
+
"oxfmt": ">=0.76",
|
|
105
|
+
"oxlint": ">=1.91",
|
|
116
106
|
"oxlint-tsgolint": ">=7.0.2005",
|
|
117
107
|
"publint": ">=0.3",
|
|
118
108
|
"release-it": ">=21.1",
|
|
119
109
|
"release-it-git-cliff": ">=0.2",
|
|
120
110
|
"tailwint": ">=1.1",
|
|
121
|
-
"tsdown": ">=0.23.
|
|
111
|
+
"tsdown": ">=0.23.5",
|
|
122
112
|
"typescript": "^7.1.0-beta"
|
|
123
113
|
},
|
|
124
114
|
"peerDependenciesMeta": {
|
|
@@ -128,18 +118,6 @@
|
|
|
128
118
|
"@tailwindcss/language-server": {
|
|
129
119
|
"optional": true
|
|
130
120
|
},
|
|
131
|
-
"@vitest/istanbul-lib-coverage": {
|
|
132
|
-
"optional": true
|
|
133
|
-
},
|
|
134
|
-
"@vitest/istanbul-lib-instrument": {
|
|
135
|
-
"optional": true
|
|
136
|
-
},
|
|
137
|
-
"@vitest/istanbul-lib-report": {
|
|
138
|
-
"optional": true
|
|
139
|
-
},
|
|
140
|
-
"@vitest/istanbul-lib-source-maps": {
|
|
141
|
-
"optional": true
|
|
142
|
-
},
|
|
143
121
|
"publint": {
|
|
144
122
|
"optional": true
|
|
145
123
|
},
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"bask.base.d.ts","names":[],"sources":["../../src/configs/bask.base.ts"],"mappings":"A,qBAwBa,mCAAS;qBAIT,iCAAO;qBASP,kCAAQ;qBAOR,8BAAI;qBAIJ,8BAAI;qBA0BJ,+BAAK;qBAYL,iCAAO;qBAIP,oCAAU;qBAIV,qCAAW"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"commitlint.base.d.ts","names":["_$_merge_config_merge_config_ts0.OptionalMergeConfigFn"],"sources":["../../src/configs/commitlint.base.ts"],"mappings":";;qBAkBa,kBAAgBA,sBAAA;;;aAJzB"}
|
|
@@ -1 +0,0 @@
|
|
|
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 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"oxfmt.base.d.ts","names":["_$_merge_config_merge_config_ts0.OptionalMergeConfigFn"],"sources":["../../src/configs/oxfmt.base.ts"],"mappings":";;qBA4Ba,aAAWA,sBAAA;WApBV;;;aAEH;;WACqB;;;aAG5B;;;aASiB"}
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"release-it.base.d.ts","names":["_$_merge_config_merge_config_ts0.OptionalMergeConfigFn"],"sources":["../../src/configs/release-it.base.ts"],"mappings":";;KAOK,cAAc,QAAQ;KACtB,kBAAkB;EAAW,QAAQ;;qBA+B7B,iBAAeA,sBAAA;;aA3BxB;aACA;;;aAGA;eACE;eACA;;;;aAIF;aAEA;aACA;aACA;;;aAGA;aACA;;;aAGA;aACA;aACA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tsdown.base.d.ts","names":[],"sources":["../../src/configs/tsdown.base.ts"],"mappings":";;;KAOK,eAAe,YAAY;cAE1B;;WAEM;;;;WAIF;;;;aAIN;;;aAGA;;;aAGA;aACA;;;;;;KAQC,qBAAqB,YAAY;cAGhC;WA1BM;;WAIF;;;;aAON;;;;;;;;;;;aAwBA;eACE;;;;KAMD,kBAAkB,YAAY;cAG7B;;WAzCI;;;;aAON;;;;;;;;;;;aAwBA;eACE;;;WAWM;;aACkB;;;qBAKjB,cAAc,cAAc,qBAAqB;qBAKjD,oBAAoB,cAAc,2BAA2B;qBAK7D,iBAAiB,cAAc,wBAAwB"}
|
package/dist/env/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/env/index.ts"],"mappings":";;KAiBK,gBAAgB;qBAER,UAOP"}
|
package/dist/env/utils.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","names":["arktype"],"sources":["../../src/env/utils.ts"],"mappings":";;;;;;;wBASgB,kBAAkB,KAChC,eACA,MAAMA,KAAQ,SAAS,OACtB,WAAWA,KAAQ,YAAY;wBAClB,kBAAkB,KAChC,eACA,MAAMA,KAAQ,SAAS,MACvB,UAAUA,KAAQ,MAAM,OACvBA,KAAQ,YAAY"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"merge-config.d.ts","names":[],"sources":["../../src/merge-config/merge-config.ts"],"mappings":";;;;;;;;;;;;YAgCY,cAAc,YAAY,sBAAsB,0BAA0B,aAAa,aACjG,YAAY,sBACT,aAAa,YAAY,8BAEpB,0BAA0B,aAAa,mBACvC,6BAA6B,aAAa,QAAQ,cAExD,YAAY,mBACZ,eAAe,yBACZ,aAAa,aAAa,YAAY,oBAAoB;;YAGrD,sBAAsB,YAAY,cAAc,cAAc,YAAY,qBAC3E,MAAM"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"merge.types.d.ts","names":[],"sources":["../../src/merge-config/merge.types.ts"],"mappings":"A,KAWK,kBAAkB;;YAGX;;;;;;KAOP;;;;;;KAOA,eAAe,cAAc,OAAO,SAAS;YAAoB,OAAO;;;;;;;;YAQjE,MAAM,GAAG,mCAAmC,YAAY,mBAChE,0CAA0C,kBACxC,UAAU,eACR,iBACa,WAAW,IAAI,MAAM,EAAE,IAAI,qBAC1C,IACF;;;;;KAMC,YACH,WACA,sCACA,kCACA,UAAU,QACR,qBACA,wCACG,MAAM,mBAAmB,SAAS,MAAM,mBAAmB,YAC5D,MAAM,WAAW,SACnB,MAAM,WAAW;;;;;KAMhB,YAAY,WAAW,WAAW,kCAAkC,UAAU,QAAQ,2BACvF,uCACE,YAAY,WAAW,WAAW,OAAO,KACzC,kBAAkB,eAChB,YACA,uCAAuC,eACrC,MAAM,WAAW,SACjB,2BACE,aAAa,WAAW,WAAW,OAAO,KAC1C,MAAM,WAAW,SACzB;;;;;;;;KASC,aAAa,YAAY,YAAY,kCAAkC,UAAU,QAAQ,0CAEnF,+BAGM,WAAW,aAAa,gBAAgB,+BAC7B,WAAW,KAEvB,YAAY,WAAW,IAAI,QAAQ,WAAW,gBAAgB,gBAAgB,KAC9E,MAAM,WAAW,IAAI,kBACzB,YAAY,WAAW,IAAI,WAAW,IAAI,gBAAgB,KAC5D,MAAM,WAAW,IAAI,kCAEd,WAAW,cAAc,gBAAgB,8BAA8B,IAAI,MACpF,WAAW,IACX,kCAEY,aACX,WAAW,SAAS,OAAO,gBAEhC;;;;;YAMQ,aAAa,YAAY,YAAY,UAAU,mBAAmB,aAC5E,YACA,YACA,UACA"}
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"pack.d.ts","names":[],"sources":["../../src/test-utils/pack.ts"],"mappings":";qBAQa,cAAW,iBAAsB"}
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"env.d.ts","names":[],"sources":["../../../src/test-utils/shell/env.ts"],"mappings":";;qBAKa,aAAU,QAAW,aAAgB"}
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {}
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { SUBPROCESS_COVERAGE_SETTINGS_VAR } from "./env.js";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
import bun from "bun";
|
|
4
|
-
import crypto from "node:crypto";
|
|
5
|
-
import fs from "node:fs";
|
|
6
|
-
import { createInstrumenter } from "@vitest/istanbul-lib-instrument";
|
|
7
|
-
// src/test-utils/subprocess-coverage/child-preload.ts
|
|
8
|
-
const INSTRUMENTER_COVERAGE_VARIABLE = "subprocessCoverage";
|
|
9
|
-
const isCoverageSettings = (value) => typeof value === "object" && value !== null && "rawDir" in value && typeof value.rawDir === "string" && "root" in value && typeof value.root === "string" && "packageName" in value && typeof value.packageName === "string";
|
|
10
|
-
/** Reads the coverage settings from the environment, and throws when they're missing or invalid. */
|
|
11
|
-
const readCoverageSettings = () => {
|
|
12
|
-
const settings = process.env[SUBPROCESS_COVERAGE_SETTINGS_VAR];
|
|
13
|
-
if (settings === void 0) throw new Error(`the subprocess coverage preload loaded without ${SUBPROCESS_COVERAGE_SETTINGS_VAR}`);
|
|
14
|
-
const parsed = JSON.parse(settings);
|
|
15
|
-
if (!isCoverageSettings(parsed)) throw new Error(`${SUBPROCESS_COVERAGE_SETTINGS_VAR} isn't valid: ${settings}`);
|
|
16
|
-
return parsed;
|
|
17
|
-
};
|
|
18
|
-
const { rawDir, root, packageName } = readCoverageSettings();
|
|
19
|
-
const isSourceMap = (value) => typeof value === "object" && value !== null && "sources" in value && Array.isArray(value.sources);
|
|
20
|
-
/** Points each source in the installed package's map at the same file in the project, so reports name `src/`. */
|
|
21
|
-
const readSourceMap = async (file, packageDir, projectDir) => {
|
|
22
|
-
const sourceMap = await bun.file(`${file}.map`).json();
|
|
23
|
-
if (!isSourceMap(sourceMap)) throw new Error(`no source map for ${file}`);
|
|
24
|
-
const sources = sourceMap.sources.map((source) => {
|
|
25
|
-
const installedSource = path.resolve(path.dirname(file), source ?? "");
|
|
26
|
-
return path.join(projectDir, path.relative(packageDir, installedSource));
|
|
27
|
-
});
|
|
28
|
-
return {
|
|
29
|
-
...sourceMap,
|
|
30
|
-
sources
|
|
31
|
-
};
|
|
32
|
-
};
|
|
33
|
-
const instrumenter = createInstrumenter({
|
|
34
|
-
esModules: true,
|
|
35
|
-
coverageVariable: INSTRUMENTER_COVERAGE_VARIABLE
|
|
36
|
-
});
|
|
37
|
-
const installedDist = new RegExp(String.raw`^(.*/node_modules/${RegExp.escape(packageName)})/dist/.*\.js$`, "v");
|
|
38
|
-
bun.plugin({
|
|
39
|
-
name: "subprocess-coverage",
|
|
40
|
-
setup: (build) => {
|
|
41
|
-
build.onLoad({ filter: installedDist }, async ({ path: file }) => {
|
|
42
|
-
const [, packageDir = ""] = installedDist.exec(file) ?? [];
|
|
43
|
-
const code = await bun.file(file).text();
|
|
44
|
-
const sourceMap = await readSourceMap(file, packageDir, root);
|
|
45
|
-
return {
|
|
46
|
-
contents: instrumenter.instrumentSync(code, file, sourceMap),
|
|
47
|
-
loader: "js"
|
|
48
|
-
};
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
const hasCoverage = (value) => INSTRUMENTER_COVERAGE_VARIABLE in value;
|
|
53
|
-
const writeCoverage = () => {
|
|
54
|
-
const globalScope = globalThis;
|
|
55
|
-
if (!hasCoverage(globalScope)) return;
|
|
56
|
-
fs.writeFileSync(path.join(rawDir, `${crypto.randomUUID()}.json`), JSON.stringify(globalScope[INSTRUMENTER_COVERAGE_VARIABLE]));
|
|
57
|
-
};
|
|
58
|
-
process.on("exit", writeCoverage);
|
|
59
|
-
process.on("newListener", (event, listener) => {
|
|
60
|
-
if (event !== "exit" || listener === writeCoverage) return;
|
|
61
|
-
queueMicrotask(() => {
|
|
62
|
-
process.removeListener("exit", writeCoverage);
|
|
63
|
-
process.on("exit", writeCoverage);
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
export {};
|
|
67
|
-
|
|
68
|
-
//# sourceMappingURL=child-preload.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"child-preload.js","names":[],"sources":["../../../src/test-utils/subprocess-coverage/child-preload.ts"],"sourcesContent":["// Records coverage of the installed package in every Bun process that a test starts.\n// Tests load this file through `BUN_OPTIONS` once a project imports `subprocess-coverage`.\nimport crypto from \"node:crypto\"\nimport fs from \"node:fs\"\nimport path from \"node:path\"\n\nimport { createInstrumenter } from \"@vitest/istanbul-lib-instrument\"\nimport type { InputSourceMap } from \"@vitest/istanbul-lib-instrument\"\nimport bun from \"bun\"\n\nimport { SUBPROCESS_COVERAGE_SETTINGS_VAR } from \"#test-utils/subprocess-coverage/env.ts\"\nimport type { CoverageSettings } from \"#test-utils/subprocess-coverage/env.ts\"\n\nconst INSTRUMENTER_COVERAGE_VARIABLE = \"subprocessCoverage\"\n\nconst isCoverageSettings = (value: unknown): value is CoverageSettings =>\n typeof value === \"object\"\n && value !== null\n && \"rawDir\" in value\n && typeof value.rawDir === \"string\"\n && \"root\" in value\n && typeof value.root === \"string\"\n && \"packageName\" in value\n && typeof value.packageName === \"string\"\n\n/** Reads the coverage settings from the environment, and throws when they're missing or invalid. */\nconst readCoverageSettings = () => {\n const settings = process.env[SUBPROCESS_COVERAGE_SETTINGS_VAR]\n if (settings === undefined)\n throw new Error(`the subprocess coverage preload loaded without ${SUBPROCESS_COVERAGE_SETTINGS_VAR}`)\n const parsed: unknown = JSON.parse(settings)\n if (!isCoverageSettings(parsed)) throw new Error(`${SUBPROCESS_COVERAGE_SETTINGS_VAR} isn't valid: ${settings}`)\n return parsed\n}\n\nconst { rawDir, root, packageName } = readCoverageSettings()\n\nconst isSourceMap = (value: unknown): value is InputSourceMap =>\n typeof value === \"object\" && value !== null && \"sources\" in value && Array.isArray(value.sources)\n\n/** Points each source in the installed package's map at the same file in the project, so reports name `src/`. */\nconst readSourceMap = async (file: string, packageDir: string, projectDir: string) => {\n const sourceMap: unknown = await bun.file(`${file}.map`).json()\n if (!isSourceMap(sourceMap)) throw new Error(`no source map for ${file}`)\n const sources = sourceMap.sources.map((source) => {\n const installedSource = path.resolve(path.dirname(file), source ?? \"\")\n return path.join(projectDir, path.relative(packageDir, installedSource))\n })\n return { ...sourceMap, sources }\n}\n\nconst instrumenter = createInstrumenter({ esModules: true, coverageVariable: INSTRUMENTER_COVERAGE_VARIABLE })\n// Match the built files of the copy that a test project installs, and capture its package dir.\nconst installedDist = new RegExp(String.raw`^(.*/node_modules/${RegExp.escape(packageName)})/dist/.*\\.js$`, \"v\")\n\nbun.plugin({\n name: \"subprocess-coverage\",\n setup: (build) => {\n build.onLoad({ filter: installedDist }, async ({ path: file }) => {\n const [, packageDir = \"\"] = installedDist.exec(file) ?? []\n const code = await bun.file(file).text()\n const sourceMap = await readSourceMap(file, packageDir, root)\n return { contents: instrumenter.instrumentSync(code, file, sourceMap), loader: \"js\" }\n })\n },\n})\n\nconst hasCoverage = (value: object): value is Record<typeof INSTRUMENTER_COVERAGE_VARIABLE, unknown> =>\n INSTRUMENTER_COVERAGE_VARIABLE in value\n\nconst writeCoverage = () => {\n // Copy `globalThis` to a local because TypeScript doesn't narrow `globalThis` itself.\n const globalScope: object = globalThis\n // Skip a process that never loaded the package, because only instrumented code creates the global.\n if (!hasCoverage(globalScope)) return\n fs.writeFileSync(\n path.join(rawDir, `${crypto.randomUUID()}.json`),\n JSON.stringify(globalScope[INSTRUMENTER_COVERAGE_VARIABLE]),\n )\n}\n\nprocess.on(\"exit\", writeCoverage)\n\n// Move `writeCoverage` behind each later exit listener so the coverage file includes what those listeners run.\n// Wait a microtask because `newListener` fires before the new listener is added.\n// A listener added in the same tick as a synchronous `process.exit()` still runs after the write.\nprocess.on(\"newListener\", (event, listener) => {\n if (event !== \"exit\" || listener === writeCoverage) return\n queueMicrotask(() => {\n process.removeListener(\"exit\", writeCoverage)\n process.on(\"exit\", writeCoverage)\n })\n})\n"],"mappings":";;;;;;;AAaA,MAAM,iCAAiC;AAEvC,MAAM,sBAAsB,UAC1B,OAAO,UAAU,YACd,UAAU,QACV,YAAY,SACZ,OAAO,MAAM,WAAW,YACxB,UAAU,SACV,OAAO,MAAM,SAAS,YACtB,iBAAiB,SACjB,OAAO,MAAM,gBAAgB;;AAGlC,MAAM,6BAA6B;CACjC,MAAM,WAAW,QAAQ,IAAI;CAC7B,IAAI,aAAa,KAAA,GACf,MAAM,IAAI,MAAM,kDAAkD,kCAAkC;CACtG,MAAM,SAAkB,KAAK,MAAM,QAAQ;CAC3C,IAAI,CAAC,mBAAmB,MAAM,GAAG,MAAM,IAAI,MAAM,GAAG,iCAAiC,gBAAgB,UAAU;CAC/G,OAAO;AACT;AAEA,MAAM,EAAE,QAAQ,MAAM,gBAAgB,qBAAqB;AAE3D,MAAM,eAAe,UACnB,OAAO,UAAU,YAAY,UAAU,QAAQ,aAAa,SAAS,MAAM,Q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,aAAa;AAKhC,QAAQ,GAAG,gBAAgB,OAAO,aAAa;CAC7C,IAAI,UAAU,UAAU,aAAa,eAAe;CACpD,qBAAqB;EACnB,QAAQ,eAAe,QAAQ,aAAa;EAC5C,QAAQ,GAAG,QAAQ,aAAa;CAClC,CAAC;AACH,CAAC"}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { ShellEnv } from "../shell/shell.js";
|
|
2
|
-
/**
|
|
3
|
-
* Returns the variables that make child Bun processes record coverage, for a shell that doesn't inherit `process.env`.
|
|
4
|
-
* Returns nothing when the project doesn't import `@adamhl8/configs/test/subprocess-coverage`.
|
|
5
|
-
*/
|
|
6
|
-
export declare const subprocessCoverageEnv: () => ShellEnv;
|
|
7
|
-
//# sourceMappingURL=env.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"env.d.ts","names":[],"sources":["../../../src/test-utils/subprocess-coverage/env.ts"],"mappings":";;;;;qBAiBa,6BAA4B"}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import process from "node:process";
|
|
2
|
-
// src/test-utils/subprocess-coverage/env.ts
|
|
3
|
-
/** Holds the JSON settings that tell a child's preload where to write coverage and what to instrument. */
|
|
4
|
-
const SUBPROCESS_COVERAGE_SETTINGS_VAR = "ADAMHL8_SUBPROCESS_COVERAGE_SETTINGS";
|
|
5
|
-
/**
|
|
6
|
-
* Returns the variables that make child Bun processes record coverage, for a shell that doesn't inherit `process.env`.
|
|
7
|
-
* Returns nothing when the project doesn't import `@adamhl8/configs/test/subprocess-coverage`.
|
|
8
|
-
*/
|
|
9
|
-
const subprocessCoverageEnv = () => {
|
|
10
|
-
const settings = process.env[SUBPROCESS_COVERAGE_SETTINGS_VAR];
|
|
11
|
-
if (settings === void 0) return {};
|
|
12
|
-
return {
|
|
13
|
-
BUN_OPTIONS: process.env["BUN_OPTIONS"],
|
|
14
|
-
[SUBPROCESS_COVERAGE_SETTINGS_VAR]: settings
|
|
15
|
-
};
|
|
16
|
-
};
|
|
17
|
-
export { SUBPROCESS_COVERAGE_SETTINGS_VAR, subprocessCoverageEnv };
|
|
18
|
-
|
|
19
|
-
//# sourceMappingURL=env.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"env.js","names":[],"sources":["../../../src/test-utils/subprocess-coverage/env.ts"],"sourcesContent":["import process from \"node:process\"\n\nimport type { ShellEnv } from \"#test-utils/shell/shell.ts\"\n\n/** Holds the JSON settings that tell a child's preload where to write coverage and what to instrument. */\nexport const SUBPROCESS_COVERAGE_SETTINGS_VAR = \"ADAMHL8_SUBPROCESS_COVERAGE_SETTINGS\"\n\nexport interface CoverageSettings {\n rawDir: string\n root: string\n packageName: string\n}\n\n/**\n * Returns the variables that make child Bun processes record coverage, for a shell that doesn't inherit `process.env`.\n * Returns nothing when the project doesn't import `@adamhl8/configs/test/subprocess-coverage`.\n */\nexport const subprocessCoverageEnv = (): ShellEnv => {\n const settings = process.env[SUBPROCESS_COVERAGE_SETTINGS_VAR]\n if (settings === undefined) return {}\n return { BUN_OPTIONS: process.env[\"BUN_OPTIONS\"], [SUBPROCESS_COVERAGE_SETTINGS_VAR]: settings }\n}\n"],"mappings":";;;AAKA,MAAa,mCAAmC;;;;;AAYhD,MAAa,8BAAwC;CACnD,MAAM,WAAW,QAAQ,IAAI;CAC7B,IAAI,aAAa,KAAA,GAAW,OAAO,CAAC;CACpC,OAAO;EAAE,aAAa,QAAQ,IAAI;GAAiB,mCAAmC;CAAS;AACjG"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { SUBPROCESS_COVERAGE_SETTINGS_VAR } from "./env.js";
|
|
2
|
-
import { reportCoverage } from "./report.js";
|
|
3
|
-
import process from "node:process";
|
|
4
|
-
import fs from "node:fs/promises";
|
|
5
|
-
import path from "node:path";
|
|
6
|
-
import bun from "bun";
|
|
7
|
-
import os from "node:os";
|
|
8
|
-
import { afterAll } from "bun:test";
|
|
9
|
-
// src/test-utils/subprocess-coverage/preload.ts
|
|
10
|
-
const CHILD_PRELOAD = path.join(import.meta.dir, `child-preload${path.extname(import.meta.path)}`);
|
|
11
|
-
const hasName = (value) => typeof value === "object" && value !== null && "name" in value && typeof value.name === "string";
|
|
12
|
-
const isRecord = (value) => typeof value === "object" && value !== null;
|
|
13
|
-
const root = process.cwd();
|
|
14
|
-
const packageJson = await bun.file(path.join(root, "package.json")).json();
|
|
15
|
-
if (!hasName(packageJson)) throw new Error(`subprocess coverage needs a package name in ${root}/package.json`);
|
|
16
|
-
const REPORT_DIR = path.join(root, "coverage/subprocess");
|
|
17
|
-
/** Returns Bun's `coveragePathIgnorePatterns` while its coverage is on, or `undefined` when it's off. */
|
|
18
|
-
const readBunIgnorePatterns = async () => {
|
|
19
|
-
const bunfigFile = bun.file(path.join(root, "bunfig.toml"));
|
|
20
|
-
const bunfig = await bunfigFile.exists() ? bun.TOML.parse(await bunfigFile.text()) : {};
|
|
21
|
-
const test = isRecord(bunfig) && isRecord(bunfig["test"]) ? bunfig["test"] : {};
|
|
22
|
-
if (!(test["coverage"] === true)) return;
|
|
23
|
-
return [test["coveragePathIgnorePatterns"]].flat().filter((pattern) => typeof pattern === "string");
|
|
24
|
-
};
|
|
25
|
-
const includePatterns = (await readBunIgnorePatterns())?.map((pattern) => path.join(root, pattern));
|
|
26
|
-
const rawDir = await fs.mkdtemp(path.join(os.tmpdir(), "subprocess-coverage-"));
|
|
27
|
-
const settings = {
|
|
28
|
-
rawDir,
|
|
29
|
-
root,
|
|
30
|
-
packageName: packageJson.name
|
|
31
|
-
};
|
|
32
|
-
process.env["BUN_OPTIONS"] = `--preload=${CHILD_PRELOAD}`;
|
|
33
|
-
process.env[SUBPROCESS_COVERAGE_SETTINGS_VAR] = JSON.stringify(settings);
|
|
34
|
-
afterAll(async () => {
|
|
35
|
-
await reportCoverage(rawDir, REPORT_DIR, includePatterns);
|
|
36
|
-
await fs.rm(rawDir, {
|
|
37
|
-
recursive: true,
|
|
38
|
-
force: true
|
|
39
|
-
});
|
|
40
|
-
});
|
|
41
|
-
export {};
|
|
42
|
-
|
|
43
|
-
//# sourceMappingURL=preload.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"preload.js","names":[],"sources":["../../../src/test-utils/subprocess-coverage/preload.ts"],"sourcesContent":["// Turns on coverage for the package's own bins and modules that tests run in child processes.\n// Import it once, from the test preload, in the package's repo.\nimport { afterAll } from \"bun:test\"\nimport fs from \"node:fs/promises\"\nimport os from \"node:os\"\nimport path from \"node:path\"\nimport process from \"node:process\"\n\nimport bun from \"bun\"\n\nimport { SUBPROCESS_COVERAGE_SETTINGS_VAR } from \"#test-utils/subprocess-coverage/env.ts\"\nimport type { CoverageSettings } from \"#test-utils/subprocess-coverage/env.ts\"\nimport { reportCoverage } from \"#test-utils/subprocess-coverage/report.ts\"\n\n// Match this file's extension so the preload is the `.ts` source in this repo and the built `.js` in `dist/`.\nconst CHILD_PRELOAD = path.join(import.meta.dir, `child-preload${path.extname(import.meta.path)}`)\n\nconst hasName = (value: unknown): value is { name: string } =>\n typeof value === \"object\" && value !== null && \"name\" in value && typeof value.name === \"string\"\n\nconst isRecord = (value: unknown): value is Record<string, unknown> => typeof value === \"object\" && value !== null\n\nconst root = process.cwd()\nconst packageJson: unknown = await bun.file(path.join(root, \"package.json\")).json()\nif (!hasName(packageJson)) throw new Error(`subprocess coverage needs a package name in ${root}/package.json`)\n\n// Write to a subdir because Bun writes its own `coverage/lcov.info` after this report.\nconst REPORT_DIR = path.join(root, \"coverage/subprocess\")\n\n/** Returns Bun's `coveragePathIgnorePatterns` while its coverage is on, or `undefined` when it's off. */\nconst readBunIgnorePatterns = async () => {\n const bunfigFile = bun.file(path.join(root, \"bunfig.toml\"))\n const bunfig: unknown = (await bunfigFile.exists()) ? bun.TOML.parse(await bunfigFile.text()) : {}\n const test = isRecord(bunfig) && isRecord(bunfig[\"test\"]) ? bunfig[\"test\"] : {}\n\n const isBunCoverageOn = test[\"coverage\"] === true\n if (!isBunCoverageOn) return\n\n const coverageIgnorePatterns = test[\"coveragePathIgnorePatterns\"]\n return [coverageIgnorePatterns].flat().filter((pattern) => typeof pattern === \"string\")\n}\n\n// Report only the files that Bun's coverage ignores, so each file appears in one report.\n// Join each pattern onto `root` because Bun's patterns are root-relative and the report's paths are absolute.\nconst includePatterns = (await readBunIgnorePatterns())?.map((pattern) => path.join(root, pattern))\n\nconst rawDir = await fs.mkdtemp(path.join(os.tmpdir(), \"subprocess-coverage-\"))\nconst settings: CoverageSettings = { rawDir, root, packageName: packageJson.name }\n\n// Set these on `process.env` so `subprocessCoverageEnv` and shells that inherit `process.env` pass them on.\nprocess.env[\"BUN_OPTIONS\"] = `--preload=${CHILD_PRELOAD}`\nprocess.env[SUBPROCESS_COVERAGE_SETTINGS_VAR] = JSON.stringify(settings)\n\nafterAll(async () => {\n await reportCoverage(rawDir, REPORT_DIR, includePatterns)\n await fs.rm(rawDir, { recursive: true, force: true })\n})\n"],"mappings":";;;;;;;;;AAeA,MAAM,gBAAgB,KAAK,KAAK,YAAY,KAAK,gBAAgB,KAAK,QAAQ,YAAY,IAAI,GAAG;AAEjG,MAAM,WAAW,UACf,OAAO,UAAU,YAAY,UAAU,QAAQ,UAAU,SAAS,OAAO,MAAM,SAAS;AAE1F,MAAM,YAAY,UAAqD,OAAO,UAAU,YAAY,UAAU;AAE9G,MAAM,OAAO,QAAQ,IAAI;AACzB,MAAM,cAAuB,MAAM,IAAI,KAAK,KAAK,KAAK,MAAM,cAAc,CAAC,CAAC,CAAC,KAAK;AAClF,IAAI,CAAC,QAAQ,WAAW,GAAG,MAAM,IAAI,MAAM,+CAA+C,KAAK,cAAc;AAG7G,MAAM,aAAa,KAAK,KAAK,MAAM,qBAAqB;;AAGxD,MAAM,wBAAwB,YAAY;CACxC,MAAM,aAAa,IAAI,KAAK,KAAK,KAAK,MAAM,aAAa,CAAC;CAC1D,MAAM,SAAmB,MAAM,WAAW,OAAO,IAAK,IAAI,KAAK,MAAM,MAAM,WAAW,KAAK,CAAC,IAAI,CAAC;CACjG,MAAM,OAAO,SAAS,MAAM,KAAK,SAAS,OAAO,OAAO,IAAI,OAAO,UAAU,CAAC;CAG9E,IAAI,EADoB,KAAK,gBAAgB,OACvB;CAGtB,OAAO,CADwB,KAAK,6BACN,CAAC,CAAC,KAAK,CAAC,CAAC,QAAQ,YAAY,OAAO,YAAY,QAAQ;AACxF;AAIA,MAAM,mBAAmB,MAAM,sBAAsB,EAAA,EAAI,KAAK,YAAY,KAAK,KAAK,MAAM,OAAO,CAAC;AAElG,MAAM,SAAS,MAAM,GAAG,QAAQ,KAAK,KAAK,GAAG,OAAO,GAAG,sBAAsB,CAAC;AAC9E,MAAM,WAA6B;CAAE;CAAQ;CAAM,aAAa,YAAY;AAAK;AAGjF,QAAQ,IAAI,iBAAiB,aAAa;AAC1C,QAAQ,IAAI,oCAAoC,KAAK,UAAU,QAAQ;AAEvE,SAAS,YAAY;CACnB,MAAM,eAAe,QAAQ,YAAY,eAAe;CACxD,MAAM,GAAG,GAAG,QAAQ;EAAE,WAAW;EAAM,OAAO;CAAK,CAAC;AACtD,CAAC"}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import fs from "node:fs/promises";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
import bun from "bun";
|
|
4
|
-
import { createCoverageMap } from "@vitest/istanbul-lib-coverage";
|
|
5
|
-
import { create, createContext } from "@vitest/istanbul-lib-report";
|
|
6
|
-
import { createSourceMapStore } from "@vitest/istanbul-lib-source-maps";
|
|
7
|
-
// src/test-utils/subprocess-coverage/report.ts
|
|
8
|
-
const isCoverageMapData = (value) => typeof value === "object" && value !== null;
|
|
9
|
-
/**
|
|
10
|
-
* Merges the coverage from every process in `rawDir`, maps it back to the source, and writes a text and lcov report.
|
|
11
|
-
* Reports only the source files that match a glob in `includePatterns`, or every file when it's `undefined`.
|
|
12
|
-
*/
|
|
13
|
-
const reportCoverage = async (rawDir, reportDir, includePatterns) => {
|
|
14
|
-
const rawFiles = await fs.readdir(rawDir);
|
|
15
|
-
if (rawFiles.length === 0) return;
|
|
16
|
-
const rawCoverages = await Promise.all(rawFiles.map(async (rawFile) => bun.file(path.join(rawDir, rawFile)).json()));
|
|
17
|
-
const coverageMap = createCoverageMap({});
|
|
18
|
-
for (const rawCoverage of rawCoverages) if (isCoverageMapData(rawCoverage)) coverageMap.merge(rawCoverage);
|
|
19
|
-
const sourceCoverageMap = await createSourceMapStore().transformCoverage(coverageMap);
|
|
20
|
-
if (includePatterns) {
|
|
21
|
-
const globs = includePatterns.map((pattern) => new bun.Glob(pattern));
|
|
22
|
-
sourceCoverageMap.filter((file) => globs.some((glob) => glob.match(file)));
|
|
23
|
-
}
|
|
24
|
-
if (sourceCoverageMap.files().length === 0) return;
|
|
25
|
-
console.log("\nSubprocess coverage:");
|
|
26
|
-
const context = createContext({
|
|
27
|
-
dir: reportDir,
|
|
28
|
-
coverageMap: sourceCoverageMap
|
|
29
|
-
});
|
|
30
|
-
create("text").execute(context);
|
|
31
|
-
create("lcovonly").execute(context);
|
|
32
|
-
};
|
|
33
|
-
export { reportCoverage };
|
|
34
|
-
|
|
35
|
-
//# sourceMappingURL=report.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"report.js","names":[],"sources":["../../../src/test-utils/subprocess-coverage/report.ts"],"sourcesContent":["import fs from \"node:fs/promises\"\nimport path from \"node:path\"\n\nimport { createCoverageMap } from \"@vitest/istanbul-lib-coverage\"\nimport type { CoverageMapData } from \"@vitest/istanbul-lib-coverage\"\nimport { create as createReport, createContext } from \"@vitest/istanbul-lib-report\"\nimport { createSourceMapStore } from \"@vitest/istanbul-lib-source-maps\"\nimport bun from \"bun\"\n\nconst isCoverageMapData = (value: unknown): value is CoverageMapData => typeof value === \"object\" && value !== null\n\n/**\n * Merges the coverage from every process in `rawDir`, maps it back to the source, and writes a text and lcov report.\n * Reports only the source files that match a glob in `includePatterns`, or every file when it's `undefined`.\n */\nexport const reportCoverage = async (rawDir: string, reportDir: string, includePatterns?: string[]) => {\n const rawFiles = await fs.readdir(rawDir)\n if (rawFiles.length === 0) return\n\n const rawCoverages = await Promise.all(\n rawFiles.map(async (rawFile): Promise<unknown> => bun.file(path.join(rawDir, rawFile)).json()),\n )\n const coverageMap = createCoverageMap({})\n for (const rawCoverage of rawCoverages) if (isCoverageMapData(rawCoverage)) coverageMap.merge(rawCoverage)\n\n const sourceCoverageMap = await createSourceMapStore().transformCoverage(coverageMap)\n if (includePatterns) {\n const globs = includePatterns.map((pattern) => new bun.Glob(pattern))\n sourceCoverageMap.filter((file) => globs.some((glob) => glob.match(file)))\n }\n if (sourceCoverageMap.files().length === 0) return\n\n // Label the table because Bun's own coverage table can print next to it.\n console.log(\"\\nSubprocess coverage:\")\n const context = createContext({ dir: reportDir, coverageMap: sourceCoverageMap })\n createReport(\"text\").execute(context)\n createReport(\"lcovonly\").execute(context)\n}\n"],"mappings":";;;;;;;AASA,MAAM,qBAAqB,UAA6C,OAAO,UAAU,YAAY,UAAU;;;;;AAM/G,MAAa,iBAAiB,OAAO,QAAgB,WAAmB,oBAA+B;CACrG,MAAM,WAAW,MAAM,GAAG,QAAQ,MAAM;CACxC,IAAI,SAAS,WAAW,GAAG;CAE3B,MAAM,eAAe,MAAM,QAAQ,IACjC,SAAS,IAAI,OAAO,YAA8B,IAAI,KAAK,KAAK,KAAK,QAAQ,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAC/F;CACA,MAAM,cAAc,kBAAkB,CAAC,CAAC;CACxC,KAAK,MAAM,eAAe,cAAc,IAAI,kBAAkB,WAAW,GAAG,YAAY,MAAM,WAAW;CAEzG,MAAM,oBAAoB,MAAM,qBAAqB,CAAC,CAAC,kBAAkB,WAAW;CACpF,IAAI,iBAAiB;EACnB,MAAM,QAAQ,gBAAgB,KAAK,YAAY,IAAI,IAAI,KAAK,OAAO,CAAC;EACpE,kBAAkB,QAAQ,SAAS,MAAM,MAAM,SAAS,KAAK,MAAM,IAAI,CAAC,CAAC;CAC3E;CACA,IAAI,kBAAkB,MAAM,CAAC,CAAC,WAAW,GAAG;CAG5C,QAAQ,IAAI,wBAAwB;CACpC,MAAM,UAAU,cAAc;EAAE,KAAK;EAAW,aAAa;CAAkB,CAAC;CAChF,OAAa,MAAM,CAAC,CAAC,QAAQ,OAAO;CACpC,OAAa,UAAU,CAAC,CAAC,QAAQ,OAAO;AAC1C"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"temp-dir.d.ts","names":[],"sources":["../../src/test-utils/temp-dir.ts"],"mappings":";qBAOa,cAAW,mBAAwB"}
|