Skip to content

Commit a8b89cf

Browse files
committed
Cleanup more dependencies
1 parent 6ac9826 commit a8b89cf

File tree

7 files changed

+33
-100
lines changed

7 files changed

+33
-100
lines changed

.config/rollup.base.config.mjs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,18 @@ import { purgePolyfills } from 'unplugin-purge-polyfills'
1212

1313
import { isRelative } from '@socketsecurity/registry/lib/path'
1414
import { escapeRegExp } from '@socketsecurity/registry/lib/regexps'
15+
import {
16+
isValidPackageName,
17+
readPackageJsonSync
18+
} from '@socketsecurity/registry/lib/packages'
1519

1620
import socketModifyPlugin from '../scripts/rollup/socket-modify-plugin.js'
1721
import {
1822
getPackageName,
1923
getPackageNameEnd,
2024
isEsmId,
2125
normalizeId,
22-
isPackageName,
2326
isBuiltin,
24-
readPackageJsonSync,
2527
resolveId
2628
} from '../scripts/utils/packages.js'
2729

@@ -106,7 +108,7 @@ export default (extendConfig = {}) => {
106108
return isAncestorsCjs(resolvedId, parentId)
107109
}
108110
const name = getPackageName(id)
109-
if (!isPackageName(name) || name === '@babel/runtime') {
111+
if (!isValidPackageName(name) || name === '@babel/runtime') {
110112
return false
111113
}
112114
if (isEsmId(resolvedId, parentId)) {
@@ -202,7 +204,7 @@ export default (extendConfig = {}) => {
202204
replace: ''
203205
}),
204206
// Fix incorrectly set "spinners" binding caused by a transpilation bug
205-
// https://github.com/sindresorhus/ora/blob/v8.1.0/index.js#L415
207+
// https://github.com/sindresorhus/ora/blob/v8.1.1/index.js#L424
206208
// export {default as spinners} from 'cli-spinners'
207209
socketModifyPlugin({
208210
find: /(?<=ora[^.]+\.spinners\s*=\s*)[$\w]+/g,

.config/rollup.dist.config.mjs

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import { chmodSync, readFileSync, writeFileSync } from 'node:fs'
1+
import { chmodSync, writeFileSync } from 'node:fs'
22
import path from 'node:path'
33
import { fileURLToPath } from 'node:url'
44

5-
import { hasKeys, toSortedObject } from '@socketsecurity/registry/lib/objects'
5+
import { toSortedObject } from '@socketsecurity/registry/lib/objects'
6+
import { readPackageJsonSync } from '@socketsecurity/registry/lib/packages'
67

78
import baseConfig from './rollup.base.config.mjs'
89
import { readJsonSync } from '../scripts/utils/fs.js'
910
import { formatObject } from '../scripts/utils/objects.js'
10-
import { readPackageJsonSync } from '../scripts/utils/packages.js'
1111

1212
const __dirname = fileURLToPath(new URL('.', import.meta.url))
1313

@@ -16,8 +16,7 @@ const depStatsPath = path.join(rootPath, '.dep-stats.json')
1616
const distPath = path.join(rootPath, 'dist')
1717
const srcPath = path.join(rootPath, 'src')
1818

19-
const pkgJsonPath = path.resolve(rootPath, 'package.json')
20-
const pkgJson = readPackageJsonSync(pkgJsonPath)
19+
const editablePkgJson = readPackageJsonSync(rootPath, { editable: true })
2120

2221
export default () => {
2322
const config = baseConfig({
@@ -40,6 +39,7 @@ export default () => {
4039
plugins: [
4140
{
4241
writeBundle() {
42+
const { content: pkgJson } = editablePkgJson
4343
const { '@cyclonedx/cdxgen': cdxgenRange, synp: synpRange } =
4444
pkgJson.dependencies
4545
const { depStats } = config.meta
@@ -71,28 +71,19 @@ export default () => {
7171

7272
// Write dep stats
7373
writeFileSync(depStatsPath, `${formatObject(depStats)}\n`, 'utf8')
74-
7574
// Make dist files chmod +x
7675
chmodSync(path.join(distPath, 'cli.js'), 0o755)
7776
chmodSync(path.join(distPath, 'npm-cli.js'), 0o755)
7877
chmodSync(path.join(distPath, 'npx-cli.js'), 0o755)
79-
8078
// Update dependencies with additional inlined modules
81-
writeFileSync(
82-
pkgJsonPath,
83-
readFileSync(pkgJsonPath, 'utf8').replace(
84-
/(?<="dependencies":\s*)\{[^\}]*\}/,
85-
() => {
86-
const deps = {
87-
...depStats.dependencies,
88-
...depStats.transitives
89-
}
90-
const formatted = formatObject(deps, 4)
91-
return hasKeys(deps) ? formatted.replace('}', ' }') : formatted
79+
editablePkgJson
80+
.update({
81+
dependencies: {
82+
...depStats.dependencies,
83+
...depStats.transitives
9284
}
93-
),
94-
'utf8'
95-
)
85+
})
86+
.saveSync()
9687
}
9788
}
9889
]

.dep-stats.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"@npmcli/promise-spawn": "^8.0.2",
77
"@socketregistry/hyrious__bun.lockb": "1.0.4",
88
"@socketsecurity/config": "^2.1.3",
9-
"@socketsecurity/registry": "^1.0.22",
9+
"@socketsecurity/registry": "^1.0.25",
1010
"@socketsecurity/sdk": "^1.3.0",
1111
"blessed": "^0.1.81",
1212
"blessed-contrib": "^4.11.0",
@@ -64,7 +64,7 @@
6464
"@npmcli/promise-spawn": "^8.0.2",
6565
"@socketregistry/hyrious__bun.lockb": "1.0.4",
6666
"@socketsecurity/config": "^2.1.3",
67-
"@socketsecurity/registry": "^1.0.22",
67+
"@socketsecurity/registry": "^1.0.25",
6868
"@socketsecurity/sdk": "^1.3.0",
6969
"blessed": "^0.1.81",
7070
"blessed-contrib": "^4.11.0",

package-lock.json

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

package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"@npmcli/promise-spawn": "^8.0.2",
4646
"@socketregistry/hyrious__bun.lockb": "1.0.4",
4747
"@socketsecurity/config": "^2.1.3",
48-
"@socketsecurity/registry": "^1.0.22",
48+
"@socketsecurity/registry": "^1.0.25",
4949
"@socketsecurity/sdk": "^1.3.0",
5050
"blessed": "^0.1.81",
5151
"blessed-contrib": "^4.11.0",
@@ -115,7 +115,6 @@
115115
"meow": "^13.2.0",
116116
"mock-fs": "^5.4.1",
117117
"nock": "^13.5.5",
118-
"normalize-package-data": "^7.0.0",
119118
"npm-run-all2": "^7.0.1",
120119
"open": "^10.1.0",
121120
"ora": "^8.1.1",
@@ -130,8 +129,7 @@
130129
"type-coverage": "^2.29.7",
131130
"typescript": "5.4.5",
132131
"typescript-eslint": "^8.13.0",
133-
"unplugin-purge-polyfills": "^0.0.7",
134-
"validate-npm-package-name": "^6.0.0"
132+
"unplugin-purge-polyfills": "^0.0.7"
135133
},
136134
"overrides": {
137135
"aggregate-error": "npm:@socketregistry/aggregate-error@^1",

scripts/utils/packages.js

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ const Module = require('node:module')
55
const path = require('node:path')
66
const vm = require('node:vm')
77

8-
const normalizePackageData = require('normalize-package-data')
9-
const validatePackageName = require('validate-npm-package-name')
10-
8+
const { isValidPackageName } = require('@socketsecurity/registry/lib/packages')
119
const {
1210
isRelative,
1311
normalizePath
@@ -17,8 +15,6 @@ const { findUpSync } = require('./fs')
1715

1816
const { createRequire, isBuiltin } = Module
1917

20-
const PACKAGE_JSON = 'package.json'
21-
2218
// eslint-disable-next-line no-control-regex
2319
const cjsPluginPrefixRegExp = /^\x00/
2420
const cjsPluginSuffixRegExp =
@@ -65,17 +61,13 @@ function resolveId(id_, req = require) {
6561
if (resolvedId === undefined) {
6662
resolvedId = id
6763
}
68-
if (isPackageName(id)) {
64+
if (isValidPackageName(id)) {
6965
return resolvedId
7066
}
7167
const tsId = `${resolvedId}.ts`
7268
return fs.existsSync(tsId) ? tsId : resolvedId
7369
}
7470

75-
function isPackageName(id) {
76-
return validatePackageName(id).validForOldPackages
77-
}
78-
7971
function isEsmId(id_, parentId_) {
8072
if (isBuiltin(id_)) {
8173
return false
@@ -131,26 +123,11 @@ function normalizeId(id) {
131123
.replace(cjsPluginSuffixRegExp, '')
132124
}
133125

134-
function normalizePackageJson(pkgJson) {
135-
normalizePackageData(pkgJson)
136-
return pkgJson
137-
}
138-
139-
function readPackageJsonSync(filepath_) {
140-
const filepath = filepath_.endsWith(PACKAGE_JSON)
141-
? filepath_
142-
: path.join(filepath_, PACKAGE_JSON)
143-
return normalizePackageJson(JSON.parse(fs.readFileSync(filepath, 'utf8')))
144-
}
145-
146126
module.exports = {
147127
isBuiltin,
148128
isEsmId,
149-
isPackageName,
150129
getPackageName,
151130
getPackageNameEnd,
152131
normalizeId,
153-
normalizePackageJson,
154-
readPackageJsonSync,
155132
resolveId
156133
}

src/commands/optimize.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ import {
1515
isObject,
1616
toSortedObject
1717
} from '@socketsecurity/registry/lib/objects'
18-
import { fetchPackageManifest, readPackageJson } from '@socketsecurity/registry/lib/packages'
18+
import {
19+
fetchPackageManifest,
20+
readPackageJson
21+
} from '@socketsecurity/registry/lib/packages'
1922
import { pEach } from '@socketsecurity/registry/lib/promises'
2023
import { escapeRegExp } from '@socketsecurity/registry/lib/regexps'
2124
import { isNonEmptyString } from '@socketsecurity/registry/lib/strings'

0 commit comments

Comments
 (0)