@@ -69,11 +69,11 @@ const PUBLISHED_BUNDLED_RUNTIME_SIDECAR_PATHS = BUNDLED_RUNTIME_SIDECAR_PATHS.fi
6969const NODE_BUILTIN_MODULES = new Set ( builtinModules . map ( ( name ) => name . replace ( / ^ n o d e : / u, "" ) ) ) ;
7070const MAX_INSTALLED_ROOT_PACKAGE_JSON_BYTES = 1024 * 1024 ;
7171const MAX_INSTALLED_ROOT_DIST_JS_BYTES = 6 * 1024 * 1024 ;
72+ const MAX_INSTALLED_WORKER_DEPLOY_DIST_JS_BYTES = 80 * 1024 * 1024 ;
7273// Keep the dependency scan bounded while allowing headroom for generated root chunks.
7374const MAX_INSTALLED_ROOT_DIST_JS_FILES = 10_000 ;
7475const ROOT_DIST_JAVASCRIPT_MODULE_FILE_RE = / \. (?: c | m ) ? j s $ / u;
75- // These artifacts bundle their full runtime closure and have a dedicated layout/import guard.
76- // Keep the generic parser bound on every other installed dist file.
76+ // The ~69 MB self-contained worker needs extra headroom, but synchronous read/parse stays bounded.
7777const SELF_CONTAINED_WORKER_DEPLOY_DIST_PATHS = new Set ( [
7878 `worker/${ WORKER_BUNDLE_ENTRY_PATH } ` ,
7979 `worker/${ WORKER_BUNDLE_RSYNC_RECEIVER_PATH } ` ,
@@ -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,22 +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- if (
763- ! fileStat . isFile ( ) ||
764- ( fileStat . size > MAX_INSTALLED_ROOT_DIST_JS_BYTES &&
765- ! SELF_CONTAINED_WORKER_DEPLOY_DIST_PATHS . has ( relativePath ) )
766- ) {
767- return [
768- `installed package root dist file '${ relativePath } ' is invalid or exceeds ${ MAX_INSTALLED_ROOT_DIST_JS_BYTES } bytes.` ,
769- ] ;
768+ const file = readInstalledRootDistJavaScriptFile ( packageRoot , filePath ) ;
769+ if ( ! file . ok ) {
770+ return [ file . error ] ;
770771 }
771- const source = readFileSync ( filePath , "utf8" ) ;
772- const parsedSpecifiers = extractJavaScriptImportSpecifiers ( source ) ;
772+ const parsedSpecifiers = extractJavaScriptImportSpecifiers ( file . source ) ;
773773 if ( ! parsedSpecifiers . ok ) {
774774 return [
775- `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 } .` ,
776776 ] ;
777777 }
778778 for ( const specifier of parsedSpecifiers . specifiers ) {
@@ -785,13 +785,13 @@ export function collectInstalledRootDependencyManifestErrors(packageRoot: string
785785 isBundledExtensionOwnedRuntimeImport ( {
786786 dependencyName,
787787 ownersByDependency : bundledExtensionRuntimeDependencyOwners ,
788- source,
788+ source : file . source ,
789789 } )
790790 ) {
791791 continue ;
792792 }
793793 const importers = missingImporters . get ( dependencyName ) ?? new Set < string > ( ) ;
794- importers . add ( relativePath ) ;
794+ importers . add ( file . relativePath ) ;
795795 missingImporters . set ( dependencyName , importers ) ;
796796 }
797797 }
0 commit comments