@nx/storybook 20.2.2 → 20.3.0-beta.0
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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/storybook",
|
|
3
|
-
"version": "20.
|
|
3
|
+
"version": "20.3.0-beta.0",
|
|
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": {
|
|
@@ -33,13 +33,13 @@
|
|
|
33
33
|
"migrations": "./migrations.json"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@nx/devkit": "20.
|
|
36
|
+
"@nx/devkit": "20.3.0-beta.0",
|
|
37
37
|
"@phenomnomnominal/tsquery": "~5.0.1",
|
|
38
38
|
"semver": "^7.5.3",
|
|
39
39
|
"tslib": "^2.3.0",
|
|
40
|
-
"@nx/cypress": "20.
|
|
41
|
-
"@nx/js": "20.
|
|
42
|
-
"@nx/eslint": "20.
|
|
40
|
+
"@nx/cypress": "20.3.0-beta.0",
|
|
41
|
+
"@nx/js": "20.3.0-beta.0",
|
|
42
|
+
"@nx/eslint": "20.3.0-beta.0"
|
|
43
43
|
},
|
|
44
44
|
"publishConfig": {
|
|
45
45
|
"access": "public"
|
package/plugin.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { createNodes, StorybookPluginOptions, createDependencies, } from './src/plugins/plugin';
|
|
1
|
+
export { createNodes, createNodesV2, StorybookPluginOptions, createDependencies, } from './src/plugins/plugin';
|
package/plugin.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createDependencies = exports.createNodes = void 0;
|
|
3
|
+
exports.createDependencies = exports.createNodesV2 = exports.createNodes = void 0;
|
|
4
4
|
var plugin_1 = require("./src/plugins/plugin");
|
|
5
5
|
Object.defineProperty(exports, "createNodes", { enumerable: true, get: function () { return plugin_1.createNodes; } });
|
|
6
|
+
Object.defineProperty(exports, "createNodesV2", { enumerable: true, get: function () { return plugin_1.createNodesV2; } });
|
|
6
7
|
Object.defineProperty(exports, "createDependencies", { enumerable: true, get: function () { return plugin_1.createDependencies; } });
|
|
@@ -11,7 +11,7 @@ const versions_1 = require("../../utils/versions");
|
|
|
11
11
|
async function convertToInferred(tree, options) {
|
|
12
12
|
const projectGraph = await (0, devkit_1.createProjectGraphAsync)();
|
|
13
13
|
const migrationLogs = new aggregate_log_util_1.AggregatedLog();
|
|
14
|
-
const migratedProjects = await (0, executor_to_plugin_migrator_1.
|
|
14
|
+
const migratedProjects = await (0, executor_to_plugin_migrator_1.migrateProjectExecutorsToPlugin)(tree, projectGraph, '@nx/storybook/plugin', plugin_1.createNodesV2, {
|
|
15
15
|
buildStorybookTargetName: 'build-storybook',
|
|
16
16
|
serveStorybookTargetName: 'storybook',
|
|
17
17
|
staticStorybookTargetName: 'static-storybook',
|
|
@@ -58,7 +58,7 @@ async function initGeneratorInternal(tree, schema) {
|
|
|
58
58
|
nxJson.useInferencePlugins !== false;
|
|
59
59
|
schema.addPlugin ??= addPluginDefault;
|
|
60
60
|
if (schema.addPlugin) {
|
|
61
|
-
await (0, add_plugin_1.
|
|
61
|
+
await (0, add_plugin_1.addPlugin)(tree, await (0, devkit_1.createProjectGraphAsync)(), '@nx/storybook/plugin', plugin_1.createNodesV2, {
|
|
62
62
|
serveStorybookTargetName: [
|
|
63
63
|
'storybook',
|
|
64
64
|
'serve:storybook',
|
package/src/plugins/plugin.d.ts
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
import { CreateDependencies, CreateNodes } from '@nx/devkit';
|
|
1
|
+
import { CreateDependencies, CreateNodes, CreateNodesV2 } from '@nx/devkit';
|
|
2
2
|
export interface StorybookPluginOptions {
|
|
3
3
|
buildStorybookTargetName?: string;
|
|
4
4
|
serveStorybookTargetName?: string;
|
|
5
5
|
staticStorybookTargetName?: string;
|
|
6
6
|
testStorybookTargetName?: string;
|
|
7
7
|
}
|
|
8
|
+
/**
|
|
9
|
+
* @deprecated The 'createDependencies' function is now a no-op. This functionality is included in 'createNodesV2'.
|
|
10
|
+
*/
|
|
8
11
|
export declare const createDependencies: CreateDependencies;
|
|
12
|
+
export declare const createNodesV2: CreateNodesV2<StorybookPluginOptions>;
|
|
9
13
|
export declare const createNodes: CreateNodes<StorybookPluginOptions>;
|
package/src/plugins/plugin.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createNodes = exports.createDependencies = void 0;
|
|
3
|
+
exports.createNodes = exports.createNodesV2 = exports.createDependencies = void 0;
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
|
5
5
|
const path_1 = require("path");
|
|
6
6
|
const get_named_inputs_1 = require("@nx/devkit/src/utils/get-named-inputs");
|
|
@@ -9,57 +9,73 @@ const calculate_hash_for_create_nodes_1 = require("@nx/devkit/src/utils/calculat
|
|
|
9
9
|
const cache_directory_1 = require("nx/src/utils/cache-directory");
|
|
10
10
|
const js_1 = require("@nx/js");
|
|
11
11
|
const config_utils_1 = require("@nx/devkit/src/utils/config-utils");
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
function readTargetsCache() {
|
|
12
|
+
const file_hasher_1 = require("nx/src/hasher/file-hasher");
|
|
13
|
+
function readTargetsCache(cachePath) {
|
|
15
14
|
return (0, fs_1.existsSync)(cachePath) ? (0, devkit_1.readJsonFile)(cachePath) : {};
|
|
16
15
|
}
|
|
17
|
-
function writeTargetsToCache() {
|
|
18
|
-
|
|
19
|
-
(0, devkit_1.writeJsonFile)(cachePath, {
|
|
20
|
-
...oldCache,
|
|
21
|
-
...targetsCache,
|
|
22
|
-
});
|
|
16
|
+
function writeTargetsToCache(cachePath, results) {
|
|
17
|
+
(0, devkit_1.writeJsonFile)(cachePath, results);
|
|
23
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* @deprecated The 'createDependencies' function is now a no-op. This functionality is included in 'createNodesV2'.
|
|
21
|
+
*/
|
|
24
22
|
const createDependencies = () => {
|
|
25
|
-
writeTargetsToCache();
|
|
26
23
|
return [];
|
|
27
24
|
};
|
|
28
25
|
exports.createDependencies = createDependencies;
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
if (projectRoot === '') {
|
|
40
|
-
projectRoot = '.';
|
|
26
|
+
const storybookConfigGlob = '**/.storybook/main.{js,ts,mjs,mts,cjs,cts}';
|
|
27
|
+
exports.createNodesV2 = [
|
|
28
|
+
storybookConfigGlob,
|
|
29
|
+
async (configFilePaths, options, context) => {
|
|
30
|
+
const normalizedOptions = normalizeOptions(options);
|
|
31
|
+
const optionsHash = (0, file_hasher_1.hashObject)(normalizedOptions);
|
|
32
|
+
const cachePath = (0, path_1.join)(cache_directory_1.workspaceDataDirectory, `storybook-${optionsHash}.hash`);
|
|
33
|
+
const targetsCache = readTargetsCache(cachePath);
|
|
34
|
+
try {
|
|
35
|
+
return await (0, devkit_1.createNodesFromFiles)((configFile, _, context) => createNodesInternal(configFile, normalizedOptions, context, targetsCache), configFilePaths, normalizedOptions, context);
|
|
41
36
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
if (!siblingFiles.includes('package.json') &&
|
|
45
|
-
!siblingFiles.includes('project.json')) {
|
|
46
|
-
return {};
|
|
37
|
+
finally {
|
|
38
|
+
writeTargetsToCache(cachePath, targetsCache);
|
|
47
39
|
}
|
|
48
|
-
options = normalizeOptions(options);
|
|
49
|
-
const hash = await (0, calculate_hash_for_create_nodes_1.calculateHashForCreateNodes)(projectRoot, options, context, [(0, js_1.getLockFileName)((0, devkit_1.detectPackageManager)(context.workspaceRoot))]);
|
|
50
|
-
const projectName = buildProjectName(projectRoot, context.workspaceRoot);
|
|
51
|
-
targetsCache[hash] ??= await buildStorybookTargets(configFilePath, projectRoot, options, context, projectName);
|
|
52
|
-
const result = {
|
|
53
|
-
projects: {
|
|
54
|
-
[projectRoot]: {
|
|
55
|
-
root: projectRoot,
|
|
56
|
-
targets: targetsCache[hash],
|
|
57
|
-
},
|
|
58
|
-
},
|
|
59
|
-
};
|
|
60
|
-
return result;
|
|
61
40
|
},
|
|
62
41
|
];
|
|
42
|
+
exports.createNodes = [
|
|
43
|
+
storybookConfigGlob,
|
|
44
|
+
(configFilePath, options, context) => {
|
|
45
|
+
devkit_1.logger.warn('`createNodes` is deprecated. Update your plugin to utilize createNodesV2 instead. In Nx 20, this will change to the createNodesV2 API.');
|
|
46
|
+
return createNodesInternal(configFilePath, normalizeOptions(options), context, {});
|
|
47
|
+
},
|
|
48
|
+
];
|
|
49
|
+
async function createNodesInternal(configFilePath, options, context, targetsCache) {
|
|
50
|
+
let projectRoot = '';
|
|
51
|
+
if (configFilePath.includes('/.storybook')) {
|
|
52
|
+
projectRoot = (0, path_1.dirname)(configFilePath).replace('/.storybook', '');
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
projectRoot = (0, path_1.dirname)(configFilePath).replace('.storybook', '');
|
|
56
|
+
}
|
|
57
|
+
if (projectRoot === '') {
|
|
58
|
+
projectRoot = '.';
|
|
59
|
+
}
|
|
60
|
+
// Do not create a project if package.json and project.json isn't there.
|
|
61
|
+
const siblingFiles = (0, fs_1.readdirSync)((0, path_1.join)(context.workspaceRoot, projectRoot));
|
|
62
|
+
if (!siblingFiles.includes('package.json') &&
|
|
63
|
+
!siblingFiles.includes('project.json')) {
|
|
64
|
+
return {};
|
|
65
|
+
}
|
|
66
|
+
const hash = await (0, calculate_hash_for_create_nodes_1.calculateHashForCreateNodes)(projectRoot, options, context, [(0, js_1.getLockFileName)((0, devkit_1.detectPackageManager)(context.workspaceRoot))]);
|
|
67
|
+
const projectName = buildProjectName(projectRoot, context.workspaceRoot);
|
|
68
|
+
targetsCache[hash] ??= await buildStorybookTargets(configFilePath, projectRoot, options, context, projectName);
|
|
69
|
+
const result = {
|
|
70
|
+
projects: {
|
|
71
|
+
[projectRoot]: {
|
|
72
|
+
root: projectRoot,
|
|
73
|
+
targets: targetsCache[hash],
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
return result;
|
|
78
|
+
}
|
|
63
79
|
async function buildStorybookTargets(configFilePath, projectRoot, options, context, projectName) {
|
|
64
80
|
const buildOutputs = getOutputs();
|
|
65
81
|
const namedInputs = (0, get_named_inputs_1.getNamedInputs)(projectRoot, context);
|
|
@@ -184,12 +200,12 @@ function getOutputs() {
|
|
|
184
200
|
return outputs;
|
|
185
201
|
}
|
|
186
202
|
function normalizeOptions(options) {
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
203
|
+
return {
|
|
204
|
+
buildStorybookTargetName: options.buildStorybookTargetName ?? 'build-storybook',
|
|
205
|
+
serveStorybookTargetName: options.serveStorybookTargetName ?? 'storybook',
|
|
206
|
+
testStorybookTargetName: options.testStorybookTargetName ?? 'test-storybook',
|
|
207
|
+
staticStorybookTargetName: options.staticStorybookTargetName ?? 'static-storybook',
|
|
208
|
+
};
|
|
193
209
|
}
|
|
194
210
|
function buildProjectName(projectRoot, workspaceRoot) {
|
|
195
211
|
const packageJsonPath = (0, path_1.join)(workspaceRoot, projectRoot, 'package.json');
|