From a9345017aad7aea1d612387881353f1e8662cef4 Mon Sep 17 00:00:00 2001 From: fengmk2 Date: Wed, 2 Aug 2023 09:48:30 +0800 Subject: [PATCH] feat: use typescript v5 (#107) --- .github/workflows/codeql.yml | 2 -- .github/workflows/nodejs.yml | 5 ++--- .github/workflows/release.yml | 2 +- README.md | 27 ++++++++++----------------- README.zh-CN.md | 30 ++++++++++++------------------ package.json | 12 ++++++------ src/cmd/clean.ts | 2 +- src/utils.ts | 3 +-- src/watcher.ts | 3 +-- test/fixtures/app12/tsHelper.json | 5 ++--- test/fixtures/app13/tsCustom.json | 5 ++--- test/fixtures/app9/tsconfig.json | 1 - test/tsconfig.json | 2 -- tsconfig.json | 1 - 14 files changed, 38 insertions(+), 62 deletions(-) diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 77f6c97..028b997 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -5,8 +5,6 @@ on: branches: [ "master" ] pull_request: branches: [ "master" ] - schedule: - - cron: "55 4 * * 4" jobs: analyze: diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index 4fdb3a8..c1d0bc9 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -12,8 +12,7 @@ on: jobs: Job: name: Node.js - uses: artusjs/github-actions/.github/workflows/node-test.yml@v1 + uses: node-modules/github-actions/.github/workflows/node-test.yml@master with: os: 'ubuntu-latest' - version: '14, 16, 18' - install: 'npm i -g npminstall && npminstall' + version: '14, 16, 18, 20' diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 1612587..64a499b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -9,7 +9,7 @@ on: jobs: release: name: Node.js - uses: artusjs/github-actions/.github/workflows/node-release.yml@v1 + uses: node-modules/github-actions/.github/workflows/node-release.yml@master secrets: NPM_TOKEN: ${{ secrets.NPM_TOKEN }} GIT_TOKEN: ${{ secrets.GIT_TOKEN }} diff --git a/README.md b/README.md index 437c6b7..7dc9ab3 100644 --- a/README.md +++ b/README.md @@ -15,39 +15,32 @@ A simple tool for creating `d.ts` in [egg](https://eggjs.org) application. Injecting `controller, proxy, service, etc.` to definition type of egg ( such as `Context` `Application` etc. ) by [Declaration Merging](https://www.typescriptlang.org/docs/handbook/declaration-merging.html), and making IntelliSense works in both egg-js and egg-ts. - ## Install open your application and install. -``` +```bash npm i egg-ts-helper --save-dev ``` -or - -``` -yarn add egg-ts-helper --dev -``` - ## QuickStart Open your egg application, executing ets by [npx](https://github.com/zkat/npx) -``` -$ npx ets +```bash +npx ets ``` Watching files by `-w` flag. -``` -$ npx ets -w +```bash +npx ets -w ``` `egg-ts-helper` has build-in in `egg-bin`, You can easily to use it by -``` -$ egg-bin dev --dts +```bash +egg-bin dev --dts ``` or add configuration `egg.declarations` in `package.json` @@ -180,7 +173,7 @@ Also you can pass options by env ( support since 1.22.0 ) > Support since 1.24.0 -`egg-ts-helper` support customLoader configuration of egg. see https://github.com/eggjs/egg/issues/3480 +`egg-ts-helper` support customLoader configuration of egg. see Configure in `config.default.ts` @@ -535,9 +528,9 @@ module.exports = { `egg-ts-helper` can works in both `ts` and `js` egg project. -TS demo: https://github.com/whxaxes/egg-boilerplate-d-ts +TS demo: -JS demo: https://github.com/whxaxes/egg-boilerplate-d-js +JS demo: ## License diff --git a/README.zh-CN.md b/README.zh-CN.md index a7013b0..8af6d7d 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -19,41 +19,35 @@ 打开应用目录并且安装 -``` +```bash npm i egg-ts-helper --save-dev ``` -或者 - -``` -yarn add egg-ts-helper --dev -``` - ## 快速开始 打开你的 egg 应用,通过 [npx](https://github.com/zkat/npx) 来执行 ets 指令 -``` -$ npx ets +```bash +npx ets ``` 可以通过 `-w` 来监听文件改动并且重新生成 `d.ts` -``` -$ npx ets -w +```bash +npx ets -w ``` `egg-ts-helper` 已经内置在 `egg-bin` 中,可以通过以下命令方便使用 -``` -$ egg-bin dev --dts +```bash +egg-bin dev --dts ``` 再或者在 `package.json` 中配置 `egg.declarations` 为 true 即可。 ## 命令行 -``` +```bash $ ets -h Usage: ets [commands] [options] @@ -161,7 +155,7 @@ module.exports = { > 在 1.24.0 之后版本支持 -`egg-ts-helper` 支持 egg 的 customLoader 配置,会自动去读取应用/插件/框架中的 customLoader 配置. 详情请看 https://github.com/eggjs/egg/issues/3480 +`egg-ts-helper` 支持 egg 的 customLoader 配置,会自动去读取应用/插件/框架中的 customLoader 配置. 详情请看 在 `config.default.ts` 中配置 customLoader @@ -190,7 +184,7 @@ export default function(appInfo: EggAppConfig) { } ``` -`egg-ts-helper` 将会根据 `app/model` 目录下的文件,自动生成声明 ( 参考 https://github.com/whxaxes/egg-boilerplate-d-ts 这个项目 ) +`egg-ts-helper` 将会根据 `app/model` 目录下的文件,自动生成声明 ( 参考 这个项目 ) ```typescript // This file is created by egg-ts-helper@1.24.1 @@ -515,9 +509,9 @@ module.exports = { `egg-ts-helper` 可用于 egg 的 `ts` 和 `js` 项目. -TS 项目: https://github.com/whxaxes/egg-boilerplate-d-ts +TS 项目: -JS 项目: https://github.com/whxaxes/egg-boilerplate-d-js +JS 项目: ## License diff --git a/package.json b/package.json index 2865488..567ab8f 100644 --- a/package.json +++ b/package.json @@ -35,16 +35,16 @@ "author": "wanghx", "license": "MIT", "dependencies": { - "chalk": "^2.4.2", + "chalk": "^4.0.0", "chokidar": "^3.0.0", "commander": "^2.15.1", "dot-prop": "^4.2.0", "enquirer": "^2.3.0", "globby": "^11.0.0", - "json5": "^2.2.0", + "json5": "^2.2.3", "ts-node": "^10.9.1", - "tslib": "^2.0.0", - "typescript": "^4.0.0", + "tslib": "^2.6.1", + "typescript": "^5.1.6", "yn": "^3.0.0" }, "devDependencies": { @@ -53,11 +53,11 @@ "@types/del": "^3.0.0", "@types/globby": "^6.1.0", "@types/mocha": "^10.0.0", - "@types/node": "^14.18.36", + "@types/node": "^20.4.5", "del": "^3.0.0", "del-cli": "^1.1.0", "egg": "^3.5.0", - "egg-bin": "^5.5.0", + "egg-bin": "^6.4.1", "egg-mock": "^5.2.1", "egg-sequelize": "^4.3.1", "eslint": "^8.28.0", diff --git a/src/cmd/clean.ts b/src/cmd/clean.ts index 9e41f14..bf84ed7 100644 --- a/src/cmd/clean.ts +++ b/src/cmd/clean.ts @@ -1,5 +1,5 @@ -import { cleanJs } from '../utils'; import chalk from 'chalk'; +import { cleanJs } from '../utils'; class CleanCommand implements SubCommand { description = 'Clean js file while it has the same name ts/tsx file'; diff --git a/src/utils.ts b/src/utils.ts index ba31fe2..ff27f30 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -20,7 +20,6 @@ export const TS_CONFIG: Partial = { experimentalDecorators: true, emitDecoratorMetadata: true, allowSyntheticDefaultImports: true, - charset: 'utf8', allowJs: false, pretty: true, lib: [ 'es6' ], @@ -546,7 +545,7 @@ export function isClass(v): v is { new (...args: any[]): any } { } // check kind in node.modifiers. -export function modifierHas(node: ts.Node, kind) { +export function modifierHas(node, kind) { return node.modifiers && node.modifiers.find(mod => kind === mod.kind); } diff --git a/src/watcher.ts b/src/watcher.ts index 254138e..e39f091 100644 --- a/src/watcher.ts +++ b/src/watcher.ts @@ -73,8 +73,7 @@ export default class Watcher extends EventEmitter { .concat(utils.toArray(this.options.ignore).map(p => `!${utils.formatPath(p)}`)); assert(options.directory, `options.directory must set in ${generatorName}`); - const baseDir = options.directory.replace(/\/|\\/, path.sep); - this.dir = path.resolve(this.config.cwd, baseDir); + this.dir = path.resolve(this.config.cwd, options.directory); this.dtsDir = path.resolve( this.config.typings, path.relative(this.config.cwd, this.dir), diff --git a/test/fixtures/app12/tsHelper.json b/test/fixtures/app12/tsHelper.json index 61e6d0c..b10cd8f 100644 --- a/test/fixtures/app12/tsHelper.json +++ b/test/fixtures/app12/tsHelper.json @@ -1,7 +1,6 @@ { "generatorConfig.dal": { "directory": "app/dal/dao", - "caseStyle": "upper", - "watch": false + "caseStyle": "upper" } -} \ No newline at end of file +} diff --git a/test/fixtures/app13/tsCustom.json b/test/fixtures/app13/tsCustom.json index 61e6d0c..b10cd8f 100644 --- a/test/fixtures/app13/tsCustom.json +++ b/test/fixtures/app13/tsCustom.json @@ -1,7 +1,6 @@ { "generatorConfig.dal": { "directory": "app/dal/dao", - "caseStyle": "upper", - "watch": false + "caseStyle": "upper" } -} \ No newline at end of file +} diff --git a/test/fixtures/app9/tsconfig.json b/test/fixtures/app9/tsconfig.json index 5eedc7f..042ae8c 100644 --- a/test/fixtures/app9/tsconfig.json +++ b/test/fixtures/app9/tsconfig.json @@ -5,7 +5,6 @@ "module": "commonjs", "moduleResolution": "node", "skipLibCheck": true, - "watch": false, "jsx": "react", }, "include": [ diff --git a/test/tsconfig.json b/test/tsconfig.json index 6d81399..8a08278 100644 --- a/test/tsconfig.json +++ b/test/tsconfig.json @@ -10,9 +10,7 @@ "esModuleInterop": true, "experimentalDecorators": true, "emitDecoratorMetadata": true, - "charset": "utf8", "allowJs": true, - "watch": false, "pretty": true, "noEmitOnError": false, "noUnusedLocals": true, diff --git a/tsconfig.json b/tsconfig.json index 0d4a02a..3ae2ab0 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -11,7 +11,6 @@ "experimentalDecorators": true, "emitDecoratorMetadata": true, "esModuleInterop": true, - "charset": "utf8", "allowJs": false, "pretty": true, "declaration": true,