build(tsc-wrapped): use tsickleCompilerHost for initial file load
In order for tsickle's new support for input source maps to work, the tsickleCompilerHost must be used for the initial load of source files, since that's when the inline source maps are read and stripped.
This commit is contained in:
parent
49764a5bff
commit
5c0ea20bd0
|
@ -86,7 +86,25 @@ export function main(
|
|||
parsed.fileNames.push(name);
|
||||
}
|
||||
|
||||
const program = createProgram(host);
|
||||
const tsickleCompilerHostOptions: tsickle.Options = {
|
||||
googmodule: false,
|
||||
untyped: true,
|
||||
convertIndexImportShorthand:
|
||||
ngOptions.target === ts.ScriptTarget.ES2015, // This covers ES6 too
|
||||
};
|
||||
|
||||
const tsickleHost: tsickle.TsickleHost = {
|
||||
shouldSkipTsickleProcessing: (fileName) => /\.d\.ts$/.test(fileName),
|
||||
pathToModuleName: (context, importPath) => '',
|
||||
shouldIgnoreWarningsForPath: (filePath) => false,
|
||||
fileNameToModuleId: (fileName) => fileName,
|
||||
};
|
||||
|
||||
const tsickleCompilerHost =
|
||||
new tsickle.TsickleCompilerHost(host, ngOptions, tsickleCompilerHostOptions, tsickleHost);
|
||||
|
||||
const program = createProgram(tsickleCompilerHost);
|
||||
|
||||
const errors = program.getOptionsDiagnostics();
|
||||
check(errors);
|
||||
|
||||
|
@ -97,35 +115,16 @@ export function main(
|
|||
if (diagnostics) console.time('NG codegen');
|
||||
return codegen(ngOptions, cliOptions, program, host).then(() => {
|
||||
if (diagnostics) console.timeEnd('NG codegen');
|
||||
let definitionsHost = host;
|
||||
let definitionsHost: ts.CompilerHost = tsickleCompilerHost;
|
||||
if (!ngOptions.skipMetadataEmit) {
|
||||
definitionsHost = new MetadataWriterHost(host, ngOptions);
|
||||
definitionsHost = new MetadataWriterHost(tsickleCompilerHost, ngOptions);
|
||||
}
|
||||
// Create a new program since codegen files were created after making the old program
|
||||
let programWithCodegen = createProgram(definitionsHost, program);
|
||||
tsc.typeCheck(host, programWithCodegen);
|
||||
|
||||
let preprocessHost = host;
|
||||
let programForJsEmit = programWithCodegen;
|
||||
|
||||
|
||||
const tsickleCompilerHostOptions: tsickle.Options = {
|
||||
googmodule: false,
|
||||
untyped: true,
|
||||
convertIndexImportShorthand:
|
||||
ngOptions.target === ts.ScriptTarget.ES2015, // This covers ES6 too
|
||||
};
|
||||
|
||||
const tsickleHost: tsickle.TsickleHost = {
|
||||
shouldSkipTsickleProcessing: (fileName) => /\.d\.ts$/.test(fileName),
|
||||
pathToModuleName: (context, importPath) => '',
|
||||
shouldIgnoreWarningsForPath: (filePath) => false,
|
||||
fileNameToModuleId: (fileName) => fileName,
|
||||
};
|
||||
|
||||
const tsickleCompilerHost = new tsickle.TsickleCompilerHost(
|
||||
preprocessHost, ngOptions, tsickleCompilerHostOptions, tsickleHost);
|
||||
|
||||
if (ngOptions.annotationsAs !== 'decorators') {
|
||||
if (diagnostics) console.time('NG downlevel');
|
||||
tsickleCompilerHost.reconfigureForRun(programForJsEmit, tsickle.Pass.DECORATOR_DOWNLEVEL);
|
||||
|
@ -133,7 +132,6 @@ export function main(
|
|||
// metadataWriter
|
||||
programForJsEmit = createProgram(tsickleCompilerHost);
|
||||
check(tsickleCompilerHost.diagnostics);
|
||||
preprocessHost = tsickleCompilerHost;
|
||||
if (diagnostics) console.timeEnd('NG downlevel');
|
||||
}
|
||||
|
||||
|
|
|
@ -264,4 +264,35 @@ describe('tsc-wrapped', () => {
|
|||
})
|
||||
.catch(e => done.fail(e));
|
||||
});
|
||||
|
||||
it('should accept input source maps', (done) => {
|
||||
write('tsconfig.json', `{
|
||||
"compilerOptions": {
|
||||
"experimentalDecorators": true,
|
||||
"types": [],
|
||||
"outDir": "built",
|
||||
"declaration": true,
|
||||
"moduleResolution": "node",
|
||||
"target": "es2015",
|
||||
"sourceMap": true
|
||||
},
|
||||
"angularCompilerOptions": {
|
||||
"annotateForClosureCompiler": true
|
||||
},
|
||||
"files": ["test.ts"]
|
||||
}`);
|
||||
// Provide a file called test.ts that has an inline source map
|
||||
// which says that it was transpiled from a file other_test.ts
|
||||
// with exactly the same content.
|
||||
write('test.ts', `const x = 3;
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm90aGVyX3Rlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsTUFBTSxFQUFFLEVBQUUsQ0FBQyIsImZpbGUiOiIuLi90ZXN0LnRzIiwic291cmNlUm9vdCI6IiJ9`);
|
||||
|
||||
main(basePath, {basePath})
|
||||
.then(() => {
|
||||
const out = readOut('js.map');
|
||||
expect(out).toContain('"sources":["other_test.ts"]');
|
||||
done();
|
||||
})
|
||||
.catch(e => done.fail(e));
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue