Skip to content

Commit 1bb07d8

Browse files
committed
Env cleanup
1 parent 5571942 commit 1bb07d8

2 files changed

Lines changed: 46 additions & 44 deletions

File tree

scripts/constants.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ const SOCKET_CLI_SENTRY_NPX_BIN_NAME = 'socket-npx-with-sentry'
4343
const SOCKET_CLI_SENTRY_PACKAGE_NAME = '@socketsecurity/cli-with-sentry'
4444

4545
const LAZY_ENV = () => {
46-
const { envAsBoolean } = require('@socketsecurity/registry/lib/env')
4746
const { env } = process
47+
const { envAsBoolean } = require('@socketsecurity/registry/lib/env')
4848
return Object.freeze({
4949
// Lazily access registryConstants.ENV.
5050
...registryConstants.ENV,

src/constants.mts

Lines changed: 45 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ function getNpmStdioPipeOptions() {
234234
}
235235

236236
const LAZY_ENV = () => {
237-
const { env: processEnv } = process
237+
const { env } = process
238238
const envHelpers = /*@__PURE__*/ require('@socketsecurity/registry/lib/env')
239239
const utils = /*@__PURE__*/ require(
240240
path.join(constants.rootPath, 'dist/utils.js'),
@@ -244,7 +244,7 @@ const LAZY_ENV = () => {
244244
const envAsString = envHelpers.envAsString
245245
const getConfigValueOrUndef = utils.getConfigValueOrUndef
246246
const readOrDefaultSocketJson = utils.readOrDefaultSocketJson
247-
const GITHUB_TOKEN = envAsString(processEnv['GITHUB_TOKEN'])
247+
const GITHUB_TOKEN = envAsString(env['GITHUB_TOKEN'])
248248
const INLINED_SOCKET_CLI_PUBLISHED_BUILD = envAsBoolean(
249249
process.env['INLINED_SOCKET_CLI_PUBLISHED_BUILD'],
250250
)
@@ -256,31 +256,31 @@ const LAZY_ENV = () => {
256256
...registryConstants.ENV,
257257
// Disable using GitHub's workflow actions/cache.
258258
// https://github.com/actions/cache
259-
DISABLE_GITHUB_CACHE: envAsBoolean(processEnv['DISABLE_GITHUB_CACHE']),
259+
DISABLE_GITHUB_CACHE: envAsBoolean(env['DISABLE_GITHUB_CACHE']),
260260
// The API URL. For example, https://api.github.com.
261261
// https://docs.github.com/en/codespaces/developing-in-a-codespace/default-environment-variables-for-your-codespace#list-of-default-environment-variables
262262
GITHUB_API_URL:
263-
envAsString(processEnv['GITHUB_API_URL']) || 'https://api.github.com',
263+
envAsString(env['GITHUB_API_URL']) || 'https://api.github.com',
264264
// The name of the base ref or target branch of the pull request in a workflow
265265
// run. This is only set when the event that triggers a workflow run is either
266266
// pull_request or pull_request_target. For example, main.
267267
// https://docs.github.com/en/codespaces/developing-in-a-codespace/default-environment-variables-for-your-codespace#list-of-default-environment-variables
268-
GITHUB_BASE_REF: envAsString(processEnv['GITHUB_BASE_REF']),
268+
GITHUB_BASE_REF: envAsString(env['GITHUB_BASE_REF']),
269269
// The short ref name of the branch or tag that triggered the GitHub workflow
270270
// run. This value matches the branch or tag name shown on GitHub. For example,
271271
// feature-branch-1. For pull requests, the format is <pr_number>/merge.
272272
// https://docs.github.com/en/codespaces/developing-in-a-codespace/default-environment-variables-for-your-codespace#list-of-default-environment-variables
273-
GITHUB_REF_NAME: envAsString(processEnv['GITHUB_REF_NAME']),
273+
GITHUB_REF_NAME: envAsString(env['GITHUB_REF_NAME']),
274274
// The type of ref that triggered the workflow run. Valid values are branch or tag.
275275
// https://docs.github.com/en/codespaces/developing-in-a-codespace/default-environment-variables-for-your-codespace#list-of-default-environment-variables
276-
GITHUB_REF_TYPE: envAsString(processEnv['GITHUB_REF_TYPE']),
276+
GITHUB_REF_TYPE: envAsString(env['GITHUB_REF_TYPE']),
277277
// The owner and repository name. For example, octocat/Hello-World.
278278
// https://docs.github.com/en/codespaces/developing-in-a-codespace/default-environment-variables-for-your-codespace#list-of-default-environment-variables
279-
GITHUB_REPOSITORY: envAsString(processEnv['GITHUB_REPOSITORY']),
279+
GITHUB_REPOSITORY: envAsString(env['GITHUB_REPOSITORY']),
280280
// The URL of the GitHub server. For example, https://github.com.
281281
// https://docs.github.com/en/codespaces/developing-in-a-codespace/default-environment-variables-for-your-codespace#list-of-default-environment-variables
282282
GITHUB_SERVER_URL:
283-
envAsString(processEnv['GITHUB_SERVER_URL']) || 'https://github.com',
283+
envAsString(env['GITHUB_SERVER_URL']) || 'https://github.com',
284284
// The GITHUB_TOKEN secret is a GitHub App installation access token.
285285
// The token's permissions are limited to the repository that contains the
286286
// workflow.
@@ -337,7 +337,7 @@ const LAZY_ENV = () => {
337337
// The absolute location of the %localappdata% folder on Windows used to store
338338
// user-specific, non-roaming application data, like temporary files, cached
339339
// data, and program settings, that are specific to the current machine and user.
340-
LOCALAPPDATA: envAsString(processEnv[LOCALAPPDATA]),
340+
LOCALAPPDATA: envAsString(env[LOCALAPPDATA]),
341341
// Enable the module compile cache for the Node.js instance.
342342
// https://nodejs.org/api/cli.html#node_compile_cachedir
343343
NODE_COMPILE_CACHE: constants.SUPPORTS_NODE_COMPILE_CACHE_ENV_VAR
@@ -346,70 +346,72 @@ const LAZY_ENV = () => {
346346
// Redefine registryConstants.ENV.NODE_ENV to account for the
347347
// INLINED_SOCKET_CLI_PUBLISHED_BUILD environment variable.
348348
NODE_ENV:
349-
envAsString(processEnv['NODE_ENV']).toLowerCase() === 'production'
349+
envAsString(env['NODE_ENV']).toLowerCase() === 'production'
350350
? 'production'
351-
: (INLINED_SOCKET_CLI_PUBLISHED_BUILD ? '' : 'development'),
351+
: INLINED_SOCKET_CLI_PUBLISHED_BUILD
352+
? ''
353+
: 'development',
352354
// Well known "root" CAs (like VeriSign) will be extended with the extra
353355
// certificates in file. The file should consist of one or more trusted
354356
// certificates in PEM format.
355357
// https://nodejs.org/api/cli.html#node_extra_ca_certsfile
356358
NODE_EXTRA_CA_CERTS:
357-
envAsString(processEnv['NODE_EXTRA_CA_CERTS']) ||
359+
envAsString(env['NODE_EXTRA_CA_CERTS']) ||
358360
// Commonly used environment variable to specify the path to a single
359361
// PEM-encoded certificate file.
360-
envAsString(processEnv['SSL_CERT_FILE']),
362+
envAsString(env['SSL_CERT_FILE']),
361363
// PATH is an environment variable that lists directories where executable
362364
// programs are located. When a command is run, the system searches these
363365
// directories to find the executable.
364-
PATH: envAsString(processEnv['PATH']),
366+
PATH: envAsString(env['PATH']),
365367
// Accept risks of a Socket wrapped npm/npx run.
366-
SOCKET_CLI_ACCEPT_RISKS: envAsBoolean(processEnv[SOCKET_CLI_ACCEPT_RISKS]),
368+
SOCKET_CLI_ACCEPT_RISKS: envAsBoolean(env[SOCKET_CLI_ACCEPT_RISKS]),
367369
// Change the base URL for Socket API calls.
368370
// https://github.com/SocketDev/socket-cli?tab=readme-ov-file#environment-variables-for-development
369371
SOCKET_CLI_API_BASE_URL:
370-
envAsString(processEnv['SOCKET_CLI_API_BASE_URL']) ||
372+
envAsString(env['SOCKET_CLI_API_BASE_URL']) ||
371373
// TODO: Remove legacy environment variable name.
372-
envAsString(processEnv['SOCKET_SECURITY_API_BASE_URL']) ||
374+
envAsString(env['SOCKET_SECURITY_API_BASE_URL']) ||
373375
getConfigValueOrUndef('apiBaseUrl') ||
374376
'https://api.socket.dev/v0/',
375377
// Set the proxy that all requests are routed through.
376378
// https://github.com/SocketDev/socket-cli?tab=readme-ov-file#environment-variables-for-development
377379
SOCKET_CLI_API_PROXY:
378-
envAsString(processEnv['SOCKET_CLI_API_PROXY']) ||
380+
envAsString(env['SOCKET_CLI_API_PROXY']) ||
379381
// TODO: Remove legacy environment variable name.
380-
envAsString(processEnv['SOCKET_SECURITY_API_PROXY']) ||
382+
envAsString(env['SOCKET_SECURITY_API_PROXY']) ||
381383
// Commonly used environment variables to specify routing requests through
382384
// a proxy server.
383-
envAsString(processEnv['HTTPS_PROXY']) ||
384-
envAsString(processEnv['https_proxy']) ||
385-
envAsString(processEnv['HTTP_PROXY']) ||
386-
envAsString(processEnv['http_proxy']),
385+
envAsString(env['HTTPS_PROXY']) ||
386+
envAsString(env['https_proxy']) ||
387+
envAsString(env['HTTP_PROXY']) ||
388+
envAsString(env['http_proxy']),
387389
// Set the timeout in milliseconds for Socket API requests.
388390
// https://nodejs.org/api/http.html#httprequesturl-options-callback
389-
SOCKET_CLI_API_TIMEOUT: envAsNumber(processEnv['SOCKET_CLI_API_TOKEN']),
391+
SOCKET_CLI_API_TIMEOUT: envAsNumber(env['SOCKET_CLI_API_TOKEN']),
390392
// Set the Socket API token.
391393
// https://github.com/SocketDev/socket-cli?tab=readme-ov-file#environment-variables
392394
SOCKET_CLI_API_TOKEN:
393-
envAsString(processEnv['SOCKET_CLI_API_TOKEN']) ||
395+
envAsString(env['SOCKET_CLI_API_TOKEN']) ||
394396
// TODO: Remove legacy environment variable names.
395-
envAsString(processEnv['SOCKET_CLI_API_KEY']) ||
396-
envAsString(processEnv['SOCKET_SECURITY_API_TOKEN']) ||
397-
envAsString(processEnv['SOCKET_SECURITY_API_KEY']),
397+
envAsString(env['SOCKET_CLI_API_KEY']) ||
398+
envAsString(env['SOCKET_SECURITY_API_TOKEN']) ||
399+
envAsString(env['SOCKET_SECURITY_API_KEY']),
398400
// A JSON stringified Socket configuration object.
399-
SOCKET_CLI_CONFIG: envAsString(processEnv['SOCKET_CLI_CONFIG']),
401+
SOCKET_CLI_CONFIG: envAsString(env['SOCKET_CLI_CONFIG']),
400402
// The git config user.email used by Socket CLI.
401403
SOCKET_CLI_GIT_USER_EMAIL:
402-
envAsString(processEnv['SOCKET_CLI_GIT_USER_EMAIL']) ||
404+
envAsString(env['SOCKET_CLI_GIT_USER_EMAIL']) ||
403405
'github-actions[bot]@users.noreply.github.com',
404406
// The git config user.name used by Socket CLI.
405407
SOCKET_CLI_GIT_USER_NAME:
406-
envAsString(processEnv['SOCKET_CLI_GIT_USER_NAME']) ||
407-
envAsString(processEnv['SOCKET_CLI_GIT_USERNAME']) ||
408+
envAsString(env['SOCKET_CLI_GIT_USER_NAME']) ||
409+
envAsString(env['SOCKET_CLI_GIT_USERNAME']) ||
408410
'github-actions[bot]',
409411
// Change the base URL for GitHub REST API calls.
410412
// https://docs.github.com/en/rest
411413
SOCKET_CLI_GITHUB_API_URL:
412-
envAsString(processEnv['SOCKET_CLI_GITHUB_API_URL']) ||
414+
envAsString(env['SOCKET_CLI_GITHUB_API_URL']) ||
413415
readOrDefaultSocketJson(process.cwd())?.defaults?.scan?.github
414416
?.githubApiUrl ||
415417
'https://api.github.com',
@@ -418,30 +420,30 @@ const LAZY_ENV = () => {
418420
// "Contents" and "Pull Request".
419421
// https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens
420422
SOCKET_CLI_GITHUB_TOKEN:
421-
envAsString(processEnv['SOCKET_CLI_GITHUB_TOKEN']) ||
423+
envAsString(env['SOCKET_CLI_GITHUB_TOKEN']) ||
422424
// TODO: Remove undocumented legacy environment variable name.
423-
envAsString(processEnv['SOCKET_SECURITY_GITHUB_PAT']) ||
425+
envAsString(env['SOCKET_SECURITY_GITHUB_PAT']) ||
424426
GITHUB_TOKEN,
425427
// Make the default API token `undefined`.
426428
SOCKET_CLI_NO_API_TOKEN: envAsBoolean(
427-
processEnv['SOCKET_CLI_NO_API_TOKEN'],
429+
env['SOCKET_CLI_NO_API_TOKEN'],
428430
),
429431
// The absolute location of the npm directory.
430-
SOCKET_CLI_NPM_PATH: envAsString(processEnv['SOCKET_CLI_NPM_PATH']),
432+
SOCKET_CLI_NPM_PATH: envAsString(env['SOCKET_CLI_NPM_PATH']),
431433
// Specify the Socket organization slug.
432434
SOCKET_CLI_ORG_SLUG:
433-
envAsString(processEnv['SOCKET_CLI_ORG_SLUG']) ||
435+
envAsString(env['SOCKET_CLI_ORG_SLUG']) ||
434436
// Coana CLI accepts the SOCKET_ORG_SLUG environment variable.
435-
envAsString(processEnv['SOCKET_ORG_SLUG']),
437+
envAsString(env['SOCKET_ORG_SLUG']),
436438
// View all risks of a Socket wrapped npm/npx run.
437439
SOCKET_CLI_VIEW_ALL_RISKS: envAsBoolean(
438-
processEnv[SOCKET_CLI_VIEW_ALL_RISKS],
440+
env[SOCKET_CLI_VIEW_ALL_RISKS],
439441
),
440442
// Specifies the type of terminal or terminal emulator being used by the process.
441-
TERM: envAsString(processEnv['TERM']),
443+
TERM: envAsString(env['TERM']),
442444
// The location of the base directory on Linux and MacOS used to store
443445
// user-specific data files, defaulting to $HOME/.local/share if not set or empty.
444-
XDG_DATA_HOME: envAsString(processEnv['XDG_DATA_HOME']),
446+
XDG_DATA_HOME: envAsString(env['XDG_DATA_HOME']),
445447
})
446448
}
447449

0 commit comments

Comments
 (0)