guess-js-deps-bash 0.1.59 → 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 +70 -13
  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
@@ -88,18 +107,39 @@ function init_resolve_cache () {
88
107
 
89
108
  function init_resolve_cache__prep () {
90
109
  init_resolve_cache__webpack_cfg || return $?
110
+ init_resolve_cache__forced_custom || return $?
91
111
  }
92
112
 
93
113
 
94
114
  function init_resolve_cache__webpack_cfg () {
95
115
  local WPCFG='./webpack.config.js'
96
116
  [ -f "$WPCFG" ] || return 0
97
- local VAL="$(nodejs -p "Object.keys(require('./webpack.config.js'
117
+ local VAL="$(nodejs -p "Object.keys(require('$WPCFG'
98
118
  ).resolve.alias).join('\n')" 2>/dev/null)"
99
119
  [ -z "$VAL" ] || RESOLVE_CACHE['?packer/alias_pkgnames']+="$VAL"$'\n'
100
120
  }
101
121
 
102
122
 
123
+ function init_resolve_cache__forced_custom () {
124
+ local LIST=()
125
+ readarray -t LIST < <(
126
+ nodejs -p 'var manif = require("./package.json"); JSON.stringify([
127
+ manif.dependencies,
128
+ manif.devDependencies,
129
+ ], null, 2)' | sed -nrf <(echo '
130
+ s~^\s+"~~
131
+ s~",?$~~
132
+ s~": "([a-z]\S+/\S+#\S)~\t\1~p
133
+ '))
134
+ local KEY= VAL=
135
+ for VAL in "${LIST[@]}"; do
136
+ KEY="${VAL%%$'\t'*}"
137
+ VAL="${VAL#*$'\t'}"
138
+ RESOLVE_CACHE["$KEY?ver"]="$VAL"
139
+ done
140
+ }
141
+
142
+
103
143
  function find_scannable_files_in_project () {
104
144
  local FF=(
105
145
  -type f
@@ -195,8 +235,16 @@ function find_manif_eslint_deps () {
195
235
  local BUF="$DEPS"
196
236
  BUF="¶ ${BUF//$'\n'/ ¶ } ¶"
197
237
  BUF="${BUF//$'\t'/ » }"
238
+
239
+ local ECNP='eslint-config-nodejs-pmb'
198
240
  case "$BUF" in
199
- *'eslint-config-nodejs-pmb '* )
241
+ *"$ECNP "* )
242
+ local PEER_DEPS="$ECNP/test/expectedPeerDependencies.js"
243
+ PEER_DEPS="require('$PEER_DEPS').join('\n')"
244
+ PEER_DEPS="$(nodejs -p "$PEER_DEPS")"
245
+ [ -n "$PEER_DEPS" ] || return 4$(
246
+ echo "E: Failed to detect peer dependencies of $ECNP" >&2)
247
+ DEPS+=$'\n'"$PEER_DEPS"
200
248
  <<<"$SCRIPTS" grep -qoPe '^\s*"elp[ \&"]' && DEPS+=$'\neslint-pretty-pmb'
201
249
  ;;
202
250
  esac
@@ -692,14 +740,23 @@ function guess_one_dep_type () {
692
740
  doc | \
693
741
  test ) DEP_TYPE=devDep;;
694
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
+
695
753
  case "$REQ_NORM_FEXT" in
696
- */webpack.config.js | \
697
754
  manif://scripts/*lint* | \
698
755
  manif://scripts/*test* | \
699
- manif://lint ) DEP_TYPE=devDep;;
756
+ manif://lint | \
757
+ . ) DEP_TYPE=devDep;;
700
758
  */* ) ;; # files in subdirs are handled above
701
759
  # below: top-level files
702
- *[.-]test.%JS | \
703
760
  test.* ) DEP_TYPE=devDep;;
704
761
  esac
705
762
  fi
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  { "name": "guess-js-deps-bash",
2
- "version": "0.1.59",
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": [