@atlaskit/dependency-version-analytics 0.4.2 → 1.1.0
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/CHANGELOG.md +12 -0
- package/README.md +2 -1
- package/dist/cjs/cli.js +4 -18
- package/dist/cjs/commands/populate-historic-data/index.js +0 -3
- package/dist/cjs/commands/populate-historic-data/lib/dependency-store.js +24 -141
- package/dist/cjs/commands/populate-historic-data/package.js +8 -29
- package/dist/cjs/commands/populate-historic-data/product.js +114 -150
- package/dist/cjs/commands/populate-historic-data/util/generate-csv.js +4 -16
- package/dist/cjs/index.js +0 -2
- package/dist/cjs/util/analytics.js +16 -41
- package/dist/cjs/util/assert.js +0 -1
- package/dist/cjs/util/env-with-guard.js +0 -2
- package/dist/cjs/util/get-file-history-from-git.js +0 -5
- package/dist/cjs/util/get-package-version-history.js +8 -10
- package/dist/cjs/util/git.js +20 -58
- package/dist/cjs/util/statlas.js +0 -25
- package/dist/cjs/util/yarn.js +0 -32
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/cli.js +4 -8
- package/dist/es2019/commands/populate-historic-data/lib/dependency-store.js +24 -73
- package/dist/es2019/commands/populate-historic-data/package.js +7 -12
- package/dist/es2019/commands/populate-historic-data/product.js +21 -23
- package/dist/es2019/commands/populate-historic-data/util/generate-csv.js +2 -9
- package/dist/es2019/util/analytics.js +17 -19
- package/dist/es2019/util/env-with-guard.js +0 -1
- package/dist/es2019/util/get-file-history-from-git.js +2 -3
- package/dist/es2019/util/get-package-version-history.js +7 -7
- package/dist/es2019/util/git.js +29 -24
- package/dist/es2019/util/statlas.js +0 -6
- package/dist/es2019/util/yarn.js +2 -11
- package/dist/es2019/version.json +1 -1
- package/dist/esm/cli.js +6 -12
- package/dist/esm/commands/populate-historic-data/lib/dependency-store.js +27 -131
- package/dist/esm/commands/populate-historic-data/package.js +10 -24
- package/dist/esm/commands/populate-historic-data/product.js +114 -134
- package/dist/esm/commands/populate-historic-data/util/generate-csv.js +4 -13
- package/dist/esm/util/analytics.js +18 -31
- package/dist/esm/util/env-with-guard.js +0 -1
- package/dist/esm/util/get-file-history-from-git.js +2 -3
- package/dist/esm/util/get-package-version-history.js +7 -7
- package/dist/esm/util/git.js +21 -50
- package/dist/esm/util/statlas.js +0 -19
- package/dist/esm/util/yarn.js +0 -19
- package/dist/esm/version.json +1 -1
- package/dist/types/types.d.ts +7 -0
- package/dist/types/util/analytics.d.ts +2 -1
- package/dist/types/util/get-package-version-history.d.ts +7 -3
- package/package.json +3 -3
- package/report.api.md +5 -1
- package/tmp/api-report-tmp.d.ts +4 -0
package/dist/cjs/util/yarn.js
CHANGED
|
@@ -1,40 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
6
|
-
|
|
7
5
|
Object.defineProperty(exports, "__esModule", {
|
|
8
6
|
value: true
|
|
9
7
|
});
|
|
10
8
|
exports.getWorkspaceGlobs = getWorkspaceGlobs;
|
|
11
9
|
exports.getWorkspacePaths = getWorkspacePaths;
|
|
12
|
-
|
|
13
10
|
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
14
|
-
|
|
15
11
|
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
16
|
-
|
|
17
12
|
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
18
|
-
|
|
19
13
|
var _path = _interopRequireDefault(require("path"));
|
|
20
|
-
|
|
21
14
|
var _debug = _interopRequireDefault(require("debug"));
|
|
22
|
-
|
|
23
15
|
var _micromatch = _interopRequireDefault(require("micromatch"));
|
|
24
|
-
|
|
25
16
|
var git = _interopRequireWildcard(require("./git"));
|
|
26
|
-
|
|
27
17
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
28
|
-
|
|
29
18
|
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; }
|
|
30
|
-
|
|
31
19
|
var rootPackageJsonPath = 'package.json';
|
|
32
20
|
var debug = (0, _debug.default)('atlaskit:yarn');
|
|
33
|
-
|
|
34
21
|
function getWorkspaceGlobs(_x, _x2) {
|
|
35
22
|
return _getWorkspaceGlobs.apply(this, arguments);
|
|
36
23
|
}
|
|
37
|
-
|
|
38
24
|
function _getWorkspaceGlobs() {
|
|
39
25
|
_getWorkspaceGlobs = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(ref, cwd) {
|
|
40
26
|
var file, rootPackageJsonFile, workspaces, workspacePackages;
|
|
@@ -47,47 +33,38 @@ function _getWorkspaceGlobs() {
|
|
|
47
33
|
return git.showFile(ref, rootPackageJsonPath, {
|
|
48
34
|
cwd: cwd
|
|
49
35
|
});
|
|
50
|
-
|
|
51
36
|
case 3:
|
|
52
37
|
file = _context.sent;
|
|
53
38
|
_context.next = 10;
|
|
54
39
|
break;
|
|
55
|
-
|
|
56
40
|
case 6:
|
|
57
41
|
_context.prev = 6;
|
|
58
42
|
_context.t0 = _context["catch"](0);
|
|
59
43
|
debug("".concat(rootPackageJsonPath, " does not exist"));
|
|
60
44
|
return _context.abrupt("return", new Set([]));
|
|
61
|
-
|
|
62
45
|
case 10:
|
|
63
46
|
_context.prev = 10;
|
|
64
47
|
rootPackageJsonFile = JSON.parse(file);
|
|
65
48
|
_context.next = 18;
|
|
66
49
|
break;
|
|
67
|
-
|
|
68
50
|
case 14:
|
|
69
51
|
_context.prev = 14;
|
|
70
52
|
_context.t1 = _context["catch"](10);
|
|
71
53
|
console.error("Error parsing ".concat(file, "@").concat(ref, ": ").concat(_context.t1));
|
|
72
54
|
return _context.abrupt("return", null);
|
|
73
|
-
|
|
74
55
|
case 18:
|
|
75
56
|
workspaces = rootPackageJsonFile.workspaces;
|
|
76
|
-
|
|
77
57
|
if (workspaces) {
|
|
78
58
|
_context.next = 21;
|
|
79
59
|
break;
|
|
80
60
|
}
|
|
81
|
-
|
|
82
61
|
return _context.abrupt("return", new Set([rootPackageJsonPath]));
|
|
83
|
-
|
|
84
62
|
case 21:
|
|
85
63
|
// There are actually two formats for workspaces and they are poorly documented
|
|
86
64
|
workspacePackages = Array.isArray(workspaces) ? workspaces : workspaces.packages;
|
|
87
65
|
return _context.abrupt("return", new Set([rootPackageJsonPath].concat((0, _toConsumableArray2.default)(workspacePackages.map(function (glob) {
|
|
88
66
|
return _path.default.join(glob, 'package.json');
|
|
89
67
|
})))));
|
|
90
|
-
|
|
91
68
|
case 23:
|
|
92
69
|
case "end":
|
|
93
70
|
return _context.stop();
|
|
@@ -97,11 +74,9 @@ function _getWorkspaceGlobs() {
|
|
|
97
74
|
}));
|
|
98
75
|
return _getWorkspaceGlobs.apply(this, arguments);
|
|
99
76
|
}
|
|
100
|
-
|
|
101
77
|
function getWorkspacePaths(_x3, _x4, _x5) {
|
|
102
78
|
return _getWorkspacePaths.apply(this, arguments);
|
|
103
79
|
}
|
|
104
|
-
|
|
105
80
|
function _getWorkspacePaths() {
|
|
106
81
|
_getWorkspacePaths = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(ref, workspaceGlobs, cwd) {
|
|
107
82
|
var workspacePackageJsons, matchedWorkspaces;
|
|
@@ -113,29 +88,22 @@ function _getWorkspacePaths() {
|
|
|
113
88
|
_context2.next = 2;
|
|
114
89
|
break;
|
|
115
90
|
}
|
|
116
|
-
|
|
117
91
|
return _context2.abrupt("return", []);
|
|
118
|
-
|
|
119
92
|
case 2:
|
|
120
93
|
_context2.next = 4;
|
|
121
94
|
return git.getFiles(ref, '**/package.json', {
|
|
122
95
|
cwd: cwd
|
|
123
96
|
});
|
|
124
|
-
|
|
125
97
|
case 4:
|
|
126
98
|
workspacePackageJsons = _context2.sent;
|
|
127
99
|
matchedWorkspaces = (0, _micromatch.default)(workspacePackageJsons, (0, _toConsumableArray2.default)(workspaceGlobs));
|
|
128
|
-
|
|
129
100
|
if (!(matchedWorkspaces.length === 0)) {
|
|
130
101
|
_context2.next = 8;
|
|
131
102
|
break;
|
|
132
103
|
}
|
|
133
|
-
|
|
134
104
|
throw new Error("Could not find any workspace or package.json under ".concat(cwd));
|
|
135
|
-
|
|
136
105
|
case 8:
|
|
137
106
|
return _context2.abrupt("return", matchedWorkspaces);
|
|
138
|
-
|
|
139
107
|
case 9:
|
|
140
108
|
case "end":
|
|
141
109
|
return _context2.stop();
|
package/dist/cjs/version.json
CHANGED
package/dist/es2019/cli.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
/// <reference lib="es2017.object" />
|
|
2
|
+
|
|
2
3
|
import chalk from 'chalk';
|
|
3
4
|
import meow from 'meow';
|
|
4
|
-
import { populateProduct, populatePackage } from './commands/populate-historic-data';
|
|
5
|
+
import { populateProduct, populatePackage } from './commands/populate-historic-data';
|
|
5
6
|
|
|
7
|
+
// prettier-ignore
|
|
6
8
|
const HELP_MSG = `
|
|
7
9
|
${chalk.green('Global options')}
|
|
8
10
|
${chalk.yellow('--dev')} Send analytics to dev analytics pipeline instead of prod
|
|
@@ -73,15 +75,12 @@ export function run({
|
|
|
73
75
|
});
|
|
74
76
|
const [command, ...inputs] = cli.input;
|
|
75
77
|
const limit = cli.flags.limit != null ? +cli.flags.limit : undefined;
|
|
76
|
-
|
|
77
78
|
if (command === 'populate-product') {
|
|
78
79
|
const product = inputs[0];
|
|
79
|
-
|
|
80
80
|
if (!product) {
|
|
81
81
|
console.error(chalk.red('Must pass a product parameter'));
|
|
82
82
|
process.exit(1);
|
|
83
83
|
}
|
|
84
|
-
|
|
85
84
|
return populateProduct({
|
|
86
85
|
csv: cli.flags.csv || false,
|
|
87
86
|
dev: dev || cli.flags.dev || false,
|
|
@@ -95,12 +94,10 @@ export function run({
|
|
|
95
94
|
});
|
|
96
95
|
} else if (command === 'populate-package') {
|
|
97
96
|
const pkg = inputs[0];
|
|
98
|
-
|
|
99
97
|
if (!pkg) {
|
|
100
98
|
console.error(chalk.red('Must pass a package parameter'));
|
|
101
99
|
process.exit(1);
|
|
102
100
|
}
|
|
103
|
-
|
|
104
101
|
return populatePackage({
|
|
105
102
|
dev: dev || cli.flags.dev || false,
|
|
106
103
|
dryRun: cli.flags.dryRun || false,
|
|
@@ -110,8 +107,7 @@ export function run({
|
|
|
110
107
|
since: cli.flags.since
|
|
111
108
|
});
|
|
112
109
|
}
|
|
113
|
-
/* eslint-disable no-console */
|
|
114
|
-
|
|
115
110
|
|
|
111
|
+
/* eslint-disable no-console */
|
|
116
112
|
return Promise.resolve(console.log(cli.help));
|
|
117
113
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
-
|
|
3
2
|
/** Workspace code */
|
|
3
|
+
|
|
4
4
|
import debugModule from 'debug';
|
|
5
5
|
import semver from 'semver';
|
|
6
6
|
import { getWorkspacePaths, getWorkspaceGlobs } from '../../../util/yarn';
|
|
@@ -9,7 +9,6 @@ import { DEP_TYPES } from '../../../constants';
|
|
|
9
9
|
import { assert } from '../../../util/assert';
|
|
10
10
|
import micromatch from 'micromatch';
|
|
11
11
|
const debug = debugModule('atlaskit:dependency');
|
|
12
|
-
|
|
13
12
|
/**
|
|
14
13
|
* Stores the state of atlaskit dependencies in a repository
|
|
15
14
|
*/
|
|
@@ -19,132 +18,108 @@ export class DependencyStore {
|
|
|
19
18
|
/** Mapping of workspaces to their dependency map. Each dependency in their map links to an entry in `dependencies` */
|
|
20
19
|
|
|
21
20
|
/** Set of workspace globs. Used to verify that a package.json is a valid workspace */
|
|
21
|
+
|
|
22
22
|
constructor(cwd = process.cwd()) {
|
|
23
23
|
_defineProperty(this, "dependencies", {});
|
|
24
|
-
|
|
25
24
|
_defineProperty(this, "workspaces", {});
|
|
26
|
-
|
|
27
25
|
_defineProperty(this, "workspaceGlobs", new Set());
|
|
28
|
-
|
|
29
26
|
_defineProperty(this, "initialised", false);
|
|
30
|
-
|
|
31
27
|
this.cwd = cwd;
|
|
32
28
|
}
|
|
33
|
-
/** Scans the repo for dependencies at the specified git ref and return the flattened dependency map */
|
|
34
|
-
|
|
35
29
|
|
|
30
|
+
/** Scans the repo for dependencies at the specified git ref and return the flattened dependency map */
|
|
36
31
|
async initialise(gitRef) {
|
|
37
32
|
if (gitRef) {
|
|
38
33
|
await this.resetStore(gitRef);
|
|
39
34
|
}
|
|
40
|
-
|
|
41
35
|
this.initialised = true;
|
|
42
36
|
return this.getFlattenedDeps();
|
|
43
37
|
}
|
|
38
|
+
|
|
44
39
|
/** Updates the repo dependency store based on the changes in `logItem`.
|
|
45
40
|
* Returns the updated flattened dependencies
|
|
46
41
|
*/
|
|
47
|
-
|
|
48
|
-
|
|
49
42
|
async update(logItem) {
|
|
50
43
|
this.assertInitialised();
|
|
51
44
|
const hash = logItem.hash;
|
|
52
45
|
assert(!!logItem.diff, `Diff must exist in log ${logItem} ${hash}`);
|
|
53
46
|
const changedPackageJsons = logItem.diff.files.filter(f => f.file === 'package.json' || f.file.endsWith('/package.json')).map(f => f.file);
|
|
54
47
|
const didRootPackageJsonChange = !!changedPackageJsons.find(file => file === 'package.json');
|
|
55
|
-
|
|
56
48
|
if (didRootPackageJsonChange) {
|
|
57
49
|
const workspaceGlobs = await getWorkspaceGlobs(hash, this.cwd);
|
|
58
50
|
const globsChanged = workspaceGlobs !== null && (this.workspaceGlobs.size !== workspaceGlobs.size || [...this.workspaceGlobs].some(glob => !workspaceGlobs.has(glob)));
|
|
59
|
-
|
|
60
51
|
if (globsChanged) {
|
|
61
52
|
debug(`Workspace globs changed: ${[...workspaceGlobs]}. Resetting store.`);
|
|
62
53
|
await this.resetStore(hash);
|
|
63
54
|
return this.getFlattenedDeps();
|
|
64
55
|
}
|
|
65
56
|
}
|
|
66
|
-
|
|
67
57
|
const changedWorkspaces = micromatch(changedPackageJsons, [...this.workspaceGlobs]);
|
|
68
|
-
debug(`Updating changed workspaces@${hash}: ${changedWorkspaces}`);
|
|
69
|
-
// remove older workspaces that are no longer valid
|
|
58
|
+
debug(`Updating changed workspaces@${hash}: ${changedWorkspaces}`);
|
|
70
59
|
|
|
60
|
+
// Iterate over all changed package.jsons rather than only valid workspaces so that we can
|
|
61
|
+
// remove older workspaces that are no longer valid
|
|
71
62
|
for (const workspacePath of changedPackageJsons) {
|
|
72
63
|
let workspaceDeps = await this.getWorkspaceDependencies(hash, workspacePath);
|
|
73
64
|
const validWorkspace = changedWorkspaces.includes(workspacePath);
|
|
74
|
-
|
|
75
65
|
if (!validWorkspace && !this.workspaces[workspacePath]) {
|
|
76
66
|
// Ignore package.jsons that aren't a valid workspace and weren't valid previously
|
|
77
67
|
continue;
|
|
78
|
-
}
|
|
79
|
-
|
|
68
|
+
}
|
|
80
69
|
|
|
70
|
+
// For workspaces that are no longer a valid workspace but were previously, explicitly remove them
|
|
81
71
|
const noLongerWorkspace = !validWorkspace && this.workspaces[workspacePath];
|
|
82
|
-
|
|
83
72
|
if (workspaceDeps == null || noLongerWorkspace) {
|
|
84
73
|
// If workspaceDeps is undefined, package.json existed but JSON was invalid
|
|
85
74
|
// Else if workspaceDeps is null, package.json doesn't exist and has hence been deleted
|
|
86
75
|
if (workspaceDeps === undefined) {
|
|
87
76
|
console.error(`Error parsing metadata for workspace ${workspacePath}@${hash}`);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
|
|
77
|
+
}
|
|
78
|
+
// set the workspaceDeps to empty here explicitly to remove any deleted workspaces
|
|
91
79
|
workspaceDeps = {};
|
|
92
80
|
}
|
|
93
|
-
|
|
94
81
|
this.updateWorkspaces(workspacePath, workspaceDeps);
|
|
95
82
|
}
|
|
96
|
-
|
|
97
83
|
return this.getFlattenedDeps();
|
|
98
84
|
}
|
|
85
|
+
|
|
99
86
|
/** Retrieve a flattened list of p repo dependencies.
|
|
100
87
|
* If multiple versions of a dependency exist, the lowest version is returned.
|
|
101
88
|
* If the dependency is listed under multiple dependency types, 'dependencies' is prioritised over 'devDependencies'
|
|
102
89
|
*/
|
|
103
|
-
|
|
104
|
-
|
|
105
90
|
getFlattenedDeps() {
|
|
106
91
|
const deps = Object.entries(this.dependencies).filter(([, versions]) => versions.length > 0).map(([depName, versions]) => [depName, DependencyStore.getMinimumVersion(versions, depName)]);
|
|
107
92
|
return fromEntries(deps);
|
|
108
93
|
}
|
|
109
|
-
|
|
110
94
|
assertInitialised() {
|
|
111
95
|
if (!this.initialised) {
|
|
112
96
|
throw new Error('Class must be initialised first with `.initialise()`');
|
|
113
97
|
}
|
|
114
98
|
}
|
|
115
|
-
/** Scans all workspaces in repo and rebuilds dependency store */
|
|
116
|
-
|
|
117
99
|
|
|
100
|
+
/** Scans all workspaces in repo and rebuilds dependency store */
|
|
118
101
|
async resetStore(gitRef) {
|
|
119
102
|
this.dependencies = {};
|
|
120
103
|
this.workspaces = {};
|
|
121
104
|
const workspaceGlobs = await getWorkspaceGlobs(gitRef, this.cwd);
|
|
122
|
-
|
|
123
105
|
if (workspaceGlobs !== null) {
|
|
124
106
|
this.workspaceGlobs = workspaceGlobs;
|
|
125
107
|
}
|
|
126
|
-
|
|
127
108
|
const workspacePaths = await getWorkspacePaths(gitRef, this.workspaceGlobs, this.cwd);
|
|
128
109
|
debug(`Workspace paths: ${workspacePaths}`);
|
|
129
|
-
|
|
130
110
|
for (const wsPath of workspacePaths) {
|
|
131
111
|
if (this.workspaces[wsPath]) {
|
|
132
112
|
throw new Error(`Duplicate workspace path found: ${wsPath}`);
|
|
133
113
|
}
|
|
134
|
-
|
|
135
114
|
const workspaceDeps = await this.getWorkspaceDependencies(gitRef, wsPath);
|
|
136
|
-
|
|
137
115
|
if (workspaceDeps == null) {
|
|
138
116
|
continue;
|
|
139
117
|
}
|
|
140
|
-
|
|
141
118
|
this.updateWorkspaces(wsPath, workspaceDeps);
|
|
142
119
|
}
|
|
143
120
|
}
|
|
144
|
-
|
|
145
121
|
async getWorkspaceDependencies(hash, workspacePath) {
|
|
146
122
|
let file;
|
|
147
|
-
|
|
148
123
|
try {
|
|
149
124
|
file = await showFile(hash, workspacePath, {
|
|
150
125
|
cwd: this.cwd
|
|
@@ -153,46 +128,37 @@ export class DependencyStore {
|
|
|
153
128
|
debug(`Could not show file ${workspacePath}@${hash}`);
|
|
154
129
|
return null;
|
|
155
130
|
}
|
|
156
|
-
|
|
157
131
|
let json;
|
|
158
|
-
|
|
159
132
|
try {
|
|
160
133
|
json = JSON.parse(file);
|
|
161
134
|
} catch (e) {
|
|
162
135
|
console.error(`Error parsing JSON - "${file}"@${hash}`);
|
|
163
136
|
return undefined;
|
|
164
137
|
}
|
|
165
|
-
|
|
166
138
|
let workspaceDeps = {};
|
|
167
|
-
|
|
168
139
|
for (const {
|
|
169
140
|
packageJsonKey,
|
|
170
141
|
depTypeName
|
|
171
142
|
} of DEP_TYPES) {
|
|
172
143
|
const wsDeps = DependencyStore.getAkDependencies(json[packageJsonKey] || {}, depTypeName);
|
|
173
|
-
workspaceDeps = {
|
|
144
|
+
workspaceDeps = {
|
|
145
|
+
...workspaceDeps,
|
|
174
146
|
...wsDeps
|
|
175
147
|
};
|
|
176
148
|
}
|
|
177
|
-
|
|
178
149
|
return workspaceDeps;
|
|
179
150
|
}
|
|
180
|
-
|
|
181
151
|
updateWorkspaces(workspacePath, workspaceDeps) {
|
|
182
152
|
debug(`Updating workspace ${workspacePath}`);
|
|
183
|
-
|
|
184
153
|
if (!this.workspaces[workspacePath]) {
|
|
185
154
|
this.workspaces[workspacePath] = {};
|
|
186
155
|
}
|
|
187
|
-
|
|
188
156
|
const prevWorkspaceDeps = this.workspaces[workspacePath];
|
|
189
|
-
|
|
190
157
|
for (const depName of Object.keys(prevWorkspaceDeps)) {
|
|
191
158
|
if (!workspaceDeps[depName]) {
|
|
192
159
|
this.removeDependency(workspacePath, depName, prevWorkspaceDeps[depName]);
|
|
193
160
|
}
|
|
194
161
|
}
|
|
195
|
-
|
|
196
162
|
for (const [depName, {
|
|
197
163
|
version,
|
|
198
164
|
type
|
|
@@ -200,25 +166,20 @@ export class DependencyStore {
|
|
|
200
166
|
this.addDependency(workspacePath, depName, version, type);
|
|
201
167
|
}
|
|
202
168
|
}
|
|
203
|
-
|
|
204
169
|
addDependency(workspacePath, depName, version, type) {
|
|
205
170
|
if (!this.dependencies[depName]) {
|
|
206
171
|
debug(`Adding new dep ${depName}`);
|
|
207
172
|
this.dependencies[depName] = [];
|
|
208
173
|
}
|
|
209
|
-
|
|
210
174
|
const prevEntry = this.workspaces[workspacePath][depName];
|
|
211
175
|
const existingEntry = this.dependencies[depName].find(entry => entry.version === version && entry.type === type);
|
|
212
|
-
|
|
213
176
|
if (existingEntry && existingEntry === prevEntry) {
|
|
214
177
|
// We haven't added or updated the dep, exit early
|
|
215
178
|
return;
|
|
216
179
|
}
|
|
217
|
-
|
|
218
180
|
if (prevEntry) {
|
|
219
181
|
this.removeDependency(workspacePath, depName, prevEntry);
|
|
220
182
|
}
|
|
221
|
-
|
|
222
183
|
if (existingEntry) {
|
|
223
184
|
existingEntry.workspaces.add(workspacePath);
|
|
224
185
|
this.workspaces[workspacePath][depName] = existingEntry;
|
|
@@ -233,39 +194,33 @@ export class DependencyStore {
|
|
|
233
194
|
this.workspaces[workspacePath][depName] = newEntry;
|
|
234
195
|
}
|
|
235
196
|
}
|
|
236
|
-
|
|
237
197
|
removeDependency(workspacePath, depName, depEntry) {
|
|
238
198
|
debug(`${depName} removed from ${workspacePath}`);
|
|
239
199
|
assert(depEntry && depEntry.workspaces, `Dep entry should exist for ${depName}`);
|
|
240
200
|
depEntry.workspaces.delete(workspacePath);
|
|
241
|
-
|
|
242
201
|
if (depEntry.workspaces.size === 0) {
|
|
243
202
|
debug(`No more workspaces depend on ${depName}@${depEntry.version} as a ${depEntry.type}, deleting`);
|
|
244
203
|
this.dependencies[depName] = this.dependencies[depName].filter(entry => entry !== depEntry);
|
|
245
204
|
}
|
|
246
205
|
}
|
|
247
|
-
|
|
248
206
|
static getAkDependencies(depMap, type) {
|
|
249
|
-
return fromEntries(Object.entries(depMap).filter(
|
|
207
|
+
return fromEntries(Object.entries(depMap).filter(
|
|
208
|
+
// Ignore suffixed `--next` deps in jira used for independent upgrades
|
|
250
209
|
([name]) => name.includes('@atlaskit') && !name.endsWith('--next')).map(([name, version]) => [DependencyStore.transformDepName(name), {
|
|
251
210
|
version: DependencyStore.transformDepVersion(version),
|
|
252
211
|
type
|
|
253
212
|
}]));
|
|
254
213
|
}
|
|
255
|
-
|
|
256
214
|
static getMinimumVersion(versions, depName) {
|
|
257
|
-
const depOrder = ['dependency', 'peerDependency', 'devDependency', 'optionalDependency'];
|
|
258
|
-
|
|
215
|
+
const depOrder = ['dependency', 'peerDependency', 'devDependency', 'optionalDependency'];
|
|
216
|
+
// Sort deps before devDeps and then take the lowest version
|
|
259
217
|
const sorted = versions.sort((a, b) => {
|
|
260
218
|
const depSort = depOrder.indexOf(a.type) - depOrder.indexOf(b.type);
|
|
261
|
-
|
|
262
219
|
if (depSort !== 0) {
|
|
263
220
|
return depSort;
|
|
264
221
|
}
|
|
265
|
-
|
|
266
222
|
const aVersion = semver.coerce(a.version);
|
|
267
223
|
const bVersion = semver.coerce(b.version);
|
|
268
|
-
|
|
269
224
|
if (!aVersion) {
|
|
270
225
|
console.error(`Invalid version ${depName}@${a.version}`);
|
|
271
226
|
return 1;
|
|
@@ -273,37 +228,33 @@ export class DependencyStore {
|
|
|
273
228
|
console.error(`Invalid version ${depName}@${b.version}`);
|
|
274
229
|
return -1;
|
|
275
230
|
}
|
|
276
|
-
|
|
277
231
|
return semver.compare(aVersion, bVersion);
|
|
278
232
|
});
|
|
279
|
-
|
|
280
233
|
if (sorted.length > 1) {
|
|
281
|
-
debug(`Multiple versions found for ${depName}: ${JSON.stringify(sorted.map(depInfo => ({
|
|
234
|
+
debug(`Multiple versions found for ${depName}: ${JSON.stringify(sorted.map(depInfo => ({
|
|
235
|
+
...depInfo,
|
|
282
236
|
workspaces: [...depInfo.workspaces]
|
|
283
237
|
})))}`);
|
|
284
238
|
}
|
|
285
|
-
|
|
286
239
|
return sorted[0];
|
|
287
240
|
}
|
|
288
|
-
|
|
289
241
|
static transformDepName(name) {
|
|
290
242
|
// Treat `--current` as the standard dependency
|
|
291
243
|
return name.replace(/--current$/, '');
|
|
292
244
|
}
|
|
245
|
+
|
|
293
246
|
/* Coerce non-standard versions to a semver version.
|
|
294
247
|
* This essentially ignores everything up until the first number and then tries to parse a version
|
|
295
248
|
* out of that.
|
|
296
249
|
* Used to yarn alias versions used by jira's independent upgrades, e.g. npm:@atlaskit/button@^15.0.8
|
|
297
250
|
*/
|
|
298
|
-
|
|
299
|
-
|
|
300
251
|
static transformDepVersion(version) {
|
|
301
252
|
const parts = version.split('@');
|
|
302
253
|
return parts[parts.length - 1];
|
|
303
254
|
}
|
|
255
|
+
}
|
|
304
256
|
|
|
305
|
-
|
|
306
|
-
|
|
257
|
+
// Object.fromEntries polyfill, remove when upgraded to node 10
|
|
307
258
|
function fromEntries(iterable) {
|
|
308
259
|
return [...iterable].reduce((obj, {
|
|
309
260
|
0: key,
|
|
@@ -1,40 +1,35 @@
|
|
|
1
1
|
import semver from 'semver';
|
|
2
|
-
import
|
|
2
|
+
import getPackageVersionHistoryAndTags from '../../util/get-package-version-history';
|
|
3
3
|
import { createUpgradeEvent, sendAnalytics } from '../../util/analytics';
|
|
4
|
-
|
|
5
|
-
const
|
|
4
|
+
const createAnalyticsEvents = (packageName, packageVersionHistoryAndTags, since) => {
|
|
5
|
+
const packageVersionHistory = packageVersionHistoryAndTags['time'];
|
|
6
|
+
const tags = packageVersionHistoryAndTags['dist-tags'];
|
|
6
7
|
const sortedPackageVersionHistory = Object.entries(packageVersionHistory).filter(([version]) => semver.valid(version)).sort((a, b) => Number(new Date(a[1])) - Number(new Date(b[1])));
|
|
7
8
|
const upgradeEvents = sortedPackageVersionHistory.map(([version, time], i) => {
|
|
8
9
|
if (since && Number(new Date(time)) <= Number(new Date(since))) {
|
|
9
10
|
return null;
|
|
10
11
|
}
|
|
11
|
-
|
|
12
12
|
const previousVersion = sortedPackageVersionHistory[i - 1] && sortedPackageVersionHistory[i - 1][0];
|
|
13
13
|
return createUpgradeEvent(packageName, version, previousVersion, time, {
|
|
14
|
-
historical: true
|
|
14
|
+
historical: true,
|
|
15
|
+
tags
|
|
15
16
|
});
|
|
16
17
|
}).filter(e => e != null);
|
|
17
18
|
return upgradeEvents;
|
|
18
19
|
};
|
|
19
|
-
|
|
20
20
|
export default async function populatePackage(flags) {
|
|
21
21
|
if (!flags.pkg.startsWith('@atlaskit/')) {
|
|
22
22
|
throw new Error(`Package must start with '@atlaskit/'`);
|
|
23
23
|
}
|
|
24
|
-
|
|
25
|
-
const packageVersionHistory = await getPackageVersionHistory(flags.pkg);
|
|
26
|
-
|
|
24
|
+
const packageVersionHistory = await getPackageVersionHistoryAndTags(flags.pkg);
|
|
27
25
|
if (flags.since && Number.isNaN(Number(new Date(flags.since)))) {
|
|
28
26
|
throw new Error(`'since' flag is an invalid date`);
|
|
29
27
|
}
|
|
30
|
-
|
|
31
28
|
const analyticsEvents = createAnalyticsEvents(flags.pkg, packageVersionHistory, flags.since);
|
|
32
|
-
|
|
33
29
|
if (flags.dryRun) {
|
|
34
30
|
console.log(JSON.stringify(analyticsEvents));
|
|
35
31
|
return analyticsEvents;
|
|
36
32
|
}
|
|
37
|
-
|
|
38
33
|
await sendAnalytics(analyticsEvents, {
|
|
39
34
|
dev: flags.dev,
|
|
40
35
|
limit: flags.limit,
|