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';
11
11
12
12
const require = createRequire ( import . meta. url ) ;
13
13
const __dirname = path . dirname ( fileURLToPath ( import . meta. url ) ) ;
14
+ const isWindows = process . platform === 'win32' ;
14
15
15
16
// increase number of stack frames(from 10, https://github.com/v8/v8/wiki/Stack-Trace-API)
16
17
Error . stackTraceLimit = 100 ;
@@ -97,6 +98,35 @@ export function removeGlobalNodeJsModuleLookupPaths(): void {
97
98
98
99
return paths ;
99
100
} ;
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
+ } ;
100
130
}
101
131
102
132
/**
Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ import * as readline from 'readline';
12
12
import { performance } from 'perf_hooks' ;
13
13
import { fileURLToPath } from 'url' ;
14
14
import minimist from 'minimist' ;
15
- import { devInjectNodeModuleLookupPath } from './bootstrap-node.js' ;
15
+ import { devInjectNodeModuleLookupPath , removeGlobalNodeJsModuleLookupPaths } from './bootstrap-node.js' ;
16
16
import { bootstrapESM } from './bootstrap-esm.js' ;
17
17
import { resolveNLSConfiguration } from './vs/base/node/nls.js' ;
18
18
import { product } from './bootstrap-meta.js' ;
@@ -247,6 +247,9 @@ async function loadCode(nlsConfiguration: INLSConfiguration) {
247
247
delete process . env [ 'VSCODE_DEV_INJECT_NODE_MODULE_LOOKUP_PATH' ] ;
248
248
}
249
249
250
+ // Remove global paths from the node module lookup (node.js only)
251
+ removeGlobalNodeJsModuleLookupPaths ( ) ;
252
+
250
253
// Bootstrap ESM
251
254
await bootstrapESM ( ) ;
252
255
You can’t perform that action at this time.
0 commit comments