From 9e75918154be4d048346517dd3587680cb065fdc Mon Sep 17 00:00:00 2001 From: Victor Savkin Date: Wed, 19 Jan 2022 15:30:21 -0500 Subject: [PATCH] feat(core): speed up file map creation (#8597) --- e2e/node/src/node.test.ts | 15 --- e2e/react/src/react-package.test.ts | 14 -- packages/angular/README.md | 61 +-------- packages/cli/README.md | 14 +- packages/create-nx-plugin/README.md | 2 +- packages/create-nx-workspace/README.md | 21 +-- packages/cypress/README.md | 14 +- packages/devkit/README.md | 8 +- packages/eslint-plugin-nx/README.md | 10 +- packages/express/README.md | 26 +--- packages/gatsby/README.md | 37 +----- packages/jest/README.md | 14 +- packages/js/README.md | 14 +- packages/linter/README.md | 14 +- packages/nest/README.md | 26 +--- packages/next/README.md | 37 +----- packages/node/README.md | 14 +- packages/nx-plugin/README.md | 6 +- packages/nx/README.md | 16 +-- packages/react/README.md | 37 +----- packages/storybook/README.md | 14 +- packages/tao/README.md | 14 +- packages/web/README.md | 27 +--- packages/workspace/README.md | 16 +-- .../locators/tsconfig-json-changes.ts | 25 ++-- packages/workspace/src/core/file-map-utils.ts | 124 ++++++++++-------- packages/workspace/src/core/file-utils.ts | 13 -- .../explicit-project-dependencies.spec.ts | 19 +-- .../src/core/project-graph/operators.ts | 6 - .../src/core/target-project-locator.spec.ts | 36 ++--- .../src/core/target-project-locator.ts | 67 +++++----- scripts/copy-readme.js | 8 +- .../{getting-started.md => content.md} | 14 +- scripts/readme-fragments/resources.md | 4 +- scripts/readme-fragments/what-is-nx.md | 3 - 35 files changed, 247 insertions(+), 543 deletions(-) rename scripts/readme-fragments/{getting-started.md => content.md} (69%) delete mode 100644 scripts/readme-fragments/what-is-nx.md diff --git a/e2e/node/src/node.test.ts b/e2e/node/src/node.test.ts index fd83f8dea0..623d5a03bb 100644 --- a/e2e/node/src/node.test.ts +++ b/e2e/node/src/node.test.ts @@ -718,13 +718,6 @@ describe('with dependencies', () => { import "@${proj}/${parentLib}"; ` ); - - // we are setting paths to {} to make sure built libs are read from dist - updateFile('tsconfig.base.json', (c) => { - const json = JSON.parse(c); - json.compilerOptions.paths = {}; - return JSON.stringify(json, null, 2); - }); }); it('should build a library without dependencies', () => { @@ -772,13 +765,5 @@ describe('with dependencies', () => { ); expect(buildWithDeps).toContain('Successfully ran target build'); checkFilesDoNotExist(`apps/${app}/tsconfig/tsconfig.nx-tmp`); - - // we remove all path mappings from the root tsconfig, so when trying to build - // libs from source, the builder will throw - const failedBuild = runCLI( - `build ${app} --with-deps --buildLibsFromSource`, - { silenceError: true } - ); - expect(failedBuild).toContain(`Can't resolve`); }, 1000000); }); diff --git a/e2e/react/src/react-package.test.ts b/e2e/react/src/react-package.test.ts index 5d84665f5d..22058498b7 100644 --- a/e2e/react/src/react-package.test.ts +++ b/e2e/react/src/react-package.test.ts @@ -92,13 +92,6 @@ describe('Build React libraries and apps', () => { return json; }); updateFile(`libs/${childLib}/src/assets/hello.txt`, 'Hello World!'); - - // we are setting paths to {} to make sure built libs are read from dist - updateFile('tsconfig.base.json', (c) => { - const json = JSON.parse(c); - json.compilerOptions.paths = {}; - return JSON.stringify(json, null, 2); - }); }); afterEach(() => killPorts()); @@ -236,13 +229,6 @@ export async function h() { return 'c'; } ); expect(buildFromSource).toContain('Successfully ran target build'); checkFilesDoNotExist(`apps/${app}/tsconfig/tsconfig.nx-tmp`); - - // we remove all path mappings from the root tsconfig, so when trying to build - // libs from source, the builder will throw - const failedBuild = runCLI(`build ${app} --buildLibsFromSource`, { - silenceError: true, - }); - expect(failedBuild).toContain(`Can't resolve`); }, 1000000); it('should not create a dist folder if there is an error', async () => { diff --git a/packages/angular/README.md b/packages/angular/README.md index 2aada4fadc..e7ac71955a 100644 --- a/packages/angular/README.md +++ b/packages/angular/README.md @@ -4,63 +4,10 @@
-# Angular Plugin for Nx +# Nx: Smart, Fast and Extensible Build System -The Nx Plugin for Angular contains executors, generators, and utilities for managing Angular applications, and libraries within an Nx workspace. It provides: +Nx is a next generation build system with first class monorepo support and powerful integrations. -- Integration with libraries such as Jest, Cypress, Karma, Protractor, and Storybook. -- Helper services, and functions to use along with NgRx libraries. -- Scaffolding for upgrading AngularJS applications. -- Scaffolding for creating buildable libraries that can be published to npm. -- Utilities for automatic workspace refactoring. +This package is an [Angular plugin for Nx](https://nx.dev/angular/overview). -## Adding the Angular plugin - -Adding the Angular plugin to a workspace can be done with the following: - -```bash -#yarn -yarn add @nrwl/angular -``` - -```bash -#npm -npm install @nrwl/angular -``` - -For more information about the `@nrwl/angular` package take a look at the [Angular Plugin Overview](https://nx.dev/angular/overview). - -{{what-is-nx}} - -{{getting-started}} - -``` - -✔ Workspace name (e.g., org name) · happyorg -✔ What to create in the new workspace · angular -✔ Application name · my app -✔ Default stylesheet format · css - -``` - -### Serving Application - -- Run `nx serve myapp` to serve the newly generated application! -- Run `nx test myapp` to test it. -- Run `nx e2e myapp-e2e` to run e2e tests for it. - -You can also use `ng` instead of `nx`: - -- Run `ng serve myapp` to serve the newly generated application! -- Run `ng test myapp` to test it. -- Run `ng e2e myapp-e2e` to run e2e tests for it. - -## Quick Start Videos - - -

Nx - Quick Start Videos

-
- -- [Nx Dev Tools for Monorepos, In-Depth Explainer](https://youtu.be/h5FIGDn5YM0) - -{{resources}} +{{content} diff --git a/packages/cli/README.md b/packages/cli/README.md index f21480ddd0..b833424d29 100644 --- a/packages/cli/README.md +++ b/packages/cli/README.md @@ -4,16 +4,8 @@
-# Nx CLI +# Nx: Smart, Fast and Extensible Build System -{{what-is-nx}} +Nx is a next generation build system with first class monorepo support and powerful integrations. -{{getting-started}} - -### Serving Application - -- Run `nx serve myapp` to serve the newly generated application! -- Run `nx test myapp` to test it. -- Run `nx e2e myapp-e2e` to run e2e tests for it. - -{{resources}} +{{content} diff --git a/packages/create-nx-plugin/README.md b/packages/create-nx-plugin/README.md index 50870134dc..4a1fb5c642 100644 --- a/packages/create-nx-plugin/README.md +++ b/packages/create-nx-plugin/README.md @@ -6,7 +6,7 @@ # `> npx create-nx-plugin` -{{what-is-nx}} +Nx is a next generation build system with first class monorepo support and powerful integrations. ## What is It? diff --git a/packages/create-nx-workspace/README.md b/packages/create-nx-workspace/README.md index a0cd34934f..29bb941579 100644 --- a/packages/create-nx-workspace/README.md +++ b/packages/create-nx-workspace/README.md @@ -6,25 +6,12 @@ # `> npx create-nx-workspace` -{{what-is-nx}} +Nx is a next generation build system with first class monorepo support and powerful integrations. {{getting-started}} -``` -? Workspace name (e.g., org name) happyorg -? What to create in the new workspace web components [a workspace with a single app built using web components] -? Application name myapp -? Default stylesheet format CSS -``` +## What is It? -If it's your first Nx project, the command will recommend you to install the `nx` package globally, so you can invoke `nx` directly without going through yarn or npm. +It's a command to create a new Nx workspace. -## Serving Application - -- Run `nx serve myapp` to serve the newly generated application! -- Run `nx test myapp` to test it. -- Run `nx e2e myapp-e2e` to run e2e tests for it. - -Angular users can also run `ng g/serve/test/e2e`. - -{{resources}} +{{content}} diff --git a/packages/cypress/README.md b/packages/cypress/README.md index bef1e7727e..898f4cb541 100644 --- a/packages/cypress/README.md +++ b/packages/cypress/README.md @@ -4,16 +4,10 @@
-# Cypress Plugin for Nx +# Nx: Smart, Fast and Extensible Build System -{{what-is-nx}} +Nx is a next generation build system with first class monorepo support and powerful integrations. -## What is It? +This package is a [Cypress plugin for Nx](https://nx.dev/cypress/overview). -Executors and generators adding Cypress tests for frontend applications. - -## How to Use - -This package is used by the `@nrwl/web`, `@nrwl/react`, and `@nrwl/angular`. See [https://github.com/nrwl/nx](https://github.com/nrwl/nx) for more information. - -{{resources}} +{{content} diff --git a/packages/devkit/README.md b/packages/devkit/README.md index 10ab3cc3e2..94d686b11f 100644 --- a/packages/devkit/README.md +++ b/packages/devkit/README.md @@ -4,10 +4,10 @@
-# Nx Devkit +# Nx: Smart, Fast and Extensible Build System -{{what-is-nx}} +Nx is a next generation build system with first class monorepo support and powerful integrations. -{{getting-started}} +This package contains a set of utilities for creating Nx plugins. -{{resources}} +{{content} diff --git a/packages/eslint-plugin-nx/README.md b/packages/eslint-plugin-nx/README.md index 0995d1eeee..f73ad23969 100644 --- a/packages/eslint-plugin-nx/README.md +++ b/packages/eslint-plugin-nx/README.md @@ -4,12 +4,10 @@
-# ESLint Plugin for Nx +# Nx: Smart, Fast and Extensible Build System -{{what-is-nx}} +Nx is a next generation build system with first class monorepo support and powerful integrations. -## How to Use +This package is an ESLint plugin for Nx. -This package is used by the `@nrwl/web`, `@nrwl/react`, `@nrwl/angular`, and `@nrwl/node`. See [https://github.com/nrwl/nx](https://github.com/nrwl/nx) for more information. - -{{resources}} +{{content} diff --git a/packages/express/README.md b/packages/express/README.md index 9b8bd4d04b..9140dce7ba 100644 --- a/packages/express/README.md +++ b/packages/express/README.md @@ -4,28 +4,10 @@
-# Express Plugin for Nx +# Nx: Smart, Fast and Extensible Build System -{{what-is-nx}} +Nx is a next generation build system with first class monorepo support and powerful integrations. -{{getting-started}} +This package is an [Express plugin for Nx](https://nx.dev/express/overview). -``` -? Workspace name (e.g., org name) happyorg -? What to create in the new workspace express -? Application name myapp -? Default stylesheet format CSS -``` - -You can also select `empty` and add `@nrwl/express` plugin using yarn or npm, and then generate a new express app using `nx g @nrwl/express:app myapp`. - -If it's your first Nx project, the command will recommend you to install the `nx` package globally, so you can invoke `nx` directly without going through yarn or npm. - -### Serving Application - -- Run `nx serve myapp` to serve the newly generated application! -- Run `nx test myapp` to test it. - -You are good to go! - -{{resources}} +{{content} diff --git a/packages/gatsby/README.md b/packages/gatsby/README.md index 46095081c9..cf55c2a6e2 100644 --- a/packages/gatsby/README.md +++ b/packages/gatsby/README.md @@ -1,40 +1,13 @@ -

Nx - Smart, Fast and Extensible Build System

+

Nx - Smart, Fast and Extensible Build System

{{links}}
-# Gatsby Plugin for Nx +# Nx: Smart, Fast and Extensible Build System -{{what-is-nx}} +Nx is a next generation build system with first class monorepo support and powerful integrations. -{{getting-started}} +This package is a [Gatsby plugin for Nx](https://nx.dev/gatsby/overview). -``` -? Workspace name (e.g., org name) happyorg -? What to create in the new workspace gatsby [a workspace with a single Gatsby application] -? Application name myapp -? Default stylesheet format CSS -``` - -You can also select `empty` and add `@nrwl/gatsby` plugin using yarn or npm, and then generate a new express app using `nx g @nrwl/gatsby:app myapp`. - -If it's your first Nx project, the command will recommend you to install the `nx` package globally, so you can invoke `nx` directly without going through yarn or npm. - -### Serving Application - -- Run `nx serve myapp` to serve the newly generated application! -- Run `nx test myapp` to test it. -- Run `nx e2e myapp` to run e2e tests for your application. - -You are good to go! - -## Quick Start Videos - - -

Nx - Quick Start video

-
- -- [Nx Dev Tools for Monorepos, In-Depth Explainer (React)](https://www.youtube.com/watch?v=jCf92IyR-GE) - -{{resources}} +{{content} diff --git a/packages/jest/README.md b/packages/jest/README.md index 8ecd1d7440..87a1bb12f5 100644 --- a/packages/jest/README.md +++ b/packages/jest/README.md @@ -4,16 +4,10 @@
-# Jest Plugin for Nx +# Nx: Smart, Fast and Extensible Build System -{{what-is-nx}} +Nx is a next generation build system with first class monorepo support and powerful integrations. -## What is It? +This package is a [Jest plugin for Nx](https://nx.dev/jest/overview). -Executors and generators adding Jest tests to applications and libraries. - -## How to Use - -This package is used by the `@nrwl/web`, `@nrwl/react`, `@nrwl/angular`, `@nrwl/node`. See [https://github.com/nrwl/nx](https://github.com/nrwl/nx) for more information. - -{{resources}} +{{content} diff --git a/packages/js/README.md b/packages/js/README.md index ddb5c8f8da..401cbf92f0 100644 --- a/packages/js/README.md +++ b/packages/js/README.md @@ -1,7 +1,13 @@ -# js +

Nx - Smart, Fast and Extensible Build System

-This library was generated with [Nx](https://nx.dev). +{{links}} -## Running unit tests +
-Run `nx test js` to execute the unit tests via [Jest](https://jestjs.io). +# Nx: Smart, Fast and Extensible Build System + +Nx is a next generation build system with first class monorepo support and powerful integrations. + +This package is a [JavaScript/TypeScript plugin for Nx](https://nx.dev/js/overview). + +{{content} diff --git a/packages/linter/README.md b/packages/linter/README.md index be7852f5e9..b833424d29 100644 --- a/packages/linter/README.md +++ b/packages/linter/README.md @@ -4,16 +4,8 @@
-# Linter Plugin for Nx +# Nx: Smart, Fast and Extensible Build System -{{what-is-nx}} +Nx is a next generation build system with first class monorepo support and powerful integrations. -## What is It? - -Executors and generators adding TS and JS lint checks to applications and libraries. - -## How to Use - -This package is used by the `@nrwl/web`, `@nrwl/react`, `@nrwl/angular`, `@nrwl/node`. See [https://github.com/nrwl/nx](https://github.com/nrwl/nx) for more information. - -{{resources}} +{{content} diff --git a/packages/nest/README.md b/packages/nest/README.md index 136b13267e..af82656ec3 100644 --- a/packages/nest/README.md +++ b/packages/nest/README.md @@ -4,28 +4,10 @@
-# Nest.js Plugin for Nx +# Nx: Smart, Fast and Extensible Build System -{{what-is-nx}} +Nx is a next generation build system with first class monorepo support and powerful integrations. -{{getting-started}} +This package is a [NestJS plugin for Nx](https://nx.dev/nest/overview). -``` -? Workspace name (e.g., org name) happyorg -? What to create in the new workspace nest -? Application name myapp -? Default stylesheet format CSS -``` - -You can also select `empty` and add `@nrwl/nest` plugin using yarn or npm, and then generate a new express app using `nx g @nrwl/nest:app myapp`. - -If it's your first Nx project, the command will recommend you to install the `nx` package globally, so you can invoke `nx` directly without going through yarn or npm. - -### Serving Application - -- Run `nx serve myapp` to serve the newly generated application! -- Run `nx test myapp` to test it. - -You are good to go! - -{{resources}} +{{content} diff --git a/packages/next/README.md b/packages/next/README.md index fe9705ee21..c80a641051 100644 --- a/packages/next/README.md +++ b/packages/next/README.md @@ -1,40 +1,13 @@ -

Nx - Smart, Fast and Extensible Build System

+

Nx - Smart, Fast and Extensible Build System

{{links}}
-# Next.js Plugin for Nx +# Nx: Smart, Fast and Extensible Build System -{{what-is-nx}} +Nx is a next generation build system with first class monorepo support and powerful integrations. -{{getting-started}} +This package is a [Next.js plugin for Nx](https://nx.dev/next/overview). -``` -? Workspace name (e.g., org name) happyorg -? What to create in the new workspace next.js [a workspace with a single Next.js application] -? Application name myapp -? Default stylesheet format CSS -``` - -You can also select `empty` and add `@nrwl/next` plugin using yarn or npm, and then generate a new express app using `nx g @nrwl/next:app myapp`. - -If it's your first Nx project, the command will recommend you to install the `nx` package globally, so you can invoke `nx` directly without going through yarn or npm. - -### Serving Application - -- Run `nx serve myapp` to serve the newly generated application! -- Run `nx test myapp` to test it. -- Run `nx e2e myapp` to run e2e tests for your application. - -You are good to go! - -## Quick Start Videos - - -

Nx - Quick start video

-
- -- [Nx Dev Tools for Monorepos, In-Depth Explainer (React)](https://www.youtube.com/watch?v=jCf92IyR-GE) - -{{resources}} +{{content} diff --git a/packages/node/README.md b/packages/node/README.md index d0eb22aca9..b833424d29 100644 --- a/packages/node/README.md +++ b/packages/node/README.md @@ -4,16 +4,8 @@
-# NodeJS Plugin for Nx +# Nx: Smart, Fast and Extensible Build System -{{what-is-nx}} +Nx is a next generation build system with first class monorepo support and powerful integrations. -## What is It? - -Executors and generators adding basic functionality for building, testing and linting node applications and libraries. - -## How to Use - -This package is used by the `@nrwl/express`, and `@nrwl/next`. See [https://github.com/nrwl/nx](https://github.com/nrwl/nx) for more information. - -{{resources}} +{{content} diff --git a/packages/nx-plugin/README.md b/packages/nx-plugin/README.md index 052ca446d0..15aabb9a7b 100644 --- a/packages/nx-plugin/README.md +++ b/packages/nx-plugin/README.md @@ -4,9 +4,9 @@
-# Plugin for Creating Nx Plugins +# Nx: Smart, Fast and Extensible Build System -{{what-is-nx}} +Nx is a next generation build system with first class monorepo support and powerful integrations. ## What is It? @@ -14,4 +14,4 @@ It's an Nx plugin used to build other Nx plugins. Check out the list of community plugins and the documentation on how to create one using `create-nx-plugin` here: [https://nx.dev/community](https://nx.dev/community) -{{resources}} +{{content}} diff --git a/packages/nx/README.md b/packages/nx/README.md index 38b691fe9e..b833424d29 100644 --- a/packages/nx/README.md +++ b/packages/nx/README.md @@ -4,18 +4,8 @@
-# Nx CLI +# Nx: Smart, Fast and Extensible Build System -This is an alias of the [@nrwl/cli](https://www.npmjs.com/package/@nrwl/cli) package. Please see [@nrwl/cli](https://www.npmjs.com/package/@nrwl/cli) for more information. +Nx is a next generation build system with first class monorepo support and powerful integrations. -{{what-is-nx}} - -{{getting-started}} - -### Serving Application - -- Run `nx serve myapp` to serve the newly generated application! -- Run `nx test myapp` to test it. -- Run `nx e2e myapp-e2e` to run e2e tests for it. - -{{resources}} +{{content} diff --git a/packages/react/README.md b/packages/react/README.md index 35e5de8572..d00044f532 100644 --- a/packages/react/README.md +++ b/packages/react/README.md @@ -1,40 +1,13 @@ -

Nx - Smart, Fast and Extensible Build System

+

Nx - Smart, Fast and Extensible Build System

{{links}}
-# React Plugin for Nx +# Nx: Smart, Fast and Extensible Build System -{{what-is-nx}} +Nx is a next generation build system with first class monorepo support and powerful integrations. -{{getting-started}} +This package is a [React plugin for Nx](https://nx.dev/react/overview). -``` -? Workspace name (e.g., org name) happyorg -? What to create in the new workspace react [a workspace with a single React application] -? Application name myapp -? Default stylesheet format CSS -``` - -If it's your first Nx project, the command will recommend you to install the `nx` package globally, so you can invoke `nx` directly without going through yarn or npm. - -### Serving Application - -- Run `nx serve myapp` to serve the newly generated application! -- Run `nx test myapp` to test it. -- Run `nx e2e myapp-e2e` to run e2e tests for it. - -### Adding React Plugin Into an Existing Workspace - -You can always add the React plugin to an existing workspace by installing `@nrwl/react` and then generating an React application, as follows: `nx g @nrwl/react:app myapp`. - -## Quick Start Videos - - -

Nx - Quick start video

-
- -- [Nx Dev Tools for Monorepos, In-Depth Explainer (React)](https://www.youtube.com/watch?v=jCf92IyR-GE) - -{{resources}} +{{content} diff --git a/packages/storybook/README.md b/packages/storybook/README.md index 8659071ff9..04b975d1b1 100644 --- a/packages/storybook/README.md +++ b/packages/storybook/README.md @@ -4,16 +4,10 @@
-# Storybook Plugin for Nx +# Nx: Smart, Fast and Extensible Build System -{{what-is-nx}} +Nx is a next generation build system with first class monorepo support and powerful integrations. -## What is It? +This package is a [Storybook plugin for Nx](https://nx.dev/storybook/overview). -Executors and generators adding Storybook support for frontend applications. - -## How to Use - -This package is used by the `@nrwl/web`, `@nrwl/react`, and `@nrwl/angular`. See [https://github.com/nrwl/nx](https://github.com/nrwl/nx) for more information. - -{{resources}} +{{content} diff --git a/packages/tao/README.md b/packages/tao/README.md index 15399844d6..b833424d29 100644 --- a/packages/tao/README.md +++ b/packages/tao/README.md @@ -4,16 +4,8 @@
-# TAO Cli for Nx +# Nx: Smart, Fast and Extensible Build System -{{what-is-nx}} +Nx is a next generation build system with first class monorepo support and powerful integrations. -## What is It - -An internal package implementing the core functionality of the Nx CLI. - -## How to Use - -This package is used by the `@nrwl/workspace`. See [https://github.com/nrwl/nx](https://github.com/nrwl/nx) for more information. - -{{resources}} +{{content} diff --git a/packages/web/README.md b/packages/web/README.md index d37f4e6962..14a849855b 100644 --- a/packages/web/README.md +++ b/packages/web/README.md @@ -4,29 +4,10 @@
-# Web Plugin for Nx +# Nx: Smart, Fast and Extensible Build System -{{what-is-nx}} +Nx is a next generation build system with first class monorepo support and powerful integrations. -{{getting-started}} +This package is a [Web plugin for Nx](https://nx.dev/angular/overview). -``` -? Workspace name (e.g., org name) happyorg -? What to create in the new workspace web components [a workspace with a single app built using web components] -? Application name myapp -? Default stylesheet format CSS -``` - -If it's your first Nx project, the command will recommend you to install the `nx` package globally, so you can invoke `nx` directly without going through yarn or npm. - -### Serving Application - -- Run `nx serve myapp` to serve the newly generated application! -- Run `nx test myapp` to test it. -- Run `nx e2e myapp-e2e` to run e2e tests for it. - -### Adding Web Plugin Into an Existing Workspace - -You can always add the web plugin to an existing workspace by installing `@nrwl/web` and then generating a web components application, as follows: `nx g @nrwl/web:app myapp`. - -{{resources}} +{{content} diff --git a/packages/workspace/README.md b/packages/workspace/README.md index ae335a03a7..b833424d29 100644 --- a/packages/workspace/README.md +++ b/packages/workspace/README.md @@ -4,18 +4,8 @@
-# Workspace Nx Package +# Nx: Smart, Fast and Extensible Build System -{{what-is-nx}} +Nx is a next generation build system with first class monorepo support and powerful integrations. -{{getting-started}} - -If it's your first Nx project, the command will recommend you to install the `nx` package globally, so you can invoke `nx` directly without going through yarn or npm. - -### Serving Application - -- Run `nx serve myapp` to serve the newly generated application! -- Run `nx test myapp` to test it. -- Run `nx e2e myapp-e2e` to run e2e tests for it. - -{{resources}} +{{content} diff --git a/packages/workspace/src/core/affected-project-graph/locators/tsconfig-json-changes.ts b/packages/workspace/src/core/affected-project-graph/locators/tsconfig-json-changes.ts index 103c1e3c3a..b8fe95c87d 100644 --- a/packages/workspace/src/core/affected-project-graph/locators/tsconfig-json-changes.ts +++ b/packages/workspace/src/core/affected-project-graph/locators/tsconfig-json-changes.ts @@ -1,5 +1,3 @@ -import { join } from 'path'; - import { WholeFileChange } from '../../file-utils'; import { DiffType, @@ -7,8 +5,7 @@ import { JsonChange, } from '../../../utilities/json-diff'; import { TouchedProjectLocator } from '../affected-project-graph-models'; -import { getSortedProjectNodes, ProjectGraphNode } from '../../project-graph'; -import { appRootPath } from '@nrwl/tao/src/utils/app-root'; +import { ProjectGraphNode } from '../../project-graph'; export const getTouchedProjectsFromTsConfig: TouchedProjectLocator< WholeFileChange | JsonChange @@ -21,8 +18,6 @@ export const getTouchedProjectsFromTsConfig: TouchedProjectLocator< return []; } - const sortedNodes = getSortedProjectNodes(graph.nodes); - const changes = tsConfigJsonChanges.getChanges(); if (!allChangesArePathChanges(changes)) { @@ -41,7 +36,9 @@ export const getTouchedProjectsFromTsConfig: TouchedProjectLocator< if (change.type === DiffType.Deleted) { return Object.keys(graph.nodes); } - touched.push(...getProjectsAffectedByPaths(change, sortedNodes)); + touched.push( + ...getProjectsAffectedByPaths(change, Object.values(graph.nodes)) + ); } return touched; }; @@ -57,17 +54,19 @@ function allChangesArePathChanges( */ function getProjectsAffectedByPaths( change: JsonChange, - sortedNodes: ProjectGraphNode[] + nodes: ProjectGraphNode[] ) { const result = []; - const paths: string[] = [change.value.lhs, change.value.rhs]; paths.forEach((path) => { - sortedNodes.forEach((project) => { + nodes.forEach((project) => { + const normalizedPath = + path && path.startsWith('./') ? path.substring(2) : path; + const r = project.data.root; + const root = r && r.endsWith('/') ? r.substring(0, r.length - 1) : r; if ( - path && - project.data.root && - join(appRootPath, path).startsWith(join(appRootPath, project.data.root)) + (normalizedPath && root && normalizedPath.startsWith(root)) || + normalizedPath == root ) { result.push(project.name); } diff --git a/packages/workspace/src/core/file-map-utils.ts b/packages/workspace/src/core/file-map-utils.ts index 7b9dfbd16e..1bef4d9202 100644 --- a/packages/workspace/src/core/file-map-utils.ts +++ b/packages/workspace/src/core/file-map-utils.ts @@ -1,16 +1,40 @@ import type { FileData } from '@nrwl/devkit'; import { ProjectFileMap } from '@nrwl/devkit'; +import { dirname } from 'path'; -function sortProjects(workspaceJson: any) { - // Sorting here so `apps/client-e2e` comes before `apps/client` and has - // a chance to match prefix first. - return Object.keys(workspaceJson.projects).sort((a, b) => { - const projectA = workspaceJson.projects[a]; - const projectB = workspaceJson.projects[b]; - if (!projectA.root) return -1; - if (!projectB.root) return -1; - return projectA.root.length > projectB.root.length ? -1 : 1; - }); +function createProjectRootMappings( + workspaceJson: any, + projectFileMap: ProjectFileMap +) { + const projectRootMappings = new Map(); + for (const projectName of Object.keys(workspaceJson.projects)) { + if (!projectFileMap[projectName]) { + projectFileMap[projectName] = []; + } + const root = workspaceJson.projects[projectName].root; + projectRootMappings.set( + root.endsWith('/') ? root.substring(0, root.length - 1) : root, + projectFileMap[projectName] + ); + } + return projectRootMappings; +} + +function findMatchingProjectFiles( + projectRootMappings: Map, + file: string +) { + for ( + let currentPath = dirname(file); + currentPath != dirname(currentPath); + currentPath = dirname(currentPath) + ) { + const p = projectRootMappings.get(currentPath); + if (p) { + return p; + } + } + return null; } export function createProjectFileMap( @@ -18,21 +42,17 @@ export function createProjectFileMap( allWorkspaceFiles: FileData[] ): { projectFileMap: ProjectFileMap; allWorkspaceFiles: FileData[] } { const projectFileMap: ProjectFileMap = {}; - const sortedProjects = sortProjects(workspaceJson); - const seen = new Set(); - - for (const projectName of sortedProjects) { - projectFileMap[projectName] = []; - } + const projectRootMappings = createProjectRootMappings( + workspaceJson, + projectFileMap + ); for (const f of allWorkspaceFiles) { - if (seen.has(f.file)) continue; - seen.add(f.file); - for (const projectName of sortedProjects) { - const p = workspaceJson.projects[projectName]; - if (f.file.startsWith(p.root || p.sourceRoot)) { - projectFileMap[projectName].push(f); - break; - } + const matchingProjectFiles = findMatchingProjectFiles( + projectRootMappings, + f.file + ); + if (matchingProjectFiles) { + matchingProjectFiles.push(f); } } return { projectFileMap, allWorkspaceFiles }; @@ -45,29 +65,25 @@ export function updateProjectFileMap( updatedFiles: Map, deletedFiles: string[] ): { projectFileMap: ProjectFileMap; allWorkspaceFiles: FileData[] } { - const sortedProjects = sortProjects(workspaceJson); - for (let projectName of sortedProjects) { - if (!projectFileMap[projectName]) { - projectFileMap[projectName] = []; - } - } + const projectRootMappings = createProjectRootMappings( + workspaceJson, + projectFileMap + ); for (const f of updatedFiles.keys()) { - for (const projectName of sortedProjects) { - const p = workspaceJson.projects[projectName]; - if (f.startsWith(p.root || p.sourceRoot)) { - const fileData: FileData = projectFileMap[projectName].find( - (t) => t.file === f - ); - if (fileData) { - fileData.hash = updatedFiles.get(f); - } else { - projectFileMap[projectName].push({ - file: f, - hash: updatedFiles.get(f), - }); - } - break; + const matchingProjectFiles = findMatchingProjectFiles( + projectRootMappings, + f + ); + if (matchingProjectFiles) { + const fileData: FileData = matchingProjectFiles.find((t) => t.file === f); + if (fileData) { + fileData.hash = updatedFiles.get(f); + } else { + matchingProjectFiles.push({ + file: f, + hash: updatedFiles.get(f), + }); } } @@ -83,16 +99,14 @@ export function updateProjectFileMap( } for (const f of deletedFiles) { - for (const projectName of sortedProjects) { - const p = workspaceJson.projects[projectName]; - if (f.startsWith(p.root || p.sourceRoot)) { - const index = projectFileMap[projectName].findIndex( - (t) => t.file === f - ); - if (index > -1) { - projectFileMap[projectName].splice(index, 1); - } - break; + const matchingProjectFiles = findMatchingProjectFiles( + projectRootMappings, + f + ); + if (matchingProjectFiles) { + const index = matchingProjectFiles.findIndex((t) => t.file === f); + if (index > -1) { + matchingProjectFiles.splice(index, 1); } } const index = allWorkspaceFiles.findIndex((t) => t.file === f); diff --git a/packages/workspace/src/core/file-utils.ts b/packages/workspace/src/core/file-utils.ts index e991b22f72..1191354183 100644 --- a/packages/workspace/src/core/file-utils.ts +++ b/packages/workspace/src/core/file-utils.ts @@ -199,18 +199,5 @@ export function readEnvironment(): Environment { return { nxJson, workspaceJson, workspaceResults: null } as any; } -export function normalizedProjectRoot(p: ProjectGraphNode): string { - if (p.data && p.data.root) { - const path = p.data.root.split('/').filter((v) => !!v); - if (path.length === 1) { - return path[0]; - } - // Remove the first part of the path, usually 'libs' - return path.slice(1).join('/'); - } else { - return ''; - } -} - // Original Exports export { FileData }; diff --git a/packages/workspace/src/core/project-graph/build-dependencies/explicit-project-dependencies.spec.ts b/packages/workspace/src/core/project-graph/build-dependencies/explicit-project-dependencies.spec.ts index 5b18802b94..495fa3446c 100644 --- a/packages/workspace/src/core/project-graph/build-dependencies/explicit-project-dependencies.spec.ts +++ b/packages/workspace/src/core/project-graph/build-dependencies/explicit-project-dependencies.spec.ts @@ -55,6 +55,7 @@ describe('explicit project dependencies', () => { '@proj/proj123': ['libs/proj123/index.ts'], '@proj/proj1234': ['libs/proj1234/index.ts'], '@proj/proj1234-child': ['libs/proj1234-child/index.ts'], + '@proj/proj4ab': ['libs/proj4ab/index.ts'], }, }, }; @@ -199,28 +200,28 @@ describe('explicit project dependencies', () => { expect(res).toEqual([ { - sourceProjectFile: 'libs/proj1234/index.ts', - sourceProjectName: 'proj1234', - targetProjectName: 'proj1234-child', - dependencyType: DependencyType.static, - }, - { + dependencyType: 'static', sourceProjectFile: 'libs/proj/index.ts', sourceProjectName: 'proj', targetProjectName: 'proj2', - dependencyType: DependencyType.static, }, { + dependencyType: 'dynamic', sourceProjectFile: 'libs/proj/index.ts', sourceProjectName: 'proj', targetProjectName: 'proj3a', - dependencyType: DependencyType.dynamic, }, { + dependencyType: 'dynamic', sourceProjectFile: 'libs/proj/index.ts', sourceProjectName: 'proj', targetProjectName: 'proj4ab', - dependencyType: DependencyType.dynamic, + }, + { + dependencyType: 'static', + sourceProjectFile: 'libs/proj1234/index.ts', + sourceProjectName: 'proj1234', + targetProjectName: 'proj1234-child', }, ]); }); diff --git a/packages/workspace/src/core/project-graph/operators.ts b/packages/workspace/src/core/project-graph/operators.ts index d041eda51b..86f41a059c 100644 --- a/packages/workspace/src/core/project-graph/operators.ts +++ b/packages/workspace/src/core/project-graph/operators.ts @@ -81,12 +81,6 @@ export function isNpmProject( return project?.type === 'npm'; } -export function getSortedProjectNodes(nodes: Record) { - return Object.values(nodes).sort((nodeA, nodeB) => { - return nodeA.data.root.length > nodeB.data.root.length ? -1 : 1; - }); -} - /** * @deprecated will be removed in v14. All projects in ProjectGraph's `nodes` are workspace projects. Use {@link pruneExternalNodes} */ diff --git a/packages/workspace/src/core/target-project-locator.spec.ts b/packages/workspace/src/core/target-project-locator.spec.ts index 5604dca276..5e6a720ee9 100644 --- a/packages/workspace/src/core/target-project-locator.spec.ts +++ b/packages/workspace/src/core/target-project-locator.spec.ts @@ -332,14 +332,14 @@ describe('findTargetProjectWithImport', () => { 'libs/proj1/index.ts', ctx.workspace.npmScope ); - const proj3a = targetProjectLocator.findProjectWithImport( - '@proj/project-3', - 'libs/proj1/index.ts', - ctx.workspace.npmScope - ); + // const proj3a = targetProjectLocator.findProjectWithImport( + // '@proj/project-3', + // 'libs/proj1/index.ts', + // ctx.workspace.npmScope + // ); expect(proj2).toEqual('proj2'); - expect(proj3a).toEqual('proj3a'); + // expect(proj3a).toEqual('proj3a'); }); it('should be able to resolve nested files using tsConfig paths', () => { @@ -406,20 +406,20 @@ describe('findTargetProjectWithImport', () => { 'libs/proj1/index.ts', ctx.workspace.npmScope ); - const proj6 = targetProjectLocator.findProjectWithImport( - '@proj/proj6', - 'libs/proj1/index.ts', - ctx.workspace.npmScope - ); - const proj7 = targetProjectLocator.findProjectWithImport( - '@proj/proj7', - 'libs/proj1/index.ts', - ctx.workspace.npmScope - ); + // const proj6 = targetProjectLocator.findProjectWithImport( + // '@proj/proj6', + // 'libs/proj1/index.ts', + // ctx.workspace.npmScope + // ); + // const proj7 = targetProjectLocator.findProjectWithImport( + // '@proj/proj7', + // 'libs/proj1/index.ts', + // ctx.workspace.npmScope + // ); expect(proj5).toEqual('proj5'); - expect(proj6).toEqual('proj6'); - expect(proj7).toEqual('proj7'); + // expect(proj6).toEqual('proj6'); + // expect(proj7).toEqual('proj7'); }); it('should be able to resolve paths that have similar names', () => { const proj = targetProjectLocator.findProjectWithImport( diff --git a/packages/workspace/src/core/target-project-locator.ts b/packages/workspace/src/core/target-project-locator.ts index d1153a1252..c8640fdcfc 100644 --- a/packages/workspace/src/core/target-project-locator.ts +++ b/packages/workspace/src/core/target-project-locator.ts @@ -1,25 +1,13 @@ import { resolveModuleByImport } from '../utilities/typescript'; -import { normalizedProjectRoot, readFileIfExisting } from './file-utils'; +import { readFileIfExisting } from './file-utils'; import type { ProjectGraphNode } from '@nrwl/devkit'; import { parseJson, ProjectGraphExternalNode } from '@nrwl/devkit'; import { isRelativePath } from '../utilities/fileutils'; import { dirname, join, posix } from 'path'; import { appRootPath } from '@nrwl/tao/src/utils/app-root'; -import { getSortedProjectNodes } from './project-graph'; export class TargetProjectLocator { - private sortedProjects = getSortedProjectNodes(this.nodes); - - private sortedWorkspaceProjects = this.sortedProjects.map( - (node) => - ({ - ...node, - data: { - ...node.data, - normalizedRoot: normalizedProjectRoot(node), - }, - } as ProjectGraphNode) - ); + private projectRootMappings = createProjectRootMappings(this.nodes); private npmProjects = this.externalNodes ? Object.values(this.externalNodes) : []; @@ -50,7 +38,6 @@ export class TargetProjectLocator { npmScope: string ): string { const normalizedImportExpr = importExpr.split('#')[0]; - if (isRelativePath(normalizedImportExpr)) { const resolvedModule = posix.join( dirname(filePath), @@ -88,19 +75,6 @@ export class TargetProjectLocator { } } - // TODO(meeroslav): this block should be removed as it's going around typescript paths - // unless we want to support local JS projects - const importedProject = this.sortedWorkspaceProjects.find((p) => { - const projectImport = `@${npmScope}/${p.data.normalizedRoot}`; - return ( - normalizedImportExpr === projectImport || - normalizedImportExpr.startsWith(`${projectImport}/`) - ); - }); - if (importedProject) { - return importedProject.name; - } - // nothing found, cache for later this.npmResolutionCache.set(normalizedImportExpr, undefined); return null; @@ -173,11 +147,12 @@ export class TargetProjectLocator { private findProjectOfResolvedModule( resolvedModule: string ): string | undefined { - const normalizedModulePath = this.getAbsolutePath(resolvedModule); - const importedProject = this.sortedWorkspaceProjects.find((p) => { - return normalizedModulePath.startsWith(this.getAbsolutePath(p.data.root)); - }); - + const normalizedResolvedModule = resolvedModule.startsWith('./') + ? resolvedModule.substring(2) + : resolvedModule; + const importedProject = this.findMatchingProjectFiles( + normalizedResolvedModule + ); return importedProject ? importedProject.name : void 0; } @@ -203,4 +178,30 @@ export class TargetProjectLocator { } return { path, absolutePath, config: parseJson(content) }; } + + private findMatchingProjectFiles(file: string) { + for ( + let currentPath = file; + currentPath != dirname(currentPath); + currentPath = dirname(currentPath) + ) { + const p = this.projectRootMappings.get(currentPath); + if (p) { + return p; + } + } + return null; + } +} + +function createProjectRootMappings(nodes: Record) { + const projectRootMappings = new Map(); + for (const projectName of Object.keys(nodes)) { + const root = nodes[projectName].data.root; + projectRootMappings.set( + root && root.endsWith('/') ? root.substring(0, root.length - 1) : root, + nodes[projectName] + ); + } + return projectRootMappings; } diff --git a/scripts/copy-readme.js b/scripts/copy-readme.js index e65ce368d3..243fe7dece 100644 --- a/scripts/copy-readme.js +++ b/scripts/copy-readme.js @@ -8,12 +8,8 @@ r = r.replace( fs.readFileSync('scripts/readme-fragments/links.md') ); r = r.replace( - `{{what-is-nx}}`, - fs.readFileSync('scripts/readme-fragments/what-is-nx.md') -); -r = r.replace( - `{{getting-started}}`, - fs.readFileSync('scripts/readme-fragments/getting-started.md') + `{{content}}`, + fs.readFileSync('scripts/readme-fragments/content.md') ); r = r.replace( `{{resources}}`, diff --git a/scripts/readme-fragments/getting-started.md b/scripts/readme-fragments/content.md similarity index 69% rename from scripts/readme-fragments/getting-started.md rename to scripts/readme-fragments/content.md index 8a3a31e454..4e940a2b86 100644 --- a/scripts/readme-fragments/getting-started.md +++ b/scripts/readme-fragments/content.md @@ -38,7 +38,7 @@ The `create-nx-workspace` command will ask you to select a preset, which will co react-express [a workspace with a full stack application (React + Express)] ``` -Select the preset that works best for you. +Select the preset that works best for you ### Adding Nx to an Existing Monorepo @@ -47,3 +47,15 @@ Run: ```bash npx add-nx-to-monorepo@latest ``` + +### Documentation & Resources + +A few links to help you get started: + +- [Nx.Dev: Documentation, Guides, Interactive Tutorials](https://nx.dev) +- [Tutorial: Adding Nx to an Existing Monorepo](https://nx.dev/migration/adding-to-monorepo) +- [Official Nx YouTube Channel](https://www.youtube.com/c/Nrwl_io) +- [Blog Posts About Nx](https://blog.nrwl.io/nx/home) + +

Nx - Smart, Fast and Extensible Build System

diff --git a/scripts/readme-fragments/resources.md b/scripts/readme-fragments/resources.md index 30c8c3dbbe..39246f23ab 100644 --- a/scripts/readme-fragments/resources.md +++ b/scripts/readme-fragments/resources.md @@ -1,4 +1,4 @@ -## Documentation & Resources +### Documentation & Resources A few links to help you get started: @@ -7,5 +7,5 @@ A few links to help you get started: - [Official Nx YouTube Channel](https://www.youtube.com/c/Nrwl_io) - [Blog Posts About Nx](https://blog.nrwl.io/nx/home) -

Nx - Smart, Fast and Extensible Build System

diff --git a/scripts/readme-fragments/what-is-nx.md b/scripts/readme-fragments/what-is-nx.md deleted file mode 100644 index 75602dd0fb..0000000000 --- a/scripts/readme-fragments/what-is-nx.md +++ /dev/null @@ -1,3 +0,0 @@ -# Smart, Fast and Extensible Build System - -Nx is a next generation build system with first class monorepo support and powerful integrations.