Monitor and compile numerous directories simultaneously in TypeScript (monorepo)

I've been searching far and wide online for a solution to my problem, but unfortunately, I haven't come across anything useful yet. Essentially, I am in need of a tool or method that will allow me to kick off TypeScript file Watching/Compiling in multiple directories simultaneously.

Within my monorepo, I have various scoped NPM packages such as @test/one, @test/two, @test/three, and so on. My objective is to be able to watch and compile all these packages at once.

It seems that TypeScript does not directly support this functionality, and there doesn't appear to be any existing tools that can accomplish this task either. The closest solution I found was nodemon, which can watch multiple directories at the same time, but it lacks the ability to execute 'tsc' in every watched directory upon changes.

The most effective workaround I could come up with using nodemon looked like this, although it's not an ideal approach as it compiles all packages even if only one has changed:

npx nodemon --watch test-shared-api --watch test-shared-redux --watch test-shared-types -e js,ts,jsx,tsx --exec "npx tsc --build test-shared-api/tsconfig.json && npx tsc --build test-shared-types/tsconfig.json && npx tsc -build test-shared-redux/tsconfig.json"

Alternatively, utilizing concurrently in the package.json allows me to implement the following setup, which is a step closer to efficiency, but still leaves room for improvement:

"scripts": {
"ts-watch-shared-types": "tsc -p packages/@test-shared/test-shared-types/tsconfig.json -w",
"ts-watch-shared-api": "tsc -p packages/@test-shared/test-shared-api/tsconfig.json -w",
"ts-watch-shared-redux": "tsc -p packages/@test-shared/test-shared-redux/tsconfig.json -w",
"ts-shared-watch": "concurrently -k -n w: npm:ts-watch-shared-*"
  },

Any suggestions or better solutions are greatly appreciated!

Answer №2

To kick off a build pipeline, using a monorepo architecture is a typical strategy.
Facing the same situation, I found success in making it work this way (using turborepo as an example):

  • Set up a global package.json script
    "start:dev-watch": "turbo run start:dev-watch"
  • In the main package.json file, include the script:
    "start:dev-watch": "nodemon src/index.ts"
    (I opt for nodemon with ts-node installed to directly run ts files, ideal for debugging)
  • In each project's package.json that needs to be built, add the script:
    "build:watch": "tsc -w"

By doing this, when launching the npm run start:dev-watch command in the parent directory, all start:dev-watch scripts will initiate simultaneously.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The possibility exists that the onClick function may be null

I am encountering an issue with a props function that is showing an error message stating that the object may be null. import {Dropdown} from "react-bootstrap"; interface GenreButtonProps { key: number; id: number | null; genre: strin ...

Here is a guide on showcasing information obtained from ASP.NET API in Angular version 13

My goal is to fetch motorcycle data from a web API and showcase it in my Angular project. ASP.NET Framework Web API 4.7 Angular CLI: 13.3.7 Angular: 13.3.11 On the Web API end: Controller: [EnableCors(origins: "*", headers: "*", ...

Show off markdown formatting without the need for v-html

I run a unique type of platform that allows users to publish their own blog posts using a WYSIWYG editor, and then share them on the site. My top priority is to ensure security against XSS attacks, which is why I am looking for alternatives to using v-htm ...

Utilize packages from a personal GitLab repository using NPM

Having trouble installing NPM dependencies from a private GitLab instance. My repository contains basic files https://i.stack.imgur.com/Ns0t8.png I included this dependency in the package.json of my project "node-demo-package": "https://oauth2:<ACCE ...

Dialog box obscuring PrimeNG dropdown menu

I'm working on an Angular2 app that utilizes PrimeNG components. My issue arises when trying to include a dropdown inside a dialog box. Despite my implementation, the dropdown ends up being cut off due to the constraints of the dialog box, as visible ...

What causes a function loss when using the spread operator on window.localStorage?

I am attempting to enhance the window.localStorage object by adding custom methods and returning an object in the form of EnhancedStorageType, which includes extra members. Prior to using the spread operator, the storage.clear method is clearly defined... ...

The error message "npm ref could not find the bindings file" indicates that the

I have encountered an issue while using the ref package in my nodejs project with electron. Whenever I include ref in my JS code, it throws an error stating that it cannot find the bindings file. Here's the exact error message: Error: Could not locat ...

Encountering a webpack mix issue on Ubuntu version 18

Whenever I try to execute the command ( npm run watch ), I encounter this error: @ development /home/nader/Desktop/asd/blog cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setu ...

Error! Unexpected closure occurred while creating an Angular CLI project with npm

After cloning an Angular (4+) CLI project onto a new machine and running npm install, I encountered an error that reads as follows. This project works perfectly fine on other computers: npm ERR! premature close npm ERR! A complete log of this run can be ...

Is it possible for npm install to disregard development dependencies during the installation process

In a Node.js project, running npm install will install both the dependencies and dev dependencies. To skip installing dev dependencies, you can use npm install --production. Question 1: If I don't include --production, will the dependencies' dev ...

Achieving Jest integration with Angular 9 in a Storybook setup

We are currently utilizing Storybook 5 alongside Angular 9, with Jest 26 for some of the testing procedures. The issue we're facing arises when using Typescript version below 3.8.0 - a requirement for Angular 9's ng build --prod. This results in ...

Having trouble with the npm install for react-router-dom. I keep receiving the following error message

https://i.stack.imgur.com/SEvjL.pnghttps://i.stack.imgur.com/m4q79.pngI encountered an issue with my command prompt while trying to install react-router-dom. The problem arose due to three moderate severity vulnerabilities. I attempted to fix them using ...

The task of mapping an array of objects with nested values using JavaScript is proving to

Attempting to convert an array of objects with nested values in child objects like: const objs = [{ "B": { "value": 1, }, "D": { "value": "45" }, "E": { "value": "234" }, ...

What is the best way to implement lazy loading for child components in React's Next.js?

I am exploring the concept of lazy loading for children components in React Next JS. Below is a snippet from my layout.tsx file in Next JS: import {lazy, Suspense} from "react"; import "./globals.css"; import type { Metadata } from &quo ...

Guide on accessing a modal component in Angular?

I have an Edit Button on my component called SearchComponent. When the user clicks this button, it currently redirects them to another component named EditFormComponent using navigateByUrl('url-link'). However, I would like to enhance the user ex ...

Ways to extend the default timeout duration in Angular

My server calls are taking a long time, around 30-40 minutes, and my Angular frontend is timing out. Is there a way to increase the default timeout for this service call? method1(id: number): Promise<number> { const body= JSON.stringify(id); ...

tslint issues detected within a line of code in a function

I am a novice when it comes to tslint and typescript. Attempting to resolve the error: Unnecessary local variable - stackThird. Can someone guide me on how to rectify this issue? Despite research, I have not been successful in finding a solution. The err ...

Expect a reply within the loop

One of my endpoints takes some time to generate data, and I have another endpoint to retrieve that generated data. I make the initial call using await, extract the ID from the response, and then keep calling the second endpoint until the status is not "Suc ...

Managing Versions and Dependencies in NPM using package.json for Node Applications

Traditionally, we have refrained from including node_modules folder(s) in our application's revision control. As part of our build processes and developer guidelines, it is required to manually run "npm install" upon initial checkout to fetch the nece ...

Error message appears when using TypeScript with a React Material table showing a generic type error

I am currently attempting to implement react-material in a Typescript project. As a newcomer to Typescript, I am encountering some errors that I am unsure how to resolve. In this gist, I am trying to create a reusable React component (Please view the gis ...