-
Notifications
You must be signed in to change notification settings - Fork 722
support pnp resolver #1876
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
base: main
Are you sure you want to change the base?
support pnp resolver #1876
Changes from all commits
c315580
99dc36c
25b13ac
f24a170
b4aaac8
2373552
f09cda5
d00e36b
0a0f050
94a15b7
35d6188
35ee2ef
9463e11
dd08ae5
b368c1c
688455e
305fd49
f0ee55b
ef6d713
8d165ca
ae272f1
67752dc
1f06041
a9dbc68
df40d62
1485fe3
bfa05c3
e697dce
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package compiler | ||
|
||
import ( | ||
"io/fs" | ||
"os" | ||
"path/filepath" | ||
Comment on lines
+5
to
+6
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The compiler should not depend on these; any accesses it makes must go through a provided FS. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (#1911 will enforce this in the future) |
||
|
||
"github.com/microsoft/typescript-go/internal/module/pnp" | ||
) | ||
|
||
func TryGetPnpResolutionConfig(path string) *pnp.ResolutionConfig { | ||
pnpManifestPath, err := findNearestPNPPath(path) | ||
if err != nil { | ||
return nil | ||
} | ||
pnpManifest, err := pnp.LoadPNPManifest(pnpManifestPath) | ||
if err != nil { | ||
return nil | ||
} | ||
|
||
return &pnp.ResolutionConfig{ | ||
Host: pnp.PNPResolutionHost{ | ||
FindPNPManifest: func(_ string) (*pnp.Manifest, error) { | ||
return &pnpManifest, nil | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func findNearestPNPPath(start string) (string, error) { | ||
dir := start | ||
if fi, err := os.Stat(start); err == nil { | ||
if !fi.IsDir() { | ||
dir = filepath.Dir(start) | ||
} | ||
} else { | ||
dir = filepath.Dir(start) | ||
} | ||
|
||
for { | ||
for _, name := range []string{".pnp.data.json", ".pnp.cjs", ".pnp.js"} { | ||
candidate := filepath.Join(dir, name) | ||
if fi, err := os.Stat(candidate); err == nil && !fi.IsDir() { | ||
return candidate, nil | ||
} | ||
} | ||
parent := filepath.Dir(dir) | ||
if parent == dir { | ||
break | ||
} | ||
dir = parent | ||
} | ||
return "", fs.ErrNotExist | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do wonder if this is the right layer for this. Surely the language server also needs to know this information? For example, we need to read random files to do source mapping in the LS layer, which would have to dig into zips.
But, we don't want cached info to be there indefinitely either.
I also don't know where this should go in relation to the caching layer...