diff --git a/packages/angular/build/src/tools/babel/plugins/add-code-coverage.ts b/packages/angular/build/src/tools/babel/plugins/add-code-coverage.ts index 99afb281fd..efa95870f6 100644 --- a/packages/angular/build/src/tools/babel/plugins/add-code-coverage.ts +++ b/packages/angular/build/src/tools/babel/plugins/add-code-coverage.ts @@ -9,7 +9,6 @@ import { NodePath, PluginObj, types } from '@babel/core'; import { Visitor, programVisitor } from 'istanbul-lib-instrument'; import assert from 'node:assert'; -import { fileURLToPath } from 'node:url'; /** * A babel plugin factory function for adding istanbul instrumentation. @@ -23,19 +22,9 @@ export default function (): PluginObj { visitor: { Program: { enter(path, state) { - const inputSourceMap = // eslint-disable-next-line @typescript-eslint/no-explicit-any - (state.file.inputMap as undefined | { toObject(): Record })?.toObject(); - - // istanbul does not support URL as sources. - if (inputSourceMap?.sources) { - inputSourceMap.sources = inputSourceMap.sources.map((s: string) => - s.startsWith('file://') ? fileURLToPath(s) : s, - ); - } - const visitor = programVisitor(types, state.filename, { // Babel returns a Converter object from the `convert-source-map` package - inputSourceMap, + inputSourceMap: (state.file.inputMap as undefined | { toObject(): object })?.toObject(), }); visitors.set(path, visitor); 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 50fd7e689f..97444b7b4e 100644 --- a/packages/angular/build/src/tools/esbuild/angular/compiler-plugin.ts +++ b/packages/angular/build/src/tools/esbuild/angular/compiler-plugin.ts @@ -19,7 +19,6 @@ import type { import assert from 'node:assert'; import { createHash } from 'node:crypto'; import * as path from 'node:path'; -import { pathToFileURL } from 'node:url'; import { maxWorkers, useTypeChecking } from '../../../utils/environment-options'; import { AngularHostOptions } from '../../angular/angular-host'; import { AngularCompilation, DiagnosticModes, NoopCompilation } from '../../angular/compilation'; @@ -707,10 +706,6 @@ function createCompilerOptionsTransformer( return { ...compilerOptions, noEmitOnError: false, - // Using the path as a URL is necessary here; otherwise, esbuild will not generate source maps correctly. - // https://github.com/evanw/esbuild/issues/4070 - // https://github.com/evanw/esbuild/issues/4075 - outDir: absWorkingDir ? pathToFileURL(absWorkingDir + '/').href : undefined, inlineSources: !!pluginOptions.sourcemap, inlineSourceMap: !!pluginOptions.sourcemap, sourceMap: undefined, diff --git a/packages/angular/build/src/tools/esbuild/stylesheets/less-language.ts b/packages/angular/build/src/tools/esbuild/stylesheets/less-language.ts index 1b99100b90..1f6d8f2b7c 100644 --- a/packages/angular/build/src/tools/esbuild/stylesheets/less-language.ts +++ b/packages/angular/build/src/tools/esbuild/stylesheets/less-language.ts @@ -8,8 +8,6 @@ import type { Location, OnLoadResult, PluginBuild } from 'esbuild'; import { readFile } from 'node:fs/promises'; -import { isAbsolute } from 'node:path'; -import { pathToFileURL } from 'node:url'; import { StylesheetLanguage, StylesheetPluginOptions } from './stylesheet-plugin-factory'; /** @@ -115,7 +113,7 @@ async function compileString( }; try { - const { imports, map, css } = await less.render(data, { + const { imports, css } = await less.render(data, { filename, paths: options.includePaths, plugins: [resolverPlugin], @@ -123,16 +121,14 @@ async function compileString( javascriptEnabled: unsafeInlineJavaScript, sourceMap: options.sourcemap ? { - sourceMapFileInline: false, + sourceMapFileInline: true, outputSourceFiles: true, } : undefined, } as Less.Options); return { - // There can be cases where `less` will return an undefined `map` even - // though the types do not specify this as a possibility. - contents: map ? `${css}\n${sourceMapToUrlComment(map)}` : css, + contents: css, loader: 'css', watchFiles: [filename, ...imports], }; @@ -194,18 +190,3 @@ function convertExceptionLocation(exception: LessException): Partial { lineText: exception.extract && exception.extract[Math.trunc(exception.extract.length / 2)], }; } - -function sourceMapToUrlComment(sourceMap: string): string { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - const map = JSON.parse(sourceMap) as Record; - // Using file URLs instead of paths ensures that esbuild correctly resolves the source map. - // https://github.com/evanw/esbuild/issues/4070 - // https://github.com/evanw/esbuild/issues/4075 - map.sources = map.sources.map((source: string) => - source && isAbsolute(source) ? pathToFileURL(source).href : source, - ); - - const urlSourceMap = Buffer.from(JSON.stringify(map), 'utf-8').toString('base64'); - - return `/*# sourceMappingURL=data:application/json;charset=utf-8;base64,${urlSourceMap} */`; -}