![]() ![]() ![]() Now we can run the unit tests of the affected packages with a single command, but, what about if the unit:test script in any package needs any other script to be executed before? For example, suppose that the sum-two package has a build script that must be executed before running the unit tests. We will install Jest in the workspace (as mentioned above, it is a devDependency, so we don’t have to install it on every single package):īut, if you create another branch and modify the packages/sum-one/index.js file, running pnpm test:unit:affected would execute the unit tests of both packages, because modifying sum-one also affects to sum-two. So, let’s add one unit test to our recently created package in order to see an example. The scripts of each project can be executed independently from each package folder, and we can also define scripts for the workspace. And we can also use executables of the dependencies installed in the workspace from the npm scripts of the packages! □ Project and workspace scripts Note that the dependencies of all packages in the repository are installed when pnpm i is executed in the root folder. Otherwise, they will be missing when the packages are published. but note that the dependencies of each package (those required to work once they are published) must remain on their own package.json files. The one in the root folder should contain shared devDependencies across many projects, such as test, build or lint libraries, etc. Now we have two package.json files in the repository. exports = sumOne Project and workspace dependencies Here we are going to use npm to install it:įunction sumOne ( number ) There are many methods for installing it, you can check them all in the Pnpm installation docs. Installing PnpmĪs seen in the previous post, we are going to use Pnpm mainly to be able to link packages locally using its workspace feature.įirst of all you have to install Pnpm globally in order to use it as Npm client and to run the package.json scripts that we will create in next steps. I also like to keep integration or E2E tests in a different folder. In this case, all packages could be distributable and dependencies of other ones, that’s why the folder is named packages. Nx recommends as best practices to have an app folder and a libs folder for reusable libraries, but in my opinion that structure is more recommendable if you are going to include also front-end projects or other type of not versioned and distributable applications. You could store your packages depending of their type in different folders, for example. Please refer to the RFC for further details.The name of the folders is something that can be changed at your convenience. Wrapping up, there is no one-size-fits-all solution and you need to understand what you want to get and what you can sacrifice for that.Īs I mentioned in the initial answer npm v7 implemented installing peer dependencies by default. ![]() There is a plan to add this feature to npm v7, actually npm did it before v3. There is install peers cli package that works with npm and yarn. Or you can use something similar to this rollup plugin that automates adding externals basing on peerDependencies, so you can safely list them as devDependies as well.īoth options are considered legit in this lerna issueĪnother option is to install your peer dependencies and as for now, there is no "official" solution for that. ![]() And you can do pretty the same without typescript in, for example, Create React App using jsconfig.json. For example, Angular suggests using TS paths option. You may need to keep track of such dependencies and mark them as external in order to avoid including them into the built version of the lib. Option 1 is a quite common approach but as you said it adds maintenance cost. The problems may occur when some tool relies on its own resolution logic or there are different versions of some dependency and so on. So, basically it should work in most cases. Yarn workspaces should install almost everything in the root node_modules relying on node's module resolution algorithm. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |