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

fix: egginfo is not exists #159

Merged
merged 5 commits into from
Apr 25, 2021
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ test/fixtures/ts/node_modules/aliyun-egg/
!test/fixtures/egg-require/node_modules/
test/fixtures/example-ts-ets/typings/
!test/fixtures/example-ts-ets/node_modules/
!test/fixtures/example-ts-simple/node_modules/


**/run/*.json
Expand Down
14 changes: 7 additions & 7 deletions lib/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,26 +62,26 @@ class Command extends BaseCommand {
if (!path.isAbsolute(baseDir)) baseDir = path.join(cwd, baseDir);
const pkgFile = path.join(baseDir, 'package.json');
const pkgInfo = fs.existsSync(pkgFile) ? require(pkgFile) : null;
const eggInfo = pkgInfo && pkgInfo.egg;
const eggInfo = (pkgInfo && pkgInfo.egg) || {};
execArgvObj.require = execArgvObj.require || [];

// read `egg.typescript` from package.json if not pass argv
if (argv.typescript === undefined && eggInfo) {
argv.typescript = eggInfo.typescript === true;
if (argv.typescript === undefined && typeof eggInfo.typescript === 'boolean') {
argv.typescript = eggInfo.typescript;
}

// read `egg.declarations` from package.json if not pass argv
if (argv.declarations === undefined && eggInfo) {
argv.declarations = eggInfo.declarations === true;
if (argv.declarations === undefined && typeof eggInfo.declarations === 'boolean') {
argv.declarations = eggInfo.declarations;
}

// read `egg.tscompiler` from package.json if not pass argv
if (argv.tscompiler === undefined && eggInfo) {
if (argv.tscompiler === undefined) {
argv.tscompiler = eggInfo.tscompiler || 'ts-node/register';
whxaxes marked this conversation as resolved.
Show resolved Hide resolved
}

// read `egg.require` from package.json
if (eggInfo && eggInfo.require && Array.isArray(eggInfo.require)) {
if (eggInfo.require && Array.isArray(eggInfo.require)) {
execArgvObj.require = execArgvObj.require.concat(eggInfo.require);
}

Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/example-ts-simple/config/config.default.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict';

export const key = '12345';
8 changes: 8 additions & 0 deletions test/fixtures/example-ts-simple/node_modules/egg/index.js

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

3 changes: 3 additions & 0 deletions test/fixtures/example-ts-simple/node_modules/egg/package.json

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

3 changes: 3 additions & 0 deletions test/fixtures/example-ts-simple/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "example"
}
15 changes: 15 additions & 0 deletions test/ts.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,21 @@ describe('test/ts.test.js', () => {
.end();
});

it('should start app with flags in app without eggInfo', async () => {
const cwd = path.join(__dirname, './fixtures/example-ts-simple');
await coffee.fork(eggBin, [ 'dev', '--ts' ], { cwd })
// .debug()
.expect('stdout', /started/)
.expect('code', 0)
.end();

await coffee.fork(eggBin, [ 'dev', '--ts', '--tsc=esbuild-register' ], { cwd })
// .debug()
.expect('stdout', /started/)
.expect('code', 0)
.end();
});

it('should start app with other tscompiler without error', () => {
return coffee.fork(eggBin, [ 'dev', '--ts', '--tscompiler=esbuild-register' ], {
cwd: path.join(__dirname, './fixtures/example-ts'),
Expand Down