Skip to content
This repository has been archived by the owner on Jun 15, 2024. It is now read-only.

Commit

Permalink
fix(core): add resolution of symbolic links in the compiler host
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jordimarimon committed Jan 22, 2024
1 parent c105ffb commit 58bf0c6
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 4 additions & 0 deletions packages/core/src/system/compiler-host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
17 changes: 10 additions & 7 deletions packages/core/src/system/node-system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
}

Expand All @@ -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);
}

Expand Down Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion scripts/docs/generate-api-reference.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit 58bf0c6

Please sign in to comment.