@nx/react 16.8.0-beta.4 → 16.8.0-beta.6
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.d.ts +0 -1
- 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/files/common/tsconfig.lib.json__tmpl__ +6 -6
- package/src/generators/library/files/vite/tsconfig.lib.json__tmpl__ +7 -7
- 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 +10 -3
- 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,59 +1,52 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.storybookConfigurationSchematic = exports.storybookConfigurationGenerator = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
4
|
const stories_1 = require("../stories/stories");
|
|
6
5
|
const devkit_1 = require("@nx/devkit");
|
|
7
6
|
const versions_1 = require("../../utils/versions");
|
|
8
|
-
function generateStories(host, schema) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
skipFormat: true,
|
|
23
|
-
interactionTests: (_a = schema.interactionTests) !== null && _a !== void 0 ? _a : true,
|
|
24
|
-
});
|
|
7
|
+
async function generateStories(host, schema) {
|
|
8
|
+
// TODO(v18): remove Cypress
|
|
9
|
+
(0, devkit_1.ensurePackage)('@nx/cypress', versions_1.nxVersion);
|
|
10
|
+
const { getE2eProjectName } = await Promise.resolve().then(() => require('@nx/cypress/src/utils/project-name'));
|
|
11
|
+
const projectConfig = (0, devkit_1.readProjectConfiguration)(host, schema.name);
|
|
12
|
+
const cypressProject = getE2eProjectName(schema.name, projectConfig.root, schema.cypressDirectory);
|
|
13
|
+
await (0, stories_1.default)(host, {
|
|
14
|
+
project: schema.name,
|
|
15
|
+
generateCypressSpecs: schema.configureCypress && schema.generateCypressSpecs,
|
|
16
|
+
js: schema.js,
|
|
17
|
+
cypressProject,
|
|
18
|
+
ignorePaths: schema.ignorePaths,
|
|
19
|
+
skipFormat: true,
|
|
20
|
+
interactionTests: schema.interactionTests ?? true,
|
|
25
21
|
});
|
|
26
22
|
}
|
|
27
|
-
function storybookConfigurationGenerator(host, schema) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
uiFramework: uiFramework,
|
|
49
|
-
skipFormat: true,
|
|
50
|
-
});
|
|
51
|
-
if (schema.generateStories) {
|
|
52
|
-
yield generateStories(host, schema);
|
|
53
|
-
}
|
|
54
|
-
yield (0, devkit_1.formatFiles)(host);
|
|
55
|
-
return installTask;
|
|
23
|
+
async function storybookConfigurationGenerator(host, schema) {
|
|
24
|
+
const { configurationGenerator } = (0, devkit_1.ensurePackage)('@nx/storybook', versions_1.nxVersion);
|
|
25
|
+
let uiFramework = '@storybook/react-vite';
|
|
26
|
+
const projectConfig = (0, devkit_1.readProjectConfiguration)(host, schema.name);
|
|
27
|
+
if (projectConfig.targets['build']?.executor === '@nx/webpack:webpack' ||
|
|
28
|
+
projectConfig.targets['build']?.executor === '@nrwl/webpack:webpack' ||
|
|
29
|
+
projectConfig.targets['build']?.executor === '@nx/rollup:rollup' ||
|
|
30
|
+
projectConfig.targets['build']?.executor === '@nrwl/rollup:rollup') {
|
|
31
|
+
uiFramework = '@storybook/react-webpack5';
|
|
32
|
+
}
|
|
33
|
+
const installTask = await configurationGenerator(host, {
|
|
34
|
+
name: schema.name,
|
|
35
|
+
configureCypress: schema.configureCypress,
|
|
36
|
+
js: schema.js,
|
|
37
|
+
linter: schema.linter,
|
|
38
|
+
cypressDirectory: schema.cypressDirectory,
|
|
39
|
+
tsConfiguration: schema.tsConfiguration ?? true,
|
|
40
|
+
interactionTests: schema.interactionTests ?? true,
|
|
41
|
+
configureStaticServe: schema.configureStaticServe,
|
|
42
|
+
uiFramework: uiFramework,
|
|
43
|
+
skipFormat: true,
|
|
56
44
|
});
|
|
45
|
+
if (schema.generateStories) {
|
|
46
|
+
await generateStories(host, schema);
|
|
47
|
+
}
|
|
48
|
+
await (0, devkit_1.formatFiles)(host);
|
|
49
|
+
return installTask;
|
|
57
50
|
}
|
|
58
51
|
exports.storybookConfigurationGenerator = storybookConfigurationGenerator;
|
|
59
52
|
exports.default = storybookConfigurationGenerator;
|
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.removeReactReduxTypesFromPackageJson = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
4
|
const devkit_1 = require("@nx/devkit");
|
|
6
|
-
function removeReactReduxTypesFromPackageJson(host) {
|
|
7
|
-
return
|
|
8
|
-
return (0, devkit_1.removeDependenciesFromPackageJson)(host, ['@types/react-redux'], ['@types/react-redux']);
|
|
9
|
-
});
|
|
5
|
+
async function removeReactReduxTypesFromPackageJson(host) {
|
|
6
|
+
return (0, devkit_1.removeDependenciesFromPackageJson)(host, ['@types/react-redux'], ['@types/react-redux']);
|
|
10
7
|
}
|
|
11
8
|
exports.removeReactReduxTypesFromPackageJson = removeReactReduxTypesFromPackageJson;
|
|
12
9
|
exports.default = removeReactReduxTypesFromPackageJson;
|
|
@@ -1,66 +1,61 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.updateEmotionSetup = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
4
|
const devkit_1 = require("@nx/devkit");
|
|
6
|
-
function updateEmotionSetup(host) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
emotionPresetIdx = idx;
|
|
26
|
-
break;
|
|
27
|
-
}
|
|
28
|
-
else {
|
|
29
|
-
if (!preset.includes(oldPreset))
|
|
30
|
-
continue;
|
|
31
|
-
emotionPresetIdx = idx;
|
|
32
|
-
break;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
if (emotionPresetIdx !== -1) {
|
|
36
|
-
// Remove preset
|
|
37
|
-
json.presets.splice(emotionPresetIdx, 1);
|
|
38
|
-
// Add new plugin
|
|
39
|
-
(_a = json.plugins) !== null && _a !== void 0 ? _a : (json.plugins = []);
|
|
40
|
-
json.plugins.push(emotionOptions ? [newPlugin, emotionOptions] : newPlugin);
|
|
41
|
-
return json;
|
|
5
|
+
async function updateEmotionSetup(host) {
|
|
6
|
+
const projects = (0, devkit_1.getProjects)(host);
|
|
7
|
+
projects.forEach((p) => {
|
|
8
|
+
const babelrcPath = `${p.root}/.babelrc`;
|
|
9
|
+
const oldPreset = '@emotion/babel-preset-css-prop';
|
|
10
|
+
const newPlugin = '@emotion/babel-plugin';
|
|
11
|
+
if (host.exists(babelrcPath)) {
|
|
12
|
+
(0, devkit_1.updateJson)(host, babelrcPath, (json) => {
|
|
13
|
+
if (!json.presets)
|
|
14
|
+
return json;
|
|
15
|
+
let emotionPresetIdx = -1;
|
|
16
|
+
let emotionOptions = null;
|
|
17
|
+
for (const [idx, preset] of json.presets.entries()) {
|
|
18
|
+
if (Array.isArray(preset)) {
|
|
19
|
+
if (!preset[0].includes(oldPreset))
|
|
20
|
+
continue;
|
|
21
|
+
emotionOptions = preset[1];
|
|
22
|
+
emotionPresetIdx = idx;
|
|
23
|
+
break;
|
|
42
24
|
}
|
|
43
25
|
else {
|
|
44
|
-
|
|
26
|
+
if (!preset.includes(oldPreset))
|
|
27
|
+
continue;
|
|
28
|
+
emotionPresetIdx = idx;
|
|
29
|
+
break;
|
|
45
30
|
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
31
|
+
}
|
|
32
|
+
if (emotionPresetIdx !== -1) {
|
|
33
|
+
// Remove preset
|
|
34
|
+
json.presets.splice(emotionPresetIdx, 1);
|
|
35
|
+
// Add new plugin
|
|
36
|
+
json.plugins ??= [];
|
|
37
|
+
json.plugins.push(emotionOptions ? [newPlugin, emotionOptions] : newPlugin);
|
|
38
|
+
return json;
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
return json;
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
(0, devkit_1.updateJson)(host, 'package.json', (json) => {
|
|
47
|
+
if (json.devDependencies?.['@emotion/babel-preset-css-prop']) {
|
|
48
|
+
delete json.devDependencies['@emotion/babel-preset-css-prop'];
|
|
49
|
+
json.devDependencies['@emotion/babel-plugin'] = '11.2.0';
|
|
50
|
+
}
|
|
51
|
+
// Just in case someone moved it to `dependencies`
|
|
52
|
+
else if (json.dependencies?.['@emotion/babel-preset-css-prop']) {
|
|
53
|
+
delete json.dependencies['@emotion/babel-preset-css-prop'];
|
|
54
|
+
json.dependencies['@emotion/babel-plugin'] = '11.2.0';
|
|
55
|
+
}
|
|
56
|
+
return json;
|
|
63
57
|
});
|
|
58
|
+
await (0, devkit_1.formatFiles)(host);
|
|
64
59
|
}
|
|
65
60
|
exports.updateEmotionSetup = updateEmotionSetup;
|
|
66
61
|
exports.default = updateEmotionSetup;
|
|
@@ -1,26 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useReactJsxInTsconfig = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
4
|
const devkit_1 = require("@nx/devkit");
|
|
6
|
-
function useReactJsxInTsconfig(host) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
(
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
yield (0, devkit_1.formatFiles)(host);
|
|
5
|
+
async function useReactJsxInTsconfig(host) {
|
|
6
|
+
const projects = (0, devkit_1.getProjects)(host);
|
|
7
|
+
projects.forEach((p) => {
|
|
8
|
+
const tsConfigPath = `${p.root}/tsconfig.json`;
|
|
9
|
+
if (host.exists(tsConfigPath)) {
|
|
10
|
+
(0, devkit_1.updateJson)(host, tsConfigPath, (json) => {
|
|
11
|
+
if (json.compilerOptions?.jsx === 'react') {
|
|
12
|
+
// JSX is handled by babel
|
|
13
|
+
json.compilerOptions.jsx = 'react-jsx';
|
|
14
|
+
}
|
|
15
|
+
return json;
|
|
16
|
+
});
|
|
17
|
+
}
|
|
23
18
|
});
|
|
19
|
+
await (0, devkit_1.formatFiles)(host);
|
|
24
20
|
}
|
|
25
21
|
exports.useReactJsxInTsconfig = useReactJsxInTsconfig;
|
|
26
22
|
exports.default = useReactJsxInTsconfig;
|
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.removeReactReduxTypesFromPackageJson = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
4
|
const devkit_1 = require("@nx/devkit");
|
|
6
|
-
function removeReactReduxTypesFromPackageJson(host) {
|
|
7
|
-
return
|
|
8
|
-
|
|
9
|
-
'@testing-library/react-hooks': '^7.0.1',
|
|
10
|
-
});
|
|
5
|
+
async function removeReactReduxTypesFromPackageJson(host) {
|
|
6
|
+
return (0, devkit_1.addDependenciesToPackageJson)(host, {}, {
|
|
7
|
+
'@testing-library/react-hooks': '^7.0.1',
|
|
11
8
|
});
|
|
12
9
|
}
|
|
13
10
|
exports.removeReactReduxTypesFromPackageJson = removeReactReduxTypesFromPackageJson;
|
|
@@ -1,37 +1,34 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.migrateStorybookToWebPack5 = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
4
|
const devkit_1 = require("@nx/devkit");
|
|
6
5
|
const webpack5_changes_utils_1 = require("./webpack5-changes-utils");
|
|
7
6
|
let needsInstall = false;
|
|
8
|
-
function migrateStorybookToWebPack5(tree) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
(0, webpack5_changes_utils_1.workspaceHasStorybookForReact)(packageJson);
|
|
20
|
-
}
|
|
21
|
-
if (!json.dependencies['@storybook/manager-webpack5'] &&
|
|
22
|
-
!json.devDependencies['@storybook/manager-webpack5']) {
|
|
23
|
-
needsInstall = true;
|
|
24
|
-
json.devDependencies['@storybook/manager-webpack5'] =
|
|
25
|
-
(0, webpack5_changes_utils_1.workspaceHasStorybookForReact)(packageJson);
|
|
26
|
-
}
|
|
27
|
-
return json;
|
|
28
|
-
});
|
|
29
|
-
yield (0, webpack5_changes_utils_1.migrateToWebPack5)(tree);
|
|
30
|
-
if (needsInstall) {
|
|
31
|
-
devkit_1.logger.info('Please make sure to run npm install or yarn install to get the latest packages added by this migration');
|
|
7
|
+
async function migrateStorybookToWebPack5(tree) {
|
|
8
|
+
const packageJson = (0, devkit_1.readJson)(tree, 'package.json');
|
|
9
|
+
if ((0, webpack5_changes_utils_1.workspaceHasStorybookForReact)(packageJson)) {
|
|
10
|
+
(0, devkit_1.updateJson)(tree, 'package.json', (json) => {
|
|
11
|
+
json.dependencies = json.dependencies || {};
|
|
12
|
+
json.devDependencies = json.devDependencies || {};
|
|
13
|
+
if (!json.dependencies['@storybook/builder-webpack5'] &&
|
|
14
|
+
!json.devDependencies['@storybook/builder-webpack5']) {
|
|
15
|
+
needsInstall = true;
|
|
16
|
+
json.devDependencies['@storybook/builder-webpack5'] =
|
|
17
|
+
(0, webpack5_changes_utils_1.workspaceHasStorybookForReact)(packageJson);
|
|
32
18
|
}
|
|
19
|
+
if (!json.dependencies['@storybook/manager-webpack5'] &&
|
|
20
|
+
!json.devDependencies['@storybook/manager-webpack5']) {
|
|
21
|
+
needsInstall = true;
|
|
22
|
+
json.devDependencies['@storybook/manager-webpack5'] =
|
|
23
|
+
(0, webpack5_changes_utils_1.workspaceHasStorybookForReact)(packageJson);
|
|
24
|
+
}
|
|
25
|
+
return json;
|
|
26
|
+
});
|
|
27
|
+
await (0, webpack5_changes_utils_1.migrateToWebPack5)(tree);
|
|
28
|
+
if (needsInstall) {
|
|
29
|
+
devkit_1.logger.info('Please make sure to run npm install or yarn install to get the latest packages added by this migration');
|
|
33
30
|
}
|
|
34
|
-
}
|
|
31
|
+
}
|
|
35
32
|
}
|
|
36
33
|
exports.migrateStorybookToWebPack5 = migrateStorybookToWebPack5;
|
|
37
34
|
exports.default = migrateStorybookToWebPack5;
|
|
@@ -1,38 +1,35 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.updateEmotionSetup = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
4
|
const devkit_1 = require("@nx/devkit");
|
|
6
|
-
function updateEmotionSetup(host) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
if (
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
break;
|
|
23
|
-
}
|
|
5
|
+
async function updateEmotionSetup(host) {
|
|
6
|
+
const projects = (0, devkit_1.getProjects)(host);
|
|
7
|
+
projects.forEach((p) => {
|
|
8
|
+
let hasEmotion = false;
|
|
9
|
+
const babelrcPath = `${p.root}/.babelrc`;
|
|
10
|
+
const tsConfigPath = `${p.root}/tsconfig.json`;
|
|
11
|
+
if (host.exists(babelrcPath)) {
|
|
12
|
+
const babelrc = (0, devkit_1.readJson)(host, babelrcPath);
|
|
13
|
+
if (babelrc.presets) {
|
|
14
|
+
for (const [idx, preset] of babelrc.presets.entries()) {
|
|
15
|
+
if (Array.isArray(preset)) {
|
|
16
|
+
if (!preset[0].includes('@nrwl/react/babel'))
|
|
17
|
+
continue;
|
|
18
|
+
const emotionOptions = preset[1];
|
|
19
|
+
hasEmotion = emotionOptions.importSource === '@emotion/react';
|
|
20
|
+
break;
|
|
24
21
|
}
|
|
25
22
|
}
|
|
26
23
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
yield (0, devkit_1.formatFiles)(host);
|
|
24
|
+
}
|
|
25
|
+
if (hasEmotion && host.exists(tsConfigPath)) {
|
|
26
|
+
(0, devkit_1.updateJson)(host, tsConfigPath, (json) => {
|
|
27
|
+
json.compilerOptions.jsxImportSource = '@emotion/react';
|
|
28
|
+
return json;
|
|
29
|
+
});
|
|
30
|
+
}
|
|
35
31
|
});
|
|
32
|
+
await (0, devkit_1.formatFiles)(host);
|
|
36
33
|
}
|
|
37
34
|
exports.updateEmotionSetup = updateEmotionSetup;
|
|
38
35
|
exports.default = updateEmotionSetup;
|
|
@@ -1,27 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getTsSourceFile = exports.checkMainJsForOldSyntax = exports.editProjectMainJs = exports.allReactProjectsWithStorybookConfiguration = exports.workspaceHasStorybookForReact = exports.migrateToWebPack5 = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
4
|
const devkit_1 = require("@nx/devkit");
|
|
6
5
|
const devkit_2 = require("@nx/devkit");
|
|
7
6
|
const ts = require("typescript");
|
|
8
7
|
const js_1 = require("@nx/js");
|
|
9
|
-
function migrateToWebPack5(tree) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
editProjectMainJs(tree, storybookConfigFile, project.projectName);
|
|
22
|
-
});
|
|
23
|
-
yield (0, devkit_2.formatFiles)(tree);
|
|
8
|
+
async function migrateToWebPack5(tree) {
|
|
9
|
+
allReactProjectsWithStorybookConfiguration(tree).forEach((project) => {
|
|
10
|
+
let storybookConfigFile = `${project.storybookConfigPath}/main.js`;
|
|
11
|
+
if (!tree.exists(storybookConfigFile)) {
|
|
12
|
+
// try to see whether there's a main.ts file
|
|
13
|
+
storybookConfigFile = `${project.storybookConfigPath}/main.ts`;
|
|
14
|
+
}
|
|
15
|
+
if (!tree.exists(storybookConfigFile)) {
|
|
16
|
+
// ok...give up
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
editProjectMainJs(tree, storybookConfigFile, project.projectName);
|
|
24
20
|
});
|
|
21
|
+
await (0, devkit_2.formatFiles)(tree);
|
|
25
22
|
}
|
|
26
23
|
exports.migrateToWebPack5 = migrateToWebPack5;
|
|
27
24
|
function workspaceHasStorybookForReact(packageJson) {
|
|
@@ -30,28 +27,28 @@ function workspaceHasStorybookForReact(packageJson) {
|
|
|
30
27
|
}
|
|
31
28
|
exports.workspaceHasStorybookForReact = workspaceHasStorybookForReact;
|
|
32
29
|
function allReactProjectsWithStorybookConfiguration(tree) {
|
|
33
|
-
var _a, _b, _c;
|
|
34
30
|
const projects = (0, devkit_1.getProjects)(tree);
|
|
35
|
-
const reactProjectsThatHaveStorybookConfiguration =
|
|
31
|
+
const reactProjectsThatHaveStorybookConfiguration = [...projects.entries()]
|
|
32
|
+
?.filter(([_, projectConfig]) => projectConfig.targets &&
|
|
36
33
|
projectConfig.targets.storybook &&
|
|
37
|
-
projectConfig.targets.storybook.options)
|
|
38
|
-
|
|
34
|
+
projectConfig.targets.storybook.options)
|
|
35
|
+
?.map(([projectName, projectConfig]) => {
|
|
39
36
|
if (projectConfig.targets &&
|
|
40
37
|
projectConfig.targets.storybook &&
|
|
41
|
-
|
|
42
|
-
|
|
38
|
+
projectConfig.targets.storybook.options?.config?.configFolder &&
|
|
39
|
+
projectConfig.targets.storybook.options?.uiFramework ===
|
|
43
40
|
'@storybook/react') {
|
|
44
41
|
return {
|
|
45
42
|
projectName,
|
|
46
43
|
storybookConfigPath: projectConfig.targets.storybook.options.config.configFolder,
|
|
47
44
|
};
|
|
48
45
|
}
|
|
49
|
-
})
|
|
46
|
+
})
|
|
47
|
+
?.filter((entry) => !!entry);
|
|
50
48
|
return reactProjectsThatHaveStorybookConfiguration;
|
|
51
49
|
}
|
|
52
50
|
exports.allReactProjectsWithStorybookConfiguration = allReactProjectsWithStorybookConfiguration;
|
|
53
51
|
function editProjectMainJs(tree, projectMainJsFile, projectName) {
|
|
54
|
-
var _a, _b;
|
|
55
52
|
let newContents;
|
|
56
53
|
let moduleExportsIsEmptyOrNonExistentOrInvalid = false;
|
|
57
54
|
let alreadyHasBuilder;
|
|
@@ -73,15 +70,15 @@ function editProjectMainJs(tree, projectMainJsFile, projectName) {
|
|
|
73
70
|
* if it does not exist already
|
|
74
71
|
*/
|
|
75
72
|
let indexOfStoriesNode = -1;
|
|
76
|
-
const hasCoreObject =
|
|
73
|
+
const hasCoreObject = listOfStatements[0]?.getChildren()?.find((node) => {
|
|
77
74
|
if (node &&
|
|
78
75
|
node.getText().length > 0 &&
|
|
79
76
|
indexOfStoriesNode < 0 &&
|
|
80
|
-
|
|
77
|
+
node?.getText().startsWith('stories')) {
|
|
81
78
|
indexOfStoriesNode = node.getStart();
|
|
82
79
|
}
|
|
83
|
-
return (
|
|
84
|
-
|
|
80
|
+
return (node?.kind === ts.SyntaxKind.PropertyAssignment &&
|
|
81
|
+
node?.getText().startsWith('core'));
|
|
85
82
|
});
|
|
86
83
|
if (hasCoreObject) {
|
|
87
84
|
const contentsOfCoreNode = hasCoreObject.getChildren().find((node) => {
|
|
@@ -152,7 +149,6 @@ function editProjectMainJs(tree, projectMainJsFile, projectName) {
|
|
|
152
149
|
}
|
|
153
150
|
exports.editProjectMainJs = editProjectMainJs;
|
|
154
151
|
function checkMainJsForOldSyntax(nodeList, fileContent) {
|
|
155
|
-
var _a, _b, _c, _d, _e;
|
|
156
152
|
let alreadyContainsBuilder = false;
|
|
157
153
|
let coreNode;
|
|
158
154
|
let hasCoreNode = false;
|
|
@@ -165,13 +161,13 @@ function checkMainJsForOldSyntax(nodeList, fileContent) {
|
|
|
165
161
|
// If it does not, then we need to add it
|
|
166
162
|
for (let topNode of nodeList) {
|
|
167
163
|
if (topNode.kind === ts.SyntaxKind.ExpressionStatement &&
|
|
168
|
-
|
|
164
|
+
topNode.getChildren()?.length > 0) {
|
|
169
165
|
for (let node of topNode.getChildren()) {
|
|
170
166
|
if (node.kind === ts.SyntaxKind.BinaryExpression &&
|
|
171
|
-
|
|
167
|
+
node.getChildren()?.length) {
|
|
172
168
|
for (let childNode of node.getChildren()) {
|
|
173
169
|
if (childNode.kind === ts.SyntaxKind.PropertyAccessExpression &&
|
|
174
|
-
|
|
170
|
+
childNode.getChildren()?.length) {
|
|
175
171
|
for (let grandChildNode of childNode.getChildren()) {
|
|
176
172
|
if (grandChildNode.kind === ts.SyntaxKind.Identifier &&
|
|
177
173
|
grandChildNode.getText() === 'core') {
|
|
@@ -187,10 +183,10 @@ function checkMainJsForOldSyntax(nodeList, fileContent) {
|
|
|
187
183
|
}
|
|
188
184
|
}
|
|
189
185
|
if (hasCoreNode) {
|
|
190
|
-
if (
|
|
186
|
+
if (coreNode.getChildren()?.length) {
|
|
191
187
|
for (let coreChildNode of coreNode.getChildren()) {
|
|
192
188
|
if (coreChildNode.kind === ts.SyntaxKind.ObjectLiteralExpression &&
|
|
193
|
-
|
|
189
|
+
coreChildNode.getChildren()?.length) {
|
|
194
190
|
for (let coreChildNodeChild of coreChildNode.getChildren()) {
|
|
195
191
|
if (coreChildNodeChild.kind === ts.SyntaxKind.SyntaxList) {
|
|
196
192
|
for (let coreChildNodeGrandChild of coreChildNodeChild.getChildren()) {
|
|
@@ -1,28 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.updateToReact18 = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
4
|
const devkit_1 = require("@nx/devkit");
|
|
6
5
|
// Putting this here because React Native 0.67 is incompatible with React 18.
|
|
7
6
|
// Waiting for 0.68 to come out with support for React 18.
|
|
8
7
|
// TODO(jack): For Nx 14 let's add another migration for React 18 in migrations.json because by then React Native 0.68.0 should be released.
|
|
9
|
-
function updateToReact18(host) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
});
|
|
8
|
+
async function updateToReact18(host) {
|
|
9
|
+
const { dependencies } = (0, devkit_1.readJson)(host, 'package.json');
|
|
10
|
+
if (dependencies['react-native'] &&
|
|
11
|
+
!dependencies['react-native'].match(/[\^~]?0.68/)) {
|
|
12
|
+
devkit_1.logger.info(`React Native ${dependencies['react-native']} is incompatible with React 18. Skipping update until React Native 0.68.0 is released.`);
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
return (0, devkit_1.addDependenciesToPackageJson)(host, {
|
|
16
|
+
react: '18.0.0',
|
|
17
|
+
'react-dom': '18.0.0',
|
|
18
|
+
'react-is': '18.0.0',
|
|
19
|
+
}, {
|
|
20
|
+
'react-test-renderer': '18.0.0',
|
|
21
|
+
});
|
|
22
|
+
}
|
|
26
23
|
}
|
|
27
24
|
exports.updateToReact18 = updateToReact18;
|
|
28
25
|
exports.default = updateToReact18;
|