Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): import warns when source and destination directories are different #27875

Merged
merged 1 commit into from
Sep 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion packages/nx/src/command-line/import/import.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { dirname, join, relative, resolve } from 'path';
import { dirname, isAbsolute, join, relative, resolve } from 'path';
import { minimatch } from 'minimatch';
import { existsSync, promises as fsp } from 'node:fs';
import * as chalk from 'chalk';
Expand Down Expand Up @@ -177,6 +177,13 @@ export async function importHandler(options: ImportOptions) {
}

const absSource = join(sourceTempRepoPath, source);

if (isAbsolute(destination)) {
throw new Error(
`The destination directory must be a relative path in this repository.`
);
}

const absDestination = join(process.cwd(), destination);

const destinationGitClient = new GitRepository(process.cwd());
Expand Down Expand Up @@ -210,6 +217,8 @@ export async function importHandler(options: ImportOptions) {
packageManager
);

const sourceIsNxWorkspace = existsSync(join(sourceGitClient.root, 'nx.json'));

const relativeDestination = relative(
destinationGitClient.root,
absDestination
Expand Down Expand Up @@ -310,6 +319,19 @@ export async function importHandler(options: ImportOptions) {

await warnOnMissingWorkspacesEntry(packageManager, pmc, relativeDestination);

if (source != destination) {
output.warn({
title: `Check configuration files`,
bodyLines: [
`The source directory (${source}) and destination directory (${destination}) are different.`,
`You may need to update configuration files to match the directory in this repository.`,
sourceIsNxWorkspace
? `For example, path options in project.json such as "main", "tsConfig", and "outputPath" need to be updated.`
: `For example, relative paths in tsconfig.json and other tooling configuration files may need to be updated.`,
],
});
}

// When only a subdirectory is imported, there might be devDependencies in the root package.json file
// that needs to be ported over as well.
if (ref) {
Expand Down