NPM library containing common code, shared across multiple components.
Check how it's done in the "exports" key of package.json.
- Create a Personal Access Token (classic)
Go to your Github profile > Settings. Then open Developer Settings in the sidebar, and Personal access tokens > Tokens (classic). Or click here.
Create a new token (classic) with at least read:packages scope and no expiration.
Copy the provided token, we'll use it in the next step.
- Create a
.npmrcin your user folder
$ cat ~/.npmrc
@notifycal:registry=https://npm.pkg.github.com
//npm.pkg.github.com/:_authToken=<PAT_TOKEN>
- Install!
$ npm install @notifycal/shared
up to date, audited 752 packages in 1s
244 packages are looking for funding
run `npm fund` for details
found 0 vulnerabilities
- First run
npm linkfrom this package folder. - Then run
npm link @notifycal/sharedfrom the package that wants to install it.
- Go to the package settings page and ensure the repo you want to install this package from is in the list with
Readaccess. - In your workflow file, give the job the
packages: readpermission. - Tweak your workflow file to generate a
.npmrcthat uses the defaultGITHUB_TOKENbeforeactions/setup-node.
Example: Github workflow changes:
permissions:
packages: read
# any other permissions required
steps:
# [...]
- name: Generate .npmrc
run: |
echo "//npm.pkg.github.com/:_authToken=${{secrets.GITHUB_TOKEN}}" > .npmrc
echo "@notifycal=https://npm.pkg.github.com/" >> .npmrc
- uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
cache: 'npm'
# [...]
- run: npm install # or npm ciSome peerDependencies can't be peerDependencies but devDependencies cause NPM does not install peerDependencies with npm install, therefore, npm run build fails. For example, we need to make mantine/core, clsx and @tabler/icons-react because we require the types to be able to build the project.