Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: change env and proxy to getter and setter #9

Merged
merged 1 commit into from
Jun 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .github/workflows/pkg.pr.new.yml
Original file line number Diff line number Diff line change
@@ -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
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -52,6 +52,7 @@
"vary": "^1.1.2"
},
"devDependencies": {
"@arethetypeswrong/cli": "^0.15.3",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tip

Codebase Verification

Unused dependency @arethetypeswrong/cli found in package.json.

The dependency @arethetypeswrong/cli is listed in package.json but is not used anywhere in the codebase, npm scripts, or configuration files. Consider removing it to keep the project dependencies clean.

  • package.json: Line 55
Analysis chain

Added @arethetypeswrong/cli as a new dev dependency.

Ensure that this new dependency is necessary and used appropriately in the project.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the usage of the new dependency `@arethetypeswrong/cli`.

# Test: Search for the usage of `@arethetypeswrong/cli` in the codebase. Expect: The dependency should be used in the codebase.
rg '@arethetypeswrong/cli'

Length of output: 79



Script:

#!/bin/bash
# Description: Verify the usage of the new dependency `@arethetypeswrong/cli` in npm scripts and configuration files.

# Test 1: Search for the usage of `@arethetypeswrong/cli` in npm scripts defined in package.json.
jq '.scripts | .[]' package.json | grep '@arethetypeswrong/cli'

# Test 2: Search for the usage of `@arethetypeswrong/cli` in common configuration files.
rg '@arethetypeswrong/cli' --glob '*.{js,json,yml,yaml}'

Length of output: 173

"@eggjs/tsconfig": "^1.3.3",
"@types/content-type": "^1.1.8",
"@types/delegates": "^1.0.3",
Expand All @@ -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",
Expand Down
22 changes: 18 additions & 4 deletions src/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ContextDelegation>;
Expand Down Expand Up @@ -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();
Expand All @@ -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;
}

Comment on lines +93 to +106
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tip

Codebase Verification

Ensure consistent usage of getter and setter methods for env and proxy.

Direct access to _env and _proxy is found in the constructor. Please use the getter and setter methods to ensure proper encapsulation.

  • src/application.ts:
    • Line 99: this._env = options.env || process.env.NODE_ENV || 'development';
    • Line 101: this._proxy = options.proxy || false;
Analysis chain

Verify the usage of new getter and setter methods.

Ensure that the new getter and setter methods for env and proxy are used instead of direct property access.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the usage of new getter and setter methods for `env` and `proxy`.

# Test: Search for the usage of `env` and `proxy` getter and setter methods. Expect: Only the getter and setter methods should be used.
rg '\.env' --type=typescript
rg '\.proxy' --type=typescript

Length of output: 133



Script:

#!/bin/bash
# Description: Verify the usage of new getter and setter methods for `env` and `proxy`.

# Test: Search for the usage of `env` and `proxy` getter and setter methods in TypeScript files.
rg '\.env' --glob '*.ts'
rg '\.proxy' --glob '*.ts'

Length of output: 2474



Script:

#!/bin/bash
# Description: Extract context around the usage of `env` and `proxy` to verify if getter and setter methods are used.

# Extract context for `.env` usage
rg '\.env' --glob '*.ts' -C 3

# Extract context for `.proxy` usage
rg '\.proxy' --glob '*.ts' -C 3

Length of output: 12949

/**
* Shorthand for:
*
Expand Down
Loading