@@ -105,6 +105,10 @@ type DistJavaScriptFileListResult =
105105 | { files : string [ ] ; limitExceeded : false }
106106 | { files : string [ ] ; limit : number ; limitExceeded : true } ;
107107
108+ type InstalledRootDistJavaScriptReadResult =
109+ | { error : string ; ok : false }
110+ | { ok : true ; relativePath : string ; source : string } ;
111+
108112type PublishedInstallScenario = {
109113 name : string ;
110114 installSpecs : string [ ] ;
@@ -474,7 +478,7 @@ export function collectInstalledPackageErrors(params: {
474478 errors . push ( ...collectInstalledPluginSdkDeclarationErrors ( params . packageRoot ) ) ;
475479 errors . push ( ...collectInstalledRootDependencyManifestErrors ( params . packageRoot ) ) ;
476480
477- return errors ;
481+ return [ ... new Set ( errors ) ] ;
478482}
479483
480484export function collectInstalledAlwaysAllowedRuntimeFacadeErrors ( packageRoot : string ) : string [ ] {
@@ -534,13 +538,7 @@ export function normalizeInstalledBinaryVersion(output: string): string {
534538 return versionMatch ?. [ 0 ] ?? trimmed ;
535539}
536540
537- function listDistJavaScriptFiles (
538- packageRoot : string ,
539- opts : {
540- maxFiles ?: number ;
541- skipRelativePath ?: ( relativePath : string ) => boolean ;
542- } = { } ,
543- ) : DistJavaScriptFileListResult {
541+ function listInstalledRootDistJavaScriptFiles ( packageRoot : string ) : DistJavaScriptFileListResult {
544542 const distDir = join ( packageRoot , "dist" ) ;
545543 if ( ! existsSync ( distDir ) ) {
546544 return { files : [ ] , limitExceeded : false } ;
@@ -563,7 +561,7 @@ function listDistJavaScriptFiles(
563561
564562 const entryPath = join ( currentDir , entry . name ) ;
565563 const relativePath = relative ( distDir , entryPath ) . replaceAll ( "\\" , "/" ) ;
566- if ( opts . skipRelativePath ?. ( relativePath ) ) {
564+ if ( relativePath === "extensions" || relativePath . startsWith ( "extensions/" ) ) {
567565 continue ;
568566 }
569567 if ( entry . isDirectory ( ) ) {
@@ -572,10 +570,10 @@ function listDistJavaScriptFiles(
572570 }
573571 if ( entry . isFile ( ) && ROOT_DIST_JAVASCRIPT_MODULE_FILE_RE . test ( entry . name ) ) {
574572 files . push ( entryPath ) ;
575- if ( opts . maxFiles !== undefined && files . length > opts . maxFiles ) {
573+ if ( files . length > MAX_INSTALLED_ROOT_DIST_JS_FILES ) {
576574 return {
577575 files,
578- limit : opts . maxFiles ,
576+ limit : MAX_INSTALLED_ROOT_DIST_JS_FILES ,
579577 limitExceeded : true ,
580578 } ;
581579 }
@@ -593,25 +591,43 @@ function formatInstalledDistFileScanLimitError(scope: string, limit: number): st
593591 return `installed package ${ scope } contains more than ${ limit } JavaScript files; refusing to scan unbounded package contents.` ;
594592}
595593
594+ function readInstalledRootDistJavaScriptFile (
595+ packageRoot : string ,
596+ filePath : string ,
597+ ) : InstalledRootDistJavaScriptReadResult {
598+ const relativePath = relative ( join ( packageRoot , "dist" ) , filePath ) . replaceAll ( "\\" , "/" ) ;
599+ const maxBytes = SELF_CONTAINED_WORKER_DEPLOY_DIST_PATHS . has ( relativePath )
600+ ? MAX_INSTALLED_WORKER_DEPLOY_DIST_JS_BYTES
601+ : MAX_INSTALLED_ROOT_DIST_JS_BYTES ;
602+ const fileStat = lstatSync ( filePath ) ;
603+ if ( ! fileStat . isFile ( ) || fileStat . size > maxBytes ) {
604+ return {
605+ error : `installed package root dist file '${ relativePath } ' is invalid or exceeds ${ maxBytes } bytes.` ,
606+ ok : false ,
607+ } ;
608+ }
609+ return { ok : true , relativePath, source : readFileSync ( filePath , "utf8" ) } ;
610+ }
611+
596612export function collectInstalledContextEngineRuntimeErrors ( packageRoot : string ) : string [ ] {
597- const errors : string [ ] = [ ] ;
598- const distFiles = listDistJavaScriptFiles ( packageRoot , {
599- maxFiles : MAX_INSTALLED_ROOT_DIST_JS_FILES ,
600- } ) ;
613+ const distFiles = listInstalledRootDistJavaScriptFiles ( packageRoot ) ;
601614 if ( distFiles . limitExceeded ) {
602- return [ formatInstalledDistFileScanLimitError ( "dist" , distFiles . limit ) ] ;
615+ return [ formatInstalledDistFileScanLimitError ( "root dist" , distFiles . limit ) ] ;
603616 }
604617
618+ // The legacy marker is a root runtime bundling contract; extension assets are plugin-owned.
605619 for ( const filePath of distFiles . files ) {
606- const contents = readFileSync ( filePath , "utf8" ) ;
607- if ( contents . includes ( LEGACY_CONTEXT_ENGINE_UNRESOLVED_RUNTIME_MARKER ) ) {
608- errors . push (
620+ const file = readInstalledRootDistJavaScriptFile ( packageRoot , filePath ) ;
621+ if ( ! file . ok ) {
622+ return [ file . error ] ;
623+ }
624+ if ( file . source . includes ( LEGACY_CONTEXT_ENGINE_UNRESOLVED_RUNTIME_MARKER ) ) {
625+ return [
609626 "installed package includes unresolved legacy context engine runtime loader; rebuild with a bundler-traceable LegacyContextEngine import." ,
610- ) ;
611- break ;
627+ ] ;
612628 }
613629 }
614- return errors ;
630+ return [ ] ;
615631}
616632
617633function collectInstalledPluginSdkDeclarationErrors ( packageRoot : string ) : string [ ] {
@@ -642,14 +658,6 @@ function collectInstalledPluginSdkDeclarationErrors(packageRoot: string): string
642658 return errors ;
643659}
644660
645- function listInstalledRootDistJavaScriptFiles ( packageRoot : string ) : DistJavaScriptFileListResult {
646- return listDistJavaScriptFiles ( packageRoot , {
647- maxFiles : MAX_INSTALLED_ROOT_DIST_JS_FILES ,
648- skipRelativePath : ( relativePath ) =>
649- relativePath === "extensions" || relativePath . startsWith ( "extensions/" ) ,
650- } ) ;
651- }
652-
653661type ParsedImportSpecifiersResult =
654662 | { ok : true ; specifiers : Set < string > }
655663 | { ok : false ; error : string } ;
@@ -757,21 +765,14 @@ export function collectInstalledRootDependencyManifestErrors(packageRoot: string
757765 collectBundledExtensionRuntimeDependencyOwners ( packageRoot ) ;
758766
759767 for ( const filePath of distFiles . files ) {
760- const fileStat = lstatSync ( filePath ) ;
761- const relativePath = relative ( join ( packageRoot , "dist" ) , filePath ) . replaceAll ( "\\" , "/" ) ;
762- const maxBytes = SELF_CONTAINED_WORKER_DEPLOY_DIST_PATHS . has ( relativePath )
763- ? MAX_INSTALLED_WORKER_DEPLOY_DIST_JS_BYTES
764- : MAX_INSTALLED_ROOT_DIST_JS_BYTES ;
765- if ( ! fileStat . isFile ( ) || fileStat . size > maxBytes ) {
766- return [
767- `installed package root dist file '${ relativePath } ' is invalid or exceeds ${ maxBytes } bytes.` ,
768- ] ;
768+ const file = readInstalledRootDistJavaScriptFile ( packageRoot , filePath ) ;
769+ if ( ! file . ok ) {
770+ return [ file . error ] ;
769771 }
770- const source = readFileSync ( filePath , "utf8" ) ;
771- const parsedSpecifiers = extractJavaScriptImportSpecifiers ( source ) ;
772+ const parsedSpecifiers = extractJavaScriptImportSpecifiers ( file . source ) ;
772773 if ( ! parsedSpecifiers . ok ) {
773774 return [
774- `installed package root dist file '${ relativePath } ' could not be parsed for runtime dependency verification: ${ parsedSpecifiers . error } .` ,
775+ `installed package root dist file '${ file . relativePath } ' could not be parsed for runtime dependency verification: ${ parsedSpecifiers . error } .` ,
775776 ] ;
776777 }
777778 for ( const specifier of parsedSpecifiers . specifiers ) {
@@ -784,13 +785,13 @@ export function collectInstalledRootDependencyManifestErrors(packageRoot: string
784785 isBundledExtensionOwnedRuntimeImport ( {
785786 dependencyName,
786787 ownersByDependency : bundledExtensionRuntimeDependencyOwners ,
787- source,
788+ source : file . source ,
788789 } )
789790 ) {
790791 continue ;
791792 }
792793 const importers = missingImporters . get ( dependencyName ) ?? new Set < string > ( ) ;
793- importers . add ( relativePath ) ;
794+ importers . add ( file . relativePath ) ;
794795 missingImporters . set ( dependencyName , importers ) ;
795796 }
796797 }
0 commit comments