feat(rsbuild): move plugin export to root of package (#29415)

## Current Behavior
The Rsbuild plugin is exported at `@nx/rsbuild/plugin`


## Expected Behavior
Export the plugin from `@nx/rsbuild` i.e. the root of the package.
This commit is contained in:
Colum Ferry 2024-12-19 14:09:57 +00:00 committed by GitHub
parent 656d69b466
commit 2db82dd36d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
13 changed files with 58 additions and 24 deletions

View File

@ -27,7 +27,8 @@ export async function addE2e(
const hasNxBuildPlugin =
(options.bundler === 'webpack' && hasWebpackPlugin(tree)) ||
(options.bundler === 'rspack' && hasRspackPlugin(tree)) ||
(options.bundler === 'rsbuild' && hasRsbuildPlugin(tree)) ||
(options.bundler === 'rsbuild' &&
(await hasRsbuildPlugin(tree, options.appProjectRoot))) ||
(options.bundler === 'vite' && hasVitePlugin(tree));
let e2eWebServerInfo: E2EWebServerDetails = {

View File

@ -1,10 +1,8 @@
import { readNxJson, Tree } from '@nx/devkit';
import { ensurePackage, Tree } from '@nx/devkit';
import { nxVersion } from './versions';
export function hasRsbuildPlugin(tree: Tree) {
const nxJson = readNxJson(tree);
return !!nxJson.plugins?.some((p) =>
typeof p === 'string'
? p === '@nx/rsbuild/plugin'
: p.plugin === '@nx/rsbuild/plugin'
);
export async function hasRsbuildPlugin(tree: Tree, projectPath?: string) {
ensurePackage('@nx/rsbuild', nxVersion);
const { hasRsbuildPlugin } = await import('@nx/rsbuild/config-utils');
return hasRsbuildPlugin(tree, projectPath);
}

View File

@ -6,3 +6,4 @@ export {
} from './src/utils/ast-utils';
export * as versions from './src/utils/versions';
export { getRsbuildE2EWebServerInfo } from './src/utils/e2e-web-server-info-utils';
export { hasRsbuildPlugin } from './src/utils/has-rsbuild-plugin';

View File

@ -0,0 +1 @@
export { createNodesV2, RsbuildPluginOptions } from './src/plugins/plugin';

View File

@ -55,10 +55,6 @@
"./config-utils": {
"types": "./config-utils.d.ts",
"default": "./config-utils.js"
},
"./plugin": {
"types": "./plugin.d.ts",
"default": "./plugin.js"
}
}
}

View File

@ -1 +0,0 @@
export { createNodesV2, RsbuildPluginOptions } from './src/plugins/plugin';

View File

@ -43,7 +43,7 @@ export async function initGeneratorInternal(
await addPlugin(
tree,
await createProjectGraphAsync(),
'@nx/rsbuild/plugin',
'@nx/rsbuild',
createNodesV2,
{
buildTargetName: ['build', 'rsbuild:build', 'rsbuild-build'],

View File

@ -15,7 +15,7 @@ jest.mock('@nx/js/src/utils/typescript/ts-solution-setup', () => ({
isUsingTsSolutionSetup: jest.fn().mockReturnValue(false),
}));
describe('@nx/rsbuild/plugin', () => {
describe('@nx/rsbuild', () => {
let createNodesFunction = createNodesV2[1];
let context: CreateNodesContext;
let tempFs: TempFs;

View File

@ -22,7 +22,7 @@ export async function getRsbuildE2EWebServerInfo(
tree,
projectName,
{
plugin: '@nx/rsbuild/plugin',
plugin: '@nx/rsbuild',
serveTargetName: 'devTargetName',
serveStaticTargetName: 'previewTargetName',
configFilePath,

View File

@ -0,0 +1,33 @@
import { type Tree, readNxJson } from '@nx/devkit';
import { minimatch } from 'minimatch';
export function hasRsbuildPlugin(tree: Tree, projectPath?: string) {
const nxJson = readNxJson(tree);
if (!projectPath) {
return !!nxJson.plugins?.some((p) =>
typeof p === 'string' ? p === '@nx/rsbuild' : p.plugin === '@nx/rsbuild'
);
}
return !!nxJson.plugins?.some((p) => {
if (typeof p === 'string') {
return p === '@nx/rsbuild';
}
if (p.exclude) {
for (const exclude of p.exclude) {
if (minimatch(projectPath, exclude)) {
return false;
}
}
}
if (p.include) {
for (const include of p.include) {
if (minimatch(projectPath, include)) {
return true;
}
}
}
// if no include or exclude, then it's a match
return true;
});
}

View File

@ -114,7 +114,7 @@ describe('application generator', () => {
expect(listFiles(tree)).toMatchSnapshot();
expect(
readNxJson(tree).plugins.find(
(p) => typeof p !== 'string' && p.plugin === '@nx/rsbuild/plugin'
(p) => typeof p !== 'string' && p.plugin === '@nx/rsbuild'
)
).toMatchInlineSnapshot(`
{
@ -125,7 +125,7 @@ describe('application generator', () => {
"previewTargetName": "preview",
"typecheckTargetName": "typecheck",
},
"plugin": "@nx/rsbuild/plugin",
"plugin": "@nx/rsbuild",
}
`);
});

View File

@ -8,6 +8,7 @@ import {
import { webStaticServeGenerator } from '@nx/web';
import { nxVersion } from '../../../utils/versions';
import { hasRsbuildPlugin } from '../../../utils/has-rsbuild-plugin';
import { NormalizedSchema } from '../schema';
import { findPluginForConfigFile } from '@nx/devkit/src/utils/find-plugin-for-config-file';
import { addE2eCiTargetDefaults } from '@nx/devkit/src/generators/target-defaults-utils';
@ -20,11 +21,7 @@ export async function addE2e(
const nxJson = readNxJson(tree);
const hasPlugin =
options.bundler === 'rsbuild'
? nxJson.plugins?.find((p) =>
typeof p === 'string'
? p === '@nx/rsbuild/plugin'
: p.plugin === '@nx/rsbuild/plugin'
)
? await hasRsbuildPlugin(tree, options.appProjectRoot)
: nxJson.plugins?.find((p) =>
typeof p === 'string'
? p === '@nx/vite/plugin'

View File

@ -0,0 +1,8 @@
import { ensurePackage, Tree } from '@nx/devkit';
import { nxVersion } from './versions';
export async function hasRsbuildPlugin(tree: Tree, projectPath?: string) {
ensurePackage('@nx/rsbuild', nxVersion);
const { hasRsbuildPlugin } = await import('@nx/rsbuild/config-utils');
return hasRsbuildPlugin(tree, projectPath);
}