-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: process env usage with doc (#715)
- Loading branch information
Showing
11 changed files
with
110 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,15 @@ | ||
import { bootstrap } from 'global-agent' | ||
bootstrap() | ||
import { environment } from '@acala-network/chopsticks-core' | ||
import npmConf from '@pnpm/npm-conf' | ||
|
||
const npmConfig = npmConf().config | ||
|
||
global.GLOBAL_AGENT.HTTP_PROXY = | ||
process.env.HTTP_PROXY || | ||
process.env.http_proxy || | ||
process.env.HTTPS_PROXY || | ||
process.env.https_proxy || | ||
environment.HTTP_PROXY || | ||
environment.http_proxy || | ||
environment.HTTPS_PROXY || | ||
environment.https_proxy || | ||
npmConfig.get('proxy') || | ||
npmConfig.get('https-proxy') || | ||
global.GLOBAL_AGENT.HTTP_PROXY |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import * as z from 'zod' | ||
|
||
export const environmentSchema = z.object({ | ||
/** | ||
* Disable auto HRMP on setup. Default is `false`. | ||
*/ | ||
DISABLE_AUTO_HRMP: z | ||
.enum(['true', 'false']) | ||
.default('false') | ||
.transform((v) => v === 'true'), | ||
/** | ||
* Set port for Chopsticks to listen on, default is `8000`. | ||
*/ | ||
PORT: z.string().optional(), | ||
/** | ||
* Disable plugins for faster startup. Default is `false`. | ||
*/ | ||
DISABLE_PLUGINS: z | ||
.enum(['true', 'false']) | ||
.default('false') | ||
.transform((v) => v === 'true'), | ||
HTTP_PROXY: z.string().optional(), | ||
http_proxy: z.string().optional(), | ||
HTTPS_PROXY: z.string().optional(), | ||
https_proxy: z.string().optional(), | ||
/** | ||
* Chopsticks log level, "fatal" | "error" | "warn" | "info" | "debug" | "trace". | ||
* Default is "info". | ||
*/ | ||
LOG_LEVEL: z.enum(['fatal', 'error', 'warn', 'info', 'debug', 'trace']).default('info'), | ||
/** | ||
* Don't truncate log messages, show full log output. Default is `false`. | ||
*/ | ||
VERBOSE_LOG: z | ||
.enum(['true', 'false']) | ||
.default('false') | ||
.transform((v) => v === 'true'), | ||
/** | ||
* Don't log objects. Default is `false`. | ||
*/ | ||
LOG_COMPACT: z | ||
.enum(['true', 'false']) | ||
.default('false') | ||
.transform((v) => v === 'true'), | ||
}) | ||
|
||
/** | ||
* Environment variables available for users | ||
*/ | ||
export const environment = environmentSchema.parse(typeof process === 'object' ? process.env : {}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { describe, expect, it } from 'vitest' | ||
import { environment, environmentSchema } from '@acala-network/chopsticks-core' | ||
|
||
describe('environment', () => { | ||
it('defaults are correct', async () => { | ||
expect(environment).toMatchObject({ | ||
DISABLE_AUTO_HRMP: false, | ||
DISABLE_PLUGINS: false, | ||
VERBOSE_LOG: false, | ||
LOG_COMPACT: false, | ||
}) | ||
}) | ||
|
||
it('parsing is correct', async () => { | ||
process.env = { | ||
DISABLE_AUTO_HRMP: 'true', | ||
PORT: '8001', | ||
DISABLE_PLUGINS: 'false', | ||
HTTP_PROXY: 'http://localhost:8080', | ||
HTTPS_PROXY: 'https://localhost:8080', | ||
LOG_LEVEL: 'info', | ||
VERBOSE_LOG: 'false', | ||
LOG_COMPACT: 'true', | ||
} | ||
expect(environmentSchema.parse(process.env)).toMatchObject({ | ||
DISABLE_AUTO_HRMP: true, | ||
PORT: '8001', | ||
DISABLE_PLUGINS: false, | ||
HTTP_PROXY: 'http://localhost:8080', | ||
HTTPS_PROXY: 'https://localhost:8080', | ||
LOG_LEVEL: 'info', | ||
VERBOSE_LOG: false, | ||
LOG_COMPACT: true, | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters