diff --git a/package.json b/package.json index d44ab4c..d5b8911 100644 --- a/package.json +++ b/package.json @@ -14,11 +14,12 @@ "scripts": { "build": "tsc -d", "build:w": "tsc -d -w", - "release": "del ./dist && npm run build", + "release": "del dist && npm run build", "lint": "tslint ./src/**/*.ts ./test/**/*.test.ts", "check": "npm run build && npm run lint", "test": "npm run check && npm run test-local", "test-local": "egg-bin test --ts", + "prepublish": "npm run release", "cov": "npm run check && egg-bin cov --ts" }, "keywords": [ diff --git a/src/register.ts b/src/register.ts index 42a68c6..6d672b8 100644 --- a/src/register.ts +++ b/src/register.ts @@ -22,10 +22,17 @@ function register(watch: boolean) { // write jsconfig if the project is wrote by js util.writeJsConfig(cwd); } else { + const tsNodeMode = util.deepGet(util.getPkgInfo(cwd), 'egg.typescript') || + process.argv.includes('--ts') || + process.argv.includes('--typescript') || + process.env.EGG_TYPESCRIPT === 'true'; + // no need to clean in js project // clean local js file at first. // because egg-loader cannot load the same property name to egg. - util.cleanJs(cwd); + if (tsNodeMode) { + util.cleanJs(cwd); + } } if (watch) { diff --git a/src/utils.ts b/src/utils.ts index 0dd5eb2..a9b9069 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -269,9 +269,7 @@ export function cleanJs(cwd: string) { .sync([ '**/*.ts', '**/*.tsx', '!**/*.d.ts', '!**/node_modules' ], { cwd }) .forEach(f => { const jf = removeSameNameJs(path.resolve(cwd, f)); - if (jf) { - fileList.push(jf); - } + if (jf) fileList.push(path.relative(cwd, jf)); }); if (fileList.length) {