Skip to content

gronxb/lopm

Repository files navigation

lopm

NPM

Monorepo supports local packages.

Why use lopm?

When using local packages in a monorepo, you might experience peer dependency problems because you use symbolic links.

But if you use lopm, hard links the files declared in the files field in the package.json

In other words, it has the same effect as a package installed by the npm registry.

It is similar to dependenciesMeta.*.injected of pnpm, but sync is difficult periodically at current pnpm and does not support watch mode.

Installation

  • pnpm
$ pnpm install lopm -D -w
$ pnpm lopm -v
  • yarn
$ yarn add lopm -D
$ yarn lopm -v
  • npm
$ npm install lopm --save-dev
$ npm lopm -v

Command

  • lopm list

    Displays a list of available local packages and local packages specified in the current project.

    • Example
    {
      "name": "foo",
      "dependencies": {
          "bar": "workspace:^1.0.0",
          "bar2": "workspace:^1.0.0"
      }
    }
    image
  • lopm sync

    Hardlink the local packages.

    image

    Example: node_modules capacity increases due to changes from pnpm symbolic links to hard links.

  • lopm run <command>

    The command entered in the parameter is executed.
    While command is running, lopm runs in watch mode.
    Monitor the files field in the local package package.json and when a change occurs, the sync command is executed after 3 seconds.

    image

Getting Started

package.json setting for local package

Specify files field to export out

  • example
"name": "bar"
...
"files": [
    "dist",
    "package.json"
],
...

package.json setting for app

After pnpm install or yarn install, synchronization must be performed through the lopm sync command.
That is, it must be done immediately before build or development.

The lopm run <command> command is in watch mode. Hard link again if any changes to the local package occur while the command is running.

The command pnpm install or yarn install will restore it.

  • example
"name": "foo"
...
"scripts": {
    "build": "lopm sync && vite build",
    "dev": "lopm run vite"
},
...

The dependency field must specify the local package name.
Supports workspace, link and file protocols.

  • example
"name": "foo"
...
"dependencies": {
    "foo": "workspace:0.0.1",
    "foo2": "link:../../packages/foo",
    "foo3": "file:../../packages/foo",
},
...

How to use after sync

If you followed the example above well, you can use it inside the bar package as follows:

$ pnpm lopm sync
// This code in "bar" package
import { sum } from "foo";

Getting Started with Turborepo

Similar to the original Getting Started, except that there is a scripts field in package.json and a turbo.json file.

package.json setting for app

"name": "bar"
...
"scripts": {
    "sync": "lopm sync",    
    "build": "vite build",
},
...

package.json setting for root

"name": "monorepo-root"
...
"scripts": {
    "build": "turbo rub build --filter='./packages/bar'",
},
...

turbo.json

{
  "$schema": "https://turbo.build/schema.json",
  "pipeline": {
    "build": {
      "dependsOn": ["sync"]
    },
  }
}

Even if you set this much, Turbo will sync before the build!