npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@codewyre/localpackage

v1.1.0

Published

If you remember `lerna bootstrap --force-local`, this is your tool! It brings back it's functionality to plain yarn workspaces. This tool creates the ability to develop and maintain packages within yarn workspaces as symlinks, while being able to referenc

Downloads

2

Readme

Local Package Tool - Force-Local Packages with Yarn Workspaces!

If you remember lerna bootstrap --force-local, this is your tool! It brings back it's functionality to plain yarn workspaces. This tool creates the ability to develop and maintain packages within yarn workspaces as symlinks, while being able to reference them as:

{
  "name": "app",
  "dependencies": {
    "my-lib": "^1.42.3"
  }
}

Usage

yarn add -D @codewyre/localpackage

Add two scripts to your dependants package.json:

// package.json of "app"
{
  "name": "app",
  "scripts": {
    "preinstall": "cw-localpackage preinstall",
    "postinstall": "cw-localpackage postinstall"
  },
  "dependencies": {
    "my-lib": "^1.42.3"
  }
}

You can now run the added --force-local switch, using yarn --force-local in your workspace. If you need to enforce reinstalling, remember to also add the --force flag which comes with yarn out of the box:

yarn --force --force-local

Skipping --force-local flag

Environment variable

To always install packages locally, provide an environment variable:

export CW_LOCALPACKAGE_ALWAYS_FORCE_LOCAL=1

Setting force-local in config file

You can also create a .localpackage.js file in your workspace root to configure the enforcing. Pro-Tip: Add the .localpackage.js file to your .gitignore, so your CI would build the project with public references instead of local ones.

// [yarn-workspace-root]/.localpackage.js

// Use these lines for without having "type": "module" in workspace's package.json
module.exports = {
  alwaysForceLocal: true
}

// Use these lines for WITH having "type": "module" in workspace's package.json
export default {
  alwaysForceLocal: true
}

Details

If you would have a situation like above, meaning you have a local library that you actively develop and e.g. an application that references it - Then you would have to yarn link here and yarn link there, always causing manual effort when building, installing the workspace, etc.

To be more detailed, this would be the situation:

// [root]/package.json
{
  "name": "my-workspace",
  "workspaces": [
    "app/*",
    "library/*"
  ]
}
// [root]/app/web/package.json
{
  "name": "my-app",
  "dependencies": {
    "my-lib": "^1.42.3"
  }
}
// [root]/library/core/package.json
{
  "name": "my-library",
  "version": "1.42.3"
}

Problems

  • This would cause yarn to install the package from a public repository.
  • On initial development, this even means the installation will fail. You though do not want to publish the lib yet, because it is not finished.
  • After installation, you always have to manually run yarn link [libname] to have the symlink active.
  • yarn link is a global utility, polluting your global yarn folders with unnecessary symlinks
  • Having the lib in two versions (e.g in 2 workspaces) is not possible, because one link overrides the other.

How this package solves the issue

  • It is hooking into the pre- and postinstall scripts of your dependants package.json with just one command.
  • It is scoped to the workspace, so having two workspaces cloned, including both having the dependency on your machine is possible!
  • You can develop locally before you actively publish the package to an NPM registry.

Example

See ./example for a test project. After running yarn --force --force-local, you will receive:

┐
├─> /app
│    ├─> /node_modules
│    │      └─> /@codewyre
│    │            └─> /localpackage-example-lib (SYMLINK)
│    │                       ║
│    └─> /package.json       ║
│                            ║
├─> /lib      ◁◁◁════════════╝
│    │
│    └─> /package.json
│
└─> package.json (workspace)