@@ -496,12 +496,24 @@ const packageExport = (
496496 value : unknown ,
497497 moduleKind : ResolveArtifactPathInput [ "moduleKind" ] ,
498498) : PackageExportOutcome => {
499+ if ( typeof value === "object" && value !== null && ! Array . isArray ( value ) ) {
500+ const keys = Object . keys ( value ) ;
501+ if (
502+ keys . some ( ( key ) => key . startsWith ( "." ) ) &&
503+ keys . some ( ( key ) => ! key . startsWith ( "." ) )
504+ )
505+ return {
506+ status : "rejected" ,
507+ limitation :
508+ "The package exports configuration mixes subpath keys and condition keys." ,
509+ } ;
510+ }
499511 const root =
500512 typeof value === "object" && value !== null && Object . hasOwn ( value , "." )
501513 ? Reflect . get ( value , "." )
502514 : value ;
503515 const flattened = exportTargets ( root , packageExportConditions ( moduleKind ) ) ;
504- if ( flattened . kind === "invalid" )
516+ if ( flattened . kind === "invalid" || flattened . kind === "invalid-config" )
505517 return { status : "rejected" , limitation : flattened . limitation } ;
506518 const first =
507519 flattened . kind === "unmatched" ? undefined : flattened . values [ 0 ] ;
@@ -517,7 +529,8 @@ const packageExport = (
517529type ExportTargets =
518530 | { readonly kind : "targets" ; readonly values : readonly string [ ] }
519531 | { readonly kind : "unmatched" }
520- | { readonly kind : "invalid" ; readonly limitation : string } ;
532+ | { readonly kind : "invalid" ; readonly limitation : string }
533+ | { readonly kind : "invalid-config" ; readonly limitation : string } ;
521534
522535const invalidExportTarget = (
523536 value : unknown ,
@@ -570,6 +583,8 @@ const exportTargets = (
570583 let invalid : string | null = null ;
571584 for ( const entry of value ) {
572585 const nested = exportTargets ( entry , conditions ) ;
586+ // Node's array fallback catches invalid targets, not invalid configuration.
587+ if ( nested . kind === "invalid-config" ) return nested ;
573588 if ( nested . kind === "invalid" ) {
574589 invalid = nested . limitation ;
575590 continue ;
@@ -587,6 +602,14 @@ const exportTargets = (
587602 value ,
588603 "must be a relative string, object, array, or null" ,
589604 ) ;
605+ for ( const key of Object . keys ( value ) ) {
606+ const numeric = Number ( key ) ;
607+ if ( String ( numeric ) === key && numeric >= 0 && numeric < 0xffff_ffff )
608+ return {
609+ kind : "invalid-config" ,
610+ limitation : `The package exports configuration contains numeric condition key ${ JSON . stringify ( key ) } .` ,
611+ } ;
612+ }
590613 for ( const [ condition , target ] of Object . entries ( value ) ) {
591614 if ( ! conditions . has ( condition ) ) continue ;
592615 const nested = exportTargets ( target , conditions ) ;
0 commit comments