@@ -87,6 +87,7 @@ import { readFileSync, writeFileSync } from 'node:fs';
8787import { join , dirname } from 'node:path' ;
8888import { fileURLToPath } from 'node:url' ;
8989import { createContext , runInContext } from 'node:vm' ;
90+ import { isEntrypoint } from '../invoked-as.mjs' ;
9091
9192const HERE = dirname ( fileURLToPath ( import . meta. url ) ) ;
9293const REPO_ROOT = execFileSync ( 'git' , [ 'rev-parse' , '--show-toplevel' ] , { cwd : HERE } )
@@ -466,17 +467,20 @@ export async function checkReadOnlyRouting(source) {
466467
467468// --- main --------------------------------------------------------------------
468469
469- try {
470- if ( args . includes ( '--self-test' ) ) {
471- await selfTest ( ) ;
472- process . exit ( 0 ) ;
470+ // Exports bindings, so an import for those exports alone must run nothing (#10667).
471+ if ( isEntrypoint ( import . meta. url ) ) {
472+ try {
473+ if ( args . includes ( '--self-test' ) ) {
474+ await selfTest ( ) ;
475+ process . exit ( 0 ) ;
476+ }
477+ await main ( ) ;
478+ } catch ( e ) {
479+ // A structural failure (markers gone, list unparseable, derivation empty) is
480+ // a RED result with a readable reason — never a stack trace, never a pass.
481+ console . error ( `✗ ${ e . message } ` ) ;
482+ process . exit ( 1 ) ;
473483 }
474- await main ( ) ;
475- } catch ( e ) {
476- // A structural failure (markers gone, list unparseable, derivation empty) is a
477- // RED result with a readable reason — never a stack trace, and never a pass.
478- console . error ( `✗ ${ e . message } ` ) ;
479- process . exit ( 1 ) ;
480484}
481485
482486async function main ( ) {
0 commit comments