Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: search for "extends" config in node_modules in parent folders in monorepo. #236

Open
allista opened this issue Jan 23, 2023 · 1 comment

Comments

@allista
Copy link

allista commented Jan 23, 2023

Hi,
we have a monorepo with a lot of packages, and some things, including our base tsconfig.json that we extend in all other packages, are installed in the root node_modules.

Currently tsconfig-paths is only searching for the "extends" file in the node_modules next to the original tsconfig.file.

I don't have capacity right now for a proper PR, but I made a pnpm patch that solves the issue for us.

I hope it'll be useful for someone in the meantime:

diff --git a/lib/tsconfig-loader.js b/lib/tsconfig-loader.js
index d298653fa4119fff689d60cce11cce73bb801420..619a374585119e37154393b7b63c6b14e88857eb 100644
--- a/lib/tsconfig-loader.js
+++ b/lib/tsconfig-loader.js
@@ -107,7 +107,18 @@ existsSync, readFileSync) {
         if (extendedConfig.indexOf("/") !== -1 &&
             extendedConfig.indexOf(".") !== -1 &&
             !existsSync(extendedConfigPath)) {
-            extendedConfigPath = path.join(currentDir, "node_modules", extendedConfig);
+            var lookupDir = currentDir;
+            while(existsSync(lookupDir)) {
+                extendedConfigPath = path.join(lookupDir, "node_modules", extendedConfig);
+                if(existsSync(extendedConfigPath)) {
+                    break;
+                }
+                var nextDir = path.normalize(path.resolve(lookupDir, '..'));
+                if(nextDir === lookupDir){
+                    break;
+                }
+                lookupDir = nextDir;
+            }
         }
         var base = loadTsconfig(extendedConfigPath, existsSync, readFileSync) || {};
         // baseUrl should be interpreted as relative to the base tsconfig,
@attila
Copy link

attila commented Feb 6, 2023

This definitely is missing from tsconfig-paths. We have a slightly different use case where base tsconfigs are not in the monorepo root but in a package called tsconfig, so extends looks like this in a workspace's tsconfig:

{
  "extends": "@my-internal-scope/tsconfig/nodejs.json",
  "ts-node": {
    "files": true,
    "require": ["tsconfig-paths/register"],
    "transpileOnly": true
  }
}

In above example we extend from a preset called "nodejs" which in turn extends from a base, where all path mappings internal to the monorepo reside. I wish tsconfig-paths resolved those too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants