diff --git a/.gitignore b/.gitignore index dc9d2e32..447db337 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/lib/command.js b/lib/command.js index 9f78ae71..e166a022 100644 --- a/lib/command.js +++ b/lib/command.js @@ -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); } diff --git a/test/fixtures/example-ts-simple/config/config.default.ts b/test/fixtures/example-ts-simple/config/config.default.ts new file mode 100644 index 00000000..feefe62a --- /dev/null +++ b/test/fixtures/example-ts-simple/config/config.default.ts @@ -0,0 +1,3 @@ +'use strict'; + +export const key = '12345'; diff --git a/test/fixtures/example-ts-simple/node_modules/egg/index.js b/test/fixtures/example-ts-simple/node_modules/egg/index.js new file mode 100644 index 00000000..9995e5bd --- /dev/null +++ b/test/fixtures/example-ts-simple/node_modules/egg/index.js @@ -0,0 +1,8 @@ +'use strict'; + +module.exports = require('../../../../../node_modules/egg'); + +setTimeout(() => { + console.log('exit by master test end'); + process.exit(0); +}, 6000); diff --git a/test/fixtures/example-ts-simple/node_modules/egg/package.json b/test/fixtures/example-ts-simple/node_modules/egg/package.json new file mode 100644 index 00000000..6697ad3f --- /dev/null +++ b/test/fixtures/example-ts-simple/node_modules/egg/package.json @@ -0,0 +1,3 @@ +{ + "name": "egg" +} diff --git a/test/fixtures/example-ts-simple/package.json b/test/fixtures/example-ts-simple/package.json new file mode 100644 index 00000000..8389bd69 --- /dev/null +++ b/test/fixtures/example-ts-simple/package.json @@ -0,0 +1,3 @@ +{ + "name": "example" +} \ No newline at end of file diff --git a/test/ts.test.js b/test/ts.test.js index 4a9f3067..5469a812 100644 --- a/test/ts.test.js +++ b/test/ts.test.js @@ -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'),