Skip to content

Commit 5c88274

Browse files
authored
fix(typescript): emit assets when watchMode is false. fixes #1354
1 parent 7871903 commit 5c88274

File tree

6 files changed

+1979
-0
lines changed

6 files changed

+1979
-0
lines changed

packages/typescript/src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export default function typescript(options: RollupTypescriptOptions = {}): Plugi
5858
if (this.meta.watchMode !== true) {
5959
// eslint-disable-next-line
6060
program?.close();
61+
program = null;
6162
}
6263
if (!program) {
6364
program = createWatchProgram(ts, this, {

packages/typescript/test/fixtures/incremental-watch-off/dist/.tsbuildinfo

+1,920
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
type AnswerToQuestion = string | undefined;
2+
3+
const answer: AnswerToQuestion = '42';
4+
5+
// eslint-disable-next-line no-console
6+
console.log(`the answer is ${answer}`);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
type AnswerToQuestion = string | undefined;
2+
3+
const answer: AnswerToQuestion = '42';
4+
5+
// eslint-disable-next-line no-console
6+
console.log(`the answer is ${answer}`);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"include": ["main.ts"],
3+
"compilerOptions": {
4+
"incremental": true,
5+
"outDir": "./dist",
6+
"tsBuildInfoFile": "./dist/.tsbuildinfo"
7+
}
8+
}

packages/typescript/test/test.js

+38
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,44 @@ test.serial('supports incremental build for single file output', async (t) => {
730730
t.is(warnings.length, 0);
731731
});
732732

733+
test.serial('supports consecutive rebuilds when watchMode is false', async (t) => {
734+
process.chdir('fixtures/incremental-watch-off');
735+
736+
// IMPORTANT: The issue only happens if it's the same instance of rollup/plugin-typescript
737+
// Hence, generating one instance and using it twice below.
738+
const tsPlugin = typescript({ outputToFilesystem: true });
739+
740+
const firstBundle = await rollup({
741+
input: 'main.ts',
742+
plugins: [tsPlugin],
743+
onwarn
744+
});
745+
746+
const firstRun = await getCode(firstBundle, { format: 'es', dir: 'dist' }, true);
747+
const firstRunCode = firstRun[0].code;
748+
749+
try {
750+
// Mutating the source file
751+
fs.appendFileSync('main.ts', '\nexport const REBUILD_WITH_WATCH_OFF = 1;');
752+
753+
const secondBundle = await rollup({
754+
input: 'main.ts',
755+
plugins: [tsPlugin],
756+
onwarn
757+
});
758+
const secondRun = await getCode(secondBundle, { format: 'es', dir: 'dist' }, true);
759+
const secondRunCode = secondRun[0].code;
760+
761+
t.notDeepEqual(firstRunCode, secondRunCode);
762+
} finally {
763+
fs.copyFile('original.txt', 'main.ts', (err) => {
764+
if (err) {
765+
t.fail(err);
766+
}
767+
});
768+
}
769+
});
770+
733771
test.serial('does not output to filesystem when outputToFilesystem is false', async (t) => {
734772
process.chdir('fixtures/incremental-single');
735773
// clean up artefacts from earlier builds

0 commit comments

Comments
 (0)