Skip to content

Commit

Permalink
fix(nuxt): use loadConfigFile from devkit rather than @nuxt/kit
Browse files Browse the repository at this point in the history
  • Loading branch information
jaysoo committed Mar 28, 2024
1 parent 4b75255 commit 7d088cf
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
4 changes: 2 additions & 2 deletions packages/nuxt/src/plugins/plugin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { CreateNodesContext } from '@nx/devkit';
import { createNodes } from './plugin';
import { TempFs } from 'nx/src/internal-testing-utils/temp-fs';

jest.mock('@nuxt/kit', () => ({
loadNuxtConfig: jest.fn().mockImplementation(() => {
jest.mock('@nx/devkit/src/utils/config-utils', () => ({
loadConfigFile: jest.fn().mockImplementation(() => {
return Promise.resolve({
buildDir: '../dist/my-app/.nuxt',
});
Expand Down
19 changes: 10 additions & 9 deletions packages/nuxt/src/plugins/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import { basename, dirname, isAbsolute, join, relative } from 'path';
import { projectGraphCacheDirectory } from 'nx/src/utils/cache-directory';
import { getNamedInputs } from '@nx/devkit/src/utils/get-named-inputs';
import { existsSync, readdirSync } from 'fs';
import { loadNuxtKitDynamicImport } from '../utils/executor-utils';
import { calculateHashForCreateNodes } from '@nx/devkit/src/utils/calculate-hash-for-create-nodes';
import { getLockFileName } from '@nx/js';
import { loadConfigFile } from '@nx/devkit/src/utils/config-utils';

const cachePath = join(projectGraphCacheDirectory, 'nuxt.hash');
const targetsCache = existsSync(cachePath) ? readTargetsCache() : {};
Expand Down Expand Up @@ -208,15 +208,16 @@ async function getInfoFromNuxtConfig(
): Promise<{
buildDir: string;
}> {
const { loadNuxtConfig } = await loadNuxtKitDynamicImport();

const config = await loadNuxtConfig({
cwd: joinPathFragments(context.workspaceRoot, projectRoot),
configFile: basename(configFilePath),
});

// TODO(Colum): Once plugins are isolated we can go back to @nuxt/kit since each plugin will be run in its own worker.
const config = await loadConfigFile(
join(context.workspaceRoot, configFilePath)
);
return {
buildDir: config?.buildDir,
buildDir:
config?.buildDir ??
// Match .nuxt default build dir from '@nuxt/schema'
// See: https://github.com/nuxt/nuxt/blob/871404ae5673425aeedde82f123ea58aa7c6facf/packages/schema/src/config/common.ts#L117-L119
'.nuxt',
};
}

Expand Down

0 comments on commit 7d088cf

Please sign in to comment.