forked from oraoto/pib
-
-
Notifications
You must be signed in to change notification settings - Fork 44
/
remap-sourcemap.sh
executable file
·58 lines (45 loc) · 1.66 KB
/
remap-sourcemap.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env bash
set -x;
# SOURCE_MAP=packages/php-wasm/php-node.mjs.wasm.map
# SOURCE_MAP=packages/php-cgi-wasm/php-cgi-worker.mjs.wasm.map
# SOURCE_MAP=packages/php-wasm/php-web.mjs.wasm.map
SOURCE_MAP=${1}
SOURCE_MAP_DIR=`dirname ${SOURCE_MAP}`
MAPPED=${SOURCE_MAP_DIR}/mapped;
BACKUP=${SOURCE_MAP}.BAK
PHP_VERSION=8.4
if [ -e ${BACKUP} ]; then {
rm ${BACKUP};
} fi;
cp ${SOURCE_MAP} ${BACKUP}
mkdir -p ${MAPPED}
jq -r '.sources[] | select( match("^\\.\\./\\.\\./(?!\\.\\.)")) | sub("../../"; "")' < ${SOURCE_MAP} \
| while read SOURCE_FILE; do {
DIRNAME=`dirname ${SOURCE_FILE}`;
BASENAME=`basename ${SOURCE_FILE}`;
DEST_DIR=${MAPPED}/php${PHP_VERSION}/${DIRNAME}/;
mkdir -p ${DEST_DIR};
cp third_party/php${PHP_VERSION}-src/${SOURCE_FILE} ${DEST_DIR}${BASENAME};
}; done;
jq -r '.sources[] | select( match("^\\.\\./\\.\\./\\.\\./\\.\\./\\.\\./")) | sub("../../../../../"; "/")' < ${SOURCE_MAP} \
| while read SOURCE_FILE; do {
DIRNAME=`dirname ${SOURCE_FILE}`;
BASENAME=`basename ${SOURCE_FILE}`;
DEST_DIR=${MAPPED}/${DIRNAME}/;
mkdir -p ${DEST_DIR};
cp ${SOURCE_FILE} ${DEST_DIR}${BASENAME};
}; done;
jq -r '.sources[] | select( match("^(?:.+)")) | sub("../../"; "")' < ${SOURCE_MAP} \
| while read SOURCE_FILE; do {
if [[ ${SOURCE_FILE} == ../../* ]]; then
continue;
fi;
DIRNAME=`dirname ${SOURCE_FILE}`;
BASENAME=`basename ${SOURCE_FILE}`;
DEST_DIR=${MAPPED}/php${PHP_VERSION}/${DIRNAME}/;
mkdir -p ${DEST_DIR};
cp third_party/php${PHP_VERSION}-src/${SOURCE_FILE} ${DEST_DIR}${BASENAME};
}; done;
sed -i 's|\.\./\.\./\.\./\.\./\.\./|mapped/|g' ${SOURCE_MAP}
sed -i 's|\.\./\.\./|mapped/php'"${PHP_VERSION}"'/|g' ${SOURCE_MAP}
chown -R ${OUTER_UID} ${MAPPED}