@storybook/react-vite 11.0.0-alpha.9 → 11.0.0-beta.1

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.
@@ -1,215 +0,0 @@
1
- import CJS_COMPAT_NODE_URL_4dr3vpsyiyp from 'node:url';
2
- import CJS_COMPAT_NODE_PATH_4dr3vpsyiyp from 'node:path';
3
- import CJS_COMPAT_NODE_MODULE_4dr3vpsyiyp from "node:module";
4
-
5
- var __filename = CJS_COMPAT_NODE_URL_4dr3vpsyiyp.fileURLToPath(import.meta.url);
6
- var __dirname = CJS_COMPAT_NODE_PATH_4dr3vpsyiyp.dirname(__filename);
7
- var require = CJS_COMPAT_NODE_MODULE_4dr3vpsyiyp.createRequire(import.meta.url);
8
-
9
- // ------------------------------------------------------------
10
- // end of CJS compatibility banner, injected by Storybook's esbuild configuration
11
- // ------------------------------------------------------------
12
-
13
- // src/plugins/react-docgen.ts
14
- import { existsSync } from "node:fs";
15
- import { dirname, relative, sep } from "node:path";
16
- import { findTsconfigPathForFile, getTsconfigPathsBaseDir } from "storybook/internal/common";
17
- import { logger } from "storybook/internal/node-logger";
18
- import { createFilter } from "@rollup/pluginutils";
19
- import MagicString from "magic-string";
20
- import {
21
- ERROR_CODES,
22
- builtinHandlers as docgenHandlers,
23
- builtinResolvers as docgenResolver,
24
- makeFsImporter,
25
- parse
26
- } from "react-docgen";
27
- import * as TsconfigPaths from "tsconfig-paths";
28
-
29
- // src/plugins/docgen-handlers/actualNameHandler.ts
30
- import { utils } from "react-docgen";
31
- var { getNameOrValue, isReactForwardRefCall } = utils, actualNameHandler = function(documentation, componentDefinition) {
32
- if (documentation.set("definedInFile", componentDefinition.hub.file.opts.filename), (componentDefinition.isClassDeclaration() || componentDefinition.isFunctionDeclaration()) && componentDefinition.has("id"))
33
- documentation.set(
34
- "actualName",
35
- getNameOrValue(componentDefinition.get("id"))
36
- );
37
- else if (componentDefinition.isArrowFunctionExpression() || componentDefinition.isFunctionExpression() || isReactForwardRefCall(componentDefinition)) {
38
- let currentPath = componentDefinition;
39
- for (; currentPath.parentPath; ) {
40
- if (currentPath.parentPath.isVariableDeclarator()) {
41
- documentation.set("actualName", getNameOrValue(currentPath.parentPath.get("id")));
42
- return;
43
- }
44
- if (currentPath.parentPath.isAssignmentExpression()) {
45
- let leftPath = currentPath.parentPath.get("left");
46
- if (leftPath.isIdentifier() || leftPath.isLiteral()) {
47
- documentation.set("actualName", getNameOrValue(leftPath));
48
- return;
49
- }
50
- }
51
- currentPath = currentPath.parentPath;
52
- }
53
- documentation.set("actualName", "");
54
- }
55
- }, actualNameHandler_default = actualNameHandler;
56
-
57
- // src/plugins/docgen-resolver.ts
58
- import { extname } from "node:path";
59
- import resolve from "resolve";
60
- var ReactDocgenResolveError = class extends Error {
61
- constructor(filename) {
62
- super(`'${filename}' was ignored by react-docgen.`);
63
- // the magic string that react-docgen uses to check if a module is ignored
64
- this.code = "MODULE_NOT_FOUND";
65
- }
66
- }, RESOLVE_EXTENSIONS = [
67
- ".js",
68
- ".cts",
69
- // These were originally not in the code, I added them
70
- ".mts",
71
- // These were originally not in the code, I added them
72
- ".ctsx",
73
- // These were originally not in the code, I added them
74
- ".mtsx",
75
- // These were originally not in the code, I added them
76
- ".ts",
77
- ".tsx",
78
- ".mjs",
79
- ".cjs",
80
- ".mts",
81
- ".cts",
82
- ".jsx"
83
- ];
84
- function defaultLookupModule(filename, basedir) {
85
- let resolveOptions = {
86
- basedir,
87
- extensions: RESOLVE_EXTENSIONS,
88
- // we do not need to check core modules as we cannot import them anyway
89
- includeCoreModules: !1
90
- };
91
- try {
92
- return resolve.sync(filename, resolveOptions);
93
- } catch (error) {
94
- let ext = extname(filename), newFilename;
95
- switch (ext) {
96
- case ".js":
97
- case ".mjs":
98
- case ".cjs": {
99
- let base = filename.slice(0, -2);
100
- try {
101
- return resolve.sync(`${base}ts`, { ...resolveOptions, extensions: [] });
102
- } catch {
103
- newFilename = `${base}tsx`;
104
- }
105
- break;
106
- }
107
- case ".jsx":
108
- newFilename = `${filename.slice(0, -3)}tsx`;
109
- break;
110
- default:
111
- throw error;
112
- }
113
- return resolve.sync(newFilename, {
114
- ...resolveOptions,
115
- // we already know that there is an extension at this point, so no need to check other extensions
116
- extensions: []
117
- });
118
- }
119
- }
120
-
121
- // src/plugins/react-docgen.ts
122
- var defaultHandlers = Object.values(docgenHandlers).map((handler) => handler), defaultResolver = new docgenResolver.FindExportedDefinitionsResolver(), handlers = [...defaultHandlers, actualNameHandler_default];
123
- async function reactDocgen({
124
- include = /\.(mjs|tsx?|jsx?)$/,
125
- exclude = [/node_modules\/.*/]
126
- } = {}) {
127
- let cwd = process.cwd(), filter = createFilter(include, exclude);
128
- return {
129
- name: "storybook:react-docgen-plugin",
130
- enforce: "pre",
131
- async transform(src, id) {
132
- if (filter(relative(cwd, id)))
133
- try {
134
- let docgenResults = parseDocgen(src, id, createTsconfigMatchPath(id)), s = new MagicString(src);
135
- return docgenResults.forEach((info) => {
136
- let { actualName, definedInFile, ...docgenInfo } = info;
137
- if (actualName && definedInFile == id) {
138
- let docNode = JSON.stringify(docgenInfo);
139
- s.append(`;${actualName}.__docgenInfo=${docNode}`);
140
- }
141
- }), {
142
- code: s.toString(),
143
- map: s.generateMap({ hires: !0, source: id }).toString()
144
- };
145
- } catch (e) {
146
- if (e.code === ERROR_CODES.MISSING_DEFINITION)
147
- return;
148
- throw e;
149
- }
150
- }
151
- };
152
- }
153
- function parseDocgen(src, id, matchPath) {
154
- let options = {
155
- resolver: defaultResolver,
156
- handlers,
157
- importer: getReactDocgenImporter(matchPath),
158
- filename: id
159
- };
160
- try {
161
- return parse(src, {
162
- ...options,
163
- babelOptions: { babelrc: !1, configFile: !1 }
164
- });
165
- } catch (isolatedError) {
166
- if (isolatedError.code === ERROR_CODES.MISSING_DEFINITION)
167
- throw isolatedError;
168
- try {
169
- return parse(src, options);
170
- } catch (projectConfigError) {
171
- throw projectConfigError.code === ERROR_CODES.MISSING_DEFINITION ? projectConfigError : (logger.debug(
172
- `react-docgen also failed with the project Babel config for ${id}: ${projectConfigError}`
173
- ), isolatedError);
174
- }
175
- }
176
- }
177
- function getReactDocgenImporter(matchPath) {
178
- return makeFsImporter((filename, basedir) => {
179
- let mappedFilenameByPaths = matchPath && matchPath(filename) || filename, result = defaultLookupModule(mappedFilenameByPaths, basedir);
180
- if (result.includes(`${sep}react-native${sep}index.js`)) {
181
- let replaced = result.replace(
182
- `${sep}react-native${sep}index.js`,
183
- `${sep}react-native-web${sep}dist${sep}index.js`
184
- );
185
- if (existsSync(replaced) && RESOLVE_EXTENSIONS.find((ext) => result.endsWith(ext)))
186
- return replaced;
187
- }
188
- if (RESOLVE_EXTENSIONS.find((ext) => result.endsWith(ext)))
189
- return result;
190
- throw new ReactDocgenResolveError(filename);
191
- });
192
- }
193
- var matchPathByTsconfigPath = /* @__PURE__ */ new Map();
194
- function createTsconfigMatchPath(filePath) {
195
- let tsconfigPath = findTsconfigPathForFile(dirname(filePath), filePath);
196
- if (!tsconfigPath)
197
- return;
198
- let cached = matchPathByTsconfigPath.get(tsconfigPath);
199
- if (cached)
200
- return cached;
201
- let tsconfig = TsconfigPaths.loadConfig(tsconfigPath);
202
- if (tsconfig.resultType !== "success")
203
- return;
204
- logger.debug("Using tsconfig paths for react-docgen");
205
- let matchPath = TsconfigPaths.createMatchPath(
206
- getTsconfigPathsBaseDir(tsconfig.configFileAbsolutePath),
207
- tsconfig.paths,
208
- ["browser", "module", "main"]
209
- );
210
- return matchPathByTsconfigPath.set(tsconfigPath, matchPath), matchPath;
211
- }
212
- export {
213
- getReactDocgenImporter,
214
- reactDocgen
215
- };