creevey 0.9.0-beta.1 → 0.9.0-non-webpack.0
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/AUTHORS +15 -15
- package/CHANGELOG.md +1275 -1275
- package/LICENSE +21 -21
- package/README.md +7 -0
- package/addon/README.md +3 -0
- package/addon/package.json +4 -0
- package/docs/config.md +212 -212
- package/docs/grid.md +10 -10
- package/docs/tests.md +63 -63
- package/jest.config.js +6 -0
- package/lib/cjs/cli.js +5 -0
- package/lib/cjs/client/addon/Manager.js +418 -0
- package/lib/cjs/client/addon/components/Addon.js +76 -0
- package/lib/cjs/client/addon/components/Icons.js +42 -0
- package/lib/cjs/client/addon/components/Panel.js +68 -0
- package/lib/cjs/client/addon/components/TestSelect.js +63 -0
- package/lib/cjs/client/addon/components/Tools.js +114 -0
- package/lib/cjs/client/addon/decorator.js +11 -0
- package/lib/cjs/client/addon/index.js +31 -0
- package/lib/cjs/client/addon/preset.js +81 -0
- package/lib/cjs/client/addon/readyForCapture.js +12 -0
- package/lib/cjs/client/addon/register.js +100 -0
- package/lib/cjs/client/addon/utils.js +38 -0
- package/lib/cjs/client/addon/withCreevey.js +558 -0
- package/lib/cjs/client/shared/components/ImagesView/BlendView.js +85 -0
- package/lib/cjs/client/shared/components/ImagesView/ImagesView.js +88 -0
- package/lib/cjs/client/shared/components/ImagesView/SideBySideView.js +176 -0
- package/lib/cjs/client/shared/components/ImagesView/SlideView.js +179 -0
- package/lib/cjs/client/shared/components/ImagesView/SwapView.js +110 -0
- package/lib/cjs/client/shared/components/ImagesView/index.js +45 -0
- package/lib/cjs/client/shared/components/PageFooter/PageFooter.js +46 -0
- package/lib/cjs/client/shared/components/PageFooter/Paging.js +98 -0
- package/lib/cjs/client/shared/components/PageHeader/ImagePreview.js +78 -0
- package/lib/cjs/client/shared/components/PageHeader/PageHeader.js +144 -0
- package/lib/cjs/client/shared/components/ResultsPage.js +173 -0
- package/lib/cjs/client/shared/creeveyClientApi.js +107 -0
- package/lib/cjs/client/shared/helpers.js +482 -0
- package/lib/cjs/client/shared/viewMode.js +17 -0
- package/lib/cjs/client/web/142.js +2 -0
- package/lib/cjs/client/web/142.js.LICENSE.txt +12 -0
- package/lib/cjs/client/web/32.js +1 -0
- package/lib/cjs/client/web/551.js +1 -0
- package/lib/cjs/client/web/566.js +2 -0
- package/lib/cjs/client/web/566.js.LICENSE.txt +31 -0
- package/lib/cjs/client/web/691.js +2 -0
- package/lib/cjs/client/web/691.js.LICENSE.txt +8 -0
- package/lib/cjs/client/web/725.js +1 -0
- package/lib/cjs/client/web/index.html +19 -0
- package/lib/cjs/client/web/main.js +2 -38
- package/lib/cjs/client/web/main.js.LICENSE.txt +49 -0
- package/lib/cjs/creevey.js +69 -0
- package/lib/cjs/index.js +62 -0
- package/lib/cjs/server/config.js +96 -0
- package/lib/cjs/server/docker.js +146 -0
- package/lib/cjs/server/extract.js +50 -0
- package/lib/cjs/server/index.js +83 -0
- package/lib/cjs/server/loaders/babel/creevey-plugin.js +86 -0
- package/lib/cjs/server/loaders/babel/helpers.js +469 -0
- package/lib/cjs/server/loaders/babel/register.js +124 -0
- package/lib/cjs/server/loaders/hooks/mdx.js +30 -0
- package/lib/cjs/server/loaders/hooks/svelte.js +65 -0
- package/lib/cjs/server/loaders/webpack/compile.js +293 -0
- package/lib/cjs/server/loaders/webpack/creevey-loader.js +179 -0
- package/lib/cjs/server/loaders/webpack/dummy-hmr.js +39 -0
- package/lib/cjs/server/loaders/webpack/mdx-loader.js +72 -0
- package/lib/cjs/server/loaders/webpack/start.js +41 -0
- package/lib/cjs/server/logger.js +48 -0
- package/lib/cjs/server/master/api.js +71 -0
- package/lib/cjs/server/master/index.js +146 -0
- package/lib/cjs/server/master/master.js +57 -0
- package/lib/cjs/server/master/pool.js +197 -0
- package/lib/cjs/server/master/runner.js +281 -0
- package/lib/cjs/server/master/server.js +129 -0
- package/lib/cjs/server/messages.js +264 -0
- package/lib/cjs/server/selenium/browser.js +672 -0
- package/lib/cjs/server/selenium/index.js +31 -0
- package/lib/cjs/server/selenium/selenoid.js +172 -0
- package/lib/cjs/server/stories.js +159 -0
- package/lib/cjs/server/storybook/entry.js +70 -0
- package/lib/cjs/server/storybook/helpers.js +159 -0
- package/lib/cjs/server/storybook/providers/browser.js +74 -0
- package/lib/cjs/server/storybook/providers/hybrid.js +84 -0
- package/lib/cjs/server/storybook/providers/nodejs.js +239 -0
- package/lib/cjs/server/testsFiles/parser.js +72 -0
- package/lib/cjs/server/testsFiles/register.js +48 -0
- package/lib/cjs/server/update.js +79 -0
- package/lib/cjs/server/utils.js +183 -0
- package/lib/cjs/server/worker/chai-image.js +142 -0
- package/lib/cjs/server/worker/helpers.js +69 -0
- package/lib/cjs/server/worker/index.js +15 -0
- package/lib/cjs/server/worker/reporter.js +108 -0
- package/lib/cjs/server/worker/worker.js +268 -0
- package/lib/cjs/shared/index.js +89 -0
- package/lib/cjs/shared/serializeRegExp.js +41 -0
- package/lib/cjs/types.js +74 -0
- package/lib/esm/cli.js +4 -0
- package/lib/esm/client/addon/Manager.js +402 -0
- package/lib/esm/client/addon/components/Addon.js +58 -0
- package/lib/esm/client/addon/components/Icons.js +27 -0
- package/lib/esm/client/addon/components/Panel.js +49 -0
- package/lib/esm/client/addon/components/TestSelect.js +49 -0
- package/lib/esm/client/addon/components/Tools.js +91 -0
- package/lib/esm/client/addon/decorator.js +2 -0
- package/lib/esm/client/addon/index.js +2 -0
- package/lib/esm/client/addon/preset.js +56 -0
- package/lib/esm/client/addon/readyForCapture.js +5 -0
- package/lib/esm/client/addon/register.js +79 -0
- package/lib/esm/client/addon/utils.js +31 -0
- package/lib/esm/client/addon/withCreevey.js +534 -0
- package/lib/esm/client/shared/components/ImagesView/BlendView.js +63 -0
- package/lib/esm/client/shared/components/ImagesView/ImagesView.js +65 -0
- package/lib/esm/client/shared/components/ImagesView/SideBySideView.js +151 -0
- package/lib/esm/client/shared/components/ImagesView/SlideView.js +154 -0
- package/lib/esm/client/shared/components/ImagesView/SwapView.js +88 -0
- package/lib/esm/client/shared/components/ImagesView/index.js +5 -0
- package/lib/esm/client/shared/components/PageFooter/PageFooter.js +32 -0
- package/lib/esm/client/shared/components/PageFooter/Paging.js +84 -0
- package/lib/esm/client/shared/components/PageHeader/ImagePreview.js +64 -0
- package/lib/esm/client/shared/components/PageHeader/PageHeader.js +120 -0
- package/lib/esm/client/shared/components/ResultsPage.js +143 -0
- package/lib/esm/client/shared/creeveyClientApi.js +98 -0
- package/lib/esm/client/shared/helpers.js +424 -0
- package/lib/esm/client/shared/viewMode.js +6 -0
- package/lib/esm/creevey.js +54 -0
- package/lib/esm/index.js +5 -0
- package/lib/esm/server/config.js +73 -0
- package/lib/esm/server/docker.js +123 -0
- package/lib/esm/server/extract.js +34 -0
- package/lib/esm/server/index.js +64 -0
- package/lib/esm/server/loaders/babel/creevey-plugin.js +72 -0
- package/lib/esm/server/loaders/babel/helpers.js +452 -0
- package/lib/esm/server/loaders/babel/register.js +103 -0
- package/lib/esm/server/loaders/hooks/mdx.js +15 -0
- package/lib/esm/server/loaders/hooks/svelte.js +49 -0
- package/lib/esm/server/loaders/webpack/compile.js +270 -0
- package/lib/esm/server/loaders/webpack/creevey-loader.js +158 -0
- package/lib/esm/server/loaders/webpack/dummy-hmr.js +32 -0
- package/lib/esm/server/loaders/webpack/mdx-loader.js +58 -0
- package/lib/esm/server/loaders/webpack/start.js +27 -0
- package/lib/esm/server/logger.js +20 -0
- package/lib/esm/server/master/api.js +60 -0
- package/lib/esm/server/master/index.js +125 -0
- package/lib/esm/server/master/master.js +38 -0
- package/lib/esm/server/master/pool.js +176 -0
- package/lib/esm/server/master/runner.js +259 -0
- package/lib/esm/server/master/server.js +105 -0
- package/lib/esm/server/messages.js +232 -0
- package/lib/esm/server/selenium/browser.js +639 -0
- package/lib/esm/server/selenium/index.js +2 -0
- package/lib/esm/server/selenium/selenoid.js +149 -0
- package/lib/esm/server/stories.js +140 -0
- package/lib/esm/server/storybook/entry.js +46 -0
- package/lib/esm/server/storybook/helpers.js +98 -0
- package/lib/esm/server/storybook/providers/browser.js +60 -0
- package/lib/esm/server/storybook/providers/hybrid.js +64 -0
- package/lib/esm/server/storybook/providers/nodejs.js +217 -0
- package/lib/esm/server/testsFiles/parser.js +50 -0
- package/lib/esm/server/testsFiles/register.js +35 -0
- package/lib/esm/server/update.js +61 -0
- package/lib/esm/server/utils.js +142 -0
- package/lib/esm/server/worker/chai-image.js +130 -0
- package/lib/esm/server/worker/helpers.js +60 -0
- package/lib/esm/server/worker/index.js +1 -0
- package/lib/esm/server/worker/reporter.js +86 -0
- package/lib/esm/server/worker/worker.js +238 -0
- package/lib/esm/shared/index.js +66 -0
- package/lib/esm/shared/serializeRegExp.js +23 -0
- package/lib/esm/types.js +43 -0
- package/lib/types/cli.d.ts +1 -1
- package/lib/types/client/addon/Manager.d.ts +37 -37
- package/lib/types/client/addon/components/Addon.d.ts +8 -8
- package/lib/types/client/addon/components/Icons.d.ts +7 -7
- package/lib/types/client/addon/components/Panel.d.ts +9 -9
- package/lib/types/client/addon/components/TestSelect.d.ts +8 -9
- package/lib/types/client/addon/components/Tools.d.ts +6 -6
- package/lib/types/client/addon/decorator.d.ts +1 -1
- package/lib/types/client/addon/index.d.ts +2 -0
- package/lib/types/client/addon/preset.d.ts +23 -24
- package/lib/types/client/addon/readyForCapture.d.ts +6 -6
- package/lib/types/client/addon/register.d.ts +3 -3
- package/lib/types/client/addon/utils.d.ts +2 -2
- package/lib/types/client/addon/withCreevey.d.ts +24 -24
- package/lib/types/client/shared/components/ImagesView/BlendView.d.ts +3 -3
- package/lib/types/client/shared/components/ImagesView/ImagesView.d.ts +24 -25
- package/lib/types/client/shared/components/ImagesView/SideBySideView.d.ts +3 -3
- package/lib/types/client/shared/components/ImagesView/SlideView.d.ts +3 -3
- package/lib/types/client/shared/components/ImagesView/SwapView.d.ts +3 -3
- package/lib/types/client/shared/components/ImagesView/index.d.ts +5 -5
- package/lib/types/client/shared/components/PageFooter/PageFooter.d.ts +8 -9
- package/lib/types/client/shared/components/PageFooter/Paging.d.ts +7 -8
- package/lib/types/client/shared/components/PageHeader/ImagePreview.d.ts +12 -12
- package/lib/types/client/shared/components/PageHeader/PageHeader.d.ts +16 -17
- package/lib/types/client/shared/components/ResultsPage.d.ts +18 -18
- package/lib/types/client/shared/creeveyClientApi.d.ts +9 -9
- package/lib/types/client/shared/helpers.d.ts +46 -46
- package/lib/types/client/shared/viewMode.d.ts +4 -4
- package/lib/types/client/web/CreeveyApp.d.ts +11 -12
- package/lib/types/client/web/CreeveyContext.d.ts +11 -11
- package/lib/types/client/web/CreeveyLoader.d.ts +2 -3
- package/lib/types/client/web/CreeveyView/SideBar/Checkbox.d.ts +19 -19
- package/lib/types/client/web/CreeveyView/SideBar/Search.d.ts +6 -6
- package/lib/types/client/web/CreeveyView/SideBar/SideBar.d.ts +14 -14
- package/lib/types/client/web/CreeveyView/SideBar/SideBarHeader.d.ts +12 -13
- package/lib/types/client/web/CreeveyView/SideBar/SuiteLink.d.ts +33 -33
- package/lib/types/client/web/CreeveyView/SideBar/TestLink.d.ts +7 -8
- package/lib/types/client/web/CreeveyView/SideBar/TestStatusIcon.d.ts +10 -10
- package/lib/types/client/web/CreeveyView/SideBar/TestsStatus.d.ts +9 -9
- package/lib/types/client/web/CreeveyView/SideBar/Toggle.d.ts +6 -6
- package/lib/types/client/web/CreeveyView/SideBar/index.d.ts +1 -1
- package/lib/types/client/web/KeyboardEventsContext.d.ts +13 -13
- package/lib/types/client/web/index.d.ts +4 -4
- package/lib/types/creevey.d.ts +1 -1
- package/lib/types/index.d.ts +1 -4
- package/lib/types/server/config.d.ts +4 -4
- package/lib/types/server/docker.d.ts +7 -7
- package/lib/types/server/extract.d.ts +2 -2
- package/lib/types/server/index.d.ts +2 -2
- package/lib/types/server/loaders/babel/creevey-plugin.d.ts +1 -1
- package/lib/types/server/loaders/babel/helpers.d.ts +19 -19
- package/lib/types/server/loaders/babel/register.d.ts +5 -5
- package/lib/types/server/loaders/hooks/mdx.d.ts +1 -1
- package/lib/types/server/loaders/hooks/svelte.d.ts +1 -1
- package/lib/types/server/loaders/webpack/compile.d.ts +2 -2
- package/lib/types/server/loaders/webpack/creevey-loader.d.ts +4 -2
- package/lib/types/server/loaders/webpack/dummy-hmr.d.ts +10 -10
- package/lib/types/server/loaders/webpack/mdx-loader.d.ts +6 -6
- package/lib/types/server/loaders/webpack/start.d.ts +1 -1
- package/lib/types/server/logger.d.ts +10 -6
- package/lib/types/server/master/api.d.ts +7 -7
- package/lib/types/server/master/index.d.ts +3 -3
- package/lib/types/server/master/master.d.ts +7 -7
- package/lib/types/server/master/pool.d.ts +31 -31
- package/lib/types/server/master/runner.d.ts +26 -26
- package/lib/types/server/master/server.d.ts +2 -2
- package/lib/types/server/messages.d.ts +27 -27
- package/lib/types/server/selenium/browser.d.ts +17 -17
- package/lib/types/server/selenium/index.d.ts +2 -2
- package/lib/types/server/selenium/selenoid.d.ts +3 -3
- package/lib/types/server/stories.d.ts +8 -8
- package/lib/types/server/storybook/entry.d.ts +18 -18
- package/lib/types/server/storybook/helpers.d.ts +24 -24
- package/lib/types/server/storybook/providers/browser.d.ts +4 -4
- package/lib/types/server/storybook/providers/hybrid.d.ts +4 -4
- package/lib/types/server/storybook/providers/nodejs.d.ts +9 -9
- package/lib/types/server/testsFiles/parser.d.ts +12 -12
- package/lib/types/server/testsFiles/register.d.ts +2 -2
- package/lib/types/server/update.d.ts +2 -2
- package/lib/types/server/utils.d.ts +20 -20
- package/lib/types/server/worker/chai-image.d.ts +6 -6
- package/lib/types/server/worker/helpers.d.ts +8 -8
- package/lib/types/server/worker/index.d.ts +1 -1
- package/lib/types/server/worker/reporter.d.ts +8 -8
- package/lib/types/server/worker/worker.d.ts +4 -4
- package/lib/types/{shared.d.ts → shared/index.d.ts} +7 -16
- package/lib/types/shared/serializeRegExp.d.ts +9 -0
- package/lib/types/types.d.ts +490 -489
- package/package.json +115 -102
- package/preset.js +9 -9
- package/types/babel__register.d.ts +1 -1
- package/types/chai.d.ts +12 -12
- package/types/event-source-polyfill.d.ts +6 -6
- package/types/mdx.d.ts +3 -2
- package/types/mocha.d.ts +20 -20
- package/types/png.d.ts +4 -4
- package/lib/cjs/client/web/1.js +0 -13
- package/lib/cjs/client/web/2.js +0 -1
- package/storybook-static/stories.json +0 -21
@@ -0,0 +1,103 @@
|
|
1
|
+
import Module from 'module';
|
2
|
+
import fs from 'fs';
|
3
|
+
import { isAbsolute, join, relative, resolve } from 'path';
|
4
|
+
import { addHook } from 'pirates';
|
5
|
+
import { isDefined } from '../../../types';
|
6
|
+
import { extensions } from '../../utils';
|
7
|
+
import plugin from './creevey-plugin';
|
8
|
+
import { hasDocsAddon, hasSvelteCSFAddon, isStorybookVersionLessThan } from '../../storybook/helpers';
|
9
|
+
let parents = null;
|
10
|
+
let story = null; //@ts-expect-error private field doesn't have types
|
11
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-assignment
|
12
|
+
|
13
|
+
const jsLoader = Module._extensions['.js']; //@ts-expect-error private field doesn't have types
|
14
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
15
|
+
|
16
|
+
Module._extensions['.js'] = function (mod, filename) {
|
17
|
+
parents = Object.values(require.cache).filter(m => m === null || m === void 0 ? void 0 : m.children.includes(mod)).filter(isDefined).map(m => m.filename); // eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
18
|
+
|
19
|
+
jsLoader(mod, filename);
|
20
|
+
parents = null;
|
21
|
+
};
|
22
|
+
|
23
|
+
addHook(() => '', {
|
24
|
+
exts: ['.jpg', '.jpeg', '.png', '.gif', '.eot', '.otf', '.svg', '.ttf', '.woff', '.woff2', '.css', '.less', '.scss', '.styl'],
|
25
|
+
ignoreNodeModules: false
|
26
|
+
});
|
27
|
+
|
28
|
+
function getRequireContext(rootDir) {
|
29
|
+
return function requireContext(rootPath, deep, filter) {
|
30
|
+
const ids = [];
|
31
|
+
let contextPath; // Relative path
|
32
|
+
|
33
|
+
if (rootPath.startsWith('.')) contextPath = resolve(rootDir, rootPath); // Module path
|
34
|
+
else if (!isAbsolute(rootPath)) contextPath = require.resolve(rootPath); // Absolute path
|
35
|
+
else contextPath = rootPath;
|
36
|
+
|
37
|
+
const traverse = dirPath => {
|
38
|
+
fs.readdirSync(dirPath, {
|
39
|
+
withFileTypes: true
|
40
|
+
}).forEach(dirent => {
|
41
|
+
const filename = dirent.name;
|
42
|
+
const filePath = join(dirPath, filename);
|
43
|
+
if (dirent.isDirectory() && deep) return traverse(filePath);
|
44
|
+
if (dirent.isFile() && ((filter === null || filter === void 0 ? void 0 : filter.test(`./${relative(contextPath, filePath)}`)) ?? true)) return ids.push(filePath);
|
45
|
+
});
|
46
|
+
};
|
47
|
+
|
48
|
+
traverse(contextPath);
|
49
|
+
|
50
|
+
const context = id => {
|
51
|
+
story = id; // eslint-disable-next-line @typescript-eslint/no-var-requires
|
52
|
+
|
53
|
+
const storyModule = require(id);
|
54
|
+
|
55
|
+
story = null;
|
56
|
+
return storyModule;
|
57
|
+
};
|
58
|
+
|
59
|
+
context.id = contextPath;
|
60
|
+
|
61
|
+
context.keys = () => ids;
|
62
|
+
|
63
|
+
context.resolve = id => id;
|
64
|
+
|
65
|
+
return context;
|
66
|
+
};
|
67
|
+
}
|
68
|
+
|
69
|
+
export default async function register(config, debug = false) {
|
70
|
+
const rootDir = isStorybookVersionLessThan(6, 4) ? config.storybookDir : process.cwd();
|
71
|
+
const requireContext = getRequireContext(rootDir);
|
72
|
+
const preview = resolve(config.storybookDir, 'preview');
|
73
|
+
if (hasDocsAddon()) await (await import('../hooks/mdx')).addMDXHook(() => story);
|
74
|
+
if (hasSvelteCSFAddon()) await (await import('../hooks/svelte')).addSvelteHook(() => story); // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
|
75
|
+
|
76
|
+
(await import('@babel/register')).default(config.babelOptions({
|
77
|
+
babelrc: false,
|
78
|
+
rootMode: 'upward-optional',
|
79
|
+
ignore: [/node_modules/],
|
80
|
+
extensions: [...extensions, ...(hasDocsAddon() ? ['.mdx'] : []), ...(hasSvelteCSFAddon() ? ['.svelte'] : [])],
|
81
|
+
parserOpts: {
|
82
|
+
sourceType: 'module',
|
83
|
+
plugins: ['classProperties', 'decorators-legacy', 'jsx', 'typescript']
|
84
|
+
},
|
85
|
+
plugins: [[plugin, {
|
86
|
+
debug,
|
87
|
+
preview,
|
88
|
+
parents: () => parents,
|
89
|
+
story: () => story
|
90
|
+
}], ['@babel/plugin-transform-runtime', {
|
91
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
92
|
+
version: require('@babel/helpers/package.json').version,
|
93
|
+
absoluteRuntime: true,
|
94
|
+
corejs: 3
|
95
|
+
}]],
|
96
|
+
presets: [['@babel/preset-env', {
|
97
|
+
targets: {
|
98
|
+
node: '10'
|
99
|
+
}
|
100
|
+
}]]
|
101
|
+
}));
|
102
|
+
return requireContext;
|
103
|
+
}
|
@@ -0,0 +1,15 @@
|
|
1
|
+
import { addHook } from 'pirates';
|
2
|
+
import { resolveFromStorybookAddonDocs } from '../../storybook/helpers';
|
3
|
+
export const addMDXHook = async getStory => {
|
4
|
+
const mdx = (await import(resolveFromStorybookAddonDocs('@mdx-js/mdx'))).default;
|
5
|
+
const {
|
6
|
+
mdxOptions
|
7
|
+
} = await import('../webpack/mdx-loader');
|
8
|
+
addHook((code, filename) => {
|
9
|
+
const story = getStory();
|
10
|
+
if (!story || !filename.startsWith(story)) return code;
|
11
|
+
return mdx.sync(code, mdxOptions());
|
12
|
+
}, {
|
13
|
+
exts: ['.mdx']
|
14
|
+
});
|
15
|
+
};
|
@@ -0,0 +1,49 @@
|
|
1
|
+
import { addHook } from 'pirates';
|
2
|
+
import { logger } from '../../logger';
|
3
|
+
import { resolveFromStorybook, storybookConfigRef } from '../../storybook/helpers';
|
4
|
+
export const addSvelteHook = async getStory => {
|
5
|
+
const {
|
6
|
+
compile,
|
7
|
+
preprocess
|
8
|
+
} = await import(resolveFromStorybook('svelte/compiler'));
|
9
|
+
const {
|
10
|
+
default: svelteCSFLoader
|
11
|
+
} = await import(resolveFromStorybook('@storybook/addon-svelte-csf/dist/cjs/parser/svelte-stories-loader'));
|
12
|
+
addHook((code, filename) => {
|
13
|
+
var _options$compilerOpti;
|
14
|
+
|
15
|
+
const story = getStory();
|
16
|
+
const config = storybookConfigRef.current;
|
17
|
+
const {
|
18
|
+
svelteOptions: options = {}
|
19
|
+
} = config; // NOTE: Copy-paste compiling code from https://github.com/sveltejs/svelte-loader/blob/3c4d66d/index.js
|
20
|
+
|
21
|
+
const compileOptions = {
|
22
|
+
filename,
|
23
|
+
css: false,
|
24
|
+
...options.compilerOptions,
|
25
|
+
format: ((_options$compilerOpti = options.compilerOptions) === null || _options$compilerOpti === void 0 ? void 0 : _options$compilerOpti.format) || 'esm'
|
26
|
+
}; // TODO Can't use preprocess here because it async and hook must be sync
|
27
|
+
// The only way to fix it, load stories by using `import()` instead of require
|
28
|
+
// And write native nodejs `.svelte` resolver https://nodejs.org/api/esm.html#esm_resolve_specifier_context_defaultresolve
|
29
|
+
// const processed = await preprocess(code, options.preprocess, { filename });
|
30
|
+
|
31
|
+
void preprocess;
|
32
|
+
const {
|
33
|
+
js: {
|
34
|
+
code: compiledCode
|
35
|
+
},
|
36
|
+
warnings
|
37
|
+
} = compile(code, compileOptions);
|
38
|
+
warnings.forEach(warning => logger.warn(warning));
|
39
|
+
if (!story || !filename.startsWith(story)) return compiledCode;
|
40
|
+
return svelteCSFLoader.call({
|
41
|
+
_module: {
|
42
|
+
resource: filename
|
43
|
+
}
|
44
|
+
}, compiledCode); // TODO Extract parameters from `create_fragment` that created by compiler
|
45
|
+
// TODO Write babel transformation for it
|
46
|
+
}, {
|
47
|
+
exts: ['.svelte']
|
48
|
+
});
|
49
|
+
};
|
@@ -0,0 +1,270 @@
|
|
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, isStorybookVersionLessThan, 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 = isStorybookVersionLessThan(6, 2) ? [/\.(stories|story).mdx$/, /\.(stories|story)\.mdx$/] : [/(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_pre6_2(framework, configDir, outputDir) {
|
99
|
+
const {
|
100
|
+
default: storybookFrameworkOptions
|
101
|
+
} = await import(resolveFromStorybook(`@storybook/${framework}/dist/server/options`)); // eslint-disable-next-line node/no-missing-import, @typescript-eslint/no-unsafe-assignment, import/no-unresolved
|
102
|
+
|
103
|
+
const {
|
104
|
+
default: getConfig
|
105
|
+
} = await import(resolveFromStorybook('@storybook/core/dist/server/config')); // eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-call
|
106
|
+
|
107
|
+
return getConfig({
|
108
|
+
// NOTE: 6.1 storybook don't support quite any more. But we still have older versions
|
109
|
+
quiet: true,
|
110
|
+
configType: 'PRODUCTION',
|
111
|
+
outputDir,
|
112
|
+
cache: {},
|
113
|
+
// eslint-disable-next-line node/no-missing-require
|
114
|
+
corePresets: [resolveFromStorybook('@storybook/core/dist/server/preview/preview-preset')],
|
115
|
+
overridePresets: [...(hasDocsAddon() ? [require.resolve('./mdx-loader')] : []), // eslint-disable-next-line node/no-missing-require
|
116
|
+
resolveFromStorybook('@storybook/core/dist/server/preview/custom-webpack-preset')],
|
117
|
+
...storybookFrameworkOptions,
|
118
|
+
configDir
|
119
|
+
});
|
120
|
+
}
|
121
|
+
|
122
|
+
async function getWebpackConfigForStorybook_6_2(framework, configDir, outputDir) {
|
123
|
+
const {
|
124
|
+
default: storybookFrameworkOptions
|
125
|
+
} = await import(resolveFromStorybook(`@storybook/${framework}/dist/cjs/server/options`));
|
126
|
+
const options = {
|
127
|
+
quiet: true,
|
128
|
+
configType: 'PRODUCTION',
|
129
|
+
outputDir,
|
130
|
+
configDir,
|
131
|
+
...storybookFrameworkOptions
|
132
|
+
}; // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
133
|
+
|
134
|
+
const {
|
135
|
+
getPreviewBuilder
|
136
|
+
} = await import(resolveFromStorybook('@storybook/core-server/dist/cjs/utils/get-preview-builder')); // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
137
|
+
|
138
|
+
const {
|
139
|
+
loadAllPresets
|
140
|
+
} = await import(resolveFromStorybook('@storybook/core-common')); // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
|
141
|
+
|
142
|
+
const builder = await getPreviewBuilder(configDir); // NOTE: Copy-paste from storybook/lib/core-server/src/build-dev.ts
|
143
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call
|
144
|
+
|
145
|
+
const presets = loadAllPresets({
|
146
|
+
corePresets: [// eslint-disable-next-line node/no-missing-require
|
147
|
+
resolveFromStorybook('@storybook/core-server/dist/cjs/presets/common-preset'), // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
|
148
|
+
...builder.corePresets, // eslint-disable-next-line node/no-missing-require
|
149
|
+
resolveFromStorybook('@storybook/core-server/dist/cjs/presets/babel-cache-preset')],
|
150
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
|
151
|
+
overridePresets: [...(hasDocsAddon() ? [require.resolve('./mdx-loader')] : []), // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
|
152
|
+
...builder.overridePresets],
|
153
|
+
...options
|
154
|
+
}); // 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
|
155
|
+
|
156
|
+
return builder.getConfig({ ...options,
|
157
|
+
presets
|
158
|
+
});
|
159
|
+
}
|
160
|
+
|
161
|
+
async function removeAddons() {
|
162
|
+
try {
|
163
|
+
var _config$core;
|
164
|
+
|
165
|
+
const config = await importStorybookConfig();
|
166
|
+
|
167
|
+
if (((_config$core = config.core) === null || _config$core === void 0 ? void 0 : _config$core.builder) == 'webpack5') {
|
168
|
+
logger.warn("Be aware Creevey doesn't fully support webpack@5, some feature might not work well");
|
169
|
+
}
|
170
|
+
|
171
|
+
if (config.addons && config.stories) {
|
172
|
+
config.addons = [];
|
173
|
+
return true;
|
174
|
+
}
|
175
|
+
} catch (_) {
|
176
|
+
/* noop */
|
177
|
+
}
|
178
|
+
|
179
|
+
return false;
|
180
|
+
}
|
181
|
+
|
182
|
+
export default async function compile(config, {
|
183
|
+
debug,
|
184
|
+
ui
|
185
|
+
}) {
|
186
|
+
var _storybookWebpackConf, _storybookWebpackConf2, _storybookWebpackConf3, _extensions$map, _storybookWebpackConf4, _storybookWebpackConf5;
|
187
|
+
|
188
|
+
const storybookFramework = getStorybookFramework();
|
189
|
+
const outputDir = path.join(getCreeveyCache(), 'storybook');
|
190
|
+
|
191
|
+
try {
|
192
|
+
rmdirSync(outputDir, {
|
193
|
+
recursive: true
|
194
|
+
});
|
195
|
+
} catch (_) {
|
196
|
+
/* noop */
|
197
|
+
}
|
198
|
+
|
199
|
+
const creeveyLoader = {
|
200
|
+
loader: require.resolve('./creevey-loader'),
|
201
|
+
options: {
|
202
|
+
debug,
|
203
|
+
storybookDir: config.storybookDir
|
204
|
+
}
|
205
|
+
};
|
206
|
+
process.env.NODE_ENV = 'production'; // NOTE Remove addons by monkey patching, only for new config file (main.js)
|
207
|
+
|
208
|
+
const areAddonsRemoved = await removeAddons();
|
209
|
+
const getWebpackConfig = isStorybookVersionLessThan(6, 2) ? getWebpackConfigForStorybook_pre6_2 : getWebpackConfigForStorybook_6_2;
|
210
|
+
const storybookWebpackConfig = await getWebpackConfig(storybookFramework, config.storybookDir, outputDir);
|
211
|
+
const extensions = ((_storybookWebpackConf = storybookWebpackConfig.resolve) === null || _storybookWebpackConf === void 0 ? void 0 : _storybookWebpackConf.extensions) ?? fallbackExtensions;
|
212
|
+
delete storybookWebpackConfig.optimization;
|
213
|
+
storybookWebpackConfig.devtool = false;
|
214
|
+
storybookWebpackConfig.performance = false;
|
215
|
+
storybookWebpackConfig.profile = debug;
|
216
|
+
storybookWebpackConfig.mode = 'development';
|
217
|
+
storybookWebpackConfig.target = 'node';
|
218
|
+
storybookWebpackConfig.output = { ...storybookWebpackConfig.output,
|
219
|
+
filename: 'main.js'
|
220
|
+
}; // NOTE Add hack to allow stories HMR work in nodejs
|
221
|
+
|
222
|
+
Array.isArray(storybookWebpackConfig.entry) && storybookWebpackConfig.entry.unshift(require.resolve('./dummy-hmr')); // NOTE apply creevey loader to output from mdx loader
|
223
|
+
|
224
|
+
if (hasDocsAddon()) await applyMdxLoader(storybookWebpackConfig, areAddonsRemoved, creeveyLoader); // NOTE Add creevey-loader to cut off all unnecessary code except stories meta and tests
|
225
|
+
|
226
|
+
(_storybookWebpackConf2 = storybookWebpackConfig.module) === null || _storybookWebpackConf2 === void 0 ? void 0 : (_storybookWebpackConf3 = _storybookWebpackConf2.rules) === null || _storybookWebpackConf3 === void 0 ? void 0 : _storybookWebpackConf3.unshift({
|
227
|
+
enforce: 'pre',
|
228
|
+
test: new RegExp(`\\.(${(_extensions$map = extensions.map(x => x.slice(1))) === null || _extensions$map === void 0 ? void 0 : _extensions$map.join('|')})$`),
|
229
|
+
exclude: /node_modules/,
|
230
|
+
use: creeveyLoader
|
231
|
+
});
|
232
|
+
const aliases = ((_storybookWebpackConf4 = storybookWebpackConfig.resolve) === null || _storybookWebpackConf4 === void 0 ? void 0 : _storybookWebpackConf4.alias) ?? {};
|
233
|
+
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
|
234
|
+
|
235
|
+
storybookWebpackConfig.externals = [...(Array.isArray(aliases) ? aliases.map(({
|
236
|
+
name,
|
237
|
+
alias
|
238
|
+
}) => [name, alias]) : Object.entries(aliases)).filter(([alias]) => excluded.includes(alias)).flatMap(([, aliasPath]) => aliasPath == false ? [] : (Array.isArray(aliasPath) ? aliasPath : [aliasPath]).map(x => ({
|
239
|
+
[x]: `commonjs ${x}`
|
240
|
+
}))), // NOTE Replace `@storybook/${framework}` to ../../storybook.ts
|
241
|
+
{
|
242
|
+
[`@storybook/${storybookFramework}`]: `commonjs ${require.resolve('../../storybook/entry')}`
|
243
|
+
}, nodeExternals({
|
244
|
+
includeAbsolutePaths: true,
|
245
|
+
allowlist: /(webpack|dummy-hmr|generated-stories-entry|generated-config-entry|generated-other-entry)/
|
246
|
+
}), // TODO Don't work well with monorepos
|
247
|
+
nodeExternals({
|
248
|
+
modulesDir: resolveFromStorybook('@storybook/core').split('@storybook')[0],
|
249
|
+
includeAbsolutePaths: true,
|
250
|
+
allowlist: /(webpack|dummy-hmr|generated-stories-entry|generated-config-entry|generated-other-entry)/
|
251
|
+
})]; // NOTE Exclude some plugins
|
252
|
+
|
253
|
+
const excludedPlugins = ['DocgenPlugin', 'ForkTsCheckerWebpackPlugin'];
|
254
|
+
storybookWebpackConfig.plugins = (_storybookWebpackConf5 = storybookWebpackConfig.plugins) === null || _storybookWebpackConf5 === void 0 ? void 0 : _storybookWebpackConf5.filter(plugin => !excludedPlugins.includes(plugin.constructor.name));
|
255
|
+
const storybookWebpackCompiler = webpack(storybookWebpackConfig);
|
256
|
+
|
257
|
+
if (debug) {
|
258
|
+
dumpStats = stats => {
|
259
|
+
if (!stats) return;
|
260
|
+
writeFile(path.join(config.reportDir, 'stats.json'), JSON.stringify(stats.toJson(), null, 2), noop);
|
261
|
+
};
|
262
|
+
}
|
263
|
+
|
264
|
+
if (ui) {
|
265
|
+
const watcher = storybookWebpackCompiler.watch({}, handleWebpackBuild);
|
266
|
+
subscribeOn('shutdown', () => watcher.close(noop));
|
267
|
+
} else {
|
268
|
+
storybookWebpackCompiler.run(handleWebpackBuild);
|
269
|
+
}
|
270
|
+
}
|
@@ -0,0 +1,158 @@
|
|
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 { isStorybookVersionLessThan } from '../../storybook/helpers';
|
9
|
+
import { commonVisitor, mdxVisitor, previewVisitor, storyVisitor, FileType } from '../babel/helpers';
|
10
|
+
import { logger } from '../../logger';
|
11
|
+
|
12
|
+
function transform(ast) {
|
13
|
+
traverse(ast, { ...commonVisitor,
|
14
|
+
...(fileType == FileType.Preview ? previewVisitor : undefined),
|
15
|
+
...(fileType == FileType.Story ? storyVisitor : undefined),
|
16
|
+
...(isMDX ? mdxVisitor : undefined)
|
17
|
+
}, undefined, {
|
18
|
+
resourcePath,
|
19
|
+
fileType,
|
20
|
+
isMDX,
|
21
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
22
|
+
visitedTopPaths: new Set(),
|
23
|
+
visitedBindings: new Set(),
|
24
|
+
reexportedStories
|
25
|
+
});
|
26
|
+
return generate(ast, {
|
27
|
+
retainLines: true
|
28
|
+
}).code;
|
29
|
+
}
|
30
|
+
|
31
|
+
function toPosix(filePath) {
|
32
|
+
return filePath.split(path.win32.sep).join(path.posix.sep).replace(/^[a-z]:/i, '');
|
33
|
+
}
|
34
|
+
|
35
|
+
function getIssuerResource(context) {
|
36
|
+
var _context$_module, _context$_module$issu;
|
37
|
+
|
38
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-return
|
39
|
+
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;
|
40
|
+
}
|
41
|
+
|
42
|
+
function getIssuerConstructorName(context) {
|
43
|
+
var _context$_module2, _context$_module2$iss, _context$_module2$iss2;
|
44
|
+
|
45
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-return
|
46
|
+
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;
|
47
|
+
}
|
48
|
+
|
49
|
+
function isEntry(context) {
|
50
|
+
return getIssuerConstructorName(context) == 'MultiModule';
|
51
|
+
}
|
52
|
+
|
53
|
+
function isPreview(context, options) {
|
54
|
+
const {
|
55
|
+
dir: resourceDir,
|
56
|
+
name: resourceName
|
57
|
+
} = path.posix.parse(toPosix(context.resourcePath));
|
58
|
+
const storybookDir = typeof options.storybookDir == 'string' ? toPosix(options.storybookDir) : '';
|
59
|
+
const isConfigFile = resourceDir == storybookDir && (resourceName == 'preview' || resourceName == 'config');
|
60
|
+
|
61
|
+
if (isStorybookVersionLessThan(6)) {
|
62
|
+
return isEntry(context) && isConfigFile;
|
63
|
+
}
|
64
|
+
|
65
|
+
const issuerResource = getIssuerResource(context);
|
66
|
+
return Boolean(issuerResource && entries.has(issuerResource) && isConfigFile);
|
67
|
+
}
|
68
|
+
|
69
|
+
function isStoryFile(context) {
|
70
|
+
var _reexportedStories$ge, _context$_module3;
|
71
|
+
|
72
|
+
const issuerResource = getIssuerResource(context);
|
73
|
+
return getIssuerConstructorName(context) == 'ContextModule' || // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
74
|
+
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';
|
75
|
+
} // NOTE: non-story files before preview => issuer.resource is entry
|
76
|
+
|
77
|
+
|
78
|
+
const schema = {
|
79
|
+
type: 'object',
|
80
|
+
properties: {
|
81
|
+
debug: {
|
82
|
+
type: 'boolean'
|
83
|
+
},
|
84
|
+
storybookDir: {
|
85
|
+
type: 'string'
|
86
|
+
}
|
87
|
+
}
|
88
|
+
};
|
89
|
+
let fileType = FileType.Invalid;
|
90
|
+
let isMDX = false;
|
91
|
+
let previewPath = '';
|
92
|
+
let resourcePath = '';
|
93
|
+
const entries = new Set();
|
94
|
+
const stories = new Set();
|
95
|
+
const reexportedStories = new Map();
|
96
|
+
|
97
|
+
const isTest = () => process.env.__CREEVEY_ENV__ == 'test';
|
98
|
+
|
99
|
+
const defaultOptions = {
|
100
|
+
get debug() {
|
101
|
+
return isTest();
|
102
|
+
},
|
103
|
+
|
104
|
+
storybookDir: process.cwd()
|
105
|
+
};
|
106
|
+
export default function loader(source) {
|
107
|
+
const options = this ? getOptions(this) || defaultOptions : defaultOptions;
|
108
|
+
validate(schema, options, {
|
109
|
+
name: 'Creevey Stories Loader'
|
110
|
+
});
|
111
|
+
fileType = FileType.Invalid;
|
112
|
+
|
113
|
+
if (this) {
|
114
|
+
const issuerResource = getIssuerResource(this);
|
115
|
+
resourcePath = this.resourcePath;
|
116
|
+
|
117
|
+
if (isStoryFile(this)) {
|
118
|
+
fileType = FileType.Story;
|
119
|
+
isMDX = path.parse(resourcePath).ext == '.mdx';
|
120
|
+
stories.add(this.resourcePath);
|
121
|
+
} else if (isPreview(this, options)) {
|
122
|
+
fileType = FileType.Preview;
|
123
|
+
previewPath = this.resourcePath;
|
124
|
+
} else if (isEntry(this)) {
|
125
|
+
fileType = FileType.Entry;
|
126
|
+
entries.add(this.resourcePath);
|
127
|
+
return source;
|
128
|
+
} else if (issuerResource && stories.has(issuerResource) && options.debug) {
|
129
|
+
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
|
130
|
+
}
|
131
|
+
}
|
132
|
+
|
133
|
+
if (isTest() && !Number.isNaN(Number(process.env.CREEVEY_LOADER_FILE_TYPE))) {
|
134
|
+
fileType = Number(process.env.CREEVEY_LOADER_FILE_TYPE);
|
135
|
+
}
|
136
|
+
|
137
|
+
try {
|
138
|
+
const ast = parse(source, {
|
139
|
+
sourceType: 'module',
|
140
|
+
plugins: ['classProperties', 'decorators-legacy', 'jsx', 'typescript']
|
141
|
+
});
|
142
|
+
return transform(ast);
|
143
|
+
} catch (error) {
|
144
|
+
this && logger.warn('Failed to transform file', this.resourcePath);
|
145
|
+
|
146
|
+
if (typeof error == 'object' && error && 'loc' in error) {
|
147
|
+
logger.warn(codeFrameColumns(source, {
|
148
|
+
start: error.loc
|
149
|
+
}, {
|
150
|
+
highlightCode: true
|
151
|
+
}));
|
152
|
+
} else {
|
153
|
+
logger.warn(error);
|
154
|
+
}
|
155
|
+
|
156
|
+
return source;
|
157
|
+
}
|
158
|
+
}
|
@@ -0,0 +1,32 @@
|
|
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 {};
|