From 939c202db5b938e17ed3e9efc003d5ba9f0d0e3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?TZ=20=7C=20=E5=A4=A9=E7=8C=AA?= Date: Sat, 21 Apr 2018 10:50:10 +0800 Subject: [PATCH] fix: remove options.typescript support (#73) --- README.md | 6 --- README.zh_CN.md | 6 --- index.d.ts | 5 --- lib/cluster.js | 1 - lib/format_options.js | 17 --------- package.json | 10 ++--- test/fixtures/apps/foo/app/router.js | 2 +- test/fixtures/demo-async/app.js | 2 +- test/fixtures/demo/app.js | 2 +- test/fixtures/demo/app/context.js | 6 +-- test/fixtures/demo/app/service/old.js | 2 +- test/fixtures/disable-security/app.js | 2 +- test/fixtures/disable-security/app/context.js | 6 +-- .../disable-security/app/service/old.js | 2 +- test/fixtures/ts-false/package.json | 6 --- test/fixtures/ts/package.json | 6 --- test/format_options.test.js | 37 ------------------- 17 files changed, 15 insertions(+), 103 deletions(-) delete mode 100644 test/fixtures/ts-false/package.json delete mode 100644 test/fixtures/ts/package.json diff --git a/README.md b/README.md index 364e0b7..c96deff 100644 --- a/README.md +++ b/README.md @@ -265,12 +265,6 @@ Clean all logs directory, default is true. If you are using `ava`, disable it. -#### typescript {Boolean} - -Enable Typescript support, default is false. - -Support read from `process.env.EGG_TYPESCRIPT`. - ### app.httpRequest() Request current app http server. diff --git a/README.zh_CN.md b/README.zh_CN.md index 596ded2..1d96d35 100644 --- a/README.zh_CN.md +++ b/README.zh_CN.md @@ -275,12 +275,6 @@ mm.app({ 如果是通过 ava 等并行测试框架进行测试,需要手动在执行测试前进行统一的日志清理,不能通过 mm 来处理,设置 `clean` 为 `false`。 -#### typescript {Boolean} - -开启 TypeScript 支持,默认关闭。 - -支持读取环境变量 `process.env.EGG_TYPESCRIPT`。 - ### app.httpRequest() 请求当前应用 http 服务的辅助工具。 diff --git a/index.d.ts b/index.d.ts index de2d443..21f5a24 100644 --- a/index.d.ts +++ b/index.d.ts @@ -82,11 +82,6 @@ export interface MockOption { * Remove $baseDir/logs */ clean?: boolean; - - /** - * Enable typescript support - */ - typescript?: boolean; } type EnvType = 'default' | 'test' | 'prod' | 'local' | 'unittest'; diff --git a/lib/cluster.js b/lib/cluster.js index 594b089..acf8b9c 100644 --- a/lib/cluster.js +++ b/lib/cluster.js @@ -51,7 +51,6 @@ class ClusterApplication extends Coffee { * - {String} baseDir - The directory of the application * - {Object} plugins - Tustom you plugins * - {String} framework - The directory of the egg framework - * - {Boolean} [typescript] - Enable TypeScript support * - {Boolean} [cache=true] - Cache application based on baseDir * - {Boolean} [coverage=true] - Swtich on process coverage, but it'll be slower * - {Boolean} [clean=true] - Remove $baseDir/logs diff --git a/lib/format_options.js b/lib/format_options.js index 684889a..5ee50f4 100644 --- a/lib/format_options.js +++ b/lib/format_options.js @@ -1,6 +1,5 @@ 'use strict'; -const fs = require('fs'); const path = require('path'); const mm = require('mm'); const debug = require('debug')('mm'); @@ -40,22 +39,6 @@ module.exports = function formatOptions(options) { } options.customEgg = options.framework = framework; - // typescript - if (!('typescript' in options)) { - // process.env maybe force to string type - if (String(process.env.EGG_TYPESCRIPT).toLowerCase() === 'true') { - options.typescript = true; - } else { - const pkgFile = path.join(options.baseDir, 'package.json'); - if (fs.existsSync(pkgFile)) { - const pkgInfo = require(pkgFile); - if (pkgInfo && pkgInfo.egg && pkgInfo.egg.typescript === true) { - options.typescript = true; - } - } - } - } - const plugins = options.plugins = options.plugins || {}; // add self as a plugin diff --git a/package.json b/package.json index 2d133be..7964568 100644 --- a/package.json +++ b/package.json @@ -16,13 +16,11 @@ ], "scripts": { "lint": "eslint lib app index.js test/*.test.js", - "test": "npm run lint && npm run test-local && npm run test-ts", - "test-ts": "ts-node test/index.test.ts", + "test": "npm run lint && npm run test-local", "test-local": "egg-bin test", "cov": "egg-bin cov", - "ci": "npm run autod --check && npm run lint && npm run cov && npm run test-ts", + "ci": "npm run autod --check && npm run lint && npm run cov", "autod": "autod", - "autod-china": "autod --registry=https://registry.npm.taobao.org", "contributors": "ali-contributors" }, "dependencies": { @@ -57,9 +55,7 @@ "mkdirp": "^0.5.1", "mz-modules": "^1.0.0", "pedding": "^1.1.0", - "sdk-base": "^3.0.1", - "ts-node": "^3.0.4", - "typescript": "^2.3.2" + "sdk-base": "^3.0.1" }, "ci": { "version": "6, 8, 9" diff --git a/test/fixtures/apps/foo/app/router.js b/test/fixtures/apps/foo/app/router.js index e646375..a572940 100644 --- a/test/fixtures/apps/foo/app/router.js +++ b/test/fixtures/apps/foo/app/router.js @@ -1,7 +1,7 @@ 'use strict'; module.exports = function(app) { - app.get('/', function*() { + app.get('/', function* () { this.body = { fooPlugin: app.fooPlugin, }; diff --git a/test/fixtures/demo-async/app.js b/test/fixtures/demo-async/app.js index 76f957d..4d31371 100644 --- a/test/fixtures/demo-async/app.js +++ b/test/fixtures/demo-async/app.js @@ -1,5 +1,5 @@ 'use strict'; module.exports = function(app) { - + }; diff --git a/test/fixtures/demo/app.js b/test/fixtures/demo/app.js index 76f957d..4d31371 100644 --- a/test/fixtures/demo/app.js +++ b/test/fixtures/demo/app.js @@ -1,5 +1,5 @@ 'use strict'; module.exports = function(app) { - + }; diff --git a/test/fixtures/demo/app/context.js b/test/fixtures/demo/app/context.js index 595097f..dd59eb2 100644 --- a/test/fixtures/demo/app/context.js +++ b/test/fixtures/demo/app/context.js @@ -1,7 +1,7 @@ module.exports = { - getResult: function (result) { + getResult(result) { return { - body: result + body: result, }; - } + }, }; diff --git a/test/fixtures/demo/app/service/old.js b/test/fixtures/demo/app/service/old.js index 9e7f82f..29ea81e 100644 --- a/test/fixtures/demo/app/service/old.js +++ b/test/fixtures/demo/app/service/old.js @@ -1,7 +1,7 @@ 'use strict'; module.exports = () => { - exports.test = function*() { + exports.test = function* () { return 'hello'; }; diff --git a/test/fixtures/disable-security/app.js b/test/fixtures/disable-security/app.js index 76f957d..4d31371 100644 --- a/test/fixtures/disable-security/app.js +++ b/test/fixtures/disable-security/app.js @@ -1,5 +1,5 @@ 'use strict'; module.exports = function(app) { - + }; diff --git a/test/fixtures/disable-security/app/context.js b/test/fixtures/disable-security/app/context.js index 595097f..dd59eb2 100644 --- a/test/fixtures/disable-security/app/context.js +++ b/test/fixtures/disable-security/app/context.js @@ -1,7 +1,7 @@ module.exports = { - getResult: function (result) { + getResult(result) { return { - body: result + body: result, }; - } + }, }; diff --git a/test/fixtures/disable-security/app/service/old.js b/test/fixtures/disable-security/app/service/old.js index 9e7f82f..29ea81e 100644 --- a/test/fixtures/disable-security/app/service/old.js +++ b/test/fixtures/disable-security/app/service/old.js @@ -1,7 +1,7 @@ 'use strict'; module.exports = () => { - exports.test = function*() { + exports.test = function* () { return 'hello'; }; diff --git a/test/fixtures/ts-false/package.json b/test/fixtures/ts-false/package.json deleted file mode 100644 index 1aa314a..0000000 --- a/test/fixtures/ts-false/package.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "name": "ts-false", - "egg": { - "typescript": false - } -} \ No newline at end of file diff --git a/test/fixtures/ts/package.json b/test/fixtures/ts/package.json deleted file mode 100644 index 8c2c0c2..0000000 --- a/test/fixtures/ts/package.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "name": "ts", - "egg": { - "typescript": true - } -} \ No newline at end of file diff --git a/test/format_options.test.js b/test/format_options.test.js index 381d8d6..04a9e59 100644 --- a/test/format_options.test.js +++ b/test/format_options.test.js @@ -152,41 +152,4 @@ describe('test/format_options.test.js', () => { formatOptions(); assert.notEqual(process.env.HOME, baseDir); }); - - describe('typescript', () => { - it('should read egg.typescript', () => { - const baseDir = path.join(__dirname, 'fixtures/ts'); - mm(process, 'cwd', () => baseDir); - const opts = formatOptions(); - assert(opts.typescript === true); - }); - - it('should read process.env.EGG_TYPESCRIPT', () => { - const baseDir = path.join(__dirname, 'fixtures/demo'); - mm(process, 'cwd', () => baseDir); - - mm(process.env, 'EGG_TYPESCRIPT', true); - assert(formatOptions().typescript === true); - - mm(process.env, 'EGG_TYPESCRIPT', false); - assert(!formatOptions().typescript); - - mm(process.env, 'EGG_TYPESCRIPT', 'true'); - assert(formatOptions().typescript === true); - - mm(process.env, 'EGG_TYPESCRIPT', 'false'); - assert(!formatOptions().typescript); - - mm(process.env, 'EGG_TYPESCRIPT', undefined); - assert(!formatOptions().typescript); - }); - - it('should read process.env.EGG_TYPESCRIPT with pkg', () => { - const baseDir = path.join(__dirname, 'fixtures/ts-false'); - mm(process, 'cwd', () => baseDir); - mm(process.env, 'EGG_TYPESCRIPT', true); - const opts = formatOptions(); - assert(opts.typescript === true); - }); - }); });