mirror of
https://github.com/affaan-m/ECC.git
synced 2026-11-23 00:05:27 +00:00
fix(formatter): honor equivalent Windows home paths
This commit is contained in:
1 parent
69bbf04bc7
commit
e9300358da
2 files changed
+24
-1
No files matched your search
@@ -72,7 +72,7 @@ function findProjectRoot(startDir) {
|
||||
while (dir !== path.dirname(dir)) {
|
||||
// Stop before checking the home directory to avoid treating global
|
||||
// dotfiles (e.g. ~/.prettierrc) as a project root marker.
|
||||
if (dir === homeDir) break;
|
||||
if (path.relative(homeDir, dir) === '') break;
|
||||
if (detectFormatter(dir)) {
|
||||
projectRootCache.set(startDir, dir);
|
||||
return dir;
|
||||
|
||||
@@ -8,6 +8,7 @@ const assert = require('assert');
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const os = require('os');
|
||||
const vm = require('vm');
|
||||
|
||||
const { findProjectRoot, detectFormatter, resolveFormatterBin, clearCaches } = require('../../scripts/lib/resolve-formatter');
|
||||
|
||||
@@ -162,6 +163,28 @@ function runTests() {
|
||||
assert.strictEqual(findProjectRoot(workspace), workspace);
|
||||
});
|
||||
|
||||
run('findProjectRoot: keeps the home boundary across Windows path casing', () => {
|
||||
const source = fs.readFileSync(path.join(__dirname, '../../scripts/lib/resolve-formatter.js'), 'utf8');
|
||||
const existing = new Set([
|
||||
'c:\\users\\alice\\.prettierrc',
|
||||
'c:\\users\\alice\\project\\package.json',
|
||||
]);
|
||||
const mod = { exports: {} };
|
||||
const dependencies = {
|
||||
path: path.win32,
|
||||
os: { homedir: () => 'C:\\Users\\Alice' },
|
||||
fs: {
|
||||
existsSync: file => existing.has(file.toLowerCase()),
|
||||
readFileSync: () => '{}',
|
||||
},
|
||||
};
|
||||
vm.runInNewContext(source, { module: mod, require: id => dependencies[id] });
|
||||
for (const project of ['c:\\Users\\Alice\\project', 'C:\\USERS\\ALICE\\project']) {
|
||||
assert.strictEqual(mod.exports.findProjectRoot(path.win32.join(project, 'src')), project);
|
||||
assert.strictEqual(mod.exports.detectFormatter(project), null);
|
||||
}
|
||||
});
|
||||
|
||||
run('findProjectRoot: does not borrow a formatter from outside a repository', () => {
|
||||
for (const isWorktree of [false, true]) {
|
||||
const outer = makeTmpDir();
|
||||
|
||||
Reference in new issue
Block a user