@nx/rsbuild 0.0.0-pr-29314-e664f92

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.
package/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ (The MIT License)
2
+
3
+ Copyright (c) 2017-2024 Narwhal Technologies Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ 'Software'), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,68 @@
1
+ <p style="text-align: center;">
2
+ <picture>
3
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/nrwl/nx/master/images/nx-dark.svg">
4
+ <img alt="Nx - Smart Monorepos · Fast CI" src="https://raw.githubusercontent.com/nrwl/nx/master/images/nx-light.svg" width="100%">
5
+ </picture>
6
+ </p>
7
+
8
+ <div style="text-align: center;">
9
+
10
+ [![CircleCI](https://circleci.com/gh/nrwl/nx.svg?style=svg)](https://circleci.com/gh/nrwl/nx)
11
+ [![License](https://img.shields.io/npm/l/@nx/workspace.svg?style=flat-square)]()
12
+ [![NPM Version](https://badge.fury.io/js/%40nrwl%2Fworkspace.svg)](https://www.npmjs.com/@nx/workspace)
13
+ [![Semantic Release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=flat-square)]()
14
+ [![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)
15
+ [![Join the chat at https://gitter.im/nrwl-nx/community](https://badges.gitter.im/nrwl-nx/community.svg)](https://gitter.im/nrwl-nx/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
16
+ [![Join us on the Official Nx Discord Server](https://img.shields.io/discord/1143497901675401286?label=discord)](https://go.nx.dev/community)
17
+
18
+ </div>
19
+
20
+
21
+ <hr>
22
+
23
+ # Nx: Smart Monorepos · Fast CI
24
+
25
+ Nx is a build system, optimized for monorepos, with plugins for popular frameworks and tools and advanced CI capabilities including caching and distribution.
26
+
27
+ This package is a [Rsbuild plugin for Nx](https://nx.dev/nx-api/rsbuild).
28
+
29
+ ## Getting Started
30
+
31
+ ### Creating an Nx Workspace
32
+
33
+ **Using `npx`**
34
+
35
+ ```bash
36
+ npx create-nx-workspace
37
+ ```
38
+
39
+ **Using `npm init`**
40
+
41
+ ```bash
42
+ npm init nx-workspace
43
+ ```
44
+
45
+ **Using `yarn create`**
46
+
47
+ ```bash
48
+ yarn create nx-workspace
49
+ ```
50
+
51
+ ### Adding Nx to an Existing Repository
52
+
53
+ Run:
54
+
55
+ ```bash
56
+ npx nx@latest init
57
+ ```
58
+
59
+ ## Documentation & Resources
60
+
61
+ - [Nx.Dev: Documentation, Guides, Tutorials](https://nx.dev)
62
+ - [Intro to Nx](https://nx.dev/getting-started/intro)
63
+ - [Official Nx YouTube Channel](https://www.youtube.com/@NxDevtools)
64
+ - [Blog Posts About Nx](https://nx.dev/blog)
65
+
66
+ <p style="text-align: center;"><a href="https://nx.dev/#learning-materials" target="_blank" rel="noreferrer"><img src="https://raw.githubusercontent.com/nrwl/nx/master/images/nx-courses-and-videos.svg"
67
+ width="100%" alt="Nx - Smart Monorepos · Fast CI"></a></p>
68
+
package/executors.json ADDED
@@ -0,0 +1,4 @@
1
+ {
2
+ "$schema": "http://json-schema.org/schema",
3
+ "executors": {}
4
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "name": "Nx Rsbuild",
3
+ "version": "0.1",
4
+ "generators": {
5
+ "init": {
6
+ "factory": "./src/generators/init/init#initGeneratorInternal",
7
+ "schema": "./src/generators/init/schema.json",
8
+ "description": "Initialize the `@nx/rsbuild` plugin.",
9
+ "aliases": ["ng-add"],
10
+ "hidden": true
11
+ }
12
+ }
13
+ }
package/index.d.ts ADDED
File without changes
package/index.js ADDED
File without changes
@@ -0,0 +1 @@
1
+ {}
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@nx/rsbuild",
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",
5
+ "type": "commonjs",
6
+ "publishConfig": {
7
+ "access": "public"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "https://github.com/nrwl/nx.git",
12
+ "directory": "packages/rsbuild"
13
+ },
14
+ "bugs": {
15
+ "url": "https://github.com/nrwl/nx/issues"
16
+ },
17
+ "keywords": [
18
+ "Monorepo",
19
+ "Rspack",
20
+ "Webpack",
21
+ "Bundling",
22
+ "Module Federation",
23
+ "Rsbuild"
24
+ ],
25
+ "author": "Colum Ferry",
26
+ "license": "MIT",
27
+ "homepage": "https://nx.dev",
28
+ "main": "index.js",
29
+ "generators": "./generators.json",
30
+ "executors": "./executors.json",
31
+ "dependencies": {
32
+ "tslib": "^2.3.0",
33
+ "@nx/devkit": "0.0.0-pr-29314-e664f92",
34
+ "@nx/js": "0.0.0-pr-29314-e664f92",
35
+ "@rsbuild/core": "1.1.8",
36
+ "minimatch": "9.0.3"
37
+ },
38
+ "peerDependencies": {},
39
+ "nx-migrations": {
40
+ "migrations": "./migrations.json"
41
+ },
42
+ "types": "./index.d.ts"
43
+ }
package/plugin.d.ts ADDED
@@ -0,0 +1 @@
1
+ export { createNodesV2, RsbuildPluginOptions } from './src/plugins/plugin';
package/plugin.js ADDED
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createNodesV2 = void 0;
4
+ var plugin_1 = require("./src/plugins/plugin");
5
+ Object.defineProperty(exports, "createNodesV2", { enumerable: true, get: function () { return plugin_1.createNodesV2; } });
@@ -0,0 +1,6 @@
1
+ import { type Tree, type GeneratorCallback } from '@nx/devkit';
2
+ import { InitGeneratorSchema } from './schema';
3
+ export declare function updateDependencies(tree: Tree, schema: InitGeneratorSchema): GeneratorCallback;
4
+ export declare function initGenerator(tree: Tree, schema: InitGeneratorSchema): Promise<GeneratorCallback>;
5
+ export declare function initGeneratorInternal(tree: Tree, schema: InitGeneratorSchema): Promise<GeneratorCallback>;
6
+ export default initGenerator;
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.updateDependencies = updateDependencies;
4
+ exports.initGenerator = initGenerator;
5
+ exports.initGeneratorInternal = initGeneratorInternal;
6
+ const devkit_1 = require("@nx/devkit");
7
+ const add_plugin_1 = require("@nx/devkit/src/utils/add-plugin");
8
+ const plugin_1 = require("../../plugins/plugin");
9
+ const versions_1 = require("../../utils/versions");
10
+ function updateDependencies(tree, schema) {
11
+ return (0, devkit_1.addDependenciesToPackageJson)(tree, {}, {
12
+ '@nx/rsbuild': versions_1.nxVersion,
13
+ '@rsbuild/core': versions_1.rsbuildVersion,
14
+ }, undefined, schema.keepExistingVersions);
15
+ }
16
+ function initGenerator(tree, schema) {
17
+ return initGeneratorInternal(tree, { addPlugin: false, ...schema });
18
+ }
19
+ async function initGeneratorInternal(tree, schema) {
20
+ const nxJson = (0, devkit_1.readNxJson)(tree);
21
+ const addPluginDefault = process.env.NX_ADD_PLUGINS !== 'false' &&
22
+ nxJson.useInferencePlugins !== false;
23
+ schema.addPlugin ??= addPluginDefault;
24
+ if (schema.addPlugin) {
25
+ await (0, add_plugin_1.addPlugin)(tree, await (0, devkit_1.createProjectGraphAsync)(), '@nx/rsbuild/plugin', plugin_1.createNodesV2, {
26
+ buildTargetName: ['build', 'rsbuild:build', 'rsbuild-build'],
27
+ devTargetName: ['dev', 'rsbuild:dev', 'rsbuild-dev'],
28
+ previewTargetName: ['preview', 'rsbuild:preview', 'rsbuild-preview'],
29
+ inspectTargetName: ['inspect', 'rsbuild:inspect', 'rsbuild-inspect'],
30
+ typecheckTargetName: [
31
+ 'typecheck',
32
+ 'rsbuild:typecheck',
33
+ 'rsbuild-typecheck',
34
+ ],
35
+ }, schema.updatePackageScripts);
36
+ }
37
+ const tasks = [];
38
+ if (!schema.skipPackageJson) {
39
+ tasks.push(updateDependencies(tree, schema));
40
+ }
41
+ if (!schema.skipFormat) {
42
+ await (0, devkit_1.formatFiles)(tree);
43
+ }
44
+ return (0, devkit_1.runTasksInSerial)(...tasks);
45
+ }
46
+ exports.default = initGenerator;
@@ -0,0 +1,7 @@
1
+ export interface InitGeneratorSchema {
2
+ keepExistingVersions?: boolean;
3
+ updatePackageScripts?: boolean;
4
+ addPlugin?: boolean;
5
+ skipFormat?: boolean;
6
+ skipPackageJson?: boolean;
7
+ }
@@ -0,0 +1,36 @@
1
+ {
2
+ "$schema": "http://json-schema.org/schema",
3
+ "$id": "Init",
4
+ "title": "Nx Rsbuild Init Generator",
5
+ "type": "object",
6
+ "description": "Rsbuild init generator.",
7
+ "properties": {
8
+ "rootProject": {
9
+ "type": "boolean",
10
+ "x-priority": "internal"
11
+ },
12
+ "keepExistingVersions": {
13
+ "type": "boolean",
14
+ "x-priority": "internal",
15
+ "description": "Keep existing dependencies versions",
16
+ "default": false
17
+ },
18
+ "updatePackageScripts": {
19
+ "type": "boolean",
20
+ "x-priority": "internal",
21
+ "description": "Update package scripts",
22
+ "default": false
23
+ },
24
+ "skipFormat": {
25
+ "description": "Skip formatting files.",
26
+ "type": "boolean",
27
+ "default": false
28
+ },
29
+ "skipPackageJson": {
30
+ "description": "Do not add dependencies to `package.json`.",
31
+ "type": "boolean",
32
+ "default": false
33
+ }
34
+ },
35
+ "required": []
36
+ }
@@ -0,0 +1,9 @@
1
+ import { CreateNodesV2 } from '@nx/devkit';
2
+ export interface RsbuildPluginOptions {
3
+ buildTargetName?: string;
4
+ devTargetName?: string;
5
+ previewTargetName?: string;
6
+ inspectTargetName?: string;
7
+ typecheckTargetName?: string;
8
+ }
9
+ export declare const createNodesV2: CreateNodesV2<RsbuildPluginOptions>;
@@ -0,0 +1,187 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createNodesV2 = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const get_named_inputs_1 = require("@nx/devkit/src/utils/get-named-inputs");
6
+ const file_hasher_1 = require("nx/src/hasher/file-hasher");
7
+ const cache_directory_1 = require("nx/src/utils/cache-directory");
8
+ const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
9
+ const calculate_hash_for_create_nodes_1 = require("@nx/devkit/src/utils/calculate-hash-for-create-nodes");
10
+ const js_1 = require("@nx/js");
11
+ const fs_1 = require("fs");
12
+ const path_1 = require("path");
13
+ const minimatch_1 = require("minimatch");
14
+ const core_1 = require("@rsbuild/core");
15
+ const pmc = (0, devkit_1.getPackageManagerCommand)();
16
+ function readTargetsCache(cachePath) {
17
+ return (0, fs_1.existsSync)(cachePath) ? (0, devkit_1.readJsonFile)(cachePath) : {};
18
+ }
19
+ function writeTargetsCache(cachePath, results) {
20
+ (0, devkit_1.writeJsonFile)(cachePath, results);
21
+ }
22
+ const rsbuildConfigGlob = '**/rsbuild.config.{js,ts,mjs,mts,cjs,cts}';
23
+ exports.createNodesV2 = [
24
+ rsbuildConfigGlob,
25
+ async (configFilePaths, options, context) => {
26
+ const optionsHash = (0, file_hasher_1.hashObject)(options);
27
+ const cachePath = (0, path_1.join)(cache_directory_1.workspaceDataDirectory, `rsbuild-${optionsHash}.hash`);
28
+ const targetsCache = readTargetsCache(cachePath);
29
+ const isUsingTsSolutionSetup = (0, ts_solution_setup_1.isUsingTsSolutionSetup)();
30
+ try {
31
+ return await (0, devkit_1.createNodesFromFiles)((configFile, options, context) => createNodesInternal(configFile, options, context, targetsCache, isUsingTsSolutionSetup), configFilePaths, options, context);
32
+ }
33
+ finally {
34
+ writeTargetsCache(cachePath, targetsCache);
35
+ }
36
+ },
37
+ ];
38
+ async function createNodesInternal(configFilePath, options, context, targetsCache, isUsingTsSolutionSetup) {
39
+ const projectRoot = (0, path_1.dirname)(configFilePath);
40
+ // Do not create a project if package.json and project.json isn't there.
41
+ const siblingFiles = (0, fs_1.readdirSync)((0, path_1.join)(context.workspaceRoot, projectRoot));
42
+ if (!siblingFiles.includes('package.json') &&
43
+ !siblingFiles.includes('project.json')) {
44
+ return {};
45
+ }
46
+ const tsConfigFiles = siblingFiles.filter((p) => (0, minimatch_1.minimatch)(p, 'tsconfig*{.json,.*.json}')) ?? [];
47
+ const normalizedOptions = normalizeOptions(options);
48
+ const hash = await (0, calculate_hash_for_create_nodes_1.calculateHashForCreateNodes)(projectRoot, normalizedOptions, context, [(0, js_1.getLockFileName)((0, devkit_1.detectPackageManager)(context.workspaceRoot))]);
49
+ targetsCache[hash] ??= await createRsbuildTargets(configFilePath, projectRoot, normalizedOptions, tsConfigFiles, isUsingTsSolutionSetup, context);
50
+ const { targets, metadata } = targetsCache[hash];
51
+ return {
52
+ projects: {
53
+ [projectRoot]: {
54
+ root: projectRoot,
55
+ targets,
56
+ metadata,
57
+ },
58
+ },
59
+ };
60
+ }
61
+ async function createRsbuildTargets(configFilePath, projectRoot, options, tsConfigFiles, isUsingTsSolutionSetup, context) {
62
+ const absoluteConfigFilePath = (0, devkit_1.joinPathFragments)(context.workspaceRoot, configFilePath);
63
+ const rsbuildConfig = await (0, core_1.loadConfig)({
64
+ path: absoluteConfigFilePath,
65
+ });
66
+ if (!rsbuildConfig.filePath) {
67
+ return { targets: {}, metadata: {} };
68
+ }
69
+ const namedInputs = (0, get_named_inputs_1.getNamedInputs)(projectRoot, context);
70
+ const { buildOutputs } = getOutputs(rsbuildConfig.content, projectRoot, context.workspaceRoot);
71
+ const targets = {};
72
+ targets[options.buildTargetName] = {
73
+ command: `rsbuild build`,
74
+ options: { cwd: projectRoot, args: ['--mode=production'] },
75
+ cache: true,
76
+ dependsOn: [`^${options.buildTargetName}`],
77
+ inputs: [
78
+ ...('production' in namedInputs
79
+ ? ['production', '^production']
80
+ : ['default', '^default']),
81
+ {
82
+ externalDependencies: ['@rsbuild/core'],
83
+ },
84
+ ],
85
+ outputs: buildOutputs,
86
+ metadata: {
87
+ technologies: ['rsbuild'],
88
+ description: `Run Rsbuild build`,
89
+ help: {
90
+ command: `${pmc.exec} rsbuild build --help`,
91
+ example: {
92
+ options: {
93
+ watch: false,
94
+ },
95
+ },
96
+ },
97
+ },
98
+ };
99
+ targets[options.devTargetName] = {
100
+ command: `rsbuild dev`,
101
+ options: {
102
+ cwd: projectRoot,
103
+ args: ['--mode=development'],
104
+ },
105
+ };
106
+ targets[options.previewTargetName] = {
107
+ command: `rsbuild preview`,
108
+ options: {
109
+ cwd: projectRoot,
110
+ args: ['--mode=production'],
111
+ },
112
+ };
113
+ targets[options.inspectTargetName] = {
114
+ command: `rsbuild inspect`,
115
+ options: {
116
+ cwd: projectRoot,
117
+ },
118
+ };
119
+ if (tsConfigFiles.length) {
120
+ const tsConfigToUse = ['tsconfig.app.json', 'tsconfig.lib.json', 'tsconfig.json'].find((t) => tsConfigFiles.includes(t)) ?? tsConfigFiles[0];
121
+ targets[options.typecheckTargetName] = {
122
+ cache: true,
123
+ inputs: [
124
+ ...('production' in namedInputs
125
+ ? ['production', '^production']
126
+ : ['default', '^default']),
127
+ { externalDependencies: ['typescript'] },
128
+ ],
129
+ command: isUsingTsSolutionSetup
130
+ ? `tsc --build --emitDeclarationOnly --pretty --verbose`
131
+ : `tsc --noEmit -p ${tsConfigToUse}`,
132
+ options: { cwd: (0, devkit_1.joinPathFragments)(projectRoot) },
133
+ metadata: {
134
+ description: `Run Typechecking`,
135
+ help: {
136
+ command: `${pmc.exec} tsc --help -p ${tsConfigToUse}`,
137
+ example: {
138
+ options: {
139
+ noEmit: true,
140
+ },
141
+ },
142
+ },
143
+ },
144
+ };
145
+ }
146
+ return { targets, metadata: {} };
147
+ }
148
+ function getOutputs(rsbuildConfig, projectRoot, workspaceRoot) {
149
+ const buildOutputPath = normalizeOutputPath(rsbuildConfig?.output?.distPath?.root
150
+ ? (0, path_1.dirname)(rsbuildConfig?.output.distPath.root)
151
+ : undefined, projectRoot, workspaceRoot, 'dist');
152
+ return {
153
+ buildOutputs: [buildOutputPath],
154
+ };
155
+ }
156
+ function normalizeOutputPath(outputPath, projectRoot, workspaceRoot, path) {
157
+ if (!outputPath) {
158
+ if (projectRoot === '.') {
159
+ return `{projectRoot}/${path}`;
160
+ }
161
+ else {
162
+ return `{workspaceRoot}/${path}/{projectRoot}`;
163
+ }
164
+ }
165
+ else {
166
+ if ((0, path_1.isAbsolute)(outputPath)) {
167
+ return `{workspaceRoot}/${(0, path_1.relative)(workspaceRoot, outputPath)}`;
168
+ }
169
+ else {
170
+ if (outputPath.startsWith('..')) {
171
+ return (0, path_1.join)('{workspaceRoot}', (0, path_1.join)(projectRoot, outputPath));
172
+ }
173
+ else {
174
+ return (0, path_1.join)('{projectRoot}', outputPath);
175
+ }
176
+ }
177
+ }
178
+ }
179
+ function normalizeOptions(options) {
180
+ options ??= {};
181
+ options.buildTargetName ??= 'build';
182
+ options.devTargetName ??= 'dev';
183
+ options.previewTargetName ??= 'preview';
184
+ options.inspectTargetName ??= 'inspect';
185
+ options.typecheckTargetName ??= 'typecheck';
186
+ return options;
187
+ }
@@ -0,0 +1,2 @@
1
+ export declare const nxVersion: any;
2
+ export declare const rsbuildVersion = "1.1.8";
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.rsbuildVersion = exports.nxVersion = void 0;
4
+ exports.nxVersion = require('../../package.json').version;
5
+ exports.rsbuildVersion = '1.1.8';