env-cmd icon indicating copy to clipboard operation
env-cmd copied to clipboard

refactor: made adding a new loader easier

Open KilianKilmister opened this issue 5 years ago • 4 comments

KilianKilmister avatar Jul 12 '20 20:07 KilianKilmister

referencing my comment in #133

turned out to be a very small change.

  • js/cjs are loaded with dynamic import
  • other ext are mapped against an object 0f {[exst: string] (src: string) => object} (which currently just contains '.json': JSON.parse)
  • if ext doesn't have a mapping it falls back to the JSON.parse

KilianKilmister avatar Jul 12 '20 21:07 KilianKilmister

This is a very cool PR. I like the simplicity of it + the clarity it adds. Would make it a lot easier to support more file extensions.

toddbluhm avatar Aug 04 '20 08:08 toddbluhm

@toddbluhm awesome-sauce, I believe the tests only failed because i didn't pre-lint, so thats easily fixable. Now it's been a while since i wrote this and I'm still dealing with the aftermath of a corrupted system-drive on my main machine, so rewisiting the code won't be ultra swift, but i'll take your response as a green-light on polishing this up.

Want me to include YAML and/or JSON5 suport rightaway aswell? I'd suggest to include both, but it's your call.

KilianKilmister avatar Aug 04 '20 12:08 KilianKilmister

Any update on this? I'm happy to help get this merged if required. We would really like to use json with comments.

@toddbluhm if you're concerned about adding another dependency you could make it a peerDependency and/or just have a helpful error message if the user tries to use jsonc without that dependency installed. I'm happy to make a PR for this. facebook's create-react-app uses this approach

k-yle avatar Sep 11 '20 23:09 k-yle