Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: experimental isolated declaration support #411

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
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
11 changes: 11 additions & 0 deletions build.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { transform } from "esbuild/lib/main";
import { defineBuildConfig } from "./src";

export default defineBuildConfig({
rollup: {
// https://github.com/unplugin/unplugin-isolated-decl
isolatedDecl: {
transformer: "oxc",
},
},
});
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"rollup-plugin-dts": "^6.1.1",
"scule": "^1.3.0",
"ufo": "^1.5.3",
"unplugin-isolated-decl": "^0.4.0",
"untyped": "^1.4.2"
},
"devDependencies": {
Expand Down
125 changes: 125 additions & 0 deletions pnpm-lock.yaml

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

1 change: 1 addition & 0 deletions src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ async function _build(
compilerOptions: { preserveSymlinks: false },
respectExternal: true,
},
isolatedDecl: false, // Experimental
},
},
) as BuildOptions;
Expand Down
2 changes: 1 addition & 1 deletion src/builders/rollup/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export async function rollupBuild(ctx: BuildContext): Promise<void> {
}

// Types
if (ctx.options.declaration) {
if (ctx.options.declaration && !ctx.options.rollup.isolatedDecl) {
rollupOptions.plugins = [
...rollupOptions.plugins,
dts(ctx.options.rollup.dts),
Expand Down
6 changes: 6 additions & 0 deletions src/builders/rollup/config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { OutputOptions, PreRenderedChunk } from "rollup";
import commonjs from "@rollup/plugin-commonjs";
import isolatedDeclPlugin from "unplugin-isolated-decl/rolldown";
import { nodeResolve } from "@rollup/plugin-node-resolve";
import alias from "@rollup/plugin-alias";
import replace from "@rollup/plugin-replace";
Expand Down Expand Up @@ -113,6 +114,11 @@ export function getRollupOptions(ctx: BuildContext): RollupOptions {
...ctx.options.rollup.resolve,
}),

// Should be before esbuild to preserve source
ctx.options.declaration &&
ctx.options.rollup.isolatedDecl &&
isolatedDeclPlugin(ctx.options.rollup.isolatedDecl),

ctx.options.rollup.json &&
JSONPlugin({
...ctx.options.rollup.json,
Expand Down
10 changes: 10 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import type { RollupAliasOptions } from "@rollup/plugin-alias";
import type { RollupNodeResolveOptions } from "@rollup/plugin-node-resolve";
import type { RollupJsonOptions } from "@rollup/plugin-json";
import type { Options as RollupDtsOptions } from "rollup-plugin-dts";
import type { Options as RollupDeclOptions } from "unplugin-isolated-decl";
import type commonjs from "@rollup/plugin-commonjs";
import type { Jiti, JitiOptions } from "jiti";
import type { EsbuildOptions } from "./builders/rollup/plugins/esbuild";
Expand Down Expand Up @@ -136,6 +137,15 @@ export interface RollupBuildOptions {
* Read more: [rollup-plugin-dts](https://www.npmjs.com/package/rollup-plugin-dts)
*/
dts: RollupDtsOptions;

/**
* Isolated declarations plugin options
*
* @experimental Set to an empty object to enable the plugin and disable `dts`.
*
* Read more: [unplugin-isolated-decl](https://github.com/unplugin/unplugin-isolated-decl)
*/
isolatedDecl: RollupDeclOptions | false;
}

export interface BuildOptions {
Expand Down
Loading