creevey 0.8.0-beta.0 → 0.9.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (225) hide show
  1. package/CHANGELOG.md +5 -9
  2. package/lib/cjs/client/web/main.js +6 -6
  3. package/lib/types/cli.d.ts +1 -1
  4. package/lib/types/client/addon/Manager.d.ts +37 -37
  5. package/lib/types/client/addon/components/Addon.d.ts +8 -8
  6. package/lib/types/client/addon/components/Icons.d.ts +7 -7
  7. package/lib/types/client/addon/components/Panel.d.ts +9 -9
  8. package/lib/types/client/addon/components/TestSelect.d.ts +9 -9
  9. package/lib/types/client/addon/components/Tools.d.ts +6 -6
  10. package/lib/types/client/addon/decorator.d.ts +1 -1
  11. package/lib/types/client/addon/preset.d.ts +24 -22
  12. package/lib/types/client/addon/readyForCapture.d.ts +6 -0
  13. package/lib/types/client/addon/register.d.ts +3 -3
  14. package/lib/types/client/addon/utils.d.ts +2 -2
  15. package/lib/types/client/addon/withCreevey.d.ts +24 -13
  16. package/lib/types/client/shared/components/ImagesView/BlendView.d.ts +3 -3
  17. package/lib/types/client/shared/components/ImagesView/ImagesView.d.ts +25 -25
  18. package/lib/types/client/shared/components/ImagesView/SideBySideView.d.ts +3 -3
  19. package/lib/types/client/shared/components/ImagesView/SlideView.d.ts +3 -3
  20. package/lib/types/client/shared/components/ImagesView/SwapView.d.ts +3 -3
  21. package/lib/types/client/shared/components/ImagesView/index.d.ts +5 -5
  22. package/lib/types/client/shared/components/PageFooter/PageFooter.d.ts +9 -9
  23. package/lib/types/client/shared/components/PageFooter/Paging.d.ts +8 -8
  24. package/lib/types/client/shared/components/PageHeader/ImagePreview.d.ts +12 -12
  25. package/lib/types/client/shared/components/PageHeader/PageHeader.d.ts +17 -17
  26. package/lib/types/client/shared/components/ResultsPage.d.ts +18 -18
  27. package/lib/types/client/shared/creeveyClientApi.d.ts +9 -9
  28. package/lib/types/client/shared/helpers.d.ts +46 -46
  29. package/lib/types/client/shared/viewMode.d.ts +4 -4
  30. package/lib/types/client/web/CreeveyApp.d.ts +12 -12
  31. package/lib/types/client/web/CreeveyContext.d.ts +11 -11
  32. package/lib/types/client/web/CreeveyLoader.d.ts +3 -3
  33. package/lib/types/client/web/CreeveyView/SideBar/Checkbox.d.ts +19 -19
  34. package/lib/types/client/web/CreeveyView/SideBar/Search.d.ts +6 -6
  35. package/lib/types/client/web/CreeveyView/SideBar/SideBar.d.ts +14 -14
  36. package/lib/types/client/web/CreeveyView/SideBar/SideBarHeader.d.ts +13 -13
  37. package/lib/types/client/web/CreeveyView/SideBar/SuiteLink.d.ts +33 -33
  38. package/lib/types/client/web/CreeveyView/SideBar/TestLink.d.ts +8 -8
  39. package/lib/types/client/web/CreeveyView/SideBar/TestStatusIcon.d.ts +10 -10
  40. package/lib/types/client/web/CreeveyView/SideBar/TestsStatus.d.ts +9 -9
  41. package/lib/types/client/web/CreeveyView/SideBar/Toggle.d.ts +6 -6
  42. package/lib/types/client/web/CreeveyView/SideBar/index.d.ts +1 -1
  43. package/lib/types/client/web/KeyboardEventsContext.d.ts +13 -13
  44. package/lib/types/client/web/index.d.ts +4 -4
  45. package/lib/types/creevey.d.ts +1 -1
  46. package/lib/types/index.d.ts +4 -2
  47. package/lib/types/server/config.d.ts +4 -4
  48. package/lib/types/server/docker.d.ts +7 -7
  49. package/lib/types/server/extract.d.ts +2 -2
  50. package/lib/types/server/index.d.ts +2 -2
  51. package/lib/types/server/loaders/babel/creevey-plugin.d.ts +1 -1
  52. package/lib/types/server/loaders/babel/helpers.d.ts +19 -19
  53. package/lib/types/server/loaders/babel/register.d.ts +5 -5
  54. package/lib/types/server/loaders/hooks/mdx.d.ts +1 -1
  55. package/lib/types/server/loaders/hooks/svelte.d.ts +1 -1
  56. package/lib/types/server/loaders/webpack/compile.d.ts +2 -2
  57. package/lib/types/server/loaders/webpack/creevey-loader.d.ts +2 -2
  58. package/lib/types/server/loaders/webpack/dummy-hmr.d.ts +10 -10
  59. package/lib/types/server/loaders/webpack/mdx-loader.d.ts +6 -6
  60. package/lib/types/server/loaders/webpack/start.d.ts +1 -1
  61. package/lib/types/server/logger.d.ts +6 -6
  62. package/lib/types/server/master/api.d.ts +7 -7
  63. package/lib/types/server/master/index.d.ts +3 -3
  64. package/lib/types/server/master/master.d.ts +7 -6
  65. package/lib/types/server/master/pool.d.ts +31 -30
  66. package/lib/types/server/master/runner.d.ts +26 -26
  67. package/lib/types/server/master/server.d.ts +2 -2
  68. package/lib/types/server/messages.d.ts +27 -18
  69. package/lib/types/server/selenium/browser.d.ts +17 -14
  70. package/lib/types/server/selenium/index.d.ts +2 -2
  71. package/lib/types/server/selenium/selenoid.d.ts +3 -3
  72. package/lib/types/server/stories.d.ts +8 -8
  73. package/lib/types/server/storybook/entry.d.ts +18 -18
  74. package/lib/types/server/storybook/helpers.d.ts +24 -24
  75. package/lib/types/server/storybook/providers/browser.d.ts +4 -0
  76. package/lib/types/server/storybook/providers/hybrid.d.ts +4 -0
  77. package/lib/types/server/storybook/providers/nodejs.d.ts +9 -0
  78. package/lib/types/server/testsFiles/parser.d.ts +12 -0
  79. package/lib/types/server/testsFiles/register.d.ts +2 -0
  80. package/lib/types/server/update.d.ts +2 -2
  81. package/lib/types/server/utils.d.ts +20 -19
  82. package/lib/types/server/worker/chai-image.d.ts +6 -6
  83. package/lib/types/server/worker/helpers.d.ts +8 -7
  84. package/lib/types/server/worker/index.d.ts +1 -1
  85. package/lib/types/server/worker/reporter.d.ts +8 -8
  86. package/lib/types/server/worker/worker.d.ts +4 -4
  87. package/lib/types/shared.d.ts +16 -4
  88. package/lib/types/types.d.ts +489 -459
  89. package/package.json +16 -7
  90. package/storybook-static/stories.json +21 -0
  91. package/types/mocha.d.ts +1 -0
  92. package/lib/cjs/cli.js +0 -5
  93. package/lib/cjs/client/addon/Manager.js +0 -413
  94. package/lib/cjs/client/addon/components/Addon.js +0 -76
  95. package/lib/cjs/client/addon/components/Icons.js +0 -42
  96. package/lib/cjs/client/addon/components/Panel.js +0 -68
  97. package/lib/cjs/client/addon/components/TestSelect.js +0 -63
  98. package/lib/cjs/client/addon/components/Tools.js +0 -114
  99. package/lib/cjs/client/addon/decorator.js +0 -11
  100. package/lib/cjs/client/addon/preset.js +0 -80
  101. package/lib/cjs/client/addon/register.js +0 -96
  102. package/lib/cjs/client/addon/utils.js +0 -38
  103. package/lib/cjs/client/addon/withCreevey.js +0 -284
  104. package/lib/cjs/client/shared/components/ImagesView/BlendView.js +0 -85
  105. package/lib/cjs/client/shared/components/ImagesView/ImagesView.js +0 -88
  106. package/lib/cjs/client/shared/components/ImagesView/SideBySideView.js +0 -176
  107. package/lib/cjs/client/shared/components/ImagesView/SlideView.js +0 -178
  108. package/lib/cjs/client/shared/components/ImagesView/SwapView.js +0 -110
  109. package/lib/cjs/client/shared/components/ImagesView/index.js +0 -45
  110. package/lib/cjs/client/shared/components/PageFooter/PageFooter.js +0 -46
  111. package/lib/cjs/client/shared/components/PageFooter/Paging.js +0 -98
  112. package/lib/cjs/client/shared/components/PageHeader/ImagePreview.js +0 -78
  113. package/lib/cjs/client/shared/components/PageHeader/PageHeader.js +0 -144
  114. package/lib/cjs/client/shared/components/ResultsPage.js +0 -173
  115. package/lib/cjs/client/shared/creeveyClientApi.js +0 -103
  116. package/lib/cjs/client/shared/helpers.js +0 -482
  117. package/lib/cjs/client/shared/viewMode.js +0 -17
  118. package/lib/cjs/client/web/index.html +0 -19
  119. package/lib/cjs/creevey.js +0 -71
  120. package/lib/cjs/index.js +0 -44
  121. package/lib/cjs/server/config.js +0 -92
  122. package/lib/cjs/server/docker.js +0 -150
  123. package/lib/cjs/server/extract.js +0 -43
  124. package/lib/cjs/server/index.js +0 -85
  125. package/lib/cjs/server/loaders/babel/creevey-plugin.js +0 -88
  126. package/lib/cjs/server/loaders/babel/helpers.js +0 -479
  127. package/lib/cjs/server/loaders/babel/register.js +0 -126
  128. package/lib/cjs/server/loaders/hooks/mdx.js +0 -30
  129. package/lib/cjs/server/loaders/hooks/svelte.js +0 -65
  130. package/lib/cjs/server/loaders/webpack/compile.js +0 -286
  131. package/lib/cjs/server/loaders/webpack/creevey-loader.js +0 -174
  132. package/lib/cjs/server/loaders/webpack/dummy-hmr.js +0 -44
  133. package/lib/cjs/server/loaders/webpack/mdx-loader.js +0 -72
  134. package/lib/cjs/server/loaders/webpack/start.js +0 -41
  135. package/lib/cjs/server/logger.js +0 -47
  136. package/lib/cjs/server/master/api.js +0 -71
  137. package/lib/cjs/server/master/index.js +0 -152
  138. package/lib/cjs/server/master/master.js +0 -56
  139. package/lib/cjs/server/master/pool.js +0 -206
  140. package/lib/cjs/server/master/runner.js +0 -294
  141. package/lib/cjs/server/master/server.js +0 -57
  142. package/lib/cjs/server/messages.js +0 -154
  143. package/lib/cjs/server/selenium/browser.js +0 -582
  144. package/lib/cjs/server/selenium/index.js +0 -31
  145. package/lib/cjs/server/selenium/selenoid.js +0 -174
  146. package/lib/cjs/server/stories.js +0 -167
  147. package/lib/cjs/server/storybook/entry.js +0 -68
  148. package/lib/cjs/server/storybook/helpers.js +0 -165
  149. package/lib/cjs/server/storybook/nodejs-provider.js +0 -220
  150. package/lib/cjs/server/update.js +0 -83
  151. package/lib/cjs/server/utils.js +0 -178
  152. package/lib/cjs/server/worker/chai-image.js +0 -142
  153. package/lib/cjs/server/worker/helpers.js +0 -73
  154. package/lib/cjs/server/worker/index.js +0 -15
  155. package/lib/cjs/server/worker/reporter.js +0 -120
  156. package/lib/cjs/server/worker/worker.js +0 -266
  157. package/lib/cjs/shared.js +0 -35
  158. package/lib/cjs/types.js +0 -69
  159. package/lib/esm/cli.js +0 -4
  160. package/lib/esm/client/addon/Manager.js +0 -397
  161. package/lib/esm/client/addon/components/Addon.js +0 -58
  162. package/lib/esm/client/addon/components/Icons.js +0 -27
  163. package/lib/esm/client/addon/components/Panel.js +0 -49
  164. package/lib/esm/client/addon/components/TestSelect.js +0 -49
  165. package/lib/esm/client/addon/components/Tools.js +0 -91
  166. package/lib/esm/client/addon/decorator.js +0 -2
  167. package/lib/esm/client/addon/preset.js +0 -55
  168. package/lib/esm/client/addon/register.js +0 -75
  169. package/lib/esm/client/addon/utils.js +0 -31
  170. package/lib/esm/client/addon/withCreevey.js +0 -270
  171. package/lib/esm/client/shared/components/ImagesView/BlendView.js +0 -64
  172. package/lib/esm/client/shared/components/ImagesView/ImagesView.js +0 -65
  173. package/lib/esm/client/shared/components/ImagesView/SideBySideView.js +0 -152
  174. package/lib/esm/client/shared/components/ImagesView/SlideView.js +0 -154
  175. package/lib/esm/client/shared/components/ImagesView/SwapView.js +0 -89
  176. package/lib/esm/client/shared/components/ImagesView/index.js +0 -5
  177. package/lib/esm/client/shared/components/PageFooter/PageFooter.js +0 -32
  178. package/lib/esm/client/shared/components/PageFooter/Paging.js +0 -84
  179. package/lib/esm/client/shared/components/PageHeader/ImagePreview.js +0 -64
  180. package/lib/esm/client/shared/components/PageHeader/PageHeader.js +0 -120
  181. package/lib/esm/client/shared/components/ResultsPage.js +0 -143
  182. package/lib/esm/client/shared/creeveyClientApi.js +0 -94
  183. package/lib/esm/client/shared/helpers.js +0 -424
  184. package/lib/esm/client/shared/viewMode.js +0 -6
  185. package/lib/esm/creevey.js +0 -56
  186. package/lib/esm/index.js +0 -4
  187. package/lib/esm/server/config.js +0 -71
  188. package/lib/esm/server/docker.js +0 -123
  189. package/lib/esm/server/extract.js +0 -30
  190. package/lib/esm/server/index.js +0 -65
  191. package/lib/esm/server/loaders/babel/creevey-plugin.js +0 -74
  192. package/lib/esm/server/loaders/babel/helpers.js +0 -462
  193. package/lib/esm/server/loaders/babel/register.js +0 -105
  194. package/lib/esm/server/loaders/hooks/mdx.js +0 -15
  195. package/lib/esm/server/loaders/hooks/svelte.js +0 -49
  196. package/lib/esm/server/loaders/webpack/compile.js +0 -263
  197. package/lib/esm/server/loaders/webpack/creevey-loader.js +0 -153
  198. package/lib/esm/server/loaders/webpack/dummy-hmr.js +0 -36
  199. package/lib/esm/server/loaders/webpack/mdx-loader.js +0 -58
  200. package/lib/esm/server/loaders/webpack/start.js +0 -27
  201. package/lib/esm/server/logger.js +0 -20
  202. package/lib/esm/server/master/api.js +0 -60
  203. package/lib/esm/server/master/index.js +0 -131
  204. package/lib/esm/server/master/master.js +0 -37
  205. package/lib/esm/server/master/pool.js +0 -187
  206. package/lib/esm/server/master/runner.js +0 -272
  207. package/lib/esm/server/master/server.js +0 -37
  208. package/lib/esm/server/messages.js +0 -128
  209. package/lib/esm/server/selenium/browser.js +0 -554
  210. package/lib/esm/server/selenium/index.js +0 -2
  211. package/lib/esm/server/selenium/selenoid.js +0 -151
  212. package/lib/esm/server/stories.js +0 -147
  213. package/lib/esm/server/storybook/entry.js +0 -44
  214. package/lib/esm/server/storybook/helpers.js +0 -106
  215. package/lib/esm/server/storybook/nodejs-provider.js +0 -200
  216. package/lib/esm/server/update.js +0 -65
  217. package/lib/esm/server/utils.js +0 -141
  218. package/lib/esm/server/worker/chai-image.js +0 -130
  219. package/lib/esm/server/worker/helpers.js +0 -64
  220. package/lib/esm/server/worker/index.js +0 -1
  221. package/lib/esm/server/worker/reporter.js +0 -98
  222. package/lib/esm/server/worker/worker.js +0 -236
  223. package/lib/esm/shared.js +0 -22
  224. package/lib/esm/types.js +0 -40
  225. package/lib/types/server/storybook/nodejs-provider.d.ts +0 -5
@@ -1,30 +0,0 @@
1
- import { subscribeOn } from './messages';
2
- import { loadTestsFromStories, saveStoriesJson, saveTestsJson } from './stories';
3
- export default async function extract(config, options) {
4
- if (config.useWebpackToExtractTests && process.env.__CREEVEY_ENV__ != 'test') {
5
- await new Promise((resolve, reject) => {
6
- subscribeOn('webpack', message => {
7
- switch (message.type) {
8
- case 'success':
9
- return resolve();
10
-
11
- case 'fail':
12
- return reject();
13
- }
14
- });
15
- void (async () => (await import('./loaders/webpack/compile')).default(config, options))();
16
- });
17
- }
18
-
19
- const tests = await loadTestsFromStories(Object.keys(config.browsers), async listener => {
20
- const stories = await config.storiesProvider(config, {
21
- watch: false,
22
- debug: options.debug
23
- }, listener);
24
- if (options.extract) saveStoriesJson(stories, options.extract);
25
- return stories;
26
- });
27
- if (options.tests) saveTestsJson(tests); // eslint-disable-next-line no-process-exit
28
-
29
- process.exit(0);
30
- }
@@ -1,65 +0,0 @@
1
- import cluster from 'cluster';
2
- import { readConfig, defaultBrowser } from './config';
3
- import { noop } from '../types';
4
- import { logger } from './logger'; // NOTE: Impure function, mutate config by adding gridUrl prop
5
-
6
- async function startWebdriverServer(config, options) {
7
- if (config.useDocker) {
8
- return (await import('./docker')).default(config, options.browser, async () => (await import('./selenium/selenoid')).startSelenoidContainer(config, options.debug));
9
- } else {
10
- return (await import('./selenium/selenoid')).startSelenoidStandalone(config, options.debug);
11
- }
12
- }
13
-
14
- export default async function (options) {
15
- const config = await readConfig(options);
16
- const {
17
- browser = defaultBrowser,
18
- extract,
19
- tests,
20
- update,
21
- webpack,
22
- ui,
23
- port
24
- } = options;
25
- if (!config) return;
26
- const resolveApi = ui && cluster.isMaster ? (await import('./master/server')).default(config.reportDir, port) : noop; // NOTE: We don't need docker nor selenoid for webpack or update options
27
-
28
- if (!(config.gridUrl || Object.values(config.browsers).every(({
29
- gridUrl
30
- }) => gridUrl)) && !extract && !webpack && !tests && !update) {
31
- await startWebdriverServer(config, options);
32
- }
33
-
34
- switch (true) {
35
- case Boolean(extract) || tests:
36
- {
37
- return (await import('./extract')).default(config, options);
38
- }
39
-
40
- case Boolean(update):
41
- {
42
- return (await import('./update')).default(config, typeof update == 'string' ? update : undefined);
43
- }
44
-
45
- case webpack:
46
- {
47
- logger.info('Starting Webpack Compiler');
48
- return (await import('./loaders/webpack/compile')).default(config, options);
49
- }
50
-
51
- case cluster.isMaster:
52
- {
53
- logger.info('Starting Master Process');
54
- return (await import('./master')).default(config, options, resolveApi);
55
- }
56
-
57
- default:
58
- {
59
- logger.info(`Starting Worker for ${browser}`);
60
- return (await import('./worker')).default(config, { ...options,
61
- browser
62
- });
63
- }
64
- }
65
- }
@@ -1,74 +0,0 @@
1
- import path from 'path';
2
- import { commonVisitor, FileType, mdxVisitor, previewVisitor, storyVisitor } from './helpers';
3
- import { logger } from '../../logger';
4
- let lastStoryFile = null;
5
- const stories = new Set();
6
- const reexportedStories = new Map();
7
- export default function () {
8
- return {
9
- pre() {
10
- var _this$opts$parents;
11
-
12
- const parents = (_this$opts$parents = this.opts.parents()) !== null && _this$opts$parents !== void 0 ? _this$opts$parents : [];
13
- const story = this.opts.story();
14
- this.resourcePath = this.filename;
15
- this.fileType = FileType.Invalid; // eslint-disable-next-line @typescript-eslint/no-explicit-any
16
-
17
- this.visitedTopPaths = new Set();
18
- this.visitedBindings = new Set();
19
- this.reexportedStories = reexportedStories;
20
-
21
- if (story && this.filename.startsWith(story) || parents.find(parent => this.reexportedStories.has(parent))) {
22
- this.fileType = FileType.Story;
23
- this.isMDX = path.parse(this.filename).ext == '.mdx';
24
- lastStoryFile = this.filename;
25
- stories.add(this.filename);
26
- } else if (this.filename.startsWith(this.opts.preview)) this.fileType = FileType.Preview;else if (lastStoryFile && this.opts.debug) {
27
- logger.warn('Trying to transform possible non-story file', this.resourcePath, 'Please check the', lastStoryFile);
28
- lastStoryFile = null; // TODO Add link to docs, how creevey works and what user should do in this situation
29
- }
30
- },
31
-
32
- visitor: { ...commonVisitor,
33
-
34
- ExportAllDeclaration(path) {
35
- if (this.fileType == FileType.Story && typeof storyVisitor.ExportAllDeclaration == 'function') {
36
- storyVisitor.ExportAllDeclaration.call(this, path, this);
37
- }
38
- },
39
-
40
- ExportDefaultDeclaration(path) {
41
- if (this.fileType == FileType.Story && typeof storyVisitor.ExportDefaultDeclaration == 'function') {
42
- storyVisitor.ExportDefaultDeclaration.call(this, path, this);
43
- }
44
- },
45
-
46
- ExportNamedDeclaration(path) {
47
- if (this.fileType == FileType.Preview && typeof previewVisitor.ExportNamedDeclaration == 'function') {
48
- previewVisitor.ExportNamedDeclaration.call(this, path, this);
49
- }
50
-
51
- if (this.fileType == FileType.Story && typeof storyVisitor.ExportNamedDeclaration == 'function') {
52
- storyVisitor.ExportNamedDeclaration.call(this, path, this);
53
- }
54
- },
55
-
56
- CallExpression(path) {
57
- if (this.fileType == FileType.Preview && typeof previewVisitor.CallExpression == 'function') {
58
- previewVisitor.CallExpression.call(this, path, this);
59
- }
60
-
61
- if (this.fileType == FileType.Story && typeof storyVisitor.CallExpression == 'function') {
62
- storyVisitor.CallExpression.call(this, path, this);
63
- }
64
- },
65
-
66
- FunctionDeclaration(path) {
67
- if (this.isMDX && typeof mdxVisitor.FunctionDeclaration == 'function') {
68
- mdxVisitor.FunctionDeclaration.call(this, path, this);
69
- }
70
- }
71
-
72
- }
73
- };
74
- }
@@ -1,462 +0,0 @@
1
- import * as t from '@babel/types';
2
- import { isDefined } from '../../../types';
3
-
4
- function isExports(path) {
5
- const {
6
- parentPath
7
- } = path;
8
- return path.node.name == 'exports' && path.scope.hasGlobal('exports') && !path.scope.hasBinding('exports') && parentPath.isMemberExpression() && parentPath.get('object').isIdentifier({
9
- name: 'exports'
10
- });
11
- }
12
-
13
- function isModuleExports(path) {
14
- const {
15
- parentPath
16
- } = path;
17
- return path.node.name == 'module' && path.scope.hasGlobal('module') && !path.scope.hasBinding('module') && parentPath.isMemberExpression() && parentPath.get('object').isIdentifier({
18
- name: 'module'
19
- }) && parentPath.get('property').isIdentifier({
20
- name: 'exports'
21
- });
22
- }
23
-
24
- function isObjectAssign(path) {
25
- if (!(path !== null && path !== void 0 && path.isCallExpression())) return false;
26
- const calleePath = path.get('callee');
27
- return calleePath.isMemberExpression() && calleePath.get('object').isIdentifier({
28
- name: 'Object'
29
- }) && calleePath.get('property').isIdentifier({
30
- name: 'assign'
31
- });
32
- }
33
-
34
- function isTemplateBind(path) {
35
- if (!(path !== null && path !== void 0 && path.isCallExpression())) return false;
36
- const calleePath = path.get('callee');
37
- return calleePath.isMemberExpression() && calleePath.get('object').isIdentifier() && calleePath.get('property').isIdentifier({
38
- name: 'bind'
39
- });
40
- }
41
-
42
- function findRootPath(path) {
43
- return path.find(x => {
44
- var _x$parentPath;
45
-
46
- return Boolean((_x$parentPath = x.parentPath) === null || _x$parentPath === void 0 ? void 0 : _x$parentPath.isProgram());
47
- });
48
- }
49
-
50
- function getPropertyPath(path, name) {
51
- const propertyPath = path.get('properties').find(propPath => propPath.isObjectProperty() && t.isIdentifier(propPath.node.key, {
52
- name
53
- }));
54
- return propertyPath !== null && propertyPath !== void 0 && propertyPath.isObjectProperty() ? propertyPath : undefined;
55
- } // TODO Support import and process them
56
-
57
-
58
- function getDeclaratorPath(path) {
59
- if (path !== null && path !== void 0 && path.isIdentifier()) {
60
- var _path$scope$getBindin;
61
-
62
- const {
63
- path: bindingPath
64
- } = (_path$scope$getBindin = path.scope.getBinding(path.node.name)) !== null && _path$scope$getBindin !== void 0 ? _path$scope$getBindin : {};
65
- if (bindingPath !== null && bindingPath !== void 0 && bindingPath.isVariableDeclarator() || bindingPath !== null && bindingPath !== void 0 && bindingPath.isFunctionDeclaration() || bindingPath !== null && bindingPath !== void 0 && bindingPath.isImportSpecifier()) return bindingPath;
66
- }
67
- }
68
-
69
- function getKindObjectNodePath(path) {
70
- if (path.isObjectExpression()) {
71
- return getPropertyPath(path, 'title') ? path : undefined;
72
- }
73
- }
74
-
75
- function getIdentifiers(path) {
76
- return path.map(x => x.isFunctionDeclaration() ? x.get('id') : x.get('id')).map(idPath => idPath.isIdentifier() ? idPath : null).filter(isDefined);
77
- }
78
-
79
- function removeAllPropsExcept(path, propNames) {
80
- const getPropName = propPath => propNames.find(names => {
81
- const keyPath = propPath.isObjectProperty() ? propPath.get('key') : propPath.get('key');
82
- if (!keyPath.isIdentifier()) return;
83
- const name = Array.isArray(names) ? names[0] : names;
84
- return typeof name == 'string' ? keyPath.isIdentifier({
85
- name
86
- }) : name(keyPath.node.name);
87
- });
88
-
89
- path.get('properties').forEach(propPath => {
90
- if (propPath.isObjectProperty() || propPath.isObjectMethod()) {
91
- const propName = getPropName(propPath);
92
- if (!propName) return propPath.remove();
93
- const restNames = Array.isArray(propName) ? propName.slice(1) : [];
94
- if (propPath.isObjectProperty() && restNames.length != 0) removeAllExpressionPropsExcept(propPath === null || propPath === void 0 ? void 0 : propPath.get('value'), restNames);
95
- if (propPath.isObjectMethod() && restNames[0] == 'storyName') replaceStoryFnToNoop(propPath);
96
- } else if (propPath.isSpreadElement()) {
97
- removeAllExpressionPropsExcept(propPath.get('argument'), propNames);
98
- } else propPath.remove();
99
- });
100
- }
101
-
102
- function removeAllPropAssignsExcept(propAssigns, propNames) {
103
- for (const [assignPath, props] of propAssigns !== null && propAssigns !== void 0 ? propAssigns : []) {
104
- const restNames = props.reduce((subPropNames, prop) => {
105
- const propName = subPropNames.find(names => {
106
- const name = Array.isArray(names) ? names[0] : names;
107
- return typeof name == 'string' ? name == prop : name(prop);
108
- });
109
- if (Array.isArray(propName)) return propName.slice(1);
110
- if (!propName) assignPath.remove();
111
- return [];
112
- }, propNames);
113
- if (restNames.length != 0) removeAllExpressionPropsExcept(assignPath.get('right'), restNames);
114
- }
115
- }
116
-
117
- function replaceStoryFnToNoop(path) {
118
- if (path !== null && path !== void 0 && path.isArrowFunctionExpression()) path.get('body').replaceWith(t.blockStatement([]));else if (path !== null && path !== void 0 && path.isFunctionDeclaration()) path.get('body').replaceWith(t.blockStatement([]));else if (path !== null && path !== void 0 && path.isFunctionExpression()) path.get('body').replaceWith(t.blockStatement([]));else if (path !== null && path !== void 0 && path.isObjectMethod()) path.get('body').replaceWith(t.blockStatement([]));
119
- }
120
-
121
- function getAssignmentPathWithProps(refPath) {
122
- const assignmentPath = refPath.findParent(parentPath => parentPath.isAssignmentExpression());
123
- if (!(assignmentPath !== null && assignmentPath !== void 0 && assignmentPath.isAssignmentExpression())) return;
124
- const props = [];
125
-
126
- for (let propPath = refPath.parentPath; propPath != assignmentPath; propPath = propPath.parentPath) {
127
- var _propPath;
128
-
129
- if (!((_propPath = propPath) !== null && _propPath !== void 0 && _propPath.isMemberExpression())) return;
130
- const propNode = propPath.node.property;
131
- if (!t.isIdentifier(propNode)) return;
132
- props.push(propNode.name);
133
- }
134
-
135
- if (props.length != 0) return [assignmentPath, props];
136
- }
137
-
138
- function getPropertyAssignmentPaths(idPaths) {
139
- const assignPaths = new Map();
140
- idPaths.forEach(idPath => {
141
- var _idPath$scope$getBind, _idPath$scope$getBind2;
142
-
143
- const referencePaths = (_idPath$scope$getBind = (_idPath$scope$getBind2 = idPath.scope.getBinding(idPath.node.name)) === null || _idPath$scope$getBind2 === void 0 ? void 0 : _idPath$scope$getBind2.referencePaths) !== null && _idPath$scope$getBind !== void 0 ? _idPath$scope$getBind : [];
144
- referencePaths.forEach(refPath => {
145
- var _getAssignmentPathWit;
146
-
147
- const [assignmentPath, props] = (_getAssignmentPathWit = getAssignmentPathWithProps(refPath)) !== null && _getAssignmentPathWit !== void 0 ? _getAssignmentPathWit : [];
148
- if (assignmentPath && props) assignPaths.set(assignmentPath, props);
149
- });
150
- });
151
- return assignPaths;
152
- }
153
-
154
- function removeAllExpressionPropsExcept(expressionPath, propNames) {
155
- const resolvedDeclPath = getDeclaratorPath(expressionPath);
156
- if (expressionPath !== null && expressionPath !== void 0 && expressionPath.isObjectExpression()) removeAllPropsExcept(expressionPath, propNames);else if (expressionPath !== null && expressionPath !== void 0 && expressionPath.isCallExpression()) {
157
- if (isObjectAssign(expressionPath)) expressionPath.get('arguments').forEach(argumentPath => removeAllExpressionPropsExcept(argumentPath, storyProps));else if (isTemplateBind(expressionPath)) {
158
- const calleePath = expressionPath.get('callee');
159
- if (calleePath.isMemberExpression()) removeAllExpressionPropsExcept(calleePath.get('object'), propNames);
160
- } else if (propNames[0] == 'storyName') {
161
- expressionPath === null || expressionPath === void 0 ? void 0 : expressionPath.replaceWith(t.arrowFunctionExpression([], t.blockStatement([])));
162
- }
163
- } else if ((expressionPath !== null && expressionPath !== void 0 && expressionPath.isFunctionExpression() || expressionPath !== null && expressionPath !== void 0 && expressionPath.isArrowFunctionExpression()) && propNames[0] == 'storyName') replaceStoryFnToNoop(expressionPath);else if ((!resolvedDeclPath || resolvedDeclPath.isImportSpecifier()) && propNames[0] == 'storyName') expressionPath === null || expressionPath === void 0 ? void 0 : expressionPath.replaceWith(t.arrowFunctionExpression([], t.blockStatement([])));
164
-
165
- if (resolvedDeclPath) {
166
- if (!resolvedDeclPath.isImportSpecifier()) removeAllPropAssignsExcept(getPropertyAssignmentPaths(getIdentifiers([resolvedDeclPath])).entries(), propNames);
167
- if (resolvedDeclPath.isVariableDeclarator()) removeAllExpressionPropsExcept(resolvedDeclPath.get('init'), propNames);
168
- if (resolvedDeclPath.isFunctionDeclaration() && propNames[0] == 'storyName') replaceStoryFnToNoop(resolvedDeclPath);
169
- }
170
- }
171
-
172
- function cleanUpStoriesOfCallChain(storiesOfPath) {
173
- let callPath = storiesOfPath;
174
-
175
- do {
176
- const childCallPath = callPath;
177
- const {
178
- parentPath: memberPath
179
- } = childCallPath;
180
- if (!memberPath || !memberPath.isMemberExpression()) return;
181
- callPath = memberPath.parentPath;
182
- const propPath = memberPath.get('property');
183
- if (!callPath.isCallExpression()) return;
184
-
185
- if (propPath.isIdentifier({
186
- name: 'add'
187
- })) {
188
- const [, storyPath, parametersPath] = callPath.get('arguments');
189
- storyPath.replaceWith(t.arrowFunctionExpression([], t.blockStatement([])));
190
- removeAllExpressionPropsExcept(parametersPath, ['creevey']);
191
- } else if (propPath.isIdentifier({
192
- name: 'addDecorator'
193
- })) {
194
- callPath.replaceWith(childCallPath);
195
- } else if (propPath.isIdentifier({
196
- name: 'addParameters'
197
- })) {
198
- const [parametersPath] = callPath.get('arguments');
199
- removeAllExpressionPropsExcept(parametersPath, ['creevey']);
200
- }
201
- } while (callPath.parentPath != null);
202
- }
203
-
204
- function recursivelyRemoveUnreferencedBindings(path) {
205
- const getUnreferencedBindings = () => {
206
- path.scope.crawl();
207
- return Object.values(path.scope.bindings).filter(binding => !binding.referenced || binding.referencePaths.every(refPath => refPath.find(x => x.node == binding.path.node)));
208
- };
209
-
210
- let bindings = getUnreferencedBindings();
211
-
212
- do {
213
- bindings.forEach(binding => !binding.path.removed && binding.path.remove());
214
- } while ((bindings = getUnreferencedBindings()).length > 0);
215
- }
216
-
217
- function getUnvisitedRefs(paths, // eslint-disable-next-line @typescript-eslint/no-explicit-any
218
- state) {
219
- const rootPaths = [...new Set(paths.map(findRootPath).filter(isDefined))];
220
- const bindings = new Set();
221
- rootPaths.forEach(rootPath => {
222
- state.visitedTopPaths.add(rootPath);
223
- rootPath.traverse({
224
- Identifier(identifierPath) {
225
- const binding = identifierPath.scope.getBinding(identifierPath.node.name);
226
-
227
- if ((binding === null || binding === void 0 ? void 0 : binding.scope) == rootPath.scope && !state.visitedBindings.has(binding)) {
228
- bindings.add(binding);
229
- state.visitedBindings.add(binding);
230
- }
231
- }
232
-
233
- });
234
- });
235
- const refs = [].concat(...[...bindings].map(b => [b.path, ...b.referencePaths]));
236
- return [...new Set(refs)];
237
- }
238
-
239
- export let FileType;
240
-
241
- (function (FileType) {
242
- FileType[FileType["Invalid"] = -1] = "Invalid";
243
- FileType[FileType["Entry"] = 0] = "Entry";
244
- FileType[FileType["Preview"] = 1] = "Preview";
245
- FileType[FileType["Story"] = 2] = "Story";
246
- })(FileType || (FileType = {}));
247
-
248
- export const commonVisitor = {
249
- Program: {
250
- enter(path) {
251
- path.traverse({
252
- TSDeclareFunction(path) {
253
- path.remove();
254
- },
255
-
256
- TSTypeAliasDeclaration(path) {
257
- path.remove();
258
- },
259
-
260
- TSInterfaceDeclaration(path) {
261
- path.remove();
262
- },
263
-
264
- TSTypeAnnotation(path) {
265
- path.remove();
266
- },
267
-
268
- TSAsExpression(path) {
269
- path.replaceWith(path.get('expression'));
270
- }
271
-
272
- });
273
- },
274
-
275
- exit(path) {
276
- if (this.fileType != FileType.Story && this.fileType != FileType.Preview) return;
277
- recursivelyRemoveUnreferencedBindings(path);
278
- path.traverse({
279
- ImportDeclaration(path) {
280
- if (path.node.specifiers.length == 0) path.remove();
281
- }
282
-
283
- });
284
- let refs = [...this.visitedTopPaths];
285
-
286
- while (refs.length > 0) {
287
- refs = getUnvisitedRefs(refs, this);
288
- }
289
-
290
- path.get('body').filter(x => !this.visitedTopPaths.has(x)).forEach(x => x.remove());
291
- }
292
-
293
- }
294
- };
295
- export const previewVisitor = {
296
- ExportNamedDeclaration(namedPath) {
297
- this.visitedTopPaths.add(namedPath);
298
- const declarationPath = namedPath.get('declaration');
299
- if (!declarationPath.isVariableDeclaration()) return;
300
- declarationPath.get('declarations').forEach(declPath => {
301
- if (!declPath.isVariableDeclarator()) return;
302
- if (t.isIdentifier(declPath.node.id, {
303
- name: 'decorators'
304
- })) return declPath.remove();
305
-
306
- if (t.isIdentifier(declPath.node.id, {
307
- name: 'parameters'
308
- })) {
309
- removeAllExpressionPropsExcept(declPath.get('init'), ['creevey']);
310
- }
311
- });
312
- },
313
-
314
- CallExpression(rootCallPath) {
315
- const rootPath = findRootPath(rootCallPath);
316
- const calleePath = rootCallPath.get('callee');
317
- if (calleePath.isIdentifier({
318
- name: 'configure'
319
- }) && rootPath) this.visitedTopPaths.add(rootPath);else if (calleePath.isIdentifier({
320
- name: 'addDecorator'
321
- })) rootCallPath.remove();else if (calleePath.isIdentifier({
322
- name: 'addParameters'
323
- })) {
324
- const [argPath] = rootCallPath.get('arguments');
325
- if (!argPath || !argPath.isObjectExpression()) return;
326
- if (rootPath) this.visitedTopPaths.add(rootPath);
327
- removeAllPropsExcept(argPath, ['creevey']);
328
- }
329
- }
330
-
331
- };
332
- export const mdxVisitor = {
333
- FunctionDeclaration(functionPath) {
334
- var _functionPath$get$nod, _rootPath$scope$getBi, _rootPath$scope$getBi2;
335
-
336
- const functionName = (_functionPath$get$nod = functionPath.get('id').node) === null || _functionPath$get$nod === void 0 ? void 0 : _functionPath$get$nod.name;
337
- if (functionName != 'MDXContent') return;
338
- const rootPath = findRootPath(functionPath);
339
- const refs = (_rootPath$scope$getBi = rootPath === null || rootPath === void 0 ? void 0 : (_rootPath$scope$getBi2 = rootPath.scope.getBinding(functionName)) === null || _rootPath$scope$getBi2 === void 0 ? void 0 : _rootPath$scope$getBi2.referencePaths) !== null && _rootPath$scope$getBi !== void 0 ? _rootPath$scope$getBi : [];
340
- refs.forEach(refPath => {
341
- var _findRootPath;
342
-
343
- return (_findRootPath = findRootPath(refPath)) === null || _findRootPath === void 0 ? void 0 : _findRootPath.remove();
344
- });
345
- rootPath === null || rootPath === void 0 ? void 0 : rootPath.remove();
346
- }
347
-
348
- };
349
- const kindProps = ['title', 'id', ['parameters', 'creevey'], 'includeStories', 'excludeStories'];
350
- const storyProps = ['storyName', ['story', 'name', ['parameters', 'creevey', 'docsOnly']], ['parameters', 'creevey', 'docsOnly']];
351
- const exportsProps = [['default', ...kindProps], [name => name != 'default', ...storyProps]];
352
- export const storyVisitor = {
353
- ExportDefaultDeclaration(defaultPath) {
354
- const defaultDeclaration = defaultPath.get('declaration');
355
- const declaratorPath = getDeclaratorPath(defaultDeclaration);
356
- const kindPath = declaratorPath !== null && declaratorPath !== void 0 && declaratorPath.isVariableDeclarator() ? getKindObjectNodePath(declaratorPath.get('init')) : getKindObjectNodePath(defaultDeclaration);
357
- if (!kindPath) return;
358
- this.visitedTopPaths.add(defaultPath);
359
- removeAllPropsExcept(kindPath, kindProps);
360
- if (declaratorPath && !declaratorPath.isImportSpecifier()) removeAllPropAssignsExcept(getPropertyAssignmentPaths(getIdentifiers([declaratorPath])).entries(), kindProps);
361
- },
362
-
363
- ExportAllDeclaration(allPath) {
364
- var _this$reexportedStori;
365
-
366
- const request = allPath.get('source').node.value;
367
- this.reexportedStories.set(this.resourcePath, ((_this$reexportedStori = this.reexportedStories.get(this.resourcePath)) !== null && _this$reexportedStori !== void 0 ? _this$reexportedStori : new Set()).add(request));
368
- this.visitedTopPaths.add(allPath);
369
- },
370
-
371
- ExportNamedDeclaration(namedPath) {
372
- this.visitedTopPaths.add(namedPath);
373
- const declarationPath = namedPath.get('declaration');
374
- let storyFnPropAssigns = new Map();
375
-
376
- if (declarationPath.isVariableDeclaration()) {
377
- const declarations = declarationPath.get('declarations');
378
- declarations.map(x => x.get('init')).forEach(initPath => removeAllExpressionPropsExcept(initPath, storyProps));
379
- storyFnPropAssigns = getPropertyAssignmentPaths(getIdentifiers(declarations));
380
- } else if (declarationPath.isFunctionDeclaration()) {
381
- replaceStoryFnToNoop(declarationPath);
382
- storyFnPropAssigns = getPropertyAssignmentPaths(getIdentifiers([declarationPath]));
383
- }
384
-
385
- removeAllPropAssignsExcept(storyFnPropAssigns.entries(), storyProps);
386
- },
387
-
388
- CallExpression(rootCallPath) {
389
- const rootPath = findRootPath(rootCallPath);
390
- if (!rootCallPath.get('callee').isIdentifier({
391
- name: 'storiesOf'
392
- })) return;
393
- if (rootPath) this.visitedTopPaths.add(rootPath);
394
-
395
- if (rootPath !== null && rootPath !== void 0 && rootPath.isVariableDeclaration()) {
396
- var _rootPath$get$find;
397
-
398
- const storiesIdPath = (_rootPath$get$find = rootPath.get('declarations').find(decl => decl.get('init') == rootCallPath)) === null || _rootPath$get$find === void 0 ? void 0 : _rootPath$get$find.get('id');
399
-
400
- if (storiesIdPath !== null && storiesIdPath !== void 0 && storiesIdPath.isIdentifier()) {
401
- var _storiesIdPath$scope$, _storiesIdPath$scope$2;
402
-
403
- ((_storiesIdPath$scope$ = (_storiesIdPath$scope$2 = storiesIdPath.scope.getBinding(storiesIdPath.node.name)) === null || _storiesIdPath$scope$2 === void 0 ? void 0 : _storiesIdPath$scope$2.referencePaths) !== null && _storiesIdPath$scope$ !== void 0 ? _storiesIdPath$scope$ : []).forEach(cleanUpStoriesOfCallChain);
404
- }
405
- }
406
-
407
- cleanUpStoriesOfCallChain(rootCallPath);
408
- },
409
-
410
- Identifier(identifierPath) {
411
- if (isExports(identifierPath)) {
412
- var _getAssignmentPathWit2;
413
-
414
- const rootPath = findRootPath(identifierPath);
415
- if (rootPath) this.visitedTopPaths.add(rootPath);
416
- const [assignmentPath, props] = (_getAssignmentPathWit2 = getAssignmentPathWithProps(identifierPath)) !== null && _getAssignmentPathWit2 !== void 0 ? _getAssignmentPathWit2 : [];
417
-
418
- if (assignmentPath && props) {
419
- if (props.length == 1 && props[0] != 'default') {
420
- const declaratorPath = getDeclaratorPath(assignmentPath.get('right'));
421
-
422
- if (declaratorPath && !declaratorPath.isImportSpecifier()) {
423
- removeAllPropAssignsExcept(getPropertyAssignmentPaths(getIdentifiers([declaratorPath])).entries(), storyProps);
424
- } else {
425
- const rightPath = assignmentPath.get('right');
426
-
427
- if (isObjectAssign(rightPath)) {
428
- rightPath.get('arguments').forEach(argumentPath => removeAllExpressionPropsExcept(argumentPath, storyProps));
429
- } else rightPath.replaceWith(t.arrowFunctionExpression([], t.blockStatement([])));
430
- }
431
- } else removeAllPropAssignsExcept(new Map([[assignmentPath, props]]).entries(), exportsProps);
432
- }
433
- }
434
-
435
- if (isModuleExports(identifierPath)) {
436
- var _getAssignmentPathWit3;
437
-
438
- const rootPath = findRootPath(identifierPath);
439
- if (rootPath) this.visitedTopPaths.add(rootPath);
440
- const [assignmentPath, props] = (_getAssignmentPathWit3 = getAssignmentPathWithProps(identifierPath)) !== null && _getAssignmentPathWit3 !== void 0 ? _getAssignmentPathWit3 : [];
441
-
442
- if (assignmentPath && props) {
443
- if (props.length == 1 && props[0] == 'exports') {
444
- removeAllExpressionPropsExcept(assignmentPath.get('right'), exportsProps);
445
- } else if (props.length == 2 && props[0] == 'exports' && props[1] != 'default') {
446
- const declaratorPath = getDeclaratorPath(assignmentPath.get('right'));
447
-
448
- if (declaratorPath && !declaratorPath.isImportSpecifier()) {
449
- removeAllPropAssignsExcept(getPropertyAssignmentPaths(getIdentifiers([declaratorPath])).entries(), storyProps);
450
- } else {
451
- const rightPath = assignmentPath.get('right');
452
-
453
- if (isObjectAssign(rightPath)) {
454
- rightPath.get('arguments').forEach(argumentPath => removeAllExpressionPropsExcept(argumentPath, storyProps));
455
- } else rightPath.replaceWith(t.arrowFunctionExpression([], t.blockStatement([])));
456
- }
457
- } else removeAllPropAssignsExcept(new Map([[assignmentPath, props]]).entries(), [['exports', ...exportsProps]]);
458
- }
459
- }
460
- }
461
-
462
- };