1.0.4 • Published 5 years ago

monorepo-local v1.0.4

Weekly downloads
-
License
MIT
Repository
-
Last release
5 years ago

Yarn workspaces are great for local development since it will connect your project(s) with your packages and allows for nicely organized local codebases. But as soon as you want to deploy your projects to netlify, heroku, docker, etc you will need to come up with complex deployment strategies.

git subtrees are nice in that case since the will allow to push to a seperate branch which can be build through netlify or to push that subtree to heroku. But what can you do with your dependencies?

  • Publish to npm?
  • Publish to seperate git branches?
  • Or better, make them a part of the individual project that depends on them, since they basically should be a direct part of the project? Yes!

It works by scanning all ts/tsx/js/jsx files for the given scope (e.g. @example/library1) and then looking up these referenced projects by the dirname (library1), then copy that folder to the projects folder. Then, it will include it into the package.json dependencies field as local dependency. This allows for isolated installs.

Options

  • scope (-s,--scope): The scope of your libraries
  • libDir (-l,--libDir): The directory your libraries sit in
  • include (-i,--include): Which libraries to include regardless if found in your js/ts

Example

Lets say we got a project organized like

  • web-project
  • electron-project
  • react-native-project
  • packages
    • common-ui (package.json name: @example/common-ui)
    • common-utils (package.json name: @example/common-utils)
    • common-assets (package.json name: @example/assets)

You could copy handle dependencies of web-project like this:

monorepo-local web-project -i common-assets -s "@example" -l packages

This will result in:

  • web-project
    • packages
      • common-ui
      • common-utils
      • common-assets
  • electron-project
  • react-native-project
  • packages
    • common-ui (package.json name: @example/common-ui)
    • common-utils (package.json name: @example/common-utils)
    • common-assets (package.json name: @example/assets)

Also, the package.json will now contain

  • dependencies
    • @example/common-ui: ./packages/common-ui
    • @example/common-utils: ./packages/common-utils
    • @example/common-assets: ./packages/common-assets
1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago