Skip to content

Commit cdfae52

Browse files
committed
Use more constants
1 parent b825c59 commit cdfae52

File tree

4 files changed

+25
-10
lines changed

4 files changed

+25
-10
lines changed

.config/rollup.base.config.mjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import {
2929
} from '../scripts/utils/packages.js'
3030

3131
const {
32+
BABEL_RUNTIME,
3233
LATEST,
3334
ROLLUP_ENTRY_SUFFIX,
3435
ROLLUP_EXTERNAL_SUFFIX,
@@ -140,7 +141,7 @@ export default function baseConfig(extendConfig = {}) {
140141
return true
141142
}
142143
if (
143-
name === '@babel/runtime' ||
144+
name === BABEL_RUNTIME ||
144145
id.startsWith(rootSrcPath) ||
145146
id.endsWith('.mjs') ||
146147
id.endsWith('.mts') ||

.config/rollup.dist.config.mjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
} from '../scripts/utils/packages.js'
2222

2323
const {
24+
BABEL_RUNTIME,
2425
ROLLUP_EXTERNAL_SUFFIX,
2526
depStatsPath,
2627
rootDistPath,
@@ -110,7 +111,7 @@ export default () => {
110111
const id = normalizeId(id_)
111112
const name = getPackageName(id)
112113
if (
113-
name === '@babel/runtime' ||
114+
name === BABEL_RUNTIME ||
114115
id.startsWith(rootSrcPath) ||
115116
id.endsWith('.mjs') ||
116117
id.endsWith('.mts') ||

.config/rollup.test.config.mjs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ import {
99
normalizeId
1010
} from '../scripts/utils/packages.js'
1111

12-
const { ROLLUP_EXTERNAL_SUFFIX, SUPPORTS_SYNC_ESM, rootSrcPath } = constants
12+
const {
13+
BABEL_RUNTIME,
14+
ROLLUP_EXTERNAL_SUFFIX,
15+
SUPPORTS_SYNC_ESM,
16+
rootSrcPath
17+
} = constants
1318

1419
export default () =>
1520
baseConfig({
@@ -36,7 +41,7 @@ export default () =>
3641
const id = normalizeId(id_)
3742
const name = getPackageName(id)
3843
if (
39-
name === '@babel/runtime' ||
44+
name === BABEL_RUNTIME ||
4045
id.startsWith(rootSrcPath) ||
4146
id.endsWith('.mjs') ||
4247
id.endsWith('.mts') ||

src/constants.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,16 @@ type RegistryEnv = typeof registryConstants.ENV
88

99
type Constants = {
1010
readonly API_V0_URL: 'https://api.socket.dev/v0'
11+
readonly BABEL_RUNTIME: '@babel/runtime'
12+
readonly CDXGEN: 'cdxgen'
13+
readonly CYCLONEDX_CDXGEN: '@cyclonedx/cdxgen'
1114
readonly ENV: RegistryEnv & {
1215
UPDATE_SOCKET_OVERRIDES_IN_PACKAGE_LOCK_FILE: boolean
1316
}
1417
readonly DIST_TYPE: 'module-sync' | 'require'
1518
readonly NPM_REGISTRY_URL: 'https://registry.npmjs.org'
1619
readonly SOCKET_CLI_ISSUES_URL: 'https://github.com/SocketDev/socket-cli/issues'
20+
readonly SYNP: 'synp'
1721
readonly UPDATE_SOCKET_OVERRIDES_IN_PACKAGE_LOCK_FILE: 'UPDATE_SOCKET_OVERRIDES_IN_PACKAGE_LOCK_FILE'
1822
readonly cdxgenBinPath: string
1923
readonly distPath: string
@@ -35,14 +39,14 @@ const {
3539
} = registryConstants
3640

3741
const API_V0_URL = 'https://api.socket.dev/v0'
38-
42+
const BABEL_RUNTIME = '@babel/runtime'
43+
const CDXGEN = 'cdxgen'
44+
const CYCLONEDX_CDXGEN = `@cyclonedx/${CDXGEN}`
3945
const NPM_REGISTRY_URL = 'https://registry.npmjs.org'
40-
4146
const SOCKET_CLI_ISSUES_URL = 'https://github.com/SocketDev/socket-cli/issues'
42-
47+
const SYNP = 'synp'
4348
const UPDATE_SOCKET_OVERRIDES_IN_PACKAGE_LOCK_FILE =
4449
'UPDATE_SOCKET_OVERRIDES_IN_PACKAGE_LOCK_FILE'
45-
4650
const ENV: Constants['ENV'] = Object.freeze({
4751
...registryConstants.ENV,
4852
// Flag set by the optimize command to bypass the packagesHaveRiskyIssues check.
@@ -56,9 +60,9 @@ const rootDistPath = path.join(rootPath, 'dist')
5660
const rootBinPath = path.join(rootPath, 'bin')
5761
const rootPkgJsonPath = path.join(rootPath, PACKAGE_JSON)
5862
const nmBinPath = path.join(rootPath, 'node_modules/.bin')
59-
const cdxgenBinPath = path.join(nmBinPath, 'cdxgen')
63+
const cdxgenBinPath = path.join(nmBinPath, CDXGEN)
6064
const shadowBinPath = path.join(rootPath, 'shadow-bin')
61-
const synpBinPath = path.join(nmBinPath, 'synp')
65+
const synpBinPath = path.join(nmBinPath, SYNP)
6266

6367
const LAZY_DIST_TYPE = () =>
6468
registryConstants.SUPPORTS_NODE_REQUIRE_MODULE ? 'module-sync' : 'require'
@@ -68,11 +72,15 @@ const lazyDistPath = () => path.join(rootDistPath, constants.DIST_TYPE)
6872
const constants = <Constants>createConstantsObject(
6973
{
7074
API_V0_URL,
75+
BABEL_RUNTIME,
76+
CDXGEN,
77+
CYCLONEDX_CDXGEN,
7178
ENV,
7279
// Lazily defined values are initialized as `undefined` to keep their key order.
7380
DIST_TYPE: undefined,
7481
NPM_REGISTRY_URL,
7582
SOCKET_CLI_ISSUES_URL,
83+
SYNP,
7684
UPDATE_SOCKET_OVERRIDES_IN_PACKAGE_LOCK_FILE,
7785
cdxgenBinPath,
7886
distPath: undefined,

0 commit comments

Comments
 (0)