1
- import { CwdFS , ZipOpenFS , xfs } from '@berry/fslib' ;
1
+ import { CwdFS , ZipOpenFS , xfs , NodeFS } from '@berry/fslib' ;
2
2
import { execute } from '@berry/shell' ;
3
3
import { delimiter , posix } from 'path' ;
4
4
import { PassThrough , Readable , Writable } from 'stream' ;
@@ -22,16 +22,19 @@ async function makePathWrapper(location: string, name: string, argv0: string, ar
22
22
}
23
23
24
24
export async function makeScriptEnv ( project : Project ) {
25
- const scriptEnv = { ... process . env } ;
25
+ const scriptEnv : { [ key : string ] : string } = { } ;
26
+ for ( const key of Object . keys ( process . env ) )
27
+ scriptEnv [ key . toUpperCase ( ) ] = process . env [ key ] as string ;
28
+
26
29
const binFolder = scriptEnv . BERRY_BIN_FOLDER = dirSync ( ) . name ;
27
30
28
31
// Register some binaries that must be made available in all subprocesses
29
32
// spawned by Berry
30
33
31
- await makePathWrapper ( binFolder , `run` , process . execPath , [ process . argv [ 1 ] , `run` ] ) ,
32
- await makePathWrapper ( binFolder , `yarn` , process . execPath , [ process . argv [ 1 ] ] ) ,
33
- await makePathWrapper ( binFolder , `yarnpkg` , process . execPath , [ process . argv [ 1 ] ] ) ,
34
- await makePathWrapper ( binFolder , `node` , process . execPath ) ,
34
+ await makePathWrapper ( binFolder , `run` , process . execPath , [ process . argv [ 1 ] , `run` ] ) ;
35
+ await makePathWrapper ( binFolder , `yarn` , process . execPath , [ process . argv [ 1 ] ] ) ;
36
+ await makePathWrapper ( binFolder , `yarnpkg` , process . execPath , [ process . argv [ 1 ] ] ) ;
37
+ await makePathWrapper ( binFolder , `node` , process . execPath ) ;
35
38
36
39
scriptEnv . PATH = scriptEnv . PATH
37
40
? `${ binFolder } ${ delimiter } ${ scriptEnv . PATH } `
@@ -40,7 +43,7 @@ export async function makeScriptEnv(project: Project) {
40
43
// Add the .pnp.js file to the Node options, so that we're sure that PnP will
41
44
// be correctly setup
42
45
43
- const pnpPath = `${ project . cwd } /.pnp.js` ;
46
+ const pnpPath = NodeFS . fromPortablePath ( `${ project . cwd } /.pnp.js` ) ;
44
47
const pnpRequire = `--require ${ pnpPath } ` ;
45
48
46
49
if ( xfs . existsSync ( pnpPath ) ) {
@@ -144,7 +147,7 @@ type GetPackageAccessibleBinariesOptions = {
144
147
145
148
/**
146
149
* Return the binaries that can be accessed by the specified package
147
- *
150
+ *
148
151
* @param locator The queried package
149
152
* @param project The project owning the package
150
153
*/
@@ -161,43 +164,43 @@ export async function getPackageAccessibleBinaries(locator: Locator, {project}:
161
164
162
165
const linkers = project . configuration . getLinkers ( ) ;
163
166
const linkerOptions = { project, report : new StreamReport ( { configuration, stdout } ) } ;
164
-
167
+
165
168
const binaries : Map < string , [ Locator , string ] > = new Map ( ) ;
166
-
169
+
167
170
const descriptors = [
168
171
... pkg . dependencies . values ( ) ,
169
172
... pkg . peerDependencies . values ( ) ,
170
173
] ;
171
-
174
+
172
175
for ( const descriptor of descriptors ) {
173
176
const resolution = project . storedResolutions . get ( descriptor . descriptorHash ) ;
174
177
if ( ! resolution )
175
178
continue ;
176
-
179
+
177
180
const pkg = project . storedPackages . get ( resolution ) ;
178
181
if ( ! pkg )
179
182
continue ;
180
-
183
+
181
184
const linker = linkers . find ( linker => linker . supportsPackage ( pkg , linkerOptions ) ) ;
182
185
if ( ! linker )
183
186
continue ;
184
-
187
+
185
188
const packageLocation = await linker . findPackageLocation ( pkg , linkerOptions ) ;
186
189
const packageFs = new CwdFS ( packageLocation , { baseFs : zipOpenFs } ) ;
187
190
const manifest = await Manifest . find ( `.` , { baseFs : packageFs } ) ;
188
-
191
+
189
192
for ( const [ binName , file ] of manifest . bin . entries ( ) ) {
190
193
binaries . set ( binName , [ pkg , posix . resolve ( packageLocation , file ) ] ) ;
191
194
}
192
195
}
193
-
196
+
194
197
return binaries ;
195
198
} ) ;
196
199
}
197
200
198
201
/**
199
202
* Return the binaries that can be accessed by the specified workspace
200
- *
203
+ *
201
204
* @param workspace The queried workspace
202
205
*/
203
206
@@ -215,11 +218,11 @@ type ExecutePackageAccessibleBinaryOptions = {
215
218
216
219
/**
217
220
* Execute a binary from the specified package.
218
- *
221
+ *
219
222
* Note that "binary" in this sense means "a Javascript file". Actual native
220
223
* binaries cannot be executed this way, because we use Node in order to
221
224
* transparently read from the archives.
222
- *
225
+ *
223
226
* @param locator The queried package
224
227
* @param binaryName The name of the binary file to execute
225
228
* @param args The arguments to pass to the file
@@ -254,7 +257,7 @@ type ExecuteWorkspaceAccessibleBinaryOptions = {
254
257
255
258
/**
256
259
* Execute a binary from the specified workspace
257
- *
260
+ *
258
261
* @param workspace The queried package
259
262
* @param binaryName The name of the binary file to execute
260
263
* @param args The arguments to pass to the file
0 commit comments