creevey 0.9.0-beta.2 → 0.9.0-beta.20

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 (226) hide show
  1. package/.yarn/install-state.gz +0 -0
  2. package/.yarnrc.yml +1 -0
  3. package/CHANGELOG.md +51 -0
  4. package/README.md +9 -1
  5. package/addon/README.md +3 -0
  6. package/addon/package.json +5 -0
  7. package/docs/config.md +29 -26
  8. package/jest.config.js +6 -0
  9. package/lib/cjs/cli.js +1 -0
  10. package/lib/cjs/client/addon/Manager.js +170 -390
  11. package/lib/cjs/client/addon/components/Addon.js +17 -45
  12. package/lib/cjs/client/addon/components/Icons.js +12 -14
  13. package/lib/cjs/client/addon/components/Panel.js +21 -30
  14. package/lib/cjs/client/addon/components/TestSelect.js +20 -31
  15. package/lib/cjs/client/addon/components/Tools.js +35 -65
  16. package/lib/cjs/client/addon/decorator.js +1 -4
  17. package/lib/cjs/client/addon/index.js +27 -0
  18. package/lib/cjs/client/addon/preset.js +3 -76
  19. package/lib/cjs/client/addon/preview.js +11 -0
  20. package/lib/cjs/client/addon/readyForCapture.js +1 -4
  21. package/lib/cjs/client/addon/register.js +43 -82
  22. package/lib/cjs/client/addon/utils.js +4 -8
  23. package/lib/cjs/client/addon/withCreevey.js +145 -404
  24. package/lib/cjs/client/shared/components/ImagesView/BlendView.js +25 -35
  25. package/lib/cjs/client/shared/components/ImagesView/ImagesView.js +29 -41
  26. package/lib/cjs/client/shared/components/ImagesView/SideBySideView.js +46 -83
  27. package/lib/cjs/client/shared/components/ImagesView/SlideView.js +39 -67
  28. package/lib/cjs/client/shared/components/ImagesView/SwapView.js +26 -57
  29. package/lib/cjs/client/shared/components/ImagesView/index.js +9 -14
  30. package/lib/cjs/client/shared/components/PageFooter/PageFooter.js +13 -16
  31. package/lib/cjs/client/shared/components/PageFooter/Paging.js +16 -37
  32. package/lib/cjs/client/shared/components/PageHeader/ImagePreview.js +42 -34
  33. package/lib/cjs/client/shared/components/PageHeader/PageHeader.js +40 -84
  34. package/lib/cjs/client/shared/components/ResultsPage.js +42 -99
  35. package/lib/cjs/client/shared/creeveyClientApi.js +56 -93
  36. package/lib/cjs/client/shared/helpers.js +149 -274
  37. package/lib/cjs/client/shared/viewMode.js +5 -9
  38. package/lib/cjs/client/web/192.js +1 -0
  39. package/lib/cjs/client/web/632.js +43 -0
  40. package/lib/cjs/client/web/794.js +1 -0
  41. package/lib/cjs/client/web/main.js +79 -38
  42. package/lib/cjs/client/web/main.js.LICENSE.txt +34 -0
  43. package/lib/cjs/creevey.js +15 -30
  44. package/lib/cjs/index.js +0 -15
  45. package/lib/cjs/server/config.js +16 -36
  46. package/lib/cjs/server/docker.js +8 -34
  47. package/lib/cjs/server/index.js +9 -34
  48. package/lib/cjs/server/logger.js +7 -20
  49. package/lib/cjs/server/master/api.js +1 -14
  50. package/lib/cjs/server/master/index.js +25 -49
  51. package/lib/cjs/server/master/master.js +6 -21
  52. package/lib/cjs/server/master/pool.js +10 -53
  53. package/lib/cjs/server/master/runner.js +65 -105
  54. package/lib/cjs/server/master/server.js +10 -29
  55. package/lib/cjs/server/messages.js +14 -62
  56. package/lib/cjs/server/selenium/browser.js +149 -185
  57. package/lib/cjs/server/selenium/index.js +0 -4
  58. package/lib/cjs/server/selenium/selenoid.js +18 -44
  59. package/lib/cjs/server/stories.js +35 -57
  60. package/lib/cjs/server/storybook/providers/browser.js +15 -29
  61. package/lib/cjs/server/storybook/providers/hybrid.js +16 -37
  62. package/lib/cjs/server/telemetry.js +167 -0
  63. package/lib/cjs/server/testsFiles/parser.js +3 -19
  64. package/lib/cjs/server/testsFiles/register.js +8 -14
  65. package/lib/cjs/server/update.js +4 -25
  66. package/lib/cjs/server/utils.js +35 -76
  67. package/lib/cjs/server/worker/chai-image.js +1 -27
  68. package/lib/cjs/server/worker/helpers.js +2 -12
  69. package/lib/cjs/server/worker/index.js +1 -3
  70. package/lib/cjs/server/worker/reporter.js +16 -43
  71. package/lib/cjs/server/worker/worker.js +32 -72
  72. package/lib/cjs/shared/index.js +87 -0
  73. package/lib/cjs/shared/serializeRegExp.js +34 -0
  74. package/lib/cjs/types.js +11 -20
  75. package/lib/esm/cli.js +1 -1
  76. package/lib/esm/client/addon/Manager.js +170 -381
  77. package/lib/esm/client/addon/components/Addon.js +15 -34
  78. package/lib/esm/client/addon/components/Icons.js +10 -6
  79. package/lib/esm/client/addon/components/Panel.js +20 -18
  80. package/lib/esm/client/addon/components/TestSelect.js +19 -23
  81. package/lib/esm/client/addon/components/Tools.js +33 -49
  82. package/lib/esm/client/addon/decorator.js +1 -1
  83. package/lib/esm/client/addon/index.js +2 -0
  84. package/lib/esm/client/addon/preset.js +2 -56
  85. package/lib/esm/client/addon/preview.js +5 -0
  86. package/lib/esm/client/addon/readyForCapture.js +1 -3
  87. package/lib/esm/client/addon/register.js +41 -67
  88. package/lib/esm/client/addon/utils.js +3 -7
  89. package/lib/esm/client/addon/withCreevey.js +142 -388
  90. package/lib/esm/client/shared/components/ImagesView/BlendView.js +22 -18
  91. package/lib/esm/client/shared/components/ImagesView/ImagesView.js +27 -25
  92. package/lib/esm/client/shared/components/ImagesView/SideBySideView.js +43 -63
  93. package/lib/esm/client/shared/components/ImagesView/SlideView.js +36 -47
  94. package/lib/esm/client/shared/components/ImagesView/SwapView.js +23 -40
  95. package/lib/esm/client/shared/components/PageFooter/PageFooter.js +12 -8
  96. package/lib/esm/client/shared/components/PageFooter/Paging.js +15 -29
  97. package/lib/esm/client/shared/components/PageHeader/ImagePreview.js +40 -25
  98. package/lib/esm/client/shared/components/PageHeader/PageHeader.js +38 -66
  99. package/lib/esm/client/shared/components/ResultsPage.js +39 -75
  100. package/lib/esm/client/shared/creeveyClientApi.js +56 -90
  101. package/lib/esm/client/shared/helpers.js +133 -230
  102. package/lib/esm/client/shared/viewMode.js +4 -4
  103. package/lib/esm/client/web/192.js +1 -0
  104. package/lib/esm/client/web/632.js +43 -0
  105. package/lib/esm/client/web/794.js +1 -0
  106. package/lib/esm/client/web/index.html +19 -0
  107. package/lib/esm/client/web/main.js +79 -0
  108. package/lib/esm/client/web/main.js.LICENSE.txt +34 -0
  109. package/lib/esm/creevey.js +13 -16
  110. package/lib/esm/index.js +1 -4
  111. package/lib/esm/server/config.js +9 -16
  112. package/lib/esm/server/docker.js +6 -14
  113. package/lib/esm/server/index.js +8 -22
  114. package/lib/esm/server/logger.js +0 -1
  115. package/lib/esm/server/master/api.js +0 -9
  116. package/lib/esm/server/master/index.js +25 -35
  117. package/lib/esm/server/master/master.js +2 -7
  118. package/lib/esm/server/master/pool.js +8 -41
  119. package/lib/esm/server/master/runner.js +64 -90
  120. package/lib/esm/server/master/server.js +9 -11
  121. package/lib/esm/server/messages.js +8 -42
  122. package/lib/esm/server/selenium/browser.js +147 -163
  123. package/lib/esm/server/selenium/selenoid.js +16 -27
  124. package/lib/esm/server/stories.js +34 -46
  125. package/lib/esm/server/storybook/providers/browser.js +12 -17
  126. package/lib/esm/server/storybook/providers/hybrid.js +11 -22
  127. package/lib/esm/server/telemetry.js +160 -0
  128. package/lib/esm/server/testsFiles/parser.js +0 -6
  129. package/lib/esm/server/testsFiles/register.js +6 -7
  130. package/lib/esm/server/update.js +1 -13
  131. package/lib/esm/server/utils.js +20 -41
  132. package/lib/esm/server/worker/chai-image.js +0 -21
  133. package/lib/esm/server/worker/helpers.js +2 -9
  134. package/lib/esm/server/worker/reporter.js +15 -29
  135. package/lib/esm/server/worker/worker.js +31 -48
  136. package/lib/esm/shared/index.js +77 -0
  137. package/lib/esm/shared/serializeRegExp.js +24 -0
  138. package/lib/esm/types.js +5 -1
  139. package/lib/types/client/addon/Manager.d.ts +3 -3
  140. package/lib/types/client/addon/components/Addon.d.ts +1 -0
  141. package/lib/types/client/addon/components/Icons.d.ts +1 -0
  142. package/lib/types/client/addon/components/Panel.d.ts +1 -0
  143. package/lib/types/client/addon/components/Tools.d.ts +1 -0
  144. package/lib/types/client/addon/decorator.d.ts +1 -1
  145. package/lib/types/client/addon/index.d.ts +2 -0
  146. package/lib/types/client/addon/preset.d.ts +2 -24
  147. package/lib/types/client/addon/preview.d.ts +4 -0
  148. package/lib/types/client/addon/utils.d.ts +1 -0
  149. package/lib/types/client/addon/withCreevey.d.ts +4 -3
  150. package/lib/types/client/shared/components/ImagesView/BlendView.d.ts +3 -1
  151. package/lib/types/client/shared/components/ImagesView/SideBySideView.d.ts +3 -1
  152. package/lib/types/client/shared/components/ImagesView/SlideView.d.ts +3 -1
  153. package/lib/types/client/shared/components/ImagesView/SwapView.d.ts +3 -1
  154. package/lib/types/client/shared/components/PageHeader/ImagePreview.d.ts +3 -1
  155. package/lib/types/client/shared/components/ResultsPage.d.ts +3 -1
  156. package/lib/types/client/web/CreeveyLoader.d.ts +1 -1
  157. package/lib/types/client/web/CreeveyView/SideBar/Checkbox.d.ts +6 -3
  158. package/lib/types/client/web/CreeveyView/SideBar/Search.d.ts +1 -0
  159. package/lib/types/client/web/CreeveyView/SideBar/SuiteLink.d.ts +19 -14
  160. package/lib/types/client/web/CreeveyView/SideBar/TestStatusIcon.d.ts +3 -1
  161. package/lib/types/client/web/CreeveyView/SideBar/TestsStatus.d.ts +3 -1
  162. package/lib/types/client/web/CreeveyView/SideBar/Toggle.d.ts +1 -0
  163. package/lib/types/client/web/KeyboardEventsContext.d.ts +4 -2
  164. package/lib/types/index.d.ts +4 -1
  165. package/lib/types/server/logger.d.ts +6 -2
  166. package/lib/types/server/messages.d.ts +14 -12
  167. package/lib/types/server/selenium/browser.d.ts +5 -3
  168. package/lib/types/server/storybook/providers/browser.d.ts +2 -4
  169. package/lib/types/server/storybook/providers/hybrid.d.ts +2 -4
  170. package/lib/types/server/telemetry.d.ts +2 -0
  171. package/lib/types/server/utils.d.ts +5 -1
  172. package/lib/types/shared/index.d.ts +7 -0
  173. package/lib/types/shared/serializeRegExp.d.ts +9 -0
  174. package/lib/types/types.d.ts +29 -36
  175. package/package.json +132 -133
  176. package/types/global.d.ts +5 -0
  177. package/lib/cjs/client/web/1.js +0 -13
  178. package/lib/cjs/client/web/2.js +0 -1
  179. package/lib/cjs/server/extract.js +0 -50
  180. package/lib/cjs/server/loaders/babel/creevey-plugin.js +0 -88
  181. package/lib/cjs/server/loaders/babel/helpers.js +0 -479
  182. package/lib/cjs/server/loaders/babel/register.js +0 -126
  183. package/lib/cjs/server/loaders/hooks/mdx.js +0 -30
  184. package/lib/cjs/server/loaders/hooks/svelte.js +0 -65
  185. package/lib/cjs/server/loaders/webpack/compile.js +0 -286
  186. package/lib/cjs/server/loaders/webpack/creevey-loader.js +0 -174
  187. package/lib/cjs/server/loaders/webpack/dummy-hmr.js +0 -44
  188. package/lib/cjs/server/loaders/webpack/mdx-loader.js +0 -72
  189. package/lib/cjs/server/loaders/webpack/start.js +0 -41
  190. package/lib/cjs/server/storybook/entry.js +0 -68
  191. package/lib/cjs/server/storybook/helpers.js +0 -165
  192. package/lib/cjs/server/storybook/providers/nodejs.js +0 -239
  193. package/lib/cjs/shared.js +0 -124
  194. package/lib/esm/server/extract.js +0 -34
  195. package/lib/esm/server/loaders/babel/creevey-plugin.js +0 -74
  196. package/lib/esm/server/loaders/babel/helpers.js +0 -462
  197. package/lib/esm/server/loaders/babel/register.js +0 -105
  198. package/lib/esm/server/loaders/hooks/mdx.js +0 -15
  199. package/lib/esm/server/loaders/hooks/svelte.js +0 -49
  200. package/lib/esm/server/loaders/webpack/compile.js +0 -263
  201. package/lib/esm/server/loaders/webpack/creevey-loader.js +0 -153
  202. package/lib/esm/server/loaders/webpack/dummy-hmr.js +0 -36
  203. package/lib/esm/server/loaders/webpack/mdx-loader.js +0 -58
  204. package/lib/esm/server/loaders/webpack/start.js +0 -27
  205. package/lib/esm/server/storybook/entry.js +0 -44
  206. package/lib/esm/server/storybook/helpers.js +0 -106
  207. package/lib/esm/server/storybook/providers/nodejs.js +0 -217
  208. package/lib/esm/shared.js +0 -93
  209. package/lib/types/server/extract.d.ts +0 -2
  210. package/lib/types/server/loaders/babel/creevey-plugin.d.ts +0 -1
  211. package/lib/types/server/loaders/babel/helpers.d.ts +0 -19
  212. package/lib/types/server/loaders/babel/register.d.ts +0 -5
  213. package/lib/types/server/loaders/hooks/mdx.d.ts +0 -1
  214. package/lib/types/server/loaders/hooks/svelte.d.ts +0 -1
  215. package/lib/types/server/loaders/webpack/compile.d.ts +0 -2
  216. package/lib/types/server/loaders/webpack/creevey-loader.d.ts +0 -2
  217. package/lib/types/server/loaders/webpack/dummy-hmr.d.ts +0 -10
  218. package/lib/types/server/loaders/webpack/mdx-loader.d.ts +0 -6
  219. package/lib/types/server/loaders/webpack/start.d.ts +0 -1
  220. package/lib/types/server/storybook/entry.d.ts +0 -18
  221. package/lib/types/server/storybook/helpers.d.ts +0 -24
  222. package/lib/types/server/storybook/providers/nodejs.d.ts +0 -9
  223. package/lib/types/shared.d.ts +0 -16
  224. package/preset.js +0 -9
  225. package/storybook-static/stories.json +0 -21
  226. package/types/mdx.d.ts +0 -6
@@ -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
- };
@@ -1,105 +0,0 @@
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
- var _filter$test;
42
-
43
- const filename = dirent.name;
44
- const filePath = join(dirPath, filename);
45
- if (dirent.isDirectory() && deep) return traverse(filePath);
46
- if (dirent.isFile() && ((_filter$test = filter === null || filter === void 0 ? void 0 : filter.test(`./${relative(contextPath, filePath)}`)) !== null && _filter$test !== void 0 ? _filter$test : true)) return ids.push(filePath);
47
- });
48
- };
49
-
50
- traverse(contextPath);
51
-
52
- const context = id => {
53
- story = id; // eslint-disable-next-line @typescript-eslint/no-var-requires
54
-
55
- const storyModule = require(id);
56
-
57
- story = null;
58
- return storyModule;
59
- };
60
-
61
- context.id = contextPath;
62
-
63
- context.keys = () => ids;
64
-
65
- context.resolve = id => id;
66
-
67
- return context;
68
- };
69
- }
70
-
71
- export default async function register(config, debug = false) {
72
- const rootDir = isStorybookVersionLessThan(6, 4) ? config.storybookDir : process.cwd();
73
- const requireContext = getRequireContext(rootDir);
74
- const preview = resolve(config.storybookDir, 'preview');
75
- if (hasDocsAddon()) await (await import('../hooks/mdx')).addMDXHook(() => story);
76
- if (hasSvelteCSFAddon()) await (await import('../hooks/svelte')).addSvelteHook(() => story); // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
77
-
78
- (await import('@babel/register')).default(config.babelOptions({
79
- babelrc: false,
80
- rootMode: 'upward-optional',
81
- ignore: [/node_modules/],
82
- extensions: [...extensions, ...(hasDocsAddon() ? ['.mdx'] : []), ...(hasSvelteCSFAddon() ? ['.svelte'] : [])],
83
- parserOpts: {
84
- sourceType: 'module',
85
- plugins: ['classProperties', 'decorators-legacy', 'jsx', 'typescript']
86
- },
87
- plugins: [[plugin, {
88
- debug,
89
- preview,
90
- parents: () => parents,
91
- story: () => story
92
- }], ['@babel/plugin-transform-runtime', {
93
- // eslint-disable-next-line @typescript-eslint/no-var-requires
94
- version: require('@babel/helpers/package.json').version,
95
- absoluteRuntime: true,
96
- corejs: 3
97
- }]],
98
- presets: [['@babel/preset-env', {
99
- targets: {
100
- node: '10'
101
- }
102
- }]]
103
- }));
104
- return requireContext;
105
- }
@@ -1,15 +0,0 @@
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
- };