Skip to content

Commit

Permalink
fix: egginfo is not exists (#159)
Browse files Browse the repository at this point in the history
* fix: egginfo is null

* fix: ci

* fix: ci

* fix: ci

* feat: optimize code
  • Loading branch information
whxaxes authored Apr 25, 2021
1 parent a6d5b02 commit 8666e9e
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 7 deletions.
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';
}

// 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

0 comments on commit 8666e9e

Please sign in to comment.