-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This changes the path resolution to use Node's module resolution algorithm to be consistent with other usages of Node CLI tools.
- Loading branch information
1 parent
b1baba3
commit c359fd4
Showing
1 changed file
with
5 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,20 @@ | ||
#!/usr/bin/env node | ||
'use strict'; | ||
|
||
/** | ||
* External dependencies. | ||
*/ | ||
const path = require( 'path' ); | ||
const fs = require( 'fs' ); | ||
|
||
// Remove 'node' and the name of the script from the arguments. | ||
let command = process.argv.slice( 2 ); | ||
// Default to help text when they aren't running any commands. | ||
if ( ! command.length ) { | ||
command = [ '--help' ]; | ||
command = [ '--help' ]; | ||
} | ||
|
||
// Rather than just executing the current CLI we will attempt to find a local version | ||
// and execute that one instead. This prevents users from accidentally using the | ||
// global CLI when a potentially different local version is expected. | ||
const localPath = path.resolve( './node_modules/@wordpress/env/lib/cli.js' ); | ||
const cliPath = fs.existsSync( localPath ) ? localPath : '../lib/cli.js'; | ||
const cli = require( cliPath )(); | ||
const localPath = require.resolve( '@wordpress/env/lib/cli.js', { | ||
paths: [ process.cwd(), __dirname ], | ||
} ); | ||
const cli = require( localPath )(); | ||
|
||
// Now we can execute the CLI with the given command. | ||
cli.parse( command ); |