Merge pull request #962 from popododo0720/fix/issues-898-919
fix(doctor): improve AST-Grep NAPI detection for bunx environments
This commit is contained in:
commit
6312d2da52
@ -16,10 +16,10 @@ describe("dependencies check", () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
describe("checkAstGrepNapi", () => {
|
describe("checkAstGrepNapi", () => {
|
||||||
it("returns dependency info", () => {
|
it("returns dependency info", async () => {
|
||||||
// #given
|
// #given
|
||||||
// #when checking ast-grep napi
|
// #when checking ast-grep napi
|
||||||
const info = deps.checkAstGrepNapi()
|
const info = await deps.checkAstGrepNapi()
|
||||||
|
|
||||||
// #then should return valid info
|
// #then should return valid info
|
||||||
expect(info.name).toBe("AST-Grep NAPI")
|
expect(info.name).toBe("AST-Grep NAPI")
|
||||||
@ -95,7 +95,7 @@ describe("dependencies check", () => {
|
|||||||
|
|
||||||
it("returns pass when installed", async () => {
|
it("returns pass when installed", async () => {
|
||||||
// #given napi installed
|
// #given napi installed
|
||||||
checkSpy = spyOn(deps, "checkAstGrepNapi").mockReturnValue({
|
checkSpy = spyOn(deps, "checkAstGrepNapi").mockResolvedValue({
|
||||||
name: "AST-Grep NAPI",
|
name: "AST-Grep NAPI",
|
||||||
required: false,
|
required: false,
|
||||||
installed: true,
|
installed: true,
|
||||||
|
|||||||
@ -56,9 +56,10 @@ export async function checkAstGrepCli(): Promise<DependencyInfo> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function checkAstGrepNapi(): DependencyInfo {
|
export async function checkAstGrepNapi(): Promise<DependencyInfo> {
|
||||||
|
// Try dynamic import first (works in bunx temporary environments)
|
||||||
try {
|
try {
|
||||||
require.resolve("@ast-grep/napi")
|
await import("@ast-grep/napi")
|
||||||
return {
|
return {
|
||||||
name: "AST-Grep NAPI",
|
name: "AST-Grep NAPI",
|
||||||
required: false,
|
required: false,
|
||||||
@ -67,6 +68,28 @@ export function checkAstGrepNapi(): DependencyInfo {
|
|||||||
path: null,
|
path: null,
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
|
// Fallback: check common installation paths
|
||||||
|
const { existsSync } = await import("fs")
|
||||||
|
const { join } = await import("path")
|
||||||
|
const { homedir } = await import("os")
|
||||||
|
|
||||||
|
const pathsToCheck = [
|
||||||
|
join(homedir(), ".config", "opencode", "node_modules", "@ast-grep", "napi"),
|
||||||
|
join(process.cwd(), "node_modules", "@ast-grep", "napi"),
|
||||||
|
]
|
||||||
|
|
||||||
|
for (const napiPath of pathsToCheck) {
|
||||||
|
if (existsSync(napiPath)) {
|
||||||
|
return {
|
||||||
|
name: "AST-Grep NAPI",
|
||||||
|
required: false,
|
||||||
|
installed: true,
|
||||||
|
version: null,
|
||||||
|
path: napiPath,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
name: "AST-Grep NAPI",
|
name: "AST-Grep NAPI",
|
||||||
required: false,
|
required: false,
|
||||||
@ -127,7 +150,7 @@ export async function checkDependencyAstGrepCli(): Promise<CheckResult> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function checkDependencyAstGrepNapi(): Promise<CheckResult> {
|
export async function checkDependencyAstGrepNapi(): Promise<CheckResult> {
|
||||||
const info = checkAstGrepNapi()
|
const info = await checkAstGrepNapi()
|
||||||
return dependencyToCheckResult(info, CHECK_NAMES[CHECK_IDS.DEP_AST_GREP_NAPI])
|
return dependencyToCheckResult(info, CHECK_NAMES[CHECK_IDS.DEP_AST_GREP_NAPI])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user