Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(optim/fix): only emit type declarations once #691

Merged
merged 2 commits into from
Apr 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
8 changes: 6 additions & 2 deletions src/createRollupConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,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 @@ -145,7 +146,6 @@ export async function createRollupConfig(
},
typescript({
typescript: ts,
cacheRoot: `./node_modules/.cache/tsdx/${opts.format}/`,
tsconfig: opts.tsconfig,
tsconfigDefaults: {
exclude: [
Expand All @@ -170,6 +170,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,
Expand Down
23 changes: 5 additions & 18 deletions src/deprecated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
4 changes: 3 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down