Skip to content

Commit

Permalink
(fix/optim): only emit type declarations once
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
agilgur5 committed Dec 14, 2019
1 parent 8fc7a61 commit fb173ae
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/createRollupConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const errorCodeOpts = {
// shebang cache map thing because the transform only gets run once
let shebang: any = {};

export async function createRollupConfig(opts: TsdxOptions) {
export async function createRollupConfig(opts: TsdxOptions, outputNum: number) {
const findAndRecordErrorCodes = await extractErrors({
...errorCodeOpts,
...opts,
Expand Down Expand Up @@ -140,6 +140,8 @@ export async function createRollupConfig(opts: TsdxOptions) {
tsconfigOverride: {
compilerOptions: {
target: 'esnext',
// only output declarations once
declaration: outputNum !== 0 ? false : undefined,
},
},
}),
Expand Down
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,9 @@ async function createBuildConfigs(
writeMeta: index === 0,
}));
})
).map(async (options: TsdxOptions) => {
).map(async (options: TsdxOptions, index: number) => {
// pass the full rollup config to tsdx.config.js override
const config = await createRollupConfig(options);
const config = await createRollupConfig(options, index);
return tsdxConfig.rollup(config, options);
})
);
Expand Down Expand Up @@ -502,14 +502,14 @@ prog
async (inputOptions: RollupOptions & { output: OutputOptions }) => {
let bundle = await rollup(inputOptions);
await bundle.write(inputOptions.output);
await moveTypes();
}
)
.catch((e: any) => {
throw e;
});
logger(promise, 'Building modules');
await promise;
await moveTypes();
} catch (error) {
logError(error);
process.exit(1);
Expand Down

0 comments on commit fb173ae

Please sign in to comment.