GithubHelp home page GithubHelp logo

canarist's Introduction

canarist

TLDR: A bit like npm link, but for workspaces / monorepos ๐Ÿš€

Introduction

canarist is a tool that allows you to combine multiple yarn workspace monorepos into one single temporary workspace and execute commands inside each of them.

This is useful if, for example, you have a tool or library that is being developed inside a monorepo and you want to test out new changes to your library in downstream projects by executing their test suites.

At XING we have this automated within our CI, so that PRs to central repositories will be tested against a few downstream projects.

If you want to read more into how and why this tool works, check out the overview (which I had prepared for a small presentation in our company).

System requirements

This tool is built with modern Node.js and needs at least Node.js 10.13 or higher.

Since this is a tool for managing yarn workspaces, it is required to have yarn and git installed locally.

Quick start

You can use canarist as a CLI tool: Install it globally or use npx to run it as a one-off command:

npx canarist -r . -r [email protected]:some/other.git

This command will create a temporary folder and clone the repository from your current working directory (.) and the some/other repository from GitHub into a temporary folder and execute yarn test in both repositories.

Configuration and projects

canarist is fully configurable through cosmiconfig and even allows to specify multiple different combinations of repositories (called "projects") which can be run from the CLI.

You can configure canarist through one of the following places:

  • a "canarist" key in the package.json
  • a .canaristrc{.json,.yml,.js} file
  • a canarist.config.js file

Example single-mode configuration in package.json

{
  "canarist": {
    "repositories": [
      {
        "url": ".",
        "directory": "local-repo",
        "commands": [""]
      },
      {
        "url": "[email protected]:some/other.git",
        "commands": ["yarn build"]
      },
      {
        "url": "[email protected]:my/other.git",
        "directory": "my-other",
        "branch": "next"
      }
    ],
    "rootManifest": {
      "resolutions": {
        "typescript": "3.2.4"
      }
    },
    "targetDirectory": "~/work/canarist-target",
    "yarnArguments": "--production"
  }
}

The above configuration can be executed by typing:

npx canarist

into the terminal and will do the following:

  • clone the local repository (.) into ~/work/canarist-target/local-repo
  • clone the remote repository ([email protected]:some/other.git) into ~/work/canarist-target/other
  • clone the remote repository ([email protected]:my/other.git) into ~/work/canarist-target/my-other
  • create a package.json in ~/work/canarist-target/ which combines all workspaces from the other repositories
  • execute yarn --production in ~/work/canarist-target/
  • execute yarn build in ~/work/canarist-target/other
  • execute yarn test in ~/work/canarist-target/my-other

Note: This configuration will link all packages from all three configured repositories together.

In case you want to test multiple different combinations, you can make use of projects (see below):

Example project-mode configuration in package.json

{
  "canarist": {
    "projects": [
      {
        "name": "canarist",
        "repositories": [
          {
            "url": "[email protected]:xing/canarist.git"
          },
          {
            "url": "[email protected]:my/canarist.git",
            "directory": "my-canarist",
            "branch": "next",
            "commands": ["yarn build", "yarn test"]
          }
        ],
        "rootManifest": {
          "resolutions": {
            "jest": "^24.0.0"
          }
        }
      },
      {
        "name": "other",
        "repositories": [
          {
            "url": "[email protected]:some/other.git",
            "branch": "next"
          },
          {
            "url": "[email protected]:my/other.git",
            "directory": "my-other"
          }
        ],
        "yarnArguments": "--ignore-scripts"
      }
    ]
  }
}

The above configuration specifies two projects, which can each be run by typing:

npx canarist -p canarist

or

npx canarist -p other

into the terminal.

Note: This configuration allows to link canarist with my/canarist and some/other with my/other, this is useful when you want to test changes in several different repositories without linking all of them together at once.

CLI output:

$ canarist --help
Usage: canarist options [<target>]

Options:
    --repository, -r
        The URL (or local file path) to a repository to clone.
        This option accepts sub-arguments (see examples):
            --branch, -b
                The branch that should be checked out (default: master).
            --command, -c
                The command to execute in this repository (default: "yarn test").
            --directory, -d
                This option allows to change the directory name in case of conflicts.
    --root-manifest, -m
        A valid JSON string that should be merged into the generated root manifest.
    --yarn-arguments, -y
        Additional arguments that should be passed to the "yarn install" command.
    --project, -p
        The name of a project to execute in a multi-project configuration.

Examples:
    $ canarist -r [email protected]:xing/canarist.git -r [email protected]:some/other.git
        Clones xing/canarist and some/other into a temporary directory
        and executes "yarn test" in both repositories.

    $ canarist -r [[email protected]:xing/canarist.git -b next -c] -r [email protected]:some/other.git
        Clones the "next" branch of xing/canarist and the master branch of some/other
        and executes no command in xing/canarist and "yarn test" in some/other.

    $ canarist -r [[email protected]:xing/canarist.git -d canarist] -r [[email protected]:my/canarist.git -d my-canarist]
        Clones xing/canarist into canarist and my/canarist into my-canarist inside a temporary directory.

    $ canarist -r ~/work/canarist -r ~/work/other -m '{"resolutions":{"typescript":"3.2.4"},"devDependencies":{"jest":"23.0.0}}'
        Clones the master branches of both local repositories into a temporary directory
        and additionally installs yarn resolutions and a missing dev dependency.

    $ canarist -r ~/work/canarist -r ~/work/other -r ~/work/other2 -r ~/work/other3
        Clones the master branches of all four local repositories into a temporary directory
        and executes "yarn test" for each of them.

    $ canarist -r ~/work/canarist -r ~/work/other --y "--production=true"
        Clones the master branches of both repositories and installs production dependencies only

    $ canarist -p my-project
        Looks up the project configuration with the name "my-project" in the cosmiconfig
        of the current repository and clones and executes the repositories and commands therein.
        Read more: https://github.com/xing/canarist/blob/master/README.md

TODOs

  • allow to unpin dependencies which would otherwise be installed multiple times (for example: packages of both repositories have "webpack" as a dependency, one has it pinned to "4.40.0" and the other has a semver range "^4.30.0". If webpack@latest is at 4.40.0 we have no issues, but if webpack has a new release, say 4.41.0, we now have two versions installed).
  • allow to configure which dotfiles should be copied / merged into the root (currently only ".npmrc" will be merged)
  • implement a --no-install or --no-commands flag, as a simple way to "link" two repositories and debug inside them?

canarist's People

Contributors

dependabot[bot] avatar jhiode avatar renovate-bot avatar renovate[bot] avatar zaubernerd avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

nvijay-copado

canarist's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Warning

These dependencies are deprecated:

Datasource Name Replacement PR?
npm @types/rimraf Unavailable
npm eslint-plugin-node Available

Rate-Limited

These updates are currently rate-limited. Click on a checkbox below to force their creation now.

  • chore(deps): replace dependency eslint-plugin-node with eslint-plugin-n ^14.0.0
  • chore(deps): update dependency @types/rimraf to v4
  • chore(deps): update dependency eslint to v9
  • chore(deps): update typescript-eslint monorepo to v8 (major) (@typescript-eslint/eslint-plugin, @typescript-eslint/parser)
  • fix(deps): update dependency cosmiconfig to v9
  • fix(deps): update dependency git-url-parse to v15
  • fix(deps): update dependency rimraf to v6
  • ๐Ÿ” Create all rate-limited PRs at once ๐Ÿ”

Edited/Blocked

These updates have been manually edited so Renovate will no longer make changes. To discard all commits and start over, click on a checkbox.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/node-ci.yml
  • actions/checkout v2
  • actions/setup-node v2
  • actions/cache v2
.github/workflows/release.yml
  • actions/checkout v2
  • actions/setup-node v2
npm
package.json
  • cosmiconfig ^7.0.1
  • debug ^4.3.3
  • fast-glob ^3.2.11
  • git-url-parse ^11.6.0
  • lodash.mergewith ^4.6.2
  • minimist ^1.2.5
  • rimraf ^3.0.2
  • @types/debug ^4.1.7
  • @types/git-url-parse ^9.0.1
  • @types/jest ^29.0.0
  • @types/lodash.mergewith ^4.6.6
  • @types/minimist ^1.2.2
  • @types/node ^20.0.0
  • @types/rimraf ^3.0.2
  • @typescript-eslint/eslint-plugin ^5.10.2
  • @typescript-eslint/parser ^5.10.2
  • eslint ^8.8.0
  • eslint-config-prettier ^9.0.0
  • eslint-plugin-node ^11.1.0
  • eslint-plugin-prettier ^4.0.0
  • husky ^7.0.4
  • jest ^29.0.0
  • jest-runner-eslint ^2.0.0
  • lint-staged ^12.3.3
  • prettier ^2.5.1
  • ts-jest ^29.0.0
  • typescript ^4.5.5
  • node >=10.13.0

  • Check this box to trigger a request for Renovate to run again on this repository

Action Required: Fix Renovate Configuration

There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.

Location: package.json
Error type: The renovate configuration file contains some invalid settings
Message: Configuration option 'packageRules[0].node' should be a json object, Invalid configuration option: author, Invalid configuration option: bin, Invalid configuration option: eslintConfig, Invalid configuration option: husky, Invalid configuration option: jest, Invalid configuration option: license, Invalid configuration option: lint-staged, Invalid configuration option: name, Invalid configuration option: packageRules[1].cosmiconfig, Invalid configuration option: packageRules[1].debug, Invalid configuration option: packageRules[1].fast-glob, Invalid configuration option: packageRules[1].git-url-parse, Invalid configuration option: packageRules[1].lodash.mergewith, Invalid configuration option: packageRules[1].minimist, Invalid configuration option: packageRules[1].rimraf, Invalid configuration option: packageRules[2].@types/debug, Invalid configuration option: packageRules[2].@types/git-url-parse, Invalid configuration option: packageRules[2].@types/jest, Invalid configuration option: packageRules[2].@types/lodash.mergewith, Invalid configuration option: packageRules[2].@types/minimist, Invalid configuration option: packageRules[2].@types/node, Invalid configuration option: packageRules[2].@types/rimraf, Invalid configuration option: packageRules[2].@typescript-eslint/eslint-plugin, Invalid configuration option: packageRules[2].@typescript-eslint/parser, Invalid configuration option: packageRules[2].eslint, Invalid configuration option: packageRules[2].eslint-config-prettier, Invalid configuration option: packageRules[2].eslint-plugin-node, Invalid configuration option: packageRules[2].eslint-plugin-prettier, Invalid configuration option: packageRules[2].husky, Invalid configuration option: packageRules[2].jest, Invalid configuration option: packageRules[2].jest-runner-eslint, Invalid configuration option: packageRules[2].lint-staged, Invalid configuration option: packageRules[2].prettier, Invalid configuration option: packageRules[2].ts-jest, Invalid configuration option: packageRules[2].typescript, Invalid configuration option: prettier, Invalid configuration option: renovate, Invalid configuration option: scripts, Invalid configuration option: version, The "node" object can only be configured at the top level of a config but was found inside "packageRules[0]"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.