Skip to content

Commit

Permalink
Merge branch 'master' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
passbyval authored May 12, 2023
2 parents 16bcb31 + 504a639 commit 1fefa83
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 7 additions & 3 deletions packages/nx/bin/nx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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],
});
}
}
Expand Down
13 changes: 8 additions & 5 deletions packages/vite/src/executors/test/vitest.impl.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import {
ExecutorContext,
joinPathFragments,
logger,
stripIndents,
workspaceRoot,
} from '@nx/devkit';
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 {
Expand Down Expand Up @@ -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(
{
Expand Down Expand Up @@ -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}`);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ 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',
plugins: [
dts({
entryRoot: 'src',
tsConfigFilePath: join(__dirname, 'tsconfig.lib.json'),
tsConfigFilePath: joinPathFragments(__dirname, 'tsconfig.lib.json'),
skipDiagnostics: true,
}),
react(),
Expand Down Expand Up @@ -59,15 +59,15 @@ 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',
plugins: [
dts({
entryRoot: 'src',
tsConfigFilePath: join(__dirname, 'tsconfig.lib.json'),
tsConfigFilePath: joinPathFragments(__dirname, 'tsconfig.lib.json'),
skipDiagnostics: true,
}),
react(),
Expand Down Expand Up @@ -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';
Expand Down Expand Up @@ -185,7 +185,7 @@ export default defineConfig({
],
dts({
entryRoot: 'src',
tsConfigFilePath: join(__dirname, 'tsconfig.lib.json'),
tsConfigFilePath: joinPathFragments(__dirname, 'tsconfig.lib.json'),
skipDiagnostics: true,
}),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
/// <reference types="vitest" />
import { defineConfig } from 'vite';
Expand Down Expand Up @@ -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(),
Expand All @@ -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';
Expand Down Expand Up @@ -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,
}),
],
Expand All @@ -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';
Expand Down Expand Up @@ -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,
}),
],
Expand All @@ -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';
Expand Down Expand Up @@ -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,
}),
],
Expand Down Expand Up @@ -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';
Expand All @@ -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,
}),
],
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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';
Expand All @@ -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,
}),
],
Expand Down
4 changes: 2 additions & 2 deletions packages/vite/src/utils/generator-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -519,15 +519,15 @@ export function createOrEditViteConfig(
: options.includeLib
? `dts({
entryRoot: 'src',
tsConfigFilePath: join(__dirname, 'tsconfig.lib.json'),
tsConfigFilePath: joinPathFragments(__dirname, 'tsconfig.lib.json'),
skipDiagnostics: true,
}),`
: '';

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 = '';
Expand Down
9 changes: 4 additions & 5 deletions packages/vite/src/utils/options-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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.
Expand Down Expand Up @@ -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;
Expand All @@ -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)
);
Expand Down
8 changes: 4 additions & 4 deletions packages/vite/src/utils/test-files/test-vite-configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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: [
Expand Down

0 comments on commit 1fefa83

Please sign in to comment.