diff --git a/lib/index.js b/lib/index.js index ef3ceff..4248560 100644 --- a/lib/index.js +++ b/lib/index.js @@ -13,6 +13,7 @@ const isLocalPath = require('./utils/isLocalPath') const SAOError = require('./SAOError') const parseGenerator = require('./parseGenerator') const updateCheck = require('./updateCheck') +const store = require('./store') class SAO { /** @@ -64,11 +65,20 @@ class SAO { ? loaded.data : require(path.join(__dirname, 'saofile.fallback.js')) - if (!parent && this.opts.updateCheck) { - updateCheck({ - generator, - checkGenerator: config.updateCheck !== false && generator.type === 'npm' - }) + // Only run following code for root generator + if (!parent) { + if (this.opts.updateCheck) { + updateCheck({ + generator, + checkGenerator: + config.updateCheck !== false && generator.type === 'npm' + }) + } + } + + // When updated, the cached answers should be cleared too + if (this.opts.update && generator.hash) { + store.delete(`answers.${generator.hash}`) } if (generator.subGenerator) { @@ -205,7 +215,7 @@ async function ensurePackage(generator, update) { 'utf8' ) logger.debug('Installing generator at', installPath) - await require('./installPackages')({ + await installPackages({ cwd: installPath, packages: [`${generator.name}@${generator.version || 'latest'}`] })