Merge pull request #1424 from code-yeongyu/fix/auto-update-wrong-directory
fix(auto-update): use USER_CONFIG_DIR instead of CACHE_DIR for plugin invalidation
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import * as fs from "node:fs"
|
||||
import * as path from "node:path"
|
||||
import { CACHE_DIR, PACKAGE_NAME } from "./constants"
|
||||
import { PACKAGE_NAME, USER_CONFIG_DIR } from "./constants"
|
||||
import { log } from "../../shared/logger"
|
||||
|
||||
interface BunLockfile {
|
||||
@@ -17,7 +17,7 @@ function stripTrailingCommas(json: string): string {
|
||||
}
|
||||
|
||||
function removeFromBunLock(packageName: string): boolean {
|
||||
const lockPath = path.join(CACHE_DIR, "bun.lock")
|
||||
const lockPath = path.join(USER_CONFIG_DIR, "bun.lock")
|
||||
if (!fs.existsSync(lockPath)) return false
|
||||
|
||||
try {
|
||||
@@ -48,8 +48,8 @@ function removeFromBunLock(packageName: string): boolean {
|
||||
|
||||
export function invalidatePackage(packageName: string = PACKAGE_NAME): boolean {
|
||||
try {
|
||||
const pkgDir = path.join(CACHE_DIR, "node_modules", packageName)
|
||||
const pkgJsonPath = path.join(CACHE_DIR, "package.json")
|
||||
const pkgDir = path.join(USER_CONFIG_DIR, "node_modules", packageName)
|
||||
const pkgJsonPath = path.join(USER_CONFIG_DIR, "package.json")
|
||||
|
||||
let packageRemoved = false
|
||||
let dependencyRemoved = false
|
||||
|
||||
@@ -16,12 +16,6 @@ function getCacheDir(): string {
|
||||
|
||||
export const CACHE_DIR = getCacheDir()
|
||||
export const VERSION_FILE = path.join(CACHE_DIR, "version")
|
||||
export const INSTALLED_PACKAGE_JSON = path.join(
|
||||
CACHE_DIR,
|
||||
"node_modules",
|
||||
PACKAGE_NAME,
|
||||
"package.json"
|
||||
)
|
||||
|
||||
export function getWindowsAppdataDir(): string | null {
|
||||
if (process.platform !== "win32") return null
|
||||
@@ -31,3 +25,10 @@ export function getWindowsAppdataDir(): string | null {
|
||||
export const USER_CONFIG_DIR = getOpenCodeConfigDir({ binary: "opencode" })
|
||||
export const USER_OPENCODE_CONFIG = path.join(USER_CONFIG_DIR, "opencode.json")
|
||||
export const USER_OPENCODE_CONFIG_JSONC = path.join(USER_CONFIG_DIR, "opencode.jsonc")
|
||||
|
||||
export const INSTALLED_PACKAGE_JSON = path.join(
|
||||
USER_CONFIG_DIR,
|
||||
"node_modules",
|
||||
PACKAGE_NAME,
|
||||
"package.json"
|
||||
)
|
||||
|
||||
@@ -20,11 +20,11 @@ export const glob: ToolDefinition = tool({
|
||||
"simply omit it for the default behavior. Must be a valid directory path if provided."
|
||||
),
|
||||
},
|
||||
execute: async (args, ctx) => {
|
||||
execute: async (args) => {
|
||||
try {
|
||||
const cli = await resolveGrepCliWithAutoInstall()
|
||||
// Use ctx.directory as the default search path when no path is provided
|
||||
const searchPath = args.path ?? ctx.directory
|
||||
// Use process.cwd() as the default search path when no path is provided
|
||||
const searchPath = args.path ?? process.cwd()
|
||||
const paths = [searchPath]
|
||||
|
||||
const result = await runRgFiles(
|
||||
|
||||
@@ -20,11 +20,11 @@ export const grep: ToolDefinition = tool({
|
||||
.optional()
|
||||
.describe("The directory to search in. Defaults to the current working directory."),
|
||||
},
|
||||
execute: async (args, ctx) => {
|
||||
execute: async (args) => {
|
||||
try {
|
||||
const globs = args.include ? [args.include] : undefined
|
||||
// Use ctx.directory as the default search path when no path is provided
|
||||
const searchPath = args.path ?? ctx.directory
|
||||
// Use process.cwd() as the default search path when no path is provided
|
||||
const searchPath = args.path ?? process.cwd()
|
||||
const paths = [searchPath]
|
||||
|
||||
const result = await runRg({
|
||||
|
||||
Reference in New Issue
Block a user