Skip to content

Commit f828d5e

Browse files
fix: Fix rollup plugin output directory in Typescript (box/box-codegen#678) (#543)
1 parent 2475208 commit f828d5e

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

.codegen.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{ "engineHash": "8f5e41b", "specHash": "6782a0d", "version": "1.13.1" }
1+
{ "engineHash": "41feeaa", "specHash": "6782a0d", "version": "1.13.1" }

rollup.config.mjs

+30
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import commonjs from '@rollup/plugin-commonjs';
33
import typescript from '@rollup/plugin-typescript';
44
import json from '@rollup/plugin-json';
55
import fs from 'fs';
6+
import path from 'path';
67

78
function getBrowserConfig() {
89
const packageJson = JSON.parse(fs.readFileSync('./package.json', 'utf-8'));
@@ -45,6 +46,32 @@ function replaceFiles(options = {}) {
4546
};
4647
}
4748

49+
function cleanupTypeScript(options = {}) {
50+
const { tsconfig } = options;
51+
const tsconfigFile = JSON.parse(fs.readFileSync(tsconfig, 'utf-8'));
52+
let tsOutputDir;
53+
54+
return {
55+
name: 'cleanup-typescript',
56+
generateBundle(outputOptions) {
57+
const outputDir =
58+
outputOptions.dir ||
59+
(outputOptions.file
60+
? outputOptions.file.substring(0, outputOptions.file.lastIndexOf('/'))
61+
: 'dist');
62+
tsOutputDir = path.resolve(
63+
outputDir,
64+
tsconfigFile.compilerOptions.outDir,
65+
);
66+
},
67+
closeBundle() {
68+
if (tsOutputDir) {
69+
fs.rmSync(tsOutputDir, { recursive: true, force: true });
70+
}
71+
},
72+
};
73+
}
74+
4875
export default {
4976
input: 'src/index.ts',
5077
output: {
@@ -67,5 +94,8 @@ export default {
6794
tsconfig: './tsconfig.rollup.json',
6895
}), // Compiles TypeScript
6996
json(), // Converts JSON files to ES6 modules
97+
cleanupTypeScript({
98+
tsconfig: './tsconfig.rollup.json',
99+
}),
70100
],
71101
};

tsconfig.rollup.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"module": "ESNext",
55
"declaration": true,
66
"sourceMap": true,
7-
"outDir": "lib",
7+
"outDir": "lib-rollup",
88
"isolatedModules": true,
99
"esModuleInterop": true,
1010
"forceConsistentCasingInFileNames": true,

0 commit comments

Comments
 (0)