azu / rc-config-loader

Load config from .{product}rc.{json,yml,js} file
MIT License
60 stars 6 forks source link

Support ESM `"module":true` projects #22

Open josh-hemphill opened 1 year ago

josh-hemphill commented 1 year ago

When loading *rc.js files that contain export const or export default results in failing with errors.

azu commented 1 year ago

rc-config-loader treat JS as CommonJS. https://github.com/azu/rc-config-loader/blob/c4e335c2c02d347ef06f8cde9eb6efd216c0537a/src/rc-config-loader.ts#L171-L172C16

I have a feeling that if JS is to be treated as an ECMAScript Module, Dynamic Import will probably be required. It means that require Async API. Also, It looks like VM APIs require async api.

Seems difficult to support right away. rc-config-loader aim to get Sync APIs.

FYI: cosmiconfig will support ESM. https://github.com/davidtheclark/cosmiconfig/pull/283