@atlaskit/dependency-version-analytics 1.4.8 → 1.5.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 CHANGED
@@ -1,5 +1,17 @@
1
1
  # @atlaskit/dependency-version-analytics
2
2
 
3
+ ## 1.5.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`d23cb258eb0`](https://bitbucket.org/atlassian/atlassian-frontend/commits/d23cb258eb0) - Using flags.cwd to set current workDir and use package.json from current workDir instead of root
8
+
9
+ ## 1.4.9
10
+
11
+ ### Patch Changes
12
+
13
+ - [`0fd070e4bba`](https://bitbucket.org/atlassian/atlassian-frontend/commits/0fd070e4bba) - Improved logs
14
+
3
15
  ## 1.4.8
4
16
 
5
17
  ### Patch Changes
@@ -99,8 +99,14 @@ async function getSinceRef(flags) {
99
99
  return tag;
100
100
  }
101
101
  }
102
+ const getWorkDir = cwd => {
103
+ const workDir = cwd ?? process.cwd();
104
+ // Make sure that we're working in needed directory
105
+ process.chdir(workDir);
106
+ return workDir;
107
+ };
102
108
  async function populateProduct(flags) {
103
- const cwd = flags.cwd || process.cwd();
109
+ const cwd = getWorkDir(flags.cwd);
104
110
  const sinceRef = flags.reset ? undefined : await getSinceRef(flags);
105
111
  const log = await (0, _git.getChangesSince)(sinceRef);
106
112
  const supportedScopes = (0, _allowedScopes.getSupportedScopes)(flags.includeRestrictedScopes);
@@ -116,13 +122,16 @@ async function populateProduct(flags) {
116
122
  } = await getEventsFromHistory(log, sinceRef, {
117
123
  cwd
118
124
  }, supportedScopes, supportedPackages);
125
+ if (!allUpgradeEvents.length) {
126
+ console.log(`Found no dependency changes from supported scopes ${supportedScopes.join(', ')} since last run from ref "${sinceRef}"'`);
127
+ }
119
128
  if (flags.csv) {
120
129
  const csv = (0, _generateCsv.generateCSV)(allPackageChanges);
121
- console.log(csv);
130
+ console.log('Generated csv: ', csv);
122
131
  return;
123
132
  }
124
133
  if (flags.dryRun) {
125
- console.log(JSON.stringify(allUpgradeEvents));
134
+ console.log('All upgrade events: ', JSON.stringify(allUpgradeEvents));
126
135
  return;
127
136
  }
128
137
  if (allUpgradeEvents.length > 0) {
@@ -132,8 +141,6 @@ async function populateProduct(flags) {
132
141
  product: flags.product,
133
142
  skipPrompt: !flags.interactive
134
143
  });
135
- } else {
136
- console.log(`Found no dependency changes from supported scopes ${supportedScopes.join(', ')} since last run from ref "${sinceRef}"'`);
137
144
  }
138
145
  if (flags.statlas) {
139
146
  // Upload latest commit to statlas
@@ -67,7 +67,7 @@ function createUpgradeEvent(name, version, previousVersion, date, optionalEventA
67
67
  }
68
68
  });
69
69
  return {
70
- cliVersion: "1.4.8",
70
+ cliVersion: "1.5.0",
71
71
  dependencyName: name,
72
72
  versionString: eventVersion,
73
73
  major: parsedVersion ? `${parsedVersion.major}` : null,
@@ -12,16 +12,24 @@ var _micromatch = _interopRequireDefault(require("micromatch"));
12
12
  var git = _interopRequireWildcard(require("./git"));
13
13
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
14
14
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
15
- const rootPackageJsonPath = 'package.json';
16
15
  const debug = (0, _debug.default)('atlaskit:yarn');
17
16
  async function getWorkspacePackageJsonPaths(hash, cwd) {
18
17
  let file;
19
18
  try {
20
- file = await git.showFile(hash, rootPackageJsonPath, {
19
+ /**
20
+ * We need to use package.json from current working directory, not from root
21
+ * The reason is - some repositories have their package.json not in root
22
+ * For example "confluence-frontend" repo has package.json at "confluence-frontend/confluence/package.json"
23
+ */
24
+ file = await git.showFile(hash, `./package.json`, {
21
25
  cwd
22
26
  });
23
- } catch (e) {
24
- debug(`${rootPackageJsonPath} does not exist`);
27
+ } catch (error) {
28
+ const errorMessage = `File by hash "${hash}" and path "${cwd}/package.json" does not exist`;
29
+ debug(errorMessage, {
30
+ error
31
+ });
32
+ console.error(errorMessage, error);
25
33
  return new Set([]);
26
34
  }
27
35
  let rootPackageJsonFile;
@@ -33,11 +41,11 @@ async function getWorkspacePackageJsonPaths(hash, cwd) {
33
41
  }
34
42
  const workspaces = rootPackageJsonFile.workspaces;
35
43
  if (!workspaces) {
36
- return new Set([rootPackageJsonPath]);
44
+ return new Set(['package.json']);
37
45
  }
38
46
  // There are actually two formats for workspaces and they are poorly documented
39
47
  const workspacePackages = Array.isArray(workspaces) ? workspaces : workspaces.packages;
40
- return new Set([rootPackageJsonPath, ...workspacePackages.map(glob => _path.default.join(glob, 'package.json'))]);
48
+ return new Set(['package.json', ...workspacePackages.map(glob => _path.default.join(glob, 'package.json'))]);
41
49
  }
42
50
  async function getWorkspacePaths(ref, workspaceGlobs, cwd) {
43
51
  if (workspaceGlobs.size === 0) {
@@ -48,7 +56,7 @@ async function getWorkspacePaths(ref, workspaceGlobs, cwd) {
48
56
  });
49
57
  const matchedWorkspaces = (0, _micromatch.default)(workspacePackageJsons, [...workspaceGlobs]);
50
58
  if (matchedWorkspaces.length === 0) {
51
- throw new Error(`Could not find any workspace or package.json under ${cwd}`);
59
+ throw new Error(`Could not find any workspace or package.json under "${cwd}" for "${ref}" tag`);
52
60
  }
53
61
  return matchedWorkspaces;
54
62
  }
@@ -90,8 +90,14 @@ async function getSinceRef(flags) {
90
90
  return tag;
91
91
  }
92
92
  }
93
+ const getWorkDir = cwd => {
94
+ const workDir = cwd !== null && cwd !== void 0 ? cwd : process.cwd();
95
+ // Make sure that we're working in needed directory
96
+ process.chdir(workDir);
97
+ return workDir;
98
+ };
93
99
  export default async function populateProduct(flags) {
94
- const cwd = flags.cwd || process.cwd();
100
+ const cwd = getWorkDir(flags.cwd);
95
101
  const sinceRef = flags.reset ? undefined : await getSinceRef(flags);
96
102
  const log = await getChangesSince(sinceRef);
97
103
  const supportedScopes = getSupportedScopes(flags.includeRestrictedScopes);
@@ -107,13 +113,16 @@ export default async function populateProduct(flags) {
107
113
  } = await getEventsFromHistory(log, sinceRef, {
108
114
  cwd
109
115
  }, supportedScopes, supportedPackages);
116
+ if (!allUpgradeEvents.length) {
117
+ console.log(`Found no dependency changes from supported scopes ${supportedScopes.join(', ')} since last run from ref "${sinceRef}"'`);
118
+ }
110
119
  if (flags.csv) {
111
120
  const csv = generateCSV(allPackageChanges);
112
- console.log(csv);
121
+ console.log('Generated csv: ', csv);
113
122
  return;
114
123
  }
115
124
  if (flags.dryRun) {
116
- console.log(JSON.stringify(allUpgradeEvents));
125
+ console.log('All upgrade events: ', JSON.stringify(allUpgradeEvents));
117
126
  return;
118
127
  }
119
128
  if (allUpgradeEvents.length > 0) {
@@ -123,8 +132,6 @@ export default async function populateProduct(flags) {
123
132
  product: flags.product,
124
133
  skipPrompt: !flags.interactive
125
134
  });
126
- } else {
127
- console.log(`Found no dependency changes from supported scopes ${supportedScopes.join(', ')} since last run from ref "${sinceRef}"'`);
128
135
  }
129
136
  if (flags.statlas) {
130
137
  // Upload latest commit to statlas
@@ -59,7 +59,7 @@ export function createUpgradeEvent(name, version, previousVersion, date, optiona
59
59
  }
60
60
  });
61
61
  return {
62
- cliVersion: "1.4.8",
62
+ cliVersion: "1.5.0",
63
63
  dependencyName: name,
64
64
  versionString: eventVersion,
65
65
  major: parsedVersion ? `${parsedVersion.major}` : null,
@@ -2,16 +2,24 @@ import path from 'path';
2
2
  import debugModule from 'debug';
3
3
  import micromatch from 'micromatch';
4
4
  import * as git from './git';
5
- const rootPackageJsonPath = 'package.json';
6
5
  const debug = debugModule('atlaskit:yarn');
7
6
  export async function getWorkspacePackageJsonPaths(hash, cwd) {
8
7
  let file;
9
8
  try {
10
- file = await git.showFile(hash, rootPackageJsonPath, {
9
+ /**
10
+ * We need to use package.json from current working directory, not from root
11
+ * The reason is - some repositories have their package.json not in root
12
+ * For example "confluence-frontend" repo has package.json at "confluence-frontend/confluence/package.json"
13
+ */
14
+ file = await git.showFile(hash, `./package.json`, {
11
15
  cwd
12
16
  });
13
- } catch (e) {
14
- debug(`${rootPackageJsonPath} does not exist`);
17
+ } catch (error) {
18
+ const errorMessage = `File by hash "${hash}" and path "${cwd}/package.json" does not exist`;
19
+ debug(errorMessage, {
20
+ error
21
+ });
22
+ console.error(errorMessage, error);
15
23
  return new Set([]);
16
24
  }
17
25
  let rootPackageJsonFile;
@@ -23,11 +31,11 @@ export async function getWorkspacePackageJsonPaths(hash, cwd) {
23
31
  }
24
32
  const workspaces = rootPackageJsonFile.workspaces;
25
33
  if (!workspaces) {
26
- return new Set([rootPackageJsonPath]);
34
+ return new Set(['package.json']);
27
35
  }
28
36
  // There are actually two formats for workspaces and they are poorly documented
29
37
  const workspacePackages = Array.isArray(workspaces) ? workspaces : workspaces.packages;
30
- return new Set([rootPackageJsonPath, ...workspacePackages.map(glob => path.join(glob, 'package.json'))]);
38
+ return new Set(['package.json', ...workspacePackages.map(glob => path.join(glob, 'package.json'))]);
31
39
  }
32
40
  export async function getWorkspacePaths(ref, workspaceGlobs, cwd) {
33
41
  if (workspaceGlobs.size === 0) {
@@ -38,7 +46,7 @@ export async function getWorkspacePaths(ref, workspaceGlobs, cwd) {
38
46
  });
39
47
  const matchedWorkspaces = micromatch(workspacePackageJsons, [...workspaceGlobs]);
40
48
  if (matchedWorkspaces.length === 0) {
41
- throw new Error(`Could not find any workspace or package.json under ${cwd}`);
49
+ throw new Error(`Could not find any workspace or package.json under "${cwd}" for "${ref}" tag`);
42
50
  }
43
51
  return matchedWorkspaces;
44
52
  }
@@ -164,6 +164,12 @@ function _getSinceRef() {
164
164
  }));
165
165
  return _getSinceRef.apply(this, arguments);
166
166
  }
167
+ var getWorkDir = function getWorkDir(cwd) {
168
+ var workDir = cwd !== null && cwd !== void 0 ? cwd : process.cwd();
169
+ // Make sure that we're working in needed directory
170
+ process.chdir(workDir);
171
+ return workDir;
172
+ };
167
173
  export default function populateProduct(_x7) {
168
174
  return _populateProduct.apply(this, arguments);
169
175
  }
@@ -173,7 +179,7 @@ function _populateProduct() {
173
179
  return _regeneratorRuntime.wrap(function _callee3$(_context3) {
174
180
  while (1) switch (_context3.prev = _context3.next) {
175
181
  case 0:
176
- cwd = flags.cwd || process.cwd();
182
+ cwd = getWorkDir(flags.cwd);
177
183
  if (!flags.reset) {
178
184
  _context3.next = 5;
179
185
  break;
@@ -210,59 +216,57 @@ function _populateProduct() {
210
216
  _yield$getEventsFromH = _context3.sent;
211
217
  allPackageChanges = _yield$getEventsFromH.allPackageChanges;
212
218
  allUpgradeEvents = _yield$getEventsFromH.allUpgradeEvents;
219
+ if (!allUpgradeEvents.length) {
220
+ console.log("Found no dependency changes from supported scopes ".concat(supportedScopes.join(', '), " since last run from ref \"").concat(sinceRef, "\"'"));
221
+ }
213
222
  if (!flags.csv) {
214
- _context3.next = 27;
223
+ _context3.next = 28;
215
224
  break;
216
225
  }
217
226
  csv = generateCSV(allPackageChanges);
218
- console.log(csv);
227
+ console.log('Generated csv: ', csv);
219
228
  return _context3.abrupt("return");
220
- case 27:
229
+ case 28:
221
230
  if (!flags.dryRun) {
222
- _context3.next = 30;
231
+ _context3.next = 31;
223
232
  break;
224
233
  }
225
- console.log(JSON.stringify(allUpgradeEvents));
234
+ console.log('All upgrade events: ', JSON.stringify(allUpgradeEvents));
226
235
  return _context3.abrupt("return");
227
- case 30:
236
+ case 31:
228
237
  if (!(allUpgradeEvents.length > 0)) {
229
- _context3.next = 35;
238
+ _context3.next = 34;
230
239
  break;
231
240
  }
232
- _context3.next = 33;
241
+ _context3.next = 34;
233
242
  return sendAnalytics(allUpgradeEvents, {
234
243
  dev: flags.dev,
235
244
  limit: flags.limit,
236
245
  product: flags.product,
237
246
  skipPrompt: !flags.interactive
238
247
  });
239
- case 33:
240
- _context3.next = 36;
241
- break;
242
- case 35:
243
- console.log("Found no dependency changes from supported scopes ".concat(supportedScopes.join(', '), " since last run from ref \"").concat(sinceRef, "\"'"));
244
- case 36:
248
+ case 34:
245
249
  if (!flags.statlas) {
246
- _context3.next = 45;
250
+ _context3.next = 43;
247
251
  break;
248
252
  }
249
- _context3.next = 39;
253
+ _context3.next = 37;
250
254
  return getHash('HEAD');
251
- case 39:
255
+ case 37:
252
256
  currentCommit = _context3.sent;
253
- _context3.next = 42;
257
+ _context3.next = 40;
254
258
  return statlas.uploadMeta(flags.product, currentCommit);
255
- case 42:
259
+ case 40:
256
260
  console.log('Finished');
257
- _context3.next = 49;
261
+ _context3.next = 47;
258
262
  break;
259
- case 45:
263
+ case 43:
260
264
  console.log('Updating tag to current commit...');
261
- _context3.next = 48;
265
+ _context3.next = 46;
262
266
  return tagCommit(DEFAULT_TAG);
263
- case 48:
267
+ case 46:
264
268
  console.log("Finished. Run 'git push origin tag ".concat(sinceRef, "'."));
265
- case 49:
269
+ case 47:
266
270
  case "end":
267
271
  return _context3.stop();
268
272
  }
@@ -66,7 +66,7 @@ export function createUpgradeEvent(name, version, previousVersion, date) {
66
66
  }
67
67
  });
68
68
  return _objectSpread({
69
- cliVersion: "1.4.8",
69
+ cliVersion: "1.5.0",
70
70
  dependencyName: name,
71
71
  versionString: eventVersion,
72
72
  major: parsedVersion ? "".concat(parsedVersion.major) : null,
@@ -5,59 +5,62 @@ import path from 'path';
5
5
  import debugModule from 'debug';
6
6
  import micromatch from 'micromatch';
7
7
  import * as git from './git';
8
- var rootPackageJsonPath = 'package.json';
9
8
  var debug = debugModule('atlaskit:yarn');
10
9
  export function getWorkspacePackageJsonPaths(_x, _x2) {
11
10
  return _getWorkspacePackageJsonPaths.apply(this, arguments);
12
11
  }
13
12
  function _getWorkspacePackageJsonPaths() {
14
13
  _getWorkspacePackageJsonPaths = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(hash, cwd) {
15
- var file, rootPackageJsonFile, workspaces, workspacePackages;
14
+ var file, errorMessage, rootPackageJsonFile, workspaces, workspacePackages;
16
15
  return _regeneratorRuntime.wrap(function _callee$(_context) {
17
16
  while (1) switch (_context.prev = _context.next) {
18
17
  case 0:
19
18
  _context.prev = 0;
20
19
  _context.next = 3;
21
- return git.showFile(hash, rootPackageJsonPath, {
20
+ return git.showFile(hash, "./package.json", {
22
21
  cwd: cwd
23
22
  });
24
23
  case 3:
25
24
  file = _context.sent;
26
- _context.next = 10;
25
+ _context.next = 12;
27
26
  break;
28
27
  case 6:
29
28
  _context.prev = 6;
30
29
  _context.t0 = _context["catch"](0);
31
- debug("".concat(rootPackageJsonPath, " does not exist"));
30
+ errorMessage = "File by hash \"".concat(hash, "\" and path \"").concat(cwd, "/package.json\" does not exist");
31
+ debug(errorMessage, {
32
+ error: _context.t0
33
+ });
34
+ console.error(errorMessage, _context.t0);
32
35
  return _context.abrupt("return", new Set([]));
33
- case 10:
34
- _context.prev = 10;
36
+ case 12:
37
+ _context.prev = 12;
35
38
  rootPackageJsonFile = JSON.parse(file);
36
- _context.next = 18;
39
+ _context.next = 20;
37
40
  break;
38
- case 14:
39
- _context.prev = 14;
40
- _context.t1 = _context["catch"](10);
41
+ case 16:
42
+ _context.prev = 16;
43
+ _context.t1 = _context["catch"](12);
41
44
  console.error("Error parsing ".concat(file, "@").concat(hash, ": ").concat(_context.t1));
42
45
  return _context.abrupt("return", null);
43
- case 18:
46
+ case 20:
44
47
  workspaces = rootPackageJsonFile.workspaces;
45
48
  if (workspaces) {
46
- _context.next = 21;
49
+ _context.next = 23;
47
50
  break;
48
51
  }
49
- return _context.abrupt("return", new Set([rootPackageJsonPath]));
50
- case 21:
52
+ return _context.abrupt("return", new Set(['package.json']));
53
+ case 23:
51
54
  // There are actually two formats for workspaces and they are poorly documented
52
55
  workspacePackages = Array.isArray(workspaces) ? workspaces : workspaces.packages;
53
- return _context.abrupt("return", new Set([rootPackageJsonPath].concat(_toConsumableArray(workspacePackages.map(function (glob) {
56
+ return _context.abrupt("return", new Set(['package.json'].concat(_toConsumableArray(workspacePackages.map(function (glob) {
54
57
  return path.join(glob, 'package.json');
55
58
  })))));
56
- case 23:
59
+ case 25:
57
60
  case "end":
58
61
  return _context.stop();
59
62
  }
60
- }, _callee, null, [[0, 6], [10, 14]]);
63
+ }, _callee, null, [[0, 6], [12, 16]]);
61
64
  }));
62
65
  return _getWorkspacePackageJsonPaths.apply(this, arguments);
63
66
  }
@@ -87,7 +90,7 @@ function _getWorkspacePaths() {
87
90
  _context2.next = 8;
88
91
  break;
89
92
  }
90
- throw new Error("Could not find any workspace or package.json under ".concat(cwd));
93
+ throw new Error("Could not find any workspace or package.json under \"".concat(cwd, "\" for \"").concat(ref, "\" tag"));
91
94
  case 8:
92
95
  return _context2.abrupt("return", matchedWorkspaces);
93
96
  case 9:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/dependency-version-analytics",
3
- "version": "1.4.8",
3
+ "version": "1.5.0",
4
4
  "description": "Tool to pull atlaskit version history from a repo",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"