Blazing Fast Tips: Publishing to NPM

Поділитися
Вставка
  • Опубліковано 7 жов 2024
  • Publishing a package to npm can be daunting, especially when it comes to versioning. Here's how I approach it, using the best tools available in 2023.
    Got an opinion about one of these? GET IN THE COMMENTS.
    Example repo: github.com/mat...
    Changesets: github.com/cha...
    PNPM: pnpm.io/
    GitHub Actions: github.com/fea...
    TypeScript: typescriptlang...
    tsup: tsup.egoist.dev/
    Become a TypeScript Wizard with Matt's upcoming TypeScript Course:
    www.totaltypes...
    Follow Matt on Twitter
    / mattpocockuk

КОМЕНТАРІ • 184

  • @lp1926.guitars
    @lp1926.guitars 6 місяців тому +10

    the amount of info you can pack in one video plus the clarity of the sentences is remarkable

  • @diert
    @diert Рік тому +158

    Just awesome. It would be amazing if you make video about monorepo version of that with multiple packages.

    • @kevinzunigacuellar
      @kevinzunigacuellar Рік тому +1

      It's mostly the same setup it just needs a pnpm workspaces file and if you have apps and packages in the same repo you may want to ignore publishing apps to npm using the changesets config.

    • @diert
      @diert Рік тому +3

      @@kevinzunigacuellar I don't want to ignore publishing and changeset config though. What I mean was the monorepo with tool like Nx or Turborepo we can publish multiple packages to npm with Lerna.

    • @onlyspaceghost
      @onlyspaceghost Рік тому +3

      Changesets supports pnpm mono repos, it's super easy to setup. There is even information on the pnpm docs for changesets

    • @andrewglick6279
      @andrewglick6279 Рік тому +10

      I second this--I just tried setting up my first monorepo a few days ago and it took me close to a full day to get everything figured out (like how pnpm uses -F instead of -w like npm, but -w means something else, and weird stuff happened). I know there's official documentation out there, but there are so many different tools, each more complex then the last, and I think a ~5 minute high quality starter video would be extremely helpful instead of wasting 6 hours
      A few things that have personally confused me about monorepos: What packages should be installed at the top level package.json vs the ones in packages? What about defining subpackages as dependencies of the root package.json? Or as "references" in the root tsconfig? Does that mean you should/shouldn't have the tsconfigs of each package extend from the root package? Again, I know there is "official" documentation about all these things, but it can be very confusing if you're not already familiar with it, and every boilerplate I find does things slightly differently without explaining why. Thanks, Matt!

    • @lkfieilmnmdfh
      @lkfieilmnmdfh Рік тому

      Changesets + 1

  • @Atul_25
    @Atul_25 12 днів тому

    You taught in 3 mins, something, most can't do in 30 mins.
    That too so clearly.
    Brilliant 👌
    Thanks a lot 🙏 😊

  • @littleluce
    @littleluce Рік тому +32

    Loved the pace of this video. Excellent job getting right to the point without over-explaining things we already know. I wish more UA-cam videos were like this!

    • @ripvannwinkler
      @ripvannwinkler Рік тому +1

      Never seen this person''s vids before, but I subscribed after ~1 minute of watching this for the exact reasons you noted. EXCELLENT pacing.

  • @grgry06
    @grgry06 Рік тому +5

    I have learned quite a lot under 4 minutes. Quite an achievement actually. I just found out about tsc being a linter for my project, and use it along with other compilers like tsup. Thank you so much for making this awesome, educational, and straightforward video! 🍻

  • @sfulibarri
    @sfulibarri Рік тому +36

    supporting both cjs and esm is a nice touch; its really frustrating how many popular npm modules just did a hard cut to esm expecting their dependents to be able switch easily.

    • @litbro8180
      @litbro8180 Рік тому +7

      Hi. I am one of those package developers who did a hard cut to ESM. I decided against continuing to support CJS because it is 1. No longer the standard that should be used and 2. Generally a headache to support both CJS and ESM in more complex projects.

    • @sfulibarri
      @sfulibarri Рік тому +2

      @@litbro8180 I am sure there are specific situations where a more complex library would not be able to easily support both but there are many instances where a relatively simple, but popular module has transitioned and left dependents in the dust. I currently have the misfortune of maintaining a few older and very troublesome nodejs projects at work that for various reasons cannot be easily transitioned to esm. I have several dependencies that no longer support cjs and despite the authors/maintainers stating that the cjs version would continue to receive support, my `npm audit` results look worse and worse every month. I agree that esm is the new standard that we all should strive for but cjs is still widely in use and broadly speaking, and as demonstrated in this video, it is not difficult to support both.

    • @ColinRichardson
      @ColinRichardson Рік тому +1

      @@sfulibarri We have that with all the time, we want to update lib x, because it has bug fixes/features we want.. but x has the dependency on y, when y is used, then lib z breaks... its all very annoying..

  • @krimod
    @krimod Рік тому +23

    Awesome video !! it would be amazing if you could make a video on how to setup a typescript project with all the tsc, eslint, prettier with vscode. Yeah it's 2023 and I still get confused with all these packages.

  • @tjblackman08
    @tjblackman08 Рік тому +4

    I spent HOURS figuring out how to publish a TS package with esm and cjs module about 6 months ago, and I never even heard of tsup.... I'm actually excited to go make upgrades! 12/10 video! Thank you

  • @feldinho
    @feldinho Рік тому +1

    This is amazing! All the hows and whys in under 4 minutes!! Thank you so much for that!

  • @Marc-jc4uu
    @Marc-jc4uu Рік тому +2

    Great video! You did an excellent job of breaking down the complex process and making it easy to understand. I appreciate the clear explanations and step-by-step instructions for publishing npm packages. Keep up the good work!

  • @Prabhuk-s4f
    @Prabhuk-s4f 5 місяців тому

    Thank you so much Matt Pocock

  • @HosamSultan
    @HosamSultan Рік тому +1

    I really can't thank you enough for this condensed video.
    The pace made me struggle the first time I watched the video a while ago, but now that I needed the instructions, I know that this pace is all I needed!

  • @ytrkptl
    @ytrkptl Рік тому +1

    Thank you so much. Would appreciate more videos like this one where you teach us how to create and maintain or manage our own packages.

  • @nivaldolemos5280
    @nivaldolemos5280 Рік тому +1

    Succinct and to thew point. Than you for this.
    Gonna take a look at tsup.

  • @hamdaniash-siddiq5021
    @hamdaniash-siddiq5021 3 місяці тому

    When Matt uploads a new video, we know it’s going to be a new useful knowledge. You’re awesome..❤

  • @jeffnikelson5824
    @jeffnikelson5824 Рік тому +1

    bro your videos are getting better and better
    really nice format and I like that you kinda just focus on the important parts
    thumbs up 👍

  • @khairulhaaziq2332
    @khairulhaaziq2332 Рік тому +1

    Thank you for this. Learning to release my first library and this came in time!

  • @PlayerRPG85
    @PlayerRPG85 5 місяців тому

    This was great! Fast is good, people

  • @goodboyneon
    @goodboyneon Рік тому

    I just across your channel. Can't belive I've been missing all of these golden content for all these days!

  • @prasathsoosaithasan1281
    @prasathsoosaithasan1281 Рік тому

    Awesome, thank you. Good introduction to tsup will help me to get rid of my overkill rollup setup.

  • @JoystickStereo
    @JoystickStereo 9 місяців тому

    I've been running around in circles all day trying to figure out how to bundle my TS package properly in a way that let's it work properly with 'npm link'. Finally, _finally,_ I've found a video that gives a working process (and in a very concise, easily digestible manner at that)-thank you.

  • @danwhite2717
    @danwhite2717 8 місяців тому

    Probably one of the best informative videos I’ve seen in a long time

  • @somebody656
    @somebody656 Рік тому +1

    Love it. I have been doing my old export to only cjs for a while now. It’s about time my workflow for publish gets a upgrade

  • @lakardion
    @lakardion Рік тому

    This is exactly what I was looking for. Thank you very much Matt!

  • @totetoBT
    @totetoBT Рік тому

    Great summary, just what I was looking for. Nice pace also!

  • @alexcasillas
    @alexcasillas Рік тому +1

    Really liked this one Matt 👏🏻 It’s been a long since I’ve published something so the next time I might go with this setup 👌🏻

  • @FunctionGermany
    @FunctionGermany Рік тому +2

    great and concise tutorial! makes me wanna build an npm package even though i have nothing to share xD

  • @MarkJaquith
    @MarkJaquith Рік тому

    What a great knowledge dump. Love these sorts of videos.

  • @Q_20
    @Q_20 Рік тому

    Wow. I have been missing out on A LOT. Thanks you so much!

  • @sle6423
    @sle6423 Рік тому

    This is such a great reference!! Thank you
    Would love to see the Deno version next

  • @leumasme
    @leumasme Рік тому +2

    I'd recommend the `wireit` script runner developed by google for all but the most simple `npm run` scripts.

  • @anushibinj
    @anushibinj Рік тому

    🤯 Amazing video

  • @ASTLW-u8u
    @ASTLW-u8u Рік тому

    Seriously I had lost hope to support CommonJS and ES6 imports and publish a package ... but at last found your video ... Tks man!!

  • @ErmandDurro
    @ErmandDurro Рік тому

    Amazing content. Loved it. Thanks a lot 🙏

  • @spiffjekey-green4034
    @spiffjekey-green4034 Рік тому

    You made me watch a 3 minutes video in 40 minutes, the content is just too good. Big thanks :)

  • @articb
    @articb Рік тому

    Clear and concise video.👍👍

  • @claireworld_
    @claireworld_ Рік тому

    I’m really liking your videos!!

  • @rafaeltab
    @rafaeltab Рік тому +1

    How on earth is this video only 4 minutes? It taught me more than my first year of college lol.

    • @grgry06
      @grgry06 Рік тому

      College probably breaks all the simplest procedures down to very complex ones to understand like how it works on a technical level. This video demonstrates the steps to actually reach your goal, without proper understanding of what the step was intended for and etc. Anyways, Matt did a great job for making this simple and understandable at the same time!

    • @rafaeltab
      @rafaeltab Рік тому

      ​@@grgry06 Mostly it was because they decided to teach us a made-up language for the first half of the year. Only in the second half, they started teaching us python, where I literally had to explain to my teacher how to print a string to the console, when I hadn't even programmed in python before. Anyways, the only thing I really learned that year was what scrum was, and what UML was. Of course, both are very useful skills to have, however, they were taught in such a way that no one really knew what they were in the end. And I actually only learned these skills while working on personal projects about two years later.

  • @zettca
    @zettca Рік тому +1

    Really nice, concise and complete guide. Thanks 👍
    Regarding the versioning and release notes, I much prefer to use semantic-release: You just need to name your PRs/commits according to a convention, and you'll get automation SemVer and changelog for free, with the side benefit of better PR/commit messages.

    • @mattpocockuk
      @mattpocockuk  Рік тому

      Ain't no-one going to shift me off changesets, it's just the bomb.

    • @nadico5740
      @nadico5740 Рік тому

      @@mattpocockuk can you get the commit messages of the PR grouped by " type:" with changests?

  • @rthurJ
    @rthurJ Рік тому

    mandatory algorithmic signal boost, because this video is great and more people should see it!

  • @sghsri
    @sghsri Рік тому

    I was using tsc for builds, but tsup is so much better, thank you!!

  • @DEV_XO
    @DEV_XO Рік тому

    Amazing!

  • @EnricoColautti
    @EnricoColautti Рік тому +1

    Great video! Would you please make a video about the configuration of the setup of a project with microfrontends, a components library, typescript and possibly tailwind?

  • @abhaykumar9806
    @abhaykumar9806 Місяць тому

    I followed your video till the end. Definitely gained confidence on few things. This video does not publish the packages though. Just creates a PR. I would definitely love to see the complete picture. If you have a course to setup pnpm, turborepo, tsup and related course, please share the link

  • @carlosricardoziegler2650
    @carlosricardoziegler2650 Рік тому

    Great and simple. We are using Vite to create some projects and libraries too.

  • @froxx93
    @froxx93 Рік тому +1

    This video is a nice quick overview on what things to do. But it also creates lots of questions on why to do those things, and also what they do in specific. A bit more details on some of those things would be nice, like what's that licensing and why do we choose that over others? What do github workflows work? How does npm actually know that I deployed things to it?
    Maybe in a different video

    • @mattpocockuk
      @mattpocockuk  Рік тому +3

      Yep, I'm thinking with these style of videos a big-picture idea is the best thing I can deliver. Whet your appetite and spark a googling session!

  • @albertdugba
    @albertdugba Рік тому +3

    Very educative video. Keep them coming Matt. Quick question. Is something like this going to be added in total typescript maybe like deep dive or something

  • @paviad
    @paviad Рік тому

    Brilliant!

  • @mekhoinfo2118
    @mekhoinfo2118 Рік тому

    keep going brother, keep going

  • @talhaibnemahmud
    @talhaibnemahmud Рік тому

    Awesome video ❤️

  • @explodingcamera
    @explodingcamera Рік тому +7

    the module field is kinda deprecated and not supported by all bundlers, the exports field is where it's at. Otherwise great video!

  • @2ezpz2plzme
    @2ezpz2plzme Рік тому

    Very helpful.

  • @healingwithlove8614
    @healingwithlove8614 Рік тому

    This is what I looking for

  • @a7zz
    @a7zz Рік тому

    Awesome stuff

    • @a7zz
      @a7zz Рік тому

      Would be curious to see how would you set up a react library to publish to npm 👀

  • @scriptcomedian
    @scriptcomedian Рік тому

    Now its time to do it with the Bun bundler :D

  • @driverjb09
    @driverjb09 Рік тому +1

    This is great! Any chance you could do a GitLab version of the video?

  • @Luxcium
    @Luxcium Рік тому

    I would love to have a long form video about each of those topics all alone for maximum understanding… it could be fast paced I love it when it is fast but it should be going more into the details… 🎉🎉🎉🎉

  • @saorlandini0
    @saorlandini0 Рік тому

    BTW if you are a noob like me and you are using Inquirer to present prompts, in "scripts" you can add `"start": "node dist/index.js"` and to test it just run the command `npm (or pnpm) run start`. Don't know if it is the best way to do it but it works for me when I wanted to test my baby :).

  • @ashuzon
    @ashuzon 8 місяців тому +6

    Too much info. I'll come back later. But I'll return.

    • @smcalpha
      @smcalpha 16 днів тому +1

      Did you return?

    • @ashuzon
      @ashuzon 15 днів тому

      ​@@smcalpha yes, I published two of my own on npm.

  • @felipegutierrez2944
    @felipegutierrez2944 Рік тому +1

    If anyone is following this video, before"Changesets" add a github repo with a main branche, just a file is ok

    • @ThaRealIansanity
      @ThaRealIansanity Рік тому

      Yeah I was trying to figure out why changesets was giving me error "Failed to find where HEAD diverged from main. All I had was a local git repo at this point. Thanks

  • @hakuna_matata_hakuna
    @hakuna_matata_hakuna Рік тому

    great video .we need someone of your calbre to fork tsdx and update the dependancies , or even better give us a short tutorial on making a componernt library with rollup , tailwind and code splitting

  • @NsHtxZekoo
    @NsHtxZekoo Рік тому +5

    You should add "exports" in your package.json too

  • @0xAndy
    @0xAndy Рік тому +1

    Great video, but I would love to watch the unabridged version which moves more slowly and goes through everything line by line.

  • @mehrabmahmudpur6984
    @mehrabmahmudpur6984 Рік тому

    He is the real wizard

  • @magnusred2945
    @magnusred2945 Рік тому

    Hi Matt you should check out dnt, by far the best way to create npm packages IMO :)

  • @andrevenancio
    @andrevenancio Рік тому

    This looks awesome, but my main question around changeset is how to add it in the context of a monorepo (lets say with turborepo). Video idea right there!

    • @mattpocockuk
      @mattpocockuk  Рік тому +1

      Just add it! It's designed for monorepos.

  • @AdamM
    @AdamM 11 місяців тому

    Love this... Would this work with a mono-repo style where you have several packages all with differing versions?

  • @pablom8854
    @pablom8854 11 місяців тому +1

    couldn' get the changeset part please make a video about it

  • @Luxcium
    @Luxcium Рік тому

    Ho other people are asking about monorepo stuff and they do deserve to learn all that jazz from you 😅 oh - Me? No I am just asking for a friend… I am using multi root VSCode workspaces and I started using the Rush Stack but I feel like it is not something that is convivial enough for my workflow 😮

  • @javohirmirzo
    @javohirmirzo Рік тому

    Kudos to making it short!

  • @iduvall
    @iduvall Рік тому +1

    Can you make a video combining this stack with turborepo?

  • @bob_kazamakis
    @bob_kazamakis Рік тому +2

    What’s the advantages of using pnpm? I see everyone switching

    • @mattpocockuk
      @mattpocockuk  Рік тому +5

      As I say in the video, it's got the best cache in the business.

    • @bob_kazamakis
      @bob_kazamakis Рік тому

      @@mattpocockuk yeah I heard that, but just caching?

    • @mattpocockuk
      @mattpocockuk  Рік тому +1

      @@bob_kazamakis Caches make things faster. So, it's really fast.

    • @mattpocockuk
      @mattpocockuk  Рік тому +1

      Also, I really like how it doesn't do hoisting in monorepos. A lot more predictable.

  • @arthurvanleeuwen9650
    @arthurvanleeuwen9650 9 місяців тому

    Awesome! Could you make a tutorial of you how to this while using bun?

    • @mattpocockuk
      @mattpocockuk  9 місяців тому

      Probably exactly the same but with a different install step?

    • @arthurvanleeuwen9650
      @arthurvanleeuwen9650 9 місяців тому

      @@mattpocockuk Does ts paths work too?

  • @denniseriksson1071
    @denniseriksson1071 11 місяців тому

    Awesome video/videos, thanks! Heads up for a newbie question.. When you publish the package to NPM would you publish it with the same package.json as you have when coding the package? I guess that the final package sent to NPM does not need/need to know the dependency to tsup now when the source code is bundled? Even if they are set as 'devDependencies' do we really need to include them in the final package.json at all?

    • @mattpocockuk
      @mattpocockuk  11 місяців тому

      That's what devdependencies are for!

  • @romolocodes701
    @romolocodes701 Рік тому

    All terminal commands in the video (I think)
    pnpm add -D typescript
    pnpm tsc --init
    git init
    pnpm add -D tsup
    pnpm run build
    pnpm run lint
    pnpm add -D @changesets/cli
    pnpm changeset init
    pnpm changeset
    git add . && git commit -m ""
    git push

  • @Skaar18
    @Skaar18 3 місяці тому

    I would love to see an updated video for releasing a npm package. Specificaly, where you also walkthrough how to configure the github actions and getting it completely released. You said nothing about it in this video. There are also a few mistakes in this video, e.g. you never added the release script. Love your videos in general, but would love a better video about this topic

  • @romolocodes701
    @romolocodes701 Рік тому

    Hey Matt, this is the perfect video for me although I'm not sure it does exactly what it says on the tin - perhaps I'm doing something wrong but does it actually publish to npm or is that an additional step?
    One more thing I had to change the github actions settings by doing the following;
    my-package repo => settings => actions => general => Workflow permissions
    1. Choose Read and write permissions
    2. Tick Allow GitHub Actions to create and approve pull requests

    • @mattpocockuk
      @mattpocockuk  Рік тому

      I'm sure the Changesets docs can help!

  • @ralphakilian
    @ralphakilian Рік тому

    Could you add tests to this and how you would expose some scripts using the bin property in package.json

  • @ahmedAltariqi
    @ahmedAltariqi 19 днів тому

    Should I follow these steps or your new article about publishing on npm?

  • @ionelCristianLupu_
    @ionelCristianLupu_ Рік тому

    Really packed with info. Well done.
    But sometimes I like to debug(with breakpoints) the code from the libraries I use. Being compiled from TS to JS, the code is almost impossible to look at. Is there a way to see the Typescript code in the library instead of the uglified version?

  • @CaleMcCollough
    @CaleMcCollough Рік тому +1

    I'm in Windows and I can't run npm changeset. Does anyone else have this problem or know a solution? Thanks. **Update** You have to run npx changeset, but now I'm getting Error: Failed to find where HEAD diverged from main. Does main exist?

  • @samuelwittlinger7790
    @samuelwittlinger7790 Рік тому +1

    I used the bundler and now I am getting a bunch of errors of these 2 types. Does anyone please know how to fix this?
    The inferred type of 'router' cannot be named without a reference to '.pnpm/@types+express@4.17.17/node_modules/@types/express'. This is likely not portable. A type annotation is necessary.
    Property 'app' of exported class expression may not be private or protected.ts(4094)

  • @rahulsriram6295
    @rahulsriram6295 Рік тому

    Amazing video! But how good it changesets for beta releases?

  • @guzidev
    @guzidev 8 місяців тому

    Nice video, how you can group files index.js and index.d.ts in file explorer?

    • @mattpocockuk
      @mattpocockuk  8 місяців тому

      Does it automatically in VSCode I think

  • @mrbanana6969
    @mrbanana6969 Рік тому

    Nice video. One thing isn't fully clear though. Am I right in saying that with changesets the commit messages don't matter and. the semver bump info is taken fully from when the contributor runs pnpm changeset?

    • @mattpocockuk
      @mattpocockuk  Рік тому

      Commit messages still matter, but they don't contribute to the release notes. This means you can tailor your changesets to changes that are _user-facing_, which is much better.

  • @vpetryniak
    @vpetryniak Рік тому

    does it work for building backend nodejs library? Should we bundle backend nodejs libraries?

  • @thomas-sinkala
    @thomas-sinkala Рік тому

    Thank Matt. Any idea how I can build to a single .js file that could be hosted on a CDN?

  • @israelssantanna
    @israelssantanna Рік тому

    Hey Matt, thank you for this video! How about automated tests as part of CI, it is possible with GH actions?

    • @mattpocockuk
      @mattpocockuk  Рік тому +1

      Yep, just add a test script and run it, like lint

    • @israelssantanna
      @israelssantanna Рік тому

      @@mattpocockuk Thanks! I am trying to convert a lib of mine from JS to TS and tests are a really important step for me, so I'd like to setup it in CI.

  • @lion-gg
    @lion-gg 9 місяців тому

    On using "type": "module", config change to "main": "dist/index.cjs", "module": "dist/index.js". Right ?

    • @mattpocockuk
      @mattpocockuk  9 місяців тому +1

      Nope, you MUST use 'exports' - that's the standard.

  • @OdwallaJuice
    @OdwallaJuice Рік тому

    One part of the flow I'm confused about is when the changeset action creates a PR? So for example, a changeset would be created in a feature PR and then that would get merged into main. After the feature PR is merged into main, is that when the action creates the new PR for bumping the version and adding the changeset to the changelog? Then once that's merged it publishes the package?

  • @mluevanos
    @mluevanos Рік тому

    I haven't looked this up, but what would be the difference between "noEmit" and "tsup"?

  • @ironsand
    @ironsand 10 місяців тому

    It when from 0-100 so fast! 😂

  • @Angeal98
    @Angeal98 Рік тому

    You dont need a bundler in 2023. Just compile ts to js with declaration files.

  •  Рік тому

    Does tsup do bundling and minification?

  • @frontendtony
    @frontendtony Рік тому +1

    Now there's one missing piece, building and deploying a UI component library.
    The key parts being how to handle static assets like styling (CSS), and peer dependencies like React

  • @antoniogiroz
    @antoniogiroz Рік тому

    Have you tried unbuild instead of tsup?

  • @dgcp354
    @dgcp354 Рік тому

    how can i export css file from the package?

  • @jlndev1017
    @jlndev1017 Рік тому

    I heard the "exports" keyword is prefered in the package.json. Are u aware of that and what are your thoughts on that?

  • @Mitsunee_
    @Mitsunee_ Рік тому

    I'll have a look up tsup, I'm still using rollup with a package to generate my configs that I had to write myself, but I'm currently stuck looking for monorepo solutions because yarn classic is falling apart in that codebase (I literally cannot upgrade dependencies anymore and have to run yarn install like 3 times to resolve dependencies properly...). pnpm broke eslint for me with how it handles its node_modules dirs so that didn't help either.
    How does tsup handle multiple entry points? I have some packages split up with the exports key in package.json so cjs consumers still somewhat treeshake (I think nextjs still consumes the cjs bundles).

  • @thengakola6217
    @thengakola6217 Рік тому +1

    all those.. for a drop of blood