Skip to content

Commit

Permalink
Meta tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed May 21, 2017
1 parent e2f9233 commit 1055d57
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Expand Up @@ -7,6 +7,6 @@ charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[{package.json,*.yml}]
[*.yml]
indent_style = space
indent_size = 2
21 changes: 11 additions & 10 deletions index.js
Expand Up @@ -2,20 +2,21 @@
const spawn = require('child_process').spawn;
const path = require('path');
const format = require('util').format;
const lazyRequire = require('lazy-req')(require);

const configstore = lazyRequire('configstore');
const chalk = lazyRequire('chalk');
const semverDiff = lazyRequire('semver-diff');
const latestVersion = lazyRequire('latest-version');
const isNpm = lazyRequire('is-npm');
const boxen = lazyRequire('boxen');
const xdgBasedir = lazyRequire('xdg-basedir');
const importLazy = require('import-lazy')(require);

const configstore = importLazy('configstore');
const chalk = importLazy('chalk');
const semverDiff = importLazy('semver-diff');
const latestVersion = importLazy('latest-version');
const isNpm = importLazy('is-npm');
const boxen = importLazy('boxen');
const xdgBasedir = importLazy('xdg-basedir');
const ONE_DAY = 1000 * 60 * 60 * 24;

class UpdateNotifier {
constructor(options) {
this.options = options = options || {};
options = options || {};
this.options = options;
options.pkg = options.pkg || {};

// Reduce pkg to the essential keys. with fallback to deprecated options
Expand Down
6 changes: 3 additions & 3 deletions package.json
Expand Up @@ -36,17 +36,17 @@
"boxen": "^1.0.0",
"chalk": "^1.0.0",
"configstore": "^3.0.0",
"import-lazy": "^2.1.0",
"is-npm": "^1.0.0",
"latest-version": "^3.0.0",
"lazy-req": "^2.0.0",
"semver-diff": "^2.0.0",
"xdg-basedir": "^3.0.0"
},
"devDependencies": {
"clear-require": "^2.0.0",
"clear-module": "^2.1.0",
"fixture-stdout": "^0.2.1",
"mocha": "*",
"strip-ansi": "^3.0.1",
"xo": "^0.17.0"
"xo": "^0.18.2"
}
}
18 changes: 9 additions & 9 deletions test.js
Expand Up @@ -3,7 +3,7 @@
const assert = require('assert');
const fs = require('fs');
const util = require('util');
const clearRequire = require('clear-require');
const clearModule = require('clear-module');
const FixtureStdout = require('fixture-stdout');
const stripAnsi = require('strip-ansi');
let updateNotifier = require('.');
Expand Down Expand Up @@ -47,17 +47,17 @@ describe('updateNotifier', () => {

describe('updateNotifier with fs error', () => {
before(() => {
['./', 'configstore', 'xdg-basedir'].forEach(clearRequire);
['.', 'configstore', 'xdg-basedir'].forEach(clearModule);
// Set configstore.config to something
// that requires root access
process.env.XDG_CONFIG_HOME = '/usr';
updateNotifier = require('./');
updateNotifier = require('.');
});

after(() => {
['./', 'configstore', 'xdg-basedir'].forEach(clearRequire);
['.', 'configstore', 'xdg-basedir'].forEach(clearModule);
delete process.env.XDG_CONFIG_HOME;
updateNotifier = require('./');
updateNotifier = require('.');
});

it('should fail gracefully', () => {
Expand All @@ -78,23 +78,23 @@ describe('notify(opts)', () => {
let isTTYBefore;

before(() => {
['./', 'is-npm'].forEach(clearRequire);
['.', 'is-npm'].forEach(clearModule);
processEnvBefore = JSON.stringify(process.env);
isTTYBefore = process.stdout.isTTY;
['npm_config_username', 'npm_package_name', 'npm_config_heading'].forEach(name => {
delete process.env[name];
});
process.stdout.isTTY = true;
updateNotifier = require('./');
updateNotifier = require('.');
});

after(() => {
['./', 'is-npm'].forEach(clearRequire);
['.', 'is-npm'].forEach(clearModule);
process.env = JSON.parse(processEnvBefore);
process.stdout.isTTY = isTTYBefore;
processEnvBefore = undefined;
isTTYBefore = undefined;
updateNotifier = require('./');
updateNotifier = require('.');
});

function Control() {
Expand Down

0 comments on commit 1055d57

Please sign in to comment.