From ae8a723b1968f5db47b281ddbfbcaef25dc527e8 Mon Sep 17 00:00:00 2001 From: Emanuele Stoppa Date: Thu, 25 Apr 2024 10:34:12 +0100 Subject: [PATCH] fix regression --- packages/@biomejs/js-api/src/index.ts | 49 ++++++++++++++++----------- 1 file changed, 29 insertions(+), 20 deletions(-) diff --git a/packages/@biomejs/js-api/src/index.ts b/packages/@biomejs/js-api/src/index.ts index fe1e26780621..505140158822 100644 --- a/packages/@biomejs/js-api/src/index.ts +++ b/packages/@biomejs/js-api/src/index.ts @@ -6,12 +6,12 @@ import type { PullDiagnosticsResult, Workspace, } from "@biomejs/wasm-nodejs"; -import { Distribution, type WasmModule, loadModule, wrapError } from "./wasm"; +import {Distribution, type WasmModule, loadModule, wrapError} from "./wasm"; // Re-export of some useful types for users export type Configuration = PartialConfiguration; -export type { Diagnostic }; -export { Distribution }; +export type {Diagnostic}; +export {Distribution}; export interface FormatContentDebugOptions extends FormatContentOptions { /** @@ -93,7 +93,8 @@ export class Biome { private constructor( private readonly module: WasmModule, private readonly workspace: Workspace, - ) {} + ) { + } /** * It creates a new instance of the class {Biome}. @@ -101,7 +102,9 @@ export class Biome { public static async create(options: BiomeCreate): Promise { const module = await loadModule(options.distribution); const workspace = new module.Workspace(); - return new Biome(module, workspace); + const biome = new Biome(module, workspace); + biome.registerProjectFolder(); + return biome } /** @@ -123,18 +126,24 @@ export class Biome { */ public applyConfiguration(configuration: Configuration): void { try { - this.workspace.registerProjectFolder({ - setAsCurrentWorkspace: true, - }); this.workspace.updateSettings({ configuration, gitignore_matches: [], + workspace_directory: "./" }); } catch (e) { throw wrapError(e); } } + public registerProjectFolder(): void; + public registerProjectFolder(path?: String): void { + this.workspace.registerProjectFolder({ + path, + setAsCurrentWorkspace: true + }) + } + private tryCatchWrapper(func: () => T): T { try { return func(); @@ -188,7 +197,7 @@ export class Biome { return this.withFile(options.filePath, content, (path) => { let code = content; - const { diagnostics } = this.workspace.pullDiagnostics({ + const {diagnostics} = this.workspace.pullDiagnostics({ path, categories: ["Syntax"], max_diagnostics: Number.MAX_SAFE_INTEGER, @@ -239,26 +248,26 @@ export class Biome { */ lintContent( content: string, - { filePath, fixFileMode }: LintContentOptions, + {filePath, fixFileMode}: LintContentOptions, ): LintResult { const maybeFixedContent = fixFileMode ? this.withFile(filePath, content, (path) => { - let code = content; + let code = content; - const result = this.workspace.fixFile({ - path, - fix_file_mode: fixFileMode, - should_format: false, - }); + const result = this.workspace.fixFile({ + path, + fix_file_mode: fixFileMode, + should_format: false, + }); - code = result.code; + code = result.code; - return code; - }) + return code; + }) : content; return this.withFile(filePath, maybeFixedContent, (path) => { - const { diagnostics } = this.workspace.pullDiagnostics({ + const {diagnostics} = this.workspace.pullDiagnostics({ path, categories: ["Syntax", "Lint"], max_diagnostics: Number.MAX_SAFE_INTEGER,