Skip to content

feat(@angular/cli): show Node.js version support status in version command #20881

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

Merged
merged 1 commit into from
May 22, 2021

Conversation

clydin
Copy link
Member

@clydin clydin commented May 21, 2021

Unsupported versions of Node.js will now show an unsupported warning when the ng version command is executed.
Currently Node.js major versions 12 and 14 are considered supported and tested.

Closes #20879

@clydin clydin added the target: minor This PR is targeted for the next minor release label May 21, 2021
@google-cla google-cla bot added the cla: yes label May 21, 2021
@clydin clydin requested a review from josephperrott May 21, 2021 00:25
Copy link
Member

@josephperrott josephperrott left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Collaborator

@alan-agius4 alan-agius4 left a comment

Choose a reason for hiding this comment

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

Instead of adding an additional place where we need to update once we change support for Node

Can we instead of engines.node from package JSON and if the current Node doesn't fall within the specified semver, using the semver package we issue a warning?

@petebacondarwin
Copy link
Contributor

If I understand him correctly, I think I agree with @alan-agius4 here. Instead of hiding this information in the version-impl.ts file, how about putting it in the package.json:

"engines": {
  "node.js": ">12...",
  "node.js:supported": "12.x||14.x",
  ...
}

Then it is available to developers and external tooling if they want to read or consume it, while not causing a hard-error if a different version is used.

@josephperrott
Copy link
Member

@petebacondarwin @alan-agius4 I think I read Alan's proposal a bit differently which was to use the values in engines.node to determine the semver matching.

I actually tried to do this yesterday after I made the feature request initially before Charles ended up creating this. What I had was (roughly):

private isNodeSupportedForPackages(moduleNames: string[]): boolean {
  const nodeEnginesEntries = new Set<string>();
  let isUnsupportedVersion = false;
  for (const moduleName of moduleNames) {
    // Find the package in the workspace
    try {
      const packagePath = require.resolve(`${moduleName}/package.json`, {
        paths: [this.context.root],
      });
      if (packagePath) {
        const { engines } = require(packagePath) as { engines: { node: string } };
        nodeEnginesEntries.add(engines.node.replace(/(\>=?)/g, '^'));
      }
    } catch {}
  }
  nodeEnginesEntries.forEach((entry: string) => {
    isUnsupportedVersion =
      isUnsupportedVersion || !semver.satisfies(process.versions.node, entry);
  });
  return isUnsupportedVersion;
}

The concern/issue notably is the requirement of doing something like engines.node.replace(/(\>=?)/g, '^') to make our check slightly more restrictive than the actual engines node field.

@alan-agius4
Copy link
Collaborator

alan-agius4 commented May 21, 2021

@josephperrott / @petebacondarwin, following a convo with @clydin on Slack, we decided that for the time being we roll with the current approach. And indeed I did mean to use the node property in the engines field and not create a custom key.

@clydin
Copy link
Member Author

clydin commented May 21, 2021

Custom engine fields can also cause install-time errors. We ran into that issue when pnpm was briefly added as an engine for the CLI.

…mmand

Unsupported versions of Node.js will now show an unsupported warning when the `ng version` command is executed.
Currently Node.js major versions 12 and 14 are considered supported and tested.

Closes angular#20879
@clydin clydin force-pushed the supported-node-versions branch from 8123591 to 9292bf1 Compare May 21, 2021 17:54
@clydin clydin added the action: merge The PR is ready for merge by the caretaker label May 22, 2021
@clydin clydin merged commit 57640be into angular:master May 22, 2021
@clydin clydin deleted the supported-node-versions branch May 22, 2021 00:05
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Jun 22, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker target: minor This PR is targeted for the next minor release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Include node js version support status in ng version
4 participants