@nx/react 0.0.0-pr-28859-d05a640 → 0.0.0-pr-28808-0f14212
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/package.json +5 -5
- package/src/generators/application/application.js +11 -4
- package/src/generators/application/files/base-rspack/tsconfig.app.json__tmpl__ +21 -4
- package/src/generators/application/files/base-vite/tsconfig.app.json__tmpl__ +19 -2
- package/src/generators/application/files/base-webpack/tsconfig.app.json__tmpl__ +20 -3
- package/src/generators/application/files/style-css-module/src/app/__fileName__.tsx__tmpl__ +2 -2
- package/src/generators/application/lib/add-e2e.d.ts +1 -1
- package/src/generators/application/lib/add-jest.js +1 -0
- package/src/generators/application/lib/add-project.js +17 -3
- package/src/generators/application/lib/create-application-files.js +2 -0
- package/src/generators/application/lib/normalize-options.js +2 -0
- package/src/generators/application/lib/update-jest-config.js +5 -0
- package/src/generators/application/schema.d.ts +1 -0
- package/src/generators/host/host.js +0 -2
- package/src/generators/init/init.js +0 -2
- package/src/generators/library/lib/normalize-options.js +2 -0
- package/src/generators/library/library.js +14 -8
- package/src/generators/library/schema.d.ts +1 -0
- package/src/generators/remote/remote.js +0 -2
- package/src/utils/create-ts-config.js +57 -7
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/react",
|
|
3
|
-
"version": "0.0.0-pr-
|
|
3
|
+
"version": "0.0.0-pr-28808-0f14212",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "The React plugin for Nx contains executors and generators for managing React applications and libraries within an Nx workspace. It provides:\n\n\n- Integration with libraries such as Jest, Vitest, Playwright, Cypress, and Storybook.\n\n- Generators for applications, libraries, components, hooks, and more.\n\n- Library build support for publishing packages to npm or other registries.\n\n- Utilities for automatic workspace refactoring.",
|
|
6
6
|
"repository": {
|
|
@@ -39,10 +39,10 @@
|
|
|
39
39
|
"picocolors": "^1.1.0",
|
|
40
40
|
"tslib": "^2.3.0",
|
|
41
41
|
"@module-federation/enhanced": "0.6.9",
|
|
42
|
-
"@nx/devkit": "0.0.0-pr-
|
|
43
|
-
"@nx/js": "0.0.0-pr-
|
|
44
|
-
"@nx/eslint": "0.0.0-pr-
|
|
45
|
-
"@nx/web": "0.0.0-pr-
|
|
42
|
+
"@nx/devkit": "0.0.0-pr-28808-0f14212",
|
|
43
|
+
"@nx/js": "0.0.0-pr-28808-0f14212",
|
|
44
|
+
"@nx/eslint": "0.0.0-pr-28808-0f14212",
|
|
45
|
+
"@nx/web": "0.0.0-pr-28808-0f14212",
|
|
46
46
|
"express": "^4.19.2",
|
|
47
47
|
"http-proxy-middleware": "^3.0.3"
|
|
48
48
|
},
|
|
@@ -27,8 +27,8 @@ const js_1 = require("@nx/js");
|
|
|
27
27
|
const log_show_project_command_1 = require("@nx/devkit/src/utils/log-show-project-command");
|
|
28
28
|
const setup_tailwind_1 = require("../setup-tailwind/setup-tailwind");
|
|
29
29
|
const flat_config_1 = require("@nx/eslint/src/utils/flat-config");
|
|
30
|
-
const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
|
|
31
30
|
const add_project_root_to_rspack_plugin_excludes_1 = require("./lib/add-project-root-to-rspack-plugin-excludes");
|
|
31
|
+
const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
|
|
32
32
|
async function addLinting(host, options) {
|
|
33
33
|
const tasks = [];
|
|
34
34
|
if (options.linter === eslint_1.Linter.EsLint) {
|
|
@@ -74,16 +74,17 @@ async function applicationGenerator(host, schema) {
|
|
|
74
74
|
});
|
|
75
75
|
}
|
|
76
76
|
async function applicationGeneratorInternal(host, schema) {
|
|
77
|
-
(0, ts_solution_setup_1.assertNotUsingTsSolutionSetup)(host, 'react', 'application');
|
|
78
77
|
const tasks = [];
|
|
79
|
-
const options = await (0, normalize_options_1.normalizeOptions)(host, schema);
|
|
80
|
-
(0, show_possible_warnings_1.showPossibleWarnings)(host, options);
|
|
81
78
|
const jsInitTask = await (0, js_1.initGenerator)(host, {
|
|
82
79
|
...schema,
|
|
83
80
|
tsConfigName: schema.rootProject ? 'tsconfig.json' : 'tsconfig.base.json',
|
|
84
81
|
skipFormat: true,
|
|
82
|
+
addTsPlugin: process.env.NX_ADD_PLUGINS !== 'false' &&
|
|
83
|
+
process.env.NX_ADD_TS_PLUGIN !== 'false',
|
|
85
84
|
});
|
|
86
85
|
tasks.push(jsInitTask);
|
|
86
|
+
const options = await (0, normalize_options_1.normalizeOptions)(host, schema);
|
|
87
|
+
(0, show_possible_warnings_1.showPossibleWarnings)(host, options);
|
|
87
88
|
const initTask = await (0, init_1.default)(host, {
|
|
88
89
|
...options,
|
|
89
90
|
skipFormat: true,
|
|
@@ -143,6 +144,7 @@ async function applicationGeneratorInternal(host, schema) {
|
|
|
143
144
|
compiler: options.compiler,
|
|
144
145
|
skipFormat: true,
|
|
145
146
|
addPlugin: options.addPlugin,
|
|
147
|
+
projectType: 'application',
|
|
146
148
|
});
|
|
147
149
|
tasks.push(viteTask);
|
|
148
150
|
createOrEditViteConfig(host, {
|
|
@@ -251,6 +253,11 @@ async function applicationGeneratorInternal(host, schema) {
|
|
|
251
253
|
});
|
|
252
254
|
`);
|
|
253
255
|
}
|
|
256
|
+
(0, ts_solution_setup_1.updateTsconfigFiles)(host, options.appProjectRoot, 'tsconfig.app.json', {
|
|
257
|
+
jsx: 'react-jsx',
|
|
258
|
+
module: 'esnext',
|
|
259
|
+
moduleResolution: 'bundler',
|
|
260
|
+
});
|
|
254
261
|
if (!options.skipFormat) {
|
|
255
262
|
await (0, devkit_1.formatFiles)(host);
|
|
256
263
|
}
|
|
@@ -1,14 +1,31 @@
|
|
|
1
|
-
{
|
|
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 { %>{
|
|
2
18
|
"extends": "./tsconfig.json",
|
|
3
19
|
"compilerOptions": {
|
|
4
20
|
"outDir": "<%= offsetFromRoot %>dist/out-tsc",
|
|
5
21
|
"types": [
|
|
6
22
|
"node",
|
|
7
|
-
<%_ if (style === 'styled-jsx') { %>"@nx/react/typings/styled-jsx.d.ts",<% } _%>
|
|
23
|
+
<%_ if (style === 'styled-jsx') { _%>"@nx/react/typings/styled-jsx.d.ts",<%_ } _%>
|
|
8
24
|
"@nx/react/typings/cssmodule.d.ts",
|
|
9
25
|
"@nx/react/typings/image.d.ts"
|
|
10
|
-
|
|
26
|
+
]
|
|
11
27
|
},
|
|
12
|
-
"exclude": ["
|
|
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"],
|
|
13
29
|
"include": ["src/**/*.js", "src/**/*.jsx", "src/**/*.ts", "src/**/*.tsx"]
|
|
14
30
|
}
|
|
31
|
+
<% } %>
|
|
@@ -1,4 +1,20 @@
|
|
|
1
|
-
{
|
|
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 { %>{
|
|
2
18
|
"extends": "./tsconfig.json",
|
|
3
19
|
"compilerOptions": {
|
|
4
20
|
"outDir": "<%= offsetFromRoot %>dist/out-tsc",
|
|
@@ -7,8 +23,9 @@
|
|
|
7
23
|
<%_ if (style === 'styled-jsx') { _%>"@nx/react/typings/styled-jsx.d.ts",<%_ } _%>
|
|
8
24
|
"@nx/react/typings/cssmodule.d.ts",
|
|
9
25
|
"@nx/react/typings/image.d.ts"
|
|
10
|
-
|
|
26
|
+
]
|
|
11
27
|
},
|
|
12
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"],
|
|
13
29
|
"include": ["src/**/*.js", "src/**/*.jsx", "src/**/*.ts", "src/**/*.tsx"]
|
|
14
30
|
}
|
|
31
|
+
<% } %>
|
|
@@ -1,4 +1,20 @@
|
|
|
1
|
-
{
|
|
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 { %>{
|
|
2
18
|
"extends": "./tsconfig.json",
|
|
3
19
|
"compilerOptions": {
|
|
4
20
|
"outDir": "<%= offsetFromRoot %>dist/out-tsc",
|
|
@@ -7,8 +23,9 @@
|
|
|
7
23
|
<%_ if (style === 'styled-jsx') { _%>"@nx/react/typings/styled-jsx.d.ts",<%_ } _%>
|
|
8
24
|
"@nx/react/typings/cssmodule.d.ts",
|
|
9
25
|
"@nx/react/typings/image.d.ts"
|
|
10
|
-
|
|
26
|
+
]
|
|
11
27
|
},
|
|
12
|
-
"exclude": ["
|
|
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"],
|
|
13
29
|
"include": ["src/**/*.js", "src/**/*.jsx", "src/**/*.ts", "src/**/*.tsx"]
|
|
14
30
|
}
|
|
31
|
+
<% } %>
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
<% if (classComponent) { %>
|
|
2
2
|
import { Component } from 'react';
|
|
3
3
|
<%_ } _%>
|
|
4
|
-
//
|
|
5
|
-
import styles from './<%= fileName %>.module.<%= style %>';
|
|
4
|
+
// Uncomment this line to use CSS modules
|
|
5
|
+
// import styles from './<%= fileName %>.module.<%= style %>';
|
|
6
6
|
<%_ if (!minimal) { _%>
|
|
7
7
|
import NxWelcome from "./nx-welcome";
|
|
8
8
|
<%_ } _%>
|
|
@@ -4,6 +4,8 @@ exports.addProject = addProject;
|
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
|
5
5
|
const has_webpack_plugin_1 = require("../../../utils/has-webpack-plugin");
|
|
6
6
|
const maybe_js_1 = require("../../../utils/maybe-js");
|
|
7
|
+
const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
|
|
8
|
+
const get_import_path_1 = require("@nx/js/src/utils/get-import-path");
|
|
7
9
|
function addProject(host, options) {
|
|
8
10
|
const project = {
|
|
9
11
|
root: options.appProjectRoot,
|
|
@@ -20,9 +22,21 @@ function addProject(host, options) {
|
|
|
20
22
|
};
|
|
21
23
|
}
|
|
22
24
|
}
|
|
23
|
-
(0,
|
|
24
|
-
|
|
25
|
-
|
|
25
|
+
if ((0, ts_solution_setup_1.isUsingTsSolutionSetup)(host)) {
|
|
26
|
+
(0, devkit_1.writeJson)(host, (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'package.json'), {
|
|
27
|
+
name: (0, get_import_path_1.getImportPath)(host, options.name),
|
|
28
|
+
version: '0.0.1',
|
|
29
|
+
private: true,
|
|
30
|
+
nx: {
|
|
31
|
+
name: options.name,
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
(0, devkit_1.addProjectConfiguration)(host, options.projectName, {
|
|
37
|
+
...project,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
26
40
|
}
|
|
27
41
|
function createBuildTarget(options) {
|
|
28
42
|
return {
|
|
@@ -10,6 +10,7 @@ const maybe_js_1 = require("../../../utils/maybe-js");
|
|
|
10
10
|
const has_webpack_plugin_1 = require("../../../utils/has-webpack-plugin");
|
|
11
11
|
const get_app_tests_1 = require("./get-app-tests");
|
|
12
12
|
const onboarding_1 = require("nx/src/nx-cloud/utilities/onboarding");
|
|
13
|
+
const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
|
|
13
14
|
async function createApplicationFiles(host, options) {
|
|
14
15
|
let styleSolutionSpecificAppFiles;
|
|
15
16
|
if (options.styledModule && options.style !== 'styled-jsx') {
|
|
@@ -46,6 +47,7 @@ async function createApplicationFiles(host, options) {
|
|
|
46
47
|
inSourceVitestTests: (0, get_in_source_vitest_tests_template_1.getInSourceVitestTestsTemplate)(appTests),
|
|
47
48
|
style: options.style === 'tailwind' ? 'css' : options.style,
|
|
48
49
|
hasStyleFile,
|
|
50
|
+
isUsingTsSolutionSetup: (0, ts_solution_setup_1.isUsingTsSolutionSetup)(host),
|
|
49
51
|
};
|
|
50
52
|
if (options.bundler === 'vite') {
|
|
51
53
|
(0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, '../files/base-vite'), options.appProjectRoot, templateVariables);
|
|
@@ -7,6 +7,7 @@ const devkit_1 = require("@nx/devkit");
|
|
|
7
7
|
const project_name_and_root_utils_1 = require("@nx/devkit/src/generators/project-name-and-root-utils");
|
|
8
8
|
const assertion_1 = require("../../../utils/assertion");
|
|
9
9
|
const find_free_port_1 = require("./find-free-port");
|
|
10
|
+
const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
|
|
10
11
|
function normalizeDirectory(options) {
|
|
11
12
|
options.directory = options.directory?.replace(/\\{1,2}/g, '/');
|
|
12
13
|
const { projectDirectory } = (0, devkit_1.extractLayoutDirectory)(options.directory);
|
|
@@ -51,6 +52,7 @@ async function normalizeOptions(host, options) {
|
|
|
51
52
|
fileName,
|
|
52
53
|
styledModule,
|
|
53
54
|
hasStyles: options.style !== 'none',
|
|
55
|
+
isUsingTsSolutionConfig: (0, ts_solution_setup_1.isUsingTsSolutionSetup)(host),
|
|
54
56
|
};
|
|
55
57
|
normalized.routing = normalized.routing ?? false;
|
|
56
58
|
normalized.strict = normalized.strict ?? true;
|
|
@@ -17,6 +17,11 @@ function updateSpecConfig(host, options) {
|
|
|
17
17
|
types.push('@nx/react/typings/cssmodule.d.ts', '@nx/react/typings/image.d.ts');
|
|
18
18
|
compilerOptions.types = types;
|
|
19
19
|
json.compilerOptions = compilerOptions;
|
|
20
|
+
if (options.isUsingTsSolutionConfig) {
|
|
21
|
+
// add project reference to the runtime tsconfig.app.json file
|
|
22
|
+
json.references ??= [];
|
|
23
|
+
json.references.push({ path: './tsconfig.app.json' });
|
|
24
|
+
}
|
|
20
25
|
return json;
|
|
21
26
|
});
|
|
22
27
|
if (options.unitTestRunner !== 'jest') {
|
|
@@ -15,9 +15,7 @@ const add_mf_env_to_inputs_1 = require("../../utils/add-mf-env-to-inputs");
|
|
|
15
15
|
const js_1 = require("@nx/js");
|
|
16
16
|
const versions_1 = require("../../utils/versions");
|
|
17
17
|
const project_name_and_root_utils_1 = require("@nx/devkit/src/generators/project-name-and-root-utils");
|
|
18
|
-
const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
|
|
19
18
|
async function hostGenerator(host, schema) {
|
|
20
|
-
(0, ts_solution_setup_1.assertNotUsingTsSolutionSetup)(host, 'react', 'host');
|
|
21
19
|
const tasks = [];
|
|
22
20
|
const options = {
|
|
23
21
|
...(await (0, normalize_options_1.normalizeOptions)(host, schema)),
|
|
@@ -2,10 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.reactInitGenerator = reactInitGenerator;
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
|
5
|
-
const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
|
|
6
5
|
const versions_1 = require("../../utils/versions");
|
|
7
6
|
async function reactInitGenerator(host, schema) {
|
|
8
|
-
(0, ts_solution_setup_1.assertNotUsingTsSolutionSetup)(host, 'react', 'init');
|
|
9
7
|
const tasks = [];
|
|
10
8
|
if (!schema.skipPackageJson) {
|
|
11
9
|
tasks.push((0, devkit_1.removeDependenciesFromPackageJson)(host, ['@nx/react'], []));
|
|
@@ -4,6 +4,7 @@ exports.normalizeOptions = normalizeOptions;
|
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
|
5
5
|
const project_name_and_root_utils_1 = require("@nx/devkit/src/generators/project-name-and-root-utils");
|
|
6
6
|
const assertion_1 = require("../../../utils/assertion");
|
|
7
|
+
const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
|
|
7
8
|
async function normalizeOptions(host, options) {
|
|
8
9
|
await (0, project_name_and_root_utils_1.ensureProjectName)(host, options, 'library');
|
|
9
10
|
const { projectName, names: projectNames, projectRoot, importPath, } = await (0, project_name_and_root_utils_1.determineProjectNameAndRootOptions)(host, {
|
|
@@ -62,6 +63,7 @@ async function normalizeOptions(host, options) {
|
|
|
62
63
|
}
|
|
63
64
|
}
|
|
64
65
|
(0, assertion_1.assertValidStyle)(normalized.style);
|
|
66
|
+
normalized.isUsingTsSolutionConfig = (0, ts_solution_setup_1.isUsingTsSolutionSetup)(host);
|
|
65
67
|
return normalized;
|
|
66
68
|
}
|
|
67
69
|
function findMainEntry(tree, projectRoot) {
|
|
@@ -7,7 +7,6 @@ const devkit_1 = require("@nx/devkit");
|
|
|
7
7
|
const artifact_name_and_directory_utils_1 = require("@nx/devkit/src/generators/artifact-name-and-directory-utils");
|
|
8
8
|
const log_show_project_command_1 = require("@nx/devkit/src/utils/log-show-project-command");
|
|
9
9
|
const js_1 = require("@nx/js");
|
|
10
|
-
const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
|
|
11
10
|
const versions_1 = require("../../utils/versions");
|
|
12
11
|
const maybe_js_1 = require("../../utils/maybe-js");
|
|
13
12
|
const component_1 = require("../component/component");
|
|
@@ -21,6 +20,7 @@ const create_files_1 = require("./lib/create-files");
|
|
|
21
20
|
const create_ts_config_1 = require("../../utils/create-ts-config");
|
|
22
21
|
const install_common_dependencies_1 = require("./lib/install-common-dependencies");
|
|
23
22
|
const set_defaults_1 = require("./lib/set-defaults");
|
|
23
|
+
const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
|
|
24
24
|
async function libraryGenerator(host, schema) {
|
|
25
25
|
return await libraryGeneratorInternal(host, {
|
|
26
26
|
addPlugin: false,
|
|
@@ -28,8 +28,14 @@ async function libraryGenerator(host, schema) {
|
|
|
28
28
|
});
|
|
29
29
|
}
|
|
30
30
|
async function libraryGeneratorInternal(host, schema) {
|
|
31
|
-
(0, ts_solution_setup_1.assertNotUsingTsSolutionSetup)(host, 'react', 'library');
|
|
32
31
|
const tasks = [];
|
|
32
|
+
const jsInitTask = await (0, js_1.initGenerator)(host, {
|
|
33
|
+
...schema,
|
|
34
|
+
skipFormat: true,
|
|
35
|
+
addTsPlugin: process.env.NX_ADD_PLUGINS !== 'false' &&
|
|
36
|
+
process.env.NX_ADD_TS_PLUGIN !== 'false',
|
|
37
|
+
});
|
|
38
|
+
tasks.push(jsInitTask);
|
|
33
39
|
const options = await (0, normalize_options_1.normalizeOptions)(host, schema);
|
|
34
40
|
if (options.publishable === true && !schema.importPath) {
|
|
35
41
|
throw new Error(`For publishable libs you have to provide a proper "--importPath" which needs to be a valid npm package name (e.g. my-awesome-lib or @myorg/my-lib)`);
|
|
@@ -37,11 +43,6 @@ async function libraryGeneratorInternal(host, schema) {
|
|
|
37
43
|
if (!options.component) {
|
|
38
44
|
options.style = 'none';
|
|
39
45
|
}
|
|
40
|
-
const jsInitTask = await (0, js_1.initGenerator)(host, {
|
|
41
|
-
...schema,
|
|
42
|
-
skipFormat: true,
|
|
43
|
-
});
|
|
44
|
-
tasks.push(jsInitTask);
|
|
45
46
|
const initTask = await (0, init_1.default)(host, {
|
|
46
47
|
...options,
|
|
47
48
|
skipFormat: true,
|
|
@@ -178,11 +179,16 @@ async function libraryGeneratorInternal(host, schema) {
|
|
|
178
179
|
tasks.push(routeTask);
|
|
179
180
|
(0, set_defaults_1.setDefaults)(host, options);
|
|
180
181
|
(0, create_ts_config_1.extractTsConfigBase)(host);
|
|
181
|
-
if (!options.skipTsConfig) {
|
|
182
|
+
if (!options.skipTsConfig && !options.isUsingTsSolutionConfig) {
|
|
182
183
|
(0, js_1.addTsConfigPath)(host, options.importPath, [
|
|
183
184
|
(0, maybe_js_1.maybeJs)(options, (0, devkit_1.joinPathFragments)(options.projectRoot, './src/index.ts')),
|
|
184
185
|
]);
|
|
185
186
|
}
|
|
187
|
+
(0, ts_solution_setup_1.updateTsconfigFiles)(host, options.projectRoot, 'tsconfig.lib.json', {
|
|
188
|
+
jsx: 'react-jsx',
|
|
189
|
+
module: 'esnext',
|
|
190
|
+
moduleResolution: 'bundler',
|
|
191
|
+
});
|
|
186
192
|
if (!options.skipFormat) {
|
|
187
193
|
await (0, devkit_1.formatFiles)(host);
|
|
188
194
|
}
|
|
@@ -17,7 +17,6 @@ const maybe_js_1 = require("../../utils/maybe-js");
|
|
|
17
17
|
const js_1 = require("@nx/js");
|
|
18
18
|
const versions_1 = require("../../utils/versions");
|
|
19
19
|
const project_name_and_root_utils_1 = require("@nx/devkit/src/generators/project-name-and-root-utils");
|
|
20
|
-
const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
|
|
21
20
|
function addModuleFederationFiles(host, options) {
|
|
22
21
|
const templateVariables = {
|
|
23
22
|
...(0, devkit_1.names)(options.projectName),
|
|
@@ -47,7 +46,6 @@ function addModuleFederationFiles(host, options) {
|
|
|
47
46
|
}
|
|
48
47
|
}
|
|
49
48
|
async function remoteGenerator(host, schema) {
|
|
50
|
-
(0, ts_solution_setup_1.assertNotUsingTsSolutionSetup)(host, 'react', 'remote');
|
|
51
49
|
const tasks = [];
|
|
52
50
|
const options = {
|
|
53
51
|
...(await (0, normalize_options_1.normalizeOptions)(host, schema)),
|
|
@@ -4,7 +4,64 @@ exports.createTsConfig = createTsConfig;
|
|
|
4
4
|
exports.extractTsConfigBase = extractTsConfigBase;
|
|
5
5
|
const shared = require("@nx/js/src/utils/typescript/create-ts-config");
|
|
6
6
|
const json_1 = require("nx/src/generators/utils/json");
|
|
7
|
+
const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
|
|
7
8
|
function createTsConfig(host, projectRoot, type, options, relativePathToRootTsConfig) {
|
|
9
|
+
if ((0, ts_solution_setup_1.isUsingTsSolutionSetup)(host)) {
|
|
10
|
+
createTsConfigForTsSolution(host, projectRoot, type, options, relativePathToRootTsConfig);
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
createTsConfigForNonTsSolution(host, projectRoot, type, options, relativePathToRootTsConfig);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function extractTsConfigBase(host) {
|
|
17
|
+
shared.extractTsConfigBase(host);
|
|
18
|
+
if (host.exists('vite.config.ts')) {
|
|
19
|
+
const vite = host.read('vite.config.ts').toString();
|
|
20
|
+
host.write('vite.config.ts', vite.replace(`projects: []`, `projects: ['tsconfig.base.json']`));
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function createTsConfigForTsSolution(host, projectRoot, type, options, relativePathToRootTsConfig) {
|
|
24
|
+
const json = {
|
|
25
|
+
files: [],
|
|
26
|
+
include: [],
|
|
27
|
+
references: [
|
|
28
|
+
{
|
|
29
|
+
path: type === 'app' ? './tsconfig.app.json' : './tsconfig.lib.json',
|
|
30
|
+
},
|
|
31
|
+
],
|
|
32
|
+
};
|
|
33
|
+
// inline tsconfig.base.json into the project
|
|
34
|
+
if (options.rootProject) {
|
|
35
|
+
json.compileOnSave = false;
|
|
36
|
+
json.compilerOptions = {
|
|
37
|
+
...shared.tsConfigBaseOptions,
|
|
38
|
+
...json.compilerOptions,
|
|
39
|
+
};
|
|
40
|
+
json.exclude = ['node_modules', 'tmp'];
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
json.extends = relativePathToRootTsConfig;
|
|
44
|
+
}
|
|
45
|
+
(0, json_1.writeJson)(host, `${projectRoot}/tsconfig.json`, json);
|
|
46
|
+
const tsconfigProjectPath = `${projectRoot}/tsconfig.${type}.json`;
|
|
47
|
+
if (host.exists(tsconfigProjectPath)) {
|
|
48
|
+
(0, json_1.updateJson)(host, tsconfigProjectPath, (json) => {
|
|
49
|
+
if (options.bundler === 'vite') {
|
|
50
|
+
json.compilerOptions ??= {};
|
|
51
|
+
const types = new Set(json.compilerOptions.types ?? []);
|
|
52
|
+
types.add('node');
|
|
53
|
+
types.add('vite/client');
|
|
54
|
+
json.compilerOptions.types = Array.from(types);
|
|
55
|
+
}
|
|
56
|
+
if (options.style === '@emotion/styled') {
|
|
57
|
+
json.compilerOptions ??= {};
|
|
58
|
+
json.compilerOptions.jsxImportSource = '@emotion/react';
|
|
59
|
+
}
|
|
60
|
+
return json;
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
function createTsConfigForNonTsSolution(host, projectRoot, type, options, relativePathToRootTsConfig) {
|
|
8
65
|
const json = {
|
|
9
66
|
compilerOptions: {
|
|
10
67
|
jsx: 'react-jsx',
|
|
@@ -55,10 +112,3 @@ function createTsConfig(host, projectRoot, type, options, relativePathToRootTsCo
|
|
|
55
112
|
});
|
|
56
113
|
}
|
|
57
114
|
}
|
|
58
|
-
function extractTsConfigBase(host) {
|
|
59
|
-
shared.extractTsConfigBase(host);
|
|
60
|
-
if (host.exists('vite.config.ts')) {
|
|
61
|
-
const vite = host.read('vite.config.ts').toString();
|
|
62
|
-
host.write('vite.config.ts', vite.replace(`projects: []`, `projects: ['tsconfig.base.json']`));
|
|
63
|
-
}
|
|
64
|
-
}
|