Skip to main content
Glama
chunk-4QUQJTWZ.mjs2.36 kB
// src/reflect.ts import fs from "fs/promises"; import path from "path"; import fg from "fast-glob"; import { gray, green } from "kolorist"; var reflect = async (options) => { const { globOptions = {}, name = "reflect", reflect: reflect2, silent } = options; const cwd = process.cwd(); const files = await fg(options.files, { cwd: path.resolve(cwd, "dist"), ...globOptions, absolute: true, ignore: [...globOptions.ignore || [], "node_modules"] }); const logger = (message) => { if (!silent) console.log(`[${name}]`, message); }; if (!files.length) logger(gray("No files matched")); const output = []; for (const file of files) { const code = await fs.readFile(file, "utf8"); const result = await reflect2(code); const filename = path.relative(cwd, file); if (result) { await fs.writeFile(file, result); output.push(result); logger(`${green("\u2714")} ${filename}`); } else { logger(gray(`skip ${filename}`)); } } return output; }; // src/fix-cjs-dts.ts var exportRegex = /export \{\s*(?:\S.*)?\b(?<name>.+) as default.*(?:[\n\r\u{2028}\u{2029}]\s*)?\};/u; var fixCjsDts = async (options) => { return reflect({ files: "**/*.d.{ts,cts}", ...options, name: "fix-cjs-dts", reflect: (code) => { const result = exportRegex.exec(code); if (result?.groups?.name) { const statement = `export = ${result.groups.name}`; if (!code.endsWith(statement)) return code + statement; } } }); }; // src/fix-cjs-exports.ts var statements = ` // fix-cjs-exports if (module.exports.default) { Object.assign(module.exports.default, module.exports); module.exports = module.exports.default; delete module.exports.default; } `; var fixCjsExports = async (options) => { const { readPackage } = await import("read-pkg"); const { type } = await readPackage(); const isEsm = type === "module"; const suffix = isEsm ? "cjs" : "js"; const files = options?.files?.length ? options.files : `**/*.${suffix}`; return reflect({ ...options, files, name: "fix-cjs-exports", reflect: (code) => { if (code.includes("module.exports = __toCommonJS") && !code.endsWith(statements)) { return code + statements; } } }); }; export { reflect, fixCjsDts, fixCjsExports };

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/sadiuysal/mem0-mcp-server-ts'

If you have feedback or need assistance with the MCP directory API, please join our Discord server