Skip to content
This repository was archived by the owner on Aug 25, 2025. It is now read-only.

Commit 42e0f5b

Browse files
committed
Better HackCodegenConfig::getRootDir()
This should usually be used via composer, so it will end up in PROJECTROOT/vendor/facebook/hack-codegen/ If this is the case, go for that, rather than PROJECTROOT/vendor/facebook/hack-codegen/src/ Tested with `codegen_generated_from_script()` with no args; generated file now contains: ``` * To re-generate this file run vendor/phpunit/phpunit/phpunit ``` Previously it had the *full* path to the script - /Users/fred/.....
1 parent aa7af56 commit 42e0f5b

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/HackCodegenConfig.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,14 @@ public function getMaxLineLength(): int {
3737
return 80;
3838
}
3939

40+
<<__Memoize>>
4041
public function getRootDir(): string {
41-
return __DIR__;
42+
$dir = __DIR__;
43+
$root_pos = strpos($dir, '/vendor/facebook/hack-codegen/');
44+
if ($root_pos === false) {
45+
return $dir;
46+
}
47+
$root = Str::substr($dir, 0, $root_pos);
48+
return $root;
4249
}
4350
}

0 commit comments

Comments
 (0)