@nx/react 16.8.0-beta.3 → 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 +56 -60
- 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 -22
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.setupSsrSchematic = exports.setupSsrGenerator = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
4
|
const devkit_1 = require("@nx/devkit");
|
|
6
5
|
const init_1 = require("../init/init");
|
|
7
6
|
const versions_1 = require("../../utils/versions");
|
|
@@ -19,144 +18,147 @@ function readEntryFile(host, path) {
|
|
|
19
18
|
source: tsModule.createSourceFile(path, content, tsModule.ScriptTarget.Latest, true),
|
|
20
19
|
};
|
|
21
20
|
}
|
|
22
|
-
function setupSsrGenerator(tree, options) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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
|
-
projectConfig.targets
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
21
|
+
async function setupSsrGenerator(tree, options) {
|
|
22
|
+
await (0, init_1.default)(tree, { skipFormat: true });
|
|
23
|
+
const projectConfig = (0, devkit_1.readProjectConfiguration)(tree, options.project);
|
|
24
|
+
const projectRoot = projectConfig.root;
|
|
25
|
+
const appImportCandidates = [
|
|
26
|
+
options.appComponentImportPath ?? 'app/app',
|
|
27
|
+
'app',
|
|
28
|
+
'App',
|
|
29
|
+
'app/App',
|
|
30
|
+
'App/App',
|
|
31
|
+
].map((importPath) => {
|
|
32
|
+
return {
|
|
33
|
+
importPath,
|
|
34
|
+
filePath: (0, devkit_1.joinPathFragments)(projectConfig.sourceRoot || projectConfig.root, `${importPath}.tsx`),
|
|
35
|
+
};
|
|
36
|
+
});
|
|
37
|
+
const appComponentInfo = appImportCandidates.find((candidate) => tree.exists(candidate.filePath));
|
|
38
|
+
if (!appComponentInfo) {
|
|
39
|
+
throw new Error(`Cannot find an import path for <App/> component. Try passing setting --appComponentImportPath option.`);
|
|
40
|
+
}
|
|
41
|
+
if (!projectConfig.targets.build || !projectConfig.targets.serve) {
|
|
42
|
+
throw new Error(`Project ${options.project} does not have build and serve targets`);
|
|
43
|
+
}
|
|
44
|
+
if (projectConfig.targets.server) {
|
|
45
|
+
throw new Error(`Project ${options.project} already has a server target.`);
|
|
46
|
+
}
|
|
47
|
+
const originalOutputPath = projectConfig.targets.build?.options?.outputPath;
|
|
48
|
+
if (!originalOutputPath) {
|
|
49
|
+
throw new Error(`Project ${options.project} does not contain a outputPath for the build target.`);
|
|
50
|
+
}
|
|
51
|
+
projectConfig.targets.build.options.outputPath = (0, devkit_1.joinPathFragments)(originalOutputPath, 'browser');
|
|
52
|
+
projectConfig.targets = {
|
|
53
|
+
...projectConfig.targets,
|
|
54
|
+
server: {
|
|
55
|
+
dependsOn: ['build'],
|
|
56
|
+
executor: '@nx/webpack:webpack',
|
|
57
|
+
outputs: ['{options.outputPath}'],
|
|
58
|
+
defaultConfiguration: 'production',
|
|
59
|
+
options: {
|
|
60
|
+
target: 'node',
|
|
61
|
+
main: `${projectRoot}/server.ts`,
|
|
62
|
+
outputPath: (0, devkit_1.joinPathFragments)(originalOutputPath, 'server'),
|
|
63
|
+
outputFileName: 'server.js',
|
|
64
|
+
tsConfig: `${projectRoot}/tsconfig.server.json`,
|
|
65
|
+
compiler: 'babel',
|
|
66
|
+
externalDependencies: 'all',
|
|
67
|
+
outputHashing: 'none',
|
|
68
|
+
isolatedConfig: true,
|
|
69
|
+
webpackConfig: (0, devkit_1.joinPathFragments)(projectRoot, 'webpack.config.js'),
|
|
70
|
+
},
|
|
71
|
+
configurations: {
|
|
72
|
+
development: {
|
|
73
|
+
optimization: false,
|
|
74
|
+
sourceMap: true,
|
|
71
75
|
},
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
replace: `${projectRoot}/src/environments/environment.ts`,
|
|
81
|
-
with: `${projectRoot}/src/environments/environment.prod.ts`,
|
|
82
|
-
},
|
|
83
|
-
],
|
|
84
|
-
sourceMap: false,
|
|
85
|
-
},
|
|
76
|
+
production: {
|
|
77
|
+
fileReplacements: [
|
|
78
|
+
{
|
|
79
|
+
replace: `${projectRoot}/src/environments/environment.ts`,
|
|
80
|
+
with: `${projectRoot}/src/environments/environment.prod.ts`,
|
|
81
|
+
},
|
|
82
|
+
],
|
|
83
|
+
sourceMap: false,
|
|
86
84
|
},
|
|
87
|
-
},
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
'serve-browser': projectConfig.targets.serve,
|
|
88
|
+
'serve-server': {
|
|
89
|
+
executor: '@nx/js:node',
|
|
90
|
+
defaultConfiguration: 'development',
|
|
91
|
+
options: {
|
|
92
|
+
buildTarget: `${options.project}:server:development`,
|
|
93
|
+
buildTargetOptions: {
|
|
94
|
+
watch: true,
|
|
95
95
|
},
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
}
|
|
96
|
+
},
|
|
97
|
+
configurations: {
|
|
98
|
+
development: {},
|
|
99
|
+
production: {
|
|
100
|
+
buildTarget: `${options.project}:server:production`,
|
|
101
101
|
},
|
|
102
|
-
},
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
102
|
+
},
|
|
103
|
+
},
|
|
104
|
+
serve: {
|
|
105
|
+
executor: '@nx/webpack:ssr-dev-server',
|
|
106
|
+
defaultConfiguration: 'development',
|
|
107
|
+
options: {
|
|
108
|
+
browserTarget: `${options.project}:build:development`,
|
|
109
|
+
serverTarget: `${options.project}:serve-server:development`,
|
|
110
|
+
port: options.serverPort,
|
|
111
|
+
browserTargetOptions: {
|
|
112
|
+
watch: true,
|
|
112
113
|
},
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
}
|
|
114
|
+
},
|
|
115
|
+
configurations: {
|
|
116
|
+
development: {},
|
|
117
|
+
production: {
|
|
118
|
+
browserTarget: `${options.project}:build:production`,
|
|
119
|
+
serverTarget: `${options.project}:serve-server:production`,
|
|
119
120
|
},
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
return installTask;
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
};
|
|
124
|
+
(0, devkit_1.updateProjectConfiguration)(tree, options.project, projectConfig);
|
|
125
|
+
const nxJson = (0, devkit_1.readNxJson)(tree);
|
|
126
|
+
if (nxJson.tasksRunnerOptions?.default &&
|
|
127
|
+
!nxJson.tasksRunnerOptions.default.options.cacheableOperations.includes('server')) {
|
|
128
|
+
nxJson.tasksRunnerOptions.default.options.cacheableOperations = [
|
|
129
|
+
...nxJson.tasksRunnerOptions.default.options.cacheableOperations,
|
|
130
|
+
'server',
|
|
131
|
+
];
|
|
132
|
+
}
|
|
133
|
+
(0, devkit_1.generateFiles)(tree, (0, path_1.join)(__dirname, 'files'), projectRoot, {
|
|
134
|
+
tmpl: '',
|
|
135
|
+
extraInclude: options.extraInclude?.length > 0
|
|
136
|
+
? `"${options.extraInclude.join('", "')}",`
|
|
137
|
+
: '',
|
|
138
|
+
appComponentImport: appComponentInfo.importPath,
|
|
139
|
+
browserBuildOutputPath: projectConfig.targets.build.options.outputPath,
|
|
140
|
+
});
|
|
141
|
+
// Add <StaticRouter> to server main if needed.
|
|
142
|
+
// TODO: need to read main.server.tsx not main.tsx.
|
|
143
|
+
const appContent = tree.read(appComponentInfo.filePath, 'utf-8');
|
|
144
|
+
const isRouterPresent = appContent.match(/react-router-dom/);
|
|
145
|
+
if (isRouterPresent) {
|
|
146
|
+
const serverEntry = (0, devkit_1.joinPathFragments)(projectRoot, 'src/main.server.tsx');
|
|
147
|
+
const { content, source } = readEntryFile(tree, serverEntry);
|
|
148
|
+
const changes = (0, devkit_1.applyChangesToString)(content, (0, ast_utils_1.addStaticRouter)(serverEntry, source));
|
|
149
|
+
tree.write(serverEntry, changes);
|
|
150
|
+
}
|
|
151
|
+
(0, devkit_1.updateNxJson)(tree, nxJson);
|
|
152
|
+
const installTask = (0, devkit_1.addDependenciesToPackageJson)(tree, {
|
|
153
|
+
express: versions_1.expressVersion,
|
|
154
|
+
isbot: versions_1.isbotVersion,
|
|
155
|
+
cors: versions_1.corsVersion,
|
|
156
|
+
}, {
|
|
157
|
+
'@types/express': versions_1.typesExpressVersion,
|
|
158
|
+
'@types/cors': versions_1.typesCorsVersion,
|
|
159
159
|
});
|
|
160
|
+
await (0, devkit_1.formatFiles)(tree);
|
|
161
|
+
return installTask;
|
|
160
162
|
}
|
|
161
163
|
exports.setupSsrGenerator = setupSsrGenerator;
|
|
162
164
|
exports.default = setupSsrGenerator;
|
|
@@ -3,11 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.updateProject = void 0;
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
|
5
5
|
function updateProject(tree, config, options) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
((_d = (_c = config === null || config === void 0 ? void 0 : config.targets) === null || _c === void 0 ? void 0 : _c.build) === null || _d === void 0 ? void 0 : _d.executor) === '@nrwl/webpack:webpack') {
|
|
10
|
-
(_e = (_f = config.targets.build).options) !== null && _e !== void 0 ? _e : (_f.options = {});
|
|
6
|
+
if (config?.targets?.build?.executor === '@nx/webpack:webpack' ||
|
|
7
|
+
config?.targets?.build?.executor === '@nrwl/webpack:webpack') {
|
|
8
|
+
config.targets.build.options ??= {};
|
|
11
9
|
config.targets.build.options.postcssConfig = (0, devkit_1.joinPathFragments)(config.root, 'postcss.config.js');
|
|
12
10
|
(0, devkit_1.updateProjectConfiguration)(tree, options.project, config);
|
|
13
11
|
}
|
|
@@ -1,38 +1,35 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.setupTailwindSchematic = exports.setupTailwindGenerator = 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
6
|
const add_tailwind_style_imports_1 = require("./lib/add-tailwind-style-imports");
|
|
8
7
|
const update_project_1 = require("./lib/update-project");
|
|
9
8
|
const path_1 = require("path");
|
|
10
|
-
function setupTailwindGenerator(tree, options) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
tmpl: '',
|
|
21
|
-
});
|
|
22
|
-
(0, add_tailwind_style_imports_1.addTailwindStyleImports)(tree, project, options);
|
|
23
|
-
(0, update_project_1.updateProject)(tree, project, options);
|
|
24
|
-
if (!options.skipPackageJson) {
|
|
25
|
-
tasks.push((0, devkit_1.addDependenciesToPackageJson)(tree, {}, {
|
|
26
|
-
autoprefixer: versions_1.autoprefixerVersion,
|
|
27
|
-
postcss: versions_1.postcssVersion,
|
|
28
|
-
tailwindcss: versions_1.tailwindcssVersion,
|
|
29
|
-
}));
|
|
30
|
-
}
|
|
31
|
-
if (!options.skipFormat) {
|
|
32
|
-
yield (0, devkit_1.formatFiles)(tree);
|
|
33
|
-
}
|
|
34
|
-
return (0, devkit_1.runTasksInSerial)(...tasks);
|
|
9
|
+
async function setupTailwindGenerator(tree, options) {
|
|
10
|
+
const tasks = [];
|
|
11
|
+
const project = (0, devkit_1.readProjectConfiguration)(tree, options.project);
|
|
12
|
+
if (tree.exists((0, devkit_1.joinPathFragments)(project.root, 'postcss.config.js')) ||
|
|
13
|
+
tree.exists((0, devkit_1.joinPathFragments)(project.root, 'tailwind.config.js'))) {
|
|
14
|
+
devkit_1.logger.info(`Skipping setup since there are existing PostCSS or Tailwind configuration files. For manual setup instructions, see https://nx.dev/guides/using-tailwind-css-in-react.`);
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
(0, devkit_1.generateFiles)(tree, (0, path_1.join)(__dirname, './files'), project.root, {
|
|
18
|
+
tmpl: '',
|
|
35
19
|
});
|
|
20
|
+
(0, add_tailwind_style_imports_1.addTailwindStyleImports)(tree, project, options);
|
|
21
|
+
(0, update_project_1.updateProject)(tree, project, options);
|
|
22
|
+
if (!options.skipPackageJson) {
|
|
23
|
+
tasks.push((0, devkit_1.addDependenciesToPackageJson)(tree, {}, {
|
|
24
|
+
autoprefixer: versions_1.autoprefixerVersion,
|
|
25
|
+
postcss: versions_1.postcssVersion,
|
|
26
|
+
tailwindcss: versions_1.tailwindcssVersion,
|
|
27
|
+
}));
|
|
28
|
+
}
|
|
29
|
+
if (!options.skipFormat) {
|
|
30
|
+
await (0, devkit_1.formatFiles)(tree);
|
|
31
|
+
}
|
|
32
|
+
return (0, devkit_1.runTasksInSerial)(...tasks);
|
|
36
33
|
}
|
|
37
34
|
exports.setupTailwindGenerator = setupTailwindGenerator;
|
|
38
35
|
exports.default = setupTailwindGenerator;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.storiesSchematic = exports.storiesGenerator = exports.createAllStories = exports.containsComponentDeclaration = exports.projectRootPath = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
4
|
const component_story_1 = require("../component-story/component-story");
|
|
6
5
|
const component_cypress_spec_1 = require("../component-cypress-spec/component-cypress-spec");
|
|
7
6
|
const ast_utils_1 = require("../../utils/ast-utils");
|
|
@@ -11,31 +10,28 @@ const minimatch = require("minimatch");
|
|
|
11
10
|
const ensure_typescript_1 = require("@nx/js/src/utils/typescript/ensure-typescript");
|
|
12
11
|
const versions_1 = require("../../utils/versions");
|
|
13
12
|
let tsModule;
|
|
14
|
-
function projectRootPath(tree, config) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
projectDir = 'components';
|
|
23
|
-
}
|
|
24
|
-
else {
|
|
25
|
-
// apps/test-app/src/app
|
|
26
|
-
projectDir = 'app';
|
|
27
|
-
}
|
|
13
|
+
async function projectRootPath(tree, config) {
|
|
14
|
+
const { findStorybookAndBuildTargetsAndCompiler } = await Promise.resolve().then(() => require('@nx/storybook/src/utils/utilities'));
|
|
15
|
+
let projectDir;
|
|
16
|
+
if (config.projectType === 'application') {
|
|
17
|
+
const { nextBuildTarget } = findStorybookAndBuildTargetsAndCompiler(config.targets);
|
|
18
|
+
if (!!nextBuildTarget) {
|
|
19
|
+
// Next.js apps
|
|
20
|
+
projectDir = 'components';
|
|
28
21
|
}
|
|
29
|
-
else
|
|
30
|
-
//
|
|
31
|
-
projectDir = '
|
|
22
|
+
else {
|
|
23
|
+
// apps/test-app/src/app
|
|
24
|
+
projectDir = 'app';
|
|
32
25
|
}
|
|
33
|
-
|
|
34
|
-
|
|
26
|
+
}
|
|
27
|
+
else if (config.projectType == 'library') {
|
|
28
|
+
// libs/test-lib/src/lib
|
|
29
|
+
projectDir = 'lib';
|
|
30
|
+
}
|
|
31
|
+
return (0, devkit_1.joinPathFragments)(config.sourceRoot, projectDir);
|
|
35
32
|
}
|
|
36
33
|
exports.projectRootPath = projectRootPath;
|
|
37
34
|
function containsComponentDeclaration(tree, componentPath) {
|
|
38
|
-
var _a;
|
|
39
35
|
if (!tsModule) {
|
|
40
36
|
tsModule = (0, ensure_typescript_1.ensureTypescript)();
|
|
41
37
|
}
|
|
@@ -45,83 +41,78 @@ function containsComponentDeclaration(tree, componentPath) {
|
|
|
45
41
|
}
|
|
46
42
|
const sourceFile = tsModule.createSourceFile(componentPath, contents, tsModule.ScriptTarget.Latest, true);
|
|
47
43
|
return !!((0, ast_utils_1.getComponentNode)(sourceFile) ||
|
|
48
|
-
(
|
|
44
|
+
(0, ast_utils_1.findExportDeclarationsForJsx)(sourceFile)?.length);
|
|
49
45
|
}
|
|
50
46
|
exports.containsComponentDeclaration = containsComponentDeclaration;
|
|
51
|
-
function createAllStories(tree, projectName, interactionTests, js, projects, projectConfiguration, generateCypressSpecs, cypressProject, ignorePaths) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
componentPaths.push(path);
|
|
74
|
-
}
|
|
47
|
+
async function createAllStories(tree, projectName, interactionTests, js, projects, projectConfiguration, generateCypressSpecs, cypressProject, ignorePaths) {
|
|
48
|
+
const { isTheFileAStory } = await Promise.resolve().then(() => require('@nx/storybook/src/utils/utilities'));
|
|
49
|
+
const { sourceRoot, root } = projectConfiguration;
|
|
50
|
+
let componentPaths = [];
|
|
51
|
+
const projectPath = await projectRootPath(tree, projectConfiguration);
|
|
52
|
+
(0, devkit_1.visitNotIgnoredFiles)(tree, projectPath, (path) => {
|
|
53
|
+
// Ignore private files starting with "_".
|
|
54
|
+
if ((0, path_1.basename)(path).startsWith('_'))
|
|
55
|
+
return;
|
|
56
|
+
if (ignorePaths?.some((pattern) => minimatch(path, pattern)))
|
|
57
|
+
return;
|
|
58
|
+
if ((path.endsWith('.tsx') && !path.endsWith('.spec.tsx')) ||
|
|
59
|
+
(path.endsWith('.js') && !path.endsWith('.spec.js')) ||
|
|
60
|
+
(path.endsWith('.jsx') && !path.endsWith('.spec.jsx'))) {
|
|
61
|
+
// Check if file is NOT a story (either ts/tsx or js/jsx)
|
|
62
|
+
if (!isTheFileAStory(tree, path)) {
|
|
63
|
+
// Since the file is not a story
|
|
64
|
+
// Let's see if the .stories.* file exists
|
|
65
|
+
const ext = path.slice(path.lastIndexOf('.'));
|
|
66
|
+
const storyPath = `${path.split(ext)[0]}.stories${ext}`;
|
|
67
|
+
if (!tree.exists(storyPath)) {
|
|
68
|
+
componentPaths.push(path);
|
|
75
69
|
}
|
|
76
70
|
}
|
|
77
|
-
});
|
|
78
|
-
const e2eProjectName = cypressProject || `${projectName}-e2e`;
|
|
79
|
-
const e2eProject = projects.get(e2eProjectName);
|
|
80
|
-
if (generateCypressSpecs && !e2eProject) {
|
|
81
|
-
devkit_1.logger.info(`There was no e2e project "${e2eProjectName}" found, so cypress specs will not be generated. Pass "--cypressProject" to specify a different e2e project name`);
|
|
82
71
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
72
|
+
});
|
|
73
|
+
const e2eProjectName = cypressProject || `${projectName}-e2e`;
|
|
74
|
+
const e2eProject = projects.get(e2eProjectName);
|
|
75
|
+
if (generateCypressSpecs && !e2eProject) {
|
|
76
|
+
devkit_1.logger.info(`There was no e2e project "${e2eProjectName}" found, so cypress specs will not be generated. Pass "--cypressProject" to specify a different e2e project name`);
|
|
77
|
+
}
|
|
78
|
+
await Promise.all(componentPaths.map(async (componentPath) => {
|
|
79
|
+
const relativeCmpDir = componentPath.replace((0, path_1.join)(sourceRoot, '/'), '');
|
|
80
|
+
if (!containsComponentDeclaration(tree, componentPath)) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
await (0, component_story_1.default)(tree, {
|
|
84
|
+
componentPath: relativeCmpDir,
|
|
85
|
+
project: projectName,
|
|
86
|
+
skipFormat: true,
|
|
87
|
+
interactionTests,
|
|
88
|
+
});
|
|
89
|
+
if (generateCypressSpecs && e2eProject) {
|
|
90
|
+
await (0, component_cypress_spec_1.default)(tree, {
|
|
90
91
|
project: projectName,
|
|
92
|
+
componentPath: relativeCmpDir,
|
|
93
|
+
js,
|
|
94
|
+
cypressProject,
|
|
91
95
|
skipFormat: true,
|
|
92
|
-
interactionTests,
|
|
93
96
|
});
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
project: projectName,
|
|
97
|
-
componentPath: relativeCmpDir,
|
|
98
|
-
js,
|
|
99
|
-
cypressProject,
|
|
100
|
-
skipFormat: true,
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
})));
|
|
104
|
-
});
|
|
97
|
+
}
|
|
98
|
+
}));
|
|
105
99
|
}
|
|
106
100
|
exports.createAllStories = createAllStories;
|
|
107
|
-
function storiesGenerator(host, schema) {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
const
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
}
|
|
123
|
-
return (0, devkit_1.runTasksInSerial)(...tasks);
|
|
124
|
-
});
|
|
101
|
+
async function storiesGenerator(host, schema) {
|
|
102
|
+
const projects = (0, devkit_1.getProjects)(host);
|
|
103
|
+
const projectConfiguration = projects.get(schema.project);
|
|
104
|
+
schema.interactionTests = schema.interactionTests ?? true;
|
|
105
|
+
await createAllStories(host, schema.project, schema.interactionTests, schema.js, projects, projectConfiguration, schema.generateCypressSpecs, schema.cypressProject, schema.ignorePaths);
|
|
106
|
+
const tasks = [];
|
|
107
|
+
if (schema.interactionTests) {
|
|
108
|
+
const { interactionTestsDependencies, addInteractionsInAddons } = (0, devkit_1.ensurePackage)('@nx/storybook', versions_1.nxVersion);
|
|
109
|
+
tasks.push((0, devkit_1.addDependenciesToPackageJson)(host, {}, interactionTestsDependencies()));
|
|
110
|
+
addInteractionsInAddons(host, projectConfiguration);
|
|
111
|
+
}
|
|
112
|
+
if (!schema.skipFormat) {
|
|
113
|
+
await (0, devkit_1.formatFiles)(host);
|
|
114
|
+
}
|
|
115
|
+
return (0, devkit_1.runTasksInSerial)(...tasks);
|
|
125
116
|
}
|
|
126
117
|
exports.storiesGenerator = storiesGenerator;
|
|
127
118
|
exports.default = storiesGenerator;
|