Skip to content
This repository has been archived by the owner on Feb 5, 2022. It is now read-only.

Commit

Permalink
fix: cache answers by hash + pkg version
Browse files Browse the repository at this point in the history
  • Loading branch information
egoist committed Nov 6, 2018
1 parent 86b54fc commit e981a3f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
6 changes: 0 additions & 6 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const isLocalPath = require('./utils/isLocalPath')
const SAOError = require('./SAOError')
const parseGenerator = require('./parseGenerator')
const updateCheck = require('./updateCheck')
const store = require('./store')

class SAO {
/**
Expand Down Expand Up @@ -76,11 +75,6 @@ class SAO {
}
}

// When updated, the cached answers should be cleared too
if (this.opts.update && generator.hash) {
store.delete(`answers.${generator.hash}`)
}

if (generator.subGenerator) {
const subGenerator =
config.generators &&
Expand Down
7 changes: 6 additions & 1 deletion lib/runPrompts.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const inquirer = require('inquirer')
const resolveFrom = require('resolve-from')
const logger = require('./logger')
const store = require('./store')
const renderTemplate = require('./utils/renderTemplate')
Expand All @@ -13,7 +14,11 @@ module.exports = async (config, context) => {
? await config.prompts.call(context, context)
: config.prompts

const STORED_ANSWERS_ID = `answers.${context.generator.hash}`
const pkgPath = resolveFrom.silent(context.generator.path, 'package.json')
const pkgVersion = pkgPath ? require(pkgPath).version : ''
const STORED_ANSWERS_ID = `answers.${context.generator.hash +
'__npm__' +
pkgVersion}`
const storedAnswers = store.get(STORED_ANSWERS_ID) || {}

const { mock, yes } = context.sao.opts
Expand Down

0 comments on commit e981a3f

Please sign in to comment.