@nx/react 16.8.0-beta.4 → 16.8.0-beta.5
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/babel.js +2 -3
- package/package.json +7 -7
- package/plugins/bundle-rollup.js +9 -3
- package/plugins/component-testing/index.js +57 -37
- package/plugins/jest.js +4 -6
- package/plugins/storybook/index.js +46 -17
- package/plugins/with-react.js +5 -9
- package/src/executors/module-federation-dev-server/module-federation-dev-server.impl.js +101 -103
- package/src/executors/module-federation-ssr-dev-server/module-federation-ssr-dev-server.impl.js +67 -72
- package/src/generators/application/application.js +124 -124
- package/src/generators/application/lib/add-e2e.js +41 -37
- package/src/generators/application/lib/add-jest.js +13 -8
- package/src/generators/application/lib/add-project.js +4 -3
- package/src/generators/application/lib/create-application-files.js +8 -1
- package/src/generators/application/lib/find-free-port.js +1 -2
- package/src/generators/application/lib/normalize-options.js +49 -47
- package/src/generators/application/lib/set-defaults.js +25 -5
- package/src/generators/component/component.js +68 -64
- package/src/generators/component-cypress-spec/component-cypress-spec.js +6 -9
- package/src/generators/component-story/component-story.js +8 -9
- package/src/generators/component-test/component-test.js +15 -18
- package/src/generators/cypress-component-configuration/cypress-component-configuration.js +23 -26
- package/src/generators/cypress-component-configuration/lib/add-files.js +38 -42
- package/src/generators/hook/hook.js +59 -58
- package/src/generators/host/host.js +54 -53
- package/src/generators/host/lib/add-module-federation-files.js +11 -3
- package/src/generators/host/lib/normalize-remote.js +8 -11
- package/src/generators/host/lib/setup-ssr-for-host.js +21 -15
- package/src/generators/host/lib/update-module-federation-e2e-project.js +5 -2
- package/src/generators/init/init.js +30 -20
- package/src/generators/library/lib/add-linting.js +24 -27
- package/src/generators/library/lib/add-rollup-build-target.js +42 -46
- package/src/generators/library/lib/create-files.js +7 -1
- package/src/generators/library/lib/normalize-options.js +53 -50
- package/src/generators/library/lib/set-defaults.js +12 -4
- package/src/generators/library/library.js +122 -111
- package/src/generators/redux/redux.js +25 -16
- package/src/generators/remote/lib/setup-ssr-for-remote.js +25 -23
- package/src/generators/remote/remote.js +44 -39
- package/src/generators/setup-ssr/setup-ssr.js +134 -132
- package/src/generators/setup-tailwind/lib/update-project.js +3 -5
- package/src/generators/setup-tailwind/setup-tailwind.js +23 -26
- package/src/generators/stories/stories.js +79 -88
- package/src/generators/storybook-configuration/configuration.js +40 -47
- package/src/migrations/update-12-0-0/remove-react-redux-types-package.js +2 -5
- package/src/migrations/update-12-0-0/update-emotion-setup.js +50 -55
- package/src/migrations/update-12-0-0/use-react-jsx-in-tsconfig.js +14 -18
- package/src/migrations/update-12-8-0/update-12-8-0.js +3 -6
- package/src/migrations/update-13-0-0/migrate-storybook-to-webpack-5.js +23 -26
- package/src/migrations/update-13-0-0/update-emotion-setup.js +24 -27
- package/src/migrations/update-13-0-0/webpack5-changes-utils.js +30 -34
- package/src/migrations/update-13-10-0/update-13-10-0.js +15 -18
- package/src/migrations/update-14-0-0/add-default-development-configurations.js +26 -31
- package/src/migrations/update-14-0-0/replace-testing-library-react-hook.js +12 -16
- package/src/migrations/update-14-0-0/update-react-dom-render-for-v18.js +13 -17
- package/src/migrations/update-14-1-0/update-external-emotion-jsx-runtime.js +24 -27
- package/src/migrations/update-14-6-0/add-preset-jest-config.js +1 -2
- package/src/migrations/update-15-3-0/install-webpack-rollup-dependencies.js +3 -4
- package/src/migrations/update-15-3-0/update-rollup-executor.js +1 -2
- package/src/migrations/update-15-6-3/webpack-config-setup.js +53 -57
- package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.js +3 -6
- package/src/migrations/update-16-2-0-remove-package/update-16-2-0-remove-package.js +3 -6
- package/src/migrations/update-16-3-0/remove-types-react-router-dom-package.js +3 -6
- package/src/migrations/update-16-7-0/add-babel-core.js +8 -11
- package/src/migrations/update-16-7-0-add-typings/update-16-7-0-add-typings.js +36 -41
- package/src/module-federation/ast-utils.js +1 -1
- package/src/module-federation/load-config.js +1 -1
- package/src/module-federation/utils.js +36 -37
- package/src/module-federation/with-module-federation-ssr.js +24 -25
- package/src/module-federation/with-module-federation.js +23 -22
- package/src/rules/update-module-federation-project.js +9 -2
- package/src/utils/ast-utils.js +12 -15
- package/src/utils/create-ts-config.js +6 -4
- package/src/utils/ct-utils.js +31 -33
- package/src/utils/lint.js +5 -3
- package/src/utils/testing-generators.js +18 -23
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.librarySchematic = exports.libraryGeneratorInternal = exports.libraryGenerator = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
4
|
const devkit_1 = require("@nx/devkit");
|
|
6
5
|
const js_1 = require("@nx/js");
|
|
7
6
|
const versions_1 = require("../../utils/versions");
|
|
@@ -16,121 +15,133 @@ const create_files_1 = require("./lib/create-files");
|
|
|
16
15
|
const create_ts_config_1 = require("../../utils/create-ts-config");
|
|
17
16
|
const install_common_dependencies_1 = require("./lib/install-common-dependencies");
|
|
18
17
|
const set_defaults_1 = require("./lib/set-defaults");
|
|
19
|
-
function libraryGenerator(host, schema) {
|
|
20
|
-
return
|
|
21
|
-
|
|
18
|
+
async function libraryGenerator(host, schema) {
|
|
19
|
+
return await libraryGeneratorInternal(host, {
|
|
20
|
+
projectNameAndRootFormat: 'derived',
|
|
21
|
+
...schema,
|
|
22
22
|
});
|
|
23
23
|
}
|
|
24
24
|
exports.libraryGenerator = libraryGenerator;
|
|
25
|
-
function libraryGeneratorInternal(host, schema) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
25
|
+
async function libraryGeneratorInternal(host, schema) {
|
|
26
|
+
const tasks = [];
|
|
27
|
+
const options = await (0, normalize_options_1.normalizeOptions)(host, schema);
|
|
28
|
+
if (options.publishable === true && !schema.importPath) {
|
|
29
|
+
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)`);
|
|
30
|
+
}
|
|
31
|
+
if (!options.component) {
|
|
32
|
+
options.style = 'none';
|
|
33
|
+
}
|
|
34
|
+
const initTask = await (0, init_1.default)(host, {
|
|
35
|
+
...options,
|
|
36
|
+
e2eTestRunner: 'none',
|
|
37
|
+
skipFormat: true,
|
|
38
|
+
skipHelperLibs: options.bundler === 'vite',
|
|
39
|
+
});
|
|
40
|
+
tasks.push(initTask);
|
|
41
|
+
(0, devkit_1.addProjectConfiguration)(host, options.name, {
|
|
42
|
+
root: options.projectRoot,
|
|
43
|
+
sourceRoot: (0, devkit_1.joinPathFragments)(options.projectRoot, 'src'),
|
|
44
|
+
projectType: 'library',
|
|
45
|
+
tags: options.parsedTags,
|
|
46
|
+
targets: {},
|
|
47
|
+
});
|
|
48
|
+
const lintTask = await (0, add_linting_1.addLinting)(host, options);
|
|
49
|
+
tasks.push(lintTask);
|
|
50
|
+
(0, create_files_1.createFiles)(host, options);
|
|
51
|
+
// Set up build target
|
|
52
|
+
if (options.buildable && options.bundler === 'vite') {
|
|
53
|
+
const { viteConfigurationGenerator } = (0, devkit_1.ensurePackage)('@nx/vite', versions_1.nxVersion);
|
|
54
|
+
const viteTask = await viteConfigurationGenerator(host, {
|
|
55
|
+
uiFramework: 'react',
|
|
56
|
+
project: options.name,
|
|
57
|
+
newProject: true,
|
|
58
|
+
includeLib: true,
|
|
59
|
+
inSourceTests: options.inSourceTests,
|
|
60
|
+
includeVitest: options.unitTestRunner === 'vitest',
|
|
61
|
+
compiler: options.compiler,
|
|
62
|
+
skipFormat: true,
|
|
63
|
+
testEnvironment: 'jsdom',
|
|
43
64
|
});
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
// Set up test target
|
|
68
|
-
if (options.unitTestRunner === 'jest') {
|
|
69
|
-
const { configurationGenerator } = (0, devkit_1.ensurePackage)('@nx/jest', versions_1.nxVersion);
|
|
70
|
-
const jestTask = yield configurationGenerator(host, Object.assign(Object.assign({}, options), { project: options.name, setupFile: 'none', supportTsx: true, skipSerializers: true, compiler: options.compiler, skipFormat: true }));
|
|
71
|
-
tasks.push(jestTask);
|
|
72
|
-
const jestConfigPath = (0, devkit_1.joinPathFragments)(options.projectRoot, options.js ? 'jest.config.js' : 'jest.config.ts');
|
|
73
|
-
if (options.compiler === 'babel' && host.exists(jestConfigPath)) {
|
|
74
|
-
const updatedContent = (0, jest_utils_1.updateJestConfigContent)(host.read(jestConfigPath, 'utf-8'));
|
|
75
|
-
host.write(jestConfigPath, updatedContent);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
else if (options.unitTestRunner === 'vitest' &&
|
|
79
|
-
options.bundler !== 'vite' // tests are already configured if bundler is vite
|
|
80
|
-
) {
|
|
81
|
-
const { vitestGenerator } = (0, devkit_1.ensurePackage)('@nx/vite', versions_1.nxVersion);
|
|
82
|
-
const vitestTask = yield vitestGenerator(host, {
|
|
83
|
-
uiFramework: 'react',
|
|
84
|
-
project: options.name,
|
|
85
|
-
coverageProvider: 'c8',
|
|
86
|
-
inSourceTests: options.inSourceTests,
|
|
87
|
-
skipFormat: true,
|
|
88
|
-
testEnvironment: 'jsdom',
|
|
89
|
-
});
|
|
90
|
-
tasks.push(vitestTask);
|
|
91
|
-
}
|
|
92
|
-
if (options.component) {
|
|
93
|
-
const componentTask = yield (0, component_1.default)(host, {
|
|
94
|
-
name: options.fileName,
|
|
95
|
-
project: options.name,
|
|
96
|
-
flat: true,
|
|
97
|
-
style: options.style,
|
|
98
|
-
skipTests: options.unitTestRunner === 'none' ||
|
|
99
|
-
(options.unitTestRunner === 'vitest' && options.inSourceTests == true),
|
|
100
|
-
export: true,
|
|
101
|
-
routing: options.routing,
|
|
102
|
-
js: options.js,
|
|
103
|
-
pascalCaseFiles: options.pascalCaseFiles,
|
|
104
|
-
inSourceTests: options.inSourceTests,
|
|
105
|
-
skipFormat: true,
|
|
106
|
-
globalCss: options.globalCss,
|
|
107
|
-
});
|
|
108
|
-
tasks.push(componentTask);
|
|
109
|
-
}
|
|
110
|
-
if (options.publishable || options.buildable) {
|
|
111
|
-
(0, devkit_1.updateJson)(host, `${options.projectRoot}/package.json`, (json) => {
|
|
112
|
-
json.name = options.importPath;
|
|
113
|
-
return json;
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
if (!options.skipPackageJson) {
|
|
117
|
-
const installReactTask = yield (0, install_common_dependencies_1.installCommonDependencies)(host, options);
|
|
118
|
-
tasks.push(installReactTask);
|
|
119
|
-
}
|
|
120
|
-
const routeTask = (0, update_app_routes_1.updateAppRoutes)(host, options);
|
|
121
|
-
tasks.push(routeTask);
|
|
122
|
-
(0, set_defaults_1.setDefaults)(host, options);
|
|
123
|
-
(0, create_ts_config_1.extractTsConfigBase)(host);
|
|
124
|
-
if (!options.skipTsConfig) {
|
|
125
|
-
(0, js_1.addTsConfigPath)(host, options.importPath, [
|
|
126
|
-
(0, devkit_1.joinPathFragments)(options.projectRoot, './src', 'index.' + (options.js ? 'js' : 'ts')),
|
|
127
|
-
]);
|
|
128
|
-
}
|
|
129
|
-
if (!options.skipFormat) {
|
|
130
|
-
yield (0, devkit_1.formatFiles)(host);
|
|
65
|
+
tasks.push(viteTask);
|
|
66
|
+
}
|
|
67
|
+
else if (options.buildable && options.bundler === 'rollup') {
|
|
68
|
+
const rollupTask = await (0, add_rollup_build_target_1.addRollupBuildTarget)(host, options);
|
|
69
|
+
tasks.push(rollupTask);
|
|
70
|
+
}
|
|
71
|
+
// Set up test target
|
|
72
|
+
if (options.unitTestRunner === 'jest') {
|
|
73
|
+
const { configurationGenerator } = (0, devkit_1.ensurePackage)('@nx/jest', versions_1.nxVersion);
|
|
74
|
+
const jestTask = await configurationGenerator(host, {
|
|
75
|
+
...options,
|
|
76
|
+
project: options.name,
|
|
77
|
+
setupFile: 'none',
|
|
78
|
+
supportTsx: true,
|
|
79
|
+
skipSerializers: true,
|
|
80
|
+
compiler: options.compiler,
|
|
81
|
+
skipFormat: true,
|
|
82
|
+
});
|
|
83
|
+
tasks.push(jestTask);
|
|
84
|
+
const jestConfigPath = (0, devkit_1.joinPathFragments)(options.projectRoot, options.js ? 'jest.config.js' : 'jest.config.ts');
|
|
85
|
+
if (options.compiler === 'babel' && host.exists(jestConfigPath)) {
|
|
86
|
+
const updatedContent = (0, jest_utils_1.updateJestConfigContent)(host.read(jestConfigPath, 'utf-8'));
|
|
87
|
+
host.write(jestConfigPath, updatedContent);
|
|
131
88
|
}
|
|
132
|
-
|
|
133
|
-
|
|
89
|
+
}
|
|
90
|
+
else if (options.unitTestRunner === 'vitest' &&
|
|
91
|
+
options.bundler !== 'vite' // tests are already configured if bundler is vite
|
|
92
|
+
) {
|
|
93
|
+
const { vitestGenerator } = (0, devkit_1.ensurePackage)('@nx/vite', versions_1.nxVersion);
|
|
94
|
+
const vitestTask = await vitestGenerator(host, {
|
|
95
|
+
uiFramework: 'react',
|
|
96
|
+
project: options.name,
|
|
97
|
+
coverageProvider: 'c8',
|
|
98
|
+
inSourceTests: options.inSourceTests,
|
|
99
|
+
skipFormat: true,
|
|
100
|
+
testEnvironment: 'jsdom',
|
|
101
|
+
});
|
|
102
|
+
tasks.push(vitestTask);
|
|
103
|
+
}
|
|
104
|
+
if (options.component) {
|
|
105
|
+
const componentTask = await (0, component_1.default)(host, {
|
|
106
|
+
name: options.fileName,
|
|
107
|
+
project: options.name,
|
|
108
|
+
flat: true,
|
|
109
|
+
style: options.style,
|
|
110
|
+
skipTests: options.unitTestRunner === 'none' ||
|
|
111
|
+
(options.unitTestRunner === 'vitest' && options.inSourceTests == true),
|
|
112
|
+
export: true,
|
|
113
|
+
routing: options.routing,
|
|
114
|
+
js: options.js,
|
|
115
|
+
pascalCaseFiles: options.pascalCaseFiles,
|
|
116
|
+
inSourceTests: options.inSourceTests,
|
|
117
|
+
skipFormat: true,
|
|
118
|
+
globalCss: options.globalCss,
|
|
119
|
+
});
|
|
120
|
+
tasks.push(componentTask);
|
|
121
|
+
}
|
|
122
|
+
if (options.publishable || options.buildable) {
|
|
123
|
+
(0, devkit_1.updateJson)(host, `${options.projectRoot}/package.json`, (json) => {
|
|
124
|
+
json.name = options.importPath;
|
|
125
|
+
return json;
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
if (!options.skipPackageJson) {
|
|
129
|
+
const installReactTask = await (0, install_common_dependencies_1.installCommonDependencies)(host, options);
|
|
130
|
+
tasks.push(installReactTask);
|
|
131
|
+
}
|
|
132
|
+
const routeTask = (0, update_app_routes_1.updateAppRoutes)(host, options);
|
|
133
|
+
tasks.push(routeTask);
|
|
134
|
+
(0, set_defaults_1.setDefaults)(host, options);
|
|
135
|
+
(0, create_ts_config_1.extractTsConfigBase)(host);
|
|
136
|
+
if (!options.skipTsConfig) {
|
|
137
|
+
(0, js_1.addTsConfigPath)(host, options.importPath, [
|
|
138
|
+
(0, devkit_1.joinPathFragments)(options.projectRoot, './src', 'index.' + (options.js ? 'js' : 'ts')),
|
|
139
|
+
]);
|
|
140
|
+
}
|
|
141
|
+
if (!options.skipFormat) {
|
|
142
|
+
await (0, devkit_1.formatFiles)(host);
|
|
143
|
+
}
|
|
144
|
+
return (0, devkit_1.runTasksInSerial)(...tasks);
|
|
134
145
|
}
|
|
135
146
|
exports.libraryGeneratorInternal = libraryGeneratorInternal;
|
|
136
147
|
exports.default = libraryGenerator;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.reduxSchematic = exports.reduxGenerator = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
4
|
const path = require("path");
|
|
6
5
|
const ast_utils_1 = require("../../utils/ast-utils");
|
|
7
6
|
const versions_1 = require("../../utils/versions");
|
|
@@ -9,21 +8,22 @@ const devkit_1 = require("@nx/devkit");
|
|
|
9
8
|
const js_1 = require("@nx/js");
|
|
10
9
|
const ensure_typescript_1 = require("@nx/js/src/utils/typescript/ensure-typescript");
|
|
11
10
|
let tsModule;
|
|
12
|
-
function reduxGenerator(host, schema) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
return installTask;
|
|
22
|
-
});
|
|
11
|
+
async function reduxGenerator(host, schema) {
|
|
12
|
+
const options = normalizeOptions(host, schema);
|
|
13
|
+
generateReduxFiles(host, options);
|
|
14
|
+
addExportsToBarrel(host, options);
|
|
15
|
+
const installTask = addReduxPackageDependencies(host);
|
|
16
|
+
addStoreConfiguration(host, options);
|
|
17
|
+
updateReducerConfiguration(host, options);
|
|
18
|
+
await (0, devkit_1.formatFiles)(host);
|
|
19
|
+
return installTask;
|
|
23
20
|
}
|
|
24
21
|
exports.reduxGenerator = reduxGenerator;
|
|
25
22
|
function generateReduxFiles(host, options) {
|
|
26
|
-
(0, devkit_1.generateFiles)(host, (0, devkit_1.joinPathFragments)(__dirname, './files'), options.filesPath,
|
|
23
|
+
(0, devkit_1.generateFiles)(host, (0, devkit_1.joinPathFragments)(__dirname, './files'), options.filesPath, {
|
|
24
|
+
...options,
|
|
25
|
+
tmpl: '',
|
|
26
|
+
});
|
|
27
27
|
if (options.js) {
|
|
28
28
|
(0, devkit_1.toJS)(host);
|
|
29
29
|
}
|
|
@@ -77,7 +77,6 @@ function updateReducerConfiguration(host, options) {
|
|
|
77
77
|
host.write(options.appMainFilePath, changes);
|
|
78
78
|
}
|
|
79
79
|
function normalizeOptions(host, options) {
|
|
80
|
-
var _a;
|
|
81
80
|
let appProjectSourcePath;
|
|
82
81
|
let appMainFilePath;
|
|
83
82
|
const extraNames = (0, devkit_1.names)(options.name);
|
|
@@ -109,8 +108,18 @@ function normalizeOptions(host, options) {
|
|
|
109
108
|
throw new Error(`Could not find ${appMainFilePath} during store configuration`);
|
|
110
109
|
}
|
|
111
110
|
}
|
|
112
|
-
return
|
|
113
|
-
|
|
111
|
+
return {
|
|
112
|
+
...options,
|
|
113
|
+
...extraNames,
|
|
114
|
+
constantName: (0, devkit_1.names)(options.name).constantName.toUpperCase(),
|
|
115
|
+
directory: (0, devkit_1.names)(options.directory ?? '').fileName,
|
|
116
|
+
projectType,
|
|
117
|
+
projectSourcePath: sourceRoot,
|
|
118
|
+
projectModulePath: modulePath,
|
|
119
|
+
appProjectSourcePath,
|
|
120
|
+
appMainFilePath,
|
|
121
|
+
filesPath: (0, devkit_1.joinPathFragments)(sourceRoot, projectType === 'application' ? 'app' : 'lib'),
|
|
122
|
+
};
|
|
114
123
|
}
|
|
115
124
|
exports.default = reduxGenerator;
|
|
116
125
|
exports.reduxSchematic = (0, devkit_1.convertNxGenerator)(reduxGenerator);
|
|
@@ -1,31 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.setupSsrForRemote = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
4
|
const devkit_1 = require("@nx/devkit");
|
|
6
5
|
const versions_1 = require("../../../utils/versions");
|
|
7
|
-
function setupSsrForRemote(tree, options, appName) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
project.targets
|
|
16
|
-
dependsOn: ['build', 'server'],
|
|
17
|
-
executor: 'nx:run-commands',
|
|
18
|
-
defaultConfiguration: 'development',
|
|
19
|
-
options: {
|
|
20
|
-
command: `PORT=${(_c = options.devServerPort) !== null && _c !== void 0 ? _c : 4200} node ${(0, devkit_1.joinPathFragments)(originalOutputPath, 'server', 'main.js')}`,
|
|
21
|
-
},
|
|
22
|
-
};
|
|
23
|
-
(0, devkit_1.updateProjectConfiguration)(tree, appName, project);
|
|
24
|
-
const installTask = (0, devkit_1.addDependenciesToPackageJson)(tree, {
|
|
25
|
-
'@module-federation/node': versions_1.moduleFederationNodeVersion,
|
|
26
|
-
}, {});
|
|
27
|
-
tasks.push(installTask);
|
|
28
|
-
return (0, devkit_1.runTasksInSerial)(...tasks);
|
|
6
|
+
async function setupSsrForRemote(tree, options, appName) {
|
|
7
|
+
const tasks = [];
|
|
8
|
+
const project = (0, devkit_1.readProjectConfiguration)(tree, appName);
|
|
9
|
+
(0, devkit_1.generateFiles)(tree, (0, devkit_1.joinPathFragments)(__dirname, '../files/module-federation-ssr'), project.root, {
|
|
10
|
+
...options,
|
|
11
|
+
appName,
|
|
12
|
+
tmpl: '',
|
|
13
|
+
browserBuildOutputPath: project.targets.build.options.outputPath,
|
|
14
|
+
serverBuildOutputPath: project.targets.server.options.outputPath,
|
|
29
15
|
});
|
|
16
|
+
// For hosts to use when running remotes in static mode.
|
|
17
|
+
const originalOutputPath = project.targets.build?.options?.outputPath;
|
|
18
|
+
project.targets['serve-static'] = {
|
|
19
|
+
dependsOn: ['build', 'server'],
|
|
20
|
+
executor: 'nx:run-commands',
|
|
21
|
+
defaultConfiguration: 'development',
|
|
22
|
+
options: {
|
|
23
|
+
command: `PORT=${options.devServerPort ?? 4200} node ${(0, devkit_1.joinPathFragments)(originalOutputPath, 'server', 'main.js')}`,
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
(0, devkit_1.updateProjectConfiguration)(tree, appName, project);
|
|
27
|
+
const installTask = (0, devkit_1.addDependenciesToPackageJson)(tree, {
|
|
28
|
+
'@module-federation/node': versions_1.moduleFederationNodeVersion,
|
|
29
|
+
}, {});
|
|
30
|
+
tasks.push(installTask);
|
|
31
|
+
return (0, devkit_1.runTasksInSerial)(...tasks);
|
|
30
32
|
}
|
|
31
33
|
exports.setupSsrForRemote = setupSsrForRemote;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.remoteGeneratorInternal = exports.remoteGenerator = exports.addModuleFederationFiles = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
4
|
const path_1 = require("path");
|
|
6
5
|
const devkit_1 = require("@nx/devkit");
|
|
7
6
|
const normalize_options_1 = require("../application/lib/normalize-options");
|
|
@@ -11,51 +10,57 @@ const update_module_federation_project_1 = require("../../rules/update-module-fe
|
|
|
11
10
|
const setup_ssr_1 = require("../setup-ssr/setup-ssr");
|
|
12
11
|
const setup_ssr_for_remote_1 = require("./lib/setup-ssr-for-remote");
|
|
13
12
|
function addModuleFederationFiles(host, options) {
|
|
14
|
-
const templateVariables =
|
|
13
|
+
const templateVariables = {
|
|
14
|
+
...(0, devkit_1.names)(options.name),
|
|
15
|
+
...options,
|
|
16
|
+
tmpl: '',
|
|
17
|
+
};
|
|
15
18
|
(0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, `./files/module-federation`), options.appProjectRoot, templateVariables);
|
|
16
19
|
}
|
|
17
20
|
exports.addModuleFederationFiles = addModuleFederationFiles;
|
|
18
|
-
function remoteGenerator(host, schema) {
|
|
19
|
-
return
|
|
20
|
-
|
|
21
|
+
async function remoteGenerator(host, schema) {
|
|
22
|
+
return await remoteGeneratorInternal(host, {
|
|
23
|
+
projectNameAndRootFormat: 'derived',
|
|
24
|
+
...schema,
|
|
21
25
|
});
|
|
22
26
|
}
|
|
23
27
|
exports.remoteGenerator = remoteGenerator;
|
|
24
|
-
function remoteGeneratorInternal(host, schema) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
if (schema.host) {
|
|
33
|
-
(0, update_host_with_remote_1.updateHostWithRemote)(host, schema.host, options.projectName);
|
|
34
|
-
}
|
|
35
|
-
// Module federation requires bootstrap code to be dynamically imported.
|
|
36
|
-
// Renaming original entry file so we can use `import(./bootstrap)` in
|
|
37
|
-
// new entry file.
|
|
38
|
-
host.rename((0, path_1.join)(options.appProjectRoot, 'src/main.tsx'), (0, path_1.join)(options.appProjectRoot, 'src/bootstrap.tsx'));
|
|
39
|
-
addModuleFederationFiles(host, options);
|
|
40
|
-
(0, update_module_federation_project_1.updateModuleFederationProject)(host, options);
|
|
41
|
-
if (options.ssr) {
|
|
42
|
-
const setupSsrTask = yield (0, setup_ssr_1.default)(host, {
|
|
43
|
-
project: options.projectName,
|
|
44
|
-
serverPort: options.devServerPort,
|
|
45
|
-
skipFormat: true,
|
|
46
|
-
});
|
|
47
|
-
tasks.push(setupSsrTask);
|
|
48
|
-
const setupSsrForRemoteTask = yield (0, setup_ssr_for_remote_1.setupSsrForRemote)(host, options, options.projectName);
|
|
49
|
-
tasks.push(setupSsrForRemoteTask);
|
|
50
|
-
const projectConfig = (0, devkit_1.readProjectConfiguration)(host, options.projectName);
|
|
51
|
-
projectConfig.targets.server.options.webpackConfig = (0, devkit_1.joinPathFragments)(projectConfig.root, 'webpack.server.config.js');
|
|
52
|
-
(0, devkit_1.updateProjectConfiguration)(host, options.projectName, projectConfig);
|
|
53
|
-
}
|
|
54
|
-
if (!options.skipFormat) {
|
|
55
|
-
yield (0, devkit_1.formatFiles)(host);
|
|
56
|
-
}
|
|
57
|
-
return (0, devkit_1.runTasksInSerial)(...tasks);
|
|
28
|
+
async function remoteGeneratorInternal(host, schema) {
|
|
29
|
+
const tasks = [];
|
|
30
|
+
const options = await (0, normalize_options_1.normalizeOptions)(host, schema, '@nx/react:remote');
|
|
31
|
+
const initAppTask = await (0, application_1.default)(host, {
|
|
32
|
+
...options,
|
|
33
|
+
// Only webpack works with module federation for now.
|
|
34
|
+
bundler: 'webpack',
|
|
35
|
+
skipFormat: true,
|
|
58
36
|
});
|
|
37
|
+
tasks.push(initAppTask);
|
|
38
|
+
if (schema.host) {
|
|
39
|
+
(0, update_host_with_remote_1.updateHostWithRemote)(host, schema.host, options.projectName);
|
|
40
|
+
}
|
|
41
|
+
// Module federation requires bootstrap code to be dynamically imported.
|
|
42
|
+
// Renaming original entry file so we can use `import(./bootstrap)` in
|
|
43
|
+
// new entry file.
|
|
44
|
+
host.rename((0, path_1.join)(options.appProjectRoot, 'src/main.tsx'), (0, path_1.join)(options.appProjectRoot, 'src/bootstrap.tsx'));
|
|
45
|
+
addModuleFederationFiles(host, options);
|
|
46
|
+
(0, update_module_federation_project_1.updateModuleFederationProject)(host, options);
|
|
47
|
+
if (options.ssr) {
|
|
48
|
+
const setupSsrTask = await (0, setup_ssr_1.default)(host, {
|
|
49
|
+
project: options.projectName,
|
|
50
|
+
serverPort: options.devServerPort,
|
|
51
|
+
skipFormat: true,
|
|
52
|
+
});
|
|
53
|
+
tasks.push(setupSsrTask);
|
|
54
|
+
const setupSsrForRemoteTask = await (0, setup_ssr_for_remote_1.setupSsrForRemote)(host, options, options.projectName);
|
|
55
|
+
tasks.push(setupSsrForRemoteTask);
|
|
56
|
+
const projectConfig = (0, devkit_1.readProjectConfiguration)(host, options.projectName);
|
|
57
|
+
projectConfig.targets.server.options.webpackConfig = (0, devkit_1.joinPathFragments)(projectConfig.root, 'webpack.server.config.js');
|
|
58
|
+
(0, devkit_1.updateProjectConfiguration)(host, options.projectName, projectConfig);
|
|
59
|
+
}
|
|
60
|
+
if (!options.skipFormat) {
|
|
61
|
+
await (0, devkit_1.formatFiles)(host);
|
|
62
|
+
}
|
|
63
|
+
return (0, devkit_1.runTasksInSerial)(...tasks);
|
|
59
64
|
}
|
|
60
65
|
exports.remoteGeneratorInternal = remoteGeneratorInternal;
|
|
61
66
|
exports.default = remoteGenerator;
|