Over the weekend, I started using the react-runtime-config library to configure one of my React apps. While it works great, the last activity on the library was over two years ago, so I decided to fork the repository and publish the library under my own scope. This led me down a very eccentric path and opened a number of new doors.
Step One: Automate
I wanted to create an automated build and release process for the library. The original repository uses TravisCI for builds, but I much prefer having the builds within Github for everyone to see.
The build and publish processes are pretty straight forward: I implemented a build pipeline which is triggered on any commit and runs a build and test. The publish pipeline is triggered on creating a release in Github, and runs the same build/test, but updates the package version to the release version and then publishes the package to npmjs.org under the
Sure, I could have stopped there… but, well, there was a ball of yarn in the corner I had to play with.
Step 2: Move to Yarn
NPM is a beast. I have worked on projects which take 5-10 minutes to run an install. Even my little test UI project took about three minutes to run an
npm install and
The “yarn v. npm” war is not something I’d like to delve into in this blog. If you want more detail, Ashutosh Krishna recently posted a pretty objective review of both over on Knowledge Hut. Before going all in on Yarn with my new library, I tested Yarn on my small UI project.
I started by deleting my
node_modules folder. Then, I ran
yarn install to get things running. By default, Yarn was using Yarn 1.x, so I still got a
node_modules folder, but a
yarn.lock file instead of
package-lock.json. I modified my CI pipelines, and I was up and running.
On my build machine, the
yarn install command ran in 31 seconds, compared to 38 seconds for
npm install on the same project.
yarn build took 34 seconds, compared to 2 minutes and 20 seconds for
Upgrading to modern Yarn
In my research, I noted that there are two distinct flavors of yarn: what they term “modern versions” of Yarn, which is v2.x and above, and v1.x. As I mentioned, the yarn command on my machine defaults to the 1.x version. Not wanting to be left behind, I decided to migrate to the new version.
The documentation was pretty straight forward, and I was able to get everything running. I am NOT yet using the Plug and Play installation strategy, but I wanted to take advantage of what the latest versions have to offer.
I am not an “everyday npm user,” so I cannot speak to all the edge cases which might occur. Generally, I am limited to the standard install/build/test commands that are used was part of web development. While I needed to learn some new commands, like
yarn add instead of
npm install, the transition was not overly difficult.
In a team environment, however, moving to Yarn would require some coordination between the team to ensure everyone knows when changes would be made and avoid situations where both package managers are used.
With my small UI project converted, I was impressed enough to move the
react-runtime-config repository and pipelines to use Yarn 3.
Step 3: Planned improvements
I burned my allotted hobby time on steps 1 and 2, so most of what is left is a to-do list for
I am a huge fan of generated docs, so I would like to get some started for my version of the library. The current readmes are great, but I also like to have the technical documentation for those who want it.
External Configuration Injection
This one is still very much in a planning stage. My original thought was to allow the library to make a call to an API to get configuration values, however, I do not want to add any unnecessary overhead to the library. It may be best to allow for a hook.
I would also want to be able to store those values in local storage, but still have them be updatable. This type of configuration will support applications hosted within a “backend for frontend” API, and allow that API to pass configuration values as needed.
I felt like I made some progress over the weekend, if only for my own projects. Moving
react-runtime-config allowed me to make some general upgrades to the library (new dependency updates) and sets the stage for some additional work. My renewed interest in all things Node also stimulated a move from Create React App to Vite, which I will document further in an upcoming post.