@@ -14,12 +14,7 @@ import YAMLLoader from "./yaml-loader.js";
1414import JSONLoader from "./json-loader.js" ;
1515import { resolveRootDir } from "../utils.js" ;
1616import { writeIfChanged , hashContent , hashFile , hashJSON } from "./fs-cache.js" ;
17- import {
18- BuildManifest ,
19- ManifestEntry ,
20- ManifestOutput ,
21- hashConfig ,
22- } from "./build-manifest.js" ;
17+ import { BuildManifest , ManifestEntry , ManifestOutput , hashConfig } from "./build-manifest.js" ;
2318import {
2419 AnyLoader ,
2520 CompilerContext ,
@@ -472,7 +467,7 @@ export default async function compile(file: string, compilerOptions: CompilerOpt
472467 // Add content hash to URL to bust Node's ESM cache.
473468 // Without this, the same URL always returns the cached module object,
474469 // causing stale content to be used in subsequent builds.
475- const contentHash = crypto . createHash ( ' md5' ) . update ( content ) . digest ( ' hex' ) . slice ( 0 , 8 ) ;
470+ const contentHash = crypto . createHash ( " md5" ) . update ( content ) . digest ( " hex" ) . slice ( 0 , 8 ) ;
476471 const importUrl = pathToFileURL ( cache . outputPath ) . href + `?v=${ contentHash } ` ;
477472 cache . resolve ( ( await import ( importUrl ) ) as Module ) ;
478473 } catch ( importErr ) {
@@ -591,8 +586,11 @@ export default async function compile(file: string, compilerOptions: CompilerOpt
591586 finalizeEntry ( resolvedPath , loaders , result . data ) ;
592587 try {
593588 // Add content hash to URL to bust Node's ESM cache.
594- const contentStr = typeof result . content === 'string' ? result . content : JSON . stringify ( result . content ?? '' ) ;
595- const contentHash = crypto . createHash ( 'md5' ) . update ( contentStr ) . digest ( 'hex' ) . slice ( 0 , 8 ) ;
589+ const contentStr =
590+ typeof result . content === "string"
591+ ? result . content
592+ : JSON . stringify ( result . content ?? "" ) ;
593+ const contentHash = crypto . createHash ( "md5" ) . update ( contentStr ) . digest ( "hex" ) . slice ( 0 , 8 ) ;
596594 const importUrl = pathToFileURL ( cache . outputPath ) . href + `?v=${ contentHash } ` ;
597595 cache . resolve ( ( await import ( importUrl ) ) as Module ) ;
598596 } catch ( importErr ) {
@@ -636,8 +634,7 @@ export default async function compile(file: string, compilerOptions: CompilerOpt
636634 fs . mkdirpSync ( outputDir ) ;
637635 }
638636 logger . info ( `Emitting ${ name } ` ) ;
639- const writable =
640- typeof content === "string" ? content : new Uint8Array ( content ) ;
637+ const writable = typeof content === "string" ? content : new Uint8Array ( content ) ;
641638 const wrote = writeIfChanged ( outputPath , writable ) ;
642639 if ( wrote ) {
643640 changedOutputs . add ( outputPath ) ;
@@ -737,7 +734,9 @@ export default async function compile(file: string, compilerOptions: CompilerOpt
737734 const entry : ManifestEntry = {
738735 sourceHash,
739736 loaders : loaders . map ( ( l ) => l . loader . name || "anonymous" ) ,
740- loaderOptionsHash : hashJSON ( loaders . map ( ( l ) => ( { name : l . loader . name , options : l . options } ) ) ) ,
737+ loaderOptionsHash : hashJSON (
738+ loaders . map ( ( l ) => ( { name : l . loader . name , options : l . options } ) )
739+ ) ,
741740 dependencies : deps ,
742741 outputs,
743742 componentConfig : extractComponentConfigForEntry ( entryPath , data ) ,
@@ -766,10 +765,7 @@ export default async function compile(file: string, compilerOptions: CompilerOpt
766765 * 增量短路:若 manifest 里该 entry 的源/依赖/产物全部命中,则跳过 loader 链。
767766 * 跳过时仍需把 componentConfig merge 回 AppComponentsCompiler(通过触发 loadModule 钩子)。
768767 */
769- async function tryReuseEntry (
770- entryPath : string ,
771- loaders : ResolvedLoaderRule [ ]
772- ) : Promise < boolean > {
768+ async function tryReuseEntry ( entryPath : string , loaders : ResolvedLoaderRule [ ] ) : Promise < boolean > {
773769 if ( options . force ) return false ;
774770 const cached = manifest . get ( entryPath ) ;
775771 if ( ! cached ) return false ;
@@ -778,10 +774,7 @@ export default async function compile(file: string, compilerOptions: CompilerOpt
778774 const loaderOptionsHash = hashJSON (
779775 loaders . map ( ( l ) => ( { name : l . loader . name , options : l . options } ) )
780776 ) ;
781- if (
782- cached . sourceHash !== sourceHash ||
783- cached . loaderOptionsHash !== loaderOptionsHash
784- ) {
777+ if ( cached . sourceHash !== sourceHash || cached . loaderOptionsHash !== loaderOptionsHash ) {
785778 return false ;
786779 }
787780 if ( ! manifest . validateDependencies ( cached ) ) return false ;
0 commit comments