@@ -239,7 +239,7 @@ config.plugins.push(
239
239
inject : false ,
240
240
scriptLoading : "defer" ,
241
241
templateContent : ( props ) => {
242
- let entrypoints = [ ] ;
242
+ const entrypoints = [ ] ;
243
243
244
244
for ( const entryPoint of props . compilation . entrypoints . values ( ) ) {
245
245
for ( const chunk of entryPoint . chunks ) {
@@ -259,120 +259,125 @@ config.plugins.push(
259
259
return item ;
260
260
} ) ;
261
261
262
- let manifest ;
262
+ let customManifest ;
263
+
263
264
try {
264
- manifest = fs . readFileSync ( path . resolve ( process . env . INIT_CWD , "manifest.json" ) , "utf8" ) ;
265
+ customManifest = JSON . parse ( fs . readFileSync ( path . resolve ( process . env . INIT_CWD , "manifest.json" ) , "utf8" ) ) ;
265
266
} catch ( _ ) {
266
- let entrypoint = null ;
267
-
268
- if ( entrypoints . length === 1 ) {
269
- entrypoint = entrypoints [ 0 ] . id ;
270
- } else {
271
- const dependencyGraph = { } ;
272
-
273
- for ( const chunk of entrypoints ) {
274
- props . compilation . chunkGraph . getChunkModulesIterable ( chunk ) . forEach ( ( fragment ) => {
275
- const matchedImports = fragment . dependencies . filter (
276
- ( item ) => item . request === "@lastui/rocker/platform" && item . name === "Module" ,
277
- ) ;
278
-
279
- if ( matchedImports . length > 0 ) {
280
- fragment . _source . _sourceMapAsObject . sourcesContent . forEach ( ( sourceCode ) => {
281
- const ast = parser . parse ( sourceCode , {
282
- sourceType : "module" ,
283
- plugins : [ "jsx" ] ,
284
- } ) ;
285
-
286
- traverse ( ast , {
287
- CallExpression : ( path ) => {
288
- if ( path . node . callee . type !== "MemberExpression" ) {
289
- return ;
290
- }
291
- if ( path . node . callee . object . name !== "React" ) {
292
- return ;
293
- }
294
- if ( path . node . callee . property . name !== "createElement" ) {
295
- return ;
296
- }
297
- if ( path . node . arguments . length < 2 ) {
298
- return ;
299
- }
300
- if ( path . node . arguments [ 0 ] . type !== "Identifier" && path . node . arguments [ 0 ] . name !== "Module" ) {
301
- return ;
302
- }
303
- if ( path . node . arguments [ 1 ] . type !== "ObjectExpression" ) {
304
- return ;
305
- }
267
+ customManifest = { } ;
268
+ }
269
+
270
+ const implicitContext = { } ;
271
+
272
+ if ( entrypoints . length === 1 ) {
273
+ implicitContext . entrypoint = entrypoints [ 0 ] . id ;
274
+ } else {
275
+ const dependencyGraph = { } ;
276
+
277
+ for ( const chunk of entrypoints ) {
278
+ props . compilation . chunkGraph . getChunkModulesIterable ( chunk ) . forEach ( ( fragment ) => {
279
+ const matchedImports = fragment . dependencies . filter (
280
+ ( item ) => item . request === "@lastui/rocker/platform" && item . name === "Module" ,
281
+ ) ;
306
282
307
- ( path . node . arguments [ 1 ] . properties ?? [ ] ) . forEach ( ( attribute ) => {
308
- if ( attribute . key . type === "Identifier" && attribute . key . name === "name" ) {
309
- if ( ! dependencyGraph [ chunk . id ] ) {
310
- dependencyGraph [ chunk . id ] = [ ] ;
311
- }
312
- if ( ! dependencyGraph [ attribute . value . value ] ) {
313
- dependencyGraph [ attribute . value . value ] = [ ] ;
314
- }
315
- if ( ! dependencyGraph [ attribute . value . value ] . includes ( chunk . id ) ) {
316
- dependencyGraph [ attribute . value . value ] . push ( chunk . id ) ;
317
- }
283
+ if ( matchedImports . length > 0 ) {
284
+ fragment . _source . _sourceMapAsObject . sourcesContent . forEach ( ( sourceCode ) => {
285
+ const ast = parser . parse ( sourceCode , {
286
+ sourceType : "module" ,
287
+ plugins : [ "jsx" ] ,
288
+ } ) ;
289
+
290
+ traverse ( ast , {
291
+ CallExpression : ( path ) => {
292
+ if ( path . node . callee . type !== "MemberExpression" ) {
293
+ return ;
294
+ }
295
+ if ( path . node . callee . object . name !== "React" ) {
296
+ return ;
297
+ }
298
+ if ( path . node . callee . property . name !== "createElement" ) {
299
+ return ;
300
+ }
301
+ if ( path . node . arguments . length < 2 ) {
302
+ return ;
303
+ }
304
+ if ( path . node . arguments [ 0 ] . type !== "Identifier" && path . node . arguments [ 0 ] . name !== "Module" ) {
305
+ return ;
306
+ }
307
+ if ( path . node . arguments [ 1 ] . type !== "ObjectExpression" ) {
308
+ return ;
309
+ }
310
+
311
+ ( path . node . arguments [ 1 ] . properties ?? [ ] ) . forEach ( ( attribute ) => {
312
+ if ( attribute . key . type === "Identifier" && attribute . key . name === "name" ) {
313
+ if ( ! dependencyGraph [ chunk . id ] ) {
314
+ dependencyGraph [ chunk . id ] = [ ] ;
315
+ }
316
+ if ( ! dependencyGraph [ attribute . value . value ] ) {
317
+ dependencyGraph [ attribute . value . value ] = [ ] ;
318
+ }
319
+ if ( ! dependencyGraph [ attribute . value . value ] . includes ( chunk . id ) ) {
320
+ dependencyGraph [ attribute . value . value ] . push ( chunk . id ) ;
318
321
}
319
- } ) ;
320
- } ,
321
- JSXElement : ( path ) => {
322
- if ( path . node . openingElement . name . name !== "Module" ) {
323
- return ;
324
322
}
325
- ( path . node . openingElement . attributes ?? [ ] ) . forEach ( ( attribute ) => {
326
- if ( attribute . name . type === "JSXIdentifier" && attribute . name . name === "name" ) {
327
- if ( ! dependencyGraph [ chunk . id ] ) {
328
- dependencyGraph [ chunk . id ] = [ ] ;
329
- }
330
- if ( ! dependencyGraph [ attribute . value . value ] ) {
331
- dependencyGraph [ attribute . value . value ] = [ ] ;
332
- }
333
- if ( ! dependencyGraph [ attribute . value . value ] . includes ( chunk . id ) ) {
334
- dependencyGraph [ attribute . value . value ] . push ( chunk . id ) ;
335
- }
323
+ } ) ;
324
+ } ,
325
+ JSXElement : ( path ) => {
326
+ if ( path . node . openingElement . name . name !== "Module" ) {
327
+ return ;
328
+ }
329
+ ( path . node . openingElement . attributes ?? [ ] ) . forEach ( ( attribute ) => {
330
+ if ( attribute . name . type === "JSXIdentifier" && attribute . name . name === "name" ) {
331
+ if ( ! dependencyGraph [ chunk . id ] ) {
332
+ dependencyGraph [ chunk . id ] = [ ] ;
336
333
}
337
- } ) ;
338
- } ,
339
- } ) ;
334
+ if ( ! dependencyGraph [ attribute . value . value ] ) {
335
+ dependencyGraph [ attribute . value . value ] = [ ] ;
336
+ }
337
+ if ( ! dependencyGraph [ attribute . value . value ] . includes ( chunk . id ) ) {
338
+ dependencyGraph [ attribute . value . value ] . push ( chunk . id ) ;
339
+ }
340
+ }
341
+ } ) ;
342
+ } ,
340
343
} ) ;
341
- }
342
- } ) ;
343
- }
344
+ } ) ;
345
+ }
346
+ } ) ;
347
+ }
344
348
345
- const executionOrder = [ ] ;
346
- const visited = { } ;
347
- const completed = { } ;
348
- const trail = { } ;
349
+ const executionOrder = [ ] ;
350
+ const visited = { } ;
351
+ const completed = { } ;
352
+ const trail = { } ;
349
353
350
- function walk ( node ) {
351
- if ( completed [ node ] ) {
352
- return ;
353
- }
354
- if ( trail [ node ] ) {
355
- return executionOrder . unshift ( node ) ;
356
- }
357
- visited [ node ] = true ;
358
- trail [ node ] = true ;
359
- dependencyGraph [ node ] . forEach ( walk ) ;
360
- delete trail [ node ] ;
361
- completed [ node ] = true ;
362
- executionOrder . unshift ( node ) ;
354
+ function walk ( node ) {
355
+ if ( completed [ node ] ) {
356
+ return ;
363
357
}
364
-
365
- for ( const node of Object . keys ( dependencyGraph ) ) {
366
- if ( visited [ node ] ) {
367
- continue ;
368
- }
369
- walk ( node ) ;
358
+ if ( trail [ node ] ) {
359
+ return executionOrder . unshift ( node ) ;
370
360
}
361
+ visited [ node ] = true ;
362
+ trail [ node ] = true ;
363
+ dependencyGraph [ node ] . forEach ( walk ) ;
364
+ delete trail [ node ] ;
365
+ completed [ node ] = true ;
366
+ executionOrder . unshift ( node ) ;
367
+ }
371
368
372
- entrypoint = executionOrder [ executionOrder . length - 1 ] ;
369
+ for ( const node of Object . keys ( dependencyGraph ) ) {
370
+ if ( visited [ node ] ) {
371
+ continue ;
372
+ }
373
+ walk ( node ) ;
373
374
}
374
375
375
- const available = entrypoints . map ( ( chunk ) => {
376
+ implicitContext . entrypoint = executionOrder [ executionOrder . length - 1 ] ;
377
+ }
378
+
379
+ if ( entrypoints . length > 0 ) {
380
+ implicitContext . available = entrypoints . map ( ( chunk ) => {
376
381
const entry = {
377
382
name : chunk . id ,
378
383
program : {
@@ -391,11 +396,30 @@ config.plugins.push(
391
396
}
392
397
return entry ;
393
398
} ) ;
399
+ }
394
400
395
- manifest = JSON . stringify ( {
396
- entrypoint,
397
- available,
398
- } ) ;
401
+ const mergedManifest = { } ;
402
+
403
+ if ( customManifest . environment ) {
404
+ mergedManifest . environment = customManifest . environment ;
405
+ }
406
+
407
+ if ( customManifest . entrypoint ) {
408
+ mergedManifest . entrypoint = customManifest . entrypoint ;
409
+ } else if ( implicitContext . entrypoint ) {
410
+ mergedManifest . entrypoint = implicitContext . entrypoint ;
411
+ }
412
+
413
+ if ( customManifest . available && implicitContext . available ) {
414
+ mergedManifest . available = customManifest . available ;
415
+ for ( const entry of implicitContext . available ) {
416
+ mergedManifest . available = mergedManifest . available . filter ( ( existing ) => existing . name === entry . name ) ;
417
+ mergedManifest . available . push ( entry ) ;
418
+ }
419
+ } else if ( customManifest . available ) {
420
+ mergedManifest . available = customManifest . available ;
421
+ } else {
422
+ mergedManifest . available = implicitContext . available ;
399
423
}
400
424
401
425
return `
@@ -408,7 +432,7 @@ config.plugins.push(
408
432
(function() {
409
433
"use strict";
410
434
411
- const manifest = ${ manifest . trim ( ) } ;
435
+ const manifest = ${ JSON . stringify ( mergedManifest ) . trim ( ) } ;
412
436
413
437
window.addEventListener("DOMContentLoaded", function() {
414
438
const react = rocker_so_dependencies("./node_modules/react/index.js");
@@ -425,7 +449,7 @@ config.plugins.push(
425
449
})
426
450
}())
427
451
</script>
428
- <div id="${ settings . PROJECT_NAME } " style="width: 100%; height: 100%;" />
452
+ <div id="${ settings . PROJECT_NAME } " style="width: 100%; min- height: 100%; display: grid ;" />
429
453
</body>
430
454
</html>
431
455
` ;
0 commit comments