Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions packages/cli/src/runCli.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import {
createDiskBackedLinterHost,
createEphemeralLinterHost,
} from "@flint.fyi/core";
import { parseArgs } from "node:util";

import packageData from "../package.json" with { type: "json" };
Expand Down Expand Up @@ -67,7 +71,8 @@ export async function runCli(args: string[]) {
return 0;
}

const configFileName = await findConfigFileName(process.cwd());
const cwd = process.cwd();
const configFileName = await findConfigFileName(cwd);
if (!configFileName) {
console.error("No flint.config.* file found.");
console.error(
Expand All @@ -81,14 +86,21 @@ export async function runCli(args: string[]) {

const getRenderer = createRendererFactory(configFileName, values);

const host = createDiskBackedLinterHost(cwd);

if (values.watch) {
await runCliWatch(configFileName, getRenderer, values);
await runCliWatch(host, configFileName, getRenderer, values);
console.log("👋 Thanks for using Flint!");
return 0;
}

const renderer = getRenderer();
const { exitCode } = await runCliOnce(configFileName, renderer, values);
const { exitCode } = await runCliOnce(
createEphemeralLinterHost(host),
configFileName,
renderer,
values,
);

renderer.dispose?.();

Expand Down
10 changes: 3 additions & 7 deletions packages/cli/src/runCliOnce.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {
createDiskBackedLinterHost,
createEphemeralLinterHost,
isConfig,
type LinterHost,
runConfig,
runConfigFixing,
validateConfigDefinition,
Expand All @@ -17,12 +16,13 @@ import type { Renderer } from "./renderers/types.ts";
const log = debugForFile(import.meta.filename);

export async function runCliOnce(
host: LinterHost,
configFileName: string,
renderer: Renderer,
values: OptionsValues,
) {
const { default: config } = (await import(
pathToFileURL(path.join(process.cwd(), configFileName)).href
pathToFileURL(path.join(host.getCurrentDirectory(), configFileName)).href
)) as {
default: unknown;
};
Expand Down Expand Up @@ -55,10 +55,6 @@ export async function runCliOnce(

const skipDiagnostics = !!values["skip-diagnostics"];

const host = createEphemeralLinterHost(
createDiskBackedLinterHost(process.cwd()),
);

const lintResults = await (values.fix
? runConfigFixing(configDefinition, host, {
ignoreCache,
Expand Down
6 changes: 4 additions & 2 deletions packages/cli/src/runCliWatch.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { LintResults } from "@flint.fyi/core";
import type { LinterHost, LintResults } from "@flint.fyi/core";
import { normalizePath } from "@flint.fyi/core";
import debounce from "debounce";
import { debugForFile } from "debug-for-file";
Expand All @@ -11,12 +11,13 @@ import { runCliOnce } from "./runCliOnce.ts";
const log = debugForFile(import.meta.filename);

export async function runCliWatch(
host: LinterHost,
configFileName: string,
getRenderer: () => Renderer,
values: OptionsValues,
) {
const abortController = new AbortController();
const cwd = process.cwd();
const cwd = host.getCurrentDirectory();

log("Running single-run CLI once before watching");

Expand All @@ -29,6 +30,7 @@ export async function runCliWatch(
currentRenderer = renderer;

runCliOnce(
host,
configFileName,
renderer,
initial ? values : { ...values, "cache-ignore": false },
Expand Down