guess-js-deps-bash 0.1.68 → 0.1.70
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 +99 -42
- package/package.json +3 -3
package/guess-js-deps.sh
CHANGED
|
@@ -7,15 +7,19 @@ function guess_js_deps () {
|
|
|
7
7
|
|
|
8
8
|
local SELFPATH="$(readlink -m "$BASH_SOURCE"/..)"
|
|
9
9
|
#cd -- "$SELFPATH" || return $?
|
|
10
|
-
source "$SELFPATH"/lib_dict_util.sh --lib || exit $?
|
|
11
|
-
source "$SELFPATH"/lib_path_util.sh --lib || exit $?
|
|
10
|
+
source -- "$SELFPATH"/lib_dict_util.sh --lib || exit $?
|
|
11
|
+
source -- "$SELFPATH"/lib_path_util.sh --lib || exit $?
|
|
12
12
|
|
|
13
13
|
# import AUTOGUESS_SHEBANG_CMDS and AUTOGUESS_BUILD_UTIL_CMDS:
|
|
14
|
-
source "$SELFPATH"/autoguess_config.txt --lib || exit $?
|
|
14
|
+
source -- "$SELFPATH"/autoguess_config.txt --lib || exit $?
|
|
15
15
|
|
|
16
16
|
local DBGLV="${DEBUGLEVEL:-0}"
|
|
17
17
|
local COLORIZE_DIFF="$(can_haz_cmd colordiff)"
|
|
18
18
|
local MANI_BFN='package.json'
|
|
19
|
+
|
|
20
|
+
local SAFE_PLAIN_MODULE_ID_RGX='[a-z][a-z0-9_.-]*'
|
|
21
|
+
sanity_check_safe_plain_module_id_rgx || return $?
|
|
22
|
+
|
|
19
23
|
local KNOWN_DEP_TYPES=(
|
|
20
24
|
dep
|
|
21
25
|
devDep
|
|
@@ -24,9 +28,10 @@ function guess_js_deps () {
|
|
|
24
28
|
local -A CFG=(
|
|
25
29
|
[runmode]='cmp'
|
|
26
30
|
)
|
|
27
|
-
local POS_ARGN=( runmode )
|
|
31
|
+
local POS_ARGN=( runmode + )
|
|
28
32
|
local POS_ARGS=()
|
|
29
33
|
parse_cli_opts "$@" || return $?
|
|
34
|
+
set -- "${POS_ARGS[@]}"
|
|
30
35
|
|
|
31
36
|
local OUTPUT_MODE=( fail 'Unsupported output mode. This is a bug.' )
|
|
32
37
|
case "${CFG[runmode]}" in
|
|
@@ -44,7 +49,7 @@ function guess_js_deps () {
|
|
|
44
49
|
why ) debug_why "$@"; return $?;;
|
|
45
50
|
manif ) read_json_subtree "$@"; return $?;;
|
|
46
51
|
|
|
47
|
-
list-files )
|
|
52
|
+
list-js-files ) find_project_files_with_potential_js_code; return $?;;
|
|
48
53
|
scan-all ) scan_all_scannable_files_in_project; return $?;;
|
|
49
54
|
scan-imports ) warn_no_args find_imports_in_files "$@"; return $?;;
|
|
50
55
|
scan-known ) scan_manifest_deps; return $?;;
|
|
@@ -61,6 +66,42 @@ function guess_js_deps () {
|
|
|
61
66
|
}
|
|
62
67
|
|
|
63
68
|
|
|
69
|
+
function sanity_check_safe_plain_module_id_rgx () {
|
|
70
|
+
# Validate that all aspects of this regexp work correctly with the local
|
|
71
|
+
# implementation of bash, sed and grep:
|
|
72
|
+
local RGX="$SAFE_PLAIN_MODULE_ID_RGX"
|
|
73
|
+
local ACCEPT=(
|
|
74
|
+
dom80
|
|
75
|
+
highlight.js
|
|
76
|
+
)
|
|
77
|
+
local ITEM=
|
|
78
|
+
for ITEM in "${ACCEPT[@]}"; do
|
|
79
|
+
[[ "$ITEM" =~ ^$RGX$ ]]
|
|
80
|
+
[ "$?:${#BASH_REMATCH[@]}:${BASH_REMATCH[*]}" == "0:1:$ITEM" ] ||
|
|
81
|
+
return 4$(echo E: $FUNCNAME: "bash should have accepted '$ITEM'" >&2)
|
|
82
|
+
[ "$(grep -xPe "$RGX" <<<"$ITEM")" == "$ITEM" ] ||
|
|
83
|
+
return 4$(echo E: $FUNCNAME: "grep should have accepted '$ITEM'" >&2)
|
|
84
|
+
[ "$(sed -re "s~$RGX~((ok))~g" <<<"[$ITEM]")" == "[((ok))]" ] ||
|
|
85
|
+
return 4$(echo E: $FUNCNAME: "sed should have accepted '$ITEM'" >&2)
|
|
86
|
+
done
|
|
87
|
+
|
|
88
|
+
local DENY=(
|
|
89
|
+
dom80/
|
|
90
|
+
# döm80 døm80 # meh: bash is really stubborn about umlauts in A-Za-z.
|
|
91
|
+
dom∞
|
|
92
|
+
highlight.js/
|
|
93
|
+
)
|
|
94
|
+
for ITEM in "${DENY[@]}"; do
|
|
95
|
+
[[ "$ITEM" =~ ^$RGX$ ]] && return 4$(
|
|
96
|
+
echo E: $FUNCNAME: "bash should have denied '$ITEM'" >&2)
|
|
97
|
+
[ -z "$(grep -xPe "$RGX" <<<"$ITEM")" ] ||
|
|
98
|
+
return 4$(echo E: $FUNCNAME: "grep should have denied '$ITEM'" >&2)
|
|
99
|
+
[ "$(sed -re "s~$RGX~((ok))~g" <<<"[$ITEM]")" != '[((ok))]' ] ||
|
|
100
|
+
return 4$(echo E: $FUNCNAME: "sed should have denied '$ITEM'" >&2)
|
|
101
|
+
done
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
|
|
64
105
|
function parse_cli_opts () {
|
|
65
106
|
local OPT=
|
|
66
107
|
while [ "$#" -gt 0 ]; do
|
|
@@ -193,16 +234,46 @@ function init_resolve_cache__forced_custom () {
|
|
|
193
234
|
}
|
|
194
235
|
|
|
195
236
|
|
|
196
|
-
function
|
|
197
|
-
local
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
-o -name '*.html'
|
|
203
|
-
')'
|
|
237
|
+
function find_project_files_with_potential_js_code () {
|
|
238
|
+
local JS_FEXTS=(
|
|
239
|
+
html
|
|
240
|
+
js
|
|
241
|
+
jsm
|
|
242
|
+
mjs
|
|
204
243
|
)
|
|
205
|
-
|
|
244
|
+
find_project_files_with_fexts "${JS_FEXTS[@]}" || return $?
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
function find_project_files_with_fexts () {
|
|
249
|
+
local VAL=
|
|
250
|
+
if [ -f .git/config -o -f .git ]; then
|
|
251
|
+
VAL="$*"
|
|
252
|
+
VAL="${VAL// /'|'}"
|
|
253
|
+
# Let git deal with checking worktrees, ignored directories etc.
|
|
254
|
+
( git grep -lPe .
|
|
255
|
+
git status --porcelain -uall | cut --bytes=4-
|
|
256
|
+
) | grep -Pe '\.('"$VAL"')$' | LANG=C sort --version-sort --unique | grep .
|
|
257
|
+
return $?
|
|
258
|
+
fi
|
|
259
|
+
|
|
260
|
+
local FIND=(
|
|
261
|
+
-xdev
|
|
262
|
+
|
|
263
|
+
# Prunes:
|
|
264
|
+
'(' -false
|
|
265
|
+
-o -name .git
|
|
266
|
+
-o -name .svn
|
|
267
|
+
-o -name node_modules
|
|
268
|
+
-o -name bower_components
|
|
269
|
+
')' -prune ','
|
|
270
|
+
|
|
271
|
+
# Files we want:
|
|
272
|
+
-type f '(' -false )
|
|
273
|
+
for VAL in "$@"; do FIND+=( -o -name "*.$VAL" ); done
|
|
274
|
+
FIND+=( ')' )
|
|
275
|
+
find "${FIND[@]}"
|
|
276
|
+
return $?
|
|
206
277
|
}
|
|
207
278
|
|
|
208
279
|
|
|
@@ -214,7 +285,7 @@ function scan_all_scannable_files_in_project () {
|
|
|
214
285
|
fi
|
|
215
286
|
|
|
216
287
|
progress 'I: Searching for JavaScript files: '
|
|
217
|
-
readarray -t IMPORTS < <(
|
|
288
|
+
readarray -t IMPORTS < <(find_project_files_with_potential_js_code)
|
|
218
289
|
progress "found ${#IMPORTS[@]}"
|
|
219
290
|
|
|
220
291
|
progress 'I: Searching for require()s/imports: '
|
|
@@ -275,7 +346,7 @@ function find_imports_in_project () {
|
|
|
275
346
|
|
|
276
347
|
function find_manif_script_deps () {
|
|
277
348
|
local SCRIPTS=()
|
|
278
|
-
readarray -t SCRIPTS < <(
|
|
349
|
+
readarray -t SCRIPTS < <(find_project_files_with_fexts sh)
|
|
279
350
|
( </dev/null grep -HvPe '^\s*(#[^!]|$)' -- "${SCRIPTS[@]}"
|
|
280
351
|
read_json_subtree '' .scripts | sed -nre '
|
|
281
352
|
s~^\s*"([^"]+)": "~\v<manif>scripts/\1 ~p'
|
|
@@ -630,18 +701,6 @@ function node_detect_manif_version () {
|
|
|
630
701
|
}
|
|
631
702
|
|
|
632
703
|
|
|
633
|
-
function fastfind () {
|
|
634
|
-
local PRUNES=( '(' -false
|
|
635
|
-
-o -name .git
|
|
636
|
-
-o -name .svn
|
|
637
|
-
-o -name node_modules
|
|
638
|
-
-o -name bower_components
|
|
639
|
-
')' -prune ',' )
|
|
640
|
-
find -xdev "${PRUNES[@]}" "$@"
|
|
641
|
-
return $?
|
|
642
|
-
}
|
|
643
|
-
|
|
644
|
-
|
|
645
704
|
function find_imports_in_files () {
|
|
646
705
|
[ "$#" == 0 ] && return 0
|
|
647
706
|
eval "$(init_resolve_cache)"
|
|
@@ -680,30 +739,27 @@ function remove_paths_from_module_ids () {
|
|
|
680
739
|
# Actual subpath is optional: Trailing slash notation is used in
|
|
681
740
|
# ubborg-planner-pmb's slashableImport.
|
|
682
741
|
|
|
683
|
-
|
|
684
|
-
s~^((
|
|
685
|
-
'
|
|
742
|
+
local SED='
|
|
743
|
+
s~^((@æ/|)(æ))'"$SUBPATH_RGX"'(\t|$)~\1\4~
|
|
744
|
+
'
|
|
745
|
+
SED="${SED//æ/$SAFE_PLAIN_MODULE_ID_RGX}"
|
|
746
|
+
sed -rf <(echo "$SED") -- "$@" || return $?
|
|
686
747
|
}
|
|
687
748
|
|
|
688
749
|
|
|
689
750
|
function find_simple_html_script_deps () {
|
|
690
751
|
progress 'I: Searching for HTML files: ' >&2
|
|
691
|
-
|
|
692
|
-
-type f
|
|
693
|
-
'(' -name '*.html'
|
|
694
|
-
')'
|
|
695
|
-
)
|
|
696
|
-
readarray -t LIST < <(fastfind "${LIST[@]}")
|
|
752
|
+
readarray -t LIST < <(find_project_files_with_fexts html)
|
|
697
753
|
progress "found ${#LIST[@]}" >&2
|
|
698
754
|
[ "${#LIST[@]}" == 0 ] && return 0
|
|
699
755
|
local SRC_FN= TAGS= DEP=
|
|
700
756
|
local Q='"'
|
|
701
757
|
local MODBASE_RGX='(\.*/)*node_modules/'
|
|
702
|
-
local SRC_ATTR_RX=' src="'"$MODBASE_RGX"'[^"]+"'
|
|
758
|
+
local SRC_ATTR_RX=' (src|href)="'"$MODBASE_RGX"'[^"]+"'
|
|
703
759
|
for SRC_FN in "${LIST[@]}"; do
|
|
704
760
|
SRC_FN="${SRC_FN#\./}"
|
|
705
761
|
readarray -t LIST < <(<"$SRC_FN" tr -s '\r\n\t ' ' ' \
|
|
706
|
-
| grep -oPe '<script\b[^<>]+>' | grep -oPe "$SRC_ATTR_RX" \
|
|
762
|
+
| grep -oPe '<(script|link)\b[^<>]+>' | grep -oPe "$SRC_ATTR_RX" \
|
|
707
763
|
| cut -d "$Q" -sf 2 | sed -re "s~^$MODBASE_RGX~~
|
|
708
764
|
" | remove_paths_from_module_ids)
|
|
709
765
|
for DEP in "${LIST[@]}"; do
|
|
@@ -738,7 +794,6 @@ function safe_pkg_names () {
|
|
|
738
794
|
return $?
|
|
739
795
|
fi
|
|
740
796
|
local LN= PKG= ORG=
|
|
741
|
-
local ID_RGX='^[a-z][a-z0-9_.-]*$'
|
|
742
797
|
local RV=3
|
|
743
798
|
while read -r LN; do
|
|
744
799
|
PKG="$LN"
|
|
@@ -751,8 +806,8 @@ function safe_pkg_names () {
|
|
|
751
806
|
ORG="${ORG#\@}"
|
|
752
807
|
;;
|
|
753
808
|
esac
|
|
754
|
-
[[ "$PKG" =~ $
|
|
755
|
-
[ -z "$ORG" ] || [[ "$ORG" =~ $
|
|
809
|
+
[[ "$PKG" =~ ^$SAFE_PLAIN_MODULE_ID_RGX$ ]] || continue
|
|
810
|
+
[ -z "$ORG" ] || [[ "$ORG" =~ ^$SAFE_PLAIN_MODULE_ID_RGX$ ]] || continue
|
|
756
811
|
echo "$LN"
|
|
757
812
|
RV=0
|
|
758
813
|
done
|
|
@@ -828,6 +883,8 @@ function guess_one_dep_type () {
|
|
|
828
883
|
# as well as any subdir.
|
|
829
884
|
|
|
830
885
|
*[.-]test.%JS | \
|
|
886
|
+
*/.babelrc | \
|
|
887
|
+
*/test/* | \
|
|
831
888
|
*/webpack.config.%JS | \
|
|
832
889
|
. ) DEP_TYPE=devDep;;
|
|
833
890
|
esac
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{ "name": "guess-js-deps-bash",
|
|
2
|
-
"version": "0.1.
|
|
2
|
+
"version": "0.1.70",
|
|
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": [
|
|
@@ -32,9 +32,9 @@
|
|
|
32
32
|
|
|
33
33
|
"dependencies": {},
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"eslint-config-nodejs-pmb": "^0.3.
|
|
35
|
+
"eslint-config-nodejs-pmb": "^0.3.6",
|
|
36
36
|
"eslint-plugin-json-light-pmb": "^1.0.7",
|
|
37
|
-
"eslint-plugin-n": "^
|
|
37
|
+
"eslint-plugin-n": "^17.10.2",
|
|
38
38
|
"eslint-pretty-pmb": "^1.0.5"
|
|
39
39
|
},
|
|
40
40
|
|