Skip to content

Commit de8a4ab

Browse files
committed
Convert scripts to .mjs
1 parent ffa6ce6 commit de8a4ab

File tree

2 files changed

+25
-16
lines changed

2 files changed

+25
-16
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
"update": "run-p --aggregate-output update:* && run-s update:longtask:**",
6767
"update:deps": "taze",
6868
"update:socket": "pnpm update '@socketsecurity/*' --latest",
69-
"update:longtask:data:npm": "node ./scripts/update-data-npm.js"
69+
"update:longtask:data:npm": "node ./scripts/update-data-npm.mjs"
7070
},
7171
"devDependencies": {
7272
"@biomejs/biome": "2.2.4",
Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
1-
'use strict'
1+
import Module from 'node:module'
2+
import path from 'node:path'
3+
import { fileURLToPath } from 'node:url'
24

3-
const Module = require('node:module')
4-
const path = require('node:path')
5+
import pacote from 'pacote'
6+
import semver from 'semver'
7+
import validateNpmPackageName from 'validate-npm-package-name'
58

6-
const pacote = require('pacote')
7-
const semver = require('semver')
8-
const validateNpmPackageName = require('validate-npm-package-name')
9-
10-
const constants = require('@socketsecurity/registry/lib/constants')
11-
const { writeJson } = require('@socketsecurity/registry/lib/fs')
12-
const { logger } = require('@socketsecurity/registry/lib/logger')
13-
const { pFilter } = require('@socketsecurity/registry/lib/promises')
14-
const { confirm } = require('@socketsecurity/registry/lib/prompts')
15-
const { naturalCompare } = require('@socketsecurity/registry/lib/sorts')
9+
import constants from '@socketsecurity/registry/lib/constants'
10+
import { writeJson } from '@socketsecurity/registry/lib/fs'
11+
import { logger } from '@socketsecurity/registry/lib/logger'
12+
import { pFilter } from '@socketsecurity/registry/lib/promises'
13+
import { confirm } from '@socketsecurity/registry/lib/prompts'
14+
import { naturalCompare } from '@socketsecurity/registry/lib/sorts'
1615

1716
const { abortSignal } = constants
1817

18+
const __filename = fileURLToPath(import.meta.url)
19+
const __dirname = path.dirname(__filename)
20+
1921
const rootPath = path.resolve(__dirname, '..')
2022
const dataPath = path.join(rootPath, 'data')
2123
const npmDataPath = path.join(dataPath, 'npm')
@@ -59,16 +61,23 @@ void (async () => {
5961
spinner.stop()
6062
return
6163
}
64+
const allThePackageNamesData = await import('all-the-package-names/names.json', {
65+
with: { type: 'json' }
66+
})
67+
const allThePackageNamesV1Data = await import('all-the-package-names-v1.3905.0/names.json', {
68+
with: { type: 'json' }
69+
})
70+
6271
const allThePackageNames = [
6372
...new Set([
6473
// Load the 43.1MB names.json file of '[email protected]'
6574
// which keeps the json file smaller while still covering the changes from:
6675
// https://blog.npmjs.org/post/168978377570/new-package-moniker-rules.html
67-
...require('all-the-package-names/names.json'),
76+
...allThePackageNamesData.default,
6877
// Load the 24.7MB names.json from '[email protected]',
6978
// the last v1 release, because it has different names resolved by
7079
// npm's replicate.npmjs.com service.
71-
...require('all-the-package-names-v1.3905.0/names.json'),
80+
...allThePackageNamesV1Data.default,
7281
]),
7382
]
7483
const rawLegacyNames = allThePackageNames

0 commit comments

Comments
 (0)