77'use strict' ;
88
99const bootstrap = require ( './bootstrap' ) ;
10+ const bootstrapNode = require ( './bootstrap-node' ) ;
1011
1112// Remove global paths from the node module lookup
12- removeGlobalNodeModuleLookupPaths ( ) ;
13+ bootstrapNode . removeGlobalNodeModuleLookupPaths ( ) ;
1314
1415// Enable ASAR in our forked processes
1516bootstrap . enableASARSupport ( ) ;
1617
1718if ( process . env [ 'VSCODE_INJECT_NODE_MODULE_LOOKUP_PATH' ] ) {
18- injectNodeModuleLookupPath ( process . env [ 'VSCODE_INJECT_NODE_MODULE_LOOKUP_PATH' ] ) ;
19+ bootstrapNode . injectNodeModuleLookupPath ( process . env [ 'VSCODE_INJECT_NODE_MODULE_LOOKUP_PATH' ] ) ;
1920}
2021
2122// Configure: pipe logging to parent process
@@ -39,60 +40,8 @@ configureCrashReporter();
3940// Load AMD entry point
4041require ( './bootstrap-amd' ) . load ( process . env [ 'AMD_ENTRYPOINT' ] ) ;
4142
42- //#region Helpers
43-
44- /**
45- * Add support for redirecting the loading of node modules
46- *
47- * @param {string } injectPath
48- */
49- function injectNodeModuleLookupPath ( injectPath ) {
50- if ( ! injectPath ) {
51- throw new Error ( 'Missing injectPath' ) ;
52- }
53-
54- const Module = require ( 'module' ) ;
55- const path = require ( 'path' ) ;
56-
57- const nodeModulesPath = path . join ( __dirname , '../node_modules' ) ;
5843
59- // @ts -ignore
60- const originalResolveLookupPaths = Module . _resolveLookupPaths ;
61-
62- // @ts -ignore
63- Module . _resolveLookupPaths = function ( moduleName , parent ) {
64- const paths = originalResolveLookupPaths ( moduleName , parent ) ;
65- if ( Array . isArray ( paths ) ) {
66- for ( let i = 0 , len = paths . length ; i < len ; i ++ ) {
67- if ( paths [ i ] === nodeModulesPath ) {
68- paths . splice ( i , 0 , injectPath ) ;
69- break ;
70- }
71- }
72- }
73-
74- return paths ;
75- } ;
76- }
77-
78- function removeGlobalNodeModuleLookupPaths ( ) {
79- const Module = require ( 'module' ) ;
80- // @ts -ignore
81- const globalPaths = Module . globalPaths ;
82-
83- // @ts -ignore
84- const originalResolveLookupPaths = Module . _resolveLookupPaths ;
85-
86- // @ts -ignore
87- Module . _resolveLookupPaths = function ( moduleName , parent ) {
88- const paths = originalResolveLookupPaths ( moduleName , parent ) ;
89- let commonSuffixLength = 0 ;
90- while ( commonSuffixLength < paths . length && paths [ paths . length - 1 - commonSuffixLength ] === globalPaths [ globalPaths . length - 1 - commonSuffixLength ] ) {
91- commonSuffixLength ++ ;
92- }
93- return paths . slice ( 0 , paths . length - commonSuffixLength ) ;
94- } ;
95- }
44+ //#region Helpers
9645
9746function pipeLoggingToParent ( ) {
9847 const MAX_LENGTH = 100000 ;
0 commit comments