@@ -5,11 +5,6 @@ import path from 'path';
55import { Engine } from './sources/Engine' ;
66import { SupportedPackageManagerSet } from './sources/types' ;
77
8- function shouldGenerateShim ( name : string ) {
9- // No filtering needed at the moment
10- return true ;
11- }
12-
138const engine = new Engine ( ) ;
149
1510const distDir = path . join ( __dirname , `dist` ) ;
@@ -23,26 +18,33 @@ fs.mkdirSync(shimsDir, {recursive: true});
2318fs . mkdirSync ( physicalNodewinDir , { recursive : true } ) ;
2419
2520async function main ( ) {
21+ const corepackPath = path . join ( distDir , `corepack.js` ) ;
22+ fs . writeFileSync ( corepackPath , [
23+ `#!/usr/bin/env node` ,
24+ `require('./lib/corepack.cjs').runMain(process.argv.slice(2));` ,
25+ ] . join ( `\n` ) ) ;
26+ fs . chmodSync ( corepackPath , 0o755 ) ;
27+
2628 for ( const packageManager of SupportedPackageManagerSet ) {
2729 const binSet = engine . getBinariesFor ( packageManager ) ;
2830
2931 for ( const binaryName of binSet ) {
3032 const entryPath = path . join ( distDir , `${ binaryName } .js` ) ;
3133 const entryScript = [
32- `#!/usr/bin/env node\n ` ,
33- `require('./corepack').runMain(['${ binaryName } ', ...process.argv.slice(2)]);\n ` ,
34- ] . join ( `` ) ;
34+ `#!/usr/bin/env node` ,
35+ `require('./lib/ corepack.cjs ').runMain(['${ binaryName } ', ...process.argv.slice(2)]);` ,
36+ ] . join ( `\n ` ) ;
3537
3638 fs . writeFileSync ( entryPath , entryScript ) ;
3739 fs . chmodSync ( entryPath , 0o755 ) ;
3840 }
3941 }
4042
41- for ( const binaryName of fs . readdirSync ( distDir ) ) {
42- if ( shouldGenerateShim ( binaryName ) === false )
43+ for ( const entry of fs . readdirSync ( distDir , { withFileTypes : true } ) ) {
44+ if ( entry . isDirectory ( ) )
4345 continue ;
4446
45- await cmdShim ( path . join ( distDir , binaryName ) , path . join ( shimsDir , path . basename ( binaryName , `.js` ) ) , { createCmdFile : true } ) ;
47+ await cmdShim ( path . join ( distDir , entry . name ) , path . join ( shimsDir , path . basename ( entry . name , `.js` ) ) , { createCmdFile : true } ) ;
4648 }
4749
4850 // The Node distribution doesn't support symlinks, so they copy the shims into
@@ -60,11 +62,11 @@ async function main() {
6062 stat : ( p : string , cb : ( ) => void ) => fs . stat ( remapPath ( p ) , cb ) ,
6163 } ) ;
6264
63- for ( const binaryName of fs . readdirSync ( distDir ) ) {
64- if ( shouldGenerateShim ( binaryName ) === false )
65+ for ( const entry of fs . readdirSync ( distDir , { withFileTypes : true } ) ) {
66+ if ( entry . isDirectory ( ) )
6567 continue ;
6668
67- await cmdShim ( path . join ( virtualNodewinDir , `dist/${ binaryName } ` ) , path . join ( physicalNodewinDir , path . basename ( binaryName , `.js` ) ) , { createCmdFile : true , fs : easyStatFs } ) ;
69+ await cmdShim ( path . join ( virtualNodewinDir , `dist/${ entry . name } ` ) , path . join ( physicalNodewinDir , path . basename ( entry . name , `.js` ) ) , { createCmdFile : true , fs : easyStatFs } ) ;
6870 }
6971
7072 console . log ( `All shims have been generated.` ) ;
0 commit comments