File tree Expand file tree Collapse file tree 1 file changed +19
-7
lines changed
Expand file tree Collapse file tree 1 file changed +19
-7
lines changed Original file line number Diff line number Diff line change @@ -17,14 +17,26 @@ import {QuietCiLogger, QuietLogger} from './logging/quiet-logger.js';
1717import { DefaultLogger } from './logging/default-logger.js' ;
1818
1919export const packageDir = await ( async ( ) : Promise < string | undefined > => {
20- // Recent versions of npm set this environment variable that tells us the
21- // package.
22- const packageJsonPath = process . env . npm_package_json ;
23- if ( packageJsonPath ) {
24- return pathlib . dirname ( packageJsonPath ) ;
20+ // Recent versions of npm and yarn set the `npm_package_json` environment
21+ // variable.
22+ //
23+ // `yarn` will only find `wireit` with the `-T` flag, which also sets
24+ // `npm_package_json` to the package.json at the project root, even if we're
25+ // in another package.
26+ //
27+ // Therefore, trust `npm_package_json` when in npm, but introspect the
28+ // filesystem otherwise.
29+
30+ const agent = getNpmUserAgent ( ) ;
31+
32+ if ( agent === 'npm' ) {
33+ const packageJsonPath = process . env . npm_package_json ;
34+ if ( packageJsonPath ) {
35+ return pathlib . dirname ( packageJsonPath ) ;
36+ }
2537 }
26- // Older versions of npm, as well as yarn and pnpm, don't set this variable,
27- // so we have to find the nearest package.json by walking up the filesystem.
38+
39+ // Find the nearest package.json by walking up the filesystem.
2840 let maybePackageDir = process . cwd ( ) ;
2941 while ( true ) {
3042 try {
You can’t perform that action at this time.
0 commit comments