@@ -15,6 +15,8 @@ import { readConfig } from "./readConfig.js";
15
15
import * as render from "./render/index.js" ;
16
16
import { major , minor } from "semver" ;
17
17
import { getExitCode } from "./getExitCode.js" ;
18
+ import { determinePackCommand , determineTarballFilename } from "./utils.js" ;
19
+ import detectPackageManager from "which-pm-runs" ;
18
20
19
21
const packageJson = createRequire ( import . meta. url ) ( "../package.json" ) ;
20
22
const version = packageJson . version ;
@@ -74,8 +76,8 @@ particularly ESM-related module resolution issues.`,
74
76
. option ( "--exclude-entrypoints <entrypoints...>" , "Specify entrypoints to exclude from checking." )
75
77
. option (
76
78
"--entrypoints-legacy" ,
77
- ' In packages without the `exports` field, every file is an entry point. Specifying this option ' +
78
- ' only takes effect when no entrypoints are automatically detected, or explicitly provided with other options.'
79
+ " In packages without the `exports` field, every file is an entry point. Specifying this option " +
80
+ " only takes effect when no entrypoints are automatically detected, or explicitly provided with other options." ,
79
81
)
80
82
. addOption (
81
83
new Option ( "--ignore-rules <rules...>" , "Specify rules to ignore" ) . choices ( Object . values ( problemFlags ) ) . default ( [ ] ) ,
@@ -159,29 +161,30 @@ particularly ESM-related module resolution issues.`,
159
161
) ;
160
162
}
161
163
164
+ const packageManager = ( await detectPackageManager ( ) ?. name ) ?? "npm" ;
165
+ const packCommand = determinePackCommand ( packageManager ) ;
166
+
162
167
if ( ! opts . pack ) {
163
168
if ( ! process . stdout . isTTY ) {
164
169
program . error (
165
- " Specifying a directory requires the --pack option to confirm that running `npm pack ` is ok." ,
170
+ ` Specifying a directory requires the --pack option to confirm that running \` ${ packCommand } \ ` is ok.` ,
166
171
) ;
167
172
}
168
173
const rl = readline . createInterface ( process . stdin , process . stdout ) ;
169
174
const answer = await new Promise < string > ( ( resolve ) => {
170
- rl . question ( `Run \`npm pack \`? (Pass -P/--pack to skip) (Y/n) ` , resolve ) ;
175
+ rl . question ( `Run \`${ packCommand } \`? (Pass -P/--pack to skip) (Y/n) ` , resolve ) ;
171
176
} ) ;
172
177
rl . close ( ) ;
173
178
if ( answer . trim ( ) && ! answer . trim ( ) . toLowerCase ( ) . startsWith ( "y" ) ) {
174
179
process . exit ( 1 ) ;
175
180
}
176
181
}
177
182
178
- const manifest = JSON . parse ( await readFile ( path . join ( fileOrDirectory , "package.json" ) , { encoding : "utf8" } ) ) ;
179
- fileName = deleteTgz = path . join (
180
- fileOrDirectory ,
181
- // https://github.com/npm/cli/blob/f875caa86900122819311dd77cde01c700fd1817/lib/utils/tar.js#L123-L125
182
- `${ manifest . name . replace ( "@" , "" ) . replace ( "/" , "-" ) } -${ manifest . version } .tgz` ,
183
- ) ;
184
- execSync ( "npm pack" , { cwd : fileOrDirectory , encoding : "utf8" , stdio : "ignore" } ) ;
183
+ fileName = deleteTgz = await determineTarballFilename ( fileOrDirectory ) ;
184
+
185
+ const packCommandWithFilename = determinePackCommand ( packageManager , fileName ) ;
186
+
187
+ execSync ( packCommandWithFilename , { cwd : fileOrDirectory , encoding : "utf8" , stdio : "ignore" } ) ;
185
188
}
186
189
const file = await readFile ( fileName ) ;
187
190
const data = new Uint8Array ( file ) ;
0 commit comments