oxc-project / oxc-resolver

Rust version of webpack/enhanced-resolve
https://oxc.rs/docs/guide/usage/resolver.html
MIT License
122 stars 18 forks source link

Extending a `tsconfig` using a package #263

Open NicholasLYang opened 1 week ago

NicholasLYang commented 1 week ago

So uhh, this is a bit of a cart and a horse situation. You can extend a tsconfig using a package, e.g.

{
  "extends": "my-package/tsconfig.json"
}

This doesn't seem to work with oxc_resolver, understandably so, since resolving this package import requires...a resolver, which is what we're creating in the first place. But maybe we can do a "best shot" where we use a basic resolver to resolve the extends key?

Thanks!

Boshen commented 6 days ago

Can you get me a production?

I tried adding a test in the branch https://github.com/oxc-project/oxc-resolver/tree/extend-package

just example /Users/boshen/oxc/oxc-resolver/fixtures/tsconfig/cases/extends-package-tsconfig foo

gives me the tsconfig

[src/lib.rs:1116:9] &tsconfig = TsConfig {
    root: true,
    path: "/Users/boshen/oxc/oxc-resolver/fixtures/tsconfig/cases/extends-package-tsconfig/tsconfig.json",
    extends: Some(
        Single(
            "tsconfig-index/tsconfig.json",
        ),
    ),
    compiler_options: CompilerOptions {
        base_url: None,
        paths: Some(
            {
                "foo": [
                    "foo.js",
                ],
            },
        ),
        paths_base: "/Users/boshen/oxc/oxc-resolver/fixtures/tsconfig/node_modules/tsconfig-index",
    },
    references: [],
}

which seems to be correct because paths_base is pointing to tsconfig-index (the "extends": "tsconfig-index/tsconfig.json").

Boshen commented 6 days ago

If you want to debug yourself:

https://github.com/oxc-project/oxc-resolver/blob/376e25449ec13a50e1a11dc899b2137bfc8cf9b0/src/lib.rs#L1140

Resolving extended ts config just reuses the resolver:

https://github.com/oxc-project/oxc-resolver/blob/376e25449ec13a50e1a11dc899b2137bfc8cf9b0/src/lib.rs#L1193-L1219