Comparing version 0.0.0-pr-27652-161cc40 to 0.0.0-pr-27652-1746961
{ | ||
"name": "nx", | ||
"version": "0.0.0-pr-27652-161cc40", | ||
"version": "0.0.0-pr-27652-1746961", | ||
"private": false, | ||
@@ -74,3 +74,3 @@ "description": "The core Nx plugin contains the core functionality of Nx like the project graph, nx commands and task orchestration.", | ||
"ora": "5.3.0", | ||
"@nrwl/tao": "0.0.0-pr-27652-161cc40" | ||
"@nrwl/tao": "0.0.0-pr-27652-1746961" | ||
}, | ||
@@ -90,12 +90,12 @@ "peerDependencies": { | ||
"optionalDependencies": { | ||
"@nx/nx-darwin-x64": "0.0.0-pr-27652-161cc40", | ||
"@nx/nx-darwin-arm64": "0.0.0-pr-27652-161cc40", | ||
"@nx/nx-linux-x64-gnu": "0.0.0-pr-27652-161cc40", | ||
"@nx/nx-linux-x64-musl": "0.0.0-pr-27652-161cc40", | ||
"@nx/nx-win32-x64-msvc": "0.0.0-pr-27652-161cc40", | ||
"@nx/nx-linux-arm64-gnu": "0.0.0-pr-27652-161cc40", | ||
"@nx/nx-linux-arm64-musl": "0.0.0-pr-27652-161cc40", | ||
"@nx/nx-linux-arm-gnueabihf": "0.0.0-pr-27652-161cc40", | ||
"@nx/nx-win32-arm64-msvc": "0.0.0-pr-27652-161cc40", | ||
"@nx/nx-freebsd-x64": "0.0.0-pr-27652-161cc40" | ||
"@nx/nx-darwin-x64": "0.0.0-pr-27652-1746961", | ||
"@nx/nx-darwin-arm64": "0.0.0-pr-27652-1746961", | ||
"@nx/nx-linux-x64-gnu": "0.0.0-pr-27652-1746961", | ||
"@nx/nx-linux-x64-musl": "0.0.0-pr-27652-1746961", | ||
"@nx/nx-win32-x64-msvc": "0.0.0-pr-27652-1746961", | ||
"@nx/nx-linux-arm64-gnu": "0.0.0-pr-27652-1746961", | ||
"@nx/nx-linux-arm64-musl": "0.0.0-pr-27652-1746961", | ||
"@nx/nx-linux-arm-gnueabihf": "0.0.0-pr-27652-1746961", | ||
"@nx/nx-win32-arm64-msvc": "0.0.0-pr-27652-1746961", | ||
"@nx/nx-freebsd-x64": "0.0.0-pr-27652-1746961" | ||
}, | ||
@@ -102,0 +102,0 @@ "nx-migrations": { |
@@ -5,2 +5,6 @@ "use strict"; | ||
const path_1 = require("path"); | ||
const minimatch_1 = require("minimatch"); | ||
const node_fs_1 = require("node:fs"); | ||
const chalk = require("chalk"); | ||
const js_yaml_1 = require("@zkochan/js-yaml"); | ||
const git_utils_1 = require("../../utils/git-utils"); | ||
@@ -22,2 +26,3 @@ const promises_1 = require("node:fs/promises"); | ||
const needs_install_1 = require("./utils/needs-install"); | ||
const file_utils_1 = require("../../project-graph/file-utils"); | ||
const importRemoteName = '__tmp_nx_import__'; | ||
@@ -59,3 +64,3 @@ async function importHandler(options) { | ||
const sourceRepoPath = (0, path_1.join)(tempImportDirectory, 'repo'); | ||
const spinner = createSpinner(`Cloning ${sourceRemoteUrl} into a temporary directory: ${sourceRepoPath} (Hint: use --depth to limit the clone depth for faster clone times)`).start(); | ||
const spinner = createSpinner(`Cloning ${sourceRemoteUrl} into a temporary directory: ${sourceRepoPath} (Use --depth to limit commit history and speed up clone times)`).start(); | ||
try { | ||
@@ -79,2 +84,4 @@ await (0, promises_1.rm)(tempImportDirectory, { recursive: true }); | ||
spinner.succeed(`Cloned into ${sourceRepoPath}`); | ||
// Detecting the package manager before preparing the source repo for import. | ||
const sourcePackageManager = (0, package_manager_1.detectPackageManager)(sourceGitClient.root); | ||
if (!ref) { | ||
@@ -118,2 +125,14 @@ const branchChoices = await sourceGitClient.listBranches(); | ||
const absDestination = (0, path_1.join)(process.cwd(), destination); | ||
const destinationGitClient = new git_utils_1.GitRepository(process.cwd()); | ||
await assertDestinationEmpty(destinationGitClient, absDestination); | ||
const tempImportBranch = getTempImportBranch(ref); | ||
await sourceGitClient.addFetchRemote(importRemoteName, ref); | ||
await sourceGitClient.fetch(importRemoteName, ref); | ||
spinner.succeed(`Fetched ${ref} from ${sourceRemoteUrl}`); | ||
spinner.start(`Checking out a temporary branch, ${tempImportBranch} based on ${ref}`); | ||
await sourceGitClient.checkout(tempImportBranch, { | ||
new: true, | ||
base: `${importRemoteName}/${ref}`, | ||
}); | ||
spinner.succeed(`Created a ${tempImportBranch} branch based on ${ref}`); | ||
try { | ||
@@ -125,9 +144,6 @@ await (0, promises_1.stat)(absSource); | ||
} | ||
const destinationGitClient = new git_utils_1.GitRepository(process.cwd()); | ||
await assertDestinationEmpty(destinationGitClient, absDestination); | ||
const tempImportBranch = getTempImportBranch(ref); | ||
const packageManager = (0, package_manager_1.detectPackageManager)(workspace_root_1.workspaceRoot); | ||
const originalPackageWorkspaces = await (0, needs_install_1.getPackagesInPackageManagerWorkspace)(packageManager); | ||
const relativeDestination = (0, path_1.relative)(destinationGitClient.root, absDestination); | ||
await (0, prepare_source_repo_1.prepareSourceRepo)(sourceGitClient, ref, source, relativeDestination, tempImportBranch, sourceRemoteUrl, importRemoteName); | ||
await (0, prepare_source_repo_1.prepareSourceRepo)(sourceGitClient, ref, source, relativeDestination, tempImportBranch, sourceRemoteUrl); | ||
await createTemporaryRemote(destinationGitClient, (0, path_1.join)(sourceRepoPath, '.git'), importRemoteName); | ||
@@ -143,15 +159,54 @@ await (0, merge_remote_source_1.mergeRemoteSource)(destinationGitClient, sourceRemoteUrl, tempImportBranch, destination, importRemoteName, ref); | ||
const { plugins, updatePackageScripts } = await (0, init_v2_1.detectPlugins)(nxJson, options.interactive); | ||
if (packageManager !== sourcePackageManager) { | ||
output_1.output.warn({ | ||
title: `Mismatched package managers`, | ||
bodyLines: [ | ||
`The source repository is using a different package manager (${sourcePackageManager}) than this workspace (${packageManager}).`, | ||
`This could lead to install issues due to discrepancies in "package.json" features.`, | ||
], | ||
}); | ||
} | ||
// If install fails, we should continue since the errors could be resolved later. | ||
let installFailed = false; | ||
if (plugins.length > 0) { | ||
output_1.output.log({ title: 'Installing Plugins' }); | ||
(0, init_v2_1.installPlugins)(workspace_root_1.workspaceRoot, plugins, pmc, updatePackageScripts); | ||
await destinationGitClient.amendCommit(); | ||
try { | ||
output_1.output.log({ title: 'Installing Plugins' }); | ||
(0, init_v2_1.installPlugins)(workspace_root_1.workspaceRoot, plugins, pmc, updatePackageScripts); | ||
await destinationGitClient.amendCommit(); | ||
} | ||
catch (e) { | ||
installFailed = true; | ||
output_1.output.error({ | ||
title: `Install failed: ${e.message || 'Unknown error'}`, | ||
bodyLines: [e.stack], | ||
}); | ||
} | ||
} | ||
else if (await (0, needs_install_1.needsInstall)(packageManager, originalPackageWorkspaces)) { | ||
output_1.output.log({ | ||
title: 'Installing dependencies for imported code', | ||
try { | ||
output_1.output.log({ | ||
title: 'Installing dependencies for imported code', | ||
}); | ||
(0, utils_1.runInstall)(workspace_root_1.workspaceRoot, (0, package_manager_1.getPackageManagerCommand)(packageManager)); | ||
await destinationGitClient.amendCommit(); | ||
} | ||
catch (e) { | ||
installFailed = true; | ||
output_1.output.error({ | ||
title: `Install failed: ${e.message || 'Unknown error'}`, | ||
bodyLines: [e.stack], | ||
}); | ||
} | ||
} | ||
console.log(await destinationGitClient.showStat()); | ||
if (installFailed) { | ||
const pmc = (0, package_manager_1.getPackageManagerCommand)(packageManager); | ||
output_1.output.warn({ | ||
title: `The import was successful, but the install failed`, | ||
bodyLines: [ | ||
`You may need to run "${pmc.install}" manually to resolve the issue. The error is logged above.`, | ||
], | ||
}); | ||
(0, utils_1.runInstall)(workspace_root_1.workspaceRoot, (0, package_manager_1.getPackageManagerCommand)(packageManager)); | ||
await destinationGitClient.amendCommit(); | ||
} | ||
console.log(await destinationGitClient.showStat()); | ||
await warnOnMissingWorkspacesEntry(packageManager, pmc, relativeDestination); | ||
output_1.output.log({ | ||
@@ -183,1 +238,62 @@ title: `Merging these changes into ${(0, command_line_utils_1.getBaseRef)(nxJson)}`, | ||
} | ||
// If the user imports a project that isn't in NPM/Yarn/PNPM workspaces, then its dependencies | ||
// will not be installed. We should warn users and provide instructions on how to fix this. | ||
async function warnOnMissingWorkspacesEntry(pm, pmc, pkgPath) { | ||
if (!(0, package_manager_1.isWorkspacesEnabled)(pm, workspace_root_1.workspaceRoot)) { | ||
output_1.output.warn({ | ||
title: `Missing workspaces in package.json`, | ||
bodyLines: pm === 'npm' | ||
? [ | ||
`We recommend enabling NPM workspaces to install dependencies for the imported project.`, | ||
`Add \`"workspaces": ["${pkgPath}"]\` to package.json and run "${pmc.install}".`, | ||
`See: https://docs.npmjs.com/cli/using-npm/workspaces`, | ||
] | ||
: pm === 'yarn' | ||
? [ | ||
`We recommend enabling Yarn workspaces to install dependencies for the imported project.`, | ||
`Add \`"workspaces": ["${pkgPath}"]\` to package.json and run "${pmc.install}".`, | ||
`See: https://yarnpkg.com/features/workspaces`, | ||
] | ||
: [ | ||
`We recommend enabling PNPM workspaces to install dependencies for the imported project.`, | ||
`Add the following entry to to pnpm-workspace.yaml and run "${pmc.install}":`, | ||
chalk.bold(`packages:\n - '${pkgPath}'`), | ||
`See: https://pnpm.io/workspaces`, | ||
], | ||
}); | ||
} | ||
else { | ||
// Check if the new package is included in existing workspaces entries. If not, warn the user. | ||
let workspaces = null; | ||
if (pm === 'npm' || pm === 'yarn') { | ||
const packageJson = (0, file_utils_1.readPackageJson)(); | ||
workspaces = packageJson.workspaces; | ||
} | ||
else if (pm === 'pnpm') { | ||
const yamlPath = (0, path_1.join)(workspace_root_1.workspaceRoot, 'pnpm-workspace.yaml'); | ||
if ((0, node_fs_1.existsSync)(yamlPath)) { | ||
const yamlContent = await node_fs_1.promises.readFile('utf-8'); | ||
const yaml = (0, js_yaml_1.load)(yamlContent); | ||
workspaces = yaml.packages; | ||
} | ||
} | ||
if (workspaces) { | ||
const isPkgIncluded = workspaces.some((w) => (0, minimatch_1.minimatch)(pkgPath, w)); | ||
if (!isPkgIncluded) { | ||
const pkgsDir = (0, path_1.dirname)(pkgPath); | ||
output_1.output.warn({ | ||
title: `Project missing in workspaces`, | ||
bodyLines: pm === 'npm' || pm === 'yarn' | ||
? [ | ||
`The imported project (${pkgPath}) is missing the "workspaces" field in package.json.`, | ||
`Add "${pkgsDir}/*" to workspaces run "${pmc.install}".`, | ||
] | ||
: [ | ||
`The imported project (${pkgPath}) is missing the "packages" field in pnpm-workspaces.yaml.`, | ||
`Add "${pkgsDir}/*" to packages run "${pmc.install}".`, | ||
], | ||
}); | ||
} | ||
} | ||
} | ||
} |
import { GitRepository } from '../../../utils/git-utils'; | ||
export declare function prepareSourceRepo(gitClient: GitRepository, ref: string, source: string, relativeDestination: string, tempImportBranch: string, sourceRemoteUrl: string, originName: string): Promise<void>; | ||
export declare function prepareSourceRepo(gitClient: GitRepository, ref: string, source: string, relativeDestination: string, tempImportBranch: string, sourceRemoteUrl: string): Promise<void>; |
@@ -7,13 +7,4 @@ "use strict"; | ||
const promises_1 = require("node:fs/promises"); | ||
async function prepareSourceRepo(gitClient, ref, source, relativeDestination, tempImportBranch, sourceRemoteUrl, originName) { | ||
async function prepareSourceRepo(gitClient, ref, source, relativeDestination, tempImportBranch, sourceRemoteUrl) { | ||
const spinner = createSpinner().start(`Fetching ${ref} from ${sourceRemoteUrl}`); | ||
await gitClient.addFetchRemote(originName, ref); | ||
await gitClient.fetch(originName, ref); | ||
spinner.succeed(`Fetched ${ref} from ${sourceRemoteUrl}`); | ||
spinner.start(`Checking out a temporary branch, ${tempImportBranch} based on ${ref}`); | ||
await gitClient.checkout(tempImportBranch, { | ||
new: true, | ||
base: `${originName}/${ref}`, | ||
}); | ||
spinner.succeed(`Created a ${tempImportBranch} branch based on ${ref}`); | ||
const relativeSourceDir = (0, path_1.relative)(gitClient.root, (0, path_1.join)(gitClient.root, source)); | ||
@@ -42,8 +33,3 @@ if (relativeSourceDir !== '') { | ||
await (0, promises_1.mkdir)(destinationInSource, { recursive: true }); | ||
const gitignores = new Set(); | ||
for (const file of files) { | ||
if ((0, path_1.basename)(file) === '.gitignore') { | ||
gitignores.add(file); | ||
continue; | ||
} | ||
spinner.start(`Moving files and git history to ${destinationInSource}: ${file}`); | ||
@@ -61,9 +47,3 @@ const newPath = (0, path_1.join)(destinationInSource, file); | ||
await gitClient.commit(`chore(repo): move ${source} to ${relativeDestination} to prepare to be imported`); | ||
for (const gitignore of gitignores) { | ||
await gitClient.move(gitignore, (0, path_1.join)(destinationInSource, gitignore)); | ||
} | ||
await gitClient.amendCommit(); | ||
for (const gitignore of gitignores) { | ||
await (0, promises_1.copyFile)((0, path_1.join)(destinationInSource, gitignore), (0, path_1.join)(gitClient.root, gitignore)); | ||
} | ||
spinner.succeed(`${sourceRemoteUrl} has been prepared to be imported into this workspace on a temporary branch: ${tempImportBranch} in ${gitClient.root}`); | ||
@@ -70,0 +50,0 @@ } |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9177896
52052
+ Added@nrwl/tao@0.0.0-pr-27652-1746961(transitive)
+ Added@nx/nx-darwin-arm64@0.0.0-pr-27652-1746961(transitive)
+ Added@nx/nx-darwin-x64@0.0.0-pr-27652-1746961(transitive)
+ Added@nx/nx-freebsd-x64@0.0.0-pr-27652-1746961(transitive)
+ Added@nx/nx-linux-arm-gnueabihf@0.0.0-pr-27652-1746961(transitive)
+ Added@nx/nx-linux-arm64-gnu@0.0.0-pr-27652-1746961(transitive)
+ Added@nx/nx-linux-arm64-musl@0.0.0-pr-27652-1746961(transitive)
+ Added@nx/nx-linux-x64-gnu@0.0.0-pr-27652-1746961(transitive)
+ Added@nx/nx-linux-x64-musl@0.0.0-pr-27652-1746961(transitive)
+ Added@nx/nx-win32-arm64-msvc@0.0.0-pr-27652-1746961(transitive)
+ Added@nx/nx-win32-x64-msvc@0.0.0-pr-27652-1746961(transitive)
- Removed@nrwl/tao@0.0.0-pr-27652-161cc40(transitive)
- Removed@nx/nx-darwin-arm64@0.0.0-pr-27652-161cc40(transitive)
- Removed@nx/nx-darwin-x64@0.0.0-pr-27652-161cc40(transitive)
- Removed@nx/nx-freebsd-x64@0.0.0-pr-27652-161cc40(transitive)
- Removed@nx/nx-linux-arm-gnueabihf@0.0.0-pr-27652-161cc40(transitive)
- Removed@nx/nx-linux-arm64-gnu@0.0.0-pr-27652-161cc40(transitive)
- Removed@nx/nx-linux-arm64-musl@0.0.0-pr-27652-161cc40(transitive)
- Removed@nx/nx-linux-x64-gnu@0.0.0-pr-27652-161cc40(transitive)
- Removed@nx/nx-linux-x64-musl@0.0.0-pr-27652-161cc40(transitive)
- Removed@nx/nx-win32-arm64-msvc@0.0.0-pr-27652-161cc40(transitive)
- Removed@nx/nx-win32-x64-msvc@0.0.0-pr-27652-161cc40(transitive)