inertiajs / inertia

Inertia.js lets you quickly build modern single-page React, Vue and Svelte apps using classic server-side routing and controllers.
https://inertiajs.com
MIT License
6.02k stars 405 forks source link

Migrate from npm to pnpm #1875

Open jamesst20 opened 1 month ago

jamesst20 commented 1 month ago

Note: This is based from this branch https://github.com/inertiajs/inertia/pull/1874 This is just one small commit: https://github.com/inertiajs/inertia/pull/1875/commits/7dd0a030aab44f05f5186c3eccee517bebed716b

Replace npm by pnpm.

Pnpm is a much better package manager. If you are curious about its differences, I recommend you to google it. Syntax and usage is pretty much identical

pnpm add -D package-name # npm install --save-dev package-name
pnpm install # pnpm install

# Build all
pnpm build:all
# or
pnpm --workspace-concurrency 1 -r build

# Publish all
pnpm -r publish

The reason why it's a good idea is because pnpm properly scopes packages unlike npm. As you can see in the single commit of this branch, I had to add missing packages to few repos. This should have never worked in the first place. This prevent weird bugs as well where the wrong package version is used for building as well.

Also, using @inertiajs/core from the workspace would be a better approach because sometimes both adapter and core need an update. i.e adding a new type that would be missing from the core in the currently published version.

Pnpm automatically re-alias properly packages referenced from the workspace.

https://pnpm.io/workspaces

Referencing workspace packages through aliases
Let's say you have a package in the workspace named foo. Usually, you would reference it as "foo": "workspace:*".

If you want to use a different alias, the following syntax will work too: "bar": "workspace:foo@*".

Before publish, aliases are converted to regular aliased dependencies. The above example will become: "bar": "npm:foo@1.0.0".