Skip to content

Commit 831e8e8

Browse files
committed
Update test files and clean up legacy types
- Update test imports and configurations across all test files - Remove obsolete external.d.ts type declarations file - Replace eslint.config.js with eslint.config.mjs in npm tests - Add missing rebuild-registry-exports.mjs script - Update all test imports to use proper module paths
1 parent 29eb50a commit 831e8e8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+442
-220
lines changed

registry/src/types/external.d.ts

Lines changed: 0 additions & 15 deletions
This file was deleted.
Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
import { readFile, writeFile } from 'node:fs/promises'
2+
import path from 'node:path'
3+
import { fileURLToPath } from 'node:url'
4+
5+
import fastGlob from 'fast-glob'
6+
7+
const __filename = fileURLToPath(import.meta.url)
8+
const __dirname = path.dirname(__filename)
9+
10+
const registryPath = path.join(__dirname, '..', 'registry')
11+
const packageJsonPath = path.join(registryPath, 'package.json')
12+
13+
async function main() {
14+
const packageJson = JSON.parse(await readFile(packageJsonPath, 'utf8'))
15+
16+
// Find all files in dist directory
17+
const distFiles = await fastGlob.glob(['dist/**/*.{js,d.ts}'], {
18+
cwd: registryPath,
19+
ignore: ['node_modules/**', '**/*.test.*'],
20+
})
21+
22+
// Also include JSON files at root.
23+
const jsonFiles = [
24+
'extensions.json',
25+
'manifest.json',
26+
'package.json',
27+
'tsconfig.json',
28+
]
29+
30+
// Add JSON files.
31+
const exports = {}
32+
for (const jsonFile of jsonFiles) {
33+
exports[`./${jsonFile}`] = `./${jsonFile}`
34+
}
35+
36+
// Process dist files.
37+
for (const file of distFiles) {
38+
const ext = file.endsWith('.d.ts') ? '.d.ts' : path.extname(file)
39+
const relativePath = file.slice('dist/'.length)
40+
const exportPath = `./${relativePath.slice(0, -ext.length)}`
41+
const isDts = ext === '.d.ts'
42+
43+
if (exports[exportPath]) {
44+
exports[exportPath][isDts ? 'types' : 'default'] = `./${file}`
45+
} else {
46+
exports[exportPath] = {
47+
types: isDts ? `./${file}` : undefined,
48+
default: isDts ? undefined : `./${file}`,
49+
}
50+
}
51+
52+
// Clean up single property objects.
53+
if (exports[exportPath].types === undefined) {
54+
exports[exportPath] = exports[exportPath].default
55+
} else if (exports[exportPath].default === undefined) {
56+
delete exports[exportPath].default
57+
}
58+
59+
// Add index exports for directories.
60+
const basename = path.basename(relativePath, ext)
61+
if (basename === 'index') {
62+
const dirPath = `./${path.dirname(relativePath)}`
63+
if (dirPath !== './.') {
64+
if (exports[dirPath]) {
65+
exports[dirPath][isDts ? 'types' : 'default'] = `./${file}`
66+
} else {
67+
exports[dirPath] = {
68+
types: isDts ? `./${file}` : undefined,
69+
default: isDts ? undefined : `./${file}`,
70+
}
71+
}
72+
// Clean up single property objects.
73+
if (exports[dirPath].types === undefined) {
74+
exports[dirPath] = exports[dirPath].default
75+
} else if (exports[dirPath].default === undefined) {
76+
delete exports[dirPath].default
77+
}
78+
}
79+
}
80+
}
81+
82+
// Add dual exports for constants (both lowercase and uppercase).
83+
const constantsExports = {}
84+
for (const [exportPath, exportValue] of Object.entries(exports)) {
85+
if (
86+
exportPath.startsWith('./lib/constants/') &&
87+
exportPath !== './lib/constants'
88+
) {
89+
const pathAfterConstants = exportPath.slice('./lib/constants/'.length)
90+
91+
// Always add the lowercase-hyphenated version.
92+
const lowercasePath = `./lib/constants/${pathAfterConstants.toLowerCase().replace(/_/g, '-')}`
93+
constantsExports[lowercasePath] = exportValue
94+
95+
// Always add the UPPERCASE_UNDERSCORE version.
96+
const uppercasePath = `./lib/constants/${pathAfterConstants.toUpperCase().replace(/-/g, '_')}`
97+
constantsExports[uppercasePath] = exportValue
98+
}
99+
}
100+
101+
// Merge all exports.
102+
Object.assign(exports, constantsExports)
103+
104+
// Sort exports.
105+
const sortedExports = {}
106+
const sortedKeys = Object.keys(exports).sort()
107+
for (const key of sortedKeys) {
108+
sortedExports[key] = exports[key]
109+
}
110+
111+
// Add browser field for Node.js built-ins.
112+
const browser = {}
113+
const builtinNames = [
114+
'assert',
115+
'buffer',
116+
'child_process',
117+
'cluster',
118+
'console',
119+
'constants',
120+
'crypto',
121+
'dgram',
122+
'dns',
123+
'domain',
124+
'events',
125+
'fs',
126+
'http',
127+
'https',
128+
'module',
129+
'net',
130+
'os',
131+
'path',
132+
'process',
133+
'punycode',
134+
'querystring',
135+
'readline',
136+
'stream',
137+
'string_decoder',
138+
'sys',
139+
'timers',
140+
'tls',
141+
'tty',
142+
'url',
143+
'util',
144+
'vm',
145+
'zlib',
146+
]
147+
for (const name of builtinNames) {
148+
browser[name] = false
149+
}
150+
151+
packageJson.exports = sortedExports
152+
packageJson.browser = browser
153+
154+
await writeFile(packageJsonPath, JSON.stringify(packageJson, null, 2) + '\n')
155+
console.log(
156+
`✅ Created ${Object.keys(sortedExports).length} exports in registry/package.json`,
157+
)
158+
console.log(
159+
` Including ${Object.keys(constantsExports).length / 2} dual constant exports`,
160+
)
161+
}
162+
163+
main().catch(console.error)

test/npm-exec.test.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { describe, expect, it } from 'vitest'
22

3-
import { isPnpmIgnoreScriptsFlag } from '@socketsecurity/registry/lib/agent'
3+
import { isPnpmIgnoreScriptsFlag } from '../registry/dist/lib/agent.js'
44

55
// Note: execPnpm integration testing would require mocking the spawn/execBin functions.
66
// which is complex due to the module structure. The implementation can be tested.

test/npm/array-flatten.test.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { isPackageTestingSkipped } from '../../scripts/utils/tests.mjs'
99
const { NPM } = constants
1010

1111
const eco = NPM
12-
const sockRegPkgName = path.basename(__filename, '.test.ts')
12+
const sockRegPkgName = path.basename(__filename, '.test.mts')
1313

1414
describe(
1515
`${eco} > ${sockRegPkgName}`,

test/npm/es6-object-assign.test.mts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,15 @@ import path from 'node:path'
22

33
import { beforeAll, describe, expect, it } from 'vitest'
44

5-
import { logger } from '@socketsecurity/registry/lib/logger'
6-
5+
import { logger } from '../../registry/dist/lib/logger.js'
76
import constants from '../../scripts/constants.mjs'
87
import { installPackageForTesting } from '../../scripts/utils/package-utils.mjs'
98
import { isPackageTestingSkipped } from '../../scripts/utils/tests.mjs'
109

1110
const { NPM } = constants
1211

1312
const eco = NPM
14-
const sockRegPkgName = path.basename(__filename, '.test.ts')
13+
const sockRegPkgName = path.basename(__filename, '.test.mts')
1514

1615
// es6-object-assign has no unit tests.
1716
// https://github.com/rubennorte/es6-object-assign/tree/v1.1.0

test/npm/eslint.config.js

Lines changed: 0 additions & 9 deletions
This file was deleted.

test/npm/eslint.config.mjs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import constants from '@socketregistry/scripts/constants'
2+
3+
export default [
4+
{
5+
extends: constants.rootEslintConfigPath,
6+
},
7+
]

test/npm/harmony-reflect.test.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { isPackageTestingSkipped } from '../../scripts/utils/tests.mjs'
99
const { NPM } = constants
1010

1111
const eco = NPM
12-
const sockRegPkgName = path.basename(__filename, '.test.ts')
12+
const sockRegPkgName = path.basename(__filename, '.test.mts')
1313

1414
// harmony-reflect has known failures in its package and requires running tests in browser.
1515
// https://github.com/tvcutsem/harmony-reflect/tree/v1.6.2/test

test/npm/hyrious__bun.lockb.test.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { isPackageTestingSkipped } from '../../scripts/utils/tests.mjs'
1010
const { NPM, UTF8 } = constants
1111

1212
const eco = NPM
13-
const sockRegPkgName = path.basename(__filename, '.test.ts')
13+
const sockRegPkgName = path.basename(__filename, '.test.mts')
1414

1515
// @hyrious/bun.lockb has no unit tests.
1616
// https://github.com/hyrious/bun.lockb/tree/v0.0.4

test/npm/is-regex.test.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { setupMultiEntryTest } from '../utils/test-helpers.mjs'
99
const { NPM } = constants
1010

1111
const eco = NPM
12-
const sockRegPkgName = path.basename(__filename, '.test.ts')
12+
const sockRegPkgName = path.basename(__filename, '.test.mts')
1313

1414
// is-regex tests don't account for `is-regex` backed by.
1515
// `require('node:util/types).isRegExp` which triggers no proxy traps and.

0 commit comments

Comments
 (0)