Skip to content

Commit 91cd811

Browse files
authored
refactor: rename scripts/*.mjs to *.mts for native TypeScript (#1204)
* refactor: rename scripts/*.mjs to *.mts with full TypeScript types * fix: correct .mjs/.mts file extension mismatches after script rename - scripts/check.mts: update 4 validate-* spawn paths from .mjs to .mts - scripts/validate-no-cdn-refs.mts: fix self-skip check extension - scripts/lib/build-exec.mts: fix dynamic import of build-helpers - .github/workflows/provenance.yml: update 11 root script references - packages/cli/package.json: revert local script refs back to .mjs (only root scripts/ were renamed, not packages/cli/scripts/) * fix: revert cross-package imports to .mjs (files not renamed) Root scripts/ were renamed to .mts but files in packages/build-infra/ and packages/cli/scripts/ were not. Fix 7 cross-package imports that incorrectly referenced .mts extensions, and revert package-builder package.json script entries to .mjs. * Revert "fix: revert cross-package imports to .mjs (files not renamed)" This reverts commit 9f5a661. * refactor: rename sub-package scripts to .mts for native TypeScript Rename all .mjs scripts in packages/build-infra/lib/, packages/cli/scripts/, packages/cli/.config/, packages/package-builder/scripts/, and template files to .mts to match the root scripts/ rename from commit 049107c. - 73 files renamed via git mv (.mjs -> .mts) - Updated all internal imports within renamed files - Updated package.json script commands in cli, build-infra, package-builder, and template packages - Updated cross-package imports in root scripts/ - Preserved socketaddon-main/index.mjs (published npm entry point) - Preserved .mjs extension checks in bundle validation scripts * fix(build-infra): use const for non-reassigned destructured binding * refactor: add TypeScript types to sub-package scripts
1 parent d17603c commit 91cd811

File tree

119 files changed

+975
-639
lines changed

Some content is hidden

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

119 files changed

+975
-639
lines changed

.config/tsconfig.check.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
},
66
"include": [
77
"../packages/cli/src/**/*.mts",
8+
"../packages/cli/src/**/*.d.ts",
89
"../packages/cli/*.config.mts",
910
"../packages/cli/.config/*.mts"
1011
],

.github/workflows/provenance.yml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ jobs:
6363
- name: Generate platform matrix
6464
id: matrix
6565
run: |
66-
MATRIX=$(node scripts/get-platform-matrix.mjs)
66+
MATRIX=$(node scripts/get-platform-matrix.mts)
6767
echo "matrix=$MATRIX" >> $GITHUB_OUTPUT
6868
6969
- name: Upload CLI bundle
@@ -195,7 +195,7 @@ jobs:
195195
set -euo pipefail
196196
197197
# Get platform targets from single source of truth.
198-
PLATFORMS_STR=$(node scripts/get-platform-targets.mjs)
198+
PLATFORMS_STR=$(node scripts/get-platform-targets.mts)
199199
read -ra PLATFORMS <<< "$PLATFORMS_STR"
200200
201201
for target in "${PLATFORMS[@]}"; do
@@ -227,7 +227,7 @@ jobs:
227227
if [ -n "$LIBC" ]; then
228228
LIBC_FLAG="--libc=$LIBC"
229229
fi
230-
node scripts/prepublish-socketbin.mjs \
230+
node scripts/prepublish-socketbin.mts \
231231
--platform="$PLATFORM" --arch="$ARCH" $LIBC_FLAG --prod \
232232
--version="$VERSION" --method=sea
233233
@@ -253,7 +253,7 @@ jobs:
253253
TAG: ${{ steps.version.outputs.cli_tag }}
254254
run: |
255255
PKG_DIR="packages/package-builder/build/prod/out/cli"
256-
node scripts/prepare-package-for-publish.mjs "$PKG_DIR" "$VERSION"
256+
node scripts/prepare-package-for-publish.mts "$PKG_DIR" "$VERSION"
257257
cd "$PKG_DIR"
258258
npm publish --provenance --access public --no-git-checks --tag "$TAG"
259259
@@ -264,7 +264,7 @@ jobs:
264264
TAG: ${{ steps.version.outputs.cli_tag }}
265265
run: |
266266
PKG_DIR="packages/package-builder/build/prod/out/cli-with-sentry"
267-
node scripts/prepare-package-for-publish.mjs "$PKG_DIR" "$VERSION"
267+
node scripts/prepare-package-for-publish.mts "$PKG_DIR" "$VERSION"
268268
cd "$PKG_DIR"
269269
npm publish --provenance --access public --no-git-checks --tag "$TAG"
270270
@@ -276,7 +276,7 @@ jobs:
276276
TAG: ${{ steps.version.outputs.cli_tag }}
277277
run: |
278278
PKG_DIR="packages/package-builder/build/prod/out/socket"
279-
node scripts/prepare-package-for-publish.mjs "$PKG_DIR" "$VERSION"
279+
node scripts/prepare-package-for-publish.mts "$PKG_DIR" "$VERSION"
280280
cd "$PKG_DIR"
281281
npm publish --provenance --access public --no-git-checks --tag "$TAG"
282282
@@ -285,7 +285,7 @@ jobs:
285285
if: ${{ inputs.iocraft }}
286286
run: |
287287
echo "Downloading iocraft .node binaries for all platforms..."
288-
node scripts/download-iocraft-binaries.mjs
288+
node scripts/download-iocraft-binaries.mts
289289
290290
# Copy iocraft binaries to package directories.
291291
- name: Copy iocraft binaries to packages
@@ -295,7 +295,7 @@ jobs:
295295
set -euo pipefail
296296
297297
# Get platform targets from single source of truth.
298-
PLATFORMS_STR=$(node scripts/get-platform-targets.mjs)
298+
PLATFORMS_STR=$(node scripts/get-platform-targets.mts)
299299
read -ra PLATFORMS <<< "$PLATFORMS_STR"
300300
301301
for target in "${PLATFORMS[@]}"; do
@@ -320,7 +320,7 @@ jobs:
320320
TAG: ${{ steps.version.outputs.iocraft_tag }}
321321
run: |
322322
PKG_DIR="packages/package-builder/build/prod/out/socketaddon-iocraft"
323-
node scripts/prepare-package-for-publish.mjs "$PKG_DIR" "$VERSION"
323+
node scripts/prepare-package-for-publish.mts "$PKG_DIR" "$VERSION"
324324
cd "$PKG_DIR"
325325
npm publish --provenance --access public --no-git-checks --tag "$TAG"
326326
@@ -334,7 +334,7 @@ jobs:
334334
set -euo pipefail
335335
336336
# Get platform targets from single source of truth.
337-
PLATFORMS_STR=$(node scripts/get-platform-targets.mjs)
337+
PLATFORMS_STR=$(node scripts/get-platform-targets.mts)
338338
read -ra PLATFORMS <<< "$PLATFORMS_STR"
339339
340340
for target in "${PLATFORMS[@]}"; do
@@ -343,7 +343,7 @@ jobs:
343343
PKG_DIR="packages/package-builder/build/prod/out/socketaddon-iocraft-${target}"
344344
345345
# Prepare package.
346-
node scripts/prepare-package-for-publish.mjs "$PKG_DIR" "$VERSION"
346+
node scripts/prepare-package-for-publish.mts "$PKG_DIR" "$VERSION"
347347
348348
# Publish.
349349
cd "$PKG_DIR"

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,3 +136,4 @@ packages/socket/*.png
136136
!docs/build/
137137
!packages/package-builder/templates/**/*.d.ts
138138
!src/types/**/*.d.ts
139+
!packages/*/src/types/**/*.d.ts

package.json

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,31 @@
99
},
1010
"scripts": {
1111
"// Build": "",
12-
"build": "node scripts/build.mjs",
13-
"build:force": "node scripts/build.mjs --force",
12+
"build": "node scripts/build.mts",
13+
"build:force": "node scripts/build.mts --force",
1414
"build:cli": "pnpm --filter @socketsecurity/cli run build",
1515
"build:watch": "pnpm --filter @socketsecurity/cli run build:watch",
1616
"build:sea": "pnpm --filter @socketsecurity/cli run build:sea",
1717
"build:js": "pnpm --filter @socketsecurity/cli run build:js",
1818
"dev": "pnpm run build:watch",
19-
"prebuild": "node scripts/setup.mjs --restore-cache --quiet",
19+
"prebuild": "node scripts/setup.mts --restore-cache --quiet",
2020
"// Quality Checks": "",
21-
"check": "node scripts/check.mjs",
22-
"check:all": "node scripts/check.mjs --all",
23-
"fix": "node scripts/fix.mjs",
24-
"fix:all": "node scripts/fix.mjs --all",
25-
"lint": "node scripts/lint.mjs",
26-
"lint:all": "node scripts/lint.mjs --all",
21+
"check": "node scripts/check.mts",
22+
"check:all": "node scripts/check.mts --all",
23+
"fix": "node scripts/fix.mts",
24+
"fix:all": "node scripts/fix.mts --all",
25+
"lint": "node scripts/lint.mts",
26+
"lint:all": "node scripts/lint.mts --all",
2727
"format": "oxfmt --write .",
2828
"format:check": "oxfmt --check .",
2929
"// Claude": "",
3030
"claude": "pnpm --filter @socketsecurity/cli run claude --",
3131
"// Type Checking": "",
32-
"type": "node scripts/type.mjs",
33-
"type:all": "node scripts/type.mjs",
32+
"type": "node scripts/type.mts",
33+
"type:all": "node scripts/type.mts",
3434
"// Testing": "",
35-
"test": "node scripts/test-monorepo.mjs",
36-
"test:all": "node scripts/test-monorepo.mjs --all",
35+
"test": "node scripts/test-monorepo.mts",
36+
"test:all": "node scripts/test-monorepo.mts --all",
3737
"test:unit": "pnpm --filter @socketsecurity/cli run test:unit",
3838
"pretest:all": "pnpm run build",
3939
"testu": "pnpm --filter @socketsecurity/cli run test:unit:update",
@@ -42,12 +42,12 @@
4242
"security": "agentshield scan && { command -v zizmor >/dev/null && zizmor .github/ || echo 'zizmor not installed — run pnpm run setup to install'; }",
4343
"// Maintenance": "",
4444
"clean": "pnpm --filter \"./packages/**\" run clean",
45-
"clean:cache": "node scripts/clean-cache.mjs",
46-
"clean:cache:all": "node scripts/clean-cache.mjs --all",
47-
"update": "node scripts/update.mjs",
45+
"clean:cache": "node scripts/clean-cache.mts",
46+
"clean:cache:all": "node scripts/clean-cache.mts --all",
47+
"update": "node scripts/update.mts",
4848
"// Setup": "",
49-
"setup": "node scripts/setup.mjs",
50-
"postinstall": "node scripts/setup.mjs --install --quiet",
49+
"setup": "node scripts/setup.mts",
50+
"postinstall": "node scripts/setup.mts --install --quiet",
5151
"prepare": "husky",
5252
"pretest": "pnpm run build:cli"
5353
},
File renamed without changes.

packages/build-infra/lib/esbuild-plugin-unicode-transform.mjs renamed to packages/build-infra/lib/esbuild-plugin-unicode-transform.mts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
* }
1313
*/
1414

15-
import { transformUnicodePropertyEscapes } from './unicode-property-escape-transform.mjs'
15+
import type { PluginBuild, BuildResult } from 'esbuild'
16+
17+
import { transformUnicodePropertyEscapes } from './unicode-property-escape-transform.mts'
1618

1719
/**
1820
* Create esbuild plugin for Unicode property escape transformations.
@@ -22,8 +24,8 @@ import { transformUnicodePropertyEscapes } from './unicode-property-escape-trans
2224
export function unicodeTransformPlugin() {
2325
return {
2426
name: 'unicode-transform',
25-
setup(build) {
26-
build.onEnd(result => {
27+
setup(build: PluginBuild) {
28+
build.onEnd((result: BuildResult) => {
2729
const outputs = result.outputFiles
2830
if (!outputs || !outputs.length) {
2931
return
File renamed without changes.
File renamed without changes.
File renamed without changes.

packages/build-infra/lib/platform-targets.mjs renamed to packages/build-infra/lib/platform-targets.mts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,9 @@ export function parsePlatformTarget(target) {
193193
// Handle standard platform-arch.
194194
const parts = target.split('-')
195195
if (parts.length === 2) {
196-
let [platform, arch] = parts
196+
const [rawPlatform, arch] = parts
197197
// Normalize 'win' to 'win32' for internal use.
198-
if (platform === 'win') {
199-
platform = 'win32'
200-
}
198+
const platform = rawPlatform === 'win' ? 'win32' : rawPlatform
201199
if (VALID_PLATFORMS.includes(platform) && VALID_ARCHS.includes(arch)) {
202200
return { arch, platform }
203201
}

0 commit comments

Comments
 (0)