Class 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.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
output(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 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).
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAdd the given arguments.protected <T extends Resource>
Collection<T> doProvide(ResourceRequest<T> request) Invoked byResourceProviderSpi.provide(ResourceRequest)after checking if the invocation is allowed.Name.nodeJsVersion(String version) Sets the node.js version to use.Sets the function used to determine the resources generated by this provider.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 that adds aFileResourceto the required resources.Convenience method that adds aFileTreeto the required resources.Adds the givenStreamof resources to the required resources.toString()To string.Methods inherited from class AbstractProvider
context, name, of, rename, vavrStreamMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface ResourceProvider
context, name, 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
Description copied from interface:RequiredResourceSupportAdds the givenStreamof resources to the required resources.- Specified by:
requiredin interfaceRequiredResourceSupport- Parameters:
resources- the resources- Returns:
- the provider
-
required
Description copied from interface:RequiredResourceSupportConvenience method that adds aFileTreeto the required resources. Ifrootis relative, it is resolved against the project's directory.- Specified by:
requiredin interfaceRequiredResourceSupport- Parameters:
root- the rootpattern- the pattern- Returns:
- the provider
-
required
Description copied from interface:RequiredResourceSupportConvenience method that adds aFileResourceto the required resources. Ifpathis relative, it is resolved against the project's directory.- Specified by:
requiredin interfaceRequiredResourceSupport- Parameters:
root- the file- Returns:
- the provider
-
output
-
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
-
toString
To string.- Overrides:
toStringin classAbstractProvider- Returns:
- the string
-