Skip to content

Commit

Permalink
feat: auto register tsconfig-paths on env.EGG_TYPESCRIPT enable (#254)
Browse files Browse the repository at this point in the history
  • Loading branch information
fengmk2 committed Dec 19, 2022
1 parent 877b4f3 commit 6d75322
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import KoaApplication = require('koa');
import { Logger, EggConsoleLogger } from 'egg-logger';
import depd = require('depd');
import { Logger } from 'egg-logger';

type EggType = 'application' | 'agent';

Expand Down
4 changes: 4 additions & 0 deletions lib/egg.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ class EggCore extends KoaApplication {
*/
constructor(options = {}) {
options.baseDir = options.baseDir || process.cwd();
// auto require('tsconfig-paths/register') on typescript app
if (process.env.EGG_TYPESCRIPT === 'true') {
require('tsconfig-paths').register({ cwd: options.baseDir });
}
options.type = options.type || 'application';

assert(typeof options.baseDir === 'string', 'options.baseDir required, and must be a string');
Expand Down
1 change: 0 additions & 1 deletion lib/loader/egg_loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ const Timing = require('../utils/timing');

const REQUIRE_COUNT = Symbol('EggLoader#requireCount');


class EggLoader {

/**
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
"koa-convert": "^1.2.0",
"node-homedir": "^1.1.1",
"ready-callback": "^2.1.0",
"tsconfig-paths": "^4.1.1",
"utility": "^1.16.1"
}
}

0 comments on commit 6d75322

Please sign in to comment.