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 24, 2024
1 parent 096cefb commit d785db0
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 29 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
4 changes: 2 additions & 2 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 @@ -13,7 +13,7 @@ jest.mock('vite', () => ({

jest.mock('../utils/executor-utils', () => ({
loadViteDynamicImport: jest.fn().mockResolvedValue({
loadConfigFromFile: jest.fn().mockResolvedValue({
resolveConfig: jest.fn().mockResolvedValue({
path: 'vitest.config.ts',
config: {},
dependencies: [],
Expand Down
4 changes: 2 additions & 2 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 @@ -17,7 +17,7 @@ jest.mock('vite', () => ({

jest.mock('../utils/executor-utils', () => ({
loadViteDynamicImport: jest.fn().mockResolvedValue({
loadConfigFromFile: jest.fn().mockResolvedValue({
resolveConfig: jest.fn().mockResolvedValue({
path: 'vite.config.ts',
config: {
test: {
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/plugins/plugin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jest.mock('vite', () => ({

jest.mock('../utils/executor-utils', () => ({
loadViteDynamicImport: jest.fn().mockResolvedValue({
loadConfigFromFile: jest.fn().mockResolvedValue({
resolveConfig: jest.fn().mockResolvedValue({
path: 'vite.config.ts',
config: {},
dependencies: [],
Expand Down
16 changes: 11 additions & 5 deletions packages/vite/src/plugins/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,17 +92,23 @@ async function buildViteTargets(
options: VitePluginOptions,
context: CreateNodesContext
) {
const { loadConfigFromFile } = await loadViteDynamicImport();
const viteConfig = await loadConfigFromFile(
const remappedProjectRoot = projectRoot === '.' ? '' : projectRoot;
const absoluteConfigFilePath = joinPathFragments(
context.workspaceRoot,
remappedProjectRoot,
configFilePath
);
const { resolveConfig } = await loadViteDynamicImport();
const viteConfig = await resolveConfig(
{
command: 'build',
configFile: absoluteConfigFilePath,
mode: 'production',
},
configFilePath
'build'
);

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

Expand Down

0 comments on commit d785db0

Please sign in to comment.