@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.getModuleFederationConfig = exports.getFunctionDeterminateRemoteUrl = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
4
|
const module_federation_1 = require("@nx/devkit/src/utils/module-federation");
|
|
6
5
|
const devkit_1 = require("@nx/devkit");
|
|
7
6
|
const project_graph_1 = require("nx/src/project-graph/project-graph");
|
|
@@ -9,50 +8,50 @@ function getFunctionDeterminateRemoteUrl(isServer = false) {
|
|
|
9
8
|
const target = isServer ? 'serve-server' : 'serve';
|
|
10
9
|
const remoteEntry = isServer ? 'server/remoteEntry.js' : 'remoteEntry.js';
|
|
11
10
|
return function (remote) {
|
|
12
|
-
var _a, _b, _c, _d, _e;
|
|
13
11
|
const remoteConfiguration = (0, project_graph_1.readCachedProjectConfiguration)(remote);
|
|
14
|
-
const serveTarget =
|
|
12
|
+
const serveTarget = remoteConfiguration?.targets?.[target];
|
|
15
13
|
if (!serveTarget) {
|
|
16
14
|
throw new Error(`Cannot automatically determine URL of remote (${remote}). Looked for property "host" in the project's "${serveTarget}" target.\n
|
|
17
15
|
You can also use the tuple syntax in your webpack config to configure your remotes. e.g. \`remotes: [['remote1', 'http://localhost:4201']]\``);
|
|
18
16
|
}
|
|
19
|
-
const host =
|
|
20
|
-
|
|
17
|
+
const host = serveTarget.options?.host ??
|
|
18
|
+
`http${serveTarget.options.ssl ? 's' : ''}://localhost`;
|
|
19
|
+
const port = serveTarget.options?.port ?? 4201;
|
|
21
20
|
return `${host.endsWith('/') ? host.slice(0, -1) : host}:${port}/${remoteEntry}`;
|
|
22
21
|
};
|
|
23
22
|
}
|
|
24
23
|
exports.getFunctionDeterminateRemoteUrl = getFunctionDeterminateRemoteUrl;
|
|
25
|
-
function getModuleFederationConfig(mfConfig, options = { isServer: false }) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}
|
|
24
|
+
async function getModuleFederationConfig(mfConfig, options = { isServer: false }) {
|
|
25
|
+
let projectGraph;
|
|
26
|
+
try {
|
|
27
|
+
projectGraph = (0, devkit_1.readCachedProjectGraph)();
|
|
28
|
+
}
|
|
29
|
+
catch (e) {
|
|
30
|
+
projectGraph = await (0, devkit_1.createProjectGraphAsync)();
|
|
31
|
+
}
|
|
32
|
+
const project = projectGraph.nodes[mfConfig.name]?.data;
|
|
33
|
+
if (!project) {
|
|
34
|
+
throw Error(`Cannot find project "${mfConfig.name}". Check that the name is correct in module-federation.config.js`);
|
|
35
|
+
}
|
|
36
|
+
const dependencies = (0, module_federation_1.getDependentPackagesForProject)(projectGraph, mfConfig.name);
|
|
37
|
+
if (mfConfig.shared) {
|
|
38
|
+
dependencies.workspaceLibraries = dependencies.workspaceLibraries.filter((lib) => mfConfig.shared(lib.importKey, {}) !== false);
|
|
39
|
+
dependencies.npmPackages = dependencies.npmPackages.filter((pkg) => mfConfig.shared(pkg, {}) !== false);
|
|
40
|
+
}
|
|
41
|
+
const sharedLibraries = (0, module_federation_1.shareWorkspaceLibraries)(dependencies.workspaceLibraries);
|
|
42
|
+
const npmPackages = (0, module_federation_1.sharePackages)(dependencies.npmPackages);
|
|
43
|
+
const sharedDependencies = {
|
|
44
|
+
...sharedLibraries.getLibraries(),
|
|
45
|
+
...npmPackages,
|
|
46
|
+
};
|
|
47
|
+
(0, module_federation_1.applySharedFunction)(sharedDependencies, mfConfig.shared);
|
|
48
|
+
(0, module_federation_1.applyAdditionalShared)(sharedDependencies, mfConfig.additionalShared, projectGraph);
|
|
49
|
+
const mapRemotesFunction = options.isServer ? module_federation_1.mapRemotesForSSR : module_federation_1.mapRemotes;
|
|
50
|
+
const determineRemoteUrlFn = options.determineRemoteUrl ||
|
|
51
|
+
getFunctionDeterminateRemoteUrl(options.isServer);
|
|
52
|
+
const mappedRemotes = !mfConfig.remotes || mfConfig.remotes.length === 0
|
|
53
|
+
? {}
|
|
54
|
+
: mapRemotesFunction(mfConfig.remotes, 'js', determineRemoteUrlFn);
|
|
55
|
+
return { sharedLibraries, sharedDependencies, mappedRemotes };
|
|
57
56
|
}
|
|
58
57
|
exports.getModuleFederationConfig = getModuleFederationConfig;
|
|
@@ -1,32 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.withModuleFederationForSSR = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
4
|
const utils_1 = require("./utils");
|
|
6
|
-
function withModuleFederationForSSR(options) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
isServer: true,
|
|
10
|
-
});
|
|
11
|
-
return (config) => {
|
|
12
|
-
config.target = false;
|
|
13
|
-
config.output.uniqueName = options.name;
|
|
14
|
-
config.optimization = {
|
|
15
|
-
runtimeChunk: false,
|
|
16
|
-
};
|
|
17
|
-
config.plugins.push(new (require('@module-federation/node').UniversalFederationPlugin)({
|
|
18
|
-
name: options.name,
|
|
19
|
-
filename: 'remoteEntry.js',
|
|
20
|
-
exposes: options.exposes,
|
|
21
|
-
remotes: mappedRemotes,
|
|
22
|
-
shared: Object.assign({}, sharedDependencies),
|
|
23
|
-
library: {
|
|
24
|
-
type: 'commonjs-module',
|
|
25
|
-
},
|
|
26
|
-
isServer: true,
|
|
27
|
-
}, {}), sharedLibraries.getReplacementPlugin());
|
|
28
|
-
return config;
|
|
29
|
-
};
|
|
5
|
+
async function withModuleFederationForSSR(options) {
|
|
6
|
+
const { sharedLibraries, sharedDependencies, mappedRemotes } = await (0, utils_1.getModuleFederationConfig)(options, {
|
|
7
|
+
isServer: true,
|
|
30
8
|
});
|
|
9
|
+
return (config) => {
|
|
10
|
+
config.target = false;
|
|
11
|
+
config.output.uniqueName = options.name;
|
|
12
|
+
config.optimization = {
|
|
13
|
+
runtimeChunk: false,
|
|
14
|
+
};
|
|
15
|
+
config.plugins.push(new (require('@module-federation/node').UniversalFederationPlugin)({
|
|
16
|
+
name: options.name,
|
|
17
|
+
filename: 'remoteEntry.js',
|
|
18
|
+
exposes: options.exposes,
|
|
19
|
+
remotes: mappedRemotes,
|
|
20
|
+
shared: {
|
|
21
|
+
...sharedDependencies,
|
|
22
|
+
},
|
|
23
|
+
library: {
|
|
24
|
+
type: 'commonjs-module',
|
|
25
|
+
},
|
|
26
|
+
isServer: true,
|
|
27
|
+
}, {}), sharedLibraries.getReplacementPlugin());
|
|
28
|
+
return config;
|
|
29
|
+
};
|
|
31
30
|
}
|
|
32
31
|
exports.withModuleFederationForSSR = withModuleFederationForSSR;
|
|
@@ -1,34 +1,35 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.withModuleFederation = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
4
|
const utils_1 = require("./utils");
|
|
6
5
|
const ModuleFederationPlugin = require("webpack/lib/container/ModuleFederationPlugin");
|
|
7
6
|
/**
|
|
8
7
|
* @param {ModuleFederationConfig} options
|
|
9
8
|
* @return {Promise<AsyncNxWebpackPlugin>}
|
|
10
9
|
*/
|
|
11
|
-
function withModuleFederation(options) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
config.optimization = {
|
|
19
|
-
runtimeChunk: false,
|
|
20
|
-
};
|
|
21
|
-
config.experiments = Object.assign(Object.assign({}, config.experiments), { outputModule: true });
|
|
22
|
-
config.plugins.push(new ModuleFederationPlugin({
|
|
23
|
-
name: options.name,
|
|
24
|
-
library: (_a = options.library) !== null && _a !== void 0 ? _a : { type: 'module' },
|
|
25
|
-
filename: 'remoteEntry.js',
|
|
26
|
-
exposes: options.exposes,
|
|
27
|
-
remotes: mappedRemotes,
|
|
28
|
-
shared: Object.assign({}, sharedDependencies),
|
|
29
|
-
}), sharedLibraries.getReplacementPlugin());
|
|
30
|
-
return config;
|
|
10
|
+
async function withModuleFederation(options) {
|
|
11
|
+
const { sharedDependencies, sharedLibraries, mappedRemotes } = await (0, utils_1.getModuleFederationConfig)(options);
|
|
12
|
+
return (config, ctx) => {
|
|
13
|
+
config.output.uniqueName = options.name;
|
|
14
|
+
config.output.publicPath = 'auto';
|
|
15
|
+
config.optimization = {
|
|
16
|
+
runtimeChunk: false,
|
|
31
17
|
};
|
|
32
|
-
|
|
18
|
+
config.experiments = {
|
|
19
|
+
...config.experiments,
|
|
20
|
+
outputModule: true,
|
|
21
|
+
};
|
|
22
|
+
config.plugins.push(new ModuleFederationPlugin({
|
|
23
|
+
name: options.name,
|
|
24
|
+
library: options.library ?? { type: 'module' },
|
|
25
|
+
filename: 'remoteEntry.js',
|
|
26
|
+
exposes: options.exposes,
|
|
27
|
+
remotes: mappedRemotes,
|
|
28
|
+
shared: {
|
|
29
|
+
...sharedDependencies,
|
|
30
|
+
},
|
|
31
|
+
}), sharedLibraries.getReplacementPlugin());
|
|
32
|
+
return config;
|
|
33
|
+
};
|
|
33
34
|
}
|
|
34
35
|
exports.withModuleFederation = withModuleFederation;
|
|
@@ -5,8 +5,15 @@ const devkit_1 = require("@nx/devkit");
|
|
|
5
5
|
const versions_1 = require("../utils/versions");
|
|
6
6
|
function updateModuleFederationProject(host, options) {
|
|
7
7
|
const projectConfig = (0, devkit_1.readProjectConfiguration)(host, options.projectName);
|
|
8
|
-
projectConfig.targets.build.options =
|
|
9
|
-
|
|
8
|
+
projectConfig.targets.build.options = {
|
|
9
|
+
...projectConfig.targets.build.options,
|
|
10
|
+
main: `${options.appProjectRoot}/src/main.ts`,
|
|
11
|
+
webpackConfig: `${options.appProjectRoot}/webpack.config.js`,
|
|
12
|
+
};
|
|
13
|
+
projectConfig.targets.build.configurations.production = {
|
|
14
|
+
...projectConfig.targets.build.configurations.production,
|
|
15
|
+
webpackConfig: `${options.appProjectRoot}/webpack.config.prod.js`,
|
|
16
|
+
};
|
|
10
17
|
projectConfig.targets.serve.executor =
|
|
11
18
|
'@nx/react:module-federation-dev-server';
|
|
12
19
|
projectConfig.targets.serve.options.port = options.devServerPort;
|
package/src/utils/ast-utils.js
CHANGED
|
@@ -107,7 +107,7 @@ function findExportDeclarationsForJsx(source) {
|
|
|
107
107
|
...(0, js_1.findNodes)(node, tsModule.SyntaxKind.ExportSpecifier),
|
|
108
108
|
];
|
|
109
109
|
});
|
|
110
|
-
const componentNames = componentNamesNodes
|
|
110
|
+
const componentNames = componentNamesNodes?.map((node) => node.getText());
|
|
111
111
|
const all = [...variables, ...variableStatements, ...fns, ...cls];
|
|
112
112
|
let foundExport;
|
|
113
113
|
let foundJSX;
|
|
@@ -116,27 +116,25 @@ function findExportDeclarationsForJsx(source) {
|
|
|
116
116
|
tsModule.SyntaxKind.JsxSelfClosingElement,
|
|
117
117
|
tsModule.SyntaxKind.JsxOpeningElement,
|
|
118
118
|
]);
|
|
119
|
-
return foundJSX
|
|
119
|
+
return foundJSX?.length;
|
|
120
120
|
});
|
|
121
121
|
const exported = nodesContainingJSX.filter((x) => {
|
|
122
|
-
var _a, _b, _c;
|
|
123
122
|
foundExport = (0, js_1.findNodes)(x, tsModule.SyntaxKind.ExportKeyword);
|
|
124
123
|
if (x.kind === tsModule.SyntaxKind.VariableStatement) {
|
|
125
|
-
const nameNode = (
|
|
126
|
-
return (
|
|
127
|
-
|
|
128
|
-
|
|
124
|
+
const nameNode = (0, js_1.findNodes)(x, tsModule.SyntaxKind.VariableDeclaration)?.[0];
|
|
125
|
+
return (nameNode?.name?.kind === tsModule.SyntaxKind.Identifier ||
|
|
126
|
+
foundExport?.length ||
|
|
127
|
+
componentNames?.includes(nameNode?.name?.getText()));
|
|
129
128
|
}
|
|
130
129
|
else {
|
|
131
130
|
return ((x.name.kind === tsModule.SyntaxKind.Identifier &&
|
|
132
|
-
|
|
133
|
-
|
|
131
|
+
foundExport?.length) ||
|
|
132
|
+
componentNames?.includes(x.name.getText()));
|
|
134
133
|
}
|
|
135
134
|
});
|
|
136
135
|
const exportedDeclarations = exported.map((x) => {
|
|
137
|
-
var _a;
|
|
138
136
|
if (x.kind === tsModule.SyntaxKind.VariableStatement) {
|
|
139
|
-
const nameNode = (
|
|
137
|
+
const nameNode = (0, js_1.findNodes)(x, tsModule.SyntaxKind.VariableDeclaration)?.[0];
|
|
140
138
|
return nameNode;
|
|
141
139
|
}
|
|
142
140
|
return x;
|
|
@@ -473,14 +471,13 @@ function getComponentNode(sourceFile) {
|
|
|
473
471
|
}
|
|
474
472
|
exports.getComponentNode = getComponentNode;
|
|
475
473
|
function getComponentPropsInterface(sourceFile, cmpDeclaration) {
|
|
476
|
-
var _a, _b, _c, _d;
|
|
477
474
|
if (!tsModule) {
|
|
478
475
|
tsModule = (0, ensure_typescript_1.ensureTypescript)();
|
|
479
476
|
}
|
|
480
477
|
let propsTypeName = null;
|
|
481
478
|
if (tsModule.isFunctionDeclaration(cmpDeclaration)) {
|
|
482
479
|
const propsParam = cmpDeclaration.parameters.find((x) => tsModule.isParameter(x) && x.name.text === 'props');
|
|
483
|
-
if (
|
|
480
|
+
if (propsParam?.type?.['typeName']) {
|
|
484
481
|
propsTypeName = propsParam.type.typeName.text;
|
|
485
482
|
}
|
|
486
483
|
}
|
|
@@ -489,7 +486,7 @@ function getComponentPropsInterface(sourceFile, cmpDeclaration) {
|
|
|
489
486
|
const arrowFn = cmpDeclaration
|
|
490
487
|
.initializer;
|
|
491
488
|
const propsParam = arrowFn.parameters.find((x) => tsModule.isParameter(x) && x.name.text === 'props');
|
|
492
|
-
if (
|
|
489
|
+
if (propsParam?.type?.['typeName']) {
|
|
493
490
|
propsTypeName = propsParam.type.typeName.text;
|
|
494
491
|
}
|
|
495
492
|
}
|
|
@@ -505,7 +502,7 @@ function getComponentPropsInterface(sourceFile, cmpDeclaration) {
|
|
|
505
502
|
x.expression.name.text;
|
|
506
503
|
return name === 'Component' || name === 'PureComponent';
|
|
507
504
|
});
|
|
508
|
-
if (
|
|
505
|
+
if (propsTypeExpression?.typeArguments?.[0]?.['typeName']) {
|
|
509
506
|
propsTypeName = propsTypeExpression.typeArguments[0].typeName.getText();
|
|
510
507
|
}
|
|
511
508
|
}
|
|
@@ -32,7 +32,10 @@ function createTsConfig(host, projectRoot, type, options, relativePathToRootTsCo
|
|
|
32
32
|
// inline tsconfig.base.json into the project
|
|
33
33
|
if (options.rootProject) {
|
|
34
34
|
json.compileOnSave = false;
|
|
35
|
-
json.compilerOptions =
|
|
35
|
+
json.compilerOptions = {
|
|
36
|
+
...shared.tsConfigBaseOptions,
|
|
37
|
+
...json.compilerOptions,
|
|
38
|
+
};
|
|
36
39
|
json.exclude = ['node_modules', 'tmp'];
|
|
37
40
|
}
|
|
38
41
|
else {
|
|
@@ -42,9 +45,8 @@ function createTsConfig(host, projectRoot, type, options, relativePathToRootTsCo
|
|
|
42
45
|
const tsconfigProjectPath = `${projectRoot}/tsconfig.${type}.json`;
|
|
43
46
|
if (options.bundler === 'vite' && host.exists(tsconfigProjectPath)) {
|
|
44
47
|
(0, json_1.updateJson)(host, tsconfigProjectPath, (json) => {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
const types = new Set((_b = json.compilerOptions.types) !== null && _b !== void 0 ? _b : []);
|
|
48
|
+
json.compilerOptions ??= {};
|
|
49
|
+
const types = new Set(json.compilerOptions.types ?? []);
|
|
48
50
|
types.add('node');
|
|
49
51
|
types.add('vite/client');
|
|
50
52
|
json.compilerOptions.types = Array.from(types);
|
package/src/utils/ct-utils.js
CHANGED
|
@@ -1,31 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isComponent = exports.getBundlerFromTarget = exports.addCTTargetWithBuildTarget = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
4
|
const devkit_1 = require("@nx/devkit");
|
|
6
5
|
const ensure_typescript_1 = require("@nx/js/src/utils/typescript/ensure-typescript");
|
|
7
6
|
const ast_utils_1 = require("./ast-utils");
|
|
8
7
|
let tsModule;
|
|
9
8
|
const allowedFileExt = new RegExp(/\.[jt]sx?/);
|
|
10
9
|
const isSpecFile = new RegExp(/(spec|test)\./);
|
|
11
|
-
function addCTTargetWithBuildTarget(tree, options) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
projectConfig.targets['component-test'].options
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
10
|
+
async function addCTTargetWithBuildTarget(tree, options) {
|
|
11
|
+
let found = { target: options.buildTarget, config: undefined };
|
|
12
|
+
// Specifically undefined as a workaround for Remix to pass an empty string as the buildTarget
|
|
13
|
+
if (options.buildTarget === undefined) {
|
|
14
|
+
const { findBuildConfig } = await Promise.resolve().then(() => require('@nx/cypress/src/utils/find-target-options'));
|
|
15
|
+
found = await findBuildConfig(tree, {
|
|
16
|
+
project: options.project,
|
|
17
|
+
buildTarget: options.buildTarget,
|
|
18
|
+
validExecutorNames: options.validExecutorNames,
|
|
19
|
+
});
|
|
20
|
+
assertValidConfig(found?.config);
|
|
21
|
+
}
|
|
22
|
+
const projectConfig = (0, devkit_1.readProjectConfiguration)(tree, options.project);
|
|
23
|
+
projectConfig.targets['component-test'].options = {
|
|
24
|
+
...projectConfig.targets['component-test'].options,
|
|
25
|
+
devServerTarget: found.target,
|
|
26
|
+
skipServe: true,
|
|
27
|
+
};
|
|
28
|
+
(0, devkit_1.updateProjectConfiguration)(tree, options.project, projectConfig);
|
|
29
|
+
return found;
|
|
29
30
|
}
|
|
30
31
|
exports.addCTTargetWithBuildTarget = addCTTargetWithBuildTarget;
|
|
31
32
|
function assertValidConfig(config) {
|
|
@@ -33,22 +34,19 @@ function assertValidConfig(config) {
|
|
|
33
34
|
throw new Error('Unable to find a valid build configuration. Try passing in a target for an app. --build-target=<project>:<target>[:<configuration>]');
|
|
34
35
|
}
|
|
35
36
|
}
|
|
36
|
-
function getBundlerFromTarget(found, tree) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
return found.config.executor === '@nrwl/vite:build' ||
|
|
41
|
-
found.config.executor === '@nx/vite:build'
|
|
42
|
-
? 'vite'
|
|
43
|
-
: 'webpack';
|
|
44
|
-
}
|
|
45
|
-
const { target, project } = (0, devkit_1.parseTargetString)(found.target, yield (0, devkit_1.createProjectGraphAsync)());
|
|
46
|
-
const projectConfig = (0, devkit_1.readProjectConfiguration)(tree, project);
|
|
47
|
-
const executor = (_c = (_b = projectConfig === null || projectConfig === void 0 ? void 0 : projectConfig.targets) === null || _b === void 0 ? void 0 : _b[target]) === null || _c === void 0 ? void 0 : _c.executor;
|
|
48
|
-
return executor === '@nrwl/vite:build' || executor === '@nx/vite:build'
|
|
37
|
+
async function getBundlerFromTarget(found, tree) {
|
|
38
|
+
if (found.target && found.config?.executor) {
|
|
39
|
+
return found.config.executor === '@nrwl/vite:build' ||
|
|
40
|
+
found.config.executor === '@nx/vite:build'
|
|
49
41
|
? 'vite'
|
|
50
42
|
: 'webpack';
|
|
51
|
-
}
|
|
43
|
+
}
|
|
44
|
+
const { target, project } = (0, devkit_1.parseTargetString)(found.target, await (0, devkit_1.createProjectGraphAsync)());
|
|
45
|
+
const projectConfig = (0, devkit_1.readProjectConfiguration)(tree, project);
|
|
46
|
+
const executor = projectConfig?.targets?.[target]?.executor;
|
|
47
|
+
return executor === '@nrwl/vite:build' || executor === '@nx/vite:build'
|
|
48
|
+
? 'vite'
|
|
49
|
+
: 'webpack';
|
|
52
50
|
}
|
|
53
51
|
exports.getBundlerFromTarget = getBundlerFromTarget;
|
|
54
52
|
function isComponent(tree, filePath) {
|
package/src/utils/lint.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.extendReactEslintJson = exports.extraEslintDependencies = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
4
|
const versions_1 = require("./versions");
|
|
6
5
|
exports.extraEslintDependencies = {
|
|
7
6
|
dependencies: {},
|
|
@@ -16,7 +15,10 @@ exports.extraEslintDependencies = {
|
|
|
16
15
|
* @deprecated Use `addExtendsToLintConfig` from `@nx/linter` instead.
|
|
17
16
|
*/
|
|
18
17
|
const extendReactEslintJson = (json) => {
|
|
19
|
-
const { extends: pluginExtends
|
|
20
|
-
return
|
|
18
|
+
const { extends: pluginExtends, ...config } = json;
|
|
19
|
+
return {
|
|
20
|
+
extends: ['plugin:@nx/react', ...(pluginExtends || [])],
|
|
21
|
+
...config,
|
|
22
|
+
};
|
|
21
23
|
};
|
|
22
24
|
exports.extendReactEslintJson = extendReactEslintJson;
|
|
@@ -1,35 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createLib = exports.createApp = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
4
|
const devkit_1 = require("@nx/devkit");
|
|
6
5
|
const application_1 = require("../generators/application/application");
|
|
7
6
|
const linter_1 = require("@nx/linter");
|
|
8
|
-
function createApp(tree, appName) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
projectNameAndRootFormat: 'as-provided',
|
|
18
|
-
});
|
|
7
|
+
async function createApp(tree, appName) {
|
|
8
|
+
await (0, application_1.default)(tree, {
|
|
9
|
+
e2eTestRunner: 'none',
|
|
10
|
+
linter: linter_1.Linter.EsLint,
|
|
11
|
+
skipFormat: true,
|
|
12
|
+
style: 'css',
|
|
13
|
+
unitTestRunner: 'none',
|
|
14
|
+
name: appName,
|
|
15
|
+
projectNameAndRootFormat: 'as-provided',
|
|
19
16
|
});
|
|
20
17
|
}
|
|
21
18
|
exports.createApp = createApp;
|
|
22
|
-
function createLib(tree, libName) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
targets: {},
|
|
32
|
-
});
|
|
19
|
+
async function createLib(tree, libName) {
|
|
20
|
+
const { fileName } = (0, devkit_1.names)(libName);
|
|
21
|
+
tree.write(`/${fileName}/src/index.ts`, `import React from 'react';\n`);
|
|
22
|
+
(0, devkit_1.addProjectConfiguration)(tree, fileName, {
|
|
23
|
+
tags: [],
|
|
24
|
+
root: `${fileName}`,
|
|
25
|
+
projectType: 'library',
|
|
26
|
+
sourceRoot: `${fileName}/src`,
|
|
27
|
+
targets: {},
|
|
33
28
|
});
|
|
34
29
|
}
|
|
35
30
|
exports.createLib = createLib;
|