3
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
4
*--------------------------------------------------------------------------------------------*/
5
5
6
- //@ts -check
7
- 'use strict' ;
6
+ /* eslint-disable local/code-import-patterns */
8
7
9
8
import * as path from 'path' ;
10
9
import * as fs from 'fs' ;
11
10
import { fileURLToPath } from 'url' ;
12
11
import { createRequire } from 'node:module' ;
12
+ import { IProductConfiguration } from './vs/base/common/product' ;
13
13
14
- /** @ts -ignore */
15
14
const require = createRequire ( import . meta. url ) ;
16
- /** @type any */
17
- const module = { exports : { } } ;
18
15
const __dirname = path . dirname ( fileURLToPath ( import . meta. url ) ) ;
19
16
20
17
// increase number of stack frames(from 10, https://github.com/v8/v8/wiki/Stack-Trace-API)
@@ -38,7 +35,7 @@ if (!process.env['VSCODE_HANDLES_SIGPIPE']) {
38
35
// Setup current working directory in all our node & electron processes
39
36
// - Windows: call `process.chdir()` to always set application folder as cwd
40
37
// - all OS: store the `process.cwd()` inside `VSCODE_CWD` for consistent lookups
41
- function setupCurrentWorkingDirectory ( ) {
38
+ function setupCurrentWorkingDirectory ( ) : void {
42
39
try {
43
40
44
41
// Store the `process.cwd()` inside `VSCODE_CWD`
@@ -64,10 +61,8 @@ setupCurrentWorkingDirectory();
64
61
* Add support for redirecting the loading of node modules
65
62
*
66
63
* Note: only applies when running out of sources.
67
- *
68
- * @param {string } injectPath
69
64
*/
70
- module . exports . devInjectNodeModuleLookupPath = function ( injectPath ) {
65
+ export function devInjectNodeModuleLookupPath ( injectPath : string ) : void {
71
66
if ( ! process . env [ 'VSCODE_DEV' ] ) {
72
67
return ; // only applies running out of sources
73
68
}
@@ -76,25 +71,22 @@ module.exports.devInjectNodeModuleLookupPath = function (injectPath) {
76
71
throw new Error ( 'Missing injectPath' ) ;
77
72
}
78
73
79
- const Module = require ( 'node:module' ) ;
80
74
// register a loader hook
75
+ const Module = require ( 'node:module' ) ;
81
76
Module . register ( './bootstrap-import.js' , { parentURL : import . meta. url , data : injectPath } ) ;
82
- } ;
77
+ }
83
78
84
- module . exports . removeGlobalNodeJsModuleLookupPaths = function ( ) {
79
+ export function removeGlobalNodeJsModuleLookupPaths ( ) : void {
85
80
if ( typeof process ?. versions ?. electron === 'string' ) {
86
81
return ; // Electron disables global search paths in https://github.com/electron/electron/blob/3186c2f0efa92d275dc3d57b5a14a60ed3846b0e/shell/common/node_bindings.cc#L653
87
82
}
88
83
89
84
const Module = require ( 'module' ) ;
90
- // @ts -ignore
91
85
const globalPaths = Module . globalPaths ;
92
86
93
- // @ts -ignore
94
87
const originalResolveLookupPaths = Module . _resolveLookupPaths ;
95
88
96
- // @ts -ignore
97
- Module . _resolveLookupPaths = function ( moduleName , parent ) {
89
+ Module . _resolveLookupPaths = function ( moduleName : string , parent : any ) : string [ ] {
98
90
const paths = originalResolveLookupPaths ( moduleName , parent ) ;
99
91
if ( Array . isArray ( paths ) ) {
100
92
let commonSuffixLength = 0 ;
@@ -105,21 +97,15 @@ module.exports.removeGlobalNodeJsModuleLookupPaths = function () {
105
97
}
106
98
return paths ;
107
99
} ;
108
- } ;
100
+ }
109
101
110
102
/**
111
103
* Helper to enable portable mode.
112
- *
113
- * @param {Partial<import('./vs/base/common/product').IProductConfiguration> } product
114
- * @returns {{ portableDataPath: string; isPortable: boolean; } }
115
104
*/
116
- module . exports . configurePortable = function ( product ) {
105
+ export function configurePortable ( product : Partial < IProductConfiguration > ) : { portableDataPath : string ; isPortable : boolean } {
117
106
const appRoot = path . dirname ( __dirname ) ;
118
107
119
- /**
120
- * @param {import('path') } path
121
- */
122
- function getApplicationPath ( path ) {
108
+ function getApplicationPath ( ) {
123
109
if ( process . env [ 'VSCODE_DEV' ] ) {
124
110
return appRoot ;
125
111
}
@@ -131,24 +117,20 @@ module.exports.configurePortable = function (product) {
131
117
return path . dirname ( path . dirname ( appRoot ) ) ;
132
118
}
133
119
134
- /**
135
- * @param {import('path') } path
136
- */
137
- function getPortableDataPath ( path ) {
120
+ function getPortableDataPath ( ) {
138
121
if ( process . env [ 'VSCODE_PORTABLE' ] ) {
139
122
return process . env [ 'VSCODE_PORTABLE' ] ;
140
123
}
141
124
142
125
if ( process . platform === 'win32' || process . platform === 'linux' ) {
143
- return path . join ( getApplicationPath ( path ) , 'data' ) ;
126
+ return path . join ( getApplicationPath ( ) , 'data' ) ;
144
127
}
145
128
146
- // @ts -ignore
147
129
const portableDataName = product . portable || `${ product . applicationName } -portable-data` ;
148
- return path . join ( path . dirname ( getApplicationPath ( path ) ) , portableDataName ) ;
130
+ return path . join ( path . dirname ( getApplicationPath ( ) ) , portableDataName ) ;
149
131
}
150
132
151
- const portableDataPath = getPortableDataPath ( path ) ;
133
+ const portableDataPath = getPortableDataPath ( ) ;
152
134
const isPortable = ! ( 'target' in product ) && fs . existsSync ( portableDataPath ) ;
153
135
const portableTempPath = path . join ( portableDataPath , 'tmp' ) ;
154
136
const isTempPortable = isPortable && fs . existsSync ( portableTempPath ) ;
@@ -172,10 +154,4 @@ module.exports.configurePortable = function (product) {
172
154
portableDataPath,
173
155
isPortable
174
156
} ;
175
- } ;
176
-
177
- //#endregion
178
-
179
- export const devInjectNodeModuleLookupPath = module . exports . devInjectNodeModuleLookupPath ;
180
- export const removeGlobalNodeJsModuleLookupPaths = module . exports . removeGlobalNodeJsModuleLookupPaths ;
181
- export const configurePortable = module . exports . configurePortable ;
157
+ }
0 commit comments