@nx/react 0.0.0-pr-29176-d3c6c29 → 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.
- package/generators.json +4 -2
- package/package.json +6 -6
- package/plugins/bundle-rollup.js +2 -2
- package/plugins/nx-react-webpack-plugin/lib/apply-react-config.js +3 -1
- package/src/executors/module-federation-dev-server/schema.json +14 -10
- package/src/executors/module-federation-ssr-dev-server/schema.json +13 -9
- package/src/executors/module-federation-static-server/module-federation-static-server.impl.js +5 -5
- package/src/executors/module-federation-static-server/schema.json +1 -1
- package/src/generators/application/application.d.ts +3 -3
- package/src/generators/application/application.js +59 -194
- package/src/generators/application/files/base-rsbuild/src/app/__fileName__.spec.tsx__tmpl__ +10 -0
- package/src/generators/application/files/base-rsbuild/src/assets/.gitkeep +0 -0
- package/src/generators/application/files/base-rsbuild/src/favicon.ico +0 -0
- package/src/generators/application/files/base-rsbuild/src/index.html +14 -0
- package/src/generators/application/files/base-rsbuild/src/main.tsx__tmpl__ +32 -0
- package/src/generators/application/files/base-rsbuild/tsconfig.app.json__tmpl__ +31 -0
- package/src/generators/application/files/style-tailwind/src/app/__fileName__.tsx__tmpl__ +1 -1
- package/src/generators/application/lib/add-e2e.js +12 -1
- package/src/generators/application/lib/add-linting.d.ts +3 -0
- package/src/generators/application/lib/add-linting.js +48 -0
- package/src/generators/application/lib/bundlers/add-rsbuild.d.ts +4 -0
- package/src/generators/application/lib/bundlers/add-rsbuild.js +63 -0
- package/src/generators/application/lib/bundlers/add-rspack.d.ts +5 -0
- package/src/generators/application/lib/bundlers/add-rspack.js +55 -0
- package/src/generators/application/lib/bundlers/add-vite.d.ts +4 -0
- package/src/generators/application/lib/bundlers/add-vite.js +67 -0
- package/src/generators/application/lib/bundlers/add-webpack.d.ts +3 -0
- package/src/generators/application/lib/bundlers/add-webpack.js +18 -0
- package/src/generators/application/lib/create-application-files.js +5 -0
- package/src/generators/application/schema.d.ts +1 -1
- package/src/generators/application/schema.json +4 -4
- package/src/generators/component/component.js +19 -32
- package/src/generators/component/files/{__fileName__.tsx__tmpl__ → __fileName__.__ext__} +5 -5
- package/src/generators/component/lib/normalize-options.js +7 -4
- package/src/generators/component/schema.d.ts +9 -3
- package/src/generators/component/schema.json +6 -6
- package/src/generators/component-story/component-story.js +1 -2
- package/src/generators/federate-module/schema.json +14 -8
- package/src/generators/hook/files/{__fileName__.ts__tmpl__ → __fileName__.__ext__} +3 -1
- package/src/generators/hook/hook.js +21 -22
- package/src/generators/hook/schema.d.ts +4 -0
- package/src/generators/hook/schema.json +8 -4
- package/src/generators/host/schema.json +9 -8
- package/src/generators/library/lib/add-rollup-build-target.js +30 -27
- package/src/generators/library/library.js +6 -1
- package/src/generators/library/schema.json +4 -0
- package/src/generators/redux/files/js/__fileName__.__ext__ +114 -0
- package/src/generators/redux/files/{__fileName__.slice.spec.ts__tmpl__ → js/__fileName__.spec.__ext__} +1 -1
- package/src/generators/redux/files/ts/__fileName__.spec.__ext__ +56 -0
- package/src/generators/redux/redux.js +19 -16
- package/src/generators/redux/schema.d.ts +10 -2
- package/src/generators/redux/schema.json +8 -4
- package/src/generators/remote/lib/update-host-with-remote.js +2 -2
- package/src/generators/remote/schema.json +9 -8
- package/src/generators/stories/stories.js +5 -2
- package/src/generators/storybook-configuration/configuration.js +2 -2
- package/src/utils/has-rsbuild-plugin.d.ts +2 -0
- package/src/utils/has-rsbuild-plugin.js +10 -0
- /package/src/generators/component/files/{__fileName__.spec.tsx__tmpl__ → __fileName__.spec.__ext__} +0 -0
- /package/src/generators/hook/files/{__fileName__.spec.tsx__tmpl__ → __fileName__.spec.__specExt__} +0 -0
- /package/src/generators/redux/files/{__fileName__.slice.ts__tmpl__ → ts/__fileName__.__ext__} +0 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
<%_ if (isUsingTsSolutionSetup) { _%>{
|
|
2
|
+
"extends": "<%= offsetFromRoot%>tsconfig.base.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"outDir": "dist",
|
|
5
|
+
"tsBuildInfoFile": "dist/tsconfig.lib.tsbuildinfo",
|
|
6
|
+
"jsx": "react-jsx",
|
|
7
|
+
"lib": ["dom"],
|
|
8
|
+
"types": [
|
|
9
|
+
"node",
|
|
10
|
+
<%_ if (style === 'styled-jsx') { _%>"@nx/react/typings/styled-jsx.d.ts",<%_ } _%>
|
|
11
|
+
"@nx/react/typings/cssmodule.d.ts",
|
|
12
|
+
"@nx/react/typings/image.d.ts"
|
|
13
|
+
]
|
|
14
|
+
},
|
|
15
|
+
"exclude": ["src/**/*.spec.ts", "src/**/*.test.ts", "src/**/*.spec.tsx", "src/**/*.test.tsx", "src/**/*.spec.js", "src/**/*.test.js", "src/**/*.spec.jsx", "src/**/*.test.jsx"],
|
|
16
|
+
"include": ["src/**/*.js", "src/**/*.jsx", "src/**/*.ts", "src/**/*.tsx"]
|
|
17
|
+
}<% } else { %>{
|
|
18
|
+
"extends": "./tsconfig.json",
|
|
19
|
+
"compilerOptions": {
|
|
20
|
+
"outDir": "<%= offsetFromRoot %>dist/out-tsc",
|
|
21
|
+
"types": [
|
|
22
|
+
"node",
|
|
23
|
+
<%_ if (style === 'styled-jsx') { _%>"@nx/react/typings/styled-jsx.d.ts",<%_ } _%>
|
|
24
|
+
"@nx/react/typings/cssmodule.d.ts",
|
|
25
|
+
"@nx/react/typings/image.d.ts"
|
|
26
|
+
]
|
|
27
|
+
},
|
|
28
|
+
"exclude": ["src/**/*.spec.ts", "src/**/*.test.ts", "src/**/*.spec.tsx", "src/**/*.test.tsx", "src/**/*.spec.js", "src/**/*.test.js", "src/**/*.spec.jsx", "src/**/*.test.jsx"],
|
|
29
|
+
"include": ["src/**/*.js", "src/**/*.jsx", "src/**/*.ts", "src/**/*.tsx"]
|
|
30
|
+
}
|
|
31
|
+
<% } %>
|
|
@@ -7,11 +7,13 @@ const versions_1 = require("../../../utils/versions");
|
|
|
7
7
|
const has_webpack_plugin_1 = require("../../../utils/has-webpack-plugin");
|
|
8
8
|
const has_vite_plugin_1 = require("../../../utils/has-vite-plugin");
|
|
9
9
|
const has_rspack_plugin_1 = require("../../../utils/has-rspack-plugin");
|
|
10
|
+
const has_rsbuild_plugin_1 = require("../../../utils/has-rsbuild-plugin");
|
|
10
11
|
const find_plugin_for_config_file_1 = require("@nx/devkit/src/utils/find-plugin-for-config-file");
|
|
11
12
|
const target_defaults_utils_1 = require("@nx/devkit/src/generators/target-defaults-utils");
|
|
12
13
|
async function addE2e(tree, options) {
|
|
13
14
|
const hasNxBuildPlugin = (options.bundler === 'webpack' && (0, has_webpack_plugin_1.hasWebpackPlugin)(tree)) ||
|
|
14
15
|
(options.bundler === 'rspack' && (0, has_rspack_plugin_1.hasRspackPlugin)(tree)) ||
|
|
16
|
+
(options.bundler === 'rsbuild' && (0, has_rsbuild_plugin_1.hasRsbuildPlugin)(tree)) ||
|
|
15
17
|
(options.bundler === 'vite' && (0, has_vite_plugin_1.hasVitePlugin)(tree));
|
|
16
18
|
let e2eWebServerInfo = {
|
|
17
19
|
e2eWebServerAddress: `http://localhost:${options.devServerPort ?? 4200}`,
|
|
@@ -28,6 +30,11 @@ async function addE2e(tree, options) {
|
|
|
28
30
|
const { getViteE2EWebServerInfo } = (0, devkit_1.ensurePackage)('@nx/vite', versions_1.nxVersion);
|
|
29
31
|
e2eWebServerInfo = await getViteE2EWebServerInfo(tree, options.projectName, (0, devkit_1.joinPathFragments)(options.appProjectRoot, `vite.config.${options.js ? 'js' : 'ts'}`), options.addPlugin, options.devServerPort ?? 4200);
|
|
30
32
|
}
|
|
33
|
+
else if (options.bundler === 'rsbuild') {
|
|
34
|
+
(0, devkit_1.ensurePackage)('@nx/rsbuild', versions_1.nxVersion);
|
|
35
|
+
const { getRsbuildE2EWebServerInfo } = await Promise.resolve().then(() => require('@nx/rsbuild/config-utils'));
|
|
36
|
+
e2eWebServerInfo = await getRsbuildE2EWebServerInfo(tree, options.projectName, (0, devkit_1.joinPathFragments)(options.appProjectRoot, `rsbuild.config.${options.js ? 'js' : 'ts'}`), options.addPlugin, options.devServerPort ?? 4200);
|
|
37
|
+
}
|
|
31
38
|
if (!hasNxBuildPlugin) {
|
|
32
39
|
await (0, web_1.webStaticServeGenerator)(tree, {
|
|
33
40
|
buildTarget: `${options.projectName}:build`,
|
|
@@ -65,7 +72,11 @@ async function addE2e(tree, options) {
|
|
|
65
72
|
project: options.e2eProjectName,
|
|
66
73
|
directory: 'src',
|
|
67
74
|
// the name and root are already normalized, instruct the generator to use them as is
|
|
68
|
-
bundler: options.bundler === 'rspack'
|
|
75
|
+
bundler: options.bundler === 'rspack'
|
|
76
|
+
? 'webpack'
|
|
77
|
+
: options.bundler === 'rsbuild'
|
|
78
|
+
? 'none'
|
|
79
|
+
: options.bundler,
|
|
69
80
|
skipFormat: true,
|
|
70
81
|
devServerTarget: e2eWebServerInfo.e2eDevServerTarget,
|
|
71
82
|
baseUrl: e2eWebServerInfo.e2eWebServerAddress,
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.addLinting = addLinting;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const eslint_1 = require("@nx/eslint");
|
|
6
|
+
const eslint_file_1 = require("@nx/eslint/src/generators/utils/eslint-file");
|
|
7
|
+
const flat_config_1 = require("@nx/eslint/src/utils/flat-config");
|
|
8
|
+
const devkit_2 = require("@nx/devkit");
|
|
9
|
+
const add_swc_dependencies_1 = require("@nx/js/src/utils/swc/add-swc-dependencies");
|
|
10
|
+
const lint_1 = require("../../../utils/lint");
|
|
11
|
+
async function addLinting(host, options) {
|
|
12
|
+
const tasks = [];
|
|
13
|
+
if (options.linter === eslint_1.Linter.EsLint) {
|
|
14
|
+
const lintTask = await (0, eslint_1.lintProjectGenerator)(host, {
|
|
15
|
+
linter: options.linter,
|
|
16
|
+
project: options.projectName,
|
|
17
|
+
tsConfigPaths: [
|
|
18
|
+
(0, devkit_1.joinPathFragments)(options.appProjectRoot, 'tsconfig.app.json'),
|
|
19
|
+
],
|
|
20
|
+
unitTestRunner: options.unitTestRunner,
|
|
21
|
+
skipFormat: true,
|
|
22
|
+
rootProject: options.rootProject,
|
|
23
|
+
skipPackageJson: options.skipPackageJson,
|
|
24
|
+
addPlugin: options.addPlugin,
|
|
25
|
+
});
|
|
26
|
+
tasks.push(lintTask);
|
|
27
|
+
if ((0, eslint_file_1.isEslintConfigSupported)(host)) {
|
|
28
|
+
if ((0, flat_config_1.useFlatConfig)(host)) {
|
|
29
|
+
(0, eslint_file_1.addPredefinedConfigToFlatLintConfig)(host, options.appProjectRoot, 'flat/react');
|
|
30
|
+
// Add an empty rules object to users know how to add/override rules
|
|
31
|
+
(0, eslint_file_1.addOverrideToLintConfig)(host, options.appProjectRoot, {
|
|
32
|
+
files: ['*.ts', '*.tsx', '*.js', '*.jsx'],
|
|
33
|
+
rules: {},
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
const addExtendsTask = (0, eslint_file_1.addExtendsToLintConfig)(host, options.appProjectRoot, { name: 'plugin:@nx/react', needCompatFixup: true });
|
|
38
|
+
tasks.push(addExtendsTask);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if (!options.skipPackageJson) {
|
|
42
|
+
const installTask = (0, devkit_2.addDependenciesToPackageJson)(host, lint_1.extraEslintDependencies.dependencies, lint_1.extraEslintDependencies.devDependencies);
|
|
43
|
+
const addSwcTask = (0, add_swc_dependencies_1.addSwcDependencies)(host);
|
|
44
|
+
tasks.push(installTask, addSwcTask);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return (0, devkit_2.runTasksInSerial)(...tasks);
|
|
48
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type Tree } from '@nx/devkit';
|
|
2
|
+
import { NormalizedSchema, Schema } from '../../schema';
|
|
3
|
+
export declare function initRsbuild(tree: Tree, options: NormalizedSchema<Schema>, tasks: any[]): Promise<void>;
|
|
4
|
+
export declare function setupRsbuildConfiguration(tree: Tree, options: NormalizedSchema<Schema>, tasks: any[]): Promise<void>;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.initRsbuild = initRsbuild;
|
|
4
|
+
exports.setupRsbuildConfiguration = setupRsbuildConfiguration;
|
|
5
|
+
const devkit_1 = require("@nx/devkit");
|
|
6
|
+
const versions_1 = require("../../../../utils/versions");
|
|
7
|
+
const maybe_js_1 = require("../../../../utils/maybe-js");
|
|
8
|
+
async function initRsbuild(tree, options, tasks) {
|
|
9
|
+
(0, devkit_1.ensurePackage)('@nx/rsbuild', versions_1.nxVersion);
|
|
10
|
+
const { initGenerator } = await Promise.resolve().then(() => require('@nx/rsbuild/generators'));
|
|
11
|
+
const initTask = await initGenerator(tree, {
|
|
12
|
+
skipPackageJson: options.skipPackageJson,
|
|
13
|
+
addPlugin: true,
|
|
14
|
+
skipFormat: true,
|
|
15
|
+
});
|
|
16
|
+
tasks.push(initTask);
|
|
17
|
+
}
|
|
18
|
+
async function setupRsbuildConfiguration(tree, options, tasks) {
|
|
19
|
+
(0, devkit_1.ensurePackage)('@nx/rsbuild', versions_1.nxVersion);
|
|
20
|
+
const { configurationGenerator } = await Promise.resolve().then(() => require('@nx/rsbuild/generators'));
|
|
21
|
+
const { addBuildPlugin, addCopyAssets, addHtmlTemplatePath, addExperimentalSwcPlugin, versions, } = await Promise.resolve().then(() => require('@nx/rsbuild/config-utils'));
|
|
22
|
+
const rsbuildTask = await configurationGenerator(tree, {
|
|
23
|
+
project: options.projectName,
|
|
24
|
+
entry: (0, maybe_js_1.maybeJs)({
|
|
25
|
+
js: options.js,
|
|
26
|
+
useJsx: true,
|
|
27
|
+
}, `./src/main.tsx`),
|
|
28
|
+
tsConfig: './tsconfig.app.json',
|
|
29
|
+
target: 'web',
|
|
30
|
+
devServerPort: options.devServerPort ?? 4200,
|
|
31
|
+
});
|
|
32
|
+
tasks.push(rsbuildTask);
|
|
33
|
+
const pathToConfigFile = (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'rsbuild.config.ts');
|
|
34
|
+
const deps = { '@rsbuild/plugin-react': versions.rsbuildPluginReactVersion };
|
|
35
|
+
addBuildPlugin(tree, pathToConfigFile, '@rsbuild/plugin-react', 'pluginReact', options.style === '@emotion/styled'
|
|
36
|
+
? `swcReactOptions: {\n\timportSource: '@emotion/react',\n}`
|
|
37
|
+
: undefined);
|
|
38
|
+
if (options.style === 'scss') {
|
|
39
|
+
addBuildPlugin(tree, pathToConfigFile, '@rsbuild/plugin-sass', 'pluginSass');
|
|
40
|
+
deps['@rsbuild/plugin-sass'] = versions.rsbuildPluginSassVersion;
|
|
41
|
+
}
|
|
42
|
+
else if (options.style === 'less') {
|
|
43
|
+
addBuildPlugin(tree, pathToConfigFile, '@rsbuild/plugin-less', 'pluginLess');
|
|
44
|
+
deps['@rsbuild/plugin-less'] = versions.rsbuildPluginLessVersion;
|
|
45
|
+
}
|
|
46
|
+
else if (options.style === '@emotion/styled') {
|
|
47
|
+
deps['@swc/plugin-emotion'] = versions.rsbuildSwcPluginEmotionVersion;
|
|
48
|
+
addExperimentalSwcPlugin(tree, pathToConfigFile, '@swc/plugin-emotion');
|
|
49
|
+
}
|
|
50
|
+
else if (options.style === 'styled-jsx') {
|
|
51
|
+
deps['@swc/plugin-styled-jsx'] = versions.rsbuildSwcPluginStyledJsxVersion;
|
|
52
|
+
addExperimentalSwcPlugin(tree, pathToConfigFile, '@swc/plugin-styled-jsx');
|
|
53
|
+
}
|
|
54
|
+
else if (options.style === 'styled-components') {
|
|
55
|
+
deps['@rsbuild/plugin-styled-components'] =
|
|
56
|
+
versions.rsbuildPluginStyledComponentsVersion;
|
|
57
|
+
addBuildPlugin(tree, pathToConfigFile, '@rsbuild/plugin-styled-components', 'pluginStyledComponents');
|
|
58
|
+
}
|
|
59
|
+
addHtmlTemplatePath(tree, pathToConfigFile, './src/index.html');
|
|
60
|
+
addCopyAssets(tree, pathToConfigFile, './src/assets');
|
|
61
|
+
addCopyAssets(tree, pathToConfigFile, './src/favicon.ico');
|
|
62
|
+
tasks.push((0, devkit_1.addDependenciesToPackageJson)(tree, {}, deps));
|
|
63
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type Tree } from '@nx/devkit';
|
|
2
|
+
import { NormalizedSchema, Schema } from '../../schema';
|
|
3
|
+
export declare function initRspack(tree: Tree, options: NormalizedSchema<Schema>, tasks: any[]): Promise<void>;
|
|
4
|
+
export declare function setupRspackConfiguration(tree: Tree, options: NormalizedSchema<Schema>, tasks: any[]): Promise<void>;
|
|
5
|
+
export declare function handleStyledJsxForRspack(tasks: any[], tree: Tree, options: NormalizedSchema<Schema>): void;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.initRspack = initRspack;
|
|
4
|
+
exports.setupRspackConfiguration = setupRspackConfiguration;
|
|
5
|
+
exports.handleStyledJsxForRspack = handleStyledJsxForRspack;
|
|
6
|
+
const devkit_1 = require("@nx/devkit");
|
|
7
|
+
const pc = require("picocolors");
|
|
8
|
+
const versions_1 = require("../../../../utils/versions");
|
|
9
|
+
const maybe_js_1 = require("../../../../utils/maybe-js");
|
|
10
|
+
async function initRspack(tree, options, tasks) {
|
|
11
|
+
const { rspackInitGenerator } = (0, devkit_1.ensurePackage)('@nx/rspack', versions_1.nxVersion);
|
|
12
|
+
const rspackInitTask = await rspackInitGenerator(tree, {
|
|
13
|
+
...options,
|
|
14
|
+
addPlugin: false,
|
|
15
|
+
skipFormat: true,
|
|
16
|
+
});
|
|
17
|
+
tasks.push(rspackInitTask);
|
|
18
|
+
}
|
|
19
|
+
async function setupRspackConfiguration(tree, options, tasks) {
|
|
20
|
+
const { configurationGenerator } = (0, devkit_1.ensurePackage)('@nx/rspack', versions_1.nxVersion);
|
|
21
|
+
const rspackTask = await configurationGenerator(tree, {
|
|
22
|
+
project: options.projectName,
|
|
23
|
+
main: (0, devkit_1.joinPathFragments)(options.appProjectRoot, (0, maybe_js_1.maybeJs)({
|
|
24
|
+
js: options.js,
|
|
25
|
+
useJsx: true,
|
|
26
|
+
}, `src/main.tsx`)),
|
|
27
|
+
tsConfig: (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'tsconfig.app.json'),
|
|
28
|
+
target: 'web',
|
|
29
|
+
newProject: true,
|
|
30
|
+
framework: 'react',
|
|
31
|
+
});
|
|
32
|
+
tasks.push(rspackTask);
|
|
33
|
+
}
|
|
34
|
+
function handleStyledJsxForRspack(tasks, tree, options) {
|
|
35
|
+
devkit_1.logger.warn(`${pc.bold('styled-jsx')} is not supported by ${pc.bold('Rspack')}. We've added ${pc.bold('babel-loader')} to your project, but using babel will slow down your build.`);
|
|
36
|
+
tasks.push((0, devkit_1.addDependenciesToPackageJson)(tree, {}, { 'babel-loader': versions_1.babelLoaderVersion }));
|
|
37
|
+
tree.write((0, devkit_1.joinPathFragments)(options.appProjectRoot, 'rspack.config.js'), (0, devkit_1.stripIndents) `
|
|
38
|
+
const { composePlugins, withNx, withReact } = require('@nx/rspack');
|
|
39
|
+
module.exports = composePlugins(withNx(), withReact(), (config) => {
|
|
40
|
+
config.module.rules.push({
|
|
41
|
+
test: /\\.[jt]sx$/i,
|
|
42
|
+
use: [
|
|
43
|
+
{
|
|
44
|
+
loader: 'babel-loader',
|
|
45
|
+
options: {
|
|
46
|
+
presets: ['@babel/preset-typescript'],
|
|
47
|
+
plugins: ['styled-jsx/babel'],
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
],
|
|
51
|
+
});
|
|
52
|
+
return config;
|
|
53
|
+
});
|
|
54
|
+
`);
|
|
55
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type Tree } from '@nx/devkit';
|
|
2
|
+
import { NormalizedSchema, Schema } from '../../schema';
|
|
3
|
+
export declare function setupViteConfiguration(tree: Tree, options: NormalizedSchema<Schema>, tasks: any[]): Promise<void>;
|
|
4
|
+
export declare function setupVitestConfiguration(tree: Tree, options: NormalizedSchema<Schema>, tasks: any[]): Promise<void>;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.setupViteConfiguration = setupViteConfiguration;
|
|
4
|
+
exports.setupVitestConfiguration = setupVitestConfiguration;
|
|
5
|
+
const devkit_1 = require("@nx/devkit");
|
|
6
|
+
const versions_1 = require("../../../../utils/versions");
|
|
7
|
+
async function setupViteConfiguration(tree, options, tasks) {
|
|
8
|
+
const { createOrEditViteConfig, viteConfigurationGenerator } = (0, devkit_1.ensurePackage)('@nx/vite', versions_1.nxVersion);
|
|
9
|
+
// We recommend users use `import.meta.env.MODE` and other variables in their code to differentiate between production and development.
|
|
10
|
+
// See: https://vitejs.dev/guide/env-and-mode.html
|
|
11
|
+
if (tree.exists((0, devkit_1.joinPathFragments)(options.appProjectRoot, 'src/environments'))) {
|
|
12
|
+
tree.delete((0, devkit_1.joinPathFragments)(options.appProjectRoot, 'src/environments'));
|
|
13
|
+
}
|
|
14
|
+
const viteTask = await viteConfigurationGenerator(tree, {
|
|
15
|
+
uiFramework: 'react',
|
|
16
|
+
project: options.projectName,
|
|
17
|
+
newProject: true,
|
|
18
|
+
includeVitest: options.unitTestRunner === 'vitest',
|
|
19
|
+
inSourceTests: options.inSourceTests,
|
|
20
|
+
compiler: options.compiler,
|
|
21
|
+
skipFormat: true,
|
|
22
|
+
addPlugin: options.addPlugin,
|
|
23
|
+
projectType: 'application',
|
|
24
|
+
});
|
|
25
|
+
tasks.push(viteTask);
|
|
26
|
+
createOrEditViteConfig(tree, {
|
|
27
|
+
project: options.projectName,
|
|
28
|
+
includeLib: false,
|
|
29
|
+
includeVitest: options.unitTestRunner === 'vitest',
|
|
30
|
+
inSourceTests: options.inSourceTests,
|
|
31
|
+
rollupOptionsExternal: ["'react'", "'react-dom'", "'react/jsx-runtime'"],
|
|
32
|
+
imports: [
|
|
33
|
+
options.compiler === 'swc'
|
|
34
|
+
? `import react from '@vitejs/plugin-react-swc'`
|
|
35
|
+
: `import react from '@vitejs/plugin-react'`,
|
|
36
|
+
],
|
|
37
|
+
plugins: ['react()'],
|
|
38
|
+
}, false);
|
|
39
|
+
}
|
|
40
|
+
async function setupVitestConfiguration(tree, options, tasks) {
|
|
41
|
+
const { createOrEditViteConfig, vitestGenerator } = (0, devkit_1.ensurePackage)('@nx/vite', versions_1.nxVersion);
|
|
42
|
+
const vitestTask = await vitestGenerator(tree, {
|
|
43
|
+
uiFramework: 'react',
|
|
44
|
+
coverageProvider: 'v8',
|
|
45
|
+
project: options.projectName,
|
|
46
|
+
inSourceTests: options.inSourceTests,
|
|
47
|
+
skipFormat: true,
|
|
48
|
+
addPlugin: options.addPlugin,
|
|
49
|
+
});
|
|
50
|
+
tasks.push(vitestTask);
|
|
51
|
+
createOrEditViteConfig(tree, {
|
|
52
|
+
project: options.projectName,
|
|
53
|
+
includeLib: false,
|
|
54
|
+
includeVitest: true,
|
|
55
|
+
inSourceTests: options.inSourceTests,
|
|
56
|
+
rollupOptionsExternal: ["'react'", "'react-dom'", "'react/jsx-runtime'"],
|
|
57
|
+
imports: [
|
|
58
|
+
options.compiler === 'swc'
|
|
59
|
+
? `import react from '@vitejs/plugin-react-swc'`
|
|
60
|
+
: `import react from '@vitejs/plugin-react'`,
|
|
61
|
+
],
|
|
62
|
+
plugins: ['react()'],
|
|
63
|
+
}, true);
|
|
64
|
+
if (options.bundler === 'rsbuild') {
|
|
65
|
+
tree.rename((0, devkit_1.joinPathFragments)(options.appProjectRoot, 'vite.config.ts'), (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'vitest.config.ts'));
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.initWebpack = initWebpack;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const versions_1 = require("../../../../utils/versions");
|
|
6
|
+
async function initWebpack(tree, options, tasks) {
|
|
7
|
+
const { webpackInitGenerator } = (0, devkit_1.ensurePackage)('@nx/webpack', versions_1.nxVersion);
|
|
8
|
+
const webpackInitTask = await webpackInitGenerator(tree, {
|
|
9
|
+
skipPackageJson: options.skipPackageJson,
|
|
10
|
+
skipFormat: true,
|
|
11
|
+
addPlugin: options.addPlugin,
|
|
12
|
+
});
|
|
13
|
+
tasks.push(webpackInitTask);
|
|
14
|
+
if (!options.skipPackageJson) {
|
|
15
|
+
const { ensureDependencies } = await Promise.resolve().then(() => require('@nx/webpack/src/utils/ensure-dependencies'));
|
|
16
|
+
tasks.push(ensureDependencies(tree, { uiFramework: 'react' }));
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -124,6 +124,11 @@ async function createApplicationFiles(host, options) {
|
|
|
124
124
|
: null,
|
|
125
125
|
});
|
|
126
126
|
}
|
|
127
|
+
else if (options.bundler === 'rsbuild') {
|
|
128
|
+
(0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, '../files/base-rsbuild'), options.appProjectRoot, {
|
|
129
|
+
...templateVariables,
|
|
130
|
+
});
|
|
131
|
+
}
|
|
127
132
|
if (options.unitTestRunner === 'none' ||
|
|
128
133
|
(options.unitTestRunner === 'vitest' && options.inSourceTests == true)) {
|
|
129
134
|
host.delete(`${options.appProjectRoot}/src/app/${options.fileName}.spec.tsx`);
|
|
@@ -23,7 +23,7 @@ export interface Schema {
|
|
|
23
23
|
devServerPort?: number;
|
|
24
24
|
skipPackageJson?: boolean;
|
|
25
25
|
rootProject?: boolean;
|
|
26
|
-
bundler?: 'webpack' | 'vite' | 'rspack';
|
|
26
|
+
bundler?: 'webpack' | 'vite' | 'rspack' | 'rsbuild';
|
|
27
27
|
minimal?: boolean;
|
|
28
28
|
// Internal options
|
|
29
29
|
addPlugin?: boolean;
|
|
@@ -51,15 +51,15 @@
|
|
|
51
51
|
},
|
|
52
52
|
{
|
|
53
53
|
"value": "scss",
|
|
54
|
-
"label": "SASS(.scss) [ https://sass-lang.com
|
|
54
|
+
"label": "SASS(.scss) [ https://sass-lang.com ]"
|
|
55
55
|
},
|
|
56
56
|
{
|
|
57
57
|
"value": "less",
|
|
58
|
-
"label": "LESS [ https://lesscss.org
|
|
58
|
+
"label": "LESS [ https://lesscss.org ]"
|
|
59
59
|
},
|
|
60
60
|
{
|
|
61
61
|
"value": "tailwind",
|
|
62
|
-
"label": "tailwind
|
|
62
|
+
"label": "tailwind [ https://tailwindcss.com/ ]"
|
|
63
63
|
},
|
|
64
64
|
{
|
|
65
65
|
"value": "styled-components",
|
|
@@ -101,7 +101,7 @@
|
|
|
101
101
|
"bundler": {
|
|
102
102
|
"description": "The bundler to use.",
|
|
103
103
|
"type": "string",
|
|
104
|
-
"enum": ["vite", "webpack", "rspack"],
|
|
104
|
+
"enum": ["vite", "webpack", "rspack", "rsbuild"],
|
|
105
105
|
"x-prompt": "Which bundler do you want to use to build the application?",
|
|
106
106
|
"default": "vite",
|
|
107
107
|
"x-priority": "important"
|
|
@@ -32,31 +32,17 @@ function createComponentFiles(host, options) {
|
|
|
32
32
|
...options,
|
|
33
33
|
componentTests,
|
|
34
34
|
inSourceVitestTests: (0, get_in_source_vitest_tests_template_1.getInSourceVitestTestsTemplate)(componentTests),
|
|
35
|
-
|
|
35
|
+
isTs: options.fileExtensionType === 'ts',
|
|
36
|
+
ext: options.fileExtension,
|
|
36
37
|
});
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
-
if ((options.styledModule || !options.hasStyles) &&
|
|
44
|
-
c.path.endsWith(`.${options.style}`)) {
|
|
45
|
-
deleteFile = true;
|
|
46
|
-
}
|
|
47
|
-
if (options.globalCss && c.path.endsWith(`.module.${options.style}`)) {
|
|
48
|
-
deleteFile = true;
|
|
49
|
-
}
|
|
50
|
-
if (!options.globalCss &&
|
|
51
|
-
c.path.endsWith(`${options.fileName}.${options.style}`)) {
|
|
52
|
-
deleteFile = true;
|
|
53
|
-
}
|
|
54
|
-
if (deleteFile) {
|
|
55
|
-
host.delete(c.path);
|
|
56
|
-
}
|
|
38
|
+
if (options.skipTests || options.inSourceTests) {
|
|
39
|
+
host.delete((0, devkit_1.joinPathFragments)(options.directory, `${options.fileName}.spec.${options.fileExtension}`));
|
|
40
|
+
}
|
|
41
|
+
if (options.styledModule || !options.hasStyles || !options.globalCss) {
|
|
42
|
+
host.delete((0, path_1.join)(options.directory, `${options.fileName}.${options.style}`));
|
|
57
43
|
}
|
|
58
|
-
if (options.
|
|
59
|
-
(0,
|
|
44
|
+
if (options.styledModule || !options.hasStyles || options.globalCss) {
|
|
45
|
+
host.delete((0, path_1.join)(options.directory, `${options.fileName}.module.${options.style}`));
|
|
60
46
|
}
|
|
61
47
|
}
|
|
62
48
|
let tsModule;
|
|
@@ -67,16 +53,17 @@ function addExportsToBarrel(host, options) {
|
|
|
67
53
|
const workspace = (0, devkit_1.getProjects)(host);
|
|
68
54
|
const isApp = workspace.get(options.projectName).projectType === 'application';
|
|
69
55
|
if (options.export && !isApp) {
|
|
70
|
-
const indexFilePath = options.projectSourceRoot
|
|
71
|
-
?
|
|
72
|
-
:
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
const indexSourceFile = tsModule.createSourceFile(indexFilePath, indexSource, tsModule.ScriptTarget.Latest, true);
|
|
76
|
-
const relativePathFromIndex = getRelativeImportToFile(indexFilePath, options.filePath);
|
|
77
|
-
const changes = (0, devkit_1.applyChangesToString)(indexSource, (0, ast_utils_1.addImport)(indexSourceFile, `export * from '${relativePathFromIndex}';`));
|
|
78
|
-
host.write(indexFilePath, changes);
|
|
56
|
+
const indexFilePath = (0, devkit_1.joinPathFragments)(...(options.projectSourceRoot
|
|
57
|
+
? [options.projectSourceRoot]
|
|
58
|
+
: [options.projectRoot, 'src']), options.fileExtensionType === 'js' ? 'index.js' : 'index.ts');
|
|
59
|
+
if (!host.exists(indexFilePath)) {
|
|
60
|
+
return;
|
|
79
61
|
}
|
|
62
|
+
const indexSource = host.read(indexFilePath, 'utf-8');
|
|
63
|
+
const indexSourceFile = tsModule.createSourceFile(indexFilePath, indexSource, tsModule.ScriptTarget.Latest, true);
|
|
64
|
+
const relativePathFromIndex = getRelativeImportToFile(indexFilePath, options.filePath);
|
|
65
|
+
const changes = (0, devkit_1.applyChangesToString)(indexSource, (0, ast_utils_1.addImport)(indexSourceFile, `export * from '${relativePathFromIndex}';`));
|
|
66
|
+
host.write(indexFilePath, changes);
|
|
80
67
|
}
|
|
81
68
|
}
|
|
82
69
|
function getRelativeImportToFile(indexPath, filePath) {
|
|
@@ -6,7 +6,7 @@ import { Route, Link } from 'react-router-dom';
|
|
|
6
6
|
<%_ } _%>
|
|
7
7
|
|
|
8
8
|
<%_ if (hasStyles) {
|
|
9
|
-
if (styledModule && styledModule !== 'styled-jsx') {
|
|
9
|
+
if (styledModule && styledModule !== 'styled-jsx' && styledModule !== 'tailwind') {
|
|
10
10
|
var wrapper = 'Styled' + className;
|
|
11
11
|
var extras = '';
|
|
12
12
|
_%>
|
|
@@ -15,22 +15,22 @@ import styled from '<%= styledModule %>';
|
|
|
15
15
|
var wrapper = 'div';
|
|
16
16
|
var extras = globalCss || styledModule === 'styled-jsx' ? '' : " className={styles['container']}";
|
|
17
17
|
_%>
|
|
18
|
-
<%- style !== 'styled-jsx' ? globalCss ? `import './${fileName}.${style}';` : `import styles from './${fileName}.module.${style}';`: '' %>
|
|
18
|
+
<%- style !== 'styled-jsx' && style!== 'tailwind' ? globalCss ? `import './${fileName}.${style}';` : `import styles from './${fileName}.module.${style}';`: '' %>
|
|
19
19
|
<%_ }
|
|
20
20
|
} else {
|
|
21
21
|
var wrapper = 'div';
|
|
22
22
|
var extras = '';
|
|
23
23
|
} _%>
|
|
24
24
|
|
|
25
|
-
<%_ if (styledModule && styledModule !== 'styled-jsx') { _%>
|
|
25
|
+
<%_ if (styledModule && styledModule !== 'styled-jsx' && styledModule !== 'tailwind') { _%>
|
|
26
26
|
const Styled<%= className %> = styled.div`
|
|
27
27
|
color: pink;
|
|
28
28
|
`;
|
|
29
29
|
<%_ } _%>
|
|
30
30
|
<%_ if(!isNextPage) { _%>
|
|
31
31
|
<%_ if (classComponent) { _%>
|
|
32
|
-
export class <%= className %> extends Component
|
|
33
|
-
override render() {
|
|
32
|
+
export class <%= className %> extends Component<% if (isTs) { %><{}><% } %> {
|
|
33
|
+
<% if (isTs) { %>override<% } %> render() {
|
|
34
34
|
return (
|
|
35
35
|
<<%= wrapper %><%- extras %>>
|
|
36
36
|
<%= styledModule === 'styled-jsx' ? `<style jsx>{\`div { color: pink; }\`}</style>` : `` %>
|
|
@@ -6,11 +6,12 @@ const artifact_name_and_directory_utils_1 = require("@nx/devkit/src/generators/a
|
|
|
6
6
|
const assertion_1 = require("../../../utils/assertion");
|
|
7
7
|
async function normalizeOptions(tree, options) {
|
|
8
8
|
(0, assertion_1.assertValidStyle)(options.style);
|
|
9
|
-
const { artifactName: name, directory, fileName, filePath, project: projectName, } = await (0, artifact_name_and_directory_utils_1.determineArtifactNameAndDirectoryOptions)(tree, {
|
|
9
|
+
const { artifactName: name, directory, fileName, filePath, fileExtension, fileExtensionType, project: projectName, } = await (0, artifact_name_and_directory_utils_1.determineArtifactNameAndDirectoryOptions)(tree, {
|
|
10
10
|
path: options.path,
|
|
11
11
|
name: options.name,
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
allowedFileExtensions: ['js', 'jsx', 'ts', 'tsx'],
|
|
13
|
+
fileExtension: options.js ? 'js' : 'tsx',
|
|
14
|
+
js: options.js,
|
|
14
15
|
});
|
|
15
16
|
const project = (0, devkit_1.readProjectConfiguration)(tree, projectName);
|
|
16
17
|
const { className } = (0, devkit_1.names)(name);
|
|
@@ -37,6 +38,8 @@ async function normalizeOptions(tree, options) {
|
|
|
37
38
|
fileName,
|
|
38
39
|
filePath,
|
|
39
40
|
projectRoot,
|
|
40
|
-
projectSourceRoot
|
|
41
|
+
projectSourceRoot,
|
|
42
|
+
fileExtension,
|
|
43
|
+
fileExtensionType,
|
|
41
44
|
};
|
|
42
45
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { FileExtensionType } from '@nx/devkit/src/generators/artifact-name-and-directory-utils';
|
|
1
2
|
import { SupportedStyles } from '../../../typings/style';
|
|
2
3
|
|
|
3
4
|
export interface Schema {
|
|
@@ -8,22 +9,27 @@ export interface Schema {
|
|
|
8
9
|
export?: boolean;
|
|
9
10
|
classComponent?: boolean;
|
|
10
11
|
routing?: boolean;
|
|
11
|
-
js?: boolean;
|
|
12
12
|
globalCss?: boolean;
|
|
13
|
-
fileName?: string;
|
|
14
13
|
inSourceTests?: boolean;
|
|
15
14
|
skipFormat?: boolean;
|
|
16
15
|
// Used by Next.js to determine how React should generate the page
|
|
17
16
|
isNextPage?: boolean;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @deprecated Provide the full file path including the file extension in the `path` option. This option will be removed in Nx v21.
|
|
20
|
+
*/
|
|
21
|
+
js?: boolean;
|
|
18
22
|
}
|
|
19
23
|
|
|
20
|
-
export interface NormalizedSchema extends Schema {
|
|
24
|
+
export interface NormalizedSchema extends Omit<Schema, 'js'> {
|
|
21
25
|
directory: string;
|
|
22
26
|
projectRoot: string;
|
|
23
27
|
projectSourceRoot: string;
|
|
24
28
|
projectName: string;
|
|
25
29
|
fileName: string;
|
|
26
30
|
filePath: string;
|
|
31
|
+
fileExtension: string;
|
|
32
|
+
fileExtensionType: FileExtensionType;
|
|
27
33
|
className: string;
|
|
28
34
|
styledModule: null | string;
|
|
29
35
|
hasStyles: boolean;
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"properties": {
|
|
9
9
|
"path": {
|
|
10
10
|
"type": "string",
|
|
11
|
-
"description": "The file path to the component
|
|
11
|
+
"description": "The file path to the component. Relative to the current working directory.",
|
|
12
12
|
"$default": {
|
|
13
13
|
"$source": "argv",
|
|
14
14
|
"index": 0
|
|
@@ -41,6 +41,10 @@
|
|
|
41
41
|
"value": "less",
|
|
42
42
|
"label": "LESS [ https://lesscss.org ]"
|
|
43
43
|
},
|
|
44
|
+
{
|
|
45
|
+
"value": "tailwind",
|
|
46
|
+
"label": "tailwind [ https://tailwindcss.com/ ]"
|
|
47
|
+
},
|
|
44
48
|
{
|
|
45
49
|
"value": "styled-components",
|
|
46
50
|
"label": "styled-components [ https://styled-components.com ]"
|
|
@@ -63,7 +67,7 @@
|
|
|
63
67
|
"js": {
|
|
64
68
|
"type": "boolean",
|
|
65
69
|
"description": "Generate JavaScript files rather than TypeScript files.",
|
|
66
|
-
"
|
|
70
|
+
"x-deprecated": "Provide the full file path including the file extension in the `path` option. This option will be removed in Nx v21."
|
|
67
71
|
},
|
|
68
72
|
"skipTests": {
|
|
69
73
|
"type": "boolean",
|
|
@@ -93,10 +97,6 @@
|
|
|
93
97
|
"description": "Default is `false`. When `true`, the component is generated with `*.css`/`*.scss` instead of `*.module.css`/`*.module.scss`.",
|
|
94
98
|
"default": false
|
|
95
99
|
},
|
|
96
|
-
"fileName": {
|
|
97
|
-
"type": "string",
|
|
98
|
-
"description": "Create a component with this file name."
|
|
99
|
-
},
|
|
100
100
|
"inSourceTests": {
|
|
101
101
|
"type": "boolean",
|
|
102
102
|
"default": false,
|
|
@@ -13,8 +13,7 @@ function createComponentStoriesFile(host, { project, componentPath, interactionT
|
|
|
13
13
|
tsModule = (0, ensure_typescript_1.ensureTypescript)();
|
|
14
14
|
}
|
|
15
15
|
const proj = (0, devkit_1.getProjects)(host).get(project);
|
|
16
|
-
const
|
|
17
|
-
const componentFilePath = (0, devkit_1.joinPathFragments)(sourceRoot, componentPath);
|
|
16
|
+
const componentFilePath = (0, devkit_1.joinPathFragments)(proj.sourceRoot ?? proj.root, componentPath);
|
|
18
17
|
const componentDirectory = componentFilePath.replace(componentFilePath.slice(componentFilePath.lastIndexOf('/')), '');
|
|
19
18
|
const isPlainJs = componentFilePath.endsWith('.jsx') || componentFilePath.endsWith('.js');
|
|
20
19
|
const componentFileName = componentFilePath
|