fix(ivy): ngcc - ensure generated source map paths are correct (#29556)
Previously we were using absolute paths, but since at rendering time we do not know exactly where the file will be written it is more correct to change to using relative paths. This is actually better all round since it allows the folders to be portable to different machines, etc. PR Close #29556
This commit is contained in:
parent
c456b73302
commit
1df9908579
|
@ -329,8 +329,11 @@ export abstract class Renderer {
|
||||||
*/
|
*/
|
||||||
protected renderSourceAndMap(
|
protected renderSourceAndMap(
|
||||||
sourceFile: ts.SourceFile, input: SourceMapInfo, output: MagicString): FileInfo[] {
|
sourceFile: ts.SourceFile, input: SourceMapInfo, output: MagicString): FileInfo[] {
|
||||||
const outputPath = resolve(this.targetPath, relative(this.sourcePath, sourceFile.fileName));
|
const outputPath = sourceFile.fileName;
|
||||||
const outputMapPath = `${outputPath}.map`;
|
const outputMapPath = `${outputPath}.map`;
|
||||||
|
const relativeSourcePath = basename(outputPath);
|
||||||
|
const relativeMapPath = `${relativeSourcePath}.map`;
|
||||||
|
|
||||||
const outputMap = output.generateMap({
|
const outputMap = output.generateMap({
|
||||||
source: outputPath,
|
source: outputPath,
|
||||||
includeContent: true,
|
includeContent: true,
|
||||||
|
@ -339,7 +342,7 @@ export abstract class Renderer {
|
||||||
});
|
});
|
||||||
|
|
||||||
// we must set this after generation as magic string does "manipulation" on the path
|
// we must set this after generation as magic string does "manipulation" on the path
|
||||||
outputMap.file = outputPath;
|
outputMap.file = relativeSourcePath;
|
||||||
|
|
||||||
const mergedMap =
|
const mergedMap =
|
||||||
mergeSourceMaps(input.map && input.map.toObject(), JSON.parse(outputMap.toString()));
|
mergeSourceMaps(input.map && input.map.toObject(), JSON.parse(outputMap.toString()));
|
||||||
|
@ -350,7 +353,7 @@ export abstract class Renderer {
|
||||||
} else {
|
} else {
|
||||||
result.push({
|
result.push({
|
||||||
path: outputPath,
|
path: outputPath,
|
||||||
contents: `${output.toString()}\n${generateMapFileComment(outputMapPath)}`
|
contents: `${output.toString()}\n${generateMapFileComment(relativeMapPath)}`
|
||||||
});
|
});
|
||||||
result.push({path: outputMapPath, contents: mergedMap.toJSON()});
|
result.push({path: outputMapPath, contents: mergedMap.toJSON()});
|
||||||
}
|
}
|
||||||
|
|
|
@ -107,7 +107,7 @@ describe('Renderer', () => {
|
||||||
|
|
||||||
const OUTPUT_PROGRAM_MAP = fromObject({
|
const OUTPUT_PROGRAM_MAP = fromObject({
|
||||||
'version': 3,
|
'version': 3,
|
||||||
'file': '/dist/file.js',
|
'file': 'file.js',
|
||||||
'sources': ['/src/file.js'],
|
'sources': ['/src/file.js'],
|
||||||
'sourcesContent': [INPUT_PROGRAM.contents],
|
'sourcesContent': [INPUT_PROGRAM.contents],
|
||||||
'names': [],
|
'names': [],
|
||||||
|
@ -119,7 +119,7 @@ describe('Renderer', () => {
|
||||||
'sources': ['/src/file.ts'],
|
'sources': ['/src/file.ts'],
|
||||||
'names': [],
|
'names': [],
|
||||||
'mappings': ';;;;;;;;;;AAAA',
|
'mappings': ';;;;;;;;;;AAAA',
|
||||||
'file': '/dist/file.js',
|
'file': 'file.js',
|
||||||
'sourcesContent': [INPUT_PROGRAM.contents]
|
'sourcesContent': [INPUT_PROGRAM.contents]
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -131,10 +131,10 @@ describe('Renderer', () => {
|
||||||
const result = renderer.renderProgram(
|
const result = renderer.renderProgram(
|
||||||
decorationAnalyses, switchMarkerAnalyses, privateDeclarationsAnalyses,
|
decorationAnalyses, switchMarkerAnalyses, privateDeclarationsAnalyses,
|
||||||
moduleWithProvidersAnalyses);
|
moduleWithProvidersAnalyses);
|
||||||
expect(result[0].path).toEqual('/dist/file.js');
|
expect(result[0].path).toEqual('/src/file.js');
|
||||||
expect(result[0].contents)
|
expect(result[0].contents)
|
||||||
.toEqual(RENDERED_CONTENTS + '\n' + generateMapFileComment('/dist/file.js.map'));
|
.toEqual(RENDERED_CONTENTS + '\n' + generateMapFileComment('file.js.map'));
|
||||||
expect(result[1].path).toEqual('/dist/file.js.map');
|
expect(result[1].path).toEqual('/src/file.js.map');
|
||||||
expect(result[1].contents).toEqual(OUTPUT_PROGRAM_MAP.toJSON());
|
expect(result[1].contents).toEqual(OUTPUT_PROGRAM_MAP.toJSON());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -237,7 +237,7 @@ A.ngDirectiveDef = ɵngcc0.ɵdefineDirective({ type: A, selectors: [["", "a", ""
|
||||||
const result = renderer.renderProgram(
|
const result = renderer.renderProgram(
|
||||||
decorationAnalyses, switchMarkerAnalyses, privateDeclarationsAnalyses,
|
decorationAnalyses, switchMarkerAnalyses, privateDeclarationsAnalyses,
|
||||||
moduleWithProvidersAnalyses);
|
moduleWithProvidersAnalyses);
|
||||||
expect(result[0].path).toEqual('/dist/file.js');
|
expect(result[0].path).toEqual('/src/file.js');
|
||||||
expect(result[0].contents)
|
expect(result[0].contents)
|
||||||
.toEqual(RENDERED_CONTENTS + '\n' + MERGED_OUTPUT_PROGRAM_MAP.toComment());
|
.toEqual(RENDERED_CONTENTS + '\n' + MERGED_OUTPUT_PROGRAM_MAP.toComment());
|
||||||
expect(result[1]).toBeUndefined();
|
expect(result[1]).toBeUndefined();
|
||||||
|
@ -257,10 +257,10 @@ A.ngDirectiveDef = ɵngcc0.ɵdefineDirective({ type: A, selectors: [["", "a", ""
|
||||||
const result = renderer.renderProgram(
|
const result = renderer.renderProgram(
|
||||||
decorationAnalyses, switchMarkerAnalyses, privateDeclarationsAnalyses,
|
decorationAnalyses, switchMarkerAnalyses, privateDeclarationsAnalyses,
|
||||||
moduleWithProvidersAnalyses);
|
moduleWithProvidersAnalyses);
|
||||||
expect(result[0].path).toEqual('/dist/file.js');
|
expect(result[0].path).toEqual('/src/file.js');
|
||||||
expect(result[0].contents)
|
expect(result[0].contents)
|
||||||
.toEqual(RENDERED_CONTENTS + '\n' + generateMapFileComment('/dist/file.js.map'));
|
.toEqual(RENDERED_CONTENTS + '\n' + generateMapFileComment('file.js.map'));
|
||||||
expect(result[1].path).toEqual('/dist/file.js.map');
|
expect(result[1].path).toEqual('/src/file.js.map');
|
||||||
expect(result[1].contents).toEqual(MERGED_OUTPUT_PROGRAM_MAP.toJSON());
|
expect(result[1].contents).toEqual(MERGED_OUTPUT_PROGRAM_MAP.toJSON());
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue