@@ -21,10 +21,10 @@ import createCodeSandboxOverlay from './codesandbox-overlay';
21
21
import getPreset from './eval' ;
22
22
import { consumeCache , deleteAPICache , saveCache } from './eval/cache' ;
23
23
import { Module } from './eval/entities/module' ;
24
- import Manager , { Manifest } from './eval/manager' ;
24
+ import Manager from './eval/manager' ;
25
25
import TranspiledModule from './eval/transpiled-module' ;
26
26
import handleExternalResources from './external-resources' ;
27
- import { loadDependencies } from './npm' ;
27
+ import { loadDependencies , NPMDependencies } from './npm' ;
28
28
import { resetScreen } from './status-screen' ;
29
29
import { showRunOnClick } from './status-screen/run-on-click' ;
30
30
@@ -93,6 +93,7 @@ const WHITELISTED_DEV_DEPENDENCIES = [
93
93
'react-addons-test-utils' ,
94
94
'react-test-renderer' ,
95
95
'identity-obj-proxy' ,
96
+ 'react-refresh' ,
96
97
] ;
97
98
98
99
const BABEL_DEPENDENCIES = [
@@ -197,7 +198,11 @@ const PREINSTALLED_DEPENDENCIES = [
197
198
...BABEL_DEPENDENCIES ,
198
199
] ;
199
200
200
- function getDependencies ( parsedPackage , templateDefinition , configurations ) {
201
+ function getDependencies (
202
+ parsedPackage ,
203
+ templateDefinition ,
204
+ configurations
205
+ ) : NPMDependencies {
201
206
const {
202
207
dependencies : d = { } ,
203
208
peerDependencies = { } ,
@@ -304,33 +309,27 @@ function getDependencies(parsedPackage, templateDefinition, configurations) {
304
309
return returnedDependencies ;
305
310
}
306
311
307
- async function updateManager (
312
+ function initializeManager (
308
313
sandboxId : string ,
309
314
template : TemplateType ,
310
- managerModules ,
311
- manifest : Manifest ,
315
+ modules : { [ path : string ] : Module } ,
312
316
configurations : ParsedConfigurationFiles ,
313
- isNewCombination : boolean ,
314
- hasFileResolver : boolean
315
- ) : Promise < TranspiledModule [ ] > {
316
- let newManager = false ;
317
- if ( ! manager || manager . id !== sandboxId ) {
318
- newManager = true ;
319
- manager = new Manager ( sandboxId , getPreset ( template ) , managerModules , {
317
+ { hasFileResolver = false } : { hasFileResolver ?: boolean } = { }
318
+ ) {
319
+ return new Manager (
320
+ sandboxId ,
321
+ getPreset ( template , configurations . package . parsed ) ,
322
+ modules ,
323
+ {
320
324
hasFileResolver,
321
- } ) ;
322
- }
323
-
324
- if ( isNewCombination || newManager ) {
325
- manager . setManifest ( manifest ) ;
326
- }
327
-
328
- if ( firstLoad && newManager ) {
329
- // We save the state of transpiled modules, and load it here again. Gives
330
- // faster initial loads.
331
- await consumeCache ( manager ) ;
332
- }
325
+ }
326
+ ) ;
327
+ }
333
328
329
+ async function updateManager (
330
+ managerModules : { [ path : string ] : Module } ,
331
+ configurations : ParsedConfigurationFiles
332
+ ) : Promise < TranspiledModule [ ] > {
334
333
manager . updateConfigurations ( configurations ) ;
335
334
await manager . preset . setup ( manager ) ;
336
335
return manager . updateData ( managerModules ) . then ( x => {
@@ -402,7 +401,6 @@ interface CompileOptions {
402
401
skipEval ?: boolean ;
403
402
hasFileResolver ?: boolean ;
404
403
disableDependencyPreprocessing ?: boolean ;
405
- showFullScreen ?: boolean ;
406
404
}
407
405
408
406
async function compile ( {
@@ -417,7 +415,6 @@ async function compile({
417
415
skipEval = false ,
418
416
hasFileResolver = false ,
419
417
disableDependencyPreprocessing = false ,
420
- showFullScreen = false ,
421
418
} : CompileOptions ) {
422
419
dispatch ( {
423
420
type : 'start' ,
@@ -471,12 +468,20 @@ async function compile({
471
468
472
469
dispatch ( { type : 'status' , status : 'installing-dependencies' } ) ;
473
470
474
- const dependencies = getDependencies (
471
+ manager =
472
+ manager ||
473
+ initializeManager ( sandboxId , template , modules , configurations , {
474
+ hasFileResolver,
475
+ } ) ;
476
+
477
+ let dependencies : NPMDependencies = getDependencies (
475
478
parsedPackageJSON ,
476
479
templateDefinition ,
477
480
configurations
478
481
) ;
479
482
483
+ dependencies = await manager . preset . processDependencies ( dependencies ) ;
484
+
480
485
const { manifest, isNewCombination } = await loadDependencies (
481
486
dependencies ,
482
487
{
@@ -486,25 +491,34 @@ async function compile({
486
491
}
487
492
) ;
488
493
489
- if ( isNewCombination && ! firstLoad ) {
494
+ const shouldReloadManager =
495
+ ( isNewCombination && ! firstLoad ) || manager . id !== sandboxId ;
496
+
497
+ if ( shouldReloadManager ) {
490
498
// Just reset the whole manager if it's a new combination
491
- if ( manager ) {
492
- manager . dispose ( ) ;
493
- }
494
- manager = null ;
495
- }
496
- const t = Date . now ( ) ;
499
+ manager . dispose ( ) ;
497
500
498
- const updatedModules =
499
- ( await updateManager (
501
+ manager = initializeManager (
500
502
sandboxId ,
501
503
template ,
502
504
modules ,
503
- manifest ,
504
505
configurations ,
505
- isNewCombination ,
506
- hasFileResolver
507
- ) ) || [ ] ;
506
+ { hasFileResolver }
507
+ ) ;
508
+ }
509
+
510
+ if ( shouldReloadManager || firstLoad ) {
511
+ // Now initialize the data the manager can only use once dependencies are loaded
512
+
513
+ manager . setManifest ( manifest ) ;
514
+ // We save the state of transpiled modules, and load it here again. Gives
515
+ // faster initial loads.
516
+ await consumeCache ( manager ) ;
517
+ }
518
+
519
+ const t = Date . now ( ) ;
520
+
521
+ const updatedModules = ( await updateManager ( modules , configurations ) ) || [ ] ;
508
522
509
523
const possibleEntries = templateDefinition . getEntries ( configurations ) ;
510
524
@@ -521,9 +535,6 @@ async function compile({
521
535
const main = absolute ( foundMain ) ;
522
536
managerModuleToTranspile = modules [ main ] ;
523
537
524
- // TODO: make this a separate lifecycle
525
- // await manager.preset.setup(manager);
526
-
527
538
dispatch ( { type : 'status' , status : 'transpiling' } ) ;
528
539
manager . setStage ( 'transpilation' ) ;
529
540
@@ -557,7 +568,7 @@ async function compile({
557
568
/* no */
558
569
}
559
570
560
- manager . preset . preEvaluate ( manager , updatedModules ) ;
571
+ await manager . preset . preEvaluate ( manager , updatedModules ) ;
561
572
562
573
if ( ! manager . webpackHMR ) {
563
574
const htmlModulePath = templateDefinition
0 commit comments