@storybook/builder-vite 7.0.0-alpha.49 → 7.0.0-alpha.50

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.
@@ -7,6 +7,12 @@ exports.processPreviewAnnotation = processPreviewAnnotation;
7
7
 
8
8
  var _path = require("path");
9
9
 
10
+ var _slash = _interopRequireDefault(require("slash"));
11
+
12
+ var _transformAbsPath = require("./transform-abs-path");
13
+
14
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
+
10
16
  /**
11
17
  * Preview annotations can take several forms, and vite needs them to be
12
18
  * a bit more restrained.
@@ -28,14 +34,20 @@ function processPreviewAnnotation(path) {
28
34
 
29
35
 
30
36
  if (path !== null && path !== void 0 && path.startsWith('./') || path !== null && path !== void 0 && path.startsWith('../')) {
31
- return (0, _path.resolve)(path);
37
+ return (0, _slash.default)((0, _path.resolve)(path));
32
38
  } // This should not occur, since we use `.filter(Boolean)` prior to
33
39
  // calling this function, but this makes typescript happy
34
40
 
35
41
 
36
42
  if (!path) {
37
43
  throw new Error('Could not determine path for previewAnnotation');
44
+ } // For addon dependencies that use require.resolve(), we need to convert to a bare path
45
+ // so that vite will process it as a dependency (cjs -> esm, etc).
46
+
47
+
48
+ if (path.includes('node_modules')) {
49
+ return (0, _transformAbsPath.transformAbsPath)(path);
38
50
  }
39
51
 
40
- return path;
52
+ return (0, _slash.default)(path);
41
53
  }
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.transformAbsPath = transformAbsPath;
7
+
8
+ var _path = _interopRequireDefault(require("path"));
9
+
10
+ var _vite = require("vite");
11
+
12
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
+
14
+ // We need to convert from an absolute path, to a traditional node module import path,
15
+ // so that vite can correctly pre-bundle/optimize
16
+ function transformAbsPath(absPath) {
17
+ const splits = absPath.split(`node_modules${_path.default.sep}`); // Return everything after the final "node_modules/"
18
+
19
+ const module = (0, _vite.normalizePath)(splits[splits.length - 1]);
20
+ return module;
21
+ }
@@ -1,4 +1,6 @@
1
1
  import { resolve } from 'path';
2
+ import slash from 'slash';
3
+ import { transformAbsPath } from './transform-abs-path';
2
4
  /**
3
5
  * Preview annotations can take several forms, and vite needs them to be
4
6
  * a bit more restrained.
@@ -21,14 +23,20 @@ export function processPreviewAnnotation(path) {
21
23
 
22
24
 
23
25
  if (path?.startsWith('./') || path?.startsWith('../')) {
24
- return resolve(path);
26
+ return slash(resolve(path));
25
27
  } // This should not occur, since we use `.filter(Boolean)` prior to
26
28
  // calling this function, but this makes typescript happy
27
29
 
28
30
 
29
31
  if (!path) {
30
32
  throw new Error('Could not determine path for previewAnnotation');
33
+ } // For addon dependencies that use require.resolve(), we need to convert to a bare path
34
+ // so that vite will process it as a dependency (cjs -> esm, etc).
35
+
36
+
37
+ if (path.includes('node_modules')) {
38
+ return transformAbsPath(path);
31
39
  }
32
40
 
33
- return path;
41
+ return slash(path);
34
42
  }
@@ -0,0 +1,10 @@
1
+ import path from 'path';
2
+ import { normalizePath } from 'vite'; // We need to convert from an absolute path, to a traditional node module import path,
3
+ // so that vite can correctly pre-bundle/optimize
4
+
5
+ export function transformAbsPath(absPath) {
6
+ const splits = absPath.split(`node_modules${path.sep}`); // Return everything after the final "node_modules/"
7
+
8
+ const module = normalizePath(splits[splits.length - 1]);
9
+ return module;
10
+ }
@@ -0,0 +1 @@
1
+ export declare function transformAbsPath(absPath: string): string;
package/jest.config.js ADDED
@@ -0,0 +1,7 @@
1
+ const path = require('path');
2
+ const baseConfig = require('../../jest.config.node');
3
+
4
+ module.exports = {
5
+ ...baseConfig,
6
+ displayName: __dirname.split(path.sep).slice(-2).join(path.posix.sep),
7
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storybook/builder-vite",
3
- "version": "7.0.0-alpha.49",
3
+ "version": "7.0.0-alpha.50",
4
4
  "description": "A plugin to run and build Storybooks with Vite",
5
5
  "homepage": "https://github.com/storybookjs/storybook/tree/main/code/lib/builder-vite/#readme",
6
6
  "repository": {
@@ -19,14 +19,14 @@
19
19
  },
20
20
  "dependencies": {
21
21
  "@joshwooding/vite-plugin-react-docgen-typescript": "0.0.5",
22
- "@storybook/client-api": "7.0.0-alpha.49",
23
- "@storybook/client-logger": "7.0.0-alpha.49",
24
- "@storybook/core-common": "7.0.0-alpha.49",
22
+ "@storybook/client-api": "7.0.0-alpha.50",
23
+ "@storybook/client-logger": "7.0.0-alpha.50",
24
+ "@storybook/core-common": "7.0.0-alpha.50",
25
25
  "@storybook/mdx2-csf": "next",
26
- "@storybook/node-logger": "7.0.0-alpha.49",
27
- "@storybook/preview-web": "7.0.0-alpha.49",
28
- "@storybook/source-loader": "7.0.0-alpha.49",
29
- "@storybook/types": "7.0.0-alpha.49",
26
+ "@storybook/node-logger": "7.0.0-alpha.50",
27
+ "@storybook/preview-web": "7.0.0-alpha.50",
28
+ "@storybook/source-loader": "7.0.0-alpha.50",
29
+ "@storybook/types": "7.0.0-alpha.50",
30
30
  "@vitejs/plugin-react": "^2.0.0",
31
31
  "browser-assert": "^1.2.1",
32
32
  "es-module-lexer": "^0.9.3",
@@ -45,5 +45,5 @@
45
45
  "publishConfig": {
46
46
  "access": "public"
47
47
  },
48
- "gitHead": "d7eb433300cac55d3c7256c8181eb6fd7a47b4c8"
48
+ "gitHead": "77184d039091f4782dc4540df6d271a24fb3e242"
49
49
  }
@@ -1,5 +1,7 @@
1
1
  import type { PreviewAnnotation } from '@storybook/types';
2
2
  import { resolve } from 'path';
3
+ import slash from 'slash';
4
+ import { transformAbsPath } from './transform-abs-path';
3
5
 
4
6
  /**
5
7
  * Preview annotations can take several forms, and vite needs them to be
@@ -21,7 +23,7 @@ export function processPreviewAnnotation(path: PreviewAnnotation | undefined) {
21
23
  }
22
24
  // resolve relative paths into absolute paths, but don't resolve "bare" imports
23
25
  if (path?.startsWith('./') || path?.startsWith('../')) {
24
- return resolve(path);
26
+ return slash(resolve(path));
25
27
  }
26
28
  // This should not occur, since we use `.filter(Boolean)` prior to
27
29
  // calling this function, but this makes typescript happy
@@ -29,5 +31,11 @@ export function processPreviewAnnotation(path: PreviewAnnotation | undefined) {
29
31
  throw new Error('Could not determine path for previewAnnotation');
30
32
  }
31
33
 
32
- return path;
34
+ // For addon dependencies that use require.resolve(), we need to convert to a bare path
35
+ // so that vite will process it as a dependency (cjs -> esm, etc).
36
+ if (path.includes('node_modules')) {
37
+ return transformAbsPath(path);
38
+ }
39
+
40
+ return slash(path);
33
41
  }
@@ -0,0 +1,11 @@
1
+ import path from 'path';
2
+ import { normalizePath } from 'vite';
3
+
4
+ // We need to convert from an absolute path, to a traditional node module import path,
5
+ // so that vite can correctly pre-bundle/optimize
6
+ export function transformAbsPath(absPath: string) {
7
+ const splits = absPath.split(`node_modules${path.sep}`);
8
+ // Return everything after the final "node_modules/"
9
+ const module = normalizePath(splits[splits.length - 1]);
10
+ return module;
11
+ }
package/tsconfig.json CHANGED
@@ -5,6 +5,5 @@
5
5
  "resolveJsonModule": true,
6
6
  "skipLibCheck": true
7
7
  },
8
- "include": ["src/**/*"],
9
- "exclude": ["src/**/*.test.*", "src/**/__testfixtures__/**"]
8
+ "include": ["src/**/*"]
10
9
  }