Skip to content

Commit 5e25a5e

Browse files
committed
Yarn-pnp: Attach to session and hoist filesystem overrides
1 parent 3e87b7f commit 5e25a5e

5 files changed

Lines changed: 12 additions & 24 deletions

File tree

internal/project/autoimport.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"github.com/microsoft/typescript-go/internal/pnp"
1212
"github.com/microsoft/typescript-go/internal/tspath"
1313
"github.com/microsoft/typescript-go/internal/vfs"
14-
"github.com/microsoft/typescript-go/internal/vfs/pnpvfs"
1514
)
1615

1716
type autoImportBuilderFS struct {
@@ -83,14 +82,10 @@ func newAutoImportRegistryCloneHost(
8382
projectCollection *ProjectCollection,
8483
parseCache *ParseCache,
8584
snapshotFSBuilder *snapshotFSBuilder,
85+
pnpApi *pnp.PnpApi,
8686
currentDirectory string,
8787
toPath func(fileName string) tspath.Path,
8888
) *autoImportRegistryCloneHost {
89-
pnpApi := pnp.InitPnpApi(snapshotFSBuilder.fs, currentDirectory)
90-
if pnpApi != nil {
91-
snapshotFSBuilder.fs = pnpvfs.From(snapshotFSBuilder.fs)
92-
}
93-
9489
return &autoImportRegistryCloneHost{
9590
projectCollection: projectCollection,
9691
parseCache: parseCache,

internal/project/compilerhost.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"github.com/microsoft/typescript-go/internal/tsoptions"
1010
"github.com/microsoft/typescript-go/internal/tspath"
1111
"github.com/microsoft/typescript-go/internal/vfs"
12-
"github.com/microsoft/typescript-go/internal/vfs/pnpvfs"
1312
)
1413

1514
var _ compiler.CompilerHost = (*compilerHost)(nil)
@@ -34,17 +33,12 @@ func newCompilerHost(
3433
builder *ProjectCollectionBuilder,
3534
logger *logging.LogTree,
3635
) *compilerHost {
37-
pnpApi := pnp.InitPnpApi(builder.fs.fs, currentDirectory)
38-
if pnpApi != nil {
39-
builder.fs.fs = pnpvfs.From(builder.fs.fs)
40-
}
41-
4236
return &compilerHost{
4337
configFilePath: project.configFilePath,
4438
currentDirectory: currentDirectory,
4539
sessionOptions: builder.sessionOptions,
4640

47-
pnpApi: pnpApi,
41+
pnpApi: builder.pnpApi,
4842
sourceFS: newSourceFS(true, builder.fs, builder.toPath),
4943

5044
project: project,

internal/project/projectcollectionbuilder.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ type ProjectCollectionBuilder struct {
3535

3636
ctx context.Context
3737
fs *snapshotFSBuilder
38+
pnpApi *pnp.PnpApi
3839
base *ProjectCollection
3940
compilerOptionsForInferredProjects *core.CompilerOptions
4041
configFileRegistryBuilder *configFileRegistryBuilder
@@ -56,12 +57,12 @@ func newProjectCollectionBuilder(
5657
ctx context.Context,
5758
newSnapshotID uint64,
5859
fs *snapshotFSBuilder,
60+
pnpApi *pnp.PnpApi,
5961
oldProjectCollection *ProjectCollection,
6062
oldConfigFileRegistry *ConfigFileRegistry,
6163
oldAPIOpenedProjects map[tspath.Path]struct{},
6264
compilerOptionsForInferredProjects *core.CompilerOptions,
6365
sessionOptions *SessionOptions,
64-
pnpApi *pnp.PnpApi,
6566
customConfigFileName string,
6667
parseCache *ParseCache,
6768
extendedConfigCache *ExtendedConfigCache,
@@ -70,6 +71,7 @@ func newProjectCollectionBuilder(
7071
return &ProjectCollectionBuilder{
7172
ctx: ctx,
7273
fs: fs,
74+
pnpApi: pnpApi,
7375
toPath: fs.toPath,
7476
compilerOptionsForInferredProjects: compilerOptionsForInferredProjects,
7577
sessionOptions: sessionOptions,

internal/project/session.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ type Session struct {
8787
logger logging.Logger
8888
npmExecutor ata.NpmExecutor
8989
fs *overlayFS
90+
pnpApi *pnp.PnpApi
9091

9192
// parseCache is the ref-counted cache of source files used when
9293
// creating programs during snapshot cloning.
@@ -181,6 +182,7 @@ func NewSession(init *SessionInit) *Session {
181182
logger: init.Logger,
182183
npmExecutor: init.NpmExecutor,
183184
fs: overlayFS,
185+
pnpApi: init.PnpApi,
184186
parseCache: parseCache,
185187
extendedConfigCache: extendedConfigCache,
186188
programCounter: &programCounter{},
@@ -243,7 +245,7 @@ func (s *Session) GetCurrentDirectory() string {
243245

244246
// PnpApi implements module.ResolutionHost
245247
func (s *Session) PnpApi() *pnp.PnpApi {
246-
return s.snapshot.PnpApi()
248+
return s.pnpApi
247249
}
248250

249251
// Gets copy of current configuration

internal/project/snapshot.go

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"github.com/microsoft/typescript-go/internal/project/logging"
2222
"github.com/microsoft/typescript-go/internal/sourcemap"
2323
"github.com/microsoft/typescript-go/internal/tspath"
24-
"github.com/microsoft/typescript-go/internal/vfs/pnpvfs"
2524
"github.com/microsoft/typescript-go/internal/vfs/vfsmatch"
2625
)
2726

@@ -65,10 +64,6 @@ func NewSnapshot(
6564
toPath func(fileName string) tspath.Path,
6665
pnpApi *pnp.PnpApi,
6766
) *Snapshot {
68-
if pnpApi != nil {
69-
fs.fs = pnpvfs.From(fs.fs)
70-
}
71-
7267
s := &Snapshot{
7368
id: id,
7469

@@ -80,11 +75,10 @@ func NewSnapshot(
8075
ProjectCollection: &ProjectCollection{toPath: toPath},
8176
compilerOptionsForInferredProjects: compilerOptionsForInferredProjects,
8277

83-
pnpApi: pnpApi,
84-
8578
userPreferences: userPreferences,
8679
AutoImports: autoImports,
8780
autoImportsWatch: autoImportsWatch,
81+
pnpApi: pnpApi,
8882
}
8983
s.refCount.Store(1)
9084
s.converters = lsconv.NewConverters(s.sessionOptions.PositionEncoding, s.LSPLineMap)
@@ -339,12 +333,12 @@ func (s *Snapshot) Clone(ctx context.Context, change SnapshotChange, overlays ma
339333
ctx,
340334
newSnapshotID,
341335
fs,
336+
session.pnpApi,
342337
s.ProjectCollection,
343338
s.ConfigFileRegistry,
344339
s.ProjectCollection.apiOpenedProjects,
345340
compilerOptionsForInferredProjects,
346341
s.sessionOptions,
347-
s.pnpApi,
348342
customConfigFileName,
349343
session.parseCache,
350344
session.extendedConfigCache,
@@ -429,6 +423,7 @@ func (s *Snapshot) Clone(ctx context.Context, change SnapshotChange, overlays ma
429423
projectCollection,
430424
session.parseCache,
431425
fs,
426+
session.pnpApi,
432427
s.sessionOptions.CurrentDirectory,
433428
s.toPath,
434429
)
@@ -469,7 +464,7 @@ func (s *Snapshot) Clone(ctx context.Context, change SnapshotChange, overlays ma
469464
autoImports,
470465
autoImportsWatch,
471466
s.toPath,
472-
s.pnpApi,
467+
session.pnpApi,
473468
)
474469
newSnapshot.parentId = s.id
475470
newSnapshot.ProjectCollection = projectCollection

0 commit comments

Comments
 (0)