Skip to content

Commit 788d8be

Browse files
committed
feat(common-cli): add support for inferred tasks when adding the plugin to the workspace
1 parent 237e7b4 commit 788d8be

File tree

1 file changed

+27
-12
lines changed

1 file changed

+27
-12
lines changed

packages/common-cli/src/lib/utils.ts

+27-12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { NxJsonConfiguration, PackageManager } from '@nx/devkit';
1+
import { type NxJsonConfiguration, type PackageManager } from '@nx/devkit';
22
import { execSync, ExecSyncOptions } from 'child_process';
33
import {
44
ensureDirSync,
@@ -45,13 +45,22 @@ export function createWorkspaceWithNxWrapper(
4545

4646
const nxJsonPath = resolve(directory, 'nx.json');
4747
const nxJson: NxJsonConfiguration = readJSONSync(nxJsonPath);
48-
nxJson.installation = nxJson.installation ?? {
49-
version: 'latest',
50-
plugins: {},
51-
};
52-
nxJson.installation.plugins = nxJson.installation.plugins ?? {};
53-
nxJson.installation.plugins[pkgName] = presetVersion;
54-
writeJsonSync(nxJsonPath, nxJson, { spaces: 2 });
48+
49+
if (isNxCrystalEnabled(nxJson)) {
50+
runNxWrapperSync(`add ${pkgName}@${presetVersion}`, {
51+
cwd: directory,
52+
stdio: 'inherit',
53+
env: process.env,
54+
});
55+
} else {
56+
nxJson.installation = nxJson.installation ?? {
57+
version: 'latest',
58+
plugins: {},
59+
};
60+
nxJson.installation.plugins = nxJson.installation.plugins ?? {};
61+
nxJson.installation.plugins[pkgName] = presetVersion;
62+
writeJsonSync(nxJsonPath, nxJson, { spaces: 2 });
63+
}
5564

5665
runNxWrapperSync(`g ${pkgName}:preset ${extraArgs}`, {
5766
cwd: directory,
@@ -96,11 +105,10 @@ export function getNxCommand(
96105
) {
97106
if (!useNxWrapper) {
98107
switch (pkgManager) {
99-
case 'yarn':
100-
case 'pnpm':
101-
return `$(pkgManager} nx`;
102-
default:
108+
case 'npm':
103109
return 'npx nx';
110+
default:
111+
return `$(pkgManager} nx`;
104112
}
105113
}
106114
return process.platform === 'win32' ? '.\\nx.bat' : './nx';
@@ -115,6 +123,13 @@ export function isNxWrapperInstalled(cwd: string) {
115123
);
116124
}
117125

126+
export function isNxCrystalEnabled(nxJson: NxJsonConfiguration) {
127+
return (
128+
process.env['NX_ADD_PLUGINS'] !== 'false' &&
129+
nxJson.useInferencePlugins !== false
130+
);
131+
}
132+
118133
// Copied from https://github.com/nrwl/nx/blob/master/packages/nx/src/utils/workspace-root.ts
119134
// Mainly because workspaceRootInner is not exported by @nx/devkit
120135
function workspaceRootInner(

0 commit comments

Comments
 (0)