@adamhl8/configs 3.2.0 → 3.3.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 +46 -4
- package/dist/configs/gitignore.base +1 -0
- package/dist/configs/oxlint.base.d.ts +7 -0
- package/dist/configs/oxlint.base.d.ts.map +1 -1
- package/dist/configs/oxlint.base.js +8 -0
- package/dist/configs/oxlint.base.js.map +1 -1
- package/dist/test-utils/index.d.ts +2 -1
- package/dist/test-utils/index.js +2 -1
- package/dist/test-utils/subprocess-coverage/child-preload.d.ts +1 -0
- package/dist/test-utils/subprocess-coverage/child-preload.js +60 -0
- package/dist/test-utils/subprocess-coverage/child-preload.js.map +1 -0
- package/dist/test-utils/subprocess-coverage/env.d.ts +7 -0
- package/dist/test-utils/subprocess-coverage/env.d.ts.map +1 -0
- package/dist/test-utils/subprocess-coverage/env.js +19 -0
- package/dist/test-utils/subprocess-coverage/env.js.map +1 -0
- package/dist/test-utils/subprocess-coverage/preload.d.ts +1 -0
- package/dist/test-utils/subprocess-coverage/preload.js +32 -0
- package/dist/test-utils/subprocess-coverage/preload.js.map +1 -0
- package/dist/test-utils/subprocess-coverage/report.js +26 -0
- package/dist/test-utils/subprocess-coverage/report.js.map +1 -0
- package/package.json +25 -1
package/README.md
CHANGED
|
@@ -61,6 +61,7 @@ Some tools are only needed by some projects:
|
|
|
61
61
|
- Published packages: `tsdown publint @arethetypeswrong/core`
|
|
62
62
|
- Releases: `release-it release-it-git-cliff` (see [release-it](#release-it))
|
|
63
63
|
- 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))
|
|
64
65
|
|
|
65
66
|
## Setup
|
|
66
67
|
|
|
@@ -162,7 +163,9 @@ oxlint-tailwindcss runs every rule except `enforce-sort-order` and `enforce-cons
|
|
|
162
163
|
// knip.ts
|
|
163
164
|
import { knipConfig } from "@adamhl8/configs"
|
|
164
165
|
|
|
165
|
-
|
|
166
|
+
const config = knipConfig({ ... })
|
|
167
|
+
|
|
168
|
+
export default config
|
|
166
169
|
```
|
|
167
170
|
|
|
168
171
|
The base leaves `fixtures` and `fixture` dirs out of the analysis, at any depth. It adds `**/*.test.ts` and `bask.ts` to the bun plugin's entries rather than the top-level `entry`, so a project's own `entry` doesn't replace knip's default entries. knip doesn't see commands run through bask's `sh`, so a dependency that's only run there goes in `ignoreDependencies`.
|
|
@@ -189,7 +192,9 @@ The base builds `src/index.ts` as an unbundled ESM library with sourcemaps and t
|
|
|
189
192
|
// commitlint.config.ts
|
|
190
193
|
import { commitlintConfig } from "@adamhl8/configs"
|
|
191
194
|
|
|
192
|
-
|
|
195
|
+
const config = commitlintConfig({ ... })
|
|
196
|
+
|
|
197
|
+
export default config
|
|
193
198
|
```
|
|
194
199
|
|
|
195
200
|
The allowed commit types are the conventional types without `test`, `style`, and `build`, plus `improve` and `release`. `bunx bask commit-types` prints them.
|
|
@@ -210,7 +215,9 @@ With bun's `isolated` linker, our copy lives only in `@adamhl8/configs`'s own `n
|
|
|
210
215
|
// .release-it.ts
|
|
211
216
|
import { releaseItConfig } from "@adamhl8/configs"
|
|
212
217
|
|
|
213
|
-
|
|
218
|
+
const config = releaseItConfig({ ... })
|
|
219
|
+
|
|
220
|
+
export default config
|
|
214
221
|
```
|
|
215
222
|
|
|
216
223
|
The release config registers the [`release-it-git-cliff`](https://github.com/adamhl8/release-it-git-cliff) plugin with the bundled git-cliff config (`cliff.base.toml`), so there is no per-project `cliff.toml` to write. git-cliff picks the next version from the commits, and the plugin writes `CHANGELOG.md` (formatted with `oxfmt`) and sets the release notes. A release starts by running `bunx bask build`. The release commit is `release: v${version}`, and the tag is `v${version}`. It publishes with `bun publish --ignore-scripts`.
|
|
@@ -391,6 +398,7 @@ const { exitCode: failedCode } = await run`my-cli --bad-flag`.nothrow()
|
|
|
391
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.
|
|
392
399
|
- `minimalEnv(extra)` returns just `PATH` and `HOME`, plus `extra`.
|
|
393
400
|
- `makeTempDir(prefix)` makes a temp dir that's removed after the test run. `copyFixture` and `packPackage` use it.
|
|
401
|
+
- `subprocessCoverageEnv()` returns the variables that turn on [subprocess coverage](#subprocess-coverage) for a shell's `env`, or nothing when it's off.
|
|
394
402
|
|
|
395
403
|
The temp dirs are removed by a preload, which each project adds to its `bunfig.toml`:
|
|
396
404
|
|
|
@@ -407,6 +415,38 @@ import "@adamhl8/configs/test/preload"
|
|
|
407
415
|
|
|
408
416
|
It isn't in the shared bunfig base because `adamhl8-bunfig` merges arrays by index, so a project's own `preload` would replace it.
|
|
409
417
|
|
|
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/lcov.info`.
|
|
444
|
+
- Set `coverage = false` under `[test]` in `bunfig.toml`, because Bun's own coverage only sees the test process.
|
|
445
|
+
- 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.
|
|
446
|
+
- Code in the package's own `exit` handlers isn't counted, and a process killed by a signal writes no coverage.
|
|
447
|
+
|
|
448
|
+
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.
|
|
449
|
+
|
|
410
450
|
## GitHub Actions
|
|
411
451
|
|
|
412
452
|
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.
|
|
@@ -561,10 +601,12 @@ module "github" {
|
|
|
561
601
|
|
|
562
602
|
The repo's description, homepage, and topics come from the `description`, `homepage`, and `keywords` in `package.json`. A homepage that points at the repo itself is left out. The repo only allows squash merges, which use the PR title as the commit message, and deletes branches once they're merged. Secret scanning, push protection, and vulnerability alerts are on.
|
|
563
603
|
|
|
564
|
-
`actions_secrets` picks the secrets to set. `CI_SIGNING_KEY` and `CI_TOKEN` are on by default, and `NPM_CI_TOKEN` and `GH_TOKEN` are off. `additional_secrets` adds other secrets by name. Each value is read from `~/homelab/secrets/credentials.yaml` (a sops file) under the secret's lowercased name. A
|
|
604
|
+
`actions_secrets` picks the secrets to set. `CI_SIGNING_KEY` and `CI_TOKEN` are on by default, and `NPM_CI_TOKEN` and `GH_TOKEN` are off. `additional_secrets` adds other secrets by name. Each value is read from `~/homelab/secrets/credentials.yaml` (a sops file) under the secret's lowercased name. A secret on the repo that the module doesn't manage shows up as a warning in `tofu plan`, naming the secrets, and doesn't fail the plan.
|
|
565
605
|
|
|
566
606
|
The `prepare` task runs `tofu init -upgrade`, and the `tofu-check` task (which `build` runs) checks for drift with `tofu plan`. See [bask tasks](#bask-tasks) for when they run.
|
|
567
607
|
|
|
568
608
|
## Developing this repo
|
|
569
609
|
|
|
570
610
|
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.
|
|
611
|
+
|
|
612
|
+
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.
|
|
@@ -41,6 +41,13 @@ export declare const oxlintConfig: OptionalMergeConfigFn<OxlintConfig, {
|
|
|
41
41
|
readonly allowArrowFunctions: true;
|
|
42
42
|
}];
|
|
43
43
|
};
|
|
44
|
+
} | {
|
|
45
|
+
readonly files: ["**/fixtures/**", "**/fixture/**"];
|
|
46
|
+
readonly rules: {
|
|
47
|
+
readonly "clean-modules/require-import-extensions": "off";
|
|
48
|
+
readonly "clean-modules/require-subpath-imports": "off";
|
|
49
|
+
readonly "import/no-default-export": "off";
|
|
50
|
+
};
|
|
44
51
|
} | (Omit<OxlintOverride, "rules"> & {
|
|
45
52
|
rules?: PluginRules;
|
|
46
53
|
}))[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"oxlint.base.d.ts","names":["_$_merge_config_merge_config_ts0.OptionalMergeConfigFn"],"sources":["../../src/configs/oxlint.base.ts"],"mappings":";;KAmBK,cAAc,eAAe;
|
|
1
|
+
{"version":3,"file":"oxlint.base.d.ts","names":["_$_merge_config_merge_config_ts0.OptionalMergeConfigFn"],"sources":["../../src/configs/oxlint.base.ts"],"mappings":";;KAmBK,cAAc,eAAe;qBA4UrB,cAxU4CA,sBAwUhC;;aAhNrB;aACA;aACA;;;aAIA;aACA;aACA;aACA;aACA;aACA;aACA;;;;;;;eA+BI;;;;;eAMA;eACA;;;;;eAMA;;;;;;;;;;;;eAYA;eACA;eACA;;;IA9LiD,QAAA;;;;;;eAwMF;;;eAI9B;eAA2C;;;eAER;eAA4B;eAAiB;;;;iBAKxF;iBAAiB;;;;;;IAON;IACX;IACQ;IACG;IACX;IACa;IACR;IACJ;IACC;IACS;IACF;IACF;IACL;IACI;IACL;IACF;IACI;IACK;IACV;IACA;IACM;IACD;IACH;IAEU;IACC;IACG;IACD;IACE;IACG;IACC;IAET;IACE;IAED;IACD;IACP;IACW;IAEL;IACM;IACK;IAEO;IACR;IACjB;IACI;IACa;IACT;IACE;IACE;IACW;IACV;IACF;IACZ;IAEkB;IACY;IACC;IACC;IACL;IAEF;IACE;IACH;IACX;IACI;IACD;IAEX;IACmB;IACG;IACN;IACO;IACT;IACJ;IACC;IACP;IACQ"}
|
|
@@ -178,6 +178,14 @@ const nativeConfig = {
|
|
|
178
178
|
"declaration",
|
|
179
179
|
{ allowArrowFunctions: true }
|
|
180
180
|
] }
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
files: ["**/fixtures/**", "**/fixture/**"],
|
|
184
|
+
rules: {
|
|
185
|
+
"clean-modules/require-import-extensions": "off",
|
|
186
|
+
"clean-modules/require-subpath-imports": "off",
|
|
187
|
+
"import/no-default-export": "off"
|
|
188
|
+
}
|
|
181
189
|
}
|
|
182
190
|
],
|
|
183
191
|
rules: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"oxlint.base.js","names":["directiveCommentsPluginRules","regexpPluginRules"],"sources":["../../src/configs/oxlint.base.ts"],"sourcesContent":["import cleanModulesPlugin from \"@adamhl8/eslint-plugin-clean-modules\"\nimport e18ePlugin from \"@e18e/eslint-plugin\"\nimport bunismsPlugin from \"eslint-plugin-bunisms\"\nimport honoPlugin from \"eslint-plugin-hono\"\nimport reactWebApiPlugin from \"eslint-plugin-react-web-api\"\nimport reactEffectPlugin from \"eslint-plugin-react-you-might-not-need-an-effect\"\nimport { rules as regexpPluginRules } from \"eslint-plugin-regexp\"\nimport type { DummyRule, OxlintConfig, OxlintOverride } from \"oxlint\"\nimport { rules as directiveCommentsPluginRules } from \"oxlint-plugin-directive-comments\"\nimport tailwindcssPlugin from \"oxlint-tailwindcss\"\n\nimport { createMergeConfigFn } from \"#merge-config/merge-config.ts\"\nimport { readProjectPackageJson, resolvePackagePath, resolveProjectTailwind } from \"#utils.ts\"\n\n/** Sets every rule in a JS plugin to `severity`, because `categories` doesn't apply to JS plugins. */\nconst setAllPluginRules = (name: string, rules: Record<string, unknown>, severity: \"error\" | \"off\") =>\n Object.fromEntries(Object.keys(rules).map((rule) => [`${name}/${rule}`, severity] as const))\n\n// Type plugin rules with oxlint's generic `DummyRule` because its per-rule config types aren't exported, which breaks declaration emit.\ntype PluginRules = Record<string, DummyRule>\n\n/** A JS plugin and the slice of oxlint config that goes with it. Each one is merged into the base config. */\ninterface PluginPart extends Omit<OxlintConfig, \"jsPlugins\" | \"overrides\" | \"rules\"> {\n overrides?: (Omit<OxlintOverride, \"rules\"> & { rules?: PluginRules })[]\n rules?: PluginRules\n /** Loads the plugin only when true. Defaults to true. */\n enabled?: boolean\n package: string\n /** The plugin's rule definitions, used to set every rule to \"error\". The part's own `rules` then take precedence. */\n pluginRules: Record<string, unknown> | undefined\n}\n\nconst { dependencies, engines } = readProjectPackageJson()\nconst tailwindStylesheet = resolveProjectTailwind()\n\n// Key each part by the rule namespace its plugin registers.\nconst plugins: Record<string, PluginPart> = {\n bunisms: {\n overrides: [\n {\n excludeFiles: [\"src/**/__tests__/**\", \"src/**/*.test.{ts,tsx}\", \"src/**/test-setup.ts\", \"src/**/test-utils.ts\"],\n // Turn off Bun suggestions in Node runtime code. Tests and tooling still run on Bun.\n files: engines.has(\"node\") ? [\"src/**\"] : [],\n rules: setAllPluginRules(\"bunisms\", bunismsPlugin.rules, \"off\"),\n },\n ],\n package: \"eslint-plugin-bunisms\",\n pluginRules: bunismsPlugin.rules,\n rules: {\n \"bunisms/prefer-mock-restore-in-after-each\": \"off\", // `test-setup.ts` preloads restore mocks globally\n },\n },\n \"clean-modules\": {\n package: \"@adamhl8/eslint-plugin-clean-modules\",\n pluginRules: cleanModulesPlugin.rules,\n },\n \"directive-comments\": {\n package: \"oxlint-plugin-directive-comments\",\n pluginRules: directiveCommentsPluginRules,\n rules: {\n \"directive-comments/disable-enable-pair\": [\"error\", { allowWholeFile: true }],\n \"directive-comments/no-use\": \"off\", // bans every directive comment\n },\n },\n e18e: {\n package: \"@e18e/eslint-plugin\",\n pluginRules: e18ePlugin.rules,\n rules: {\n \"e18e/no-indexof-equality\": \"off\", // needs type information, which JS plugins don't get\n \"e18e/no-spread-in-reduce\": \"off\", // `oxc/no-accumulating-spread` covers this\n \"e18e/prefer-array-at\": \"off\", // `unicorn/prefer-at` covers this\n \"e18e/prefer-array-some\": \"off\", // `unicorn/prefer-array-some` covers this\n \"e18e/prefer-array-to-reversed\": \"off\", // `unicorn/no-array-reverse` covers this\n \"e18e/prefer-array-to-sorted\": \"off\", // `unicorn/no-array-sort` covers this\n \"e18e/prefer-date-now\": \"off\", // `unicorn/prefer-date-now` covers this\n \"e18e/prefer-exponentiation-operator\": \"off\", // `prefer-exponentiation-operator` covers this\n \"e18e/prefer-flatmap-over-map-flat\": \"off\", // `unicorn/prefer-array-flat-map` covers this\n \"e18e/prefer-includes\": \"off\", // `unicorn/prefer-includes` covers this\n \"e18e/prefer-nullish-coalescing\": \"off\", // `typescript/prefer-nullish-coalescing` covers this\n \"e18e/prefer-object-has-own\": \"off\", // `prefer-object-has-own` covers this\n \"e18e/prefer-slice-over-split-index\": \"off\",\n \"e18e/prefer-spread-syntax\": \"off\", // `unicorn/prefer-spread` and `prefer-object-spread` cover this\n },\n },\n hono: {\n enabled: dependencies.has(\"hono\"),\n package: \"eslint-plugin-hono\",\n pluginRules: honoPlugin.rules,\n rules: {\n \"hono/no-process-env\": \"off\", // tools and tests legitimately read the raw environment\n },\n },\n \"react-web-api\": {\n enabled: dependencies.has(\"react\"),\n package: \"eslint-plugin-react-web-api\",\n pluginRules: reactWebApiPlugin.rules,\n },\n \"react-you-might-not-need-an-effect\": {\n enabled: dependencies.has(\"react\"),\n package: \"eslint-plugin-react-you-might-not-need-an-effect\",\n pluginRules: reactEffectPlugin.rules,\n rules: {\n \"react-you-might-not-need-an-effect/no-adjust-state-on-prop-change\": \"off\", // `react/set-state-in-effect` covers this\n \"react-you-might-not-need-an-effect/no-chain-state-updates\": \"off\", // `react/set-state-in-effect` covers this\n \"react-you-might-not-need-an-effect/no-derived-state\": \"off\", // `react/set-state-in-effect` covers this\n \"react-you-might-not-need-an-effect/no-initialize-state\": \"off\", // `react/set-state-in-effect` covers this\n \"react-you-might-not-need-an-effect/no-reset-all-state-on-prop-change\": \"off\", // `react/set-state-in-effect` covers this\n },\n },\n regexp: {\n package: \"eslint-plugin-regexp\",\n pluginRules: regexpPluginRules,\n rules: {\n \"regexp/letter-case\": [\"error\", { hexadecimalEscape: \"uppercase\", unicodeEscape: \"uppercase\" }], // match `unicorn/escape-case`\n \"regexp/no-control-character\": \"off\", // `no-control-regex` covers this\n \"regexp/no-empty-character-class\": \"off\", // `no-empty-character-class` covers this\n \"regexp/no-invalid-regexp\": \"off\", // `no-invalid-regexp` covers this\n \"regexp/no-super-linear-move\": \"off\",\n \"regexp/no-useless-escape\": \"off\", // `no-useless-escape` covers this\n \"regexp/prefer-named-capture-group\": \"off\", // `prefer-named-capture-group` covers this\n \"regexp/require-unicode-regexp\": \"off\", // `require-unicode-regexp` covers this\n \"regexp/require-unicode-sets-regexp\": \"off\", // `require-unicode-regexp` covers this\n \"regexp/sort-alternatives\": \"off\",\n },\n },\n tailwindcss: {\n // Load the Tailwind plugin only with a stylesheet because it reports every class string without one.\n enabled: Boolean(tailwindStylesheet),\n package: \"oxlint-tailwindcss\",\n pluginRules: tailwindcssPlugin.rules,\n rules: {\n \"tailwindcss/enforce-consistent-line-wrapping\": \"off\", // oxfmt handles line width\n \"tailwindcss/enforce-logical\": \"off\", // conflicts with `tailwindcss/enforce-physical`\n \"tailwindcss/enforce-sort-order\": \"off\", // oxfmt sorts classes\n \"tailwindcss/max-class-count\": \"off\",\n },\n // Keep `entryPoint` relative because the plugin resolves it against the directory of the project's oxlint config.\n settings: { tailwindcss: { entryPoint: tailwindStylesheet } },\n },\n}\n\nconst nativeConfig = {\n options: {\n reportUnusedDisableDirectives: \"error\",\n typeAware: true,\n typeCheck: true,\n },\n\n categories: {\n correctness: \"error\",\n nursery: \"error\",\n pedantic: \"error\",\n perf: \"error\",\n restriction: \"error\",\n style: \"error\",\n suspicious: \"error\",\n },\n\n plugins: [\n \"eslint\",\n \"react\",\n \"unicorn\",\n \"typescript\",\n \"oxc\",\n \"import\",\n \"jsdoc\",\n \"vitest\",\n \"jsx-a11y\",\n \"react-perf\",\n \"promise\",\n \"node\",\n ],\n\n overrides: [\n {\n files: [\n \".release-it.ts\",\n \"astro.config.ts\",\n \"commitlint.config.ts\",\n \"knip.ts\",\n \"oxfmt.config.ts\",\n \"oxlint.config.ts\",\n \"prisma.config.ts\",\n \"tsdown.config.ts\",\n ],\n rules: {\n \"import/no-default-export\": \"off\",\n },\n },\n {\n files: [\"bask.ts\"],\n rules: {\n \"clean-modules/require-direct-exports\": \"off\",\n \"import/export\": \"off\",\n },\n },\n {\n files: [\".release-it.ts\"],\n rules: {\n \"no-template-curly-in-string\": \"off\",\n },\n },\n {\n files: [\"**/*.tsx\"],\n rules: {\n \"func-style\": [\"error\", \"declaration\", { allowArrowFunctions: true }],\n },\n },\n ],\n\n rules: {\n /* Modified rules */\n\n curly: [\"error\", \"multi-or-nest\"],\n \"func-style\": [\"error\", \"expression\"],\n \"require-unicode-regexp\": [\"error\", { requireFlag: \"v\" }],\n\n \"react/function-component-definition\": [\n \"error\",\n { namedComponents: \"function-declaration\", unnamedComponents: \"arrow-function\" },\n ],\n \"react/jsx-curly-brace-presence\": [\"error\", { children: \"never\", propElementValues: \"always\", props: \"never\" }],\n\n \"unicorn/filename-case\": [\n \"error\",\n {\n cases: { kebabCase: true, pascalCase: true },\n },\n ],\n \"unicorn/no-useless-undefined\": [\"error\", { checkArguments: false }],\n\n /* Disabled rules */\n\n \"capitalized-comments\": \"off\",\n \"id-length\": \"off\",\n \"init-declarations\": \"off\",\n \"max-classes-per-file\": \"off\",\n \"max-lines\": \"off\",\n \"max-lines-per-function\": \"off\",\n \"max-statements\": \"off\",\n \"no-console\": \"off\",\n \"no-continue\": \"off\",\n \"no-duplicate-imports\": \"off\",\n \"no-inline-comments\": \"off\",\n \"no-magic-numbers\": \"off\",\n \"no-plusplus\": \"off\",\n \"no-regex-spaces\": \"off\", // `regexp/prefer-quantifier` covers this\n \"no-ternary\": \"off\",\n \"no-undef\": \"off\",\n \"no-undefined\": \"off\",\n \"no-useless-return\": \"off\",\n \"no-void\": \"off\",\n \"one-var\": \"off\",\n \"require-await\": \"off\",\n \"sort-imports\": \"off\",\n \"sort-keys\": \"off\",\n\n \"import/exports-last\": \"off\",\n \"import/group-exports\": \"off\",\n \"import/max-dependencies\": \"off\",\n \"import/no-named-export\": \"off\",\n \"import/no-nodejs-modules\": \"off\",\n \"import/no-unassigned-import\": \"off\",\n \"import/prefer-default-export\": \"off\",\n\n \"jsdoc/require-param\": \"off\",\n \"jsdoc/require-returns\": \"off\",\n\n \"node/callback-return\": \"off\",\n \"node/no-process-env\": \"off\", // tools and tests legitimately read the raw environment\n \"node/no-sync\": \"off\",\n \"node/no-top-level-await\": \"off\",\n\n \"oxc/no-async-await\": \"off\",\n \"oxc/no-optional-chaining\": \"off\",\n \"oxc/no-rest-spread-properties\": \"off\",\n\n \"react/exhaustive-effect-dependencies\": \"off\", // `react/exhaustive-deps` covers this\n \"react/forbid-component-props\": \"off\",\n \"react/hooks\": \"off\", // `react/rules-of-hooks` covers this\n \"react/invariant\": \"off\",\n \"react/jsx-filename-extension\": \"off\",\n \"react/jsx-max-depth\": \"off\",\n \"react/jsx-no-literals\": \"off\",\n \"react/memo-dependencies\": \"off\", // `react/exhaustive-deps` covers this\n \"react/no-deriving-state-in-effects\": \"off\", // `react/set-state-in-effect` covers this\n \"react/react-in-jsx-scope\": \"off\",\n \"react/rule-suppression\": \"off\",\n \"react/todo\": \"off\",\n\n \"typescript/consistent-return\": \"off\",\n \"typescript/explicit-function-return-type\": \"off\",\n \"typescript/explicit-module-boundary-types\": \"off\",\n \"typescript/prefer-readonly-parameter-types\": \"off\",\n \"typescript/strict-boolean-expressions\": \"off\",\n\n \"unicorn/no-array-callback-reference\": \"off\",\n \"unicorn/no-array-method-this-argument\": \"off\",\n \"unicorn/no-await-expression-member\": \"off\",\n \"unicorn/no-process-exit\": \"off\",\n \"unicorn/number-literal-case\": \"off\",\n \"unicorn/switch-case-braces\": \"off\",\n\n \"vitest/no-hooks\": \"off\",\n \"vitest/no-importing-vitest-globals\": \"off\",\n \"vitest/prefer-describe-function-title\": \"off\",\n \"vitest/prefer-expect-assertions\": \"off\",\n \"vitest/prefer-importing-vitest-globals\": \"off\",\n \"vitest/prefer-lowercase-title\": \"off\",\n \"vitest/prefer-to-be-falsy\": \"off\",\n \"vitest/prefer-to-be-truthy\": \"off\",\n \"vitest/require-hook\": \"off\", // reenable when false positives are fixed?\n \"vitest/require-test-timeout\": \"off\",\n },\n} as const satisfies OxlintConfig\n\nconst enabledPluginEntries = Object.entries(plugins).filter(([, plugin]) => plugin.enabled ?? true)\nconst enabledPlugins = enabledPluginEntries.map(([, plugin]) => plugin)\n// Resolve JS plugins to absolute paths so consumers load them from this package's own deps.\nconst resolvedPluginPackages = enabledPlugins.map((plugin) => resolvePackagePath(plugin.package))\nconst pluginOverrides = enabledPlugins.flatMap((plugin) => plugin.overrides ?? [])\nconst pluginSettings = Object.fromEntries(enabledPlugins.flatMap((plugin) => Object.entries(plugin.settings ?? {})))\n\n/** Lists a plugin's rules as entries */\nconst toPluginRuleEntries = ([name, { pluginRules = {}, rules }]: [string, PluginPart]) => {\n const defaultRules = setAllPluginRules(name, pluginRules, \"error\")\n const pluginRuleEntries = Object.entries({ ...defaultRules, ...rules })\n return pluginRuleEntries\n}\n\nconst resolvedPluginRules = Object.fromEntries(enabledPluginEntries.flatMap(toPluginRuleEntries))\n\nconst baseConfig = {\n ...nativeConfig,\n jsPlugins: resolvedPluginPackages,\n overrides: [...nativeConfig.overrides, ...pluginOverrides],\n rules: {\n ...resolvedPluginRules,\n ...nativeConfig.rules,\n },\n settings: pluginSettings,\n} satisfies OxlintConfig\n\nexport const oxlintConfig = createMergeConfigFn<OxlintConfig, typeof baseConfig>(baseConfig)\n"],"mappings":";;;;;;;;;;;;;AAeA,MAAM,qBAAqB,MAAc,OAAgC,aACvE,OAAO,YAAY,OAAO,KAAK,KAAK,CAAC,CAAC,KAAK,SAAS,CAAC,GAAG,KAAK,GAAG,QAAQ,QAAQ,CAAU,CAAC;AAgB7F,MAAM,EAAE,cAAc,YAAY,uBAAuB;AACzD,MAAM,qBAAqB,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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,GAAG;CAAM,CAC9C;AACzB;AAEA,MAAM,sBAAsB,OAAO,YAAY,qBAAqB,QAAQ,mBAAmB,CAAC;AAEhG,MAAM,aAAa;CACjB,GAAG;CACH,WAAW;CACX,WAAW,CAAC,GAAG,aAAa,WAAW,GAAG,eAAe;CACzD,OAAO;EACL,GAAG;EACH,GAAG,aAAa;CAClB;CACA,UAAU;AACZ;AAEA,MAAa,eAAe,oBAAqD,UAAU"}
|
|
1
|
+
{"version":3,"file":"oxlint.base.js","names":["directiveCommentsPluginRules","regexpPluginRules"],"sources":["../../src/configs/oxlint.base.ts"],"sourcesContent":["import cleanModulesPlugin from \"@adamhl8/eslint-plugin-clean-modules\"\nimport e18ePlugin from \"@e18e/eslint-plugin\"\nimport bunismsPlugin from \"eslint-plugin-bunisms\"\nimport honoPlugin from \"eslint-plugin-hono\"\nimport reactWebApiPlugin from \"eslint-plugin-react-web-api\"\nimport reactEffectPlugin from \"eslint-plugin-react-you-might-not-need-an-effect\"\nimport { rules as regexpPluginRules } from \"eslint-plugin-regexp\"\nimport type { DummyRule, OxlintConfig, OxlintOverride } from \"oxlint\"\nimport { rules as directiveCommentsPluginRules } from \"oxlint-plugin-directive-comments\"\nimport tailwindcssPlugin from \"oxlint-tailwindcss\"\n\nimport { createMergeConfigFn } from \"#merge-config/merge-config.ts\"\nimport { readProjectPackageJson, resolvePackagePath, resolveProjectTailwind } from \"#utils.ts\"\n\n/** Sets every rule in a JS plugin to `severity`, because `categories` doesn't apply to JS plugins. */\nconst setAllPluginRules = (name: string, rules: Record<string, unknown>, severity: \"error\" | \"off\") =>\n Object.fromEntries(Object.keys(rules).map((rule) => [`${name}/${rule}`, severity] as const))\n\n// Type plugin rules with oxlint's generic `DummyRule` because its per-rule config types aren't exported, which breaks declaration emit.\ntype PluginRules = Record<string, DummyRule>\n\n/** A JS plugin and the slice of oxlint config that goes with it. Each one is merged into the base config. */\ninterface PluginPart extends Omit<OxlintConfig, \"jsPlugins\" | \"overrides\" | \"rules\"> {\n overrides?: (Omit<OxlintOverride, \"rules\"> & { rules?: PluginRules })[]\n rules?: PluginRules\n /** Loads the plugin only when true. Defaults to true. */\n enabled?: boolean\n package: string\n /** The plugin's rule definitions, used to set every rule to \"error\". The part's own `rules` then take precedence. */\n pluginRules: Record<string, unknown> | undefined\n}\n\nconst { dependencies, engines } = readProjectPackageJson()\nconst tailwindStylesheet = resolveProjectTailwind()\n\n// Key each part by the rule namespace its plugin registers.\nconst plugins: Record<string, PluginPart> = {\n bunisms: {\n overrides: [\n {\n excludeFiles: [\"src/**/__tests__/**\", \"src/**/*.test.{ts,tsx}\", \"src/**/test-setup.ts\", \"src/**/test-utils.ts\"],\n // Turn off Bun suggestions in Node runtime code. Tests and tooling still run on Bun.\n files: engines.has(\"node\") ? [\"src/**\"] : [],\n rules: setAllPluginRules(\"bunisms\", bunismsPlugin.rules, \"off\"),\n },\n ],\n package: \"eslint-plugin-bunisms\",\n pluginRules: bunismsPlugin.rules,\n rules: {\n \"bunisms/prefer-mock-restore-in-after-each\": \"off\", // `test-setup.ts` preloads restore mocks globally\n },\n },\n \"clean-modules\": {\n package: \"@adamhl8/eslint-plugin-clean-modules\",\n pluginRules: cleanModulesPlugin.rules,\n },\n \"directive-comments\": {\n package: \"oxlint-plugin-directive-comments\",\n pluginRules: directiveCommentsPluginRules,\n rules: {\n \"directive-comments/disable-enable-pair\": [\"error\", { allowWholeFile: true }],\n \"directive-comments/no-use\": \"off\", // bans every directive comment\n },\n },\n e18e: {\n package: \"@e18e/eslint-plugin\",\n pluginRules: e18ePlugin.rules,\n rules: {\n \"e18e/no-indexof-equality\": \"off\", // needs type information, which JS plugins don't get\n \"e18e/no-spread-in-reduce\": \"off\", // `oxc/no-accumulating-spread` covers this\n \"e18e/prefer-array-at\": \"off\", // `unicorn/prefer-at` covers this\n \"e18e/prefer-array-some\": \"off\", // `unicorn/prefer-array-some` covers this\n \"e18e/prefer-array-to-reversed\": \"off\", // `unicorn/no-array-reverse` covers this\n \"e18e/prefer-array-to-sorted\": \"off\", // `unicorn/no-array-sort` covers this\n \"e18e/prefer-date-now\": \"off\", // `unicorn/prefer-date-now` covers this\n \"e18e/prefer-exponentiation-operator\": \"off\", // `prefer-exponentiation-operator` covers this\n \"e18e/prefer-flatmap-over-map-flat\": \"off\", // `unicorn/prefer-array-flat-map` covers this\n \"e18e/prefer-includes\": \"off\", // `unicorn/prefer-includes` covers this\n \"e18e/prefer-nullish-coalescing\": \"off\", // `typescript/prefer-nullish-coalescing` covers this\n \"e18e/prefer-object-has-own\": \"off\", // `prefer-object-has-own` covers this\n \"e18e/prefer-slice-over-split-index\": \"off\",\n \"e18e/prefer-spread-syntax\": \"off\", // `unicorn/prefer-spread` and `prefer-object-spread` cover this\n },\n },\n hono: {\n enabled: dependencies.has(\"hono\"),\n package: \"eslint-plugin-hono\",\n pluginRules: honoPlugin.rules,\n rules: {\n \"hono/no-process-env\": \"off\", // tools and tests legitimately read the raw environment\n },\n },\n \"react-web-api\": {\n enabled: dependencies.has(\"react\"),\n package: \"eslint-plugin-react-web-api\",\n pluginRules: reactWebApiPlugin.rules,\n },\n \"react-you-might-not-need-an-effect\": {\n enabled: dependencies.has(\"react\"),\n package: \"eslint-plugin-react-you-might-not-need-an-effect\",\n pluginRules: reactEffectPlugin.rules,\n rules: {\n \"react-you-might-not-need-an-effect/no-adjust-state-on-prop-change\": \"off\", // `react/set-state-in-effect` covers this\n \"react-you-might-not-need-an-effect/no-chain-state-updates\": \"off\", // `react/set-state-in-effect` covers this\n \"react-you-might-not-need-an-effect/no-derived-state\": \"off\", // `react/set-state-in-effect` covers this\n \"react-you-might-not-need-an-effect/no-initialize-state\": \"off\", // `react/set-state-in-effect` covers this\n \"react-you-might-not-need-an-effect/no-reset-all-state-on-prop-change\": \"off\", // `react/set-state-in-effect` covers this\n },\n },\n regexp: {\n package: \"eslint-plugin-regexp\",\n pluginRules: regexpPluginRules,\n rules: {\n \"regexp/letter-case\": [\"error\", { hexadecimalEscape: \"uppercase\", unicodeEscape: \"uppercase\" }], // match `unicorn/escape-case`\n \"regexp/no-control-character\": \"off\", // `no-control-regex` covers this\n \"regexp/no-empty-character-class\": \"off\", // `no-empty-character-class` covers this\n \"regexp/no-invalid-regexp\": \"off\", // `no-invalid-regexp` covers this\n \"regexp/no-super-linear-move\": \"off\",\n \"regexp/no-useless-escape\": \"off\", // `no-useless-escape` covers this\n \"regexp/prefer-named-capture-group\": \"off\", // `prefer-named-capture-group` covers this\n \"regexp/require-unicode-regexp\": \"off\", // `require-unicode-regexp` covers this\n \"regexp/require-unicode-sets-regexp\": \"off\", // `require-unicode-regexp` covers this\n \"regexp/sort-alternatives\": \"off\",\n },\n },\n tailwindcss: {\n // Load the Tailwind plugin only with a stylesheet because it reports every class string without one.\n enabled: Boolean(tailwindStylesheet),\n package: \"oxlint-tailwindcss\",\n pluginRules: tailwindcssPlugin.rules,\n rules: {\n \"tailwindcss/enforce-consistent-line-wrapping\": \"off\", // oxfmt handles line width\n \"tailwindcss/enforce-logical\": \"off\", // conflicts with `tailwindcss/enforce-physical`\n \"tailwindcss/enforce-sort-order\": \"off\", // oxfmt sorts classes\n \"tailwindcss/max-class-count\": \"off\",\n },\n // Keep `entryPoint` relative because the plugin resolves it against the directory of the project's oxlint config.\n settings: { tailwindcss: { entryPoint: tailwindStylesheet } },\n },\n}\n\nconst nativeConfig = {\n options: {\n reportUnusedDisableDirectives: \"error\",\n typeAware: true,\n typeCheck: true,\n },\n\n categories: {\n correctness: \"error\",\n nursery: \"error\",\n pedantic: \"error\",\n perf: \"error\",\n restriction: \"error\",\n style: \"error\",\n suspicious: \"error\",\n },\n\n plugins: [\n \"eslint\",\n \"react\",\n \"unicorn\",\n \"typescript\",\n \"oxc\",\n \"import\",\n \"jsdoc\",\n \"vitest\",\n \"jsx-a11y\",\n \"react-perf\",\n \"promise\",\n \"node\",\n ],\n\n overrides: [\n {\n files: [\n \".release-it.ts\",\n \"astro.config.ts\",\n \"commitlint.config.ts\",\n \"knip.ts\",\n \"oxfmt.config.ts\",\n \"oxlint.config.ts\",\n \"prisma.config.ts\",\n \"tsdown.config.ts\",\n ],\n rules: {\n \"import/no-default-export\": \"off\",\n },\n },\n {\n files: [\"bask.ts\"],\n rules: {\n \"clean-modules/require-direct-exports\": \"off\",\n \"import/export\": \"off\",\n },\n },\n {\n files: [\".release-it.ts\"],\n rules: {\n \"no-template-curly-in-string\": \"off\",\n },\n },\n {\n files: [\"**/*.tsx\"],\n rules: {\n \"func-style\": [\"error\", \"declaration\", { allowArrowFunctions: true }],\n },\n },\n {\n files: [\"**/fixtures/**\", \"**/fixture/**\"],\n rules: {\n \"clean-modules/require-import-extensions\": \"off\",\n \"clean-modules/require-subpath-imports\": \"off\",\n \"import/no-default-export\": \"off\",\n },\n },\n ],\n\n rules: {\n /* Modified rules */\n\n curly: [\"error\", \"multi-or-nest\"],\n \"func-style\": [\"error\", \"expression\"],\n \"require-unicode-regexp\": [\"error\", { requireFlag: \"v\" }],\n\n \"react/function-component-definition\": [\n \"error\",\n { namedComponents: \"function-declaration\", unnamedComponents: \"arrow-function\" },\n ],\n \"react/jsx-curly-brace-presence\": [\"error\", { children: \"never\", propElementValues: \"always\", props: \"never\" }],\n\n \"unicorn/filename-case\": [\n \"error\",\n {\n cases: { kebabCase: true, pascalCase: true },\n },\n ],\n \"unicorn/no-useless-undefined\": [\"error\", { checkArguments: false }],\n\n /* Disabled rules */\n\n \"capitalized-comments\": \"off\",\n \"id-length\": \"off\",\n \"init-declarations\": \"off\",\n \"max-classes-per-file\": \"off\",\n \"max-lines\": \"off\",\n \"max-lines-per-function\": \"off\",\n \"max-statements\": \"off\",\n \"no-console\": \"off\",\n \"no-continue\": \"off\",\n \"no-duplicate-imports\": \"off\",\n \"no-inline-comments\": \"off\",\n \"no-magic-numbers\": \"off\",\n \"no-plusplus\": \"off\",\n \"no-regex-spaces\": \"off\", // `regexp/prefer-quantifier` covers this\n \"no-ternary\": \"off\",\n \"no-undef\": \"off\",\n \"no-undefined\": \"off\",\n \"no-useless-return\": \"off\",\n \"no-void\": \"off\",\n \"one-var\": \"off\",\n \"require-await\": \"off\",\n \"sort-imports\": \"off\",\n \"sort-keys\": \"off\",\n\n \"import/exports-last\": \"off\",\n \"import/group-exports\": \"off\",\n \"import/max-dependencies\": \"off\",\n \"import/no-named-export\": \"off\",\n \"import/no-nodejs-modules\": \"off\",\n \"import/no-unassigned-import\": \"off\",\n \"import/prefer-default-export\": \"off\",\n\n \"jsdoc/require-param\": \"off\",\n \"jsdoc/require-returns\": \"off\",\n\n \"node/callback-return\": \"off\",\n \"node/no-process-env\": \"off\", // tools and tests legitimately read the raw environment\n \"node/no-sync\": \"off\",\n \"node/no-top-level-await\": \"off\",\n\n \"oxc/no-async-await\": \"off\",\n \"oxc/no-optional-chaining\": \"off\",\n \"oxc/no-rest-spread-properties\": \"off\",\n\n \"react/exhaustive-effect-dependencies\": \"off\", // `react/exhaustive-deps` covers this\n \"react/forbid-component-props\": \"off\",\n \"react/hooks\": \"off\", // `react/rules-of-hooks` covers this\n \"react/invariant\": \"off\",\n \"react/jsx-filename-extension\": \"off\",\n \"react/jsx-max-depth\": \"off\",\n \"react/jsx-no-literals\": \"off\",\n \"react/memo-dependencies\": \"off\", // `react/exhaustive-deps` covers this\n \"react/no-deriving-state-in-effects\": \"off\", // `react/set-state-in-effect` covers this\n \"react/react-in-jsx-scope\": \"off\",\n \"react/rule-suppression\": \"off\",\n \"react/todo\": \"off\",\n\n \"typescript/consistent-return\": \"off\",\n \"typescript/explicit-function-return-type\": \"off\",\n \"typescript/explicit-module-boundary-types\": \"off\",\n \"typescript/prefer-readonly-parameter-types\": \"off\",\n \"typescript/strict-boolean-expressions\": \"off\",\n\n \"unicorn/no-array-callback-reference\": \"off\",\n \"unicorn/no-array-method-this-argument\": \"off\",\n \"unicorn/no-await-expression-member\": \"off\",\n \"unicorn/no-process-exit\": \"off\",\n \"unicorn/number-literal-case\": \"off\",\n \"unicorn/switch-case-braces\": \"off\",\n\n \"vitest/no-hooks\": \"off\",\n \"vitest/no-importing-vitest-globals\": \"off\",\n \"vitest/prefer-describe-function-title\": \"off\",\n \"vitest/prefer-expect-assertions\": \"off\",\n \"vitest/prefer-importing-vitest-globals\": \"off\",\n \"vitest/prefer-lowercase-title\": \"off\",\n \"vitest/prefer-to-be-falsy\": \"off\",\n \"vitest/prefer-to-be-truthy\": \"off\",\n \"vitest/require-hook\": \"off\", // reenable when false positives are fixed?\n \"vitest/require-test-timeout\": \"off\",\n },\n} as const satisfies OxlintConfig\n\nconst enabledPluginEntries = Object.entries(plugins).filter(([, plugin]) => plugin.enabled ?? true)\nconst enabledPlugins = enabledPluginEntries.map(([, plugin]) => plugin)\n// Resolve JS plugins to absolute paths so consumers load them from this package's own deps.\nconst resolvedPluginPackages = enabledPlugins.map((plugin) => resolvePackagePath(plugin.package))\nconst pluginOverrides = enabledPlugins.flatMap((plugin) => plugin.overrides ?? [])\nconst pluginSettings = Object.fromEntries(enabledPlugins.flatMap((plugin) => Object.entries(plugin.settings ?? {})))\n\n/** Lists a plugin's rules as entries */\nconst toPluginRuleEntries = ([name, { pluginRules = {}, rules }]: [string, PluginPart]) => {\n const defaultRules = setAllPluginRules(name, pluginRules, \"error\")\n const pluginRuleEntries = Object.entries({ ...defaultRules, ...rules })\n return pluginRuleEntries\n}\n\nconst resolvedPluginRules = Object.fromEntries(enabledPluginEntries.flatMap(toPluginRuleEntries))\n\nconst baseConfig = {\n ...nativeConfig,\n jsPlugins: resolvedPluginPackages,\n overrides: [...nativeConfig.overrides, ...pluginOverrides],\n rules: {\n ...resolvedPluginRules,\n ...nativeConfig.rules,\n },\n settings: pluginSettings,\n} satisfies OxlintConfig\n\nexport const oxlintConfig = createMergeConfigFn<OxlintConfig, typeof baseConfig>(baseConfig)\n"],"mappings":";;;;;;;;;;;;;AAeA,MAAM,qBAAqB,MAAc,OAAgC,aACvE,OAAO,YAAY,OAAO,KAAK,KAAK,CAAC,CAAC,KAAK,SAAS,CAAC,GAAG,KAAK,GAAG,QAAQ,QAAQ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AC1C,iCAAiC;EACjC,6BAA6B;EAC7B,8BAA8B;EAC9B,uBAAuB;EACvB,+BAA+B;CACjC;AACF;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"}
|
|
@@ -3,5 +3,6 @@ import { Shell, ShellEnv, ShellOptions, ShellResult, createShell } from "./shell
|
|
|
3
3
|
import { minimalEnv } from "./shell/env.js";
|
|
4
4
|
import { CopyFixtureOptions, copyFixture } from "./fixture.js";
|
|
5
5
|
import { packPackage } from "./pack.js";
|
|
6
|
+
import { subprocessCoverageEnv } from "./subprocess-coverage/env.js";
|
|
6
7
|
import { makeTempDir } from "./temp-dir.js";
|
|
7
|
-
export { type CopyFixtureOptions, type Shell, type ShellCommand, type ShellEnv, type ShellOptions, type ShellResult, copyFixture, createShell, makeTempDir, minimalEnv, packPackage };
|
|
8
|
+
export { type CopyFixtureOptions, type Shell, type ShellCommand, type ShellEnv, type ShellOptions, type ShellResult, copyFixture, createShell, makeTempDir, minimalEnv, packPackage, subprocessCoverageEnv };
|
package/dist/test-utils/index.js
CHANGED
|
@@ -3,4 +3,5 @@ import { createShell } from "./shell/shell.js";
|
|
|
3
3
|
import { makeTempDir } from "./temp-dir.js";
|
|
4
4
|
import { copyFixture } from "./fixture.js";
|
|
5
5
|
import { packPackage } from "./pack.js";
|
|
6
|
-
|
|
6
|
+
import { subprocessCoverageEnv } from "./subprocess-coverage/env.js";
|
|
7
|
+
export { copyFixture, createShell, makeTempDir, minimalEnv, packPackage, subprocessCoverageEnv };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {}
|
|
@@ -0,0 +1,60 @@
|
|
|
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
|
+
process.once("exit", () => {
|
|
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
|
+
export {};
|
|
59
|
+
|
|
60
|
+
//# sourceMappingURL=child-preload.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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\nprocess.once(\"exit\", () => {\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"],"mappings":";;;;;;;AAaA,MAAM,iCAAiC;AAEvC,MAAM,sBAAsB,UAC1B,OAAO,UAAU,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,GAAG,aAAa,MAAM,cAAc,KAAK,IAAI,KAAK,CAAC;GACzD,MAAM,OAAO,MAAM,IAAI,KAAK,IAAI,CAAC,CAAC,KAAK;GACvC,MAAM,YAAY,MAAM,cAAc,MAAM,YAAY,IAAI;GAC5D,OAAO;IAAE,UAAU,aAAa,eAAe,MAAM,MAAM,SAAS;IAAG,QAAQ;GAAK;EACtF,CAAC;CACH;AACF,CAAC;AAED,MAAM,eAAe,UACnB,kCAAkC;AAEpC,QAAQ,KAAK,cAAc;CAEzB,MAAM,cAAsB;CAE5B,IAAI,CAAC,YAAY,WAAW,GAAG;CAC/B,GAAG,cACD,KAAK,KAAK,QAAQ,GAAG,OAAO,WAAW,EAAE,MAAM,GAC/C,KAAK,UAAU,YAAY,+BAA+B,CAC5D;AACF,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env.d.ts","names":[],"sources":["../../../src/test-utils/subprocess-coverage/env.ts"],"mappings":";;;;;qBAiBa,6BAA4B"}
|
|
@@ -0,0 +1,19 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {}
|
|
@@ -0,0 +1,32 @@
|
|
|
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 root = process.cwd();
|
|
13
|
+
const packageJson = await bun.file(path.join(root, "package.json")).json();
|
|
14
|
+
if (!hasName(packageJson)) throw new Error(`subprocess coverage needs a package name in ${root}/package.json`);
|
|
15
|
+
const rawDir = await fs.mkdtemp(path.join(os.tmpdir(), "subprocess-coverage-"));
|
|
16
|
+
const settings = {
|
|
17
|
+
rawDir,
|
|
18
|
+
root,
|
|
19
|
+
packageName: packageJson.name
|
|
20
|
+
};
|
|
21
|
+
process.env["BUN_OPTIONS"] = `--preload=${CHILD_PRELOAD}`;
|
|
22
|
+
process.env[SUBPROCESS_COVERAGE_SETTINGS_VAR] = JSON.stringify(settings);
|
|
23
|
+
afterAll(async () => {
|
|
24
|
+
await reportCoverage(rawDir, path.join(root, "coverage"));
|
|
25
|
+
await fs.rm(rawDir, {
|
|
26
|
+
recursive: true,
|
|
27
|
+
force: true
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
export {};
|
|
31
|
+
|
|
32
|
+
//# sourceMappingURL=preload.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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 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\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, path.join(root, \"coverage\"))\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,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;AAE7G,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,KAAK,KAAK,MAAM,UAAU,CAAC;CACxD,MAAM,GAAG,GAAG,QAAQ;EAAE,WAAW;EAAM,OAAO;CAAK,CAAC;AACtD,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
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
|
+
/** Merges the coverage from every process in `rawDir`, maps it back to the source, and writes a text and lcov report. */
|
|
10
|
+
const reportCoverage = async (rawDir, reportDir) => {
|
|
11
|
+
const rawFiles = await fs.readdir(rawDir);
|
|
12
|
+
if (rawFiles.length === 0) return;
|
|
13
|
+
const rawCoverages = await Promise.all(rawFiles.map(async (rawFile) => bun.file(path.join(rawDir, rawFile)).json()));
|
|
14
|
+
const coverageMap = createCoverageMap({});
|
|
15
|
+
for (const rawCoverage of rawCoverages) if (isCoverageMapData(rawCoverage)) coverageMap.merge(rawCoverage);
|
|
16
|
+
const sourceCoverageMap = await createSourceMapStore().transformCoverage(coverageMap);
|
|
17
|
+
const context = createContext({
|
|
18
|
+
dir: reportDir,
|
|
19
|
+
coverageMap: sourceCoverageMap
|
|
20
|
+
});
|
|
21
|
+
create("text").execute(context);
|
|
22
|
+
create("lcovonly").execute(context);
|
|
23
|
+
};
|
|
24
|
+
export { reportCoverage };
|
|
25
|
+
|
|
26
|
+
//# sourceMappingURL=report.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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/** Merges the coverage from every process in `rawDir`, maps it back to the source, and writes a text and lcov report. */\nexport const reportCoverage = async (rawDir: string, reportDir: 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 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;;AAG/G,MAAa,iBAAiB,OAAO,QAAgB,cAAsB;CACzE,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,MAAM,UAAU,cAAc;EAAE,KAAK;EAAW,aAAa;CAAkB,CAAC;CAChF,OAAa,MAAM,CAAC,CAAC,QAAQ,OAAO;CACpC,OAAa,UAAU,CAAC,CAAC,QAAQ,OAAO;AAC1C"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adamhl8/configs",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.3.0",
|
|
4
4
|
"description": "My shared configs for TS projects",
|
|
5
5
|
"homepage": "https://github.com/adamhl8/configs",
|
|
6
6
|
"bugs": {
|
|
@@ -48,6 +48,10 @@
|
|
|
48
48
|
"./test/preload": {
|
|
49
49
|
"types": "./dist/test-utils/preload.d.ts",
|
|
50
50
|
"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"
|
|
51
55
|
}
|
|
52
56
|
},
|
|
53
57
|
"publishConfig": {
|
|
@@ -80,6 +84,10 @@
|
|
|
80
84
|
"@arethetypeswrong/core": "^0.18.5",
|
|
81
85
|
"@commitlint/cli": "^21.2.4",
|
|
82
86
|
"@types/bun": "^1.4.4",
|
|
87
|
+
"@vitest/istanbul-lib-coverage": "^2.0.0",
|
|
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",
|
|
83
91
|
"knip": "^6.43.0",
|
|
84
92
|
"markdown-toc": "^1.2.0",
|
|
85
93
|
"oxfmt": "^0.74.0",
|
|
@@ -97,6 +105,10 @@
|
|
|
97
105
|
"@commitlint/cli": ">=21.2",
|
|
98
106
|
"@commitlint/config-conventional": ">=21.2",
|
|
99
107
|
"@tailwindcss/language-server": ">=0.16",
|
|
108
|
+
"@vitest/istanbul-lib-coverage": ">=2.0",
|
|
109
|
+
"@vitest/istanbul-lib-instrument": ">=2.0",
|
|
110
|
+
"@vitest/istanbul-lib-report": ">=2.0",
|
|
111
|
+
"@vitest/istanbul-lib-source-maps": ">=2.0",
|
|
100
112
|
"knip": ">=6.43",
|
|
101
113
|
"markdown-toc": ">=1.2",
|
|
102
114
|
"oxfmt": ">=0.74",
|
|
@@ -116,6 +128,18 @@
|
|
|
116
128
|
"@tailwindcss/language-server": {
|
|
117
129
|
"optional": true
|
|
118
130
|
},
|
|
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
|
+
},
|
|
119
143
|
"publint": {
|
|
120
144
|
"optional": true
|
|
121
145
|
},
|