GithubHelp home page GithubHelp logo

nirgilboa / traf Goto Github PK

View Code? Open in Web Editor NEW

This project forked from lemonade-hq/traf

0.0 0.0 0.0 214 KB

Find truly affected packages in monorepos

License: MIT License

JavaScript 0.41% TypeScript 99.59%

traf's Introduction

traf ๐Ÿš€

Avoid unnecessary builds, tests, lint and more in your monorepo CI. Optimize your development process by intelligently finding affected dependencies and selectively triggering builds and tests only when needed.

Motivation

CI pipeline runtime is a precious resource, and in order to keep it as short as possible, we need to run only the necessary builds, tests, etc..

The way Nx affected algorithm works is by finding all changed projects in the current branch by file path and return the "affected" projects by the dependency graph.

This is not always accurate, as a change in a file can be a simple change in a comment, or a change in a function that is not used by a dependant project.

In Lemonade we have several big monorepos with complex dep graph, and we found that the affected algorithm causes us to run unnecessary tasks, which increases the CI runtime and slows down the development process.

This is where true affected comes in. It will find the affected projects by lines changes in the current branch. image

Packages

@traf/core

A library that finds affected projects in a monorepo, based on the changed lines in the current branch.

Installation

npm install @traf/core

Usage

import { trueAffected } = from '@traf/core';

const affected = await trueAffected({
  rootTsConfig: 'tsconfig.base.json',
  projects: [
    {
      name: 'proj1',
      sourceRoot: '<project source>',
      tsConfig: '<project source>/tsconfig.json',
    },
    // ...
  ],
})

Options

Option Type Description Default
rootTsConfig string The path to the root tsconfig file
projects Project[] An array of projects to check
cwd string The current working directory
base string The base branch to compare against origin/main

rootTsConfig - The path to the root tsconfig file, should include the paths prop with all projects mapping so ts-morph can find the references.

Project

Option Type Description
name string The project name
sourceRoot string The project source root
tsConfig string The project tsconfig file (should only include the project files)
implicitDependencies string[] An array of implicit dependencies

How it works?

The algorithm is based on the following steps:

  1. Using git to find all changed lines in the current branch.
  2. Using ts-morph to find the changed element (function, class, const etc..) per line.
  3. Using ts-morph findReferences to find all references to the changed element recursively.
  4. For each reference, find the project that contains the reference and add it to the affected projects list.

@traf/nx

A cli tool that wraps @traf/core to be used with Nx.

Will automatically find all projects in the nx workspace.

Usage

npx @traf/nx@latest affected <action> [options]

Options

Option Description Default
--cwd The current working directory process.cwd()
--base The base branch to compare against origin/main
--tsConfigFilePath The path to the root tsconfig file tsconfig.base.json
--action The action to perform. Can be any command log
--json Output the result as JSON false

traf's People

Contributors

eladbezalel avatar

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.