nodejs

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2026 License: MPL-2.0 Imports: 22 Imported by: 0

Documentation

Overview

Package nodejs generates the Dockerfile for Node.js projects.

Index

Constants

View Source
const (
	// ConfigNodeFramework is the key for the configuration for specifying
	// the Node.js framework explicitly.
	//
	// This is an undocumented internal configuration and is subjected to change.
	ConfigNodeFramework = "node.framework"

	// ConfigAppDir indicates the relative path of the app to deploy.
	//
	// For example, if the app to deploy is located at `apps/api`,
	// the value of this configuration should be `apps/api`.
	ConfigAppDir = "app_dir"
)

Variables

View Source
var (
	// NpmLatestMajorVersion is the latest major version of npm.
	NpmLatestMajorVersion uint64 = 10
	// NpmOldestMajorVersion is the oldest major version of npm.
	NpmOldestMajorVersion uint64 = 6
	// YarnLatestMajorVersions is the latest major version of yarn.
	YarnLatestMajorVersions uint64 = 4
	// YarnOldestMajorVersion is the oldest major version of yarn.
	YarnOldestMajorVersion uint64 = 1
	// PnpmLatestMajorVersion is the latest major version of pnpm.
	PnpmLatestMajorVersion uint64 = 10
	// PnpmOldestMajorVersion is the oldest major version of pnpm.
	PnpmOldestMajorVersion uint64 = 5
)

Functions

func DetermineAppFramework

func DetermineAppFramework(ctx *nodePlanContext) types.NodeProjectFramework

DetermineAppFramework determines the framework of the Node.js app.

func DetermineNeedPlaywright

func DetermineNeedPlaywright(ctx *nodePlanContext) bool

DetermineNeedPlaywright determines whether the app needs Playwright.

func DetermineNeedPuppeteer

func DetermineNeedPuppeteer(ctx *nodePlanContext) bool

DetermineNeedPuppeteer determines whether the app needs Puppeteer.

func FindAppDirByGlob

func FindAppDirByGlob(fs afero.Fs, pattern string) (match string, fnerr error)

FindAppDirByGlob finds the application directory (with package.json) by the given glob pattern.

func GenerateDockerfile

func GenerateDockerfile(meta types.PlanMeta) (string, error)

GenerateDockerfile generates the Dockerfile for Node.js projects.

func GetBuildCmd

func GetBuildCmd(ctx *nodePlanContext) string

GetBuildCmd gets the build command of the Node.js app.

func GetBuildScript

func GetBuildScript(ctx *nodePlanContext) string

GetBuildScript gets the build command in package.json's `scripts` of the Node.js app.

func GetEntry

func GetEntry(ctx *nodePlanContext) string

GetEntry gets the entry file of the Node.js app.

func GetInitCmd

func GetInitCmd(ctx *nodePlanContext) string

GetInitCmd gets the package manager initialization command of the Node.js app.

func GetInstallCmd

func GetInstallCmd(ctx *nodePlanContext) string

GetInstallCmd gets the installation command of the Node.js app.

func GetMeta

func GetMeta(opt GetMetaOptions) types.PlanMeta

GetMeta gets the metadata of the Node.js project.

func GetMonorepoAppRoot

func GetMonorepoAppRoot(ctx *nodePlanContext) string

GetMonorepoAppRoot gets the app root of the monorepo project in the Node.js project.

func GetNodeVersion

func GetNodeVersion(ctx *nodePlanContext) string

GetNodeVersion gets the Node.js version of the project.

func GetPredeployScript

func GetPredeployScript(ctx *nodePlanContext) string

GetPredeployScript gets the predeploy script in package.json's `scripts` of the Node.js app.

func GetScriptCommand

func GetScriptCommand(ctx *nodePlanContext, script string) string

GetScriptCommand gets the command to run a script in the Node.js or Bun app.

func GetStartCmd

func GetStartCmd(ctx *nodePlanContext) string

GetStartCmd gets the start command of the Node.js app.

func GetStartScript

func GetStartScript(ctx *nodePlanContext) string

GetStartScript gets the start command in package.json's `scripts` of the Node.js app.

func GetStaticOutputDir

func GetStaticOutputDir(ctx *nodePlanContext) string

GetStaticOutputDir returns the output directory for static application. If empty string is returned, the application is not deployed as static files.

func NewIdentifier

func NewIdentifier() plan.Identifier

NewIdentifier returns a new NodeJS identifier.

func NewPacker

func NewPacker() packer.Packer

NewPacker returns a new Node.js packer.

Types

type Bun

type Bun struct{}

Bun is the implementation of PackageManager for bun.

func (Bun) GetInitCommand

func (Bun) GetInitCommand() string

GetInitCommand returns the command to install bun.

func (Bun) GetInstallProjectDependenciesCommand

func (Bun) GetInstallProjectDependenciesCommand() string

GetInstallProjectDependenciesCommand returns the command to install project dependencies.

func (Bun) GetRunScript

func (Bun) GetRunScript(script string) string

GetRunScript returns the command to run a script.

func (Bun) GetType

func (Bun) GetType() types.NodePackageManager

GetType returns the type of the package manager.

type GetMetaOptions

type GetMetaOptions struct {
	Src    afero.Fs
	Config plan.ImmutableProjectConfiguration

	Bun          bool
	BunFramework optional.Option[types.BunFramework]
}

GetMetaOptions is the options for GetMeta.

type Npm

type Npm struct {
	MajorVersion uint64
}

Npm is the implementation of PackageManager for npm.

func (Npm) GetInitCommand

func (n Npm) GetInitCommand() string

GetInitCommand returns the command to install npm.

func (Npm) GetInstallProjectDependenciesCommand

func (Npm) GetInstallProjectDependenciesCommand() string

GetInstallProjectDependenciesCommand returns the command to install project dependencies.

func (Npm) GetRunScript

func (Npm) GetRunScript(script string) string

GetRunScript returns the command to run a script.

func (Npm) GetType

func (Npm) GetType() types.NodePackageManager

GetType returns the type of the package manager.

type PackageJSON

type PackageJSON struct {
	PackageManager  *string           `json:"packageManager,omitempty"`
	Dependencies    map[string]string `json:"dependencies,omitempty"`
	DevDependencies map[string]string `json:"devDependencies,omitempty"`
	Scripts         map[string]string `json:"scripts,omitempty"`
	Engines         PackageJSONEngine `json:"engines"`
	Main            string            `json:"main"`
	Module          string            `json:"module"`

	// yarn workspace
	Workspaces []string `json:"workspaces,omitempty"`
}

PackageJSON is the structure of `package.json`.

func DeserializePackageJSON

func DeserializePackageJSON(source afero.Fs) (PackageJSON, error)

DeserializePackageJSON deserializes a package.json file from source. When the deserialization failed, it returns an empty PackageJson with the error.

func NewPackageJSON

func NewPackageJSON() PackageJSON

NewPackageJSON returns a new instance of PackageJson with some default values.

func (PackageJSON) FindDependency

func (p PackageJSON) FindDependency(name string) (string, bool)

FindDependency checks if the package.json contains the given dependency in "dependency" and "devDependencies", and returns the version of the dependency.

type PackageJSONEngine

type PackageJSONEngine struct {
	Node string `json:"node"`
	Bun  string `json:"bun,omitempty"`

	Npm  string `json:"npm,omitempty"`
	Yarn string `json:"yarn,omitempty"`
	Pnpm string `json:"pnpm,omitempty"`
}

PackageJSONEngine is the structure of `package.json`'s `engines` field.

type PackageManager

type PackageManager interface {
	GetType() types.NodePackageManager
	GetInitCommand() string
	GetInstallProjectDependenciesCommand() string
	GetRunScript(script string) string
}

PackageManager defines an interface for common package management operations. It is basically the reimplementation of Corepack + Ni (https://github.com/antfu-collective/ni)

func DeterminePackageManager

func DeterminePackageManager(ctx *nodePlanContext) PackageManager

DeterminePackageManager determines the package manager of the Node.js project.

func DeterminePackageManagerUncached

func DeterminePackageManagerUncached(ctx *nodePlanContext) PackageManager

DeterminePackageManagerUncached determines the package manager of the Node.js project.

type Pnpm

type Pnpm struct {
	MajorVersion uint64
}

Pnpm is the implementation of PackageManager for pnpm.

func (Pnpm) GetInitCommand

func (p Pnpm) GetInitCommand() string

GetInitCommand returns the command to install pnpm.

func (Pnpm) GetInstallProjectDependenciesCommand

func (Pnpm) GetInstallProjectDependenciesCommand() string

GetInstallProjectDependenciesCommand returns the command to install project dependencies.

func (Pnpm) GetRunScript

func (Pnpm) GetRunScript(script string) string

GetRunScript returns the command to run a script.

func (Pnpm) GetType

func (Pnpm) GetType() types.NodePackageManager

GetType returns the type of the package manager.

type TemplateContext

type TemplateContext struct {
	NodeVersion string

	AppDir string

	InitCmd    string
	InstallCmd string
	BuildCmd   string
	StartCmd   string

	Framework string
	OutputDir string
}

TemplateContext is the context for the Node.js Dockerfile template.

func (TemplateContext) Execute

func (c TemplateContext) Execute() (string, error)

Execute executes the template.

type UnspecifiedPackageManager

type UnspecifiedPackageManager struct {
	PackageManager
}

UnspecifiedPackageManager is the implementation of PackageManager for an unspecified package manager.

The type will be set to unknown.

func (UnspecifiedPackageManager) GetType

GetType returns the type of the package manager.

type Yarn

type Yarn struct {
	MajorVersion uint64
}

Yarn is the implementation of PackageManager for yarn.

func (Yarn) GetInitCommand

func (y Yarn) GetInitCommand() string

GetInitCommand returns the command to install yarn.

func (Yarn) GetInstallProjectDependenciesCommand

func (Yarn) GetInstallProjectDependenciesCommand() string

GetInstallProjectDependenciesCommand returns the command to install project dependencies.

func (Yarn) GetRunScript

func (Yarn) GetRunScript(script string) string

GetRunScript returns the command to run a script.

func (Yarn) GetType

func (Yarn) GetType() types.NodePackageManager

GetType returns the type of the package manager.

Jump to

Keyboard shortcuts

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