@nx/storybook 16.8.0-beta.0 → 16.8.0-beta.2
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/package.json +8 -9
- package/src/executors/build-storybook/build-storybook.impl.d.ts +0 -1
- package/src/executors/build-storybook/build-storybook.impl.js +0 -1
- package/src/executors/storybook/storybook.impl.d.ts +0 -1
- package/src/executors/storybook/storybook.impl.js +0 -1
- package/src/executors/utils.d.ts +0 -1
- package/src/executors/utils.js +0 -1
- package/src/generators/configuration/configuration.js +8 -0
- package/src/generators/configuration/lib/util-functions.d.ts +1 -1
- package/src/generators/configuration/lib/util-functions.js +44 -25
- package/src/generators/configuration/project-files/.storybook/main.js__tmpl__ +14 -3
- package/src/generators/configuration/project-files-ts/.storybook/main.ts__tmpl__ +13 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/storybook",
|
|
3
|
-
"version": "16.8.0-beta.
|
|
3
|
+
"version": "16.8.0-beta.2",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "The Nx Plugin for Storybook contains executors and generators for allowing your workspace to use the powerful Storybook integration testing & documenting capabilities.",
|
|
6
6
|
"repository": {
|
|
@@ -30,14 +30,13 @@
|
|
|
30
30
|
"migrations": "./migrations.json"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@nrwl/storybook": "16.8.0-beta.
|
|
34
|
-
"@nx/cypress": "16.8.0-beta.
|
|
35
|
-
"@nx/devkit": "16.8.0-beta.
|
|
36
|
-
"@nx/js": "16.8.0-beta.
|
|
37
|
-
"@nx/linter": "16.8.0-beta.
|
|
38
|
-
"@nx/workspace": "16.8.0-beta.
|
|
33
|
+
"@nrwl/storybook": "16.8.0-beta.2",
|
|
34
|
+
"@nx/cypress": "16.8.0-beta.2",
|
|
35
|
+
"@nx/devkit": "16.8.0-beta.2",
|
|
36
|
+
"@nx/js": "16.8.0-beta.2",
|
|
37
|
+
"@nx/linter": "16.8.0-beta.2",
|
|
38
|
+
"@nx/workspace": "16.8.0-beta.2",
|
|
39
39
|
"@phenomnomnominal/tsquery": "~5.0.1",
|
|
40
|
-
"dotenv": "~16.3.1",
|
|
41
40
|
"semver": "7.5.3",
|
|
42
41
|
"tslib": "^2.3.0"
|
|
43
42
|
},
|
|
@@ -45,5 +44,5 @@
|
|
|
45
44
|
"access": "public"
|
|
46
45
|
},
|
|
47
46
|
"type": "commonjs",
|
|
48
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "9bcc04742f9e1516d8c1ddbfb1907770c347876f"
|
|
49
48
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { ExecutorContext } from '@nx/devkit';
|
|
2
2
|
import { CLIOptions } from '@storybook/types';
|
|
3
|
-
import 'dotenv/config';
|
|
4
3
|
import { CommonNxStorybookConfig } from '../../utils/models';
|
|
5
4
|
export default function buildStorybookExecutor(options: CLIOptions & CommonNxStorybookConfig, context: ExecutorContext): Promise<{
|
|
6
5
|
success: boolean;
|
|
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
|
5
5
|
const build = require("@storybook/core-server");
|
|
6
|
-
require("dotenv/config");
|
|
7
6
|
const utilities_1 = require("../../utils/utilities");
|
|
8
7
|
const utils_1 = require("../utils");
|
|
9
8
|
function buildStorybookExecutor(options, context) {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { ExecutorContext } from '@nx/devkit';
|
|
2
|
-
import 'dotenv/config';
|
|
3
2
|
import { CLIOptions } from '@storybook/types';
|
|
4
3
|
import { CommonNxStorybookConfig } from '../../utils/models';
|
|
5
4
|
export default function storybookExecutor(options: CLIOptions & CommonNxStorybookConfig, context: ExecutorContext): AsyncGenerator<{
|
|
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
|
5
5
|
const build = require("@storybook/core-server");
|
|
6
|
-
require("dotenv/config");
|
|
7
6
|
const utilities_1 = require("../../utils/utilities");
|
|
8
7
|
const utils_1 = require("../utils");
|
|
9
8
|
function storybookExecutor(options, context) {
|
package/src/executors/utils.d.ts
CHANGED
package/src/executors/utils.js
CHANGED
|
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
4
4
|
exports.builderIsWebpackButNotWebpack5 = exports.runStorybookSetupCheck = exports.getStorybookFrameworkPath = void 0;
|
|
5
5
|
const devkit_1 = require("@nx/devkit");
|
|
6
6
|
const js_1 = require("@nx/js");
|
|
7
|
-
require("dotenv/config");
|
|
8
7
|
const fs_1 = require("fs");
|
|
9
8
|
const path_1 = require("path");
|
|
10
9
|
const semver_1 = require("semver");
|
|
@@ -99,6 +99,14 @@ function configurationGenerator(tree, rawSchema) {
|
|
|
99
99
|
schema.uiFramework === '@storybook/react-webpack5') {
|
|
100
100
|
devDeps['core-js'] = versions_1.coreJsVersion;
|
|
101
101
|
}
|
|
102
|
+
if (schema.uiFramework.endsWith('-vite') &&
|
|
103
|
+
(!viteBuildTarget || !viteConfigFilePath)) {
|
|
104
|
+
// This means that the user has selected a Vite framework
|
|
105
|
+
// but the project does not have Vite configuration.
|
|
106
|
+
// We need to install the @nx/vite plugin in order to be able to use
|
|
107
|
+
// the nxViteTsPaths plugin to register the tsconfig paths in Vite.
|
|
108
|
+
devDeps['@nx/vite'] = versions_1.nxVersion;
|
|
109
|
+
}
|
|
102
110
|
tasks.push((0, devkit_1.addDependenciesToPackageJson)(tree, {}, devDeps));
|
|
103
111
|
if (!schema.skipFormat) {
|
|
104
112
|
yield (0, devkit_1.formatFiles)(tree);
|
|
@@ -14,7 +14,7 @@ export declare function configureTsSolutionConfig(tree: Tree, schema: StorybookC
|
|
|
14
14
|
* which includes *.stories files.
|
|
15
15
|
*
|
|
16
16
|
* For TSLint this is done via the builder config, for ESLint this is
|
|
17
|
-
* done within the
|
|
17
|
+
* done within the eslint config file.
|
|
18
18
|
*/
|
|
19
19
|
export declare function updateLintConfig(tree: Tree, schema: StorybookConfigureSchema): void;
|
|
20
20
|
export declare function normalizeSchema(schema: StorybookConfigureSchema): StorybookConfigureSchema;
|
|
@@ -8,6 +8,8 @@ const linter_1 = require("@nx/linter");
|
|
|
8
8
|
const path_1 = require("path");
|
|
9
9
|
const utilities_1 = require("../../../utils/utilities");
|
|
10
10
|
const versions_1 = require("../../../utils/versions");
|
|
11
|
+
const eslint_file_1 = require("@nx/linter/src/generators/utils/eslint-file");
|
|
12
|
+
const flat_config_1 = require("@nx/linter/src/utils/flat-config");
|
|
11
13
|
const DEFAULT_PORT = 4400;
|
|
12
14
|
function addStorybookTask(tree, projectName, uiFramework, interactionTests) {
|
|
13
15
|
if (uiFramework === '@storybook/react-native') {
|
|
@@ -115,7 +117,7 @@ function createStorybookTsconfigFile(tree, projectRoot, uiFramework, isRootProje
|
|
|
115
117
|
const oldStorybookTsConfigPath = (0, devkit_1.joinPathFragments)(projectRoot, '.storybook/tsconfig.json');
|
|
116
118
|
if (tree.exists(oldStorybookTsConfigPath)) {
|
|
117
119
|
devkit_1.logger.warn(`.storybook/tsconfig.json already exists for this project`);
|
|
118
|
-
devkit_1.logger.warn(`It will be renamed and moved to tsconfig.storybook.json.
|
|
120
|
+
devkit_1.logger.warn(`It will be renamed and moved to tsconfig.storybook.json.
|
|
119
121
|
Please make sure all settings look correct after this change.
|
|
120
122
|
Also, please make sure to use "nx migrate" to move from one version of Nx to another.
|
|
121
123
|
`);
|
|
@@ -252,30 +254,52 @@ exports.configureTsSolutionConfig = configureTsSolutionConfig;
|
|
|
252
254
|
* which includes *.stories files.
|
|
253
255
|
*
|
|
254
256
|
* For TSLint this is done via the builder config, for ESLint this is
|
|
255
|
-
* done within the
|
|
257
|
+
* done within the eslint config file.
|
|
256
258
|
*/
|
|
257
259
|
function updateLintConfig(tree, schema) {
|
|
258
260
|
const { name: projectName } = schema;
|
|
259
261
|
const { targets, root } = (0, devkit_1.readProjectConfiguration)(tree, projectName);
|
|
260
|
-
const tslintTargets = Object.values(targets).filter((target) => target.executor === '@angular-devkit/build-angular:tslint');
|
|
262
|
+
const tslintTargets = Object.values(targets !== null && targets !== void 0 ? targets : {}).filter((target) => target.executor === '@angular-devkit/build-angular:tslint');
|
|
261
263
|
tslintTargets.forEach((target) => {
|
|
262
264
|
target.options.tsConfig = (0, utilities_1.dedupe)([
|
|
263
265
|
...target.options.tsConfig,
|
|
264
266
|
(0, devkit_1.joinPathFragments)(root, './.storybook/tsconfig.json'),
|
|
265
267
|
]);
|
|
266
268
|
});
|
|
267
|
-
|
|
268
|
-
|
|
269
|
+
const eslintFile = (0, eslint_file_1.findEslintFile)(tree, root);
|
|
270
|
+
if (!eslintFile) {
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
const parserConfigPath = (0, path_1.join)(root, schema.uiFramework === '@storybook/angular'
|
|
274
|
+
? '.storybook/tsconfig.json'
|
|
275
|
+
: 'tsconfig.storybook.json');
|
|
276
|
+
if ((0, flat_config_1.useFlatConfig)(tree)) {
|
|
277
|
+
let config = tree.read(eslintFile, 'utf-8');
|
|
278
|
+
const projectRegex = RegExp(/project:\s?\[?['"](.*)['"]\]?/g);
|
|
279
|
+
let match;
|
|
280
|
+
while ((match = projectRegex.exec(config)) !== null) {
|
|
281
|
+
const matchSet = new Set(match[1].split(',').map((p) => p.trim().replace(/['"]/g, '')));
|
|
282
|
+
matchSet.add(parserConfigPath);
|
|
283
|
+
const insert = `project: [${Array.from(matchSet)
|
|
284
|
+
.map((p) => `'${p}'`)
|
|
285
|
+
.join(', ')}]`;
|
|
286
|
+
config =
|
|
287
|
+
config.slice(0, match.index) +
|
|
288
|
+
insert +
|
|
289
|
+
config.slice(match.index + match[0].length);
|
|
290
|
+
}
|
|
291
|
+
tree.write(eslintFile, config);
|
|
292
|
+
}
|
|
293
|
+
else {
|
|
294
|
+
(0, devkit_1.updateJson)(tree, (0, path_1.join)(root, eslintFile), (json) => {
|
|
269
295
|
var _a, _b, _c, _d;
|
|
270
296
|
if (typeof ((_a = json.parserOptions) === null || _a === void 0 ? void 0 : _a.project) === 'string') {
|
|
271
297
|
json.parserOptions.project = [json.parserOptions.project];
|
|
272
298
|
}
|
|
273
|
-
if (
|
|
299
|
+
if ((_b = json.parserOptions) === null || _b === void 0 ? void 0 : _b.project) {
|
|
274
300
|
json.parserOptions.project = (0, utilities_1.dedupe)([
|
|
275
301
|
...json.parserOptions.project,
|
|
276
|
-
|
|
277
|
-
? (0, path_1.join)(root, '.storybook/tsconfig.json')
|
|
278
|
-
: (0, path_1.join)(root, 'tsconfig.storybook.json'),
|
|
302
|
+
parserConfigPath,
|
|
279
303
|
]);
|
|
280
304
|
}
|
|
281
305
|
const overrides = json.overrides || [];
|
|
@@ -283,12 +307,10 @@ function updateLintConfig(tree, schema) {
|
|
|
283
307
|
if (typeof ((_c = o.parserOptions) === null || _c === void 0 ? void 0 : _c.project) === 'string') {
|
|
284
308
|
o.parserOptions.project = [o.parserOptions.project];
|
|
285
309
|
}
|
|
286
|
-
if (
|
|
310
|
+
if ((_d = o.parserOptions) === null || _d === void 0 ? void 0 : _d.project) {
|
|
287
311
|
o.parserOptions.project = (0, utilities_1.dedupe)([
|
|
288
312
|
...o.parserOptions.project,
|
|
289
|
-
|
|
290
|
-
? (0, path_1.join)(root, '.storybook/tsconfig.json')
|
|
291
|
-
: (0, path_1.join)(root, 'tsconfig.storybook.json'),
|
|
313
|
+
parserConfigPath,
|
|
292
314
|
]);
|
|
293
315
|
}
|
|
294
316
|
}
|
|
@@ -418,14 +440,14 @@ function workspaceHasRootProject(tree) {
|
|
|
418
440
|
exports.workspaceHasRootProject = workspaceHasRootProject;
|
|
419
441
|
function rootFileIsTs(tree, rootFileName, tsConfiguration) {
|
|
420
442
|
if (tree.exists(`.storybook/${rootFileName}.ts`) && !tsConfiguration) {
|
|
421
|
-
devkit_1.logger.info(`The root Storybook configuration is in TypeScript,
|
|
422
|
-
so Nx will generate TypeScript Storybook configuration files
|
|
443
|
+
devkit_1.logger.info(`The root Storybook configuration is in TypeScript,
|
|
444
|
+
so Nx will generate TypeScript Storybook configuration files
|
|
423
445
|
in this project's .storybook folder as well.`);
|
|
424
446
|
return true;
|
|
425
447
|
}
|
|
426
448
|
else if (tree.exists(`.storybook/${rootFileName}.js`) && tsConfiguration) {
|
|
427
|
-
devkit_1.logger.info(`The root Storybook configuration is in JavaScript,
|
|
428
|
-
so Nx will generate JavaScript Storybook configuration files
|
|
449
|
+
devkit_1.logger.info(`The root Storybook configuration is in JavaScript,
|
|
450
|
+
so Nx will generate JavaScript Storybook configuration files
|
|
429
451
|
in this project's .storybook folder as well.`);
|
|
430
452
|
return false;
|
|
431
453
|
}
|
|
@@ -511,14 +533,11 @@ function renameAndMoveOldTsConfig(projectRoot, pathToStorybookConfigFile, tree)
|
|
|
511
533
|
return json;
|
|
512
534
|
});
|
|
513
535
|
}
|
|
514
|
-
const
|
|
515
|
-
if (
|
|
516
|
-
(0, devkit_1.
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
json = JSON.parse(newJsonString);
|
|
520
|
-
return json;
|
|
521
|
-
});
|
|
536
|
+
const eslintFile = (0, eslint_file_1.findEslintFile)(tree, projectRoot);
|
|
537
|
+
if (eslintFile) {
|
|
538
|
+
const fileName = (0, devkit_1.joinPathFragments)(projectRoot, eslintFile);
|
|
539
|
+
const config = tree.read(fileName, 'utf-8');
|
|
540
|
+
tree.write(fileName, config.replace(/\.storybook\/tsconfig\.json/g, 'tsconfig.storybook.json'));
|
|
522
541
|
}
|
|
523
542
|
}
|
|
524
543
|
exports.renameAndMoveOldTsConfig = renameAndMoveOldTsConfig;
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
<% if (usesVite && !viteConfigFilePath) { %>
|
|
2
|
+
import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';
|
|
3
|
+
import { mergeConfig } from 'vite';
|
|
4
|
+
<% } %>
|
|
5
|
+
|
|
1
6
|
const config = {
|
|
2
7
|
stories: [
|
|
3
8
|
<% if(uiFramework === '@storybook/angular' && projectType === 'library') { %>
|
|
@@ -8,13 +13,19 @@ const config = {
|
|
|
8
13
|
framework: {
|
|
9
14
|
name: '<%= uiFramework %>',
|
|
10
15
|
options: {
|
|
11
|
-
<% if (usesVite) { %>
|
|
16
|
+
<% if (usesVite && viteConfigFilePath) { %>
|
|
12
17
|
builder: {
|
|
13
18
|
viteConfigPath: '<%= viteConfigFilePath %>',
|
|
14
19
|
},
|
|
15
20
|
<% } %>
|
|
16
21
|
},
|
|
17
22
|
},
|
|
23
|
+
<% if (usesVite && !viteConfigFilePath) { %>
|
|
24
|
+
viteFinal: async (config) =>
|
|
25
|
+
mergeConfig(config, {
|
|
26
|
+
plugins: [nxViteTsPaths()],
|
|
27
|
+
}),
|
|
28
|
+
<% } %>
|
|
18
29
|
};
|
|
19
30
|
|
|
20
31
|
export default config;
|
|
@@ -22,11 +33,11 @@ export default config;
|
|
|
22
33
|
<% if(!usesVite) { %>
|
|
23
34
|
// To customize your webpack configuration you can use the webpackFinal field.
|
|
24
35
|
// Check https://storybook.js.org/docs/react/builders/webpack#extending-storybooks-webpack-config
|
|
25
|
-
// and https://nx.dev/
|
|
36
|
+
// and https://nx.dev/recipes/storybook/custom-builder-configs
|
|
26
37
|
<% } %>
|
|
27
38
|
|
|
28
39
|
<% if(usesVite) { %>
|
|
29
40
|
// To customize your Vite configuration you can use the viteFinal field.
|
|
30
41
|
// Check https://storybook.js.org/docs/react/builders/vite#configuration
|
|
31
|
-
// and https://nx.dev/
|
|
42
|
+
// and https://nx.dev/recipes/storybook/custom-builder-configs
|
|
32
43
|
<% } %>
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import type { StorybookConfig } from '<%= uiFramework %>';
|
|
2
|
+
<% if (usesVite && !viteConfigFilePath) { %>
|
|
3
|
+
import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';
|
|
4
|
+
import { mergeConfig } from 'vite';
|
|
5
|
+
<% } %>
|
|
2
6
|
|
|
3
7
|
const config: StorybookConfig = {
|
|
4
8
|
stories: [
|
|
@@ -10,13 +14,19 @@ const config: StorybookConfig = {
|
|
|
10
14
|
framework: {
|
|
11
15
|
name: '<%= uiFramework %>',
|
|
12
16
|
options: {
|
|
13
|
-
<% if (usesVite) { %>
|
|
17
|
+
<% if (usesVite && viteConfigFilePath) { %>
|
|
14
18
|
builder: {
|
|
15
19
|
viteConfigPath: '<%= viteConfigFilePath %>',
|
|
16
20
|
},
|
|
17
21
|
<% } %>
|
|
18
22
|
},
|
|
19
23
|
},
|
|
24
|
+
<% if (usesVite && !viteConfigFilePath) { %>
|
|
25
|
+
viteFinal: async (config) =>
|
|
26
|
+
mergeConfig(config, {
|
|
27
|
+
plugins: [nxViteTsPaths()],
|
|
28
|
+
}),
|
|
29
|
+
<% } %>
|
|
20
30
|
};
|
|
21
31
|
|
|
22
32
|
export default config;
|
|
@@ -24,11 +34,11 @@ export default config;
|
|
|
24
34
|
<% if(!usesVite) { %>
|
|
25
35
|
// To customize your webpack configuration you can use the webpackFinal field.
|
|
26
36
|
// Check https://storybook.js.org/docs/react/builders/webpack#extending-storybooks-webpack-config
|
|
27
|
-
// and https://nx.dev/
|
|
37
|
+
// and https://nx.dev/recipes/storybook/custom-builder-configs
|
|
28
38
|
<% } %>
|
|
29
39
|
|
|
30
40
|
<% if(usesVite) { %>
|
|
31
41
|
// To customize your Vite configuration you can use the viteFinal field.
|
|
32
42
|
// Check https://storybook.js.org/docs/react/builders/vite#configuration
|
|
33
|
-
// and https://nx.dev/
|
|
43
|
+
// and https://nx.dev/recipes/storybook/custom-builder-configs
|
|
34
44
|
<% } %>
|