Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: upgrade espower-typescript to 9.0 #106

Merged
merged 4 commits into from
Aug 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions lib/cmd/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,19 @@ class TestCommand extends Command {
yield this.helper.forkNode(mochaFile, testArgs, opt);
}

get context() {
const context = super.context;
const { argv, execArgvObj } = context;

// remove ts-node, ts-node and espower-typescript can't coexist
// because espower-typescript@9 has already register ts-node
if (argv.typescript) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

判断下 espower-typescript?万一哪天 espower-typescript 被删了还是能保留 ts-node

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

在 context 的 getter 里拿不到 testArgv ,好像不好做判断,我觉得如果万一哪天 espower-typescript 被删了,单测也会挂,应该问题不大吧?

execArgvObj.require.splice(execArgvObj.require.indexOf(require.resolve('ts-node/register')), 1);
}

return context;
}

/**
* format test args then change it to array style
* @param {Object} context - { cwd, argv, ...}
Expand Down Expand Up @@ -90,6 +103,7 @@ class TestCommand extends Command {

// for power-assert
if (testArgv.typescript) {
// remove ts-node in context getter on top.
requireArr.push(require.resolve('espower-typescript/guess'));
}

Expand Down
12 changes: 10 additions & 2 deletions lib/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,16 @@ class Command extends BaseCommand {
// execArgv
if (argv.typescript) {
execArgvObj.require = execArgvObj.require || [];
execArgvObj.require.push(path.join(__dirname, './ts-helper.js'));
env.EGG_TYPESCRIPT = true;
execArgvObj.require.push(require.resolve('ts-node/register'));

// tell egg loader to load ts file
env.EGG_TYPESCRIPT = 'true';

// use type check
env.TS_NODE_TYPE_CHECK = process.env.TS_NODE_TYPE_CHECK || 'true';

// load files from tsconfig on startup
env.TS_NODE_FILES = process.env.TS_NODE_FILES || 'true';
}

return context;
Expand Down
6 changes: 0 additions & 6 deletions lib/ts-helper.js

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"debug": "^3.1.0",
"detect-port": "^1.2.3",
"egg-utils": "^2.4.0",
"espower-typescript": "^8.0.0",
"espower-typescript": "^9.0.0",
"globby": "^8.0.1",
"inspector-proxy": "^1.2.1",
"intelli-espower-loader": "^1.0.1",
Expand Down