Skip to content

Make vite a peer dependency#20

Open
cpulvermacher wants to merge 1 commit into
yoichiro:mainfrom
cpulvermacher:move-vite-to-peer-dependencies
Open

Make vite a peer dependency#20
cpulvermacher wants to merge 1 commit into
yoichiro:mainfrom
cpulvermacher:move-vite-to-peer-dependencies

Conversation

@cpulvermacher

Copy link
Copy Markdown

Greetings from Kyushu, and thank you for making this package!

This PR fixes two issues:

  • Compatibility with vite 6 and 7. The plugin itself is already working as expected with vite 6+, so this only requires listing the never versions in package.json.
  • Having vite in the dependencies can cause npm to install a second, conflicting copy of vite, which can be very hard to debug. For example, installing vite-plugin-handlebars on a project with vite 7 produces:
$ npm ls vite
...
├─┬ @yoichiro/vite-plugin-handlebars@1.4.0
│ └── vite@5.4.21
└── vite@7.3.1

Configuring it in peerDependencies will prioritize the version specified in the root project:

$ npm ls vite
...
├─┬ @yoichiro/vite-plugin-handlebars@1.4.0 (git+ssh://git@github.com/cpulvermacher/vite-plugin-handlebars.git#5b0ff3cca4310c3bcc11ca2fe60c2b1c8bf72214)
│ └── vite@7.3.1 deduped

If the version is incompatible, it will show an error instead of quietly installing an incompatible version. E.g. with vite 4 on the root project:

$ npm install
...
npm error While resolving: @yoichiro/vite-plugin-handlebars@1.4.0
npm error Found: vite@4.5.14
npm error node_modules/vite
npm error   dev vite@"^4.2.4" from the root project
npm error
npm error Could not resolve dependency:
npm error peer vite@"^5.0.0 || ^6.0.0 || ^7.0.0" from @yoichiro/vite-plugin-handlebars@1.4.0

Plugin itself is compatible with vite 6 and 7, but
without this change, npm might install two conflicting versions of vite,
requiring a cast to make it work with TypeScript.

peerDependencies makes more sense for plugins: Adding vite-plugin-handlebars
as a dependency doesn't itself pull in vite, but npm fails if vite is
missing. If both vite and vite-plugin-handlebars
are dependencies, dependency resolution will prioritize the directly
specified vite version.
@cpulvermacher

Copy link
Copy Markdown
Author

I've created a temporary fork of the package here https://github.com/cpulvermacher/vite-plugin-handlebars that includes this PR and some version updates.
Will deprecate the package if this one is updated again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant