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,
|
unsetProjectNameAndRootFormat: false,
|
||||||
});
|
});
|
||||||
runCLI(
|
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(
|
runCLI(
|
||||||
`generate @nx/nuxt:component --directory=${app}/src/components/one --name=one --nameAndDirectoryFormat=as-provided --unitTestRunner=vitest`
|
`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",
|
"cwd": "my-app",
|
||||||
},
|
},
|
||||||
"outputs": [
|
"outputs": [
|
||||||
"{workspaceRoot}/dist/my-app/",
|
"{workspaceRoot}/dist/my-app/.nuxt",
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
"acme-serve-static": {
|
"acme-serve-static": {
|
||||||
@ -56,7 +56,7 @@ exports[`@nx/nuxt/plugin not root project should create nodes 1`] = `
|
|||||||
"cwd": "my-app",
|
"cwd": "my-app",
|
||||||
},
|
},
|
||||||
"outputs": [
|
"outputs": [
|
||||||
"{workspaceRoot}/dist/my-app/",
|
"{workspaceRoot}/dist/my-app/.nuxt",
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
"my-serve": {
|
"my-serve": {
|
||||||
@ -96,7 +96,7 @@ exports[`@nx/nuxt/plugin root project should create nodes 1`] = `
|
|||||||
"cwd": ".",
|
"cwd": ".",
|
||||||
},
|
},
|
||||||
"outputs": [
|
"outputs": [
|
||||||
"dist/my-app/",
|
"dist/my-app/.nuxt",
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
"build-static": {
|
"build-static": {
|
||||||
@ -118,7 +118,7 @@ exports[`@nx/nuxt/plugin root project should create nodes 1`] = `
|
|||||||
"cwd": ".",
|
"cwd": ".",
|
||||||
},
|
},
|
||||||
"outputs": [
|
"outputs": [
|
||||||
"dist/my-app/",
|
"dist/my-app/.nuxt",
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
"serve": {
|
"serve": {
|
||||||
|
|||||||
@ -2,8 +2,8 @@ import { CreateNodesContext } from '@nx/devkit';
|
|||||||
import { createNodes } from './plugin';
|
import { createNodes } from './plugin';
|
||||||
import { TempFs } from 'nx/src/internal-testing-utils/temp-fs';
|
import { TempFs } from 'nx/src/internal-testing-utils/temp-fs';
|
||||||
|
|
||||||
jest.mock('@nuxt/kit', () => ({
|
jest.mock('@nx/devkit/src/utils/config-utils', () => ({
|
||||||
loadNuxtConfig: jest.fn().mockImplementation(() => {
|
loadConfigFile: jest.fn().mockImplementation(() => {
|
||||||
return Promise.resolve({
|
return Promise.resolve({
|
||||||
buildDir: '../dist/my-app/.nuxt',
|
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 { projectGraphCacheDirectory } from 'nx/src/utils/cache-directory';
|
||||||
import { getNamedInputs } from '@nx/devkit/src/utils/get-named-inputs';
|
import { getNamedInputs } from '@nx/devkit/src/utils/get-named-inputs';
|
||||||
import { existsSync, readdirSync } from 'fs';
|
import { existsSync, readdirSync } from 'fs';
|
||||||
import { loadNuxtKitDynamicImport } from '../utils/executor-utils';
|
|
||||||
import { calculateHashForCreateNodes } from '@nx/devkit/src/utils/calculate-hash-for-create-nodes';
|
import { calculateHashForCreateNodes } from '@nx/devkit/src/utils/calculate-hash-for-create-nodes';
|
||||||
import { getLockFileName } from '@nx/js';
|
import { getLockFileName } from '@nx/js';
|
||||||
|
import { loadConfigFile } from '@nx/devkit/src/utils/config-utils';
|
||||||
|
|
||||||
const cachePath = join(projectGraphCacheDirectory, 'nuxt.hash');
|
const cachePath = join(projectGraphCacheDirectory, 'nuxt.hash');
|
||||||
const targetsCache = existsSync(cachePath) ? readTargetsCache() : {};
|
const targetsCache = existsSync(cachePath) ? readTargetsCache() : {};
|
||||||
@ -208,15 +208,16 @@ async function getInfoFromNuxtConfig(
|
|||||||
): Promise<{
|
): Promise<{
|
||||||
buildDir: string;
|
buildDir: string;
|
||||||
}> {
|
}> {
|
||||||
const { loadNuxtConfig } = await loadNuxtKitDynamicImport();
|
// 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(
|
||||||
const config = await loadNuxtConfig({
|
join(context.workspaceRoot, configFilePath)
|
||||||
cwd: joinPathFragments(context.workspaceRoot, projectRoot),
|
);
|
||||||
configFile: basename(configFilePath),
|
|
||||||
});
|
|
||||||
|
|
||||||
return {
|
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[];
|
buildOutputs: string[];
|
||||||
} {
|
} {
|
||||||
let nuxtBuildDir = nuxtConfig?.buildDir;
|
const buildOutputPath = normalizeOutputPath(
|
||||||
if (nuxtConfig?.buildDir && basename(nuxtConfig?.buildDir) === '.nuxt') {
|
nuxtConfig?.buildDir,
|
||||||
// if buildDir exists, it will be `something/something/.nuxt`
|
projectRoot
|
||||||
// we want the "general" outputPath to be `something/something`
|
);
|
||||||
nuxtBuildDir = nuxtConfig.buildDir.replace(
|
|
||||||
basename(nuxtConfig.buildDir),
|
|
||||||
''
|
|
||||||
);
|
|
||||||
}
|
|
||||||
const buildOutputPath = normalizeOutputPath(nuxtBuildDir, projectRoot);
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
buildOutputs: [buildOutputPath],
|
buildOutputs: [buildOutputPath],
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user