in src/loader.ts [49:66]
async function isEsModule(modulePath: string): Promise<boolean> {
const ext = path.extname(modulePath);
if (ext === '.mjs') {
return true;
}
if (ext === '.cjs') {
return false;
}
const {readPackageUp} = await dynamicImport('read-package-up');
const pkg = await readPackageUp({
cwd: path.dirname(modulePath),
normalize: false,
});
// If package.json specifies type as 'module', it's an ES module.
return pkg?.packageJson.type === 'module';
}