-
Notifications
You must be signed in to change notification settings - Fork 718
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
Open
gun-yu
wants to merge
14
commits into
microsoft:main
Choose a base branch
from
gun-yu:feat/add-pnp-resolver
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+20,945
−56
Open
support pnp resolver #1876
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
c315580
add pnp resolution support
gun-yu 99dc36c
remove fmt
gun-yu 25b13ac
pnp internalize
gun-yu f24a170
remove useless code
gun-yu b4aaac8
remove useless code
gun-yu 2373552
use go-json-experiment/json
gun-yu f09cda5
lint fix
gun-yu d00e36b
Merge branch 'main' into feat/add-pnp-resolver
gun-yu 0a0f050
change test data path
gun-yu 94a15b7
fix hereby format
gun-yu 35d6188
fix hereby check:format
gun-yu 35ee2ef
fix window test
gun-yu 9463e11
Merge branch 'feat/add-pnp-resolver' of https://github.com/gun-yu/typ…
gun-yu dd08ae5
Merge branch 'main' into feat/add-pnp-resolver
gun-yu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
module github.com/microsoft/typescript-go | ||
|
||
go 1.25 | ||
go 1.25.1 | ||
|
||
require ( | ||
github.com/dlclark/regexp2 v1.11.5 | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package compiler | ||
|
||
import ( | ||
"io/fs" | ||
"os" | ||
"path/filepath" | ||
|
||
module "github.com/microsoft/typescript-go/internal/module/pnp" | ||
) | ||
|
||
func TryGetPnpResolutionConfig(path string) *module.ResolutionConfig { | ||
pnpManifestPath, err := findNearestPNPPath(path) | ||
if err != nil { | ||
return nil | ||
} | ||
pnpManifest, err := module.LoadPNPManifest(pnpManifestPath) | ||
if err != nil { | ||
return nil | ||
} | ||
|
||
return &module.ResolutionConfig{ | ||
Host: module.ResolutionHost{ | ||
FindPNPManifest: func(_ string) (*module.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 | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package pnp | ||
|
||
import "slices" | ||
|
||
var NodeJSBuiltins = []string{ | ||
"assert", | ||
"assert/strict", | ||
"async_hooks", | ||
"buffer", | ||
"child_process", | ||
"cluster", | ||
"console", | ||
"constants", | ||
"crypto", | ||
"dgram", | ||
"diagnostics_channel", | ||
"dns", | ||
"dns/promises", | ||
"domain", | ||
"events", | ||
"fs", | ||
"fs/promises", | ||
"http", | ||
"http2", | ||
"https", | ||
"inspector", | ||
"module", | ||
"net", | ||
"os", | ||
"path", | ||
"path/posix", | ||
"path/win32", | ||
"perf_hooks", | ||
"process", | ||
"punycode", | ||
"querystring", | ||
"readline", | ||
"readline/promises", | ||
"repl", | ||
"stream", | ||
"stream/consumers", | ||
"stream/promises", | ||
"stream/web", | ||
"string_decoder", | ||
"sys", | ||
"timers", | ||
"timers/promises", | ||
"tls", | ||
"trace_events", | ||
"tty", | ||
"url", | ||
"util", | ||
"util/types", | ||
"v8", | ||
"vm", | ||
"worker_threads", | ||
"zlib", | ||
} | ||
|
||
func IsNodeJSBuiltin(s string) bool { | ||
return slices.Contains(NodeJSBuiltins, s) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
On second thought, this way I wouldn’t be able to take advantage of the cached VFS, so I’m thinking of moving its location instead.