@@ -15,6 +15,8 @@ import { readConfig } from "./readConfig.js";
1515import * as render from "./render/index.js" ;
1616import { major , minor } from "semver" ;
1717import { getExitCode } from "./getExitCode.js" ;
18+ import { determinePackCommand , determineTarballFilename } from "./utils.js" ;
19+ import detectPackageManager from "which-pm-runs" ;
1820
1921const packageJson = createRequire ( import . meta. url ) ( "../package.json" ) ;
2022const version = packageJson . version ;
@@ -74,8 +76,8 @@ particularly ESM-related module resolution issues.`,
7476 . option ( "--exclude-entrypoints <entrypoints...>" , "Specify entrypoints to exclude from checking." )
7577 . option (
7678 "--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." ,
7981 )
8082 . addOption (
8183 new Option ( "--ignore-rules <rules...>" , "Specify rules to ignore" ) . choices ( Object . values ( problemFlags ) ) . default ( [ ] ) ,
@@ -159,29 +161,30 @@ particularly ESM-related module resolution issues.`,
159161 ) ;
160162 }
161163
164+ const packageManager = ( await detectPackageManager ( ) ?. name ) ?? "npm" ;
165+ const packCommand = determinePackCommand ( packageManager ) ;
166+
162167 if ( ! opts . pack ) {
163168 if ( ! process . stdout . isTTY ) {
164169 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.` ,
166171 ) ;
167172 }
168173 const rl = readline . createInterface ( process . stdin , process . stdout ) ;
169174 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 ) ;
171176 } ) ;
172177 rl . close ( ) ;
173178 if ( answer . trim ( ) && ! answer . trim ( ) . toLowerCase ( ) . startsWith ( "y" ) ) {
174179 process . exit ( 1 ) ;
175180 }
176181 }
177182
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" } ) ;
185188 }
186189 const file = await readFile ( fileName ) ;
187190 const data = new Uint8Array ( file ) ;
0 commit comments