File tree Expand file tree Collapse file tree 2 files changed +34
-1
lines changed Expand file tree Collapse file tree 2 files changed +34
-1
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ import type { IProductConfiguration } from './vs/base/common/product.js';
1111
1212const require = createRequire ( import . meta. url ) ;
1313const __dirname = path . dirname ( fileURLToPath ( import . meta. url ) ) ;
14+ const isWindows = process . platform === 'win32' ;
1415
1516// increase number of stack frames(from 10, https://github.com/v8/v8/wiki/Stack-Trace-API)
1617Error . stackTraceLimit = 100 ;
@@ -97,6 +98,35 @@ export function removeGlobalNodeJsModuleLookupPaths(): void {
9798
9899 return paths ;
99100 } ;
101+
102+ const originalNodeModulePaths = Module . _nodeModulePaths ;
103+ Module . _nodeModulePaths = function ( from : string ) : string [ ] {
104+ let paths : string [ ] = originalNodeModulePaths ( from ) ;
105+ if ( ! isWindows ) {
106+ return paths ;
107+ }
108+
109+ // On Windows, remove drive(s) and users' home directory from search paths,
110+ // UNLESS 'from' is explicitly set to one of those.
111+ const isDrive = ( p : string ) => p . length >= 3 && p . endsWith ( ':\\' ) ;
112+
113+ if ( ! isDrive ( from ) ) {
114+ paths = paths . filter ( p => ! isDrive ( path . dirname ( p ) ) ) ;
115+ }
116+
117+ if ( process . env . HOMEDRIVE && process . env . HOMEPATH ) {
118+ const userDir = path . dirname ( path . join ( process . env . HOMEDRIVE , process . env . HOMEPATH ) ) ;
119+
120+ const isUsersDir = ( p : string ) => path . relative ( p , userDir ) . length === 0 ;
121+
122+ // Check if 'from' is the same as 'userDir'
123+ if ( ! isUsersDir ( from ) ) {
124+ paths = paths . filter ( p => ! isUsersDir ( path . dirname ( p ) ) ) ;
125+ }
126+ }
127+
128+ return paths ;
129+ } ;
100130}
101131
102132/**
Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ import * as readline from 'readline';
1212import { performance } from 'perf_hooks' ;
1313import { fileURLToPath } from 'url' ;
1414import minimist from 'minimist' ;
15- import { devInjectNodeModuleLookupPath } from './bootstrap-node.js' ;
15+ import { devInjectNodeModuleLookupPath , removeGlobalNodeJsModuleLookupPaths } from './bootstrap-node.js' ;
1616import { bootstrapESM } from './bootstrap-esm.js' ;
1717import { resolveNLSConfiguration } from './vs/base/node/nls.js' ;
1818import { product } from './bootstrap-meta.js' ;
@@ -247,6 +247,9 @@ async function loadCode(nlsConfiguration: INLSConfiguration) {
247247 delete process . env [ 'VSCODE_DEV_INJECT_NODE_MODULE_LOOKUP_PATH' ] ;
248248 }
249249
250+ // Remove global paths from the node module lookup (node.js only)
251+ removeGlobalNodeJsModuleLookupPaths ( ) ;
252+
250253 // Bootstrap ESM
251254 await bootstrapESM ( ) ;
252255
You can’t perform that action at this time.
0 commit comments