修复 node 前置逻辑

This commit is contained in:
whyour 2024-07-24 23:30:18 +08:00
parent 2ad6437672
commit eddd258614
3 changed files with 15 additions and 6 deletions

View File

@ -216,8 +216,13 @@ check_file() {
if [[ -f $file_env ]]; then if [[ -f $file_env ]]; then
get_env_array get_env_array
if [[ $isJsOrPythonFile == 'true' ]]; then if [[ $isJsOrPythonFile == 'true' ]]; then
export NODE_OPTIONS="${NODE_OPTIONS} -r ${file_preload_js}" PREV_NODE_OPTIONS="${NODE_OPTIONS}"
export PYTHONPATH="${PYTHONPATH}:${dir_preload}:${dir_config}" PREV_PYTHONPATH="${PYTHONPATH}"
if [[ $1 == *.js ]] || [[ $1 == *.ts ]]; then
export NODE_OPTIONS="${NODE_OPTIONS} -r ${file_preload_js}"
else
export PYTHONPATH="${PYTHONPATH}:${dir_preload}:${dir_config}"
fi
else else
. $file_env . $file_env
fi fi
@ -265,6 +270,10 @@ if [[ $isJsOrPythonFile == 'false' ]]; then
run_task_before "${task_shell_params[@]}" run_task_before "${task_shell_params[@]}"
fi fi
main "${task_shell_params[@]}" main "${task_shell_params[@]}"
if [[ $isJsOrPythonFile == 'true' ]]; then
export NODE_OPTIONS="${PREV_NODE_OPTIONS}"
export PYTHONPATH="${PREV_PYTHONPATH}"
fi
run_task_after "${task_shell_params[@]}" run_task_after "${task_shell_params[@]}"
clear_env clear_env
handle_task_end "${task_shell_params[@]}" handle_task_end "${task_shell_params[@]}"

View File

@ -41,10 +41,10 @@ function run() {
const fileName = process.argv[1].replace(`${dir_scripts}/`, ''); const fileName = process.argv[1].replace(`${dir_scripts}/`, '');
let command = `bash -c "source ${file_task_before} ${fileName}`; let command = `bash -c "source ${file_task_before} ${fileName}`;
if (task_before) { if (task_before) {
command = `${command} && echo -e '执行前置命令\n' && eval "${task_before}" && echo -e '\n执行前置命令结束\n'`; command = `${command} && echo -e '执行前置命令\n' && eval '${task_before}' && echo -e '\n执行前置命令结束\n'`;
} }
const res = execSync( const res = execSync(
`${command} && echo "${splitStr}" && NODE_OPTIONS= node -p 'JSON.stringify(process.env)'"`, `${command} && echo -e '${splitStr}' && NODE_OPTIONS= node -p 'JSON.stringify(process.env)'"`,
{ {
encoding: 'utf-8', encoding: 'utf-8',
}, },

View File

@ -54,10 +54,10 @@ def run():
task_before = os.getenv("task_before") task_before = os.getenv("task_before")
if task_before: if task_before:
command += f" && echo -e '执行前置命令\n' && eval \"{task_before}\" && echo -e '\n执行前置命令结束\n'" command += f" && echo -e '执行前置命令\n' && eval '{task_before}' && echo -e '\n执行前置命令结束\n'"
python_command = "PYTHONPATH= python3 -c 'import os, json; print(json.dumps(dict(os.environ)))'" python_command = "PYTHONPATH= python3 -c 'import os, json; print(json.dumps(dict(os.environ)))'"
command += f' && echo "{split_str}" && {python_command}"' command += f" && echo -e '{split_str}' && {python_command}\""
res = subprocess.check_output(command, shell=True, encoding="utf-8") res = subprocess.check_output(command, shell=True, encoding="utf-8")
output, env_str = res.split(split_str) output, env_str = res.split(split_str)