Skip to content

Commit 124eba7

Browse files
authored
fix(core): Update React,Vue and Node generators applications for CNW (#31059)
<!-- Please make sure you have read the submission guidelines before posting an PR --> <!-- https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr --> <!-- Please make sure that your commit message follows our format --> <!-- Example: `fix(nx): must begin with lowercase` --> <!-- If this is a particularly complex change or feature addition, you can request a dedicated Nx release for this pull request branch. Mention someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they will confirm if the PR warrants its own release for testing purposes, and generate it for you if appropriate. --> ## Current Behavior <!-- This is the behavior we have today --> - Currently, when we create a React, Vue or Node app we add the app name inside `package.json` under the nx ``` { "name": "@myworkspace/acme", "version": "0.0.1", "private": true, "nx": { "name": "acme" } } ``` - When we create a publishable library using React/JS generator inside a ts project references workspace the `--importPath` option. ## Expected Behavior <!-- This is the behavior we should expect with the changes in this PR --> - Since the original intention is not known we should not automatically add this to the project's `package.json` - `importPath` option should not be required when using ts project references. ## Related Issue(s) <!-- Please link the issue being fixed so it gets closed when this is merged. --> For workspaces that are not using TS project references the result remains unchanged. Fixes #
1 parent 00af974 commit 124eba7

File tree

3 files changed

+17
-13
lines changed

3 files changed

+17
-13
lines changed

packages/js/src/generators/library/library.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -850,7 +850,7 @@ async function normalizeOptions(
850850
}
851851

852852
if (options.publishable) {
853-
if (!options.importPath) {
853+
if (!isUsingTsSolutionConfig && !options.importPath) {
854854
throw new Error(
855855
`For publishable libs you have to provide a proper "--importPath" which needs to be a valid npm package name (e.g. my-awesome-lib or @myorg/my-lib)`
856856
);

packages/react/src/generators/library/library.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,11 @@ export async function libraryGeneratorInternal(host: Tree, schema: Schema) {
6464

6565
const options = await normalizeOptions(host, schema);
6666

67-
if (options.publishable === true && !schema.importPath) {
67+
if (
68+
options.publishable === true &&
69+
!options.isUsingTsSolutionConfig &&
70+
!schema.importPath
71+
) {
6872
throw new Error(
6973
`For publishable libs you have to provide a proper "--importPath" which needs to be a valid npm package name (e.g. my-awesome-lib or @myorg/my-lib)`
7074
);

packages/workspace/src/generators/preset/preset.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ async function createPreset(tree: Tree, options: Schema) {
6767
'/react');
6868

6969
return reactApplicationGenerator(tree, {
70-
name: options.name,
70+
name: options.workspaces ? undefined : options.name,
7171
directory: join('apps', options.name),
7272
style: options.style,
7373
linter: options.linter,
@@ -111,7 +111,7 @@ async function createPreset(tree: Tree, options: Schema) {
111111
'/vue');
112112

113113
return vueApplicationGenerator(tree, {
114-
name: options.name,
114+
name: options.workspaces ? undefined : options.name,
115115
directory: join('apps', options.name),
116116
style: options.style,
117117
linter: options.linter,
@@ -143,7 +143,7 @@ async function createPreset(tree: Tree, options: Schema) {
143143
'/nuxt');
144144

145145
return nuxtApplicationGenerator(tree, {
146-
name: options.name,
146+
name: options.workspaces ? undefined : options.name,
147147
directory: join('apps', options.name),
148148
style: options.style,
149149
linter: options.linter,
@@ -175,7 +175,7 @@ async function createPreset(tree: Tree, options: Schema) {
175175
'/next');
176176

177177
return nextApplicationGenerator(tree, {
178-
name: options.name,
178+
name: options.workspaces ? undefined : options.name,
179179
directory: join('apps', options.name),
180180
style: options.style,
181181
linter: options.linter,
@@ -209,7 +209,7 @@ async function createPreset(tree: Tree, options: Schema) {
209209
'/web');
210210

211211
return webApplicationGenerator(tree, {
212-
name: options.name,
212+
name: options.workspaces ? undefined : options.name,
213213
directory: join('apps', options.name),
214214
style: options.style,
215215
linter: options.linter,
@@ -223,7 +223,7 @@ async function createPreset(tree: Tree, options: Schema) {
223223
'/nest');
224224

225225
return nestApplicationGenerator(tree, {
226-
name: options.name,
226+
name: options.workspaces ? undefined : options.name,
227227
directory: join('apps', options.name),
228228
linter: options.linter,
229229
e2eTestRunner: options.e2eTestRunner ?? 'jest',
@@ -238,7 +238,7 @@ async function createPreset(tree: Tree, options: Schema) {
238238
applicationGenerator: expressApplicationGenerator,
239239
} = require('@nx' + '/express');
240240
return expressApplicationGenerator(tree, {
241-
name: options.name,
241+
name: options.workspaces ? undefined : options.name,
242242
directory: join('apps', options.name),
243243
linter: options.linter,
244244
e2eTestRunner: options.e2eTestRunner ?? 'jest',
@@ -252,7 +252,7 @@ async function createPreset(tree: Tree, options: Schema) {
252252
const { reactNativeApplicationGenerator } = require('@nx' +
253253
'/react-native');
254254
return reactNativeApplicationGenerator(tree, {
255-
name: options.name,
255+
name: options.workspaces ? undefined : options.name,
256256
directory: join('apps', options.name),
257257
linter: options.linter,
258258
e2eTestRunner: options.e2eTestRunner ?? 'detox',
@@ -267,7 +267,7 @@ async function createPreset(tree: Tree, options: Schema) {
267267
} else if (options.preset === Preset.Expo) {
268268
const { expoApplicationGenerator } = require('@nx' + '/expo');
269269
return expoApplicationGenerator(tree, {
270-
name: options.name,
270+
name: options.workspaces ? undefined : options.name,
271271
directory: join('apps', options.name),
272272
linter: options.linter,
273273
e2eTestRunner: options.e2eTestRunner ?? 'detox',
@@ -302,7 +302,7 @@ async function createPreset(tree: Tree, options: Schema) {
302302
const bundler = options.bundler === 'webpack' ? 'webpack' : 'esbuild';
303303
return nodeApplicationGenerator(tree, {
304304
bundler,
305-
name: options.name,
305+
name: options.workspaces ? undefined : options.name,
306306
directory: '.',
307307
linter: options.linter,
308308
standaloneConfig: options.standaloneConfig,
@@ -319,7 +319,7 @@ async function createPreset(tree: Tree, options: Schema) {
319319
const bundler = options.bundler === 'webpack' ? 'webpack' : 'esbuild';
320320
return nodeApplicationGenerator(tree, {
321321
bundler,
322-
name: options.name,
322+
name: options.workspaces ? undefined : options.name,
323323
directory: join('apps', options.name),
324324
linter: options.linter,
325325
framework: options.framework,

0 commit comments

Comments
 (0)