fix(bazel): produce named AMD modules for codegen (#20547)
fixes #19422 Signed-off-by: Alex Eagle <alexeagle@google.com> PR Close #20547
This commit is contained in:
parent
a53a040071
commit
6e83204238
|
@ -32,7 +32,7 @@
|
||||||
"fsevents": "1.1.2"
|
"fsevents": "1.1.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@bazel/typescript": "0.3.1",
|
"@bazel/typescript": "0.3.2",
|
||||||
"@types/angularjs": "1.5.14-alpha",
|
"@types/angularjs": "1.5.14-alpha",
|
||||||
"@types/base64-js": "1.2.5",
|
"@types/base64-js": "1.2.5",
|
||||||
"@types/chokidar": "1.7.3",
|
"@types/chokidar": "1.7.3",
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
"typescript": ">=2.4.2 <2.6"
|
"typescript": ">=2.4.2 <2.6"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@bazel/typescript": "0.3.x",
|
"@bazel/typescript": "0.3.2",
|
||||||
"@types/node": "6.0.84"
|
"@types/node": "6.0.84"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
|
|
|
@ -164,11 +164,19 @@ export function compile({allowNonHermeticReads, allDepsCompiledWithBazel = true,
|
||||||
}
|
}
|
||||||
return origBazelHostFileExist.call(bazelHost, fileName);
|
return origBazelHostFileExist.call(bazelHost, fileName);
|
||||||
};
|
};
|
||||||
|
const origBazelHostShouldNameModule = bazelHost.shouldNameModule.bind(bazelHost);
|
||||||
|
bazelHost.shouldNameModule = (fileName: string) =>
|
||||||
|
origBazelHostShouldNameModule(fileName) || NGC_GEN_FILES.test(fileName);
|
||||||
|
|
||||||
const ngHost = ng.createCompilerHost({options: compilerOpts, tsHost: bazelHost});
|
const ngHost = ng.createCompilerHost({options: compilerOpts, tsHost: bazelHost});
|
||||||
|
|
||||||
ngHost.fileNameToModuleName = (importedFilePath: string, containingFilePath: string) =>
|
ngHost.fileNameToModuleName = (importedFilePath: string, containingFilePath: string) => {
|
||||||
relativeToRootDirs(importedFilePath, compilerOpts.rootDirs).replace(EXT, '');
|
if ((compilerOpts.module === ts.ModuleKind.UMD || compilerOpts.module === ts.ModuleKind.AMD) &&
|
||||||
|
ngHost.amdModuleName) {
|
||||||
|
return ngHost.amdModuleName({ fileName: importedFilePath } as ts.SourceFile);
|
||||||
|
}
|
||||||
|
return relativeToRootDirs(importedFilePath, compilerOpts.rootDirs).replace(EXT, '');
|
||||||
|
};
|
||||||
ngHost.toSummaryFileName = (fileName: string, referringSrcFileName: string) =>
|
ngHost.toSummaryFileName = (fileName: string, referringSrcFileName: string) =>
|
||||||
ngHost.fileNameToModuleName(fileName, referringSrcFileName);
|
ngHost.fileNameToModuleName(fileName, referringSrcFileName);
|
||||||
if (allDepsCompiledWithBazel) {
|
if (allDepsCompiledWithBazel) {
|
||||||
|
|
|
@ -192,6 +192,13 @@ export interface CompilerHost extends ts.CompilerHost {
|
||||||
* cause a diagnostics diagnostic error or an exception to be thrown.
|
* cause a diagnostics diagnostic error or an exception to be thrown.
|
||||||
*/
|
*/
|
||||||
readResource?(fileName: string): Promise<string>|string;
|
readResource?(fileName: string): Promise<string>|string;
|
||||||
|
/**
|
||||||
|
* Produce an AMD module name for the source file. Used in Bazel.
|
||||||
|
*
|
||||||
|
* An AMD module can have an arbitrary name, so that it is require'd by name
|
||||||
|
* rather than by path. See http://requirejs.org/docs/whyamd.html#namedmodules
|
||||||
|
*/
|
||||||
|
amdModuleName?(sf: ts.SourceFile): string|undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum EmitFlags {
|
export enum EmitFlags {
|
||||||
|
|
|
@ -303,6 +303,11 @@ export class TsCompilerAotCompilerTypeCheckHostAdapter implements ts.CompilerHos
|
||||||
/* emitSourceMaps */ false);
|
/* emitSourceMaps */ false);
|
||||||
const sf = ts.createSourceFile(
|
const sf = ts.createSourceFile(
|
||||||
genFile.genFileUrl, sourceText, this.options.target || ts.ScriptTarget.Latest);
|
genFile.genFileUrl, sourceText, this.options.target || ts.ScriptTarget.Latest);
|
||||||
|
if ((this.options.module === ts.ModuleKind.AMD || this.options.module === ts.ModuleKind.UMD) &&
|
||||||
|
this.context.amdModuleName) {
|
||||||
|
const moduleName = this.context.amdModuleName(sf);
|
||||||
|
if (moduleName) sf.moduleName = moduleName;
|
||||||
|
}
|
||||||
this.generatedSourceFiles.set(genFile.genFileUrl, {
|
this.generatedSourceFiles.set(genFile.genFileUrl, {
|
||||||
sourceFile: sf,
|
sourceFile: sf,
|
||||||
emitCtx: context, externalReferences,
|
emitCtx: context, externalReferences,
|
||||||
|
|
17
yarn.lock
17
yarn.lock
|
@ -2,9 +2,9 @@
|
||||||
# yarn lockfile v1
|
# yarn lockfile v1
|
||||||
|
|
||||||
|
|
||||||
"@bazel/typescript@0.3.1":
|
"@bazel/typescript@0.3.2":
|
||||||
version "0.3.1"
|
version "0.3.2"
|
||||||
resolved "https://registry.yarnpkg.com/@bazel/typescript/-/typescript-0.3.1.tgz#54367df8f30fa0fb25e41106eb7aa558534c36dd"
|
resolved "https://registry.yarnpkg.com/@bazel/typescript/-/typescript-0.3.2.tgz#b4721b7f9e4c447a553555eab4a437f538a9496d"
|
||||||
dependencies:
|
dependencies:
|
||||||
"@types/node" "7.0.18"
|
"@types/node" "7.0.18"
|
||||||
"@types/source-map" "^0.5.1"
|
"@types/source-map" "^0.5.1"
|
||||||
|
@ -7102,16 +7102,7 @@ ts-api-guardian@0.2.2:
|
||||||
minimist "^1.2.0"
|
minimist "^1.2.0"
|
||||||
typescript "2.0.10"
|
typescript "2.0.10"
|
||||||
|
|
||||||
tsickle@0.25.5:
|
tsickle@0.25.5, tsickle@0.25.x:
|
||||||
version "0.25.5"
|
|
||||||
resolved "https://registry.yarnpkg.com/tsickle/-/tsickle-0.25.5.tgz#2891d29f97c4aab1306e06378d8496d1765a4bfe"
|
|
||||||
dependencies:
|
|
||||||
minimist "^1.2.0"
|
|
||||||
mkdirp "^0.5.1"
|
|
||||||
source-map "^0.5.6"
|
|
||||||
source-map-support "^0.4.2"
|
|
||||||
|
|
||||||
tsickle@0.25.x:
|
|
||||||
version "0.25.5"
|
version "0.25.5"
|
||||||
resolved "https://registry.yarnpkg.com/tsickle/-/tsickle-0.25.5.tgz#2891d29f97c4aab1306e06378d8496d1765a4bfe"
|
resolved "https://registry.yarnpkg.com/tsickle/-/tsickle-0.25.5.tgz#2891d29f97c4aab1306e06378d8496d1765a4bfe"
|
||||||
dependencies:
|
dependencies:
|
||||||
|
|
Loading…
Reference in New Issue