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

Add npm to nodejs-engine build plan #622

Merged
merged 4 commits into from
Oct 4, 2023
Merged

Add npm to nodejs-engine build plan #622

merged 4 commits into from
Oct 4, 2023

Conversation

colincasey
Copy link
Contributor

A default version of npm comes bundled with every Node.js installation so this is now indicated in the build plan.

W-13916400

A default version of `npm` comes bundled with every Node.js installation so this is now indicated in the build plan.

[W-13916400](https://gus.lightning.force.com/a07EE00001XxIOnYAN)
@colincasey colincasey added the enhancement New feature or request label Aug 15, 2023
@colincasey colincasey self-assigned this Aug 15, 2023
@colincasey colincasey requested a review from a team as a code owner August 15, 2023 18:15
A default version of `npm` comes bundled with every Node.js installation so this is now indicated in the build plan.

[W-13916400](https://gus.lightning.force.com/a07EE00001XxIOnYAN)
@colincasey colincasey marked this pull request as draft August 15, 2023 21:37
@schneems
Copy link
Contributor

I understand the high-level truthfulness that this buildpack provides npm, but I don't understand the specific use case of when this is intended to be used. I'm comparing this to the Ruby buildpack which only currently provides ruby but it also installs bundler, as well as running rake assets compilation, but if you only wanted bundler and not Ruby I think you would be surprised to requires("bundler") and get a Ruby version installed too. I think the same might be true of the node buildpack.

I see these provides/requires values more as tags to specific buildpacks than as actual generic features. I could use some help understanding either an app user or buildpack maintainer's perspective on how this is intended to be used versus what's available today.

@colincasey
Copy link
Contributor Author

colincasey commented Aug 16, 2023

in regards to your questions @schneems:

I understand the high-level truthfulness that this buildpack provides npm, but I don't understand the specific use case of when this is intended to be used. I'm comparing this to the Ruby buildpack which only currently provides ruby but it also installs bundler, as well as running rake assets compilation, but if you only wanted bundler and not Ruby I think you would be surprised to requires("bundler") and get a Ruby version installed too. I think the same might be true of the node buildpack.

the node-engine buildpack cannot install dependencies like the ruby buildpack might because we support multiple package managers (i.e.; npm, yarn, pnpm). so node-engine gets combined with a matching package manager buildpack that runs after. still, the npm tooling is provided by node-engine because it comes with every install of node which is why i thought it would helpful to specify that.

the way i intended it to be used was in conjunction with #623 and #625 so that the nodejs meta-buildpack would have eventually have the following group defined:

  • node-engine (provides node + npm)
  • node-npm-engine (optional, requires node, provides npm)
  • node-npm-install (requires node + npm + node_modules, provides node_modules)

that would support a standard npm-based application that either:

  • has no specific version of npm declared (only node-engine and node-npm-install are active)
  • has a specific version of npm declared in engines.npm (all 3 three buildpacks are active)

the strange this about this PR is that providing npm here fails the integration test with the following:

===> DETECTING
======== Results ========
pass: heroku/nodejs-engine@1.1.4
Resolving plan... (try #1)
fail: heroku/nodejs-engine@1.1.4 provides unused npm
ERROR: No buildpack groups passed detection.
ERROR: Please check that you are running against the correct path.
ERROR: failed to detect: no buildpacks participating

which seems surprising. i would think that if a buildpack provides something that is not required by later buildpacks but all other require criteria are met then this should be fine but, from the above error, this doesn't appear to be the case. it seems like this would need to be combined with #623 and #625 to work fully.

@edmorley
Copy link
Member

the strange this about this PR is that providing npm here fails the integration test with the following:

This is part of the spec:
https://github.com/buildpacks/spec/blob/main/buildpack.md#phase-1-detection

If a required buildpack provides a dependency that is not required by the same buildpack or a subsequent buildpack, the trial MUST fail to detect.

The solution is to have an OR and say ~"(provides node and npm) OR (provides node)"

@colincasey
Copy link
Contributor Author

thanks, @edmorley. i figured i was misinterpreting what the spec said about the build plan. i didn't realize the implication of the [[or]] declarations.

@colincasey colincasey marked this pull request as ready for review August 16, 2023 19:36
@joshwlewis
Copy link
Member

The solution is to have an OR and say ~"(provides node and npm) OR (provides node)"

I think there is another solution. Have this buildpack also require npm.

I don't love the OR idea - it seems misleading to say this buildpack provides npm only some of the time. This buildpack always installs npm if it runs, so always put it in the provides seems closer to developer expectations.

@edmorley
Copy link
Member

edmorley commented Aug 17, 2023

@joshwlewis I don't think it's misleading per-se, it's just how the build plan is meant to be used IMO.

ie: Let's say I have some other buildpack that only needs Node and doesn't need NPM (eg it's running a JS script that has no dependencies). Without the or, this other buildpack would have to incorrectly state that it required both node and npm, otherwise detection would always fail.

That is, I think "provides" is meant to be more of a "here are the various scenarios I cater for, pick and match".

@joshwlewis
Copy link
Member

ie: Let's say I have some other buildpack that only needs Node and doesn't need NPM (eg it's running a JS script that has no dependencies). Without the or, this other buildpack would have to incorrectly state that it required both node and npm, otherwise detection would always fail.

Having this buildpack self-require npm (instead of using OR) would allow downstream buildpacks to require node without npm too.

That is, I think "provides" is meant to be more of a "here are the various scenarios I cater for, pick and match".

Yeah, I think folks who know the CNB spec well understand this. My comment about developer expectations was targeted at someone less familiar (like someone writing a JS script buildpack).

@edmorley
Copy link
Member

Having this buildpack self-require npm (instead of using OR) would allow downstream buildpacks to require node without npm too.

Ah true :-)

@colincasey
Copy link
Contributor Author

I think there is another solution. Have this buildpack also require npm.

i also find this usage to be as confusing as the or usage. why claim this buildpack requires npm when it doesn't?

I don't love the OR idea - it seems misleading to say this buildpack provides npm only some of the time. This buildpack always installs npm if it runs, so always put it in the provides seems closer to developer expectations.

i'm glad i'm not the only one who finds this contrary to developer expectations.

it's just how the build plan is meant to be used IMO.

i'm not sure why an unmet provides should cause an issue though. i get why requires would but if something is provided but not used, why does that matter to the build? if this is how the build plan is meant to be interpreted then fine, but it seems like an unnecessary restriction to me.

@edmorley
Copy link
Member

edmorley commented Sep 1, 2023

@joshwlewis @colincasey What is the status of / next steps for this PR? Both the PR and the associated GUS work item have been in the "awaiting review" state for 2 weeks.

* main: (48 commits)
  Remove cutlass job from CI (#675)
  Update Inventory for heroku/nodejs-npm-engine (#624)
  Remove cutlass integration tests (#674)
  Update Inventory for heroku/nodejs-engine (#671)
  Update Inventory for heroku/nodejs-yarn (#670)
  Prepare integration tests to run under a single builder (#663)
  Bump Swatinem/rust-cache from 2.6.2 to 2.7.0 (#665)
  Bump actions/checkout from 3 to 4 (#664)
  Bump regex from 1.9.5 to 1.9.6 (#666)
  Bump thiserror from 1.0.48 to 1.0.49 (#667)
  Bump ureq from 2.7.1 to 2.8.0 (#668)
  Bump serde_json from 1.0.105 to 1.0.107 (#669)
  Fix CNB builder repo URL (#672)
  Fix non-existent builder Docker image name (#673)
  Updates `libcnb` to 0.15.0 (#662)
  Switch tests from `heroku/buildpacks:20` to `heroku/builder:20` (#660)
  Prepare release v1.1.6 (#658)
  Bump regex from 1.9.4 to 1.9.5 (#656)
  Bump indoc from 2.0.3 to 2.0.4 (#657)
  Bump toml from 0.7.6 to 0.7.8 (#654)
  ...

# Conflicts:
#	buildpacks/nodejs-engine/CHANGELOG.md
@colincasey colincasey enabled auto-merge (squash) October 4, 2023 14:20
@colincasey colincasey merged commit d3b7829 into main Oct 4, 2023
17 checks passed
@colincasey colincasey deleted the system_npm branch October 4, 2023 14:26
colincasey added a commit that referenced this pull request Oct 4, 2023
* main: (31 commits)
  Add `npm` to `nodejs-engine` build plan (#622)
  Remove cutlass job from CI (#675)
  Update Inventory for heroku/nodejs-npm-engine (#624)
  Remove cutlass integration tests (#674)
  Update Inventory for heroku/nodejs-engine (#671)
  Update Inventory for heroku/nodejs-yarn (#670)
  Prepare integration tests to run under a single builder (#663)
  Bump Swatinem/rust-cache from 2.6.2 to 2.7.0 (#665)
  Bump actions/checkout from 3 to 4 (#664)
  Bump regex from 1.9.5 to 1.9.6 (#666)
  Bump thiserror from 1.0.48 to 1.0.49 (#667)
  Bump ureq from 2.7.1 to 2.8.0 (#668)
  Bump serde_json from 1.0.105 to 1.0.107 (#669)
  Fix CNB builder repo URL (#672)
  Fix non-existent builder Docker image name (#673)
  Updates `libcnb` to 0.15.0 (#662)
  Switch tests from `heroku/buildpacks:20` to `heroku/builder:20` (#660)
  Prepare release v1.1.6 (#658)
  Bump regex from 1.9.4 to 1.9.5 (#656)
  Bump indoc from 2.0.3 to 2.0.4 (#657)
  ...

# Conflicts:
#	Cargo.lock
#	Cargo.toml
#	buildpacks/nodejs-npm-engine/CHANGELOG.md
#	test_support/Cargo.toml
#	test_support/src/lib.rs
colincasey added a commit that referenced this pull request Oct 4, 2023
* main: (31 commits)
  Add `npm` to `nodejs-engine` build plan (#622)
  Remove cutlass job from CI (#675)
  Update Inventory for heroku/nodejs-npm-engine (#624)
  Remove cutlass integration tests (#674)
  Update Inventory for heroku/nodejs-engine (#671)
  Update Inventory for heroku/nodejs-yarn (#670)
  Prepare integration tests to run under a single builder (#663)
  Bump Swatinem/rust-cache from 2.6.2 to 2.7.0 (#665)
  Bump actions/checkout from 3 to 4 (#664)
  Bump regex from 1.9.5 to 1.9.6 (#666)
  Bump thiserror from 1.0.48 to 1.0.49 (#667)
  Bump ureq from 2.7.1 to 2.8.0 (#668)
  Bump serde_json from 1.0.105 to 1.0.107 (#669)
  Fix CNB builder repo URL (#672)
  Fix non-existent builder Docker image name (#673)
  Updates `libcnb` to 0.15.0 (#662)
  Switch tests from `heroku/buildpacks:20` to `heroku/builder:20` (#660)
  Prepare release v1.1.6 (#658)
  Bump regex from 1.9.4 to 1.9.5 (#656)
  Bump indoc from 2.0.3 to 2.0.4 (#657)
  ...

# Conflicts:
#	Cargo.lock
#	Cargo.toml
#	meta-buildpacks/nodejs/buildpack.toml
#	test_support/Cargo.toml
#	test_support/src/lib.rs
@heroku-linguist heroku-linguist bot mentioned this pull request Oct 17, 2023
heroku-linguist bot added a commit that referenced this pull request Oct 17, 2023
## heroku/nodejs

### Changed

- Updated `heroku/nodejs-corepack` to `1.1.7`.
- Updated `heroku/nodejs-engine` to `1.1.7`.
- Updated `heroku/nodejs-npm` to `1.1.7`.
- Updated `heroku/nodejs-pnpm-install` to `1.1.7`.
- Updated `heroku/nodejs-yarn` to `1.1.7`.

## heroku/nodejs-corepack

- No changes.

## heroku/nodejs-engine

- Added Node.js version 20.8.1.
- Added Node.js version 18.18.2.
- Added Node.js version 18.18.1.
- Added Node.js version 20.8.0.
- Provides `npm` added to the build plan since a default version of `npm` is bundled with Node.js. ([#622](#622))

## heroku/nodejs-function

### Changed

- Updated `heroku/nodejs-engine` to `1.1.7`.
- Updated `heroku/nodejs-function-invoker` to `1.1.7`.
- Updated `heroku/nodejs-npm` to `1.1.7`.

## heroku/nodejs-function-invoker

- No changes.

## heroku/nodejs-npm

- No changes.

## heroku/nodejs-pnpm-install

- No changes.

## heroku/nodejs-yarn

- Added Yarn version 4.0.0-rc.53.
- Added Yarn version 4.0.0-rc.52.
- Added Yarn version 3.6.4.

Co-authored-by: heroku-linguist[bot] <136119646+heroku-linguist[bot]@users.noreply.github.com>
colincasey added a commit that referenced this pull request Oct 18, 2023
* main:
  Added `nodejs-npm-install` Buildpack (#625)
  Added `nodejs-npm-engine` Buildpack (#623)
  Prepare release v1.1.7 (#683)
  Update Inventory for heroku/nodejs-engine (#682)
  Update Inventory for heroku/nodejs-engine (#681)
  Update Inventory for heroku/nodejs-npm-engine (#678)
  Bump the rust-dependencies group with 2 updates (#680)
  Group minor/patch version Rust Dependabot updates into one PR (#679)
  Add `npm` to `nodejs-engine` build plan (#622)

# Conflicts:
#	buildpacks/nodejs-engine/tests/fixtures/node-with-indexjs/package-lock.json
#	buildpacks/nodejs-engine/tests/fixtures/node-with-serverjs/package-lock.json
#	buildpacks/nodejs-engine/tests/integration_test.rs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants