[New] add `nvm_find_project_dir` helper
parent
1d88ecfce5
commit
cf92956e5d
|
@ -18,5 +18,11 @@ indent_size = false
|
||||||
[test/fast/Listing versions/Running "nvm ls --no-alias" does not call into nvm_alias]
|
[test/fast/Listing versions/Running "nvm ls --no-alias" does not call into nvm_alias]
|
||||||
indent_size = false
|
indent_size = false
|
||||||
|
|
||||||
|
[test/fast/Unit tests/mocks/**]
|
||||||
|
insert_final_newline = off
|
||||||
|
|
||||||
|
[test/**/.urchin*]
|
||||||
|
insert_final_newline = off
|
||||||
|
|
||||||
[Makefile]
|
[Makefile]
|
||||||
indent_style = tab
|
indent_style = tab
|
||||||
|
|
11
nvm.sh
11
nvm.sh
|
@ -317,6 +317,15 @@ nvm_tree_contains_path() {
|
||||||
[ "${pathdir}" = "${tree}" ]
|
[ "${pathdir}" = "${tree}" ]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nvm_find_project_dir() {
|
||||||
|
local path_
|
||||||
|
path_="${PWD}"
|
||||||
|
while [ "${path_}" != "" ] && [ ! -f "${path_}/package.json" ] && [ ! -d "${path_}/node_modules" ]; do
|
||||||
|
path_=${path_%/*}
|
||||||
|
done
|
||||||
|
nvm_echo "${path_}"
|
||||||
|
}
|
||||||
|
|
||||||
# Traverse up in directory tree to find containing folder
|
# Traverse up in directory tree to find containing folder
|
||||||
nvm_find_up() {
|
nvm_find_up() {
|
||||||
local path_
|
local path_
|
||||||
|
@ -3654,7 +3663,7 @@ nvm() {
|
||||||
nvm_normalize_version nvm_is_valid_version \
|
nvm_normalize_version nvm_is_valid_version \
|
||||||
nvm_ensure_version_installed nvm_cache_dir \
|
nvm_ensure_version_installed nvm_cache_dir \
|
||||||
nvm_version_path nvm_alias_path nvm_version_dir \
|
nvm_version_path nvm_alias_path nvm_version_dir \
|
||||||
nvm_find_nvmrc nvm_find_up nvm_tree_contains_path \
|
nvm_find_nvmrc nvm_find_up nvm_find_project_dir nvm_tree_contains_path \
|
||||||
nvm_version_greater nvm_version_greater_than_or_equal_to \
|
nvm_version_greater nvm_version_greater_than_or_equal_to \
|
||||||
nvm_print_npm_version nvm_install_latest_npm nvm_npm_global_modules \
|
nvm_print_npm_version nvm_install_latest_npm nvm_npm_global_modules \
|
||||||
nvm_has_system_node nvm_has_system_iojs \
|
nvm_has_system_node nvm_has_system_iojs \
|
||||||
|
|
0
test/fast/Unit tests/mocks/project_dirs/inside-n_m-nested-pkg/node_modules/foo/bar/.gitkeep
generated
vendored
100644
0
test/fast/Unit tests/mocks/project_dirs/inside-n_m-nested-pkg/node_modules/foo/bar/.gitkeep
generated
vendored
100644
0
test/fast/Unit tests/mocks/project_dirs/inside-n_m-nested-pkg/node_modules/foo/package.json
generated
vendored
100644
0
test/fast/Unit tests/mocks/project_dirs/inside-n_m-nested-pkg/node_modules/foo/package.json
generated
vendored
100644
0
test/fast/Unit tests/mocks/project_dirs/inside-n_m-nested/node_modules/foo/bar/.gitkeep
generated
vendored
100644
0
test/fast/Unit tests/mocks/project_dirs/inside-n_m-nested/node_modules/foo/bar/.gitkeep
generated
vendored
100644
0
test/fast/Unit tests/mocks/project_dirs/nested-both/node_modules/.gitkeep
generated
vendored
100644
0
test/fast/Unit tests/mocks/project_dirs/nested-both/node_modules/.gitkeep
generated
vendored
100644
0
test/fast/Unit tests/mocks/project_dirs/nested-n_m/node_modules/.gitkeep
generated
vendored
100644
0
test/fast/Unit tests/mocks/project_dirs/nested-n_m/node_modules/.gitkeep
generated
vendored
100644
0
test/fast/Unit tests/mocks/project_dirs/no-nesting-both/node_modules/.gitkeep
generated
vendored
100644
0
test/fast/Unit tests/mocks/project_dirs/no-nesting-both/node_modules/.gitkeep
generated
vendored
100644
0
test/fast/Unit tests/mocks/project_dirs/no-nesting-n_m/node_modules/.gitkeep
generated
vendored
100644
0
test/fast/Unit tests/mocks/project_dirs/no-nesting-n_m/node_modules/.gitkeep
generated
vendored
100644
|
@ -0,0 +1,33 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
die () { echo "$@" ; exit 1; }
|
||||||
|
|
||||||
|
\. ../../../nvm.sh
|
||||||
|
|
||||||
|
set -ex
|
||||||
|
|
||||||
|
TEST_DIR="$PWD/mocks/project_dirs"
|
||||||
|
|
||||||
|
ACTUAL="$(PWD=$TEST_DIR/inside-n_m-nested/node_modules/foo/bar nvm_find_project_dir)"
|
||||||
|
[ "${ACTUAL}" = "$TEST_DIR/inside-n_m-nested" ] || die "inside-n_m-nested: got ${ACTUAL}"
|
||||||
|
|
||||||
|
ACTUAL="$(PWD=$TEST_DIR/inside-n_m-nested-pkg/node_modules/foo/bar nvm_find_project_dir)"
|
||||||
|
[ "${ACTUAL}" = "$TEST_DIR/inside-n_m-nested-pkg/node_modules/foo" ] || die "inside-n_m-nested-pkg: got ${ACTUAL}"
|
||||||
|
|
||||||
|
ACTUAL="$(PWD=$TEST_DIR/nested-both/a/b/c/d nvm_find_project_dir)"
|
||||||
|
[ "${ACTUAL}" = "$TEST_DIR/nested-both" ] || die "nested-both: got ${ACTUAL}"
|
||||||
|
|
||||||
|
ACTUAL="$(PWD=$TEST_DIR/nested-pkg/a/b/c/d nvm_find_project_dir)"
|
||||||
|
[ "${ACTUAL}" = "$TEST_DIR/nested-pkg" ] || die "nested-pkg: got ${ACTUAL}"
|
||||||
|
|
||||||
|
ACTUAL="$(PWD=$TEST_DIR/nested-n_m/a/b/c/d nvm_find_project_dir)"
|
||||||
|
[ "${ACTUAL}" = "$TEST_DIR/nested-n_m" ] || die "nested-n_m: got ${ACTUAL}"
|
||||||
|
|
||||||
|
ACTUAL="$(PWD=$TEST_DIR/no-nesting-both nvm_find_project_dir)"
|
||||||
|
[ "${ACTUAL}" = "$TEST_DIR/no-nesting-both" ] || die "no-nesting-both: got ${ACTUAL}"
|
||||||
|
|
||||||
|
ACTUAL="$(PWD=$TEST_DIR/no-nesting-n_m nvm_find_project_dir)"
|
||||||
|
[ "${ACTUAL}" = "$TEST_DIR/no-nesting-n_m" ] || die "no-nesting-n_m: got ${ACTUAL}"
|
||||||
|
|
||||||
|
ACTUAL="$(PWD=$TEST_DIR/no-nesting-pkg nvm_find_project_dir)"
|
||||||
|
[ "${ACTUAL}" = "$TEST_DIR/no-nesting-pkg" ] || die "no-nesting-pkg: got ${ACTUAL}"
|
Loading…
Reference in New Issue