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 Mar 6, 2020
1 parent 09a35fb commit 14b5397
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/createBuildConfigs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ export async function createBuildConfigs(
);

return await Promise.all(
allInputs.map(async (options: TsdxOptions) => {
allInputs.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
5 changes: 4 additions & 1 deletion src/createRollupConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ const errorCodeOpts = {
let shebang: any = {};

export async function createRollupConfig(
opts: TsdxOptions
opts: TsdxOptions,
outputNum: number
): Promise<RollupOptions> {
const findAndRecordErrorCodes = await extractErrors({
...errorCodeOpts,
Expand Down Expand Up @@ -162,6 +163,8 @@ export async function createRollupConfig(
compilerOptions: {
// TS -> esnext, then leave the rest to babel-preset-env
target: 'esnext',
// only output declarations once
declaration: outputNum !== 0 ? false : undefined,
},
},
check: !opts.transpileOnly,
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -456,14 +456,14 @@ prog
async (inputOptions: RollupOptions & { output: OutputOptions }) => {
let bundle = await rollup(inputOptions);
await bundle.write(inputOptions.output);
await deprecated.moveTypes();
}
)
.catch((e: any) => {
throw e;
});
logger(promise, 'Building modules');
await promise;
await deprecated.moveTypes();
} catch (error) {
logError(error);
process.exit(1);
Expand Down

0 comments on commit 14b5397

Please sign in to comment.