Skip to content

Commit f922e2b

Browse files
authored
fix(misc): fix misc generation issues with the ts solution setup (#29350)
Fix misc generation issues related to the new TS solution setup: - Improve Cypress config default formatting (when no prettier) - Remove leftover compiler options from `tsconfig.json` files - Do not add TS path mappings - Update `outDir` for `typecheck` tasks to be `out-tsc/...` - Generate Nx configuration in `package.json` files for e2e test runner projects - Fix issue with `@nx/js:library` and `--bundler=vite` - Other smaller changes <!-- 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 --> ## Expected Behavior <!-- This is the behavior we should expect with the changes in this PR --> ## Related Issue(s) <!-- Please link the issue being fixed so it gets closed when this is merged. --> Fixes #
1 parent bf15e68 commit f922e2b

File tree

40 files changed

+248
-131
lines changed

40 files changed

+248
-131
lines changed

packages/angular/src/generators/ng-add/migrators/projects/__snapshots__/e2e.migrator.spec.ts.snap

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,15 @@ export default defineConfig({
1515

1616
exports[`e2e migrator cypress with project root at "" cypress version >=10 should create a cypress.config.ts file when it does not exist 1`] = `
1717
"import { nxE2EPreset } from '@nx/cypress/plugins/cypress-preset';
18-
1918
import { defineConfig } from 'cypress';
2019
2120
export default defineConfig({
2221
e2e: {
2322
...nxE2EPreset(__filename, {
2423
cypressDir: 'src',
25-
webServerCommands: { default: 'nx run app1:serve' },
24+
webServerCommands: {
25+
default: 'nx run app1:serve',
26+
},
2627
}),
2728
baseUrl: 'http://localhost:4200',
2829
},
@@ -98,14 +99,15 @@ export default defineConfig({
9899

99100
exports[`e2e migrator cypress with project root at "projects/app1" cypress version >=10 should create a cypress.config.ts file when it does not exist 1`] = `
100101
"import { nxE2EPreset } from '@nx/cypress/plugins/cypress-preset';
101-
102102
import { defineConfig } from 'cypress';
103103
104104
export default defineConfig({
105105
e2e: {
106106
...nxE2EPreset(__filename, {
107107
cypressDir: 'src',
108-
webServerCommands: { default: 'nx run app1:serve' },
108+
webServerCommands: {
109+
default: 'nx run app1:serve',
110+
},
109111
}),
110112
baseUrl: 'http://localhost:4200',
111113
},

packages/cypress/src/generators/base-setup/files/tsconfig/ts-solution/__directory__/tsconfig.json__ext__

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
{
22
"extends": "<%= tsConfigPath %>",
33
"compilerOptions": {
4-
"outDir": "dist",
5-
"tsBuildInfoFile": "dist/tsconfig.tsbuildinfo",
4+
"outDir": "out-tsc/cypress",
65
"allowJs": true,
76
"types": ["cypress", "node"],
87
"sourceMap": false
@@ -17,5 +16,5 @@
1716
<%_ if (jsx) { _%>"<%= offsetFromProjectRoot %>**/*.cy.jsx",<%_ } _%>
1817
"<%= offsetFromProjectRoot %>**/*.d.ts"
1918
],
20-
"exclude": ["dist"<% if (linter === 'eslint') { %>, "eslint.config.js"<% } %>]
19+
"exclude": ["out-tsc", "test-output"<% if (linter === 'eslint') { %>, "eslint.config.js"<% } %>]
2120
}

packages/cypress/src/generators/configuration/configuration.spec.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ describe('Cypress e2e configuration', () => {
5757
expect(tree.read('apps/my-app/cypress.config.ts', 'utf-8'))
5858
.toMatchInlineSnapshot(`
5959
"import { nxE2EPreset } from '@nx/cypress/plugins/cypress-preset';
60-
6160
import { defineConfig } from 'cypress';
6261
6362
export default defineConfig({
@@ -116,7 +115,6 @@ describe('Cypress e2e configuration', () => {
116115
expect(tree.read('apps/my-app/cypress.config.ts', 'utf-8'))
117116
.toMatchInlineSnapshot(`
118117
"import { nxE2EPreset } from '@nx/cypress/plugins/cypress-preset';
119-
120118
import { defineConfig } from 'cypress';
121119
122120
export default defineConfig({
@@ -176,7 +174,6 @@ describe('Cypress e2e configuration', () => {
176174
expect(tree.read('libs/my-lib/cypress.config.ts', 'utf-8'))
177175
.toMatchInlineSnapshot(`
178176
"import { nxE2EPreset } from '@nx/cypress/plugins/cypress-preset';
179-
180177
import { defineConfig } from 'cypress';
181178
182179
export default defineConfig({
@@ -207,7 +204,6 @@ describe('Cypress e2e configuration', () => {
207204
expect(tree.read('apps/my-app/cypress.config.ts', 'utf-8'))
208205
.toMatchInlineSnapshot(`
209206
"import { nxE2EPreset } from '@nx/cypress/plugins/cypress-preset';
210-
211207
import { defineConfig } from 'cypress';
212208
213209
export default defineConfig({
@@ -450,14 +446,15 @@ export default defineConfig({
450446
expect(tree.read('libs/my-lib/cypress.config.ts', 'utf-8'))
451447
.toMatchInlineSnapshot(`
452448
"import { nxE2EPreset } from '@nx/cypress/plugins/cypress-preset';
453-
454449
import { defineConfig } from 'cypress';
455450
import { nxComponentTestingPreset } from '@nx/angular/plugins/component-testing';
456451
457452
export default defineConfig({
458453
component: nxComponentTestingPreset(__filename),
459454
e2e: {
460-
...nxE2EPreset(__filename, { cypressDir: 'src' }),
455+
...nxE2EPreset(__filename, {
456+
cypressDir: 'src',
457+
}),
461458
baseUrl: 'http://localhost:4200',
462459
},
463460
});
@@ -513,12 +510,13 @@ export default defineConfig({
513510
expect(tree.read('libs/my-lib/cypress.config.js', 'utf-8'))
514511
.toMatchInlineSnapshot(`
515512
"const { nxE2EPreset } = require('@nx/cypress/plugins/cypress-preset');
516-
517513
const { defineConfig } = require('cypress');
518514
519515
module.exports = defineConfig({
520516
e2e: {
521-
...nxE2EPreset(__filename, { cypressDir: 'src' }),
517+
...nxE2EPreset(__filename, {
518+
cypressDir: 'src',
519+
}),
522520
baseUrl: 'http://localhost:4200',
523521
},
524522
});
@@ -544,12 +542,13 @@ export default defineConfig({
544542
expect(tree.read('libs/my-lib/cypress.config.js', 'utf-8'))
545543
.toMatchInlineSnapshot(`
546544
"import { nxE2EPreset } from '@nx/cypress/plugins/cypress-preset';
547-
548545
import { defineConfig } from 'cypress';
549546
550547
export default defineConfig({
551548
e2e: {
552-
...nxE2EPreset(__filename, { cypressDir: 'src' }),
549+
...nxE2EPreset(__filename, {
550+
cypressDir: 'src',
551+
}),
553552
baseUrl: 'http://localhost:4200',
554553
},
555554
});

packages/cypress/src/utils/config.spec.ts

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,16 @@ export default defineConfig({
4242
);
4343
expect(actual).toMatchInlineSnapshot(`
4444
"import { nxE2EPreset } from '@nx/cypress/plugins/cypress-preset';
45-
46-
import { defineConfig } from 'cypress';
45+
import { defineConfig } from 'cypress';
4746
import { nxComponentTestingPreset } from '@nx/angular/plugins/component-testing';
4847
4948
export default defineConfig({
5049
component: nxComponentTestingPreset(__filename),
51-
e2e: { ...nxE2EPreset(__filename, {"cypressDir":"cypress"}) }
50+
e2e: {
51+
...nxE2EPreset(__filename, {
52+
"cypressDir": "cypress"
53+
})
54+
}
5255
});
5356
"
5457
`);
@@ -134,13 +137,16 @@ export default defineConfig({
134137
);
135138
expect(actual).toMatchInlineSnapshot(`
136139
"import { nxE2EPreset } from '@nx/cypress/plugins/cypress-preset';
137-
138-
import { defineConfig } from 'cypress';
140+
import { defineConfig } from 'cypress';
139141
import { nxComponentTestingPreset } from '@nx/angular/plugins/component-testing';
140142
141143
export default defineConfig({
142-
e2e: { ...nxE2EPreset(__filename, {"cypressDir":"cypress"}),
143-
baseUrl: 'https://example.com' }
144+
e2e: {
145+
...nxE2EPreset(__filename, {
146+
"cypressDir": "cypress"
147+
}),
148+
baseUrl: 'https://example.com'
149+
}
144150
});
145151
"
146152
`);
@@ -166,12 +172,20 @@ export default defineConfig({
166172
);
167173
expect(actual).toMatchInlineSnapshot(`
168174
"import { nxE2EPreset } from '@nx/cypress/plugins/cypress-preset';
169-
170-
import { defineConfig } from 'cypress';
175+
import { defineConfig } from 'cypress';
171176
import { nxComponentTestingPreset } from '@nx/angular/plugins/component-testing';
172177
173178
export default defineConfig({
174-
e2e: { ...nxE2EPreset(__filename, {"cypressDir":"cypress","webServerCommands":{"default":"my-app:serve","production":"my-app:serve:production"},"ciWebServerCommand":"my-app:serve-static"}) }
179+
e2e: {
180+
...nxE2EPreset(__filename, {
181+
"cypressDir": "cypress",
182+
"webServerCommands": {
183+
"default": "my-app:serve",
184+
"production": "my-app:serve:production"
185+
},
186+
"ciWebServerCommand": "my-app:serve-static"
187+
})
188+
}
175189
});
176190
"
177191
`);

packages/cypress/src/utils/config.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,32 +39,40 @@ export async function addDefaultE2EConfig(
3939
let updatedConfigContents = cyConfigContents;
4040

4141
if (testingTypeConfig.length === 0) {
42-
const configValue = `nxE2EPreset(__filename, ${JSON.stringify(options)})`;
42+
const configValue = `nxE2EPreset(__filename, ${JSON.stringify(
43+
options,
44+
null,
45+
2
46+
)
47+
.split('\n')
48+
.join('\n ')})`;
4349

4450
updatedConfigContents = tsquery.replace(
4551
cyConfigContents,
4652
`${TS_QUERY_EXPORT_CONFIG_PREFIX} ObjectLiteralExpression:first-child`,
4753
(node: ObjectLiteralExpression) => {
48-
let baseUrlContents = baseUrl ? `,\nbaseUrl: '${baseUrl}'` : '';
54+
let baseUrlContents = baseUrl ? `,\n baseUrl: '${baseUrl}'` : '';
4955
if (node.properties.length > 0) {
5056
return `{
5157
${node.properties.map((p) => p.getText()).join(',\n')},
52-
e2e: { ...${configValue}${baseUrlContents} }
58+
e2e: {
59+
...${configValue}${baseUrlContents}
60+
}
5361
}`;
5462
}
5563
return `{
56-
e2e: { ...${configValue}${baseUrlContents} }
64+
e2e: {
65+
...${configValue}${baseUrlContents}
66+
}
5767
}`;
5868
}
5969
);
6070

6171
return isCommonJS
6272
? `const { nxE2EPreset } = require('@nx/cypress/plugins/cypress-preset');
63-
64-
${updatedConfigContents}`
73+
${updatedConfigContents}`
6574
: `import { nxE2EPreset } from '@nx/cypress/plugins/cypress-preset';
66-
67-
${updatedConfigContents}`;
75+
${updatedConfigContents}`;
6876
}
6977
return updatedConfigContents;
7078
}

packages/expo/src/generators/application/application.spec.ts

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -370,19 +370,6 @@ describe('app', () => {
370370
`);
371371
expect(readJson(tree, 'my-app/tsconfig.json')).toMatchInlineSnapshot(`
372372
{
373-
"compilerOptions": {
374-
"allowSyntheticDefaultImports": true,
375-
"declaration": true,
376-
"jsx": "react-native",
377-
"lib": [
378-
"dom",
379-
"esnext",
380-
],
381-
"moduleResolution": "node",
382-
"resolveJsonModule": true,
383-
"skipLibCheck": true,
384-
"strict": true,
385-
},
386373
"extends": "../tsconfig.base.json",
387374
"files": [],
388375
"include": [],
@@ -411,6 +398,7 @@ describe('app', () => {
411398
],
412399
},
413400
"exclude": [
401+
"out-tsc",
414402
"dist",
415403
"**/*.test.ts",
416404
"**/*.spec.ts",

packages/expo/src/generators/application/files/base/tsconfig.json.template

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"extends": "<%= offsetFromRoot %>tsconfig.base.json",
3+
<%_ if (!isTsSolutionSetup) { _%>
34
"compilerOptions": {
45
"allowSyntheticDefaultImports": true,
56
"jsx": "react-native",
@@ -10,6 +11,7 @@
1011
"strict": true,
1112
"declaration": true
1213
},
14+
<%_ } _%>
1315
"files": [],
1416
"include": [],
1517
"references": [

packages/expo/src/generators/application/lib/normalize-options.spec.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ describe('Normalize Options', () => {
3939
rootProject: false,
4040
e2eProjectName: 'my-app-e2e',
4141
e2eProjectRoot: 'my-app-e2e',
42+
isTsSolutionSetup: false,
4243
} as NormalizedSchema);
4344
});
4445

@@ -70,6 +71,7 @@ describe('Normalize Options', () => {
7071
rootProject: false,
7172
e2eProjectName: 'myApp-e2e',
7273
e2eProjectRoot: 'myApp-e2e',
74+
isTsSolutionSetup: false,
7375
} as NormalizedSchema);
7476
});
7577

@@ -102,6 +104,7 @@ describe('Normalize Options', () => {
102104
rootProject: false,
103105
e2eProjectName: 'my-app-e2e',
104106
e2eProjectRoot: 'directory-e2e',
107+
isTsSolutionSetup: false,
105108
} as NormalizedSchema);
106109
});
107110

@@ -133,6 +136,7 @@ describe('Normalize Options', () => {
133136
rootProject: false,
134137
e2eProjectName: 'my-app-e2e',
135138
e2eProjectRoot: 'directory/my-app-e2e',
139+
isTsSolutionSetup: false,
136140
} as NormalizedSchema);
137141
});
138142

@@ -165,6 +169,7 @@ describe('Normalize Options', () => {
165169
rootProject: false,
166170
e2eProjectName: 'my-app-e2e',
167171
e2eProjectRoot: 'my-app-e2e',
172+
isTsSolutionSetup: false,
168173
} as NormalizedSchema);
169174
});
170175
});

packages/expo/src/generators/application/lib/normalize-options.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
determineProjectNameAndRootOptions,
44
ensureProjectName,
55
} from '@nx/devkit/src/generators/project-name-and-root-utils';
6+
import { isUsingTsSolutionSetup } from '@nx/js/src/utils/typescript/ts-solution-setup';
67
import { Schema } from '../schema';
78

89
export interface NormalizedSchema extends Schema {
@@ -14,6 +15,7 @@ export interface NormalizedSchema extends Schema {
1415
rootProject: boolean;
1516
e2eProjectName: string;
1617
e2eProjectRoot: string;
18+
isTsSolutionSetup: boolean;
1719
}
1820

1921
export async function normalizeOptions(
@@ -59,5 +61,6 @@ export async function normalizeOptions(
5961
rootProject,
6062
e2eProjectName,
6163
e2eProjectRoot,
64+
isTsSolutionSetup: isUsingTsSolutionSetup(host),
6265
};
6366
}

packages/expo/src/generators/library/files/lib/tsconfig.json.template

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
{
22
"extends": "<%= rootTsConfigPath %>",
3+
<%_ if (!isUsingTsSolutionConfig) { _%>
34
"compilerOptions": {
45
"jsx": "react-jsx",
56
"allowJs": true,
67
"esModuleInterop": true,
78
"allowSyntheticDefaultImports": true
89
},
10+
<%_ } _%>
911
"files": [],
1012
"include": [],
1113
"references": [

packages/expo/src/generators/library/library.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ export async function expoLibraryGeneratorInternal(
106106
updateLibPackageNpmScope(host, options);
107107
}
108108

109-
if (!options.skipTsConfig) {
109+
if (!options.skipTsConfig && !options.isUsingTsSolutionConfig) {
110110
addTsConfigPath(host, options.importPath, [
111111
joinPathFragments(
112112
options.projectRoot,

packages/express/src/generators/application/application.spec.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,6 @@ describe('app', () => {
236236
`);
237237
expect(readJson(appTree, 'myapp/tsconfig.json')).toMatchInlineSnapshot(`
238238
{
239-
"compilerOptions": {
240-
"esModuleInterop": true,
241-
},
242239
"extends": "../tsconfig.base.json",
243240
"files": [],
244241
"include": [],
@@ -267,6 +264,7 @@ describe('app', () => {
267264
],
268265
},
269266
"exclude": [
267+
"out-tsc",
270268
"dist",
271269
"jest.config.ts",
272270
"src/**/*.spec.ts",
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export * from './lib/<%= fileName %>';
1+
export * from './lib/<%= fileNameImport %>';

0 commit comments

Comments
 (0)