Skip to content

Commit 58c8bbc

Browse files
committed
Add module and method documentation headers to scripts
1 parent 13c3024 commit 58c8bbc

16 files changed

Lines changed: 125 additions & 4 deletions

scripts/check-registry-package-types.mjs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/** @fileoverview Validate that all registry package constants have corresponding TypeScript type declarations. */
2+
13
import { createRequire } from 'node:module'
24
import { promises as fs } from 'node:fs'
35
import path from 'node:path'
@@ -8,6 +10,10 @@ import constants from './constants.mjs'
810

911
const require = createRequire(import.meta.url)
1012

13+
/**
14+
* Verify that all constants have matching TypeScript declarations.
15+
* @throws {Error} When a constant is missing from type declarations.
16+
*/
1117
async function main() {
1218
const { registryPkgPath, rootPath } = constants
1319

scripts/clean-test-cache.mjs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1+
/** @fileoverview Clean test cache directories for npm package tests. */
2+
13
import os from 'node:os'
24
import path from 'node:path'
35

46
import { safeRemove } from './utils/fs.mjs'
57

8+
/**
9+
* Remove all test cache directories.
10+
*/
611
async function cleanTestCache() {
712
const dirs = [
813
path.join(os.homedir(), '.socket-npm-test-cache'),

scripts/convert-requires-to-imports.mjs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
/**
2-
* Convert CommonJS require() calls to dynamic import() for constants.
3-
* This allows Vite to properly resolve and transform them during coverage.
4-
*/
1+
/** @fileoverview Convert CommonJS require() calls to dynamic import() for constants. */
52

63
import { readFileSync, readdirSync, writeFileSync } from 'node:fs'
74
import { join } from 'node:path'
85

96
const libDir = './registry/src/lib'
107

8+
/**
9+
* Convert require calls to dynamic imports in a file.
10+
*/
1111
function processFile(filePath) {
1212
const content = readFileSync(filePath, 'utf8')
1313
let modified = false
@@ -38,6 +38,9 @@ function processFile(filePath) {
3838
return 0
3939
}
4040

41+
/**
42+
* Recursively process all TypeScript files in a directory.
43+
*/
4144
function processDirectory(dir) {
4245
let count = 0
4346
const files = readdirSync(dir, { withFileTypes: true })

scripts/fix-import-extensions.mjs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1+
/** @fileoverview Add .js extensions to relative import statements. */
2+
13
import { readFileSync, readdirSync, writeFileSync } from 'node:fs'
24
import { join } from 'node:path'
35

46
const libDir = './registry/src/lib'
57

8+
/**
9+
* Add .js extensions to imports missing them.
10+
*/
611
function processFile(filePath) {
712
const content = readFileSync(filePath, 'utf8')
813
let modified = false
@@ -44,6 +49,9 @@ function processFile(filePath) {
4449
return 0
4550
}
4651

52+
/**
53+
* Recursively process all TypeScript files in a directory.
54+
*/
4755
function processDirectory(dir) {
4856
let count = 0
4957
const files = readdirSync(dir, { withFileTypes: true })

scripts/generate-actions-allow-list.mjs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/** @fileoverview Generate GitHub Actions allow list from workflow and action dependencies. */
2+
13
import fs from 'node:fs/promises'
24
import path from 'node:path'
35

@@ -8,6 +10,9 @@ const GITHUB_PATH = '.github'
810
const WORKFLOWS_PATH = path.join(GITHUB_PATH, 'workflows')
911
const ACTIONS_PATH = path.join(GITHUB_PATH, 'actions')
1012

13+
/**
14+
* Extract action dependencies from a workflow or action file.
15+
*/
1116
async function extractDependencies(filePath) {
1217
const content = await fs.readFile(filePath, 'utf8')
1318
const dependencies = new Set()
@@ -44,6 +49,9 @@ async function extractDependencies(filePath) {
4449
return dependencies
4550
}
4651

52+
/**
53+
* Recursively find all YAML files in a directory.
54+
*/
4755
async function getAllYamlFiles(dir) {
4856
const files = []
4957
try {
@@ -62,6 +70,9 @@ async function getAllYamlFiles(dir) {
6270
return files
6371
}
6472

73+
/**
74+
* Generate and display GitHub Actions allow list.
75+
*/
6576
async function main() {
6677
const allDependencies = new Set()
6778

scripts/rebuild-registry-exports.mjs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/** @fileoverview Rebuild package.json exports field from built dist files. */
2+
13
import { readFile, writeFile } from 'node:fs/promises'
24
import path from 'node:path'
35
import { fileURLToPath } from 'node:url'
@@ -10,6 +12,9 @@ const __dirname = path.dirname(__filename)
1012
const registryPath = path.join(__dirname, '..', 'registry')
1113
const packageJsonPath = path.join(registryPath, 'package.json')
1214

15+
/**
16+
* Generate package.json exports from dist directory structure.
17+
*/
1318
async function main() {
1419
const packageJson = JSON.parse(await readFile(packageJsonPath, 'utf8'))
1520

scripts/release-npm-packages.mjs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/** @fileoverview Detect package changes and bump versions for npm release. */
2+
13
import crypto from 'node:crypto'
24
import fs from 'node:fs/promises'
35
import path from 'node:path'
@@ -40,6 +42,9 @@ const registryPkg = packageData({
4042

4143
const EXTRACT_PACKAGE_TMP_PREFIX = 'release-npm-'
4244

45+
/**
46+
* Compute SHA256 hashes for all files in a local package directory.
47+
*/
4348
async function getLocalPackageFileHashes(packagePath) {
4449
const fileHashes = {}
4550

@@ -125,6 +130,9 @@ async function getLocalPackageFileHashes(packagePath) {
125130
return toSortedObject(fileHashes)
126131
}
127132

133+
/**
134+
* Compute SHA256 hashes for all files in a remote published package.
135+
*/
128136
async function getRemotePackageFileHashes(spec) {
129137
const fileHashes = {}
130138

@@ -187,6 +195,9 @@ async function getRemotePackageFileHashes(spec) {
187195
return toSortedObject(fileHashes)
188196
}
189197

198+
/**
199+
* Compare local and remote package files to detect changes.
200+
*/
190201
async function hasPackageChanged(pkg, manifest_, options) {
191202
const { state } = { __proto__: null, ...options }
192203

@@ -231,12 +242,18 @@ async function hasPackageChanged(pkg, manifest_, options) {
231242
return changed
232243
}
233244

245+
/**
246+
* Check if a file is automatically included by npm in published packages.
247+
*/
234248
function isNpmAutoIncluded(fileName) {
235249
const upperName = fileName.toUpperCase()
236250
// NPM automatically includes LICENSE and README files with any case and extension.
237251
return upperName.startsWith('LICENSE') || upperName.startsWith('README')
238252
}
239253

254+
/**
255+
* Bump package version if changes are detected.
256+
*/
240257
async function maybeBumpPackage(pkg, options) {
241258
const {
242259
spinner,
@@ -284,6 +301,9 @@ async function maybeBumpPackage(pkg, options) {
284301
}
285302
}
286303

304+
/**
305+
* Create package metadata with defaults.
306+
*/
287307
function packageData(data) {
288308
const { manifest, printName = data.name, tag = LATEST, version } = data
289309
return Object.assign(data, {
@@ -294,6 +314,9 @@ function packageData(data) {
294314
})
295315
}
296316

317+
/**
318+
* Detect changes and bump versions for all packages.
319+
*/
297320
async function main() {
298321
const { spinner } = constants
299322

scripts/remove-require-js-extensions.mjs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1+
/** @fileoverview Remove .js extensions from require() calls with relative paths. */
2+
13
import { readFileSync, readdirSync, writeFileSync } from 'node:fs'
24
import { join } from 'node:path'
35

46
const libDir = './registry/src/lib'
57

8+
/**
9+
* Remove .js extensions from require calls in a file.
10+
*/
611
function processFile(filePath) {
712
const content = readFileSync(filePath, 'utf8')
813
let modified = false
@@ -27,6 +32,9 @@ function processFile(filePath) {
2732
return 0
2833
}
2934

35+
/**
36+
* Recursively process all TypeScript files in a directory.
37+
*/
3038
function processDirectory(dir) {
3139
let count = 0
3240
const files = readdirSync(dir, { withFileTypes: true })

scripts/revert-import-extensions.mjs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1+
/** @fileoverview Revert import extensions by removing .js extensions from relative imports. */
2+
13
import { readFileSync, readdirSync, writeFileSync } from 'node:fs'
24
import { join } from 'node:path'
35

46
const libDir = './registry/src/lib'
57

8+
/**
9+
* Remove .js extensions from import statements in a file.
10+
*/
611
function processFile(filePath) {
712
const content = readFileSync(filePath, 'utf8')
813
let modified = false
@@ -28,6 +33,9 @@ function processFile(filePath) {
2833
return 0
2934
}
3035

36+
/**
37+
* Recursively process all TypeScript files in a directory.
38+
*/
3139
function processDirectory(dir) {
3240
let count = 0
3341
const files = readdirSync(dir, { withFileTypes: true })

scripts/set-npm-package-access.mjs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/** @fileoverview Set MFA automation access level for published npm packages. */
2+
13
import path from 'node:path'
24

35
import { parseArgs } from '../registry/dist/lib/parse-args.js'
@@ -25,11 +27,17 @@ const { values: cliArgs } = parseArgs({
2527
strict: false,
2628
})
2729

30+
/**
31+
* Create package metadata with defaults.
32+
*/
2833
function packageData(data) {
2934
const { printName = data.name } = data
3035
return Object.assign(data, { printName })
3136
}
3237

38+
/**
39+
* Configure MFA automation for token-based packages.
40+
*/
3341
async function main() {
3442
// Exit early if not running in CI or with --force.
3543
const { ENV } = constants

0 commit comments

Comments
 (0)