Class NpmExecutor

java.lang.Object
org.jdrupes.builder.core.AbstractProvider
org.jdrupes.builder.ext.nodejs.NpmExecutor
All Implemented Interfaces:
Renamable, RequiredResourceSupport, ResourceProvider

A provider for execution results from invoking npm. The provider generates resources in response to requests for ExecResult where the request's ResourceRequest.name() matches this provider's name.

  • The working directory is the project directory.

  • The provider first checks if a file package.json exists, else it fails. If no directory node_modules exists or package.json is newer than node_modules/.package-lock.json it invokes npm init.

  • Then, the provider retrieves all resources added by required(Stream). While the provider itself does not process these resources, it is assumed that they are processed by the npm command and therefore need to be available.

  • If no arguments were specified, the provider returns an ExecResult that indicates successful invocation. The date of the result is set to the date of node_modules/.package-lock.json.

  • The provider invokes the function configured with output(Function) and collects all resources. If the generated resources exist and no resource from required is newer then the generated resources found, the provider returns a result that indicates successful invocation. The date of the result is set to the newest date from the generated resources and the (existing) resources are attached.

  • Else, the provider invokes npm, calls the function set with provided again and adds the result to the ExecResult that it returns.

The provider also uses the function set with output(Function) to determine the resources to be removed when it is invoked with a request for Cleanliness.

The generated resources can also be provided directly in response to a request, see provideResources(ResourceRequest).

This provider is made available as an extension. org.jdrupes:jdbld-ext-nodejs: