Fix ts_library to produce files that rollup knows how to find.

Currently we produce .closure.js files with ESModules, this naming convention was chosen arbitrarily to indicate we expected these to be inputs to closure compiler.

However other bundlers don't understand this convention and cannot find their inputs. Today we work around this by copying a bunch of files around before running rollup, but this is a performance issue we can avoid just by naming our outputs in the standard way for esmodules.

PiperOrigin-RevId: 269585536
diff --git a/internal/common/compilation.bzl b/internal/common/compilation.bzl
index 3155f0c..1bcf2bc 100644
--- a/internal/common/compilation.bzl
+++ b/internal/common/compilation.bzl
@@ -194,13 +194,13 @@
             if basename.endswith(ext):
                 basename = basename[:-len(ext)]
                 break
-        closure_js_files += [ctx.actions.declare_file(basename + ".closure.js")]
+        closure_js_files += [ctx.actions.declare_file(basename + ".mjs")]
 
         # Temporary until all imports of ngfactory/ngsummary files are removed
         # TODO(alexeagle): clean up after Ivy launch
         if getattr(ctx, "compile_angular_templates", False):
-            closure_js_files += [ctx.actions.declare_file(basename + ".ngfactory.closure.js")]
-            closure_js_files += [ctx.actions.declare_file(basename + ".ngsummary.closure.js")]
+            closure_js_files += [ctx.actions.declare_file(basename + ".ngfactory.mjs")]
+            closure_js_files += [ctx.actions.declare_file(basename + ".ngsummary.mjs")]
 
         if not is_dts:
             devmode_js_files += [ctx.actions.declare_file(basename + ".js")]
@@ -428,7 +428,7 @@
     # deps (do not re-export transitive types from the transitive closure).
     transitive_decls = depset(src_declarations + gen_declarations, transitive = [dep_declarations.transitive])
 
-    # both ts_library and ts_declarations generate .closure.js files:
+    # both ts_library and ts_declarations generate .mjs files:
     # - for libraries, this is the ES6/production code
     # - for declarations, these are generated shims
     es6_sources = depset(transpiled_closure_js + tsickle_externs)
diff --git a/internal/tsc_wrapped/compiler_host.ts b/internal/tsc_wrapped/compiler_host.ts
index c05b3c3..2b7113b 100644
--- a/internal/tsc_wrapped/compiler_host.ts
+++ b/internal/tsc_wrapped/compiler_host.ts
@@ -142,7 +142,7 @@
    * For the given potentially absolute input file path (typically .ts), returns
    * the relative output path. For example, for
    * /path/to/root/blaze-out/k8-fastbuild/genfiles/my/file.ts, will return
-   * my/file.js or my/file.closure.js (depending on ES5 mode).
+   * my/file.js or my/file.mjs (depending on ES5 mode).
    */
   relativeOutputPath(fileName: string) {
     let result = this.rootDirsRelative(fileName);
@@ -506,13 +506,13 @@
             path.join(this.bazelOpts.transpiledJsOutputDirectory!, fileName);
       }
     } else if (!this.bazelOpts.es5Mode) {
-      // Write ES6 transpiled files to *.closure.js.
+      // Write ES6 transpiled files to *.mjs.
       if (this.bazelOpts.locale) {
         // i18n paths are required to end with __locale.js so we put
         // the .closure segment before the __locale
         fileName = fileName.replace(/(__[^\.]+)?\.js$/, '.closure$1.js');
       } else {
-        fileName = fileName.replace(/\.js$/, '.closure.js');
+        fileName = fileName.replace(/\.js$/, '.mjs');
       }
     }
 
diff --git a/internal/tsc_wrapped/tsc_wrapped_test.ts b/internal/tsc_wrapped/tsc_wrapped_test.ts
index 59d725b..2351cd8 100644
--- a/internal/tsc_wrapped/tsc_wrapped_test.ts
+++ b/internal/tsc_wrapped/tsc_wrapped_test.ts
@@ -259,12 +259,12 @@
     });
 
     describe('output files', () => {
-      it('writes to .closure.js in ES6 mode', () => {
+      it('writes to .mjs in ES6 mode', () => {
         createFakeGoogle3Host({
           es5: false,
         }).writeFile('a.js', 'some.code();', false, undefined, []);
         expect(Object.keys(writtenFiles)).toEqual([
-          '/root/google3/blaze-out/k8-fastbuild/bin/a.closure.js'
+          '/root/google3/blaze-out/k8-fastbuild/bin/a.mjs'
         ]);
       });
 
diff --git a/internal/tsc_wrapped/tsconfig.ts b/internal/tsc_wrapped/tsconfig.ts
index 9bc0a33..a50ac1c 100644
--- a/internal/tsc_wrapped/tsconfig.ts
+++ b/internal/tsc_wrapped/tsconfig.ts
@@ -39,7 +39,7 @@
 
   /**
    * If true, emit devmode output into filename.js.
-   * If false, emit prodmode output into filename.closure.js.
+   * If false, emit prodmode output into filename.mjs.
    */
   es5Mode: boolean;