4bfcf8345c
Simplify the esmodule detection. If there's any import/exprt usage, it will return `Module` in ast.type otherwise `Script` when `isModule` is set to `"unknown"`
13 lines
375 B
TypeScript
13 lines
375 B
TypeScript
export function buildExports(moduleExports: any, isESM: boolean) {
|
|
let ret = ''
|
|
Object.keys(moduleExports).forEach((key) => {
|
|
const exportExpression = isESM
|
|
? `export ${key === 'default' ? key : `const ${key} =`} ${
|
|
moduleExports[key]
|
|
}`
|
|
: `exports.${key} = ${moduleExports[key]}`
|
|
|
|
ret += exportExpression + '\n'
|
|
})
|
|
return ret
|
|
}
|