@nx/react 17.0.3 → 17.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +9 -4
- package/generators.json +1 -1
- package/index.d.ts +1 -0
- package/index.js +3 -1
- package/mf/dynamic-federation.d.ts +4 -0
- package/mf/dynamic-federation.js +75 -0
- package/mf/index.d.ts +1 -0
- package/mf/index.js +7 -0
- package/migrations.json +21 -0
- package/package.json +7 -7
- package/plugins/component-testing/index.js +52 -24
- package/plugins/component-testing/webpack-fallback.js +1 -1
- package/plugins/nx-react-webpack-plugin/lib/apply-react-config.d.ts +4 -0
- package/plugins/nx-react-webpack-plugin/lib/apply-react-config.js +86 -0
- package/plugins/nx-react-webpack-plugin/nx-react-webpack-plugin.d.ts +8 -0
- package/plugins/nx-react-webpack-plugin/nx-react-webpack-plugin.js +13 -0
- package/plugins/storybook/index.js +6 -2
- package/plugins/storybook/merge-plugins.d.ts +1 -1
- package/plugins/webpack.d.ts +1 -3
- package/plugins/webpack.js +3 -11
- package/plugins/with-react.d.ts +2 -4
- package/plugins/with-react.js +2 -58
- package/src/executors/module-federation-dev-server/module-federation-dev-server.impl.d.ts +12 -0
- package/src/executors/module-federation-dev-server/module-federation-dev-server.impl.js +149 -51
- package/src/executors/module-federation-dev-server/schema.json +9 -1
- package/src/generators/application/application.js +41 -18
- package/src/generators/application/files/base-vite/index.html__tmpl__ +1 -1
- package/src/generators/application/files/base-webpack/src/index.html +0 -2
- package/src/generators/application/files/base-webpack/webpack.config.js__tmpl__ +46 -5
- package/src/generators/application/files/nx-welcome/src/app/nx-welcome.tsx +54 -13
- package/src/generators/application/files/style-tailwind/src/app/__fileName__.tsx__tmpl__ +33 -0
- package/src/generators/application/files/style-tailwind/src/styles.css +1 -0
- package/src/generators/application/lib/add-e2e.js +25 -7
- package/src/generators/application/lib/add-jest.js +2 -2
- package/src/generators/application/lib/add-project.d.ts +2 -2
- package/src/generators/application/lib/add-project.js +12 -15
- package/src/generators/application/lib/add-routing.d.ts +1 -1
- package/src/generators/application/lib/add-routing.js +4 -8
- package/src/generators/application/lib/create-application-files.js +30 -1
- package/src/generators/application/lib/install-common-dependencies.js +15 -1
- package/src/generators/application/lib/normalize-options.js +35 -1
- package/src/generators/application/lib/set-defaults.js +1 -0
- package/src/generators/application/lib/update-jest-config.js +8 -8
- package/src/generators/application/schema.d.ts +5 -0
- package/src/generators/application/schema.json +7 -3
- package/src/generators/component/files/__fileName__.tsx__tmpl__ +39 -22
- package/src/generators/component/lib/normalize-options.js +4 -2
- package/src/generators/component/schema.d.ts +6 -4
- package/src/generators/component/schema.json +7 -7
- package/src/generators/component-cypress-spec/schema.json +1 -1
- package/src/generators/component-story/schema.json +1 -1
- package/src/generators/component-test/schema.json +1 -1
- package/src/generators/cypress-component-configuration/cypress-component-configuration.d.ts +2 -1
- package/src/generators/cypress-component-configuration/cypress-component-configuration.js +18 -7
- package/src/generators/cypress-component-configuration/lib/add-files.js +1 -6
- package/src/generators/cypress-component-configuration/schema.d.ts +1 -0
- package/src/generators/federate-module/federate-module.js +2 -2
- package/src/generators/federate-module/schema.d.ts +1 -1
- package/src/generators/federate-module/schema.json +4 -3
- package/src/generators/hook/files/__fileName__.ts__tmpl__ +15 -15
- package/src/generators/hook/schema.d.ts +4 -4
- package/src/generators/hook/schema.json +5 -5
- package/src/generators/host/files/common/src/main.js__tmpl__ +10 -0
- package/src/generators/host/files/common/tsconfig.lint.json__tmpl__ +19 -0
- package/src/generators/host/files/common-ts/src/app/__fileName__.tsx__tmpl__ +41 -0
- package/src/generators/host/files/common-ts/src/main.ts__tmpl__ +10 -0
- package/src/generators/host/files/module-federation/module-federation.config.js__tmpl__ +17 -2
- package/src/generators/host/files/module-federation-ssr/module-federation.server.config.js__tmpl__ +5 -2
- package/src/generators/host/files/module-federation-ssr-ts/module-federation.server.config.ts__tmpl__ +5 -2
- package/src/generators/host/files/module-federation-ts/module-federation.config.ts__tmpl__ +17 -2
- package/src/generators/host/files/module-federation-ts/webpack.config.prod.ts__tmpl__ +2 -1
- package/src/generators/host/files/module-federation-ts/webpack.config.ts__tmpl__ +2 -2
- package/src/generators/host/host.js +15 -1
- package/src/generators/host/lib/add-module-federation-files.d.ts +2 -1
- package/src/generators/host/lib/add-module-federation-files.js +24 -11
- package/src/generators/host/lib/setup-ssr-for-host.js +1 -0
- package/src/generators/host/lib/update-module-federation-e2e-project.js +7 -5
- package/src/generators/host/schema.d.ts +5 -2
- package/src/generators/host/schema.json +16 -6
- package/src/generators/init/init.d.ts +1 -1
- package/src/generators/init/init.js +10 -49
- package/src/generators/init/schema.d.ts +1 -6
- package/src/generators/init/schema.json +5 -22
- package/src/generators/library/lib/add-linting.js +2 -2
- package/src/generators/library/lib/add-rollup-build-target.d.ts +2 -1
- package/src/generators/library/lib/add-rollup-build-target.js +16 -8
- package/src/generators/library/lib/install-common-dependencies.js +13 -5
- package/src/generators/library/lib/normalize-options.js +34 -5
- package/src/generators/library/lib/update-app-routes.js +1 -1
- package/src/generators/library/library.js +17 -6
- package/src/generators/library/schema.d.ts +1 -0
- package/src/generators/library/schema.json +3 -3
- package/src/generators/redux/schema.d.ts +1 -1
- package/src/generators/redux/schema.json +2 -2
- package/src/generators/remote/files/module-federation/module-federation.config.js__tmpl__ +4 -1
- package/src/generators/remote/files/module-federation-ssr/module-federation.server.config.js__tmpl__ +1 -1
- package/src/generators/remote/files/module-federation-ssr-ts/module-federation.server.config.ts__tmpl__ +1 -1
- package/src/generators/remote/files/module-federation-ssr-ts/tsconfig.lint.json__tmpl__ +19 -0
- package/src/generators/remote/files/module-federation-ts/module-federation.config.ts__tmpl__ +4 -1
- package/src/generators/remote/files/module-federation-ts/tsconfig.lint.json__tmpl__ +19 -0
- package/src/generators/remote/lib/add-remote-to-dynamic-host.d.ts +2 -0
- package/src/generators/remote/lib/add-remote-to-dynamic-host.js +11 -0
- package/src/generators/remote/lib/setup-ssr-for-remote.js +5 -1
- package/src/generators/remote/lib/setup-tspath-for-remote.js +2 -1
- package/src/generators/remote/lib/update-host-with-remote.js +10 -1
- package/src/generators/remote/remote.js +22 -2
- package/src/generators/remote/schema.d.ts +3 -2
- package/src/generators/remote/schema.json +17 -6
- package/src/generators/setup-ssr/schema.json +1 -1
- package/src/generators/setup-ssr/setup-ssr.js +23 -7
- package/src/generators/setup-tailwind/schema.json +1 -1
- package/src/generators/stories/schema.json +1 -1
- package/src/generators/stories/stories.js +17 -5
- package/src/generators/storybook-configuration/configuration.d.ts +2 -0
- package/src/generators/storybook-configuration/configuration.js +37 -15
- package/src/generators/storybook-configuration/schema.d.ts +2 -1
- package/src/generators/storybook-configuration/schema.json +7 -7
- package/src/migrations/update-18-0-0/add-mf-env-var-to-target-defaults.d.ts +2 -0
- package/src/migrations/update-18-0-0/add-mf-env-var-to-target-defaults.js +26 -0
- package/src/migrations/update-18-1-1/fix-target-defaults-inputs.d.ts +2 -0
- package/src/migrations/update-18-1-1/fix-target-defaults-inputs.js +53 -0
- package/src/module-federation/ast-utils.js +1 -1
- package/src/module-federation/utils.js +8 -1
- package/src/module-federation/with-module-federation-ssr.js +3 -0
- package/src/module-federation/with-module-federation.d.ts +3 -3
- package/src/module-federation/with-module-federation.js +14 -4
- package/src/rules/update-module-federation-project.d.ts +2 -0
- package/src/rules/update-module-federation-project.js +12 -3
- package/src/utils/add-mf-env-to-inputs.d.ts +2 -0
- package/src/utils/add-mf-env-to-inputs.js +27 -0
- package/src/utils/assertion.js +1 -0
- package/src/utils/ct-utils.d.ts +6 -1
- package/src/utils/ct-utils.js +39 -9
- package/src/utils/get-in-source-vitest-tests-template.js +1 -1
- package/src/utils/has-vite-plugin.d.ts +2 -0
- package/src/utils/has-vite-plugin.js +11 -0
- package/src/utils/has-webpack-plugin.d.ts +2 -0
- package/src/utils/has-webpack-plugin.js +11 -0
- package/src/utils/maybe-js.d.ts +3 -0
- package/src/utils/versions.d.ts +1 -1
- package/src/utils/versions.js +1 -1
- package/typings/style.d.ts +1 -0
- package/src/generators/application/files/base-webpack/src/environments/environment.prod.ts__tmpl__ +0 -3
- package/src/generators/application/files/base-webpack/src/environments/environment.ts__tmpl__ +0 -6
- package/src/generators/host/files/module-federation/src/main.ts__tmpl__ +0 -1
- package/src/generators/host/files/module-federation-ts/src/main.ts__tmpl__ +0 -1
- package/src/generators/library/lib/maybe-js.d.ts +0 -2
- /package/src/generators/host/files/common/src/app/{__fileName__.tsx__tmpl__ → __fileName__.js__tmpl__} +0 -0
- /package/src/generators/remote/files/{module-federation/src/main.ts__tmpl__ → common/src/main.js__tmpl__} +0 -0
- /package/src/generators/remote/files/{module-federation/src/remote-entry.ts__tmpl__ → common/src/remote-entry.js__tmpl__} +0 -0
- /package/src/generators/remote/files/{module-federation-ts → common-ts}/src/main.ts__tmpl__ +0 -0
- /package/src/generators/remote/files/{module-federation-ts → common-ts}/src/remote-entry.ts__tmpl__ +0 -0
- /package/src/{generators/library/lib → utils}/maybe-js.js +0 -0
|
@@ -13,6 +13,7 @@ async function setupSsrForHost(tree, options, appName, defaultRemoteManifest) {
|
|
|
13
13
|
: 'module-federation-ssr';
|
|
14
14
|
(0, devkit_1.generateFiles)(tree, (0, devkit_1.joinPathFragments)(__dirname, `../files/${pathToModuleFederationSsrFiles}`), project.root, {
|
|
15
15
|
...options,
|
|
16
|
+
static: !options?.dynamic,
|
|
16
17
|
remotes: defaultRemoteManifest.map(({ name, port }) => {
|
|
17
18
|
return {
|
|
18
19
|
...(0, devkit_1.names)(name),
|
|
@@ -5,11 +5,13 @@ const devkit_1 = require("@nx/devkit");
|
|
|
5
5
|
function updateModuleFederationE2eProject(host, options) {
|
|
6
6
|
try {
|
|
7
7
|
let projectConfig = (0, devkit_1.readProjectConfiguration)(host, options.e2eProjectName);
|
|
8
|
-
projectConfig.targets.e2e.
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
if (projectConfig.targets.e2e.executor !== '@nx/playwright:playwright') {
|
|
9
|
+
projectConfig.targets.e2e.options = {
|
|
10
|
+
...projectConfig.targets.e2e.options,
|
|
11
|
+
baseUrl: `http://localhost:${options.devServerPort}`,
|
|
12
|
+
};
|
|
13
|
+
(0, devkit_1.updateProjectConfiguration)(host, options.e2eProjectName, projectConfig);
|
|
14
|
+
}
|
|
13
15
|
}
|
|
14
16
|
catch {
|
|
15
17
|
// nothing
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ProjectNameAndRootFormat } from '@nx/devkit/src/generators/project-name-and-root-utils';
|
|
2
2
|
import type { Linter } from '@nx/eslint';
|
|
3
|
-
import type { SupportedStyles } from '../../../typings';
|
|
3
|
+
import type { SupportedStyles } from '../../../typings/style';
|
|
4
4
|
|
|
5
5
|
export interface Schema {
|
|
6
6
|
classComponent?: boolean;
|
|
@@ -8,7 +8,7 @@ export interface Schema {
|
|
|
8
8
|
devServerPort?: number;
|
|
9
9
|
directory?: string;
|
|
10
10
|
projectNameAndRootFormat?: ProjectNameAndRootFormat;
|
|
11
|
-
e2eTestRunner: 'cypress' | 'none';
|
|
11
|
+
e2eTestRunner: 'cypress' | 'playwright' | 'none';
|
|
12
12
|
globalCss?: boolean;
|
|
13
13
|
js?: boolean;
|
|
14
14
|
linter: Linter;
|
|
@@ -25,10 +25,13 @@ export interface Schema {
|
|
|
25
25
|
unitTestRunner: 'jest' | 'vitest' | 'none';
|
|
26
26
|
minimal?: boolean;
|
|
27
27
|
typescriptConfiguration?: boolean;
|
|
28
|
+
dynamic?: boolean;
|
|
29
|
+
addPlugin?: boolean;
|
|
28
30
|
}
|
|
29
31
|
|
|
30
32
|
export interface NormalizedSchema extends Schema {
|
|
31
33
|
appProjectRoot: string;
|
|
32
34
|
e2eProjectName: string;
|
|
33
35
|
projectName: string;
|
|
36
|
+
addPlugin?: boolean;
|
|
34
37
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"$schema": "
|
|
2
|
+
"$schema": "https://json-schema.org/schema",
|
|
3
3
|
"$id": "GeneratorReactHost",
|
|
4
4
|
"cli": "nx",
|
|
5
5
|
"title": "Generate Module Federation Setup for React Host App",
|
|
@@ -43,11 +43,15 @@
|
|
|
43
43
|
},
|
|
44
44
|
{
|
|
45
45
|
"value": "scss",
|
|
46
|
-
"label": "SASS(.scss) [
|
|
46
|
+
"label": "SASS(.scss) [ https://sass-lang.com ]"
|
|
47
47
|
},
|
|
48
48
|
{
|
|
49
49
|
"value": "less",
|
|
50
|
-
"label": "LESS [
|
|
50
|
+
"label": "LESS [ https://lesscss.org ]"
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
"value": "tailwind",
|
|
54
|
+
"label": "tailwind [ https://tailwindcss.com/ ]"
|
|
51
55
|
},
|
|
52
56
|
{
|
|
53
57
|
"value": "styled-components",
|
|
@@ -74,6 +78,11 @@
|
|
|
74
78
|
"enum": ["eslint"],
|
|
75
79
|
"default": "eslint"
|
|
76
80
|
},
|
|
81
|
+
"dynamic": {
|
|
82
|
+
"type": "boolean",
|
|
83
|
+
"description": "Should the host application use dynamic federation?",
|
|
84
|
+
"default": false
|
|
85
|
+
},
|
|
77
86
|
"skipFormat": {
|
|
78
87
|
"description": "Skip formatting files.",
|
|
79
88
|
"type": "boolean",
|
|
@@ -94,8 +103,9 @@
|
|
|
94
103
|
},
|
|
95
104
|
"e2eTestRunner": {
|
|
96
105
|
"type": "string",
|
|
97
|
-
"enum": ["cypress", "none"],
|
|
98
|
-
"description": "Test runner to use for end to end (
|
|
106
|
+
"enum": ["cypress", "playwright", "none"],
|
|
107
|
+
"description": "Test runner to use for end to end (E2E) tests.",
|
|
108
|
+
"x-prompt": "Which E2E test runner would you like to use?",
|
|
99
109
|
"default": "cypress"
|
|
100
110
|
},
|
|
101
111
|
"tags": {
|
|
@@ -165,7 +175,7 @@
|
|
|
165
175
|
},
|
|
166
176
|
"typescriptConfiguration": {
|
|
167
177
|
"type": "boolean",
|
|
168
|
-
"description": "Whether the module federation configuration and webpack configuration files should use TS.",
|
|
178
|
+
"description": "Whether the module federation configuration and webpack configuration files should use TS. When --js is used, this flag is ignored.",
|
|
169
179
|
"default": true
|
|
170
180
|
}
|
|
171
181
|
},
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { GeneratorCallback, Tree } from '@nx/devkit';
|
|
1
|
+
import { type GeneratorCallback, type Tree } from '@nx/devkit';
|
|
2
2
|
import { InitSchema } from './schema';
|
|
3
3
|
export declare function reactInitGenerator(host: Tree, schema: InitSchema): Promise<GeneratorCallback>;
|
|
4
4
|
export default reactInitGenerator;
|
|
@@ -2,59 +2,20 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.reactInitGenerator = void 0;
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
|
5
|
-
const js_1 = require("@nx/js");
|
|
6
5
|
const versions_1 = require("../../utils/versions");
|
|
7
|
-
function setDefault(host) {
|
|
8
|
-
const workspace = (0, devkit_1.readNxJson)(host);
|
|
9
|
-
workspace.generators = workspace.generators || {};
|
|
10
|
-
const reactGenerators = workspace.generators['@nx/react'] || {};
|
|
11
|
-
const generators = {
|
|
12
|
-
...workspace.generators,
|
|
13
|
-
'@nx/react': {
|
|
14
|
-
...reactGenerators,
|
|
15
|
-
application: {
|
|
16
|
-
...reactGenerators.application,
|
|
17
|
-
babel: true,
|
|
18
|
-
},
|
|
19
|
-
},
|
|
20
|
-
};
|
|
21
|
-
(0, devkit_1.updateNxJson)(host, { ...workspace, generators });
|
|
22
|
-
}
|
|
23
|
-
function updateDependencies(host, schema) {
|
|
24
|
-
(0, devkit_1.removeDependenciesFromPackageJson)(host, ['@nx/react'], []);
|
|
25
|
-
const dependencies = {
|
|
26
|
-
react: versions_1.reactVersion,
|
|
27
|
-
'react-dom': versions_1.reactDomVersion,
|
|
28
|
-
};
|
|
29
|
-
if (!schema.skipHelperLibs) {
|
|
30
|
-
dependencies['tslib'] = versions_1.tsLibVersion;
|
|
31
|
-
}
|
|
32
|
-
return (0, devkit_1.addDependenciesToPackageJson)(host, dependencies, {
|
|
33
|
-
'@nx/react': versions_1.nxVersion,
|
|
34
|
-
'@types/node': versions_1.typesNodeVersion,
|
|
35
|
-
'@types/react': versions_1.typesReactVersion,
|
|
36
|
-
'@types/react-dom': versions_1.typesReactDomVersion,
|
|
37
|
-
'@testing-library/react': versions_1.testingLibraryReactVersion,
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
6
|
async function reactInitGenerator(host, schema) {
|
|
41
7
|
const tasks = [];
|
|
42
|
-
const jsInitTask = await (0, js_1.initGenerator)(host, {
|
|
43
|
-
...schema,
|
|
44
|
-
tsConfigName: schema.rootProject ? 'tsconfig.json' : 'tsconfig.base.json',
|
|
45
|
-
skipFormat: true,
|
|
46
|
-
});
|
|
47
|
-
tasks.push(jsInitTask);
|
|
48
|
-
setDefault(host);
|
|
49
|
-
if (!schema.e2eTestRunner || schema.e2eTestRunner === 'cypress') {
|
|
50
|
-
(0, devkit_1.ensurePackage)('@nx/cypress', versions_1.nxVersion);
|
|
51
|
-
const { cypressInitGenerator } = await Promise.resolve().then(() => require('@nx/cypress/src/generators/init/init'));
|
|
52
|
-
const cypressTask = await cypressInitGenerator(host, {});
|
|
53
|
-
tasks.push(cypressTask);
|
|
54
|
-
}
|
|
55
8
|
if (!schema.skipPackageJson) {
|
|
56
|
-
|
|
57
|
-
tasks.push(
|
|
9
|
+
tasks.push((0, devkit_1.removeDependenciesFromPackageJson)(host, ['@nx/react'], []));
|
|
10
|
+
tasks.push((0, devkit_1.addDependenciesToPackageJson)(host, {
|
|
11
|
+
react: versions_1.reactVersion,
|
|
12
|
+
'react-dom': versions_1.reactDomVersion,
|
|
13
|
+
}, {
|
|
14
|
+
'@nx/react': versions_1.nxVersion,
|
|
15
|
+
}, undefined, schema.keepExistingVersions));
|
|
16
|
+
}
|
|
17
|
+
if (!schema.skipFormat) {
|
|
18
|
+
await (0, devkit_1.formatFiles)(host);
|
|
58
19
|
}
|
|
59
20
|
return (0, devkit_1.runTasksInSerial)(...tasks);
|
|
60
21
|
}
|
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
export interface InitSchema {
|
|
2
|
-
unitTestRunner?: 'jest' | 'vitest' | 'none';
|
|
3
|
-
e2eTestRunner?: 'cypress' | 'playwright' | 'none';
|
|
4
2
|
skipFormat?: boolean;
|
|
5
3
|
skipPackageJson?: boolean;
|
|
6
|
-
|
|
7
|
-
js?: boolean;
|
|
8
|
-
|
|
9
|
-
rootProject?: boolean;
|
|
4
|
+
keepExistingVersions?: boolean;
|
|
10
5
|
}
|
|
@@ -1,23 +1,11 @@
|
|
|
1
1
|
{
|
|
2
|
-
"$schema": "
|
|
2
|
+
"$schema": "https://json-schema.org/schema",
|
|
3
3
|
"$id": "NxReactNgInit",
|
|
4
4
|
"title": "Init React Plugin",
|
|
5
5
|
"description": "Initialize a React Plugin.",
|
|
6
6
|
"cli": "nx",
|
|
7
7
|
"type": "object",
|
|
8
8
|
"properties": {
|
|
9
|
-
"unitTestRunner": {
|
|
10
|
-
"description": "Adds the specified unit test runner.",
|
|
11
|
-
"type": "string",
|
|
12
|
-
"enum": ["jest", "none"],
|
|
13
|
-
"default": "jest"
|
|
14
|
-
},
|
|
15
|
-
"e2eTestRunner": {
|
|
16
|
-
"description": "Adds the specified E2E test runner.",
|
|
17
|
-
"type": "string",
|
|
18
|
-
"enum": ["cypress", "playwright", "none"],
|
|
19
|
-
"default": "cypress"
|
|
20
|
-
},
|
|
21
9
|
"skipFormat": {
|
|
22
10
|
"description": "Skip formatting files.",
|
|
23
11
|
"type": "boolean",
|
|
@@ -28,16 +16,11 @@
|
|
|
28
16
|
"type": "boolean",
|
|
29
17
|
"default": false
|
|
30
18
|
},
|
|
31
|
-
"
|
|
32
|
-
"description": "Do not install tslib.",
|
|
19
|
+
"keepExistingVersions": {
|
|
33
20
|
"type": "boolean",
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
|
|
37
|
-
"js": {
|
|
38
|
-
"type": "boolean",
|
|
39
|
-
"default": false,
|
|
40
|
-
"description": "Use JavaScript instead of TypeScript"
|
|
21
|
+
"x-priority": "internal",
|
|
22
|
+
"description": "Keep existing dependencies versions",
|
|
23
|
+
"default": false
|
|
41
24
|
}
|
|
42
25
|
},
|
|
43
26
|
"required": []
|
|
@@ -15,17 +15,17 @@ async function addLinting(host, options) {
|
|
|
15
15
|
(0, path_1.joinPathFragments)(options.projectRoot, 'tsconfig.lib.json'),
|
|
16
16
|
],
|
|
17
17
|
unitTestRunner: options.unitTestRunner,
|
|
18
|
-
eslintFilePatterns: [`${options.projectRoot}/**/*.{ts,tsx,js,jsx}`],
|
|
19
18
|
skipFormat: true,
|
|
20
19
|
skipPackageJson: options.skipPackageJson,
|
|
21
20
|
setParserOptionsProject: options.setParserOptionsProject,
|
|
21
|
+
addPlugin: options.addPlugin,
|
|
22
22
|
});
|
|
23
23
|
if ((0, eslint_file_1.isEslintConfigSupported)(host)) {
|
|
24
24
|
(0, eslint_file_1.addExtendsToLintConfig)(host, options.projectRoot, 'plugin:@nx/react');
|
|
25
25
|
}
|
|
26
26
|
let installTask = () => { };
|
|
27
27
|
if (!options.skipPackageJson) {
|
|
28
|
-
installTask =
|
|
28
|
+
installTask = (0, devkit_1.addDependenciesToPackageJson)(host, lint_1.extraEslintDependencies.dependencies, lint_1.extraEslintDependencies.devDependencies);
|
|
29
29
|
}
|
|
30
30
|
return (0, devkit_1.runTasksInSerial)(lintTask, installTask);
|
|
31
31
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { Tree } from 'nx/src/generators/tree';
|
|
2
|
+
import { GeneratorCallback } from '@nx/devkit';
|
|
2
3
|
import { NormalizedSchema } from '../schema';
|
|
3
|
-
export declare function addRollupBuildTarget(host: Tree, options: NormalizedSchema): Promise<
|
|
4
|
+
export declare function addRollupBuildTarget(host: Tree, options: NormalizedSchema): Promise<GeneratorCallback>;
|
|
@@ -2,15 +2,23 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.addRollupBuildTarget = void 0;
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
|
5
|
-
const maybe_js_1 = require("
|
|
5
|
+
const maybe_js_1 = require("../../../utils/maybe-js");
|
|
6
6
|
const versions_1 = require("../../../utils/versions");
|
|
7
7
|
async function addRollupBuildTarget(host, options) {
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
(
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
const tasks = [];
|
|
9
|
+
const { configurationGenerator } = (0, devkit_1.ensurePackage)('@nx/rollup', versions_1.nxVersion);
|
|
10
|
+
tasks.push(await configurationGenerator(host, {
|
|
11
|
+
...options,
|
|
12
|
+
project: options.name,
|
|
13
|
+
skipFormat: true,
|
|
14
|
+
}));
|
|
15
|
+
if (!options.skipPackageJson) {
|
|
16
|
+
// These are used in `@nx/react/plugins/bundle-rollup`
|
|
17
|
+
tasks.push((0, devkit_1.addDependenciesToPackageJson)(host, {}, {
|
|
18
|
+
'@rollup/plugin-url': versions_1.rollupPluginUrlVersion,
|
|
19
|
+
'@svgr/rollup': versions_1.svgrRollupVersion,
|
|
20
|
+
}));
|
|
21
|
+
}
|
|
14
22
|
const { targets } = (0, devkit_1.readProjectConfiguration)(host, options.name);
|
|
15
23
|
const external = ['react', 'react-dom'];
|
|
16
24
|
if (options.style === '@emotion/styled') {
|
|
@@ -46,6 +54,6 @@ async function addRollupBuildTarget(host, options) {
|
|
|
46
54
|
tags: options.parsedTags,
|
|
47
55
|
targets,
|
|
48
56
|
});
|
|
49
|
-
return
|
|
57
|
+
return (0, devkit_1.runTasksInSerial)(...tasks);
|
|
50
58
|
}
|
|
51
59
|
exports.addRollupBuildTarget = addRollupBuildTarget;
|
|
@@ -6,7 +6,15 @@ const add_swc_dependencies_1 = require("@nx/js/src/utils/swc/add-swc-dependencie
|
|
|
6
6
|
const versions_1 = require("../../../utils/versions");
|
|
7
7
|
function installCommonDependencies(host, options) {
|
|
8
8
|
const tasks = [];
|
|
9
|
-
const
|
|
9
|
+
const dependencies = {};
|
|
10
|
+
const devDependencies = {
|
|
11
|
+
'@types/node': versions_1.typesNodeVersion,
|
|
12
|
+
'@types/react': versions_1.typesReactVersion,
|
|
13
|
+
'@types/react-dom': versions_1.typesReactDomVersion,
|
|
14
|
+
};
|
|
15
|
+
if (options.bundler !== 'vite') {
|
|
16
|
+
dependencies['tslib'] = versions_1.tsLibVersion;
|
|
17
|
+
}
|
|
10
18
|
// Vite requires style preprocessors to be installed manually.
|
|
11
19
|
// `@nx/webpack` installs them automatically for now.
|
|
12
20
|
// TODO(jack): Once we clean up webpack we can remove this check
|
|
@@ -20,10 +28,10 @@ function installCommonDependencies(host, options) {
|
|
|
20
28
|
break;
|
|
21
29
|
}
|
|
22
30
|
}
|
|
23
|
-
|
|
24
|
-
react
|
|
25
|
-
|
|
26
|
-
|
|
31
|
+
if (options.unitTestRunner && options.unitTestRunner !== 'none') {
|
|
32
|
+
devDependencies['@testing-library/react'] = versions_1.testingLibraryReactVersion;
|
|
33
|
+
}
|
|
34
|
+
const baseInstallTask = (0, devkit_1.addDependenciesToPackageJson)(host, dependencies, devDependencies);
|
|
27
35
|
tasks.push(baseInstallTask);
|
|
28
36
|
if (options.compiler === 'swc') {
|
|
29
37
|
tasks.push((0, add_swc_dependencies_1.addSwcDependencies)(host));
|
|
@@ -13,6 +13,10 @@ async function normalizeOptions(host, options) {
|
|
|
13
13
|
projectNameAndRootFormat: options.projectNameAndRootFormat,
|
|
14
14
|
callingGenerator: '@nx/react:library',
|
|
15
15
|
});
|
|
16
|
+
const nxJson = (0, devkit_1.readNxJson)(host);
|
|
17
|
+
const addPlugin = process.env.NX_ADD_PLUGINS !== 'false' &&
|
|
18
|
+
nxJson.useInferencePlugins !== false;
|
|
19
|
+
options.addPlugin ??= addPlugin;
|
|
16
20
|
const fileName = options.simpleName
|
|
17
21
|
? projectNames.projectSimpleName
|
|
18
22
|
: projectNames.projectFileName;
|
|
@@ -49,11 +53,12 @@ async function normalizeOptions(host, options) {
|
|
|
49
53
|
if (appProjectConfig.projectType !== 'application') {
|
|
50
54
|
throw new Error(`appProject expected type of "application" but got "${appProjectConfig.projectType}"`);
|
|
51
55
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
56
|
+
normalized.appMain =
|
|
57
|
+
appProjectConfig.targets.build?.options?.main ??
|
|
58
|
+
findMainEntry(host, appProjectConfig.root);
|
|
59
|
+
normalized.appSourceRoot = (0, devkit_1.normalizePath)(appProjectConfig.sourceRoot);
|
|
60
|
+
// TODO(jack): We should use appEntryFile instead of appProject so users can directly set it rather than us inferring it.
|
|
61
|
+
if (!normalized.appMain) {
|
|
57
62
|
throw new Error(`Could not locate project main for ${options.appProject}`);
|
|
58
63
|
}
|
|
59
64
|
}
|
|
@@ -61,3 +66,27 @@ async function normalizeOptions(host, options) {
|
|
|
61
66
|
return normalized;
|
|
62
67
|
}
|
|
63
68
|
exports.normalizeOptions = normalizeOptions;
|
|
69
|
+
function findMainEntry(tree, projectRoot) {
|
|
70
|
+
const mainFiles = [
|
|
71
|
+
// These are the main files we generate with.
|
|
72
|
+
'src/main.ts',
|
|
73
|
+
'src/main.tsx',
|
|
74
|
+
'src/main.js',
|
|
75
|
+
'src/main.jsx',
|
|
76
|
+
// Other options just in case
|
|
77
|
+
'src/index.ts',
|
|
78
|
+
'src/index.tsx',
|
|
79
|
+
'src/index.js',
|
|
80
|
+
'src/index.jsx',
|
|
81
|
+
'main.ts',
|
|
82
|
+
'main.tsx',
|
|
83
|
+
'main.js',
|
|
84
|
+
'main.jsx',
|
|
85
|
+
'index.ts',
|
|
86
|
+
'index.tsx',
|
|
87
|
+
'index.js',
|
|
88
|
+
'index.jsx',
|
|
89
|
+
];
|
|
90
|
+
const mainEntry = mainFiles.find((file) => tree.exists((0, devkit_1.joinPathFragments)(projectRoot, file)));
|
|
91
|
+
return mainEntry ? (0, devkit_1.joinPathFragments)(projectRoot, mainEntry) : undefined;
|
|
92
|
+
}
|
|
@@ -4,7 +4,7 @@ exports.updateAppRoutes = void 0;
|
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
|
5
5
|
const ast_utils_1 = require("../../../utils/ast-utils");
|
|
6
6
|
const ast_utils_2 = require("../../../utils/ast-utils");
|
|
7
|
-
const maybe_js_1 = require("
|
|
7
|
+
const maybe_js_1 = require("../../../utils/maybe-js");
|
|
8
8
|
const versions_1 = require("../../../utils/versions");
|
|
9
9
|
const ensure_typescript_1 = require("@nx/js/src/utils/typescript/ensure-typescript");
|
|
10
10
|
let tsModule;
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.libraryGeneratorInternal = exports.libraryGenerator = void 0;
|
|
4
|
+
const path_1 = require("path");
|
|
4
5
|
const devkit_1 = require("@nx/devkit");
|
|
5
6
|
const artifact_name_and_directory_utils_1 = require("@nx/devkit/src/generators/artifact-name-and-directory-utils");
|
|
7
|
+
const log_show_project_command_1 = require("@nx/devkit/src/utils/log-show-project-command");
|
|
6
8
|
const js_1 = require("@nx/js");
|
|
7
9
|
const versions_1 = require("../../utils/versions");
|
|
10
|
+
const maybe_js_1 = require("../../utils/maybe-js");
|
|
8
11
|
const component_1 = require("../component/component");
|
|
9
12
|
const init_1 = require("../init/init");
|
|
10
13
|
const jest_utils_1 = require("../../utils/jest-utils");
|
|
@@ -16,9 +19,9 @@ const create_files_1 = require("./lib/create-files");
|
|
|
16
19
|
const create_ts_config_1 = require("../../utils/create-ts-config");
|
|
17
20
|
const install_common_dependencies_1 = require("./lib/install-common-dependencies");
|
|
18
21
|
const set_defaults_1 = require("./lib/set-defaults");
|
|
19
|
-
const path_1 = require("path");
|
|
20
22
|
async function libraryGenerator(host, schema) {
|
|
21
23
|
return await libraryGeneratorInternal(host, {
|
|
24
|
+
addPlugin: false,
|
|
22
25
|
projectNameAndRootFormat: 'derived',
|
|
23
26
|
...schema,
|
|
24
27
|
});
|
|
@@ -33,11 +36,14 @@ async function libraryGeneratorInternal(host, schema) {
|
|
|
33
36
|
if (!options.component) {
|
|
34
37
|
options.style = 'none';
|
|
35
38
|
}
|
|
39
|
+
const jsInitTask = await (0, js_1.initGenerator)(host, {
|
|
40
|
+
...schema,
|
|
41
|
+
skipFormat: true,
|
|
42
|
+
});
|
|
43
|
+
tasks.push(jsInitTask);
|
|
36
44
|
const initTask = await (0, init_1.default)(host, {
|
|
37
45
|
...options,
|
|
38
|
-
e2eTestRunner: 'none',
|
|
39
46
|
skipFormat: true,
|
|
40
|
-
skipHelperLibs: options.bundler === 'vite',
|
|
41
47
|
});
|
|
42
48
|
tasks.push(initTask);
|
|
43
49
|
(0, devkit_1.addProjectConfiguration)(host, options.name, {
|
|
@@ -63,6 +69,7 @@ async function libraryGeneratorInternal(host, schema) {
|
|
|
63
69
|
compiler: options.compiler,
|
|
64
70
|
skipFormat: true,
|
|
65
71
|
testEnvironment: 'jsdom',
|
|
72
|
+
addPlugin: options.addPlugin,
|
|
66
73
|
});
|
|
67
74
|
tasks.push(viteTask);
|
|
68
75
|
createOrEditViteConfig(host, {
|
|
@@ -113,10 +120,11 @@ async function libraryGeneratorInternal(host, schema) {
|
|
|
113
120
|
const vitestTask = await vitestGenerator(host, {
|
|
114
121
|
uiFramework: 'react',
|
|
115
122
|
project: options.name,
|
|
116
|
-
coverageProvider: '
|
|
123
|
+
coverageProvider: 'v8',
|
|
117
124
|
inSourceTests: options.inSourceTests,
|
|
118
125
|
skipFormat: true,
|
|
119
126
|
testEnvironment: 'jsdom',
|
|
127
|
+
addPlugin: options.addPlugin,
|
|
120
128
|
});
|
|
121
129
|
tasks.push(vitestTask);
|
|
122
130
|
createOrEditViteConfig(host, {
|
|
@@ -161,7 +169,7 @@ async function libraryGeneratorInternal(host, schema) {
|
|
|
161
169
|
});
|
|
162
170
|
}
|
|
163
171
|
if (!options.skipPackageJson) {
|
|
164
|
-
const installReactTask =
|
|
172
|
+
const installReactTask = (0, install_common_dependencies_1.installCommonDependencies)(host, options);
|
|
165
173
|
tasks.push(installReactTask);
|
|
166
174
|
}
|
|
167
175
|
const routeTask = (0, update_app_routes_1.updateAppRoutes)(host, options);
|
|
@@ -170,12 +178,15 @@ async function libraryGeneratorInternal(host, schema) {
|
|
|
170
178
|
(0, create_ts_config_1.extractTsConfigBase)(host);
|
|
171
179
|
if (!options.skipTsConfig) {
|
|
172
180
|
(0, js_1.addTsConfigPath)(host, options.importPath, [
|
|
173
|
-
(0, devkit_1.joinPathFragments)(options.projectRoot, './src
|
|
181
|
+
(0, maybe_js_1.maybeJs)(options, (0, devkit_1.joinPathFragments)(options.projectRoot, './src/index.ts')),
|
|
174
182
|
]);
|
|
175
183
|
}
|
|
176
184
|
if (!options.skipFormat) {
|
|
177
185
|
await (0, devkit_1.formatFiles)(host);
|
|
178
186
|
}
|
|
187
|
+
tasks.push(() => {
|
|
188
|
+
(0, log_show_project_command_1.logShowProjectCommand)(options.name);
|
|
189
|
+
});
|
|
179
190
|
return (0, devkit_1.runTasksInSerial)(...tasks);
|
|
180
191
|
}
|
|
181
192
|
exports.libraryGeneratorInternal = libraryGeneratorInternal;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"$schema": "
|
|
2
|
+
"$schema": "https://json-schema.org/schema",
|
|
3
3
|
"cli": "nx",
|
|
4
4
|
"$id": "NxReactLibrary",
|
|
5
5
|
"title": "Create a React Library",
|
|
@@ -50,11 +50,11 @@
|
|
|
50
50
|
{ "value": "css", "label": "CSS" },
|
|
51
51
|
{
|
|
52
52
|
"value": "scss",
|
|
53
|
-
"label": "SASS(.scss) [
|
|
53
|
+
"label": "SASS(.scss) [ https://sass-lang.com ]"
|
|
54
54
|
},
|
|
55
55
|
{
|
|
56
56
|
"value": "less",
|
|
57
|
-
"label": "LESS [
|
|
57
|
+
"label": "LESS [ https://lesscss.org ]"
|
|
58
58
|
},
|
|
59
59
|
{
|
|
60
60
|
"value": "styled-components",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export interface Schema {
|
|
2
2
|
name: string;
|
|
3
3
|
/**
|
|
4
|
-
* @deprecated Provide the `directory` option instead and use the `as-provided` format. The project will be determined from the directory provided. It will be removed in Nx
|
|
4
|
+
* @deprecated Provide the `directory` option instead and use the `as-provided` format. The project will be determined from the directory provided. It will be removed in Nx v19.
|
|
5
5
|
*/
|
|
6
6
|
project?: string;
|
|
7
7
|
directory?: string;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"$schema": "
|
|
2
|
+
"$schema": "https://json-schema.org/schema",
|
|
3
3
|
"cli": "nx",
|
|
4
4
|
"$id": "redux",
|
|
5
5
|
"title": "Create Redux state",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"$default": {
|
|
23
23
|
"$source": "projectName"
|
|
24
24
|
},
|
|
25
|
-
"x-deprecated": "Provide the `directory` option instead and use the `as-provided` format. The project will be determined from the directory provided. It will be removed in Nx
|
|
25
|
+
"x-deprecated": "Provide the `directory` option instead and use the `as-provided` format. The project will be determined from the directory provided. It will be removed in Nx v19."
|
|
26
26
|
},
|
|
27
27
|
"directory": {
|
|
28
28
|
"type": "string",
|
|
@@ -3,7 +3,7 @@ import {ModuleFederationConfig} from '@nx/webpack';
|
|
|
3
3
|
const config: ModuleFederationConfig = {
|
|
4
4
|
name: '<%= projectName %>',
|
|
5
5
|
exposes: {
|
|
6
|
-
'./Module': '<%= appProjectRoot %>/src/remote-entry
|
|
6
|
+
'./Module': '<%= appProjectRoot %>/src/remote-entry.<%= js ? 'js' : 'ts' %>',
|
|
7
7
|
},
|
|
8
8
|
};
|
|
9
9
|
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "./tsconfig.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"outDir": "../../dist/out-tsc",
|
|
5
|
+
"types": [
|
|
6
|
+
"node",
|
|
7
|
+
"@nx/react/typings/cssmodule.d.ts",
|
|
8
|
+
"@nx/react/typings/image.d.ts"
|
|
9
|
+
]
|
|
10
|
+
},
|
|
11
|
+
"include": [
|
|
12
|
+
"src/**/*.js",
|
|
13
|
+
"src/**/*.jsx",
|
|
14
|
+
"src/**/*.ts",
|
|
15
|
+
"src/**/*.tsx",
|
|
16
|
+
"webpack.config.ts",
|
|
17
|
+
"webpack.prod.config.ts"
|
|
18
|
+
]
|
|
19
|
+
}
|
package/src/generators/remote/files/module-federation-ts/module-federation.config.ts__tmpl__
CHANGED
|
@@ -2,8 +2,11 @@ import {ModuleFederationConfig} from '@nx/webpack';
|
|
|
2
2
|
|
|
3
3
|
const config: ModuleFederationConfig = {
|
|
4
4
|
name: '<%= projectName %>',
|
|
5
|
+
<% if (dynamic) { %>
|
|
6
|
+
library: { type: 'var', name: '<%= projectName %>'},
|
|
7
|
+
<% } %>
|
|
5
8
|
exposes: {
|
|
6
|
-
'./Module': './src/remote-entry
|
|
9
|
+
'./Module': './src/remote-entry.<%= js ? 'js' : 'ts' %>',
|
|
7
10
|
},
|
|
8
11
|
};
|
|
9
12
|
|