Skip to content

Use npm to manage tool dependencies #240

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 2 commits into from
Jun 23, 2022
Merged

Use npm to manage tool dependencies #240

merged 2 commits into from
Jun 23, 2022

Conversation

per1234
Copy link
Contributor

@per1234 per1234 commented Jun 21, 2022

Some of the assets use tools sourced from the npm software registry.

Previously, the version of the tools used was not controlled. This was problematic because:

  • A different version of the tool may be used on the contributor's machine than on the CI runner, resulting in confusing failures.
  • The project is immediately subject to disruption or breakage resulting from a release of the tool.

These tools were installed via either of the following methods:

npx <pkg>

This approach has the following behaviors of interest:

https://docs.npmjs.com/cli/v8/commands/npx#description

If any requested packages are not present in the local project dependencies, then they are installed to a folder in the npm cache, which is added to the PATH environment variable in the executed process.

Package names provided without a specifier will be matched with whatever version exists in the local project. Package names with a specifier will only be considered a match if they have the exact same name and version as the local dependency.

This means that the version used was:

  1. Whatever happens to be present in the local npm cache
  2. The latest available version if it is not already present

npm install --global <pkg>

The latest available version of the package is used.


The new approach is to specify the version of the tools via the standard npm metadata files (package.json + package-lock.json). This approach was chosen over the npx <pkg>@<version> alternative for the following reasons:


Resolves #213

per1234 added 2 commits June 21, 2022 02:17
Some of the assets use tools sourced from the npm software registry.

Previously, the version of the tools used was not controlled. This was problematic because:

- A different version of the tool may be used on the contributor's machine than on the CI runner, resulting in confusing
  failures.
- The project is immediately subject to disruption or breakage resulting from a release of the tool.

---

These tools were installed via either of the following methods:

`npx <pkg>`

This approach has the following behaviors of interest:

https://docs.npmjs.com/cli/v8/commands/npx#description

> If any requested packages are not present in the local project dependencies, then they are installed to a folder in the npm cache, which is added to the PATH environment variable in the executed process.

> Package names provided without a specifier will be matched with whatever version exists in the local project. Package names with a specifier will only be considered a match if they have the exact same name and version as the local dependency.

This means that the version used was:

1. Whatever happens to be present in the local cache
2. The latest available version if it is not already present

`npm install --global <pkg>`

The latest available version of the package is used.

---
`
The new approach is to specify the version of the tools via the standard npm metadata files (package.json +
package-lock.json). This approach was chosen over the `npx <pkg>@<version>` alternative for the following reasons:

- Enables automated updates via Dependabot PRs
- Enables automated vulnerability alerts
- Separates dependency management from the asset contents (i.e., no need to mess with the taskfile or workflow on every
  update)
- Matches how we are already managing Python dependencies (pyproject.toml + poetry.lock)
We are now standardizing on the use of npm to manage tool dependencies of the assets.

There is one drawback to that approach, which is that it requires the addition of the npm metadata files to the
repository (if not already present).

Two more files are not of any concern for the average Arduino tooling project. However, the "Sync Labels" workflow is
already in widespread usage in other types of official Arduino projects. In some projects (e.g., Arduino libraries),
where the contents are intended to be very approachable to less advanced users, the added files may be considered
problematic, especially since, unlike all the other workflows that were candidates for npm-managed tools, the
"Sync Labels" workflow did not require the addition of any files other than the GitHub Actions workflow (the others also
require a taskfile at minimum). For this reason, the previous lightweight version of "Sync Labels" is retained, but
another version added for use in projects where the dependency management is desired.
@per1234 per1234 added type: enhancement Proposed improvement topic: code Related to content of the project itself labels Jun 21, 2022
@per1234 per1234 requested a review from umbynos June 21, 2022 10:33
@per1234 per1234 self-assigned this Jun 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: code Related to content of the project itself type: enhancement Proposed improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Manage npm-sourced tool dependency versions
2 participants