Skip to content

Commit 03fb221

Browse files
committed
(fix/optim): only emit type declarations once
- every other emission is just a duplicate -- no need to spend compute to duplicate - this also fixes a bug with multi-entry where if an entry in a subdir of src/ were added, e.g. src/foo/bar, the entire tree of type declarations would get output into dist/foo/src/*.d.ts - alternatively, could call `moveTypes()` with an arg for each entry, but there's no need since all declarations get produced the first time around anyway
1 parent c69978a commit 03fb221

2 files changed

Lines changed: 11 additions & 5 deletions

File tree

‎src/createRollupConfig.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const errorCodeOpts = {
2020
// shebang cache map thing because the transform only gets run once
2121
let shebang: any = {};
2222

23-
export async function createRollupConfig(opts: TsdxOptions) {
23+
export async function createRollupConfig(opts: TsdxOptions, outputNum: number) {
2424
const findAndRecordErrorCodes = await extractErrors({
2525
...errorCodeOpts,
2626
...opts,
@@ -140,6 +140,8 @@ export async function createRollupConfig(opts: TsdxOptions) {
140140
tsconfigOverride: {
141141
compilerOptions: {
142142
target: 'esnext',
143+
// only output declarations once
144+
declaration: outputNum !== 0 ? false : undefined,
143145
},
144146
},
145147
}),

‎src/index.ts‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,9 @@ async function createBuildConfigs(
164164
writeMeta: index === 0,
165165
}));
166166
})
167-
).map(async (options: TsdxOptions) => {
167+
).map(async (options: TsdxOptions, index: number) => {
168168
// pass the full rollup config to tsdx.config.js override
169-
const config = await createRollupConfig(options);
169+
const config = await createRollupConfig(options, index);
170170
return tsdxConfig.rollup(config, options);
171171
})
172172
);
@@ -475,10 +475,14 @@ prog
475475
const promise = asyncro
476476
.map(
477477
buildConfigs,
478-
async (inputOptions: RollupOptions & { output: OutputOptions }) => {
478+
async (
479+
inputOptions: RollupOptions & { output: OutputOptions },
480+
index: number
481+
) => {
479482
let bundle = await rollup(inputOptions);
480483
await bundle.write(inputOptions.output);
481-
await moveTypes();
484+
// declarations are only output on first run
485+
if (index === 0) await moveTypes();
482486
}
483487
)
484488
.catch((e: any) => {

0 commit comments

Comments
 (0)