Documentation
¶
Overview ¶
Copyright 2016-2024, KhulnaSoft Ltd.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Index ¶
- Variables
- func FindWorkspaceRoot(startingPath string) (string, error)
- func Install(ctx context.Context, packagemanager PackageManagerType, dir string, ...) (string, error)
- func Pack(ctx context.Context, packagemanager PackageManagerType, dir string, ...) ([]byte, error)
- type PackageManager
- type PackageManagerType
Constants ¶
This section is empty.
Variables ¶
var ErrNotInWorkspace = errors.New("not in a workspace")
Functions ¶
func FindWorkspaceRoot ¶
FindWorkspaceRoot determines if we are in a yarn/npm workspace setup and returns the root directory of the workspace. If the startingPath is not in a workspace, it returns ErrNotInWorkspace.
func Install ¶
func Install(ctx context.Context, packagemanager PackageManagerType, dir string, production bool, stdout, stderr io.Writer, ) (string, error)
Install runs `npm install` in the given directory, installing the dependencies for the Node.js app located there. If the `CODEINFRA_PREFER_YARN` environment variable is set, `yarn install` is used instead of `npm install`. The returned string is the name of the package manager used during installation.
func Pack ¶
func Pack(ctx context.Context, packagemanager PackageManagerType, dir string, stderr io.Writer) ([]byte, error)
Pack runs `npm pack` in the given directory, packaging the Node.js app located there into a tarball and returning it as `[]byte`. `stdout` is ignored for the command, as it does not generate useful data. If the `CODEINFRA_PREFER_YARN` environment variable is set, `yarn pack` is run instead of `npm pack`.
Types ¶
type PackageManager ¶
type PackageManager interface { // Install will install dependencies with the given package manager. Install(ctx context.Context, dir string, production bool, stdout, stderr io.Writer) error Pack(ctx context.Context, dir string, stderr io.Writer) ([]byte, error) // Name is the name of the binary executable used to invoke this package manager. // e.g. yarn or npm Name() string }
A `PackageManager` is responsible for installing dependencies, packaging Codeinfra programs, and executing Node in the context of installed packages. In practice, each implementation of this interface represents one of the package managers in the Node ecosystem e.g. Yarn, NPM, etc. The language host will dynamically dispatch to an instance of PackageManager in response to RPC requests.
func ResolvePackageManager ¶
func ResolvePackageManager(packagemanager PackageManagerType, pwd string) (PackageManager, error)
ResolvePackageManager determines which package manager to use.
If the packagemanager argument is set, and it is not `AutoPackageManager` then, that package manager is used. Otherwise, if the `CODEINFRA_PREFER_YARN` environment variable is set, or if a yarn.lock file exists, then YarnClassic is used. If a pnpm-lock.yaml file exists, then pnpm is used. Otherwise npm is used. The argument pwd is the directory we're checking for the presence of a lockfile.
type PackageManagerType ¶
type PackageManagerType string
const ( // AutoPackageManager automatically choses a packagemanager by looking for environment variables and lockfiles. AutoPackageManager PackageManagerType = "auto" NpmPackageManager PackageManagerType = "npm" YarnPackageManager PackageManagerType = "yarn" PnpmPackageManager PackageManagerType = "pnpm" )