MCPcopy Create free account
hub / github.com/angular/angular / emitFile

Function emitFile

packages/compiler-cli/preprocessor/ngp.ts:156–270  ·  view source on GitHub ↗
(
  file: AnalysisResult,
  outDir: string | null,
  compiler: HybridCompiler,
  options: RunOptions,
  chunkContext: ChunkContext,
  rootDir: string,
  tracer: Tracer,
  fileId: number,
)

Source from the content-addressed store, hash-verified

154}
155
156async function emitFile(
157 file: AnalysisResult,
158 outDir: string | null,
159 compiler: HybridCompiler,
160 options: RunOptions,
161 chunkContext: ChunkContext,
162 rootDir: string,
163 tracer: Tracer,
164 fileId: number,
165) {
166 const {filePath} = file;
167 const content =
168 compiler.fileCache.get(filePath)?.sourceContent ?? (await fs.readFile(filePath, 'utf-8'));
169 const processed = await compiler.processFile(filePath, content, file, chunkContext, fileId);
170 const s = processed.magicString;
171
172 const writeOutput = outDir || options.inPlace;
173 const emitsTcb = compiler.optimize && !compiler.emitDeclarationOnly;
174
175 if (options.inPlace && !outDir && !s.hasChanged() && !processed.tcb?.code) {
176 return;
177 }
178
179 if (writeOutput) {
180 if (tracer.enabled && !s.hasChanged()) {
181 tracer.count(Counter.UnchangedFilesEmitted);
182 }
183 let outputPath: string;
184 let relativeSourcePath: string;
185
186 if (outDir) {
187 const normalizedRoot =
188 process.platform === 'win32' || process.platform === 'darwin'
189 ? rootDir.toLowerCase()
190 : rootDir;
191 const normalizedFile =
192 process.platform === 'win32' || process.platform === 'darwin'
193 ? filePath.toLowerCase()
194 : filePath;
195 const relativePath = path.relative(normalizedRoot, normalizedFile);
196 outputPath = path.join(outDir, relativePath);
197 relativeSourcePath = relativePath;
198 } else {
199 outputPath = filePath.replace(/\.ts$/, '.ng.ts');
200 relativeSourcePath = path.basename(filePath);
201 }
202
203 const outputDir = path.dirname(outputPath);
204 const mapPath = outputPath + '.map';
205
206 if (outDir) {
207 await fs.mkdir(outputDir, {recursive: true});
208 }
209
210 const outputBase = path.basename(outputPath);
211 const mapCacheKey = `${relativeSourcePath}\0${outputBase}`;
212 let mapEntry = reusedSourceMapCache.get(processed);
213 if (!mapEntry || mapEntry.key !== mapCacheKey) {

Callers 1

processFileFunction · 0.85

Calls 15

processFileMethod · 0.80
mkdirMethod · 0.80
generateSourceMapMethod · 0.80
getMethod · 0.65
readFileMethod · 0.65
countMethod · 0.65
relativeMethod · 0.65
joinMethod · 0.65
basenameMethod · 0.65
dirnameMethod · 0.65
sliceMethod · 0.65
toStringMethod · 0.65

Tested by

no test coverage detected