2020-03-02 00:00:24 +08:00
|
|
|
# This file is explicitly sourced by the npm and yarn completions
|
2019-01-11 13:10:21 +08:00
|
|
|
# It is used to enumerate entries from the npm registry, interact with a locally installed
|
|
|
|
# package.json file, and more.
|
|
|
|
# Other completions that would depend on this include jspm, pnpm, etc.
|
|
|
|
|
|
|
|
# If all-the-package-names is installed, it will be used to generate npm completions.
|
|
|
|
# Install globally with `sudo npm install -g all-the-package-names`. Keep it up to date.
|
update npm completions (#9800)
* update npm install completions
* update npm uninstall
* init npm dep rewrite
+ init npm
* npm uninstall complete global packages
* add npm pack completions
* add npm publish completions
* add npm init completions
* add missing commands, remove outdated, add missing aliases
* add npm audit completions
* implement requested changes
* rename __yarn_ to __npm_
* add missing commands / aliases
* slightly less verbose options, reword dry-run description (meh)
* more commands and options
* add and update completions for several commands
* access, adduser, bugs, ci, config, cache
* dedupe, deprecate, dist-tag, diff, docs, doctor
* edit, exec, explain, explore, find-dupes, fund
* hooks, help-search, install, ls, publish, search
* version, view
* more commands, fixes
* fish_indent
* remove most aliases from command suggestions
* add most other commands
* npm help, --help
* minor fixes
* remove npm builtin completion, new install option, fish_indent
* add completions for npm set, npm get
2023-05-30 17:22:18 +08:00
|
|
|
function __npm_helper_installed
|
2019-01-11 13:10:21 +08:00
|
|
|
# This function takes the command to globally install a package as $argv[1]
|
2019-02-10 14:09:21 +08:00
|
|
|
if not type -q all-the-package-names
|
update npm completions (#9800)
* update npm install completions
* update npm uninstall
* init npm dep rewrite
+ init npm
* npm uninstall complete global packages
* add npm pack completions
* add npm publish completions
* add npm init completions
* add missing commands, remove outdated, add missing aliases
* add npm audit completions
* implement requested changes
* rename __yarn_ to __npm_
* add missing commands / aliases
* slightly less verbose options, reword dry-run description (meh)
* more commands and options
* add and update completions for several commands
* access, adduser, bugs, ci, config, cache
* dedupe, deprecate, dist-tag, diff, docs, doctor
* edit, exec, explain, explore, find-dupes, fund
* hooks, help-search, install, ls, publish, search
* version, view
* more commands, fixes
* fish_indent
* remove most aliases from command suggestions
* add most other commands
* npm help, --help
* minor fixes
* remove npm builtin completion, new install option, fish_indent
* add completions for npm set, npm get
2023-05-30 17:22:18 +08:00
|
|
|
if not set -qg __fish_npm_pkg_info_shown
|
2019-01-11 13:10:21 +08:00
|
|
|
set -l old (commandline)
|
|
|
|
commandline -r ""
|
|
|
|
echo \nfish: Run `$argv[1] all-the-package-names` to gain intelligent \
|
2019-03-10 01:30:17 +08:00
|
|
|
package completion >&2
|
2019-01-11 13:10:21 +08:00
|
|
|
commandline -f repaint
|
|
|
|
commandline -r $old
|
update npm completions (#9800)
* update npm install completions
* update npm uninstall
* init npm dep rewrite
+ init npm
* npm uninstall complete global packages
* add npm pack completions
* add npm publish completions
* add npm init completions
* add missing commands, remove outdated, add missing aliases
* add npm audit completions
* implement requested changes
* rename __yarn_ to __npm_
* add missing commands / aliases
* slightly less verbose options, reword dry-run description (meh)
* more commands and options
* add and update completions for several commands
* access, adduser, bugs, ci, config, cache
* dedupe, deprecate, dist-tag, diff, docs, doctor
* edit, exec, explain, explore, find-dupes, fund
* hooks, help-search, install, ls, publish, search
* version, view
* more commands, fixes
* fish_indent
* remove most aliases from command suggestions
* add most other commands
* npm help, --help
* minor fixes
* remove npm builtin completion, new install option, fish_indent
* add completions for npm set, npm get
2023-05-30 17:22:18 +08:00
|
|
|
set -g __fish_npm_pkg_info_shown 1
|
2019-01-11 13:10:21 +08:00
|
|
|
end
|
|
|
|
return 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Entire list of packages is too long to be used efficiently in a `complete` subcommand.
|
|
|
|
# Search it for matches instead.
|
update npm completions (#9800)
* update npm install completions
* update npm uninstall
* init npm dep rewrite
+ init npm
* npm uninstall complete global packages
* add npm pack completions
* add npm publish completions
* add npm init completions
* add missing commands, remove outdated, add missing aliases
* add npm audit completions
* implement requested changes
* rename __yarn_ to __npm_
* add missing commands / aliases
* slightly less verbose options, reword dry-run description (meh)
* more commands and options
* add and update completions for several commands
* access, adduser, bugs, ci, config, cache
* dedupe, deprecate, dist-tag, diff, docs, doctor
* edit, exec, explain, explore, find-dupes, fund
* hooks, help-search, install, ls, publish, search
* version, view
* more commands, fixes
* fish_indent
* remove most aliases from command suggestions
* add most other commands
* npm help, --help
* minor fixes
* remove npm builtin completion, new install option, fish_indent
* add completions for npm set, npm get
2023-05-30 17:22:18 +08:00
|
|
|
function __npm_filtered_list_packages
|
2019-01-11 13:10:21 +08:00
|
|
|
# This function takes the command to globally install a package as $argv[1]
|
update npm completions (#9800)
* update npm install completions
* update npm uninstall
* init npm dep rewrite
+ init npm
* npm uninstall complete global packages
* add npm pack completions
* add npm publish completions
* add npm init completions
* add missing commands, remove outdated, add missing aliases
* add npm audit completions
* implement requested changes
* rename __yarn_ to __npm_
* add missing commands / aliases
* slightly less verbose options, reword dry-run description (meh)
* more commands and options
* add and update completions for several commands
* access, adduser, bugs, ci, config, cache
* dedupe, deprecate, dist-tag, diff, docs, doctor
* edit, exec, explain, explore, find-dupes, fund
* hooks, help-search, install, ls, publish, search
* version, view
* more commands, fixes
* fish_indent
* remove most aliases from command suggestions
* add most other commands
* npm help, --help
* minor fixes
* remove npm builtin completion, new install option, fish_indent
* add completions for npm set, npm get
2023-05-30 17:22:18 +08:00
|
|
|
if not __npm_helper_installed $argv[1]
|
2019-01-11 13:10:21 +08:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
# Do not provide any completions if nothing has been entered yet to avoid long hang.
|
|
|
|
if string match -r . (commandline -ct)
|
|
|
|
# Filter the results here rather than in the C++ code due to #5267
|
2020-10-22 11:23:50 +08:00
|
|
|
all-the-package-names | string match -er -- '(?:\b|_|^)'(commandline -ct |
|
2019-01-11 13:10:21 +08:00
|
|
|
string escape --style=regex) | head -n1000
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
update npm completions (#9800)
* update npm install completions
* update npm uninstall
* init npm dep rewrite
+ init npm
* npm uninstall complete global packages
* add npm pack completions
* add npm publish completions
* add npm init completions
* add missing commands, remove outdated, add missing aliases
* add npm audit completions
* implement requested changes
* rename __yarn_ to __npm_
* add missing commands / aliases
* slightly less verbose options, reword dry-run description (meh)
* more commands and options
* add and update completions for several commands
* access, adduser, bugs, ci, config, cache
* dedupe, deprecate, dist-tag, diff, docs, doctor
* edit, exec, explain, explore, find-dupes, fund
* hooks, help-search, install, ls, publish, search
* version, view
* more commands, fixes
* fish_indent
* remove most aliases from command suggestions
* add most other commands
* npm help, --help
* minor fixes
* remove npm builtin completion, new install option, fish_indent
* add completions for npm set, npm get
2023-05-30 17:22:18 +08:00
|
|
|
function __npm_find_package_json
|
2020-05-16 03:34:48 +08:00
|
|
|
set -l parents (__fish_parent_directories (pwd -P))
|
2019-01-11 13:10:21 +08:00
|
|
|
|
|
|
|
for p in $parents
|
|
|
|
if test -f "$p/package.json"
|
|
|
|
echo "$p/package.json"
|
|
|
|
return 0
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return 1
|
|
|
|
end
|
|
|
|
|
update npm completions (#9800)
* update npm install completions
* update npm uninstall
* init npm dep rewrite
+ init npm
* npm uninstall complete global packages
* add npm pack completions
* add npm publish completions
* add npm init completions
* add missing commands, remove outdated, add missing aliases
* add npm audit completions
* implement requested changes
* rename __yarn_ to __npm_
* add missing commands / aliases
* slightly less verbose options, reword dry-run description (meh)
* more commands and options
* add and update completions for several commands
* access, adduser, bugs, ci, config, cache
* dedupe, deprecate, dist-tag, diff, docs, doctor
* edit, exec, explain, explore, find-dupes, fund
* hooks, help-search, install, ls, publish, search
* version, view
* more commands, fixes
* fish_indent
* remove most aliases from command suggestions
* add most other commands
* npm help, --help
* minor fixes
* remove npm builtin completion, new install option, fish_indent
* add completions for npm set, npm get
2023-05-30 17:22:18 +08:00
|
|
|
function __npm_installed_global_packages
|
2023-06-02 00:20:19 +08:00
|
|
|
set -l prefix (npm prefix -g)
|
|
|
|
set -l node_modules "$prefix/lib/node_modules"
|
update npm completions (#9800)
* update npm install completions
* update npm uninstall
* init npm dep rewrite
+ init npm
* npm uninstall complete global packages
* add npm pack completions
* add npm publish completions
* add npm init completions
* add missing commands, remove outdated, add missing aliases
* add npm audit completions
* implement requested changes
* rename __yarn_ to __npm_
* add missing commands / aliases
* slightly less verbose options, reword dry-run description (meh)
* more commands and options
* add and update completions for several commands
* access, adduser, bugs, ci, config, cache
* dedupe, deprecate, dist-tag, diff, docs, doctor
* edit, exec, explain, explore, find-dupes, fund
* hooks, help-search, install, ls, publish, search
* version, view
* more commands, fixes
* fish_indent
* remove most aliases from command suggestions
* add most other commands
* npm help, --help
* minor fixes
* remove npm builtin completion, new install option, fish_indent
* add completions for npm set, npm get
2023-05-30 17:22:18 +08:00
|
|
|
|
2023-06-02 00:20:19 +08:00
|
|
|
for path in $node_modules/*
|
|
|
|
set -l mod (path basename -- $path)
|
update npm completions (#9800)
* update npm install completions
* update npm uninstall
* init npm dep rewrite
+ init npm
* npm uninstall complete global packages
* add npm pack completions
* add npm publish completions
* add npm init completions
* add missing commands, remove outdated, add missing aliases
* add npm audit completions
* implement requested changes
* rename __yarn_ to __npm_
* add missing commands / aliases
* slightly less verbose options, reword dry-run description (meh)
* more commands and options
* add and update completions for several commands
* access, adduser, bugs, ci, config, cache
* dedupe, deprecate, dist-tag, diff, docs, doctor
* edit, exec, explain, explore, find-dupes, fund
* hooks, help-search, install, ls, publish, search
* version, view
* more commands, fixes
* fish_indent
* remove most aliases from command suggestions
* add most other commands
* npm help, --help
* minor fixes
* remove npm builtin completion, new install option, fish_indent
* add completions for npm set, npm get
2023-05-30 17:22:18 +08:00
|
|
|
|
2023-06-02 00:20:19 +08:00
|
|
|
if string match -rq "^@" $mod
|
|
|
|
for sub_path in $path/*
|
|
|
|
set -l sub_mod (string split '/' $sub_path)[-1]
|
|
|
|
echo $mod/$sub_mod
|
|
|
|
end
|
|
|
|
else
|
|
|
|
echo $mod
|
|
|
|
end
|
|
|
|
end
|
update npm completions (#9800)
* update npm install completions
* update npm uninstall
* init npm dep rewrite
+ init npm
* npm uninstall complete global packages
* add npm pack completions
* add npm publish completions
* add npm init completions
* add missing commands, remove outdated, add missing aliases
* add npm audit completions
* implement requested changes
* rename __yarn_ to __npm_
* add missing commands / aliases
* slightly less verbose options, reword dry-run description (meh)
* more commands and options
* add and update completions for several commands
* access, adduser, bugs, ci, config, cache
* dedupe, deprecate, dist-tag, diff, docs, doctor
* edit, exec, explain, explore, find-dupes, fund
* hooks, help-search, install, ls, publish, search
* version, view
* more commands, fixes
* fish_indent
* remove most aliases from command suggestions
* add most other commands
* npm help, --help
* minor fixes
* remove npm builtin completion, new install option, fish_indent
* add completions for npm set, npm get
2023-05-30 17:22:18 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
function __npm_installed_local_packages
|
|
|
|
set -l package_json (__npm_find_package_json)
|
2019-01-11 13:10:21 +08:00
|
|
|
if not test $status -eq 0
|
|
|
|
# no package.json in tree
|
|
|
|
return 1
|
|
|
|
end
|
|
|
|
|
2019-03-10 01:30:17 +08:00
|
|
|
if set -l python (__fish_anypython)
|
2020-02-27 20:48:42 +08:00
|
|
|
$python -S -c 'import json, sys; data = json.load(sys.stdin);
|
2019-05-05 18:09:25 +08:00
|
|
|
print("\n".join(data["dependencies"])); print("\n".join(data["devDependencies"]))' <$package_json 2>/dev/null
|
2019-03-10 01:30:17 +08:00
|
|
|
else if type -q jq
|
2019-01-11 13:10:21 +08:00
|
|
|
jq -r '.dependencies as $a1 | .devDependencies as $a2 | ($a1 + $a2) | to_entries[] | .key' $package_json
|
|
|
|
else
|
|
|
|
set -l depsFound 0
|
|
|
|
for line in (cat $package_json)
|
|
|
|
# echo "evaluating $line"
|
|
|
|
if test $depsFound -eq 0
|
|
|
|
# echo "mode: noDeps"
|
|
|
|
if string match -qr '(devD|d)ependencies"' -- $line
|
|
|
|
# echo "switching to mode: deps"
|
|
|
|
set depsFound 1
|
|
|
|
continue
|
|
|
|
end
|
|
|
|
continue
|
|
|
|
end
|
|
|
|
|
|
|
|
if string match -qr '\}' -- $line
|
|
|
|
# echo "switching to mode: noDeps"
|
|
|
|
set depsFound 0
|
|
|
|
continue
|
|
|
|
end
|
|
|
|
|
|
|
|
# echo "mode: deps"
|
|
|
|
|
|
|
|
string replace -r '^\s*"([^"]+)".*' '$1' -- $line
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|