Jump to content

nx monorepo paina work chesevallu...itu randi...


dasari4kntr

Recommended Posts

nx monorepo setup vundi...

i am using vscode...and installed jest, jestrunner plugins...(normally these plugins setup is pretty straight forward..in normal react applications..)

but how do you setup for monorepos..? most importantly...how do you setup debug for monorepo...is it same old launch.json or NX give any special command for that....

Link to comment
Share on other sites

Setting up a monorepo can vary depending on the tools and frameworks you are using. However, some general steps can help you set up a monorepo:

  1. Choose a package manager: Select a package manager like npm, Yarn, or pnpm, that can manage dependencies across multiple packages.

  2. Define the structure of your monorepo: Decide on the directory structure and naming conventions for packages in your monorepo. Some popular structures include Lerna, Yarn Workspaces, and Nx.

  3. Create packages: Create packages within your monorepo that contain code for different parts of your application. You can create packages for libraries, services, and UI components.

  4. Set up cross-dependencies: Configure dependencies between packages in your monorepo so that they can communicate with each other. For example, a library package may be used by a service package.

  5. Configure build and test scripts: Configure build and test scripts to compile and test all packages in your monorepo.

As for debugging in a monorepo, it depends on the tool you are using. If you are using VS Code and the Nx workspace, you can use the same old launch.json to debug your applications. However, you will need to specify the name of the project you want to debug in the "program" field of the launch configuration.

For example, if you have an Angular application called "my-app" in your Nx workspace, you can set up a launch configuration like this:

 
{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "chrome",
      "request": "launch",
      "name": "Debug my-app",
      "url": "http://localhost:4200",
      "webRoot": "${workspaceFolder}/apps/my-app",
      "sourceMaps": true,
      "sourceMapPathOverrides": {
        "webpack:///*": "${webRoot}/*"
      }
    }
  ]
}

If you have multiple applications in your monorepo, you can create separate launch configurations for each of them. You can also use the Nx CLI to run and debug your applications using the nx run command. For example, to run the "my-app" application in debug mode, you can use the following command:

nx run my-app:serve --configuration=debug

This will start the application in debug mode, and you can attach the VS Code debugger to it using the launch configuration.

 

  • Thanks 1
Link to comment
Share on other sites

24 minutes ago, Spartan said:

@dasari4kntr  same root repo package.json lo ne set chesam script

using Lerna

yea..that basic setup is there..

but nx has its own commands...just checking..is there any additional configuration needed with NX...

Link to comment
Share on other sites

20 minutes ago, dasari4kntr said:

yea..that basic setup is there..

but nx has its own commands...just checking..is there any additional configuration needed with NX...

i dont think so..it should be same basic setup.

Link to comment
Share on other sites

3 minutes ago, Spartan said:

@dasari4kntr if you havent already seen this.

https://github.com/nrwl/nx-examples

yes..i seen this...these commands are good to run in console...and also its very difficult to run the single unit test or debug..we have to run all the unit tests...

instead  i am trying to configure those commands to run in vscode plugins...

 

see the below screenshot... (this setup is working somehow in my personal MAC...but same setup is giving trouble in office work..)

left side gives you list of unit tests...

and every unit test will have run and debug...option to run the individual test..

eER1ZkR.png

 

Link to comment
Share on other sites

2 minutes ago, dasari4kntr said:

yes..i seen this...these commands are good to run in console...and also its very difficult to run the single unit test or debug..we have to run all the unit tests...

instead  i am trying to configure those commands to run in vscode plugins...

 

see the below screenshot... (this setup is working somehow in my personal MAC...but same setup is giving trouble in office work..)

left side gives you list of unit tests...

and every unit test will have run and debug...option to run the individual test..

eER1ZkR.png

 

sCo_^Y individual ga particular unittest teliyadu kaani..

you can try to run the unit-test related to one particular component of that monorepo.

something like  `jest comp1`   or `jest comp2`  and define them in package.json

Link to comment
Share on other sites

7 minutes ago, Spartan said:

sCo_^Y individual ga particular unittest teliyadu kaani..

you can try to run the unit-test related to one particular component of that monorepo.

something like  `jest comp1`   or `jest comp2`  and define them in package.json

yes.."nx test comp1" "nx test comp2"..etc vunnayi...options..thats how we are doing it...

but the problem with that is...once your testcases grow...like houndreds...once you write a new test case...you need to waiting all tests to finish...to test your new unit test...

generally this can be handled easily in normal react projects...

but for monorepo with nx...its bit tricky...

anduke checking...if anyone already done this or not ani...

Link to comment
Share on other sites

19 minutes ago, dasari4kntr said:

yes.."nx test comp1" "nx test comp2"..etc vunnayi...options..thats how we are doing it...

but the problem with that is...once your testcases grow...like houndreds...once you write a new test case...you need to waiting all tests to finish...to test your new unit test...

generally this can be handled easily in normal react projects...

but for monorepo with nx...its bit tricky...

anduke checking...if anyone already done this or not ani...

I dont think it will be specific to NX,  it would be jest feature.  sCo_^Y

 

did u explore `jest -t` flag.?

Link to comment
Share on other sites

12 hours ago, Spartan said:

I dont think it will be specific to NX,  it would be jest feature.  sCo_^Y

 

did u explore `jest -t` flag.?

nx test configurations are like this...

"test": {
      "executor": "@nrwl/jest:jest",
      "outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
      "options": {
        "jestConfig": "packages/frontend/jest.config.ts",
        "passWithNoTests": true
      },
      "configurations": {
        "ci": {
          "ci": true,
          "codeCoverage": true
        }
      }
    }

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...