Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/vite-config-oxc-parser.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@stll/oxlint-config": patch
---

The Vite publish target resolver reads the declaration helper's config with oxc-parser instead of stripping TypeScript with esbuild and parsing with acorn, and the toolchain check reads declared TypeScript API importers the same way, so `esbuild` is no longer a direct dependency. A config that exports `defineConfig(...)` through a local constant is now recognized, and a value import of `vite-plugin-dts` or `unplugin-dts` beside the helper fails even when unused.
48 changes: 45 additions & 3 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions packages/oxlint-config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,8 @@ This adapter requires consumer-installed `vite-plugin-dts` 5.1.2 and its
Unsupported versions fail explicitly.
The resolver proves a direct helper import and call in a literal plugin array;
raw declaration plugins, opaque plugin arrays, and additional emitters fail.
It reads the config with oxc-parser and ignores TypeScript-only syntax, so a
TypeScript config needs no compiler; any value import of a raw emitter fails.
Options are closed and static: include/exclude, entryRoot, pathsToAliases,
compilerOptions.declarationMap=false, strictOutput=true, and declarationOnly=false. Hooks may
emit only `.d.ts`, `.d.mts`, `.d.cts`, and their maps. Bundle and on-disk non-declaration
Expand All @@ -886,8 +888,8 @@ TypeScript import on the package's minimum supported Node release.
Packed-artifact checks run nightly, while the static contract check runs per PR.
Every packed `.js`, `.mjs`, and `.cjs` file is checked, including non-entry chunks
and executables. The actual packed manifest must match the committed contract.
Acorn 8.15.0 applies the strictest declared ECMAScript target (`es5`, `es2015`
through `es2025`); the provisioned consumer Node also parses every file with
Acorn applies the strictest declared ECMAScript target (`es5`, `es2015`
through `es2025`; oxc-parser has no per-year grammar); the provisioned consumer Node also parses every file with
`--check`, without executing artifact code. `esnext` and supported Node targets use the native consumer Node bound.
Node target identifiers follow the same grammar and compatibility rule as the
static contract; no older Node-to-ECMAScript mapping is inferred. Browser targets
Expand Down
2 changes: 1 addition & 1 deletion packages/oxlint-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
"@changesets/read": "1.0.1",
"@manypkg/get-packages": "3.1.0",
"acorn": "8.19.0",
"esbuild": "0.28.2",
"oxc-parser": "0.155.0",
"picomatch": "4.0.7",
"semver": "7.8.6",
"smol-toml": "1.9.1",
Expand Down
13 changes: 5 additions & 8 deletions packages/oxlint-config/src/entry-graph.test.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
import { expect, test } from "bun:test";
import { build } from "esbuild";
import { fileURLToPath } from "node:url";

import manifest from "../package.json";

const graphImports = async (entry: URL) => {
const result = await build({
entryPoints: [fileURLToPath(entry)],
bundle: true,
const result = await Bun.build({
entrypoints: [fileURLToPath(entry)],
packages: "external",
platform: "node",
write: false,
target: "node",
metafile: true,
treeShaking: false,
logLevel: "silent",
});
if (result.metafile === undefined)
throw new Error("Bun.build returned no metafile for the entry graph");
return new Set(
Object.values(result.metafile.inputs).flatMap(({ imports }) =>
imports.map(({ path }) => path),
Expand Down
59 changes: 59 additions & 0 deletions packages/oxlint-config/src/publish-build-target-vite.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,65 @@ export default defineConfig({ plugins: [declarations({ directory: import.meta.di
).toThrow();
});

test("declaration helper configuration reads TypeScript syntax without a type-stripping compiler", () => {
const source = `import type { UserConfig } from 'vite';
import { type PluginOption, defineConfig } from 'vite';
import { declarationOnlyDts } from '@stll/oxlint-config/declaration-only-dts';
import type { PluginOptions } from 'vite-plugin-dts';
interface Extra { value: string }
declare const injected: PluginOption;
const config: UserConfig = defineConfig<UserConfig>({
plugins: [declarationOnlyDts({ directory: import.meta.dirname!, include: ['src/**/*'] as string[] })],
} satisfies UserConfig);
type Helper = typeof declarationOnlyDts;
class Runner { run(declarationOnlyDts: string): void; run(value: string): void {} }
export default config;`;
for (const loader of ["ts", "js"] as const) {
const input =
loader === "ts"
? source
: `import { defineConfig } from 'vite';
import { declarationOnlyDts } from '@stll/oxlint-config/declaration-only-dts';
const config = defineConfig({ plugins: [declarationOnlyDts({ directory: import.meta.dirname, include: ['src/**/*'] })] });
export default config;`;
expect(
reviewedDtsConfiguration({
source: input,
directory: "/package",
loader,
}),
).toEqual({ include: ["src/**/*"] });
}
expect(
reviewedDtsConfiguration({
source: source
.replace("const config: UserConfig", "export const config: UserConfig")
.replace("export default config;", "export { config as default };"),
directory: "/package",
loader: "ts",
}),
).toEqual({ include: ["src/**/*"] });
for (const [mutation, message] of [
[
source.replace("import type { PluginOptions }", "import raw"),
"Raw declaration emitters cannot accompany the reviewed helper",
],
[
source
.replace("plugins: [", "plugins: [[")
.replace("as string[] })]", "as string[] })]]"),
"Declare exactly one direct declaration helper call",
],
] as const)
expect(() =>
reviewedDtsConfiguration({
source: mutation,
directory: "/package",
loader: "ts",
}),
).toThrow(message);
});

test("Vite native callbacks are version-profile-bound at their exact option paths", () => {
const callback = () => undefined;
for (const [name, field] of [
Expand Down
Loading
Loading