Skip to content
Myr

[New] add `nvm_find_project_dir` helper

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Jordan Harband · committed by Jordan Harband · parent 1d88ecf · Browse files · 17 files+49 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

17 files+49 added−1 removed

  • tests:+33 added−0 removed
  • other:+16 added−1 removed

17 files+49 added−1 removed

added:test/fast/Unit tests/mocks/project_dirs/inside-n_m-nested/node_modules/foo/bar/.gitkeep
added:test/fast/Unit tests/mocks/project_dirs/inside-n_m-nested-pkg/node_modules/foo/bar/.gitkeep
added:test/fast/Unit tests/mocks/project_dirs/inside-n_m-nested-pkg/node_modules/foo/package.json
added:test/fast/Unit tests/mocks/project_dirs/nested-both/a/b/c/d/.gitkeep
added:test/fast/Unit tests/mocks/project_dirs/nested-both/node_modules/.gitkeep
added:test/fast/Unit tests/mocks/project_dirs/nested-both/package.json
added:test/fast/Unit tests/mocks/project_dirs/nested-n_m/a/b/c/d/.gitkeep
added:test/fast/Unit tests/mocks/project_dirs/nested-n_m/node_modules/.gitkeep
added:test/fast/Unit tests/mocks/project_dirs/nested-pkg/a/b/c/d/.gitkeep
added:test/fast/Unit tests/mocks/project_dirs/nested-pkg/package.json
added:test/fast/Unit tests/mocks/project_dirs/no-nesting-both/node_modules/.gitkeep
added:test/fast/Unit tests/mocks/project_dirs/no-nesting-both/package.json
added:test/fast/Unit tests/mocks/project_dirs/no-nesting-n_m/node_modules/.gitkeep
added:test/fast/Unit tests/mocks/project_dirs/no-nesting-pkg/package.json
added:test/fast/Unit tests/nvm_find_project_dir+33 added
1#!/bin/sh23die () { echo "$@" ; exit 1; }45\. ../../../nvm.sh67set -ex89TEST_DIR="$PWD/mocks/project_dirs"1011ACTUAL="$(PWD=$TEST_DIR/inside-n_m-nested/node_modules/foo/bar nvm_find_project_dir)"12[ "${ACTUAL}" = "$TEST_DIR/inside-n_m-nested" ] || die "inside-n_m-nested: got ${ACTUAL}"1314ACTUAL="$(PWD=$TEST_DIR/inside-n_m-nested-pkg/node_modules/foo/bar nvm_find_project_dir)"15[ "${ACTUAL}" = "$TEST_DIR/inside-n_m-nested-pkg/node_modules/foo" ] || die "inside-n_m-nested-pkg: got ${ACTUAL}"1617ACTUAL="$(PWD=$TEST_DIR/nested-both/a/b/c/d nvm_find_project_dir)"18[ "${ACTUAL}" = "$TEST_DIR/nested-both" ] || die "nested-both: got ${ACTUAL}"1920ACTUAL="$(PWD=$TEST_DIR/nested-pkg/a/b/c/d nvm_find_project_dir)"21[ "${ACTUAL}" = "$TEST_DIR/nested-pkg" ] || die "nested-pkg: got ${ACTUAL}"2223ACTUAL="$(PWD=$TEST_DIR/nested-n_m/a/b/c/d nvm_find_project_dir)"24[ "${ACTUAL}" = "$TEST_DIR/nested-n_m" ] || die "nested-n_m: got ${ACTUAL}"2526ACTUAL="$(PWD=$TEST_DIR/no-nesting-both nvm_find_project_dir)"27[ "${ACTUAL}" = "$TEST_DIR/no-nesting-both" ] || die "no-nesting-both: got ${ACTUAL}"2829ACTUAL="$(PWD=$TEST_DIR/no-nesting-n_m nvm_find_project_dir)"30[ "${ACTUAL}" = "$TEST_DIR/no-nesting-n_m" ] || die "no-nesting-n_m: got ${ACTUAL}"3132ACTUAL="$(PWD=$TEST_DIR/no-nesting-pkg nvm_find_project_dir)"33[ "${ACTUAL}" = "$TEST_DIR/no-nesting-pkg" ] || die "no-nesting-pkg: got ${ACTUAL}"
modified:.editorconfig+6 added
16 unmodified lines
1718[test/fast/Listing versions/Running "nvm ls --no-alias" does not call into nvm_alias]19indent_size = false2021[test/fast/Unit tests/mocks/**]22insert_final_newline = off2324[test/**/.urchin*]25insert_final_newline = off2627[Makefile]28indent_style = tab
modified:nvm.sh+10 added-1 removed
315 unmodified lines
316 done317 [ "${pathdir}" = "${tree}" ]318}319320nvm_find_project_dir() {321 local path_322 path_="${PWD}"323 while [ "${path_}" != "" ] && [ ! -f "${path_}/package.json" ] && [ ! -d "${path_}/node_modules" ]; do324 path_=${path_%/*}325 done326 nvm_echo "${path_}"327}328329# Traverse up in directory tree to find containing folder330nvm_find_up() {331 local path_332 path_="${PWD}"
3329 unmodified lines
3662 nvm_num_version_groups nvm_format_version nvm_ensure_version_prefix \3663 nvm_normalize_version nvm_is_valid_version \3664 nvm_ensure_version_installed nvm_cache_dir \3665 nvm_version_path nvm_alias_path nvm_version_dir \3657 nvm_find_nvmrc nvm_find_up nvm_tree_contains_path \3666 nvm_find_nvmrc nvm_find_up nvm_find_project_dir nvm_tree_contains_path \3667 nvm_version_greater nvm_version_greater_than_or_equal_to \3668 nvm_print_npm_version nvm_install_latest_npm nvm_npm_global_modules \3669 nvm_has_system_node nvm_has_system_iojs \3670 nvm_download nvm_get_latest nvm_has nvm_install_default_packages nvm_get_default_packages \
178 unmodified lines