Skip to content

Commit 99d18ff

Browse files
committed
Use socket-registry array and path helpers in update-data-npm script
Replace manual Set deduplication with arrayUnique helper and Node.js path module with socket-registry path helpers for consistency with project standards.
1 parent 1f35ca0 commit 99d18ff

File tree

1 file changed

+18
-19
lines changed

1 file changed

+18
-19
lines changed

scripts/update-data-npm.mjs

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import Module from 'node:module'
2-
import path from 'node:path'
32
import { fileURLToPath } from 'node:url'
43

54
import allThePackageNamesData from 'all-the-package-names/names.json' with {
@@ -12,23 +11,25 @@ import pacote from 'pacote'
1211
import semver from 'semver'
1312
import validateNpmPackageName from 'validate-npm-package-name'
1413

14+
import { arrayUnique } from '@socketsecurity/registry/lib/arrays'
1515
import constants from '@socketsecurity/registry/lib/constants'
1616
import { writeJson } from '@socketsecurity/registry/lib/fs'
1717
import { logger } from '@socketsecurity/registry/lib/logger'
18+
import { dirname, resolve } from '@socketsecurity/registry/lib/path'
1819
import { pFilter } from '@socketsecurity/registry/lib/promises'
1920
import { confirm } from '@socketsecurity/registry/lib/prompts'
2021
import { naturalCompare } from '@socketsecurity/registry/lib/sorts'
2122

2223
const { abortSignal } = constants
2324

2425
const __filename = fileURLToPath(import.meta.url)
25-
const __dirname = path.dirname(__filename)
26+
const __dirname = dirname(__filename)
2627

27-
const rootPath = path.resolve(__dirname, '..')
28-
const dataPath = path.join(rootPath, 'data')
29-
const npmDataPath = path.join(dataPath, 'npm')
30-
const npmBuiltinNamesJsonPath = path.join(npmDataPath, 'builtin-names.json')
31-
const npmLegacyNamesJsonPath = path.join(npmDataPath, 'legacy-names.json')
28+
const rootPath = resolve(__dirname, '..')
29+
const dataPath = resolve(rootPath, 'data')
30+
const npmDataPath = resolve(dataPath, 'npm')
31+
const npmBuiltinNamesJsonPath = resolve(npmDataPath, 'builtin-names.json')
32+
const npmLegacyNamesJsonPath = resolve(npmDataPath, 'legacy-names.json')
3233

3334
void (async () => {
3435
// Lazily access constants.spinner.
@@ -67,18 +68,16 @@ void (async () => {
6768
spinner.stop()
6869
return
6970
}
70-
const allThePackageNames = [
71-
...new Set([
72-
// Load the 43.1MB names.json file of '[email protected]'
73-
// which keeps the json file smaller while still covering the changes from:
74-
// https://blog.npmjs.org/post/168978377570/new-package-moniker-rules.html
75-
...allThePackageNamesData,
76-
// Load the 24.7MB names.json from '[email protected]',
77-
// the last v1 release, because it has different names resolved by
78-
// npm's replicate.npmjs.com service.
79-
...allThePackageNamesV1Data,
80-
]),
81-
]
71+
const allThePackageNames = arrayUnique([
72+
// Load the 43.1MB names.json file of '[email protected]'
73+
// which keeps the json file smaller while still covering the changes from:
74+
// https://blog.npmjs.org/post/168978377570/new-package-moniker-rules.html
75+
...allThePackageNamesData,
76+
// Load the 24.7MB names.json from '[email protected]',
77+
// the last v1 release, because it has different names resolved by
78+
// npm's replicate.npmjs.com service.
79+
...allThePackageNamesV1Data,
80+
])
8281
const rawLegacyNames = allThePackageNames
8382
// Don't simply check validateNpmPackageName(n).validForOldPackages.
8483
// Instead let registry.npmjs.org be our source of truth to whether a

0 commit comments

Comments
 (0)