Skip to content

Commit

Permalink
fix: remove options.typescript support (#73)
Browse files Browse the repository at this point in the history
  • Loading branch information
atian25 authored Apr 21, 2018
1 parent 4e94845 commit 939c202
Show file tree
Hide file tree
Showing 17 changed files with 15 additions and 103 deletions.
6 changes: 0 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 0 additions & 6 deletions README.zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -275,12 +275,6 @@ mm.app({

如果是通过 ava 等并行测试框架进行测试,需要手动在执行测试前进行统一的日志清理,不能通过 mm 来处理,设置 `clean``false`

#### typescript {Boolean}

开启 TypeScript 支持,默认关闭。

支持读取环境变量 `process.env.EGG_TYPESCRIPT`

### app.httpRequest()

请求当前应用 http 服务的辅助工具。
Expand Down
5 changes: 0 additions & 5 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,6 @@ export interface MockOption {
* Remove $baseDir/logs
*/
clean?: boolean;

/**
* Enable typescript support
*/
typescript?: boolean;
}

type EnvType = 'default' | 'test' | 'prod' | 'local' | 'unittest';
Expand Down
1 change: 0 additions & 1 deletion lib/cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 0 additions & 17 deletions lib/format_options.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';

const fs = require('fs');
const path = require('path');
const mm = require('mm');
const debug = require('debug')('mm');
Expand Down Expand Up @@ -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
Expand Down
10 changes: 3 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/apps/foo/app/router.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

module.exports = function(app) {
app.get('/', function*() {
app.get('/', function* () {
this.body = {
fooPlugin: app.fooPlugin,
};
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/demo-async/app.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';

module.exports = function(app) {

};
2 changes: 1 addition & 1 deletion test/fixtures/demo/app.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';

module.exports = function(app) {

};
6 changes: 3 additions & 3 deletions test/fixtures/demo/app/context.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = {
getResult: function (result) {
getResult(result) {
return {
body: result
body: result,
};
}
},
};
2 changes: 1 addition & 1 deletion test/fixtures/demo/app/service/old.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

module.exports = () => {
exports.test = function*() {
exports.test = function* () {
return 'hello';
};

Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/disable-security/app.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';

module.exports = function(app) {

};
6 changes: 3 additions & 3 deletions test/fixtures/disable-security/app/context.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = {
getResult: function (result) {
getResult(result) {
return {
body: result
body: result,
};
}
},
};
2 changes: 1 addition & 1 deletion test/fixtures/disable-security/app/service/old.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

module.exports = () => {
exports.test = function*() {
exports.test = function* () {
return 'hello';
};

Expand Down
6 changes: 0 additions & 6 deletions test/fixtures/ts-false/package.json

This file was deleted.

6 changes: 0 additions & 6 deletions test/fixtures/ts/package.json

This file was deleted.

37 changes: 0 additions & 37 deletions test/format_options.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
});

0 comments on commit 939c202

Please sign in to comment.