storycrawler
Advanced tools
Comparing version 4.2.0 to 4.3.0
@@ -44,19 +44,39 @@ "use strict"; | ||
}); | ||
await this.page.waitForFunction(() => window.__STORYBOOK_CLIENT_API__, { | ||
await this.page.waitForFunction(() => { | ||
var _a; | ||
return window.__STORYBOOK_CLIENT_API__ || | ||
((_a = window.__STORYBOOK_PREVIEW__) === null || _a === void 0 ? void 0 : _a.storyStoreValue); | ||
}, { | ||
timeout: 60000, | ||
}); | ||
await this.page.evaluate(() => { | ||
const { __STORYBOOK_CLIENT_API__: api } = window; | ||
api.storyStore && api.storyStore.cacheAllCSFFiles(); | ||
var _a; | ||
const api = window.__STORYBOOK_CLIENT_API__ || window.__STORYBOOK_PREVIEW__; | ||
function isPreviewApi(api) { | ||
return api.storyStoreValue !== undefined; | ||
} | ||
if (api === undefined) | ||
return; | ||
if (isPreviewApi(api)) { | ||
return api.storyStoreValue && api.storyStoreValue.cacheAllCSFFiles(); | ||
} | ||
return ((_a = api.storyStore) === null || _a === void 0 ? void 0 : _a.cacheAllCSFFiles) && api.storyStore.cacheAllCSFFiles(); | ||
}); | ||
const result = await this.page.evaluate(() => new Promise(res => { | ||
const getStories = (count = 0) => { | ||
const MAX_CONFIGURE_WAIT_COUNT = 4000; | ||
const { __STORYBOOK_CLIENT_API__: api } = window; | ||
if (api.raw) { | ||
const result = await this.page.evaluate(() => { | ||
function isPreviewApi(api) { | ||
return api.storyStoreValue !== undefined; | ||
} | ||
return new Promise(res => { | ||
const getStories = (count = 0) => { | ||
const MAX_CONFIGURE_WAIT_COUNT = 4000; | ||
const api = window.__STORYBOOK_CLIENT_API__ || window.__STORYBOOK_PREVIEW__; | ||
if (api === undefined) | ||
return; | ||
// for Storybook v6 | ||
const configuring = api.store && api.store()._configuring; | ||
const configuring = !isPreviewApi(api) && api.store && api.store()._configuring; | ||
// for Storybook v6 and 'storyStoreV7' option | ||
const configuringV7store = api.storyStore && !api.storyStore.cachedCSFFiles; | ||
if (configuring || configuringV7store) { | ||
const configuringV7store = !isPreviewApi(api) && api.storyStore && !api.storyStore.cachedCSFFiles; | ||
// for Storybook v8 | ||
const configuringV8store = isPreviewApi(api) && api.storyStoreValue && !api.storyStoreValue.cachedCSFFiles; | ||
if (configuring || configuringV7store || configuringV8store) { | ||
if (count < MAX_CONFIGURE_WAIT_COUNT) { | ||
@@ -70,9 +90,12 @@ setTimeout(() => getStories(++count), 16); | ||
} | ||
// for Storybook v5 | ||
const stories = api.raw().map(_ => ({ id: _.id, kind: _.kind, story: _.name, version: 'v5' })); | ||
const stories = (isPreviewApi(api) && api.storyStoreValue | ||
? Object.values(api.storyStoreValue.extract()) | ||
: api.raw | ||
? api.raw() | ||
: []).map(_ => ({ id: _.id, kind: _.kind, story: _.name, version: 'v5' })); | ||
res({ stories, timeout: false }); | ||
} | ||
}; | ||
getStories(); | ||
})); | ||
}; | ||
getStories(); | ||
}); | ||
}); | ||
if (result.timeout) { | ||
@@ -79,0 +102,0 @@ throw new errors_1.StoriesTimeoutError(); |
{ | ||
"name": "storycrawler", | ||
"version": "4.2.0", | ||
"version": "4.3.0", | ||
"description": "Utilities to build Storybook crawling tools with Puppeteer", | ||
@@ -43,7 +43,7 @@ "engines": { | ||
"devDependencies": { | ||
"@types/jest": "29.5.3", | ||
"jest": "29.6.1", | ||
"ts-jest": "29.1.1", | ||
"typedoc": "0.24.8", | ||
"typescript": "5.1.6" | ||
"@types/jest": "29.5.12", | ||
"jest": "29.7.0", | ||
"ts-jest": "29.1.2", | ||
"typedoc": "0.25.11", | ||
"typescript": "5.4.2" | ||
}, | ||
@@ -83,3 +83,3 @@ "dependencies": { | ||
}, | ||
"gitHead": "5717d29a59ef7f51429d3b631bbc8bb86323e983" | ||
"gitHead": "495fe9168e0156765d0f44abef3dafef3432b25f" | ||
} |
64386
1927