Skip to content

Commit 2db82dd

Browse files
authored
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.
1 parent 656d69b commit 2db82dd

File tree

13 files changed

+58
-24
lines changed

13 files changed

+58
-24
lines changed

packages/react/src/generators/application/lib/add-e2e.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ export async function addE2e(
2727
const hasNxBuildPlugin =
2828
(options.bundler === 'webpack' && hasWebpackPlugin(tree)) ||
2929
(options.bundler === 'rspack' && hasRspackPlugin(tree)) ||
30-
(options.bundler === 'rsbuild' && hasRsbuildPlugin(tree)) ||
30+
(options.bundler === 'rsbuild' &&
31+
(await hasRsbuildPlugin(tree, options.appProjectRoot))) ||
3132
(options.bundler === 'vite' && hasVitePlugin(tree));
3233

3334
let e2eWebServerInfo: E2EWebServerDetails = {
Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
import { readNxJson, Tree } from '@nx/devkit';
1+
import { ensurePackage, Tree } from '@nx/devkit';
2+
import { nxVersion } from './versions';
23

3-
export function hasRsbuildPlugin(tree: Tree) {
4-
const nxJson = readNxJson(tree);
5-
return !!nxJson.plugins?.some((p) =>
6-
typeof p === 'string'
7-
? p === '@nx/rsbuild/plugin'
8-
: p.plugin === '@nx/rsbuild/plugin'
9-
);
4+
export async function hasRsbuildPlugin(tree: Tree, projectPath?: string) {
5+
ensurePackage('@nx/rsbuild', nxVersion);
6+
const { hasRsbuildPlugin } = await import('@nx/rsbuild/config-utils');
7+
return hasRsbuildPlugin(tree, projectPath);
108
}

packages/rsbuild/config-utils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ export {
66
} from './src/utils/ast-utils';
77
export * as versions from './src/utils/versions';
88
export { getRsbuildE2EWebServerInfo } from './src/utils/e2e-web-server-info-utils';
9+
export { hasRsbuildPlugin } from './src/utils/has-rsbuild-plugin';

packages/rsbuild/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { createNodesV2, RsbuildPluginOptions } from './src/plugins/plugin';

packages/rsbuild/package.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,6 @@
5555
"./config-utils": {
5656
"types": "./config-utils.d.ts",
5757
"default": "./config-utils.js"
58-
},
59-
"./plugin": {
60-
"types": "./plugin.d.ts",
61-
"default": "./plugin.js"
6258
}
6359
}
6460
}

packages/rsbuild/plugin.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

packages/rsbuild/src/generators/init/init.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export async function initGeneratorInternal(
4343
await addPlugin(
4444
tree,
4545
await createProjectGraphAsync(),
46-
'@nx/rsbuild/plugin',
46+
'@nx/rsbuild',
4747
createNodesV2,
4848
{
4949
buildTargetName: ['build', 'rsbuild:build', 'rsbuild-build'],

packages/rsbuild/src/plugins/plugin.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jest.mock('@nx/js/src/utils/typescript/ts-solution-setup', () => ({
1515
isUsingTsSolutionSetup: jest.fn().mockReturnValue(false),
1616
}));
1717

18-
describe('@nx/rsbuild/plugin', () => {
18+
describe('@nx/rsbuild', () => {
1919
let createNodesFunction = createNodesV2[1];
2020
let context: CreateNodesContext;
2121
let tempFs: TempFs;

packages/rsbuild/src/utils/e2e-web-server-info-utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export async function getRsbuildE2EWebServerInfo(
2222
tree,
2323
projectName,
2424
{
25-
plugin: '@nx/rsbuild/plugin',
25+
plugin: '@nx/rsbuild',
2626
serveTargetName: 'devTargetName',
2727
serveStaticTargetName: 'previewTargetName',
2828
configFilePath,
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { type Tree, readNxJson } from '@nx/devkit';
2+
import { minimatch } from 'minimatch';
3+
4+
export function hasRsbuildPlugin(tree: Tree, projectPath?: string) {
5+
const nxJson = readNxJson(tree);
6+
if (!projectPath) {
7+
return !!nxJson.plugins?.some((p) =>
8+
typeof p === 'string' ? p === '@nx/rsbuild' : p.plugin === '@nx/rsbuild'
9+
);
10+
}
11+
return !!nxJson.plugins?.some((p) => {
12+
if (typeof p === 'string') {
13+
return p === '@nx/rsbuild';
14+
}
15+
if (p.exclude) {
16+
for (const exclude of p.exclude) {
17+
if (minimatch(projectPath, exclude)) {
18+
return false;
19+
}
20+
}
21+
}
22+
if (p.include) {
23+
for (const include of p.include) {
24+
if (minimatch(projectPath, include)) {
25+
return true;
26+
}
27+
}
28+
}
29+
30+
// if no include or exclude, then it's a match
31+
return true;
32+
});
33+
}

packages/vue/src/generators/application/application.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ describe('application generator', () => {
114114
expect(listFiles(tree)).toMatchSnapshot();
115115
expect(
116116
readNxJson(tree).plugins.find(
117-
(p) => typeof p !== 'string' && p.plugin === '@nx/rsbuild/plugin'
117+
(p) => typeof p !== 'string' && p.plugin === '@nx/rsbuild'
118118
)
119119
).toMatchInlineSnapshot(`
120120
{
@@ -125,7 +125,7 @@ describe('application generator', () => {
125125
"previewTargetName": "preview",
126126
"typecheckTargetName": "typecheck",
127127
},
128-
"plugin": "@nx/rsbuild/plugin",
128+
"plugin": "@nx/rsbuild",
129129
}
130130
`);
131131
});

packages/vue/src/generators/application/lib/add-e2e.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
import { webStaticServeGenerator } from '@nx/web';
99

1010
import { nxVersion } from '../../../utils/versions';
11+
import { hasRsbuildPlugin } from '../../../utils/has-rsbuild-plugin';
1112
import { NormalizedSchema } from '../schema';
1213
import { findPluginForConfigFile } from '@nx/devkit/src/utils/find-plugin-for-config-file';
1314
import { addE2eCiTargetDefaults } from '@nx/devkit/src/generators/target-defaults-utils';
@@ -20,11 +21,7 @@ export async function addE2e(
2021
const nxJson = readNxJson(tree);
2122
const hasPlugin =
2223
options.bundler === 'rsbuild'
23-
? nxJson.plugins?.find((p) =>
24-
typeof p === 'string'
25-
? p === '@nx/rsbuild/plugin'
26-
: p.plugin === '@nx/rsbuild/plugin'
27-
)
24+
? await hasRsbuildPlugin(tree, options.appProjectRoot)
2825
: nxJson.plugins?.find((p) =>
2926
typeof p === 'string'
3027
? p === '@nx/vite/plugin'
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { ensurePackage, Tree } from '@nx/devkit';
2+
import { nxVersion } from './versions';
3+
4+
export async function hasRsbuildPlugin(tree: Tree, projectPath?: string) {
5+
ensurePackage('@nx/rsbuild', nxVersion);
6+
const { hasRsbuildPlugin } = await import('@nx/rsbuild/config-utils');
7+
return hasRsbuildPlugin(tree, projectPath);
8+
}

0 commit comments

Comments
 (0)