Skip to content

Commit

Permalink
feat: use @eggjs/tsconfig (#109)
Browse files Browse the repository at this point in the history
  • Loading branch information
fengmk2 authored Aug 31, 2023
1 parent 68642dc commit 5b0a976
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 38 deletions.
2 changes: 0 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
"windows": { "runtimeExecutable": "npm.cmd" },
"runtimeArgs": [ "run", "test-local", "--", "--inspect-brk=9229" ],
"console": "integratedTerminal",
"protocol": "auto",
"port": 9229,
"autoAttachChildProcesses": true
}
]
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@
},
"scripts": {
"clean": "tsc -b --clean",
"build": "tsc -d",
"build:w": "tsc -d -w",
"tsc": "tsc -d",
"tsc:w": "tsc -d -w",
"lint": "eslint . --ext .ts",
"check": "npm run build && npm run lint",
"check": "npm run tsc && npm run lint",
"test": "npm run check && npm run test-local",
"test-local": "egg-bin test --ts",
"prepublish": "del dist && npm run build",
"prepublishOnly": "del dist && npm run tsc",
"cov": "egg-bin cov --ts",
"ci": "npm run check && npm run cov"
"ci": "npm run check && npm run cov && npm run tsc"
},
"keywords": [
"egg",
Expand Down
9 changes: 6 additions & 3 deletions src/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
import path from 'path';
import { Command } from 'commander';
import assert from 'assert';
import packInfo from '../package.json';
import TsHelper, { defaultConfig } from './core';
import { loadModules, writeJsConfig, checkMaybeIsJsProj } from './utils';
import { loadModules, writeJsConfig, checkMaybeIsJsProj, getPkgInfo } from './utils';

export interface CommandOption {
version?: string;
Expand All @@ -19,8 +18,12 @@ export default class Commander {
constructor(options?: CommandOption) {
this.commands = loadModules<SubCommand>(path.resolve(__dirname, './cmd'), true);
this.tsHelperClazz = options?.tsHelperClazz || TsHelper;
let version = options?.version;
if (!version) {
version = getPkgInfo(path.dirname(__dirname)).version;
}
this.program = new Command()
.version(options?.version || packInfo.version, '-v, --version')
.version(version!, '-v, --version')
.usage('[commands] [options]')
.option('-w, --watch', 'Watching files, d.ts would recreated while file changed')
.option('-c, --cwd [path]', 'Egg application base dir (default: process.cwd)')
Expand Down
8 changes: 5 additions & 3 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import path from 'path';
import packInfo from '../package.json';
import { getPkgInfo } from './utils';

export const tmpDir = path.resolve(__dirname, '../.tmp');
export const eggInfoPath = path.resolve(tmpDir, './eggInfo.json');
const root = path.dirname(__dirname);
const packInfo = getPkgInfo(root);
export const tmpDir = path.join(root, '.tmp');
export const eggInfoPath = path.resolve(tmpDir, 'eggInfo.json');
export const dtsCommentRE = new RegExp(`^\\/\\/ [\\w ]+ ${packInfo.name}(@\\d+\\.\\d+\\.\\d+)?`);
export const dtsComment =
`// This file is created by ${packInfo.name}@${packInfo.version}\n` +
Expand Down
4 changes: 2 additions & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import glob from 'globby';
import path from 'path';
import ts from 'typescript';
import yn from 'yn';
import { eggInfoPath, tmpDir } from './config';
import { execFileSync, execFile, ExecFileOptions } from 'child_process';
import JSON5 from 'json5';
import { eggInfoPath, tmpDir } from './config';

export const JS_CONFIG = {
include: [ '**/*' ],
Expand Down Expand Up @@ -383,7 +383,7 @@ export function parseJson(jsonStr: string) {

// load package.json
export function getPkgInfo(cwd: string) {
return readJson(path.resolve(cwd, './package.json'));
return readJson(path.resolve(cwd, 'package.json'));
}

// read json file
Expand Down
28 changes: 5 additions & 23 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,30 +1,12 @@
{
"extends": "@eggjs/tsconfig",
"compilerOptions": {
"strict": true,
"target": "es2017",
"module": "commonjs",
"moduleResolution": "nodenext",
"target": "ES2021",
"outDir": "dist",
"rootDir": "src",
"noImplicitAny": false,
"allowSyntheticDefaultImports": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"esModuleInterop": true,
"allowJs": false,
"pretty": true,
"declaration": true,
"declarationMap": true,
"noEmitOnError": false,
"noUnusedLocals": true,
"noUnusedParameters": true,
"allowUnreachableCode": false,
"allowUnusedLabels": false,
"strictPropertyInitialization": false,
"noFallthroughCasesInSwitch": true,
"skipLibCheck": true,
"skipDefaultLibCheck": true,
"importHelpers": true
"module": "NodeNext",
"moduleResolution": "NodeNext",
"allowUnreachableCode": true
},
"include": [
"./src/**/*",
Expand Down

0 comments on commit 5b0a976

Please sign in to comment.