Skip to content

Commit 7044881

Browse files
authored
fix: compare paths on windows (#216)
Signed-off-by: Ruben Romero Montes <[email protected]>
1 parent 7c3d5d2 commit 7044881

File tree

1 file changed

+22
-11
lines changed

1 file changed

+22
-11
lines changed

src/providers/base_java.js

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -175,22 +175,33 @@ export default class Base_Java {
175175
* @returns {string|undefined}
176176
*/
177177
traverseForWrapper(startingManifest, repoRoot = undefined) {
178-
repoRoot = repoRoot || getGitRootDir(path.resolve(path.dirname(startingManifest))) || path.parse(path.resolve(startingManifest)).root
179-
180-
const wrapperName = this.localWrapper;
181-
const wrapperPath = path.join(path.resolve(path.dirname(startingManifest)), wrapperName);
178+
const normalizedManifest = this.normalizePath(startingManifest);
179+
const currentDir = this.normalizePath(path.dirname(normalizedManifest));
180+
repoRoot = repoRoot || getGitRootDir(currentDir) || path.parse(normalizedManifest).root;
181+
const wrapperPath = path.join(currentDir, this.localWrapper);
182182

183183
try {
184-
fs.accessSync(wrapperPath, fs.constants.X_OK)
185-
} catch(error) {
184+
fs.accessSync(wrapperPath, fs.constants.X_OK);
185+
return wrapperPath;
186+
}
187+
catch (error) {
186188
if (error.code === 'ENOENT') {
187-
if (path.resolve(path.dirname(startingManifest)) === repoRoot) {
188-
return undefined
189+
const rootDir = path.parse(currentDir).root;
190+
if (currentDir === repoRoot || currentDir === rootDir) {
191+
return undefined;
192+
}
193+
const parentDir = path.dirname(currentDir);
194+
if (parentDir === currentDir || parentDir === rootDir) {
195+
return undefined;
189196
}
190-
return this.traverseForWrapper(path.resolve(path.dirname(startingManifest)), repoRoot)
197+
return this.traverseForWrapper(path.join(parentDir, path.basename(normalizedManifest)), repoRoot);
191198
}
192-
throw new Error(`failure searching for ${this.localWrapper}`, {cause: error})
199+
throw new Error(`failure searching for ${this.localWrapper}`, { cause: error });
193200
}
194-
return wrapperPath
201+
}
202+
203+
normalizePath(thePath) {
204+
const normalized = path.resolve(thePath).normalize();
205+
return process.platform === 'win32' ? normalized.toLowerCase() : normalized;
195206
}
196207
}

0 commit comments

Comments
 (0)