@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.
Files changed (76) hide show
  1. package/babel.js +2 -3
  2. package/package.json +7 -7
  3. package/plugins/bundle-rollup.js +9 -3
  4. package/plugins/component-testing/index.js +57 -37
  5. package/plugins/jest.js +4 -6
  6. package/plugins/storybook/index.js +46 -17
  7. package/plugins/with-react.js +5 -9
  8. package/src/executors/module-federation-dev-server/module-federation-dev-server.impl.js +101 -103
  9. package/src/executors/module-federation-ssr-dev-server/module-federation-ssr-dev-server.impl.js +67 -72
  10. package/src/generators/application/application.js +124 -124
  11. package/src/generators/application/lib/add-e2e.js +41 -37
  12. package/src/generators/application/lib/add-jest.js +13 -8
  13. package/src/generators/application/lib/add-project.js +4 -3
  14. package/src/generators/application/lib/create-application-files.js +8 -1
  15. package/src/generators/application/lib/find-free-port.js +1 -2
  16. package/src/generators/application/lib/normalize-options.js +49 -47
  17. package/src/generators/application/lib/set-defaults.js +25 -5
  18. package/src/generators/component/component.js +68 -64
  19. package/src/generators/component-cypress-spec/component-cypress-spec.js +6 -9
  20. package/src/generators/component-story/component-story.js +8 -9
  21. package/src/generators/component-test/component-test.js +15 -18
  22. package/src/generators/cypress-component-configuration/cypress-component-configuration.js +23 -26
  23. package/src/generators/cypress-component-configuration/lib/add-files.js +38 -42
  24. package/src/generators/hook/hook.js +59 -58
  25. package/src/generators/host/host.js +54 -53
  26. package/src/generators/host/lib/add-module-federation-files.js +11 -3
  27. package/src/generators/host/lib/normalize-remote.js +8 -11
  28. package/src/generators/host/lib/setup-ssr-for-host.js +21 -15
  29. package/src/generators/host/lib/update-module-federation-e2e-project.js +5 -2
  30. package/src/generators/init/init.js +30 -20
  31. package/src/generators/library/lib/add-linting.js +24 -27
  32. package/src/generators/library/lib/add-rollup-build-target.js +42 -46
  33. package/src/generators/library/lib/create-files.js +7 -1
  34. package/src/generators/library/lib/normalize-options.js +53 -50
  35. package/src/generators/library/lib/set-defaults.js +12 -4
  36. package/src/generators/library/library.js +122 -111
  37. package/src/generators/redux/redux.js +25 -16
  38. package/src/generators/remote/lib/setup-ssr-for-remote.js +25 -23
  39. package/src/generators/remote/remote.js +44 -39
  40. package/src/generators/setup-ssr/setup-ssr.js +134 -132
  41. package/src/generators/setup-tailwind/lib/update-project.js +3 -5
  42. package/src/generators/setup-tailwind/setup-tailwind.js +23 -26
  43. package/src/generators/stories/stories.js +79 -88
  44. package/src/generators/storybook-configuration/configuration.js +40 -47
  45. package/src/migrations/update-12-0-0/remove-react-redux-types-package.js +2 -5
  46. package/src/migrations/update-12-0-0/update-emotion-setup.js +50 -55
  47. package/src/migrations/update-12-0-0/use-react-jsx-in-tsconfig.js +14 -18
  48. package/src/migrations/update-12-8-0/update-12-8-0.js +3 -6
  49. package/src/migrations/update-13-0-0/migrate-storybook-to-webpack-5.js +23 -26
  50. package/src/migrations/update-13-0-0/update-emotion-setup.js +24 -27
  51. package/src/migrations/update-13-0-0/webpack5-changes-utils.js +30 -34
  52. package/src/migrations/update-13-10-0/update-13-10-0.js +15 -18
  53. package/src/migrations/update-14-0-0/add-default-development-configurations.js +26 -31
  54. package/src/migrations/update-14-0-0/replace-testing-library-react-hook.js +12 -16
  55. package/src/migrations/update-14-0-0/update-react-dom-render-for-v18.js +13 -17
  56. package/src/migrations/update-14-1-0/update-external-emotion-jsx-runtime.js +24 -27
  57. package/src/migrations/update-14-6-0/add-preset-jest-config.js +1 -2
  58. package/src/migrations/update-15-3-0/install-webpack-rollup-dependencies.js +3 -4
  59. package/src/migrations/update-15-3-0/update-rollup-executor.js +1 -2
  60. package/src/migrations/update-15-6-3/webpack-config-setup.js +56 -60
  61. package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.js +3 -6
  62. package/src/migrations/update-16-2-0-remove-package/update-16-2-0-remove-package.js +3 -6
  63. package/src/migrations/update-16-3-0/remove-types-react-router-dom-package.js +3 -6
  64. package/src/migrations/update-16-7-0/add-babel-core.js +8 -11
  65. package/src/migrations/update-16-7-0-add-typings/update-16-7-0-add-typings.js +36 -41
  66. package/src/module-federation/ast-utils.js +1 -1
  67. package/src/module-federation/load-config.js +1 -1
  68. package/src/module-federation/utils.js +36 -37
  69. package/src/module-federation/with-module-federation-ssr.js +24 -25
  70. package/src/module-federation/with-module-federation.js +23 -22
  71. package/src/rules/update-module-federation-project.js +9 -2
  72. package/src/utils/ast-utils.js +12 -15
  73. package/src/utils/create-ts-config.js +6 -4
  74. package/src/utils/ct-utils.js +31 -33
  75. package/src/utils/lint.js +5 -3
  76. 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
- var _a, _b, _c, _d, _e;
24
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
25
- yield (0, init_1.default)(tree, { skipFormat: true });
26
- const projectConfig = (0, devkit_1.readProjectConfiguration)(tree, options.project);
27
- const projectRoot = projectConfig.root;
28
- const appImportCandidates = [
29
- (_a = options.appComponentImportPath) !== null && _a !== void 0 ? _a : 'app/app',
30
- 'app',
31
- 'App',
32
- 'app/App',
33
- 'App/App',
34
- ].map((importPath) => {
35
- return {
36
- importPath,
37
- filePath: (0, devkit_1.joinPathFragments)(projectConfig.sourceRoot || projectConfig.root, `${importPath}.tsx`),
38
- };
39
- });
40
- const appComponentInfo = appImportCandidates.find((candidate) => tree.exists(candidate.filePath));
41
- if (!appComponentInfo) {
42
- throw new Error(`Cannot find an import path for <App/> component. Try passing setting --appComponentImportPath option.`);
43
- }
44
- if (!projectConfig.targets.build || !projectConfig.targets.serve) {
45
- throw new Error(`Project ${options.project} does not have build and serve targets`);
46
- }
47
- if (projectConfig.targets.server) {
48
- throw new Error(`Project ${options.project} already has a server target.`);
49
- }
50
- const originalOutputPath = (_c = (_b = projectConfig.targets.build) === null || _b === void 0 ? void 0 : _b.options) === null || _c === void 0 ? void 0 : _c.outputPath;
51
- if (!originalOutputPath) {
52
- throw new Error(`Project ${options.project} does not contain a outputPath for the build target.`);
53
- }
54
- projectConfig.targets.build.options.outputPath = (0, devkit_1.joinPathFragments)(originalOutputPath, 'browser');
55
- projectConfig.targets = Object.assign(Object.assign({}, projectConfig.targets), { server: {
56
- dependsOn: ['build'],
57
- executor: '@nx/webpack:webpack',
58
- outputs: ['{options.outputPath}'],
59
- defaultConfiguration: 'production',
60
- options: {
61
- target: 'node',
62
- main: `${projectRoot}/server.ts`,
63
- outputPath: (0, devkit_1.joinPathFragments)(originalOutputPath, 'server'),
64
- outputFileName: 'server.js',
65
- tsConfig: `${projectRoot}/tsconfig.server.json`,
66
- compiler: 'babel',
67
- externalDependencies: 'all',
68
- outputHashing: 'none',
69
- isolatedConfig: true,
70
- webpackConfig: (0, devkit_1.joinPathFragments)(projectRoot, 'webpack.config.js'),
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
- configurations: {
73
- development: {
74
- optimization: false,
75
- sourceMap: true,
76
- },
77
- production: {
78
- fileReplacements: [
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
- }, 'serve-browser': projectConfig.targets.serve, 'serve-server': {
88
- executor: '@nx/js:node',
89
- defaultConfiguration: 'development',
90
- options: {
91
- buildTarget: `${options.project}:server:development`,
92
- buildTargetOptions: {
93
- watch: true,
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
- configurations: {
97
- development: {},
98
- production: {
99
- buildTarget: `${options.project}:server:production`,
100
- },
96
+ },
97
+ configurations: {
98
+ development: {},
99
+ production: {
100
+ buildTarget: `${options.project}:server:production`,
101
101
  },
102
- }, serve: {
103
- executor: '@nx/webpack:ssr-dev-server',
104
- defaultConfiguration: 'development',
105
- options: {
106
- browserTarget: `${options.project}:build:development`,
107
- serverTarget: `${options.project}:serve-server:development`,
108
- port: options.serverPort,
109
- browserTargetOptions: {
110
- watch: true,
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
- configurations: {
114
- development: {},
115
- production: {
116
- browserTarget: `${options.project}:build:production`,
117
- serverTarget: `${options.project}:serve-server:production`,
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
- (0, devkit_1.updateProjectConfiguration)(tree, options.project, projectConfig);
122
- const nxJson = (0, devkit_1.readNxJson)(tree);
123
- if (((_d = nxJson.tasksRunnerOptions) === null || _d === void 0 ? void 0 : _d.default) &&
124
- !nxJson.tasksRunnerOptions.default.options.cacheableOperations.includes('server')) {
125
- nxJson.tasksRunnerOptions.default.options.cacheableOperations = [
126
- ...nxJson.tasksRunnerOptions.default.options.cacheableOperations,
127
- 'server',
128
- ];
129
- }
130
- (0, devkit_1.generateFiles)(tree, (0, path_1.join)(__dirname, 'files'), projectRoot, {
131
- tmpl: '',
132
- extraInclude: ((_e = options.extraInclude) === null || _e === void 0 ? void 0 : _e.length) > 0
133
- ? `"${options.extraInclude.join('", "')}",`
134
- : '',
135
- appComponentImport: appComponentInfo.importPath,
136
- browserBuildOutputPath: projectConfig.targets.build.options.outputPath,
137
- });
138
- // Add <StaticRouter> to server main if needed.
139
- // TODO: need to read main.server.tsx not main.tsx.
140
- const appContent = tree.read(appComponentInfo.filePath, 'utf-8');
141
- const isRouterPresent = appContent.match(/react-router-dom/);
142
- if (isRouterPresent) {
143
- const serverEntry = (0, devkit_1.joinPathFragments)(projectRoot, 'src/main.server.tsx');
144
- const { content, source } = readEntryFile(tree, serverEntry);
145
- const changes = (0, devkit_1.applyChangesToString)(content, (0, ast_utils_1.addStaticRouter)(serverEntry, source));
146
- tree.write(serverEntry, changes);
147
- }
148
- (0, devkit_1.updateNxJson)(tree, nxJson);
149
- const installTask = (0, devkit_1.addDependenciesToPackageJson)(tree, {
150
- express: versions_1.expressVersion,
151
- isbot: versions_1.isbotVersion,
152
- cors: versions_1.corsVersion,
153
- }, {
154
- '@types/express': versions_1.typesExpressVersion,
155
- '@types/cors': versions_1.typesCorsVersion,
156
- });
157
- yield (0, devkit_1.formatFiles)(tree);
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
- var _a, _b, _c, _d, _e;
7
- var _f;
8
- if (((_b = (_a = config === null || config === void 0 ? void 0 : config.targets) === null || _a === void 0 ? void 0 : _a.build) === null || _b === void 0 ? void 0 : _b.executor) === '@nx/webpack:webpack' ||
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
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
12
- const tasks = [];
13
- const project = (0, devkit_1.readProjectConfiguration)(tree, options.project);
14
- if (tree.exists((0, devkit_1.joinPathFragments)(project.root, 'postcss.config.js')) ||
15
- tree.exists((0, devkit_1.joinPathFragments)(project.root, 'tailwind.config.js'))) {
16
- 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.`);
17
- return;
18
- }
19
- (0, devkit_1.generateFiles)(tree, (0, path_1.join)(__dirname, './files'), project.root, {
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
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
16
- const { findStorybookAndBuildTargetsAndCompiler } = yield Promise.resolve().then(() => require('@nx/storybook/src/utils/utilities'));
17
- let projectDir;
18
- if (config.projectType === 'application') {
19
- const { nextBuildTarget } = findStorybookAndBuildTargetsAndCompiler(config.targets);
20
- if (!!nextBuildTarget) {
21
- // Next.js apps
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 if (config.projectType == 'library') {
30
- // libs/test-lib/src/lib
31
- projectDir = 'lib';
22
+ else {
23
+ // apps/test-app/src/app
24
+ projectDir = 'app';
32
25
  }
33
- return (0, devkit_1.joinPathFragments)(config.sourceRoot, projectDir);
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
- ((_a = (0, ast_utils_1.findExportDeclarationsForJsx)(sourceFile)) === null || _a === void 0 ? void 0 : _a.length));
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
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
53
- const { isTheFileAStory } = yield Promise.resolve().then(() => require('@nx/storybook/src/utils/utilities'));
54
- const { sourceRoot, root } = projectConfiguration;
55
- let componentPaths = [];
56
- const projectPath = yield projectRootPath(tree, projectConfiguration);
57
- (0, devkit_1.visitNotIgnoredFiles)(tree, projectPath, (path) => {
58
- // Ignore private files starting with "_".
59
- if ((0, path_1.basename)(path).startsWith('_'))
60
- return;
61
- if (ignorePaths === null || ignorePaths === void 0 ? void 0 : ignorePaths.some((pattern) => minimatch(path, pattern)))
62
- return;
63
- if ((path.endsWith('.tsx') && !path.endsWith('.spec.tsx')) ||
64
- (path.endsWith('.js') && !path.endsWith('.spec.js')) ||
65
- (path.endsWith('.jsx') && !path.endsWith('.spec.jsx'))) {
66
- // Check if file is NOT a story (either ts/tsx or js/jsx)
67
- if (!isTheFileAStory(tree, path)) {
68
- // Since the file is not a story
69
- // Let's see if the .stories.* file exists
70
- const ext = path.slice(path.lastIndexOf('.'));
71
- const storyPath = `${path.split(ext)[0]}.stories${ext}`;
72
- if (!tree.exists(storyPath)) {
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
- yield Promise.all(componentPaths.map((componentPath) => tslib_1.__awaiter(this, void 0, void 0, function* () {
84
- const relativeCmpDir = componentPath.replace((0, path_1.join)(sourceRoot, '/'), '');
85
- if (!containsComponentDeclaration(tree, componentPath)) {
86
- return;
87
- }
88
- yield (0, component_story_1.default)(tree, {
89
- componentPath: relativeCmpDir,
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
- if (generateCypressSpecs && e2eProject) {
95
- yield (0, component_cypress_spec_1.default)(tree, {
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
- var _a;
109
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
110
- const projects = (0, devkit_1.getProjects)(host);
111
- const projectConfiguration = projects.get(schema.project);
112
- schema.interactionTests = (_a = schema.interactionTests) !== null && _a !== void 0 ? _a : true;
113
- yield createAllStories(host, schema.project, schema.interactionTests, schema.js, projects, projectConfiguration, schema.generateCypressSpecs, schema.cypressProject, schema.ignorePaths);
114
- const tasks = [];
115
- if (schema.interactionTests) {
116
- const { interactionTestsDependencies, addInteractionsInAddons } = (0, devkit_1.ensurePackage)('@nx/storybook', versions_1.nxVersion);
117
- tasks.push((0, devkit_1.addDependenciesToPackageJson)(host, {}, interactionTestsDependencies()));
118
- addInteractionsInAddons(host, projectConfiguration);
119
- }
120
- if (!schema.skipFormat) {
121
- yield (0, devkit_1.formatFiles)(host);
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;