@nx/storybook 21.1.2 → 21.1.3

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/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  <p style="text-align: center;">
2
2
  <picture>
3
3
  <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/nrwl/nx/master/images/nx-dark.svg">
4
- <img alt="Nx - Smart Monorepos · Fast CI" src="https://raw.githubusercontent.com/nrwl/nx/master/images/nx-light.svg" width="100%">
4
+ <img alt="Nx - Smart Repos · Fast Builds" src="https://raw.githubusercontent.com/nrwl/nx/master/images/nx-light.svg" width="100%">
5
5
  </picture>
6
6
  </p>
7
7
 
@@ -20,9 +20,9 @@
20
20
 
21
21
  <hr>
22
22
 
23
- # Nx: Smart Monorepos · Fast CI
23
+ # Nx: Smart Repos · Fast Builds
24
24
 
25
- Nx is a build system, optimized for monorepos, with plugins for popular frameworks and tools and advanced CI capabilities including caching and distribution.
25
+ An AI-first build platform that connects everything from your editor to CI. Helping you deliver fast, without breaking things.
26
26
 
27
27
  This package is a [Storybook plugin for Nx](https://nx.dev/nx-api/storybook).
28
28
 
@@ -64,5 +64,5 @@ npx nx@latest init
64
64
  - [Blog Posts About Nx](https://nx.dev/blog)
65
65
 
66
66
  <p style="text-align: center;"><a href="https://nx.dev/#learning-materials" target="_blank" rel="noreferrer"><img src="https://raw.githubusercontent.com/nrwl/nx/master/images/nx-courses-and-videos.svg"
67
- width="100%" alt="Nx - Smart Monorepos · Fast CI"></a></p>
67
+ width="100%" alt="Nx - Smart Repos · Fast Builds"></a></p>
68
68
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/storybook",
3
- "version": "21.1.2",
3
+ "version": "21.1.3",
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": "21.1.2",
36
+ "@nx/devkit": "21.1.3",
37
37
  "@phenomnomnominal/tsquery": "~5.0.1",
38
38
  "semver": "^7.5.3",
39
39
  "tslib": "^2.3.0",
40
- "@nx/cypress": "21.1.2",
41
- "@nx/js": "21.1.2",
42
- "@nx/eslint": "21.1.2"
40
+ "@nx/cypress": "21.1.3",
41
+ "@nx/js": "21.1.3",
42
+ "@nx/eslint": "21.1.3"
43
43
  },
44
44
  "publishConfig": {
45
45
  "access": "public"
@@ -10,6 +10,7 @@ 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
12
  const file_hasher_1 = require("nx/src/hasher/file-hasher");
13
+ const tsquery_1 = require("@phenomnomnominal/tsquery");
13
14
  function readTargetsCache(cachePath) {
14
15
  return (0, fs_1.existsSync)(cachePath) ? (0, devkit_1.readJsonFile)(cachePath) : {};
15
16
  }
@@ -79,7 +80,10 @@ async function createNodesInternal(configFilePath, options, context, targetsCach
79
80
  async function buildStorybookTargets(configFilePath, projectRoot, options, context, projectName) {
80
81
  const buildOutputs = getOutputs();
81
82
  const namedInputs = (0, get_named_inputs_1.getNamedInputs)(projectRoot, context);
82
- const storybookFramework = await getStorybookFramework(configFilePath, context);
83
+ // First attempt to do a very fast lookup for the framework
84
+ // If that fails, the framework might be inherited, so do a very heavyweight lookup
85
+ const storybookFramework = (await getStorybookFramework(configFilePath, context)) ||
86
+ (await getStorybookFullyResolvedFramework(configFilePath, context));
83
87
  const frameworkIsAngular = storybookFramework === '@storybook/angular';
84
88
  if (frameworkIsAngular && !projectName) {
85
89
  throw new Error(`Could not find a name for the project at '${projectRoot}'. Please make sure that the project has a package.json or project.json file with name specified.`);
@@ -190,6 +194,34 @@ function serveStaticTarget(options, projectRoot) {
190
194
  return targetConfig;
191
195
  }
192
196
  async function getStorybookFramework(configFilePath, context) {
197
+ const resolvedPath = (0, path_1.join)(context.workspaceRoot, configFilePath);
198
+ const mainTsJs = (0, fs_1.readFileSync)(resolvedPath, 'utf-8');
199
+ const importDeclarations = tsquery_1.tsquery.query(mainTsJs, 'ImportDeclaration:has(ImportSpecifier:has([text="StorybookConfig"]))')?.[0];
200
+ if (!importDeclarations) {
201
+ return parseFrameworkName(mainTsJs);
202
+ }
203
+ const storybookConfigImportPackage = tsquery_1.tsquery.query(importDeclarations, 'StringLiteral')?.[0];
204
+ if (storybookConfigImportPackage?.getText() === `'@storybook/core-common'`) {
205
+ return parseFrameworkName(mainTsJs);
206
+ }
207
+ return storybookConfigImportPackage?.getText();
208
+ }
209
+ function parseFrameworkName(mainTsJs) {
210
+ const frameworkPropertyAssignment = tsquery_1.tsquery.query(mainTsJs, `PropertyAssignment:has(Identifier:has([text="framework"]))`)?.[0];
211
+ if (!frameworkPropertyAssignment) {
212
+ return undefined;
213
+ }
214
+ const propertyAssignments = tsquery_1.tsquery.query(frameworkPropertyAssignment, `PropertyAssignment:has(Identifier:has([text="name"]))`);
215
+ const namePropertyAssignment = propertyAssignments?.find((expression) => {
216
+ return expression.getText().startsWith('name');
217
+ });
218
+ if (!namePropertyAssignment) {
219
+ const storybookConfigImportPackage = tsquery_1.tsquery.query(frameworkPropertyAssignment, 'StringLiteral')?.[0];
220
+ return storybookConfigImportPackage?.getText();
221
+ }
222
+ return tsquery_1.tsquery.query(namePropertyAssignment, `StringLiteral`)?.[0]?.getText();
223
+ }
224
+ async function getStorybookFullyResolvedFramework(configFilePath, context) {
193
225
  const resolvedPath = (0, path_1.join)(context.workspaceRoot, configFilePath);
194
226
  const { framework } = await (0, config_utils_1.loadConfigFile)(resolvedPath);
195
227
  return typeof framework === 'string' ? framework : framework.name;