Convert build scripts from CommonJS to ES Modules (#416)

* Convert build scripts from CommonJS to ES Modules

- Convert all eng/*.js files to ES Modules (.mjs)
- Update package.json scripts to reference .mjs files
- Fix ERR_REQUIRE_ESM error with vfile v6.0.3
- Add __dirname polyfills for ES Modules

* completing the migration of all files to es modules

---------

Co-authored-by: Lyubomir Filipov <lyubomir.filipov@jakala.com>
Co-authored-by: Aaron Powell <me@aaron-powell.com>
This commit is contained in:
spectatora 2025-11-18 02:23:51 +02:00 committed by GitHub
parent b147f8349c
commit 8440d151d3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 43 additions and 30 deletions

9
.vscode/tasks.json vendored
View File

@ -12,19 +12,19 @@
{ {
"label": "generate-readme", "label": "generate-readme",
"type": "shell", "type": "shell",
"command": "node ${workspaceFolder}/eng/update-readme.js", "command": "npm run build",
"problemMatcher": [], "problemMatcher": [],
"group": { "group": {
"kind": "build", "kind": "build",
"isDefault": true "isDefault": true
}, },
"detail": "Generates the README.md file using update-readme.js script.", "detail": "Generates the README.md file using npm build run-script.",
"dependsOn": "npm install" "dependsOn": "npm install"
}, },
{ {
"label": "validate-collections", "label": "validate-collections",
"type": "shell", "type": "shell",
"command": "node ${workspaceFolder}/eng/validate-collections.js", "command": "npm run collection:validate",
"problemMatcher": [], "problemMatcher": [],
"group": "build", "group": "build",
"detail": "Validates all collection manifest files.", "detail": "Validates all collection manifest files.",
@ -33,9 +33,8 @@
{ {
"label": "create-collection", "label": "create-collection",
"type": "shell", "type": "shell",
"command": "node", "command": "npm run collection:create",
"args": [ "args": [
"${workspaceFolder}/eng/create-collection.js",
"--id", "--id",
"${input:collectionId}", "${input:collectionId}",
"--tags", "--tags",

View File

@ -1,4 +1,9 @@
const path = require("path"); import path from "path";
import { fileURLToPath } from "url";
import { dirname } from "path";
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
// Template sections for the README // Template sections for the README
const TEMPLATES = { const TEMPLATES = {
@ -115,7 +120,7 @@ const MAX_COLLECTION_ITEMS = 50;
const DOCS_DIR = path.join(ROOT_FOLDER, "docs"); const DOCS_DIR = path.join(ROOT_FOLDER, "docs");
module.exports = { export {
TEMPLATES, TEMPLATES,
vscodeInstallImage, vscodeInstallImage,
vscodeInsidersInstallImage, vscodeInsidersInstallImage,
@ -130,3 +135,4 @@ module.exports = {
MAX_COLLECTION_ITEMS, MAX_COLLECTION_ITEMS,
DOCS_DIR, DOCS_DIR,
}; };

10
eng/create-collection.js → eng/create-collection.mjs Executable file → Normal file
View File

@ -1,9 +1,9 @@
#!/usr/bin/env node #!/usr/bin/env node
const fs = require("fs"); import fs from "fs";
const path = require("path"); import path from "path";
const readline = require("readline"); import readline from "readline";
const { COLLECTIONS_DIR } = require("./constants"); import { COLLECTIONS_DIR } from "./constants.mjs";
const rl = readline.createInterface({ const rl = readline.createInterface({
input: process.stdin, input: process.stdin,
@ -166,7 +166,7 @@ display:
console.log("\n📝 Next steps:"); console.log("\n📝 Next steps:");
console.log("1. Edit the collection manifest to add your items"); console.log("1. Edit the collection manifest to add your items");
console.log("2. Update the name, description, and tags as needed"); console.log("2. Update the name, description, and tags as needed");
console.log("3. Run 'npm run validate:collections' to validate"); console.log("3. Run 'npm run collection:validate' to validate");
console.log("4. Run 'npm start' to generate documentation"); console.log("4. Run 'npm start' to generate documentation");
console.log("\n📄 Collection template contents:"); console.log("\n📄 Collection template contents:");
console.log(template); console.log(template);

18
eng/update-readme.js → eng/update-readme.mjs Executable file → Normal file
View File

@ -1,14 +1,16 @@
#!/usr/bin/env node #!/usr/bin/env node
const fs = require("fs"); import fs from "fs";
const path = require("path"); import path from "path";
const { import { fileURLToPath } from "url";
import { dirname } from "path";
import {
parseCollectionYaml, parseCollectionYaml,
extractMcpServers, extractMcpServers,
extractMcpServerConfigs, extractMcpServerConfigs,
parseFrontmatter, parseFrontmatter,
} = require("./yaml-parser"); } from "./yaml-parser.mjs";
const { import {
TEMPLATES, TEMPLATES,
AKA_INSTALL_URLS, AKA_INSTALL_URLS,
repoBaseUrl, repoBaseUrl,
@ -21,7 +23,10 @@ const {
COLLECTIONS_DIR, COLLECTIONS_DIR,
INSTRUCTIONS_DIR, INSTRUCTIONS_DIR,
DOCS_DIR, DOCS_DIR,
} = require("./constants"); } from "./constants.mjs";
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
// Cache of MCP registry server names (lower-cased) loaded from github-mcp-registry.json // Cache of MCP registry server names (lower-cased) loaded from github-mcp-registry.json
let MCP_REGISTRY_SET = null; let MCP_REGISTRY_SET = null;
@ -968,3 +973,4 @@ try {
console.error(`Error generating category README files: ${error.message}`); console.error(`Error generating category README files: ${error.message}`);
process.exit(1); process.exit(1);
} }

View File

@ -1,13 +1,13 @@
#!/usr/bin/env node #!/usr/bin/env node
const fs = require("fs"); import fs from "fs";
const path = require("path"); import path from "path";
const { parseCollectionYaml, parseFrontmatter } = require("./yaml-parser"); import { parseCollectionYaml, parseFrontmatter } from "./yaml-parser.mjs";
const { import {
ROOT_FOLDER, ROOT_FOLDER,
COLLECTIONS_DIR, COLLECTIONS_DIR,
MAX_COLLECTION_ITEMS, MAX_COLLECTION_ITEMS,
} = require("./constants"); } from "./constants.mjs";
// Validation functions // Validation functions
function validateCollectionId(id) { function validateCollectionId(id) {
@ -370,3 +370,4 @@ try {
console.error(`Error during validation: ${error.message}`); console.error(`Error during validation: ${error.message}`);
process.exit(1); process.exit(1);
} }

View File

@ -1,8 +1,8 @@
// YAML parser for collection files and frontmatter parsing using vfile-matter // YAML parser for collection files and frontmatter parsing using vfile-matter
const fs = require("fs"); import fs from "fs";
const yaml = require("js-yaml"); import yaml from "js-yaml";
const { VFile } = require("vfile"); import { VFile } from "vfile";
const { matter } = require("vfile-matter"); import { matter } from "vfile-matter";
function safeFileOperation(operation, filePath, defaultValue = null) { function safeFileOperation(operation, filePath, defaultValue = null) {
try { try {
@ -137,7 +137,7 @@ function extractMcpServerConfigs(filePath) {
}); });
} }
module.exports = { export {
parseCollectionYaml, parseCollectionYaml,
parseFrontmatter, parseFrontmatter,
extractAgentMetadata, extractAgentMetadata,

View File

@ -6,11 +6,12 @@
"private": true, "private": true,
"scripts": { "scripts": {
"start": "npm run build", "start": "npm run build",
"build": "node ./eng/update-readme.js", "build": "node ./eng/update-readme.mjs",
"contributors:add": "all-contributors add", "contributors:add": "all-contributors add",
"contributors:generate": "all-contributors generate", "contributors:generate": "all-contributors generate",
"contributors:check": "all-contributors check", "contributors:check": "all-contributors check",
"validate:collections": "node ./eng/validate-collections.js" "collection:validate": "node ./eng/validate-collections.mjs",
"collection:create": "node ./eng/create-collection.mjs"
}, },
"repository": { "repository": {
"type": "git", "type": "git",