Handle missing cache directory for changedCache (#6327)

* handle missing cache directory for changedCache

* fallback to temp dir when cache dir not found
master
Gabriel Harel 2019-07-26 09:03:26 -07:00 committed by Lucas Duailibe
parent 6fae09b67e
commit 48697e9237
1 changed files with 4 additions and 1 deletions

View File

@ -9,6 +9,7 @@ const chalk = require("chalk");
const readline = require("readline");
const stringify = require("json-stable-stringify");
const findCacheDir = require("find-cache-dir");
const os = require("os");
const minimist = require("./minimist");
const prettier = require("../../index");
@ -445,7 +446,9 @@ function formatFiles(context) {
let changedCache = null;
if (context.argv["only-changed"]) {
const cacheDir = findCacheDir({ name: "prettier", create: true });
const cacheDir =
findCacheDir({ name: "prettier", create: true }) || os.tmpdir();
changedCache = new ChangedCache({
location: path.join(cacheDir, "changed"),
readFile: fs.readFileSync,