Skip to content

Commit ae925ae

Browse files
committed
feat: support dts filter for transform entries
1 parent 5543925 commit ae925ae

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/builders/transform.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,12 +201,17 @@ async function transformModule(entryPath: string, entry: TransformEntry, entryDi
201201

202202
sourceText = magicString.toString();
203203

204+
let emitDeclaration = entry.dts;
205+
if (typeof emitDeclaration === "function") {
206+
emitDeclaration = await emitDeclaration(entryPath);
207+
}
208+
204209
const transformed = transformSync(entryPath, sourceText, {
205210
...entry.oxc,
206211
...sourceOptions,
207212
cwd: dirname(entryPath),
208213
typescript: {
209-
declaration: { stripInternal: true },
214+
declaration: emitDeclaration ? { stripInternal: true } : undefined,
210215
...entry.oxc?.typescript,
211216
},
212217
});

src/types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@ export type TransformEntry = _BuildEntry & {
9696
* A filter function to exclude files from being transformed.
9797
*/
9898
filter?: (filePath: string) => boolean | Promise<boolean>;
99+
100+
/**
101+
* If sets to `false`, or if the function returns `false`, declaration files won't be emitted for the module.
102+
*/
103+
dts?: boolean | ((filePath: string) => boolean | Promise<boolean>);
99104
};
100105

101106
export type BuildEntry = BundleEntry | TransformEntry;

0 commit comments

Comments
 (0)