Skip to content

Commit

Permalink
fix: require tscompiler on current process (#207)
Browse files Browse the repository at this point in the history
let current command process can require ts files
  • Loading branch information
fengmk2 authored Jan 13, 2023
1 parent fff6c67 commit 3462835
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lib/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down

0 comments on commit 3462835

Please sign in to comment.