From a325c9a969c1b2eaca093a6bc39ec0c1230452b9 Mon Sep 17 00:00:00 2001 From: Charles Lyding <19598772+clydin@users.noreply.github.com> Date: Fri, 8 Nov 2024 12:53:32 -0500 Subject: [PATCH] fix(@angular/build): allow .js file replacements in all configuration cases Previously the `fileReplacements` option within the `application` builder would only replace `.js` files if the TypeScript `allowJs` option was enabled. This differs from the `browser` builder which did not require the option. To minimize friction when migrating to the new build system, the `allowJs` option is no longer required for this file replacement case. --- .../src/tools/esbuild/angular/compiler-plugin.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/packages/angular/build/src/tools/esbuild/angular/compiler-plugin.ts b/packages/angular/build/src/tools/esbuild/angular/compiler-plugin.ts index e7964cfe43ac..6d23af4399be 100644 --- a/packages/angular/build/src/tools/esbuild/angular/compiler-plugin.ts +++ b/packages/angular/build/src/tools/esbuild/angular/compiler-plugin.ts @@ -483,12 +483,20 @@ export function createCompilerPlugin( build.onLoad( { filter: /\.[cm]?js$/ }, createCachedLoad(pluginOptions.loadResultCache, async (args) => { + let request = args.path; + if (pluginOptions.fileReplacements) { + const replacement = pluginOptions.fileReplacements[path.normalize(args.path)]; + if (replacement) { + request = path.normalize(replacement); + } + } + return profileAsync( 'NG_EMIT_JS*', async () => { - const sideEffects = await hasSideEffects(args.path); + const sideEffects = await hasSideEffects(request); const contents = await javascriptTransformer.transformFile( - args.path, + request, pluginOptions.jit, sideEffects, ); @@ -496,6 +504,7 @@ export function createCompilerPlugin( return { contents, loader: 'js', + watchFiles: request !== args.path ? [request] : undefined, }; }, true,