From febe5c9f3a65d6adbb927eb581195e03318ed603 Mon Sep 17 00:00:00 2001 From: Jan Kubica Date: Mon, 26 Oct 2026 21:13:45 +0100 Subject: [PATCH 1/2] feat(oxlint-config)!: emit Vite declarations with tsrs The declaration-only Vite helper runs tsrs once after the bundle is written. It reads a generated config that extends the package tsconfig and emits declarations only into build.outDir. Consumers no longer install vite-plugin-dts, unplugin-dts or TypeScript 6.0.3. Because the helper no longer wraps a third-party plugin, the hook and context guards around it are deleted. The output check that leaves non-declaration files untouched stays. Options shrink to include, exclude, entryRoot and compilerOptions.declarationMap=false. compilerOptions.paths fails the build, because declarations keep import specifiers as written. The helper loads the tsrs API from tsrs/async, its current entry point. --- .changeset/declarations-with-tsrs.md | 11 + bun.lock | 120 ------ packages/oxlint-config/README.md | 24 +- packages/oxlint-config/package.json | 4 +- .../publish-build-target-vite-dts-helper.ts | 321 ++++++++------ .../src/publish-build-target-vite-dts.test.ts | 394 +++++++----------- .../src/publish-build-target-vite-dts.ts | 344 +-------------- scripts/check-publish-artifact-profiles.ts | 120 ++---- 8 files changed, 404 insertions(+), 934 deletions(-) create mode 100644 .changeset/declarations-with-tsrs.md diff --git a/.changeset/declarations-with-tsrs.md b/.changeset/declarations-with-tsrs.md new file mode 100644 index 00000000..545ab107 --- /dev/null +++ b/.changeset/declarations-with-tsrs.md @@ -0,0 +1,11 @@ +--- +"@stll/oxlint-config": major +--- + +The `declaration-only-dts` Vite helper emits declarations with tsrs, which `@stll/oxlint-config` already depends on. Consumers no longer install `vite-plugin-dts`, `unplugin-dts` or TypeScript 6.0.3 for it, and can remove them. + +Breaking changes: + +- The helper accepts only `include`, `exclude`, `entryRoot` and `compilerOptions.declarationMap: false`. `pathsToAliases`, `strictOutput` and `declarationOnly` were vite-plugin-dts settings and are now rejected; remove them from the config. +- A package tsconfig with `compilerOptions.paths` fails the build, because declarations keep import specifiers as written. Use package imports or relative paths instead. +- Declarations are TypeScript 7's own output. Import lines keep their `type` modifiers and double quotes, and union members and inferred properties can appear in a different order. Doc comments are kept, and side-effect imports are still dropped. With `allowJs`, JavaScript inputs inside `include` now get declarations too. diff --git a/bun.lock b/bun.lock index 96933e18..8e353eb7 100644 --- a/bun.lock +++ b/bun.lock @@ -52,9 +52,7 @@ "@types/picomatch": "4.0.3", "@types/semver": "7.8.0", "oxlint": "1.93.0", - "unplugin-dts": "1.1.2", "vite": "8.3.7", - "vite-plugin-dts": "5.1.2", }, "peerDependencies": { "oxlint": ">=1.93.0 <2", @@ -217,16 +215,6 @@ "@esbuild/win32-x64": ["@esbuild/win32-x64@0.28.2", "", { "os": "win32", "cpu": "x64" }, "sha512-5ebpxr3nWMzrL/rnUI755Jkuee0bHL/Gq0WTF9lvcpv73wAp5eu8MfBUgWK9bhWvZjj7yX8etf/8tI8Ney695g=="], - "@jridgewell/gen-mapping": ["@jridgewell/gen-mapping@0.3.13", "", { "dependencies": { "@jridgewell/sourcemap-codec": "^1.5.0", "@jridgewell/trace-mapping": "^0.3.24" } }, "sha512-2kkt/7niJ6MgEPxF0bYdQ6etZaA+fQvDcLKckhy1yIQOzaoKjBBjSj63/aLVjYE3qhRt5dvM+uUyfCg6UKCBbA=="], - - "@jridgewell/remapping": ["@jridgewell/remapping@2.3.5", "", { "dependencies": { "@jridgewell/gen-mapping": "^0.3.5", "@jridgewell/trace-mapping": "^0.3.24" } }, "sha512-LI9u/+laYG4Ds1TDKSJW2YPrIlcVYOwi2fUC6xB43lueCjgxV4lffOCZCtYFiH6TNOX+tQKXx97T4IKHbhyHEQ=="], - - "@jridgewell/resolve-uri": ["@jridgewell/resolve-uri@3.1.2", "", {}, "sha512-bRISgCIjP20/tbWSPWMEi54QVPRZExkuD9lJL+UIxUKtwVJA8wW1Trb1jMs1RFXo1CBTNZ/5hpC9QvmKWdopKw=="], - - "@jridgewell/sourcemap-codec": ["@jridgewell/sourcemap-codec@1.6.0", "", {}, "sha512-T7jf+5zgsZHwNJ4lvQ7/aezbyk0nNX+zJVWpmHA7VYsEx7a7qr5Rg5IbtJFqkgze5Y2sruq1RUY8Q837Od7iFw=="], - - "@jridgewell/trace-mapping": ["@jridgewell/trace-mapping@0.3.31", "", { "dependencies": { "@jridgewell/resolve-uri": "^3.1.0", "@jridgewell/sourcemap-codec": "^1.4.14" } }, "sha512-zzNR+SdQSDJzc8joaeP8QQoCQr8NuYx2dIIytl1QeBEZHJ9uW6hebsrYgbz8hJwUQao3TWCMtmfV8Nu1twOLAw=="], - "@manypkg/find-root": ["@manypkg/find-root@3.1.0", "", { "dependencies": { "@manypkg/tools": "^2.1.0" } }, "sha512-BcSqCyKhBVZ5YkSzOiheMCV41kqAFptW6xGqYSTjkVTl9XQpr+pqHhwgGCOHQtjDCv7Is6EFyA14Sm5GVbVABA=="], "@manypkg/get-packages": ["@manypkg/get-packages@3.1.0", "", { "dependencies": { "@manypkg/find-root": "^3.1.0", "@manypkg/tools": "^2.1.0" } }, "sha512-0TbBVyvPrP7xGYBI/cP8UP+yl/z+HtbTttAD7FMAJgn/kXOTwh5/60TsqP9ZYY710forNfyV0N8P/IE/ujGZJg=="], @@ -395,8 +383,6 @@ "@rolldown/pluginutils": ["@rolldown/pluginutils@1.1.0", "", {}, "sha512-K+NU2HDCEem4sClgHH4ZZXwdJeNFkJo+hRk479DIwdIviAPN2hFJH1KHHwg8CxHQXvi0M5XY4deTXINfIiSG6w=="], - "@rollup/pluginutils": ["@rollup/pluginutils@5.5.1", "", { "dependencies": { "@types/estree": "^1.0.0", "estree-walker": "^2.0.2", "picomatch": "^4.0.2" }, "peerDependencies": { "rollup": "^1.20.0||^2.0.0||^3.0.0||^4.0.0" }, "optionalPeers": ["rollup"] }, "sha512-P9ZvnfouRu4MSC+ilERaw6FmZs8zqKhpHxEs4aGDGWQAMzQGXnhvCSvoNwokfNvdt7t3Y5Y4p6gStQgezeIqug=="], - "@stll/oxlint-config": ["@stll/oxlint-config@workspace:packages/oxlint-config"], "@stll/oxlint-plugin": ["@stll/oxlint-plugin@workspace:packages/oxlint-plugin"], @@ -423,62 +409,12 @@ "@tybys/wasm-util": ["@tybys/wasm-util@0.10.4", "", { "dependencies": { "tslib": "^2.4.0" } }, "sha512-W3c4gRigFS0T/Ma4qIYF3GDAc5AQdHb1yL5znJT1Zv1YaD9Kitx656wBjvr19qbiosmZT8lWDM5BEMynUqX65A=="], - "@types/estree": ["@types/estree@1.0.10", "", {}, "sha512-lTyOMnOcmRBzdCv6/4zUZCrEhV0xrqQiUZBZtVcbmLHBXKLnN8q89v/wKRF/Q0HbwVsqbIG3o5HDoFl9sduM+g=="], - "@types/node": ["@types/node@26.6.6", "", { "dependencies": { "undici-types": "~8.9.0" } }, "sha512-MzQj+8Kx3XI40OmUAE6Qoh58ZMNstNNMwn2nfd3qWsfe7nDNSqJNzes4njhz6AHwrSHOffSLwXU6yb474Q4aog=="], "@types/picomatch": ["@types/picomatch@4.0.3", "", {}, "sha512-iG0T6+nYJ9FAPmx9SsUlnwcq1ZVRuCXcVEvWnntoPlrOpwtSTKNDC9uVAxTsC3PUvJ+99n4RpAcNgBbHX3JSnQ=="], "@types/semver": ["@types/semver@7.8.0", "", {}, "sha512-1mAINjtQCXXeLkJ9ehXkwOcBpqtLxiVtKhpUf83DdRNdQKV0iXZpaHYqRr7nj+wvxuJzoAmAwXI+sCNMv1CzLQ=="], - "@typescript/typescript-aix-ppc64": ["@typescript/typescript-aix-ppc64@7.0.2", "", { "os": "aix", "cpu": "ppc64" }, "sha512-MTKKkWB7p/0E9xi1d1tHtZ5PiLkGEMIq88pK2CubZjOsLtYTLqhgIgi6zepFa+9GHZ6h05NMCkQxGKiPXMxXtQ=="], - - "@typescript/typescript-darwin-arm64": ["@typescript/typescript-darwin-arm64@7.0.2", "", { "os": "darwin", "cpu": "arm64" }, "sha512-gowzar9MwS/aRWp6f3a4KUqzRjAZjOsmGNCM6LcTgXum+dBfgsBVMN+AgvOCCbguXyick6LJhpBszxMebJ8syA=="], - - "@typescript/typescript-darwin-x64": ["@typescript/typescript-darwin-x64@7.0.2", "", { "os": "darwin", "cpu": "x64" }, "sha512-SZ9xZInqApNlNGc9s0W1VSsktYSOe9cFqNOIqmN1Gs8SmkjKZYFt017G4VwPxASInODuAdbTW7sXiFUf893RgA=="], - - "@typescript/typescript-freebsd-arm64": ["@typescript/typescript-freebsd-arm64@7.0.2", "", { "os": "freebsd", "cpu": "arm64" }, "sha512-W5NH4y/J0plIIS5b2xvTEkU7JFxyqdMAOgf+Ilhl0vHQXKO5dZoxd+C/jEtq56c4F3wk71RB4BMRQ2XdI+bwYQ=="], - - "@typescript/typescript-freebsd-x64": ["@typescript/typescript-freebsd-x64@7.0.2", "", { "os": "freebsd", "cpu": "x64" }, "sha512-UMGDx5sTpzNw3WiPebH7l90IWfJggEd+egHt/q6p7/Cm3zqoV7VxkGXt+3DxPIw8CcmvAB0j3sVVfbhX+M4Tpw=="], - - "@typescript/typescript-linux-arm": ["@typescript/typescript-linux-arm@7.0.2", "", { "os": "linux", "cpu": "arm" }, "sha512-gffT3xPz9sR7j/YJExkyPntrI0P2EP9XbOyWzth2/Gs0RstK+90RBcO0ncXoXy/beYll1SXw846Nf2zdnEz0QQ=="], - - "@typescript/typescript-linux-arm64": ["@typescript/typescript-linux-arm64@7.0.2", "", { "os": "linux", "cpu": "arm64" }, "sha512-Qh4eU4/y3yDjnfjjyPYihMj5/ODIlmt+Bzu17OI+fiSRDW57QmU5SiN63exPRNJPKUzcc1INa1NXdrJ+MqHjUQ=="], - - "@typescript/typescript-linux-loong64": ["@typescript/typescript-linux-loong64@7.0.2", "", { "os": "linux", "cpu": "none" }, "sha512-uEHck9i8hoAzXPiYRib1O7miOnz23SxIeVl6F4LXox+qov1K35jHcEW6VHKvZI+pyvl7fZEP4MCU5LYvIq1GuQ=="], - - "@typescript/typescript-linux-mips64el": ["@typescript/typescript-linux-mips64el@7.0.2", "", { "os": "linux", "cpu": "none" }, "sha512-R4KvAMnE43W5Qeqb0Ly56O3mWMWIAgsMyz36DCaycd5nbg/9kzm0liw3JocfRqyJY0KPmzFjbswozXyW0DnIYA=="], - - "@typescript/typescript-linux-ppc64": ["@typescript/typescript-linux-ppc64@7.0.2", "", { "os": "linux", "cpu": "ppc64" }, "sha512-DORx5b3sd/4S7eayxm4FQv+A7CrkUIGRaHiwI8oiHTAI1fAPWhF4J0vAlkC8biAlHSVVwxMQ3tjZ2/DVbnQiiA=="], - - "@typescript/typescript-linux-riscv64": ["@typescript/typescript-linux-riscv64@7.0.2", "", { "os": "linux", "cpu": "none" }, "sha512-wf0jqEDOjrPRnKwYRyyJDRo11KMbvMFrU+q4zqKyChODBzvlkbhNQfKvLxQCcwTpdDaXSHZTVuh0JoCrKCUMHQ=="], - - "@typescript/typescript-linux-s390x": ["@typescript/typescript-linux-s390x@7.0.2", "", { "os": "linux", "cpu": "s390x" }, "sha512-IkwJc3L7yhytWd/ewjyxNDfOmswCm9GWMJT/ue/dU4aZNbwZeYAetq42VyLmsmSjvoX7z74X6ZaYCtzAr0EuGw=="], - - "@typescript/typescript-linux-x64": ["@typescript/typescript-linux-x64@7.0.2", "", { "os": "linux", "cpu": "x64" }, "sha512-EYdf2cNg7rgCWJnxCdJ+F3V39O8ihb37eHAu1LK8oAFizgTQbPOK7zHHXbPt8rX24COqODXeI3sIf0fCXG7H/A=="], - - "@typescript/typescript-netbsd-arm64": ["@typescript/typescript-netbsd-arm64@7.0.2", "", { "os": "none", "cpu": "arm64" }, "sha512-+polYF4MF04aPpO5FTkHran9yUQDSXqy5GiSDKpsll5jy3l3+g9QLhpf39T+ePtefhXLOGrLl0QIjkQP6VnelA=="], - - "@typescript/typescript-netbsd-x64": ["@typescript/typescript-netbsd-x64@7.0.2", "", { "os": "none", "cpu": "x64" }, "sha512-8YIT0EHM/3dq10ZOVF/A7pc/YSMtbcecct4rWtexrnSCHOPcpC2KTLXfTCR6vDpnSiY12heNb1GiN/wu+T/FyA=="], - - "@typescript/typescript-openbsd-arm64": ["@typescript/typescript-openbsd-arm64@7.0.2", "", { "os": "openbsd", "cpu": "arm64" }, "sha512-APT8+ClYnuYm1u9+kgGXoMj2VzWzcymwh2gNSQVySHfkRDGOTVkoWLjCmOQSaO+PoqQ57B0flRp9SA+7GnnkzQ=="], - - "@typescript/typescript-openbsd-x64": ["@typescript/typescript-openbsd-x64@7.0.2", "", { "os": "openbsd", "cpu": "x64" }, "sha512-yX7s+Q0Dln0Dt9tEzZsAjXXR/+ytBM7AlglaqyeMPxQszJ1JhlJdZ6jLA+IzldHtflX81em7lDao1xXu+aRRkg=="], - - "@typescript/typescript-sunos-x64": ["@typescript/typescript-sunos-x64@7.0.2", "", { "os": "sunos", "cpu": "x64" }, "sha512-dLJDGaLZ1D4HPQn62u1n8mBDkJREwMsAkCdkwd4Ieqw+x3TUyTsqY0YiBCtE6H6OzzgGk3iuZ3vFWRS+E8/d1g=="], - - "@typescript/typescript-win32-arm64": ["@typescript/typescript-win32-arm64@7.0.2", "", { "os": "win32", "cpu": "arm64" }, "sha512-Gyl1Vy6OsWesLzmq+EP0Fb7b4Nid5232AvcA2SFcdYreldpNtYFFofPjnt62y9hQy7VTaZp65ICJjuAQRaVcIQ=="], - - "@typescript/typescript-win32-x64": ["@typescript/typescript-win32-x64@7.0.2", "", { "os": "win32", "cpu": "x64" }, "sha512-0BQ3HkAHHlKLSp1qRvf3SUhGpGsDuhB/jgFw75guyqbxJqEaS0Cw/VFO8i2nHglJUzQCRtMMR/IBAKE3ETMC4g=="], - - "@volar/language-core": ["@volar/language-core@2.4.31", "", { "dependencies": { "@volar/source-map": "2.4.31" } }, "sha512-OM+OZfynHa1/4WlC8klqvwTQVmhYUZuwpAKdfl/rlvK8jaIozMD5qwXsOkxcRJA2tC+TEFsG1K81lNP4s/IAzQ=="], - - "@volar/language-service": ["@volar/language-service@2.4.31", "", { "dependencies": { "@volar/language-core": "2.4.31", "vscode-languageserver-protocol": "^3.17.5", "vscode-languageserver-textdocument": "^1.0.11", "vscode-uri": "^3.0.8" }, "peerDependencies": { "typescript": "<7" }, "optionalPeers": ["typescript"] }, "sha512-LM9HFsBVhHZ7RbFUZK9P23FvamK8XCDcN0kNgOTts02wVgnygo3ReLbmBmUZ3GuYnrYn6HHoQvqk/eHIzzTnrg=="], - - "@volar/source-map": ["@volar/source-map@2.4.31", "", {}, "sha512-odi31S3mKm57aO7Pd5P624FmGIB49U4lUPnYRUKvCDa8WZy5N5Yb+GMp2WJNaeIr4+q0ijNpuHsJLrfEiWvHtA=="], - - "@volar/typescript": ["@volar/typescript@2.4.31", "", { "dependencies": { "@volar/language-core": "2.4.31", "@volar/language-service": "2.4.31", "path-browserify": "^1.0.1", "vscode-uri": "^3.0.8" }, "peerDependencies": { "typescript": "<7" }, "optionalPeers": ["typescript"] }, "sha512-OBHLLAi03AmaRWqzytdFhgtW2B3HM+2/vXFkvnZAlEKltalUTyu+No7g9aZx7e9efrDLOtHsd/3PgCHSfgVJ/Q=="], - "@yuku-toolchain/darwin-arm64": ["@yuku-toolchain/darwin-arm64@0.27.0", "", { "os": "darwin", "cpu": "arm64" }, "sha512-A3v83rNyHWlnJeeMBsWggZ+RZDP2BEMHIiMk+j23LqtVch24MXwg8veflkQgZ2GtCtZOxcG+NkztnsSUS4rWEQ=="], "@yuku-toolchain/darwin-x64": ["@yuku-toolchain/darwin-x64@0.27.0", "", { "os": "darwin", "cpu": "x64" }, "sha512-u+fcqQw0uRj5irtO5f0xu5nGazYRxfBVBNIuhiONWX6Mh2izRONSNXhCwFDaYRqHunublzw2l2aQMB0n5n1t0Q=="], @@ -499,14 +435,8 @@ "cac": ["cac@7.1.0", "", {}, "sha512-LMDU/U2yA4IPIY8KT0NsNPWEYZvAMkbgyspxJ6btJaYV+WMDOHAZCmB0lsTObiHaRS1V/ztKAl7+TSkTqXyeoA=="], - "compare-versions": ["compare-versions@6.1.1", "", {}, "sha512-4hm4VPpIecmlg59CHXnRDnqGplJFrbLG4aFEl5vl6cK1u76ws3LLvX7ikFnTDl5vo39sjWD6AaDPYodJp/NNHg=="], - - "confbox": ["confbox@0.3.2", "", {}, "sha512-ZUAKhKlkCOrIGKc8cj7zek9s9z1mveHif/25nUshI2BzCRzF7KH7KHa+Lnh2ubq+e1tIlaFuP763mzW4qVoehg=="], - "dataloader": ["dataloader@2.2.3", "", {}, "sha512-y2krtASINtPFS1rSDjacrFgn1dcUuoREVabwlOGOe4SdxenREqwjwjElAdwvbGM7kgZz9a3KVicWR7vcz8rnzA=="], - "debug": ["debug@4.4.3", "", { "dependencies": { "ms": "^2.1.3" }, "peerDependencies": { "supports-color": "*" }, "optionalPeers": ["supports-color"] }, "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA=="], - "defu": ["defu@6.1.7", "", {}, "sha512-7z22QmUWiQ/2d0KkdYmANbRUVABpZ9SNYyH5vx6PZ+nE5bcC0l7uFvEfHlyld/HcGBFTL536ClDt3DEcSlEJAQ=="], "detect-libc": ["detect-libc@2.1.2", "", {}, "sha512-Btj2BOOO83o3WyH59e8MgXsxEQVcarkUOpEYrubB0urwnN10yQ364rsiByU11nZlqWYZm05i/of7io4mzihBtQ=="], @@ -519,10 +449,6 @@ "esbuild": ["esbuild@0.28.2", "", { "optionalDependencies": { "@esbuild/aix-ppc64": "0.28.2", "@esbuild/android-arm": "0.28.2", "@esbuild/android-arm64": "0.28.2", "@esbuild/android-x64": "0.28.2", "@esbuild/darwin-arm64": "0.28.2", "@esbuild/darwin-x64": "0.28.2", "@esbuild/freebsd-arm64": "0.28.2", "@esbuild/freebsd-x64": "0.28.2", "@esbuild/linux-arm": "0.28.2", "@esbuild/linux-arm64": "0.28.2", "@esbuild/linux-ia32": "0.28.2", "@esbuild/linux-loong64": "0.28.2", "@esbuild/linux-mips64el": "0.28.2", "@esbuild/linux-ppc64": "0.28.2", "@esbuild/linux-riscv64": "0.28.2", "@esbuild/linux-s390x": "0.28.2", "@esbuild/linux-x64": "0.28.2", "@esbuild/netbsd-arm64": "0.28.2", "@esbuild/netbsd-x64": "0.28.2", "@esbuild/openbsd-arm64": "0.28.2", "@esbuild/openbsd-x64": "0.28.2", "@esbuild/openharmony-arm64": "0.28.2", "@esbuild/sunos-x64": "0.28.2", "@esbuild/win32-arm64": "0.28.2", "@esbuild/win32-ia32": "0.28.2", "@esbuild/win32-x64": "0.28.2" }, "bin": { "esbuild": "bin/esbuild" } }, "sha512-HKVLS8dvII+xoKW9kmqxbRKrnWEXfJJr/FZhhJmiqIB0e053QNYFqOBouTMO/k5sID4MvCiUCvv8b9M4h32wIA=="], - "estree-walker": ["estree-walker@2.0.2", "", {}, "sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w=="], - - "exsolve": ["exsolve@1.2.0", "", {}, "sha512-h1pQPR9XoeSMdntRNCjyTznaume4UpfXrULBnlkZ2CUM/G5eSa+pBByGldO5uR8dxbPC+OuJXsPPNf+JZ81ADg=="], - "fast-check": ["fast-check@4.10.2", "", { "dependencies": { "pure-rand": "^8.0.0" } }, "sha512-iK2f+YrcmoeGqk6fA0ea2bptcu/itMIm4NfEozq6N25+aG6h7s5HZbB/k1aV7b5w5sFLMCbbtRUsTVR+BgC3xw=="], "fast-string-truncated-width": ["fast-string-truncated-width@3.0.3", "", {}, "sha512-0jjjIEL6+0jag3l2XWWizO64/aZVtpiGE3t0Zgqxv0DPuxiMjvB3M24fCyhZUO4KomJQPj3LTSUnDP3GpdwC0g=="], @@ -537,8 +463,6 @@ "get-tsconfig": ["get-tsconfig@5.0.0-beta.6", "", { "dependencies": { "resolve-pkg-maps": "^1.0.0" } }, "sha512-X6fBC0pmImC70gvX2zm56go9hx0MyoGVdG0tUCkg/D+Xnh5TJsOZ7iDbOdI3PvmtrDxnu1YdDufpK2QJX1Meqw=="], - "glob-to-regexp": ["glob-to-regexp@0.4.1", "", {}, "sha512-lkX1HJXwyMcprw/5YUZc2s7DrpAiHB21/V+E1rHUrVNokkvB6bqMzT0VfV6/86ZNabt1k14YOIaT7nDvOX3Iiw=="], - "hookable": ["hookable@6.1.2", "", {}, "sha512-+abwxtiEA52GCVIsQqut3S/uKTbUwYIp4Pe/vv+6py5XiXBCqMZHg6pA6Y5qhgLSEys0/cYuPbO0z1QFj5ZCmg=="], "human-id": ["human-id@4.2.2", "", { "bin": { "human-id": "dist/cli.js" } }, "sha512-Z+8unD6em/MJwyrkWQ2M3wygRGI1+MztbutiNwk1DCuEPXOZRWGjtcMPZYP1exY9iNZMhd7ZOSMQSo9WYtiQRw=="], @@ -551,8 +475,6 @@ "jsonc-parser": ["jsonc-parser@3.3.1", "", {}, "sha512-HUgH65KyejrUFPvHFPbqOY0rsFip3Bo5wb4ngvdi1EpCYWUQDC5V+Y7mZws+DLkr4M//zQJoanu1SP+87Dv1oQ=="], - "kolorist": ["kolorist@1.8.0", "", {}, "sha512-Y+60/zizpJ3HRH8DCss+q95yr6145JXZo46OTpFvDZWLfRCE4qChOyk1b26nMaNpfHHgxagk9dXT5OP0Tfe+dQ=="], - "launch-editor": ["launch-editor@2.14.2", "", { "dependencies": { "picocolors": "^1.1.1", "shell-quote": "^1.10.0" } }, "sha512-NHJEb30MGBCkmZXLZwz25t37QR4aY03ZzPYUJXOJaOa92uWwExI9SBQUuIznBYc1xkD7cJNGX7oc3Nl3sq2kQQ=="], "lightningcss": ["lightningcss@1.33.0", "", { "dependencies": { "detect-libc": "^2.0.3" }, "optionalDependencies": { "lightningcss-android-arm64": "1.33.0", "lightningcss-darwin-arm64": "1.33.0", "lightningcss-darwin-x64": "1.33.0", "lightningcss-freebsd-x64": "1.33.0", "lightningcss-linux-arm-gnueabihf": "1.33.0", "lightningcss-linux-arm64-gnu": "1.33.0", "lightningcss-linux-arm64-musl": "1.33.0", "lightningcss-linux-x64-gnu": "1.33.0", "lightningcss-linux-x64-musl": "1.33.0", "lightningcss-win32-arm64-msvc": "1.33.0", "lightningcss-win32-x64-msvc": "1.33.0" } }, "sha512-WkUDrojuJs0xkgGf2udWxa3yGBRxPtxUkB79i6aCZLRgc7PM8fZe9TosfPDcvEpQZbuFASnHYmRLBLUbmLOIIA=="], @@ -579,16 +501,8 @@ "lightningcss-win32-x64-msvc": ["lightningcss-win32-x64-msvc@1.33.0", "", { "os": "win32", "cpu": "x64" }, "sha512-OlEICDx/Xl0FqSp4bry8zFnCvGpig3Gl4gCquvYwHuqJKEC1+n9NgDniFvqHGmMv1ZkqDJrDqKKSykTDX+ehuA=="], - "local-pkg": ["local-pkg@1.2.1", "", { "dependencies": { "mlly": "^1.7.4", "pkg-types": "^2.3.0", "quansync": "^0.2.11" } }, "sha512-++gUqRDEvcnN6Zhqrr+y/CkVEHhlrR96vZn3nZZPYzMcBUyBtTKzB9NadClFIsIVSsu+3i9tfk/erqy9kAmt7Q=="], - - "magic-string": ["magic-string@0.30.21", "", { "dependencies": { "@jridgewell/sourcemap-codec": "^1.5.5" } }, "sha512-vd2F4YUyEXKGcLHoq+TEyCjxueSeHnFxyyjNp80yg0XV4vUhnDer/lvvlqM/arB5bXQN5K2/3oinyCRyx8T2CQ=="], - - "mlly": ["mlly@1.8.2", "", { "dependencies": { "acorn": "^8.16.0", "pathe": "^2.0.3", "pkg-types": "^1.3.1", "ufo": "^1.6.3" } }, "sha512-d+ObxMQFmbt10sretNDytwt85VrbkhhUA/JBGm1MPaWJ65Cl4wOgLaB1NYvJSZ0Ef03MMEU/0xpPMXUIQ29UfA=="], - "mri": ["mri@1.2.0", "", {}, "sha512-tzzskb3bG8LvYGFF/mDTpq3jpI6Q9wc3LEmBaghu+DdCssd1FakN7Bc0hVNmEyGq1bq3RgfkCb3cmQLpNPOroA=="], - "ms": ["ms@2.1.3", "", {}, "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA=="], - "nanoid": ["nanoid@3.3.20", "", { "bin": { "nanoid": "bin/nanoid.cjs" } }, "sha512-uKdg2G3GNCKQn9byYOpxbGqrT2fGO5KRt5J/8b3pok8rT6qxGWF6hxMyJiEYtAf+FVyYuD9hRaDqX5uPFYJ4ZQ=="], "obug": ["obug@3.0.0", "", {}, "sha512-5vvB5+W7ePv+p3uqxi+RcW1XAzLW0/hxt3/4X4Lc4qHudzOhmBiBwOY6DRob4WnanAEGvNcLjF+KNOufrUoEQw=="], @@ -601,16 +515,10 @@ "package-manager-detector": ["package-manager-detector@1.9.0", "", {}, "sha512-zAMfbta9nPA8AKkA4WdmNAT8R8s6Dk0/xwPsqNnRidMFcLo1YkLuPDTgs2f64XdzS8vbLNnoJ+uUIkgbz7oRHA=="], - "path-browserify": ["path-browserify@1.0.1", "", {}, "sha512-b7uo2UCUOYZcnF/3ID0lulOJi/bafxa1xPe7ZPsammBSpjSWQkjNxlt635YGS2MiR9GjvuXCtz2emr3jbsz98g=="], - - "pathe": ["pathe@2.0.3", "", {}, "sha512-WUjGcAqP1gQacoQe+OBJsFA7Ld4DyXuUIjZ5cc75cLHvJ7dtNsTugphxIADwspS+AraAUePCKrSVtPLFj/F88w=="], - "picocolors": ["picocolors@1.1.1", "", {}, "sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA=="], "picomatch": ["picomatch@4.0.7", "", {}, "sha512-qcJu88Q2IWqJsDD529JKMdwGm/dvInW4HvQnRwiH9JtihJvzGOscDtHE3x1pBKeUOTysQ8kVmLnJ2kJu7yhcGA=="], - "pkg-types": ["pkg-types@2.4.0", "", { "dependencies": { "confbox": "^0.3.1", "exsolve": "^1.1.3", "pathe": "^2.0.3" } }, "sha512-07Fys7iVx0X6TcviMOgogM1Lk33ZyqOezMnU79S+kffWqwolG/5W9V8EgQSeYCIfFTYVgssRbnH630Oa2+soBA=="], - "pnpm": ["pnpm@12.18.0", "", { "optionalDependencies": { "@pnpm/exe.android-arm64": "12.18.0", "@pnpm/exe.android-x64": "12.18.0", "@pnpm/exe.darwin-arm64": "12.18.0", "@pnpm/exe.darwin-x64": "12.18.0", "@pnpm/exe.freebsd-x64": "12.18.0", "@pnpm/exe.linux-arm64": "12.18.0", "@pnpm/exe.linux-arm64-musl": "12.18.0", "@pnpm/exe.linux-ppc64": "12.18.0", "@pnpm/exe.linux-riscv64": "12.18.0", "@pnpm/exe.linux-s390x": "12.18.0", "@pnpm/exe.linux-x64": "12.18.0", "@pnpm/exe.linux-x64-musl": "12.18.0", "@pnpm/exe.win32-arm64": "12.18.0", "@pnpm/exe.win32-x64": "12.18.0" }, "hasInstallScript": true, "bin": { "pn": "pn", "pnx": "pnx", "pnpm": "pnpm", "pnpx": "pnpx" } }, "sha512-nXiC1dyCFH7PxOBiqjSDTgrQKWcQoYN6ERWuASEn02txCeMhrBWYod0KZVl2gbHpmRfhLtDXSerpEYeUM2O+sw=="], "postcss": ["postcss@8.5.32", "", { "dependencies": { "nanoid": "^3.3.20", "picocolors": "^1.1.1", "source-map-js": "^1.2.2" } }, "sha512-LJlKCCAUFKOuZxipUdYw1NzIITEsPcgyOG9LkvRJvuKj/bRzbuRY0ARXvL0pWGpsZvn8jku+LMep2eU0seHp8g=="], @@ -659,50 +567,22 @@ "tsx": ["tsx@4.23.15", "", { "dependencies": { "esbuild": "~0.28.0" }, "optionalDependencies": { "fsevents": "~2.3.3" }, "bin": { "tsx": "dist/cli.mjs" } }, "sha512-Yiex1Ovn8z2xPpOWckIiysV1SSyRMY9BkLF++q0yKiDxCqRhosKfMg3janKkiLBwZ5c/YryloKwGZcrEmtwxKw=="], - "typescript": ["typescript@7.0.2", "", { "optionalDependencies": { "@typescript/typescript-aix-ppc64": "7.0.2", "@typescript/typescript-darwin-arm64": "7.0.2", "@typescript/typescript-darwin-x64": "7.0.2", "@typescript/typescript-freebsd-arm64": "7.0.2", "@typescript/typescript-freebsd-x64": "7.0.2", "@typescript/typescript-linux-arm": "7.0.2", "@typescript/typescript-linux-arm64": "7.0.2", "@typescript/typescript-linux-loong64": "7.0.2", "@typescript/typescript-linux-mips64el": "7.0.2", "@typescript/typescript-linux-ppc64": "7.0.2", "@typescript/typescript-linux-riscv64": "7.0.2", "@typescript/typescript-linux-s390x": "7.0.2", "@typescript/typescript-linux-x64": "7.0.2", "@typescript/typescript-netbsd-arm64": "7.0.2", "@typescript/typescript-netbsd-x64": "7.0.2", "@typescript/typescript-openbsd-arm64": "7.0.2", "@typescript/typescript-openbsd-x64": "7.0.2", "@typescript/typescript-sunos-x64": "7.0.2", "@typescript/typescript-win32-arm64": "7.0.2", "@typescript/typescript-win32-x64": "7.0.2" }, "bin": { "tsc": "bin/tsc" } }, "sha512-8FYau96o3NKOhbjKi/qNvG/W5jhzxkbdm5sj9AbZ/5T5sWqn3hJgLfGx27sRKZWTvyzCP8dLRBTf5tBTSRVUNA=="], - - "ufo": ["ufo@1.6.4", "", {}, "sha512-JFNbkD1Svwe0KvGi8GOeLcP4kAWQ609twvCdcHxq1oSL8svv39ZuSvajcD8B+5D0eL4+s1Is2D/O6KN3qcTeRA=="], - "unconfig-core": ["unconfig-core@7.5.0", "", { "dependencies": { "@quansync/fs": "^1.0.0", "quansync": "^1.0.0" } }, "sha512-Su3FauozOGP44ZmKdHy2oE6LPjk51M/TRRjHv2HNCWiDvfvCoxC2lno6jevMA91MYAdCdwP05QnWdWpSbncX/w=="], "undici-types": ["undici-types@8.9.0", "", {}, "sha512-KTDyRTYX8sWmKXAikPHHSyc63CRPETMctyjKFupcC6OBLXT3xsN0e9aF7m+mIXutFWpUXuedtowG7iLOzp0kQg=="], - "unplugin": ["unplugin@2.3.11", "", { "dependencies": { "@jridgewell/remapping": "^2.3.5", "acorn": "^8.15.0", "picomatch": "^4.0.3", "webpack-virtual-modules": "^0.6.2" } }, "sha512-5uKD0nqiYVzlmCRs01Fhs2BdkEgBS3SAVP6ndrBsuK42iC2+JHyxM05Rm9G8+5mkmRtzMZGY8Ct5+mliZxU/Ww=="], - - "unplugin-dts": ["unplugin-dts@1.1.2", "", { "dependencies": { "@rollup/pluginutils": "^5.1.4", "@volar/typescript": "^2.4.26", "compare-versions": "^6.1.1", "debug": "^4.4.0", "glob-to-regexp": "0.4.1", "kolorist": "^1.8.0", "local-pkg": "^1.1.1", "magic-string": "^0.30.17", "unplugin": "^2.3.2" }, "peerDependencies": { "@microsoft/api-extractor": ">=7", "@rspack/core": "^1", "@vue/language-core": "^3.1.5", "esbuild": "*", "rolldown": "*", "rollup": ">=3", "typescript": ">=4", "vite": ">=3", "webpack": "^4 || ^5" }, "optionalPeers": ["@microsoft/api-extractor", "@rspack/core", "@vue/language-core", "esbuild", "rolldown", "rollup", "vite", "webpack"] }, "sha512-RDqy90XUmFj6rz4U5YoTMdYdaCJe2ZnQZaWIjkWS4952Gv0zBTQyqWtlGgVMPYHa982dURvyoc+sUOFIcDFv+w=="], - "verkit": ["verkit@0.5.0", "", {}, "sha512-u4J1hr6Y+C/hit34GwL3eIcUf3wngT8TlYUjK7tk0jxydKLAq3sYvifjdTDA6U3KCKRcQCQDGf/srjxfZF3l7g=="], "vite": ["vite@8.3.7", "", { "dependencies": { "lightningcss": "^1.33.0", "picomatch": "^4.0.7", "postcss": "^8.5.32", "rolldown": "~1.2.18", "tinyglobby": "^0.2.17" }, "optionalDependencies": { "fsevents": "~2.3.3" }, "peerDependencies": { "@types/node": "^20.19.0 || >=22.12.0", "@vitejs/devtools": "^0.7.1 || ^0.8.0", "esbuild": "^0.27.0 || ^0.28.0", "jiti": ">=1.21.0", "less": "^4.0.0", "sass": "^1.70.0", "sass-embedded": "^1.70.0", "stylus": ">=0.54.8", "sugarss": "^5.0.0", "terser": "^5.16.0", "tsx": "^4.8.1", "yaml": "^2.4.2" }, "optionalPeers": ["@types/node", "@vitejs/devtools", "esbuild", "jiti", "less", "sass", "sass-embedded", "stylus", "sugarss", "terser", "tsx", "yaml"], "bin": { "vite": "bin/vite.js" } }, "sha512-oxh0dMxrayBr33ScJvvBJ2HBQ2jc1TBrXKR2NyL/MJ9WPuX19mN2DXWUmywKdyw5RFVQBo8hmtb2FMC0LHrnng=="], - "vite-plugin-dts": ["vite-plugin-dts@5.1.2", "", { "dependencies": { "unplugin-dts": "1.1.2" }, "peerDependencies": { "@microsoft/api-extractor": ">=7", "rollup": ">=3", "vite": ">=3" }, "optionalPeers": ["@microsoft/api-extractor", "rollup", "vite"] }, "sha512-1bXUz836sWq6ewEMQre3ZtNFVfZk/92DppgCCKP8tWx/NWwV2wHuXlRHb2TztHjbikPxvyAGLGu7hVh94Plwww=="], - - "vscode-jsonrpc": ["vscode-jsonrpc@10.0.0", "", {}, "sha512-USSfxg0vDIpTQqlQBGxF3mBARyoS8cU7LHLpbYNh6dOJt32dlskxPWB0Irrh5TllTmyf7oNLAvqDqzklbwwnpA=="], - - "vscode-languageserver-protocol": ["vscode-languageserver-protocol@3.18.5", "", { "dependencies": { "vscode-jsonrpc": "10.0.0", "vscode-languageserver-types": "3.18.5" } }, "sha512-FW4fBMzZ99N8xeob4py0l050wgCoRgTpEq5Xcsb9lM1bc29UKGR/wSV+4knaqFxssFHajy7OzNiKP/m3U1ZEuA=="], - - "vscode-languageserver-textdocument": ["vscode-languageserver-textdocument@1.0.16", "", {}, "sha512-qeNEuOi9a3qkqRf7Gfez2WL2VwlBTLCNekHBGO9kxPVUp9XuY15yfTJ9jwvOwKI0I2MhUUfZq95NSp+LK1CLQg=="], - - "vscode-languageserver-types": ["vscode-languageserver-types@3.18.5", "", {}, "sha512-kPd6+JQNz3HMJvjKlqUxERSlZHAntl/aGpsk7ImwIh0ewDKDcjgAEyVSYciPiOJD3ftbK9IrfiqUeTZLSbCizw=="], - - "vscode-uri": ["vscode-uri@3.2.0", "", {}, "sha512-m2gXo3bn0G1kT9InzMf07fTbqMbGtyckj3bH5ktLO+1Ssv+yiATZ4dhwaQv9UZWxJh6E9IFGnQyjgWVDWVBDrg=="], - - "webpack-virtual-modules": ["webpack-virtual-modules@0.6.2", "", {}, "sha512-66/V2i5hQanC51vBQKPH4aI8NMAcBW59FVBs+rC7eGHupMyfn34q7rZIE+ETlJ+XTevqfUhVVBgSUNSW2flEUQ=="], - "yaml": ["yaml@2.9.1", "", { "bin": { "yaml": "bin.mjs" } }, "sha512-3NxN8+78OdzbT7C/WjGsyfPAtJaN3FNDsWxv7Y7mcDsT/oOmgW8BpyQQFFBnvZE3j9Y2Sdz1ULFLezL7Eb2yFw=="], "yuku": ["yuku@0.27.0", "", { "optionalDependencies": { "@yuku-toolchain/darwin-arm64": "0.27.0", "@yuku-toolchain/darwin-x64": "0.27.0", "@yuku-toolchain/linux-arm64": "0.27.0", "@yuku-toolchain/linux-x64": "0.27.0", "@yuku-toolchain/win32-arm64": "0.27.0", "@yuku-toolchain/win32-x64": "0.27.0" }, "peerDependencies": { "@yuku-toolchain/wasm": "0.27.0" }, "optionalPeers": ["@yuku-toolchain/wasm"] }, "sha512-YmSD4xYlESRi8egxzC4guegQdMhAcz1G9NUsMNrTABAIV9dQxoBzDC7ZyAG/dSG18o1Oxt4xDok2irvPy9FSJQ=="], - "local-pkg/quansync": ["quansync@0.2.11", "", {}, "sha512-AifT7QEbW9Nri4tAwR5M/uzpBuqfZf+zwaEM/QkzEjj7NBuFD2rBuy0K3dE+8wltbezDV7JMA0WfnCPYRSYbXA=="], - - "mlly/pkg-types": ["pkg-types@1.3.1", "", { "dependencies": { "confbox": "^0.1.8", "mlly": "^1.7.4", "pathe": "^2.0.1" } }, "sha512-/Jm5M4RvtBFVkKWRu2BLUTNP8/M2a+UwuAX+ae4770q1qVGtfjG+WTCupoZixokjmHiry8uI+dlY8KXYV5HVVQ=="], - "rolldown/@oxc-project/types": ["@oxc-project/types@0.157.0", "", {}, "sha512-95iTox1qdt6WGWce3xwNOVayByOfLaYAq+qGPpub6NWbBh9sv0GG3+zyfh9ZBCO/jVu5A0EWI+qQI7g6fevjxg=="], "vite/rolldown": ["rolldown@1.2.18", "", { "dependencies": { "@oxc-project/types": "=0.156.0", "@rolldown/pluginutils": "^1.0.0" }, "optionalDependencies": { "@rolldown/binding-android-arm-eabi": "1.2.18", "@rolldown/binding-android-arm64": "1.2.18", "@rolldown/binding-darwin-arm64": "1.2.18", "@rolldown/binding-darwin-x64": "1.2.18", "@rolldown/binding-freebsd-x64": "1.2.18", "@rolldown/binding-linux-arm-gnueabihf": "1.2.18", "@rolldown/binding-linux-arm64-gnu": "1.2.18", "@rolldown/binding-linux-arm64-musl": "1.2.18", "@rolldown/binding-linux-ppc64-gnu": "1.2.18", "@rolldown/binding-linux-s390x-gnu": "1.2.18", "@rolldown/binding-linux-x64-gnu": "1.2.18", "@rolldown/binding-linux-x64-musl": "1.2.18", "@rolldown/binding-openharmony-arm64": "1.2.18", "@rolldown/binding-win32-arm64-msvc": "1.2.18", "@rolldown/binding-win32-x64-msvc": "1.2.18" }, "bin": { "rolldown": "./bin/cli.mjs" } }, "sha512-C1uuT3UR60SShuCaPQFAAZyefJCWZlAKB02BV3BuPE2Rs4fevRQltEKoFO2tV5W9/eJhU5RieV6vJj3euulfNQ=="], - "mlly/pkg-types/confbox": ["confbox@0.1.8", "", {}, "sha512-RMtmw0iFkeR4YV+fUOSucriAQNb9g8zFR52MWCtl+cCZOFRNL6zeB395vPzFhEjjn4fMxXudmELnl/KF/WrK6w=="], - "vite/rolldown/@oxc-project/types": ["@oxc-project/types@0.156.0", "", {}, "sha512-1Duyg48TdJNdyhEB8Xn1L36bT9Pv6GUtlKjHxOys8xkaF/rQq3XJE+bAurSK/AgIz5mGFsb77cn9Pb20+WCScw=="], "vite/rolldown/@rolldown/binding-android-arm-eabi": ["@rolldown/binding-android-arm-eabi@1.2.18", "", { "os": "android", "cpu": "arm" }, "sha512-ubTG+4KlidvioxjOFdsdEa2F6JVGZb8m2ByJUqQ7fYzUeT1cEn194POcsQ10PKH4p//q0YQn4SB3YpSuzcA1Yg=="], diff --git a/packages/oxlint-config/README.md b/packages/oxlint-config/README.md index c0ea2c8a..4b95b435 100644 --- a/packages/oxlint-config/README.md +++ b/packages/oxlint-config/README.md @@ -859,19 +859,25 @@ export default { }; ``` -This adapter requires consumer-installed `vite-plugin-dts` 5.1.2 and its -`unplugin-dts` 1.1.2 implementation. Its dependency scope must provide TypeScript -6.0.3 as `typescript` or the plugin's `@typescript/typescript6` fallback. -Unsupported versions fail explicitly. +The helper emits declarations with the tsrs that `@stll/oxlint-config` already +depends on; the consumer installs neither TypeScript nor a declaration plugin. +After the bundle is written, it runs `tsrs -p` once on a generated config that +extends the package `tsconfig.json` with `emitDeclarationOnly`, `outDir` set to +`build.outDir`, the helper's include/exclude, and `rootDir` set to `entryRoot` +(or the common directory of the inputs). +Doc comments are kept. Side-effect imports such as `import "./styles.css"` are +dropped from the declarations. Type errors are reported as warnings, and +declarations are still written. Option errors, inputs outside `entryRoot`, and +`compilerOptions.paths` aliases fail the build, because declarations keep +import specifiers exactly as written. 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 -bytes must remain unchanged across each declaration hook; this is checked during -the actual build, without a comparison build. +Options are closed and static: include/exclude, entryRoot, and +compilerOptions.declarationMap=false. The emit may add or change only `.d.ts`, +`.d.mts`, `.d.cts`, and their maps. Every other file in the output directory +must stay byte-identical, and this is checked during the actual build. Nuxt modules can set both emitted targets without replacing the builder's entries: diff --git a/packages/oxlint-config/package.json b/packages/oxlint-config/package.json index b1b61bae..6ecbfe0e 100644 --- a/packages/oxlint-config/package.json +++ b/packages/oxlint-config/package.json @@ -147,9 +147,7 @@ "@types/picomatch": "4.0.3", "@types/semver": "7.8.0", "oxlint": "1.93.0", - "unplugin-dts": "1.1.2", - "vite": "8.3.7", - "vite-plugin-dts": "5.1.2" + "vite": "8.3.7" }, "peerDependencies": { "oxlint": ">=1.93.0 <2", diff --git a/packages/oxlint-config/src/publish-build-target-vite-dts-helper.ts b/packages/oxlint-config/src/publish-build-target-vite-dts-helper.ts index 0d39263a..4acd3929 100644 --- a/packages/oxlint-config/src/publish-build-target-vite-dts-helper.ts +++ b/packages/oxlint-config/src/publish-build-target-vite-dts-helper.ts @@ -1,127 +1,205 @@ -import { readFileSync, realpathSync } from "node:fs"; +import { execFile } from "node:child_process"; +import { + existsSync, + mkdtempSync, + readFileSync, + realpathSync, + rmSync, + writeFileSync, +} from "node:fs"; import { createRequire } from "node:module"; +import { tmpdir } from "node:os"; import path from "node:path"; +import { parseSync } from "oxc-parser"; import type { Plugin } from "vite"; -import { compilerPackages } from "./compiler-packages"; import { - createDeclarationEmissionLedger, - declarationHookParts, - guardDeclarationHook, + assertDeclarationOnlyOutput, type ReviewedViteDtsOptions, reviewedViteDtsOptions, - reviewedViteDtsVersions, + snapshotDeclarationDirectory, } from "./publish-build-target-vite-dts"; type DeclarationOnlyDtsOptions = { directory: string } & ReviewedViteDtsOptions; const record = (value: unknown): value is Record => typeof value === "object" && value !== null && !Array.isArray(value); -/** The actual build uses this closed factory and its guarded declaration hooks. */ -export const declarationOnlyDts = ({ - directory, - ...options -}: DeclarationOnlyDtsOptions): Plugin => { - const root = realpathSync(directory); - const require = createRequire(path.join(root, "package.json")); - const pluginRequire = createRequire(require.resolve("vite-plugin-dts")); - for (const [name, version] of Object.entries(reviewedViteDtsVersions)) { - const owner = name === "unplugin-dts" ? pluginRequire : require; - const metadata: unknown = JSON.parse( - readFileSync(owner.resolve(`${name}/package.json`), "utf8"), +/** Side-effect imports name runtime modules (often styles) that declarations cannot resolve. */ +export const withoutSideEffectImports = (file: string, source: string) => { + const { program, errors } = parseSync(file, source, { + lang: "dts", + sourceType: "module", + }); + if (errors.length > 0) + throw new Error( + `Emitted declaration ${file} does not parse: ${errors[0]?.message ?? ""}`, ); - if (!record(metadata) || metadata["version"] !== version) - throw new Error(`Declaration-only adapter requires ${name} ${version}`); + let result = source; + for (const statement of program.body.toReversed()) { + if ( + statement.type !== "ImportDeclaration" || + statement.importKind === "type" || + statement.specifiers.length > 0 + ) + continue; + const end = /^\r?\n/.exec(result.slice(statement.end))?.[0].length ?? 0; + result = + result.slice(0, statement.start) + result.slice(statement.end + end); } - const compilerRequire = createRequire(pluginRequire.resolve("unplugin-dts")); - const compilerVersion = (name: string) => { - try { - const metadata: unknown = JSON.parse( - readFileSync(compilerRequire.resolve(`${name}/package.json`), "utf8"), - ); - return record(metadata) && typeof metadata["version"] === "string" - ? metadata["version"] - : undefined; - } catch (error) { - if (!record(error) || error["code"] !== "MODULE_NOT_FOUND") throw error; - return undefined; - } + return result; +}; + +const commonDirectory = (files: readonly string[]) => { + const directories = files.map((file) => path.dirname(file).split(path.sep)); + const first = directories.at(0); + if (first === undefined) + throw new Error("Declaration emit found no TypeScript inputs"); + let length = first.length; + for (const parts of directories) + while ( + parts.slice(0, length).join(path.sep) !== + first.slice(0, length).join(path.sep) + ) + length -= 1; + return first.slice(0, length).join(path.sep); +}; + +const run = (args: string[], cwd: string) => + new Promise<{ status: number; output: string }>((resolve, reject) => { + execFile( + process.execPath, + [ + path.join( + path.dirname( + createRequire(import.meta.url).resolve("tsrs/package.json"), + ), + "bin", + "tsrs", + ), + ...args, + ], + { cwd, encoding: "utf8", maxBuffer: 32 * 1024 * 1024, timeout: 300_000 }, + (error, stdout, stderr) => { + const status = error === null ? 0 : error.code; + if (typeof status !== "number") + reject(error ?? new Error("tsrs failed")); + else resolve({ status, output: `${stdout}${stderr}`.trim() }); + }, + ); + }); + +type EmitDeclarationsOptions = { + root: string; + output: string; + options: ReviewedViteDtsOptions; + warn: (message: string) => void; +}; +/** tsrs emits declarations for the package tsconfig into the build output; nothing else may change. */ +export const emitDeclarations = async ({ + root, + output, + options, + warn, +}: EmitDeclarationsOptions) => { + const base = path.join(root, "tsconfig.json"); + if (!existsSync(base)) + throw new Error("Declaration emit requires the package tsconfig.json"); + const scratch = mkdtempSync(path.join(tmpdir(), "stll-declarations-")); + const config = path.join(scratch, "tsconfig.json"); + const absolute = (patterns: readonly string[]) => + patterns.map((pattern) => path.join(root, pattern)); + const compilerOptions: Record = { + noEmit: false, + declaration: true, + emitDeclarationOnly: true, + noEmitOnError: false, + noUnusedLocals: false, + noUnusedParameters: false, + // The bundler resolves style and asset imports; their declarations are dropped below. + noUncheckedSideEffectImports: false, + outDir: output, + declarationDir: null, + outFile: null, + composite: false, + incremental: false, + tsBuildInfoFile: null, + ...options.compilerOptions, }; - const primaryCompiler = compilerVersion(compilerPackages.typescript); - const compatibleCompiler = - primaryCompiler === "6.0.3" || - (primaryCompiler?.startsWith("7.") === true && - compilerVersion(compilerPackages.typescriptCompatibility) === "6.0.3"); - if (!compatibleCompiler) - throw new Error( - "Declaration-only adapter requires TypeScript 6.0.3 as typescript or the TypeScript 7 @typescript/typescript6 fallback in the declaration plugin's dependency scope", + const project = { + extends: base, + compilerOptions, + ...(options.include === undefined + ? {} + : { files: [], include: absolute(options.include) }), + ...(options.exclude === undefined + ? {} + : { exclude: absolute(options.exclude) }), + }; + const { API } = await import("tsrs/async"); + const api = new API({ cwd: root }); + try { + writeFileSync(config, JSON.stringify(project)); + const parsed = await api.parseConfigFile(config); + const error = parsed.errors.at(0); + if (error !== undefined) + throw new Error( + `Declaration emit cannot read ${base}: TS${error.code} ${error.text}`, + ); + const paths: unknown = parsed.options.paths; + if (record(paths) && Object.keys(paths).length > 0) + throw new Error( + "Declaration emit keeps import specifiers as written; replace compilerOptions.paths aliases with package imports or relative paths", + ); + compilerOptions["rootDir"] = + options.entryRoot === undefined + ? commonDirectory( + parsed.fileNames.filter((file) => !/\.d\.[cm]?ts$/.test(file)), + ) + : path.join(root, options.entryRoot); + writeFileSync(config, JSON.stringify(project)); + const before = snapshotDeclarationDirectory(output); + const { status, output: diagnostics } = await run( + ["-p", config, "--pretty", "false"], + root, ); - const loaded: unknown = require("vite-plugin-dts"); - const factory = record(loaded) ? loaded["default"] : loaded; - if (typeof factory !== "function") - throw new Error("Installed declaration plugin does not expose its factory"); - const plugin: unknown = Reflect.apply(factory, undefined, [ - reviewedViteDtsOptions(options), - ]); - if (!record(plugin)) throw new Error("Invalid installed declaration plugin"); - const hookNames = [ - "config", - "configResolved", - "buildStart", - "transform", - "watchChange", - "generateBundle", - "writeBundle", - ] as const; - const allowed = new Set([ - "name", - "apply", - "enforce", - "vite", - "rollup", - "rolldown", - "webpack", - "rspack", - "esbuild", - ...hookNames, - ]); - for (const key of Reflect.ownKeys(plugin)) { - const descriptor = Object.getOwnPropertyDescriptor(plugin, key); + // Exit 2 reports type diagnostics with outputs written. Compiler option and output + // errors (TS5xxx), inputs outside rootDir or the project, and no inputs stop the build. if ( - typeof key !== "string" || - !allowed.has(key) || - !descriptor || - !("value" in descriptor) + status !== 0 && + (status !== 2 || /TS(?:5\d{3}|6059|6307|18003):/.test(diagnostics)) ) - throw new Error("Unreviewed installed declaration plugin shape"); + throw new Error(`Declaration emit failed:\n${diagnostics}`); + if (status === 2) warn(`Declaration emit diagnostics:\n${diagnostics}`); + const after = snapshotDeclarationDirectory(output); + assertDeclarationOnlyOutput({ before, after }); + for (const [file, digest] of Object.entries(after)) { + if (before[file] === digest || !/\.d\.[cm]?ts$/.test(file)) continue; + const target = path.join(output, file); + writeFileSync( + target, + withoutSideEffectImports(file, readFileSync(target, "utf8")), + ); + } + } finally { + await api.close(); + rmSync(scratch, { recursive: true, force: true }); } - if ( - plugin["name"] !== "unplugin-dts" || - plugin["apply"] !== "build" || - plugin["enforce"] !== "pre" - ) - throw new Error("Unreviewed installed declaration plugin identity"); - const outputDirectories: string[] = []; - // Only the dts producer is confined here; JS emitted by other plugins is out of scope. - // Resolve its emitter references at both output hooks, including deferred assets. - const ledger = createDeclarationEmissionLedger(); - const hook = (name: (typeof hookNames)[number]) => - guardDeclarationHook({ - hook: declarationHookParts(plugin[name]).handler, - hookName: name, - outputDirectories, - ledger, - }); - // The object form's static id filter is kept; its handler stays guarded. - const transformFilter = declarationHookParts(plugin["transform"]).filter; - const transform = hook("transform"); - const configResolved = hook("configResolved"); +}; + +/** The actual build uses this closed factory; tsrs writes only declarations after the bundle. */ +export const declarationOnlyDts = ({ + directory, + ...options +}: DeclarationOnlyDtsOptions): Plugin => { + const root = realpathSync(directory); + const reviewed = reviewedViteDtsOptions(options); + let output: string | undefined; + let emitted = false; return { name: "stll:declaration-only-dts", apply: "build", enforce: "pre", - config: hook("config"), - async configResolved(config) { + configResolved(config) { if ( realpathSync(config.root) !== root || !config.build.write || @@ -130,8 +208,8 @@ export const declarationOnlyDts = ({ throw new Error( "Declaration-only adapter requires a package-local production build", ); - const output = path.resolve(root, config.build.outDir); - const relative = path.relative(root, output); + const resolved = path.resolve(root, config.build.outDir); + const relative = path.relative(root, resolved); if ( relative === "" || relative === ".." || @@ -141,12 +219,11 @@ export const declarationOnlyDts = ({ throw new Error( "Declaration output directory must stay within the package", ); - // Check existing ancestor paths before the declaration plugin can write. - let ancestor = output; + // Check existing ancestor paths before declarations are written. + let ancestor = resolved; while (ancestor !== root) { try { - const resolved = realpathSync(ancestor); - const within = path.relative(root, resolved); + const within = path.relative(root, realpathSync(ancestor)); if ( within === ".." || within.startsWith(`..${path.sep}`) || @@ -159,27 +236,23 @@ export const declarationOnlyDts = ({ ancestor = path.dirname(ancestor); } } - outputDirectories.push(output); - await configResolved.call(this, config); - }, - buildStart: hook("buildStart"), - transform: - transformFilter === undefined - ? transform - : { filter: transformFilter, handler: transform }, - watchChange: hook("watchChange"), - generateBundle: { - order: "post", - async handler(outputOptions, bundle, isWrite) { - await hook("generateBundle").call(this, outputOptions, bundle, isWrite); - ledger.audit(); - }, + output = resolved; }, writeBundle: { order: "post", - async handler(outputOptions, bundle) { - await hook("writeBundle").call(this, outputOptions, bundle); - ledger.audit(); + sequential: true, + async handler() { + // Every output format shares one outDir; declarations are emitted once. + if (emitted) return; + emitted = true; + if (output === undefined) + throw new Error("Declaration output directory was not resolved"); + await emitDeclarations({ + root, + output, + options: reviewed, + warn: (message) => this.warn(message), + }); }, }, }; diff --git a/packages/oxlint-config/src/publish-build-target-vite-dts.test.ts b/packages/oxlint-config/src/publish-build-target-vite-dts.test.ts index f9e069ef..efbd5b46 100644 --- a/packages/oxlint-config/src/publish-build-target-vite-dts.test.ts +++ b/packages/oxlint-config/src/publish-build-target-vite-dts.test.ts @@ -1,34 +1,57 @@ import { afterEach, expect, test } from "bun:test"; -import { mkdtempSync, rmSync, writeFileSync } from "node:fs"; +import assert from "node:assert/strict"; +import { + mkdirSync, + mkdtempSync, + readdirSync, + readFileSync, + rmSync, + writeFileSync, +} from "node:fs"; import { tmpdir } from "node:os"; import path from "node:path"; import { assertDeclarationOnlyOutput, - createDeclarationEmissionLedger, - declarationHookParts, - guardDeclarationHook, reviewedViteDtsOptions, - snapshotDeclarationBundle, snapshotDeclarationDirectory, } from "./publish-build-target-vite-dts"; - -// `typeof === "function"` narrows to `Function`, whose calls return `any`. -const callable = ( - value: unknown, -): value is (...parameters: readonly unknown[]) => unknown => - typeof value === "function"; +import { + emitDeclarations, + withoutSideEffectImports, +} from "./publish-build-target-vite-dts-helper"; const directories: string[] = []; afterEach(() => { for (const directory of directories.splice(0)) rmSync(directory, { recursive: true, force: true }); }); -const outputDirectory = () => { +const scratchDirectory = () => { const directory = mkdtempSync(path.join(tmpdir(), "reviewed-vite-dts-")); directories.push(directory); return directory; }; +const write = (root: string, files: Record) => { + for (const [file, source] of Object.entries(files)) { + mkdirSync(path.dirname(path.join(root, file)), { recursive: true }); + writeFileSync(path.join(root, file), source); + } +}; +const tsconfig = (compilerOptions: Record = {}) => + JSON.stringify({ + compilerOptions: { + target: "ES2022", + module: "ESNext", + moduleResolution: "Bundler", + strict: true, + noEmit: true, + noUnusedLocals: true, + skipLibCheck: true, + types: [], + ...compilerOptions, + }, + include: ["src"], + }); test("default and existing static declaration options are frozen and isolated from caller mutation", () => { expect(reviewedViteDtsOptions()).toEqual({}); @@ -36,49 +59,43 @@ test("default and existing static declaration options are frozen and isolated fr const compilerOptions = { declarationMap: false }; const options = reviewedViteDtsOptions({ include, - exclude: ["src/**/*.test.ts"], + exclude: "src/**/*.test.ts", entryRoot: "src", - pathsToAliases: false, compilerOptions, }); include.push("outside/**/*"); compilerOptions.declarationMap = true; expect(options.include).toEqual(["src/**/*"]); + expect(options.exclude).toEqual(["src/**/*.test.ts"]); expect(options.compilerOptions).toEqual({ declarationMap: false }); expect(Object.isFrozen(options)).toBe(true); expect(Object.isFrozen(options.include)).toBe(true); }); -test("the option boundary rejects every callback and output-changing escape in the reviewed profile", () => { +test("the option boundary rejects callbacks, foreign plugin options and output escapes", () => { for (const key of [ - "afterBootstrap", - "afterDiagnostic", - "beforeWriteFile", - "afterRollup", "afterBuild", + "beforeWriteFile", "resolvers", "processor", "root", "outDirs", - "bundleTypes", "aliases", + "pathsToAliases", + "strictOutput", + "declarationOnly", ]) expect(() => reviewedViteDtsOptions({ [key]: () => undefined })).toThrow( "Unreviewed", ); for (const options of [ - { declarationOnly: true }, - { strictOutput: false }, { compilerOptions: { declarationMap: true } }, { compilerOptions: { declarationMap: false, plugins: [] } }, { include: "../outside/*" }, + { include: [] }, { entryRoot: "/outside" }, ]) expect(() => reviewedViteDtsOptions(options)).toThrow(); - const hidden = Object.defineProperty({}, "afterBuild", { - value: () => undefined, - }); - expect(() => reviewedViteDtsOptions(hidden)).toThrow("Unreviewed"); expect(() => reviewedViteDtsOptions( Object.defineProperty({}, "include", { get: () => ["src/*"] }), @@ -86,250 +103,123 @@ test("the option boundary rejects every callback and output-changing escape in t ).toThrow("accessors"); }); -test("bundle snapshots retain original bytes despite later producer mutation", () => { - const asset = { type: "asset", fileName: "index.js", source: "original" }; - const before = snapshotDeclarationBundle({ "index.js": asset }); - asset.source = "changed"; - expect(Object.isFrozen(before)).toBe(true); +test("only declaration files and their maps can be added, changed or removed", () => { + const output = scratchDirectory(); + write(output, { "index.js": "code", "index.d.ts": "declaration" }); + const before = snapshotDeclarationDirectory(output); + write(output, { + "index.d.ts": "changed", + "index.d.mts": "", + "index.d.cts.map": "", + "nested/index.d.ts": "", + }); expect(() => assertDeclarationOnlyOutput({ before, - after: snapshotDeclarationBundle({ "index.js": asset }), + after: snapshotDeclarationDirectory(output), }), - ).toThrow("index.js"); -}); - -test("only declaration files and their maps can be emitted or changed", () => { - for (const file of [ - "index.d.ts", - "index.d.mts", - "index.d.cts", - "index.d.ts.map", - "index.d.cts.map", - ]) { - const after = snapshotDeclarationBundle({ - [file]: { type: "asset", fileName: file, source: "declaration" }, - }); - expect(() => - assertDeclarationOnlyOutput({ before: {}, after }), - ).not.toThrow(); - } + ).not.toThrow(); for (const file of ["index.js", "index.mjs", "index.cjs", "index.css"]) { - const after = snapshotDeclarationBundle({ - [file]: { type: "asset", fileName: file, source: "code" }, - }); - expect(() => assertDeclarationOnlyOutput({ before: {}, after })).toThrow( - file, - ); + const changed = { ...before, [file]: "other" }; expect(() => - assertDeclarationOnlyOutput({ before: after, after: {} }), + assertDeclarationOnlyOutput({ before, after: changed }), ).toThrow(file); } + expect(() => + assertDeclarationOnlyOutput({ before, after: { "index.d.ts": "" } }), + ).toThrow("index.js"); }); -test("the actual wrapped hook preserves its receiver and arguments while guarding direct disk writes", async () => { - const directory = outputDirectory(); - writeFileSync(path.join(directory, "index.js"), "original"); - const receiver = { marker: "original" }; - const bundle = { - "index.js": { type: "chunk", fileName: "index.js", code: "original" }, - }; - function producer(this: unknown, ...args: unknown[]) { - expect(this).not.toBe(receiver); - expect(Reflect.get(Object(this), "marker")).toBe("original"); - expect(args).toEqual([{}, bundle]); - writeFileSync( - path.join(directory, "index.d.ts"), - "export declare const value: number;", - ); - } - const guarded = guardDeclarationHook({ - hook: producer, - hookName: "writeBundle", - outputDirectories: [directory], - }); - await guarded.call(receiver, {}, bundle); - expect(Object.keys(snapshotDeclarationDirectory(directory)).sort()).toEqual([ - "index.d.ts", - "index.js", - ]); - for (const file of ["index.js", "index.mjs", "index.cjs"]) { - const mutate = guardDeclarationHook({ - hook: () => { - writeFileSync(path.join(directory, file), "changed"); - }, - hookName: "writeBundle", - outputDirectories: [directory], - }); - const failure = await mutate - .call(receiver, {}, bundle) - .catch((error: unknown) => error); - expect(failure).toBeInstanceOf(Error); - if (failure instanceof Error) expect(failure.message).toContain(file); - } +test("side-effect imports leave declarations; type and named imports stay", () => { + expect( + withoutSideEffectImports( + "index.d.ts", + 'import "./styles.css";\nimport type {} from "./types";\nimport { type A } from "./a";\nimport "./runtime";\r\nexport declare const value: A;\n', + ), + ).toBe( + 'import type {} from "./types";\nimport { type A } from "./a";\nexport declare const value: A;\n', + ); }); -test("the emission ledger rejects deferred JavaScript and foreign asset updates", () => { - const ledger = createDeclarationEmissionLedger(); - const assets = new Map(); - const host = { - emitFile: (asset: unknown) => { - if ( - typeof asset !== "object" || - asset === null || - !("fileName" in asset) || - typeof asset.fileName !== "string" - ) - throw new Error("Invalid fixture asset"); - const reference = `asset-${assets.size}`; - assets.set(reference, asset.fileName); - return reference; - }, - getFileName: (reference: unknown) => - typeof reference === "string" ? assets.get(reference) : undefined, - setAssetSource: () => undefined, - emitChunk: () => { - throw new Error("Unknown API reached host"); - }, - getNativeBuildContext: () => ({ framework: "webpack" }), - }; - const context = ledger.wrapContext(host); - // The native bundler context is withheld, not forwarded. - expect(Reflect.get(context, "getNativeBuildContext")).toBeUndefined(); - const emit = context["emitFile"]; - if (!callable(emit)) throw new Error("Missing fixture emitFile"); - expect(() => - emit({ type: "asset", fileName: "index.js", source: "deferred" }), - ).toThrow("Declaration plugin"); - const reference: unknown = emit({ - type: "asset", - fileName: "index.d.cts", - source: "declaration", +test("tsrs emits declarations with doc comments under entryRoot and leaves JavaScript output alone", async () => { + const root = scratchDirectory(); + write(root, { + "tsconfig.json": tsconfig({ declarationMap: true }), + "src/index.ts": + 'import "./styles.css";\nimport type { Shape } from "./nested/shape";\nexport * from "./nested/shape";\nconst unused = 1;\n/** Documented area. */\nexport const area = (shape: Shape): number => shape.width * shape.height;\n', + "src/nested/shape.ts": + "export interface Shape { width: number; height: number }\n", + "src/index.test.ts": "export const ignored = true;\n", + "src/styles.css": "", + "dist/index.js": "export const area = () => 0;\n", }); - expect(reference).toBe("asset-0"); - expect(() => ledger.audit()).not.toThrow(); - const update = context["setAssetSource"]; - if (!callable(update)) throw new Error("Missing fixture setAssetSource"); - expect(() => update(reference, "updated declaration")).not.toThrow(); - expect(() => update("foreign", "modified JS")).toThrow("foreign"); - expect(() => Reflect.get(context, "emitChunk")).toThrow("Declaration plugin"); - assets.set("asset-0", "index.js"); - expect(() => ledger.audit()).toThrow("Declaration plugin"); -}); - -test("a shared emitter ledger audits deferred references in output hooks", async () => { - const ledger = createDeclarationEmissionLedger(); - let resolved = "index.d.ts"; - const host = { - emitFile: () => "deferred-asset", - getFileName: () => resolved, - }; - const context = ledger.wrapContext(host); - const emit = context["emitFile"]; - if (!callable(emit)) throw new Error("Missing fixture emitFile"); - emit({ type: "asset", fileName: "index.d.ts" }); - const guarded = guardDeclarationHook({ - hook: () => undefined, - hookName: "generateBundle", - outputDirectories: [], - ledger, + const warnings: string[] = []; + await emitDeclarations({ + root, + output: path.join(root, "dist"), + options: reviewedViteDtsOptions({ + include: ["src/**/*"], + exclude: ["src/**/*.test.ts"], + entryRoot: "src", + compilerOptions: { declarationMap: false }, + }), + warn: (message) => warnings.push(message), }); - await guarded.call(host, {}, {}); - resolved = "index.mjs"; - const failed = await guarded - .call(host, {}, {}) - .catch((error: unknown) => error); - expect(failed).toBeInstanceOf(Error); - if (failed instanceof Error) - expect(failed.message).toContain("Declaration plugin"); -}); + expect( + readdirSync(path.join(root, "dist"), { recursive: true }).toSorted((a, b) => + String(a).localeCompare(String(b)), + ), + ).toEqual(["index.d.ts", "index.js", "nested", "nested/shape.d.ts"]); + expect(readFileSync(path.join(root, "dist/index.d.ts"), "utf8")).toBe( + 'import type { Shape } from "./nested/shape";\nexport * from "./nested/shape";\n/** Documented area. */\nexport declare const area: (shape: Shape) => number;\n', + ); + expect(readFileSync(path.join(root, "dist/index.js"), "utf8")).toBe( + "export const area = () => 0;\n", + ); + expect(warnings).toEqual([]); +}, 60_000); -test("wrapped bundle mutations and dynamic hook return values fail", async () => { - const bundle = { - "index.js": { type: "chunk", fileName: "index.js", code: "original" }, - }; - const mutate = guardDeclarationHook({ - hook: () => { - bundle["index.js"].code = "changed"; - }, - hookName: "generateBundle", - outputDirectories: [], +test("type errors warn and still emit; path aliases and inputs outside entryRoot fail", async () => { + const root = scratchDirectory(); + write(root, { + "tsconfig.json": tsconfig(), + "src/index.ts": 'export const value: number = "text";\n', + "other/extra.ts": "export const extra = 1;\n", }); - const mutated = await mutate({}, bundle).catch((error: unknown) => error); - expect(mutated).toBeInstanceOf(Error); - if (mutated instanceof Error) expect(mutated.message).toContain("index.js"); - const dynamic = guardDeclarationHook({ - hook: () => ({ code: "replacement" }), - hookName: "transform", - outputDirectories: [], + const output = path.join(root, "dist"); + const warnings: string[] = []; + await emitDeclarations({ + root, + output, + options: reviewedViteDtsOptions(), + warn: (message) => warnings.push(message), }); - const returned = await dynamic("original", "src/index.ts").catch( - (error: unknown) => error, + expect(readFileSync(path.join(output, "index.d.ts"), "utf8")).toBe( + "export declare const value: number;\n", ); - expect(returned).toBeInstanceOf(Error); - if (returned instanceof Error) - expect(returned.message).toContain("dynamic build change"); -}); - -test("bundle snapshots read emitted bytes and ignore output metadata getters", () => { - const chunk = { - type: "chunk", - fileName: "index.js", - code: "original", - get modules() { - throw new Error("output metadata getter must not run"); - }, - }; - const map = { type: "asset", fileName: "index.js.map", source: "AAAA" }; - const bundle = { "index.js": chunk, "index.js.map": map }; - const before = snapshotDeclarationBundle(bundle); - expect(() => - assertDeclarationOnlyOutput({ - before, - after: snapshotDeclarationBundle(bundle), + expect(warnings.join("\n")).toContain("TS2322"); + await assert.rejects( + emitDeclarations({ + root, + output, + options: reviewedViteDtsOptions({ + include: ["src/**/*", "other/**/*"], + entryRoot: "src", + }), + warn: () => undefined, }), - ).not.toThrow(); - map.source = "BBBB"; - expect(() => - assertDeclarationOnlyOutput({ - before, - after: snapshotDeclarationBundle(bundle), - }), - ).toThrow("index.js.map"); -}); - -test("object hooks keep only a static id filter and a guarded handler", () => { - const handler = () => undefined; - expect(declarationHookParts(handler)).toEqual({ handler }); - expect(declarationHookParts({ filter: undefined, handler })).toEqual({ - handler, + /Declaration emit failed/, + ); + write(root, { + "tsconfig.json": tsconfig({ paths: { "#lib/*": ["./src/*"] } }), }); - const include = /\.ts$/; - expect( - declarationHookParts({ filter: { id: { include } }, handler }), - ).toEqual({ handler, filter: { id: { include } } }); - expect( - declarationHookParts({ - filter: { id: { include: ["a.ts", /b/], exclude: "c.ts" } }, - handler, + await assert.rejects( + emitDeclarations({ + root, + output, + options: reviewedViteDtsOptions(), + warn: () => undefined, }), - ).toEqual({ - handler, - filter: { id: { include: ["a.ts", /b/], exclude: "c.ts" } }, - }); - for (const hook of [ - { handler, order: "pre" }, - { handler, filter: { code: { include: "x" } } }, - { handler, filter: { id: { include: () => true } } }, - { handler, filter: { id: { include: [/a/, 1] } } }, - { handler, filter: { id: /a/ } }, - "transform", - ]) - expect(() => declarationHookParts(hook)).toThrow(); - const accessor = { handler }; - Object.defineProperty(accessor, "filter", { - enumerable: true, - get: () => ({ id: { include: /a/ } }), - }); - expect(() => declarationHookParts(accessor)).toThrow("accessors"); -}); + /compilerOptions\.paths/, + ); +}, 60_000); diff --git a/packages/oxlint-config/src/publish-build-target-vite-dts.ts b/packages/oxlint-config/src/publish-build-target-vite-dts.ts index fb2961f1..00fa1d70 100644 --- a/packages/oxlint-config/src/publish-build-target-vite-dts.ts +++ b/packages/oxlint-config/src/publish-build-target-vite-dts.ts @@ -2,11 +2,6 @@ import { createHash } from "node:crypto"; import { lstatSync, readdirSync, readFileSync } from "node:fs"; import path from "node:path"; -export const reviewedViteDtsVersions = { - "vite-plugin-dts": "5.1.2", - "unplugin-dts": "1.1.2", -} as const; - const record = (value: unknown): value is Record => typeof value === "object" && value !== null && !Array.isArray(value); @@ -15,12 +10,12 @@ const staticEntries = (value: unknown): [string, unknown][] => { ? Object.getPrototypeOf(value) : undefined; if (!record(value) || (prototype !== Object.prototype && prototype !== null)) - throw new Error("Declaration plugin options must be plain static records"); + throw new Error("Declaration options must be plain static records"); return Reflect.ownKeys(value).map((key) => { const descriptor = Object.getOwnPropertyDescriptor(value, key); if (typeof key !== "string" || !descriptor || !("value" in descriptor)) throw new Error( - "Declaration plugin options cannot contain accessors or symbols", + "Declaration options cannot contain accessors or symbols", ); return [key, descriptor.value]; }); @@ -35,25 +30,22 @@ const relativePattern = (value: unknown): string => { value.includes("\\") || value.split("/").includes("..") ) - throw new Error("Declaration plugin paths must stay within the package"); + throw new Error("Declaration paths must stay within the package"); return value; }; const patterns = (value: unknown) => { - if (typeof value === "string") return relativePattern(value); + if (typeof value === "string") return Object.freeze([relativePattern(value)]); if (!Array.isArray(value) || value.length === 0) - throw new Error("Declaration plugin include/exclude must be static paths"); + throw new Error("Declaration include/exclude must be static paths"); return Object.freeze(value.map(relativePattern)); }; -/** Closed factory options; callbacks, custom compilers and output relocation are unsupported. */ +/** Closed helper options; callbacks, custom compilers and output relocation are unsupported. */ export type ReviewedViteDtsOptions = { - include?: string | readonly string[]; - exclude?: string | readonly string[]; + include?: readonly string[]; + exclude?: readonly string[]; entryRoot?: string; - pathsToAliases?: boolean; compilerOptions?: Readonly<{ declarationMap: false }>; - strictOutput?: true; - declarationOnly?: false; }; export const reviewedViteDtsOptions = (value: unknown = {}) => { const result: ReviewedViteDtsOptions = {}; @@ -66,11 +58,6 @@ export const reviewedViteDtsOptions = (value: unknown = {}) => { case "entryRoot": result.entryRoot = relativePattern(entry); break; - case "pathsToAliases": - if (typeof entry !== "boolean") - throw new Error("pathsToAliases must be a static boolean"); - result.pathsToAliases = entry; - break; case "compilerOptions": { const entries = staticEntries(entry); if ( @@ -84,20 +71,8 @@ export const reviewedViteDtsOptions = (value: unknown = {}) => { result.compilerOptions = Object.freeze({ declarationMap: false }); break; } - case "strictOutput": - if (entry !== true) - throw new Error("Declaration output containment cannot be disabled"); - result.strictOutput = true; - break; - case "declarationOnly": - if (entry !== false) - throw new Error( - "Declaration plugin cannot remove JavaScript outputs", - ); - result.declarationOnly = false; - break; default: - throw new Error(`Unreviewed declaration plugin option: ${key}`); + throw new Error(`Unreviewed declaration option: ${key}`); } } return Object.freeze(result); @@ -122,7 +97,7 @@ const safeOutputPath = (file: string) => { ) || file.split("/").includes("..") ) - throw new Error("Declaration plugin emitted an unsafe output path"); + throw new Error("Declaration emit produced an unsafe output path"); }; /** Capture bytes now; later mutations cannot alter this frozen snapshot. */ @@ -153,37 +128,11 @@ export const snapshotDeclarationDirectory = ( return Object.freeze(result); }; -export const snapshotDeclarationBundle = ( - bundle: unknown, -): DeclarationOutputSnapshot => { - const result: Record = {}; - for (const [file, entry] of staticEntries(bundle)) { - safeOutputPath(file); - if ( - !record(entry) || - entry["fileName"] !== file || - !["asset", "chunk"].includes(String(entry["type"])) - ) - throw new Error("Invalid declaration bundle entry"); - if (declarationPath(file) && entry["type"] !== "asset") - throw new Error("Declarations must be emitted as assets"); - const type = entry["type"]; - const bytes = type === "chunk" ? entry["code"] : entry["source"]; - if (typeof bytes !== "string" && !(bytes instanceof Uint8Array)) - throw new Error("Declaration bundle output must contain text or bytes"); - Object.defineProperty(result, file, { - value: `${String(type)}:${hash(bytes)}`, - enumerable: true, - }); - } - return Object.freeze(result); -}; - type DeclarationOutputOptions = { before: DeclarationOutputSnapshot; after: DeclarationOutputSnapshot; }; -/** This plugin may only add or change declaration files; every existing non-declaration is immutable. */ +/** Declaration emit may only add or change declaration files; every existing non-declaration is immutable. */ export const assertDeclarationOnlyOutput = ({ before, after, @@ -192,276 +141,7 @@ export const assertDeclarationOnlyOutput = ({ safeOutputPath(file); if (!declarationPath(file) && before[file] !== after[file]) throw new Error( - `Declaration plugin changed non-declaration output: ${file}`, - ); - } -}; - -// Optional capabilities the plugin probes and handles as absent: withholding -// the native bundler context keeps it on its bundler-neutral path. -const withheldContextCapabilities = new Set(["getNativeBuildContext"]); -const passiveContextMethods = new Set([ - "warn", - "error", - "info", - "debug", - "addWatchFile", - "getWatchFiles", - "parse", - "resolve", - "getModuleInfo", - "getModuleIds", - "getFileName", -]); -const contextData = (value: unknown): unknown => { - if ( - value === null || - ["string", "number", "boolean", "undefined"].includes(typeof value) - ) - return value; - if (Array.isArray(value)) return Object.freeze(value.map(contextData)); - const snapshot = {}; - Object.setPrototypeOf(snapshot, null); - for (const [key, entry] of staticEntries(value)) - Object.defineProperty(snapshot, key, { - value: contextData(entry), - enumerable: true, - }); - return Object.freeze(snapshot); -}; -const declarationAssetName = (value: unknown) => { - if (typeof value !== "string") - throw new Error("Declaration plugin requires an explicit asset fileName"); - safeOutputPath(value); - if (!declarationPath(value)) - throw new Error( - `Declaration plugin emitted non-declaration asset: ${value}`, - ); - return value; -}; - -/** One build owns all emitter references, including assets materialized after the producer hook. */ -export const createDeclarationEmissionLedger = () => { - const references = new Map< - string, - { fileName: string; getFileName: () => unknown } - >(); - const wrapContext = (host: unknown) => { - const receiver = record(host) ? host : {}; - const hostMethod = (name: string) => { - const method: unknown = receiver[name]; - if (typeof method !== "function") - throw new Error(`Declaration plugin host method unavailable: ${name}`); - return (...args: unknown[]): unknown => - Reflect.apply(method, receiver, args); - }; - const methods = new Map unknown>(); - methods.set("emitFile", (asset: unknown) => { - const entries = staticEntries(asset); - if (!record(asset) || asset["type"] !== "asset") - throw new Error("Declaration plugin may only emit assets"); - const fileName = declarationAssetName(asset["fileName"]); - for (const [, value] of entries) - if (typeof value === "function") - throw new Error("Declaration plugin asset metadata must be static"); - const source = asset["source"]; - if ( - source !== undefined && - typeof source !== "string" && - !(source instanceof Uint8Array) - ) - throw new Error( - "Declaration plugin asset source must be text or bytes", - ); - const getFileName = hostMethod("getFileName"); - const emitted: Record = {}; - for (const [key, value] of entries) { - const copied = - value instanceof Uint8Array - ? new Uint8Array(value) - : contextData(value); - Object.defineProperty(emitted, key, { - value: copied, - enumerable: true, - }); - } - const reference = hostMethod("emitFile")(emitted); - if (typeof reference !== "string" || references.has(reference)) - throw new Error( - "Declaration plugin emitted an invalid asset reference", - ); - references.set(reference, { - fileName, - getFileName: () => getFileName(reference), - }); - return reference; - }); - methods.set("setAssetSource", (reference: unknown, source: unknown) => { - if (typeof reference !== "string" || !references.has(reference)) - throw new Error( - "Declaration plugin cannot update a foreign asset reference", - ); - if (typeof source !== "string" && !(source instanceof Uint8Array)) - throw new Error( - "Declaration plugin asset source must be text or bytes", - ); - return hostMethod("setAssetSource")(reference, source); - }); - const surrogate: Record = {}; - Object.setPrototypeOf(surrogate, null); - return new Proxy(surrogate, { - get: (_target, key) => { - if (typeof key !== "string") - throw new Error("Declaration plugin context symbols are unsupported"); - const method = methods.get(key); - if (method !== undefined) return method; - if (passiveContextMethods.has(key)) { - const forwarded = hostMethod(key); - methods.set(key, forwarded); - return forwarded; - } - if (withheldContextCapabilities.has(key)) return undefined; - const value: unknown = receiver[key]; - if (key === "meta") return contextData(value); - if ( - value === null || - ["string", "number", "boolean"].includes(typeof value) - ) - return value; - throw new Error( - `Declaration plugin context capability is unsupported: ${key}`, - ); - }, - set: () => { - throw new Error("Declaration plugin context is readonly"); - }, - defineProperty: () => { - throw new Error("Declaration plugin context is readonly"); - }, - setPrototypeOf: () => { - throw new Error("Declaration plugin context is readonly"); - }, - }); - }; - const audit = () => { - for (const [reference, emission] of references) { - const resolved = declarationAssetName(emission.getFileName()); - if (resolved !== emission.fileName) - throw new Error( - `Declaration plugin asset reference changed filename: ${reference}`, - ); - } - }; - return { wrapContext, audit }; -}; -export type DeclarationEmissionLedger = ReturnType< - typeof createDeclarationEmissionLedger ->; - -type IdPattern = string | RegExp | (string | RegExp)[]; -type DeclarationHookFilter = { - id: { include?: IdPattern; exclude?: IdPattern }; -}; - -const idPattern = (value: unknown): IdPattern | undefined => { - if (value === undefined || typeof value === "string") return value; - if (value instanceof RegExp) return value; - if ( - Array.isArray(value) && - value.every( - (entry): entry is string | RegExp => - typeof entry === "string" || entry instanceof RegExp, - ) - ) - return value; - throw new Error("Declaration hook filters may only name static ids"); -}; - -const dataEntries = (value: Record, keys: string[]) => - Reflect.ownKeys(value).map((key) => { - const descriptor = Object.getOwnPropertyDescriptor(value, key); - if (typeof key !== "string" || !keys.includes(key) || !descriptor) - throw new Error("Invalid reviewed declaration hook"); - if (!("value" in descriptor)) - throw new Error("Declaration hooks cannot contain accessors"); - const entry: unknown = descriptor.value; - return [key, entry] as const; - }); - -/** - * Split a plugin hook into its function and the static id filter of the - * object form; a filter only narrows which modules reach the handler. - */ -export const declarationHookParts = ( - value: unknown, -): { handler: unknown; filter?: DeclarationHookFilter } => { - if (typeof value === "function") return { handler: value }; - if (!record(value)) throw new Error("Invalid reviewed declaration hook"); - const parts = Object.fromEntries(dataEntries(value, ["handler", "filter"])); - const filter = parts["filter"]; - if (filter === undefined) return { handler: parts["handler"] }; - if (!record(filter)) throw new Error("Invalid reviewed declaration hook"); - const id = Object.fromEntries(dataEntries(filter, ["id"]))["id"]; - if (!record(id)) throw new Error("Invalid reviewed declaration hook"); - const idFilter = Object.fromEntries(dataEntries(id, ["include", "exclude"])); - const ids: DeclarationHookFilter["id"] = {}; - const include = idPattern(idFilter["include"]); - const exclude = idPattern(idFilter["exclude"]); - if (include !== undefined) ids.include = include; - if (exclude !== undefined) ids.exclude = exclude; - return { handler: parts["handler"], filter: { id: ids } }; -}; - -type GuardDeclarationHookOptions = { - hook: unknown; - hookName: string; - outputDirectories: readonly string[]; - ledger?: DeclarationEmissionLedger; -}; -/** Substitute a closed producer context while guarding the actual hook invocation. */ -export const guardDeclarationHook = ({ - hook, - hookName, - outputDirectories, - ledger = createDeclarationEmissionLedger(), -}: GuardDeclarationHookOptions) => { - if (typeof hook !== "function") - throw new Error("Invalid reviewed declaration hook"); - const producer = hook; - async function guarded(this: unknown, ...args: unknown[]) { - const beforeDirectories = outputDirectories.map( - snapshotDeclarationDirectory, - ); - const bundle = ["generateBundle", "writeBundle"].includes(hookName) - ? args.at(1) - : undefined; - const beforeBundle = - bundle === undefined ? undefined : snapshotDeclarationBundle(bundle); - const result: unknown = await Reflect.apply( - producer, - ledger.wrapContext(this), - args, - ); - if (result !== undefined) - throw new Error( - `Declaration plugin hook ${hookName} returned a dynamic build change`, + `Declaration emit changed non-declaration output: ${file}`, ); - if (beforeBundle !== undefined) - assertDeclarationOnlyOutput({ - before: beforeBundle, - after: snapshotDeclarationBundle(bundle), - }); - for (const [index, directory] of outputDirectories.entries()) { - const before = beforeDirectories.at(index); - if (before === undefined) - throw new Error("Missing declaration output snapshot"); - assertDeclarationOnlyOutput({ - before, - after: snapshotDeclarationDirectory(directory), - }); - } - if (["generateBundle", "writeBundle"].includes(hookName)) ledger.audit(); - return result; } - return guarded; }; diff --git a/scripts/check-publish-artifact-profiles.ts b/scripts/check-publish-artifact-profiles.ts index c8155db0..6f96c61d 100644 --- a/scripts/check-publish-artifact-profiles.ts +++ b/scripts/check-publish-artifact-profiles.ts @@ -16,29 +16,19 @@ if (process.env["CI"] !== "true") const repository = fileURLToPath(new URL("../", import.meta.url)); const fixture = mkdtempSync(path.join(tmpdir(), "stll-vite-dts-profile-")); try { + // The consumer installs Vite only; declarations come from the helper's own tsrs. writeFileSync( path.join(fixture, "package.json"), JSON.stringify({ name: "reviewed-dts-profile", private: true, type: "module", - devDependencies: { - vite: "8.3.7", - "vite-plugin-dts": "5.1.2", - "unplugin-dts": "1.1.2", - typescript: "6.0.3", - }, + devDependencies: { vite: "8.3.7" }, }), ); const install = spawnSync( "npm", - [ - "install", - "--legacy-peer-deps", - "--ignore-scripts", - "--no-audit", - "--no-fund", - ], + ["install", "--ignore-scripts", "--no-audit", "--no-fund"], { cwd: fixture, encoding: "utf8", @@ -59,8 +49,9 @@ try { mkdirSync(path.join(fixture, "src")); writeFileSync( path.join(fixture, "src", "index.ts"), - "export const profileValue: number = 42;\n", + 'import "./styles.css";\n/** The profile value. */\nexport const profileValue: number = 42;\n', ); + writeFileSync(path.join(fixture, "src", "styles.css"), "a { color: red }\n"); writeFileSync( path.join(fixture, "tsconfig.json"), JSON.stringify({ @@ -68,7 +59,7 @@ try { target: "ES2022", module: "ESNext", moduleResolution: "Bundler", - declaration: true, + noEmit: true, skipLibCheck: true, }, include: ["src"], @@ -78,97 +69,38 @@ try { path.join(fixture, "vite.config.mjs"), `import { defineConfig } from 'vite'; import { declarationOnlyDts } from '@stll/oxlint-config/declaration-only-dts'; -export default defineConfig({ plugins: [declarationOnlyDts({ directory: import.meta.dirname, include: ['src/**/*'], entryRoot: 'src', compilerOptions: { declarationMap: false } })], build: { target: 'es2022', sourcemap: true, lib: { entry: 'src/index.ts', formats: ['es'], fileName: 'index' } } });\n`, +export default defineConfig({ plugins: [declarationOnlyDts({ directory: import.meta.dirname, include: ['src/**/*'], entryRoot: 'src', compilerOptions: { declarationMap: false } })], build: { target: 'es2022', sourcemap: true, lib: { entry: 'src/index.ts', formats: ['es', 'cjs'], fileName: 'index' } } });\n`, ); writeFileSync( path.join(fixture, "run-profile.mjs"), `import { createRequire } from 'node:module'; -import { readFileSync, readdirSync, writeFileSync } from 'node:fs'; +import { readFileSync, readdirSync } from 'node:fs'; import path from 'node:path'; const require = createRequire(import.meta.url); -const mutate = process.argv.includes('--mutate-dts'); -const emitJavaScript = process.argv.includes('--emit-js'); -const emitDeclaration = process.argv.includes('--emit-declaration'); -if (mutate || emitJavaScript || emitDeclaration) { - const loaded = require('vite-plugin-dts'); - const factory = loaded.default; - loaded.default = options => { - const plugin = factory(options); - if (mutate) { - const original = plugin.writeBundle; - plugin.writeBundle = async function (...args) { - await original.apply(this, args); - const output = path.join(import.meta.dirname, 'dist'); - const file = readdirSync(output).find(file => /\\.(?:js|mjs|cjs)$/.test(file)); - if (!file) throw new Error('missing JavaScript output before declaration mutation'); - writeFileSync(path.join(output, file), 'export const changedByDeclaration = true;'); - }; - } else { - const original = plugin.buildStart; - const handler = typeof original === 'function' ? original : original?.handler; - if (original !== undefined && typeof handler !== 'function') throw new Error('Unsupported declaration buildStart hook'); - plugin.buildStart = async function (...args) { - if (handler) await handler.apply(this, args); - this.emitFile({ type: 'asset', fileName: emitJavaScript ? 'extra.js' : 'index-extra.d.ts', source: emitJavaScript ? 'export const extra = true;' : 'export declare const extra: boolean;' }); - }; - } - return plugin; - }; -} +for (const name of ['typescript', 'vite-plugin-dts', 'unplugin-dts']) + try { require.resolve(name); throw new Error(name + ' must not be installed'); } catch (error) { if (error.code !== 'MODULE_NOT_FOUND') throw error; } const { build } = await import('vite'); -await build({ root: import.meta.dirname }); +await build({ root: import.meta.dirname, logLevel: 'warn' }); const output = path.join(import.meta.dirname, 'dist'); const files = readdirSync(output); -if (!files.includes('index.d.ts') || !files.some(file => /\\.(?:js|mjs|cjs)$/.test(file))) throw new Error('actual build did not emit JS and declarations'); -if (!readFileSync(path.join(output, 'index.d.ts'), 'utf8').includes('profileValue')) throw new Error('missing actual generated declaration'); -if (emitDeclaration && (!files.includes('index-extra.d.ts') || !readFileSync(path.join(output, 'index-extra.d.ts'), 'utf8').includes('extra: boolean'))) throw new Error('missing extra declaration emitted through buildStart'); +if (!files.includes('index.d.ts') || !files.some(file => /\\.(?:js|mjs|cjs)$/.test(file))) throw new Error('actual build did not emit JS and declarations: ' + files.join(', ')); +const declaration = readFileSync(path.join(output, 'index.d.ts'), 'utf8'); +if (declaration !== '/** The profile value. */\\nexport declare const profileValue: number;\\n') throw new Error('unexpected declaration output: ' + declaration); `, ); - for (const mode of [ - "normal", - "mutate-dts", - "emit-js", - "emit-declaration", - ] as const) { - const args = [path.join(fixture, "run-profile.mjs")]; - if (mode !== "normal") args.push(`--${mode}`); - const result = spawnSync("node", args, { - cwd: fixture, - encoding: "utf8", - timeout: 60_000, - maxBuffer: 1024 * 1024, - }); - if (result.error) throw result.error; - if ( - (mode === "normal" || mode === "emit-declaration") && - result.status !== 0 - ) - throw new Error( - `Reviewed actual Vite/dts build failed: ${result.stderr}`, - ); - if ( - mode === "mutate-dts" && - (result.status === 0 || - !result.stderr.includes( - "Declaration plugin changed non-declaration output", - )) - ) - throw new Error( - `Actual declaration hook mutation was not rejected: ${result.stderr}`, - ); - if ( - mode === "emit-js" && - (result.status === 0 || - !/Declaration plugin|declaration-only (?:plugin|output|asset|hook|profile)/.test( - result.stderr, - )) - ) - throw new Error( - `Actual declaration hook JavaScript asset emission was not rejected: ${result.stderr}`, - ); - } + const result = spawnSync("node", [path.join(fixture, "run-profile.mjs")], { + cwd: fixture, + encoding: "utf8", + timeout: 120_000, + maxBuffer: 1024 * 1024, + }); + if (result.error) throw result.error; + if (result.status !== 0) + throw new Error( + `Reviewed actual Vite declaration build failed: ${result.stderr}`, + ); process.stdout.write( - "Reviewed Vite/dts actual build and JavaScript immutability passed\n", + "Reviewed Vite declaration build without TypeScript passed\n", ); } finally { rmSync(fixture, { recursive: true, force: true }); From 074338652d50483a4c8d177f4387930a7e47eb4b Mon Sep 17 00:00:00 2001 From: jan-kubica Date: Wed, 18 Nov 2026 10:30:52 +0100 Subject: [PATCH 2/2] build(oxlint-config): emit declarations with the tsrs generator tsdown's tsgo generator only falls back to a tsrs binary path when TypeScript 7.0 is installed, which came in through vite-plugin-dts. With that dependency gone the build selects the tsrs generator directly. --- README.md | 4 ++-- packages/oxlint-config/tsdown.config.ts | 9 +-------- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 13c4b71a..4bd7afcb 100644 --- a/README.md +++ b/README.md @@ -345,8 +345,8 @@ Every repository that uses these configs follows one toolchain: shared list of such tools. - **Declarations** built with tsdown use `dts: { generator: "oxc" }`, which needs explicit types on exported declarations. A package that cannot provide - them points tsdown at tsrs instead: - `dts: { generator: "tsgo", tsgo: { path: } }`. + them points tsdown at tsrs instead: `dts: { generator: "tsrs" }`. The + `tsgo` generator with a tsrs binary path needs an installed TypeScript 7.0. - **Compiler-API code does not import `typescript`.** Programs, the type checker and tsconfig resolution use `tsrs` `0.21.0-ts7.1.0-beta` through its async API only (`import { API } from "tsrs/async"`; close diff --git a/packages/oxlint-config/tsdown.config.ts b/packages/oxlint-config/tsdown.config.ts index 34626c64..79f60b51 100644 --- a/packages/oxlint-config/tsdown.config.ts +++ b/packages/oxlint-config/tsdown.config.ts @@ -1,15 +1,8 @@ import { readFileSync } from "node:fs"; -import { createRequire } from "node:module"; -import path from "node:path"; import { defineConfig } from "tsdown"; // About 200 exported declarations here rely on inferred types, which the oxc // generator cannot emit; tsrs emits them from the program instead. -const tsrs = path.join( - path.dirname(createRequire(import.meta.url).resolve("tsrs/package.json")), - "bin/tsrs", -); - export default defineConfig({ define: { STLL_RUST_TEMPLATES: JSON.stringify( @@ -49,7 +42,7 @@ export default defineConfig({ "src/wasi-loader-normalizer-cli.ts", ], format: ["esm", "cjs"], - dts: { generator: "tsgo", tsgo: { path: tsrs } }, + dts: { generator: "tsrs" }, clean: true, sourcemap: true, hash: false,