Skip to content

Commit 1b03ba8

Browse files
committed
Merge branch 'main' into vitest_poc
2 parents 9bb8515 + bbb426c commit 1b03ba8

File tree

9 files changed

+78
-74
lines changed

9 files changed

+78
-74
lines changed

.config/rollup.base.config.mjs

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,8 @@ const requireUrlAssignmentRegExp =
7575
const splitUrlRequiresRegExp = /require\(["']u["']\s*\+\s*["']rl["']\)/g
7676

7777
function isAncestorsExternal(id, depStats) {
78-
const { rootPackageJsonPath } = constants
79-
80-
const { dependencies: pkgDeps } = require(rootPackageJsonPath)
81-
78+
// Lazily access constants.rootPackageJsonPath.
79+
const { dependencies: pkgDeps } = require(constants.rootPackageJsonPath)
8280
let currNmIndex = id.indexOf(SLASH_NODE_MODULES_SLASH)
8381
while (currNmIndex !== -1) {
8482
const nextNmIndex = id.indexOf(SLASH_NODE_MODULES_SLASH, currNmIndex + 1)
@@ -97,7 +95,7 @@ function isAncestorsExternal(id, depStats) {
9795
dependencies = {},
9896
optionalDependencies = {},
9997
peerDependencies = {}
100-
} = readPackageJsonSync(`${id.slice(0, nameEnd)}/package.json`)
98+
} = readPackageJsonSync(id.slice(0, nameEnd))
10199
const range =
102100
dependencies[name] ??
103101
optionalDependencies[name] ??
@@ -113,23 +111,17 @@ function isAncestorsExternal(id, depStats) {
113111
}
114112

115113
export default function baseConfig(extendConfig = {}) {
116-
// Lazily access constants props.
117-
const {
118-
babelConfigPath,
119-
rootPackageJsonPath,
120-
rootPath,
121-
rootSrcPath,
122-
tsconfigPath
123-
} = constants
124-
114+
// Lazily access constants.rootSrcPath.
115+
const { rootSrcPath } = constants
125116
const {
126117
dependencies: pkgDeps,
127118
devDependencies: pkgDevDeps,
128119
overrides: pkgOverrides
129-
} = require(rootPackageJsonPath)
130-
120+
// Lazily access constants.rootPackageJsonPath.
121+
} = require(constants.rootPackageJsonPath)
131122
const constantsSrcPath = path.join(rootSrcPath, `${CONSTANTS}.ts`)
132-
const babelConfig = require(babelConfigPath)
123+
// Lazily access constants.babelConfigPath.
124+
const babelConfig = require(constants.babelConfigPath)
133125
const tsPlugin = require('rollup-plugin-ts')
134126

135127
const depStats = {
@@ -197,9 +189,7 @@ export default function baseConfig(extendConfig = {}) {
197189
dependencies = {},
198190
optionalDependencies = {},
199191
peerDependencies = {}
200-
} = readPackageJsonSync(
201-
`${parentId.slice(0, parentNameEnd)}/package.json`
202-
)
192+
} = readPackageJsonSync(parentId.slice(0, parentNameEnd))
203193
const range =
204194
dependencies[name] ??
205195
optionalDependencies[name] ??
@@ -229,7 +219,8 @@ export default function baseConfig(extendConfig = {}) {
229219
transpileOnly: true,
230220
exclude: ['**/*.json'],
231221
babelConfig,
232-
tsconfig: tsconfigPath
222+
// Lazily access constants.tsconfigPath.
223+
tsconfig: constants.tsconfigPath
233224
}),
234225
purgePolyfills.rollup({
235226
replacements: {}
@@ -338,7 +329,8 @@ function ${SOCKET_INTEROP}(e) {
338329
delimiters: ['(?<=["\'])', '/'],
339330
preventAssignment: false,
340331
values: {
341-
[rootPath]: '../../'
332+
// Lazily access constants.rootPath.
333+
[constants.rootPath]: '../../'
342334
}
343335
})
344336
return { name, renderChunk }

.config/rollup.dist.config.mjs

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,29 +29,31 @@ import {
2929

3030
const {
3131
BABEL_RUNTIME,
32+
CLI,
3233
CONSTANTS,
34+
INSTRUMENT_WITH_SENTRY,
3335
MODULE_SYNC,
3436
NPM_INJECTION,
3537
REQUIRE,
3638
ROLLUP_EXTERNAL_SUFFIX,
3739
SHADOW_BIN,
40+
SOCKET,
3841
SOCKET_CLI_LEGACY_BUILD,
3942
SOCKET_CLI_PUBLISHED_BUILD,
4043
SOCKET_CLI_SENTRY_BUILD,
4144
SOCKET_CLI_VERSION_HASH,
4245
VENDOR,
4346
VITEST,
47+
WITH_SENTRY,
4448
depStatsPath,
4549
rootDistPath,
4650
rootPackageLockPath,
4751
rootPath,
4852
rootSrcPath
4953
} = constants
5054

51-
const WITH_SENTRY = 'with-sentry'
52-
const INSTRUMENT_WITH_SENTRY = `instrument-${WITH_SENTRY}`
55+
const CLI_WITH_SENTRY = `${CLI}-${WITH_SENTRY}`
5356
const SENTRY_NODE = '@sentry/node'
54-
const SOCKET = 'socket'
5557
const SOCKET_DESCRIPTION = 'CLI tool for Socket.dev'
5658
const SOCKET_DESCRIPTION_WITH_SENTRY = `${SOCKET_DESCRIPTION}, includes Sentry error handling, otherwise identical to the regular \`${SOCKET}\` package`
5759
const SOCKET_NPM = 'socket-npm'
@@ -153,12 +155,12 @@ async function removeJsFiles(namePattern, srcPath) {
153155

154156
function resetBin(bin) {
155157
const tmpBin = {
156-
socket: bin?.[SOCKET] ?? bin?.[SOCKET_WITH_SENTRY],
158+
[SOCKET]: bin?.[SOCKET] ?? bin?.[SOCKET_WITH_SENTRY],
157159
[SOCKET_NPM]: bin?.[SOCKET_NPM] ?? bin?.[SOCKET_NPM_WITH_SENTRY],
158160
[SOCKET_NPX]: bin?.[SOCKET_NPX] ?? bin?.[SOCKET_NPX_WITH_SENTRY]
159161
}
160162
const newBin = {
161-
...(tmpBin[SOCKET] ? { socket: tmpBin.socket } : {}),
163+
...(tmpBin[SOCKET] ? { [SOCKET]: tmpBin.socket } : {}),
162164
...(tmpBin[SOCKET_NPM] ? { [SOCKET_NPM]: tmpBin[SOCKET_NPM] } : {}),
163165
...(tmpBin[SOCKET_NPX] ? { [SOCKET_NPX]: tmpBin[SOCKET_NPX] } : {})
164166
}
@@ -243,12 +245,8 @@ async function updatePackageJson() {
243245
editablePkgJson.update({
244246
name: SOCKET_SECURITY_CLI,
245247
bin: {
246-
cli: bin.socket,
248+
[CLI]: bin[SOCKET],
247249
...bin
248-
},
249-
dependencies: {
250-
...dependencies,
251-
[SENTRY_NODE]: (await getSentryManifest()).version
252250
}
253251
})
254252
}
@@ -258,7 +256,8 @@ async function updatePackageJson() {
258256
name: SOCKET_SECURITY_CLI_WITH_SENTRY,
259257
description: SOCKET_DESCRIPTION_WITH_SENTRY,
260258
bin: {
261-
[SOCKET_WITH_SENTRY]: bin.socket,
259+
[CLI_WITH_SENTRY]: bin[SOCKET],
260+
[SOCKET_WITH_SENTRY]: bin[SOCKET],
262261
[SOCKET_NPM_WITH_SENTRY]: bin[SOCKET_NPM],
263262
[SOCKET_NPX_WITH_SENTRY]: bin[SOCKET_NPX]
264263
},
@@ -289,14 +288,20 @@ async function updatePackageLockFile() {
289288
lockJson.name = SOCKET_SECURITY_CLI
290289
rootPkg.name = SOCKET_SECURITY_CLI
291290
rootPkg.bin = toSortedObject({
292-
cli: bin.socket,
291+
[CLI]: bin[SOCKET],
293292
...bin
294293
})
295294
}
296295
// Lazily access constants.ENV[SOCKET_CLI_SENTRY_BUILD].
297296
else if (constants.ENV[SOCKET_CLI_SENTRY_BUILD]) {
298297
lockJson.name = SOCKET_SECURITY_CLI_WITH_SENTRY
299298
rootPkg.name = SOCKET_SECURITY_CLI_WITH_SENTRY
299+
rootPkg.bin = {
300+
[CLI_WITH_SENTRY]: bin[SOCKET],
301+
[SOCKET_WITH_SENTRY]: bin[SOCKET],
302+
[SOCKET_NPM_WITH_SENTRY]: bin[SOCKET_NPM],
303+
[SOCKET_NPX_WITH_SENTRY]: bin[SOCKET_NPX]
304+
}
300305
rootPkg.dependencies = toSortedObject({
301306
...dependencies,
302307
[SENTRY_NODE]: (await getSentryManifest()).version

.dep-stats.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"@socketregistry/is-unicode-supported": "^1.0.0",
1111
"@socketregistry/packageurl-js": "^1.0.2",
1212
"@socketsecurity/config": "^2.1.3",
13-
"@socketsecurity/registry": "^1.0.90",
13+
"@socketsecurity/registry": "^1.0.93",
1414
"@socketsecurity/sdk": "^1.4.5",
1515
"blessed": "^0.1.81",
1616
"blessed-contrib": "^4.11.0",

package-lock.json

Lines changed: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "socket",
3-
"version": "0.14.43",
3+
"version": "0.14.46",
44
"description": "CLI tool for Socket.dev",
55
"homepage": "http://github.com/SocketDev/socket-cli",
66
"license": "MIT",
@@ -36,8 +36,8 @@
3636
},
3737
"scripts": {
3838
"build": "run-s build:*",
39-
"build:dist": "rollup -c .config/rollup.dist.config.mjs",
40-
"build:test": "rollup -c .config/rollup.test.config.mjs",
39+
"build:dist": "del-cli 'dist' && rollup -c .config/rollup.dist.config.mjs",
40+
"build:test": "del-cli 'test/dist' && rollup -c .config/rollup.test.config.mjs",
4141
"check": "run-p -c --aggregate-output check:*",
4242
"check:lint": "eslint --report-unused-disable-directives .",
4343
"check:lint:fix": "npm run check:lint -- --fix",
@@ -75,7 +75,7 @@
7575
"@socketregistry/is-unicode-supported": "^1.0.0",
7676
"@socketregistry/packageurl-js": "^1.0.2",
7777
"@socketsecurity/config": "^2.1.3",
78-
"@socketsecurity/registry": "^1.0.90",
78+
"@socketsecurity/registry": "^1.0.93",
7979
"@socketsecurity/sdk": "^1.4.5",
8080
"blessed": "^0.1.81",
8181
"blessed-contrib": "^4.11.0",
@@ -147,7 +147,7 @@
147147
"eslint-plugin-sort-destructure-keys": "^2.0.0",
148148
"eslint-plugin-unicorn": "^56.0.1",
149149
"husky": "^9.1.7",
150-
"knip": "^5.44.5",
150+
"knip": "^5.45.0",
151151
"lint-staged": "^15.4.3",
152152
"magic-string": "^0.30.17",
153153
"mock-fs": "^5.5.0",

scripts/constants.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,18 @@ const {
1212
[kInternalsSymbol]: { createConstantsObject }
1313
} = registryConstants
1414

15+
const WITH_SENTRY = 'with-sentry'
1516
const CLI = 'cli'
1617
const CONSTANTS = 'constants'
18+
const INSTRUMENT_WITH_SENTRY = `instrument-${WITH_SENTRY}`
1719
const MODULE_SYNC = 'module-sync'
1820
const NPM_INJECTION = 'npm-injection'
1921
const REQUIRE = 'require'
2022
const ROLLUP_ENTRY_SUFFIX = '?commonjs-entry'
2123
const ROLLUP_EXTERNAL_SUFFIX = '?commonjs-external'
2224
const SHADOW_BIN = 'shadow-bin'
2325
const SLASH_NODE_MODULES_SLASH = '/node_modules/'
26+
const SOCKET = 'socket'
2427
const SOCKET_CLI_LEGACY_BUILD = 'SOCKET_CLI_LEGACY_BUILD'
2528
const SOCKET_CLI_PUBLISHED_BUILD = 'SOCKET_CLI_PUBLISHED_BUILD'
2629
const SOCKET_CLI_SENTRY_BUILD = 'SOCKET_CLI_SENTRY_BUILD'
@@ -83,19 +86,22 @@ const constants = createConstantsObject(
8386
CLI,
8487
CONSTANTS,
8588
ENV: undefined,
89+
INSTRUMENT_WITH_SENTRY,
8690
MODULE_SYNC,
8791
NPM_INJECTION,
8892
REQUIRE,
8993
ROLLUP_ENTRY_SUFFIX,
9094
ROLLUP_EXTERNAL_SUFFIX,
9195
SHADOW_BIN,
9296
SLASH_NODE_MODULES_SLASH,
97+
SOCKET,
9398
SOCKET_CLI_LEGACY_BUILD,
9499
SOCKET_CLI_PUBLISHED_BUILD,
95100
SOCKET_CLI_SENTRY_BUILD,
96101
SOCKET_CLI_VERSION_HASH,
97102
VENDOR,
98103
VITEST,
104+
WITH_SENTRY,
99105
babelConfigPath: undefined,
100106
depStatsPath: undefined,
101107
rootConfigPath: undefined,

src/cli.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ import { AuthError, InputError, captureException } from './utils/errors'
3535
import { getLogSymbols } from './utils/logging'
3636
import { meowWithSubcommands } from './utils/meow-with-subcommands'
3737

38-
const { rootPkgJsonPath } = constants
38+
const { SOCKET, rootPkgJsonPath } = constants
3939

4040
// TODO: Add autocompletion using https://socket.dev/npm/package/omelette
4141
void (async () => {
4242
await updateNotifier({
43-
name: 'socket',
43+
name: SOCKET,
4444
version: require(rootPkgJsonPath).version,
4545
ttl: 86_400_000 /* 24 hours in milliseconds */
4646
})
@@ -80,7 +80,7 @@ void (async () => {
8080
}
8181
},
8282
argv: process.argv.slice(2),
83-
name: 'socket',
83+
name: SOCKET,
8484
importMeta: { url: `${pathToFileURL(__filename)}` } as ImportMeta
8585
}
8686
)

src/constants.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { envAsBoolean } from '@socketsecurity/registry/lib/env'
88
import type { Remap } from '@socketsecurity/registry/lib/objects'
99

1010
const {
11+
NODE_MODULES,
1112
PACKAGE_JSON,
1213
kInternalsSymbol,
1314
[kInternalsSymbol as unknown as 'Symbol(kInternalsSymbol)']: {
@@ -79,6 +80,7 @@ type Constants = Remap<
7980
readonly PNPM: 'pnpm'
8081
readonly REQUIRE: 'require'
8182
readonly SHADOW_BIN: 'shadow-bin'
83+
readonly SOCKET: 'socket'
8284
readonly SOCKET_CLI_DEBUG: 'SOCKET_CLI_DEBUG'
8385
readonly SOCKET_CLI_FIX: 'SOCKET_CLI_FIX'
8486
readonly SOCKET_CLI_ISSUES_URL: 'https://github.com/SocketDev/socket-cli/issues'
@@ -127,6 +129,7 @@ const NPX = 'npx'
127129
const PNPM = 'pnpm'
128130
const REQUIRE = 'require'
129131
const SHADOW_BIN = 'shadow-bin'
132+
const SOCKET = 'socket'
130133
const SOCKET_CLI_DEBUG = 'SOCKET_CLI_DEBUG'
131134
const SOCKET_CLI_FIX = 'SOCKET_CLI_FIX'
132135
const SOCKET_CLI_ISSUES_URL = 'https://github.com/SocketDev/socket-cli/issues'
@@ -190,7 +193,7 @@ const lazyInstrumentWithSentryPath = () =>
190193

191194
const lazyNmBinPath = () =>
192195
// Lazily access constants.rootPath.
193-
path.join(constants.rootPath, 'node_modules/.bin')
196+
path.join(constants.rootPath, `${NODE_MODULES}/.bin`)
194197

195198
const lazyNpmInjectionPath = () =>
196199
// Lazily access constants.distPath.
@@ -250,6 +253,7 @@ const constants = <Constants>createConstantsObject(
250253
PNPM,
251254
REQUIRE,
252255
SHADOW_BIN,
256+
SOCKET,
253257
SOCKET_CLI_DEBUG,
254258
SOCKET_CLI_FIX,
255259
SOCKET_CLI_ISSUES_URL,

0 commit comments

Comments
 (0)