@nx/rsbuild 0.0.0-pr-29314-e664f92 → 0.0.0-pr-29314-bfd9d0c

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,4 @@
1
+ export { addBuildPlugin } from './src/utils/add-build-plugin';
2
+ export { addCopyAssets, addHtmlTemplatePath, addExperimentalSwcPlugin, } from './src/utils/ast-utils';
3
+ export * as versions from './src/utils/versions';
4
+ export { getRsbuildE2EWebServerInfo } from './src/utils/e2e-web-server-info-utils';
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getRsbuildE2EWebServerInfo = exports.versions = exports.addExperimentalSwcPlugin = exports.addHtmlTemplatePath = exports.addCopyAssets = exports.addBuildPlugin = void 0;
4
+ var add_build_plugin_1 = require("./src/utils/add-build-plugin");
5
+ Object.defineProperty(exports, "addBuildPlugin", { enumerable: true, get: function () { return add_build_plugin_1.addBuildPlugin; } });
6
+ var ast_utils_1 = require("./src/utils/ast-utils");
7
+ Object.defineProperty(exports, "addCopyAssets", { enumerable: true, get: function () { return ast_utils_1.addCopyAssets; } });
8
+ Object.defineProperty(exports, "addHtmlTemplatePath", { enumerable: true, get: function () { return ast_utils_1.addHtmlTemplatePath; } });
9
+ Object.defineProperty(exports, "addExperimentalSwcPlugin", { enumerable: true, get: function () { return ast_utils_1.addExperimentalSwcPlugin; } });
10
+ exports.versions = require("./src/utils/versions");
11
+ var e2e_web_server_info_utils_1 = require("./src/utils/e2e-web-server-info-utils");
12
+ Object.defineProperty(exports, "getRsbuildE2EWebServerInfo", { enumerable: true, get: function () { return e2e_web_server_info_utils_1.getRsbuildE2EWebServerInfo; } });
@@ -0,0 +1,2 @@
1
+ export { configurationGenerator } from './src/generators/configuration/configuration';
2
+ export { initGenerator } from './src/generators/init/init';
package/generators.js ADDED
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.initGenerator = exports.configurationGenerator = void 0;
4
+ var configuration_1 = require("./src/generators/configuration/configuration");
5
+ Object.defineProperty(exports, "configurationGenerator", { enumerable: true, get: function () { return configuration_1.configurationGenerator; } });
6
+ var init_1 = require("./src/generators/init/init");
7
+ Object.defineProperty(exports, "initGenerator", { enumerable: true, get: function () { return init_1.initGenerator; } });
package/generators.json CHANGED
@@ -8,6 +8,11 @@
8
8
  "description": "Initialize the `@nx/rsbuild` plugin.",
9
9
  "aliases": ["ng-add"],
10
10
  "hidden": true
11
+ },
12
+ "configuration": {
13
+ "factory": "./src/generators/configuration/configuration",
14
+ "schema": "./src/generators/configuration/schema.json",
15
+ "description": "Add an Rsbuild configuration for the provided project."
11
16
  }
12
17
  }
13
18
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@nx/rsbuild",
3
3
  "description": "The Nx Plugin for Rsbuild contains an Nx plugin, executors and utilities that support building applications using Rsbuild.",
4
- "version": "0.0.0-pr-29314-e664f92",
4
+ "version": "0.0.0-pr-29314-bfd9d0c",
5
5
  "type": "commonjs",
6
6
  "publishConfig": {
7
7
  "access": "public"
@@ -30,14 +30,36 @@
30
30
  "executors": "./executors.json",
31
31
  "dependencies": {
32
32
  "tslib": "^2.3.0",
33
- "@nx/devkit": "0.0.0-pr-29314-e664f92",
34
- "@nx/js": "0.0.0-pr-29314-e664f92",
33
+ "@nx/devkit": "0.0.0-pr-29314-bfd9d0c",
34
+ "@nx/js": "0.0.0-pr-29314-bfd9d0c",
35
35
  "@rsbuild/core": "1.1.8",
36
- "minimatch": "9.0.3"
36
+ "minimatch": "9.0.3",
37
+ "@phenomnomnominal/tsquery": "~5.0.1"
37
38
  },
38
39
  "peerDependencies": {},
39
40
  "nx-migrations": {
40
41
  "migrations": "./migrations.json"
41
42
  },
43
+ "exports": {
44
+ ".": {
45
+ "types": "./index.d.ts",
46
+ "default": "./index.js"
47
+ },
48
+ "./package.json": {
49
+ "default": "./package.json"
50
+ },
51
+ "./generators": {
52
+ "types": "./generators.d.ts",
53
+ "default": "./generators.js"
54
+ },
55
+ "./config-utils": {
56
+ "types": "./config-utils.d.ts",
57
+ "default": "./config-utils.js"
58
+ },
59
+ "./plugin": {
60
+ "types": "./plugin.d.ts",
61
+ "default": "./plugin.js"
62
+ }
63
+ },
42
64
  "types": "./index.d.ts"
43
65
  }
@@ -0,0 +1,4 @@
1
+ import { GeneratorCallback, type Tree } from '@nx/devkit';
2
+ import { type Schema } from './schema';
3
+ export declare function configurationGenerator(tree: Tree, schema: Schema): Promise<GeneratorCallback>;
4
+ export default configurationGenerator;
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.configurationGenerator = configurationGenerator;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const lib_1 = require("./lib");
6
+ const js_1 = require("@nx/js");
7
+ const init_1 = require("../init/init");
8
+ const versions_1 = require("../../utils/versions");
9
+ const path_1 = require("path");
10
+ async function configurationGenerator(tree, schema) {
11
+ const projectGraph = await (0, devkit_1.createProjectGraphAsync)();
12
+ const projects = (0, devkit_1.readProjectsConfigurationFromProjectGraph)(projectGraph);
13
+ let project = projects.projects[schema.project];
14
+ if (!project) {
15
+ project = (0, devkit_1.readProjectConfiguration)(tree, schema.project);
16
+ if (!project) {
17
+ throw new Error(`Could not find project '${schema.project}'. Please choose a project that exists in the Nx Workspace.`);
18
+ }
19
+ }
20
+ const options = await (0, lib_1.normalizeOptions)(tree, schema, project);
21
+ const tasks = [];
22
+ const jsInitTask = await (0, js_1.initGenerator)(tree, {
23
+ ...schema,
24
+ skipFormat: true,
25
+ tsConfigName: options.projectRoot === '.' ? 'tsconfig.json' : 'tsconfig.base.json',
26
+ });
27
+ tasks.push(jsInitTask);
28
+ const initTask = await (0, init_1.initGenerator)(tree, { skipFormat: true });
29
+ tasks.push(initTask);
30
+ if (options.skipValidation) {
31
+ const projectJson = (0, devkit_1.readProjectConfiguration)(tree, project.name);
32
+ if (projectJson.targets['build']) {
33
+ delete projectJson.targets['build'];
34
+ }
35
+ if (projectJson.targets['serve']) {
36
+ delete projectJson.targets['serve'];
37
+ }
38
+ if (projectJson.targets['dev']) {
39
+ delete projectJson.targets['dev'];
40
+ }
41
+ }
42
+ tasks.push((0, devkit_1.addDependenciesToPackageJson)(tree, {}, { '@rsbuild/core': versions_1.rsbuildVersion }));
43
+ (0, devkit_1.generateFiles)(tree, (0, path_1.join)(__dirname, 'files'), options.projectRoot, {
44
+ ...options,
45
+ tpl: '',
46
+ });
47
+ return (0, devkit_1.runTasksInSerial)(...tasks);
48
+ }
49
+ exports.default = configurationGenerator;
@@ -0,0 +1,19 @@
1
+ import { defineConfig } from '@rsbuild/core';
2
+
3
+ export default defineConfig({
4
+ source: {
5
+ entry: {
6
+ index: '<%= entry %>'
7
+ },<% if (tsConfig) { %>
8
+ tsconfigPath: '<%= tsConfig %>',<% } %>
9
+ },
10
+ server: {
11
+ port: <%= devServerPort %>
12
+ },
13
+ output: {
14
+ target: '<%= target %>',
15
+ distPath: {
16
+ root: 'dist',
17
+ },
18
+ }
19
+ });
@@ -0,0 +1 @@
1
+ export * from './normalize-options';
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./normalize-options"), exports);
@@ -0,0 +1,10 @@
1
+ import { type Tree, type ProjectConfiguration } from '@nx/devkit';
2
+ import { type Schema } from '../schema';
3
+ export interface NormalizedOptions extends Schema {
4
+ entry: string;
5
+ target: 'node' | 'web' | 'web-worker';
6
+ devServerPort: number;
7
+ tsConfig: string;
8
+ projectRoot: string;
9
+ }
10
+ export declare function normalizeOptions(tree: Tree, schema: Schema, project: ProjectConfiguration): Promise<NormalizedOptions>;
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.normalizeOptions = normalizeOptions;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const path_1 = require("path");
6
+ async function normalizeOptions(tree, schema, project) {
7
+ // Paths should be relative to the project root because inferred task will run from project root
8
+ let options = {
9
+ ...schema,
10
+ target: schema.target ?? 'web',
11
+ entry: normalizeRelativePath(schema.entry ?? './src/index.ts', project.root),
12
+ tsConfig: normalizeRelativePath(schema.tsConfig ?? './tsconfig.json', project.root),
13
+ devServerPort: schema.devServerPort ?? 4200,
14
+ projectRoot: project.root,
15
+ skipFormat: schema.skipFormat ?? false,
16
+ skipValidation: schema.skipValidation ?? false,
17
+ };
18
+ if (!schema.tsConfig) {
19
+ const possibleTsConfigPaths = [
20
+ './tsconfig.app.json',
21
+ './tsconfig.lib.json',
22
+ './tsconfig.json',
23
+ ];
24
+ const tsConfigPath = possibleTsConfigPaths.find((p) => tree.exists((0, devkit_1.joinPathFragments)(project.root, p)));
25
+ options.tsConfig = tsConfigPath ?? undefined;
26
+ }
27
+ return options;
28
+ }
29
+ function normalizeRelativePath(filePath, projectRoot) {
30
+ if (filePath.startsWith('./')) {
31
+ return filePath;
32
+ }
33
+ filePath = filePath.startsWith(projectRoot)
34
+ ? (0, path_1.relative)(projectRoot, filePath)
35
+ : filePath;
36
+ return `./${filePath}`;
37
+ }
@@ -0,0 +1,9 @@
1
+ export interface Schema {
2
+ project: string;
3
+ entry?: string;
4
+ tsConfig?: string;
5
+ devServerPort?: number;
6
+ target?: 'node' | 'web' | 'web-worker';
7
+ skipValidation?: boolean;
8
+ skipFormat?: boolean;
9
+ }
@@ -0,0 +1,47 @@
1
+ {
2
+ "$schema": "http://json-schema.org/schema",
3
+ "$id": "Rsbuild",
4
+ "title": "Nx Rsbuild Configuration Generator",
5
+ "description": "Rsbuild configuration generator.",
6
+ "type": "object",
7
+ "properties": {
8
+ "project": {
9
+ "type": "string",
10
+ "description": "The name of the project.",
11
+ "$default": {
12
+ "$source": "argv",
13
+ "index": 0
14
+ },
15
+ "x-dropdown": "project",
16
+ "x-prompt": "What is the name of the project to set up a Rsbuild for?",
17
+ "x-priority": "important"
18
+ },
19
+ "entry": {
20
+ "type": "string",
21
+ "description": "Path relative to the workspace root for the entry file. Defaults to '<projectRoot>/src/index.ts'.",
22
+ "x-priority": "important"
23
+ },
24
+ "tsConfig": {
25
+ "type": "string",
26
+ "description": "Path relative to the workspace root for the tsconfig file to build with. Defaults to '<projectRoot>/tsconfig.app.json'.",
27
+ "x-priority": "important"
28
+ },
29
+ "devServerPort": {
30
+ "type": "number",
31
+ "description": "The port for the dev server to listen on.",
32
+ "default": 4200
33
+ },
34
+ "target": {
35
+ "type": "string",
36
+ "description": "Target platform for the build, same as the Rsbuild output.target config option.",
37
+ "enum": ["node", "web", "web-worker"],
38
+ "default": "web"
39
+ },
40
+ "skipFormat": {
41
+ "description": "Skip formatting files.",
42
+ "type": "boolean",
43
+ "default": false,
44
+ "x-priority": "internal"
45
+ }
46
+ }
47
+ }
@@ -105,6 +105,7 @@ async function createRsbuildTargets(configFilePath, projectRoot, options, tsConf
105
105
  };
106
106
  targets[options.previewTargetName] = {
107
107
  command: `rsbuild preview`,
108
+ dependsOn: [`${options.buildTargetName}`, `^${options.buildTargetName}`],
108
109
  options: {
109
110
  cwd: projectRoot,
110
111
  args: ['--mode=production'],
@@ -0,0 +1,10 @@
1
+ import { type Tree } from '@nx/devkit';
2
+ /**
3
+ * Adds a plugin to the build configuration.
4
+ * @param tree - Nx Devkit Tree
5
+ * @param pathToConfigFile - Path to the build configuration file
6
+ * @param importPath - Path to the plugin
7
+ * @param pluginName - Name of the plugin
8
+ * @param options - Optional but should be defined as a string such as `property: {foo: 'bar'}`
9
+ */
10
+ export declare function addBuildPlugin(tree: Tree, pathToConfigFile: string, importPath: string, pluginName: string, options?: string): void;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addBuildPlugin = addBuildPlugin;
4
+ const tsquery_1 = require("@phenomnomnominal/tsquery");
5
+ const indent_by_1 = require("./indent-by");
6
+ const DEFINE_CONFIG_SELECTOR = 'CallExpression:has(Identifier[name=defineConfig]) > ObjectLiteralExpression';
7
+ const PLUGINS_ARRAY_SELECTOR = 'CallExpression:has(Identifier[name=defineConfig]) PropertyAssignment:has(Identifier[name=plugins]) > ArrayLiteralExpression';
8
+ /**
9
+ * Adds a plugin to the build configuration.
10
+ * @param tree - Nx Devkit Tree
11
+ * @param pathToConfigFile - Path to the build configuration file
12
+ * @param importPath - Path to the plugin
13
+ * @param pluginName - Name of the plugin
14
+ * @param options - Optional but should be defined as a string such as `property: {foo: 'bar'}`
15
+ */
16
+ function addBuildPlugin(tree, pathToConfigFile, importPath, pluginName, options) {
17
+ let configContents = tree.read(pathToConfigFile, 'utf-8');
18
+ configContents = `import { ${pluginName} } from '${importPath}';
19
+ ${configContents}`;
20
+ const ast = tsquery_1.tsquery.ast(configContents);
21
+ const pluginsArrayNodes = (0, tsquery_1.tsquery)(ast, PLUGINS_ARRAY_SELECTOR);
22
+ if (pluginsArrayNodes.length === 0) {
23
+ const defineConfigNodes = (0, tsquery_1.tsquery)(ast, DEFINE_CONFIG_SELECTOR);
24
+ if (defineConfigNodes.length === 0) {
25
+ throw new Error(`Could not find defineConfig in the config file at ${pathToConfigFile}.`);
26
+ }
27
+ const defineConfigNode = defineConfigNodes[0];
28
+ configContents = `${configContents.slice(0, defineConfigNode.getStart() + 1)}\n${(0, indent_by_1.indentBy)(1)(`plugins: [${pluginName}(${options ?? ''})],`)}\n\t${configContents.slice(defineConfigNode.getStart() + 1)}`;
29
+ }
30
+ else {
31
+ const pluginsArrayNode = pluginsArrayNodes[0];
32
+ const pluginsArrayContents = pluginsArrayNode.getText();
33
+ const newPluginsArrayContents = `[\n${(0, indent_by_1.indentBy)(2)(`${pluginsArrayContents.length > 2
34
+ ? `${pluginsArrayContents.slice(1, pluginsArrayContents.length - 1)},\n${pluginName}`
35
+ : pluginName}(${options ? `{\n${(0, indent_by_1.indentBy)(1)(`${options}`)}\n}` : ''})`)}\n\t]`;
36
+ configContents = `${configContents.slice(0, pluginsArrayNode.getStart())}${newPluginsArrayContents}${configContents.slice(pluginsArrayNode.getEnd())}`;
37
+ }
38
+ tree.write(pathToConfigFile, configContents);
39
+ }
@@ -0,0 +1,4 @@
1
+ import { type Tree } from '@nx/devkit';
2
+ export declare function addHtmlTemplatePath(tree: Tree, configFilePath: string, templatePath: string): void;
3
+ export declare function addCopyAssets(tree: Tree, configFilePath: string, from: string): void;
4
+ export declare function addExperimentalSwcPlugin(tree: Tree, configFilePath: string, pluginName: string): void;
@@ -0,0 +1,120 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addHtmlTemplatePath = addHtmlTemplatePath;
4
+ exports.addCopyAssets = addCopyAssets;
5
+ exports.addExperimentalSwcPlugin = addExperimentalSwcPlugin;
6
+ const indent_by_1 = require("./indent-by");
7
+ const tsquery_1 = require("@phenomnomnominal/tsquery");
8
+ const DEFINE_CONFIG_SELECTOR = 'CallExpression:has(Identifier[name=defineConfig]) > ObjectLiteralExpression';
9
+ function addHtmlTemplatePath(tree, configFilePath, templatePath) {
10
+ const HTML_CONFIG_SELECTOR = 'CallExpression:has(Identifier[name=defineConfig]) ObjectLiteralExpression PropertyAssignment:has(Identifier[name=html]) > ObjectLiteralExpression';
11
+ const TEMPLATE_STRING_SELECTOR = 'PropertyAssignment:has(Identifier[name=template]) > StringLiteral';
12
+ let configContents = tree.read(configFilePath, 'utf-8');
13
+ const ast = tsquery_1.tsquery.ast(configContents);
14
+ const htmlConfigNodes = (0, tsquery_1.tsquery)(ast, HTML_CONFIG_SELECTOR);
15
+ if (htmlConfigNodes.length === 0) {
16
+ const defineConfigNodes = (0, tsquery_1.tsquery)(ast, DEFINE_CONFIG_SELECTOR);
17
+ if (defineConfigNodes.length === 0) {
18
+ throw new Error(`Could not find 'defineConfig' in the config file at ${configFilePath}.`);
19
+ }
20
+ const defineConfigNode = defineConfigNodes[0];
21
+ configContents = `${configContents.slice(0, defineConfigNode.getStart() + 1)}\n${(0, indent_by_1.indentBy)(1)(`html: {\n${(0, indent_by_1.indentBy)(1)(`template: '${templatePath}'`)}\n},`)}\t${configContents.slice(defineConfigNode.getStart() + 1)}`;
22
+ }
23
+ else {
24
+ const htmlConfigNode = htmlConfigNodes[0];
25
+ const templateStringNodes = (0, tsquery_1.tsquery)(htmlConfigNode, TEMPLATE_STRING_SELECTOR);
26
+ if (templateStringNodes.length === 0) {
27
+ configContents = `${configContents.slice(0, htmlConfigNode.getStart() + 1)}\n${(0, indent_by_1.indentBy)(2)(`template: '${templatePath}',`)}\n\t\t${configContents.slice(htmlConfigNode.getStart() + 1)}`;
28
+ }
29
+ else {
30
+ const templateStringNode = templateStringNodes[0];
31
+ configContents = `${configContents.slice(0, templateStringNode.getStart())}'${templatePath}',${configContents.slice(templateStringNode.getEnd())}`;
32
+ }
33
+ }
34
+ tree.write(configFilePath, configContents);
35
+ }
36
+ function addCopyAssets(tree, configFilePath, from) {
37
+ const OUTPUT_CONFIG_SELECTOR = 'CallExpression:has(Identifier[name=defineConfig]) ObjectLiteralExpression PropertyAssignment:has(Identifier[name=output]) > ObjectLiteralExpression';
38
+ const COPY_ARRAY_SELECTOR = 'PropertyAssignment:has(Identifier[name=copy]) > ArrayLiteralExpression';
39
+ const copyAssetArrayElement = `{ from: '${from}' }`;
40
+ let configContents = tree.read(configFilePath, 'utf-8');
41
+ const ast = tsquery_1.tsquery.ast(configContents);
42
+ const outputConfigNodes = (0, tsquery_1.tsquery)(ast, OUTPUT_CONFIG_SELECTOR);
43
+ if (outputConfigNodes.length === 0) {
44
+ const defineConfigNodes = (0, tsquery_1.tsquery)(ast, DEFINE_CONFIG_SELECTOR);
45
+ if (defineConfigNodes.length === 0) {
46
+ throw new Error(`Could not find 'defineConfig' in the config file at ${configFilePath}.`);
47
+ }
48
+ const defineConfigNode = defineConfigNodes[0];
49
+ configContents = `${configContents.slice(0, defineConfigNode.getStart() + 1)}\n${(0, indent_by_1.indentBy)(1)(`output: {\n${(0, indent_by_1.indentBy)(2)(`copy: [${copyAssetArrayElement}]`)},\n}`)},${configContents.slice(defineConfigNode.getStart() + 1)}`;
50
+ }
51
+ else {
52
+ const outputConfigNode = outputConfigNodes[0];
53
+ const copyAssetsArrayNodes = (0, tsquery_1.tsquery)(outputConfigNode, COPY_ARRAY_SELECTOR);
54
+ if (copyAssetsArrayNodes.length === 0) {
55
+ configContents = `${configContents.slice(0, outputConfigNode.getStart() + 1)}\n${(0, indent_by_1.indentBy)(2)(`copy: [${copyAssetArrayElement}],`)}\n\t${configContents.slice(outputConfigNode.getStart() + 1)}`;
56
+ }
57
+ else {
58
+ const copyAssetsArrayNode = copyAssetsArrayNodes[0];
59
+ configContents = `${configContents.slice(0, copyAssetsArrayNode.getStart() + 1)}\n${(0, indent_by_1.indentBy)(2)(copyAssetArrayElement)},\n\t\t${configContents.slice(copyAssetsArrayNode.getStart() + 1)}`;
60
+ }
61
+ }
62
+ tree.write(configFilePath, configContents);
63
+ }
64
+ function addExperimentalSwcPlugin(tree, configFilePath, pluginName) {
65
+ const SWC_JSC_EXPERIMENTAL_PLUGIN_ARRAY_SELECTOR = 'CallExpression:has(Identifier[name=defineConfig]) ObjectLiteralExpression PropertyAssignment:has(Identifier[name=tools]) PropertyAssignment:has(Identifier[name=swc]) PropertyAssignment:has(Identifier[name=jsc]) PropertyAssignment:has(Identifier[name=experimental]) PropertyAssignment:has(Identifier[name=plugins]) > ArrayLiteralExpression';
66
+ const SWC_JSC_EXPERIMENTAL_SELECTOR = 'CallExpression:has(Identifier[name=defineConfig]) ObjectLiteralExpression PropertyAssignment:has(Identifier[name=tools]) PropertyAssignment:has(Identifier[name=swc]) PropertyAssignment:has(Identifier[name=jsc]) PropertyAssignment:has(Identifier[name=experimental]) > ObjectLiteralExpression';
67
+ const SWC_JSC_SELECTOR = 'CallExpression:has(Identifier[name=defineConfig]) ObjectLiteralExpression PropertyAssignment:has(Identifier[name=tools]) PropertyAssignment:has(Identifier[name=swc]) PropertyAssignment:has(Identifier[name=jsc]) > ObjectLiteralExpression';
68
+ const SWC_SELECTOR = 'CallExpression:has(Identifier[name=defineConfig]) ObjectLiteralExpression PropertyAssignment:has(Identifier[name=tools]) PropertyAssignment:has(Identifier[name=swc]) > ObjectLiteralExpression';
69
+ const TOOLS_SELECTOR = 'CallExpression:has(Identifier[name=defineConfig]) ObjectLiteralExpression PropertyAssignment:has(Identifier[name=tools]) > ObjectLiteralExpression';
70
+ let configContents = tree.read(configFilePath, 'utf-8');
71
+ const ast = tsquery_1.tsquery.ast(configContents);
72
+ const pluginToAdd = (0, indent_by_1.indentBy)(1)(`['${pluginName}', {}],`);
73
+ const pluginsArrayToAdd = (0, indent_by_1.indentBy)(1)(`plugins: [\n${pluginToAdd}\n],`);
74
+ const experimentalObjectToAdd = (0, indent_by_1.indentBy)(1)(`experimental: {\n${pluginsArrayToAdd} \n},`);
75
+ const jscObjectToAdd = (0, indent_by_1.indentBy)(1)(`jsc: {\n${experimentalObjectToAdd}\n},`);
76
+ const swcObjectToAdd = (0, indent_by_1.indentBy)(1)(`swc: {\n${jscObjectToAdd}\n},`);
77
+ const toolsObjectToAdd = (0, indent_by_1.indentBy)(1)(`tools: {\n${swcObjectToAdd}\n},`);
78
+ const toolsNodes = (0, tsquery_1.tsquery)(ast, TOOLS_SELECTOR);
79
+ if (toolsNodes.length === 0) {
80
+ const defineConfigNodes = (0, tsquery_1.tsquery)(ast, DEFINE_CONFIG_SELECTOR);
81
+ if (defineConfigNodes.length === 0) {
82
+ throw new Error(`Could not find 'defineConfig' in the config file at ${configFilePath}.`);
83
+ }
84
+ const defineConfigNode = defineConfigNodes[0];
85
+ configContents = `${configContents.slice(0, defineConfigNode.getStart() + 1)}\n${toolsObjectToAdd}${configContents.slice(defineConfigNode.getStart() + 1)}`;
86
+ }
87
+ else {
88
+ const swcNodes = (0, tsquery_1.tsquery)(ast, SWC_SELECTOR);
89
+ if (swcNodes.length === 0) {
90
+ const toolsNode = toolsNodes[0];
91
+ configContents = `${configContents.slice(0, toolsNode.getStart() + 1)}\n${(0, indent_by_1.indentBy)(1)(swcObjectToAdd)}\n\t${configContents.slice(toolsNode.getStart() + 1)}`;
92
+ }
93
+ else {
94
+ const jscNodes = (0, tsquery_1.tsquery)(ast, SWC_JSC_SELECTOR);
95
+ if (jscNodes.length === 0) {
96
+ const swcNode = swcNodes[0];
97
+ configContents = `${configContents.slice(0, swcNode.getStart() + 1)}\n${(0, indent_by_1.indentBy)(2)(jscObjectToAdd)}\n\t\t${configContents.slice(swcNode.getStart() + 1)}`;
98
+ }
99
+ else {
100
+ const experimentalNodes = (0, tsquery_1.tsquery)(ast, SWC_JSC_EXPERIMENTAL_SELECTOR);
101
+ if (experimentalNodes.length === 0) {
102
+ const jscNode = jscNodes[0];
103
+ configContents = `${configContents.slice(0, jscNode.getStart() + 1)}\n${(0, indent_by_1.indentBy)(3)(experimentalObjectToAdd)}\n\t\t\t${configContents.slice(jscNode.getStart() + 1)}`;
104
+ }
105
+ else {
106
+ const pluginsArrayNodes = (0, tsquery_1.tsquery)(ast, SWC_JSC_EXPERIMENTAL_PLUGIN_ARRAY_SELECTOR);
107
+ if (pluginsArrayNodes.length === 0) {
108
+ const experimentalNode = experimentalNodes[0];
109
+ configContents = `${configContents.slice(0, experimentalNode.getStart() + 1)}\n${(0, indent_by_1.indentBy)(4)(pluginsArrayToAdd)}\n\t\t\t\t${configContents.slice(experimentalNode.getStart() + 1)}`;
110
+ }
111
+ else {
112
+ const pluginsArrayNode = pluginsArrayNodes[0];
113
+ configContents = `${configContents.slice(0, pluginsArrayNode.getStart() + 1)}\n${(0, indent_by_1.indentBy)(4)(pluginToAdd)}\n\t\t\t\t\t${configContents.slice(pluginsArrayNode.getStart() + 1)}`;
114
+ }
115
+ }
116
+ }
117
+ }
118
+ }
119
+ tree.write(configFilePath, configContents);
120
+ }
@@ -0,0 +1,2 @@
1
+ import { type Tree } from '@nx/devkit';
2
+ export declare function getRsbuildE2EWebServerInfo(tree: Tree, projectName: string, configFilePath: string, isPluginBeingAdded: boolean, e2ePortOverride?: number): Promise<import("@nx/devkit/src/generators/e2e-web-server-info-utils").E2EWebServerDetails>;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getRsbuildE2EWebServerInfo = getRsbuildE2EWebServerInfo;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const e2e_web_server_info_utils_1 = require("@nx/devkit/src/generators/e2e-web-server-info-utils");
6
+ async function getRsbuildE2EWebServerInfo(tree, projectName, configFilePath, isPluginBeingAdded, e2ePortOverride) {
7
+ const nxJson = (0, devkit_1.readNxJson)(tree);
8
+ let e2ePort = e2ePortOverride ?? 4200;
9
+ if (nxJson.targetDefaults?.['dev'] &&
10
+ nxJson.targetDefaults?.['dev'].options?.port) {
11
+ e2ePort = nxJson.targetDefaults?.['dev'].options?.port;
12
+ }
13
+ return (0, e2e_web_server_info_utils_1.getE2EWebServerInfo)(tree, projectName, {
14
+ plugin: '@nx/rsbuild/plugin',
15
+ serveTargetName: 'devTargetName',
16
+ serveStaticTargetName: 'previewTargetName',
17
+ configFilePath,
18
+ }, {
19
+ defaultServeTargetName: 'dev',
20
+ defaultServeStaticTargetName: 'preview',
21
+ defaultE2EWebServerAddress: `http://localhost:${e2ePort}`,
22
+ defaultE2ECiBaseUrl: 'http://localhost:4200',
23
+ defaultE2EPort: e2ePort,
24
+ }, isPluginBeingAdded);
25
+ }
@@ -0,0 +1 @@
1
+ export declare function indentBy(tabNumber: number): (str: string) => string;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.indentBy = indentBy;
4
+ function indentBy(tabNumber) {
5
+ return (str) => {
6
+ const indentation = '\t'.repeat(tabNumber);
7
+ return str
8
+ .split('\n')
9
+ .map((line) => `${indentation}${line}`)
10
+ .join('\n');
11
+ };
12
+ }
@@ -1,2 +1,16 @@
1
1
  export declare const nxVersion: any;
2
- export declare const rsbuildVersion = "1.1.8";
2
+ export declare const rsbuildVersion = "1.1.10";
3
+ export declare const rsbuildPluginReactVersion = "1.1.0";
4
+ export declare const rsbuildPluginVueVersion = "1.0.5";
5
+ export declare const rsbuildPluginSassVersion = "1.1.2";
6
+ export declare const rsbuildPluginLessVersion = "1.1.0";
7
+ export declare const rsbuildPluginStyledComponentsVersion = "1.1.0";
8
+ /**
9
+ * These versions need to line up with the version of the swc_core crate Rspack uses for the version of Rsbuild above
10
+ * Checking the `cargo.toml` at https://github.com/web-infra-dev/rspack/blob/main/Cargo.toml for the correct Rspack version
11
+ * is the best way to ensure that these versions are correct.
12
+ *
13
+ * The release notes for the packages below are very helpful in understanding what version of swc_core crate they require.
14
+ */
15
+ export declare const rsbuildSwcPluginEmotionVersion = "^7.0.3";
16
+ export declare const rsbuildSwcPluginStyledJsxVersion = "^5.0.2";
@@ -1,5 +1,19 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.rsbuildVersion = exports.nxVersion = void 0;
3
+ exports.rsbuildSwcPluginStyledJsxVersion = exports.rsbuildSwcPluginEmotionVersion = exports.rsbuildPluginStyledComponentsVersion = exports.rsbuildPluginLessVersion = exports.rsbuildPluginSassVersion = exports.rsbuildPluginVueVersion = exports.rsbuildPluginReactVersion = exports.rsbuildVersion = exports.nxVersion = void 0;
4
4
  exports.nxVersion = require('../../package.json').version;
5
- exports.rsbuildVersion = '1.1.8';
5
+ exports.rsbuildVersion = '1.1.10';
6
+ exports.rsbuildPluginReactVersion = '1.1.0';
7
+ exports.rsbuildPluginVueVersion = '1.0.5';
8
+ exports.rsbuildPluginSassVersion = '1.1.2';
9
+ exports.rsbuildPluginLessVersion = '1.1.0';
10
+ exports.rsbuildPluginStyledComponentsVersion = '1.1.0';
11
+ /**
12
+ * These versions need to line up with the version of the swc_core crate Rspack uses for the version of Rsbuild above
13
+ * Checking the `cargo.toml` at https://github.com/web-infra-dev/rspack/blob/main/Cargo.toml for the correct Rspack version
14
+ * is the best way to ensure that these versions are correct.
15
+ *
16
+ * The release notes for the packages below are very helpful in understanding what version of swc_core crate they require.
17
+ */
18
+ exports.rsbuildSwcPluginEmotionVersion = '^7.0.3';
19
+ exports.rsbuildSwcPluginStyledJsxVersion = '^5.0.2';