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

fix(typescript): fix sourcemap sourcecontent referencing non-existent files #1571

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
8 changes: 4 additions & 4 deletions packages/typescript/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import findTypescriptOutput, {
normalizePath,
emitFile,
isDeclarationOutputFile,
isMapOutputFile
isTypeScriptMapOutputFile
} from './outputFile';
import { preflight } from './preflight';
import createWatchProgram, { WatchProgramHelper } from './watchProgram';
Expand Down Expand Up @@ -156,11 +156,11 @@ export default function typescript(options: RollupTypescriptOptions = {}): Plugi
},

async generateBundle(outputOptions) {
const declarationAndMapFiles = [...emittedFiles.keys()].filter(
(fileName) => isDeclarationOutputFile(fileName) || isMapOutputFile(fileName)
const declarationAndTypeScriptMapFiles = [...emittedFiles.keys()].filter(
(fileName) => isDeclarationOutputFile(fileName) || isTypeScriptMapOutputFile(fileName)
);

declarationAndMapFiles.forEach((id) => {
declarationAndTypeScriptMapFiles.forEach((id) => {
const code = getEmittedFile(id, emittedFiles, tsCache);
if (!code || !parsedOptions.options.declaration) {
return;
Expand Down
7 changes: 7 additions & 0 deletions packages/typescript/src/outputFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ export function isCodeOutputFile(name: string): boolean {
* Checks if the given OutputFile represents some source map
*/
export function isMapOutputFile(name: string): boolean {
return name.endsWith('.map');
}

/**
* Checks if the given OutputFile represents some TypeScript source map
*/
export function isTypeScriptMapOutputFile(name: string): boolean {
return name.endsWith('ts.map');
}

Expand Down
18 changes: 18 additions & 0 deletions packages/typescript/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,24 @@ test.serial('should not emit null sourceContent', async (t) => {
t.false(sourcemap.sourcesContent.includes(undefined));
});

test.serial('should not emit sourceContent that references a non-existent file', async (t) => {
const bundle = await rollup({
input: 'fixtures/basic/main.ts',
output: {
sourcemap: true
},
plugins: [
typescript({
tsconfig: 'fixtures/basic/tsconfig.json'
})
],
onwarn
});
const output = await getCode(bundle, { format: 'es', sourcemap: true }, true);
const sourcemap = output[0].map;
t.false(sourcemap.sourcesContent.includes('//# sourceMappingURL=main.js.map'));
});

test.serial('should not fail if source maps are off', async (t) => {
await t.notThrowsAsync(
rollup({
Expand Down
Loading