refactor(format): move oxfmt flag to runtime flags (#27608)
This commit is contained in:
@@ -3,9 +3,10 @@ import type { InstanceContext } from "../project/instance"
|
||||
import { Filesystem } from "@/util/filesystem"
|
||||
import { Process } from "@/util/process"
|
||||
import { which } from "../util/which"
|
||||
import { Flag } from "@opencode-ai/core/flag/flag"
|
||||
|
||||
export interface Context extends Pick<InstanceContext, "directory" | "worktree"> {}
|
||||
export interface Context extends Pick<InstanceContext, "directory" | "worktree"> {
|
||||
experimentalOxfmt: boolean
|
||||
}
|
||||
|
||||
export interface Info {
|
||||
name: string
|
||||
@@ -90,7 +91,7 @@ export const oxfmt: Info = {
|
||||
},
|
||||
extensions: [".js", ".jsx", ".mjs", ".cjs", ".ts", ".tsx", ".mts", ".cts"],
|
||||
async enabled(context) {
|
||||
if (!Flag.OPENCODE_EXPERIMENTAL_OXFMT) return false
|
||||
if (!context.experimentalOxfmt) return false
|
||||
const items = await Filesystem.findUp("package.json", context.directory, context.worktree)
|
||||
for (const item of items) {
|
||||
const json = await Filesystem.readJson<{
|
||||
|
||||
@@ -5,6 +5,7 @@ import { InstanceState } from "@/effect/instance-state"
|
||||
import path from "path"
|
||||
import { mergeDeep } from "remeda"
|
||||
import { Config } from "@/config/config"
|
||||
import { RuntimeFlags } from "@/effect/runtime-flags"
|
||||
import { errorMessage } from "@/util/error"
|
||||
import * as Log from "@opencode-ai/core/util/log"
|
||||
import * as Formatter from "./formatter"
|
||||
@@ -31,6 +32,7 @@ export const layer = Layer.effect(
|
||||
Effect.gen(function* () {
|
||||
const config = yield* Config.Service
|
||||
const appProcess = yield* AppProcess.Service
|
||||
const flags = yield* RuntimeFlags.Service
|
||||
|
||||
const state = yield* InstanceState.make(
|
||||
Effect.fn("Format.state")(function* (ctx) {
|
||||
@@ -40,7 +42,7 @@ export const layer = Layer.effect(
|
||||
async function getCommand(item: Formatter.Info) {
|
||||
let cmd = commands[item.name]
|
||||
if (cmd === false || cmd === undefined) {
|
||||
cmd = await item.enabled(ctx)
|
||||
cmd = await item.enabled({ ...ctx, experimentalOxfmt: flags.experimentalOxfmt })
|
||||
commands[item.name] = cmd
|
||||
}
|
||||
return cmd
|
||||
@@ -198,6 +200,10 @@ export const layer = Layer.effect(
|
||||
}),
|
||||
)
|
||||
|
||||
export const defaultLayer = layer.pipe(Layer.provide(Config.defaultLayer), Layer.provide(AppProcess.defaultLayer))
|
||||
export const defaultLayer = layer.pipe(
|
||||
Layer.provide(Config.defaultLayer),
|
||||
Layer.provide(AppProcess.defaultLayer),
|
||||
Layer.provide(RuntimeFlags.defaultLayer),
|
||||
)
|
||||
|
||||
export * as Format from "."
|
||||
|
||||
Reference in New Issue
Block a user