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

Set the package.json pulumi name even if PluginName isn't set #10088

Merged
merged 3 commits into from Jul 11, 2022

Conversation

Frassle
Copy link
Member

@Frassle Frassle commented Jul 11, 2022

Description

Related to #10087

Currently the nodejs runtime will use "pulumi.name" from package.json as the plugin name, if it's not set it falls back to the npm package name (i.e. "name" in package.json). This is nearly always wrong as npm names look like "@pulumiverse/sentry" while the pulumi package name (and thus plugin name) would be something like "sentry".

This changes nodejs codegen to always set "pulumi.name" to either the user given "PluginName", or if that is not set to the pulumi package name. This should mean most users don't even need to set "PluginName".

Checklist

  • I have added tests that prove my fix is effective or that my feature works
  • Yes, there are changes in this PR that warrants bumping the Pulumi Service API version

@pulumi-bot
Copy link
Contributor

Please view the results of the Downstream Codegen Tests Here

@ringods
Copy link
Member

ringods commented Jul 11, 2022

This will not completely fix #10087, but it will consistently set:

  "pulumi": {
     "name": <plugin name>
  }

in the generated package.json files, hereby preventing to execute the faulty code path for third-party providers.

@pulumi-bot
Copy link
Contributor

Please view the results of the Downstream Codegen Tests Here

@Frassle Frassle requested a review from iwahbe July 11, 2022 11:26
@pulumi-bot
Copy link
Contributor

Please view the results of the Downstream Codegen Tests Here

@@ -2135,6 +2135,13 @@ func genNPMPackageMetadata(pkg *schema.Package, info NodePackageInfo) string {
scriptVersion = pluginVersion
}

pluginName := info.PluginName
// Default to the pulumi package name if PluginName isn't set by the user. This is different to the npm
Copy link
Member Author

Choose a reason for hiding this comment

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

Note we could be a bit smarter here and only set name if needed. A lot of "@pulumi" packages would work even without name set here because we strip it off the npm name. That is a plugin "azure" with a npm package name of "@pulumi/azure" doesn't need the plugin name explicitly set. Similarly if the plugin name == the npm package name then this doesn't need to be set.

That would reduce the diff of this change a bit because all the test packages would fit this style, and also means things like actual azure codegen won't change from this.

But then maybe it's better to just be simple and explicit.

Copy link
Member

Choose a reason for hiding this comment

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

I'm happy to take the bigger diff if we get simpler logic.

Copy link
Member

@iwahbe iwahbe left a comment

Choose a reason for hiding this comment

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

I'm assuming the test failure is unrelated.

@Frassle
Copy link
Member Author

Frassle commented Jul 11, 2022

I'm assuming the test failure is unrelated.

Looks it

@Frassle Frassle merged commit f02fb5b into master Jul 11, 2022
@pulumi-bot pulumi-bot deleted the fraser/nodejsPackageName branch July 11, 2022 22:17
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

4 participants