@davenportsociety/clear-thought-patterns
Version:
A Model Context Protocol (MCP) server providing systematic thinking tools, mental models, and debugging approaches for enhanced problem-solving capabilities
53 lines (44 loc) • 1.49 kB
JavaScript
/* eslint-disable no-unused-vars */
/* eslint-disable no-undef */
/*
* Adaptive launcher that loads the appropriate build (ESM or CJS) produced by tsup.
* We emit both formats into dist/. This script will prefer the ESM build when
* running in an environment that supports dynamic import of ESM from CommonJS context.
*/
import { pathToFileURL } from 'url'
import { createRequire } from 'module'
import { existsSync } from 'fs'
import { join, dirname } from 'path'
import { fileURLToPath } from 'url'
const __filename = fileURLToPath(import.meta.url)
const __dirname = dirname(__filename)
async function main() {
const distDir = join(__dirname, '..', 'dist')
const esmEntry = join(distDir, 'index.js') // ESM build (package type=module)
const cjsEntry = join(distDir, 'index.cjs') // tsup will emit .cjs for cjs format
const hasCjs = existsSync(cjsEntry)
const hasEsm = existsSync(esmEntry)
if (!hasCjs && !hasEsm) {
console.error('Build outputs not found. Please run `pnpm build` first.')
process.exit(1)
}
// If executed via Node that supports ESM (>=13.2 with type=module) we can just import the esm file.
if (hasEsm) {
try {
await import(pathToFileURL(esmEntry).href)
return
} catch (_e) {
// Fallback to CJS below
}
}
if (hasCjs) {
const require = createRequire(import.meta.url)
require(cjsEntry)
return
}
}
main().catch((err) => {
console.error(err)
process.exit(1)
})