From e8c31d7ac72a6eeb98d07b61f6ae945a2612d8ac Mon Sep 17 00:00:00 2001 From: Emily Xiong Date: Fri, 12 May 2023 04:09:46 -0400 Subject: [PATCH 1/3] fix(react): fix react windows e2e tests (#16959) --- .../vite/src/executors/test/vitest.impl.ts | 13 +++++---- .../__snapshots__/configuration.spec.ts.snap | 12 ++++---- .../vite-config-edit-utils.spec.ts.snap | 28 +++++++++---------- packages/vite/src/utils/generator-utils.ts | 4 +-- packages/vite/src/utils/options-utils.ts | 9 +++--- .../src/utils/test-files/test-vite-configs.ts | 8 +++--- 6 files changed, 38 insertions(+), 36 deletions(-) diff --git a/packages/vite/src/executors/test/vitest.impl.ts b/packages/vite/src/executors/test/vitest.impl.ts index 06c81a3e4c4b4..af8f087b0896b 100644 --- a/packages/vite/src/executors/test/vitest.impl.ts +++ b/packages/vite/src/executors/test/vitest.impl.ts @@ -1,5 +1,6 @@ import { ExecutorContext, + joinPathFragments, logger, stripIndents, workspaceRoot, @@ -7,7 +8,7 @@ import { import { CoverageOptions, File, Reporter } from 'vitest'; import { loadConfigFromFile } from 'vite'; import { VitestExecutorOptions } from './schema'; -import { join, relative } from 'path'; +import { relative } from 'path'; import { existsSync } from 'fs'; class NxReporter implements Reporter { @@ -105,8 +106,8 @@ async function getSettings( : ({} as CoverageOptions); const viteConfigPath = options.config - ? join(context.root, options.config) - : findViteConfig(join(context.root, projectRoot)); + ? joinPathFragments(context.root, options.config) + : findViteConfig(joinPathFragments(context.root, projectRoot)); const resolved = await loadConfigFromFile( { @@ -148,8 +149,10 @@ function findViteConfig(projectRootFullPath: string): string { const allowsExt = ['js', 'mjs', 'ts', 'cjs', 'mts', 'cts']; for (const ext of allowsExt) { - if (existsSync(join(projectRootFullPath, `vite.config.${ext}`))) { - return join(projectRootFullPath, `vite.config.${ext}`); + if ( + existsSync(joinPathFragments(projectRootFullPath, `vite.config.${ext}`)) + ) { + return joinPathFragments(projectRootFullPath, `vite.config.${ext}`); } } } diff --git a/packages/vite/src/generators/configuration/__snapshots__/configuration.spec.ts.snap b/packages/vite/src/generators/configuration/__snapshots__/configuration.spec.ts.snap index e00e5984f2b16..7e944ee624768 100644 --- a/packages/vite/src/generators/configuration/__snapshots__/configuration.spec.ts.snap +++ b/packages/vite/src/generators/configuration/__snapshots__/configuration.spec.ts.snap @@ -6,7 +6,7 @@ import { defineConfig } from 'vite'; import react from '@vitejs/plugin-react'; import viteTsConfigPaths from 'vite-tsconfig-paths'; import dts from 'vite-plugin-dts'; -import { join } from 'path'; +import { joinPathFragments } from '@nx/devkit'; export default defineConfig({ cacheDir: '../node_modules/.vite/my-lib', @@ -14,7 +14,7 @@ export default defineConfig({ plugins: [ dts({ entryRoot: 'src', - tsConfigFilePath: join(__dirname, 'tsconfig.lib.json'), + tsConfigFilePath: joinPathFragments(__dirname, 'tsconfig.lib.json'), skipDiagnostics: true, }), react(), @@ -59,7 +59,7 @@ import { defineConfig } from 'vite'; import react from '@vitejs/plugin-react'; import viteTsConfigPaths from 'vite-tsconfig-paths'; import dts from 'vite-plugin-dts'; -import { join } from 'path'; +import { joinPathFragments } from '@nx/devkit'; export default defineConfig({ cacheDir: '../../node_modules/.vite/react-lib-nonb-jest', @@ -67,7 +67,7 @@ export default defineConfig({ plugins: [ dts({ entryRoot: 'src', - tsConfigFilePath: join(__dirname, 'tsconfig.lib.json'), + tsConfigFilePath: joinPathFragments(__dirname, 'tsconfig.lib.json'), skipDiagnostics: true, }), react(), @@ -152,7 +152,7 @@ exports[`@nx/vite:configuration library mode should set up non buildable library exports[`@nx/vite:configuration library mode should set up non buildable library which already has vite.config.ts correctly 1`] = ` "import dts from 'vite-plugin-dts'; -import { join } from 'path'; +import { joinPathFragments } from '@nx/devkit'; import { defineConfig } from 'vite'; import react from '@vitejs/plugin-react'; import viteTsConfigPaths from 'vite-tsconfig-paths'; @@ -185,7 +185,7 @@ export default defineConfig({ ], dts({ entryRoot: 'src', - tsConfigFilePath: join(__dirname, 'tsconfig.lib.json'), + tsConfigFilePath: joinPathFragments(__dirname, 'tsconfig.lib.json'), skipDiagnostics: true, }), ], diff --git a/packages/vite/src/utils/__snapshots__/vite-config-edit-utils.spec.ts.snap b/packages/vite/src/utils/__snapshots__/vite-config-edit-utils.spec.ts.snap index 5d249f27117cf..93f6c1d005d60 100644 --- a/packages/vite/src/utils/__snapshots__/vite-config-edit-utils.spec.ts.snap +++ b/packages/vite/src/utils/__snapshots__/vite-config-edit-utils.spec.ts.snap @@ -2,7 +2,7 @@ exports[`ensureViteConfigIsCorrect should add build and test options if defineConfig is empty 1`] = ` "import dts from 'vite-plugin-dts'; -import { join } from 'path'; +import { joinPathFragments } from '@nx/devkit'; /// import { defineConfig } from 'vite'; @@ -30,7 +30,7 @@ import { join } from 'path'; },plugins: [ dts({ entryRoot: 'src', - tsConfigFilePath: join(__dirname, 'tsconfig.lib.json'), + tsConfigFilePath: joinPathFragments(__dirname, 'tsconfig.lib.json'), skipDiagnostics: true, }), react(), @@ -51,7 +51,7 @@ import { join } from 'path'; exports[`ensureViteConfigIsCorrect should add build option but not update test option if test already setup 1`] = ` "import dts from 'vite-plugin-dts'; -import { join } from 'path'; +import { joinPathFragments } from '@nx/devkit'; import { defineConfig } from 'vite'; import react from '@vitejs/plugin-react'; import viteTsConfigPaths from 'vite-tsconfig-paths'; @@ -83,7 +83,7 @@ import { defineConfig } from 'vite'; ], dts({ entryRoot: 'src', - tsConfigFilePath: join(__dirname, 'tsconfig.lib.json'), + tsConfigFilePath: joinPathFragments(__dirname, 'tsconfig.lib.json'), skipDiagnostics: true, }), ], @@ -103,7 +103,7 @@ import { defineConfig } from 'vite'; exports[`ensureViteConfigIsCorrect should add build options if build options don't exist 1`] = ` "import dts from 'vite-plugin-dts'; -import { join } from 'path'; +import { joinPathFragments } from '@nx/devkit'; import { defineConfig } from 'vite'; import react from '@vitejs/plugin-react'; import viteTsConfigPaths from 'vite-tsconfig-paths'; @@ -135,7 +135,7 @@ import { defineConfig } from 'vite'; ], dts({ entryRoot: 'src', - tsConfigFilePath: join(__dirname, 'tsconfig.lib.json'), + tsConfigFilePath: joinPathFragments(__dirname, 'tsconfig.lib.json'), skipDiagnostics: true, }), ], @@ -155,7 +155,7 @@ import { defineConfig } from 'vite'; exports[`ensureViteConfigIsCorrect should add build options if defineConfig is not used 1`] = ` "import dts from 'vite-plugin-dts'; -import { join } from 'path'; +import { joinPathFragments } from '@nx/devkit'; import { defineConfig } from 'vite'; import react from '@vitejs/plugin-react'; import viteTsConfigPaths from 'vite-tsconfig-paths'; @@ -194,7 +194,7 @@ import { defineConfig } from 'vite'; ], dts({ entryRoot: 'src', - tsConfigFilePath: join(__dirname, 'tsconfig.lib.json'), + tsConfigFilePath: joinPathFragments(__dirname, 'tsconfig.lib.json'), skipDiagnostics: true, }), ], @@ -227,7 +227,7 @@ exports[`ensureViteConfigIsCorrect should add build options if it is using condi exports[`ensureViteConfigIsCorrect should add new build options if some build options already exist 1`] = ` "import dts from 'vite-plugin-dts'; -import { join } from 'path'; +import { joinPathFragments } from '@nx/devkit'; import { defineConfig } from 'vite'; import react from '@vitejs/plugin-react'; import viteTsConfigPaths from 'vite-tsconfig-paths'; @@ -242,7 +242,7 @@ import { defineConfig } from 'vite'; ], dts({ entryRoot: 'src', - tsConfigFilePath: join(__dirname, 'tsconfig.lib.json'), + tsConfigFilePath: joinPathFragments(__dirname, 'tsconfig.lib.json'), skipDiagnostics: true, }), ], @@ -276,13 +276,13 @@ exports[`ensureViteConfigIsCorrect should not do anything if project has everyth import react from '@vitejs/plugin-react'; import viteTsConfigPaths from 'vite-tsconfig-paths'; import dts from 'vite-plugin-dts'; - import { join } from 'path'; + import { joinPathFragments } from '@nx/devkit'; export default defineConfig({ plugins: [ dts({ entryRoot: 'src', - tsConfigFilePath: join(__dirname, 'tsconfig.lib.json'), + tsConfigFilePath: joinPathFragments(__dirname, 'tsconfig.lib.json'), skipDiagnostics: true, }), react(), @@ -323,7 +323,7 @@ exports[`ensureViteConfigIsCorrect should not do anything if project has everyth exports[`ensureViteConfigIsCorrect should update both test and build options - keep existing settings 1`] = ` "import dts from 'vite-plugin-dts'; -import { join } from 'path'; +import { joinPathFragments } from '@nx/devkit'; import { defineConfig } from 'vite'; import react from '@vitejs/plugin-react'; import viteTsConfigPaths from 'vite-tsconfig-paths'; @@ -338,7 +338,7 @@ import { defineConfig } from 'vite'; ], dts({ entryRoot: 'src', - tsConfigFilePath: join(__dirname, 'tsconfig.lib.json'), + tsConfigFilePath: joinPathFragments(__dirname, 'tsconfig.lib.json'), skipDiagnostics: true, }), ], diff --git a/packages/vite/src/utils/generator-utils.ts b/packages/vite/src/utils/generator-utils.ts index 7a8c0474b699a..ccd5d0fcf5065 100644 --- a/packages/vite/src/utils/generator-utils.ts +++ b/packages/vite/src/utils/generator-utils.ts @@ -519,7 +519,7 @@ export function createOrEditViteConfig( : options.includeLib ? `dts({ entryRoot: 'src', - tsConfigFilePath: join(__dirname, 'tsconfig.lib.json'), + tsConfigFilePath: joinPathFragments(__dirname, 'tsconfig.lib.json'), skipDiagnostics: true, }),` : ''; @@ -527,7 +527,7 @@ export function createOrEditViteConfig( const dtsImportLine = onlyVitest ? '' : options.includeLib - ? `import dts from 'vite-plugin-dts';\nimport { join } from 'path';` + ? `import dts from 'vite-plugin-dts';\nimport { joinPathFragments } from '@nx/devkit';` : ''; let viteConfigContent = ''; diff --git a/packages/vite/src/utils/options-utils.ts b/packages/vite/src/utils/options-utils.ts index b3c6d82ded916..a6ecf3896dfa4 100644 --- a/packages/vite/src/utils/options-utils.ts +++ b/packages/vite/src/utils/options-utils.ts @@ -6,7 +6,7 @@ import { readTargetOptions, } from '@nx/devkit'; import { existsSync } from 'fs'; -import { join, relative } from 'path'; +import { relative } from 'path'; import { BuildOptions, InlineConfig, @@ -19,7 +19,6 @@ import { ViteDevServerExecutorOptions } from '../executors/dev-server/schema'; import { VitePreviewServerExecutorOptions } from '../executors/preview-server/schema'; import replaceFiles from '../../plugins/rollup-replace-files.plugin'; import { ViteBuildExecutorOptions } from '../executors/build/schema'; -import * as path from 'path'; /** * Returns the path to the vite config file or undefined when not found. @@ -56,8 +55,8 @@ export function getViteServerProxyConfigPath( context.projectsConfigurations.projects[context.projectName].root; const proxyConfigPath = nxProxyConfig - ? join(context.root, nxProxyConfig) - : join(projectRoot, 'proxy.conf.json'); + ? joinPathFragments(context.root, nxProxyConfig) + : joinPathFragments(projectRoot, 'proxy.conf.json'); if (existsSync(proxyConfigPath)) { return proxyConfigPath; @@ -78,7 +77,7 @@ export function getViteSharedConfig( const projectRoot = context.projectsConfigurations.projects[context.projectName].root; - const root = path.relative( + const root = relative( context.cwd, joinPathFragments(context.root, projectRoot) ); diff --git a/packages/vite/src/utils/test-files/test-vite-configs.ts b/packages/vite/src/utils/test-files/test-vite-configs.ts index 3a6a5147ce7c1..cbd0fc5066433 100644 --- a/packages/vite/src/utils/test-files/test-vite-configs.ts +++ b/packages/vite/src/utils/test-files/test-vite-configs.ts @@ -154,13 +154,13 @@ export const hasEverything = ` import react from '@vitejs/plugin-react'; import viteTsConfigPaths from 'vite-tsconfig-paths'; import dts from 'vite-plugin-dts'; - import { join } from 'path'; + import { joinPathFragments } from '@nx/devkit'; export default defineConfig({ plugins: [ dts({ entryRoot: 'src', - tsConfigFilePath: join(__dirname, 'tsconfig.lib.json'), + tsConfigFilePath: joinPathFragments(__dirname, 'tsconfig.lib.json'), skipDiagnostics: true, }), react(), @@ -248,10 +248,10 @@ export const testOptionObject = { export const dtsPlugin = `dts({ entryRoot: 'src', - tsConfigFilePath: join(__dirname, 'tsconfig.lib.json'), + tsConfigFilePath: joinPathFragments(__dirname, 'tsconfig.lib.json'), skipDiagnostics: true, }),`; -export const dtsImportLine = `import dts from 'vite-plugin-dts';\nimport { join } from 'path';`; +export const dtsImportLine = `import dts from 'vite-plugin-dts';\nimport { joinPathFragments } from '@nx/devkit';`; export const pluginOption = ` plugins: [ From 55d40c01052a3b0dce76756d245f9af0f3ae61c7 Mon Sep 17 00:00:00 2001 From: hi2u <9689599+hi2u@users.noreply.github.com> Date: Sat, 13 May 2023 01:16:41 +1000 Subject: [PATCH 2/3] =?UTF-8?q?fix(node):=20build-esbuild-options.ts=20cod?= =?UTF-8?q?e-generated=20"exactMatch"=20prope=E2=80=A6=20(#16655)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../esbuild/src/executors/esbuild/lib/build-esbuild-options.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/esbuild/src/executors/esbuild/lib/build-esbuild-options.ts b/packages/esbuild/src/executors/esbuild/lib/build-esbuild-options.ts index 4c302327bb8b6..0aa84b66d25e0 100644 --- a/packages/esbuild/src/executors/esbuild/lib/build-esbuild-options.ts +++ b/packages/esbuild/src/executors/esbuild/lib/build-esbuild-options.ts @@ -226,7 +226,7 @@ export function getRegisterFileContent( // Path specifies a single entry point e.g. "a/b/src/index.ts". // This is the default setup. const { dir, name } = path.parse(pattern); - exactMatch = path.join(dir, `${name}${outExtension}`); + exactMatch = joinPathFragments(dir, `${name}${outExtension}`); } acc.push({ module: k, exactMatch, pattern }); return acc; From 504a639e2e1171562405abaa70519742b39bcafc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Jona=C5=A1?= Date: Fri, 12 May 2023 18:22:21 +0200 Subject: [PATCH 3/3] fix(core): resolve nx against command root if workspace not provided (#16859) --- packages/nx/bin/nx.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/nx/bin/nx.ts b/packages/nx/bin/nx.ts index 47ff78c576e46..1404f40f9fe75 100644 --- a/packages/nx/bin/nx.ts +++ b/packages/nx/bin/nx.ts @@ -14,6 +14,7 @@ import { major } from 'semver'; import { stripIndents } from '../src/utils/strip-indents'; import { readModulePackageJson } from '../src/utils/package-json'; import { execSync } from 'child_process'; +import { join } from 'path'; function main() { const workspace = findWorkspaceRoot(process.cwd()); @@ -123,23 +124,26 @@ function determineNxVersions( } function resolveNx(workspace: WorkspaceTypeAndRoot | null) { + // root relative to location of the nx bin + const globalsRoot = join(__dirname, '../../../'); + // prefer Nx installed in .nx/installation try { return require.resolve('nx/bin/nx.js', { - paths: workspace ? [getNxInstallationPath(workspace.dir)] : undefined, + paths: [getNxInstallationPath(workspace ? workspace.dir : globalsRoot)], }); } catch {} // check for root install try { return require.resolve('nx/bin/nx.js', { - paths: workspace ? [workspace.dir] : undefined, + paths: [workspace ? workspace.dir : globalsRoot], }); } catch { // TODO(v17): Remove this // fallback for old CLI install setup return require.resolve('@nrwl/cli/bin/nx.js', { - paths: workspace ? [workspace.dir] : undefined, + paths: [workspace ? workspace.dir : globalsRoot], }); } }