guess-js-deps-bash 0.1.56 → 0.1.57
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 +65 -20
- package/package.json +1 -1
package/guess-js-deps.sh
CHANGED
|
@@ -16,7 +16,11 @@ function guess_js_deps () {
|
|
|
16
16
|
local DBGLV="${DEBUGLEVEL:-0}"
|
|
17
17
|
local COLORIZE_DIFF="$(can_haz_cmd colordiff)"
|
|
18
18
|
local MANI_BFN='package.json'
|
|
19
|
-
local KNOWN_DEP_TYPES=(
|
|
19
|
+
local KNOWN_DEP_TYPES=(
|
|
20
|
+
dep
|
|
21
|
+
devDep
|
|
22
|
+
peerDep
|
|
23
|
+
)
|
|
20
24
|
|
|
21
25
|
local RUNMODE="$1"; shift
|
|
22
26
|
case "$RUNMODE" in
|
|
@@ -32,16 +36,26 @@ function guess_js_deps () {
|
|
|
32
36
|
cmp ) OUTPUT_MODE=( maybe_colorize_diff compare_deps_as_json );;
|
|
33
37
|
upd ) OUTPUT_MODE=( update_manifest );;
|
|
34
38
|
sym ) OUTPUT_MODE=( symlink_nonlocal_node_modules );;
|
|
39
|
+
|
|
35
40
|
usy )
|
|
36
41
|
OUTPUT_MODE=( output_multi
|
|
37
42
|
update_manifest
|
|
38
43
|
symlink_nonlocal_node_modules
|
|
39
44
|
);;
|
|
45
|
+
|
|
46
|
+
why )
|
|
47
|
+
scan_all_scannable_files_in_project \
|
|
48
|
+
| guess_unique_stdin_dep_types
|
|
49
|
+
return $?;;
|
|
50
|
+
|
|
40
51
|
manif ) read_json_subtree "$@"; return $?;;
|
|
41
|
-
|
|
52
|
+
list-files ) find_scannable_files_in_project; return $?;;
|
|
53
|
+
scan-all ) scan_all_scannable_files_in_project; return $?;;
|
|
54
|
+
scan-imports ) warn_no_args find_imports_in_files "$@"; return $?;;
|
|
42
55
|
scan-known ) scan_manifest_deps; return $?;;
|
|
43
56
|
scan-manif ) find_manif_script_deps "$@"; return $?;;
|
|
44
57
|
scan-eslint-cfg ) find_manif_eslint_deps "$@"; return $?;;
|
|
58
|
+
guess-types ) guess_unique_stdin_dep_types; return $?;;
|
|
45
59
|
tabulate-found ) OUTPUT_MODE=( 'fmt://tsv' );;
|
|
46
60
|
tabulate-known ) tabulate_manifest_deps; return $?;;
|
|
47
61
|
--func ) "$@"; return $?;;
|
|
@@ -52,6 +66,12 @@ function guess_js_deps () {
|
|
|
52
66
|
}
|
|
53
67
|
|
|
54
68
|
|
|
69
|
+
function warn_no_args () {
|
|
70
|
+
[ "$#" -ge 2 ] || echo "W: Calling $1 with no arguments!" >&2
|
|
71
|
+
"$@"; return $?
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
|
|
55
75
|
function maybe_colorize_diff () {
|
|
56
76
|
[ -z "$*" ] || exec < <("$@")
|
|
57
77
|
"${COLORIZE_DIFF:-cat}"
|
|
@@ -80,14 +100,8 @@ function init_resolve_cache__webpack_cfg () {
|
|
|
80
100
|
}
|
|
81
101
|
|
|
82
102
|
|
|
83
|
-
function
|
|
84
|
-
local
|
|
85
|
-
local CWD_PKG_NAME="$(guess_cwd_pkg_name)"
|
|
86
|
-
progress 'I: Searching for JavaScript files: '
|
|
87
|
-
local -A DEPS_BY_TYPE=()
|
|
88
|
-
eval "$(init_resolve_cache)"
|
|
89
|
-
local IMPORTS=()
|
|
90
|
-
IMPORTS=(
|
|
103
|
+
function find_scannable_files_in_project () {
|
|
104
|
+
local FF=(
|
|
91
105
|
-type f
|
|
92
106
|
'(' -name '*.js'
|
|
93
107
|
-o -name '*.mjs'
|
|
@@ -95,16 +109,40 @@ function find_imports_in_project () {
|
|
|
95
109
|
-o -name '*.html'
|
|
96
110
|
')'
|
|
97
111
|
)
|
|
98
|
-
|
|
112
|
+
fastfind "${FF[@]}" || return $?
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
function scan_all_scannable_files_in_project () {
|
|
117
|
+
if [ "$1" == --reuse-imports-array ]; then
|
|
118
|
+
shift
|
|
119
|
+
else
|
|
120
|
+
local IMPORTS=()
|
|
121
|
+
fi
|
|
122
|
+
|
|
123
|
+
progress 'I: Searching for JavaScript files: '
|
|
124
|
+
readarray -t IMPORTS < <(find_scannable_files_in_project)
|
|
99
125
|
progress "found ${#IMPORTS[@]}"
|
|
100
126
|
|
|
101
127
|
progress 'I: Searching for require()s/imports: '
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
128
|
+
find_imports_in_files "${IMPORTS[@]}"
|
|
129
|
+
find_manif_script_deps
|
|
130
|
+
find_manif_eslint_deps
|
|
131
|
+
find_simple_html_script_deps
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
function find_imports_in_project () {
|
|
136
|
+
local THEN=( "$@" )
|
|
137
|
+
local CWD_PKG_NAME="$(guess_cwd_pkg_name)"
|
|
138
|
+
local -A DEPS_BY_TYPE=()
|
|
139
|
+
eval "$(init_resolve_cache)"
|
|
140
|
+
|
|
141
|
+
local IMPORTS=()
|
|
142
|
+
readarray -t IMPORTS < <(
|
|
143
|
+
scan_all_scannable_files_in_project \
|
|
144
|
+
| guess_unique_stdin_dep_types \
|
|
145
|
+
| cut -sf 1-3)
|
|
108
146
|
progress 'done.'
|
|
109
147
|
|
|
110
148
|
[ -n "${IMPORTS[0]}" ] || return 3$(
|
|
@@ -666,10 +704,16 @@ function guess_one_dep_type () {
|
|
|
666
704
|
test.* ) DEP_TYPE=devDep;;
|
|
667
705
|
esac
|
|
668
706
|
fi
|
|
707
|
+
case "$DEP_TYPE:$REQ_MOD" in
|
|
708
|
+
dep:eslin't' )
|
|
709
|
+
# :TODO: Better way to opt-out from eslint guessing
|
|
710
|
+
DEP_TYPE='peerDep';;
|
|
711
|
+
esac
|
|
669
712
|
|
|
670
713
|
echo -n "$DEP_TYPE"
|
|
671
714
|
echo -n $'\t'"$REQ_MOD"
|
|
672
715
|
echo -n $'\t'"$DEP_VER"
|
|
716
|
+
echo -n $'\t'"$REQ_FILE"
|
|
673
717
|
# echo -n $'\t'"$RESOLVED"
|
|
674
718
|
echo
|
|
675
719
|
}
|
|
@@ -702,9 +746,10 @@ function merge_redundant_devdeps () {
|
|
|
702
746
|
# Assumption: If dupes exist, they will be exact (esp. same version)
|
|
703
747
|
# because we guessed those version anyway. (The source files didn't
|
|
704
748
|
# care about versions.)
|
|
705
|
-
# Thus we can just eliminate devDeps that are also deps:
|
|
706
|
-
DEPS_BY_TYPE[
|
|
707
|
-
|
|
749
|
+
# Thus we can just eliminate devDeps that are also deps or peerDeps:
|
|
750
|
+
local EXCLUDE="${DEPS_BY_TYPE[dep]}"
|
|
751
|
+
EXCLUDE+=$'\n'"${DEPS_BY_TYPE[peerDep]}"
|
|
752
|
+
DEPS_BY_TYPE[devDep]="$(<<<"${DEPS_BY_TYPE[devDep]}" grep -vxFe "$EXCLUDE")"
|
|
708
753
|
return 0
|
|
709
754
|
}
|
|
710
755
|
|
package/package.json
CHANGED