diff --git a/src/createBuildConfigs.ts b/src/createBuildConfigs.ts index b53bdee54..261c4f755 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 eedc7dd5b..a06f5df24 100644 --- a/src/createRollupConfig.ts +++ b/src/createRollupConfig.ts @@ -24,7 +24,8 @@ const errorCodeOpts = { let shebang: any = {}; export async function createRollupConfig( - opts: TsdxOptions + opts: TsdxOptions, + outputNum: number ): Promise { const findAndRecordErrorCodes = await extractErrors({ ...errorCodeOpts, @@ -170,6 +171,10 @@ export async function createRollupConfig( compilerOptions: { // TS -> esnext, then leave the rest to babel-preset-env target: 'esnext', + // don't output declarations more than once + ...(outputNum > 0 + ? { declaration: false, declarationMap: false } + : {}), }, }, check: !opts.transpileOnly, diff --git a/src/deprecated.ts b/src/deprecated.ts index 275caadb8..41319cdcc 100644 --- a/src/deprecated.ts +++ b/src/deprecated.ts @@ -21,27 +21,14 @@ export async function moveTypes() { '[tsdx]: Your rootDir is currently set to "./". Please change your ' + 'rootDir to "./src".\n' + 'TSDX has deprecated setting tsconfig.compilerOptions.rootDir to ' + - '"./" as it caused buggy output for declarationMaps and occassionally ' + - 'for type declarations themselves.\n' + + '"./" as it caused buggy output for declarationMaps and more.\n' + 'You may also need to change your include to remove "test", which also ' + 'caused declarations to be unnecessarily created for test files.' ); - try { - // Move the typescript types to the base of the ./dist folder - await fs.copy(appDistSrc, paths.appDist, { - overwrite: true, - }); - } catch (err) { - // ignore errors about the destination dir already existing or files not - // existing as those always occur for some reason, re-throw any other - // unexpected failures - // NOTE: these errors mean that sometimes files don't get moved properly, - // meaning that it's buggy / unreliable (see console.warn above) - if (err.code !== 'EEXIST' && err.code !== 'ENOENT') { - throw err; - } - } - + // Move the typescript types to the base of the ./dist folder + await fs.copy(appDistSrc, paths.appDist, { + overwrite: true, + }); await fs.remove(appDistSrc); } diff --git a/src/index.ts b/src/index.ts index b5d8254d6..bcc53c17f 100755 --- a/src/index.ts +++ b/src/index.ts @@ -401,11 +401,13 @@ prog async (inputOptions: RollupOptions & { output: OutputOptions }) => { let bundle = await rollup(inputOptions); await bundle.write(inputOptions.output); - await deprecated.moveTypes(); } ) .catch((e: any) => { throw e; + }) + .then(async () => { + await deprecated.moveTypes(); }); logger(promise, 'Building modules'); await promise;