@nx/rspack 0.0.0-pr-28218-5048fd1

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.
Files changed (133) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +117 -0
  3. package/executors.json +35 -0
  4. package/generators.json +31 -0
  5. package/migrations.json +98 -0
  6. package/module-federation.d.ts +1 -0
  7. package/module-federation.js +4 -0
  8. package/package.json +49 -0
  9. package/plugin.d.ts +2 -0
  10. package/plugin.js +6 -0
  11. package/src/executors/dev-server/dev-server.impl.d.ts +6 -0
  12. package/src/executors/dev-server/dev-server.impl.js +50 -0
  13. package/src/executors/dev-server/lib/get-dev-server-config.d.ts +4 -0
  14. package/src/executors/dev-server/lib/get-dev-server-config.js +69 -0
  15. package/src/executors/dev-server/lib/serve-path.d.ts +3 -0
  16. package/src/executors/dev-server/lib/serve-path.js +44 -0
  17. package/src/executors/dev-server/schema.d.ts +12 -0
  18. package/src/executors/dev-server/schema.json +45 -0
  19. package/src/executors/module-federation-dev-server/module-federation-dev-server.impl.d.ts +6 -0
  20. package/src/executors/module-federation-dev-server/module-federation-dev-server.impl.js +177 -0
  21. package/src/executors/module-federation-dev-server/schema.d.ts +18 -0
  22. package/src/executors/module-federation-dev-server/schema.json +98 -0
  23. package/src/executors/module-federation-ssr-dev-server/module-federation-ssr-dev-server.impl.d.ts +21 -0
  24. package/src/executors/module-federation-ssr-dev-server/module-federation-ssr-dev-server.impl.js +214 -0
  25. package/src/executors/module-federation-ssr-dev-server/schema.json +79 -0
  26. package/src/executors/module-federation-static-server/module-federation-static-server.impl.d.ts +12 -0
  27. package/src/executors/module-federation-static-server/module-federation-static-server.impl.js +244 -0
  28. package/src/executors/module-federation-static-server/schema.d.ts +3 -0
  29. package/src/executors/module-federation-static-server/schema.json +14 -0
  30. package/src/executors/rspack/rspack.impl.d.ts +6 -0
  31. package/src/executors/rspack/rspack.impl.js +118 -0
  32. package/src/executors/rspack/schema.d.ts +34 -0
  33. package/src/executors/rspack/schema.json +177 -0
  34. package/src/executors/ssr-dev-server/lib/wait-until-server-is-listening.d.ts +1 -0
  35. package/src/executors/ssr-dev-server/lib/wait-until-server-is-listening.js +39 -0
  36. package/src/executors/ssr-dev-server/schema.d.ts +11 -0
  37. package/src/executors/ssr-dev-server/schema.json +36 -0
  38. package/src/executors/ssr-dev-server/ssr-dev-server.impl.d.ts +8 -0
  39. package/src/executors/ssr-dev-server/ssr-dev-server.impl.js +38 -0
  40. package/src/generators/application/application.d.ts +3 -0
  41. package/src/generators/application/application.js +90 -0
  42. package/src/generators/application/lib/create-ts-config.d.ts +3 -0
  43. package/src/generators/application/lib/create-ts-config.js +49 -0
  44. package/src/generators/application/lib/normalize-options.d.ts +5 -0
  45. package/src/generators/application/lib/normalize-options.js +42 -0
  46. package/src/generators/application/schema.d.ts +16 -0
  47. package/src/generators/application/schema.json +98 -0
  48. package/src/generators/configuration/configuration.d.ts +4 -0
  49. package/src/generators/configuration/configuration.js +79 -0
  50. package/src/generators/configuration/schema.d.ts +12 -0
  51. package/src/generators/configuration/schema.json +73 -0
  52. package/src/generators/init/init.d.ts +5 -0
  53. package/src/generators/init/init.js +71 -0
  54. package/src/generators/init/schema.d.ts +11 -0
  55. package/src/generators/init/schema.json +31 -0
  56. package/src/generators/preset/preset.d.ts +3 -0
  57. package/src/generators/preset/preset.js +34 -0
  58. package/src/generators/preset/schema.d.ts +18 -0
  59. package/src/generators/preset/schema.json +71 -0
  60. package/src/index.d.ts +6 -0
  61. package/src/index.js +9 -0
  62. package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.d.ts +2 -0
  63. package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.js +9 -0
  64. package/src/plugins/generate-package-json-plugin.d.ts +12 -0
  65. package/src/plugins/generate-package-json-plugin.js +46 -0
  66. package/src/plugins/plugin.d.ts +9 -0
  67. package/src/plugins/plugin.js +149 -0
  68. package/src/utils/config.d.ts +17 -0
  69. package/src/utils/config.js +22 -0
  70. package/src/utils/create-compiler.d.ts +7 -0
  71. package/src/utils/create-compiler.js +33 -0
  72. package/src/utils/generator-utils.d.ts +34 -0
  73. package/src/utils/generator-utils.js +444 -0
  74. package/src/utils/get-copy-patterns.d.ts +9 -0
  75. package/src/utils/get-copy-patterns.js +22 -0
  76. package/src/utils/jest-utils.d.ts +1 -0
  77. package/src/utils/jest-utils.js +8 -0
  78. package/src/utils/mode-utils.d.ts +2 -0
  79. package/src/utils/mode-utils.js +6 -0
  80. package/src/utils/model.d.ts +6 -0
  81. package/src/utils/model.js +2 -0
  82. package/src/utils/module-federation/build-static.remotes.d.ts +4 -0
  83. package/src/utils/module-federation/build-static.remotes.js +69 -0
  84. package/src/utils/module-federation/dependencies.d.ts +6 -0
  85. package/src/utils/module-federation/dependencies.js +56 -0
  86. package/src/utils/module-federation/get-remotes-for-host.d.ts +16 -0
  87. package/src/utils/module-federation/get-remotes-for-host.js +99 -0
  88. package/src/utils/module-federation/index.d.ts +6 -0
  89. package/src/utils/module-federation/index.js +9 -0
  90. package/src/utils/module-federation/models/index.d.ts +47 -0
  91. package/src/utils/module-federation/models/index.js +2 -0
  92. package/src/utils/module-federation/package-json.d.ts +8 -0
  93. package/src/utils/module-federation/package-json.js +12 -0
  94. package/src/utils/module-federation/parse-static-remotes-config.d.ts +13 -0
  95. package/src/utils/module-federation/parse-static-remotes-config.js +34 -0
  96. package/src/utils/module-federation/plugins/runtime-library-control.plugin.d.ts +3 -0
  97. package/src/utils/module-federation/plugins/runtime-library-control.plugin.js +54 -0
  98. package/src/utils/module-federation/public-api.d.ts +8 -0
  99. package/src/utils/module-federation/public-api.js +20 -0
  100. package/src/utils/module-federation/remotes.d.ts +19 -0
  101. package/src/utils/module-federation/remotes.js +77 -0
  102. package/src/utils/module-federation/secondary-entry-points.d.ts +12 -0
  103. package/src/utils/module-federation/secondary-entry-points.js +104 -0
  104. package/src/utils/module-federation/share.d.ts +48 -0
  105. package/src/utils/module-federation/share.js +235 -0
  106. package/src/utils/module-federation/start-remote-proxies.d.ts +5 -0
  107. package/src/utils/module-federation/start-remote-proxies.js +45 -0
  108. package/src/utils/module-federation/start-ssr-remote-proxies.d.ts +5 -0
  109. package/src/utils/module-federation/start-ssr-remote-proxies.js +59 -0
  110. package/src/utils/module-federation/typescript.d.ts +4 -0
  111. package/src/utils/module-federation/typescript.js +53 -0
  112. package/src/utils/module-federation/with-module-federation/package-json.d.ts +8 -0
  113. package/src/utils/module-federation/with-module-federation/package-json.js +12 -0
  114. package/src/utils/module-federation/with-module-federation/utils.d.ts +12 -0
  115. package/src/utils/module-federation/with-module-federation/utils.js +76 -0
  116. package/src/utils/module-federation/with-module-federation/with-module-federation-ssr.d.ts +3 -0
  117. package/src/utils/module-federation/with-module-federation/with-module-federation-ssr.js +55 -0
  118. package/src/utils/module-federation/with-module-federation/with-module-federation.d.ts +8 -0
  119. package/src/utils/module-federation/with-module-federation/with-module-federation.js +70 -0
  120. package/src/utils/normalize-assets.d.ts +1 -0
  121. package/src/utils/normalize-assets.js +42 -0
  122. package/src/utils/read-rspack-options.d.ts +10 -0
  123. package/src/utils/read-rspack-options.js +37 -0
  124. package/src/utils/resolve-user-defined-rspack-config.d.ts +3 -0
  125. package/src/utils/resolve-user-defined-rspack-config.js +38 -0
  126. package/src/utils/versions.d.ts +21 -0
  127. package/src/utils/versions.js +24 -0
  128. package/src/utils/with-nx.d.ts +3 -0
  129. package/src/utils/with-nx.js +187 -0
  130. package/src/utils/with-react.d.ts +3 -0
  131. package/src/utils/with-react.js +69 -0
  132. package/src/utils/with-web.d.ts +9 -0
  133. package/src/utils/with-web.js +106 -0
@@ -0,0 +1,36 @@
1
+ {
2
+ "outputCapture": "direct-nodejs",
3
+ "title": "Rspack SSR Dev Server",
4
+ "description": "Serve a SSR application using rspack.",
5
+ "cli": "nx",
6
+ "type": "object",
7
+ "properties": {
8
+ "browserTarget": {
9
+ "type": "string",
10
+ "description": "Target which builds the browser application.",
11
+ "x-priority": "important"
12
+ },
13
+ "serverTarget": {
14
+ "type": "string",
15
+ "description": "Target which builds the server application.",
16
+ "x-priority": "important"
17
+ },
18
+ "port": {
19
+ "type": "number",
20
+ "description": "The port to be set on `process.env.PORT` for use in the server.",
21
+ "default": 4200,
22
+ "x-priority": "important"
23
+ },
24
+ "browserTargetOptions": {
25
+ "type": "object",
26
+ "description": "Additional options to pass into the browser build target.",
27
+ "default": {}
28
+ },
29
+ "serverTargetOptions": {
30
+ "type": "object",
31
+ "description": "Additional options to pass into the server build target.",
32
+ "default": {}
33
+ }
34
+ },
35
+ "required": ["browserTarget", "serverTarget"]
36
+ }
@@ -0,0 +1,8 @@
1
+ import { ExecutorContext } from '@nx/devkit';
2
+ import { RspackSsrDevServerOptions, TargetOptions } from './schema';
3
+ export declare function ssrDevServerExecutor(options: RspackSsrDevServerOptions, context: ExecutorContext): AsyncGenerator<{
4
+ baseUrl: string;
5
+ success: boolean;
6
+ options: TargetOptions;
7
+ }, void, unknown>;
8
+ export default ssrDevServerExecutor;
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ssrDevServerExecutor = ssrDevServerExecutor;
4
+ const tslib_1 = require("tslib");
5
+ const devkit_1 = require("@nx/devkit");
6
+ const async_iterable_1 = require("@nx/devkit/src/utils/async-iterable");
7
+ const chalk = tslib_1.__importStar(require("chalk"));
8
+ const wait_until_server_is_listening_1 = require("./lib/wait-until-server-is-listening");
9
+ async function* ssrDevServerExecutor(options, context) {
10
+ const browserTarget = (0, devkit_1.parseTargetString)(options.browserTarget, context.projectGraph);
11
+ const serverTarget = (0, devkit_1.parseTargetString)(options.serverTarget, context);
12
+ const browserOptions = (0, devkit_1.readTargetOptions)(browserTarget, context);
13
+ const serverOptions = (0, devkit_1.readTargetOptions)(serverTarget, context);
14
+ const runBrowser = await (0, devkit_1.runExecutor)(browserTarget, { ...browserOptions, ...options.browserTargetOptions }, context);
15
+ const runServer = await (0, devkit_1.runExecutor)(serverTarget, { ...serverOptions, ...options.serverTargetOptions }, context);
16
+ let browserBuilt = false;
17
+ let nodeStarted = false;
18
+ const combined = (0, async_iterable_1.combineAsyncIterables)(runBrowser, runServer);
19
+ for await (const output of combined) {
20
+ if (!output.success)
21
+ throw new Error('Could not build application');
22
+ if (output.options?.target === 'node') {
23
+ nodeStarted = true;
24
+ }
25
+ else if (output.options?.target === 'web') {
26
+ browserBuilt = true;
27
+ }
28
+ if (nodeStarted && browserBuilt) {
29
+ await (0, wait_until_server_is_listening_1.waitUntilServerIsListening)(options.port);
30
+ console.log(`[ ${chalk.green('ready')} ] on http://localhost:${options.port}`);
31
+ yield {
32
+ ...output,
33
+ baseUrl: `http://localhost:${options.port}`,
34
+ };
35
+ }
36
+ }
37
+ }
38
+ exports.default = ssrDevServerExecutor;
@@ -0,0 +1,3 @@
1
+ import { Tree } from '@nx/devkit';
2
+ import { ApplicationGeneratorSchema } from './schema';
3
+ export default function (tree: Tree, _options: ApplicationGeneratorSchema): Promise<import("@nx/devkit").GeneratorCallback>;
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = default_1;
4
+ const tslib_1 = require("tslib");
5
+ const devkit_1 = require("@nx/devkit");
6
+ const package_json_1 = require("nx/package.json");
7
+ const configuration_1 = tslib_1.__importDefault(require("../configuration/configuration"));
8
+ const init_1 = tslib_1.__importDefault(require("../init/init"));
9
+ const normalize_options_1 = require("./lib/normalize-options");
10
+ async function default_1(tree, _options) {
11
+ const tasks = [];
12
+ const initTask = await (0, init_1.default)(tree, {
13
+ ..._options,
14
+ // TODO: Crystalize the default rspack.config.js file.
15
+ // The default setup isn't crystalized so don't add plugin.
16
+ addPlugin: false,
17
+ });
18
+ tasks.push(initTask);
19
+ const options = (0, normalize_options_1.normalizeOptions)(tree, _options);
20
+ options.style ??= 'css';
21
+ if (options.framework === 'nest') {
22
+ const { applicationGenerator: nestAppGenerator } = (0, devkit_1.ensurePackage)('@nx/nest', package_json_1.version);
23
+ const createAppTask = await nestAppGenerator(tree, {
24
+ ...options,
25
+ skipFormat: true,
26
+ tags: options.tags ?? '',
27
+ addPlugin: false,
28
+ });
29
+ const convertAppTask = await (0, configuration_1.default)(tree, {
30
+ project: options.name,
31
+ target: 'node',
32
+ newProject: false,
33
+ buildTarget: 'build',
34
+ framework: 'nest',
35
+ });
36
+ tasks.push(createAppTask, convertAppTask);
37
+ }
38
+ else if (options.framework === 'web') {
39
+ const { applicationGenerator: webAppGenerator } = (0, devkit_1.ensurePackage)('@nx/web', package_json_1.version);
40
+ const createAppTask = await webAppGenerator(tree, {
41
+ bundler: 'webpack',
42
+ name: options.name,
43
+ style: options.style,
44
+ directory: options.directory,
45
+ tags: options.tags ?? '',
46
+ unitTestRunner: options.unitTestRunner,
47
+ e2eTestRunner: options.e2eTestRunner,
48
+ rootProject: options.rootProject,
49
+ skipFormat: true,
50
+ addPlugin: false,
51
+ });
52
+ const convertAppTask = await (0, configuration_1.default)(tree, {
53
+ project: options.name,
54
+ target: 'web',
55
+ newProject: false,
56
+ buildTarget: 'build',
57
+ serveTarget: 'serve',
58
+ framework: 'web',
59
+ addPlugin: false,
60
+ });
61
+ tasks.push(createAppTask, convertAppTask);
62
+ }
63
+ else {
64
+ // default to react
65
+ const { applicationGenerator: reactAppGenerator } = (0, devkit_1.ensurePackage)('@nx/react', package_json_1.version);
66
+ const createAppTask = await reactAppGenerator(tree, {
67
+ bundler: 'webpack',
68
+ name: options.name,
69
+ style: options.style,
70
+ directory: options.directory,
71
+ tags: options.tags ?? '',
72
+ unitTestRunner: options.unitTestRunner,
73
+ e2eTestRunner: options.e2eTestRunner,
74
+ rootProject: options.rootProject,
75
+ skipFormat: true,
76
+ addPlugin: false,
77
+ });
78
+ const convertAppTask = await (0, configuration_1.default)(tree, {
79
+ project: options.name,
80
+ target: 'web',
81
+ newProject: false,
82
+ buildTarget: 'build',
83
+ serveTarget: 'serve',
84
+ framework: 'react',
85
+ });
86
+ tasks.push(createAppTask, convertAppTask);
87
+ }
88
+ await (0, devkit_1.formatFiles)(tree);
89
+ return (0, devkit_1.runTasksInSerial)(...tasks);
90
+ }
@@ -0,0 +1,3 @@
1
+ import { Tree } from '@nx/devkit';
2
+ import { Framework } from '../../init/schema';
3
+ export declare function editTsConfig(tree: Tree, projectRoot: string, framework: Framework, relativePathToRootTsConfig: string): void;
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.editTsConfig = editTsConfig;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const path_1 = require("path");
6
+ function editTsConfig(tree, projectRoot, framework, relativePathToRootTsConfig) {
7
+ // Nx 15.8 moved util to @nx/js, but it is in @nx/workspace in 15.7
8
+ let shared;
9
+ try {
10
+ shared = require('@nx/js/src/utils/typescript/create-ts-config');
11
+ }
12
+ catch {
13
+ shared = require('@nx/workspace/src/utils/create-ts-config');
14
+ }
15
+ if (framework === 'react') {
16
+ const json = {
17
+ compilerOptions: {
18
+ jsx: 'react-jsx',
19
+ allowJs: false,
20
+ esModuleInterop: false,
21
+ allowSyntheticDefaultImports: true,
22
+ strict: true,
23
+ },
24
+ files: [],
25
+ include: [],
26
+ references: [
27
+ {
28
+ path: './tsconfig.app.json',
29
+ },
30
+ ],
31
+ };
32
+ // inline tsconfig.base.json into the project
33
+ if (projectIsRootProjectInStandaloneWorkspace(projectRoot)) {
34
+ json.compileOnSave = false;
35
+ json.compilerOptions = {
36
+ ...shared.tsConfigBaseOptions,
37
+ ...json.compilerOptions,
38
+ };
39
+ json.exclude = ['node_modules', 'tmp'];
40
+ }
41
+ else {
42
+ json.extends = relativePathToRootTsConfig;
43
+ }
44
+ (0, devkit_1.writeJson)(tree, `${projectRoot}/tsconfig.json`, json);
45
+ }
46
+ }
47
+ function projectIsRootProjectInStandaloneWorkspace(projectRoot) {
48
+ return (0, path_1.relative)(devkit_1.workspaceRoot, projectRoot).length === 0;
49
+ }
@@ -0,0 +1,5 @@
1
+ import { Tree } from '@nx/devkit';
2
+ import { ApplicationGeneratorSchema, NormalizedSchema } from '../schema';
3
+ export declare function normalizeDirectory(options: ApplicationGeneratorSchema): string;
4
+ export declare function normalizeProjectName(options: ApplicationGeneratorSchema): string;
5
+ export declare function normalizeOptions(host: Tree, options: ApplicationGeneratorSchema): NormalizedSchema;
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.normalizeDirectory = normalizeDirectory;
4
+ exports.normalizeProjectName = normalizeProjectName;
5
+ exports.normalizeOptions = normalizeOptions;
6
+ const devkit_1 = require("@nx/devkit");
7
+ function normalizeDirectory(options) {
8
+ const { projectDirectory } = (0, devkit_1.extractLayoutDirectory)(options.directory);
9
+ return projectDirectory
10
+ ? `${(0, devkit_1.names)(projectDirectory).fileName}/${(0, devkit_1.names)(options.name).fileName}`
11
+ : (0, devkit_1.names)(options.name).fileName;
12
+ }
13
+ function normalizeProjectName(options) {
14
+ return normalizeDirectory(options).replace(new RegExp('/', 'g'), '-');
15
+ }
16
+ function normalizeOptions(host, options) {
17
+ // --monorepo takes precedence over --rootProject
18
+ // This won't be needed once we add --bundler=rspack to the @nx/react:app preset
19
+ const rootProject = !options.monorepo && options.rootProject;
20
+ const appDirectory = normalizeDirectory(options);
21
+ const appProjectName = normalizeProjectName(options);
22
+ const e2eProjectName = options.rootProject
23
+ ? 'e2e'
24
+ : `${(0, devkit_1.names)(options.name).fileName}-e2e`;
25
+ const { layoutDirectory } = (0, devkit_1.extractLayoutDirectory)(options.directory);
26
+ const appsDir = layoutDirectory ?? (0, devkit_1.getWorkspaceLayout)(host).appsDir;
27
+ const appProjectRoot = rootProject
28
+ ? '.'
29
+ : (0, devkit_1.normalizePath)(`${appsDir}/${appDirectory}`);
30
+ const normalized = {
31
+ ...options,
32
+ rootProject,
33
+ name: (0, devkit_1.names)(options.name).fileName,
34
+ projectName: appProjectName,
35
+ appProjectRoot,
36
+ e2eProjectName,
37
+ fileName: 'app',
38
+ };
39
+ normalized.unitTestRunner ??= 'jest';
40
+ normalized.e2eTestRunner ??= 'cypress';
41
+ return normalized;
42
+ }
@@ -0,0 +1,16 @@
1
+ export interface ApplicationGeneratorSchema {
2
+ name: string;
3
+ framework?: Framework;
4
+ style: 'css' | 'scss' | 'less' | 'styl';
5
+ unitTestRunner?: 'none' | 'jest';
6
+ e2eTestRunner?: 'none' | 'cypress';
7
+ directory?: string;
8
+ tags?: string;
9
+ rootProject?: boolean;
10
+ monorepo?: boolean;
11
+ }
12
+
13
+ export interface NormalizedSchema extends ApplicationGeneratorSchema {
14
+ appProjectRoot: string;
15
+ e2eProjectName: string;
16
+ }
@@ -0,0 +1,98 @@
1
+ {
2
+ "$schema": "http://json-schema.org/schema",
3
+ "$id": "Application",
4
+ "title": "Application generator for React + rspack",
5
+ "type": "object",
6
+ "description": "React + Rspack application generator.",
7
+ "examples": [
8
+ {
9
+ "command": "nx g app myapp --directory=myorg",
10
+ "description": "Generate `apps/myorg/myapp` and `apps/myorg/myapp-e2e`"
11
+ }
12
+ ],
13
+ "properties": {
14
+ "name": {
15
+ "description": "The name of the application.",
16
+ "type": "string",
17
+ "$default": {
18
+ "$source": "argv",
19
+ "index": 0
20
+ },
21
+ "x-prompt": "What name would you like to use for the application?",
22
+ "pattern": "^[a-zA-Z].*$",
23
+ "x-priority": "important"
24
+ },
25
+ "framework": {
26
+ "type": "string",
27
+ "description": "The framework to use for the application.",
28
+ "x-prompt": "What framework do you want to use when generating this application?",
29
+ "enum": ["none", "react", "web", "nest"],
30
+ "alias": ["uiFramework"],
31
+ "x-priority": "important",
32
+ "default": "react"
33
+ },
34
+ "style": {
35
+ "description": "The file extension to be used for style files.",
36
+ "type": "string",
37
+ "default": "css",
38
+ "alias": "s",
39
+ "x-prompt": {
40
+ "message": "Which stylesheet format would you like to use?",
41
+ "type": "list",
42
+ "items": [
43
+ {
44
+ "value": "css",
45
+ "label": "CSS"
46
+ },
47
+ {
48
+ "value": "scss",
49
+ "label": "SASS(.scss) [ http://sass-lang.com ]"
50
+ },
51
+ {
52
+ "value": "styl",
53
+ "label": "Stylus(.styl) [ http://stylus-lang.com ]"
54
+ },
55
+ {
56
+ "value": "less",
57
+ "label": "LESS [ http://lesscss.org ]"
58
+ },
59
+ {
60
+ "value": "none",
61
+ "label": "None"
62
+ }
63
+ ]
64
+ }
65
+ },
66
+ "unitTestRunner": {
67
+ "type": "string",
68
+ "description": "The unit test runner to use.",
69
+ "enum": ["none", "jest"],
70
+ "default": "jest"
71
+ },
72
+ "e2eTestRunner": {
73
+ "type": "string",
74
+ "description": "The e2e test runner to use.",
75
+ "enum": ["none", "cypress"],
76
+ "default": "cypress"
77
+ },
78
+ "directory": {
79
+ "type": "string",
80
+ "description": "The directory to nest the app under."
81
+ },
82
+ "tags": {
83
+ "type": "string",
84
+ "description": "Add tags to the application (used for linting).",
85
+ "alias": "t"
86
+ },
87
+ "monorepo": {
88
+ "type": "boolean",
89
+ "description": "Creates an integrated monorepo.",
90
+ "aliases": ["integrated"]
91
+ },
92
+ "rootProject": {
93
+ "type": "boolean",
94
+ "x-priority": "internal"
95
+ }
96
+ },
97
+ "required": ["name"]
98
+ }
@@ -0,0 +1,4 @@
1
+ import { Tree } from '@nx/devkit';
2
+ import { ConfigurationSchema } from './schema';
3
+ export declare function configurationGenerator(tree: Tree, options: ConfigurationSchema): Promise<import("@nx/devkit").GeneratorCallback>;
4
+ export default configurationGenerator;
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.configurationGenerator = configurationGenerator;
4
+ const tslib_1 = require("tslib");
5
+ const devkit_1 = require("@nx/devkit");
6
+ const generator_utils_1 = require("../../utils/generator-utils");
7
+ const create_ts_config_1 = require("../application/lib/create-ts-config");
8
+ const init_1 = tslib_1.__importDefault(require("../init/init"));
9
+ async function configurationGenerator(tree, options) {
10
+ const task = await (0, init_1.default)(tree, {
11
+ ...options,
12
+ // TODO: Crystalize the default rspack.config.js file.
13
+ // The default setup isn't crystalized so don't add plugin.
14
+ addPlugin: false,
15
+ });
16
+ const { targets, root, projectType } = (0, devkit_1.readProjectConfiguration)(tree, options.project);
17
+ const { target, framework } = (0, generator_utils_1.determineFrameworkAndTarget)(tree, options, root, targets);
18
+ options.framework = framework;
19
+ options.target = target;
20
+ let foundStylePreprocessorOptions;
21
+ let buildTargetName = 'build';
22
+ let serveTargetName = 'serve';
23
+ /**
24
+ * This is for when we are converting an existing project
25
+ * to use the vite executors.
26
+ */
27
+ let projectAlreadyHasRspackTargets = {};
28
+ if (!options.newProject) {
29
+ const userProvidedTargetName = {
30
+ build: options.buildTarget,
31
+ serve: options.serveTarget,
32
+ };
33
+ const { validFoundTargetName, projectContainsUnsupportedExecutor, userProvidedTargetIsUnsupported, alreadyHasNxRspackTargets, } = (0, generator_utils_1.findExistingTargetsInProject)(targets, userProvidedTargetName);
34
+ projectAlreadyHasRspackTargets = alreadyHasNxRspackTargets;
35
+ if (alreadyHasNxRspackTargets.build &&
36
+ (alreadyHasNxRspackTargets.serve ||
37
+ projectType === 'library' ||
38
+ options.framework === 'nest')) {
39
+ throw new Error(`The project ${options.project} is already configured to use the @nx/rspack executors.
40
+ Please try a different project, or remove the existing targets
41
+ and re-run this generator to reset the existing Rspack Configuration.
42
+ `);
43
+ }
44
+ if (!validFoundTargetName.build && projectContainsUnsupportedExecutor) {
45
+ throw new Error(`The project ${options.project} cannot be converted to use the @nx/rspack executors.`);
46
+ }
47
+ if (!projectContainsUnsupportedExecutor &&
48
+ !validFoundTargetName.build &&
49
+ !validFoundTargetName.serve) {
50
+ await (0, generator_utils_1.handleUnknownExecutors)(options.project);
51
+ }
52
+ await (0, generator_utils_1.handleUnsupportedUserProvidedTargets)(userProvidedTargetIsUnsupported, userProvidedTargetName, validFoundTargetName, options.framework);
53
+ /**
54
+ * Once the user is at this stage, then they can go ahead and convert.
55
+ */
56
+ buildTargetName = validFoundTargetName.build ?? buildTargetName;
57
+ serveTargetName = validFoundTargetName.serve ?? serveTargetName;
58
+ // Not needed atm
59
+ // if (projectType === 'application' && options.target !== 'node') {
60
+ // moveAndEditIndexHtml(tree, options, buildTargetName);
61
+ // }
62
+ foundStylePreprocessorOptions =
63
+ targets?.[buildTargetName]?.options?.stylePreprocessorOptions;
64
+ (0, generator_utils_1.deleteWebpackConfig)(tree, root, targets?.[buildTargetName]?.options?.webpackConfig);
65
+ (0, create_ts_config_1.editTsConfig)(tree, root, options.framework, (0, devkit_1.joinPathFragments)((0, devkit_1.offsetFromRoot)(root), 'tsconfig.base.json'));
66
+ }
67
+ if (!projectAlreadyHasRspackTargets.build) {
68
+ (0, generator_utils_1.addOrChangeBuildTarget)(tree, options, buildTargetName);
69
+ }
70
+ if ((options.framework !== 'none' || options.devServer) &&
71
+ options.framework !== 'nest' &&
72
+ !projectAlreadyHasRspackTargets.serve) {
73
+ (0, generator_utils_1.addOrChangeServeTarget)(tree, options, serveTargetName);
74
+ }
75
+ (0, generator_utils_1.writeRspackConfigFile)(tree, options, foundStylePreprocessorOptions);
76
+ await (0, devkit_1.formatFiles)(tree);
77
+ return task;
78
+ }
79
+ exports.default = configurationGenerator;
@@ -0,0 +1,12 @@
1
+ import { InitGeneratorSchema } from '../init/schema';
2
+
3
+ export interface ConfigurationSchema extends InitGeneratorSchema {
4
+ project: string;
5
+ main?: string;
6
+ tsConfig?: string;
7
+ target?: 'node' | 'web';
8
+ skipValidation?: boolean;
9
+ newProject?: boolean;
10
+ buildTarget?: string;
11
+ serveTarget?: string;
12
+ }
@@ -0,0 +1,73 @@
1
+ {
2
+ "$schema": "http://json-schema.org/schema",
3
+ "$id": "Rspack",
4
+ "title": "Nx Rspack Configuration Generator",
5
+ "description": "Rspack 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 rspack for?",
17
+ "x-priority": "important"
18
+ },
19
+ "framework": {
20
+ "type": "string",
21
+ "description": "The framework used by the project.",
22
+ "x-prompt": "What framework is the project you want to convert using?",
23
+ "enum": ["none", "react", "web", "nest"],
24
+ "alias": ["uiFramework"],
25
+ "x-priority": "important"
26
+ },
27
+ "main": {
28
+ "type": "string",
29
+ "description": "Path relative to the workspace root for the main entry file. Defaults to '<projectRoot>/src/main.ts'.",
30
+ "x-priority": "important"
31
+ },
32
+ "tsConfig": {
33
+ "type": "string",
34
+ "description": "Path relative to the workspace root for the tsconfig file to build with. Defaults to '<projectRoot>/tsconfig.app.json'.",
35
+ "x-priority": "important"
36
+ },
37
+ "target": {
38
+ "type": "string",
39
+ "description": "Target platform for the build, same as the rspack config option.",
40
+ "enum": ["node", "web"],
41
+ "default": "web"
42
+ },
43
+ "devServer": {
44
+ "type": "boolean",
45
+ "description": "Add a serve target to run a local rspack dev-server",
46
+ "default": false
47
+ },
48
+ "style": {
49
+ "type": "string",
50
+ "description": "The style solution to use.",
51
+ "enum": ["none", "css", "scss", "less"]
52
+ },
53
+ "newProject": {
54
+ "type": "boolean",
55
+ "description": "Is this a new project?",
56
+ "default": false,
57
+ "hidden": true
58
+ },
59
+ "buildTarget": {
60
+ "type": "string",
61
+ "description": "The build target of the project to be transformed to use the @nx/vite:build executor."
62
+ },
63
+ "serveTarget": {
64
+ "type": "string",
65
+ "description": "The serve target of the project to be transformed to use the @nx/vite:dev-server and @nx/vite:preview-server executors."
66
+ },
67
+ "rootProject": {
68
+ "type": "boolean",
69
+ "x-priority": "internal"
70
+ }
71
+ },
72
+ "required": ["project"]
73
+ }
@@ -0,0 +1,5 @@
1
+ import { GeneratorCallback, Tree } from '@nx/devkit';
2
+ import { InitGeneratorSchema } from './schema';
3
+ export declare function rspackInitGenerator(tree: Tree, schema: InitGeneratorSchema): Promise<GeneratorCallback>;
4
+ export default rspackInitGenerator;
5
+ export declare const rspackInitSchematic: (generatorOptions: InitGeneratorSchema) => (tree: any, context: any) => Promise<any>;
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.rspackInitSchematic = void 0;
4
+ exports.rspackInitGenerator = rspackInitGenerator;
5
+ const devkit_1 = require("@nx/devkit");
6
+ const add_plugin_1 = require("@nx/devkit/src/utils/add-plugin");
7
+ const js_1 = require("@nx/js");
8
+ const plugin_1 = require("../../../plugin");
9
+ const versions_1 = require("../../utils/versions");
10
+ async function rspackInitGenerator(tree, schema) {
11
+ const tasks = [];
12
+ const nxJson = (0, devkit_1.readNxJson)(tree);
13
+ const addPluginDefault = process.env.NX_ADD_PLUGINS !== 'false' &&
14
+ nxJson.useInferencePlugins !== false;
15
+ schema.addPlugin ??= addPluginDefault;
16
+ if (schema.addPlugin) {
17
+ await (0, add_plugin_1.addPlugin)(tree, await (0, devkit_1.createProjectGraphAsync)(), '@nx/rspack/plugin', plugin_1.createNodesV2, {
18
+ buildTargetName: [
19
+ 'build',
20
+ 'rspack:build',
21
+ 'build:rspack',
22
+ 'rspack-build',
23
+ 'build-rspack',
24
+ ],
25
+ serveTargetName: [
26
+ 'serve',
27
+ 'rspack:serve',
28
+ 'serve:rspack',
29
+ 'rspack-serve',
30
+ 'serve-rspack',
31
+ ],
32
+ previewTargetName: [
33
+ 'preview',
34
+ 'rspack:preview',
35
+ 'preview:rspack',
36
+ 'rspack-preview',
37
+ 'preview-rspack',
38
+ ],
39
+ }, schema.updatePackageScripts);
40
+ }
41
+ const jsInitTask = await (0, js_1.initGenerator)(tree, {
42
+ ...schema,
43
+ tsConfigName: schema.rootProject ? 'tsconfig.json' : 'tsconfig.base.json',
44
+ skipFormat: true,
45
+ });
46
+ tasks.push(jsInitTask);
47
+ const devDependencies = {
48
+ '@rspack/core': versions_1.rspackCoreVersion,
49
+ '@rspack/cli': versions_1.rspackCoreVersion,
50
+ '@rspack/plugin-minify': versions_1.rspackPluginMinifyVersion,
51
+ '@rspack/plugin-react-refresh': versions_1.rspackPluginReactRefreshVersion,
52
+ 'react-refresh': versions_1.reactRefreshVersion,
53
+ };
54
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
55
+ const version = require('../../../package.json').version;
56
+ if (version !== '0.0.1') {
57
+ // Ignored for local dev / e2e tests.
58
+ devDependencies['@nx/rspack'] = version;
59
+ }
60
+ if (schema.style === 'less') {
61
+ devDependencies['less-loader'] = versions_1.lessLoaderVersion;
62
+ }
63
+ if (schema.framework !== 'none' || schema.devServer) {
64
+ devDependencies['@rspack/dev-server'] = versions_1.rspackDevServerVersion;
65
+ }
66
+ const installTask = (0, devkit_1.addDependenciesToPackageJson)(tree, {}, devDependencies, undefined, schema.keepExistingVersions);
67
+ tasks.push(installTask);
68
+ return (0, devkit_1.runTasksInSerial)(...tasks);
69
+ }
70
+ exports.default = rspackInitGenerator;
71
+ exports.rspackInitSchematic = (0, devkit_1.convertNxGenerator)(rspackInitGenerator);
@@ -0,0 +1,11 @@
1
+ export type Framework = 'none' | 'react' | 'web' | 'nest';
2
+
3
+ export interface InitGeneratorSchema {
4
+ addPlugin?: boolean;
5
+ devServer?: boolean;
6
+ framework?: Framework;
7
+ keepExistingVersions?: boolean;
8
+ rootProject?: boolean;
9
+ style?: 'none' | 'css' | 'scss' | 'less' | 'styl';
10
+ updatePackageScripts?: boolean;
11
+ }