guess-js-deps-bash 0.1.61 → 0.1.62

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/guess-js-deps.sh +40 -12
  2. package/package.json +1 -1
package/guess-js-deps.sh CHANGED
@@ -33,9 +33,9 @@ function guess_js_deps () {
33
33
  case "$RUNMODE" in
34
34
  as-json ) OUTPUT_MODE=( dump_deps_as_json );;
35
35
  '' | \
36
- cmp ) OUTPUT_MODE=( maybe_colorize_diff compare_deps_as_json );;
37
- upd ) OUTPUT_MODE=( update_manifest );;
38
- sym ) OUTPUT_MODE=( symlink_nonlocal_node_modules );;
36
+ cmp ) OUTPUT_MODE=( maybe_colorize_diff compare_deps_as_json );;
37
+ upd ) OUTPUT_MODE=( update_manifest );;
38
+ sym ) OUTPUT_MODE=( symlink_nonlocal_node_modules );;
39
39
 
40
40
  usy )
41
41
  OUTPUT_MODE=( output_multi
@@ -43,12 +43,9 @@ function guess_js_deps () {
43
43
  symlink_nonlocal_node_modules
44
44
  );;
45
45
 
46
- why )
47
- scan_all_scannable_files_in_project \
48
- | guess_unique_stdin_dep_types
49
- return $?;;
46
+ why ) debug_why "$@"; return $?;;
47
+ manif ) read_json_subtree "$@"; return $?;;
50
48
 
51
- manif ) read_json_subtree "$@"; return $?;;
52
49
  list-files ) find_scannable_files_in_project; return $?;;
53
50
  scan-all ) scan_all_scannable_files_in_project; return $?;;
54
51
  scan-imports ) warn_no_args find_imports_in_files "$@"; return $?;;
@@ -78,6 +75,28 @@ function maybe_colorize_diff () {
78
75
  }
79
76
 
80
77
 
78
+ function debug_why () {
79
+ if [ "$#" == 0 ]; then
80
+ scan_all_scannable_files_in_project \
81
+ | guess_unique_stdin_dep_types
82
+ return $?
83
+ fi
84
+
85
+ local OPT=()
86
+ local KWD=
87
+ case "$1" in
88
+ -* ) OPT=( "$@" );;
89
+ * )
90
+ KWD="$(<<<"$*" grep -Pe '\S+')"
91
+ [ -n "$KWD" ] || return 4$(echo "E: $FUNCNAME: Empty keywords" >&2)
92
+ tty --silent <&1 && OPT+=( --color=always )
93
+ OPT+=( -Fie "$KWD" )
94
+ ;;
95
+ esac
96
+ </dev/null "$FUNCNAME" | grep "${OPT[@]}"
97
+ }
98
+
99
+
81
100
  function init_resolve_cache () {
82
101
  # echo "D: ${FUNCNAME[*]}: <${!RESOLVE_CACHE[*]}>" >&2
83
102
  [ -n "${!RESOLVE_CACHE[*]}" ] && return 0
@@ -95,7 +114,7 @@ function init_resolve_cache__prep () {
95
114
  function init_resolve_cache__webpack_cfg () {
96
115
  local WPCFG='./webpack.config.js'
97
116
  [ -f "$WPCFG" ] || return 0
98
- local VAL="$(nodejs -p "Object.keys(require('./webpack.config.js'
117
+ local VAL="$(nodejs -p "Object.keys(require('$WPCFG'
99
118
  ).resolve.alias).join('\n')" 2>/dev/null)"
100
119
  [ -z "$VAL" ] || RESOLVE_CACHE['?packer/alias_pkgnames']+="$VAL"$'\n'
101
120
  }
@@ -721,14 +740,23 @@ function guess_one_dep_type () {
721
740
  doc | \
722
741
  test ) DEP_TYPE=devDep;;
723
742
  esac
743
+
744
+ case "…/$REQ_NORM_FEXT" in
745
+ # ^-- The following patterns shall match the top-level directory
746
+ # as well as any subdir.
747
+
748
+ *[.-]test.%JS | \
749
+ */webpack.config.%JS | \
750
+ . ) DEP_TYPE=devDep;;
751
+ esac
752
+
724
753
  case "$REQ_NORM_FEXT" in
725
- */webpack.config.js | \
726
754
  manif://scripts/*lint* | \
727
755
  manif://scripts/*test* | \
728
- manif://lint ) DEP_TYPE=devDep;;
756
+ manif://lint | \
757
+ . ) DEP_TYPE=devDep;;
729
758
  */* ) ;; # files in subdirs are handled above
730
759
  # below: top-level files
731
- *[.-]test.%JS | \
732
760
  test.* ) DEP_TYPE=devDep;;
733
761
  esac
734
762
  fi
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  { "name": "guess-js-deps-bash",
2
- "version": "0.1.61",
2
+ "version": "0.1.62",
3
3
  "description": "A bash attempt at npm-forgot: Guess JavaScript require() dependencies, detect their versions, compare with package.json.",
4
4
 
5
5
  "keywords": [