Class NpmExecutor
- All Implemented Interfaces:
Renamable, 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 provider first checks if a file
package.jsonexists, else it fails. If no directorynode_modulesexists orpackage.jsonis newer thannode_modules/.package-lock.jsonit invokesnpm 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 thenpmcommand and therefore need to be available. -
If no arguments were specified, the provider returns an
ExecResultthat indicates successful invocation. The date of the result is set to the date ofnode_modules/.package-lock.json. -
The provider invokes the function configured with
generated(Function)and collects all resources. If the generated resources exist and no resource fromrequiredis 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
providedagain and adds the result to theExecResultthat it returns.
The provider also uses the function set with generated(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).
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAdd the given arguments.doProvide(ResourceRequest<T> request) Invoked byResourceProviderSpi.provide(ResourceRequest)after checking if the invocation is allowed.Sets the function used to determine the resources generated by this provider.Name.nodeJsVersion(String version) Sets the node.js version to use.project()Returns the project that this provider belongs to.provideResources(ResourceRequest<?> proto) Provide the generated resources in response to a request like the given one.Convenience method to add aFileResourceto the required resources.Convenience method to add aFileTreeto the required resources.Add the givenStreamof resources to the required resources.Methods inherited from class AbstractProvider
context, name, of, rename, toString, vavrStreamMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface ResourceProvider
of, resources
-
Constructor Details
-
NpmExecutor
Initializes a new NPM executor.- Parameters:
project- the project
-
-
Method Details
-
project
-
name
Name. -
nodeJsVersion
Sets the node.js version to use. Setting a version is mandatory.- Parameters:
version- the version- Returns:
- the npm executor
-
args
Add the given arguments.- Parameters:
args- the arguments- Returns:
- the npm executor
-
required
Add the givenStreamof resources to the required resources.- Parameters:
resources- the resources- Returns:
- the npm executor
-
required
Convenience method to add aFileTreeto the required resources. Ifrootis a relative path, it is resolved against the project's directory.- Parameters:
root- the rootpattern- the pattern- Returns:
- the npm executor
-
required
Convenience method to add aFileResourceto the required resources. Ifpathis relative, it is resolved against the project's directory.- Parameters:
root- the root- Returns:
- the npm executor
-
generated
-
provideResources
Provide the generated resources in response to a request like the given one.- Parameters:
proto- defines the kind of request that the npm executor should respond to with the generated resources- Returns:
- the npm executor
-
doProvide
Description copied from class:AbstractProviderInvoked byResourceProviderSpi.provide(ResourceRequest)after checking if the invocation is allowed.- Specified by:
doProvidein classAbstractProvider- Type Parameters:
T- the generic type- Parameters:
request- the request for resources- Returns:
- the stream
-