update: 动态替换core中的wcc,wcsc return表达式

使用正则匹配,最大化兼容可能发生的函数名变更
This commit is contained in:
msojocs 2022-04-26 11:14:44 +08:00
parent 8c02f7a13c
commit 069f18556d
2 changed files with 27 additions and 3 deletions

17
test/compiler-replace-test Executable file
View File

@ -0,0 +1,17 @@
#!/bin/bash
# 此脚本用于使修改 core.wxvpkg 内的代码及时生效
set -e
root_dir=$(cd `dirname $0`/.. && pwd -P)
find_result="$root_dir/package.nw/core.wxvpkg.ext/19c6ae7eff08f795d1f2124f7b0248ad.js"
return_exp_wcc=$(cat $find_result | grep -P 'return [a-z]+\("wcc"\)' -o) # return ?("wcc")
echo "return exp: $return_exp_wcc"
return_exp_wcc_replace="${return_exp_wcc//wcc/wcc.bin}" # return ?("wcc.bin")
echo "replace exp1: $return_exp_wcc_replace"
return_exp_wcc_replace="${return_exp_wcc//return /${return_exp_wcc_replace},}" # return ?("wcc.bin")
echo "replace exp2: $return_exp_wcc_replace"
return_exp_wcsc=$(cat $find_result | grep -P 'return [a-z]+\("wcsc"\)' -o) # return ?("wcc")
return_exp_wcsc_replace="${return_exp_wcc_replace//wcc/wcsc}"
sed -i "s#$return_exp_wcc#$return_exp_wcc_replace#g" "$find_result"
sed -i "s#$return_exp_wcsc#$return_exp_wcsc_replace#g" "$find_result"

View File

@ -52,9 +52,16 @@ if [[ $NO_WINE == 'true' ]];then
sed -i "s#{wcc:!0,wcsc:!0}#$new_str#g" "$find_result"
new_str='"linux"===process.platform'
sed -i "s#\"darwin\"===process.platform#$new_str#g" "$find_result"
# TODO: 看能不能动态识别函数名j,因为不同版本会发生变化
sed -i 's#return j("wcc")#return j("wcc.bin"),j("wcc")#g' "$find_result"
sed -i 's#return j("wcsc")#return j("wcsc.bin"),j("wcsc")#g' "$find_result"
return_exp_wcc=$(cat $find_result | grep -P 'return [a-z]+\("wcc"\)' -o) # return ?("wcc")
return_exp_wcc_replace="${return_exp_wcc//wcc/wcc.bin}" # return ?("wcc.bin")
return_exp_wcc_replace="${return_exp_wcc//return /${return_exp_wcc_replace},}" # return ?("wcc.bin")
return_exp_wcsc=$(cat $find_result | grep -P 'return [a-z]+\("wcsc"\)' -o) # return ?("wcsc")
return_exp_wcsc_replace="${return_exp_wcc_replace//wcc/wcsc}"
sed -i "s#$return_exp_wcc#$return_exp_wcc_replace#g" "$find_result"
sed -i "s#$return_exp_wcsc#$return_exp_wcsc_replace#g" "$find_result"
fi
# 处理报错时控制台显示的环境
find_result=$( grep -lr '(env:' "$tmp_dir/core.wxvpkg" )