diff --git a/internal/tsc_wrapped/compiler_host.ts b/internal/tsc_wrapped/compiler_host.ts index 580985f1..8494077e 100644 --- a/internal/tsc_wrapped/compiler_host.ts +++ b/internal/tsc_wrapped/compiler_host.ts @@ -321,6 +321,13 @@ export class CompilerHost implements ts.CompilerHost, tsickle.TsickleHost { relativeFileName) { return this.bazelOpts.moduleName; } + // Support the common case of commonjs convention that index is the + // default module in a directory. + // This makes our module naming scheme more conventional and lets users + // refer to modules with the natural name they're used to. + if (relativeFileName === 'index') { + return this.bazelOpts.moduleName; + } return path.posix.join(this.bazelOpts.moduleName, relativeFileName); } }