From fdfef5f334deac2cfe83288a99f22b73995ae736 Mon Sep 17 00:00:00 2001 From: Pat Gavlin Date: Tue, 13 Aug 2019 15:40:25 -0700 Subject: [PATCH] Update the NodeJS version compat checks. (#3083) - Unify the 1.x.y series and the 0.17.z series - Fix the check s.t. post-1.0, only the major versions are required to match --- CHANGELOG.md | 5 +++ sdk/nodejs/cmd/pulumi-language-nodejs/main.go | 31 +++++++++++++++++-- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 19639487d..e61464b06 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ CHANGELOG ========= +## 1.0.0-beta.2 (2019-08-13) + +- Fix the package version compatibility checks in the NodeJS language host. + [#3083](https://github.com/pulumi/pulumi/pull/3083) + ## 1.0.0-beta.1 (2019-08-13) - Do not propagate input properties to missing output properties during preview. The old behavior can cause issues that diff --git a/sdk/nodejs/cmd/pulumi-language-nodejs/main.go b/sdk/nodejs/cmd/pulumi-language-nodejs/main.go index c943cb497..fadf505d9 100644 --- a/sdk/nodejs/cmd/pulumi-language-nodejs/main.go +++ b/sdk/nodejs/cmd/pulumi-language-nodejs/main.go @@ -160,6 +160,31 @@ func newLanguageHost(nodePath, runPath, engineAddress, } } +func compatibleVersions(a, b semver.Version) (bool, string) { + switch { + case a.Major == 0 && b.Major == 0: + // If both major versions are pre-1.0, we require that the major and minor versions match. + if a.Minor != b.Minor { + return false, "Differing major or minor versions are not supported." + } + + case a.Major >= 1 && b.Major >= 1: + // If both major versions are post-1.0, we require that the major versions match. + if a.Major != b.Major { + return false, "Differing major versions are not supported." + } + + case a.Major == 1 && b.Major == 0 && b.Minor == 17 || b.Major == 1 && a.Major == 0 && a.Minor == 17: + // If one version is pre-1.0 and the other is post-1.0, we unify 1.x.y and 0.17.z. This combination is legal. + + default: + // All other combinations of versions are illegal. + return false, "Differing major or minor versions are not supported." + } + + return true, "" +} + // GetRequiredPlugins computes the complete set of anticipated plugins required by a program. func (host *nodeLanguageHost) GetRequiredPlugins(ctx context.Context, req *pulumirpc.GetRequiredPluginsRequest) (*pulumirpc.GetRequiredPluginsResponse, error) { @@ -186,12 +211,12 @@ func (host *nodeLanguageHost) GetRequiredPlugins(ctx context.Context, continue } - if version.Major != firstVersion.Major || version.Minor != firstVersion.Minor { + if ok, message := compatibleVersions(version, firstVersion); !ok { fmt.Fprintf(os.Stderr, - `Found incompatible versions of @pulumi/pulumi. Differing major or minor versions are not supported. + `Found incompatible versions of @pulumi/pulumi. %s Version %s referenced at %s Version %s referenced at %s -`, firstVersion, firstPath, version, path) +`, message, firstVersion, firstPath, version, path) break } }