Skip to content

Commit 04ac4ff

Browse files
committed
Changed cache dir to be user specific
1 parent 399ad12 commit 04ac4ff

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/plugins/resolver.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,23 +48,23 @@ export class PluginResolver {
4848
throw new Error(`Un-able to fetch plugin ${name}. Body was null`);
4949
}
5050

51-
const fileUrl = path.join(PLUGIN_CACHE_DIR, `${name}.js`);
51+
const fileUrl = path.join(PluginResolver.getCacheDir(), `${name}.js`);
5252
const ws = fsSync.createWriteStream(fileUrl)
5353

5454
// Different type definitions here for readable stream (NodeJS vs DOM). Small hack to fix that
5555
await finished(Readable.fromWeb(body as never).pipe(ws));
5656

5757
return new Plugin(
58-
name,
58+
name,
5959
version,
60-
fileUrl,
60+
fileUrl,
6161
)
6262
}
6363

6464
private static async checkAndCreateCacheDirIfNotExists() {
6565
let pluginDirStat = null;
6666
try {
67-
pluginDirStat = await fs.stat(PLUGIN_CACHE_DIR)
67+
pluginDirStat = await fs.stat(PluginResolver.getCacheDir())
6868
} catch {
6969
ctx.log('Plugin cache dir does not exist')
7070
}
@@ -74,10 +74,15 @@ export class PluginResolver {
7474
}
7575

7676
if (pluginDirStat && !pluginDirStat.isDirectory()) {
77-
throw new Error(`An object already exists at ${PLUGIN_CACHE_DIR} and is not a directory. Please delete and try again`);
77+
throw new Error(`An object already exists at ${PluginResolver.getCacheDir()} and is not a directory. Please delete and try again`);
7878
}
7979

8080
ctx.log('Creating a new cache dir for codify');
81-
await fs.mkdir(PLUGIN_CACHE_DIR, { recursive: true });
81+
await fs.mkdir(PluginResolver.getCacheDir(), { recursive: true });
82+
}
83+
84+
private static getCacheDir() {
85+
const homeDir = process.env.HOME!;
86+
return path.join(homeDir, PLUGIN_CACHE_DIR);
8287
}
8388
}

0 commit comments

Comments
 (0)