From 2d80a9dff1d1f0378e9eb2211f1c9505ea9489ba Mon Sep 17 00:00:00 2001 From: Slawomir Koszewski Date: Mon, 2 Feb 2026 06:43:40 +0100 Subject: [PATCH] Converted leftover CommonJS scripts to ESModule. --- package.json | 2 +- scripts/build-image.mjs | 38 ++++++++++++++++++++++---------------- scripts/new-version.mjs | 35 +++++++++++++++++++++-------------- 3 files changed, 44 insertions(+), 31 deletions(-) diff --git a/package.json b/package.json index 2d02e2c..c7fe3f5 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "test": "vitest", "server": "node server.js --dev", "dev": "concurrently \"npm start\" \"node --watch server.js --dev\"", - "build-image": "vite build && node scripts/build-image.js" + "build-image": "vite build && node scripts/build-image.mjs" }, "engines": { "node": ">=24.0.0" diff --git a/scripts/build-image.mjs b/scripts/build-image.mjs index 80a97bc..cd29391 100755 --- a/scripts/build-image.mjs +++ b/scripts/build-image.mjs @@ -1,10 +1,13 @@ #!/usr/bin/env node -const { execSync } = require('child_process'); -const fs = require('fs'); -const path = require('path'); -const { pathToFileURL } = require('url'); -const { parseArgs } = require('util'); +import { execSync } from 'node:child_process'; +import fs from 'node:fs'; +import path from 'node:path'; +import { fileURLToPath, pathToFileURL } from 'node:url'; +import { parseArgs } from 'node:util'; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); function execCommand(command, description) { try { @@ -71,7 +74,7 @@ function showHelp() { console.log(`Build multi-architecture container images for JMESPath Playground Usage: - build-image.js [OPTIONS] + build-image.mjs [OPTIONS] Options: --all-arch Build for both arm64 and amd64 (default: build for host architecture only) @@ -79,11 +82,11 @@ Options: --help, -h Show this help message and exit Examples: - build-image.js # Builds for ${hostArch} only (host architecture) - build-image.js --all-arch # Builds for both arm64 and amd64 - build-image.js --arch arm64 # Builds for arm64 only - build-image.js --arch arm64 --arch amd64 # Explicitly specify both - build-image.js -h # Show help`); + build-image.mjs # Builds for ${hostArch} only (host architecture) + build-image.mjs --all-arch # Builds for both arm64 and amd64 + build-image.mjs --arch arm64 # Builds for arm64 only + build-image.mjs --arch arm64 --arch amd64 # Explicitly specify both + build-image.mjs -h # Show help`); } async function main() { @@ -150,10 +153,10 @@ async function main() { // Show usage instructions console.log(`\nUsage examples:`); - console.log(` build-image.js # Builds for host architecture only`); - console.log(` build-image.js --all-arch # Builds for both arm64 and amd64`); - console.log(` build-image.js --arch arm64 # Builds for arm64 only`); - console.log(` build-image.js --arch arm64 --arch amd64 # Explicitly specify both`); + console.log(` build-image.mjs # Builds for host architecture only`); + console.log(` build-image.mjs --all-arch # Builds for both arm64 and amd64`); + console.log(` build-image.mjs --arch arm64 # Builds for arm64 only`); + console.log(` build-image.mjs --arch arm64 --arch amd64 # Explicitly specify both`); if (isRelease) { console.log(`\nTo run the container:`); @@ -169,7 +172,10 @@ async function main() { } } -if (require.main === module) { +const isDirectRun = process.argv[1] + && fileURLToPath(import.meta.url) === path.resolve(process.argv[1]); + +if (isDirectRun) { main().catch((error) => { console.error(`Error: ${error.message}`); process.exit(1); diff --git a/scripts/new-version.mjs b/scripts/new-version.mjs index eee151e..bdd1b30 100755 --- a/scripts/new-version.mjs +++ b/scripts/new-version.mjs @@ -1,11 +1,13 @@ #!/usr/bin/env node -const fs = require('fs'); -const { execSync } = require('child_process'); +import { execSync } from 'node:child_process'; +import fs from 'node:fs'; +import path from 'node:path'; +import { fileURLToPath } from 'node:url'; function showUsage() { - console.log('Usage: node scripts/new-version.js [--force] [-m|--message "commit message"]'); - console.log(' node scripts/new-version.js --check '); + console.log('Usage: node scripts/new-version.mjs [--force] [-m|--message "commit message"]'); + console.log(' node scripts/new-version.mjs --check '); console.log(''); console.log('Creates a new version by tagging the current commit.'); console.log(''); @@ -15,10 +17,10 @@ function showUsage() { console.log(' -m, --message TEXT Custom commit message (only used when commit is needed)'); console.log(''); console.log('Example:'); - console.log(' node scripts/new-version.js 1.2.0'); - console.log(' node scripts/new-version.js 1.2.0 --force'); - console.log(' node scripts/new-version.js 1.2.0 -m "Add new feature XYZ"'); - console.log(' node scripts/new-version.js --check 1.3.0'); + console.log(' node scripts/new-version.mjs 1.2.0'); + console.log(' node scripts/new-version.mjs 1.2.0 --force'); + console.log(' node scripts/new-version.mjs 1.2.0 -m "Add new feature XYZ"'); + console.log(' node scripts/new-version.mjs --check 1.3.0'); } function performCheck(targetVersion) { @@ -129,18 +131,18 @@ function performCheck(targetVersion) { console.log(''); console.log('📋 Commands that would work:'); if (isRepoDirty || needsPackageUpdate) { - console.log(` node scripts/new-version.js ${targetVersion} --force`); + console.log(` node scripts/new-version.mjs ${targetVersion} --force`); } else { - console.log(` node scripts/new-version.js ${targetVersion}`); - console.log(` node scripts/new-version.js ${targetVersion} --force`); + console.log(` node scripts/new-version.mjs ${targetVersion}`); + console.log(` node scripts/new-version.mjs ${targetVersion} --force`); } } else { console.log('⚡ Actions needed:'); console.log(` • Create tag ${tagName} (no commit needed)`); console.log(''); console.log('📋 Commands that would work:'); - console.log(` node scripts/new-version.js ${targetVersion}`); - console.log(` node scripts/new-version.js ${targetVersion} --force`); + console.log(` node scripts/new-version.mjs ${targetVersion}`); + console.log(` node scripts/new-version.mjs ${targetVersion} --force`); } console.log(''); @@ -297,4 +299,9 @@ function main() { } } -main(); \ No newline at end of file +const isDirectRun = process.argv[1] + && fileURLToPath(import.meta.url) === path.resolve(process.argv[1]); + +if (isDirectRun) { + main(); +}