Skip to content

Commit

Permalink
fix(nuxt): use loadNuxtConfig to load nuxt config for plugin (#28795)
Browse files Browse the repository at this point in the history
<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr
-->

<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->

<!-- If this is a particularly complex change or feature addition, you
can request a dedicated Nx release for this pull request branch. Mention
someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they
will confirm if the PR warrants its own release for testing purposes,
and generate it for you if appropriate. -->

## Current Behavior
<!-- This is the behavior we have today -->
We switched to using `loadConfigFile` from `@nx/devkit` to load Nuxt
Config files when plugins were not isolated.
However, they are now, so we can use `loadNuxtConfig` again.

The effect of using `loadConfigFile` paired with Nuxt's auto-imports
resulted in inconsistent failures.



## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->
Use `loadNuxtConfig` when `NX_ISOLATE_PLUGINS=true`


## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #28506
Fixes #28374
  • Loading branch information
Coly010 authored Nov 5, 2024
1 parent 7e3f256 commit be7bfa4
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 be7bfa4

Please sign in to comment.