Skip to content

Commit

Permalink
feat: removes npm update prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
thisislawatts committed Oct 17, 2019
1 parent adbeef9 commit b25335b
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .releaserc
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
{
"prepare": [
"@semantic-release/npm",
{
"//": "adds a file to identify a build as a standalone binary",
"path": "@semantic-release/exec",
"cmd": "echo '' > dist/STANDALONE"
},
{
"//": "build the alpine, macos, linux and windows binaries",
"path": "@semantic-release/exec",
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@
"assets": [
"config.default.json",
"test-unpublished.json",
"help/**/*.txt"
"help/**/*.txt",
"dist/STANDALONE"
]
}
}
7 changes: 7 additions & 0 deletions src/lib/updater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ export function updateCheck() {
return false;
}

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

if (isStandaloneBuild) {
return false;
}

const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));

// if there's no version (f.e. during tests) - do not proceed
Expand Down
28 changes: 20 additions & 8 deletions test/updater.test.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
const tap = require('tap');
const test = tap.test;
const updateCheck = require('../src/lib/updater').updateCheck;
const path = require('path');
const fs = require('fs');
const p = require('path');
const sinon = require('sinon').createSandbox();
const updateNotifier = require('update-notifier');

// Fake location of the package.json file and verify the code behaves well
test('missing package.json', (t) => {
t.plan(1);
let resolveStub = sinon.stub(path, 'resolve');
resolveStub.onFirstCall().returns('falseDir');
resolveStub.onSecondCall().returns('falseFile');
const fsStub = sinon.stub(fs, 'existsSync');
fsStub.withArgs(p.join(__dirname, '../', 'package.json')).returns(false);

t.tearDown(() => {
resolveStub.restore();
fsStub.restore();
});

t.equal(
Expand All @@ -24,9 +23,22 @@ test('missing package.json', (t) => {
t.end();
});

// Run updateNotifier API for the basic package. THe target is to verify API still stands
test('STANDALONE declaration present', (t) => {
const fsStub = sinon.stub(fs, 'existsSync');
fsStub.withArgs(p.join(__dirname, '../', 'package.json')).returns(true);
fsStub.withArgs(p.join(__dirname, '../src', 'STANDALONE')).returns(true);

t.tearDown(() => {
fsStub.restore();
});

t.equal(updateCheck(), false, 'Notifier was not started for binary build');
t.end();
});

// Run updateNotifier API for the basic package. The target is to verify API still stands
test('verify updater', (t) => {
var pkg = {
const pkg = {
name: 'snyk',
version: '1.0.0',
};
Expand Down

0 comments on commit b25335b

Please sign in to comment.