creevey 0.9.0-beta.13 → 0.9.0-beta.14
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/.yarn/install-state.gz +0 -0
- package/.yarnrc.yml +1 -0
- package/lib/cjs/cli.js +1 -0
- package/lib/cjs/client/addon/Manager.js +151 -223
- package/lib/cjs/client/addon/components/Addon.js +2 -9
- package/lib/cjs/client/addon/components/Icons.js +1 -7
- package/lib/cjs/client/addon/components/Panel.js +5 -18
- package/lib/cjs/client/addon/components/TestSelect.js +12 -25
- package/lib/cjs/client/addon/components/Tools.js +17 -28
- package/lib/cjs/client/addon/decorator.js +1 -4
- package/lib/cjs/client/addon/index.js +0 -4
- package/lib/cjs/client/addon/preset.js +3 -12
- package/lib/cjs/client/addon/preview.js +1 -4
- package/lib/cjs/client/addon/readyForCapture.js +1 -4
- package/lib/cjs/client/addon/register.js +11 -26
- package/lib/cjs/client/addon/utils.js +1 -9
- package/lib/cjs/client/addon/withCreevey.js +55 -134
- package/lib/cjs/client/shared/components/ImagesView/BlendView.js +5 -17
- package/lib/cjs/client/shared/components/ImagesView/ImagesView.js +8 -24
- package/lib/cjs/client/shared/components/ImagesView/SideBySideView.js +7 -23
- package/lib/cjs/client/shared/components/ImagesView/SlideView.js +7 -22
- package/lib/cjs/client/shared/components/ImagesView/SwapView.js +5 -17
- package/lib/cjs/client/shared/components/ImagesView/index.js +0 -5
- package/lib/cjs/client/shared/components/PageFooter/PageFooter.js +1 -8
- package/lib/cjs/client/shared/components/PageFooter/Paging.js +2 -19
- package/lib/cjs/client/shared/components/PageHeader/ImagePreview.js +21 -17
- package/lib/cjs/client/shared/components/PageHeader/PageHeader.js +5 -24
- package/lib/cjs/client/shared/components/ResultsPage.js +9 -37
- package/lib/cjs/client/shared/creeveyClientApi.js +3 -13
- package/lib/cjs/client/shared/helpers.js +21 -75
- package/lib/cjs/client/shared/viewMode.js +2 -6
- package/lib/cjs/client/web/192.js +1 -0
- package/lib/cjs/client/web/632.js +43 -0
- package/lib/cjs/client/web/794.js +1 -0
- package/lib/cjs/client/web/main.js +78 -1
- package/lib/cjs/client/web/main.js.LICENSE.txt +0 -15
- package/lib/cjs/creevey.js +5 -21
- package/lib/cjs/index.js +0 -15
- package/lib/cjs/server/config.js +13 -33
- package/lib/cjs/server/docker.js +5 -27
- package/lib/cjs/server/index.js +8 -33
- package/lib/cjs/server/logger.js +5 -19
- package/lib/cjs/server/master/api.js +1 -14
- package/lib/cjs/server/master/index.js +15 -46
- package/lib/cjs/server/master/master.js +6 -21
- package/lib/cjs/server/master/pool.js +2 -37
- package/lib/cjs/server/master/runner.js +15 -42
- package/lib/cjs/server/master/server.js +5 -27
- package/lib/cjs/server/messages.js +7 -53
- package/lib/cjs/server/selenium/browser.js +51 -136
- package/lib/cjs/server/selenium/index.js +0 -4
- package/lib/cjs/server/selenium/selenoid.js +7 -33
- package/lib/cjs/server/stories.js +25 -30
- package/lib/cjs/server/storybook/providers/browser.js +5 -18
- package/lib/cjs/server/storybook/providers/hybrid.js +9 -29
- package/lib/cjs/server/testsFiles/parser.js +3 -19
- package/lib/cjs/server/testsFiles/register.js +7 -9
- package/lib/cjs/server/update.js +3 -20
- package/lib/cjs/server/utils.js +9 -41
- package/lib/cjs/server/worker/chai-image.js +1 -27
- package/lib/cjs/server/worker/helpers.js +2 -12
- package/lib/cjs/server/worker/index.js +1 -3
- package/lib/cjs/server/worker/reporter.js +8 -24
- package/lib/cjs/server/worker/worker.js +5 -49
- package/lib/cjs/shared/index.js +22 -36
- package/lib/cjs/shared/serializeRegExp.js +0 -8
- package/lib/cjs/types.js +4 -14
- package/lib/esm/cli.js +1 -1
- package/lib/esm/client/addon/Manager.js +151 -214
- package/lib/esm/client/addon/components/Panel.js +4 -6
- package/lib/esm/client/addon/components/TestSelect.js +11 -17
- package/lib/esm/client/addon/components/Tools.js +15 -14
- package/lib/esm/client/addon/preset.js +2 -8
- package/lib/esm/client/addon/readyForCapture.js +1 -3
- package/lib/esm/client/addon/register.js +6 -8
- package/lib/esm/client/addon/utils.js +0 -5
- package/lib/esm/client/addon/withCreevey.js +54 -116
- package/lib/esm/client/shared/components/ImagesView/BlendView.js +1 -1
- package/lib/esm/client/shared/components/ImagesView/ImagesView.js +6 -8
- package/lib/esm/client/shared/components/ImagesView/SideBySideView.js +3 -4
- package/lib/esm/client/shared/components/ImagesView/SlideView.js +3 -3
- package/lib/esm/client/shared/components/ImagesView/SwapView.js +1 -1
- package/lib/esm/client/shared/components/PageFooter/Paging.js +1 -11
- package/lib/esm/client/shared/components/PageHeader/ImagePreview.js +18 -7
- package/lib/esm/client/shared/components/PageHeader/PageHeader.js +3 -8
- package/lib/esm/client/shared/components/ResultsPage.js +6 -15
- package/lib/esm/client/shared/creeveyClientApi.js +3 -10
- package/lib/esm/client/shared/helpers.js +21 -47
- package/lib/esm/client/web/192.js +1 -0
- package/lib/esm/client/web/632.js +43 -0
- package/lib/esm/client/web/794.js +1 -0
- package/lib/esm/client/web/index.html +19 -0
- package/lib/esm/client/web/main.js +79 -0
- package/lib/esm/client/web/main.js.LICENSE.txt +34 -0
- package/lib/esm/creevey.js +4 -8
- package/lib/esm/index.js +0 -1
- package/lib/esm/server/config.js +7 -14
- package/lib/esm/server/docker.js +4 -12
- package/lib/esm/server/index.js +7 -21
- package/lib/esm/server/logger.js +0 -1
- package/lib/esm/server/master/api.js +0 -9
- package/lib/esm/server/master/index.js +15 -32
- package/lib/esm/server/master/master.js +2 -7
- package/lib/esm/server/master/pool.js +0 -23
- package/lib/esm/server/master/runner.js +14 -27
- package/lib/esm/server/master/server.js +4 -9
- package/lib/esm/server/messages.js +6 -38
- package/lib/esm/server/selenium/browser.js +50 -114
- package/lib/esm/server/selenium/selenoid.js +6 -17
- package/lib/esm/server/stories.js +24 -20
- package/lib/esm/server/storybook/providers/browser.js +4 -8
- package/lib/esm/server/storybook/providers/hybrid.js +6 -14
- package/lib/esm/server/testsFiles/parser.js +0 -6
- package/lib/esm/server/testsFiles/register.js +5 -2
- package/lib/esm/server/update.js +0 -8
- package/lib/esm/server/utils.js +3 -11
- package/lib/esm/server/worker/chai-image.js +0 -21
- package/lib/esm/server/worker/helpers.js +2 -9
- package/lib/esm/server/worker/reporter.js +7 -10
- package/lib/esm/server/worker/worker.js +4 -25
- package/lib/esm/shared/index.js +24 -25
- package/lib/esm/types.js +4 -1
- package/lib/types/client/addon/Manager.d.ts +1 -1
- package/lib/types/client/addon/components/Addon.d.ts +1 -0
- package/lib/types/client/addon/components/Icons.d.ts +1 -0
- package/lib/types/client/addon/components/Panel.d.ts +1 -0
- package/lib/types/client/addon/components/TestSelect.d.ts +1 -0
- package/lib/types/client/addon/components/Tools.d.ts +1 -0
- package/lib/types/client/addon/decorator.d.ts +1 -1
- package/lib/types/client/addon/preset.d.ts +2 -2
- package/lib/types/client/addon/preview.d.ts +1 -1
- package/lib/types/client/addon/withCreevey.d.ts +3 -2
- package/lib/types/client/shared/components/ImagesView/BlendView.d.ts +3 -1
- package/lib/types/client/shared/components/ImagesView/ImagesView.d.ts +1 -0
- package/lib/types/client/shared/components/ImagesView/SideBySideView.d.ts +3 -1
- package/lib/types/client/shared/components/ImagesView/SlideView.d.ts +3 -1
- package/lib/types/client/shared/components/ImagesView/SwapView.d.ts +3 -1
- package/lib/types/client/shared/components/PageFooter/PageFooter.d.ts +1 -0
- package/lib/types/client/shared/components/PageFooter/Paging.d.ts +1 -0
- package/lib/types/client/shared/components/PageHeader/ImagePreview.d.ts +3 -1
- package/lib/types/client/shared/components/PageHeader/PageHeader.d.ts +1 -0
- package/lib/types/client/shared/components/ResultsPage.d.ts +3 -1
- package/lib/types/client/web/CreeveyApp.d.ts +1 -0
- package/lib/types/client/web/CreeveyLoader.d.ts +2 -1
- package/lib/types/client/web/CreeveyView/SideBar/Checkbox.d.ts +4 -1
- package/lib/types/client/web/CreeveyView/SideBar/Search.d.ts +1 -0
- package/lib/types/client/web/CreeveyView/SideBar/SideBarHeader.d.ts +1 -0
- package/lib/types/client/web/CreeveyView/SideBar/SuiteLink.d.ts +19 -14
- package/lib/types/client/web/CreeveyView/SideBar/TestLink.d.ts +1 -0
- package/lib/types/client/web/CreeveyView/SideBar/TestStatusIcon.d.ts +3 -1
- package/lib/types/client/web/CreeveyView/SideBar/TestsStatus.d.ts +3 -1
- package/lib/types/client/web/CreeveyView/SideBar/Toggle.d.ts +1 -0
- package/lib/types/shared/index.d.ts +1 -1
- package/lib/types/types.d.ts +7 -28
- package/package.json +60 -78
- package/lib/cjs/client/addon/preset.ie11.js +0 -74
- package/lib/cjs/client/addon/preset.sb7.js +0 -19
- package/lib/cjs/client/web/142.js +0 -2
- package/lib/cjs/client/web/142.js.LICENSE.txt +0 -12
- package/lib/cjs/client/web/32.js +0 -1
- package/lib/cjs/client/web/551.js +0 -1
- package/lib/cjs/client/web/566.js +0 -2
- package/lib/cjs/client/web/566.js.LICENSE.txt +0 -31
- package/lib/cjs/client/web/691.js +0 -2
- package/lib/cjs/client/web/691.js.LICENSE.txt +0 -8
- package/lib/cjs/client/web/725.js +0 -1
- package/lib/cjs/server/extract.js +0 -46
- package/lib/cjs/server/loaders/babel/creevey-plugin.js +0 -86
- package/lib/cjs/server/loaders/babel/helpers.js +0 -469
- package/lib/cjs/server/loaders/babel/register.js +0 -124
- package/lib/cjs/server/loaders/hooks/mdx.js +0 -30
- package/lib/cjs/server/loaders/hooks/svelte.js +0 -65
- package/lib/cjs/server/loaders/webpack/compile.js +0 -269
- package/lib/cjs/server/loaders/webpack/creevey-loader.js +0 -172
- package/lib/cjs/server/loaders/webpack/dummy-hmr.js +0 -39
- package/lib/cjs/server/loaders/webpack/mdx-loader.js +0 -72
- package/lib/cjs/server/loaders/webpack/start.js +0 -41
- package/lib/cjs/server/storybook/entry.js +0 -53
- package/lib/cjs/server/storybook/helpers.js +0 -158
- package/lib/cjs/server/storybook/providers/nodejs.js +0 -239
- package/lib/esm/client/addon/preset.ie11.js +0 -59
- package/lib/esm/client/addon/preset.sb7.js +0 -8
- package/lib/esm/server/extract.js +0 -32
- package/lib/esm/server/loaders/babel/creevey-plugin.js +0 -72
- package/lib/esm/server/loaders/babel/helpers.js +0 -452
- package/lib/esm/server/loaders/babel/register.js +0 -103
- package/lib/esm/server/loaders/hooks/mdx.js +0 -15
- package/lib/esm/server/loaders/hooks/svelte.js +0 -49
- package/lib/esm/server/loaders/webpack/compile.js +0 -246
- package/lib/esm/server/loaders/webpack/creevey-loader.js +0 -152
- package/lib/esm/server/loaders/webpack/dummy-hmr.js +0 -32
- package/lib/esm/server/loaders/webpack/mdx-loader.js +0 -58
- package/lib/esm/server/loaders/webpack/start.js +0 -27
- package/lib/esm/server/storybook/entry.js +0 -27
- package/lib/esm/server/storybook/helpers.js +0 -97
- package/lib/esm/server/storybook/providers/nodejs.js +0 -216
- package/lib/types/client/addon/preset.ie11.d.ts +0 -10
- package/lib/types/client/addon/preset.sb7.d.ts +0 -2
- package/lib/types/server/extract.d.ts +0 -2
- package/lib/types/server/loaders/babel/creevey-plugin.d.ts +0 -1
- package/lib/types/server/loaders/babel/helpers.d.ts +0 -19
- package/lib/types/server/loaders/babel/register.d.ts +0 -5
- package/lib/types/server/loaders/hooks/mdx.d.ts +0 -1
- package/lib/types/server/loaders/hooks/svelte.d.ts +0 -1
- package/lib/types/server/loaders/webpack/compile.d.ts +0 -2
- package/lib/types/server/loaders/webpack/creevey-loader.d.ts +0 -4
- package/lib/types/server/loaders/webpack/dummy-hmr.d.ts +0 -10
- package/lib/types/server/loaders/webpack/mdx-loader.d.ts +0 -6
- package/lib/types/server/loaders/webpack/start.d.ts +0 -1
- package/lib/types/server/storybook/entry.d.ts +0 -17
- package/lib/types/server/storybook/helpers.d.ts +0 -24
- package/lib/types/server/storybook/providers/nodejs.d.ts +0 -9
- package/preset/ie11.js +0 -5
- package/preset/index.js +0 -9
- package/preset/sb7.js +0 -5
- package/types/mdx.d.ts +0 -7
@@ -1,246 +0,0 @@
|
|
1
|
-
import { rmdirSync, writeFile } from 'fs';
|
2
|
-
import path from 'path';
|
3
|
-
import webpack from 'webpack';
|
4
|
-
import nodeExternals from 'webpack-node-externals';
|
5
|
-
import { extensions as fallbackExtensions, getCreeveyCache } from '../../utils';
|
6
|
-
import { getStorybookFramework, hasDocsAddon, importStorybookConfig, resolveFromStorybook } from '../../storybook/helpers';
|
7
|
-
import { noop } from '../../../types';
|
8
|
-
import { emitWebpackMessage, subscribeOn } from '../../messages';
|
9
|
-
import { logger } from '../../logger';
|
10
|
-
let isInitiated = false;
|
11
|
-
let dumpStats = noop;
|
12
|
-
|
13
|
-
function handleWebpackBuild(error, stats) {
|
14
|
-
var _stats$toJson$warning;
|
15
|
-
|
16
|
-
dumpStats(stats);
|
17
|
-
|
18
|
-
if (error || !stats || stats.hasErrors()) {
|
19
|
-
emitWebpackMessage({
|
20
|
-
type: isInitiated ? 'rebuild failed' : 'fail'
|
21
|
-
});
|
22
|
-
console.error('=> Failed to build the Storybook preview bundle');
|
23
|
-
if (error) return console.error(error.message);
|
24
|
-
|
25
|
-
if (stats && (stats.hasErrors() || stats.hasWarnings())) {
|
26
|
-
var _statsJson$errors, _statsJson$warnings;
|
27
|
-
|
28
|
-
const statsJson = stats.toJson();
|
29
|
-
(_statsJson$errors = statsJson.errors) === null || _statsJson$errors === void 0 ? void 0 : _statsJson$errors.forEach(e => console.error(e));
|
30
|
-
(_statsJson$warnings = statsJson.warnings) === null || _statsJson$warnings === void 0 ? void 0 : _statsJson$warnings.forEach(e => console.error(e));
|
31
|
-
return;
|
32
|
-
}
|
33
|
-
}
|
34
|
-
|
35
|
-
stats === null || stats === void 0 ? void 0 : (_stats$toJson$warning = stats.toJson().warnings) === null || _stats$toJson$warning === void 0 ? void 0 : _stats$toJson$warning.forEach(e => console.warn(e));
|
36
|
-
|
37
|
-
if (!isInitiated) {
|
38
|
-
isInitiated = true;
|
39
|
-
emitWebpackMessage({
|
40
|
-
type: 'success'
|
41
|
-
});
|
42
|
-
} else {
|
43
|
-
emitWebpackMessage({
|
44
|
-
type: 'rebuild succeeded'
|
45
|
-
});
|
46
|
-
}
|
47
|
-
|
48
|
-
return;
|
49
|
-
}
|
50
|
-
|
51
|
-
async function applyMdxLoader(config, areAddonsRemoved, loader) {
|
52
|
-
const {
|
53
|
-
mdxLoaders
|
54
|
-
} = await import('./mdx-loader');
|
55
|
-
mdxLoaders.splice(1, 0, loader);
|
56
|
-
const mdxRegexps = [/(stories|story)\.mdx$/]; // NOTE replace md/mdx to null loader
|
57
|
-
|
58
|
-
const mdRegexps = [/\.md$/, /\.mdx$/];
|
59
|
-
|
60
|
-
if (areAddonsRemoved) {
|
61
|
-
var _config$module2, _config$module2$rules;
|
62
|
-
|
63
|
-
mdRegexps.forEach(test => {
|
64
|
-
var _config$module, _config$module$rules;
|
65
|
-
|
66
|
-
return (_config$module = config.module) === null || _config$module === void 0 ? void 0 : (_config$module$rules = _config$module.rules) === null || _config$module$rules === void 0 ? void 0 : _config$module$rules.unshift({
|
67
|
-
test,
|
68
|
-
exclude: /(stories|story)\.mdx$/,
|
69
|
-
use: require.resolve('null-loader')
|
70
|
-
});
|
71
|
-
});
|
72
|
-
(_config$module2 = config.module) === null || _config$module2 === void 0 ? void 0 : (_config$module2$rules = _config$module2.rules) === null || _config$module2$rules === void 0 ? void 0 : _config$module2$rules.unshift({
|
73
|
-
test: /(stories|story)\.mdx$/,
|
74
|
-
use: mdxLoaders
|
75
|
-
});
|
76
|
-
} else {
|
77
|
-
var _config$module3, _config$module3$rules, _config$module4, _config$module4$rules, _config$module5, _config$module5$rules;
|
78
|
-
|
79
|
-
// NOTE Exclude addons' entry points
|
80
|
-
config.entry = Array.isArray(config.entry) ? config.entry.filter(entry => !/@storybook(\/|\\)addon/.test(entry)) : config.entry;
|
81
|
-
(_config$module3 = config.module) === null || _config$module3 === void 0 ? void 0 : (_config$module3$rules = _config$module3.rules) === null || _config$module3$rules === void 0 ? void 0 : _config$module3$rules.flatMap(rule => typeof rule == 'object' && 'test' in rule ? rule : []).filter(rule => mdRegexps.some(test => {
|
82
|
-
var _rule$test;
|
83
|
-
|
84
|
-
return ((_rule$test = rule.test) === null || _rule$test === void 0 ? void 0 : _rule$test.toString()) == test.toString();
|
85
|
-
})).forEach(rule => rule.use = require.resolve('null-loader'));
|
86
|
-
(_config$module4 = config.module) === null || _config$module4 === void 0 ? void 0 : (_config$module4$rules = _config$module4.rules) === null || _config$module4$rules === void 0 ? void 0 : _config$module4$rules.flatMap(rule => typeof rule == 'object' && 'test' in rule ? rule : []).filter(rule => mdxRegexps.some(test => {
|
87
|
-
var _rule$test2;
|
88
|
-
|
89
|
-
return ((_rule$test2 = rule.test) === null || _rule$test2 === void 0 ? void 0 : _rule$test2.toString()) == test.toString();
|
90
|
-
})).forEach(rule => rule.use = mdxLoaders); // NOTE Exclude source-loader
|
91
|
-
|
92
|
-
config.module = { ...config.module,
|
93
|
-
rules: ((_config$module5 = config.module) === null || _config$module5 === void 0 ? void 0 : (_config$module5$rules = _config$module5.rules) === null || _config$module5$rules === void 0 ? void 0 : _config$module5$rules.flatMap(rule => typeof rule == 'object' && 'test' in rule ? rule : []).filter(rule => !(typeof rule.loader == 'string' && /@storybook(\/|\\)source-loader/.test(rule.loader)))) ?? []
|
94
|
-
};
|
95
|
-
}
|
96
|
-
}
|
97
|
-
|
98
|
-
async function getWebpackConfigForStorybook_6_2(framework, configDir, outputDir) {
|
99
|
-
const {
|
100
|
-
default: storybookFrameworkOptions
|
101
|
-
} = await import(resolveFromStorybook(`@storybook/${framework}/dist/cjs/server/options`));
|
102
|
-
const options = {
|
103
|
-
quiet: true,
|
104
|
-
configType: 'PRODUCTION',
|
105
|
-
outputDir,
|
106
|
-
configDir,
|
107
|
-
...storybookFrameworkOptions
|
108
|
-
}; // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
109
|
-
|
110
|
-
const {
|
111
|
-
getPreviewBuilder
|
112
|
-
} = await import(resolveFromStorybook('@storybook/core-server/dist/cjs/utils/get-preview-builder')); // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
113
|
-
|
114
|
-
const {
|
115
|
-
loadAllPresets
|
116
|
-
} = await import(resolveFromStorybook('@storybook/core-common')); // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
|
117
|
-
|
118
|
-
const builder = await getPreviewBuilder(configDir); // NOTE: Copy-paste from storybook/lib/core-server/src/build-dev.ts
|
119
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
|
120
|
-
|
121
|
-
const presets = loadAllPresets({
|
122
|
-
corePresets: [// eslint-disable-next-line node/no-missing-require
|
123
|
-
resolveFromStorybook('@storybook/core-server/dist/cjs/presets/common-preset'), // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
|
124
|
-
...builder.corePresets, // eslint-disable-next-line node/no-missing-require
|
125
|
-
resolveFromStorybook('@storybook/core-server/dist/cjs/presets/babel-cache-preset')],
|
126
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
|
127
|
-
overridePresets: [...(hasDocsAddon() ? [require.resolve('./mdx-loader')] : []), // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
|
128
|
-
...builder.overridePresets],
|
129
|
-
...options
|
130
|
-
}); // eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-assignment
|
131
|
-
|
132
|
-
return builder.getConfig({ ...options,
|
133
|
-
presets
|
134
|
-
});
|
135
|
-
}
|
136
|
-
|
137
|
-
async function removeAddons() {
|
138
|
-
try {
|
139
|
-
var _config$core;
|
140
|
-
|
141
|
-
const config = await importStorybookConfig();
|
142
|
-
|
143
|
-
if (((_config$core = config.core) === null || _config$core === void 0 ? void 0 : _config$core.builder) == 'webpack5') {
|
144
|
-
logger.warn("Be aware Creevey doesn't fully support webpack@5, some feature might not work well");
|
145
|
-
}
|
146
|
-
|
147
|
-
if (config.addons && config.stories) {
|
148
|
-
config.addons = [];
|
149
|
-
return true;
|
150
|
-
}
|
151
|
-
} catch (_) {
|
152
|
-
/* noop */
|
153
|
-
}
|
154
|
-
|
155
|
-
return false;
|
156
|
-
}
|
157
|
-
|
158
|
-
export default async function compile(config, {
|
159
|
-
debug,
|
160
|
-
ui
|
161
|
-
}) {
|
162
|
-
var _storybookWebpackConf, _storybookWebpackConf2, _storybookWebpackConf3, _extensions$map, _storybookWebpackConf4, _storybookWebpackConf5;
|
163
|
-
|
164
|
-
const storybookFramework = getStorybookFramework();
|
165
|
-
const outputDir = path.join(getCreeveyCache(), 'storybook');
|
166
|
-
|
167
|
-
try {
|
168
|
-
rmdirSync(outputDir, {
|
169
|
-
recursive: true
|
170
|
-
});
|
171
|
-
} catch (_) {
|
172
|
-
/* noop */
|
173
|
-
}
|
174
|
-
|
175
|
-
const creeveyLoader = {
|
176
|
-
loader: require.resolve('./creevey-loader'),
|
177
|
-
options: {
|
178
|
-
debug,
|
179
|
-
storybookDir: config.storybookDir
|
180
|
-
}
|
181
|
-
};
|
182
|
-
process.env.NODE_ENV = 'production'; // NOTE Remove addons by monkey patching, only for new config file (main.js)
|
183
|
-
|
184
|
-
const areAddonsRemoved = await removeAddons();
|
185
|
-
const getWebpackConfig = getWebpackConfigForStorybook_6_2;
|
186
|
-
const storybookWebpackConfig = await getWebpackConfig(storybookFramework, config.storybookDir, outputDir);
|
187
|
-
const extensions = ((_storybookWebpackConf = storybookWebpackConfig.resolve) === null || _storybookWebpackConf === void 0 ? void 0 : _storybookWebpackConf.extensions) ?? fallbackExtensions;
|
188
|
-
delete storybookWebpackConfig.optimization;
|
189
|
-
storybookWebpackConfig.devtool = false;
|
190
|
-
storybookWebpackConfig.performance = false;
|
191
|
-
storybookWebpackConfig.profile = debug;
|
192
|
-
storybookWebpackConfig.mode = 'development';
|
193
|
-
storybookWebpackConfig.target = 'node';
|
194
|
-
storybookWebpackConfig.output = { ...storybookWebpackConfig.output,
|
195
|
-
filename: 'main.js'
|
196
|
-
}; // NOTE Add hack to allow stories HMR work in nodejs
|
197
|
-
|
198
|
-
Array.isArray(storybookWebpackConfig.entry) && storybookWebpackConfig.entry.unshift(require.resolve('./dummy-hmr')); // NOTE apply creevey loader to output from mdx loader
|
199
|
-
|
200
|
-
if (hasDocsAddon()) await applyMdxLoader(storybookWebpackConfig, areAddonsRemoved, creeveyLoader); // NOTE Add creevey-loader to cut off all unnecessary code except stories meta and tests
|
201
|
-
|
202
|
-
(_storybookWebpackConf2 = storybookWebpackConfig.module) === null || _storybookWebpackConf2 === void 0 ? void 0 : (_storybookWebpackConf3 = _storybookWebpackConf2.rules) === null || _storybookWebpackConf3 === void 0 ? void 0 : _storybookWebpackConf3.unshift({
|
203
|
-
enforce: 'pre',
|
204
|
-
test: new RegExp(`\\.(${(_extensions$map = extensions.map(x => x.slice(1))) === null || _extensions$map === void 0 ? void 0 : _extensions$map.join('|')})$`),
|
205
|
-
exclude: /node_modules/,
|
206
|
-
use: creeveyLoader
|
207
|
-
});
|
208
|
-
const aliases = ((_storybookWebpackConf4 = storybookWebpackConfig.resolve) === null || _storybookWebpackConf4 === void 0 ? void 0 : _storybookWebpackConf4.alias) ?? {};
|
209
|
-
const excluded = ['@storybook/addons', '@storybook/api', '@storybook/channel-postmessage', '@storybook/channels', '@storybook/client-api', '@storybook/client-logger', '@storybook/components', '@storybook/core-events', '@storybook/router', '@storybook/semver', '@storybook/theming']; // NOTE Exclude from bundle all modules from node_modules
|
210
|
-
|
211
|
-
storybookWebpackConfig.externals = [...(Array.isArray(aliases) ? aliases.map(({
|
212
|
-
name,
|
213
|
-
alias
|
214
|
-
}) => [name, alias]) : Object.entries(aliases)).filter(([alias]) => excluded.includes(alias)).flatMap(([, aliasPath]) => aliasPath == false ? [] : (Array.isArray(aliasPath) ? aliasPath : [aliasPath]).map(x => ({
|
215
|
-
[x]: `commonjs ${x}`
|
216
|
-
}))), // NOTE Replace `@storybook/${framework}` to ../../storybook.ts
|
217
|
-
{
|
218
|
-
[`@storybook/${storybookFramework}`]: `commonjs ${require.resolve('../../storybook/entry')}`
|
219
|
-
}, nodeExternals({
|
220
|
-
includeAbsolutePaths: true,
|
221
|
-
allowlist: /(webpack|dummy-hmr|generated-stories-entry|generated-config-entry|generated-other-entry)/
|
222
|
-
}), // TODO Don't work well with monorepos
|
223
|
-
nodeExternals({
|
224
|
-
modulesDir: resolveFromStorybook('@storybook/core-client').split('@storybook')[0],
|
225
|
-
includeAbsolutePaths: true,
|
226
|
-
allowlist: /(webpack|dummy-hmr|generated-stories-entry|generated-config-entry|generated-other-entry)/
|
227
|
-
})]; // NOTE Exclude some plugins
|
228
|
-
|
229
|
-
const excludedPlugins = ['DocgenPlugin', 'ForkTsCheckerWebpackPlugin'];
|
230
|
-
storybookWebpackConfig.plugins = (_storybookWebpackConf5 = storybookWebpackConfig.plugins) === null || _storybookWebpackConf5 === void 0 ? void 0 : _storybookWebpackConf5.filter(plugin => !excludedPlugins.includes(plugin.constructor.name));
|
231
|
-
const storybookWebpackCompiler = webpack(storybookWebpackConfig);
|
232
|
-
|
233
|
-
if (debug) {
|
234
|
-
dumpStats = stats => {
|
235
|
-
if (!stats) return;
|
236
|
-
writeFile(path.join(config.reportDir, 'stats.json'), JSON.stringify(stats.toJson(), null, 2), noop);
|
237
|
-
};
|
238
|
-
}
|
239
|
-
|
240
|
-
if (ui) {
|
241
|
-
const watcher = storybookWebpackCompiler.watch({}, handleWebpackBuild);
|
242
|
-
subscribeOn('shutdown', () => watcher.close(noop));
|
243
|
-
} else {
|
244
|
-
storybookWebpackCompiler.run(handleWebpackBuild);
|
245
|
-
}
|
246
|
-
}
|
@@ -1,152 +0,0 @@
|
|
1
|
-
import path from 'path';
|
2
|
-
import { codeFrameColumns } from '@babel/code-frame';
|
3
|
-
import { getOptions } from 'loader-utils';
|
4
|
-
import { validate } from 'schema-utils';
|
5
|
-
import { parse } from '@babel/parser';
|
6
|
-
import traverse from '@babel/traverse';
|
7
|
-
import generate from '@babel/generator';
|
8
|
-
import { commonVisitor, mdxVisitor, previewVisitor, storyVisitor, FileType } from '../babel/helpers';
|
9
|
-
import { logger } from '../../logger';
|
10
|
-
|
11
|
-
function transform(ast) {
|
12
|
-
traverse(ast, { ...commonVisitor,
|
13
|
-
...(fileType == FileType.Preview ? previewVisitor : undefined),
|
14
|
-
...(fileType == FileType.Story ? storyVisitor : undefined),
|
15
|
-
...(isMDX ? mdxVisitor : undefined)
|
16
|
-
}, undefined, {
|
17
|
-
resourcePath,
|
18
|
-
fileType,
|
19
|
-
isMDX,
|
20
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
21
|
-
visitedTopPaths: new Set(),
|
22
|
-
visitedBindings: new Set(),
|
23
|
-
reexportedStories
|
24
|
-
});
|
25
|
-
return generate(ast, {
|
26
|
-
retainLines: true
|
27
|
-
}).code;
|
28
|
-
}
|
29
|
-
|
30
|
-
function toPosix(filePath) {
|
31
|
-
return filePath.split(path.win32.sep).join(path.posix.sep).replace(/^[a-z]:/i, '');
|
32
|
-
}
|
33
|
-
|
34
|
-
function getIssuerResource(context) {
|
35
|
-
var _context$_module, _context$_module$issu;
|
36
|
-
|
37
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-return
|
38
|
-
return (_context$_module = context._module) === null || _context$_module === void 0 ? void 0 : (_context$_module$issu = _context$_module.issuer) === null || _context$_module$issu === void 0 ? void 0 : _context$_module$issu.resource;
|
39
|
-
}
|
40
|
-
|
41
|
-
function getIssuerConstructorName(context) {
|
42
|
-
var _context$_module2, _context$_module2$iss, _context$_module2$iss2;
|
43
|
-
|
44
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-return
|
45
|
-
return (_context$_module2 = context._module) === null || _context$_module2 === void 0 ? void 0 : (_context$_module2$iss = _context$_module2.issuer) === null || _context$_module2$iss === void 0 ? void 0 : (_context$_module2$iss2 = _context$_module2$iss.constructor) === null || _context$_module2$iss2 === void 0 ? void 0 : _context$_module2$iss2.name;
|
46
|
-
}
|
47
|
-
|
48
|
-
function isEntry(context) {
|
49
|
-
return getIssuerConstructorName(context) == 'MultiModule';
|
50
|
-
}
|
51
|
-
|
52
|
-
function isPreview(context, options) {
|
53
|
-
const {
|
54
|
-
dir: resourceDir,
|
55
|
-
name: resourceName
|
56
|
-
} = path.posix.parse(toPosix(context.resourcePath));
|
57
|
-
const storybookDir = typeof options.storybookDir == 'string' ? toPosix(options.storybookDir) : '';
|
58
|
-
const isConfigFile = resourceDir == storybookDir && (resourceName == 'preview' || resourceName == 'config');
|
59
|
-
const issuerResource = getIssuerResource(context);
|
60
|
-
return Boolean(issuerResource && entries.has(issuerResource) && isConfigFile);
|
61
|
-
}
|
62
|
-
|
63
|
-
function isStoryFile(context) {
|
64
|
-
var _reexportedStories$ge, _context$_module3;
|
65
|
-
|
66
|
-
const issuerResource = getIssuerResource(context);
|
67
|
-
return getIssuerConstructorName(context) == 'ContextModule' || // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
68
|
-
Boolean(issuerResource && ((_reexportedStories$ge = reexportedStories.get(issuerResource)) === null || _reexportedStories$ge === void 0 ? void 0 : _reexportedStories$ge.has((_context$_module3 = context._module) === null || _context$_module3 === void 0 ? void 0 : _context$_module3.rawRequest))) || issuerResource == previewPath && path.posix.parse(toPosix(previewPath)).name == 'config';
|
69
|
-
} // NOTE: non-story files before preview => issuer.resource is entry
|
70
|
-
|
71
|
-
|
72
|
-
const schema = {
|
73
|
-
type: 'object',
|
74
|
-
properties: {
|
75
|
-
debug: {
|
76
|
-
type: 'boolean'
|
77
|
-
},
|
78
|
-
storybookDir: {
|
79
|
-
type: 'string'
|
80
|
-
}
|
81
|
-
}
|
82
|
-
};
|
83
|
-
let fileType = FileType.Invalid;
|
84
|
-
let isMDX = false;
|
85
|
-
let previewPath = '';
|
86
|
-
let resourcePath = '';
|
87
|
-
const entries = new Set();
|
88
|
-
const stories = new Set();
|
89
|
-
const reexportedStories = new Map();
|
90
|
-
|
91
|
-
const isTest = () => process.env.__CREEVEY_ENV__ == 'test';
|
92
|
-
|
93
|
-
const defaultOptions = {
|
94
|
-
get debug() {
|
95
|
-
return isTest();
|
96
|
-
},
|
97
|
-
|
98
|
-
storybookDir: process.cwd()
|
99
|
-
};
|
100
|
-
export default function loader(source) {
|
101
|
-
const options = this ? getOptions(this) || defaultOptions : defaultOptions;
|
102
|
-
validate(schema, options, {
|
103
|
-
name: 'Creevey Stories Loader'
|
104
|
-
});
|
105
|
-
fileType = FileType.Invalid;
|
106
|
-
|
107
|
-
if (this) {
|
108
|
-
const issuerResource = getIssuerResource(this);
|
109
|
-
resourcePath = this.resourcePath;
|
110
|
-
|
111
|
-
if (isStoryFile(this)) {
|
112
|
-
fileType = FileType.Story;
|
113
|
-
isMDX = path.parse(resourcePath).ext == '.mdx';
|
114
|
-
stories.add(this.resourcePath);
|
115
|
-
} else if (isPreview(this, options)) {
|
116
|
-
fileType = FileType.Preview;
|
117
|
-
previewPath = this.resourcePath;
|
118
|
-
} else if (isEntry(this)) {
|
119
|
-
fileType = FileType.Entry;
|
120
|
-
entries.add(this.resourcePath);
|
121
|
-
return source;
|
122
|
-
} else if (issuerResource && stories.has(issuerResource) && options.debug) {
|
123
|
-
logger.warn('Trying to transform possible non-story file', this.resourcePath, 'Please check the', issuerResource); // TODO Add link to docs, how creevey works and what user should do in this situation
|
124
|
-
}
|
125
|
-
}
|
126
|
-
|
127
|
-
if (isTest() && !Number.isNaN(Number(process.env.CREEVEY_LOADER_FILE_TYPE))) {
|
128
|
-
fileType = Number(process.env.CREEVEY_LOADER_FILE_TYPE);
|
129
|
-
}
|
130
|
-
|
131
|
-
try {
|
132
|
-
const ast = parse(source, {
|
133
|
-
sourceType: 'module',
|
134
|
-
plugins: ['classProperties', 'decorators-legacy', 'jsx', 'typescript']
|
135
|
-
});
|
136
|
-
return transform(ast);
|
137
|
-
} catch (error) {
|
138
|
-
this && logger.warn('Failed to transform file', this.resourcePath);
|
139
|
-
|
140
|
-
if (typeof error == 'object' && error && 'loc' in error) {
|
141
|
-
logger.warn(codeFrameColumns(source, {
|
142
|
-
start: error.loc
|
143
|
-
}, {
|
144
|
-
highlightCode: true
|
145
|
-
}));
|
146
|
-
} else {
|
147
|
-
logger.warn(error);
|
148
|
-
}
|
149
|
-
|
150
|
-
return source;
|
151
|
-
}
|
152
|
-
}
|
@@ -1,32 +0,0 @@
|
|
1
|
-
global.__CREEVEY_HMR_DATA__ = global.__CREEVEY_HMR_DATA__ ?? {};
|
2
|
-
Object.entries(__webpack_require__.m).forEach(([key, moduleFn]) => {
|
3
|
-
__webpack_require__.m[key] = new Proxy(moduleFn, {
|
4
|
-
apply(target, thisArg, args) {
|
5
|
-
const [module] = args;
|
6
|
-
const {
|
7
|
-
data
|
8
|
-
} = global.__CREEVEY_HMR_DATA__[module.i] = global.__CREEVEY_HMR_DATA__[module.i] ?? {
|
9
|
-
data: {}
|
10
|
-
};
|
11
|
-
Object.assign(module, {
|
12
|
-
hot: {
|
13
|
-
accept() {
|
14
|
-
/* noop */
|
15
|
-
},
|
16
|
-
|
17
|
-
get data() {
|
18
|
-
return data;
|
19
|
-
},
|
20
|
-
|
21
|
-
dispose(callback) {
|
22
|
-
global.__CREEVEY_HMR_DATA__[module.i].callback = callback;
|
23
|
-
}
|
24
|
-
|
25
|
-
}
|
26
|
-
});
|
27
|
-
return target.apply(thisArg, args);
|
28
|
-
}
|
29
|
-
|
30
|
-
});
|
31
|
-
});
|
32
|
-
export default {};
|
@@ -1,58 +0,0 @@
|
|
1
|
-
/* eslint-disable */
|
2
|
-
|
3
|
-
/* Copy-paste from storybook/addons/docs/src/frameworks/common/preset.ts */
|
4
|
-
import { resolveFromStorybook, resolveFromStorybookAddonDocs, resolveFromStorybookBuilderWebpack4 } from '../../storybook/helpers';
|
5
|
-
export let mdxLoaders = []; // for frameworks that are not working with react, we need to configure
|
6
|
-
// the jsx to transpile mdx, for now there will be a flag for that
|
7
|
-
// for more complex solutions we can find alone that we need to add '@babel/plugin-transform-react-jsx'
|
8
|
-
|
9
|
-
function createBabelOptions({
|
10
|
-
babelOptions,
|
11
|
-
mdxBabelOptions,
|
12
|
-
configureJSX
|
13
|
-
}) {
|
14
|
-
const babelPlugins = (mdxBabelOptions === null || mdxBabelOptions === void 0 ? void 0 : mdxBabelOptions.plugins) || (babelOptions === null || babelOptions === void 0 ? void 0 : babelOptions.plugins) || [];
|
15
|
-
const jsxPlugin = [resolveFromStorybookAddonDocs('@babel/plugin-transform-react-jsx'), {
|
16
|
-
pragma: 'React.createElement',
|
17
|
-
pragmaFrag: 'React.Fragment'
|
18
|
-
}];
|
19
|
-
const plugins = configureJSX ? [...babelPlugins, jsxPlugin] : babelPlugins;
|
20
|
-
return {
|
21
|
-
// don't use the root babelrc by default (users can override this in mdxBabelOptions)
|
22
|
-
babelrc: false,
|
23
|
-
configFile: false,
|
24
|
-
...babelOptions,
|
25
|
-
...mdxBabelOptions,
|
26
|
-
plugins
|
27
|
-
};
|
28
|
-
}
|
29
|
-
|
30
|
-
const remarkPlugins = ['remark-slug', 'remark-external-links'].map(plugin => require(resolveFromStorybookAddonDocs(plugin)));
|
31
|
-
|
32
|
-
const createCompiler = require(resolveFromStorybook('@storybook/addon-docs/mdx-compiler-plugin'));
|
33
|
-
|
34
|
-
export const mdxOptions = (options = {}) => ({
|
35
|
-
compilers: [createCompiler(options)],
|
36
|
-
remarkPlugins
|
37
|
-
});
|
38
|
-
export function webpack(webpackConfig = {}, options = {}) {
|
39
|
-
// it will reuse babel options that are already in use in storybook
|
40
|
-
// also, these babel options are chained with other presets.
|
41
|
-
const {
|
42
|
-
babelOptions,
|
43
|
-
mdxBabelOptions,
|
44
|
-
configureJSX = true
|
45
|
-
} = options;
|
46
|
-
mdxLoaders = [{
|
47
|
-
loader: resolveFromStorybookBuilderWebpack4('babel-loader'),
|
48
|
-
options: createBabelOptions({
|
49
|
-
babelOptions,
|
50
|
-
mdxBabelOptions,
|
51
|
-
configureJSX
|
52
|
-
})
|
53
|
-
}, {
|
54
|
-
loader: resolveFromStorybookAddonDocs('@mdx-js/loader'),
|
55
|
-
options: mdxOptions(options)
|
56
|
-
}];
|
57
|
-
return webpackConfig;
|
58
|
-
}
|
@@ -1,27 +0,0 @@
|
|
1
|
-
import cluster from 'cluster';
|
2
|
-
import { isWebpackMessage } from '../../../types';
|
3
|
-
import { emitWebpackMessage } from '../../messages';
|
4
|
-
export function startWebpackCompiler() {
|
5
|
-
return new Promise((resolve, reject) => {
|
6
|
-
cluster.setupMaster({
|
7
|
-
args: ['--webpack', ...process.argv.slice(2)]
|
8
|
-
});
|
9
|
-
const webpackCompiler = cluster.fork();
|
10
|
-
webpackCompiler.on('message', message => {
|
11
|
-
if (!isWebpackMessage(message)) return;
|
12
|
-
Object.values(cluster.workers ?? {}).filter(worker => worker != webpackCompiler).forEach(worker => worker === null || worker === void 0 ? void 0 : worker.send(message));
|
13
|
-
|
14
|
-
switch (message.type) {
|
15
|
-
case 'success':
|
16
|
-
return resolve();
|
17
|
-
|
18
|
-
case 'fail':
|
19
|
-
return reject();
|
20
|
-
|
21
|
-
case 'rebuild succeeded':
|
22
|
-
case 'rebuild failed':
|
23
|
-
return emitWebpackMessage(message);
|
24
|
-
}
|
25
|
-
});
|
26
|
-
});
|
27
|
-
}
|
@@ -1,27 +0,0 @@
|
|
1
|
-
import { addons } from '@storybook/addons';
|
2
|
-
import { getStorybookFramework, resolveFromStorybook } from './helpers';
|
3
|
-
const framework = getStorybookFramework(); // eslint-disable-next-line @typescript-eslint/no-var-requires
|
4
|
-
|
5
|
-
const core = require(resolveFromStorybook('@storybook/core-client'));
|
6
|
-
|
7
|
-
const start = core.start;
|
8
|
-
const api = start(() => void 0);
|
9
|
-
export const channel = addons.getChannel();
|
10
|
-
export const clientApi = api.clientApi;
|
11
|
-
export const forceReRender = api.forceReRender;
|
12
|
-
export const storiesOf = (kind, m) => {
|
13
|
-
return clientApi.storiesOf(kind, m).addParameters({
|
14
|
-
framework
|
15
|
-
});
|
16
|
-
};
|
17
|
-
export const configure = (...args) => {
|
18
|
-
//NOTE Storybook 6.x pass `framework` as first argument
|
19
|
-
//@ts-expect-error: ignore it
|
20
|
-
return api.configure(framework, ...args);
|
21
|
-
};
|
22
|
-
export const addDecorator = clientApi.addDecorator;
|
23
|
-
export const addParameters = clientApi.addParameters;
|
24
|
-
export const clearDecorators = clientApi.clearDecorators;
|
25
|
-
export const setAddon = clientApi.setAddon;
|
26
|
-
export const getStorybook = clientApi.getStorybook;
|
27
|
-
export const raw = clientApi.raw;
|
@@ -1,97 +0,0 @@
|
|
1
|
-
import path from 'path';
|
2
|
-
import resolveFrom from 'resolve-from';
|
3
|
-
const supportedFrameworks = ['react', 'vue', 'vue3', 'angular', 'marionette', 'mithril', 'marko', 'html', 'svelte', 'riot', 'ember', 'preact', 'rax', 'aurelia', 'server', 'web-components'];
|
4
|
-
export const storybookDirRef = {
|
5
|
-
current: path.resolve('.storybook')
|
6
|
-
};
|
7
|
-
export const resolveFromStorybook = modulePath => resolveFrom(storybookDirRef.current, modulePath);
|
8
|
-
export const resolveFromStorybookAddonDocs = modulePath => resolveFrom(resolveFromStorybook('@storybook/addon-docs'), modulePath);
|
9
|
-
export const resolveFromStorybookBuilderWebpack4 = modulePath => resolveFrom(resolveFromStorybook('@storybook/builder-webpack4'), modulePath);
|
10
|
-
export const resolveFromStorybookCoreClient = modulePath => resolveFrom(resolveFromStorybook('@storybook/core-client'), modulePath);
|
11
|
-
export const resolveFromStorybookCoreServer = modulePath => resolveFrom(resolveFromStorybook('@storybook/core-server'), modulePath);
|
12
|
-
|
13
|
-
const importFromStorybook = modulePath => import(resolveFromStorybook(modulePath));
|
14
|
-
|
15
|
-
export const importStorybookClientLogger = () => importFromStorybook('@storybook/client-logger');
|
16
|
-
export const importStorybookCoreCommon = () => importFromStorybook('@storybook/core-common');
|
17
|
-
export const importStorybookCoreEvents = () => importFromStorybook('@storybook/core-events');
|
18
|
-
export function hasDocsAddon() {
|
19
|
-
try {
|
20
|
-
resolveFromStorybook('@storybook/addon-docs');
|
21
|
-
return true;
|
22
|
-
} catch (_) {
|
23
|
-
return false;
|
24
|
-
}
|
25
|
-
}
|
26
|
-
export function hasSvelteCSFAddon() {
|
27
|
-
try {
|
28
|
-
resolveFromStorybook('@storybook/addon-svelte-csf');
|
29
|
-
return true;
|
30
|
-
} catch (_) {
|
31
|
-
return false;
|
32
|
-
}
|
33
|
-
}
|
34
|
-
export function getStorybookVersion() {
|
35
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
36
|
-
const {
|
37
|
-
version
|
38
|
-
} = require(resolveFromStorybook('@storybook/core-server/package.json'));
|
39
|
-
|
40
|
-
return version;
|
41
|
-
}
|
42
|
-
export function isStorybookVersionLessThan(major, minor) {
|
43
|
-
const [sbMajor, sbMinor] = (process.env.__CREEVEY_STORYBOOK_VERSION__ ?? getStorybookVersion()).split('.');
|
44
|
-
return Number(sbMajor) < major || minor != undefined && Number(sbMajor) == major && Number(sbMinor) < minor;
|
45
|
-
}
|
46
|
-
export function isStorybookVersionGreaterThan(major, minor) {
|
47
|
-
const [sbMajor, sbMinor] = (process.env.__CREEVEY_STORYBOOK_VERSION__ ?? getStorybookVersion()).split('.');
|
48
|
-
return Number(sbMajor) > major || minor != undefined && Number(sbMajor) == major && Number(sbMinor) > minor;
|
49
|
-
}
|
50
|
-
export function isStorybookVersion(major, minor) {
|
51
|
-
const [sbMajor, sbMinor] = (process.env.__CREEVEY_STORYBOOK_VERSION__ ?? getStorybookVersion()).split('.');
|
52
|
-
return Number(sbMajor) == major || minor != undefined && Number(sbMajor) == major && Number(sbMinor) == minor;
|
53
|
-
}
|
54
|
-
export function getStorybookFramework() {
|
55
|
-
const framework = process.env.__CREEVEY_STORYBOOK_FRAMEWORK__ ?? supportedFrameworks.find(framework => {
|
56
|
-
try {
|
57
|
-
return require.resolve(resolveFromStorybook(`@storybook/${framework}`));
|
58
|
-
} catch (_) {
|
59
|
-
return false;
|
60
|
-
}
|
61
|
-
});
|
62
|
-
if (!framework) throw new Error("Couldn't detect used Storybook framework. Please ensure that you install `@storybook/<framework>` package");
|
63
|
-
return framework;
|
64
|
-
}
|
65
|
-
export const storybookConfigRef = {
|
66
|
-
current: {
|
67
|
-
stories: []
|
68
|
-
}
|
69
|
-
};
|
70
|
-
export async function importStorybookConfig() {
|
71
|
-
const configPath = `${storybookDirRef.current}/main`;
|
72
|
-
|
73
|
-
try {
|
74
|
-
return storybookConfigRef.current = (await import(require.resolve(configPath))).default;
|
75
|
-
} catch (_) {
|
76
|
-
const storybookUtilsPath = '@storybook/core-common/dist/cjs/utils';
|
77
|
-
const serverRequireModule = 'interpret-require'; // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
78
|
-
|
79
|
-
const {
|
80
|
-
getInterpretedFile
|
81
|
-
} = await import(resolveFromStorybook(`${storybookUtilsPath}/interpret-files`)); // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
82
|
-
|
83
|
-
const {
|
84
|
-
default: serverRequireFallback,
|
85
|
-
serverRequire = serverRequireFallback
|
86
|
-
} = await import(resolveFromStorybook(`${storybookUtilsPath}/${serverRequireModule}`)); // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
|
87
|
-
|
88
|
-
const mainConfigFile = getInterpretedFile(configPath); // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
|
89
|
-
|
90
|
-
return storybookConfigRef.current = serverRequire(mainConfigFile);
|
91
|
-
}
|
92
|
-
}
|
93
|
-
export async function isCSFv3Enabled() {
|
94
|
-
var _await$importStoryboo, _await$importStoryboo2;
|
95
|
-
|
96
|
-
return ((_await$importStoryboo = await importStorybookConfig()) === null || _await$importStoryboo === void 0 ? void 0 : (_await$importStoryboo2 = _await$importStoryboo.features) === null || _await$importStoryboo2 === void 0 ? void 0 : _await$importStoryboo2.previewCsfV3) ?? false;
|
97
|
-
}
|