-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(core): import documentation (#27859)
Create an import project recipe Creates the import command API reference Adds the import command to the command landing page
- Loading branch information
1 parent
4517d9f
commit 514ce17
Showing
12 changed files
with
271 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
--- | ||
title: 'import - CLI command' | ||
description: 'Import code and git history from another repository into this repository.' | ||
--- | ||
|
||
# import | ||
|
||
Import code and git history from another repository into this repository. | ||
|
||
## Usage | ||
|
||
```shell | ||
nx import [sourceRepository] [destinationDirectory] | ||
``` | ||
|
||
Install `nx` globally to invoke the command directly using `nx`, or use `npx nx`, `yarn nx`, or `pnpm nx`. | ||
|
||
## Options | ||
|
||
| Option | Type | Description | | ||
| ------------------------ | ------- | --------------------------------------------------------------------------- | | ||
| `--depth` | number | The depth to clone the source repository (limit this for faster git clone). | | ||
| `--destinationDirectory` | string | The directory in the current workspace to import into. | | ||
| `--help` | boolean | Show help. | | ||
| `--interactive` | boolean | Interactive mode. (Default: `true`) | | ||
| `--ref` | string | The branch from the source repository to import. | | ||
| `--sourceDirectory` | string | The directory in the source repository to import from. | | ||
| `--sourceRepository` | string | The remote URL of the source to import. | | ||
| `--verbose` | boolean | Prints additional information about the commands (e.g., stack traces). | | ||
| `--version` | boolean | Show version number. | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
--- | ||
title: 'import - CLI command' | ||
description: 'Import code and git history from another repository into this repository.' | ||
--- | ||
|
||
# import | ||
|
||
Import code and git history from another repository into this repository. | ||
|
||
## Usage | ||
|
||
```shell | ||
nx import [sourceRepository] [destinationDirectory] | ||
``` | ||
|
||
Install `nx` globally to invoke the command directly using `nx`, or use `npx nx`, `yarn nx`, or `pnpm nx`. | ||
|
||
## Options | ||
|
||
| Option | Type | Description | | ||
| ------------------------ | ------- | --------------------------------------------------------------------------- | | ||
| `--depth` | number | The depth to clone the source repository (limit this for faster git clone). | | ||
| `--destinationDirectory` | string | The directory in the current workspace to import into. | | ||
| `--help` | boolean | Show help. | | ||
| `--interactive` | boolean | Interactive mode. (Default: `true`) | | ||
| `--ref` | string | The branch from the source repository to import. | | ||
| `--sourceDirectory` | string | The directory in the source repository to import from. | | ||
| `--sourceRepository` | string | The remote URL of the source to import. | | ||
| `--verbose` | boolean | Prints additional information about the commands (e.g., stack traces). | | ||
| `--version` | boolean | Show version number. | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
# Import an Existing Project into an Nx Workspace | ||
|
||
Nx can help with the process of moving an existing project from another repository into an Nx workspace. In order to communicate clearly about this process, we'll call the repository we're moving the project out of the "source repository" and the repository we're moving the project into the "destination repository". Here's an example of what those repositories might look like. | ||
|
||
{% side-by-side %} | ||
|
||
```{% fileName="Source Repository" %} | ||
└─ inventory-app | ||
├─ ... | ||
├─ public | ||
│ └─ ... | ||
├─ src | ||
│ ├─ assets | ||
│ ├─ App.css | ||
│ ├─ App.tsx | ||
│ ├─ index.css | ||
│ └─ main.tsx | ||
├─ .eslintrc.cjs | ||
├─ index.html | ||
├─ package.json | ||
├─ README.md | ||
├─ tsconfig.json | ||
├─ tsconfig.node.json | ||
└─ vite.config.ts | ||
``` | ||
|
||
```{% fileName="Destination Repository" %} | ||
└─ myorg | ||
├─ ... | ||
├─ packages | ||
│ └─ ... | ||
├─ apps | ||
│ ├─ account | ||
│ │ └─ ... | ||
│ ├─ cart | ||
│ │ └─ ... | ||
│ └─ users | ||
│ └─ ... | ||
├─ .eslintrc.json | ||
├─ .gitignore | ||
├─ nx.json | ||
├─ package.json | ||
├─ README.md | ||
└─ tsconfig.base.json | ||
``` | ||
|
||
{% /side-by-side %} | ||
|
||
In this example, the source repository contains a single application while the destination repository is already a monorepo. You can also import a project from a sub-directory of the source repository (if the source repository is a monorepo, for instance). The `nx import` command can be run with no arguments and you will be prompted to for the required arguments: | ||
|
||
```shell | ||
nx import | ||
``` | ||
|
||
Make sure to run `nx import` from within the **destination repository**. | ||
|
||
You can also directly specify arguments from the terminal, like one of these commands: | ||
|
||
```shell {% path="~/myorg" %} | ||
nx import [sourceRepository] [destinationDirectory] | ||
nx import ../inventory-app apps/inventory | ||
nx import https://github.com/myorg/inventory-app.git apps/inventory | ||
``` | ||
|
||
{% callout type="note" title="Source Repository Local or Remote" %} | ||
The sourceRepository argument for `nx import` can be either a local file path to the source git repository on your local machine or a git URL to the hosted git repository. | ||
{% /callout %} | ||
|
||
The `nx import` command will: | ||
|
||
- Maintain the git history from the source repository | ||
- Suggest adding plugins to the destination repository based on the newly added project code | ||
|
||
Every code base is different, so you will still need to manually: | ||
|
||
- Manage any dependency conflicts between the two code bases | ||
- Migrate over code outside the source project's root folder that the source project depends on | ||
|
||
## Manage Dependencies | ||
|
||
If both repositories are managed with npm workspaces, the imported project will have all its required dependencies defined in its `package.json` file that is moved over. You'll need to make sure that the destination repository includes the `destinationDirectory` in the `workspaces` defined in the root `package.json`. | ||
|
||
If the destination repository does not use npm workspaces, it will ease the import process to temporarily enable it. With npm workspaces enabled, you can easily import a self-contained project and gain the benefits of code sharing, atomic commits and shared infrastructure. Once the import process is complete, you can make a follow-up PR that merges the dependencies into the root `package.json` and disables npm workspaces again. | ||
|
||
## Migrate External Code and Configuration | ||
|
||
Few projects are completely isolated from the rest of the repository where they are located. After `nx import` has run, here are a few types of external code references that you should account for: | ||
|
||
- Project configuration files that extend root configuration files | ||
- Scripts outside the project folder that are required by the project | ||
- Local project dependencies that are not present or have a different name in the destination repository | ||
|
||
{% callout type="note" title="Importing Multiple Projects" %} | ||
If multiple projects need to be imported into the destination repository, try to import as many of the projects together as possible. If projects need to be imported with separate `nx import` commands, start with the leaf projects in the dependency graph (the projects without any dependencies) and then work your way up to the top level applications. This way every project that is imported into the destination repository will have its required dependencies available. | ||
{% /callout %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters