Skip to content

Commit

Permalink
fix(vite): PCV3 Plugin update to use resolveConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
ndcunningham committed Jan 23, 2024
1 parent 096cefb commit 1e99127
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,25 +46,6 @@ exports[`@nx/vite/plugin with test node root project should create nodes - with
"buildTarget": "build",
},
},
"test": {
"cache": true,
"command": "vitest run",
"inputs": [
"default",
"^production",
{
"externalDependencies": [
"vitest",
],
},
],
"options": {
"cwd": ".",
},
"outputs": [
"{projectRoot}/coverage",
],
},
},
},
},
Expand Down
12 changes: 1 addition & 11 deletions packages/vite/src/plugins/plugin-vitest.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { CreateNodesContext } from '@nx/devkit';
import { createNodes } from './plugin';

jest.mock('vite', () => ({
loadConfigFromFile: jest.fn().mockImplementation(() => {
resolveConfig: jest.fn().mockImplementation(() => {
return Promise.resolve({
path: 'vitest.config.ts',
config: {},
Expand All @@ -11,16 +11,6 @@ jest.mock('vite', () => ({
}),
}));

jest.mock('../utils/executor-utils', () => ({
loadViteDynamicImport: jest.fn().mockResolvedValue({
loadConfigFromFile: jest.fn().mockResolvedValue({
path: 'vitest.config.ts',
config: {},
dependencies: [],
}),
}),
}));

describe('@nx/vite/plugin', () => {
let createNodesFunction = createNodes[1];
let context: CreateNodesContext;
Expand Down
16 changes: 1 addition & 15 deletions packages/vite/src/plugins/plugin-with-test.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { CreateNodesContext } from '@nx/devkit';
import { createNodes } from './plugin';

jest.mock('vite', () => ({
loadConfigFromFile: jest.fn().mockImplementation(() => {
resolveConfig: jest.fn().mockImplementation(() => {
return Promise.resolve({
path: 'vite.config.ts',
config: {
Expand All @@ -15,20 +15,6 @@ jest.mock('vite', () => ({
}),
}));

jest.mock('../utils/executor-utils', () => ({
loadViteDynamicImport: jest.fn().mockResolvedValue({
loadConfigFromFile: jest.fn().mockResolvedValue({
path: 'vite.config.ts',
config: {
test: {
some: 'option',
},
},
dependencies: [],
}),
}),
}));

describe('@nx/vite/plugin with test node', () => {
let createNodesFunction = createNodes[1];
let context: CreateNodesContext;
Expand Down
12 changes: 1 addition & 11 deletions packages/vite/src/plugins/plugin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { createNodes } from './plugin';
import { TempFs } from 'nx/src/internal-testing-utils/temp-fs';

jest.mock('vite', () => ({
loadConfigFromFile: jest.fn().mockImplementation(() => {
resolveConfig: jest.fn().mockImplementation(() => {
return Promise.resolve({
path: 'vite.config.ts',
config: {},
Expand All @@ -12,16 +12,6 @@ jest.mock('vite', () => ({
}),
}));

jest.mock('../utils/executor-utils', () => ({
loadViteDynamicImport: jest.fn().mockResolvedValue({
loadConfigFromFile: jest.fn().mockResolvedValue({
path: 'vite.config.ts',
config: {},
dependencies: [],
}),
}),
}));

describe('@nx/vite/plugin', () => {
let createNodesFunction = createNodes[1];
let context: CreateNodesContext;
Expand Down
11 changes: 5 additions & 6 deletions packages/vite/src/plugins/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { existsSync, readdirSync } from 'fs';
import { calculateHashForCreateNodes } from '@nx/devkit/src/utils/calculate-hash-for-create-nodes';
import { projectGraphCacheDirectory } from 'nx/src/utils/cache-directory';
import { getLockFileName } from '@nx/js';
import { loadViteDynamicImport } from '../utils/executor-utils';
import { resolveConfig } from 'vite';

export interface VitePluginOptions {
buildTargetName?: string;
Expand Down Expand Up @@ -92,17 +92,16 @@ async function buildViteTargets(
options: VitePluginOptions,
context: CreateNodesContext
) {
const { loadConfigFromFile } = await loadViteDynamicImport();
const viteConfig = await loadConfigFromFile(
const viteConfig = await resolveConfig(
{
command: 'build',
configFile: configFilePath,
mode: 'production',
},
configFilePath
'build'
);

const { buildOutputs, testOutputs, hasTest } = getOutputs(
viteConfig?.config,
viteConfig,
projectRoot
);

Expand Down

0 comments on commit 1e99127

Please sign in to comment.