@nx/rspack 19.7.1 → 20.0.0-beta.3

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 (122) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +70 -34
  3. package/executors.json +2 -2
  4. package/module-federation.js +0 -1
  5. package/package.json +14 -9
  6. package/plugin.js +0 -1
  7. package/src/executors/dev-server/dev-server.impl.js +39 -38
  8. package/src/executors/dev-server/lib/get-dev-server-config.js +1 -3
  9. package/src/executors/dev-server/lib/serve-path.js +0 -1
  10. package/src/executors/dev-server/schema.json +3 -9
  11. package/src/executors/module-federation-dev-server/module-federation-dev-server.impl.js +109 -98
  12. package/src/executors/module-federation-dev-server/schema.json +1 -3
  13. package/src/executors/module-federation-ssr-dev-server/module-federation-ssr-dev-server.impl.js +153 -148
  14. package/src/executors/module-federation-ssr-dev-server/schema.json +1 -4
  15. package/src/executors/module-federation-static-server/module-federation-static-server.impl.js +117 -125
  16. package/src/executors/rspack/rspack.impl.js +60 -67
  17. package/src/executors/rspack/schema.json +6 -26
  18. package/src/executors/ssr-dev-server/lib/wait-until-server-is-listening.js +0 -1
  19. package/src/executors/ssr-dev-server/schema.json +1 -4
  20. package/src/executors/ssr-dev-server/ssr-dev-server.impl.js +26 -40
  21. package/src/generators/application/application.js +79 -76
  22. package/src/generators/application/lib/create-ts-config.js +5 -3
  23. package/src/generators/application/lib/normalize-options.js +12 -7
  24. package/src/generators/application/schema.json +1 -0
  25. package/src/generators/configuration/configuration.js +63 -65
  26. package/src/generators/configuration/schema.json +2 -1
  27. package/src/generators/init/init.js +58 -59
  28. package/src/generators/init/schema.json +2 -1
  29. package/src/generators/preset/preset.js +26 -29
  30. package/src/generators/preset/schema.json +1 -0
  31. package/src/index.js +0 -1
  32. package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.js +3 -7
  33. package/src/plugins/generate-package-json-plugin.js +1 -3
  34. package/src/plugins/plugin.js +81 -90
  35. package/src/utils/config.js +7 -11
  36. package/src/utils/create-compiler.js +21 -25
  37. package/src/utils/generator-utils.js +55 -66
  38. package/src/utils/get-copy-patterns.js +1 -3
  39. package/src/utils/jest-utils.js +0 -1
  40. package/src/utils/mode-utils.js +0 -1
  41. package/src/utils/model.js +0 -1
  42. package/src/utils/module-federation/build-static.remotes.js +57 -61
  43. package/src/utils/module-federation/dependencies.js +1 -3
  44. package/src/utils/module-federation/get-remotes-for-host.js +4 -8
  45. package/src/utils/module-federation/index.js +0 -1
  46. package/src/utils/module-federation/models/index.js +0 -1
  47. package/src/utils/module-federation/package-json.js +0 -1
  48. package/src/utils/module-federation/parse-static-remotes-config.js +2 -3
  49. package/src/utils/module-federation/plugins/runtime-library-control.plugin.js +1 -2
  50. package/src/utils/module-federation/public-api.js +0 -1
  51. package/src/utils/module-federation/remotes.js +0 -1
  52. package/src/utils/module-federation/secondary-entry-points.js +4 -5
  53. package/src/utils/module-federation/share.js +22 -19
  54. package/src/utils/module-federation/start-remote-proxies.js +0 -1
  55. package/src/utils/module-federation/start-ssr-remote-proxies.js +0 -1
  56. package/src/utils/module-federation/typescript.js +6 -6
  57. package/src/utils/module-federation/with-module-federation/package-json.js +0 -1
  58. package/src/utils/module-federation/with-module-federation/utils.js +41 -43
  59. package/src/utils/module-federation/with-module-federation/with-module-federation-ssr.js +48 -35
  60. package/src/utils/module-federation/with-module-federation/with-module-federation.js +56 -38
  61. package/src/utils/normalize-assets.js +5 -3
  62. package/src/utils/read-rspack-options.js +23 -27
  63. package/src/utils/resolve-user-defined-rspack-config.js +0 -1
  64. package/src/utils/versions.d.ts +2 -2
  65. package/src/utils/versions.js +2 -3
  66. package/src/utils/with-nx.js +30 -13
  67. package/src/utils/with-react.js +11 -5
  68. package/src/utils/with-web.js +20 -11
  69. package/module-federation.js.map +0 -1
  70. package/plugin.js.map +0 -1
  71. package/src/executors/dev-server/dev-server.impl.js.map +0 -1
  72. package/src/executors/dev-server/lib/get-dev-server-config.js.map +0 -1
  73. package/src/executors/dev-server/lib/serve-path.js.map +0 -1
  74. package/src/executors/module-federation-dev-server/module-federation-dev-server.impl.js.map +0 -1
  75. package/src/executors/module-federation-ssr-dev-server/module-federation-ssr-dev-server.impl.js.map +0 -1
  76. package/src/executors/module-federation-static-server/module-federation-static-server.impl.js.map +0 -1
  77. package/src/executors/rspack/rspack.impl.js.map +0 -1
  78. package/src/executors/ssr-dev-server/lib/wait-until-server-is-listening.js.map +0 -1
  79. package/src/executors/ssr-dev-server/ssr-dev-server.impl.js.map +0 -1
  80. package/src/generators/application/application.js.map +0 -1
  81. package/src/generators/application/lib/create-ts-config.js.map +0 -1
  82. package/src/generators/application/lib/normalize-options.js.map +0 -1
  83. package/src/generators/configuration/configuration.js.map +0 -1
  84. package/src/generators/init/init.js.map +0 -1
  85. package/src/generators/preset/preset.js.map +0 -1
  86. package/src/index.js.map +0 -1
  87. package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.js.map +0 -1
  88. package/src/plugins/generate-package-json-plugin.js.map +0 -1
  89. package/src/plugins/plugin.js.map +0 -1
  90. package/src/utils/config.js.map +0 -1
  91. package/src/utils/create-compiler.js.map +0 -1
  92. package/src/utils/generator-utils.js.map +0 -1
  93. package/src/utils/get-copy-patterns.js.map +0 -1
  94. package/src/utils/jest-utils.js.map +0 -1
  95. package/src/utils/mode-utils.js.map +0 -1
  96. package/src/utils/model.js.map +0 -1
  97. package/src/utils/module-federation/build-static.remotes.js.map +0 -1
  98. package/src/utils/module-federation/dependencies.js.map +0 -1
  99. package/src/utils/module-federation/get-remotes-for-host.js.map +0 -1
  100. package/src/utils/module-federation/index.js.map +0 -1
  101. package/src/utils/module-federation/models/index.js.map +0 -1
  102. package/src/utils/module-federation/package-json.js.map +0 -1
  103. package/src/utils/module-federation/parse-static-remotes-config.js.map +0 -1
  104. package/src/utils/module-federation/plugins/runtime-library-control.plugin.js.map +0 -1
  105. package/src/utils/module-federation/public-api.js.map +0 -1
  106. package/src/utils/module-federation/remotes.js.map +0 -1
  107. package/src/utils/module-federation/secondary-entry-points.js.map +0 -1
  108. package/src/utils/module-federation/share.js.map +0 -1
  109. package/src/utils/module-federation/start-remote-proxies.js.map +0 -1
  110. package/src/utils/module-federation/start-ssr-remote-proxies.js.map +0 -1
  111. package/src/utils/module-federation/typescript.js.map +0 -1
  112. package/src/utils/module-federation/with-module-federation/package-json.js.map +0 -1
  113. package/src/utils/module-federation/with-module-federation/utils.js.map +0 -1
  114. package/src/utils/module-federation/with-module-federation/with-module-federation-ssr.js.map +0 -1
  115. package/src/utils/module-federation/with-module-federation/with-module-federation.js.map +0 -1
  116. package/src/utils/normalize-assets.js.map +0 -1
  117. package/src/utils/read-rspack-options.js.map +0 -1
  118. package/src/utils/resolve-user-defined-rspack-config.js.map +0 -1
  119. package/src/utils/versions.js.map +0 -1
  120. package/src/utils/with-nx.js.map +0 -1
  121. package/src/utils/with-react.js.map +0 -1
  122. package/src/utils/with-web.js.map +0 -1
@@ -6,76 +6,74 @@ const devkit_1 = require("@nx/devkit");
6
6
  const generator_utils_1 = require("../../utils/generator-utils");
7
7
  const create_ts_config_1 = require("../application/lib/create-ts-config");
8
8
  const init_1 = tslib_1.__importDefault(require("../init/init"));
9
- function configurationGenerator(tree, options) {
10
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
11
- var _a, _b, _c, _d, _e, _f;
12
- const task = yield (0, init_1.default)(tree, Object.assign(Object.assign({}, options), {
13
- // TODO: Crystalize the default rspack.config.js file.
14
- // The default setup isn't crystalized so don't add plugin.
15
- addPlugin: false }));
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.
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
40
  Please try a different project, or remove the existing targets
41
41
  and re-run this generator to reset the existing Rspack Configuration.
42
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
- yield (0, generator_utils_1.handleUnknownExecutors)(options.project);
51
- }
52
- yield (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 = (_a = validFoundTargetName.build) !== null && _a !== void 0 ? _a : buildTargetName;
57
- serveTargetName = (_b = validFoundTargetName.serve) !== null && _b !== void 0 ? _b : serveTargetName;
58
- // Not needed atm
59
- // if (projectType === 'application' && options.target !== 'node') {
60
- // moveAndEditIndexHtml(tree, options, buildTargetName);
61
- // }
62
- foundStylePreprocessorOptions =
63
- (_d = (_c = targets === null || targets === void 0 ? void 0 : targets[buildTargetName]) === null || _c === void 0 ? void 0 : _c.options) === null || _d === void 0 ? void 0 : _d.stylePreprocessorOptions;
64
- (0, generator_utils_1.deleteWebpackConfig)(tree, root, (_f = (_e = targets === null || targets === void 0 ? void 0 : targets[buildTargetName]) === null || _e === void 0 ? void 0 : _e.options) === null || _f === void 0 ? void 0 : _f.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
43
  }
67
- if (!projectAlreadyHasRspackTargets.build) {
68
- (0, generator_utils_1.addOrChangeBuildTarget)(tree, options, buildTargetName);
44
+ if (!validFoundTargetName.build && projectContainsUnsupportedExecutor) {
45
+ throw new Error(`The project ${options.project} cannot be converted to use the @nx/rspack executors.`);
69
46
  }
70
- if ((options.framework !== 'none' || options.devServer) &&
71
- options.framework !== 'nest' &&
72
- !projectAlreadyHasRspackTargets.serve) {
73
- (0, generator_utils_1.addOrChangeServeTarget)(tree, options, serveTargetName);
47
+ if (!projectContainsUnsupportedExecutor &&
48
+ !validFoundTargetName.build &&
49
+ !validFoundTargetName.serve) {
50
+ await (0, generator_utils_1.handleUnknownExecutors)(options.project);
74
51
  }
75
- (0, generator_utils_1.writeRspackConfigFile)(tree, options, foundStylePreprocessorOptions);
76
- yield (0, devkit_1.formatFiles)(tree);
77
- return task;
78
- });
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;
79
78
  }
80
79
  exports.default = configurationGenerator;
81
- //# sourceMappingURL=configuration.js.map
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "$schema": "http://json-schema.org/schema",
3
3
  "$id": "Rspack",
4
- "title": "",
4
+ "title": "Nx Rspack Configuration Generator",
5
+ "description": "Rspack configuration generator.",
5
6
  "type": "object",
6
7
  "properties": {
7
8
  "project": {
@@ -2,71 +2,70 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.rspackInitSchematic = void 0;
4
4
  exports.rspackInitGenerator = rspackInitGenerator;
5
- const tslib_1 = require("tslib");
6
5
  const devkit_1 = require("@nx/devkit");
7
6
  const add_plugin_1 = require("@nx/devkit/src/utils/add-plugin");
8
7
  const js_1 = require("@nx/js");
9
8
  const plugin_1 = require("../../../plugin");
10
9
  const versions_1 = require("../../utils/versions");
11
- function rspackInitGenerator(tree, schema) {
12
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
13
- var _a;
14
- const tasks = [];
15
- const nxJson = (0, devkit_1.readNxJson)(tree);
16
- const addPluginDefault = process.env.NX_ADD_PLUGINS !== 'false' &&
17
- nxJson.useInferencePlugins !== false;
18
- (_a = schema.addPlugin) !== null && _a !== void 0 ? _a : (schema.addPlugin = addPluginDefault);
19
- if (schema.addPlugin) {
20
- yield (0, add_plugin_1.addPlugin)(tree, yield (0, devkit_1.createProjectGraphAsync)(), '@nx/rspack/plugin', plugin_1.createNodesV2, {
21
- buildTargetName: [
22
- 'build',
23
- 'rspack:build',
24
- 'build:rspack',
25
- 'rspack-build',
26
- 'build-rspack',
27
- ],
28
- serveTargetName: [
29
- 'serve',
30
- 'rspack:serve',
31
- 'serve:rspack',
32
- 'rspack-serve',
33
- 'serve-rspack',
34
- ],
35
- previewTargetName: [
36
- 'preview',
37
- 'rspack:preview',
38
- 'preview:rspack',
39
- 'rspack-preview',
40
- 'preview-rspack',
41
- ],
42
- }, schema.updatePackageScripts);
43
- }
44
- const jsInitTask = yield (0, js_1.initGenerator)(tree, Object.assign(Object.assign({}, schema), { tsConfigName: schema.rootProject ? 'tsconfig.json' : 'tsconfig.base.json', skipFormat: true }));
45
- tasks.push(jsInitTask);
46
- const devDependencies = {
47
- '@rspack/core': versions_1.rspackCoreVersion,
48
- '@rspack/cli': versions_1.rspackCoreVersion,
49
- '@rspack/plugin-minify': versions_1.rspackPluginMinifyVersion,
50
- '@rspack/plugin-react-refresh': versions_1.rspackPluginReactRefreshVersion,
51
- 'react-refresh': versions_1.reactRefreshVersion,
52
- };
53
- // eslint-disable-next-line @typescript-eslint/no-var-requires
54
- const version = require('../../../package.json').version;
55
- if (version !== '0.0.1') {
56
- // Ignored for local dev / e2e tests.
57
- devDependencies['@nx/rspack'] = version;
58
- }
59
- if (schema.style === 'less') {
60
- devDependencies['less-loader'] = versions_1.lessLoaderVersion;
61
- }
62
- if (schema.framework !== 'none' || schema.devServer) {
63
- devDependencies['@rspack/dev-server'] = versions_1.rspackDevServerVersion;
64
- }
65
- const installTask = (0, devkit_1.addDependenciesToPackageJson)(tree, {}, devDependencies, undefined, schema.keepExistingVersions);
66
- tasks.push(installTask);
67
- return (0, devkit_1.runTasksInSerial)(...tasks);
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,
68
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
69
  }
70
70
  exports.default = rspackInitGenerator;
71
71
  exports.rspackInitSchematic = (0, devkit_1.convertNxGenerator)(rspackInitGenerator);
72
- //# sourceMappingURL=init.js.map
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "$schema": "http://json-schema.org/schema",
3
3
  "$id": "Init",
4
- "title": "",
4
+ "title": "Nx Rspack Init Generator",
5
5
  "type": "object",
6
+ "description": "Rspack init generator.",
6
7
  "properties": {
7
8
  "framework": {
8
9
  "type": "string",
@@ -4,34 +4,31 @@ exports.default = default_1;
4
4
  const tslib_1 = require("tslib");
5
5
  const devkit_1 = require("@nx/devkit");
6
6
  const application_1 = tslib_1.__importDefault(require("../application/application"));
7
- function default_1(tree, options) {
8
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
9
- const appTask = (0, application_1.default)(tree, Object.assign(Object.assign({}, options), {
10
- // Since `--style` is not passed down to custom preset, we're using individual flags for now.
11
- style: options.sass
12
- ? 'scss'
13
- : options.less
14
- ? 'less'
15
- : options.stylus
16
- ? 'styl'
17
- : 'css' }));
18
- (0, devkit_1.updateJson)(tree, 'package.json', (json) => {
19
- var _a, _b, _c, _d, _e, _f;
20
- var _g, _h, _j, _k, _l;
21
- (_a = json.scripts) !== null && _a !== void 0 ? _a : (json.scripts = {});
22
- (_b = (_g = json.scripts).build) !== null && _b !== void 0 ? _b : (_g.build = 'npx nx build');
23
- (_c = (_h = json.scripts).start) !== null && _c !== void 0 ? _c : (_h.start = 'npx nx serve');
24
- (_d = (_j = json.scripts).lint) !== null && _d !== void 0 ? _d : (_j.lint = 'npx nx lint');
25
- (_e = (_k = json.scripts).test) !== null && _e !== void 0 ? _e : (_k.test = 'npx nx test');
26
- (_f = (_l = json.scripts).e2e) !== null && _f !== void 0 ? _f : (_l.e2e = 'npx nx e2e e2e');
27
- return json;
28
- });
29
- if (options.rootProject) {
30
- // Remove these folders so projects will be generated at the root.
31
- tree.delete('apps');
32
- tree.delete('libs');
33
- }
34
- return appTask;
7
+ async function default_1(tree, options) {
8
+ const appTask = (0, application_1.default)(tree, {
9
+ ...options,
10
+ // Since `--style` is not passed down to custom preset, we're using individual flags for now.
11
+ style: options.sass
12
+ ? 'scss'
13
+ : options.less
14
+ ? 'less'
15
+ : options.stylus
16
+ ? 'styl'
17
+ : 'css',
35
18
  });
19
+ (0, devkit_1.updateJson)(tree, 'package.json', (json) => {
20
+ json.scripts ??= {};
21
+ json.scripts.build ??= 'npx nx build';
22
+ json.scripts.start ??= 'npx nx serve';
23
+ json.scripts.lint ??= 'npx nx lint';
24
+ json.scripts.test ??= 'npx nx test';
25
+ json.scripts.e2e ??= 'npx nx e2e e2e';
26
+ return json;
27
+ });
28
+ if (options.rootProject) {
29
+ // Remove these folders so projects will be generated at the root.
30
+ tree.delete('apps');
31
+ tree.delete('libs');
32
+ }
33
+ return appTask;
36
34
  }
37
- //# sourceMappingURL=preset.js.map
@@ -2,6 +2,7 @@
2
2
  "$schema": "http://json-schema.org/schema",
3
3
  "$id": "Preset",
4
4
  "title": "Standalone React and rspack preset",
5
+ "description": "React + Rspack preset generator.",
5
6
  "type": "object",
6
7
  "properties": {
7
8
  "name": {
package/src/index.js CHANGED
@@ -7,4 +7,3 @@ tslib_1.__exportStar(require("./utils/config"), exports);
7
7
  tslib_1.__exportStar(require("./utils/with-nx"), exports);
8
8
  tslib_1.__exportStar(require("./utils/with-react"), exports);
9
9
  tslib_1.__exportStar(require("./utils/with-web"), exports);
10
- //# sourceMappingURL=index.js.map
@@ -1,13 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = replacePackage;
4
- const tslib_1 = require("tslib");
5
4
  const devkit_1 = require("@nx/devkit");
6
5
  const replace_package_1 = require("@nx/devkit/src/utils/replace-package");
7
- function replacePackage(tree) {
8
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
9
- yield (0, replace_package_1.replaceNrwlPackageWithNxPackage)(tree, '@nrwl/rspack', '@nx/rspack');
10
- yield (0, devkit_1.formatFiles)(tree);
11
- });
6
+ async function replacePackage(tree) {
7
+ await (0, replace_package_1.replaceNrwlPackageWithNxPackage)(tree, '@nrwl/rspack', '@nx/rspack');
8
+ await (0, devkit_1.formatFiles)(tree);
12
9
  }
13
- //# sourceMappingURL=update-16-0-0-add-nx-packages.js.map
@@ -17,7 +17,6 @@ class GeneratePackageJsonPlugin {
17
17
  name: pluginName,
18
18
  stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL,
19
19
  }, () => {
20
- var _a;
21
20
  const helperDependencies = (0, js_1.getHelperDependenciesFromProjectGraph)(this.context.root, this.context.projectName, this.projectGraph);
22
21
  const importHelpers = !!(0, js_1.readTsConfig)(this.options.tsConfig).options
23
22
  .importHelpers;
@@ -36,7 +35,7 @@ class GeneratePackageJsonPlugin {
36
35
  isProduction: true,
37
36
  helperDependencies: helperDependencies.map((dep) => dep.target),
38
37
  });
39
- packageJson.main = (_a = packageJson.main) !== null && _a !== void 0 ? _a : this.options.outputFileName;
38
+ packageJson.main = packageJson.main ?? this.options.outputFileName;
40
39
  compilation.emitAsset('package.json', new webpack_sources_1.RawSource((0, devkit_1.serializeJson)(packageJson)));
41
40
  const packageManager = (0, devkit_1.detectPackageManager)(this.context.root);
42
41
  compilation.emitAsset((0, js_1.getLockFileName)(packageManager), new webpack_sources_1.RawSource((0, js_1.createLockFile)(packageJson, this.projectGraph, packageManager)));
@@ -45,4 +44,3 @@ class GeneratePackageJsonPlugin {
45
44
  }
46
45
  }
47
46
  exports.GeneratePackageJsonPlugin = GeneratePackageJsonPlugin;
48
- //# sourceMappingURL=generate-package-json-plugin.js.map
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createNodesV2 = exports.createDependencies = void 0;
4
- const tslib_1 = require("tslib");
5
4
  const devkit_1 = require("@nx/devkit");
6
5
  const calculate_hash_for_create_nodes_1 = require("@nx/devkit/src/utils/calculate-hash-for-create-nodes");
7
6
  const get_named_inputs_1 = require("@nx/devkit/src/utils/get-named-inputs");
@@ -25,106 +24,99 @@ exports.createDependencies = createDependencies;
25
24
  const rspackConfigGlob = '**/rspack.config.{js,ts,mjs,mts,cjs,cts}';
26
25
  exports.createNodesV2 = [
27
26
  rspackConfigGlob,
28
- (configFilePaths, options, context) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
27
+ async (configFilePaths, options, context) => {
29
28
  const optionsHash = (0, file_hasher_1.hashObject)(options);
30
- const cachePath = (0, path_1.join)(cache_directory_1.workspaceDataDirectory, `vite-${optionsHash}.hash`);
29
+ const cachePath = (0, path_1.join)(cache_directory_1.workspaceDataDirectory, `rspack-${optionsHash}.hash`);
31
30
  const targetsCache = readTargetsCache(cachePath);
32
31
  try {
33
- return yield (0, devkit_1.createNodesFromFiles)((configFile, options, context) => createNodesInternal(configFile, options, context, targetsCache), configFilePaths, options, context);
32
+ return await (0, devkit_1.createNodesFromFiles)((configFile, options, context) => createNodesInternal(configFile, options, context, targetsCache), configFilePaths, options, context);
34
33
  }
35
34
  finally {
36
35
  writeTargetsToCache(cachePath, targetsCache);
37
36
  }
38
- }),
37
+ },
39
38
  ];
40
- function createNodesInternal(configFilePath, options, context, targetsCache) {
41
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
42
- var _a;
43
- const projectRoot = (0, path_1.dirname)(configFilePath);
44
- // Do not create a project if package.json and project.json isn't there.
45
- const siblingFiles = (0, fs_1.readdirSync)((0, path_1.join)(context.workspaceRoot, projectRoot));
46
- if (!siblingFiles.includes('package.json') &&
47
- !siblingFiles.includes('project.json')) {
48
- return {};
49
- }
50
- const normalizedOptions = normalizeOptions(options);
51
- // We do not want to alter how the hash is calculated, so appending the config file path to the hash
52
- // to prevent vite/vitest files overwriting the target cache created by the other
53
- const hash = (yield (0, calculate_hash_for_create_nodes_1.calculateHashForCreateNodes)(projectRoot, normalizedOptions, context, [(0, js_1.getLockFileName)((0, devkit_1.detectPackageManager)(context.workspaceRoot))])) + configFilePath;
54
- (_a = targetsCache[hash]) !== null && _a !== void 0 ? _a : (targetsCache[hash] = yield createRspackTargets(configFilePath, projectRoot, normalizedOptions, context));
55
- const { targets, metadata } = targetsCache[hash];
56
- return {
57
- projects: {
58
- [projectRoot]: {
59
- root: projectRoot,
60
- targets,
61
- metadata,
62
- },
39
+ async function createNodesInternal(configFilePath, options, context, targetsCache) {
40
+ const projectRoot = (0, path_1.dirname)(configFilePath);
41
+ // Do not create a project if package.json and project.json isn't there.
42
+ const siblingFiles = (0, fs_1.readdirSync)((0, path_1.join)(context.workspaceRoot, projectRoot));
43
+ if (!siblingFiles.includes('package.json') &&
44
+ !siblingFiles.includes('project.json')) {
45
+ return {};
46
+ }
47
+ const normalizedOptions = normalizeOptions(options);
48
+ // We do not want to alter how the hash is calculated, so appending the config file path to the hash
49
+ // to prevent vite/vitest files overwriting the target cache created by the other
50
+ const hash = (await (0, calculate_hash_for_create_nodes_1.calculateHashForCreateNodes)(projectRoot, normalizedOptions, context, [(0, js_1.getLockFileName)((0, devkit_1.detectPackageManager)(context.workspaceRoot))])) + configFilePath;
51
+ targetsCache[hash] ??= await createRspackTargets(configFilePath, projectRoot, normalizedOptions, context);
52
+ const { targets, metadata } = targetsCache[hash];
53
+ return {
54
+ projects: {
55
+ [projectRoot]: {
56
+ root: projectRoot,
57
+ targets,
58
+ metadata,
63
59
  },
64
- };
65
- });
60
+ },
61
+ };
66
62
  }
67
- function createRspackTargets(configFilePath, projectRoot, options, context) {
68
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
69
- var _a;
70
- const namedInputs = (0, get_named_inputs_1.getNamedInputs)(projectRoot, context);
71
- const rspackConfig = (0, resolve_user_defined_rspack_config_1.resolveUserDefinedRspackConfig)((0, path_1.join)(context.workspaceRoot, configFilePath), (0, js_1.getRootTsConfigPath)(), true);
72
- const rspackOptions = yield (0, read_rspack_options_1.readRspackOptions)(rspackConfig);
73
- const outputPath = normalizeOutputPath((_a = rspackOptions.output) === null || _a === void 0 ? void 0 : _a.path, projectRoot);
74
- const targets = {};
75
- targets[options.buildTargetName] = {
76
- command: `rspack build`,
77
- options: { cwd: projectRoot, args: ['--node-env=production'] },
78
- cache: true,
79
- dependsOn: [`^${options.buildTargetName}`],
80
- inputs: 'production' in namedInputs
81
- ? [
82
- 'production',
83
- '^production',
84
- {
85
- externalDependencies: ['@rspack/cli'],
86
- },
87
- ]
88
- : [
89
- 'default',
90
- '^default',
91
- {
92
- externalDependencies: ['@rspack/cli'],
93
- },
94
- ],
95
- outputs: [outputPath],
96
- };
97
- targets[options.serveTargetName] = {
98
- command: `rspack serve`,
99
- options: {
100
- cwd: projectRoot,
101
- args: ['--node-env=development'],
102
- },
103
- };
104
- targets[options.previewTargetName] = {
105
- command: `rspack serve`,
106
- options: {
107
- cwd: projectRoot,
108
- args: ['--node-env=production'],
109
- },
110
- };
111
- targets[options.serveStaticTargetName] = {
112
- executor: '@nx/web:file-server',
113
- options: {
114
- buildTarget: options.buildTargetName,
115
- spa: true,
116
- },
117
- };
118
- return { targets, metadata: {} };
119
- });
63
+ async function createRspackTargets(configFilePath, projectRoot, options, context) {
64
+ const namedInputs = (0, get_named_inputs_1.getNamedInputs)(projectRoot, context);
65
+ const rspackConfig = (0, resolve_user_defined_rspack_config_1.resolveUserDefinedRspackConfig)((0, path_1.join)(context.workspaceRoot, configFilePath), (0, js_1.getRootTsConfigPath)(), true);
66
+ const rspackOptions = await (0, read_rspack_options_1.readRspackOptions)(rspackConfig);
67
+ const outputPath = normalizeOutputPath(rspackOptions.output?.path, projectRoot);
68
+ const targets = {};
69
+ targets[options.buildTargetName] = {
70
+ command: `rspack build`,
71
+ options: { cwd: projectRoot, args: ['--node-env=production'] },
72
+ cache: true,
73
+ dependsOn: [`^${options.buildTargetName}`],
74
+ inputs: 'production' in namedInputs
75
+ ? [
76
+ 'production',
77
+ '^production',
78
+ {
79
+ externalDependencies: ['@rspack/cli'],
80
+ },
81
+ ]
82
+ : [
83
+ 'default',
84
+ '^default',
85
+ {
86
+ externalDependencies: ['@rspack/cli'],
87
+ },
88
+ ],
89
+ outputs: [outputPath],
90
+ };
91
+ targets[options.serveTargetName] = {
92
+ command: `rspack serve`,
93
+ options: {
94
+ cwd: projectRoot,
95
+ args: ['--node-env=development'],
96
+ },
97
+ };
98
+ targets[options.previewTargetName] = {
99
+ command: `rspack serve`,
100
+ options: {
101
+ cwd: projectRoot,
102
+ args: ['--node-env=production'],
103
+ },
104
+ };
105
+ targets[options.serveStaticTargetName] = {
106
+ executor: '@nx/web:file-server',
107
+ options: {
108
+ buildTarget: options.buildTargetName,
109
+ spa: true,
110
+ },
111
+ };
112
+ return { targets, metadata: {} };
120
113
  }
121
114
  function normalizeOptions(options) {
122
- var _a, _b, _c, _d;
123
- options !== null && options !== void 0 ? options : (options = {});
124
- (_a = options.buildTargetName) !== null && _a !== void 0 ? _a : (options.buildTargetName = 'build');
125
- (_b = options.serveTargetName) !== null && _b !== void 0 ? _b : (options.serveTargetName = 'serve');
126
- (_c = options.previewTargetName) !== null && _c !== void 0 ? _c : (options.previewTargetName = 'preview');
127
- (_d = options.serveStaticTargetName) !== null && _d !== void 0 ? _d : (options.serveStaticTargetName = 'serve-static');
115
+ options ??= {};
116
+ options.buildTargetName ??= 'build';
117
+ options.serveTargetName ??= 'serve';
118
+ options.previewTargetName ??= 'preview';
119
+ options.serveStaticTargetName ??= 'serve-static';
128
120
  return options;
129
121
  }
130
122
  function normalizeOutputPath(outputPath, projectRoot) {
@@ -155,4 +147,3 @@ function normalizeOutputPath(outputPath, projectRoot) {
155
147
  }
156
148
  }
157
149
  }
158
- //# sourceMappingURL=plugin.js.map