fix(nuxt): use loadConfigFile from devkit rather than @nuxt/kit (#22571)
This commit is contained in:
parent
557f873c43
commit
ef81455b64
@ -17,7 +17,7 @@ describe('Nuxt Plugin', () => {
|
||||
unsetProjectNameAndRootFormat: false,
|
||||
});
|
||||
runCLI(
|
||||
`generate @nx/nuxt:app ${app} --unitTestRunner=vitest --projectNameAndRootFormat=as-provided e2eTestRunner=cypress`
|
||||
`generate @nx/nuxt:app ${app} --unitTestRunner=vitest --projectNameAndRootFormat=as-provided --e2eTestRunner=cypress`
|
||||
);
|
||||
runCLI(
|
||||
`generate @nx/nuxt:component --directory=${app}/src/components/one --name=one --nameAndDirectoryFormat=as-provided --unitTestRunner=vitest`
|
||||
|
||||
@ -25,7 +25,7 @@ exports[`@nx/nuxt/plugin not root project should create nodes 1`] = `
|
||||
"cwd": "my-app",
|
||||
},
|
||||
"outputs": [
|
||||
"{workspaceRoot}/dist/my-app/",
|
||||
"{workspaceRoot}/dist/my-app/.nuxt",
|
||||
],
|
||||
},
|
||||
"acme-serve-static": {
|
||||
@ -56,7 +56,7 @@ exports[`@nx/nuxt/plugin not root project should create nodes 1`] = `
|
||||
"cwd": "my-app",
|
||||
},
|
||||
"outputs": [
|
||||
"{workspaceRoot}/dist/my-app/",
|
||||
"{workspaceRoot}/dist/my-app/.nuxt",
|
||||
],
|
||||
},
|
||||
"my-serve": {
|
||||
@ -96,7 +96,7 @@ exports[`@nx/nuxt/plugin root project should create nodes 1`] = `
|
||||
"cwd": ".",
|
||||
},
|
||||
"outputs": [
|
||||
"dist/my-app/",
|
||||
"dist/my-app/.nuxt",
|
||||
],
|
||||
},
|
||||
"build-static": {
|
||||
@ -118,7 +118,7 @@ exports[`@nx/nuxt/plugin root project should create nodes 1`] = `
|
||||
"cwd": ".",
|
||||
},
|
||||
"outputs": [
|
||||
"dist/my-app/",
|
||||
"dist/my-app/.nuxt",
|
||||
],
|
||||
},
|
||||
"serve": {
|
||||
|
||||
@ -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',
|
||||
});
|
||||
|
||||
@ -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() : {};
|
||||
@ -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',
|
||||
};
|
||||
}
|
||||
|
||||
@ -226,16 +227,10 @@ function getOutputs(
|
||||
): {
|
||||
buildOutputs: string[];
|
||||
} {
|
||||
let nuxtBuildDir = nuxtConfig?.buildDir;
|
||||
if (nuxtConfig?.buildDir && basename(nuxtConfig?.buildDir) === '.nuxt') {
|
||||
// if buildDir exists, it will be `something/something/.nuxt`
|
||||
// we want the "general" outputPath to be `something/something`
|
||||
nuxtBuildDir = nuxtConfig.buildDir.replace(
|
||||
basename(nuxtConfig.buildDir),
|
||||
''
|
||||
);
|
||||
}
|
||||
const buildOutputPath = normalizeOutputPath(nuxtBuildDir, projectRoot);
|
||||
const buildOutputPath = normalizeOutputPath(
|
||||
nuxtConfig?.buildDir,
|
||||
projectRoot
|
||||
);
|
||||
|
||||
return {
|
||||
buildOutputs: [buildOutputPath],
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user