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: support set eggTsHelper #183

Merged
merged 5 commits into from Jul 15, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -17,6 +17,7 @@ test/fixtures/ts/node_modules/aliyun-egg/
test/fixtures/example-ts-ets/typings/
!test/fixtures/example-ts-ets/node_modules/
!test/fixtures/example-ts-simple/node_modules/
!test/fixtures/test-files/node_modules/

**/run/*.json
.tmp
Expand Down
18 changes: 16 additions & 2 deletions lib/command.js
Expand Up @@ -23,7 +23,7 @@ class Command extends BaseCommand {
},

declarations: {
description: 'whether create dts, will load `egg-ts-helper/register`',
description: 'whether create dts, will load options.eggTsHelper',
type: 'boolean',
alias: 'dts',
default: undefined,
Expand All @@ -35,6 +35,13 @@ class Command extends BaseCommand {
alias: 'tsc',
default: undefined,
},

eggTsHelper: {
description: 'egg-ts-helper register, default use `egg-ts-helper/register`',
type: 'string',
alias: 'ets',
default: undefined,
},
};
}

Expand Down Expand Up @@ -105,9 +112,16 @@ class Command extends BaseCommand {
env.TS_NODE_FILES = process.env.TS_NODE_FILES || 'true';
}

// read egg-ts-helper
if (argv.eggTsHelper === undefined) {
argv.eggTsHelper = require.resolve('egg-ts-helper/register');
} else {
argv.eggTsHelper = require.resolve(argv.eggTsHelper, { paths: [ cwd ] });
}

// load egg-ts-helper
if (argv.declarations) {
execArgvObj.require.push(require.resolve('egg-ts-helper/register'));
execArgvObj.require.push(argv.eggTsHelper);
}

return context;
Expand Down
13 changes: 13 additions & 0 deletions test/fixtures/my-egg-bin/lib/cmd/echo.js
Expand Up @@ -3,6 +3,19 @@
const Command = require('../../../../../');

class EchoCommand extends Command {
constructor(rawArgv) {
super(rawArgv);

this.options = {
eggTsHelper: {
description: 'egg-ts-helper register, default use `egg-ts-helper/register`',
type: 'string',
alias: 'ets',
default: 'custom-egg-ts-helper/register',
},
};
}

get description() {
return 'echo test';
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 15 additions & 1 deletion test/my-egg-bin.test.js
Expand Up @@ -65,7 +65,7 @@ describe('test/my-egg-bin.test.js', () => {
'--es_staging', '--harmony', '--harmony_default_parameters',
];
coffee.fork(eggBin, args, { cwd })
// .debug()
.debug()
.expect('stdout', /"baseDir":".\/dist"/)
.expect('stdout', /debugPort: 6666/)
.notExpect('stdout', /"argv: {.*debugBrk":true/)
Expand Down Expand Up @@ -99,4 +99,18 @@ describe('test/my-egg-bin.test.js', () => {
.expect('code', 1)
.end(done);
});

it('should custom eggTsHelper success', done => {
const args = [
'echo',
'--typescript',
'--declarations',
];
coffee.fork(eggBin, args, { cwd })
// .debug()
.expect('stdout', /custom-egg-ts-helper/)
.expect('stdout', /register\.js/)
.expect('code', 0)
.end(done);
});
});