jonschlinkert / gray-matter

Smarter YAML front matter parser, used by metalsmith, Gatsby, Netlify, Assemble, mapbox-gl, phenomic, vuejs vitepress, TinaCMS, Shopify Polaris, Ant Design, Astro, hashicorp, garden, slidev, saber, sourcegraph, and many others. Simple to use, and battle tested. Parses YAML by default but can also parse JSON Front Matter, Coffee Front Matter, TOML Front Matter, and has support for custom parsers. Please follow gray-matter's author: https://github.com/jonschlinkert
https://github.com/jonschlinkert
MIT License
3.97k stars 138 forks source link

consider removing fs #50

Closed jonschlinkert closed 7 years ago

jonschlinkert commented 7 years ago

The goal is to make gray-matter easier to use in browsers/non-node.js environments.

Related: https://github.com/jonschlinkert/gray-matter/issues/49

My first thought is that we could achieve this by publishing gray-matter-fs or something. Any other ideas?

cc @tech4him1

jonschlinkert commented 7 years ago

just saw this comment. That might be a solution too.

tech4him1 commented 7 years ago

Another way that would work for us if you don't want to change the sources would be to have a re-packaged version for browsers that was run through Babel or something like that and left out the Node functions like matter.read/fs.

If we did it that way, then you should be able to build the sources however you want, then publish it as two separate packages (maybe gray-matter and gray-matter-browser or something like that).

jonschlinkert commented 7 years ago

If we did it that way, then you should be able to build the sources however you want, then publish it as two separate packages (maybe gray-matter and gray-matter-browser or something like that).

yeah, that's not a bad idea. Let me think about it for a little bit (today). @doowb?

tech4him1 commented 7 years ago

Another option if we are just considering fs is wrapping the require in an if:

if (require) { require('fs'); }

I'd still have to test this though, I'm not sure that it works with WebPack.

jonschlinkert commented 7 years ago

what if we did gray-matter-lite or something, then we could require that into this module for the time being to keep the API the same here.

tech4him1 commented 7 years ago

That sounds really good.

doowb commented 7 years ago

I like the idea of having a separate module with browser compatible features that is then required into gray-matter.

The if(require) { require('fs'); } won't work for webpack because webpack does static analysis to determine which modules to include by looking at the require keyword.

Another option that might work is for gray-matter to add a browser property to package.json with {"fs": false} since webpack supports the package browser field spec now. I haven't tested this to know if it would work for you or not.

erquhart commented 7 years ago

That would be awesome.

tech4him1 commented 7 years ago

This is working as of version 3.0.6. Thanks!

jonschlinkert commented 7 years ago

This is working as of version 3.0.6. Thanks!

Great! I was going to ask. Thanks!