diff --git a/packages/angular/src/generators/ng-add/migrators/projects/__snapshots__/e2e.migrator.spec.ts.snap b/packages/angular/src/generators/ng-add/migrators/projects/__snapshots__/e2e.migrator.spec.ts.snap index 506f8d22532b8..98974d07afa08 100644 --- a/packages/angular/src/generators/ng-add/migrators/projects/__snapshots__/e2e.migrator.spec.ts.snap +++ b/packages/angular/src/generators/ng-add/migrators/projects/__snapshots__/e2e.migrator.spec.ts.snap @@ -15,14 +15,15 @@ export default defineConfig({ exports[`e2e migrator cypress with project root at "" cypress version >=10 should create a cypress.config.ts file when it does not exist 1`] = ` "import { nxE2EPreset } from '@nx/cypress/plugins/cypress-preset'; - import { defineConfig } from 'cypress'; export default defineConfig({ e2e: { ...nxE2EPreset(__filename, { cypressDir: 'src', - webServerCommands: { default: 'nx run app1:serve' }, + webServerCommands: { + default: 'nx run app1:serve', + }, }), baseUrl: 'http://localhost:4200', }, @@ -98,14 +99,15 @@ export default defineConfig({ 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`] = ` "import { nxE2EPreset } from '@nx/cypress/plugins/cypress-preset'; - import { defineConfig } from 'cypress'; export default defineConfig({ e2e: { ...nxE2EPreset(__filename, { cypressDir: 'src', - webServerCommands: { default: 'nx run app1:serve' }, + webServerCommands: { + default: 'nx run app1:serve', + }, }), baseUrl: 'http://localhost:4200', }, diff --git a/packages/cypress/src/generators/base-setup/files/tsconfig/ts-solution/__directory__/tsconfig.json__ext__ b/packages/cypress/src/generators/base-setup/files/tsconfig/ts-solution/__directory__/tsconfig.json__ext__ index 88dc50152e31c..3c711de7a2ba3 100644 --- a/packages/cypress/src/generators/base-setup/files/tsconfig/ts-solution/__directory__/tsconfig.json__ext__ +++ b/packages/cypress/src/generators/base-setup/files/tsconfig/ts-solution/__directory__/tsconfig.json__ext__ @@ -1,8 +1,7 @@ { "extends": "<%= tsConfigPath %>", "compilerOptions": { - "outDir": "dist", - "tsBuildInfoFile": "dist/tsconfig.tsbuildinfo", + "outDir": "out-tsc/cypress", "allowJs": true, "types": ["cypress", "node"], "sourceMap": false @@ -17,5 +16,5 @@ <%_ if (jsx) { _%>"<%= offsetFromProjectRoot %>**/*.cy.jsx",<%_ } _%> "<%= offsetFromProjectRoot %>**/*.d.ts" ], - "exclude": ["dist"<% if (linter === 'eslint') { %>, "eslint.config.js"<% } %>] + "exclude": ["out-tsc", "test-output"<% if (linter === 'eslint') { %>, "eslint.config.js"<% } %>] } diff --git a/packages/cypress/src/generators/configuration/configuration.spec.ts b/packages/cypress/src/generators/configuration/configuration.spec.ts index 449b1e22b30e7..a7a12a0cb810f 100644 --- a/packages/cypress/src/generators/configuration/configuration.spec.ts +++ b/packages/cypress/src/generators/configuration/configuration.spec.ts @@ -57,7 +57,6 @@ describe('Cypress e2e configuration', () => { expect(tree.read('apps/my-app/cypress.config.ts', 'utf-8')) .toMatchInlineSnapshot(` "import { nxE2EPreset } from '@nx/cypress/plugins/cypress-preset'; - import { defineConfig } from 'cypress'; export default defineConfig({ @@ -116,7 +115,6 @@ describe('Cypress e2e configuration', () => { expect(tree.read('apps/my-app/cypress.config.ts', 'utf-8')) .toMatchInlineSnapshot(` "import { nxE2EPreset } from '@nx/cypress/plugins/cypress-preset'; - import { defineConfig } from 'cypress'; export default defineConfig({ @@ -176,7 +174,6 @@ describe('Cypress e2e configuration', () => { expect(tree.read('libs/my-lib/cypress.config.ts', 'utf-8')) .toMatchInlineSnapshot(` "import { nxE2EPreset } from '@nx/cypress/plugins/cypress-preset'; - import { defineConfig } from 'cypress'; export default defineConfig({ @@ -207,7 +204,6 @@ describe('Cypress e2e configuration', () => { expect(tree.read('apps/my-app/cypress.config.ts', 'utf-8')) .toMatchInlineSnapshot(` "import { nxE2EPreset } from '@nx/cypress/plugins/cypress-preset'; - import { defineConfig } from 'cypress'; export default defineConfig({ @@ -450,14 +446,15 @@ export default defineConfig({ expect(tree.read('libs/my-lib/cypress.config.ts', 'utf-8')) .toMatchInlineSnapshot(` "import { nxE2EPreset } from '@nx/cypress/plugins/cypress-preset'; - import { defineConfig } from 'cypress'; import { nxComponentTestingPreset } from '@nx/angular/plugins/component-testing'; export default defineConfig({ component: nxComponentTestingPreset(__filename), e2e: { - ...nxE2EPreset(__filename, { cypressDir: 'src' }), + ...nxE2EPreset(__filename, { + cypressDir: 'src', + }), baseUrl: 'http://localhost:4200', }, }); @@ -513,12 +510,13 @@ export default defineConfig({ expect(tree.read('libs/my-lib/cypress.config.js', 'utf-8')) .toMatchInlineSnapshot(` "const { nxE2EPreset } = require('@nx/cypress/plugins/cypress-preset'); - const { defineConfig } = require('cypress'); module.exports = defineConfig({ e2e: { - ...nxE2EPreset(__filename, { cypressDir: 'src' }), + ...nxE2EPreset(__filename, { + cypressDir: 'src', + }), baseUrl: 'http://localhost:4200', }, }); @@ -544,12 +542,13 @@ export default defineConfig({ expect(tree.read('libs/my-lib/cypress.config.js', 'utf-8')) .toMatchInlineSnapshot(` "import { nxE2EPreset } from '@nx/cypress/plugins/cypress-preset'; - import { defineConfig } from 'cypress'; export default defineConfig({ e2e: { - ...nxE2EPreset(__filename, { cypressDir: 'src' }), + ...nxE2EPreset(__filename, { + cypressDir: 'src', + }), baseUrl: 'http://localhost:4200', }, }); diff --git a/packages/cypress/src/utils/config.spec.ts b/packages/cypress/src/utils/config.spec.ts index 64a0f10b0f725..8d6f12eff5fc2 100644 --- a/packages/cypress/src/utils/config.spec.ts +++ b/packages/cypress/src/utils/config.spec.ts @@ -42,13 +42,16 @@ export default defineConfig({ ); expect(actual).toMatchInlineSnapshot(` "import { nxE2EPreset } from '@nx/cypress/plugins/cypress-preset'; - - import { defineConfig } from 'cypress'; + import { defineConfig } from 'cypress'; import { nxComponentTestingPreset } from '@nx/angular/plugins/component-testing'; export default defineConfig({ component: nxComponentTestingPreset(__filename), - e2e: { ...nxE2EPreset(__filename, {"cypressDir":"cypress"}) } + e2e: { + ...nxE2EPreset(__filename, { + "cypressDir": "cypress" + }) + } }); " `); @@ -134,13 +137,16 @@ export default defineConfig({ ); expect(actual).toMatchInlineSnapshot(` "import { nxE2EPreset } from '@nx/cypress/plugins/cypress-preset'; - - import { defineConfig } from 'cypress'; + import { defineConfig } from 'cypress'; import { nxComponentTestingPreset } from '@nx/angular/plugins/component-testing'; export default defineConfig({ - e2e: { ...nxE2EPreset(__filename, {"cypressDir":"cypress"}), - baseUrl: 'https://example.com' } + e2e: { + ...nxE2EPreset(__filename, { + "cypressDir": "cypress" + }), + baseUrl: 'https://example.com' + } }); " `); @@ -166,12 +172,20 @@ export default defineConfig({ ); expect(actual).toMatchInlineSnapshot(` "import { nxE2EPreset } from '@nx/cypress/plugins/cypress-preset'; - - import { defineConfig } from 'cypress'; + import { defineConfig } from 'cypress'; import { nxComponentTestingPreset } from '@nx/angular/plugins/component-testing'; export default defineConfig({ - e2e: { ...nxE2EPreset(__filename, {"cypressDir":"cypress","webServerCommands":{"default":"my-app:serve","production":"my-app:serve:production"},"ciWebServerCommand":"my-app:serve-static"}) } + e2e: { + ...nxE2EPreset(__filename, { + "cypressDir": "cypress", + "webServerCommands": { + "default": "my-app:serve", + "production": "my-app:serve:production" + }, + "ciWebServerCommand": "my-app:serve-static" + }) + } }); " `); diff --git a/packages/cypress/src/utils/config.ts b/packages/cypress/src/utils/config.ts index 43862c659c058..2ab169208786d 100644 --- a/packages/cypress/src/utils/config.ts +++ b/packages/cypress/src/utils/config.ts @@ -39,32 +39,40 @@ export async function addDefaultE2EConfig( let updatedConfigContents = cyConfigContents; if (testingTypeConfig.length === 0) { - const configValue = `nxE2EPreset(__filename, ${JSON.stringify(options)})`; + const configValue = `nxE2EPreset(__filename, ${JSON.stringify( + options, + null, + 2 + ) + .split('\n') + .join('\n ')})`; updatedConfigContents = tsquery.replace( cyConfigContents, `${TS_QUERY_EXPORT_CONFIG_PREFIX} ObjectLiteralExpression:first-child`, (node: ObjectLiteralExpression) => { - let baseUrlContents = baseUrl ? `,\nbaseUrl: '${baseUrl}'` : ''; + let baseUrlContents = baseUrl ? `,\n baseUrl: '${baseUrl}'` : ''; if (node.properties.length > 0) { return `{ ${node.properties.map((p) => p.getText()).join(',\n')}, - e2e: { ...${configValue}${baseUrlContents} } + e2e: { + ...${configValue}${baseUrlContents} + } }`; } return `{ - e2e: { ...${configValue}${baseUrlContents} } + e2e: { + ...${configValue}${baseUrlContents} + } }`; } ); return isCommonJS ? `const { nxE2EPreset } = require('@nx/cypress/plugins/cypress-preset'); - - ${updatedConfigContents}` +${updatedConfigContents}` : `import { nxE2EPreset } from '@nx/cypress/plugins/cypress-preset'; - - ${updatedConfigContents}`; +${updatedConfigContents}`; } return updatedConfigContents; } diff --git a/packages/expo/src/generators/application/application.spec.ts b/packages/expo/src/generators/application/application.spec.ts index 24ce4173ec20e..25c24bc2ee704 100644 --- a/packages/expo/src/generators/application/application.spec.ts +++ b/packages/expo/src/generators/application/application.spec.ts @@ -370,19 +370,6 @@ describe('app', () => { `); expect(readJson(tree, 'my-app/tsconfig.json')).toMatchInlineSnapshot(` { - "compilerOptions": { - "allowSyntheticDefaultImports": true, - "declaration": true, - "jsx": "react-native", - "lib": [ - "dom", - "esnext", - ], - "moduleResolution": "node", - "resolveJsonModule": true, - "skipLibCheck": true, - "strict": true, - }, "extends": "../tsconfig.base.json", "files": [], "include": [], @@ -410,6 +397,7 @@ describe('app', () => { ], }, "exclude": [ + "out-tsc", "dist", "**/*.test.ts", "**/*.spec.ts", diff --git a/packages/expo/src/generators/application/files/base/tsconfig.json.template b/packages/expo/src/generators/application/files/base/tsconfig.json.template index 55140e5b8c460..9dd7e0699788a 100644 --- a/packages/expo/src/generators/application/files/base/tsconfig.json.template +++ b/packages/expo/src/generators/application/files/base/tsconfig.json.template @@ -1,5 +1,6 @@ { "extends": "<%= offsetFromRoot %>tsconfig.base.json", + <%_ if (!isTsSolutionSetup) { _%> "compilerOptions": { "allowSyntheticDefaultImports": true, "jsx": "react-native", @@ -10,6 +11,7 @@ "strict": true, "declaration": true }, + <%_ } _%> "files": [], "include": [], "references": [ diff --git a/packages/expo/src/generators/application/lib/normalize-options.spec.ts b/packages/expo/src/generators/application/lib/normalize-options.spec.ts index 841e51a571223..6ae07b52efc10 100644 --- a/packages/expo/src/generators/application/lib/normalize-options.spec.ts +++ b/packages/expo/src/generators/application/lib/normalize-options.spec.ts @@ -39,6 +39,7 @@ describe('Normalize Options', () => { rootProject: false, e2eProjectName: 'my-app-e2e', e2eProjectRoot: 'my-app-e2e', + isTsSolutionSetup: false, } as NormalizedSchema); }); @@ -70,6 +71,7 @@ describe('Normalize Options', () => { rootProject: false, e2eProjectName: 'myApp-e2e', e2eProjectRoot: 'myApp-e2e', + isTsSolutionSetup: false, } as NormalizedSchema); }); @@ -102,6 +104,7 @@ describe('Normalize Options', () => { rootProject: false, e2eProjectName: 'my-app-e2e', e2eProjectRoot: 'directory-e2e', + isTsSolutionSetup: false, } as NormalizedSchema); }); @@ -133,6 +136,7 @@ describe('Normalize Options', () => { rootProject: false, e2eProjectName: 'my-app-e2e', e2eProjectRoot: 'directory/my-app-e2e', + isTsSolutionSetup: false, } as NormalizedSchema); }); @@ -165,6 +169,7 @@ describe('Normalize Options', () => { rootProject: false, e2eProjectName: 'my-app-e2e', e2eProjectRoot: 'my-app-e2e', + isTsSolutionSetup: false, } as NormalizedSchema); }); }); diff --git a/packages/expo/src/generators/application/lib/normalize-options.ts b/packages/expo/src/generators/application/lib/normalize-options.ts index f38a267b08270..fe33090610fce 100644 --- a/packages/expo/src/generators/application/lib/normalize-options.ts +++ b/packages/expo/src/generators/application/lib/normalize-options.ts @@ -3,6 +3,7 @@ import { determineProjectNameAndRootOptions, ensureProjectName, } from '@nx/devkit/src/generators/project-name-and-root-utils'; +import { isUsingTsSolutionSetup } from '@nx/js/src/utils/typescript/ts-solution-setup'; import { Schema } from '../schema'; export interface NormalizedSchema extends Schema { @@ -14,6 +15,7 @@ export interface NormalizedSchema extends Schema { rootProject: boolean; e2eProjectName: string; e2eProjectRoot: string; + isTsSolutionSetup: boolean; } export async function normalizeOptions( @@ -59,5 +61,6 @@ export async function normalizeOptions( rootProject, e2eProjectName, e2eProjectRoot, + isTsSolutionSetup: isUsingTsSolutionSetup(host), }; } diff --git a/packages/expo/src/generators/library/files/lib/tsconfig.json.template b/packages/expo/src/generators/library/files/lib/tsconfig.json.template index d9affba903da0..4723ebd058283 100644 --- a/packages/expo/src/generators/library/files/lib/tsconfig.json.template +++ b/packages/expo/src/generators/library/files/lib/tsconfig.json.template @@ -1,11 +1,13 @@ { "extends": "<%= rootTsConfigPath %>", + <%_ if (!isUsingTsSolutionConfig) { _%> "compilerOptions": { "jsx": "react-jsx", "allowJs": true, "esModuleInterop": true, "allowSyntheticDefaultImports": true }, + <%_ } _%> "files": [], "include": [], "references": [ diff --git a/packages/expo/src/generators/library/library.ts b/packages/expo/src/generators/library/library.ts index aa158f52f868b..fa66b8d618171 100644 --- a/packages/expo/src/generators/library/library.ts +++ b/packages/expo/src/generators/library/library.ts @@ -106,7 +106,7 @@ export async function expoLibraryGeneratorInternal( updateLibPackageNpmScope(host, options); } - if (!options.skipTsConfig) { + if (!options.skipTsConfig && !options.isUsingTsSolutionConfig) { addTsConfigPath(host, options.importPath, [ joinPathFragments( options.projectRoot, diff --git a/packages/express/src/generators/application/application.spec.ts b/packages/express/src/generators/application/application.spec.ts index 7de92c58e455d..9a9fb219b4c01 100644 --- a/packages/express/src/generators/application/application.spec.ts +++ b/packages/express/src/generators/application/application.spec.ts @@ -236,9 +236,6 @@ describe('app', () => { `); expect(readJson(appTree, 'myapp/tsconfig.json')).toMatchInlineSnapshot(` { - "compilerOptions": { - "esModuleInterop": true, - }, "extends": "../tsconfig.base.json", "files": [], "include": [], @@ -266,6 +263,7 @@ describe('app', () => { ], }, "exclude": [ + "out-tsc", "dist", "jest.config.ts", "src/**/*.spec.ts", diff --git a/packages/js/src/generators/library/files/lib/src/index.ts__tmpl__ b/packages/js/src/generators/library/files/lib/src/index.ts__tmpl__ index 32176b3ef175e..a1ed8fb1effe4 100644 --- a/packages/js/src/generators/library/files/lib/src/index.ts__tmpl__ +++ b/packages/js/src/generators/library/files/lib/src/index.ts__tmpl__ @@ -1 +1 @@ -export * from './lib/<%= fileName %>'; +export * from './lib/<%= fileNameImport %>'; diff --git a/packages/js/src/generators/library/library.ts b/packages/js/src/generators/library/library.ts index d76f8ed879677..b93bb7e4dc819 100644 --- a/packages/js/src/generators/library/library.ts +++ b/packages/js/src/generators/library/library.ts @@ -51,6 +51,7 @@ import { addTsConfigPath, getRelativePathToRootTsConfig, getRootTsConfigFileName, + readTsConfigFromTree, } from '../../utils/typescript/ts-config'; import { isUsingTsSolutionSetup, @@ -70,6 +71,7 @@ import type { LibraryGeneratorSchema, NormalizedLibraryGeneratorOptions, } from './schema'; +import { ensureTypescript } from '../../utils/typescript/ensure-typescript'; const defaultOutputDirectory = 'dist'; @@ -510,6 +512,21 @@ function createFiles(tree: Tree, options: NormalizedLibraryGeneratorOptions) { createProjectTsConfigs(tree, options); + let fileNameImport = options.fileName; + if (options.bundler === 'vite') { + const tsConfig = readTsConfigFromTree( + tree, + join(options.projectRoot, 'tsconfig.lib.json') + ); + const ts = ensureTypescript(); + if ( + tsConfig.options.moduleResolution === ts.ModuleResolutionKind.Node16 || + tsConfig.options.moduleResolution === ts.ModuleResolutionKind.NodeNext + ) { + fileNameImport = `${options.fileName}.js`; + } + } + generateFiles(tree, join(__dirname, './files/lib'), options.projectRoot, { ...options, dot: '.', @@ -523,6 +540,7 @@ function createFiles(tree: Tree, options: NormalizedLibraryGeneratorOptions) { offsetFromRoot: offsetFromRoot(options.projectRoot), buildable: options.bundler && options.bundler !== 'none', hasUnitTestRunner: options.unitTestRunner !== 'none', + fileNameImport, }); if (!options.rootProject) { @@ -979,6 +997,10 @@ function createProjectTsConfigs( .map(([k, v]) => `${JSON.stringify(k)}: ${JSON.stringify(v)}`) .join(',\n '), tmpl: '', + outDir: + options.bundler === 'tsc' + ? 'dist' + : `out-tsc/${options.projectRoot.split('/').pop()}`, } ); @@ -1106,14 +1128,10 @@ function determineEntryFields( }; case 'vite': return { - // Since we're publishing both formats, skip the type field. - // Bundlers or Node will determine the entry point to use. + type: 'module', main: options.isUsingTsSolutionConfig ? './dist/index.js' : './index.js', - module: options.isUsingTsSolutionConfig - ? './dist/index.mjs' - : './index.mjs', typings: options.isUsingTsSolutionConfig ? './dist/index.d.ts' : './index.d.ts', diff --git a/packages/js/src/utils/typescript/configuration.ts b/packages/js/src/utils/typescript/configuration.ts index 217db92238425..f4a55bbbdd7f3 100644 --- a/packages/js/src/utils/typescript/configuration.ts +++ b/packages/js/src/utils/typescript/configuration.ts @@ -1,7 +1,8 @@ import type { Tree } from '@nx/devkit'; import { dirname } from 'path'; -import type { CompilerOptions, System } from 'typescript'; +import type { CompilerOptions, ParsedCommandLine, System } from 'typescript'; import { ensureTypescript } from './ensure-typescript'; +import { readTsConfig } from './ts-config'; type CompilerOptionsEnumProps = Pick< CompilerOptions, diff --git a/packages/js/src/utils/typescript/ts-config.ts b/packages/js/src/utils/typescript/ts-config.ts index a68d798a3fcb0..61705cf76cece 100644 --- a/packages/js/src/utils/typescript/ts-config.ts +++ b/packages/js/src/utils/typescript/ts-config.ts @@ -24,6 +24,22 @@ export function readTsConfig( ); } +export function readTsConfigFromTree( + tree: Tree, + tsConfigPath: string +): ts.ParsedCommandLine { + if (!tsModule) { + tsModule = ensureTypescript(); + } + + const tsSysFromTree: ts.System = { + ...tsModule.sys, + readFile: (path) => tree.read(path, 'utf-8'), + }; + + return readTsConfig(tsConfigPath, tsSysFromTree); +} + export function getRootTsConfigPathInTree(tree: Tree): string | null { for (const path of ['tsconfig.base.json', 'tsconfig.json']) { if (tree.exists(path)) { diff --git a/packages/js/src/utils/typescript/ts-solution-setup.ts b/packages/js/src/utils/typescript/ts-solution-setup.ts index c726556004337..65874d2fae9c1 100644 --- a/packages/js/src/utils/typescript/ts-solution-setup.ts +++ b/packages/js/src/utils/typescript/ts-solution-setup.ts @@ -142,7 +142,7 @@ export function updateTsconfigFiles( }; const excludeSet: Set = json.exclude - ? new Set(['dist', ...json.exclude, ...exclude]) + ? new Set(['out-tsc', 'dist', ...json.exclude, ...exclude]) : new Set(exclude); json.exclude = Array.from(excludeSet); diff --git a/packages/nest/src/generators/application/application.spec.ts b/packages/nest/src/generators/application/application.spec.ts index de6999353a90c..8c30258c28d81 100644 --- a/packages/nest/src/generators/application/application.spec.ts +++ b/packages/nest/src/generators/application/application.spec.ts @@ -261,9 +261,6 @@ describe('application generator', () => { `); expect(readJson(tree, 'myapp/tsconfig.json')).toMatchInlineSnapshot(` { - "compilerOptions": { - "esModuleInterop": true, - }, "extends": "../tsconfig.base.json", "files": [], "include": [], @@ -291,6 +288,7 @@ describe('application generator', () => { ], }, "exclude": [ + "out-tsc", "dist", "jest.config.ts", "src/**/*.spec.ts", diff --git a/packages/next/src/generators/application/application.spec.ts b/packages/next/src/generators/application/application.spec.ts index a1977fc601f22..8b776f7ba69f4 100644 --- a/packages/next/src/generators/application/application.spec.ts +++ b/packages/next/src/generators/application/application.spec.ts @@ -922,6 +922,7 @@ describe('app (legacy)', () => { "compilerOptions": { "allowJs": true, "allowSyntheticDefaultImports": true, + "emitDeclarationOnly": false, "esModuleInterop": true, "forceConsistentCasingInFileNames": true, "incremental": true, @@ -955,6 +956,7 @@ describe('app (legacy)', () => { ], }, "exclude": [ + "out-tsc", "dist", "node_modules", "jest.config.ts", @@ -1013,16 +1015,16 @@ describe('app (legacy)', () => { { "compilerOptions": { "allowJs": true, - "outDir": "dist", + "outDir": "out-tsc/cypress", "sourceMap": false, - "tsBuildInfoFile": "dist/tsconfig.tsbuildinfo", "types": [ "cypress", "node", ], }, "exclude": [ - "dist", + "out-tsc", + "test-output", ], "extends": "../tsconfig.base.json", "include": [ diff --git a/packages/next/src/generators/application/files/common/tsconfig.json__tmpl__ b/packages/next/src/generators/application/files/common/tsconfig.json__tmpl__ index e82f281c5a6f6..3289efde05631 100644 --- a/packages/next/src/generators/application/files/common/tsconfig.json__tmpl__ +++ b/packages/next/src/generators/application/files/common/tsconfig.json__tmpl__ @@ -5,6 +5,7 @@ <% if (style === '@emotion/styled') { %>"jsxImportSource": "@emotion/react",<% } %> "strict": true, "noEmit": true, + "emitDeclarationOnly": false, "esModuleInterop": true, "module": "esnext", "moduleResolution": "bundler", diff --git a/packages/next/src/generators/library/library.ts b/packages/next/src/generators/library/library.ts index 0269a3cf36a2c..55ad331a7935d 100644 --- a/packages/next/src/generators/library/library.ts +++ b/packages/next/src/generators/library/library.ts @@ -15,7 +15,10 @@ import { nextInitGenerator } from '../init/init'; import { Schema } from './schema'; import { normalizeOptions } from './lib/normalize-options'; import { eslintConfigNextVersion, tsLibVersion } from '../../utils/versions'; -import { updateTsconfigFiles } from '@nx/js/src/utils/typescript/ts-solution-setup'; +import { + isUsingTsSolutionSetup, + updateTsconfigFiles, +} from '@nx/js/src/utils/typescript/ts-solution-setup'; export async function libraryGenerator(host: Tree, rawOptions: Schema) { return await libraryGeneratorInternal(host, { @@ -106,7 +109,11 @@ export async function libraryGeneratorInternal(host: Tree, rawOptions: Schema) { } ` ); - addTsConfigPath(host, `${options.importPath}/server`, [serverEntryPath]); + + const isTsSolutionSetup = isUsingTsSolutionSetup(host); + if (!options.skipTsConfig && !isTsSolutionSetup) { + addTsConfigPath(host, `${options.importPath}/server`, [serverEntryPath]); + } updateJson( host, diff --git a/packages/node/src/generators/application/application.spec.ts b/packages/node/src/generators/application/application.spec.ts index 3c64143e1b473..cd721ec774c17 100644 --- a/packages/node/src/generators/application/application.spec.ts +++ b/packages/node/src/generators/application/application.spec.ts @@ -639,9 +639,6 @@ describe('app', () => { `); expect(readJson(tree, 'myapp/tsconfig.json')).toMatchInlineSnapshot(` { - "compilerOptions": { - "esModuleInterop": true, - }, "extends": "../tsconfig.base.json", "files": [], "include": [], @@ -667,6 +664,7 @@ describe('app', () => { ], }, "exclude": [ + "out-tsc", "dist", "jest.config.ts", "src/**/*.spec.ts", diff --git a/packages/node/src/generators/application/application.ts b/packages/node/src/generators/application/application.ts index 9709a8d7f62cb..76659be06aab9 100644 --- a/packages/node/src/generators/application/application.ts +++ b/packages/node/src/generators/application/application.ts @@ -398,6 +398,10 @@ function addProjectDependencies( } function updateTsConfigOptions(tree: Tree, options: NormalizedSchema) { + if (options.isUsingTsSolutionConfig) { + return; + } + updateJson(tree, `${options.appProjectRoot}/tsconfig.json`, (json) => { if (options.rootProject) { return { diff --git a/packages/nuxt/src/generators/application/application.spec.ts b/packages/nuxt/src/generators/application/application.spec.ts index d5c222c75a2d1..5553fdd417b45 100644 --- a/packages/nuxt/src/generators/application/application.spec.ts +++ b/packages/nuxt/src/generators/application/application.spec.ts @@ -269,6 +269,7 @@ describe('app', () => { "rootDir": "src", }, "exclude": [ + "out-tsc", "dist", "vite.config.ts", "vite.config.mts", @@ -339,12 +340,12 @@ describe('app', () => { { "compilerOptions": { "allowJs": true, - "outDir": "dist", + "outDir": "out-tsc/playwright", "sourceMap": false, - "tsBuildInfoFile": "dist/tsconfig.tsbuildinfo", }, "exclude": [ - "dist", + "out-tsc", + "test-output", "eslint.config.js", "eslint.config.mjs", "eslint.config.cjs", diff --git a/packages/nuxt/src/generators/application/lib/add-e2e.ts b/packages/nuxt/src/generators/application/lib/add-e2e.ts index 624f53e2ff66d..a2cc76e9d9cf1 100644 --- a/packages/nuxt/src/generators/application/lib/add-e2e.ts +++ b/packages/nuxt/src/generators/application/lib/add-e2e.ts @@ -1,10 +1,10 @@ import { addProjectConfiguration, ensurePackage, - getPackageManagerCommand, joinPathFragments, readNxJson, Tree, + writeJson, } from '@nx/devkit'; import { getE2EWebServerInfo } from '@nx/devkit/src/generators/e2e-web-server-info-utils'; import { nxVersion } from '../../../utils/versions'; @@ -25,14 +25,31 @@ export async function addE2e(host: Tree, options: NormalizedSchema) { const { configurationGenerator } = ensurePackage< typeof import('@nx/cypress') >('@nx/cypress', nxVersion); - addProjectConfiguration(host, options.e2eProjectName, { - projectType: 'application', - root: options.e2eProjectRoot, - sourceRoot: joinPathFragments(options.e2eProjectRoot, 'src'), - targets: {}, - tags: [], - implicitDependencies: [options.projectName], - }); + if (options.isUsingTsSolutionConfig) { + writeJson( + host, + joinPathFragments(options.e2eProjectRoot, 'package.json'), + { + name: options.e2eProjectName, + version: '0.0.1', + private: true, + nx: { + projectType: 'application', + sourceRoot: joinPathFragments(options.e2eProjectRoot, 'src'), + implicitDependencies: [options.projectName], + }, + } + ); + } else { + addProjectConfiguration(host, options.e2eProjectName, { + projectType: 'application', + root: options.e2eProjectRoot, + sourceRoot: joinPathFragments(options.e2eProjectRoot, 'src'), + targets: {}, + tags: [], + implicitDependencies: [options.projectName], + }); + } const e2eTask = await configurationGenerator(host, { ...options, project: options.e2eProjectName, @@ -80,12 +97,30 @@ export async function addE2e(host: Tree, options: NormalizedSchema) { const { configurationGenerator } = ensurePackage< typeof import('@nx/playwright') >('@nx/playwright', nxVersion); - addProjectConfiguration(host, options.e2eProjectName, { - root: options.e2eProjectRoot, - sourceRoot: joinPathFragments(options.e2eProjectRoot, 'src'), - targets: {}, - implicitDependencies: [options.projectName], - }); + if (options.isUsingTsSolutionConfig) { + writeJson( + host, + joinPathFragments(options.e2eProjectRoot, 'package.json'), + { + name: options.e2eProjectName, + version: '0.0.1', + private: true, + nx: { + projectType: 'application', + sourceRoot: joinPathFragments(options.e2eProjectRoot, 'src'), + implicitDependencies: [options.projectName], + }, + } + ); + } else { + addProjectConfiguration(host, options.e2eProjectName, { + projectType: 'application', + root: options.e2eProjectRoot, + sourceRoot: joinPathFragments(options.e2eProjectRoot, 'src'), + targets: {}, + implicitDependencies: [options.projectName], + }); + } const e2eTask = await configurationGenerator(host, { project: options.e2eProjectName, skipFormat: true, diff --git a/packages/playwright/src/generators/configuration/configuration.ts b/packages/playwright/src/generators/configuration/configuration.ts index 5e9d6030a5f20..7b5ab7c65ee8f 100644 --- a/packages/playwright/src/generators/configuration/configuration.ts +++ b/packages/playwright/src/generators/configuration/configuration.ts @@ -95,18 +95,17 @@ export async function configurationGeneratorInternal( }; if (isTsSolutionSetup) { + tsconfig.exclude = ['out-tsc', 'test-output']; // skip eslint from typechecking since it extends from root file that is outside rootDir if (options.linter === 'eslint') { - tsconfig.exclude = [ - 'dist', + tsconfig.exclude.push( 'eslint.config.js', 'eslint.config.mjs', - 'eslint.config.cjs', - ]; + 'eslint.config.cjs' + ); } - tsconfig.compilerOptions.outDir = 'dist'; - tsconfig.compilerOptions.tsBuildInfoFile = 'dist/tsconfig.tsbuildinfo'; + tsconfig.compilerOptions.outDir = 'out-tsc/playwright'; if (!options.rootProject) { updateJson(tree, 'tsconfig.json', (json) => { diff --git a/packages/react-native/src/generators/application/application.spec.ts b/packages/react-native/src/generators/application/application.spec.ts index 51f3fc653e930..395e8d100f473 100644 --- a/packages/react-native/src/generators/application/application.spec.ts +++ b/packages/react-native/src/generators/application/application.spec.ts @@ -293,18 +293,6 @@ describe('app', () => { `); expect(readJson(tree, 'my-app/tsconfig.json')).toMatchInlineSnapshot(` { - "compilerOptions": { - "allowSyntheticDefaultImports": true, - "declaration": true, - "jsx": "react-native", - "lib": [ - "dom", - "esnext", - ], - "moduleResolution": "node", - "resolveJsonModule": true, - "skipLibCheck": true, - }, "extends": "../tsconfig.base.json", "files": [], "include": [], @@ -335,6 +323,7 @@ describe('app', () => { ], }, "exclude": [ + "out-tsc", "dist", "src/**/*.test.ts", "src/**/*.spec.ts", diff --git a/packages/react-native/src/generators/application/files/app/tsconfig.json.template b/packages/react-native/src/generators/application/files/app/tsconfig.json.template index 388b961ab2121..6ee93c43cc885 100644 --- a/packages/react-native/src/generators/application/files/app/tsconfig.json.template +++ b/packages/react-native/src/generators/application/files/app/tsconfig.json.template @@ -1,5 +1,6 @@ { "extends": "<%= rootTsConfigPath %>", + <%_ if (!isTsSolutionSetup) { _%> "compilerOptions": { "allowSyntheticDefaultImports": true, "jsx": "react-native", @@ -9,6 +10,7 @@ "resolveJsonModule": true, "declaration": true }, + <%_ } _%> "files": [], "include": [], "references": [ diff --git a/packages/react-native/src/generators/application/lib/normalize-options.spec.ts b/packages/react-native/src/generators/application/lib/normalize-options.spec.ts index c0d54f4bf5979..d482db00ac718 100644 --- a/packages/react-native/src/generators/application/lib/normalize-options.spec.ts +++ b/packages/react-native/src/generators/application/lib/normalize-options.spec.ts @@ -43,6 +43,7 @@ describe('Normalize Options', () => { rootProject: false, e2eProjectName: 'my-app-e2e', e2eProjectRoot: 'my-app-e2e', + isTsSolutionSetup: false, }); }); @@ -78,6 +79,7 @@ describe('Normalize Options', () => { rootProject: false, e2eProjectName: 'myApp-e2e', e2eProjectRoot: 'myApp-e2e', + isTsSolutionSetup: false, }); }); @@ -114,6 +116,7 @@ describe('Normalize Options', () => { rootProject: false, e2eProjectName: 'my-app-e2e', e2eProjectRoot: 'directory/my-app-e2e', + isTsSolutionSetup: false, }); }); @@ -149,6 +152,7 @@ describe('Normalize Options', () => { rootProject: false, e2eProjectName: 'my-app-e2e', e2eProjectRoot: 'directory/my-app-e2e', + isTsSolutionSetup: false, }); }); @@ -185,6 +189,7 @@ describe('Normalize Options', () => { rootProject: false, e2eProjectName: 'my-app-e2e', e2eProjectRoot: 'my-app-e2e', + isTsSolutionSetup: false, }); }); }); diff --git a/packages/react-native/src/generators/application/lib/normalize-options.ts b/packages/react-native/src/generators/application/lib/normalize-options.ts index 685ac7b57d317..dfcde96a76a3b 100644 --- a/packages/react-native/src/generators/application/lib/normalize-options.ts +++ b/packages/react-native/src/generators/application/lib/normalize-options.ts @@ -4,6 +4,7 @@ import { ensureProjectName, } from '@nx/devkit/src/generators/project-name-and-root-utils'; import { Schema } from '../schema'; +import { isUsingTsSolutionSetup } from '@nx/js/src/utils/typescript/ts-solution-setup'; export interface NormalizedSchema extends Schema { className: string; // app name in class case @@ -18,6 +19,7 @@ export interface NormalizedSchema extends Schema { rootProject: boolean; e2eProjectName: string; e2eProjectRoot: string; + isTsSolutionSetup: boolean; } export async function normalizeOptions( @@ -70,5 +72,6 @@ export async function normalizeOptions( rootProject, e2eProjectName, e2eProjectRoot, + isTsSolutionSetup: isUsingTsSolutionSetup(host), }; } diff --git a/packages/react-native/src/generators/library/files/lib/tsconfig.json.template b/packages/react-native/src/generators/library/files/lib/tsconfig.json.template index d9affba903da0..4723ebd058283 100644 --- a/packages/react-native/src/generators/library/files/lib/tsconfig.json.template +++ b/packages/react-native/src/generators/library/files/lib/tsconfig.json.template @@ -1,11 +1,13 @@ { "extends": "<%= rootTsConfigPath %>", + <%_ if (!isUsingTsSolutionConfig) { _%> "compilerOptions": { "jsx": "react-jsx", "allowJs": true, "esModuleInterop": true, "allowSyntheticDefaultImports": true }, + <%_ } _%> "files": [], "include": [], "references": [ diff --git a/packages/react-native/src/generators/library/library.ts b/packages/react-native/src/generators/library/library.ts index 4e42ac8cbddb0..ea4c9a69725b1 100644 --- a/packages/react-native/src/generators/library/library.ts +++ b/packages/react-native/src/generators/library/library.ts @@ -34,10 +34,7 @@ import { NormalizedSchema, normalizeOptions } from './lib/normalize-options'; import { Schema } from './schema'; import { ensureDependencies } from '../../utils/ensure-dependencies'; import { logShowProjectCommand } from '@nx/devkit/src/utils/log-show-project-command'; -import { - isUsingTsSolutionSetup, - updateTsconfigFiles, -} from '@nx/js/src/utils/typescript/ts-solution-setup'; +import { updateTsconfigFiles } from '@nx/js/src/utils/typescript/ts-solution-setup'; import { getImportPath } from '@nx/js/src/utils/get-import-path'; export async function reactNativeLibraryGenerator( @@ -107,7 +104,7 @@ export async function reactNativeLibraryGeneratorInternal( updateLibPackageNpmScope(host, options); } - if (!options.skipTsConfig) { + if (!options.skipTsConfig && !options.isUsingTsSolutionConfig) { addTsConfigPath(host, options.importPath, [ joinPathFragments( options.projectRoot, @@ -222,6 +219,10 @@ async function addProject( } function updateTsConfig(tree: Tree, options: NormalizedSchema) { + if (options.isUsingTsSolutionConfig) { + return; + } + updateJson( tree, joinPathFragments(options.projectRoot, 'tsconfig.json'), diff --git a/packages/react/src/generators/application/application.spec.ts b/packages/react/src/generators/application/application.spec.ts index 3da3698851e8e..15c1cde0110c3 100644 --- a/packages/react/src/generators/application/application.spec.ts +++ b/packages/react/src/generators/application/application.spec.ts @@ -86,20 +86,31 @@ describe('app', () => { addPlugin: true, }); - const snapshot = ` + expect( + appTree.read('my-app-e2e/cypress.config.ts', 'utf-8') + ).toMatchInlineSnapshot( + ` "import { nxE2EPreset } from '@nx/cypress/plugins/cypress-preset'; - - import { defineConfig } from 'cypress'; + import { defineConfig } from 'cypress'; export default defineConfig({ - e2e: { ...nxE2EPreset(__filename, {"cypressDir":"src","bundler":"vite","webServerCommands":{"default":"${packageCmd} nx run my-app:serve","production":"${packageCmd} nx run my-app:preview"},"ciWebServerCommand":"${packageCmd} nx run my-app:preview","ciBaseUrl":"http://localhost:4300"}), - baseUrl: 'http://localhost:4200' } + e2e: { + ...nxE2EPreset(__filename, { + "cypressDir": "src", + "bundler": "vite", + "webServerCommands": { + "default": "${packageCmd} nx run my-app:serve", + "production": "${packageCmd} nx run my-app:preview" + }, + "ciWebServerCommand": "${packageCmd} nx run my-app:preview", + "ciBaseUrl": "http://localhost:4300" + }), + baseUrl: 'http://localhost:4200' + } }); " - `; - expect( - appTree.read('my-app-e2e/cypress.config.ts', 'utf-8') - ).toMatchInlineSnapshot(snapshot); + ` + ); }); it('should setup playwright correctly for vite', async () => { @@ -1340,6 +1351,7 @@ describe('app', () => { ], }, "exclude": [ + "out-tsc", "dist", "src/**/*.spec.ts", "src/**/*.test.ts", @@ -1412,12 +1424,12 @@ describe('app', () => { { "compilerOptions": { "allowJs": true, - "outDir": "dist", + "outDir": "out-tsc/playwright", "sourceMap": false, - "tsBuildInfoFile": "dist/tsconfig.tsbuildinfo", }, "exclude": [ - "dist", + "out-tsc", + "test-output", "eslint.config.js", "eslint.config.mjs", "eslint.config.cjs", diff --git a/packages/react/src/generators/host/host.rspack.spec.ts b/packages/react/src/generators/host/host.rspack.spec.ts index 032ab68ce10d6..a3fa22b969eda 100644 --- a/packages/react/src/generators/host/host.rspack.spec.ts +++ b/packages/react/src/generators/host/host.rspack.spec.ts @@ -516,6 +516,7 @@ describe('hostGenerator', () => { ], }, "exclude": [ + "out-tsc", "dist", "src/**/*.spec.ts", "src/**/*.test.ts", diff --git a/packages/react/src/generators/library/library.spec.ts b/packages/react/src/generators/library/library.spec.ts index 13a46b13c809d..096eb17e4c0d9 100644 --- a/packages/react/src/generators/library/library.spec.ts +++ b/packages/react/src/generators/library/library.spec.ts @@ -1047,6 +1047,7 @@ module.exports = withNx( ], }, "exclude": [ + "out-tsc", "dist", "**/*.spec.ts", "**/*.test.ts", diff --git a/packages/remix/src/generators/application/__snapshots__/application.impl.spec.ts.snap b/packages/remix/src/generators/application/__snapshots__/application.impl.spec.ts.snap index 23338adb44680..7aa583a3a96b0 100644 --- a/packages/remix/src/generators/application/__snapshots__/application.impl.spec.ts.snap +++ b/packages/remix/src/generators/application/__snapshots__/application.impl.spec.ts.snap @@ -134,7 +134,6 @@ export default function Index() { exports[`Remix Application Integrated Repo --e2eTestRunner should generate a cypress e2e application for the app 1`] = ` "import { nxE2EPreset } from '@nx/cypress/plugins/cypress-preset'; - import { defineConfig } from 'cypress'; export default defineConfig({ @@ -386,7 +385,6 @@ export default function Index() { exports[`Remix Application Standalone Project Repo --e2eTestRunner should generate a cypress e2e application for the app 1`] = ` "import { nxE2EPreset } from '@nx/cypress/plugins/cypress-preset'; - import { defineConfig } from 'cypress'; export default defineConfig({ diff --git a/packages/remix/src/generators/application/application.impl.spec.ts b/packages/remix/src/generators/application/application.impl.spec.ts index 9737ca910b0e4..60319d57a2975 100644 --- a/packages/remix/src/generators/application/application.impl.spec.ts +++ b/packages/remix/src/generators/application/application.impl.spec.ts @@ -431,6 +431,7 @@ describe('Remix Application', () => { ], }, "exclude": [ + "out-tsc", "dist", "tests/**/*.spec.ts", "tests/**/*.test.ts", @@ -500,12 +501,12 @@ describe('Remix Application', () => { { "compilerOptions": { "allowJs": true, - "outDir": "dist", + "outDir": "out-tsc/playwright", "sourceMap": false, - "tsBuildInfoFile": "dist/tsconfig.tsbuildinfo", }, "exclude": [ - "dist", + "out-tsc", + "test-output", "eslint.config.js", "eslint.config.mjs", "eslint.config.cjs", diff --git a/packages/vue/src/generators/application/__snapshots__/application.spec.ts.snap b/packages/vue/src/generators/application/__snapshots__/application.spec.ts.snap index 2944d649a680a..9ce09f61339b3 100644 --- a/packages/vue/src/generators/application/__snapshots__/application.spec.ts.snap +++ b/packages/vue/src/generators/application/__snapshots__/application.spec.ts.snap @@ -123,7 +123,6 @@ describe('App', () => { exports[`application generator should set up project correctly for cypress 5`] = ` "import { nxE2EPreset } from '@nx/cypress/plugins/cypress-preset'; - import { defineConfig } from 'cypress'; export default defineConfig({ diff --git a/packages/vue/src/generators/application/application.spec.ts b/packages/vue/src/generators/application/application.spec.ts index 7aa6caa4ff498..5f5812e26c8fd 100644 --- a/packages/vue/src/generators/application/application.spec.ts +++ b/packages/vue/src/generators/application/application.spec.ts @@ -211,6 +211,7 @@ describe('application generator', () => { ], }, "exclude": [ + "out-tsc", "dist", "src/**/*.spec.ts", "src/**/*.test.ts", diff --git a/packages/vue/src/generators/library/library.spec.ts b/packages/vue/src/generators/library/library.spec.ts index 79ebba4e39a17..a089a5135f965 100644 --- a/packages/vue/src/generators/library/library.spec.ts +++ b/packages/vue/src/generators/library/library.spec.ts @@ -531,6 +531,7 @@ module.exports = [ ], }, "exclude": [ + "out-tsc", "dist", "src/**/__tests__/*", "src/**/*.spec.vue", diff --git a/packages/web/src/generators/application/application.spec.ts b/packages/web/src/generators/application/application.spec.ts index e30f5ae87411b..4f56ce563359a 100644 --- a/packages/web/src/generators/application/application.spec.ts +++ b/packages/web/src/generators/application/application.spec.ts @@ -184,7 +184,6 @@ describe('app', () => { expect(tree.read('cool-app-e2e/cypress.config.ts', 'utf-8')) .toMatchInlineSnapshot(` "import { nxE2EPreset } from '@nx/cypress/plugins/cypress-preset'; - import { defineConfig } from 'cypress'; export default defineConfig({ @@ -217,7 +216,6 @@ describe('app', () => { expect(tree.read('cool-app-e2e/cypress.config.ts', 'utf-8')) .toMatchInlineSnapshot(` "import { nxE2EPreset } from '@nx/cypress/plugins/cypress-preset'; - import { defineConfig } from 'cypress'; export default defineConfig({