yalc

repository·master·Indexed 27 days ago

https://github.com/wclr/yalc

A 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.

Tokens
2.2K
Snippets
1
Records
22
Agent score
92%

What's inside yalc

  1. Clean up stale package installations

    master
    Use cleanInstallations() to remove package installations that are no longer present in the local lockfile of the target directory. This helps prevent yalc from tracking
  2. Add packages to the yalc.lock file

    master

    Use 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' });
  3. Run package manager update for specific packages

    master
    Use 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.
  4. Manage yalc global store and directory paths

    master

    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.
  5. Read and write yalc signature files

    master

    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.
  6. Core yalc management functions

    master

    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.
  7. Add new package installations

    master
    Use 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.
  8. Get package manager commands for install, update, or running scripts

    master

    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).
  9. Remove package installations

    master
    Use 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.
  10. Read the yalc installations file

    master
    Use 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.