Skip to content

NPM Exec ValueSource #337

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

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft

Conversation

adam-enko
Copy link
Contributor

Implement ValueSource for executing npm.

This is a very rough first draft.

See #334 for motivations.

Example usage:

// build.gradle.kts

val npmExec = providers.of(NpmExecSource::class) { /* ... */ }
val result = npmExec.get()

Limitations

npm must be installed before NpmExecSource can be used.

Currently npm is installed using a Task, so NpmExecSourcewill fail unless the task runs first. This is not ideal, because I want to (eventually) useNpmExecSource` in the configuration phase should not depend on the execution of a task.

This can be remedied by installing npm in ValueSource in the Configuration phase. I think this should be done in a separate PR, and NpmExecSource can be released as experimental.

No caching

Each NpmExecSource will recompute the required exec properties independently. This could be slow, or expensive.

Gradle does not yet provide a tool to cache configuration-time work https://github.com/gradle/gradle/issues/

We could implement a custom mechanism for caching the exec properties.

Duplicated code

I copied this existing logic from VariantComputer and NpmExecRunner into NpmExecSource. This was to avoid the complicated provider mapping logic, which is not necessary inside of a ValueSource, because the values can be computed directly.

This means the initial implementation duplicates a lot of code.

I anticipate this will be deduplicated once the tasks are converted to use a 'ValueSource first' approach.

TODO

  • Add docs
  • Add experimental opt-in annotation

#334

adam-enko added 2 commits July 3, 2025 15:29
Everything is duplicated into NpmExecSource
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.

1 participant