Conversation
| @@ -0,0 +1,2 @@ | |||
| /** Version of SVGO. */ | |||
| export const VERSION = '4.0.0'; | |||
There was a problem hiding this comment.
Just wondering why don't you just require package.json? It seems simpler...
Also, mind you that requires come with a penalty when in CJS; modules is a different case since they are inherently a lot faster when loading.
There was a problem hiding this comment.
- ESM doesn't have stable support for importing JSON files yet. (When it does, we'll migrate to this!)
- When using
require, Rollup isn't bundling/inlining JSON files, which breaks the browser build. (Tries to importpackage.jsonrather than inlining the JSON at build time, while there may be a fix for that I'm also concerned that it will bundle the wholepackage.jsoninstead of just theversionwhich I also don't want.) - Don't want to take an approach with reading it from
fsas this would break the browser version wherefsisn't available.
Most other projects that export a version appear to take a similar approach, which is what I referenced when I did this solution:
- Axios, which uses a gulpfile.
- Moment.js, which uses a grunt task.
- Handlebars, which also uses a grunt task.
I've only seen 2 projects so far take your approach with require, but neither is applicable in our case:
- Mongoose, but it only exports the version in the Node.js exports, and isn't available in the browser bundle.
- Winston, which requires, but lacks browser support so supporting both isn't a concern for them.
Feature parity between Node.js and browser is important for SVGO, and this seemed like the best approach for that. Then I opted for a Node.js script instead of a gulpfile or grunt task, just because we don't have too much going on yet.
If you have a better idea, you're welcome to pitch it though! I was waiting before merging, specifically to see if others would propose a better approach.
There was a problem hiding this comment.
I guess I didn't consider the browser bundle, although I'm pretty sure there are ways to do it.
I guess your solution does the job too, I was just thinking out loud in case there was a simpler way :)
Adds a
VERSIONexport, similar to React, Axios, and Lodash.This will enable third-party libraries to check what version of SVGO is in use during runtime, and is intended to supersede the need to import our
package.jsonfile, which we don't want to make part of our public API.Chores
Updates our ESLint config from
2021to'latest'. I wanted to keep it at 2022 or later as we can use top-level awaits.Usage
Related