Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix(core): generator prompt should not throw in encapsulated mode (#1…
  • Loading branch information
AgentEnder committed Feb 22, 2023
1 parent 23de5b7 commit 902f644
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 22 deletions.
1 change: 1 addition & 0 deletions nx.json
Expand Up @@ -15,6 +15,7 @@
"build-base",
"build-native",
"e2e",
"e2e-macos",
"test",
"test-native",
"sitemap",
Expand Down
7 changes: 2 additions & 5 deletions packages/nx/bin/nx.ts
Expand Up @@ -5,9 +5,8 @@ import {
} from '../src/utils/find-workspace-root';
import * as chalk from 'chalk';
import { initLocal } from './init-local';
import { detectPackageManager } from '../src/utils/package-manager';
import { output } from '../src/utils/output';
import { join } from 'path';
import { getNxInstallationPath } from 'nx/src/utils/installation-directory';

const workspace = findWorkspaceRoot(process.cwd());
// new is a special case because there is no local workspace to load
Expand Down Expand Up @@ -74,9 +73,7 @@ function resolveNx(workspace: WorkspaceTypeAndRoot | null) {
// prefer Nx installed in .nx/installation
try {
return require.resolve('nx/bin/nx.js', {
paths: workspace
? [join(workspace.dir, '.nx', 'installation')]
: undefined,
paths: workspace ? [getNxInstallationPath(workspace.dir)] : undefined,
});
} catch {}

Expand Down
7 changes: 2 additions & 5 deletions packages/nx/src/command-line/report.ts
Expand Up @@ -19,8 +19,8 @@ import {
readProjectsConfigurationFromProjectGraph,
} from '../project-graph/project-graph';
import { gt, valid } from 'semver';
import { NxJsonConfiguration } from '../config/nx-json';
import { findInstalledPlugins } from '../utils/plugins/installed-plugins';
import { getNxRequirePaths } from '../utils/installation-directory';

const nxPackageJson = readJsonFile<typeof import('../../package.json')>(
join(__dirname, '../../package.json')
Expand Down Expand Up @@ -190,10 +190,7 @@ async function findLocalPlugins() {

function readPackageJson(p: string): PackageJson | null {
try {
return readModulePackageJson(p, [
workspaceRoot,
join(workspaceRoot, '.nx', 'installation'),
]).packageJson;
return readModulePackageJson(p, getNxRequirePaths()).packageJson;
} catch {
return null;
}
Expand Down
7 changes: 2 additions & 5 deletions packages/nx/src/config/workspaces.ts
Expand Up @@ -38,6 +38,7 @@ import {
mergeAngularJsonAndGlobProjects,
shouldMergeAngularProjects,
} from '../adapter/angular-json';
import { getNxRequirePaths } from '../utils/installation-directory';

export class Workspaces {
private cachedProjectsConfig: ProjectsConfigurations;
Expand Down Expand Up @@ -598,11 +599,7 @@ export function globForProjectFiles(

if (!ignorePluginInference) {
projectGlobPatterns.push(
...getGlobPatternsFromPlugins(
nxJson,
[root, join(root, '.nx', 'installation')],
root
)
...getGlobPatternsFromPlugins(nxJson, getNxRequirePaths(root), root)
);
}

Expand Down
Expand Up @@ -11,14 +11,14 @@ import {
getGlobPatternsFromPlugins,
} from '../../../config/workspaces';
import { workspaceRoot } from '../../../utils/workspace-root';
import { join } from 'path';
import { getNxRequirePaths } from 'nx/src/utils/installation-directory';

export const getTouchedProjectsFromProjectGlobChanges: TouchedProjectLocator<
WholeFileChange | JsonChange | DeletedFileChange
> = (touchedFiles, projectGraphNodes, nxJson): string[] => {
const pluginGlobPatterns = getGlobPatternsFromPlugins(
nxJson,
[workspaceRoot, join(workspaceRoot, '.nx', 'installation')],
getNxRequirePaths(),
workspaceRoot
);
const workspacesGlobPatterns =
Expand Down
10 changes: 10 additions & 0 deletions packages/nx/src/utils/installation-directory.ts
@@ -0,0 +1,10 @@
import { join } from 'path';
import { workspaceRoot } from './workspace-root';

export function getNxInstallationPath(root: string = workspaceRoot) {
return join(root, '.nx', 'installation');
}

export function getNxRequirePaths(root: string = workspaceRoot) {
return [root, getNxInstallationPath(root)];
}
3 changes: 2 additions & 1 deletion packages/nx/src/utils/nx-plugin.ts
Expand Up @@ -23,6 +23,7 @@ import {
} from '../project-graph/utils/find-project-for-path';
import { normalizePath } from './path';
import { join } from 'path';
import { getNxRequirePaths } from './installation-directory';

export type ProjectTargetConfigurator = (
file: string
Expand Down Expand Up @@ -85,7 +86,7 @@ function loadNxPlugin(moduleName: string, paths: string[], root: string) {

export function loadNxPlugins(
plugins?: string[],
paths = [workspaceRoot, join(workspaceRoot, '.nx', 'installation')],
paths = getNxRequirePaths(),
root = workspaceRoot
): NxPlugin[] {
const result: NxPlugin[] = [];
Expand Down
6 changes: 2 additions & 4 deletions packages/nx/src/utils/plugins/installed-plugins.ts
Expand Up @@ -8,6 +8,7 @@ import { PackageJson, readModulePackageJson } from '../package-json';
import { workspaceRoot } from '../workspace-root';
import { join } from 'path';
import { NxJsonConfiguration } from '../../config/nx-json';
import { getNxRequirePaths } from '../installation-directory';

export function findInstalledPlugins(): PackageJson[] {
const packageJsonDeps = getDependenciesFromPackageJson();
Expand All @@ -25,10 +26,7 @@ export function findInstalledPlugins(): PackageJson[] {

function getNxPluginPackageJsonOrNull(pkg: string): PackageJson | null {
try {
const { packageJson } = readModulePackageJson(pkg, [
workspaceRoot,
join(workspaceRoot, '.nx', ' installation'),
]);
const { packageJson } = readModulePackageJson(pkg, getNxRequirePaths());
return packageJson &&
[
'ng-update',
Expand Down

1 comment on commit 902f644

@vercel
Copy link

@vercel vercel bot commented on 902f644 Feb 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

nx-dev – ./

nx-dev-git-master-nrwl.vercel.app
nx-dev-nrwl.vercel.app
nx-five.vercel.app
nx.dev

Please sign in to comment.