@atlaskit/dependency-version-analytics 0.4.1 → 1.0.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 (45) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/cjs/cli.js +4 -18
  3. package/dist/cjs/commands/populate-historic-data/index.js +0 -3
  4. package/dist/cjs/commands/populate-historic-data/lib/dependency-store.js +24 -141
  5. package/dist/cjs/commands/populate-historic-data/package.js +3 -27
  6. package/dist/cjs/commands/populate-historic-data/product.js +15 -88
  7. package/dist/cjs/commands/populate-historic-data/util/generate-csv.js +4 -16
  8. package/dist/cjs/index.js +0 -2
  9. package/dist/cjs/util/analytics.js +0 -38
  10. package/dist/cjs/util/assert.js +0 -1
  11. package/dist/cjs/util/env-with-guard.js +0 -2
  12. package/dist/cjs/util/get-file-history-from-git.js +0 -5
  13. package/dist/cjs/util/get-package-version-history.js +0 -6
  14. package/dist/cjs/util/git.js +20 -58
  15. package/dist/cjs/util/statlas.js +0 -25
  16. package/dist/cjs/util/yarn.js +0 -32
  17. package/dist/cjs/version.json +1 -1
  18. package/dist/es2019/cli.js +4 -8
  19. package/dist/es2019/commands/populate-historic-data/lib/dependency-store.js +24 -73
  20. package/dist/es2019/commands/populate-historic-data/package.js +0 -8
  21. package/dist/es2019/commands/populate-historic-data/product.js +4 -22
  22. package/dist/es2019/commands/populate-historic-data/util/generate-csv.js +2 -9
  23. package/dist/es2019/util/analytics.js +4 -19
  24. package/dist/es2019/util/env-with-guard.js +0 -1
  25. package/dist/es2019/util/get-file-history-from-git.js +2 -3
  26. package/dist/es2019/util/get-package-version-history.js +0 -4
  27. package/dist/es2019/util/git.js +29 -24
  28. package/dist/es2019/util/statlas.js +0 -6
  29. package/dist/es2019/util/yarn.js +2 -11
  30. package/dist/es2019/version.json +1 -1
  31. package/dist/esm/cli.js +6 -12
  32. package/dist/esm/commands/populate-historic-data/lib/dependency-store.js +27 -131
  33. package/dist/esm/commands/populate-historic-data/package.js +3 -20
  34. package/dist/esm/commands/populate-historic-data/product.js +15 -72
  35. package/dist/esm/commands/populate-historic-data/util/generate-csv.js +4 -13
  36. package/dist/esm/util/analytics.js +2 -28
  37. package/dist/esm/util/env-with-guard.js +0 -1
  38. package/dist/esm/util/get-file-history-from-git.js +2 -3
  39. package/dist/esm/util/get-package-version-history.js +0 -4
  40. package/dist/esm/util/git.js +21 -50
  41. package/dist/esm/util/statlas.js +0 -19
  42. package/dist/esm/util/yarn.js +0 -19
  43. package/dist/esm/version.json +1 -1
  44. package/package.json +4 -4
  45. package/report.api.md +1 -1
@@ -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.1",
3
+ "version": "1.0.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
  }