@@ -600,72 +600,100 @@ module Handlers =
600600
601601 let resolutionA = ImportMaps.resolveForBuildA config importMapA
602602
603+ let missing =
604+ adaptive {
605+ let! config = config
606+ let! map = importMapA
607+ return Build.getMissingLocalDependencies config map
608+ }
609+ |> AVal.force
610+
603611 let {
604612 importMap = map
605613 externals = externals
606614 } =
607615 resolutionA |> AVal.force
608616
609- let cssPaths , jsBundleEntrypoints , jsStandalonePaths =
610- Build.EntryPoints document
611-
612- // Step 9: Run esbuild or move/copy output
613- let! esbuildOutput =
614- container.BuildService.RunEsbuild(
615- config,
616- tempDir,
617- cssPaths,
618- jsBundleEntrypoints,
619- externals |> Seq.map UMX.untag |> Seq.toList
617+ // Pre-build check for missing local dependencies
618+ if ( config |> AVal.force) .useLocalPkgs && missing.Length > 0 then
619+ container.Logger.LogError(
620+ " We've found undeclared dependencies: {pkgs}." ,
621+ String.concat " , " missing
620622 )
621623
622- container.BuildService.MoveOrCopyOutput(
623- config,
624- tempDir,
625- esbuildOutput.outputDir
626- )
624+ container.Logger.LogError
625+ " Your project is currently implicitly using these undeclared dependencies, to proceed with the build add them to your dependencies."
627626
628- // Step 10: Write index.html
629- let jsPaths = seq {
630- yield ! jsStandalonePaths
631- yield ! jsBundleEntrypoints
632- }
627+ container.Logger.LogError(
628+ " {cmd}" ,
629+ " perla add " + String.concat " " missing
630+ )
633631
634- do !
635- container.BuildService.WriteIndex(
632+ return 1
633+ else
634+ let cssPaths , jsBundleEntrypoints , jsStandalonePaths =
635+ Build.EntryPoints document
636+
637+ // Step 9: Run esbuild or move/copy output
638+ let! esbuildOutput =
639+ container.BuildService.RunEsbuild(
640+ config,
641+ tempDir,
642+ cssPaths,
643+ jsBundleEntrypoints,
644+ externals |> Seq.map UMX.untag |> Seq.toList
645+ )
646+
647+ container.BuildService.MoveOrCopyOutput(
636648 config,
637- document,
638- map,
639- jsPaths,
640- cssPaths,
641- esbuildOutput.cssFiles
649+ tempDir,
650+ esbuildOutput.outputDir
642651 )
643652
644- // // cleanup temporary directory
645- try
646- Directory.Delete( UMX.untag " .tmp/perla" , true ) |> ignore
647- with ex ->
648- container.Logger.LogWarning(
649- " Failed to delete temporary directory {dir}: {error}" ,
650- UMX.untag " .tmp/perla" ,
651- ex.Message
652- )
653+ // Step 10: Write index.html
654+ let jsPaths = seq {
655+ yield ! jsStandalonePaths
656+ yield ! jsBundleEntrypoints
657+ }
653658
654- // Step 11: Start preview server if requested
655- if options.enablePreview then
656- container.Logger.LogInformation " Starting a preview server for the build"
659+ do !
660+ container.BuildService.WriteIndex(
661+ config,
662+ document,
663+ map,
664+ jsPaths,
665+ cssPaths,
666+ esbuildOutput.cssFiles
667+ )
657668
658- SuaveServer.startStaticServer
659- {
660- Logger = container.Logger
661- VirtualFileSystem = container.VirtualFileSystem
662- Config = config
663- FsManager = container.FsManager
664- FileChangedEvents = container.VirtualFileSystem.FileChanges
665- }
666- token
669+ // // cleanup temporary directory
670+ try
671+ Directory.Delete ( UMX.untag " .tmp/perla " , true ) |> ignore
672+ with ex ->
673+ container.Logger.LogWarning (
674+ " Failed to delete temporary directory {dir}: {error} " ,
675+ UMX.untag " .tmp/perla " ,
676+ ex.Message
677+ )
667678
668- return 0
679+ // Step 11: Start preview server if requested
680+ if options.enablePreview then
681+ container.Logger.LogInformation
682+ " Starting a preview server for the build"
683+
684+ SuaveServer.startStaticServer
685+ {
686+ Logger = container.Logger
687+ VirtualFileSystem = container.VirtualFileSystem
688+ Config = config
689+ FsManager = container.FsManager
690+ FileChangedEvents = container.VirtualFileSystem.FileChanges
691+ }
692+ token
693+
694+ return 0
695+ else
696+ return 0
669697 }
670698
671699 let runServe ( container : AppContainer ) ( options : ServeOptions ) = cancellableTask {
@@ -1031,7 +1059,10 @@ module Handlers =
10311059 " Generating Import Map..." ,
10321060 pkgManager.Install(
10331061 installSet,
1034- [ DefaultProvider provider ],
1062+ [
1063+ DefaultProvider provider
1064+ Env( set [ ExportCondition.Browser; ExportCondition.Module ])
1065+ ],
10351066 cancellationToken = token
10361067 )
10371068 )
@@ -1064,7 +1095,7 @@ module Handlers =
10641095 " Downloading Sources..." ,
10651096 pkgManager.GoOffline(
10661097 installResponse.map,
1067- [ Provider config.provider ],
1098+ [ Provider config.provider; Exclude ( set [ Unused ]) ],
10681099 token
10691100 )
10701101 )
@@ -1165,7 +1196,10 @@ module Handlers =
11651196 " Regenerating import map with remaining packages..." ,
11661197 container.PkgManager.Install(
11671198 remainingPackages,
1168- [ DefaultProvider provider ],
1199+ [
1200+ DefaultProvider provider
1201+ Env( set [ ExportCondition.Browser; ExportCondition.Module ])
1202+ ],
11691203 token
11701204 )
11711205 )
@@ -1184,7 +1218,7 @@ module Handlers =
11841218 " Consolidating local packages..." ,
11851219 container.PkgManager.GoOffline(
11861220 newMapResponse.map,
1187- [ Provider config.provider ],
1221+ [ Provider config.provider; Exclude ( set [ Unused ]) ],
11881222 token
11891223 )
11901224 )
0 commit comments