@@ -68,6 +68,50 @@ async function writeBaileysMediaFile(packageRoot: string, text: string) {
6868}
6969
7070describe ( "bundled plugin postinstall" , ( ) => {
71+ it ( "resolves TypeScript from NODE_PATH during external modules-dir installs" , async ( ) => {
72+ const packageRoot = await createTempDirAsync ( "openclaw-postinstall-node-path-" ) ;
73+ const scriptRoot = path . join ( packageRoot , "scripts" ) ;
74+ const externalModulesDir = path . join ( packageRoot , "external-node-modules" ) ;
75+ await fs . mkdir ( path . join ( scriptRoot , "lib" ) , { recursive : true } ) ;
76+ await fs . mkdir ( externalModulesDir , { recursive : true } ) ;
77+ await fs . writeFile (
78+ path . join ( packageRoot , "package.json" ) ,
79+ '{"name":"openclaw","type":"module","version":"2026.7.2"}\n' ,
80+ ) ;
81+ for ( const relativePath of [
82+ "scripts/postinstall-bundled-plugins.mjs" ,
83+ "scripts/lib/package-dist-imports.mjs" ,
84+ "scripts/lib/guard-inventory-utils.mjs" ,
85+ ] ) {
86+ await fs . copyFile (
87+ fileURLToPath ( new URL ( `../../${ relativePath } ` , import . meta. url ) ) ,
88+ path . join ( packageRoot , relativePath ) ,
89+ ) ;
90+ }
91+ await fs . symlink (
92+ fileURLToPath ( new URL ( "../../node_modules/typescript" , import . meta. url ) ) ,
93+ path . join ( externalModulesDir , "typescript" ) ,
94+ process . platform === "win32" ? "junction" : "dir" ,
95+ ) ;
96+
97+ const result = spawnSync (
98+ process . execPath ,
99+ [ path . join ( scriptRoot , "postinstall-bundled-plugins.mjs" ) ] ,
100+ {
101+ cwd : packageRoot ,
102+ encoding : "utf8" ,
103+ env : {
104+ ...process . env ,
105+ NODE_PATH : [ externalModulesDir , process . env . NODE_PATH ]
106+ . filter ( Boolean )
107+ . join ( path . delimiter ) ,
108+ } ,
109+ } ,
110+ ) ;
111+
112+ expect ( result . status , result . stderr ) . toBe ( 0 ) ;
113+ } ) ;
114+
71115 it ( "recognizes direct invocation through symlinked temp prefixes" , ( ) => {
72116 const realpathSync = vi . fn ( ( value : string ) =>
73117 value . replace ( / ^ \/ v a r \/ f o l d e r s \/ / u, "/private/var/folders/" ) ,
0 commit comments