feat: init
This commit is contained in:
22
node_modules/vite-plugin-checker/dist/checkers/biome/cli.d.ts
generated
vendored
Normal file
22
node_modules/vite-plugin-checker/dist/checkers/biome/cli.d.ts
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
import { NormalizedDiagnostic } from '../../logger.js';
|
||||
import { DiagnosticLevel } from '../../types.js';
|
||||
import '@babel/code-frame';
|
||||
import 'eslint';
|
||||
import 'stylelint';
|
||||
import 'typescript';
|
||||
import 'vscode-languageclient/node';
|
||||
import 'node:worker_threads';
|
||||
import 'vite';
|
||||
import '../vls/initParams.js';
|
||||
import 'vscode-languageserver/node';
|
||||
import 'vscode-uri';
|
||||
|
||||
declare const severityMap: {
|
||||
readonly error: DiagnosticLevel.Error;
|
||||
readonly warning: DiagnosticLevel.Warning;
|
||||
readonly info: DiagnosticLevel.Suggestion;
|
||||
};
|
||||
declare function getBiomeCommand(command: string, flags: string, files: string): string;
|
||||
declare function runBiome(command: string, cwd: string): Promise<NormalizedDiagnostic[]>;
|
||||
|
||||
export { getBiomeCommand, runBiome, severityMap };
|
||||
87
node_modules/vite-plugin-checker/dist/checkers/biome/cli.js
generated
vendored
Normal file
87
node_modules/vite-plugin-checker/dist/checkers/biome/cli.js
generated
vendored
Normal file
@@ -0,0 +1,87 @@
|
||||
import { exec } from "node:child_process";
|
||||
import path from "node:path";
|
||||
import { stripVTControlCharacters as strip } from "node:util";
|
||||
import { createFrame } from "../../codeFrame.js";
|
||||
import { DiagnosticLevel } from "../../types.js";
|
||||
const severityMap = {
|
||||
error: DiagnosticLevel.Error,
|
||||
warning: DiagnosticLevel.Warning,
|
||||
info: DiagnosticLevel.Suggestion
|
||||
};
|
||||
function getBiomeCommand(command, flags, files) {
|
||||
const defaultFlags = "--reporter json";
|
||||
if (flags.includes("--flags")) {
|
||||
throw Error(
|
||||
`vite-plugin-checker will force append "--reporter json" to the flags in dev mode, please don't use "--flags" in "config.biome.flags".
|
||||
If you need to customize "--flags" in build mode, please use "config.biome.build.flags" instead.`
|
||||
);
|
||||
}
|
||||
return ["biome", command, flags, defaultFlags, files].filter(Boolean).join(" ");
|
||||
}
|
||||
function runBiome(command, cwd) {
|
||||
return new Promise((resolve, _reject) => {
|
||||
exec(
|
||||
command,
|
||||
{
|
||||
cwd,
|
||||
maxBuffer: Number.POSITIVE_INFINITY
|
||||
},
|
||||
(_error, stdout, _stderr) => {
|
||||
resolve([...parseBiomeOutput(stdout, cwd)]);
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
function parseBiomeOutput(output, cwd) {
|
||||
let parsed;
|
||||
try {
|
||||
parsed = JSON.parse(output);
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
const diagnostics = parsed.diagnostics.map((d) => {
|
||||
var _a, _b, _c;
|
||||
let file = (_a = d.location.path) == null ? void 0 : _a.file;
|
||||
if (file) {
|
||||
file = path.isAbsolute(file) ? file : path.resolve(cwd, file);
|
||||
file = path.normalize(file);
|
||||
}
|
||||
const loc = {
|
||||
file: file || "",
|
||||
start: getLineAndColumn(d.location.sourceCode, (_b = d.location.span) == null ? void 0 : _b[0]),
|
||||
end: getLineAndColumn(d.location.sourceCode, (_c = d.location.span) == null ? void 0 : _c[1])
|
||||
};
|
||||
const codeFrame = createFrame(d.location.sourceCode || "", loc);
|
||||
return {
|
||||
message: `[${d.category}] ${d.description}`,
|
||||
conclusion: "",
|
||||
level: severityMap[d.severity] ?? DiagnosticLevel.Error,
|
||||
checker: "Biome",
|
||||
id: file,
|
||||
codeFrame,
|
||||
stripedCodeFrame: codeFrame && strip(codeFrame),
|
||||
loc
|
||||
};
|
||||
});
|
||||
return diagnostics;
|
||||
}
|
||||
function getLineAndColumn(text, offset) {
|
||||
if (!text || !offset) return { line: 0, column: 0 };
|
||||
let line = 1;
|
||||
let column = 1;
|
||||
for (let i = 0; i < offset; i++) {
|
||||
if (text[i] === "\n") {
|
||||
line++;
|
||||
column = 1;
|
||||
} else {
|
||||
column++;
|
||||
}
|
||||
}
|
||||
return { line, column };
|
||||
}
|
||||
export {
|
||||
getBiomeCommand,
|
||||
runBiome,
|
||||
severityMap
|
||||
};
|
||||
//# sourceMappingURL=cli.js.map
|
||||
1
node_modules/vite-plugin-checker/dist/checkers/biome/cli.js.map
generated
vendored
Normal file
1
node_modules/vite-plugin-checker/dist/checkers/biome/cli.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../../../src/checkers/biome/cli.ts"],"sourcesContent":["import { exec } from 'node:child_process'\nimport path from 'node:path'\nimport { stripVTControlCharacters as strip } from 'node:util'\nimport { createFrame } from '../../codeFrame.js'\nimport type { NormalizedDiagnostic } from '../../logger.js'\nimport { DiagnosticLevel } from '../../types.js'\nimport type { BiomeOutput } from './types.js'\n\nexport const severityMap = {\n error: DiagnosticLevel.Error,\n warning: DiagnosticLevel.Warning,\n info: DiagnosticLevel.Suggestion,\n} as const\n\nexport function getBiomeCommand(command: string, flags: string, files: string) {\n const defaultFlags = '--reporter json'\n if (flags.includes('--flags')) {\n throw Error(\n `vite-plugin-checker will force append \"--reporter json\" to the flags in dev mode, please don't use \"--flags\" in \"config.biome.flags\".\nIf you need to customize \"--flags\" in build mode, please use \"config.biome.build.flags\" instead.`,\n )\n }\n return ['biome', command, flags, defaultFlags, files]\n .filter(Boolean)\n .join(' ')\n}\n\nexport function runBiome(command: string, cwd: string) {\n return new Promise<NormalizedDiagnostic[]>((resolve, _reject) => {\n exec(\n command,\n {\n cwd,\n maxBuffer: Number.POSITIVE_INFINITY,\n },\n (_error, stdout, _stderr) => {\n resolve([...parseBiomeOutput(stdout, cwd)])\n },\n )\n })\n}\n\nfunction parseBiomeOutput(output: string, cwd: string) {\n let parsed: BiomeOutput\n try {\n parsed = JSON.parse(output)\n } catch {\n return []\n }\n\n const diagnostics: NormalizedDiagnostic[] = parsed.diagnostics.map((d) => {\n let file = d.location.path?.file\n if (file) {\n // Convert relative path to absolute path\n file = path.isAbsolute(file) ? file : path.resolve(cwd, file)\n file = path.normalize(file)\n }\n\n const loc = {\n file: file || '',\n start: getLineAndColumn(d.location.sourceCode, d.location.span?.[0]),\n end: getLineAndColumn(d.location.sourceCode, d.location.span?.[1]),\n }\n\n const codeFrame = createFrame(d.location.sourceCode || '', loc)\n\n return {\n message: `[${d.category}] ${d.description}`,\n conclusion: '',\n level:\n severityMap[d.severity as keyof typeof severityMap] ??\n DiagnosticLevel.Error,\n checker: 'Biome',\n id: file,\n codeFrame,\n stripedCodeFrame: codeFrame && strip(codeFrame),\n loc,\n }\n })\n\n return diagnostics\n}\n\nfunction getLineAndColumn(text?: string, offset?: number) {\n if (!text || !offset) return { line: 0, column: 0 }\n\n let line = 1\n let column = 1\n\n for (let i = 0; i < offset; i++) {\n if (text[i] === '\\n') {\n line++\n column = 1\n } else {\n column++\n }\n }\n\n return { line, column }\n}\n"],"mappings":"AAAA,SAAS,YAAY;AACrB,OAAO,UAAU;AACjB,SAAS,4BAA4B,aAAa;AAClD,SAAS,mBAAmB;AAE5B,SAAS,uBAAuB;AAGzB,MAAM,cAAc;AAAA,EACzB,OAAO,gBAAgB;AAAA,EACvB,SAAS,gBAAgB;AAAA,EACzB,MAAM,gBAAgB;AACxB;AAEO,SAAS,gBAAgB,SAAiB,OAAe,OAAe;AAC7E,QAAM,eAAe;AACrB,MAAI,MAAM,SAAS,SAAS,GAAG;AAC7B,UAAM;AAAA,MACJ;AAAA;AAAA,IAEF;AAAA,EACF;AACA,SAAO,CAAC,SAAS,SAAS,OAAO,cAAc,KAAK,EACjD,OAAO,OAAO,EACd,KAAK,GAAG;AACb;AAEO,SAAS,SAAS,SAAiB,KAAa;AACrD,SAAO,IAAI,QAAgC,CAAC,SAAS,YAAY;AAC/D;AAAA,MACE;AAAA,MACA;AAAA,QACE;AAAA,QACA,WAAW,OAAO;AAAA,MACpB;AAAA,MACA,CAAC,QAAQ,QAAQ,YAAY;AAC3B,gBAAQ,CAAC,GAAG,iBAAiB,QAAQ,GAAG,CAAC,CAAC;AAAA,MAC5C;AAAA,IACF;AAA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,OAAO;AACxB;","names":[]}
|
||||
18
node_modules/vite-plugin-checker/dist/checkers/biome/main.d.ts
generated
vendored
Normal file
18
node_modules/vite-plugin-checker/dist/checkers/biome/main.d.ts
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
import { Checker } from '../../Checker.js';
|
||||
import 'vite';
|
||||
import '../../types.js';
|
||||
import 'node:worker_threads';
|
||||
import 'eslint';
|
||||
import 'stylelint';
|
||||
import '../vls/initParams.js';
|
||||
import 'vscode-languageserver/node';
|
||||
import 'vscode-uri';
|
||||
import '../../worker.js';
|
||||
|
||||
declare let createServeAndBuild: any;
|
||||
declare class BiomeChecker extends Checker<'biome'> {
|
||||
constructor();
|
||||
init(): void;
|
||||
}
|
||||
|
||||
export { BiomeChecker, createServeAndBuild };
|
||||
153
node_modules/vite-plugin-checker/dist/checkers/biome/main.js
generated
vendored
Normal file
153
node_modules/vite-plugin-checker/dist/checkers/biome/main.js
generated
vendored
Normal file
@@ -0,0 +1,153 @@
|
||||
import path from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { parentPort } from "node:worker_threads";
|
||||
import chokidar from "chokidar";
|
||||
import { Checker } from "../../Checker.js";
|
||||
import { FileDiagnosticManager } from "../../FileDiagnosticManager.js";
|
||||
import {
|
||||
composeCheckerSummary,
|
||||
consoleLog,
|
||||
diagnosticToConsoleLevel,
|
||||
diagnosticToRuntimeError,
|
||||
diagnosticToTerminalLog,
|
||||
filterLogLevel,
|
||||
toClientPayload
|
||||
} from "../../logger.js";
|
||||
import {
|
||||
ACTION_TYPES,
|
||||
DiagnosticLevel
|
||||
} from "../../types.js";
|
||||
import { getBiomeCommand, runBiome, severityMap } from "./cli.js";
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const manager = new FileDiagnosticManager();
|
||||
let createServeAndBuild;
|
||||
const createDiagnostic = (pluginConfig) => {
|
||||
var _a, _b;
|
||||
const biomeConfig = pluginConfig.biome;
|
||||
let overlay = true;
|
||||
let terminal = true;
|
||||
let command = "lint";
|
||||
let flags = "";
|
||||
if (typeof biomeConfig === "object") {
|
||||
command = ((_a = biomeConfig == null ? void 0 : biomeConfig.dev) == null ? void 0 : _a.command) || (biomeConfig == null ? void 0 : biomeConfig.command) || "lint";
|
||||
flags = ((_b = biomeConfig == null ? void 0 : biomeConfig.dev) == null ? void 0 : _b.flags) || (biomeConfig == null ? void 0 : biomeConfig.flags) || "";
|
||||
}
|
||||
return {
|
||||
config: async ({ enableOverlay, enableTerminal }) => {
|
||||
overlay = enableOverlay;
|
||||
terminal = enableTerminal;
|
||||
},
|
||||
async configureServer({ root }) {
|
||||
if (!biomeConfig) return;
|
||||
const logLevel = (() => {
|
||||
var _a2;
|
||||
if (typeof biomeConfig !== "object") return void 0;
|
||||
const userLogLevel = (_a2 = biomeConfig.dev) == null ? void 0 : _a2.logLevel;
|
||||
if (!userLogLevel) return void 0;
|
||||
return userLogLevel.map((l) => severityMap[l]);
|
||||
})();
|
||||
const dispatchDiagnostics = () => {
|
||||
var _a2;
|
||||
const diagnostics2 = filterLogLevel(manager.getDiagnostics(), logLevel);
|
||||
if (terminal) {
|
||||
for (const d of diagnostics2) {
|
||||
consoleLog(
|
||||
diagnosticToTerminalLog(d, "Biome"),
|
||||
diagnosticToConsoleLevel(d)
|
||||
);
|
||||
}
|
||||
const errorCount = diagnostics2.filter(
|
||||
(d) => d.level === DiagnosticLevel.Error
|
||||
).length;
|
||||
const warningCount = diagnostics2.filter(
|
||||
(d) => d.level === DiagnosticLevel.Warning
|
||||
).length;
|
||||
consoleLog(
|
||||
composeCheckerSummary("Biome", errorCount, warningCount),
|
||||
errorCount ? "error" : warningCount ? "warn" : "info"
|
||||
);
|
||||
}
|
||||
if (overlay) {
|
||||
(_a2 = parentPort) == null ? void 0 : _a2.postMessage({
|
||||
type: ACTION_TYPES.overlayError,
|
||||
payload: toClientPayload(
|
||||
"biome",
|
||||
diagnostics2.map((d) => diagnosticToRuntimeError(d))
|
||||
)
|
||||
});
|
||||
}
|
||||
};
|
||||
const handleFileChange = async (filePath, type) => {
|
||||
const absPath = path.resolve(root, filePath);
|
||||
if (type === "unlink") {
|
||||
manager.updateByFileId(absPath, []);
|
||||
} else if (type === "change") {
|
||||
const isConfigFile = path.basename(absPath) === "biome.json";
|
||||
if (isConfigFile) {
|
||||
const runCommand2 = getBiomeCommand(command, flags, root);
|
||||
const diagnostics2 = await runBiome(runCommand2, root);
|
||||
manager.initWith(diagnostics2);
|
||||
} else {
|
||||
const runCommand2 = getBiomeCommand(command, flags, absPath);
|
||||
const diagnosticsOfChangedFile = await runBiome(runCommand2, root);
|
||||
manager.updateByFileId(absPath, diagnosticsOfChangedFile);
|
||||
}
|
||||
}
|
||||
dispatchDiagnostics();
|
||||
};
|
||||
const runCommand = getBiomeCommand(command, flags, root);
|
||||
const diagnostics = await runBiome(runCommand, root);
|
||||
manager.initWith(diagnostics);
|
||||
dispatchDiagnostics();
|
||||
let watchTarget = root;
|
||||
if (typeof biomeConfig === "object" && biomeConfig.watchPath) {
|
||||
if (Array.isArray(biomeConfig.watchPath)) {
|
||||
watchTarget = biomeConfig.watchPath.map((p) => path.resolve(root, p));
|
||||
} else {
|
||||
watchTarget = path.resolve(root, biomeConfig.watchPath);
|
||||
}
|
||||
}
|
||||
const watcher = chokidar.watch(watchTarget, {
|
||||
cwd: root,
|
||||
ignored: (path2) => path2.includes("node_modules")
|
||||
});
|
||||
watcher.on("change", async (filePath) => {
|
||||
handleFileChange(filePath, "change");
|
||||
});
|
||||
watcher.on("unlink", async (filePath) => {
|
||||
handleFileChange(filePath, "unlink");
|
||||
});
|
||||
}
|
||||
};
|
||||
};
|
||||
class BiomeChecker extends Checker {
|
||||
constructor() {
|
||||
super({
|
||||
name: "biome",
|
||||
absFilePath: __filename,
|
||||
build: {
|
||||
buildBin: (pluginConfig) => {
|
||||
if (typeof pluginConfig.biome === "object") {
|
||||
const { command, flags } = pluginConfig.biome;
|
||||
return ["biome", [command || "check", flags || ""]];
|
||||
}
|
||||
return ["biome", ["check"]];
|
||||
}
|
||||
},
|
||||
createDiagnostic
|
||||
});
|
||||
}
|
||||
init() {
|
||||
const _createServeAndBuild = super.initMainThread();
|
||||
createServeAndBuild = _createServeAndBuild;
|
||||
super.initWorkerThread();
|
||||
}
|
||||
}
|
||||
const biomeChecker = new BiomeChecker();
|
||||
biomeChecker.prepare();
|
||||
biomeChecker.init();
|
||||
export {
|
||||
BiomeChecker,
|
||||
createServeAndBuild
|
||||
};
|
||||
//# sourceMappingURL=main.js.map
|
||||
1
node_modules/vite-plugin-checker/dist/checkers/biome/main.js.map
generated
vendored
Normal file
1
node_modules/vite-plugin-checker/dist/checkers/biome/main.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
97
node_modules/vite-plugin-checker/dist/checkers/biome/types.d.ts
generated
vendored
Normal file
97
node_modules/vite-plugin-checker/dist/checkers/biome/types.d.ts
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
1
node_modules/vite-plugin-checker/dist/checkers/biome/types.js
generated
vendored
Normal file
1
node_modules/vite-plugin-checker/dist/checkers/biome/types.js
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
//# sourceMappingURL=types.js.map
|
||||
1
node_modules/vite-plugin-checker/dist/checkers/biome/types.js.map
generated
vendored
Normal file
1
node_modules/vite-plugin-checker/dist/checkers/biome/types.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
||||
Reference in New Issue
Block a user