Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Francesco Menghi
Francesco Menghi

Posted on • Edited on

     

Publish packages from within a Monorepo

In this blog post I will go over the details of how we manage and publish packages inside our Telescope monorepo.

David recently shared alink where I found a good definition for monorepo that I wanted to share:

A monorepo is a single repository containing multiple distinct projects, with well-defined relationships.

Within Telescope, we have just that:

└── src   ├── api   ├── backend   ├── docs   ├── mobile   └── web
Enter fullscreen modeExit fullscreen mode

We have all of the APIs, backend, frontend, mobile app and the new Docusaurus docs all inside the same repo.

We recently made the switch to Turborepo and to try out itsfeatures, I havechanged the way we lint our project. We used to run eslint from the root of Telescope, but now we have individual.eslintrc.js files inside each project and let Turborepo manage it all.

Sinceversion 1.1, Turborepo config moved frompackage.json to its ownturbo.json file.

This is ourturbo.json that defines thelint command inside itspipeline:

{"pipeline":{"build":{"dependsOn":["^build"]},"lint":{"outputs":[]}}}
Enter fullscreen modeExit fullscreen mode

When we runpnpm turbo run lint, Turborepo will go over each package defined inpnpm-workspace.yaml and run the lint command. This process is very efficient because it keeps a cache and reuses it if there are no changes to the files in the project.

For example, if I make changes to the docs, Turborepo will only run eslint in the docs, and use the previously created cache for everywhere else.

We have a new@senecacdot/eslint-config-telescope package that contains the rules we reuse with every.eslintrc.js and it lives inside thetools directory:

└── tools   └── eslint      ├── index.js      └── package.json
Enter fullscreen modeExit fullscreen mode

This package ispublished to the npmjs registry. To call it inside a.eslintrc.js file we useextends:

module.exports={extends:'@senecacdot/eslint-config-telescope',overrides:[// more rules here],};
Enter fullscreen modeExit fullscreen mode

Since@senecacdot/eslint-config-telescope lives inside the monorepo, we have automated the release of the package thanks topnpm publish.

Release to npmjs registry

There is a GitHub Actionsworkflow that handles the release of Telescope and, at the end of it, I added:

-uses:pnpm/action-setup@v2.0.1with:version:6.30.1-name:NPM Publishuses:actions/setup-node@v2with:node-version:'16.x'registry-url:'https://registry.npmjs.org'cache:'pnpm'-run:pnpm install-run:pnpm -r publish --no-git-checks --access=publicenv:NODE_AUTH_TOKEN:${{ secrets.NPM_TOKEN }}
Enter fullscreen modeExit fullscreen mode

The key part here ispnpm -r publish. The-r stands for recursive: pnpm will go look at eachpackage.json to see if a package has an updated version and, if so, will publish it to the registry.

Top comments(1)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss
CollapseExpand
 
jackmellis profile image
Jack
Typescript and React nerd. I have a soft spot for architecture and unit testing
  • Location
    United Kingdom
  • Joined

Thanks for this. I've been fighting lerna publish + github actions for a week now and it turns out the solution was to just switch from npm to pnpm for the publish command.

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

  • Location
    Toronto, Canada
  • Joined

More fromFrancesco Menghi

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp