Skip to content

Commit

Permalink
feat: include standalone-ness in the analytics
Browse files Browse the repository at this point in the history
isStandaloneBuild is already tested by updater.test.ts, so don't
bother mocking this for the analytics.test, only check that it is included.

Tested manually with the --version changes on linux.
  • Loading branch information
FauxFaux committed May 27, 2020
1 parent 399c8a1 commit 7a5a2e0
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 6 deletions.
10 changes: 8 additions & 2 deletions src/cli/commands/version.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
import { getVersion } from '../../lib/version';
import { getVersion, isStandaloneBuild } from '../../lib/version';

export = getVersion;
export = async () => {
let version = await getVersion();
if (isStandaloneBuild()) {
version += ' (standalone)';
}
return version;
};
3 changes: 3 additions & 0 deletions src/lib/analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,16 @@ function postAnalytics(data) {
return Promise.resolve();
}

const isStandalone = version.isStandaloneBuild();

// get snyk version
return version
.getVersion()
.then((version) => {
data.version = version;
data.os = osName(os.platform(), os.release());
data.nodeVersion = process.version;
data.standalone = isStandalone;

const seed = uuid.v4();
const shasum = crypto.createHash('sha1');
Expand Down
6 changes: 2 additions & 4 deletions src/lib/updater.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as updateNotifier from 'update-notifier';
import * as fs from 'fs';
import * as p from 'path';
import { isStandaloneBuild } from './version';

export function updateCheck() {
const pkgPath = p.join(__dirname, '../..', 'package.json');
Expand All @@ -10,10 +11,7 @@ export function updateCheck() {
return false;
}

const standalonePath = p.join(__dirname, '../', 'STANDALONE');
const isStandaloneBuild = fs.existsSync(standalonePath);

if (isStandaloneBuild) {
if (isStandaloneBuild()) {
return false;
}

Expand Down
6 changes: 6 additions & 0 deletions src/lib/version.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as fs from 'fs';
import * as path from 'path';
import { executeCommand } from './exec';

Expand All @@ -20,6 +21,11 @@ export function getVersion(): Promise<string> {
});
}

export function isStandaloneBuild() {
const standalonePath = path.join(__dirname, '../', 'STANDALONE');
return fs.existsSync(standalonePath);
}

async function getBranchCommitAndDirty(promises): Promise<string> {
try {
const res: string[] = await Promise.all(promises);
Expand Down
3 changes: 3 additions & 0 deletions test/analytics.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ test('analytics', (t) => {
'metadata',
'args',
'nodeVersion',
'standalone',
'durationMs',
].sort(),
'keys as expected',
Expand Down Expand Up @@ -97,6 +98,7 @@ test('analytics with args', (t) => {
'metadata',
'args',
'nodeVersion',
'standalone',
'durationMs',
].sort(),
'keys as expected',
Expand Down Expand Up @@ -132,6 +134,7 @@ test('analytics with args and org', (t) => {
'metadata',
'args',
'nodeVersion',
'standalone',
'durationMs',
'org',
].sort(),
Expand Down

0 comments on commit 7a5a2e0

Please sign in to comment.