guess-js-deps-bash 0.1.63 → 0.1.64
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.
- package/guess-js-deps.sh +70 -14
- package/package.json +8 -3
package/guess-js-deps.sh
CHANGED
|
@@ -21,18 +21,16 @@ function guess_js_deps () {
|
|
|
21
21
|
devDep
|
|
22
22
|
peerDep
|
|
23
23
|
)
|
|
24
|
+
local -A CFG=(
|
|
25
|
+
[runmode]='cmp'
|
|
26
|
+
)
|
|
27
|
+
local POS_ARGN=( runmode )
|
|
28
|
+
local POS_ARGS=()
|
|
29
|
+
parse_cli_opts "$@" || return $?
|
|
24
30
|
|
|
25
|
-
local RUNMODE="$1"; shift
|
|
26
|
-
case "$RUNMODE" in
|
|
27
|
-
'..' | '../'* )
|
|
28
|
-
cd -- "$RUNMODE" # probably to where your package.json is.
|
|
29
|
-
RUNMODE="$1"
|
|
30
|
-
shift;;
|
|
31
|
-
esac
|
|
32
31
|
local OUTPUT_MODE=( fail 'Unsupported output mode. This is a bug.' )
|
|
33
|
-
case "$
|
|
32
|
+
case "${CFG[runmode]}" in
|
|
34
33
|
as-json ) OUTPUT_MODE=( dump_deps_as_json );;
|
|
35
|
-
'' | \
|
|
36
34
|
cmp ) OUTPUT_MODE=( maybe_colorize_diff compare_deps_as_json );;
|
|
37
35
|
upd ) OUTPUT_MODE=( update_manifest );;
|
|
38
36
|
sym ) OUTPUT_MODE=( symlink_nonlocal_node_modules );;
|
|
@@ -56,13 +54,46 @@ function guess_js_deps () {
|
|
|
56
54
|
tabulate-found ) OUTPUT_MODE=( 'fmt://tsv' );;
|
|
57
55
|
tabulate-known ) tabulate_manifest_deps; return $?;;
|
|
58
56
|
--func ) "$@"; return $?;;
|
|
59
|
-
* ) fail "unsupported runmode: $
|
|
57
|
+
* ) fail "unsupported runmode: ${CFG[runmode]}"; return 2;;
|
|
60
58
|
esac
|
|
61
59
|
|
|
62
60
|
find_imports_in_project "${OUTPUT_MODE[@]}"
|
|
63
61
|
}
|
|
64
62
|
|
|
65
63
|
|
|
64
|
+
function parse_cli_opts () {
|
|
65
|
+
local OPT=
|
|
66
|
+
while [ "$#" -gt 0 ]; do
|
|
67
|
+
OPT="$1"; shift
|
|
68
|
+
# [ -n "$OPT" ] || continue
|
|
69
|
+
#case "${CFG[no-more-opts]}$OPT" in
|
|
70
|
+
case "$OPT" in
|
|
71
|
+
'' ) continue;;
|
|
72
|
+
'..' | '../'* ) cd -- "$OPT";; # probably to where your package.json is.
|
|
73
|
+
-- ) POS_ARGS+=( "$@" ); break;;
|
|
74
|
+
#-- ) CFG[no-more-opts]='%%--'; continue;;
|
|
75
|
+
--expect-no-changes | \
|
|
76
|
+
--maybe-no-imports | \
|
|
77
|
+
'' ) CFG["${OPT#--}"]=+;;
|
|
78
|
+
--*=* )
|
|
79
|
+
OPT="${OPT#--}"
|
|
80
|
+
CFG["${OPT%%=*}"]="${OPT#*=}";;
|
|
81
|
+
--help | \
|
|
82
|
+
-* )
|
|
83
|
+
local -fp "${FUNCNAME[0]}" | guess_bash_script_config_opts-pmb
|
|
84
|
+
[ "${OPT//-/}" == help ] && return 1
|
|
85
|
+
echo "E: $0, CLI: unsupported option: $OPT" >&2; return 1;;
|
|
86
|
+
* )
|
|
87
|
+
case "${POS_ARGN[0]}" in
|
|
88
|
+
'' ) echo "E: $0: unexpected positional argument" >&2; return 1;;
|
|
89
|
+
'+' ) POS_ARGS+=( "$OPT" );;
|
|
90
|
+
* ) CFG["${POS_ARGN[0]}"]="$OPT"; POS_ARGN=( "${POS_ARGN[@]:1}" );;
|
|
91
|
+
esac;;
|
|
92
|
+
esac
|
|
93
|
+
done
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
|
|
66
97
|
function warn_no_args () {
|
|
67
98
|
[ "$#" -ge 2 ] || echo "W: Calling $1 with no arguments!" >&2
|
|
68
99
|
"$@"; return $?
|
|
@@ -70,8 +101,18 @@ function warn_no_args () {
|
|
|
70
101
|
|
|
71
102
|
|
|
72
103
|
function maybe_colorize_diff () {
|
|
73
|
-
[ -
|
|
74
|
-
"$
|
|
104
|
+
[ -n "$*" ] || return 0
|
|
105
|
+
if [ -n "$COLORIZE_DIFF" ]; then
|
|
106
|
+
exec > >("$COLORIZE_DIFF")
|
|
107
|
+
fi
|
|
108
|
+
local RV=
|
|
109
|
+
"$@"; RV=$?
|
|
110
|
+
|
|
111
|
+
# Wait for output to go through the coloring process before returning
|
|
112
|
+
# control to parent process. (Which might want to print something
|
|
113
|
+
# immediately, which might overlap.)
|
|
114
|
+
[ -z "$COLORIZE_DIFF" ] || sleep 0.2s
|
|
115
|
+
return "$RV"
|
|
75
116
|
}
|
|
76
117
|
|
|
77
118
|
|
|
@@ -200,8 +241,16 @@ function find_imports_in_project () {
|
|
|
200
241
|
| guess_unique_stdin_dep_types 1-3)
|
|
201
242
|
progress 'done.'
|
|
202
243
|
|
|
203
|
-
|
|
204
|
-
|
|
244
|
+
local ERR=
|
|
245
|
+
if [ -z "${IMPORTS[0]}" ]; then
|
|
246
|
+
ERR="Unable to find any import()s/imports in package: $CWD_PKG_NAME"
|
|
247
|
+
if [ -n "${CFG[maybe-no-imports]}" ]; then
|
|
248
|
+
echo "D: $ERR"
|
|
249
|
+
return 0
|
|
250
|
+
fi
|
|
251
|
+
fail "$ERR"
|
|
252
|
+
return 3
|
|
253
|
+
fi
|
|
205
254
|
|
|
206
255
|
if [ "${OUTPUT_MODE[0]}" == 'fmt://tsv' ]; then
|
|
207
256
|
printf '%s\n' "${IMPORTS[@]}"
|
|
@@ -362,9 +411,15 @@ function compare_deps_as_json () {
|
|
|
362
411
|
eval local -A DEP_OFFSETS="( $(find_dep_keys_line_numbers) )"
|
|
363
412
|
|
|
364
413
|
local DEP_TYPE=
|
|
414
|
+
local CHANGES_IN_DEP_TYPES=
|
|
415
|
+
|
|
365
416
|
for DEP_TYPE in "${KNOWN_DEP_TYPES[@]}"; do
|
|
366
417
|
compare_deps_as_json__one_dep_type || return $?
|
|
367
418
|
done
|
|
419
|
+
|
|
420
|
+
[ -z "$CHANGES_IN_DEP_TYPES" ] \
|
|
421
|
+
|| [ -z "${CFG[expect-no-changes]}" ] || return 4$(
|
|
422
|
+
fail "Found unexpected changes! in:$CHANGES_IN_DEP_TYPES")
|
|
368
423
|
}
|
|
369
424
|
|
|
370
425
|
|
|
@@ -376,6 +431,7 @@ function compare_deps_as_json__one_dep_type () {
|
|
|
376
431
|
echo "D: no changes in ${DEP_TYPE}s"
|
|
377
432
|
return 0
|
|
378
433
|
fi
|
|
434
|
+
CHANGES_IN_DEP_TYPES+=" $DEP_TYPE"
|
|
379
435
|
|
|
380
436
|
local EMPTY="${DEP_OFFSETS[$DEP_TYPE:empty]}"
|
|
381
437
|
if [ -n "$VERBATIM_EMPTY_ORIG" -a -n "$EMPTY" ]; then
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{ "name": "guess-js-deps-bash",
|
|
2
|
-
"version": "0.1.
|
|
2
|
+
"version": "0.1.64",
|
|
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": [
|
|
@@ -26,12 +26,17 @@
|
|
|
26
26
|
|
|
27
27
|
"main": "capture-bash.js",
|
|
28
28
|
"bin": { "guess-js-deps": "guess-js-deps.sh" },
|
|
29
|
-
"scripts": { "test": "
|
|
29
|
+
"scripts": { "test": "elp && guess-js-deps cmp --expect-no-changes" },
|
|
30
30
|
"directories": { "test": "test" },
|
|
31
31
|
"eslintConfig": { "extends": "nodejs-pmb" },
|
|
32
32
|
|
|
33
33
|
"dependencies": {},
|
|
34
|
-
"devDependencies": {
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"eslint-config-nodejs-pmb": "^0.3.5",
|
|
36
|
+
"eslint-plugin-json-light-pmb": "^1.0.7",
|
|
37
|
+
"eslint-plugin-n": "^15.2.4",
|
|
38
|
+
"eslint-pretty-pmb": "^1.0.5"
|
|
39
|
+
},
|
|
35
40
|
|
|
36
41
|
|
|
37
42
|
"engines": { "npm": ">=7.0.0", "node": ">=16.0.0" }
|