Skip to content

Commit

Permalink
Fix constants.ts d.ts generation
Browse files Browse the repository at this point in the history
  • Loading branch information
jdalton committed Dec 16, 2024
1 parent 1d97ed0 commit e6ff653
Showing 1 changed file with 24 additions and 20 deletions.
44 changes: 24 additions & 20 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,28 @@ import path from 'node:path'
import { envAsBoolean } from '@socketsecurity/registry/lib/env'
import registryConstants from '@socketsecurity/registry/lib/constants'

type RegistryEnv = typeof registryConstants.ENV

type Constants = {
readonly API_V0_URL: 'https://api.socket.dev/v0'
readonly ENV: RegistryEnv & {
UPDATE_SOCKET_OVERRIDES_IN_PACKAGE_LOCK_FILE: boolean
}
readonly DIST_TYPE: 'module-sync' | 'require'
readonly NPM_REGISTRY_URL: 'https://registry.npmjs.org'
readonly SOCKET_CLI_ISSUES_URL: 'https://github.com/SocketDev/socket-cli/issues'
readonly UPDATE_SOCKET_OVERRIDES_IN_PACKAGE_LOCK_FILE: 'UPDATE_SOCKET_OVERRIDES_IN_PACKAGE_LOCK_FILE'
readonly cdxgenBinPath: string
readonly distPath: string
readonly nmBinPath: string
readonly rootBinPath: string
readonly rootDistPath: string
readonly rootPath: string
readonly rootPkgJsonPath: string
readonly shadowBinPath: string
readonly synpBinPath: string
} & typeof registryConstants

const {
kInternalsSymbol,
PACKAGE_JSON,
Expand All @@ -21,7 +43,7 @@ const SOCKET_CLI_ISSUES_URL = 'https://github.com/SocketDev/socket-cli/issues'
const UPDATE_SOCKET_OVERRIDES_IN_PACKAGE_LOCK_FILE =
'UPDATE_SOCKET_OVERRIDES_IN_PACKAGE_LOCK_FILE'

const ENV = Object.freeze({
const ENV: Constants['ENV'] = Object.freeze({
...registryConstants.ENV,
// Flag set by the optimize command to bypass the packagesHaveRiskyIssues check.
[UPDATE_SOCKET_OVERRIDES_IN_PACKAGE_LOCK_FILE]: envAsBoolean(
Expand All @@ -43,25 +65,7 @@ const LAZY_DIST_TYPE = () =>

const lazyDistPath = () => path.join(rootDistPath, constants.DIST_TYPE)

const constants = <
{
readonly API_V0_URL: 'https://api.socket.dev/v0'
readonly ENV: typeof ENV
readonly DIST_TYPE: 'module-sync' | 'require'
readonly NPM_REGISTRY_URL: 'https://registry.npmjs.org'
readonly SOCKET_CLI_ISSUES_URL: 'https://github.com/SocketDev/socket-cli/issues'
readonly UPDATE_SOCKET_OVERRIDES_IN_PACKAGE_LOCK_FILE: 'UPDATE_SOCKET_OVERRIDES_IN_PACKAGE_LOCK_FILE'
readonly cdxgenBinPath: string
readonly distPath: string
readonly nmBinPath: string
readonly rootBinPath: string
readonly rootDistPath: string
readonly rootPath: string
readonly rootPkgJsonPath: string
readonly shadowBinPath: string
readonly synpBinPath: string
} & typeof registryConstants
>createConstantsObject(
const constants = <Constants>createConstantsObject(
{
API_V0_URL,
ENV,
Expand Down

0 comments on commit e6ff653

Please sign in to comment.