Skip to content

Commit

Permalink
fix(nuxt): use loadNuxtConfig to load nuxt config for plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Coly010 committed Nov 5, 2024
1 parent e2f5eaa commit 0f663e2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
4 changes: 3 additions & 1 deletion packages/nuxt/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@
"@nx/vite": "file:../vite",
"@phenomnomnominal/tsquery": "~5.0.1"
},
"peerDependencies": {},
"peerDependencies": {
"@nuxt/schema": "^3.10.0"
},
"publishConfig": {
"access": "public"
}
Expand Down
24 changes: 16 additions & 8 deletions packages/nuxt/src/plugins/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { NuxtOptions } from '@nuxt/schema';
import {
CreateDependencies,
CreateNodes,
Expand All @@ -8,13 +9,14 @@ import {
workspaceRoot,
writeJsonFile,
} from '@nx/devkit';
import { dirname, isAbsolute, join, relative } from 'path';
import { workspaceDataDirectory } from 'nx/src/utils/cache-directory';
import { loadConfigFile } from '@nx/devkit/src/utils/config-utils';
import { getNamedInputs } from '@nx/devkit/src/utils/get-named-inputs';
import { existsSync, readdirSync } from 'fs';
import { calculateHashForCreateNodes } from '@nx/devkit/src/utils/calculate-hash-for-create-nodes';
import { workspaceDataDirectory } from 'nx/src/utils/cache-directory';
import { getLockFileName } from '@nx/js';
import { loadConfigFile } from '@nx/devkit/src/utils/config-utils';
import { dirname, isAbsolute, join, relative } from 'path';
import { existsSync, readdirSync } from 'fs';
import { loadNuxtKitDynamicImport } from '../utils/executor-utils';

const cachePath = join(workspaceDataDirectory, 'nuxt.hash');
const targetsCache = readTargetsCache();
Expand Down Expand Up @@ -208,10 +210,16 @@ async function getInfoFromNuxtConfig(
): Promise<{
buildDir: string;
}> {
// 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)
);
let config: NuxtOptions;
if (process.env.NX_ISOLATE_PLUGINS !== 'false') {
config = await (
await loadNuxtKitDynamicImport()
).loadNuxtConfig({
configFile: configFilePath,
});
} else {
config = await loadConfigFile(join(context.workspaceRoot, configFilePath));
}
return {
buildDir:
config?.buildDir ??
Expand Down

0 comments on commit 0f663e2

Please sign in to comment.