From 7c66aedc4aed013f48adfff2f94c4b83f1d773f3 Mon Sep 17 00:00:00 2001 From: Jordi Marimon Date: Mon, 11 Mar 2024 19:16:44 +0100 Subject: [PATCH] refactor(core): use system in the format diagnostics host --- packages/core/src/analyser-diagnostic.ts | 10 ++++------ packages/core/src/project.ts | 4 ++-- packages/core/src/system/analyser-system.ts | 4 +--- packages/core/src/utils/member.ts | 3 +++ tailwind.config.cjs | 3 +-- 5 files changed, 11 insertions(+), 13 deletions(-) diff --git a/packages/core/src/analyser-diagnostic.ts b/packages/core/src/analyser-diagnostic.ts index 08d182b6..2d86f4ca 100644 --- a/packages/core/src/analyser-diagnostic.ts +++ b/packages/core/src/analyser-diagnostic.ts @@ -1,4 +1,5 @@ import ts from 'typescript'; +import type { AnalyserSystem } from './system/analyser-system.js'; /** @@ -25,14 +26,11 @@ export class AnalyserDiagnostic { private readonly _formatDiagnosticHost: ts.FormatDiagnosticsHost; - private readonly _cwd: string; - - constructor(cwd: string) { - this._cwd = cwd; + constructor(system: AnalyserSystem) { this._formatDiagnosticHost = { getCanonicalFileName: (name: string) => name, - getCurrentDirectory: () => this._cwd, - getNewLine: () => '\n', + getCurrentDirectory: () => system.getCurrentDirectory(), + getNewLine: () => system.newLine, }; } diff --git a/packages/core/src/project.ts b/packages/core/src/project.ts index fd0a3521..2fbb6ce1 100644 --- a/packages/core/src/project.ts +++ b/packages/core/src/project.ts @@ -49,7 +49,7 @@ export class Project { this._program = program; this._commandLine = commandLine; this._options = options; - this._diagnostics = new AnalyserDiagnostic(system.getCurrentDirectory()); + this._diagnostics = new AnalyserDiagnostic(system); this._packageJson = this._getPackageJSON(); this._context = new ProjectContext( system, @@ -191,7 +191,7 @@ export class Project { * @returns True if the source file has been already analysed, false otherwise */ has(filePath: string): boolean { - const normalizedPath = this._context.getSystem().normalizePath(filePath); + const normalizedPath = this._system.normalizePath(filePath); return this._modules.some(m => m.getSourcePath() === normalizedPath); } diff --git a/packages/core/src/system/analyser-system.ts b/packages/core/src/system/analyser-system.ts index 92caaa6e..bd249557 100644 --- a/packages/core/src/system/analyser-system.ts +++ b/packages/core/src/system/analyser-system.ts @@ -23,9 +23,7 @@ export interface AnalyserSystem extends ts.System { getAbsolutePath(path: string): string; /** - * Returns the real location of the path. - * - * This is handy when resolving symlinks. + * Returns the real location of the path (resolves symlinks). */ realpath(path: string): string; diff --git a/packages/core/src/utils/member.ts b/packages/core/src/utils/member.ts index eb7a076e..0f84bc99 100644 --- a/packages/core/src/utils/member.ts +++ b/packages/core/src/utils/member.ts @@ -5,6 +5,9 @@ import { isThirdParty } from './import.js'; import ts from 'typescript'; +// TODO(Jordi M.): Create method that abstracts the call to "ts.canHaveModifier" +// as this method only exists in TS >= 4.8 + export function getVisibilityModifier(member: ts.ClassElement): ModifierType { const modifierFlags = ts.getCombinedModifierFlags(member); diff --git a/tailwind.config.cjs b/tailwind.config.cjs index 617e70c2..12c43bf4 100644 --- a/tailwind.config.cjs +++ b/tailwind.config.cjs @@ -1,8 +1,7 @@ /** @type {import('tailwindcss').Config} */ module.exports = { content: [ - './docs/**/*.{njk,md,html}', - './scripts/docs/generate-api-reference.js', + './docs/**/*.{njk,md,html}' ], theme: {