creevey 0.9.0-beta.12 → 0.9.0-beta.14

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