craft_parts.plugins.npm_plugin module

The npm plugin.

class craft_parts.plugins.npm_plugin.NpmPlugin(*args, **kwargs)[source]

Bases: Plugin

A plugin for npm projects.

This plugin uses the common plugin keywords as well as those for “sources”. For more information check the ‘plugins’ topic for the former and the ‘sources’ topic for the latter.

Additionally, this plugin uses the following plugin-specific keywords:
  • npm-include-node (bool; default: False) If true, download and include the node binary and its dependencies. If npm-include-node is true, then npm-node-version must be defined.

  • npm-node-version (str; default: None) Which version of node to download. Required if npm-include-node is set to true. The option accepts a NVM-style version string, you can specify:

    • exact version (e.g. “20.12.2”)

    • major+minor version (e.g. “20.12”)

    • major version (e.g. “20”)

    • LTS code name (e.g. “lts/iron”)

    • latest mainline version (“node”)

    Note that “system” and “iojs” options are not supported.

Parameters:
  • args (Any)

  • kwargs (Any)

get_build_commands()[source]

Return a list of commands to run during the build step.

Return type:

list[str]

get_build_environment()[source]

Return a dictionary with the environment to use in the build step.

Return type:

dict[str, str]

get_build_packages()[source]

Return a set of required packages to install in the build environment.

Return type:

set[str]

get_build_snaps()[source]

Return a set of required snaps to install in the build environment.

Return type:

set[str]

get_pull_commands()[source]

Return a list of commands to run during the pull step.

Return type:

list[str]

properties_class

alias of NpmPluginProperties

validator_class

alias of NpmPluginEnvironmentValidator

class craft_parts.plugins.npm_plugin.NpmPluginEnvironmentValidator(*, part_name, env, properties)[source]

Bases: PluginEnvironmentValidator

Check the execution environment for the npm plugin.

Parameters:
  • part_name (str) – The part whose build environment is being validated.

  • env (str) – A string containing the build step environment setup.

  • properties (PluginProperties)

validate_environment(*, part_dependencies=None)[source]

Ensure the environment has the dependencies to build npm applications.

Parameters:

part_dependencies (Optional[list[str]]) – A list of the parts this part depends on.

Return type:

None

class craft_parts.plugins.npm_plugin.NpmPluginProperties(**data)[source]

Bases: PluginProperties

The part properties used by the npm plugin.

Parameters:

data (Any)

model_config: ClassVar[ConfigDict] = {'alias_generator': <function PluginProperties.<lambda>>, 'extra': 'forbid', 'frozen': True, 'validate_assignment': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

node_version_defined()[source]

If npm-include-node is true, then npm-node-version must be defined.

Return type:

Self

npm_include_node: bool
npm_node_version: str | None
plugin: Literal['npm']
source: str