Skip to content

Commit

Permalink
fix: should clean file more intelligent (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
whxaxes authored Mar 20, 2019
1 parent c4a0e45 commit c886d80
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
9 changes: 8 additions & 1 deletion src/register.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 1 addition & 3 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit c886d80

Please sign in to comment.