@@ -32,6 +32,7 @@ type NormalizedOptions = {
32
32
projectRoot : string ;
33
33
projectSourceRoot : string ;
34
34
manifestPath : string ;
35
+ manifestRelPath : string ;
35
36
projectConfig : any ;
36
37
main : string ;
37
38
port : number ;
@@ -70,14 +71,15 @@ export default function config(options: MfSchematicSchema): Rule {
70
71
const workspaceFileName = getWorkspaceFileName ( tree ) ;
71
72
const workspace = JSON . parse ( tree . read ( workspaceFileName ) . toString ( 'utf8' ) ) ;
72
73
73
- const normalized = normalizeOptions ( options , workspace ) ;
74
+ const normalized = normalizeOptions ( options , workspace , tree ) ;
74
75
75
76
const {
76
77
polyfills,
77
78
projectName,
78
79
projectRoot,
79
80
projectSourceRoot,
80
81
manifestPath,
82
+ manifestRelPath,
81
83
main,
82
84
} = normalized ;
83
85
@@ -116,22 +118,30 @@ export default function config(options: MfSchematicSchema): Rule {
116
118
117
119
context . addTask ( new NodePackageInstallTask ( ) ) ;
118
120
119
- return chain ( [ generateRule , makeMainAsync ( main , options , remoteMap ) ] ) ;
121
+ return chain ( [
122
+ generateRule ,
123
+ makeMainAsync ( main , options , remoteMap , manifestRelPath ) ,
124
+ ] ) ;
120
125
} ;
121
126
}
122
127
123
- export function patchAngularBuild ( tree ) {
128
+ export function patchAngularBuild ( tree : Tree ) {
124
129
const packagePath = 'node_modules/@angular/build/package.json' ;
125
130
const privatePath = 'node_modules/@angular/build/private.js' ;
126
131
127
132
if ( ! tree . exists ( packagePath ) ) {
128
133
return ;
129
134
}
130
135
131
- const packageJson = JSON . parse ( tree . read ( packagePath ) ) ;
136
+ const packageJson = JSON . parse ( tree . read ( packagePath ) . toString ( 'utf8' ) ) ;
132
137
patchAngularBuildPackageJson ( packageJson ) ;
133
138
tree . overwrite ( packagePath , JSON . stringify ( packageJson , null , 2 ) ) ;
134
- tree . overwrite ( privatePath , privateEntrySrc ) ;
139
+
140
+ if ( ! tree . exists ( privatePath ) ) {
141
+ tree . create ( privatePath , privateEntrySrc ) ;
142
+ } else {
143
+ tree . overwrite ( privatePath , privateEntrySrc ) ;
144
+ }
135
145
}
136
146
137
147
function updateWorkspaceConfig (
@@ -159,18 +169,14 @@ function updateWorkspaceConfig(
159
169
delete originalBuild . configurations ?. development ?. vendorChunk ;
160
170
}
161
171
162
- // if (originalBuild.options.browser) {
163
- // const browser = originalBuild.options.browser;
164
- // delete originalBuild.options.browser;
165
- // originalBuild.options.main = browser;
166
- // }
167
-
168
172
if ( originalBuild . options . main ) {
169
173
const main = originalBuild . options . main ;
170
174
delete originalBuild . options . main ;
171
175
originalBuild . options . browser = main ;
172
176
}
173
177
178
+ delete originalBuild . options . commonChunk ;
179
+
174
180
projectConfig . architect . esbuild = originalBuild ;
175
181
176
182
projectConfig . architect . build = {
@@ -192,6 +198,8 @@ function updateWorkspaceConfig(
192
198
serve . options ??= { } ;
193
199
serve . options . port = port ;
194
200
201
+ delete serve . options . commonChunk ;
202
+
195
203
const serveProd = projectConfig . architect . serve . configurations ?. production ;
196
204
if ( serveProd ) {
197
205
serveProd . buildTarget = `${ projectName } :esbuild:production` ;
@@ -232,7 +240,8 @@ function updateWorkspaceConfig(
232
240
233
241
function normalizeOptions (
234
242
options : MfSchematicSchema ,
235
- workspace : any
243
+ workspace : any ,
244
+ tree : Tree
236
245
) : NormalizedOptions {
237
246
if ( ! options . project ) {
238
247
options . project = workspace . defaultProject ;
@@ -266,10 +275,22 @@ function normalizeOptions(
266
275
'/'
267
276
) ;
268
277
269
- const manifestPath = path
270
- . join ( projectRoot , 'public/federation.manifest.json' )
278
+ const publicPath = path . join ( projectRoot , 'public' ) . replace ( / \\ / g, '/' ) ;
279
+
280
+ let manifestPath = path
281
+ . join ( publicPath , 'federation.manifest.json' )
271
282
. replace ( / \\ / g, '/' ) ;
272
283
284
+ let manifestRelPath = 'public/federation.manifest.json' ;
285
+
286
+ if ( ! tree . exists ( publicPath ) ) {
287
+ manifestPath = path
288
+ . join ( projectRoot , 'src/assets/federation.manifest.json' )
289
+ . replace ( / \\ / g, '/' ) ;
290
+
291
+ manifestRelPath = 'assets/federation.manifest.json' ;
292
+ }
293
+
273
294
const main =
274
295
projectConfig . architect . build . options . main ||
275
296
projectConfig . architect . build . options . browser ;
@@ -278,13 +299,20 @@ function normalizeOptions(
278
299
projectConfig . architect . build . options . polyfills = [ ] ;
279
300
}
280
301
302
+ if ( typeof projectConfig . architect . build . options . polyfills === 'string' ) {
303
+ projectConfig . architect . build . options . polyfills = [
304
+ projectConfig . architect . build . options . polyfills ,
305
+ ] ;
306
+ }
307
+
281
308
const polyfills = projectConfig . architect . build . options . polyfills ;
282
309
return {
283
310
polyfills,
284
311
projectName,
285
312
projectRoot,
286
313
projectSourceRoot,
287
314
manifestPath,
315
+ manifestRelPath,
288
316
projectConfig,
289
317
main,
290
318
port : + ( options . port || 4200 ) ,
@@ -348,7 +376,8 @@ function generateRemoteMap(workspace: any, projectName: string) {
348
376
function makeMainAsync (
349
377
main : string ,
350
378
options : MfSchematicSchema ,
351
- remoteMap : unknown
379
+ remoteMap : unknown ,
380
+ manifestRelPath : string
352
381
) : Rule {
353
382
return async function ( tree ) {
354
383
const mainPath = path . dirname ( main ) ;
@@ -366,7 +395,7 @@ function makeMainAsync(
366
395
if ( options . type === 'dynamic-host' ) {
367
396
newMainContent = `import { initFederation } from '@angular-architects/native-federation';
368
397
369
- initFederation('federation.manifest.json ')
398
+ initFederation('${ manifestRelPath } ')
370
399
.catch(err => console.error(err))
371
400
.then(_ => import('./bootstrap'))
372
401
.catch(err => console.error(err));
0 commit comments