creevey 0.9.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 (148) hide show
  1. package/lib/types/index.d.ts +4 -3
  2. package/lib/types/server/config.d.ts +1 -1
  3. package/lib/types/server/messages.d.ts +0 -1
  4. package/lib/types/server/{parser.d.ts → testsFiles/parser.d.ts} +1 -1
  5. package/lib/types/server/testsFiles/register.d.ts +2 -0
  6. package/lib/types/types.d.ts +3 -2
  7. package/package.json +5 -2
  8. package/lib/cjs/cli.js +0 -5
  9. package/lib/cjs/client/addon/Manager.js +0 -412
  10. package/lib/cjs/client/addon/components/Addon.js +0 -76
  11. package/lib/cjs/client/addon/components/Icons.js +0 -42
  12. package/lib/cjs/client/addon/components/Panel.js +0 -68
  13. package/lib/cjs/client/addon/components/TestSelect.js +0 -63
  14. package/lib/cjs/client/addon/components/Tools.js +0 -114
  15. package/lib/cjs/client/addon/decorator.js +0 -11
  16. package/lib/cjs/client/addon/preset.js +0 -81
  17. package/lib/cjs/client/addon/readyForCapture.js +0 -12
  18. package/lib/cjs/client/addon/register.js +0 -96
  19. package/lib/cjs/client/addon/utils.js +0 -38
  20. package/lib/cjs/client/addon/withCreevey.js +0 -556
  21. package/lib/cjs/client/shared/components/ImagesView/BlendView.js +0 -85
  22. package/lib/cjs/client/shared/components/ImagesView/ImagesView.js +0 -88
  23. package/lib/cjs/client/shared/components/ImagesView/SideBySideView.js +0 -176
  24. package/lib/cjs/client/shared/components/ImagesView/SlideView.js +0 -179
  25. package/lib/cjs/client/shared/components/ImagesView/SwapView.js +0 -110
  26. package/lib/cjs/client/shared/components/ImagesView/index.js +0 -45
  27. package/lib/cjs/client/shared/components/PageFooter/PageFooter.js +0 -46
  28. package/lib/cjs/client/shared/components/PageFooter/Paging.js +0 -98
  29. package/lib/cjs/client/shared/components/PageHeader/ImagePreview.js +0 -78
  30. package/lib/cjs/client/shared/components/PageHeader/PageHeader.js +0 -144
  31. package/lib/cjs/client/shared/components/ResultsPage.js +0 -173
  32. package/lib/cjs/client/shared/creeveyClientApi.js +0 -103
  33. package/lib/cjs/client/shared/helpers.js +0 -482
  34. package/lib/cjs/client/shared/viewMode.js +0 -17
  35. package/lib/cjs/client/web/index.html +0 -19
  36. package/lib/cjs/creevey.js +0 -71
  37. package/lib/cjs/index.js +0 -62
  38. package/lib/cjs/server/config.js +0 -96
  39. package/lib/cjs/server/docker.js +0 -150
  40. package/lib/cjs/server/extract.js +0 -50
  41. package/lib/cjs/server/index.js +0 -83
  42. package/lib/cjs/server/loaders/babel/creevey-plugin.js +0 -88
  43. package/lib/cjs/server/loaders/babel/helpers.js +0 -479
  44. package/lib/cjs/server/loaders/babel/register.js +0 -126
  45. package/lib/cjs/server/loaders/hooks/mdx.js +0 -30
  46. package/lib/cjs/server/loaders/hooks/svelte.js +0 -65
  47. package/lib/cjs/server/loaders/webpack/compile.js +0 -286
  48. package/lib/cjs/server/loaders/webpack/creevey-loader.js +0 -174
  49. package/lib/cjs/server/loaders/webpack/dummy-hmr.js +0 -44
  50. package/lib/cjs/server/loaders/webpack/mdx-loader.js +0 -72
  51. package/lib/cjs/server/loaders/webpack/start.js +0 -41
  52. package/lib/cjs/server/logger.js +0 -47
  53. package/lib/cjs/server/master/api.js +0 -71
  54. package/lib/cjs/server/master/index.js +0 -146
  55. package/lib/cjs/server/master/master.js +0 -57
  56. package/lib/cjs/server/master/pool.js +0 -206
  57. package/lib/cjs/server/master/runner.js +0 -294
  58. package/lib/cjs/server/master/server.js +0 -129
  59. package/lib/cjs/server/messages.js +0 -266
  60. package/lib/cjs/server/parser.js +0 -85
  61. package/lib/cjs/server/selenium/browser.js +0 -680
  62. package/lib/cjs/server/selenium/index.js +0 -31
  63. package/lib/cjs/server/selenium/selenoid.js +0 -174
  64. package/lib/cjs/server/stories.js +0 -170
  65. package/lib/cjs/server/storybook/entry.js +0 -68
  66. package/lib/cjs/server/storybook/helpers.js +0 -165
  67. package/lib/cjs/server/storybook/providers/browser.js +0 -78
  68. package/lib/cjs/server/storybook/providers/hybrid.js +0 -79
  69. package/lib/cjs/server/storybook/providers/nodejs.js +0 -239
  70. package/lib/cjs/server/update.js +0 -83
  71. package/lib/cjs/server/utils.js +0 -185
  72. package/lib/cjs/server/worker/chai-image.js +0 -142
  73. package/lib/cjs/server/worker/helpers.js +0 -69
  74. package/lib/cjs/server/worker/index.js +0 -15
  75. package/lib/cjs/server/worker/reporter.js +0 -120
  76. package/lib/cjs/server/worker/worker.js +0 -278
  77. package/lib/cjs/shared.js +0 -107
  78. package/lib/cjs/types.js +0 -74
  79. package/lib/esm/cli.js +0 -4
  80. package/lib/esm/client/addon/Manager.js +0 -396
  81. package/lib/esm/client/addon/components/Addon.js +0 -58
  82. package/lib/esm/client/addon/components/Icons.js +0 -27
  83. package/lib/esm/client/addon/components/Panel.js +0 -49
  84. package/lib/esm/client/addon/components/TestSelect.js +0 -49
  85. package/lib/esm/client/addon/components/Tools.js +0 -91
  86. package/lib/esm/client/addon/decorator.js +0 -2
  87. package/lib/esm/client/addon/preset.js +0 -56
  88. package/lib/esm/client/addon/readyForCapture.js +0 -5
  89. package/lib/esm/client/addon/register.js +0 -75
  90. package/lib/esm/client/addon/utils.js +0 -31
  91. package/lib/esm/client/addon/withCreevey.js +0 -532
  92. package/lib/esm/client/shared/components/ImagesView/BlendView.js +0 -63
  93. package/lib/esm/client/shared/components/ImagesView/ImagesView.js +0 -65
  94. package/lib/esm/client/shared/components/ImagesView/SideBySideView.js +0 -151
  95. package/lib/esm/client/shared/components/ImagesView/SlideView.js +0 -154
  96. package/lib/esm/client/shared/components/ImagesView/SwapView.js +0 -88
  97. package/lib/esm/client/shared/components/ImagesView/index.js +0 -5
  98. package/lib/esm/client/shared/components/PageFooter/PageFooter.js +0 -32
  99. package/lib/esm/client/shared/components/PageFooter/Paging.js +0 -84
  100. package/lib/esm/client/shared/components/PageHeader/ImagePreview.js +0 -64
  101. package/lib/esm/client/shared/components/PageHeader/PageHeader.js +0 -120
  102. package/lib/esm/client/shared/components/ResultsPage.js +0 -143
  103. package/lib/esm/client/shared/creeveyClientApi.js +0 -94
  104. package/lib/esm/client/shared/helpers.js +0 -424
  105. package/lib/esm/client/shared/viewMode.js +0 -6
  106. package/lib/esm/creevey.js +0 -56
  107. package/lib/esm/index.js +0 -7
  108. package/lib/esm/server/config.js +0 -73
  109. package/lib/esm/server/docker.js +0 -123
  110. package/lib/esm/server/extract.js +0 -34
  111. package/lib/esm/server/index.js +0 -64
  112. package/lib/esm/server/loaders/babel/creevey-plugin.js +0 -74
  113. package/lib/esm/server/loaders/babel/helpers.js +0 -462
  114. package/lib/esm/server/loaders/babel/register.js +0 -105
  115. package/lib/esm/server/loaders/hooks/mdx.js +0 -15
  116. package/lib/esm/server/loaders/hooks/svelte.js +0 -49
  117. package/lib/esm/server/loaders/webpack/compile.js +0 -263
  118. package/lib/esm/server/loaders/webpack/creevey-loader.js +0 -153
  119. package/lib/esm/server/loaders/webpack/dummy-hmr.js +0 -36
  120. package/lib/esm/server/loaders/webpack/mdx-loader.js +0 -58
  121. package/lib/esm/server/loaders/webpack/start.js +0 -27
  122. package/lib/esm/server/logger.js +0 -20
  123. package/lib/esm/server/master/api.js +0 -60
  124. package/lib/esm/server/master/index.js +0 -125
  125. package/lib/esm/server/master/master.js +0 -38
  126. package/lib/esm/server/master/pool.js +0 -187
  127. package/lib/esm/server/master/runner.js +0 -272
  128. package/lib/esm/server/master/server.js +0 -105
  129. package/lib/esm/server/messages.js +0 -234
  130. package/lib/esm/server/parser.js +0 -63
  131. package/lib/esm/server/selenium/browser.js +0 -647
  132. package/lib/esm/server/selenium/index.js +0 -2
  133. package/lib/esm/server/selenium/selenoid.js +0 -151
  134. package/lib/esm/server/stories.js +0 -151
  135. package/lib/esm/server/storybook/entry.js +0 -44
  136. package/lib/esm/server/storybook/helpers.js +0 -106
  137. package/lib/esm/server/storybook/providers/browser.js +0 -61
  138. package/lib/esm/server/storybook/providers/hybrid.js +0 -63
  139. package/lib/esm/server/storybook/providers/nodejs.js +0 -217
  140. package/lib/esm/server/update.js +0 -65
  141. package/lib/esm/server/utils.js +0 -146
  142. package/lib/esm/server/worker/chai-image.js +0 -130
  143. package/lib/esm/server/worker/helpers.js +0 -60
  144. package/lib/esm/server/worker/index.js +0 -1
  145. package/lib/esm/server/worker/reporter.js +0 -98
  146. package/lib/esm/server/worker/worker.js +0 -248
  147. package/lib/esm/shared.js +0 -76
  148. package/lib/esm/types.js +0 -43
@@ -1,479 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.storyVisitor = exports.mdxVisitor = exports.previewVisitor = exports.commonVisitor = exports.FileType = void 0;
7
-
8
- var t = _interopRequireWildcard(require("@babel/types"));
9
-
10
- var _types2 = require("../../../types");
11
-
12
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
13
-
14
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
15
-
16
- function isExports(path) {
17
- const {
18
- parentPath
19
- } = path;
20
- return path.node.name == 'exports' && path.scope.hasGlobal('exports') && !path.scope.hasBinding('exports') && parentPath.isMemberExpression() && parentPath.get('object').isIdentifier({
21
- name: 'exports'
22
- });
23
- }
24
-
25
- function isModuleExports(path) {
26
- const {
27
- parentPath
28
- } = path;
29
- return path.node.name == 'module' && path.scope.hasGlobal('module') && !path.scope.hasBinding('module') && parentPath.isMemberExpression() && parentPath.get('object').isIdentifier({
30
- name: 'module'
31
- }) && parentPath.get('property').isIdentifier({
32
- name: 'exports'
33
- });
34
- }
35
-
36
- function isObjectAssign(path) {
37
- if (!(path !== null && path !== void 0 && path.isCallExpression())) return false;
38
- const calleePath = path.get('callee');
39
- return calleePath.isMemberExpression() && calleePath.get('object').isIdentifier({
40
- name: 'Object'
41
- }) && calleePath.get('property').isIdentifier({
42
- name: 'assign'
43
- });
44
- }
45
-
46
- function isTemplateBind(path) {
47
- if (!(path !== null && path !== void 0 && path.isCallExpression())) return false;
48
- const calleePath = path.get('callee');
49
- return calleePath.isMemberExpression() && calleePath.get('object').isIdentifier() && calleePath.get('property').isIdentifier({
50
- name: 'bind'
51
- });
52
- }
53
-
54
- function findRootPath(path) {
55
- return path.find(x => {
56
- var _x$parentPath;
57
-
58
- return Boolean((_x$parentPath = x.parentPath) === null || _x$parentPath === void 0 ? void 0 : _x$parentPath.isProgram());
59
- });
60
- }
61
-
62
- function getPropertyPath(path, name) {
63
- const propertyPath = path.get('properties').find(propPath => propPath.isObjectProperty() && t.isIdentifier(propPath.node.key, {
64
- name
65
- }));
66
- return propertyPath !== null && propertyPath !== void 0 && propertyPath.isObjectProperty() ? propertyPath : undefined;
67
- } // TODO Support import and process them
68
-
69
-
70
- function getDeclaratorPath(path) {
71
- if (path !== null && path !== void 0 && path.isIdentifier()) {
72
- var _path$scope$getBindin;
73
-
74
- const {
75
- path: bindingPath
76
- } = (_path$scope$getBindin = path.scope.getBinding(path.node.name)) !== null && _path$scope$getBindin !== void 0 ? _path$scope$getBindin : {};
77
- if (bindingPath !== null && bindingPath !== void 0 && bindingPath.isVariableDeclarator() || bindingPath !== null && bindingPath !== void 0 && bindingPath.isFunctionDeclaration() || bindingPath !== null && bindingPath !== void 0 && bindingPath.isImportSpecifier()) return bindingPath;
78
- }
79
- }
80
-
81
- function getKindObjectNodePath(path) {
82
- if (path.isObjectExpression()) {
83
- return getPropertyPath(path, 'title') ? path : undefined;
84
- }
85
- }
86
-
87
- function getIdentifiers(path) {
88
- return path.map(x => x.isFunctionDeclaration() ? x.get('id') : x.get('id')).map(idPath => idPath.isIdentifier() ? idPath : null).filter(_types2.isDefined);
89
- }
90
-
91
- function removeAllPropsExcept(path, propNames) {
92
- const getPropName = propPath => propNames.find(names => {
93
- const keyPath = propPath.isObjectProperty() ? propPath.get('key') : propPath.get('key');
94
- if (!keyPath.isIdentifier()) return;
95
- const name = Array.isArray(names) ? names[0] : names;
96
- return typeof name == 'string' ? keyPath.isIdentifier({
97
- name
98
- }) : name(keyPath.node.name);
99
- });
100
-
101
- path.get('properties').forEach(propPath => {
102
- if (propPath.isObjectProperty() || propPath.isObjectMethod()) {
103
- const propName = getPropName(propPath);
104
- if (!propName) return propPath.remove();
105
- const restNames = Array.isArray(propName) ? propName.slice(1) : [];
106
- if (propPath.isObjectProperty() && restNames.length != 0) removeAllExpressionPropsExcept(propPath === null || propPath === void 0 ? void 0 : propPath.get('value'), restNames);
107
- if (propPath.isObjectMethod() && restNames[0] == 'storyName') replaceStoryFnToNoop(propPath);
108
- } else if (propPath.isSpreadElement()) {
109
- removeAllExpressionPropsExcept(propPath.get('argument'), propNames);
110
- } else propPath.remove();
111
- });
112
- }
113
-
114
- function removeAllPropAssignsExcept(propAssigns, propNames) {
115
- for (const [assignPath, props] of propAssigns !== null && propAssigns !== void 0 ? propAssigns : []) {
116
- const restNames = props.reduce((subPropNames, prop) => {
117
- const propName = subPropNames.find(names => {
118
- const name = Array.isArray(names) ? names[0] : names;
119
- return typeof name == 'string' ? name == prop : name(prop);
120
- });
121
- if (Array.isArray(propName)) return propName.slice(1);
122
- if (!propName) assignPath.remove();
123
- return [];
124
- }, propNames);
125
- if (restNames.length != 0) removeAllExpressionPropsExcept(assignPath.get('right'), restNames);
126
- }
127
- }
128
-
129
- function replaceStoryFnToNoop(path) {
130
- 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([]));
131
- }
132
-
133
- function getAssignmentPathWithProps(refPath) {
134
- const assignmentPath = refPath.findParent(parentPath => parentPath.isAssignmentExpression());
135
- if (!(assignmentPath !== null && assignmentPath !== void 0 && assignmentPath.isAssignmentExpression())) return;
136
- const props = [];
137
-
138
- for (let propPath = refPath.parentPath; propPath != assignmentPath; propPath = propPath.parentPath) {
139
- var _propPath;
140
-
141
- if (!((_propPath = propPath) !== null && _propPath !== void 0 && _propPath.isMemberExpression())) return;
142
- const propNode = propPath.node.property;
143
- if (!t.isIdentifier(propNode)) return;
144
- props.push(propNode.name);
145
- }
146
-
147
- if (props.length != 0) return [assignmentPath, props];
148
- }
149
-
150
- function getPropertyAssignmentPaths(idPaths) {
151
- const assignPaths = new Map();
152
- idPaths.forEach(idPath => {
153
- var _idPath$scope$getBind, _idPath$scope$getBind2;
154
-
155
- 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 : [];
156
- referencePaths.forEach(refPath => {
157
- var _getAssignmentPathWit;
158
-
159
- const [assignmentPath, props] = (_getAssignmentPathWit = getAssignmentPathWithProps(refPath)) !== null && _getAssignmentPathWit !== void 0 ? _getAssignmentPathWit : [];
160
- if (assignmentPath && props) assignPaths.set(assignmentPath, props);
161
- });
162
- });
163
- return assignPaths;
164
- }
165
-
166
- function removeAllExpressionPropsExcept(expressionPath, propNames) {
167
- const resolvedDeclPath = getDeclaratorPath(expressionPath);
168
- if (expressionPath !== null && expressionPath !== void 0 && expressionPath.isObjectExpression()) removeAllPropsExcept(expressionPath, propNames);else if (expressionPath !== null && expressionPath !== void 0 && expressionPath.isCallExpression()) {
169
- if (isObjectAssign(expressionPath)) expressionPath.get('arguments').forEach(argumentPath => removeAllExpressionPropsExcept(argumentPath, storyProps));else if (isTemplateBind(expressionPath)) {
170
- const calleePath = expressionPath.get('callee');
171
- if (calleePath.isMemberExpression()) removeAllExpressionPropsExcept(calleePath.get('object'), propNames);
172
- } else if (propNames[0] == 'storyName') {
173
- expressionPath === null || expressionPath === void 0 ? void 0 : expressionPath.replaceWith(t.arrowFunctionExpression([], t.blockStatement([])));
174
- }
175
- } 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([])));
176
-
177
- if (resolvedDeclPath) {
178
- if (!resolvedDeclPath.isImportSpecifier()) removeAllPropAssignsExcept(getPropertyAssignmentPaths(getIdentifiers([resolvedDeclPath])).entries(), propNames);
179
- if (resolvedDeclPath.isVariableDeclarator()) removeAllExpressionPropsExcept(resolvedDeclPath.get('init'), propNames);
180
- if (resolvedDeclPath.isFunctionDeclaration() && propNames[0] == 'storyName') replaceStoryFnToNoop(resolvedDeclPath);
181
- }
182
- }
183
-
184
- function cleanUpStoriesOfCallChain(storiesOfPath) {
185
- let callPath = storiesOfPath;
186
-
187
- do {
188
- const childCallPath = callPath;
189
- const {
190
- parentPath: memberPath
191
- } = childCallPath;
192
- if (!memberPath || !memberPath.isMemberExpression()) return;
193
- callPath = memberPath.parentPath;
194
- const propPath = memberPath.get('property');
195
- if (!callPath.isCallExpression()) return;
196
-
197
- if (propPath.isIdentifier({
198
- name: 'add'
199
- })) {
200
- const [, storyPath, parametersPath] = callPath.get('arguments');
201
- storyPath.replaceWith(t.arrowFunctionExpression([], t.blockStatement([])));
202
- removeAllExpressionPropsExcept(parametersPath, ['creevey']);
203
- } else if (propPath.isIdentifier({
204
- name: 'addDecorator'
205
- })) {
206
- callPath.replaceWith(childCallPath);
207
- } else if (propPath.isIdentifier({
208
- name: 'addParameters'
209
- })) {
210
- const [parametersPath] = callPath.get('arguments');
211
- removeAllExpressionPropsExcept(parametersPath, ['creevey']);
212
- }
213
- } while (callPath.parentPath != null);
214
- }
215
-
216
- function recursivelyRemoveUnreferencedBindings(path) {
217
- const getUnreferencedBindings = () => {
218
- path.scope.crawl();
219
- return Object.values(path.scope.bindings).filter(binding => !binding.referenced || binding.referencePaths.every(refPath => refPath.find(x => x.node == binding.path.node)));
220
- };
221
-
222
- let bindings = getUnreferencedBindings();
223
-
224
- do {
225
- bindings.forEach(binding => !binding.path.removed && binding.path.remove());
226
- } while ((bindings = getUnreferencedBindings()).length > 0);
227
- }
228
-
229
- function getUnvisitedRefs(paths, // eslint-disable-next-line @typescript-eslint/no-explicit-any
230
- state) {
231
- const rootPaths = [...new Set(paths.map(findRootPath).filter(_types2.isDefined))];
232
- const bindings = new Set();
233
- rootPaths.forEach(rootPath => {
234
- state.visitedTopPaths.add(rootPath);
235
- rootPath.traverse({
236
- Identifier(identifierPath) {
237
- const binding = identifierPath.scope.getBinding(identifierPath.node.name);
238
-
239
- if ((binding === null || binding === void 0 ? void 0 : binding.scope) == rootPath.scope && !state.visitedBindings.has(binding)) {
240
- bindings.add(binding);
241
- state.visitedBindings.add(binding);
242
- }
243
- }
244
-
245
- });
246
- });
247
- const refs = [].concat(...[...bindings].map(b => [b.path, ...b.referencePaths]));
248
- return [...new Set(refs)];
249
- }
250
-
251
- let FileType;
252
- exports.FileType = FileType;
253
-
254
- (function (FileType) {
255
- FileType[FileType["Invalid"] = -1] = "Invalid";
256
- FileType[FileType["Entry"] = 0] = "Entry";
257
- FileType[FileType["Preview"] = 1] = "Preview";
258
- FileType[FileType["Story"] = 2] = "Story";
259
- })(FileType || (exports.FileType = FileType = {}));
260
-
261
- const commonVisitor = {
262
- Program: {
263
- enter(path) {
264
- path.traverse({
265
- TSDeclareFunction(path) {
266
- path.remove();
267
- },
268
-
269
- TSTypeAliasDeclaration(path) {
270
- path.remove();
271
- },
272
-
273
- TSInterfaceDeclaration(path) {
274
- path.remove();
275
- },
276
-
277
- TSTypeAnnotation(path) {
278
- path.remove();
279
- },
280
-
281
- TSAsExpression(path) {
282
- path.replaceWith(path.get('expression'));
283
- }
284
-
285
- });
286
- },
287
-
288
- exit(path) {
289
- if (this.fileType != FileType.Story && this.fileType != FileType.Preview) return;
290
- recursivelyRemoveUnreferencedBindings(path);
291
- path.traverse({
292
- ImportDeclaration(path) {
293
- if (path.node.specifiers.length == 0) path.remove();
294
- }
295
-
296
- });
297
- let refs = [...this.visitedTopPaths];
298
-
299
- while (refs.length > 0) {
300
- refs = getUnvisitedRefs(refs, this);
301
- }
302
-
303
- path.get('body').filter(x => !this.visitedTopPaths.has(x)).forEach(x => x.remove());
304
- }
305
-
306
- }
307
- };
308
- exports.commonVisitor = commonVisitor;
309
- const previewVisitor = {
310
- ExportNamedDeclaration(namedPath) {
311
- this.visitedTopPaths.add(namedPath);
312
- const declarationPath = namedPath.get('declaration');
313
- if (!declarationPath.isVariableDeclaration()) return;
314
- declarationPath.get('declarations').forEach(declPath => {
315
- if (!declPath.isVariableDeclarator()) return;
316
- if (t.isIdentifier(declPath.node.id, {
317
- name: 'decorators'
318
- })) return declPath.remove();
319
-
320
- if (t.isIdentifier(declPath.node.id, {
321
- name: 'parameters'
322
- })) {
323
- removeAllExpressionPropsExcept(declPath.get('init'), ['creevey']);
324
- }
325
- });
326
- },
327
-
328
- CallExpression(rootCallPath) {
329
- const rootPath = findRootPath(rootCallPath);
330
- const calleePath = rootCallPath.get('callee');
331
- if (calleePath.isIdentifier({
332
- name: 'configure'
333
- }) && rootPath) this.visitedTopPaths.add(rootPath);else if (calleePath.isIdentifier({
334
- name: 'addDecorator'
335
- })) rootCallPath.remove();else if (calleePath.isIdentifier({
336
- name: 'addParameters'
337
- })) {
338
- const [argPath] = rootCallPath.get('arguments');
339
- if (!argPath || !argPath.isObjectExpression()) return;
340
- if (rootPath) this.visitedTopPaths.add(rootPath);
341
- removeAllPropsExcept(argPath, ['creevey']);
342
- }
343
- }
344
-
345
- };
346
- exports.previewVisitor = previewVisitor;
347
- const mdxVisitor = {
348
- FunctionDeclaration(functionPath) {
349
- var _functionPath$get$nod, _rootPath$scope$getBi, _rootPath$scope$getBi2;
350
-
351
- const functionName = (_functionPath$get$nod = functionPath.get('id').node) === null || _functionPath$get$nod === void 0 ? void 0 : _functionPath$get$nod.name;
352
- if (functionName != 'MDXContent') return;
353
- const rootPath = findRootPath(functionPath);
354
- 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 : [];
355
- refs.forEach(refPath => {
356
- var _findRootPath;
357
-
358
- return (_findRootPath = findRootPath(refPath)) === null || _findRootPath === void 0 ? void 0 : _findRootPath.remove();
359
- });
360
- rootPath === null || rootPath === void 0 ? void 0 : rootPath.remove();
361
- }
362
-
363
- };
364
- exports.mdxVisitor = mdxVisitor;
365
- const kindProps = ['title', 'id', ['parameters', 'creevey'], 'includeStories', 'excludeStories'];
366
- const storyProps = ['storyName', ['story', 'name', ['parameters', 'creevey', 'docsOnly']], ['parameters', 'creevey', 'docsOnly']];
367
- const exportsProps = [['default', ...kindProps], [name => name != 'default', ...storyProps]];
368
- const storyVisitor = {
369
- ExportDefaultDeclaration(defaultPath) {
370
- const defaultDeclaration = defaultPath.get('declaration');
371
- const declaratorPath = getDeclaratorPath(defaultDeclaration);
372
- const kindPath = declaratorPath !== null && declaratorPath !== void 0 && declaratorPath.isVariableDeclarator() ? getKindObjectNodePath(declaratorPath.get('init')) : getKindObjectNodePath(defaultDeclaration);
373
- if (!kindPath) return;
374
- this.visitedTopPaths.add(defaultPath);
375
- removeAllPropsExcept(kindPath, kindProps);
376
- if (declaratorPath && !declaratorPath.isImportSpecifier()) removeAllPropAssignsExcept(getPropertyAssignmentPaths(getIdentifiers([declaratorPath])).entries(), kindProps);
377
- },
378
-
379
- ExportAllDeclaration(allPath) {
380
- var _this$reexportedStori;
381
-
382
- const request = allPath.get('source').node.value;
383
- this.reexportedStories.set(this.resourcePath, ((_this$reexportedStori = this.reexportedStories.get(this.resourcePath)) !== null && _this$reexportedStori !== void 0 ? _this$reexportedStori : new Set()).add(request));
384
- this.visitedTopPaths.add(allPath);
385
- },
386
-
387
- ExportNamedDeclaration(namedPath) {
388
- this.visitedTopPaths.add(namedPath);
389
- const declarationPath = namedPath.get('declaration');
390
- let storyFnPropAssigns = new Map();
391
-
392
- if (declarationPath.isVariableDeclaration()) {
393
- const declarations = declarationPath.get('declarations');
394
- declarations.map(x => x.get('init')).forEach(initPath => removeAllExpressionPropsExcept(initPath, storyProps));
395
- storyFnPropAssigns = getPropertyAssignmentPaths(getIdentifiers(declarations));
396
- } else if (declarationPath.isFunctionDeclaration()) {
397
- replaceStoryFnToNoop(declarationPath);
398
- storyFnPropAssigns = getPropertyAssignmentPaths(getIdentifiers([declarationPath]));
399
- }
400
-
401
- removeAllPropAssignsExcept(storyFnPropAssigns.entries(), storyProps);
402
- },
403
-
404
- CallExpression(rootCallPath) {
405
- const rootPath = findRootPath(rootCallPath);
406
- if (!rootCallPath.get('callee').isIdentifier({
407
- name: 'storiesOf'
408
- })) return;
409
- if (rootPath) this.visitedTopPaths.add(rootPath);
410
-
411
- if (rootPath !== null && rootPath !== void 0 && rootPath.isVariableDeclaration()) {
412
- var _rootPath$get$find;
413
-
414
- 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');
415
-
416
- if (storiesIdPath !== null && storiesIdPath !== void 0 && storiesIdPath.isIdentifier()) {
417
- var _storiesIdPath$scope$, _storiesIdPath$scope$2;
418
-
419
- ((_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);
420
- }
421
- }
422
-
423
- cleanUpStoriesOfCallChain(rootCallPath);
424
- },
425
-
426
- Identifier(identifierPath) {
427
- if (isExports(identifierPath)) {
428
- var _getAssignmentPathWit2;
429
-
430
- const rootPath = findRootPath(identifierPath);
431
- if (rootPath) this.visitedTopPaths.add(rootPath);
432
- const [assignmentPath, props] = (_getAssignmentPathWit2 = getAssignmentPathWithProps(identifierPath)) !== null && _getAssignmentPathWit2 !== void 0 ? _getAssignmentPathWit2 : [];
433
-
434
- if (assignmentPath && props) {
435
- if (props.length == 1 && props[0] != '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(), exportsProps);
448
- }
449
- }
450
-
451
- if (isModuleExports(identifierPath)) {
452
- var _getAssignmentPathWit3;
453
-
454
- const rootPath = findRootPath(identifierPath);
455
- if (rootPath) this.visitedTopPaths.add(rootPath);
456
- const [assignmentPath, props] = (_getAssignmentPathWit3 = getAssignmentPathWithProps(identifierPath)) !== null && _getAssignmentPathWit3 !== void 0 ? _getAssignmentPathWit3 : [];
457
-
458
- if (assignmentPath && props) {
459
- if (props.length == 1 && props[0] == 'exports') {
460
- removeAllExpressionPropsExcept(assignmentPath.get('right'), exportsProps);
461
- } else if (props.length == 2 && props[0] == 'exports' && props[1] != 'default') {
462
- const declaratorPath = getDeclaratorPath(assignmentPath.get('right'));
463
-
464
- if (declaratorPath && !declaratorPath.isImportSpecifier()) {
465
- removeAllPropAssignsExcept(getPropertyAssignmentPaths(getIdentifiers([declaratorPath])).entries(), storyProps);
466
- } else {
467
- const rightPath = assignmentPath.get('right');
468
-
469
- if (isObjectAssign(rightPath)) {
470
- rightPath.get('arguments').forEach(argumentPath => removeAllExpressionPropsExcept(argumentPath, storyProps));
471
- } else rightPath.replaceWith(t.arrowFunctionExpression([], t.blockStatement([])));
472
- }
473
- } else removeAllPropAssignsExcept(new Map([[assignmentPath, props]]).entries(), [['exports', ...exportsProps]]);
474
- }
475
- }
476
- }
477
-
478
- };
479
- exports.storyVisitor = storyVisitor;
@@ -1,126 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = register;
7
-
8
- var _module = _interopRequireDefault(require("module"));
9
-
10
- var _fs = _interopRequireDefault(require("fs"));
11
-
12
- var _path = require("path");
13
-
14
- var _pirates = require("pirates");
15
-
16
- var _types = require("../../../types");
17
-
18
- var _utils = require("../../utils");
19
-
20
- var _creeveyPlugin = _interopRequireDefault(require("./creevey-plugin"));
21
-
22
- var _helpers = require("../../storybook/helpers");
23
-
24
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
25
-
26
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
27
-
28
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
29
-
30
- let parents = null;
31
- let story = null; //@ts-expect-error private field doesn't have types
32
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-assignment
33
-
34
- const jsLoader = _module.default._extensions['.js']; //@ts-expect-error private field doesn't have types
35
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
36
-
37
- _module.default._extensions['.js'] = function (mod, filename) {
38
- parents = Object.values(require.cache).filter(m => m === null || m === void 0 ? void 0 : m.children.includes(mod)).filter(_types.isDefined).map(m => m.filename); // eslint-disable-next-line @typescript-eslint/no-unsafe-call
39
-
40
- jsLoader(mod, filename);
41
- parents = null;
42
- };
43
-
44
- (0, _pirates.addHook)(() => '', {
45
- exts: ['.jpg', '.jpeg', '.png', '.gif', '.eot', '.otf', '.svg', '.ttf', '.woff', '.woff2', '.css', '.less', '.scss', '.styl'],
46
- ignoreNodeModules: false
47
- });
48
-
49
- function getRequireContext(rootDir) {
50
- return function requireContext(rootPath, deep, filter) {
51
- const ids = [];
52
- let contextPath; // Relative path
53
-
54
- if (rootPath.startsWith('.')) contextPath = (0, _path.resolve)(rootDir, rootPath); // Module path
55
- else if (!(0, _path.isAbsolute)(rootPath)) contextPath = require.resolve(rootPath); // Absolute path
56
- else contextPath = rootPath;
57
-
58
- const traverse = dirPath => {
59
- _fs.default.readdirSync(dirPath, {
60
- withFileTypes: true
61
- }).forEach(dirent => {
62
- var _filter$test;
63
-
64
- const filename = dirent.name;
65
- const filePath = (0, _path.join)(dirPath, filename);
66
- if (dirent.isDirectory() && deep) return traverse(filePath);
67
- if (dirent.isFile() && ((_filter$test = filter === null || filter === void 0 ? void 0 : filter.test(`./${(0, _path.relative)(contextPath, filePath)}`)) !== null && _filter$test !== void 0 ? _filter$test : true)) return ids.push(filePath);
68
- });
69
- };
70
-
71
- traverse(contextPath);
72
-
73
- const context = id => {
74
- story = id; // eslint-disable-next-line @typescript-eslint/no-var-requires
75
-
76
- const storyModule = require(id);
77
-
78
- story = null;
79
- return storyModule;
80
- };
81
-
82
- context.id = contextPath;
83
-
84
- context.keys = () => ids;
85
-
86
- context.resolve = id => id;
87
-
88
- return context;
89
- };
90
- }
91
-
92
- async function register(config, debug = false) {
93
- const rootDir = (0, _helpers.isStorybookVersionLessThan)(6, 4) ? config.storybookDir : process.cwd();
94
- const requireContext = getRequireContext(rootDir);
95
- const preview = (0, _path.resolve)(config.storybookDir, 'preview');
96
- if ((0, _helpers.hasDocsAddon)()) await (await Promise.resolve().then(() => _interopRequireWildcard(require('../hooks/mdx')))).addMDXHook(() => story);
97
- if ((0, _helpers.hasSvelteCSFAddon)()) await (await Promise.resolve().then(() => _interopRequireWildcard(require('../hooks/svelte')))).addSvelteHook(() => story); // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
98
-
99
- (await Promise.resolve().then(() => _interopRequireWildcard(require('@babel/register')))).default(config.babelOptions({
100
- babelrc: false,
101
- rootMode: 'upward-optional',
102
- ignore: [/node_modules/],
103
- extensions: [..._utils.extensions, ...((0, _helpers.hasDocsAddon)() ? ['.mdx'] : []), ...((0, _helpers.hasSvelteCSFAddon)() ? ['.svelte'] : [])],
104
- parserOpts: {
105
- sourceType: 'module',
106
- plugins: ['classProperties', 'decorators-legacy', 'jsx', 'typescript']
107
- },
108
- plugins: [[_creeveyPlugin.default, {
109
- debug,
110
- preview,
111
- parents: () => parents,
112
- story: () => story
113
- }], ['@babel/plugin-transform-runtime', {
114
- // eslint-disable-next-line @typescript-eslint/no-var-requires
115
- version: require('@babel/helpers/package.json').version,
116
- absoluteRuntime: true,
117
- corejs: 3
118
- }]],
119
- presets: [['@babel/preset-env', {
120
- targets: {
121
- node: '10'
122
- }
123
- }]]
124
- }));
125
- return requireContext;
126
- }
@@ -1,30 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.addMDXHook = void 0;
7
-
8
- var _pirates = require("pirates");
9
-
10
- var _helpers = require("../../storybook/helpers");
11
-
12
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
13
-
14
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
15
-
16
- const addMDXHook = async getStory => {
17
- const mdx = (await Promise.resolve(`${(0, _helpers.resolveFromStorybookAddonDocs)('@mdx-js/mdx')}`).then(s => _interopRequireWildcard(require(s)))).default;
18
- const {
19
- mdxOptions
20
- } = await Promise.resolve().then(() => _interopRequireWildcard(require('../webpack/mdx-loader')));
21
- (0, _pirates.addHook)((code, filename) => {
22
- const story = getStory();
23
- if (!story || !filename.startsWith(story)) return code;
24
- return mdx.sync(code, mdxOptions());
25
- }, {
26
- exts: ['.mdx']
27
- });
28
- };
29
-
30
- exports.addMDXHook = addMDXHook;