From 14aa2c5afff73d853ebd0fc113a259fdc735a1aa Mon Sep 17 00:00:00 2001 From: fengmk2 Date: Mon, 1 Jul 2024 00:04:05 +0800 Subject: [PATCH] fix: change env and proxy to getter and setter (#9) ## Summary by CodeRabbit - **New Features** - Introduced GitHub Actions workflow for automatic publishing on push and pull requests. - **Enhancements** - Added new CI script to streamline the build and publishing process. - Improved type safety and code quality with updated devDependencies. - **Refactor** - Updated class properties in the `Application` class to use getter and setter methods for better encapsulation. --- .github/workflows/pkg.pr.new.yml | 23 +++++++++++++++++++++++ package.json | 5 +++-- src/application.ts | 22 ++++++++++++++++++---- 3 files changed, 44 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/pkg.pr.new.yml diff --git a/.github/workflows/pkg.pr.new.yml b/.github/workflows/pkg.pr.new.yml new file mode 100644 index 000000000..ebe7c34db --- /dev/null +++ b/.github/workflows/pkg.pr.new.yml @@ -0,0 +1,23 @@ +name: Publish Any Commit +on: [push, pull_request] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - run: corepack enable + - uses: actions/setup-node@v4 + with: + node-version: 20 + + - name: Install dependencies + run: npm install + + - name: Build + run: npm run prepublishOnly + + - run: npx pkg-pr-new publish diff --git a/package.json b/package.json index d19d67c5c..38b568a4b 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "description": "Koa web app framework for https://eggjs.org", "scripts": { "test": "npm run lint -- --fix && egg-bin test", - "ci": "npm run lint && egg-bin cov && npm run prepublishOnly", + "ci": "npm run lint && egg-bin cov && npm run prepublishOnly && attw --pack", "lint": "eslint src test", "authors": "git log --format='%aN <%aE>' | sort -u > AUTHORS", "prepublishOnly": "tshy && tshy-after" @@ -52,6 +52,7 @@ "vary": "^1.1.2" }, "devDependencies": { + "@arethetypeswrong/cli": "^0.15.3", "@eggjs/tsconfig": "^1.3.3", "@types/content-type": "^1.1.8", "@types/delegates": "^1.0.3", @@ -71,7 +72,7 @@ "@types/vary": "^1.1.3", "egg-bin": "^6.4.0", "eslint": "^8.41.0", - "eslint-config-egg": "^13.1.0", + "eslint-config-egg": "14", "mm": "^3.3.0", "supertest": "^3.1.0", "tsd": "^0.31.0", diff --git a/src/application.ts b/src/application.ts index 5a48d1495..ce4cfcd7e 100644 --- a/src/application.ts +++ b/src/application.ts @@ -35,11 +35,11 @@ export class Application extends Emitter { */ static HttpError = HttpError; - proxy: boolean; + protected _proxy: boolean; + protected _env: string; subdomainOffset: number; proxyIpHeader: string; maxIpsCount: number; - env: string; keys?: string[]; middleware: MiddlewareFunc[]; ctxStorage: AsyncLocalStorage; @@ -73,11 +73,11 @@ export class Application extends Emitter { }) { super(); options = options || {}; - this.proxy = options.proxy || false; + this._proxy = options.proxy || false; this.subdomainOffset = options.subdomainOffset || 2; this.proxyIpHeader = options.proxyIpHeader || 'X-Forwarded-For'; this.maxIpsCount = options.maxIpsCount || 0; - this.env = options.env || process.env.NODE_ENV || 'development'; + this._env = options.env || process.env.NODE_ENV || 'development'; if (options.keys) this.keys = options.keys; this.middleware = []; this.ctxStorage = getAsyncLocalStorage(); @@ -90,6 +90,20 @@ export class Application extends Emitter { this.response = this.ResponseClass.prototype; } + get env() { + return this._env; + } + set env(value: string) { + this._env = value; + } + + get proxy() { + return this._proxy; + } + set proxy(value: boolean) { + this._proxy = value; + } + /** * Shorthand for: *