Files
dinlo 436a9631fc Initial commit
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-05-31 18:44:04 +08:00

24 lines
552 B
JavaScript

const url = require("url")
const fs = require("fs")
exports.dynamicImport = async function dynamicImport(path) {
try {
return await import(fs.existsSync(path) ? url.pathToFileURL(path).href : path)
} catch (error) {
return Promise.reject(error)
}
}
exports.dynamicImportMaybe = async function dynamicImportMaybe(path) {
try {
return require(path)
} catch (e1) {
try {
return await exports.dynamicImport(path)
} catch (e2) {
e1.message = "\n1. " + e1.message + "\n2. " + e2.message
throw e1
}
}
}