cosmiconfig icon indicating copy to clipboard operation
cosmiconfig copied to clipboard

javascript loader doesn't support custom content

Open jheyer159 opened this issue 4 years ago • 1 comments

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?

jheyer159 avatar Aug 03 '21 22:08 jheyer159

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.)

davidtheclark avatar Aug 06 '21 16:08 davidtheclark