feat: config file supports "type": "module" in package.json

This commit is contained in:
alex8088
2024-01-04 00:00:57 +08:00
parent 40a1b64639
commit 694e134a52
2 changed files with 13 additions and 6 deletions

View File

@@ -73,3 +73,14 @@ export function loadPackageData(root = process.cwd()): PackageData | null {
}
return null
}
export function isFilePathESM(filePath: string): boolean {
if (/\.m[jt]s$/.test(filePath) || filePath.endsWith('.ts')) {
return true
} else if (/\.c[jt]s$/.test(filePath)) {
return false
} else {
const pkg = loadPackageData()
return pkg?.type === 'module'
}
}