Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(node-resolve): expose plugin version #1050

Merged
merged 1 commit into from Dec 13, 2021

Conversation

lukastaegert
Copy link
Member

@lukastaegert lukastaegert commented Nov 24, 2021

Rollup Plugin Name: node-resolve

This PR contains:

  • bugfix
  • feature
  • refactor
  • documentation
  • other

Are tests included?

  • yes (bugfixes and features will not be merged without tests)
  • no

Breaking Changes?

  • yes (breaking changes will not be merged unless absolutely necessary)
  • no

If yes, then include "BREAKING CHANGES:" in the first commit message body, followed by a description of what is breaking.

List any relevant issue numbers:
#1038

Description

In the course of #1038, we discovered that we actually can have a peer-dependency-like situation between the commonjs plugin and the node-resolve plugin: If the new commonjs version is used together with a node-resolve version older than 13.0.6, then we would like to throw an error.

Unfortunately while it is easy to discover that the node-resolve plugin is used by inspecting build options, it is close to impossible to discover its actual version.

This PR does something very simple: It fetches the plugin version from the package.json file and attaches it as a version property to the plugin so that other plugins can inspect it.

This could serve as a pattern for other plugins as well. E.g. I am also attaching a version property to the commonjs plugin in #1038.

To ease the release of #1038, I would see having something like this in node-resolve as blocking for the release of #1038. If we want to recommend this pattern to others, I am also considering to include a recommendation in the "plugin communication" section of the official Rollup docs.

Copy link
Member

@tjenkinson tjenkinson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm

@shellscape shellscape merged commit 59add60 into master Dec 13, 2021
@shellscape shellscape deleted the node-resolve/expose-version branch December 13, 2021 13:45
@lukastaegert
Copy link
Member Author

lukastaegert commented Dec 14, 2021

Checking the version with the newly released plugin it turns out that the published version is always one release behind. E.g. @rollup/plugin-node-resolve@13.1.0 reports to have version 13.0.6 and 13.1.1. is reported as 13.1.0. The reason is that the last build of the plugin occurs before the version is incremented.

@shellscape the easiest possible way to address this is to add a "prebublish": "pnpm build" script to the node-resolve package.json file. This script would indeed run after the version is increased. Do you see any issues with that? Then I would create a small PR.

@shellscape
Copy link
Collaborator

You'll want prepublishOnly but that should work

@lukastaegert
Copy link
Member Author

Ah you are right, forgot that prepublish does not do anything what you would expect it to do.

@shellscape
Copy link
Collaborator

For this use case, would this suffice?

const { version } = require('./package.json');
module.exports = { version };

Would save you a build step.

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.

None yet

3 participants