guess-js-deps-bash 0.1.56 → 0.1.59
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 +67 -21
- 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,39 @@ 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 1-3)
|
|
108
145
|
progress 'done.'
|
|
109
146
|
|
|
110
147
|
[ -n "${IMPORTS[0]}" ] || return 3$(
|
|
@@ -666,17 +703,25 @@ function guess_one_dep_type () {
|
|
|
666
703
|
test.* ) DEP_TYPE=devDep;;
|
|
667
704
|
esac
|
|
668
705
|
fi
|
|
706
|
+
case "$DEP_TYPE:$REQ_MOD" in
|
|
707
|
+
dep:eslin't' )
|
|
708
|
+
# :TODO: Better way to opt-out from eslint guessing
|
|
709
|
+
DEP_TYPE='peerDep';;
|
|
710
|
+
esac
|
|
669
711
|
|
|
670
712
|
echo -n "$DEP_TYPE"
|
|
671
713
|
echo -n $'\t'"$REQ_MOD"
|
|
672
714
|
echo -n $'\t'"$DEP_VER"
|
|
715
|
+
echo -n $'\t'"$REQ_FILE"
|
|
673
716
|
# echo -n $'\t'"$RESOLVED"
|
|
674
717
|
echo
|
|
675
718
|
}
|
|
676
719
|
|
|
677
720
|
|
|
678
721
|
function guess_unique_stdin_dep_types () {
|
|
679
|
-
|
|
722
|
+
local FIELDS="${1:-1-}"; shift
|
|
723
|
+
csort --unique | with_stdin_args guess_dep_types | cut -sf "$FIELDS" \
|
|
724
|
+
| csort --unique # <-- not --version-sort: would group "@" after "z"
|
|
680
725
|
}
|
|
681
726
|
|
|
682
727
|
|
|
@@ -702,9 +747,10 @@ function merge_redundant_devdeps () {
|
|
|
702
747
|
# Assumption: If dupes exist, they will be exact (esp. same version)
|
|
703
748
|
# because we guessed those version anyway. (The source files didn't
|
|
704
749
|
# care about versions.)
|
|
705
|
-
# Thus we can just eliminate devDeps that are also deps:
|
|
706
|
-
DEPS_BY_TYPE[
|
|
707
|
-
|
|
750
|
+
# Thus we can just eliminate devDeps that are also deps or peerDeps:
|
|
751
|
+
local EXCLUDE="${DEPS_BY_TYPE[dep]}"
|
|
752
|
+
EXCLUDE+=$'\n'"${DEPS_BY_TYPE[peerDep]}"
|
|
753
|
+
DEPS_BY_TYPE[devDep]="$(<<<"${DEPS_BY_TYPE[devDep]}" grep -vxFe "$EXCLUDE")"
|
|
708
754
|
return 0
|
|
709
755
|
}
|
|
710
756
|
|
package/package.json
CHANGED