Skip to content

Commit da3e497

Browse files
committed
Use more @socketsecurity/registry
1 parent e466fac commit da3e497

File tree

6 files changed

+55
-193
lines changed

6 files changed

+55
-193
lines changed

.dep-stats.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"@npmcli/promise-spawn": "^8.0.2",
88
"@socketregistry/hyrious__bun.lockb": "1.0.4",
99
"@socketsecurity/config": "^2.1.3",
10-
"@socketsecurity/registry": "^1.0.14",
10+
"@socketsecurity/registry": "^1.0.16",
1111
"@socketsecurity/sdk": "^1.3.0",
1212
"blessed": "^0.1.81",
1313
"blessed-contrib": "^4.11.0",
@@ -17,7 +17,6 @@
1717
"ignore": "^6.0.2",
1818
"micromatch": "^4.0.8",
1919
"npm-package-arg": "^12.0.0",
20-
"pacote": "^20.0.0",
2120
"pony-cause": "^2.1.11",
2221
"semver": "^7.6.3",
2322
"synp": "^1.9.13",
@@ -86,7 +85,7 @@
8685
"@npmcli/promise-spawn": "^8.0.2",
8786
"@socketregistry/hyrious__bun.lockb": "1.0.4",
8887
"@socketsecurity/config": "^2.1.3",
89-
"@socketsecurity/registry": "^1.0.14",
88+
"@socketsecurity/registry": "^1.0.16",
9089
"@socketsecurity/sdk": "^1.3.0",
9190
"blessed": "^0.1.81",
9291
"blessed-contrib": "^4.11.0",
@@ -98,7 +97,6 @@
9897
"ini": "4.1.1",
9998
"micromatch": "^4.0.8",
10099
"npm-package-arg": "^12.0.0",
101-
"pacote": "^20.0.0",
102100
"pony-cause": "^2.1.11",
103101
"semver": "^7.6.3",
104102
"synp": "^1.9.13",

package-lock.json

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

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
"@npmcli/promise-spawn": "^8.0.2",
4747
"@socketregistry/hyrious__bun.lockb": "1.0.4",
4848
"@socketsecurity/config": "^2.1.3",
49-
"@socketsecurity/registry": "^1.0.14",
49+
"@socketsecurity/registry": "^1.0.16",
5050
"@socketsecurity/sdk": "^1.3.0",
5151
"blessed": "^0.1.81",
5252
"blessed-contrib": "^4.11.0",
@@ -58,7 +58,6 @@
5858
"ini": "4.1.1",
5959
"micromatch": "^4.0.8",
6060
"npm-package-arg": "^12.0.0",
61-
"pacote": "^20.0.0",
6261
"pony-cause": "^2.1.11",
6362
"semver": "^7.6.3",
6463
"synp": "^1.9.13",

src/commands/optimize.ts

Lines changed: 13 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,11 @@ import { getManifestData } from '@socketsecurity/registry'
88
import meow from 'meow'
99
import npa from 'npm-package-arg'
1010
import ora from 'ora'
11-
import pacote from 'pacote'
1211
import semver from 'semver'
1312
import { glob as tinyGlob } from 'tinyglobby'
1413
import { parse as yamlParse } from 'yaml'
1514

16-
//import { packumentCache, pacoteCachePath } from '../constants'
17-
import { packumentCache } from '../constants'
15+
import { fetchPackageManifest } from '@socketsecurity/registry/lib/packages'
1816
import { commonFlags } from '../flags'
1917
import { printFlagList } from '../utils/formatting'
2018
import { existsSync } from '../utils/fs'
@@ -24,10 +22,9 @@ import { pEach } from '@socketsecurity/registry/lib/promises'
2422
import { escapeRegExp } from '@socketsecurity/registry/lib/regexps'
2523
import { isNonEmptyString } from '@socketsecurity/registry/lib/strings'
2624

27-
import type { Content as PackageJsonContent } from '@npmcli/package-json'
25+
import type { Content as NPMCliPackageJson } from '@npmcli/package-json'
2826
import type { ManifestEntry } from '@socketsecurity/registry'
2927
import type { Ora } from 'ora'
30-
import type { PacoteOptions } from 'pacote'
3128
import type { CliSubcommand } from '../utils/meow-with-subcommands'
3229
import type {
3330
Agent,
@@ -45,42 +42,42 @@ const manifestNpmOverrides = getManifestData('npm')!
4542
type NpmOverrides = { [key: string]: string | StringKeyValueObject }
4643
type PnpmOrYarnOverrides = { [key: string]: string }
4744
type Overrides = NpmOverrides | PnpmOrYarnOverrides
48-
type GetOverrides = (pkgJson: PackageJsonContent) => GetOverridesResult
45+
type GetOverrides = (pkgJson: NPMCliPackageJson) => GetOverridesResult
4946
type GetOverridesResult = {
5047
type: Agent
5148
overrides: Overrides
5249
}
5350

5451
const getOverridesDataByAgent: Record<Agent, GetOverrides> = {
55-
bun(pkgJson: PackageJsonContent) {
52+
bun(pkgJson: NPMCliPackageJson) {
5653
const overrides = (pkgJson as any)?.resolutions ?? {}
5754
return { type: 'yarn/berry', overrides }
5855
},
5956
// npm overrides documentation:
6057
// https://docs.npmjs.com/cli/v10/configuring-npm/package-json#overrides
61-
npm(pkgJson: PackageJsonContent) {
58+
npm(pkgJson: NPMCliPackageJson) {
6259
const overrides = (pkgJson as any)?.overrides ?? {}
6360
return { type: 'npm', overrides }
6461
},
6562
// pnpm overrides documentation:
6663
// https://pnpm.io/package_json#pnpmoverrides
67-
pnpm(pkgJson: PackageJsonContent) {
64+
pnpm(pkgJson: NPMCliPackageJson) {
6865
const overrides = (pkgJson as any)?.pnpm?.overrides ?? {}
6966
return { type: 'pnpm', overrides }
7067
},
71-
vlt(pkgJson: PackageJsonContent) {
68+
vlt(pkgJson: NPMCliPackageJson) {
7269
const overrides = (pkgJson as any)?.overrides ?? {}
7370
return { type: 'vlt', overrides }
7471
},
7572
// Yarn resolutions documentation:
7673
// https://yarnpkg.com/configuration/manifest#resolutions
77-
'yarn/berry'(pkgJson: PackageJsonContent) {
74+
'yarn/berry'(pkgJson: NPMCliPackageJson) {
7875
const overrides = (pkgJson as any)?.resolutions ?? {}
7976
return { type: 'yarn/berry', overrides }
8077
},
8178
// Yarn resolutions documentation:
8279
// https://classic.yarnpkg.com/en/docs/selective-version-resolutions
83-
'yarn/classic'(pkgJson: PackageJsonContent) {
80+
'yarn/classic'(pkgJson: NPMCliPackageJson) {
8481
const overrides = (pkgJson as any)?.resolutions ?? {}
8582
return { type: 'yarn/classic', overrides }
8683
}
@@ -335,7 +332,7 @@ function createActionMessage(
335332
return `${verb} ${overrideCount} Socket.dev optimized overrides${workspaceCount ? ` in ${workspaceCount} workspace${workspaceCount > 1 ? 's' : ''}` : ''}`
336333
}
337334

338-
function getDependencyEntries(pkgJson: PackageJsonContent) {
335+
function getDependencyEntries(pkgJson: NPMCliPackageJson) {
339336
const {
340337
dependencies,
341338
devDependencies,
@@ -367,7 +364,7 @@ function getDependencyEntries(pkgJson: PackageJsonContent) {
367364
async function getWorkspaceGlobs(
368365
agent: Agent,
369366
pkgPath: string,
370-
pkgJson: PackageJsonContent
367+
pkgJson: NPMCliPackageJson
371368
): Promise<string[] | undefined> {
372369
let workspacePatterns
373370
if (agent === 'pnpm') {
@@ -471,7 +468,7 @@ async function addOverrides(
471468
editablePkgJson = await EditablePackageJson.load(pkgPath)
472469
}
473470
const { spinner } = state
474-
const pkgJson: Readonly<PackageJsonContent> = editablePkgJson.content
471+
const pkgJson: Readonly<NPMCliPackageJson> = editablePkgJson.content
475472
const isRoot = pkgPath === rootPath
476473
const isLockScanned = isRoot && !prod
477474
const workspaceName = path.relative(rootPath, pkgPath)
@@ -621,7 +618,7 @@ async function addOverrides(
621618
})
622619
}
623620
if (state.added.size > 0 || state.updated.size > 0) {
624-
editablePkgJson.update(<PackageJsonContent>Object.fromEntries(depEntries))
621+
editablePkgJson.update(<NPMCliPackageJson>Object.fromEntries(depEntries))
625622
for (const { overrides, type } of overridesDataObjects) {
626623
updateManifestByAgent[type](editablePkgJson, toSortedObject(overrides))
627624
}
@@ -630,61 +627,6 @@ async function addOverrides(
630627
return state
631628
}
632629

633-
// type ExtractOptions = pacote.Options & {
634-
// tmpPrefix?: string
635-
// [key: string]: any
636-
// }
637-
638-
// async function extractPackage(pkgNameOrId: string, options: ExtractOptions | undefined, callback: (tmpDirPath: string) => any) {
639-
// if (arguments.length === 2 && typeof options === 'function') {
640-
// callback = options
641-
// options = undefined
642-
// }
643-
// const { tmpPrefix, ...extractOptions } = { __proto__: null, ...options }
644-
// // cacache.tmp.withTmp DOES return a promise.
645-
// await cacache.tmp.withTmp(
646-
// pacoteCachePath,
647-
// { tmpPrefix },
648-
// // eslint-disable-next-line @typescript-eslint/no-misused-promises
649-
// async tmpDirPath => {
650-
// await pacote.extract(pkgNameOrId, tmpDirPath, {
651-
// __proto__: null,
652-
// packumentCache,
653-
// preferOffline: true,
654-
// ...<Omit<typeof extractOptions, '__proto__'>>extractOptions
655-
// })
656-
// await callback(tmpDirPath)
657-
// }
658-
// )
659-
// }
660-
661-
type FetchPackageManifestOptions = {
662-
signal?: AbortSignal
663-
}
664-
665-
async function fetchPackageManifest(
666-
pkgNameOrId: string,
667-
options?: FetchPackageManifestOptions
668-
) {
669-
const pacoteOptions = <PacoteOptions & { signal?: AbortSignal }>{
670-
...options,
671-
packumentCache,
672-
preferOffline: true
673-
}
674-
const { signal } = pacoteOptions
675-
if (signal?.aborted) {
676-
return null
677-
}
678-
let result
679-
try {
680-
result = await pacote.manifest(pkgNameOrId, pacoteOptions)
681-
} catch {}
682-
if (signal?.aborted) {
683-
return null
684-
}
685-
return result
686-
}
687-
688630
export const optimize: CliSubcommand = {
689631
description: 'Optimize dependencies with @socketregistry overrides',
690632
async run(argv, importMeta, { parentName }) {

0 commit comments

Comments
 (0)