nodejs

package
v1.1.10 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 13, 2021 License: MPL-2.0 Imports: 13 Imported by: 3 modules, 2 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package nodejs provides analyzers for Node.js projects.

A Node.js project is defined as any folder with a `package.json`. A project may or may not have dependencies.

A `BuildTarget` for Node.js is defined as the relative path to the directory containing the `package.json`, and the `Dir` is defined as the CWD for running build tools (like `npm` or `yarn`).

`npm` and `yarn` are explicitly supported as first-class tools. Where possible, these tools are queried before falling back to other strategies.

All Node.js projects are implicitly supported via `node_modules` parsing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Discover

func Discover(dir string, options map[string]interface{}) ([]module.Module, error)

Discover searches for `package.json`s not within a `node_modules` or `bower_components`.

Types

type Analyzer

type Analyzer struct {
	NodeVersion string

	NPM  npm.NPM
	Yarn yarn.YarnTool

	Module  module.Module
	Options Options

	DevDeps bool
}

func New

func New(m module.Module, devDeps bool) (*Analyzer, error)

New configures Node, NPM, and Yarn commands.

func (*Analyzer) Analyze

func (a *Analyzer) Analyze() (graph.Deps, error)

func (*Analyzer) Build

func (a *Analyzer) Build() error

Build runs `yarn install --production --frozen-lockfile` if there exists a `yarn.lock` and `yarn` is available. Otherwise, it runs `npm install --production`.

func (*Analyzer) Clean

func (a *Analyzer) Clean() error

Clean removes `node_modules`.

func (*Analyzer) IsBuilt

func (a *Analyzer) IsBuilt() (bool, error)

type Options

type Options struct {
	Strategy    string `mapstructure:"strategy"`
	AllowNPMErr bool   `mapstructure:"allow-npm-err"`
}

Options contains options for the `Analyzer`.

The analyzer can use many different strategies. These are:

  • `yarn`: Run and parse `yarn ls --json`.
  • `npm`: Run and parse `npm ls --json`.
  • `yarn.lock`: Parse `./yarn.lock`.
  • `package-lock.json`: Parse `./package-lock.json`.
  • `node_modules`: Parse `./package.json` and recursively look up dependencies with `node_modules` resolution.
  • `node_modules_local`: Parse manifests in `./node_modules“.
  • `package.json`: Parse `./package.json`.

If no strategies are specified, the analyzer will try each of these strategies in descending order.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL