@@ -38,9 +38,6 @@ import {
38
38
import { RebuildEvents , RebuildHubs } from './rebuild-events' ;
39
39
40
40
import JSON5 from 'json5' ;
41
- // import { ComponentStylesheetBundler } from '@angular/build/src/tools/esbuild/angular/component-stylesheets';
42
-
43
- // const fesmFolderRegExp = /[/\\]fesm\d+[/\\]/;
44
41
45
42
export type MemResultHandler = (
46
43
outfiles : esbuild . OutputFile [ ] ,
@@ -72,6 +69,8 @@ export function createAngularBuildAdapter(
72
69
platform,
73
70
} = options ;
74
71
72
+ setNgServerMode ( ) ;
73
+
75
74
const files = await runEsbuild (
76
75
builderOptions ,
77
76
context ,
@@ -285,26 +284,6 @@ async function runEsbuild(
285
284
createCompilerPlugin (
286
285
pluginOptions . pluginOptions ,
287
286
pluginOptions . styleOptions
288
-
289
- // TODO: Once available, use helper functions
290
- // for creating these config objects:
291
- // @angular_devkit /build_angular/src/tools/esbuild/compiler-plugin-options.ts
292
- // {
293
- // jit: false,
294
- // sourcemap: dev,
295
- // tsconfig: tsConfigPath,
296
- // advancedOptimizations: !dev,
297
- // thirdPartySourcemaps: false,
298
- // },
299
- // {
300
- // optimization: !dev,
301
- // sourcemap: dev ? 'inline' : false,
302
- // workspaceRoot: __dirname,
303
- // inlineStyleLanguage: builderOptions.inlineStyleLanguage,
304
- // // browsers: browsers,
305
-
306
- // target: target,
307
- // }
308
287
) ,
309
288
...( mappedPaths && mappedPaths . length > 0
310
289
? [ createSharedMappingsPlugin ( mappedPaths ) ]
@@ -338,17 +317,9 @@ async function runEsbuild(
338
317
ctx . dispose ( ) ;
339
318
}
340
319
341
- // cleanUpTsConfigForFederation(tsConfigPath);
342
-
343
320
return writtenFiles ;
344
321
}
345
322
346
- // function cleanUpTsConfigForFederation(tsConfigPath: string) {
347
- // if (tsConfigPath.includes('.federation.')) {
348
- // fs.unlinkSync(tsConfigPath);
349
- // }
350
- // }
351
-
352
323
function createTsConfigForFederation (
353
324
workspaceRoot : string ,
354
325
tsConfigPath : string ,
@@ -365,11 +336,6 @@ function createTsConfigForFederation(
365
336
. map ( ( ep ) => path . relative ( tsconfigDir , ep . fileName ) . replace ( / \\ \\ / g, '/' ) ) ;
366
337
367
338
const tsconfigAsString = fs . readFileSync ( fullTsConfigPath , 'utf-8' ) ;
368
- // const tsconfigWithoutComments = tsconfigAsString.replace(
369
- // /\/\*.+?\*\/|\/\/.*(?=[\n\r])/g,
370
- // ''
371
- // );
372
-
373
339
const tsconfig = JSON5 . parse ( tsconfigAsString ) ;
374
340
375
341
if ( ! tsconfig . include ) {
@@ -450,3 +416,32 @@ export function loadEsmModule<T>(modulePath: string | URL): Promise<T> {
450
416
modulePath
451
417
) as Promise < T > ;
452
418
}
419
+
420
+ //
421
+ // Usually, ngServerMode is set during bundling. However, we need to infer this
422
+ // value at runtime as we are using the same shared bundle for @angular /core
423
+ // on the server and in the browser.
424
+ //
425
+ function setNgServerMode ( ) : void {
426
+ const fileToPatch = 'node_modules/@angular/core/fesm2022/core.mjs' ;
427
+ const lineToAdd = `const ngServerMode = (typeof window === 'undefined') ? true : false;` ;
428
+
429
+ try {
430
+ if ( fs . existsSync ( fileToPatch ) ) {
431
+ let content = fs . readFileSync ( fileToPatch , 'utf-8' ) ;
432
+ if ( ! content . includes ( lineToAdd ) ) {
433
+ content = lineToAdd + '\n' + content ;
434
+ fs . writeFileSync ( fileToPatch , content ) ;
435
+ console . log ( 'patched!' ) ;
436
+ } else {
437
+ console . log ( 'not patched!' ) ;
438
+ }
439
+ }
440
+ } catch ( e ) {
441
+ console . error (
442
+ 'Error patching file ' ,
443
+ fileToPatch ,
444
+ '\nIs it write-protected?'
445
+ ) ;
446
+ }
447
+ }
0 commit comments