fix write access error of the update-notifier

Signed-off-by: Pierre Noël <petersg83@gmail.com>
This commit is contained in:
Pierre Noël 2020-11-10 18:11:58 +01:00
parent e44dae0a42
commit 1be4237e4c

View File

@ -1,12 +1,15 @@
'use strict'; 'use strict';
const path = require('path');
const packageJson = require('package-json'); const packageJson = require('package-json');
const Configstore = require('configstore'); const Configstore = require('configstore');
const semver = require('semver'); const semver = require('semver');
const boxen = require('boxen'); const boxen = require('boxen');
const chalk = require('chalk'); const chalk = require('chalk');
const path = require('path');
const pkg = require('../../../package');
const { env } = require('strapi-utils'); const { env } = require('strapi-utils');
const pkg = require('../../../package');
const CHECK_INTERVAL = 1000 * 60 * 60 * 24 * 1; // 1 day const CHECK_INTERVAL = 1000 * 60 * 60 * 24 * 1; // 1 day
const NOTIF_INTERVAL = 1000 * 60 * 60 * 24 * 7; // 1 week const NOTIF_INTERVAL = 1000 * 60 * 60 * 24 * 7; // 1 week
const boxenOptions = { const boxenOptions = {
@ -29,11 +32,18 @@ Check out the new the releases at: ${releaseLink}
}; };
const createUpdateNotifier = strapi => { const createUpdateNotifier = strapi => {
const config = new Configstore( let config = null;
try {
config = new Configstore(
pkg.name, pkg.name,
{}, {},
{ configPath: path.join(strapi.dir, '.strapi-updater.json') } { configPath: path.join(strapi.dir, '.strapi-updater.json') }
); );
} catch {
// we don't have write access to the file system
// we silence the error
}
const checkUpdate = async checkInterval => { const checkUpdate = async checkInterval => {
const now = Date.now(); const now = Date.now();
@ -74,7 +84,7 @@ const createUpdateNotifier = strapi => {
return { return {
notify({ checkInterval = CHECK_INTERVAL, notifInterval = NOTIF_INTERVAL } = {}) { notify({ checkInterval = CHECK_INTERVAL, notifInterval = NOTIF_INTERVAL } = {}) {
if (env.bool('STRAPI_DISABLE_UPDATE_NOTIFICATION', false)) { if (env.bool('STRAPI_DISABLE_UPDATE_NOTIFICATION', false) || !config) {
return; return;
} }
display(notifInterval); display(notifInterval);