@storybook/telemetry 6.5.0-beta.2
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.
- package/LICENSE +21 -0
- package/README.md +5 -0
- package/dist/cjs/anonymous-id.js +49 -0
- package/dist/cjs/get-monorepo-type.js +55 -0
- package/dist/cjs/index.js +130 -0
- package/dist/cjs/notify.js +72 -0
- package/dist/cjs/one-way-hash.js +21 -0
- package/dist/cjs/package-versions.js +95 -0
- package/dist/cjs/sanitize.js +57 -0
- package/dist/cjs/storybook-metadata.js +346 -0
- package/dist/cjs/telemetry.js +150 -0
- package/dist/cjs/types.js +5 -0
- package/dist/esm/anonymous-id.js +29 -0
- package/dist/esm/get-monorepo-type.js +34 -0
- package/dist/esm/index.js +94 -0
- package/dist/esm/notify.js +54 -0
- package/dist/esm/one-way-hash.js +11 -0
- package/dist/esm/package-versions.js +72 -0
- package/dist/esm/sanitize.js +42 -0
- package/dist/esm/storybook-metadata.js +304 -0
- package/dist/esm/telemetry.js +127 -0
- package/dist/esm/types.js +1 -0
- package/dist/modern/anonymous-id.js +27 -0
- package/dist/modern/get-monorepo-type.js +30 -0
- package/dist/modern/index.js +39 -0
- package/dist/modern/notify.js +22 -0
- package/dist/modern/one-way-hash.js +11 -0
- package/dist/modern/package-versions.js +21 -0
- package/dist/modern/sanitize.js +32 -0
- package/dist/modern/storybook-metadata.js +188 -0
- package/dist/modern/telemetry.js +66 -0
- package/dist/modern/types.js +1 -0
- package/dist/ts3.4/anonymous-id.d.ts +1 -0
- package/dist/ts3.4/get-monorepo-type.d.ts +9 -0
- package/dist/ts3.4/index.d.ts +3 -0
- package/dist/ts3.4/notify.d.ts +1 -0
- package/dist/ts3.4/one-way-hash.d.ts +2 -0
- package/dist/ts3.4/package-versions.d.ts +9 -0
- package/dist/ts3.4/sanitize.d.ts +8 -0
- package/dist/ts3.4/storybook-metadata.d.ts +8 -0
- package/dist/ts3.4/telemetry.d.ts +2 -0
- package/dist/ts3.4/types.d.ts +56 -0
- package/dist/ts3.9/anonymous-id.d.ts +1 -0
- package/dist/ts3.9/get-monorepo-type.d.ts +9 -0
- package/dist/ts3.9/index.d.ts +3 -0
- package/dist/ts3.9/notify.d.ts +1 -0
- package/dist/ts3.9/one-way-hash.d.ts +2 -0
- package/dist/ts3.9/package-versions.d.ts +9 -0
- package/dist/ts3.9/sanitize.d.ts +8 -0
- package/dist/ts3.9/storybook-metadata.d.ts +8 -0
- package/dist/ts3.9/telemetry.d.ts +2 -0
- package/dist/ts3.9/types.d.ts +56 -0
- package/package.json +61 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import "regenerator-runtime/runtime.js";
|
|
2
|
+
import "core-js/modules/es.string.bold.js";
|
|
3
|
+
import "core-js/modules/es.object.to-string.js";
|
|
4
|
+
import "core-js/modules/es.promise.js";
|
|
5
|
+
|
|
6
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
7
|
+
|
|
8
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
9
|
+
|
|
10
|
+
import chalk from 'chalk';
|
|
11
|
+
import { cache } from '@storybook/core-common';
|
|
12
|
+
var TELEMETRY_KEY_NOTIFY_DATE = 'telemetry-notification-date';
|
|
13
|
+
var logger = console;
|
|
14
|
+
export var notify = /*#__PURE__*/function () {
|
|
15
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
|
|
16
|
+
var telemetryNotifyDate;
|
|
17
|
+
return regeneratorRuntime.wrap(function _callee$(_context) {
|
|
18
|
+
while (1) {
|
|
19
|
+
switch (_context.prev = _context.next) {
|
|
20
|
+
case 0:
|
|
21
|
+
_context.next = 2;
|
|
22
|
+
return cache.get(TELEMETRY_KEY_NOTIFY_DATE, null);
|
|
23
|
+
|
|
24
|
+
case 2:
|
|
25
|
+
telemetryNotifyDate = _context.sent;
|
|
26
|
+
|
|
27
|
+
if (!telemetryNotifyDate) {
|
|
28
|
+
_context.next = 5;
|
|
29
|
+
break;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return _context.abrupt("return");
|
|
33
|
+
|
|
34
|
+
case 5:
|
|
35
|
+
cache.set(TELEMETRY_KEY_NOTIFY_DATE, Date.now());
|
|
36
|
+
logger.log();
|
|
37
|
+
logger.log("".concat(chalk.magenta.bold('attention'), " => Storybook now collects completely anonymous telemetry regarding usage."));
|
|
38
|
+
logger.log("This information is used to shape Storybook's roadmap and prioritize features.");
|
|
39
|
+
logger.log("You can learn more, including how to opt-out if you'd not like to participate in this anonymous program, by visiting the following URL:");
|
|
40
|
+
logger.log(chalk.cyan('https://storybook.js.org/telemetry'));
|
|
41
|
+
logger.log();
|
|
42
|
+
|
|
43
|
+
case 12:
|
|
44
|
+
case "end":
|
|
45
|
+
return _context.stop();
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}, _callee);
|
|
49
|
+
}));
|
|
50
|
+
|
|
51
|
+
return function notify() {
|
|
52
|
+
return _ref.apply(this, arguments);
|
|
53
|
+
};
|
|
54
|
+
}();
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createHash } from 'crypto';
|
|
2
|
+
export var oneWayHash = function oneWayHash(payload) {
|
|
3
|
+
var hash = createHash('sha256'); // Always prepend the payload value with salt. This ensures the hash is truly
|
|
4
|
+
// one-way.
|
|
5
|
+
|
|
6
|
+
hash.update('storybook-telemetry-salt'); // Update is an append operation, not a replacement. The salt from the prior
|
|
7
|
+
// update is still present!
|
|
8
|
+
|
|
9
|
+
hash.update(payload);
|
|
10
|
+
return hash.digest('hex');
|
|
11
|
+
};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import "regenerator-runtime/runtime.js";
|
|
2
|
+
import "core-js/modules/es.object.keys.js";
|
|
3
|
+
import "core-js/modules/es.array.iterator.js";
|
|
4
|
+
import "core-js/modules/es.object.to-string.js";
|
|
5
|
+
import "core-js/modules/es.promise.js";
|
|
6
|
+
import "core-js/modules/es.string.iterator.js";
|
|
7
|
+
import "core-js/modules/web.dom-collections.iterator.js";
|
|
8
|
+
import "core-js/modules/es.array.map.js";
|
|
9
|
+
import "core-js/modules/es.array.join.js";
|
|
10
|
+
|
|
11
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
12
|
+
|
|
13
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
14
|
+
|
|
15
|
+
import path from 'path';
|
|
16
|
+
export var getActualPackageVersions = /*#__PURE__*/function () {
|
|
17
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(packages) {
|
|
18
|
+
var packageNames;
|
|
19
|
+
return regeneratorRuntime.wrap(function _callee$(_context) {
|
|
20
|
+
while (1) {
|
|
21
|
+
switch (_context.prev = _context.next) {
|
|
22
|
+
case 0:
|
|
23
|
+
packageNames = Object.keys(packages);
|
|
24
|
+
return _context.abrupt("return", Promise.all(packageNames.map(getActualPackageVersion)));
|
|
25
|
+
|
|
26
|
+
case 2:
|
|
27
|
+
case "end":
|
|
28
|
+
return _context.stop();
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}, _callee);
|
|
32
|
+
}));
|
|
33
|
+
|
|
34
|
+
return function getActualPackageVersions(_x) {
|
|
35
|
+
return _ref.apply(this, arguments);
|
|
36
|
+
};
|
|
37
|
+
}();
|
|
38
|
+
export var getActualPackageVersion = /*#__PURE__*/function () {
|
|
39
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(packageName) {
|
|
40
|
+
var packageJson;
|
|
41
|
+
return regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
42
|
+
while (1) {
|
|
43
|
+
switch (_context2.prev = _context2.next) {
|
|
44
|
+
case 0:
|
|
45
|
+
_context2.prev = 0;
|
|
46
|
+
// eslint-disable-next-line import/no-dynamic-require,global-require
|
|
47
|
+
packageJson = require(path.join(packageName, 'package.json'));
|
|
48
|
+
return _context2.abrupt("return", {
|
|
49
|
+
name: packageName,
|
|
50
|
+
version: packageJson.version
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
case 5:
|
|
54
|
+
_context2.prev = 5;
|
|
55
|
+
_context2.t0 = _context2["catch"](0);
|
|
56
|
+
return _context2.abrupt("return", {
|
|
57
|
+
name: packageName,
|
|
58
|
+
version: null
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
case 8:
|
|
62
|
+
case "end":
|
|
63
|
+
return _context2.stop();
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}, _callee2, null, [[0, 5]]);
|
|
67
|
+
}));
|
|
68
|
+
|
|
69
|
+
return function getActualPackageVersion(_x2) {
|
|
70
|
+
return _ref2.apply(this, arguments);
|
|
71
|
+
};
|
|
72
|
+
}();
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import "core-js/modules/es.regexp.exec.js";
|
|
2
|
+
import "core-js/modules/es.string.replace.js";
|
|
3
|
+
import "core-js/modules/es.string.split.js";
|
|
4
|
+
import "core-js/modules/es.array.join.js";
|
|
5
|
+
import "core-js/modules/es.regexp.constructor.js";
|
|
6
|
+
import "core-js/modules/es.regexp.to-string.js";
|
|
7
|
+
import "core-js/modules/es.object.get-own-property-names.js";
|
|
8
|
+
|
|
9
|
+
/* eslint-disable no-param-reassign */
|
|
10
|
+
import { sep } from 'path';
|
|
11
|
+
|
|
12
|
+
// Removes all user paths
|
|
13
|
+
function regexpEscape(str) {
|
|
14
|
+
return str.replace(/[-[/{}()*+?.\\^$|]/g, "\\$&");
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function cleanPaths(str) {
|
|
18
|
+
var separator = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : sep;
|
|
19
|
+
if (!str) return str;
|
|
20
|
+
var stack = process.cwd().split(separator);
|
|
21
|
+
|
|
22
|
+
while (stack.length > 1) {
|
|
23
|
+
var currentPath = stack.join(separator);
|
|
24
|
+
var currentRegex = new RegExp(regexpEscape(currentPath), "g");
|
|
25
|
+
str = str.replace(currentRegex, "$SNIP");
|
|
26
|
+
var currentPath2 = stack.join(separator + separator);
|
|
27
|
+
var currentRegex2 = new RegExp(regexpEscape(currentPath2), "g");
|
|
28
|
+
str = str.replace(currentRegex2, "$SNIP");
|
|
29
|
+
stack.pop();
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return str;
|
|
33
|
+
} // Takes an Error and returns a sanitized JSON String
|
|
34
|
+
|
|
35
|
+
export function sanitizeError(error) {
|
|
36
|
+
var pathSeparator = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : sep;
|
|
37
|
+
// Hack because Node
|
|
38
|
+
error = JSON.parse(JSON.stringify(error, Object.getOwnPropertyNames(error))); // Removes all user paths
|
|
39
|
+
|
|
40
|
+
var errorString = cleanPaths(JSON.stringify(error), pathSeparator);
|
|
41
|
+
return JSON.parse(errorString);
|
|
42
|
+
}
|
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
2
|
+
|
|
3
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
4
|
+
|
|
5
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
6
|
+
|
|
7
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
8
|
+
|
|
9
|
+
import "core-js/modules/es.array.map.js";
|
|
10
|
+
import "core-js/modules/es.object.assign.js";
|
|
11
|
+
import "core-js/modules/es.array.find.js";
|
|
12
|
+
import "core-js/modules/es.object.to-string.js";
|
|
13
|
+
import "core-js/modules/es.object.keys.js";
|
|
14
|
+
import "core-js/modules/es.function.name.js";
|
|
15
|
+
import "core-js/modules/web.dom-collections.for-each.js";
|
|
16
|
+
import "core-js/modules/es.regexp.exec.js";
|
|
17
|
+
import "core-js/modules/es.string.replace.js";
|
|
18
|
+
import "core-js/modules/es.array.filter.js";
|
|
19
|
+
import "core-js/modules/es.array.includes.js";
|
|
20
|
+
import "core-js/modules/es.string.includes.js";
|
|
21
|
+
import "core-js/modules/es.promise.js";
|
|
22
|
+
import "core-js/modules/es.array.slice.js";
|
|
23
|
+
import "core-js/modules/es.array.from.js";
|
|
24
|
+
import "core-js/modules/es.string.iterator.js";
|
|
25
|
+
import "core-js/modules/es.symbol.js";
|
|
26
|
+
import "core-js/modules/es.symbol.description.js";
|
|
27
|
+
import "core-js/modules/es.symbol.iterator.js";
|
|
28
|
+
import "core-js/modules/es.array.iterator.js";
|
|
29
|
+
import "core-js/modules/web.dom-collections.iterator.js";
|
|
30
|
+
import "regenerator-runtime/runtime.js";
|
|
31
|
+
|
|
32
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
33
|
+
|
|
34
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
35
|
+
|
|
36
|
+
import readPkgUp from 'read-pkg-up';
|
|
37
|
+
import { detect, getNpmVersion } from 'detect-package-manager';
|
|
38
|
+
import { loadMainConfig, getStorybookInfo, getStorybookConfiguration, getProjectRoot } from '@storybook/core-common';
|
|
39
|
+
import { getActualPackageVersion, getActualPackageVersions } from './package-versions';
|
|
40
|
+
import { getMonorepoType } from './get-monorepo-type';
|
|
41
|
+
var cachedMetadata;
|
|
42
|
+
export var getStorybookMetadata = /*#__PURE__*/function () {
|
|
43
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(_configDir) {
|
|
44
|
+
var _ref2;
|
|
45
|
+
|
|
46
|
+
var packageJson, configDir, mainConfig;
|
|
47
|
+
return regeneratorRuntime.wrap(function _callee$(_context) {
|
|
48
|
+
while (1) {
|
|
49
|
+
switch (_context.prev = _context.next) {
|
|
50
|
+
case 0:
|
|
51
|
+
if (!cachedMetadata) {
|
|
52
|
+
_context.next = 2;
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return _context.abrupt("return", cachedMetadata);
|
|
57
|
+
|
|
58
|
+
case 2:
|
|
59
|
+
packageJson = readPkgUp.sync({
|
|
60
|
+
cwd: process.cwd()
|
|
61
|
+
}).packageJson;
|
|
62
|
+
configDir = (_ref2 = _configDir || getStorybookConfiguration(packageJson.scripts.storybook, '-c', '--config-dir')) !== null && _ref2 !== void 0 ? _ref2 : '.storybook';
|
|
63
|
+
mainConfig = loadMainConfig({
|
|
64
|
+
configDir: configDir
|
|
65
|
+
});
|
|
66
|
+
_context.next = 7;
|
|
67
|
+
return computeStorybookMetadata({
|
|
68
|
+
mainConfig: mainConfig,
|
|
69
|
+
packageJson: packageJson
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
case 7:
|
|
73
|
+
cachedMetadata = _context.sent;
|
|
74
|
+
return _context.abrupt("return", cachedMetadata);
|
|
75
|
+
|
|
76
|
+
case 9:
|
|
77
|
+
case "end":
|
|
78
|
+
return _context.stop();
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}, _callee);
|
|
82
|
+
}));
|
|
83
|
+
|
|
84
|
+
return function getStorybookMetadata(_x) {
|
|
85
|
+
return _ref.apply(this, arguments);
|
|
86
|
+
};
|
|
87
|
+
}();
|
|
88
|
+
export var metaFrameworks = {
|
|
89
|
+
next: 'Next',
|
|
90
|
+
'react-scripts': 'CRA',
|
|
91
|
+
gatsby: 'Gatsby',
|
|
92
|
+
'@nuxtjs/storybook': 'nuxt',
|
|
93
|
+
'@nrwl/storybook': 'nx',
|
|
94
|
+
'@vue/cli-service': 'vue-cli',
|
|
95
|
+
'@sveltejs/kit': 'svelte-kit'
|
|
96
|
+
}; // @TODO: This should be removed in 7.0 as the framework.options field in main.js will replace this
|
|
97
|
+
|
|
98
|
+
var getFrameworkOptions = function getFrameworkOptions(mainConfig) {
|
|
99
|
+
var possibleOptions = ['angular', 'ember', 'html', 'preact', 'react', 'server', 'svelte', 'vue', 'vue3', 'webComponents'].map(function (opt) {
|
|
100
|
+
return "".concat(opt, "Options");
|
|
101
|
+
}); // eslint-disable-next-line no-restricted-syntax
|
|
102
|
+
|
|
103
|
+
var _iterator = _createForOfIteratorHelper(possibleOptions),
|
|
104
|
+
_step;
|
|
105
|
+
|
|
106
|
+
try {
|
|
107
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
108
|
+
var opt = _step.value;
|
|
109
|
+
|
|
110
|
+
if (opt in mainConfig) {
|
|
111
|
+
return mainConfig[opt];
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
} catch (err) {
|
|
115
|
+
_iterator.e(err);
|
|
116
|
+
} finally {
|
|
117
|
+
_iterator.f();
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return undefined;
|
|
121
|
+
}; // Analyze a combination of information from main.js and package.json
|
|
122
|
+
// to provide telemetry over a Storybook project
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
export var computeStorybookMetadata = /*#__PURE__*/function () {
|
|
126
|
+
var _ref4 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(_ref3) {
|
|
127
|
+
var _mainConfig$core;
|
|
128
|
+
|
|
129
|
+
var packageJson, mainConfig, metadata, allDependencies, metaFramework, _yield$getActualPacka, version, monorepoType, packageManagerType, packageManagerVerson, _builder$options, builder, addons, addonVersions, addonNames, storybookPackages, storybookPackageVersions, language, hasStorybookEslint, storybookInfo;
|
|
130
|
+
|
|
131
|
+
return regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
132
|
+
while (1) {
|
|
133
|
+
switch (_context2.prev = _context2.next) {
|
|
134
|
+
case 0:
|
|
135
|
+
packageJson = _ref3.packageJson, mainConfig = _ref3.mainConfig;
|
|
136
|
+
metadata = {
|
|
137
|
+
generatedAt: new Date().getTime(),
|
|
138
|
+
builder: {
|
|
139
|
+
name: 'webpack4'
|
|
140
|
+
},
|
|
141
|
+
hasCustomBabel: false,
|
|
142
|
+
hasCustomWebpack: false,
|
|
143
|
+
hasStaticDirs: false,
|
|
144
|
+
hasStorybookEslint: false,
|
|
145
|
+
refCount: 0
|
|
146
|
+
};
|
|
147
|
+
allDependencies = Object.assign({}, packageJson === null || packageJson === void 0 ? void 0 : packageJson.dependencies, packageJson === null || packageJson === void 0 ? void 0 : packageJson.devDependencies, packageJson === null || packageJson === void 0 ? void 0 : packageJson.peerDependencies);
|
|
148
|
+
metaFramework = Object.keys(allDependencies).find(function (dep) {
|
|
149
|
+
return !!metaFrameworks[dep];
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
if (!metaFramework) {
|
|
153
|
+
_context2.next = 10;
|
|
154
|
+
break;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
_context2.next = 7;
|
|
158
|
+
return getActualPackageVersion(metaFramework);
|
|
159
|
+
|
|
160
|
+
case 7:
|
|
161
|
+
_yield$getActualPacka = _context2.sent;
|
|
162
|
+
version = _yield$getActualPacka.version;
|
|
163
|
+
metadata.metaFramework = {
|
|
164
|
+
name: metaFrameworks[metaFramework],
|
|
165
|
+
packageName: metaFramework,
|
|
166
|
+
version: version
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
case 10:
|
|
170
|
+
monorepoType = getMonorepoType();
|
|
171
|
+
|
|
172
|
+
if (monorepoType) {
|
|
173
|
+
metadata.monorepo = monorepoType;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
_context2.prev = 12;
|
|
177
|
+
_context2.next = 15;
|
|
178
|
+
return detect({
|
|
179
|
+
cwd: getProjectRoot()
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
case 15:
|
|
183
|
+
packageManagerType = _context2.sent;
|
|
184
|
+
_context2.next = 18;
|
|
185
|
+
return getNpmVersion(packageManagerType);
|
|
186
|
+
|
|
187
|
+
case 18:
|
|
188
|
+
packageManagerVerson = _context2.sent;
|
|
189
|
+
metadata.packageManager = {
|
|
190
|
+
type: packageManagerType,
|
|
191
|
+
version: packageManagerVerson
|
|
192
|
+
}; // Better be safe than sorry, some codebases/paths might end up breaking with something like "spawn pnpm ENOENT"
|
|
193
|
+
// so we just set the package manager if the detection is successful
|
|
194
|
+
// eslint-disable-next-line no-empty
|
|
195
|
+
|
|
196
|
+
_context2.next = 24;
|
|
197
|
+
break;
|
|
198
|
+
|
|
199
|
+
case 22:
|
|
200
|
+
_context2.prev = 22;
|
|
201
|
+
_context2.t0 = _context2["catch"](12);
|
|
202
|
+
|
|
203
|
+
case 24:
|
|
204
|
+
metadata.hasCustomBabel = !!mainConfig.babel;
|
|
205
|
+
metadata.hasCustomWebpack = !!mainConfig.webpackFinal;
|
|
206
|
+
metadata.hasStaticDirs = !!mainConfig.staticDirs;
|
|
207
|
+
|
|
208
|
+
if (mainConfig.typescript) {
|
|
209
|
+
metadata.typescriptOptions = mainConfig.typescript;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
if ((_mainConfig$core = mainConfig.core) !== null && _mainConfig$core !== void 0 && _mainConfig$core.builder) {
|
|
213
|
+
builder = mainConfig.core.builder;
|
|
214
|
+
metadata.builder = {
|
|
215
|
+
name: typeof builder === 'string' ? builder : builder.name,
|
|
216
|
+
options: typeof builder === 'string' ? undefined : (_builder$options = builder === null || builder === void 0 ? void 0 : builder.options) !== null && _builder$options !== void 0 ? _builder$options : undefined
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
if (mainConfig.refs) {
|
|
221
|
+
metadata.refCount = Object.keys(mainConfig.refs).length;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
if (mainConfig.features) {
|
|
225
|
+
metadata.features = mainConfig.features;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
addons = {};
|
|
229
|
+
|
|
230
|
+
if (mainConfig.addons) {
|
|
231
|
+
mainConfig.addons.forEach(function (addon) {
|
|
232
|
+
var result;
|
|
233
|
+
var options;
|
|
234
|
+
|
|
235
|
+
if (typeof addon === 'string') {
|
|
236
|
+
result = addon.replace('/register', '');
|
|
237
|
+
} else {
|
|
238
|
+
options = addon.options;
|
|
239
|
+
result = addon.name;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
addons[result] = {
|
|
243
|
+
options: options,
|
|
244
|
+
version: undefined
|
|
245
|
+
};
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
_context2.next = 35;
|
|
250
|
+
return getActualPackageVersions(addons);
|
|
251
|
+
|
|
252
|
+
case 35:
|
|
253
|
+
addonVersions = _context2.sent;
|
|
254
|
+
addonVersions.forEach(function (_ref5) {
|
|
255
|
+
var name = _ref5.name,
|
|
256
|
+
version = _ref5.version;
|
|
257
|
+
addons[name].version = version;
|
|
258
|
+
});
|
|
259
|
+
addonNames = Object.keys(addons); // all Storybook deps minus the addons
|
|
260
|
+
|
|
261
|
+
storybookPackages = Object.keys(allDependencies).filter(function (dep) {
|
|
262
|
+
return dep.includes('storybook') && !addonNames.includes(dep);
|
|
263
|
+
}).reduce(function (acc, dep) {
|
|
264
|
+
return Object.assign({}, acc, _defineProperty({}, dep, {
|
|
265
|
+
version: undefined
|
|
266
|
+
}));
|
|
267
|
+
}, {});
|
|
268
|
+
_context2.next = 41;
|
|
269
|
+
return getActualPackageVersions(storybookPackages);
|
|
270
|
+
|
|
271
|
+
case 41:
|
|
272
|
+
storybookPackageVersions = _context2.sent;
|
|
273
|
+
storybookPackageVersions.forEach(function (_ref6) {
|
|
274
|
+
var name = _ref6.name,
|
|
275
|
+
version = _ref6.version;
|
|
276
|
+
storybookPackages[name].version = version;
|
|
277
|
+
});
|
|
278
|
+
language = allDependencies.typescript ? 'typescript' : 'javascript';
|
|
279
|
+
hasStorybookEslint = !!allDependencies['eslint-plugin-storybook'];
|
|
280
|
+
storybookInfo = getStorybookInfo(packageJson);
|
|
281
|
+
return _context2.abrupt("return", Object.assign({}, metadata, {
|
|
282
|
+
storybookVersion: storybookInfo.version,
|
|
283
|
+
language: language,
|
|
284
|
+
storybookPackages: storybookPackages,
|
|
285
|
+
framework: {
|
|
286
|
+
name: storybookInfo.framework,
|
|
287
|
+
options: getFrameworkOptions(mainConfig)
|
|
288
|
+
},
|
|
289
|
+
addons: addons,
|
|
290
|
+
hasStorybookEslint: hasStorybookEslint
|
|
291
|
+
}));
|
|
292
|
+
|
|
293
|
+
case 47:
|
|
294
|
+
case "end":
|
|
295
|
+
return _context2.stop();
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
}, _callee2, null, [[12, 22]]);
|
|
299
|
+
}));
|
|
300
|
+
|
|
301
|
+
return function computeStorybookMetadata(_x2) {
|
|
302
|
+
return _ref4.apply(this, arguments);
|
|
303
|
+
};
|
|
304
|
+
}();
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import "core-js/modules/es.object.keys.js";
|
|
2
|
+
import "core-js/modules/es.symbol.js";
|
|
3
|
+
var _excluded = ["payload", "metadata"];
|
|
4
|
+
import "regenerator-runtime/runtime.js";
|
|
5
|
+
|
|
6
|
+
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
7
|
+
|
|
8
|
+
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
9
|
+
|
|
10
|
+
import "core-js/modules/es.object.to-string.js";
|
|
11
|
+
import "core-js/modules/es.promise.js";
|
|
12
|
+
import "core-js/modules/es.object.assign.js";
|
|
13
|
+
import "core-js/modules/es.array.iterator.js";
|
|
14
|
+
import "core-js/modules/es.string.iterator.js";
|
|
15
|
+
import "core-js/modules/web.dom-collections.iterator.js";
|
|
16
|
+
import "core-js/modules/es.array.filter.js";
|
|
17
|
+
|
|
18
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
19
|
+
|
|
20
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
21
|
+
|
|
22
|
+
import originalFetch from 'isomorphic-unfetch';
|
|
23
|
+
import retry from 'fetch-retry';
|
|
24
|
+
import { nanoid } from 'nanoid';
|
|
25
|
+
import { getAnonymousProjectId } from './anonymous-id';
|
|
26
|
+
var URL = 'https://storybook.js.org/event-log';
|
|
27
|
+
var fetch = retry(originalFetch);
|
|
28
|
+
var tasks = []; // getStorybookMetadata -> packagejson + Main.js
|
|
29
|
+
// event specific data: sessionId, ip, etc..
|
|
30
|
+
// send telemetry
|
|
31
|
+
|
|
32
|
+
var sessionId = nanoid();
|
|
33
|
+
export function sendTelemetry(_x) {
|
|
34
|
+
return _sendTelemetry.apply(this, arguments);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function _sendTelemetry() {
|
|
38
|
+
_sendTelemetry = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(data) {
|
|
39
|
+
var options,
|
|
40
|
+
payload,
|
|
41
|
+
metadata,
|
|
42
|
+
rest,
|
|
43
|
+
context,
|
|
44
|
+
eventId,
|
|
45
|
+
body,
|
|
46
|
+
request,
|
|
47
|
+
_args = arguments;
|
|
48
|
+
return regeneratorRuntime.wrap(function _callee$(_context) {
|
|
49
|
+
while (1) {
|
|
50
|
+
switch (_context.prev = _context.next) {
|
|
51
|
+
case 0:
|
|
52
|
+
options = _args.length > 1 && _args[1] !== undefined ? _args[1] : {
|
|
53
|
+
retryDelay: 1000,
|
|
54
|
+
immediate: false
|
|
55
|
+
};
|
|
56
|
+
// We use this id so we can de-dupe events that arrive at the index multiple times due to the
|
|
57
|
+
// use of retries. There are situations in which the request "5xx"s (or times-out), but
|
|
58
|
+
// the server actually gets the request and stores it anyway.
|
|
59
|
+
// flatten the data before we send it
|
|
60
|
+
payload = data.payload, metadata = data.metadata, rest = _objectWithoutProperties(data, _excluded);
|
|
61
|
+
context = {
|
|
62
|
+
anonymousId: getAnonymousProjectId(),
|
|
63
|
+
inCI: process.env.CI === 'true'
|
|
64
|
+
};
|
|
65
|
+
eventId = nanoid();
|
|
66
|
+
body = Object.assign({}, rest, {
|
|
67
|
+
eventId: eventId,
|
|
68
|
+
sessionId: sessionId,
|
|
69
|
+
metadata: metadata,
|
|
70
|
+
payload: payload,
|
|
71
|
+
context: context
|
|
72
|
+
});
|
|
73
|
+
_context.prev = 5;
|
|
74
|
+
request = fetch(URL, {
|
|
75
|
+
method: 'POST',
|
|
76
|
+
body: JSON.stringify(body),
|
|
77
|
+
headers: {
|
|
78
|
+
'Content-Type': 'application/json'
|
|
79
|
+
},
|
|
80
|
+
retries: 3,
|
|
81
|
+
retryOn: [503, 504],
|
|
82
|
+
retryDelay: function retryDelay(attempt) {
|
|
83
|
+
return Math.pow(2, attempt) * options.retryDelay;
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
tasks.push(request);
|
|
87
|
+
|
|
88
|
+
if (!options.immediate) {
|
|
89
|
+
_context.next = 13;
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
_context.next = 11;
|
|
94
|
+
return Promise.all(tasks);
|
|
95
|
+
|
|
96
|
+
case 11:
|
|
97
|
+
_context.next = 15;
|
|
98
|
+
break;
|
|
99
|
+
|
|
100
|
+
case 13:
|
|
101
|
+
_context.next = 15;
|
|
102
|
+
return request;
|
|
103
|
+
|
|
104
|
+
case 15:
|
|
105
|
+
_context.next = 19;
|
|
106
|
+
break;
|
|
107
|
+
|
|
108
|
+
case 17:
|
|
109
|
+
_context.prev = 17;
|
|
110
|
+
_context.t0 = _context["catch"](5);
|
|
111
|
+
|
|
112
|
+
case 19:
|
|
113
|
+
_context.prev = 19;
|
|
114
|
+
tasks = tasks.filter(function (task) {
|
|
115
|
+
return task !== request;
|
|
116
|
+
});
|
|
117
|
+
return _context.finish(19);
|
|
118
|
+
|
|
119
|
+
case 22:
|
|
120
|
+
case "end":
|
|
121
|
+
return _context.stop();
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}, _callee, null, [[5, 17, 19, 22]]);
|
|
125
|
+
}));
|
|
126
|
+
return _sendTelemetry.apply(this, arguments);
|
|
127
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import { execSync } from 'child_process';
|
|
3
|
+
import { getProjectRoot } from '@storybook/core-common';
|
|
4
|
+
import { oneWayHash } from './one-way-hash';
|
|
5
|
+
let anonymousProjectId;
|
|
6
|
+
export const getAnonymousProjectId = () => {
|
|
7
|
+
if (anonymousProjectId) {
|
|
8
|
+
return anonymousProjectId;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
let unhashedProjectId;
|
|
12
|
+
|
|
13
|
+
try {
|
|
14
|
+
const projectRoot = getProjectRoot();
|
|
15
|
+
const projectRootPath = path.relative(projectRoot, process.cwd());
|
|
16
|
+
const originBuffer = execSync(`git config --local --get remote.origin.url`, {
|
|
17
|
+
timeout: 1000,
|
|
18
|
+
stdio: `pipe`
|
|
19
|
+
}); // we use a combination of remoteUrl and working directory
|
|
20
|
+
// to separate multiple storybooks from the same project (e.g. monorepo)
|
|
21
|
+
|
|
22
|
+
unhashedProjectId = `${String(originBuffer).trim()}${projectRootPath}`; // eslint-disable-next-line no-empty
|
|
23
|
+
} catch (_) {}
|
|
24
|
+
|
|
25
|
+
anonymousProjectId = oneWayHash(unhashedProjectId);
|
|
26
|
+
return anonymousProjectId;
|
|
27
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import fs from 'fs-extra';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { getProjectRoot } from '@storybook/core-common';
|
|
4
|
+
export const monorepoConfigs = {
|
|
5
|
+
Nx: 'nx.json',
|
|
6
|
+
Turborepo: 'turbo.json',
|
|
7
|
+
Lerna: 'lerna.json',
|
|
8
|
+
Rush: 'rush.json',
|
|
9
|
+
Lage: 'lage.config.json'
|
|
10
|
+
};
|
|
11
|
+
export const getMonorepoType = () => {
|
|
12
|
+
const projectRootPath = getProjectRoot();
|
|
13
|
+
if (!projectRootPath) return undefined;
|
|
14
|
+
const monorepoType = Object.keys(monorepoConfigs).find(monorepo => {
|
|
15
|
+
const configFile = path.join(projectRootPath, monorepoConfigs[monorepo]);
|
|
16
|
+
return fs.existsSync(configFile);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
if (monorepoType) {
|
|
20
|
+
return monorepoType;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const packageJson = fs.readJsonSync(path.join(projectRootPath, 'package.json'));
|
|
24
|
+
|
|
25
|
+
if (packageJson !== null && packageJson !== void 0 && packageJson.workspaces) {
|
|
26
|
+
return 'Workspaces';
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return undefined;
|
|
30
|
+
};
|