@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.
Files changed (50) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +2 -1
  3. package/dist/cjs/cli.js +4 -18
  4. package/dist/cjs/commands/populate-historic-data/index.js +0 -3
  5. package/dist/cjs/commands/populate-historic-data/lib/dependency-store.js +24 -141
  6. package/dist/cjs/commands/populate-historic-data/package.js +8 -29
  7. package/dist/cjs/commands/populate-historic-data/product.js +114 -150
  8. package/dist/cjs/commands/populate-historic-data/util/generate-csv.js +4 -16
  9. package/dist/cjs/index.js +0 -2
  10. package/dist/cjs/util/analytics.js +16 -41
  11. package/dist/cjs/util/assert.js +0 -1
  12. package/dist/cjs/util/env-with-guard.js +0 -2
  13. package/dist/cjs/util/get-file-history-from-git.js +0 -5
  14. package/dist/cjs/util/get-package-version-history.js +8 -10
  15. package/dist/cjs/util/git.js +20 -58
  16. package/dist/cjs/util/statlas.js +0 -25
  17. package/dist/cjs/util/yarn.js +0 -32
  18. package/dist/cjs/version.json +1 -1
  19. package/dist/es2019/cli.js +4 -8
  20. package/dist/es2019/commands/populate-historic-data/lib/dependency-store.js +24 -73
  21. package/dist/es2019/commands/populate-historic-data/package.js +7 -12
  22. package/dist/es2019/commands/populate-historic-data/product.js +21 -23
  23. package/dist/es2019/commands/populate-historic-data/util/generate-csv.js +2 -9
  24. package/dist/es2019/util/analytics.js +17 -19
  25. package/dist/es2019/util/env-with-guard.js +0 -1
  26. package/dist/es2019/util/get-file-history-from-git.js +2 -3
  27. package/dist/es2019/util/get-package-version-history.js +7 -7
  28. package/dist/es2019/util/git.js +29 -24
  29. package/dist/es2019/util/statlas.js +0 -6
  30. package/dist/es2019/util/yarn.js +2 -11
  31. package/dist/es2019/version.json +1 -1
  32. package/dist/esm/cli.js +6 -12
  33. package/dist/esm/commands/populate-historic-data/lib/dependency-store.js +27 -131
  34. package/dist/esm/commands/populate-historic-data/package.js +10 -24
  35. package/dist/esm/commands/populate-historic-data/product.js +114 -134
  36. package/dist/esm/commands/populate-historic-data/util/generate-csv.js +4 -13
  37. package/dist/esm/util/analytics.js +18 -31
  38. package/dist/esm/util/env-with-guard.js +0 -1
  39. package/dist/esm/util/get-file-history-from-git.js +2 -3
  40. package/dist/esm/util/get-package-version-history.js +7 -7
  41. package/dist/esm/util/git.js +21 -50
  42. package/dist/esm/util/statlas.js +0 -19
  43. package/dist/esm/util/yarn.js +0 -19
  44. package/dist/esm/version.json +1 -1
  45. package/dist/types/types.d.ts +7 -0
  46. package/dist/types/util/analytics.d.ts +2 -1
  47. package/dist/types/util/get-package-version-history.d.ts +7 -3
  48. package/package.json +3 -3
  49. package/report.api.md +5 -1
  50. package/tmp/api-report-tmp.d.ts +4 -0
@@ -6,7 +6,7 @@ import * as statlas from '../../util/statlas';
6
6
  import { generateCSV } from './util/generate-csv';
7
7
  import { assert } from '../../util/assert';
8
8
  import { DependencyStore } from './lib/dependency-store';
9
-
9
+ import getPackageVersionHistoryAndTags from '../../util/get-package-version-history';
10
10
  const getUpgradeEventsFromPkgChange = (oldDeps, newDeps, {
11
11
  date,
12
12
  commitHash
@@ -15,9 +15,9 @@ const getUpgradeEventsFromPkgChange = (oldDeps, newDeps, {
15
15
  version,
16
16
  type
17
17
  }]) => {
18
- const prevDep = oldDeps[name]; // Only treat a dependency as previous if the dependency type matches
18
+ const prevDep = oldDeps[name];
19
+ // Only treat a dependency as previous if the dependency type matches
19
20
  // Otherwise, we want separate add/remove events
20
-
21
21
  const prevVersion = prevDep && prevDep.type === type ? prevDep.version : undefined;
22
22
  return createUpgradeEvent(name, version, prevVersion, date, {
23
23
  commitHash,
@@ -27,7 +27,8 @@ const getUpgradeEventsFromPkgChange = (oldDeps, newDeps, {
27
27
  }).filter(e => e != null);
28
28
  const removeEvents = Object.entries(oldDeps).filter(([name, {
29
29
  type
30
- }]) => // Treat the same dep under a different dependency type as a new dep
30
+ }]) =>
31
+ // Treat the same dep under a different dependency type as a new dep
31
32
  newDeps[name] == null || newDeps[name].type !== type).map(([name, {
32
33
  version,
33
34
  type
@@ -40,23 +41,19 @@ const getUpgradeEventsFromPkgChange = (oldDeps, newDeps, {
40
41
  }).filter(e => e != null);
41
42
  return [...addOrUpgradeEvents, ...removeEvents];
42
43
  };
43
-
44
44
  const getEventsFromHistory = async (packageChangesLog, prevRunHash, {
45
45
  cwd
46
46
  }) => {
47
47
  const allPackageChanges = [];
48
- const allUpgradeEvents = [];
48
+ let allUpgradeEvents = [];
49
49
  assert(packageChangesLog.all.length > 0, '');
50
50
  let dependencyStore = new DependencyStore(cwd);
51
51
  let dependencies = await dependencyStore.initialise(prevRunHash);
52
-
53
52
  for (let i = 0; i < packageChangesLog.all.length; i++) {
54
53
  let item = packageChangesLog.all[i];
55
-
56
54
  if (allPackageChanges.length > 0) {
57
55
  dependencies = allPackageChanges[allPackageChanges.length - 1].akDeps;
58
56
  }
59
-
60
57
  const newDependencies = await dependencyStore.update(item);
61
58
  const packageChange = {
62
59
  date: new Date(item.date).toISOString(),
@@ -66,69 +63,71 @@ const getEventsFromHistory = async (packageChangesLog, prevRunHash, {
66
63
  date: packageChange.date,
67
64
  commitHash: item.hash
68
65
  });
69
-
70
66
  if (upgradeEvents.length > 0) {
71
67
  allUpgradeEvents.push(...upgradeEvents);
72
68
  allPackageChanges.push(packageChange);
73
69
  }
74
70
  }
75
-
71
+ // add dist-tags to upgrade event
72
+ allUpgradeEvents = await Promise.all(allUpgradeEvents.map(async upgradeEvent => {
73
+ var _distTags$hotfix, _distTags$latest, _distTags$next;
74
+ const getPackageTags = await getPackageVersionHistoryAndTags(upgradeEvent.dependencyName);
75
+ const distTags = getPackageTags['dist-tags'];
76
+ Object.keys(distTags).forEach(key => {
77
+ if (key.startsWith('rc')) {
78
+ upgradeEvent.rcTag = distTags[key];
79
+ }
80
+ });
81
+ upgradeEvent.hotfixTag = (_distTags$hotfix = distTags['hotfix']) !== null && _distTags$hotfix !== void 0 ? _distTags$hotfix : null;
82
+ upgradeEvent.latestTag = (_distTags$latest = distTags['latest']) !== null && _distTags$latest !== void 0 ? _distTags$latest : null;
83
+ upgradeEvent.nextTag = (_distTags$next = distTags['next']) !== null && _distTags$next !== void 0 ? _distTags$next : null;
84
+ return upgradeEvent;
85
+ }));
76
86
  return {
77
87
  allPackageChanges,
78
88
  allUpgradeEvents
79
89
  };
80
90
  };
81
-
82
91
  async function getSinceRef(flags) {
83
92
  if (flags.statlas) {
84
93
  const meta = await statlas.getMeta(flags.product);
85
-
86
94
  if (!meta || !meta.lastRunHash) {
87
95
  throw new Error(chalk.red(`Missing or invalid metadata file for ${flags.product}. Must use --reset for populating from start of history`));
88
96
  }
89
-
90
97
  return meta.lastRunHash;
91
98
  } else {
92
99
  const tag = flags.tag || DEFAULT_TAG;
93
100
  await refetchTag(tag);
94
101
  const tagExists = await doesTagExist(tag);
95
-
96
102
  if (!tagExists) {
97
103
  throw new Error(chalk.red(`Tag '${tag}' does not exist. Must use --reset for populating from start of history.`));
98
104
  }
99
-
100
105
  return tag;
101
106
  }
102
107
  }
103
-
104
108
  export default async function populateProduct(flags) {
105
109
  const cwd = flags.cwd || process.cwd();
106
110
  const sinceRef = flags.reset ? undefined : await getSinceRef(flags);
107
111
  const log = await getChangesSince(sinceRef);
108
-
109
112
  if (log.all.length === 0) {
110
113
  console.log(`No package.json changes found since '${sinceRef}'.`);
111
114
  return;
112
115
  }
113
-
114
116
  const {
115
117
  allPackageChanges,
116
118
  allUpgradeEvents
117
119
  } = await getEventsFromHistory(log, sinceRef, {
118
120
  cwd
119
121
  });
120
-
121
122
  if (flags.csv) {
122
123
  const csv = generateCSV(allPackageChanges);
123
124
  console.log(csv);
124
125
  return;
125
126
  }
126
-
127
127
  if (flags.dryRun) {
128
128
  console.log(JSON.stringify(allUpgradeEvents));
129
129
  return;
130
130
  }
131
-
132
131
  if (allUpgradeEvents.length > 0) {
133
132
  await sendAnalytics(allUpgradeEvents, {
134
133
  dev: flags.dev,
@@ -139,7 +138,6 @@ export default async function populateProduct(flags) {
139
138
  } else {
140
139
  console.log(`Found no AK dependency changes since last run from ref "${sinceRef}"'`);
141
140
  }
142
-
143
141
  if (flags.statlas) {
144
142
  // Upload latest commit to statlas
145
143
  const currentCommit = await getHash('HEAD');
@@ -8,16 +8,14 @@ export const generateCSV = packageChanges => {
8
8
  version
9
9
  }]) => {
10
10
  let depColumnIndex = csvData.findIndex(item => item[0] === name);
11
-
12
11
  if (depColumnIndex === -1) {
13
12
  depColumnIndex = csvData.push([name]) - 1;
14
- } // console.log(csvData)
15
-
13
+ }
16
14
 
15
+ // console.log(csvData)
17
16
  csvData[depColumnIndex][currentRow] = version;
18
17
  });
19
18
  });
20
-
21
19
  for (let i = 0; i < csvData.length; i++) {
22
20
  for (let j = 0; j < csvData.length; j++) {
23
21
  if (typeof csvData[i][j] !== 'string') {
@@ -25,23 +23,18 @@ export const generateCSV = packageChanges => {
25
23
  csvData[i][j] = '';
26
24
  }
27
25
  }
28
-
29
26
  if (i !== 0 && csvData[0].length < csvData[i].length) {}
30
27
  }
31
-
32
28
  const csvStrings = [];
33
29
  csvData.forEach(column => {
34
30
  if (!column) {
35
31
  return;
36
32
  }
37
-
38
33
  for (let rowIndex = 0; rowIndex < csvData[0].length; rowIndex++) {
39
34
  const rowItem = column[rowIndex] || '';
40
-
41
35
  if (typeof csvStrings[rowIndex] !== 'string') {
42
36
  csvStrings[rowIndex] = '';
43
37
  }
44
-
45
38
  csvStrings[rowIndex] += `"${rowItem}",`;
46
39
  }
47
40
  });
@@ -1,12 +1,10 @@
1
- import chalk from 'chalk'; // @ts-ignore
2
-
1
+ import chalk from 'chalk';
2
+ // @ts-ignore
3
3
  import inquirer from 'inquirer';
4
4
  import semver from 'semver';
5
5
  /* eslint-disable-next-line import/no-unresolved */
6
-
7
6
  import { analyticsClient } from '@atlassiansox/analytics-node-client';
8
7
  import { version as packageVersion } from '../version.json';
9
-
10
8
  function getUpgradeType(version, previousVersion) {
11
9
  if (previousVersion == null && version != null) {
12
10
  return 'add';
@@ -15,12 +13,10 @@ function getUpgradeType(version, previousVersion) {
15
13
  } else if (previousVersion != null && version != null && previousVersion !== version) {
16
14
  const coercedPrevious = semver.coerce(previousVersion);
17
15
  const coercedNew = semver.coerce(version);
18
-
19
16
  if (coercedNew == null) {
20
17
  console.error(`Found invalid version "${version}", skipping`);
21
18
  return null;
22
19
  }
23
-
24
20
  if (coercedPrevious != null && semver.lt(coercedNew, coercedPrevious)) {
25
21
  return 'downgrade';
26
22
  } else {
@@ -30,39 +26,39 @@ function getUpgradeType(version, previousVersion) {
30
26
  return null;
31
27
  }
32
28
  }
33
-
34
29
  function getUpgradeSubType(version, previousVersion) {
35
30
  let upgradeSubType = null;
36
-
37
31
  if (version == null || previousVersion == null) {
38
32
  return upgradeSubType;
39
33
  }
40
-
41
34
  const parsedOld = semver.coerce(previousVersion);
42
35
  const parsedNew = semver.coerce(version);
43
-
44
36
  if (parsedOld && parsedNew) {
45
37
  upgradeSubType = semver.diff(parsedOld.version, parsedNew.version);
46
38
  }
47
-
48
39
  return upgradeSubType;
49
40
  }
50
-
51
41
  export function createUpgradeEvent(name, version, previousVersion, date, optionalArgs = {}) {
42
+ var _optionalArgs$tags, _ref, _tags$next, _tags$hotfix, _ref2;
52
43
  if (Number.isNaN(Date.parse(date))) {
53
44
  throw new Error(`Invalid date: '${date}'`);
54
45
  }
55
-
56
46
  const upgradeType = getUpgradeType(version, previousVersion);
57
-
58
47
  if (!upgradeType) {
59
48
  // Not an upgrade for this dependency, return null
60
49
  return null;
61
50
  }
62
-
63
51
  const upgradeSubType = getUpgradeSubType(version, previousVersion);
64
52
  const eventVersion = upgradeType !== 'remove' ? version : previousVersion;
65
53
  const parsedVersion = semver.coerce(eventVersion);
54
+ let rcKey = null;
55
+ const tags = (_optionalArgs$tags = optionalArgs === null || optionalArgs === void 0 ? void 0 : optionalArgs.tags) !== null && _optionalArgs$tags !== void 0 ? _optionalArgs$tags : {};
56
+ Object.keys(tags).forEach(key => {
57
+ if (key.startsWith('rc')) {
58
+ rcKey = key;
59
+ return;
60
+ }
61
+ });
66
62
  return {
67
63
  cliVersion: packageVersion,
68
64
  dependencyName: name,
@@ -73,6 +69,10 @@ export function createUpgradeEvent(name, version, previousVersion, date, optiona
73
69
  date: new Date(date).toISOString(),
74
70
  upgradeType,
75
71
  upgradeSubType,
72
+ latestTag: (_ref = tags && tags['latest']) !== null && _ref !== void 0 ? _ref : null,
73
+ nextTag: (_tags$next = tags['next']) !== null && _tags$next !== void 0 ? _tags$next : null,
74
+ hotfixTag: (_tags$hotfix = tags['hotfix']) !== null && _tags$hotfix !== void 0 ? _tags$hotfix : null,
75
+ rcTag: (_ref2 = rcKey && tags[rcKey]) !== null && _ref2 !== void 0 ? _ref2 : null,
76
76
  ...optionalArgs
77
77
  };
78
78
  }
@@ -88,7 +88,6 @@ export async function sendAnalytics(analyticsEvents, {
88
88
  env: dev ? 'dev' : 'prod',
89
89
  product: product
90
90
  });
91
-
92
91
  if (!skipPrompt) {
93
92
  const answers = await inquirer.prompt([{
94
93
  type: 'confirm',
@@ -96,13 +95,11 @@ export async function sendAnalytics(analyticsEvents, {
96
95
  message: `Are you sure you want to send ${eventsToSend.length} historical analytics events to '${analyticsEnv}' env for product '${product}?`,
97
96
  default: false
98
97
  }]);
99
-
100
98
  if (!answers.continue) {
101
99
  console.log('Aborting');
102
100
  process.exit(0);
103
101
  }
104
102
  }
105
-
106
103
  try {
107
104
  const promises = await Promise.all(eventsToSend.map(event => {
108
105
  return client.sendTrackEvent({
@@ -112,7 +109,8 @@ export async function sendAnalytics(analyticsEvents, {
112
109
  source: '@atlaskit/dependency-version-analytics',
113
110
  action: 'upgraded',
114
111
  actionSubject: 'akDependency',
115
- attributes: { ...event
112
+ attributes: {
113
+ ...event
116
114
  },
117
115
  origin: 'console',
118
116
  platform: 'bot'
@@ -2,6 +2,5 @@ export default function (name) {
2
2
  if (!process.env.hasOwnProperty(name) || !process.env[name] || typeof process.env[name] !== 'string') {
3
3
  return null;
4
4
  }
5
-
6
5
  return process.env[name];
7
6
  }
@@ -1,5 +1,6 @@
1
- import { exec } from 'child_process'; // Lock files tend to be huge
1
+ import { exec } from 'child_process';
2
2
 
3
+ // Lock files tend to be huge
3
4
  const FiveMBBuffer = 1024 * 5000;
4
5
  export default function getFileHistoryFromGit(fileName) {
5
6
  return new Promise((resolve, reject) => {
@@ -9,11 +10,9 @@ export default function getFileHistoryFromGit(fileName) {
9
10
  if (error) {
10
11
  reject(error);
11
12
  }
12
-
13
13
  if (stderr) {
14
14
  reject(stderr);
15
15
  }
16
-
17
16
  resolve(stdout);
18
17
  });
19
18
  });
@@ -1,23 +1,23 @@
1
1
  import { exec } from 'child_process';
2
- export default function getPackageVersionHistory(packageName) {
2
+ export default function getPackageVersionHistoryAndTags(packageName) {
3
3
  return new Promise((resolve, reject) => {
4
- exec(`yarn info ${packageName} --json time`, (error, stdout, stderr) => {
4
+ exec(`yarn info ${packageName} --json`, (error, stdout, stderr) => {
5
5
  if (error) {
6
6
  reject(error);
7
7
  }
8
-
9
8
  if (stderr) {
10
9
  reject(stderr);
11
10
  }
12
-
13
11
  let json;
14
-
15
12
  try {
16
- json = JSON.parse(stdout).data;
13
+ const parseData = JSON.parse(stdout).data;
14
+ json = {
15
+ time: parseData['time'],
16
+ 'dist-tags': parseData['dist-tags']
17
+ };
17
18
  } catch (e) {
18
19
  reject(`Error parsing json output: ${e}`);
19
20
  }
20
-
21
21
  resolve(json);
22
22
  });
23
23
  });
@@ -1,35 +1,40 @@
1
1
  // @ts-ignore
2
+
2
3
  import git from 'simple-git';
3
4
  import { assert } from './assert';
4
5
  export async function getChangesSince(since) {
5
6
  const revisionRange = since ? [`${since}..`] : [];
6
- const listLogSummary = await git().log([// Only commits on mainline master
7
- '--first-parent', // Show merge commit contents
8
- '-m', // Reverse the order
9
- '--reverse', // Show filename changes - simple-git parses --stat flag but not --name-only unfortunately
10
- '--stat=4096', // Make +- graph width as small as possible to maximise filename length
11
- '--stat-graph-width=1', ...revisionRange, // Any commit that modifies a package.json
7
+ const listLogSummary = await git().log([
8
+ // Only commits on mainline master
9
+ '--first-parent',
10
+ // Show merge commit contents
11
+ '-m',
12
+ // Reverse the order
13
+ '--reverse',
14
+ // Show filename changes - simple-git parses --stat flag but not --name-only unfortunately
15
+ '--stat=4096',
16
+ // Make +- graph width as small as possible to maximise filename length
17
+ '--stat-graph-width=1', ...revisionRange,
18
+ // Any commit that modifies a package.json
12
19
  ':(glob)**/package.json']);
13
- return { ...listLogSummary,
20
+ return {
21
+ ...listLogSummary,
14
22
  all: listLogSummary.all.map(logLine => parseLogLine(logLine))
15
23
  };
16
24
  }
17
-
18
25
  function parseLogLine(logLine) {
19
26
  if (!logLine.diff) {
20
27
  return logLine;
21
- } // Split files into separate entries when a rename has occurred so both old and new files are processed
22
-
28
+ }
23
29
 
30
+ // Split files into separate entries when a rename has occurred so both old and new files are processed
24
31
  const parsedDiffFiles = logLine.diff.files.reduce((acc, curr) => {
25
32
  const renameArrowCount = curr.file.match(/ => /g);
26
-
27
33
  if (renameArrowCount == null) {
28
34
  return [...acc, curr];
29
- } // Multiple rename parts are not supported. They most likely don't exist in git but we check
35
+ }
36
+ // Multiple rename parts are not supported. They most likely don't exist in git but we check
30
37
  // for them anyway just in case
31
-
32
-
33
38
  assert(renameArrowCount.length === 1, `Multiple rename parts detected: ${curr.file}`);
34
39
  /* Matches:
35
40
  * - '{new-frontend/src => src}/package.json'
@@ -37,25 +42,28 @@ function parseLogLine(logLine) {
37
42
  * - 'src/{ => platform}/analytics/package.json'
38
43
  * - 'src/packages/spa/{main => }/package.json'
39
44
  */
40
-
41
45
  const renameMatch = curr.file.match(/\{?([^{]+)? => ([^}]+)?\}?/);
42
46
  assert(renameMatch != null, `Invalid rename format ${curr.file}`);
43
- const oldFile = curr.file.replace(renameMatch[0], renameMatch[1] || '') // If the previous name segment is empty, we will have a double slash
47
+ const oldFile = curr.file.replace(renameMatch[0], renameMatch[1] || '')
48
+ // If the previous name segment is empty, we will have a double slash
44
49
  .replace('//', '/');
45
50
  const newFile = curr.file.replace(renameMatch[0], renameMatch[2] || '').replace('//', '/');
46
- return [...acc, { ...curr,
51
+ return [...acc, {
52
+ ...curr,
47
53
  file: oldFile
48
- }, { ...curr,
54
+ }, {
55
+ ...curr,
49
56
  file: newFile
50
57
  }];
51
58
  }, []);
52
- return { ...logLine,
53
- diff: { ...logLine.diff,
59
+ return {
60
+ ...logLine,
61
+ diff: {
62
+ ...logLine.diff,
54
63
  files: parsedDiffFiles
55
64
  }
56
65
  };
57
66
  }
58
-
59
67
  export async function tagCommit(tag) {
60
68
  return git().tag(['-f', tag]);
61
69
  }
@@ -74,9 +82,7 @@ export async function refetchTag(tag) {
74
82
  throw e;
75
83
  }
76
84
  }
77
-
78
85
  let fetchTagResult;
79
-
80
86
  try {
81
87
  fetchTagResult = await git().fetch(['origin', 'tag', tag]);
82
88
  } catch (e) {
@@ -85,7 +91,6 @@ export async function refetchTag(tag) {
85
91
  throw e;
86
92
  }
87
93
  }
88
-
89
94
  return {
90
95
  fetchTagResult
91
96
  };
@@ -9,25 +9,20 @@ export function uploadMeta(product, lastRunHash) {
9
9
  lastRunHash
10
10
  });
11
11
  }
12
-
13
12
  function getProductMetaPath(product) {
14
13
  return `product/${product}.json`;
15
14
  }
16
-
17
15
  async function retrieveJSON(filepath) {
18
16
  const response = await fetch(`${STATLAS_BASE_URL}/${filepath}?statlasredirect`);
19
17
  let json = null;
20
-
21
18
  if (response.ok) {
22
19
  json = await response.json();
23
20
  }
24
-
25
21
  return {
26
22
  json,
27
23
  rawResponse: response
28
24
  };
29
25
  }
30
-
31
26
  async function uploadJSON(filepath, json) {
32
27
  const res = await fetch(`${STATLAS_BASE_URL}/${filepath}`, {
33
28
  method: 'PUT',
@@ -36,7 +31,6 @@ async function uploadJSON(filepath, json) {
36
31
  Authorization: `Bearer ${process.env.bamboo_JWT_TOKEN}`
37
32
  }
38
33
  });
39
-
40
34
  if (!res.ok) {
41
35
  throw new Error(`Statlas upload failed: ${res.statusText}`);
42
36
  }
@@ -6,7 +6,6 @@ const rootPackageJsonPath = 'package.json';
6
6
  const debug = debugModule('atlaskit:yarn');
7
7
  export async function getWorkspaceGlobs(ref, cwd) {
8
8
  let file;
9
-
10
9
  try {
11
10
  file = await git.showFile(ref, rootPackageJsonPath, {
12
11
  cwd
@@ -15,23 +14,18 @@ export async function getWorkspaceGlobs(ref, cwd) {
15
14
  debug(`${rootPackageJsonPath} does not exist`);
16
15
  return new Set([]);
17
16
  }
18
-
19
17
  let rootPackageJsonFile;
20
-
21
18
  try {
22
19
  rootPackageJsonFile = JSON.parse(file);
23
20
  } catch (e) {
24
21
  console.error(`Error parsing ${file}@${ref}: ${e}`);
25
22
  return null;
26
23
  }
27
-
28
24
  const workspaces = rootPackageJsonFile.workspaces;
29
-
30
25
  if (!workspaces) {
31
26
  return new Set([rootPackageJsonPath]);
32
- } // There are actually two formats for workspaces and they are poorly documented
33
-
34
-
27
+ }
28
+ // There are actually two formats for workspaces and they are poorly documented
35
29
  const workspacePackages = Array.isArray(workspaces) ? workspaces : workspaces.packages;
36
30
  return new Set([rootPackageJsonPath, ...workspacePackages.map(glob => path.join(glob, 'package.json'))]);
37
31
  }
@@ -39,15 +33,12 @@ export async function getWorkspacePaths(ref, workspaceGlobs, cwd) {
39
33
  if (workspaceGlobs.size === 0) {
40
34
  return [];
41
35
  }
42
-
43
36
  const workspacePackageJsons = await git.getFiles(ref, '**/package.json', {
44
37
  cwd
45
38
  });
46
39
  const matchedWorkspaces = micromatch(workspacePackageJsons, [...workspaceGlobs]);
47
-
48
40
  if (matchedWorkspaces.length === 0) {
49
41
  throw new Error(`Could not find any workspace or package.json under ${cwd}`);
50
42
  }
51
-
52
43
  return matchedWorkspaces;
53
44
  }
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/dependency-version-analytics",
3
- "version": "0.4.2",
3
+ "version": "1.1.0",
4
4
  "sideEffects": false
5
5
  }
package/dist/esm/cli.js CHANGED
@@ -1,9 +1,11 @@
1
1
  import _toArray from "@babel/runtime/helpers/toArray";
2
2
  /// <reference lib="es2017.object" />
3
+
3
4
  import chalk from 'chalk';
4
5
  import meow from 'meow';
5
- import { populateProduct, populatePackage } from './commands/populate-historic-data'; // prettier-ignore
6
+ import { populateProduct, populatePackage } from './commands/populate-historic-data';
6
7
 
8
+ // prettier-ignore
7
9
  var HELP_MSG = "\n".concat(chalk.green('Global options'), "\n ").concat(chalk.yellow('--dev'), " Send analytics to dev analytics pipeline instead of prod\n ").concat(chalk.yellow('--dryRun'), " Performs a dry run, prints analytics events to console in JSON format instead of sending them\n ").concat(chalk.yellow('--limit'), " Limit the number of events sent, used for validation purposes\n ").concat(chalk.yellow('--no-interactive'), " Disable any interactive prompts\n\n").concat(chalk.yellow.bold('[populate-product] <product>'), "\n Sends analytics events for atlaskit dependency versions changes in package.json.\n\n Detects changes since the last time the tool was run by storing the last run in either statlas (--statlas flag) or using the\n 'atlaskit-dependency-version-analytics-last-run' git tag.\n If running the tool for the first time (last run does not exist), --reset must be used to detect changes since the beginning of the repo.\n\n ").concat(chalk.green('Options'), "\n ").concat(chalk.yellow('--csv'), " Prints AK dependency history in CSV format\n ").concat(chalk.yellow('--reset'), " Reset change detection to detect changes from the beginning of time\n ").concat(chalk.yellow('--tag'), " Specify a different tag to mark when the tool was last run\n ").concat(chalk.yellow('--statlas'), " Use statlas rather than git tags for storing and sourcing last run info\n\n ").concat(chalk.green('Examples'), "\n ").concat(chalk.dim('$ atlaskit-version-analytics populate-product jira'), "\n\n").concat(chalk.yellow.bold('[populate-package] <package>'), "\n Sends analytics events for published versions of the specified atlaskit package.\n\n ").concat(chalk.green('Options'), "\n ").concat(chalk.yellow('--since'), " Only publish versions since the following JS date string (exclusive)\n\n ").concat(chalk.green('Examples'), "\n ").concat(chalk.dim('$ atlaskit-version-analytics populate-package @atlaskit/button'), "\n");
8
10
  export function run(_ref) {
9
11
  var dev = _ref.dev;
@@ -40,21 +42,16 @@ export function run(_ref) {
40
42
  }
41
43
  }
42
44
  });
43
-
44
45
  var _cli$input = _toArray(cli.input),
45
- command = _cli$input[0],
46
- inputs = _cli$input.slice(1);
47
-
46
+ command = _cli$input[0],
47
+ inputs = _cli$input.slice(1);
48
48
  var limit = cli.flags.limit != null ? +cli.flags.limit : undefined;
49
-
50
49
  if (command === 'populate-product') {
51
50
  var product = inputs[0];
52
-
53
51
  if (!product) {
54
52
  console.error(chalk.red('Must pass a product parameter'));
55
53
  process.exit(1);
56
54
  }
57
-
58
55
  return populateProduct({
59
56
  csv: cli.flags.csv || false,
60
57
  dev: dev || cli.flags.dev || false,
@@ -68,12 +65,10 @@ export function run(_ref) {
68
65
  });
69
66
  } else if (command === 'populate-package') {
70
67
  var pkg = inputs[0];
71
-
72
68
  if (!pkg) {
73
69
  console.error(chalk.red('Must pass a package parameter'));
74
70
  process.exit(1);
75
71
  }
76
-
77
72
  return populatePackage({
78
73
  dev: dev || cli.flags.dev || false,
79
74
  dryRun: cli.flags.dryRun || false,
@@ -83,8 +78,7 @@ export function run(_ref) {
83
78
  since: cli.flags.since
84
79
  });
85
80
  }
86
- /* eslint-disable no-console */
87
-
88
81
 
82
+ /* eslint-disable no-console */
89
83
  return Promise.resolve(console.log(cli.help));
90
84
  }