Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions tsc/internal/bundled/embed.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import (
"strings"
"time"

"github.com/microsoft/TypeScript/tsc/internal/fswatch"
"github.com/microsoft/TypeScript/tsc/internal/vfs"
"github.com/microsoft/TypeScript/tsc/internal/watchalias"
)

const embedded = true
Expand Down Expand Up @@ -46,6 +48,21 @@ func (vfs *wrappedFS) UseCaseSensitiveFileNames() bool {
return vfs.fs.UseCaseSensitiveFileNames()
}

func (vfs *wrappedFS) WatchPathComparer(directory string) (fswatch.PathComparer, error) {
if !IsBundled(directory) {
if provider, ok := vfs.fs.(interface {
WatchPathComparer(directory string) (fswatch.PathComparer, error)
}); ok {
return provider.WatchPathComparer(directory)
}
}
return fswatch.PathComparer{}, nil
}

func (vfs *wrappedFS) WatchPathComparisonEnabled() bool {
return watchalias.Enabled(vfs.fs)
}

func (vfs *wrappedFS) FileExists(path string) bool {
if rest, ok := splitPath(path); ok {
_, ok := embeddedContents[rest]
Expand Down Expand Up @@ -152,6 +169,13 @@ func (vfs *wrappedFS) Realpath(path string) string {
return vfs.fs.Realpath(path)
}

func (fsys *wrappedFS) RealpathWithParent(path string, realpath func(string) string) string {
if IsBundled(path) {
return path
}
return vfs.RealpathWithParent(fsys.fs, path, realpath)
}

func (vfs *wrappedFS) WriteFile(path string, data string) error {
if _, ok := splitPath(path); ok {
panic("cannot write to embedded file system")
Expand Down
26 changes: 22 additions & 4 deletions tsc/internal/execute/build/buildtask.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/microsoft/TypeScript/tsc/internal/execute/tsc"
"github.com/microsoft/TypeScript/tsc/internal/tsoptions"
"github.com/microsoft/TypeScript/tsc/internal/tspath"
"github.com/microsoft/TypeScript/tsc/internal/vfs/trackingvfs"
)

type buildKind uint
Expand All @@ -37,10 +38,18 @@ type upstreamTask struct {
type buildInfoEntry struct {
buildInfo *incremental.BuildInfo
path tspath.Path
fileName string
mTime time.Time
dtsTime *time.Time
}

func (b *buildInfoEntry) directory() string {
if b.fileName != "" {
return tspath.GetDirectoryPath(b.fileName)
}
return tspath.GetDirectoryPath(string(b.path))
}

type taskResult struct {
builder strings.Builder
reportStatus tsc.DiagnosticReporter
Expand Down Expand Up @@ -68,6 +77,7 @@ type BuildTask struct {
buildInfoEntry *buildInfoEntry
buildInfoEntryMu sync.Mutex
packageJsons []string
seenFiles []string

errors []*ast.Diagnostic
pending atomic.Bool
Expand Down Expand Up @@ -147,11 +157,11 @@ func (t *BuildTask) report(orchestrator *Orchestrator, configPath tspath.Path, b
close(t.reportDone)
}

func (t *BuildTask) buildProject(orchestrator *Orchestrator, path tspath.Path) {
func (t *BuildTask) buildProject(orchestrator *Orchestrator, path tspath.Path, force bool) {
// Wait on upstream tasks to complete
t.waitOnUpstream()
if t.pending.Load() {
t.status = t.getUpToDateStatus(orchestrator, path)
t.status = t.getUpToDateStatus(orchestrator, path, force)
t.reportUpToDateStatus(orchestrator)
if !t.handleStatusThatDoesntRequireBuild(orchestrator) {
t.compileAndEmit(orchestrator, path)
Expand Down Expand Up @@ -247,6 +257,9 @@ func (t *BuildTask) compileAndEmit(orchestrator *Orchestrator, path tspath.Path)
trace: tsc.GetTraceWithWriterFromSys(&t.result.builder, orchestrator.opts.Command.Locale(), orchestrator.opts.Testing),
contentMapperProject: contentMapperProject,
}
if orchestrator.opts.Command.CompilerOptions.Watch.IsTrue() {
compilerHost.tracked = &trackingvfs.FS{Inner: orchestrator.host.FS()}
}
if !orchestrator.opts.Command.BuildOptions.Force.IsTrue() {
oldProgram = incremental.ReadBuildInfoProgram(t.resolved, orchestrator.host, compilerHost)
}
Expand All @@ -256,6 +269,9 @@ func (t *BuildTask) compileAndEmit(orchestrator *Orchestrator, path tspath.Path)
Config: t.resolved,
Host: compilerHost,
})
if compilerHost.tracked != nil {
t.seenFiles = compilerHost.tracked.SeenFiles.ToSlice()
}
compileTimes.ParseTime = orchestrator.opts.Sys.Now().Sub(parseStart)
changesComputeStart := orchestrator.opts.Sys.Now()
t.result.program = incremental.NewProgram(program, oldProgram, orchestrator.host, orchestrator.opts.Sys.Now, orchestrator.opts.Testing != nil)
Expand Down Expand Up @@ -348,7 +364,7 @@ func (t *BuildTask) handleStatusThatDoesntRequireBuild(orchestrator *Orchestrato
return false
}

func (t *BuildTask) getUpToDateStatus(orchestrator *Orchestrator, configPath tspath.Path) *upToDateStatus {
func (t *BuildTask) getUpToDateStatus(orchestrator *Orchestrator, configPath tspath.Path, force bool) *upToDateStatus {
if t.status != nil {
return t.status
}
Expand All @@ -369,7 +385,7 @@ func (t *BuildTask) getUpToDateStatus(orchestrator *Orchestrator, configPath tsp
}
}

if orchestrator.opts.Command.BuildOptions.Force.IsTrue() {
if orchestrator.opts.Command.BuildOptions.Force.IsTrue() || force {
return &upToDateStatus{kind: upToDateStatusTypeForceBuild}
}

Expand Down Expand Up @@ -854,6 +870,7 @@ func (t *BuildTask) loadOrStoreBuildInfo(orchestrator *Orchestrator, configPath
t.buildInfoEntry = &buildInfoEntry{
buildInfo: incremental.NewBuildInfoReader(orchestrator.host).ReadBuildInfo(t.resolved),
path: path,
fileName: buildInfoFileName,
}
var mTime time.Time
if t.buildInfoEntry.buildInfo != nil {
Expand All @@ -876,6 +893,7 @@ func (t *BuildTask) onBuildInfoEmit(orchestrator *Orchestrator, buildInfoFileNam
t.buildInfoEntry = &buildInfoEntry{
buildInfo: buildInfo,
path: orchestrator.toPath(buildInfoFileName),
fileName: buildInfoFileName,
mTime: mTime,
dtsTime: dtsTime,
}
Expand Down
8 changes: 8 additions & 0 deletions tsc/internal/execute/build/compilerHost.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,22 @@ import (
"github.com/microsoft/TypeScript/tsc/internal/tsoptions"
"github.com/microsoft/TypeScript/tsc/internal/tspath"
"github.com/microsoft/TypeScript/tsc/internal/vfs"
"github.com/microsoft/TypeScript/tsc/internal/vfs/trackingvfs"
)

type compilerHost struct {
host *host
trace func(msg *diagnostics.Message, args ...any)
contentMapperProject contentmapper.Project
tracked *trackingvfs.FS
}

var _ compiler.CompilerHost = (*compilerHost)(nil)

func (h *compilerHost) FS() vfs.FS {
if h.tracked != nil {
return h.tracked
}
return h.host.FS()
}

Expand All @@ -35,6 +40,9 @@ func (h *compilerHost) Trace(msg *diagnostics.Message, args ...any) {
}

func (h *compilerHost) GetSourceFile(opts ast.SourceFileParseOptions) *ast.SourceFile {
if h.tracked != nil {
h.tracked.SeenFiles.Add(opts.FileName)
}
return h.host.GetSourceFile(opts)
}

Expand Down
Loading