Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
December 22, 2022 03:23 pm GMT

Different approaches to testing your own packages: local files

Introduction

Lets say youre developing a new package; it doesnt matter if its a really cool library of React components or a great new set of utils for NodeJS based projects. We all know that the first step to making sure that it will be compatible with different node versions and will work smoothly and without errors is having a proper set of tests.

However, perhaps you also want to test it locally in one of your projects before publishing it to npm / yarn so everyone can start using it. And thinking wider, not only focus on the first release but also take into account new updates that you want to try before publishing them.

In this series of posts, well describe four alternatives you can use to achieve this purpose. They are sorted by difficulty, but thats not the only factor to take into account, because the most advanced ones also offer a set of utils that the easier ones dont have. So, its up to you to decide which one fits best for your use case.

Well briefly explain how to use these techniques and the benefits of:

  1. Linking local files
  2. Npm link
  3. Verdaccio
  4. Relative deps

So, lets start with the first approach!

Local files

There is an extremely easy way to add a package to our project from a local dependency, and those are the steps.

First of all, lets imagine we have our projects structured as in the following image

Folder filesystem with two projects at same level

  • Go to the root project of your library, install the package and build the library of the local package:
$ cd my-fancy-library $ npm i && npm run build 
  • As the next step we must move the project to where we need to use our fancy library as a local package and install it
$ cd my-awesome-project $ npm i -save ../my-fancy-library 

This command will create a link between the two projects, adding the library as dependency

package.lock entry with relative route to a my fancy library folder

And create a link inside the node_modules/@ks folder

my fancy library folder with sym link

  • Now every time we modify the local package, we must rebuild the library to allow our project to detect the changes and rebuild it, or.... we can update the package.json file and add a new command to watch and rebuild the library on every change: "build:watch": "rollup -c --watch && copyfiles -f ./src/**/assets/* ./dist/assets"

Original Link: https://dev.to/one-beyond/different-approaches-to-testing-your-own-packages-1kdg

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To