File tree Expand file tree Collapse file tree 4 files changed +37
-2
lines changed
Expand file tree Collapse file tree 4 files changed +37
-2
lines changed Original file line number Diff line number Diff line change @@ -148,6 +148,17 @@ This is especially useful when you have a single `tsconfig.json` for multiple pr
148148
149149---
150150
151+ ### newContext
152+
153+ If ` true ` , the plugin will create a new isolated context for each build,
154+ ensuring that previously generated ` .d.ts ` code and caches are not reused.
155+
156+ By default, the plugin may reuse internal caches or incremental build artifacts
157+ to speed up repeated builds. Enabling this option forces a clean context,
158+ guaranteeing that all type definitions are generated from scratch.
159+
160+ ---
161+
151162### tsgo
152163
153164** [ Experimental] ** Enables DTS generation using [ ` tsgo ` ] ( https://github.com/microsoft/typescript-go ) .
Original file line number Diff line number Diff line change @@ -52,6 +52,7 @@ export function createGeneratePlugin({
5252 parallel,
5353 eager,
5454 tsgo,
55+ newContext,
5556} : Pick <
5657 OptionsResolved ,
5758 | 'cwd'
@@ -64,6 +65,7 @@ export function createGeneratePlugin({
6465 | 'parallel'
6566 | 'eager'
6667 | 'tsgo'
68+ | 'newContext'
6769> ) : Plugin {
6870 const dtsMap : DtsMap = new Map < string , TsModule > ( )
6971
@@ -105,7 +107,9 @@ export function createGeneratePlugin({
105107 tsgoDist = await runTsgo ( cwd , tsconfig )
106108 } else if ( ! parallel && ( ! isolatedDeclarations || vue ) ) {
107109 tscModule = await import ( './tsc/index.ts' )
108- tscContext = eager ? undefined : tscModule . createContext ( )
110+ if ( newContext ) {
111+ tscContext = tscModule . createContext ( )
112+ }
109113 }
110114
111115 if ( ! Array . isArray ( options . input ) ) {
@@ -279,7 +283,10 @@ export function createGeneratePlugin({
279283 if ( ! debug . enabled && tsgoDist ) {
280284 await rm ( tsgoDist , { recursive : true , force : true } ) . catch ( ( ) => { } )
281285 }
282- tscContext = tsgoDist = undefined
286+ tsgoDist = undefined
287+ if ( newContext ) {
288+ tscContext = undefined
289+ }
283290 } ,
284291 }
285292}
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ import { createFakeJsPlugin } from './fake-js.ts'
55import { createGeneratePlugin } from './generate.ts'
66import { resolveOptions , type Options } from './options.ts'
77import { createDtsResolvePlugin } from './resolver.ts'
8+ import { createContext , type TscContext } from './tsc/index.ts'
89import type { Plugin } from 'rolldown'
910
1011export {
@@ -35,8 +36,10 @@ export function dts(options: Options = {}): Plugin[] {
3536}
3637
3738export {
39+ createContext ,
3840 createFakeJsPlugin ,
3941 createGeneratePlugin ,
4042 resolveOptions ,
4143 type Options ,
44+ type TscContext ,
4245}
Original file line number Diff line number Diff line change @@ -130,6 +130,18 @@ export interface Options {
130130 * `tsconfigRaw` and `isolatedDeclarations` options will be ignored when this option is enabled.
131131 */
132132 tsgo ?: boolean
133+
134+ /**
135+ * If `true`, the plugin will create a new isolated context for each build,
136+ * ensuring that previously generated `.d.ts` code and caches are not reused.
137+ *
138+ * By default, the plugin may reuse internal caches or incremental build artifacts
139+ * to speed up repeated builds. Enabling this option forces a clean context,
140+ * guaranteeing that all type definitions are generated from scratch.
141+ *
142+ * **Default:** `false`
143+ */
144+ newContext ?: boolean
133145}
134146
135147type Overwrite < T , U > = Pick < T , Exclude < keyof T , keyof U > > & U
@@ -160,6 +172,7 @@ export function resolveOptions({
160172 parallel = false ,
161173 eager = false ,
162174 tsgo = false ,
175+ newContext = false ,
163176} : Options ) : OptionsResolved {
164177 let resolvedTsconfig : TsConfigJsonResolved | undefined
165178 if ( tsconfig === true || tsconfig == null ) {
@@ -222,5 +235,6 @@ export function resolveOptions({
222235 parallel,
223236 eager,
224237 tsgo,
238+ newContext,
225239 }
226240}
You can’t perform that action at this time.
0 commit comments