Skip to content

Commit 8440d15

Browse files
spectatoraLyubomir Filipovaaronpowell
authored
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 <[email protected]> Co-authored-by: Aaron Powell <[email protected]>
1 parent b147f83 commit 8440d15

File tree

7 files changed

+43
-30
lines changed

7 files changed

+43
-30
lines changed

.vscode/tasks.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,19 @@
1212
{
1313
"label": "generate-readme",
1414
"type": "shell",
15-
"command": "node ${workspaceFolder}/eng/update-readme.js",
15+
"command": "npm run build",
1616
"problemMatcher": [],
1717
"group": {
1818
"kind": "build",
1919
"isDefault": true
2020
},
21-
"detail": "Generates the README.md file using update-readme.js script.",
21+
"detail": "Generates the README.md file using npm build run-script.",
2222
"dependsOn": "npm install"
2323
},
2424
{
2525
"label": "validate-collections",
2626
"type": "shell",
27-
"command": "node ${workspaceFolder}/eng/validate-collections.js",
27+
"command": "npm run collection:validate",
2828
"problemMatcher": [],
2929
"group": "build",
3030
"detail": "Validates all collection manifest files.",
@@ -33,9 +33,8 @@
3333
{
3434
"label": "create-collection",
3535
"type": "shell",
36-
"command": "node",
36+
"command": "npm run collection:create",
3737
"args": [
38-
"${workspaceFolder}/eng/create-collection.js",
3938
"--id",
4039
"${input:collectionId}",
4140
"--tags",

eng/constants.js renamed to eng/constants.mjs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
const path = require("path");
1+
import path from "path";
2+
import { fileURLToPath } from "url";
3+
import { dirname } from "path";
4+
5+
const __filename = fileURLToPath(import.meta.url);
6+
const __dirname = dirname(__filename);
27

38
// Template sections for the README
49
const TEMPLATES = {
@@ -115,7 +120,7 @@ const MAX_COLLECTION_ITEMS = 50;
115120

116121
const DOCS_DIR = path.join(ROOT_FOLDER, "docs");
117122

118-
module.exports = {
123+
export {
119124
TEMPLATES,
120125
vscodeInstallImage,
121126
vscodeInsidersInstallImage,
@@ -130,3 +135,4 @@ module.exports = {
130135
MAX_COLLECTION_ITEMS,
131136
DOCS_DIR,
132137
};
138+
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#!/usr/bin/env node
22

3-
const fs = require("fs");
4-
const path = require("path");
5-
const readline = require("readline");
6-
const { COLLECTIONS_DIR } = require("./constants");
3+
import fs from "fs";
4+
import path from "path";
5+
import readline from "readline";
6+
import { COLLECTIONS_DIR } from "./constants.mjs";
77

88
const rl = readline.createInterface({
99
input: process.stdin,
@@ -166,7 +166,7 @@ display:
166166
console.log("\n📝 Next steps:");
167167
console.log("1. Edit the collection manifest to add your items");
168168
console.log("2. Update the name, description, and tags as needed");
169-
console.log("3. Run 'npm run validate:collections' to validate");
169+
console.log("3. Run 'npm run collection:validate' to validate");
170170
console.log("4. Run 'npm start' to generate documentation");
171171
console.log("\n📄 Collection template contents:");
172172
console.log(template);
Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
#!/usr/bin/env node
22

3-
const fs = require("fs");
4-
const path = require("path");
5-
const {
3+
import fs from "fs";
4+
import path from "path";
5+
import { fileURLToPath } from "url";
6+
import { dirname } from "path";
7+
import {
68
parseCollectionYaml,
79
extractMcpServers,
810
extractMcpServerConfigs,
911
parseFrontmatter,
10-
} = require("./yaml-parser");
11-
const {
12+
} from "./yaml-parser.mjs";
13+
import {
1214
TEMPLATES,
1315
AKA_INSTALL_URLS,
1416
repoBaseUrl,
@@ -21,7 +23,10 @@ const {
2123
COLLECTIONS_DIR,
2224
INSTRUCTIONS_DIR,
2325
DOCS_DIR,
24-
} = require("./constants");
26+
} from "./constants.mjs";
27+
28+
const __filename = fileURLToPath(import.meta.url);
29+
const __dirname = dirname(__filename);
2530

2631
// Cache of MCP registry server names (lower-cased) loaded from github-mcp-registry.json
2732
let MCP_REGISTRY_SET = null;
@@ -968,3 +973,4 @@ try {
968973
console.error(`Error generating category README files: ${error.message}`);
969974
process.exit(1);
970975
}
976+
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
#!/usr/bin/env node
22

3-
const fs = require("fs");
4-
const path = require("path");
5-
const { parseCollectionYaml, parseFrontmatter } = require("./yaml-parser");
6-
const {
3+
import fs from "fs";
4+
import path from "path";
5+
import { parseCollectionYaml, parseFrontmatter } from "./yaml-parser.mjs";
6+
import {
77
ROOT_FOLDER,
88
COLLECTIONS_DIR,
99
MAX_COLLECTION_ITEMS,
10-
} = require("./constants");
10+
} from "./constants.mjs";
1111

1212
// Validation functions
1313
function validateCollectionId(id) {
@@ -370,3 +370,4 @@ try {
370370
console.error(`Error during validation: ${error.message}`);
371371
process.exit(1);
372372
}
373+
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// YAML parser for collection files and frontmatter parsing using vfile-matter
2-
const fs = require("fs");
3-
const yaml = require("js-yaml");
4-
const { VFile } = require("vfile");
5-
const { matter } = require("vfile-matter");
2+
import fs from "fs";
3+
import yaml from "js-yaml";
4+
import { VFile } from "vfile";
5+
import { matter } from "vfile-matter";
66

77
function safeFileOperation(operation, filePath, defaultValue = null) {
88
try {
@@ -137,7 +137,7 @@ function extractMcpServerConfigs(filePath) {
137137
});
138138
}
139139

140-
module.exports = {
140+
export {
141141
parseCollectionYaml,
142142
parseFrontmatter,
143143
extractAgentMetadata,

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66
"private": true,
77
"scripts": {
88
"start": "npm run build",
9-
"build": "node ./eng/update-readme.js",
9+
"build": "node ./eng/update-readme.mjs",
1010
"contributors:add": "all-contributors add",
1111
"contributors:generate": "all-contributors generate",
1212
"contributors:check": "all-contributors check",
13-
"validate:collections": "node ./eng/validate-collections.js"
13+
"collection:validate": "node ./eng/validate-collections.mjs",
14+
"collection:create": "node ./eng/create-collection.mjs"
1415
},
1516
"repository": {
1617
"type": "git",

0 commit comments

Comments
 (0)