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,34 +0,0 @@
1
- import { denormalizeStoryParameters } from '../shared';
2
- import { subscribeOn } from './messages';
3
- import { loadTestsFromStories, saveStoriesJson, saveTestsJson } from './stories';
4
- import { isStorybookVersionGreaterThan, isStorybookVersionLessThan } from './storybook/helpers';
5
- import { extractStoriesData } from './storybook/providers/nodejs';
6
- export default async function extract(config, options) {
7
- if (config.useWebpackToExtractTests && process.env.__CREEVEY_ENV__ != 'test') {
8
- await new Promise((resolve, reject) => {
9
- subscribeOn('webpack', message => {
10
- switch (message.type) {
11
- case 'success':
12
- return resolve();
13
-
14
- case 'fail':
15
- return reject();
16
- }
17
- });
18
- void (async () => (await import('./loaders/webpack/compile')).default(config, options))();
19
- });
20
- }
21
-
22
- const tests = await loadTestsFromStories(Object.keys(config.browsers), async () => {
23
- const data = await extractStoriesData(config, {
24
- watch: false,
25
- debug: options.debug
26
- });
27
- const stories = isStorybookVersionLessThan(6) || isStorybookVersionGreaterThan(6, 3) ? data.stories : denormalizeStoryParameters(data);
28
- if (options.extract) saveStoriesJson(data, options.extract);
29
- return stories;
30
- });
31
- if (options.tests) saveTestsJson(tests); // eslint-disable-next-line no-process-exit
32
-
33
- process.exit(0);
34
- }
@@ -1,64 +0,0 @@
1
- import cluster from 'cluster';
2
- import { readConfig, defaultBrowser } from './config';
3
- import { logger } from './logger'; // NOTE: Impure function, mutate config by adding gridUrl prop
4
-
5
- async function startWebdriverServer(config, options) {
6
- if (config.useDocker) {
7
- return (await import('./docker')).default(config, options.browser, async () => (await import('./selenium/selenoid')).startSelenoidContainer(config, options.debug));
8
- } else {
9
- return (await import('./selenium/selenoid')).startSelenoidStandalone(config, options.debug);
10
- }
11
- }
12
-
13
- export default async function (options) {
14
- const config = await readConfig(options);
15
- const {
16
- browser = defaultBrowser,
17
- extract,
18
- tests,
19
- update,
20
- webpack,
21
- ui,
22
- port
23
- } = options;
24
- if (!config) return; // NOTE: We don't need docker nor selenoid for webpack or update options
25
-
26
- if (!(config.gridUrl || Object.values(config.browsers).every(({
27
- gridUrl
28
- }) => gridUrl)) && !extract && !webpack && !tests && !update) {
29
- await startWebdriverServer(config, options);
30
- }
31
-
32
- switch (true) {
33
- case Boolean(extract) || tests:
34
- {
35
- return (await import('./extract')).default(config, options);
36
- }
37
-
38
- case Boolean(update):
39
- {
40
- return (await import('./update')).default(config, typeof update == 'string' ? update : undefined);
41
- }
42
-
43
- case webpack:
44
- {
45
- logger.info('Starting Webpack Compiler');
46
- return (await import('./loaders/webpack/compile')).default(config, options);
47
- }
48
-
49
- case cluster.isMaster:
50
- {
51
- logger.info('Starting Master Process');
52
- const resolveApi = (await import('./master/server')).default(config.reportDir, port, ui);
53
- return (await import('./master')).default(config, options, resolveApi);
54
- }
55
-
56
- default:
57
- {
58
- logger.info(`Starting Worker for ${browser}`);
59
- return (await import('./worker')).default(config, { ...options,
60
- browser
61
- });
62
- }
63
- }
64
- }
@@ -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
- };