@@ -20,12 +20,17 @@ export async function normalizeSchema(
20
20
projectConfiguration
21
21
) ;
22
22
23
+ const isNxConfiguredInPackageJson = ! tree . exists (
24
+ joinPathFragments ( projectConfiguration . root , 'project.json' )
25
+ ) ;
26
+
23
27
return {
24
28
...schema ,
25
29
destination : normalizePathSlashes ( schema . destination ) ,
26
30
importPath,
27
31
newProjectName,
28
32
relativeToRootDestination : destination ,
33
+ isNxConfiguredInPackageJson,
29
34
} ;
30
35
}
31
36
@@ -41,13 +46,45 @@ async function determineProjectNameAndRootOptions(
41
46
projectConfiguration : ProjectConfiguration
42
47
) : Promise < ProjectNameAndRootOptions > {
43
48
validateName ( tree , options . newProjectName , projectConfiguration ) ;
44
- const projectNameAndRootOptions = getProjectNameAndRootOptions (
45
- tree ,
46
- options ,
47
- projectConfiguration
48
- ) ;
49
49
50
- return projectNameAndRootOptions ;
50
+ let destination = normalizePathSlashes ( options . destination ) ;
51
+
52
+ if (
53
+ options . newProjectName &&
54
+ options . newProjectName . includes ( '/' ) &&
55
+ ! options . newProjectName . startsWith ( '@' )
56
+ ) {
57
+ throw new Error (
58
+ `You can't specify a new project name with a directory path (${ options . newProjectName } ). ` +
59
+ `Please provide a valid name without path segments and the full destination with the "--destination" option.`
60
+ ) ;
61
+ }
62
+
63
+ const newProjectName = options . newProjectName ?? options . projectName ;
64
+
65
+ if ( projectConfiguration . projectType !== 'library' ) {
66
+ return { destination, newProjectName } ;
67
+ }
68
+
69
+ let importPath = options . importPath ;
70
+ if ( importPath ) {
71
+ return { destination, newProjectName, importPath } ;
72
+ }
73
+
74
+ if ( options . newProjectName ?. startsWith ( '@' ) ) {
75
+ // keep the existing import path if the name didn't change
76
+ importPath =
77
+ options . newProjectName && options . projectName !== options . newProjectName
78
+ ? newProjectName
79
+ : undefined ;
80
+ } else if ( options . newProjectName ) {
81
+ const npmScope = getNpmScope ( tree ) ;
82
+ importPath = npmScope
83
+ ? `${ npmScope === '@' ? '' : '@' } ${ npmScope } /${ newProjectName } `
84
+ : newProjectName ;
85
+ }
86
+
87
+ return { destination, newProjectName, importPath } ;
51
88
}
52
89
53
90
function validateName (
@@ -100,63 +137,3 @@ function validateName(
100
137
}
101
138
}
102
139
}
103
-
104
- function getProjectNameAndRootOptions (
105
- tree : Tree ,
106
- options : Schema ,
107
- projectConfiguration : ProjectConfiguration
108
- ) : ProjectNameAndRootOptions {
109
- let destination = normalizePathSlashes ( options . destination ) ;
110
-
111
- if (
112
- options . newProjectName &&
113
- options . newProjectName . includes ( '/' ) &&
114
- ! options . newProjectName . startsWith ( '@' )
115
- ) {
116
- throw new Error (
117
- `You can't specify a new project name with a directory path (${ options . newProjectName } ). ` +
118
- `Please provide a valid name without path segments and the full destination with the "--destination" option.`
119
- ) ;
120
- }
121
-
122
- const asProvidedOptions = getAsProvidedOptions (
123
- tree ,
124
- { ...options , destination } ,
125
- projectConfiguration
126
- ) ;
127
-
128
- return asProvidedOptions ;
129
- }
130
-
131
- function getAsProvidedOptions (
132
- tree : Tree ,
133
- options : Schema ,
134
- projectConfiguration : ProjectConfiguration
135
- ) : ProjectNameAndRootOptions {
136
- const newProjectName = options . newProjectName ?? options . projectName ;
137
- const destination = options . destination ;
138
-
139
- if ( projectConfiguration . projectType !== 'library' ) {
140
- return { destination, newProjectName } ;
141
- }
142
-
143
- let importPath = options . importPath ;
144
- if ( importPath ) {
145
- return { destination, newProjectName, importPath } ;
146
- }
147
-
148
- if ( options . newProjectName ?. startsWith ( '@' ) ) {
149
- // keep the existing import path if the name didn't change
150
- importPath =
151
- options . newProjectName && options . projectName !== options . newProjectName
152
- ? newProjectName
153
- : undefined ;
154
- } else if ( options . newProjectName ) {
155
- const npmScope = getNpmScope ( tree ) ;
156
- importPath = npmScope
157
- ? `${ npmScope === '@' ? '' : '@' } ${ npmScope } /${ newProjectName } `
158
- : newProjectName ;
159
- }
160
-
161
- return { destination, newProjectName, importPath } ;
162
- }
0 commit comments