1
- import type { NxJsonConfiguration , PackageManager } from '@nx/devkit' ;
1
+ import { type NxJsonConfiguration , type PackageManager } from '@nx/devkit' ;
2
2
import { execSync , ExecSyncOptions } from 'child_process' ;
3
3
import {
4
4
ensureDirSync ,
@@ -45,13 +45,22 @@ export function createWorkspaceWithNxWrapper(
45
45
46
46
const nxJsonPath = resolve ( directory , 'nx.json' ) ;
47
47
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
+ }
55
64
56
65
runNxWrapperSync ( `g ${ pkgName } :preset ${ extraArgs } ` , {
57
66
cwd : directory ,
@@ -96,11 +105,10 @@ export function getNxCommand(
96
105
) {
97
106
if ( ! useNxWrapper ) {
98
107
switch ( pkgManager ) {
99
- case 'yarn' :
100
- case 'pnpm' :
101
- return `$(pkgManager} nx` ;
102
- default :
108
+ case 'npm' :
103
109
return 'npx nx' ;
110
+ default :
111
+ return `$(pkgManager} nx` ;
104
112
}
105
113
}
106
114
return process . platform === 'win32' ? '.\\nx.bat' : './nx' ;
@@ -115,6 +123,13 @@ export function isNxWrapperInstalled(cwd: string) {
115
123
) ;
116
124
}
117
125
126
+ export function isNxCrystalEnabled ( nxJson : NxJsonConfiguration ) {
127
+ return (
128
+ process . env [ 'NX_ADD_PLUGINS' ] !== 'false' &&
129
+ nxJson . useInferencePlugins !== false
130
+ ) ;
131
+ }
132
+
118
133
// Copied from https://github.com/nrwl/nx/blob/master/packages/nx/src/utils/workspace-root.ts
119
134
// Mainly because workspaceRootInner is not exported by @nx /devkit
120
135
function workspaceRootInner (
0 commit comments