Skip to content

Commit

Permalink
fix(typescript): emit assets when watchMode is false. fixes #1354
Browse files Browse the repository at this point in the history
  • Loading branch information
gbaron committed Nov 28, 2022
1 parent 7871903 commit 5c88274
Show file tree
Hide file tree
Showing 6 changed files with 1,979 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/typescript/src/index.ts
Expand Up @@ -58,6 +58,7 @@ export default function typescript(options: RollupTypescriptOptions = {}): Plugi
if (this.meta.watchMode !== true) {
// eslint-disable-next-line
program?.close();
program = null;
}
if (!program) {
program = createWatchProgram(ts, this, {
Expand Down
1,920 changes: 1,920 additions & 0 deletions packages/typescript/test/fixtures/incremental-watch-off/dist/.tsbuildinfo

Large diffs are not rendered by default.

@@ -0,0 +1,6 @@
type AnswerToQuestion = string | undefined;

const answer: AnswerToQuestion = '42';

// eslint-disable-next-line no-console
console.log(`the answer is ${answer}`);
@@ -0,0 +1,6 @@
type AnswerToQuestion = string | undefined;

const answer: AnswerToQuestion = '42';

// eslint-disable-next-line no-console
console.log(`the answer is ${answer}`);
@@ -0,0 +1,8 @@
{
"include": ["main.ts"],
"compilerOptions": {
"incremental": true,
"outDir": "./dist",
"tsBuildInfoFile": "./dist/.tsbuildinfo"
}
}
38 changes: 38 additions & 0 deletions packages/typescript/test/test.js
Expand Up @@ -730,6 +730,44 @@ test.serial('supports incremental build for single file output', async (t) => {
t.is(warnings.length, 0);
});

test.serial('supports consecutive rebuilds when watchMode is false', async (t) => {
process.chdir('fixtures/incremental-watch-off');

// IMPORTANT: The issue only happens if it's the same instance of rollup/plugin-typescript
// Hence, generating one instance and using it twice below.
const tsPlugin = typescript({ outputToFilesystem: true });

const firstBundle = await rollup({
input: 'main.ts',
plugins: [tsPlugin],
onwarn
});

const firstRun = await getCode(firstBundle, { format: 'es', dir: 'dist' }, true);
const firstRunCode = firstRun[0].code;

try {
// Mutating the source file
fs.appendFileSync('main.ts', '\nexport const REBUILD_WITH_WATCH_OFF = 1;');

const secondBundle = await rollup({
input: 'main.ts',
plugins: [tsPlugin],
onwarn
});
const secondRun = await getCode(secondBundle, { format: 'es', dir: 'dist' }, true);
const secondRunCode = secondRun[0].code;

t.notDeepEqual(firstRunCode, secondRunCode);
} finally {
fs.copyFile('original.txt', 'main.ts', (err) => {
if (err) {
t.fail(err);
}
});
}
});

test.serial('does not output to filesystem when outputToFilesystem is false', async (t) => {
process.chdir('fixtures/incremental-single');
// clean up artefacts from earlier builds
Expand Down

0 comments on commit 5c88274

Please sign in to comment.