coopbri / knit

🧶 Knit local dependencies together
https://www.npmjs.com/package/@omnidev/knit
MIT License
20 stars 0 forks source link
dependencies local-development nodejs npm package-manager yarn

🧶 Knit

Streamline your local Node.js package dependency workflow.

Knit is a fork of yalc, which was created by @wclr. The name is inspired by this GitHub thread.

Overview

knit is a CLI with a local repository designed to mirror a remote package repository, such as npm. It allows you to publish packages from a local project folder to a local store, and install them in other local projects. It also allows you to easily propagate package updates.

knit can be used with projects where package managers, such as npm, yarn, or pnpm, are used for managing package.json dependencies. knit creates a knit.lock file in your project (similar to yarn.lock and package-lock.json) that is used to ensure consistency while performing knit routines.

Quick Start

Install locally in a project (replace yarn with your preferred package manager):

yarn add -D @omnidev/knit

Or execute it directly and ephemerally with yarn dlx:

yarn dlx @omnidev/knit [...]

Key Commands

Usage

Publish (knit publish)

Run in a project to publish it to the store.

Add (knit add)

Run in a project to pull a package from the store and install it as a dependency.

Link (knit link)

As an alternative to add, you can use the link command. This is similar to npm link/yarn link, except the symlink source will be the local .knit folder of your project instead of the global link directory.

After knit copies package content to the .knit folder, it will create a symlink (and not modify package.json): $PROJECT_DIR/.knit/$PACKAGE_NAME ⟹ $PROJECT_DIR/node_modules/$PACKAGE_NAME.

Update (knit update)

Run knit update $PACKAGE_NAME to update to the latest version of $PACKAGE_NAME from the store, or just knit update to update all the packages found in knit.lock.

Remove (knit remove)

Installations (knit installations)

Advanced Usage

Pushing Updates Automatically to All Installations

knit publish --push (or knit push) will publish your package to the store and propagate all changes to existing knit package installations (this performs the update operation on the target location).

When you run knit add|link|update, the project's package locations are tracked and saved, so knit knows where each package in the store is being used in your local environment.

The scripts option is false by default, so it won't run pre/post scripts (change this behavior by passing --scripts).

Flags:

Committing knit files

It is up to you whether you would like to commit the files generated by knit (.knit/ and knit.lock) to your repository.

Reasons not to commit:

Reasons to commit:

If you decide to commit, consider that standard non-code files like README.md and LICENSE.md will also be included, so you may want to exclude them in .gitignore with a pattern such as **/.knit/**/*.md. Alternatively, use .knitignore to avoid including those files in package content.

Publish/Push Subprojects

Useful for monorepos, knit publish $PROJECT_NAME will perform the publish operation in the ./$PROJECT_NAME directory relative to process.cwd().

Retreat and Restore

Instead of completely removing a package, it can be temporary set back with knit retreat [--all] (e.g. before package publication to a remote registry).

Later, it can be restored with knit restore.

Use with npm/yarn/pnpm Workspaces

--pure will be used by default if you try to add a project in a workspaces-enabled package, so package.json and node_modules will not be modified. Then, you can add the Knit-enabled package folder to workspaces in package.json (e.g. add .knit/* and .knit/@*/* patterns). During the update (or push) operation, package content will be updated automatically and your package manager will handle the rest.

If you want to override the default pure behavior, use --no-pure.

Clean up Installations File

While working with knit, you might face a situation when you have locations where Knit-enabled projects have been removed from the filesystem, which will cause warnings when knit tries to push a package to the missing location. To get rid of these warnings, use knit installations clean $PACKAGE_NAME.

Override Default Package Store Folder

Use --store-folder to override the default location for storing published packages.

Control Output

Use --quiet to fully disable output, except for errors. Use --no-colors to disable colors.

Set Default Options via .knitrc

A .knitrc file can be created to declaratively set default options for Knit.

Valid options:

Example:

workspace-resolve=false
sig=false

License

The code in this repository is licensed under MIT, © Brian Cooper. The original yalc work is licensed under MIT, © Alex Osh. See LICENSE.md for more information.