@storybook/core
Advanced tools
Comparing version 8.3.0-beta.0 to 8.3.0-beta.1
@@ -7,16 +7,16 @@ import ESM_COMPAT_Module from "node:module"; | ||
const require = ESM_COMPAT_Module.createRequire(import.meta.url); | ||
var Ne = Object.create; | ||
var L = Object.defineProperty; | ||
var we = Object.getOwnPropertyDescriptor; | ||
var Fe = Object.getOwnPropertyNames; | ||
var Ce = Object.getPrototypeOf, Te = Object.prototype.hasOwnProperty; | ||
var p = (s, e) => L(s, "name", { value: e, configurable: !0 }); | ||
var ke = (s, e) => () => (e || s((e = { exports: {} }).exports, e), e.exports); | ||
var Ve = (s, e, i, t) => { | ||
var we = Object.create; | ||
var M = Object.defineProperty; | ||
var Fe = Object.getOwnPropertyDescriptor; | ||
var Ce = Object.getOwnPropertyNames; | ||
var Te = Object.getPrototypeOf, ke = Object.prototype.hasOwnProperty; | ||
var p = (s, e) => M(s, "name", { value: e, configurable: !0 }); | ||
var Ve = (s, e) => () => (e || s((e = { exports: {} }).exports, e), e.exports); | ||
var Ae = (s, e, i, t) => { | ||
if (e && typeof e == "object" || typeof e == "function") | ||
for (let r of Fe(e)) | ||
!Te.call(s, r) && r !== i && L(s, r, { get: () => e[r], enumerable: !(t = we(e, r)) || t.enumerable }); | ||
for (let r of Ce(e)) | ||
!ke.call(s, r) && r !== i && M(s, r, { get: () => e[r], enumerable: !(t = Fe(e, r)) || t.enumerable }); | ||
return s; | ||
}; | ||
var A = (s, e, i) => (i = s != null ? Ne(Ce(s)) : {}, Ve( | ||
var A = (s, e, i) => (i = s != null ? we(Te(s)) : {}, Ae( | ||
// If the importer is in node compatibility mode or this is not an ESM | ||
@@ -26,3 +26,3 @@ // file that has been converted to a CommonJS file using a Babel- | ||
// "default" to the CommonJS "module.exports" for node compatibility. | ||
e || !s || !s.__esModule ? L(i, "default", { value: s, enumerable: !0 }) : i, | ||
e || !s || !s.__esModule ? M(i, "default", { value: s, enumerable: !0 }) : i, | ||
s | ||
@@ -32,7 +32,7 @@ )); | ||
// ../node_modules/ts-dedent/dist/index.js | ||
var N = ke((I) => { | ||
var N = Ve((I) => { | ||
"use strict"; | ||
Object.defineProperty(I, "__esModule", { value: !0 }); | ||
I.dedent = void 0; | ||
function H(s) { | ||
function Y(s) { | ||
for (var e = [], i = 1; i < arguments.length; i++) | ||
@@ -69,5 +69,5 @@ e[i - 1] = arguments[i]; | ||
} | ||
p(H, "dedent"); | ||
I.dedent = H; | ||
I.default = H; | ||
p(Y, "dedent"); | ||
I.dedent = Y; | ||
I.default = Y; | ||
}); | ||
@@ -77,12 +77,12 @@ | ||
var F = A(N(), 1); | ||
import { readFile as Ae, writeFile as Re } from "node:fs/promises"; | ||
import { readFile as Re, writeFile as Le } from "node:fs/promises"; | ||
import { | ||
BabelFileClass as Le, | ||
babelParse as se, | ||
generate as Me, | ||
recast as ne, | ||
BabelFileClass as Me, | ||
babelParse as ne, | ||
generate as $e, | ||
recast as oe, | ||
types as c, | ||
traverse as $e | ||
traverse as Ue | ||
} from "@storybook/core/babel"; | ||
import { isExportStory as Y, storyNameFromExport as Z, toId as Ue } from "@storybook/csf"; | ||
import { isExportStory as Z, storyNameFromExport as ee, toId as qe } from "@storybook/csf"; | ||
@@ -99,4 +99,4 @@ // src/csf-tools/findVarInitialization.ts | ||
// src/csf-tools/CsfFile.ts | ||
var ee = console; | ||
function qe(s) { | ||
var te = console; | ||
function Be(s) { | ||
if (c.isArrayExpression(s)) | ||
@@ -114,4 +114,4 @@ return s.elements.map((e) => { | ||
} | ||
p(qe, "parseIncludeExclude"); | ||
function te(s) { | ||
p(Be, "parseIncludeExclude"); | ||
function re(s) { | ||
if (!c.isArrayExpression(s)) | ||
@@ -125,7 +125,7 @@ throw new Error("CSF: Expected tags array"); | ||
} | ||
p(te, "parseTags"); | ||
var M = /* @__PURE__ */ p((s, e) => { | ||
p(re, "parseTags"); | ||
var $ = /* @__PURE__ */ p((s, e) => { | ||
let { line: i, column: t } = s.loc?.start || {}; | ||
return `${e || ""} (line ${i}, col ${t})`.trim(); | ||
}, "formatLocation"), Be = /* @__PURE__ */ p((s) => Ge.test(s), "isModuleMock"), re = /* @__PURE__ */ p((s, e, i) => { | ||
}, "formatLocation"), We = /* @__PURE__ */ p((s) => Je.test(s), "isModuleMock"), ie = /* @__PURE__ */ p((s, e, i) => { | ||
let t = s; | ||
@@ -141,3 +141,3 @@ if (c.isCallExpression(s)) { | ||
return c.isArrowFunctionExpression(t) || c.isFunctionDeclaration(t) ? t.params.length > 0 : !1; | ||
}, "isArgsStory"), We = /* @__PURE__ */ p((s) => { | ||
}, "isArgsStory"), ze = /* @__PURE__ */ p((s) => { | ||
if (c.isArrayExpression(s)) | ||
@@ -150,3 +150,3 @@ return s.elements.map((e) => { | ||
throw new Error(`Expected array of string literals: ${s}`); | ||
}, "parseExportsOrder"), ie = /* @__PURE__ */ p((s, e) => e.reduce( | ||
}, "parseExportsOrder"), se = /* @__PURE__ */ p((s, e) => e.reduce( | ||
(i, t) => { | ||
@@ -157,3 +157,3 @@ let r = s[t]; | ||
{} | ||
), "sortExports"), ze = /* @__PURE__ */ p((s) => { | ||
), "sortExports"), Ge = /* @__PURE__ */ p((s) => { | ||
if (c.isArrowFunctionExpression(s) || c.isFunctionDeclaration(s)) { | ||
@@ -171,3 +171,3 @@ let e = s.params; | ||
return !1; | ||
}, "hasMount"), Ge = /^[.\/#].*\.mock($|\.[^.]*$)/i, R = class extends Error { | ||
}, "hasMount"), Je = /^[.\/#].*\.mock($|\.[^.]*$)/i, R = class extends Error { | ||
static { | ||
@@ -178,3 +178,3 @@ p(this, "NoMetaError"); | ||
super(F.dedent` | ||
CSF: ${e} ${M(i, t)} | ||
CSF: ${e} ${$(i, t)} | ||
@@ -184,3 +184,3 @@ More info: https://storybook.js.org/docs/react/writing-stories#default-export | ||
} | ||
}, $ = class { | ||
}, U = class { | ||
constructor(e, i, t) { | ||
@@ -213,3 +213,3 @@ this._stories = {}; | ||
throw new Error(F.dedent` | ||
CSF: unexpected dynamic title ${M(i, this._options.fileName)} | ||
CSF: unexpected dynamic title ${$(i, this._options.fileName)} | ||
@@ -226,3 +226,3 @@ More info: https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#string-literal-titles | ||
else if (["includeStories", "excludeStories"].includes(r.key.name)) | ||
t[r.key.name] = qe(r.value); | ||
t[r.key.name] = Be(r.value); | ||
else if (r.key.name === "component") { | ||
@@ -239,7 +239,7 @@ let a = r.value; | ||
} | ||
let { code: n } = ne.print(r.value, {}); | ||
let { code: n } = oe.print(r.value, {}); | ||
t.component = n; | ||
} else if (r.key.name === "tags") { | ||
let a = r.value; | ||
c.isIdentifier(a) && (a = O(a.name, this._ast.program)), t.tags = te(a); | ||
c.isIdentifier(a) && (a = O(a.name, this._ast.program)), t.tags = re(a); | ||
} else if (r.key.name === "id") | ||
@@ -267,3 +267,3 @@ if (c.isStringLiteral(r.value)) | ||
let e = this; | ||
if ($e(this._ast, { | ||
if (Ue(this._ast, { | ||
ExportDefaultDeclaration: { | ||
@@ -312,8 +312,8 @@ enter(t) { | ||
if (l === "__namedExportsOrder" && c.isVariableDeclarator(n)) { | ||
e._namedExportsOrder = We(n.init); | ||
e._namedExportsOrder = ze(n.init); | ||
return; | ||
} | ||
e._storyExports[l] = n, e._storyStatements[l] = t; | ||
let u = Z(l); | ||
e._storyAnnotations[l] ? ee.warn( | ||
let u = ee(l); | ||
e._storyAnnotations[l] ? te.warn( | ||
`Unexpected annotations for "${l}" before story declaration` | ||
@@ -328,3 +328,3 @@ ) : e._storyAnnotations[l] = {}; | ||
if (g.key.name === "render") | ||
x.__isArgsStory = re( | ||
x.__isArgsStory = ie( | ||
g.value, | ||
@@ -337,3 +337,3 @@ r, | ||
else if (g.key.name === "storyName" && c.isStringLiteral(g.value)) | ||
ee.warn( | ||
te.warn( | ||
`Unexpected usage of "storyName" in "${l}". Please use "name" instead.` | ||
@@ -349,3 +349,3 @@ ); | ||
} | ||
})) : x.__isArgsStory = re(d, r, e), e._stories[l] = { | ||
})) : x.__isArgsStory = ie(d, r, e), e._stories[l] = { | ||
id: "FIXME", | ||
@@ -399,3 +399,3 @@ name: u, | ||
throw new Error(F.dedent` | ||
Unexpected \`storiesOf\` usage: ${M(t, e._options.fileName)}. | ||
Unexpected \`storiesOf\` usage: ${$(t, e._options.fileName)}. | ||
@@ -421,6 +421,6 @@ SB8 does not support \`storiesOf\`. | ||
(t, [r, a]) => { | ||
if (!Y(r, e._meta)) | ||
if (!Z(r, e._meta)) | ||
return t; | ||
let n = a.parameters?.__id ?? Ue(e._meta?.id || e._meta?.title, Z(r)), l = { ...a.parameters, __id: n }, { includeStories: u } = e._meta || | ||
{}; | ||
let n = a.parameters?.__id ?? qe(e._meta?.id || e._meta?.title, ee(r)), l = { ...a.parameters, __id: n }, { includeStories: u } = e. | ||
_meta || {}; | ||
r === "__page" && (i.length === 1 || Array.isArray(u) && u.length === 1) && (l.docsOnly = !0), t[r] = { ...a, id: n, parameters: l }; | ||
@@ -430,3 +430,3 @@ let d = e._storyAnnotations[r], { tags: x, play: g } = d; | ||
let _ = c.isIdentifier(x) ? O(x.name, this._ast.program) : x; | ||
t[r].tags = te(_); | ||
t[r].tags = re(_); | ||
} | ||
@@ -439,11 +439,11 @@ g && (t[r].tags = [...t[r].tags || [], "play-fn"]); | ||
let h = e.getStoryExport(r); | ||
return b.storyFn = !!(c.isArrowFunctionExpression(h) || c.isFunctionDeclaration(h)), b.mount = ze(d.play ?? e._metaAnnotations.play), | ||
b.moduleMock = !!e.imports.find((_) => Be(_)), t; | ||
return b.storyFn = !!(c.isArrowFunctionExpression(h) || c.isFunctionDeclaration(h)), b.mount = Ge(d.play ?? e._metaAnnotations.play), | ||
b.moduleMock = !!e.imports.find((_) => We(_)), t; | ||
}, | ||
{} | ||
), Object.keys(e._storyExports).forEach((t) => { | ||
Y(t, e._meta) || (delete e._storyExports[t], delete e._storyAnnotations[t], delete e._storyStatements[t]); | ||
Z(t, e._meta) || (delete e._storyExports[t], delete e._storyAnnotations[t], delete e._storyStatements[t]); | ||
}), e._namedExportsOrder) { | ||
let t = Object.keys(e._storyExports); | ||
e._storyExports = ie(e._storyExports, e._namedExportsOrder), e._stories = ie(e._stories, e._namedExportsOrder); | ||
e._storyExports = se(e._storyExports, e._namedExportsOrder), e._stories = se(e._stories, e._namedExportsOrder); | ||
let r = Object.keys(e._storyExports); | ||
@@ -488,32 +488,32 @@ if (t.length !== r.length) | ||
} | ||
}, Je = /* @__PURE__ */ p(({ | ||
}, Ke = /* @__PURE__ */ p(({ | ||
code: s, | ||
filename: e = "", | ||
ast: i | ||
}) => new Le({ filename: e }, { code: s, ast: i ?? se(s) }), "babelParseFile"), U = /* @__PURE__ */ p((s, e) => { | ||
let i = se(s), t = Je({ code: s, filename: e.fileName, ast: i }); | ||
return new $(i, e, t); | ||
}, "loadCsf"), oe = /* @__PURE__ */ p((s, e = { sourceMaps: !1 }, i) => { | ||
let t = Me(s._ast, e, i); | ||
}) => new Me({ filename: e }, { code: s, ast: i ?? ne(s) }), "babelParseFile"), q = /* @__PURE__ */ p((s, e) => { | ||
let i = ne(s), t = Ke({ code: s, filename: e.fileName, ast: i }); | ||
return new U(i, e, t); | ||
}, "loadCsf"), ae = /* @__PURE__ */ p((s, e = { sourceMaps: !1 }, i) => { | ||
let t = $e(s._ast, e, i); | ||
return e.sourceMaps ? t : t.code; | ||
}, "formatCsf"), Ke = /* @__PURE__ */ p((s, e = {}) => ne.print(s._ast, e), "printCsf"), Pt = /* @__PURE__ */ p(async (s, e) => { | ||
let i = (await Ae(s, "utf-8")).toString(); | ||
return U(i, { ...e, fileName: s }); | ||
}, "readCsf"), Dt = /* @__PURE__ */ p(async (s, e) => { | ||
}, "formatCsf"), Xe = /* @__PURE__ */ p((s, e = {}) => oe.print(s._ast, e), "printCsf"), Dt = /* @__PURE__ */ p(async (s, e) => { | ||
let i = (await Re(s, "utf-8")).toString(); | ||
return q(i, { ...e, fileName: s }); | ||
}, "readCsf"), vt = /* @__PURE__ */ p(async (s, e) => { | ||
if (!(e || s._options.fileName)) | ||
throw new Error("Please specify a fileName for writeCsf"); | ||
await Re(e, Ke(s).code); | ||
await Le(e, Xe(s).code); | ||
}, "writeCsf"); | ||
// src/csf-tools/ConfigFile.ts | ||
var pe = A(N(), 1); | ||
import { readFile as Xe, writeFile as Qe } from "node:fs/promises"; | ||
var fe = A(N(), 1); | ||
import { readFile as Qe, writeFile as He } from "node:fs/promises"; | ||
import { | ||
babelParse as ce, | ||
generate as ae, | ||
recast as He, | ||
babelParse as pe, | ||
generate as le, | ||
recast as Ye, | ||
types as o, | ||
traverse as le | ||
traverse as ce | ||
} from "@storybook/core/babel"; | ||
var q = console, B = /* @__PURE__ */ p(({ | ||
var B = console, W = /* @__PURE__ */ p(({ | ||
expectedType: s, | ||
@@ -529,3 +529,3 @@ foundType: e, | ||
} | ||
return pe.dedent` | ||
return fe.dedent` | ||
CSF Parsing error: Expected '${s}' but found '${e}' instead in '${i?.type}'. | ||
@@ -535,3 +535,4 @@ ${t} | ||
}, "getCsfParsingErrorMessage"), C = /* @__PURE__ */ p((s) => o.isIdentifier(s.key) ? s.key.name : o.isStringLiteral(s.key) ? s.key.value : null, | ||
"propKey"), fe = /* @__PURE__ */ p((s, e) => { | ||
"propKey"), L = /* @__PURE__ */ p((s) => o.isTSAsExpression(s) || o.isTSSatisfiesExpression(s) ? L(s.expression) : s, "unwrap"), de = /* @__PURE__ */ p( | ||
(s, e) => { | ||
if (s.length === 0) | ||
@@ -542,5 +543,5 @@ return e; | ||
if (r) | ||
return fe(t, r.value); | ||
return de(t, r.value); | ||
} | ||
}, "_getPath"), de = /* @__PURE__ */ p((s, e) => { | ||
}, "_getPath"), ue = /* @__PURE__ */ p((s, e) => { | ||
if (s.length === 0) { | ||
@@ -554,5 +555,5 @@ if (o.isObjectExpression(e)) | ||
if (r) | ||
return t.length === 0 ? e.properties : de(t, r.value); | ||
return t.length === 0 ? e.properties : ue(t, r.value); | ||
} | ||
}, "_getPathProperties"), ue = /* @__PURE__ */ p((s, e) => { | ||
}, "_getPathProperties"), me = /* @__PURE__ */ p((s, e) => { | ||
let i = null, t = null; | ||
@@ -562,3 +563,3 @@ return e.body.find((r) => (o.isVariableDeclaration(r) ? t = r.declarations : o.isExportNamedDeclaration(r) && o.isVariableDeclaration(r.declaration) && | ||
i; | ||
}, "_findVarDeclarator"), D = /* @__PURE__ */ p((s, e) => ue(s, e)?.init, "_findVarInitialization"), T = /* @__PURE__ */ p((s, e) => { | ||
}, "_findVarDeclarator"), D = /* @__PURE__ */ p((s, e) => me(s, e)?.init, "_findVarInitialization"), T = /* @__PURE__ */ p((s, e) => { | ||
if (s.length === 0) | ||
@@ -568,10 +569,10 @@ return e; | ||
return o.objectExpression([o.objectProperty(o.identifier(i), r)]); | ||
}, "_makeObjectExpression"), W = /* @__PURE__ */ p((s, e, i) => { | ||
}, "_makeObjectExpression"), z = /* @__PURE__ */ p((s, e, i) => { | ||
let [t, ...r] = s, a = i.properties.find( | ||
(n) => C(n) === t | ||
); | ||
a ? o.isObjectExpression(a.value) && r.length > 0 ? W(r, e, a.value) : a.value = T(r, e) : i.properties.push( | ||
a ? o.isObjectExpression(a.value) && r.length > 0 ? z(r, e, a.value) : a.value = T(r, e) : i.properties.push( | ||
o.objectProperty(o.identifier(t), T(r, e)) | ||
); | ||
}, "_updateExportNode"), z = class { | ||
}, "_updateExportNode"), G = class { | ||
constructor(e, i, t) { | ||
@@ -591,3 +592,3 @@ this._exports = {}; | ||
let e = this; | ||
return le(this._ast, { | ||
return ce(this._ast, { | ||
ExportDefaultDeclaration: { | ||
@@ -597,4 +598,3 @@ enter({ node: i, parent: t }) { | ||
let r = o.isIdentifier(i.declaration) && o.isProgram(t) ? D(i.declaration.name, t) : i.declaration; | ||
(o.isTSAsExpression(r) || o.isTSSatisfiesExpression(r)) && (r = r.expression), o.isObjectExpression(r) ? (e._exportsObject = r, r. | ||
properties.forEach((a) => { | ||
r = L(r), o.isObjectExpression(r) ? (e._exportsObject = r, r.properties.forEach((a) => { | ||
let n = C(a); | ||
@@ -605,4 +605,4 @@ if (n) { | ||
} | ||
})) : q.warn( | ||
B({ | ||
})) : B.warn( | ||
W({ | ||
expectedType: "ObjectExpression", | ||
@@ -624,7 +624,7 @@ foundType: r?.type, | ||
if (o.isExportSpecifier(r) && o.isIdentifier(r.local) && o.isIdentifier(r.exported)) { | ||
let { name: a } = r.local, { name: n } = r.exported, l = ue(a, t); | ||
let { name: a } = r.local, { name: n } = r.exported, l = me(a, t); | ||
e._exports[n] = l.init, e._exportDecls[n] = l; | ||
} | ||
}) : q.warn( | ||
B({ | ||
}) : B.warn( | ||
W({ | ||
expectedType: "VariableDeclaration", | ||
@@ -644,4 +644,3 @@ foundType: i.declaration?.type, | ||
let n = a; | ||
o.isIdentifier(a) && (n = D(a.name, t)), (o.isTSAsExpression(n) || o.isTSSatisfiesExpression(n)) && (n = n.expression), o.isObjectExpression( | ||
n) ? (e._exportsObject = n, n.properties.forEach((l) => { | ||
o.isIdentifier(a) && (n = D(a.name, t)), n = L(n), o.isObjectExpression(n) ? (e._exportsObject = n, n.properties.forEach((l) => { | ||
let u = C(l); | ||
@@ -655,4 +654,4 @@ if (u) { | ||
} | ||
})) : q.warn( | ||
B({ | ||
})) : B.warn( | ||
W({ | ||
expectedType: "ObjectExpression", | ||
@@ -672,3 +671,3 @@ foundType: n?.type, | ||
if (r) | ||
return fe(t, r); | ||
return de(t, r); | ||
} | ||
@@ -678,3 +677,3 @@ getFieldProperties(e) { | ||
if (r) | ||
return de(t, r); | ||
return ue(t, r); | ||
} | ||
@@ -684,3 +683,3 @@ getFieldValue(e) { | ||
if (i) { | ||
let { code: t } = ae(i, {}); | ||
let { code: t } = le(i, {}); | ||
return (0, eval)(`(() => (${t}))()`); | ||
@@ -698,5 +697,5 @@ } | ||
if (this._exportsObject) | ||
W(e, i, this._exportsObject), this._exports[e[0]] = i; | ||
z(e, i, this._exportsObject), this._exports[e[0]] = i; | ||
else if (a && o.isObjectExpression(a) && r.length > 0) | ||
W(r, i, a); | ||
z(r, i, a); | ||
else if (a && r.length === 0 && this._exportDecls[e[0]]) { | ||
@@ -798,4 +797,3 @@ let n = this._exportDecls[e[0]]; | ||
let n = a.declaration; | ||
if (o.isIdentifier(n) && (n = D(n.name, this._ast.program)), (o.isTSAsExpression(n) || o.isTSSatisfiesExpression(n)) && (n = n.expression), | ||
o.isObjectExpression(n)) { | ||
if (o.isIdentifier(n) && (n = D(n.name, this._ast.program)), n = L(n), o.isObjectExpression(n)) { | ||
let l = n.properties; | ||
@@ -863,4 +861,4 @@ i(l, e[0]), r = !0; | ||
if (i === "single") { | ||
let { code: r } = ae(o.valueToNode(e), { jsescOption: { quotes: i } }), a = ce(`const __x = ${r}`); | ||
le(a, { | ||
let { code: r } = le(o.valueToNode(e), { jsescOption: { quotes: i } }), a = pe(`const __x = ${r}`); | ||
ce(a, { | ||
VariableDeclaration: { | ||
@@ -989,20 +987,20 @@ enter({ node: n }) { | ||
} | ||
}, Ye = /* @__PURE__ */ p((s, e) => { | ||
let i = ce(s); | ||
return new z(i, s, e); | ||
}, "loadConfig"), Ze = /* @__PURE__ */ p((s) => et(s).code, "formatConfig"), et = /* @__PURE__ */ p((s, e = {}) => He.print(s._ast, e), "pri\ | ||
ntConfig"), Ft = /* @__PURE__ */ p(async (s) => { | ||
let e = (await Xe(s, "utf-8")).toString(); | ||
return Ye(e, s).parse(); | ||
}, "readConfig"), Ct = /* @__PURE__ */ p(async (s, e) => { | ||
}, Ze = /* @__PURE__ */ p((s, e) => { | ||
let i = pe(s); | ||
return new G(i, s, e); | ||
}, "loadConfig"), et = /* @__PURE__ */ p((s) => tt(s).code, "formatConfig"), tt = /* @__PURE__ */ p((s, e = {}) => Ye.print(s._ast, e), "pri\ | ||
ntConfig"), Ct = /* @__PURE__ */ p(async (s) => { | ||
let e = (await Qe(s, "utf-8")).toString(); | ||
return Ze(e, s).parse(); | ||
}, "readConfig"), Tt = /* @__PURE__ */ p(async (s, e) => { | ||
let i = e || s.fileName; | ||
if (!i) | ||
throw new Error("Please specify a fileName for writeConfig"); | ||
await Qe(i, Ze(s)); | ||
await He(i, et(s)); | ||
}, "writeConfig"); | ||
// src/csf-tools/getStorySortParameter.ts | ||
var ge = A(N(), 1); | ||
import { babelParse as tt, generate as me, types as y, traverse as rt } from "@storybook/core/babel"; | ||
var it = console, G = /* @__PURE__ */ p((s, e) => { | ||
var xe = A(N(), 1); | ||
import { babelParse as rt, generate as ge, types as y, traverse as it } from "@storybook/core/babel"; | ||
var st = console, J = /* @__PURE__ */ p((s, e) => { | ||
let i; | ||
@@ -1012,8 +1010,8 @@ return s.properties.forEach((t) => { | ||
}), i; | ||
}, "getValue"), J = /* @__PURE__ */ p((s) => { | ||
}, "getValue"), K = /* @__PURE__ */ p((s) => { | ||
let e = k(s); | ||
if (y.isArrayExpression(e)) | ||
return e.elements.map((i) => J(i)); | ||
return e.elements.map((i) => K(i)); | ||
if (y.isObjectExpression(e)) | ||
return e.properties.reduce((i, t) => (y.isIdentifier(t.key) && (i[t.key.name] = J(t.value)), i), {}); | ||
return e.properties.reduce((i, t) => (y.isIdentifier(t.key) && (i[t.key.name] = K(t.value)), i), {}); | ||
if (y.isLiteral(e)) | ||
@@ -1025,3 +1023,3 @@ return e.value; | ||
}, "parseValue"), v = /* @__PURE__ */ p((s, e) => { | ||
let i = ge.dedent` | ||
let i = xe.dedent` | ||
Unexpected '${s}'. Parameter 'options.storySort' should be defined inline e.g.: | ||
@@ -1039,27 +1037,27 @@ | ||
throw new Error(i); | ||
it.info(i); | ||
st.info(i); | ||
}, "unsupported"), k = /* @__PURE__ */ p((s) => y.isTSAsExpression(s) || y.isTSSatisfiesExpression(s) ? s.expression : s, "stripTSModifiers"), | ||
xe = /* @__PURE__ */ p((s) => { | ||
ye = /* @__PURE__ */ p((s) => { | ||
let e = k(s); | ||
if (y.isObjectExpression(e)) { | ||
let i = G(e, "options"); | ||
let i = J(e, "options"); | ||
if (i) { | ||
if (y.isObjectExpression(i)) | ||
return G(i, "storySort"); | ||
return J(i, "storySort"); | ||
v("options", !0); | ||
} | ||
} | ||
}, "parseParameters"), st = /* @__PURE__ */ p((s, e) => { | ||
}, "parseParameters"), nt = /* @__PURE__ */ p((s, e) => { | ||
let i = k(s); | ||
if (y.isObjectExpression(i)) { | ||
let t = G(i, "parameters"); | ||
let t = J(i, "parameters"); | ||
if (y.isIdentifier(t) && (t = O(t.name, e)), t) | ||
return xe(t); | ||
return ye(t); | ||
} else | ||
v("default", !0); | ||
}, "parseDefault"), Rt = /* @__PURE__ */ p((s) => { | ||
}, "parseDefault"), Lt = /* @__PURE__ */ p((s) => { | ||
if (!s.includes("storySort")) | ||
return; | ||
let e, i = tt(s); | ||
if (rt(i, { | ||
let e, i = rt(s); | ||
if (it(i, { | ||
ExportNamedDeclaration: { | ||
@@ -1072,3 +1070,3 @@ enter({ node: t }) { | ||
let n = k(r.init); | ||
e = xe(n); | ||
e = ye(n); | ||
} | ||
@@ -1084,3 +1082,3 @@ } | ||
let r = t.declaration; | ||
y.isIdentifier(r) && (r = O(r.name, i.program)), r = k(r), y.isObjectExpression(r) ? e = st(r, i.program) : v("default", !1); | ||
y.isIdentifier(r) && (r = O(r.name, i.program)), r = k(r), y.isObjectExpression(r) ? e = nt(r, i.program) : v("default", !1); | ||
} | ||
@@ -1090,7 +1088,7 @@ } | ||
if (y.isArrowFunctionExpression(e)) { | ||
let { code: t } = me(e, {}); | ||
let { code: t } = ge(e, {}); | ||
return (0, eval)(t); | ||
} | ||
if (y.isFunctionExpression(e)) { | ||
let { code: t } = me(e, {}), r = e.id?.name, a = `(a, b) => { | ||
let { code: t } = ge(e, {}), r = e.id?.name, a = `(a, b) => { | ||
${t}; | ||
@@ -1101,3 +1099,3 @@ return ${r}(a, b) | ||
} | ||
return y.isLiteral(e) || y.isArrayExpression(e) || y.isObjectExpression(e) ? J(e) : v("storySort", !0); | ||
return y.isLiteral(e) || y.isArrayExpression(e) || y.isObjectExpression(e) ? K(e) : v("storySort", !0); | ||
} | ||
@@ -1107,5 +1105,5 @@ }, "getStorySortParameter"); | ||
// src/csf-tools/enrichCsf.ts | ||
import { generate as nt, types as m } from "@storybook/core/babel"; | ||
var ot = /* @__PURE__ */ p((s, e, i, t) => { | ||
let r = e.getStoryExport(i), a = !t?.disableSource && lt(r), n = !t?.disableDescription && be(e._storyStatements[i]), l = [], u = m.memberExpression( | ||
import { generate as ot, types as m } from "@storybook/core/babel"; | ||
var at = /* @__PURE__ */ p((s, e, i, t) => { | ||
let r = e.getStoryExport(i), a = !t?.disableSource && ct(r), n = !t?.disableDescription && Ee(e._storyStatements[i]), l = [], u = m.memberExpression( | ||
m.identifier(i), m.identifier("parameters")); | ||
@@ -1165,3 +1163,3 @@ l.push(m.spreadElement(u)); | ||
} | ||
}, "enrichCsfStory"), ye = /* @__PURE__ */ p((s, e, i) => { | ||
}, "enrichCsfStory"), be = /* @__PURE__ */ p((s, e, i) => { | ||
if (!e.length) { | ||
@@ -1176,8 +1174,8 @@ s.properties.find( | ||
), n; | ||
a ? n = a.value : (n = m.objectExpression([]), s.properties.push(m.objectProperty(m.identifier(t), n))), ye(n, r, i); | ||
}, "addComponentDescription"), at = /* @__PURE__ */ p((s, e, i) => { | ||
let t = !i?.disableDescription && be(e._metaStatement); | ||
a ? n = a.value : (n = m.objectExpression([]), s.properties.push(m.objectProperty(m.identifier(t), n))), be(n, r, i); | ||
}, "addComponentDescription"), lt = /* @__PURE__ */ p((s, e, i) => { | ||
let t = !i?.disableDescription && Ee(e._metaStatement); | ||
if (t) { | ||
let r = s._metaNode; | ||
r && m.isObjectExpression(r) && ye( | ||
r && m.isObjectExpression(r) && be( | ||
r, | ||
@@ -1188,10 +1186,10 @@ ["parameters", "docs", "description"], | ||
} | ||
}, "enrichCsfMeta"), Ut = /* @__PURE__ */ p((s, e, i) => { | ||
at(s, e, i), Object.keys(s._storyExports).forEach((t) => { | ||
ot(s, e, t, i); | ||
}, "enrichCsfMeta"), qt = /* @__PURE__ */ p((s, e, i) => { | ||
lt(s, e, i), Object.keys(s._storyExports).forEach((t) => { | ||
at(s, e, t, i); | ||
}); | ||
}, "enrichCsf"), lt = /* @__PURE__ */ p((s) => { | ||
let e = m.isVariableDeclarator(s) ? s.init : s, { code: i } = nt(e, {}); | ||
}, "enrichCsf"), ct = /* @__PURE__ */ p((s) => { | ||
let e = m.isVariableDeclarator(s) ? s.init : s, { code: i } = ot(e, {}); | ||
return i; | ||
}, "extractSource"), be = /* @__PURE__ */ p((s) => s?.leadingComments ? s.leadingComments.map((i) => i.type === "CommentLine" || !i.value.startsWith( | ||
}, "extractSource"), Ee = /* @__PURE__ */ p((s) => s?.leadingComments ? s.leadingComments.map((i) => i.type === "CommentLine" || !i.value.startsWith( | ||
"*") ? null : i.value.split(` | ||
@@ -1203,14 +1201,14 @@ `).map((t) => t.replace(/^(\s+)?(\*+)?(\s)?/, "")).join(` | ||
// src/csf-tools/index.ts | ||
import { babelParse as rr } from "@storybook/core/babel"; | ||
import { babelParse as ir } from "@storybook/core/babel"; | ||
// src/csf-tools/vitest-plugin/transformer.ts | ||
var K = A(N(), 1); | ||
var X = A(N(), 1); | ||
import { types as f } from "@storybook/core/babel"; | ||
import { getStoryTitle as ct } from "@storybook/core/common"; | ||
import { combineTags as pt } from "@storybook/csf"; | ||
var Ee = console, ft = /* @__PURE__ */ p((s, e) => { | ||
import { getStoryTitle as pt } from "@storybook/core/common"; | ||
import { combineTags as ft } from "@storybook/csf"; | ||
var he = console, dt = /* @__PURE__ */ p((s, e) => { | ||
let i = e?.include.length === 0 || e?.include.some((r) => s.includes(r)), t = e?.exclude.every((r) => !s.includes(r)); | ||
return i && t; | ||
}, "isValidTest"); | ||
async function dt({ | ||
async function ut({ | ||
code: s, | ||
@@ -1225,7 +1223,7 @@ fileName: e, | ||
return s; | ||
let l = U(s, { | ||
let l = q(s, { | ||
fileName: e, | ||
transformInlineMeta: !0, | ||
makeTitle: /* @__PURE__ */ p((E) => { | ||
let j = ct({ | ||
let j = pt({ | ||
storyFilePath: e, | ||
@@ -1236,4 +1234,4 @@ configDir: i, | ||
}) || "unknown"; | ||
return j === "unknown" && Ee.warn( | ||
K.dedent` | ||
return j === "unknown" && he.warn( | ||
X.dedent` | ||
[Storybook]: Could not calculate story title for "${e}". | ||
@@ -1256,3 +1254,3 @@ Please make sure that this file matches the globs included in the "stories" field in your Storybook configuration at "${i}". | ||
Object.keys(l._stories).map((E) => { | ||
let j = pt( | ||
let j = ft( | ||
"test", | ||
@@ -1264,8 +1262,8 @@ "dev", | ||
); | ||
ft(j, r) && (h[E] = l._storyStatements[E]); | ||
dt(j, r) && (h[E] = l._storyStatements[E]); | ||
}); | ||
let _ = l._file.path.scope.generateUidIdentifier("test"), X = l._file.path.scope.generateUidIdentifier("describe"); | ||
let _ = l._file.path.scope.generateUidIdentifier("test"), Q = l._file.path.scope.generateUidIdentifier("describe"); | ||
if (Object.keys(h).length === 0) { | ||
let E = f.expressionStatement( | ||
f.callExpression(f.memberExpression(X, f.identifier("skip")), [ | ||
f.callExpression(f.memberExpression(Q, f.identifier("skip")), [ | ||
f.stringLiteral("No valid tests found") | ||
@@ -1279,3 +1277,3 @@ ]) | ||
f.importSpecifier(_, f.identifier("test")), | ||
f.importSpecifier(X, f.identifier("describe")) | ||
f.importSpecifier(Q, f.identifier("describe")) | ||
], | ||
@@ -1287,3 +1285,3 @@ f.stringLiteral("vitest") | ||
} else { | ||
let Q = function() { | ||
let H = function() { | ||
let S = l._file.path.scope.generateUidIdentifier("isRunningFromThisFile"), P = f.memberExpression( | ||
@@ -1295,3 +1293,3 @@ f.callExpression(f.memberExpression(E, f.identifier("getState")), []), | ||
f.identifier("filepath") | ||
), ve = f.logicalExpression( | ||
), Ie = f.logicalExpression( | ||
"??", | ||
@@ -1302,3 +1300,3 @@ // TODO: switch order of testPathProperty and filePathProperty when the bug is fixed | ||
P | ||
), Ie = f.callExpression( | ||
), Ne = f.callExpression( | ||
f.memberExpression( | ||
@@ -1311,14 +1309,14 @@ f.memberExpression( | ||
), | ||
[ve] | ||
[Ie] | ||
); | ||
return { isRunningFromThisFileDeclaration: f.variableDeclaration("const", [ | ||
f.variableDeclarator(S, Ie) | ||
f.variableDeclarator(S, Ne) | ||
]), isRunningFromThisFileId: S }; | ||
}; | ||
var ut = Q; | ||
p(Q, "getTestGuardDeclaration"); | ||
let E = l._file.path.scope.generateUidIdentifier("expect"), j = l._file.path.scope.generateUidIdentifier("testStory"), he = f.identifier( | ||
JSON.stringify(r.skip)), { isRunningFromThisFileDeclaration: _e, isRunningFromThisFileId: Se } = Q(); | ||
u.program.body.push(_e); | ||
let je = /* @__PURE__ */ p(({ | ||
var mt = H; | ||
p(H, "getTestGuardDeclaration"); | ||
let E = l._file.path.scope.generateUidIdentifier("expect"), j = l._file.path.scope.generateUidIdentifier("testStory"), _e = f.identifier( | ||
JSON.stringify(r.skip)), { isRunningFromThisFileDeclaration: Se, isRunningFromThisFileId: je } = H(); | ||
u.program.body.push(Se); | ||
let Oe = /* @__PURE__ */ p(({ | ||
exportName: S, | ||
@@ -1334,3 +1332,3 @@ node: P | ||
f.identifier(d), | ||
he | ||
_e | ||
]) | ||
@@ -1340,6 +1338,6 @@ ]) | ||
return V.loc = P.loc, V; | ||
}, "getTestStatementForStory"), Oe = Object.entries(h).map(([S, P]) => { | ||
}, "getTestStatementForStory"), Pe = Object.entries(h).map(([S, P]) => { | ||
if (P === null) { | ||
Ee.warn( | ||
K.dedent` | ||
he.warn( | ||
X.dedent` | ||
[Storybook]: Could not transform "${S}" story into test at "${e}". | ||
@@ -1351,9 +1349,9 @@ Please make sure to define stories in the same file and not re-export stories coming from other files". | ||
} | ||
return je({ | ||
return Oe({ | ||
exportName: S, | ||
node: P | ||
}); | ||
}).filter((S) => !!S), Pe = f.ifStatement(Se, f.blockStatement(Oe)); | ||
u.program.body.push(Pe); | ||
let De = [ | ||
}).filter((S) => !!S), De = f.ifStatement(je, f.blockStatement(Pe)); | ||
u.program.body.push(De); | ||
let ve = [ | ||
f.importDeclaration( | ||
@@ -1371,31 +1369,31 @@ [ | ||
]; | ||
u.program.body.unshift(...De); | ||
u.program.body.unshift(...ve); | ||
} | ||
return oe(l, { sourceMaps: !0, sourceFileName: e }, s); | ||
return ae(l, { sourceMaps: !0, sourceFileName: e }, s); | ||
} | ||
p(dt, "vitestTransform"); | ||
p(ut, "vitestTransform"); | ||
export { | ||
z as ConfigFile, | ||
$ as CsfFile, | ||
G as ConfigFile, | ||
U as CsfFile, | ||
R as NoMetaError, | ||
rr as babelParse, | ||
Je as babelParseFile, | ||
Ut as enrichCsf, | ||
at as enrichCsfMeta, | ||
ot as enrichCsfStory, | ||
be as extractDescription, | ||
lt as extractSource, | ||
Ze as formatConfig, | ||
oe as formatCsf, | ||
Rt as getStorySortParameter, | ||
Be as isModuleMock, | ||
Ye as loadConfig, | ||
U as loadCsf, | ||
et as printConfig, | ||
Ke as printCsf, | ||
Ft as readConfig, | ||
Pt as readCsf, | ||
dt as vitestTransform, | ||
Ct as writeConfig, | ||
Dt as writeCsf | ||
ir as babelParse, | ||
Ke as babelParseFile, | ||
qt as enrichCsf, | ||
lt as enrichCsfMeta, | ||
at as enrichCsfStory, | ||
Ee as extractDescription, | ||
ct as extractSource, | ||
et as formatConfig, | ||
ae as formatCsf, | ||
Lt as getStorySortParameter, | ||
We as isModuleMock, | ||
Ze as loadConfig, | ||
q as loadCsf, | ||
tt as printConfig, | ||
Xe as printCsf, | ||
Ct as readConfig, | ||
Dt as readCsf, | ||
ut as vitestTransform, | ||
Tt as writeConfig, | ||
vt as writeCsf | ||
}; |
{ | ||
"name": "@storybook/core", | ||
"version": "8.3.0-beta.0", | ||
"version": "8.3.0-beta.1", | ||
"description": "Storybook framework-agnostic API", | ||
@@ -289,2 +289,3 @@ "keywords": [ | ||
"semver": "^7.6.2", | ||
"util": "^0.12.5", | ||
"ws": "^8.2.3" | ||
@@ -422,3 +423,2 @@ }, | ||
"use-resize-observer": "^9.1.0", | ||
"util": "^0.12.4", | ||
"watchpack": "^2.2.0" | ||
@@ -425,0 +425,0 @@ }, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
130
32442237
11
539349
+ Addedutil@^0.12.5
+ Addedavailable-typed-arrays@1.0.7(transitive)
+ Addedfor-each@0.3.3(transitive)
+ Addedhas-tostringtag@1.0.2(transitive)
+ Addedis-arguments@1.1.1(transitive)
+ Addedis-callable@1.2.7(transitive)
+ Addedis-generator-function@1.0.10(transitive)
+ Addedis-typed-array@1.1.13(transitive)
+ Addedpossible-typed-array-names@1.0.0(transitive)
+ Addedutil@0.12.5(transitive)
+ Addedwhich-typed-array@1.1.15(transitive)