Skip to content

Commit 512291b

Browse files
Make cache directory be relative to cwd (#582)
Co-authored-by: Sindre Sorhus <[email protected]>
1 parent f038f9c commit 512291b

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

lib/options-manager.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,12 @@ resolveFrom.silent = (moduleId, fromDirectory) => {
4949
const resolveLocalConfig = name => resolveModule(normalizePackageName(name, 'eslint-config'), import.meta.url);
5050

5151
const nodeVersion = process && process.version;
52-
const cacheLocation = findCacheDir({name: CACHE_DIR_NAME}) || path.join(os.homedir() || os.tmpdir(), '.xo-cache/');
52+
const cacheLocation = cwd => findCacheDir({name: CACHE_DIR_NAME, cwd}) || path.join(os.homedir() || os.tmpdir(), '.xo-cache/');
5353

5454
const DEFAULT_CONFIG = {
5555
useEslintrc: false,
5656
cache: true,
57-
cacheLocation: path.join(cacheLocation, 'xo-cache.json'),
57+
cacheLocation: path.join(cacheLocation(), 'xo-cache.json'),
5858
globInputPaths: false,
5959
baseConfig: {
6060
extends: [
@@ -131,7 +131,7 @@ const mergeWithFileConfig = options => {
131131
const tsConfigExplorer = cosmiconfigSync([], {searchPlaces: ['tsconfig.json'], loaders: {'.json': (_, content) => JSON5.parse(content)}});
132132
const {config: tsConfig, filepath: tsConfigPath} = tsConfigExplorer.search(options.filePath) || {};
133133

134-
options.tsConfigPath = getTsConfigCachePath([options.filePath], options.tsConfigPath);
134+
options.tsConfigPath = getTsConfigCachePath([options.filePath], options.tsConfigPath, options.cwd);
135135
options.ts = true;
136136
outputJsonSync(options.tsConfigPath, makeTSConfig(tsConfig, tsConfigPath, [options.filePath]));
137137
}
@@ -187,7 +187,7 @@ const mergeWithFileConfigs = async (files, options, configFiles) => {
187187
await Promise.all(Object.entries(groupBy(groups.filter(({options}) => Boolean(options.ts)), group => group.options.tsConfigPath || '')).map(
188188
([tsConfigPath, groups]) => {
189189
const files = groups.flatMap(group => group.files);
190-
const cachePath = getTsConfigCachePath(files, tsConfigPath);
190+
const cachePath = getTsConfigCachePath(files, tsConfigPath, options.cwd);
191191

192192
for (const group of groups) {
193193
group.options.tsConfigPath = cachePath;
@@ -206,8 +206,8 @@ const findApplicableConfig = (file, configFiles) => configFiles.find(({filepath}
206206
Generate a unique and consistent path for the temporary `tsconfig.json`.
207207
Hashing based on https://github.com/eslint/eslint/blob/cf38d0d939b62f3670cdd59f0143fd896fccd771/lib/cli-engine/lint-result-cache.js#L30
208208
*/
209-
const getTsConfigCachePath = (files, tsConfigPath) => path.join(
210-
cacheLocation,
209+
const getTsConfigCachePath = (files, tsConfigPath, cwd) => path.join(
210+
cacheLocation(cwd),
211211
`tsconfig.${murmur(`${pkg.version}_${nodeVersion}_${stringify({files: files.sort(), tsConfigPath})}`).result().toString(36)}.json`,
212212
);
213213

test/options-manager.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,8 @@ test('mergeWithFileConfig: typescript files', async t => {
554554
semicolon: false,
555555
ts: true,
556556
};
557+
const expectedConfigPath = new RegExp(`${slash(cwd)}/node_modules/.cache/xo-linter/tsconfig\\..*\\.json[\\/]?$`, 'u');
558+
t.regex(slash(options.tsConfigPath), expectedConfigPath);
557559
t.deepEqual(omit(options, 'tsConfigPath'), expected);
558560
t.deepEqual(await readJson(options.tsConfigPath), {
559561
extends: path.resolve(cwd, 'tsconfig.json'),
@@ -574,6 +576,8 @@ test('mergeWithFileConfig: tsx files', async t => {
574576
semicolon: false,
575577
ts: true,
576578
};
579+
const expectedConfigPath = new RegExp(`${slash(cwd)}/node_modules/.cache/xo-linter/tsconfig\\..*\\.json[\\/]?$`, 'u');
580+
t.regex(slash(options.tsConfigPath), expectedConfigPath);
577581
t.deepEqual(omit(options, 'tsConfigPath'), expected);
578582
t.deepEqual(await readJson(options.tsConfigPath), {
579583
extends: path.resolve(cwd, 'tsconfig.json'),

0 commit comments

Comments
 (0)