From 3462835bf9060721a50e04cfeada601bb97cd0dc Mon Sep 17 00:00:00 2001 From: fengmk2 Date: Fri, 13 Jan 2023 19:37:46 +0800 Subject: [PATCH] fix: require tscompiler on current process (#207) let current command process can require ts files --- lib/command.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib/command.js b/lib/command.js index 2ad49363..a4fb9f2a 100644 --- a/lib/command.js +++ b/lib/command.js @@ -111,8 +111,23 @@ class Command extends BaseCommand { if (argv.typescript) { execArgvObj.require.push(argv.tscompiler); + // should require argv.tscompiler on current process, let it can require *.ts files + // e.g.: dev command will execute egg loader to find configs and plugins + require(argv.tscompiler); + // let child process auto require ts-node too + const requireOptions = `--require ${argv.tscompiler}`; + if (process.env.NODE_OPTIONS) { + if (!process.env.NODE_OPTIONS.includes(requireOptions)) { + process.env.NODE_OPTIONS = `${process.env.NODE_OPTIONS} ${requireOptions}`; + } + } else { + process.env.NODE_OPTIONS = requireOptions; + } // tell egg loader to load ts file + // see https://github.com/eggjs/egg-core/blob/master/lib/loader/egg_loader.js#L443 env.EGG_TYPESCRIPT = 'true'; + // set current process.env.EGG_TYPESCRIPT too + process.env.EGG_TYPESCRIPT = 'true'; // load files from tsconfig on startup env.TS_NODE_FILES = process.env.TS_NODE_FILES || 'true';