diff options
author | Gar <gar+gh@danger.computer> | 2021-11-04 17:45:56 +0300 |
---|---|---|
committer | Gar <gar+gh@danger.computer> | 2021-11-04 19:36:29 +0300 |
commit | 1e9c31c4e3929483580a0a554d7515095b5418ca (patch) | |
tree | 0b52f59e3fe5141820fa5536652cf86cbb0661ae /lib/commands | |
parent | cad9bc7af21da781c6858f65355ca3fdf4a06404 (diff) |
fix(help|edit): use npm.exec, use file:///
Windows no longer allows `file://`, but instead requires `file:///` for
local file urls.
Also after the command refactor things shifted and the tests didn't
catch that the help pages didn't work at all anymore, and that the
post-edit rebuild didn't work. This cleans up those two issues.
PR-URL: https://github.com/npm/cli/pull/3994
Credit: @wraithgar
Close: #3994
Reviewed-by: @lukekarrys
Diffstat (limited to 'lib/commands')
-rw-r--r-- | lib/commands/edit.js | 7 | ||||
-rw-r--r-- | lib/commands/help-search.js | 2 | ||||
-rw-r--r-- | lib/commands/help.js | 17 |
3 files changed, 6 insertions, 20 deletions
diff --git a/lib/commands/edit.js b/lib/commands/edit.js index 26fb18b29..db9be4a26 100644 --- a/lib/commands/edit.js +++ b/lib/commands/edit.js @@ -50,12 +50,7 @@ class Edit extends BaseCommand { editor.on('exit', (code) => { if (code) return reject(new Error(`editor process exited with code: ${code}`)) - this.npm.commands.rebuild([dir], (err) => { - if (err) - return reject(err) - - resolve() - }) + this.npm.exec('rebuild', [dir]).catch(reject).then(resolve) }) }) }) diff --git a/lib/commands/help-search.js b/lib/commands/help-search.js index a9acf21c6..4ab4a0896 100644 --- a/lib/commands/help-search.js +++ b/lib/commands/help-search.js @@ -30,7 +30,7 @@ class HelpSearch extends BaseCommand { if (!args.length) return this.npm.output(this.usage) - const docPath = path.resolve(__dirname, '..', 'docs/content') + const docPath = path.resolve(__dirname, '..', '..', 'docs/content') const files = await glob(`${docPath}/*/*.md`) const data = await this.readFiles(files) const results = await this.searchFiles(args, data, files) diff --git a/lib/commands/help.js b/lib/commands/help.js index 5b6a87bfc..bfc7f8b60 100644 --- a/lib/commands/help.js +++ b/lib/commands/help.js @@ -36,7 +36,7 @@ class Help extends BaseCommand { async completion (opts) { if (opts.conf.argv.remain.length > 2) return [] - const g = path.resolve(__dirname, '../man/man[0-9]/*.[0-9]') + const g = path.resolve(__dirname, '../../man/man[0-9]/*.[0-9]') const files = await glob(g) return Object.keys(files.reduce(function (acc, file) { @@ -66,7 +66,7 @@ class Help extends BaseCommand { // support `npm help package.json` section = section.replace('.json', '-json') - const manroot = path.resolve(__dirname, '..', 'man') + const manroot = path.resolve(__dirname, '..', '..', 'man') // find either section.n or npm-section.n const f = `${manroot}/${manSearch}/?(npm-)${section}.[0-9]*` let mans = await glob(f) @@ -90,16 +90,7 @@ class Help extends BaseCommand { } helpSearch (args) { - return new Promise((resolve, reject) => { - this.npm.commands['help-search'](args, (err) => { - // This would only error if args was empty, which it never is - /* istanbul ignore next */ - if (err) - return reject(err) - - resolve() - }) - }) + return this.npm.exec('help-search', args) } async viewMan (man) { @@ -157,7 +148,7 @@ class Help extends BaseCommand { sect = 'using-npm' break } - return 'file://' + path.resolve(__dirname, '..', 'docs', 'output', sect, f + '.html') + return 'file:///' + path.resolve(__dirname, '..', '..', 'docs', 'output', sect, f + '.html') } } module.exports = Help |