World map

 

BM: Baca dalam Bahasa Melayu

World 9: Power Tools

Packages

You will learn: how to share your code as a package that other projects install.

The problem

Three of your projects use the same date helper. You fixed a bug in one copy. The other two still break.

Pick one answer.

Watch

bash
npm publish
npm install @aina-codes/date-helper
Two commands. npm publish uploads the date helper. In another project, npm install @aina-codes/date-helper downloads it.

A package: A bundle of code with a name and a version that others can install. is code with a name and a version. It sits on a registry: An online shelf where packages are stored and shared., like a shop shelf. GitHub Packages is a shelf on GitHub, right next to your code.

Try it

GitHub Packages has shelves for many kinds of package. Sort each one.

Drag a card into a box. Or tap the card, then tap the box.

        Try it

        In another project, build the command that installs the date helper.

        Tap the pieces in the right order.

        …

        Predict

        You publish version 1.2.1 with the fix. What do your three projects get?

        Pick one answer.

        Check

        Good package habit, or needs work? Swipe each one.

        Swipe right for good, left for needs work. Or use the buttons.

        1 / 4

        Give every release a new version number

        Give every release a new version number

        You did it!

        You can now share code as a package on GitHub.

        Go deeper (optional)

        On GitHub Packages, npm names need your scope, like @aina-codes. You also tell npm to use GitHub’s registry. Container images live at ghcr.io. Publishing from your laptop needs a personal access token (classic). In Actions, GITHUB_TOKEN works. Public packages are free.