Clean up stale package installations
mastercleanInstallations() to remove package installations that are no longer present in the local lockfile of the target directory. This helps prevent yalc from trackingrepository·master·Indexed 27 days ago
https://github.com/wclr/yalcA tool for managing local package dependencies that simulates npm/yarn publishing and installation workflows locally without a remote registry. Version 1.0.0-pre.53 provides an API to manage the global yalc store, handle yalc.sig and .yalcignore files, manipulate yalc.lock configurations, and interact with package manifests and various package managers including npm, yarn, and pnpm.
cleanInstallations() to remove package installations that are no longer present in the local lockfile of the target directory. This helps prevent yalc from trackingUse addPackageToLockfile to update the yalc.lock file with new package entries. Each package object in the input array must include a name and can optionally include any LockFilePackageEntry properties.
import { addPackageToLockfile } from './src/lockfile';
await addPackageToLockfile([
{
name: 'my-package',
version: '1.2.3',
file: true,
signature: 'some-sig'
}
], { workingDir: '/path/to/project' });saveInstallationsFile() to persist an InstallationsFile object to the yalc store directory. This overwrites the existing installations configuration file with the provided object.runPmUpdate(workingDir, packages) to execute an update command for a list of specific packages in a target directory. This function automatically detects the package manager (npm, yarn, or pnpm) and executes the corresponding update command synchronously.The yalc entrypoint provides functions to locate and manage the global yalc store and package directories.
getStoreMainDir(): Returns the path to the main yalc store directory. On Windows, this defaults to %LOCALAPPDATA%/Yalc. On other platforms, it defaults to ~/.yalc.getStorePackagesDir(): Returns the path to the packages directory within the main yalc store.getPackageStoreDir(packageName, version): Returns the specific directory for a package within the store. If version is provided, it includes the version in the path.Use these functions to manage the yalc.sig file within a working directory, which is used to track package state.
readSignatureFile(workingDir): Reads the content of yalc.sig in the specified directory. Returns an empty string if the file does not exist.writeSignatureFile(workingDir, signature): Writes the provided signature string to yalc.sig in the specified directory. Throws an error if writing fails.The following core functions are exported for managing packages via the yalc API:
publishPackage(...): Publishes a package to the local yalc store.updatePackages(options: UpdatePackagesOptions): Updates packages. UpdatePackagesOptions accepts workingDir: string and an optional safe: boolean.checkManifest(...): Checks the package manifest.removePackages(...): Removes packages.addPackages(...): Adds packages.addInstallations() to register new package installation paths in the yalc installations file. This function updates the global installations configuration to include the provided PackageInstallation objects.The API provides helper functions to retrieve the correct CLI command string based on the detected package manager in a given directory (cwd).
getPackageManagerInstallCmd(cwd): Returns the command to install dependencies (e.g., npm install, yarn, or pnpm install).getPackageManagerUpdateCmd(cwd): Returns the command to update dependencies (e.g., npm update, yarn upgrade, or pnpm update).getRunScriptCmd(cwd): Returns the base command for running scripts (e.g., npm run, yarn, or pnpm).readIgnoreFile(workingDir) function reads the content of the .yalcignore file in the specified working directory. It returns an empty string if the file is not found.removeInstallations() to unregister specific package installation paths from the yalc installations file. If a package no longer has any registered installation paths, its entry will be removed from the configuration entirely.readInstallationsFile() to retrieve the current mapping of packages to their installation locations. The function reads the installations configuration file from the yalc store directory. It returns an InstallationsFile object where keys are package names and values are arrays of file paths where that package is installed.