cosmiconfig
cosmiconfig copied to clipboard
javascript loader doesn't support custom content
This loadJS function doesn't have a content parameter.
https://github.com/davidtheclark/cosmiconfig/blob/18346056c9a7fdf8d7531ea5a998edfb255fc140/src/loaders.ts#L10
loadJson and loadYaml both support custom content
https://github.com/davidtheclark/cosmiconfig/blob/18346056c9a7fdf8d7531ea5a998edfb255fc140/src/loaders.ts#L20
https://github.com/davidtheclark/cosmiconfig/blob/18346056c9a7fdf8d7531ea5a998edfb255fc140/src/loaders.ts#L35
Is this intended?
Hi @jheyer159. The loadJS implementation uses require, relying on Node.js to parse the JS, so it doesn't have a way to handle a content parameter where you'd pass a raw JS string. You could write a custom loader for this, using an npm package like https://www.npmjs.com/package/require-from-string. (That's how cosmiconfig did it a while ago, but we ran into some troubles with it as a generic solution.)