From 14b539763ef21019bf2dd70747a9b09ed1ec0287 Mon Sep 17 00:00:00 2001 From: Anton Gilgur Date: Thu, 12 Dec 2019 22:33:40 -0500 Subject: [PATCH] (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 --- src/createBuildConfigs.ts | 4 ++-- src/createRollupConfig.ts | 5 ++++- src/index.ts | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/createBuildConfigs.ts b/src/createBuildConfigs.ts index caf0bbcbc..84e4975a4 100644 --- a/src/createBuildConfigs.ts +++ b/src/createBuildConfigs.ts @@ -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); }) ); diff --git a/src/createRollupConfig.ts b/src/createRollupConfig.ts index d9b3bd417..9a328969b 100644 --- a/src/createRollupConfig.ts +++ b/src/createRollupConfig.ts @@ -23,7 +23,8 @@ const errorCodeOpts = { let shebang: any = {}; export async function createRollupConfig( - opts: TsdxOptions + opts: TsdxOptions, + outputNum: number ): Promise { const findAndRecordErrorCodes = await extractErrors({ ...errorCodeOpts, @@ -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, diff --git a/src/index.ts b/src/index.ts index 472e22257..666f0c73c 100755 --- a/src/index.ts +++ b/src/index.ts @@ -456,7 +456,6 @@ prog async (inputOptions: RollupOptions & { output: OutputOptions }) => { let bundle = await rollup(inputOptions); await bundle.write(inputOptions.output); - await deprecated.moveTypes(); } ) .catch((e: any) => { @@ -464,6 +463,7 @@ prog }); logger(promise, 'Building modules'); await promise; + await deprecated.moveTypes(); } catch (error) { logError(error); process.exit(1);