From 58bf0c6f518e2620e4b9f6f05609b1b65655cfa7 Mon Sep 17 00:00:00 2001 From: Jordi Marimon Date: Mon, 22 Jan 2024 16:34:01 +0100 Subject: [PATCH] fix(core): add resolution of symbolic links in the compiler host Now the library can be used in projects where PNPM is used as the package manager. PNPM node_module layout uses symbolic links. We need to resolve the symbolic links. Refs #211 --- .eslintrc.json | 2 ++ packages/core/src/system/compiler-host.ts | 4 ++++ packages/core/src/system/node-system.ts | 17 ++++++++++------- scripts/docs/generate-api-reference.js | 2 +- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 403aacc1..497d96bf 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -280,6 +280,8 @@ "sonarjs/cognitive-complexity": "off", "jsdoc/require-jsdoc": "off", + "jsdoc/require-param-description": "off", + "jsdoc/require-returns": "off", "jsdoc/tag-lines": [ "error", "any", diff --git a/packages/core/src/system/compiler-host.ts b/packages/core/src/system/compiler-host.ts index a795ef94..43b4b236 100644 --- a/packages/core/src/system/compiler-host.ts +++ b/packages/core/src/system/compiler-host.ts @@ -75,4 +75,8 @@ export class CompilerHost implements ts.CompilerHost { ): string[] { return this._system.readDirectory(rootDir, extensions, excludes, includes, depth); } + + realpath(filePath: string): string { + return this._system.realpath(filePath); + } } diff --git a/packages/core/src/system/node-system.ts b/packages/core/src/system/node-system.ts index c94c9971..d93ac87b 100644 --- a/packages/core/src/system/node-system.ts +++ b/packages/core/src/system/node-system.ts @@ -30,7 +30,7 @@ export class NodeSystem implements AnalyserSystem { /** * Writes the content * - * @param content + * @param content - Content to write to the file */ write(content: string): void { ts.sys.write(content); @@ -39,8 +39,10 @@ export class NodeSystem implements AnalyserSystem { /** * Reads the data encoded inside a file * - * @param filePath - * @param encoding + * @param filePath - The file path + * @param encoding - The file econding + * + * @returns The content of the file */ readFile(filePath: string, encoding?: string): string { const absolutePath = this.getAbsolutePath(filePath); @@ -49,9 +51,7 @@ export class NodeSystem implements AnalyserSystem { writeFile(filePath: string, data: string): void { const absolutePath = this.getAbsolutePath(filePath); - this._ensureDirectoryExistence(absolutePath); - ts.sys.writeFile(absolutePath, data); } @@ -77,9 +77,7 @@ export class NodeSystem implements AnalyserSystem { createDirectory(filePath: string): void { const absolutePath = this.getAbsolutePath(filePath); - this._ensureDirectoryExistence(absolutePath); - ts.sys.createDirectory(absolutePath); } @@ -167,6 +165,11 @@ export class NodeSystem implements AnalyserSystem { return path.isAbsolute(filePath); } + /** + * Resolves symlinks to get the real path + * + * @param filePath + */ realpath(filePath: string): string { return fs.realpathSync.native ? platform === 'win32' diff --git a/scripts/docs/generate-api-reference.js b/scripts/docs/generate-api-reference.js index 1477bbd3..1111860c 100644 --- a/scripts/docs/generate-api-reference.js +++ b/scripts/docs/generate-api-reference.js @@ -81,7 +81,7 @@ if (!indexModule) { // The modules that are explicitly exported in the entry point of the package const publicModules = indexModule .getExports() - .filter(exp => is.ReExportNode(exp)) + .filter(is.ReExportNode) .map(exp => { // Modern ESM imports include the ".js" extension const modulePath = exp.getModule().replace(/'/g, '').replace('.js', '.ts');