ttsc 0.14.2 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/driver/emit_plugin.go +131 -0
- package/driver/plugins.go +37 -0
- package/go.mod +0 -3
- package/go.sum +0 -4
- package/lib/compiler/internal/resolveEmittedJavaScript.js +25 -4
- package/lib/compiler/internal/resolveEmittedJavaScript.js.map +1 -1
- package/lib/launcher/internal/prepareExecution.d.ts +4 -1
- package/lib/launcher/internal/prepareExecution.js +13 -17
- package/lib/launcher/internal/prepareExecution.js.map +1 -1
- package/lib/launcher/internal/registerRuntimeHooks.js +43 -8
- package/lib/launcher/internal/registerRuntimeHooks.js.map +1 -1
- package/lib/launcher/internal/runTtsx.js +46 -386
- package/lib/launcher/internal/runTtsx.js.map +1 -1
- package/lib/launcher/internal/runtimeHookPreload.d.ts +1 -0
- package/lib/launcher/internal/runtimeHookPreload.js +16 -0
- package/lib/launcher/internal/runtimeHookPreload.js.map +1 -0
- package/lib/launcher/internal/runtimeHooks.d.ts +16 -38
- package/lib/launcher/internal/runtimeHooks.js +672 -119
- package/lib/launcher/internal/runtimeHooks.js.map +1 -1
- package/lib/plugin/internal/buildSourcePlugin.js +120 -16
- package/lib/plugin/internal/buildSourcePlugin.js.map +1 -1
- package/lib/plugin/internal/loadProjectPlugins.js +15 -4
- package/lib/plugin/internal/loadProjectPlugins.js.map +1 -1
- package/package.json +8 -8
- package/shim/ast/parent.go +31 -0
- package/shim/compiler/emitassemble.go +30 -0
- package/shim/compiler/emithook.go +22 -0
- package/shim/compiler/go.mod +9 -0
- package/shim/compiler/go.sum +22 -0
- package/shim/core/modulekind.go +10 -0
- package/shim/printer/emithost.go +24 -0
- package/shim/printer/go.mod +9 -0
- package/shim/printer/go.sum +22 -0
- package/shim/transformers/go.mod +14 -0
- package/shim/transformers/go.sum +20 -0
- package/shim/transformers/shim.go +15 -0
- package/src/compiler/internal/resolveEmittedJavaScript.ts +35 -4
- package/src/launcher/internal/prepareExecution.ts +18 -21
- package/src/launcher/internal/registerRuntimeHooks.ts +53 -8
- package/src/launcher/internal/runTtsx.ts +61 -453
- package/src/launcher/internal/runtimeHookPreload.ts +14 -0
- package/src/launcher/internal/runtimeHooks.ts +794 -136
- package/src/plugin/internal/buildSourcePlugin.ts +147 -16
- package/src/plugin/internal/loadProjectPlugins.ts +16 -4
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
package driver
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"errors"
|
|
5
|
+
|
|
6
|
+
shimast "github.com/microsoft/typescript-go/shim/ast"
|
|
7
|
+
shimcompiler "github.com/microsoft/typescript-go/shim/compiler"
|
|
8
|
+
shimcore "github.com/microsoft/typescript-go/shim/core"
|
|
9
|
+
shimprinter "github.com/microsoft/typescript-go/shim/printer"
|
|
10
|
+
shimtsoptions "github.com/microsoft/typescript-go/shim/tsoptions"
|
|
11
|
+
shimtspath "github.com/microsoft/typescript-go/shim/tspath"
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
// pluginEmitHost implements printer.EmitHost (and, structurally,
|
|
15
|
+
// SourceFileMayBeEmittedHost + OutputPathsHost — their methods are a subset) by
|
|
16
|
+
// delegating to the driver Program, exactly like tsgo's internal emitHost. It
|
|
17
|
+
// carries the emit resolver from the program's single checker.
|
|
18
|
+
type pluginEmitHost struct {
|
|
19
|
+
program *shimcompiler.Program
|
|
20
|
+
emitResolver shimprinter.EmitResolver
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
func (h *pluginEmitHost) Options() *shimcore.CompilerOptions { return h.program.Options() }
|
|
24
|
+
func (h *pluginEmitHost) SourceFiles() []*shimast.SourceFile { return h.program.SourceFiles() }
|
|
25
|
+
func (h *pluginEmitHost) UseCaseSensitiveFileNames() bool {
|
|
26
|
+
return h.program.UseCaseSensitiveFileNames()
|
|
27
|
+
}
|
|
28
|
+
func (h *pluginEmitHost) GetCurrentDirectory() string { return h.program.GetCurrentDirectory() }
|
|
29
|
+
func (h *pluginEmitHost) CommonSourceDirectory() string { return h.program.CommonSourceDirectory() }
|
|
30
|
+
func (h *pluginEmitHost) IsEmitBlocked(file string) bool { return h.program.IsEmitBlocked(file) }
|
|
31
|
+
func (h *pluginEmitHost) WriteFile(fileName string, text string) error {
|
|
32
|
+
return h.program.Host().FS().WriteFile(fileName, text)
|
|
33
|
+
}
|
|
34
|
+
func (h *pluginEmitHost) GetEmitModuleFormatOfFile(file shimast.HasFileName) shimcore.ModuleKind {
|
|
35
|
+
return h.program.GetEmitModuleFormatOfFile(file)
|
|
36
|
+
}
|
|
37
|
+
func (h *pluginEmitHost) GetEmitResolver() shimprinter.EmitResolver {
|
|
38
|
+
return guardedEmitResolver{h.emitResolver}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// guardedEmitResolver makes tsgo's const-enum inliner safe against plugin-built
|
|
42
|
+
// nodes. The inliner calls GetConstantValue on every property/element access it
|
|
43
|
+
// visits — including synthetic ones a plugin injects — and tsgo's checker can
|
|
44
|
+
// nil-panic while computing a contextual type for such a node. A failure there
|
|
45
|
+
// only means "not a const enum", so recover to nil and leave the node as-is.
|
|
46
|
+
type guardedEmitResolver struct {
|
|
47
|
+
shimprinter.EmitResolver
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
func (g guardedEmitResolver) GetConstantValue(node *shimast.Node) (result any) {
|
|
51
|
+
defer func() {
|
|
52
|
+
if recover() != nil {
|
|
53
|
+
result = nil
|
|
54
|
+
}
|
|
55
|
+
}()
|
|
56
|
+
return g.EmitResolver.GetConstantValue(node)
|
|
57
|
+
}
|
|
58
|
+
func (h *pluginEmitHost) GetProjectReferenceFromSource(path shimtspath.Path) *shimtsoptions.SourceOutputAndProjectReference {
|
|
59
|
+
return h.program.GetProjectReferenceFromSource(path)
|
|
60
|
+
}
|
|
61
|
+
func (h *pluginEmitHost) IsSourceFileFromExternalLibrary(file *shimast.SourceFile) bool {
|
|
62
|
+
return h.program.IsSourceFileFromExternalLibrary(file)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// PluginTransform transforms one source file in the emit phase, bound to the
|
|
66
|
+
// emit EmitContext: nodes it builds with ec.Factory (and links with
|
|
67
|
+
// ec.SetOriginal) are recognized and aliased by tsgo's builtin module-transform.
|
|
68
|
+
// Returning nil leaves the file unchanged. This is the AST-integration contract
|
|
69
|
+
// that replaces text-splice: a plugin returns AST, not text. The shape mirrors a
|
|
70
|
+
// classic ts.TransformerFactory (SourceFile -> SourceFile) so an existing
|
|
71
|
+
// node-based transformer plugs in by just accepting the EmitContext.
|
|
72
|
+
type PluginTransform func(ec *shimprinter.EmitContext, sourceFile *shimast.SourceFile) *shimast.SourceFile
|
|
73
|
+
|
|
74
|
+
// EmitWithPluginTransformer emits with a single plugin transformer. It is a thin
|
|
75
|
+
// wrapper over EmitWithPluginTransformers.
|
|
76
|
+
func (p *Program) EmitWithPluginTransformer(transform PluginTransform, writeFile shimcompiler.WriteFile) ([]Diagnostic, error) {
|
|
77
|
+
return p.EmitWithPluginTransformers([]PluginTransform{transform}, writeFile)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// EmitLinkedTransforms emits using the emit-phase transformers contributed by
|
|
81
|
+
// every registered EmitTransformPlugin (in registration order). This is the
|
|
82
|
+
// AST-integration emit path that replaces the ProgramPlugin + RewriteSet
|
|
83
|
+
// text-splice path.
|
|
84
|
+
func (p *Program) EmitLinkedTransforms(writeFile shimcompiler.WriteFile) ([]Diagnostic, error) {
|
|
85
|
+
if p == nil || p.TSProgram == nil {
|
|
86
|
+
return nil, errors.New("driver: nil program")
|
|
87
|
+
}
|
|
88
|
+
transforms, err := p.plugins.emitTransforms()
|
|
89
|
+
if err != nil {
|
|
90
|
+
return nil, err
|
|
91
|
+
}
|
|
92
|
+
return p.EmitWithPluginTransformers(transforms, writeFile)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// EmitWithPluginTransformers emits every source file by assembling tsgo's emit
|
|
96
|
+
// pipeline from shim parts and running the plugin transformers FIRST (in order)
|
|
97
|
+
// in the same EmitContext as the builtin chain (type-erase, import-elision,
|
|
98
|
+
// module-transform, ...). No text-splice and no hand-rolled import aliasing:
|
|
99
|
+
// tsgo's module-transform aliases the plugins' injected imports itself.
|
|
100
|
+
func (p *Program) EmitWithPluginTransformers(transforms []PluginTransform, writeFile shimcompiler.WriteFile) ([]Diagnostic, error) {
|
|
101
|
+
if p == nil || p.TSProgram == nil {
|
|
102
|
+
return nil, errors.New("driver: nil program")
|
|
103
|
+
}
|
|
104
|
+
host := &pluginEmitHost{program: p.TSProgram, emitResolver: p.Checker.GetEmitResolver()}
|
|
105
|
+
options := p.TSProgram.Options()
|
|
106
|
+
newLine := options.NewLine.GetNewLineCharacter()
|
|
107
|
+
for _, sf := range shimcompiler.GetSourceFilesToEmit(host, nil, false) {
|
|
108
|
+
ec := shimprinter.NewEmitContext()
|
|
109
|
+
out := sf
|
|
110
|
+
for _, transform := range transforms {
|
|
111
|
+
if transform == nil {
|
|
112
|
+
continue
|
|
113
|
+
}
|
|
114
|
+
if next := transform(ec, out); next != nil {
|
|
115
|
+
out = next
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
shimast.SetParentInChildrenUnset(out.AsNode())
|
|
119
|
+
for _, tr := range shimcompiler.GetScriptTransformers(ec, host, out) {
|
|
120
|
+
out = tr.TransformSourceFile(out)
|
|
121
|
+
}
|
|
122
|
+
paths := shimcompiler.GetOutputPathsFor(sf, options, host, false)
|
|
123
|
+
writer := shimprinter.NewTextWriter(newLine, 0)
|
|
124
|
+
p2 := shimprinter.NewPrinter(shimprinter.PrinterOptions{NewLine: options.NewLine}, shimprinter.PrintHandlers{}, ec)
|
|
125
|
+
p2.Write(out.AsNode(), out, writer, nil)
|
|
126
|
+
if err := writeFile(paths.JsFilePath(), writer.String(), nil); err != nil {
|
|
127
|
+
return nil, err
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return nil, nil
|
|
131
|
+
}
|
package/driver/plugins.go
CHANGED
|
@@ -39,6 +39,18 @@ type ProgramPlugin interface {
|
|
|
39
39
|
ApplyProgram(*Program, PluginContext) error
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
+
// EmitTransformPlugin contributes an emit-phase AST transformer. The returned
|
|
43
|
+
// PluginTransform runs first in tsgo's per-file emit chain, sharing the emit
|
|
44
|
+
// EmitContext with the builtin transformers, so a plugin returns AST instead of
|
|
45
|
+
// spliced text: it injects its own imports with ec.Factory and references them
|
|
46
|
+
// via NewGeneratedNameForNode, and tsgo's module-transform emits the require and
|
|
47
|
+
// aliases the references itself. This is the AST-integration replacement for the
|
|
48
|
+
// ProgramPlugin + RewriteSet text-splice model. A plugin whose returned
|
|
49
|
+
// transform is nil contributes nothing.
|
|
50
|
+
type EmitTransformPlugin interface {
|
|
51
|
+
EmitTransform(PluginContext) (PluginTransform, error)
|
|
52
|
+
}
|
|
53
|
+
|
|
42
54
|
type linkedPluginState struct {
|
|
43
55
|
cwd string
|
|
44
56
|
entries []PluginEntry
|
|
@@ -118,6 +130,31 @@ func (state linkedPluginState) apply(prog *Program) error {
|
|
|
118
130
|
return nil
|
|
119
131
|
}
|
|
120
132
|
|
|
133
|
+
// emitTransforms collects an emit-phase PluginTransform from every registered
|
|
134
|
+
// EmitTransformPlugin, in registration order. Entries that do not implement
|
|
135
|
+
// EmitTransformPlugin, or whose transform is nil, are skipped.
|
|
136
|
+
func (state linkedPluginState) emitTransforms() ([]PluginTransform, error) {
|
|
137
|
+
var out []PluginTransform
|
|
138
|
+
for index, entry := range state.entries {
|
|
139
|
+
plugin, ok := registeredPlugin(index)
|
|
140
|
+
if !ok {
|
|
141
|
+
return nil, fmt.Errorf("ttsc driver: linked plugin entry %d was requested but no linked plugin registered at that position", index)
|
|
142
|
+
}
|
|
143
|
+
emitter, ok := plugin.(EmitTransformPlugin)
|
|
144
|
+
if !ok {
|
|
145
|
+
continue
|
|
146
|
+
}
|
|
147
|
+
transform, err := emitter.EmitTransform(state.context(entry))
|
|
148
|
+
if err != nil {
|
|
149
|
+
return nil, err
|
|
150
|
+
}
|
|
151
|
+
if transform != nil {
|
|
152
|
+
out = append(out, transform)
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return out, nil
|
|
156
|
+
}
|
|
157
|
+
|
|
121
158
|
// registeredPlugin returns the plugin registered at position index, or
|
|
122
159
|
// (nil, false) when the index is out of range. Registration order matches
|
|
123
160
|
// the order of linked Go init() calls.
|
package/go.mod
CHANGED
|
@@ -31,7 +31,6 @@ require (
|
|
|
31
31
|
github.com/microsoft/typescript-go/shim/compiler v0.0.0
|
|
32
32
|
github.com/microsoft/typescript-go/shim/core v0.0.0
|
|
33
33
|
github.com/microsoft/typescript-go/shim/diagnosticwriter v0.0.0
|
|
34
|
-
github.com/microsoft/typescript-go/shim/lsp v0.0.0
|
|
35
34
|
github.com/microsoft/typescript-go/shim/printer v0.0.0
|
|
36
35
|
github.com/microsoft/typescript-go/shim/scanner v0.0.0
|
|
37
36
|
github.com/microsoft/typescript-go/shim/tsoptions v0.0.0
|
|
@@ -42,10 +41,8 @@ require (
|
|
|
42
41
|
)
|
|
43
42
|
|
|
44
43
|
require (
|
|
45
|
-
github.com/Microsoft/go-winio v0.6.2 // indirect
|
|
46
44
|
github.com/go-json-experiment/json v0.0.0-20260214004413-d219187c3433 // indirect
|
|
47
45
|
github.com/klauspost/cpuid/v2 v2.2.10 // indirect
|
|
48
|
-
github.com/mackerelio/go-osstat v0.2.7 // indirect
|
|
49
46
|
github.com/microsoft/typescript-go v0.0.0-20260429010842-56ab4af42157 // indirect
|
|
50
47
|
github.com/zeebo/xxh3 v1.1.0 // indirect
|
|
51
48
|
golang.org/x/sync v0.20.0 // indirect
|
package/go.sum
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY=
|
|
2
|
-
github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU=
|
|
3
1
|
github.com/go-json-experiment/json v0.0.0-20260214004413-d219187c3433 h1:vymEbVwYFP/L05h5TKQxvkXoKxNvTpjxYKdF1Nlwuao=
|
|
4
2
|
github.com/go-json-experiment/json v0.0.0-20260214004413-d219187c3433/go.mod h1:tphK2c80bpPhMOI4v6bIc2xWywPfbqi1Z06+RcrMkDg=
|
|
5
3
|
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
|
|
6
4
|
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
|
|
7
5
|
github.com/klauspost/cpuid/v2 v2.2.10 h1:tBs3QSyvjDyFTq3uoc/9xFpCuOsJQFNPiAhYdw2skhE=
|
|
8
6
|
github.com/klauspost/cpuid/v2 v2.2.10/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0=
|
|
9
|
-
github.com/mackerelio/go-osstat v0.2.7 h1:TCavZi10wF49bT6iQZ9eT2keGZQpC69MTDfdJej5e94=
|
|
10
|
-
github.com/mackerelio/go-osstat v0.2.7/go.mod h1:dwpYh5pIPmvk+IEwBKNIWRFMB92mrC08CmXOhDC7nQk=
|
|
11
7
|
github.com/microsoft/typescript-go v0.0.0-20260429010842-56ab4af42157 h1:llOMPhKDiQ+UEJiAaQuuWaJOTg5V7tNNTEf9JPWoYSY=
|
|
12
8
|
github.com/microsoft/typescript-go v0.0.0-20260429010842-56ab4af42157/go.mod h1:m8YA0PMC7ti0GW0RI05D6fEcjQeu98XVS+FWF+VDW2k=
|
|
13
9
|
github.com/peter-evans/patience v0.3.0 h1:rX0JdJeepqdQl1Sk9c9uvorjYYzL2TfgLX1adqYm9cA=
|
|
@@ -27,19 +27,40 @@ function resolveEmittedJavaScript(options) {
|
|
|
27
27
|
if (exact && node_fs_1.default.existsSync(exact)) {
|
|
28
28
|
return exact;
|
|
29
29
|
}
|
|
30
|
+
// Score the pre-computed emit list first (cheap). When it yields nothing —
|
|
31
|
+
// because the list is incomplete (a native transform host such as typia emits
|
|
32
|
+
// without printing the `--listEmittedFiles` lines) or because the emit landed
|
|
33
|
+
// at a path the exact mirror did not predict (tsgo shifts every output path
|
|
34
|
+
// when the program pulls a raw-`.ts` dependency that sits outside `rootDir`,
|
|
35
|
+
// so it strips the common source root rather than `rootDir`) — fall back to a
|
|
36
|
+
// full recursive scan of `outDir`. Trailing-stem scoring still pins the right
|
|
37
|
+
// file regardless of how deep the shifted prefix is.
|
|
38
|
+
const primary = bestStemMatch(options.emittedFiles ?? listJavaScriptFiles(options.outDir), options.sourceFile);
|
|
39
|
+
if (primary !== null && node_fs_1.default.existsSync(primary)) {
|
|
40
|
+
return primary;
|
|
41
|
+
}
|
|
42
|
+
if (options.emittedFiles !== undefined) {
|
|
43
|
+
const fromDir = bestStemMatch(listJavaScriptFiles(options.outDir), options.sourceFile);
|
|
44
|
+
if (fromDir !== null && node_fs_1.default.existsSync(fromDir)) {
|
|
45
|
+
return fromDir;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
/** Highest trailing-stem-scoring JavaScript output among `files`, or `null`. */
|
|
51
|
+
function bestStemMatch(files, sourceFile) {
|
|
30
52
|
let best = null;
|
|
31
53
|
let bestScore = 0;
|
|
32
|
-
for (const file of
|
|
33
|
-
listJavaScriptFiles(options.outDir)) {
|
|
54
|
+
for (const file of files) {
|
|
34
55
|
if (!isJavaScriptOutput(file))
|
|
35
56
|
continue;
|
|
36
|
-
const score = sharedSourceStemSegments(file,
|
|
57
|
+
const score = sharedSourceStemSegments(file, sourceFile);
|
|
37
58
|
if (score > bestScore) {
|
|
38
59
|
best = file;
|
|
39
60
|
bestScore = score;
|
|
40
61
|
}
|
|
41
62
|
}
|
|
42
|
-
return best
|
|
63
|
+
return best;
|
|
43
64
|
}
|
|
44
65
|
/**
|
|
45
66
|
* Derive the exact output path for `sourceFile` by mirroring its position
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolveEmittedJavaScript.js","sourceRoot":"","sources":["../../../src/compiler/internal/resolveEmittedJavaScript.ts"],"names":[],"mappings":";;;;;;AAAA,sDAAyB;AACzB,0DAA6B;AAE7B,mCAAgD;AAEhD;;;;;;;;;;;;;;GAcG;AACH,kCAAyC,OAMxC;IACC,MAAM,KAAK,GAAG,uBAAuB,CACnC,OAAO,CAAC,MAAM,EACd,OAAO,CAAC,WAAW,EACnB,OAAO,CAAC,UAAU,CACnB,CAAC;IACF,IAAI,KAAK,IAAI,iBAAE,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC;QAClC,OAAO,KAAK,CAAC;IACf,CAAC;IAED,IAAI,IAAI,
|
|
1
|
+
{"version":3,"file":"resolveEmittedJavaScript.js","sourceRoot":"","sources":["../../../src/compiler/internal/resolveEmittedJavaScript.ts"],"names":[],"mappings":";;;;;;AAAA,sDAAyB;AACzB,0DAA6B;AAE7B,mCAAgD;AAEhD;;;;;;;;;;;;;;GAcG;AACH,kCAAyC,OAMxC;IACC,MAAM,KAAK,GAAG,uBAAuB,CACnC,OAAO,CAAC,MAAM,EACd,OAAO,CAAC,WAAW,EACnB,OAAO,CAAC,UAAU,CACnB,CAAC;IACF,IAAI,KAAK,IAAI,iBAAE,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC;QAClC,OAAO,KAAK,CAAC;IACf,CAAC;IAED,2EAA2E;IAC3E,8EAA8E;IAC9E,8EAA8E;IAC9E,4EAA4E;IAC5E,6EAA6E;IAC7E,8EAA8E;IAC9E,8EAA8E;IAC9E,qDAAqD;IACrD,MAAM,OAAO,GAAG,aAAa,CAC3B,OAAO,CAAC,YAAY,IAAI,mBAAmB,CAAC,OAAO,CAAC,MAAM,CAAC,EAC3D,OAAO,CAAC,UAAU,CACnB,CAAC;IACF,IAAI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|
+
emittedFiles?: readonly string[];
|
|
9
10
|
entryFile: string;
|
|
10
|
-
|
|
11
|
+
moduleOption?: string;
|
|
12
|
+
projectRoot: string;
|
|
13
|
+
rootDir: string;
|
|
11
14
|
};
|
|
@@ -33,12 +33,14 @@ function prepareExecution(entryFile, options = {}) {
|
|
|
33
33
|
if (emittedEntry === null) {
|
|
34
34
|
throw new Error(`ttsx: emitted entry not found for ${entryFile}`);
|
|
35
35
|
}
|
|
36
|
-
const output = node_fs_1.default.readFileSync(emittedEntry, "utf8");
|
|
37
36
|
return {
|
|
38
37
|
cleanupDir: context.processDir,
|
|
39
38
|
emitDir: context.emitDir,
|
|
39
|
+
emittedFiles: context.emittedFiles ?? undefined,
|
|
40
40
|
entryFile: emittedEntry,
|
|
41
|
-
|
|
41
|
+
moduleOption: context.moduleOption,
|
|
42
|
+
projectRoot: context.root,
|
|
43
|
+
rootDir: context.runtimeRootDir,
|
|
42
44
|
};
|
|
43
45
|
}
|
|
44
46
|
catch (error) {
|
|
@@ -67,6 +69,15 @@ function createProjectContext(cwd, filename, options) {
|
|
|
67
69
|
emitDir: project.compilerOptions.outDir
|
|
68
70
|
? virtualPath(virtualRoot, project.compilerOptions.outDir)
|
|
69
71
|
: virtualPath(virtualRoot, resolveRuntimeSourceRoot(project, filename)),
|
|
72
|
+
// The source-tree root the emit mirrors (tsgo strips this prefix). Used to
|
|
73
|
+
// map a source `.ts` back to its emitted `.js` when the runtime hooks serve
|
|
74
|
+
// the built entry under its source URL.
|
|
75
|
+
runtimeRootDir: resolveRuntimeSourceRoot(project, filename),
|
|
76
|
+
// The tsconfig `module` option, so the runtime hooks classify each served
|
|
77
|
+
// file's format the same way tsgo chose when emitting it.
|
|
78
|
+
moduleOption: typeof project.compilerOptions.module === "string"
|
|
79
|
+
? project.compilerOptions.module
|
|
80
|
+
: undefined,
|
|
70
81
|
built: false,
|
|
71
82
|
emittedFiles: undefined,
|
|
72
83
|
};
|
|
@@ -214,19 +225,4 @@ function virtualPath(root, absolute) {
|
|
|
214
225
|
const relative = node_path_1.default.relative(parsed.root, node_path_1.default.resolve(absolute));
|
|
215
226
|
return node_path_1.default.join(root, label, relative);
|
|
216
227
|
}
|
|
217
|
-
/**
|
|
218
|
-
* Heuristic: classify emitted JS as ESM when it contains top-level `import` or
|
|
219
|
-
* `export` statements but none of the well-known CJS patterns. The CJS checks
|
|
220
|
-
* run first so that re-exported CJS bundles with both `require` calls and an
|
|
221
|
-
* `export` declaration are conservatively treated as CJS.
|
|
222
|
-
*/
|
|
223
|
-
function looksLikeESM(output) {
|
|
224
|
-
if (/\bObject\.defineProperty\(exports\b/.test(output) ||
|
|
225
|
-
/\bmodule\.exports\b/.test(output) ||
|
|
226
|
-
/\brequire\(/.test(output) ||
|
|
227
|
-
/\bexports\./.test(output)) {
|
|
228
|
-
return false;
|
|
229
|
-
}
|
|
230
|
-
return /^\s*(import|export)\s/m.test(output);
|
|
231
|
-
}
|
|
232
228
|
//# sourceMappingURL=prepareExecution.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prepareExecution.js","sourceRoot":"","sources":["../../../src/launcher/internal/prepareExecution.ts"],"names":[],"mappings":";;;;;;AAAA,sDAAyB;AACzB,sDAAyB;AACzB,0DAA6B;AAE7B,yFAAsF;AACtF,+FAA4F;AAC5F,+DAA4D;AAG5D,wEAAwE;AACxE,MAAM,iBAAiB,GAAG,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;AAC9C;;;;;GAKG;AACH,MAAM,wBAAwB,GAAG,CAAC,CAAC;AAEnC,mFAAmF;AACnF,0BACE,SAAiB,EACjB,OAAO,GAGH,EAAE;
|
|
1
|
+
{"version":3,"file":"prepareExecution.js","sourceRoot":"","sources":["../../../src/launcher/internal/prepareExecution.ts"],"names":[],"mappings":";;;;;;AAAA,sDAAyB;AACzB,sDAAyB;AACzB,0DAA6B;AAE7B,yFAAsF;AACtF,+FAA4F;AAC5F,+DAA4D;AAG5D,wEAAwE;AACxE,MA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,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IACzC,MAAM,IAAI,GAAG,mBAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC;IACvC,OAAO,QAAQ,KAAK,IAAI,IAAI,QAAQ,KAAK,mBAAI,CAAC,OAAO,CAAC,iBAAE,CAAC,MAAM,EAAE,CAAC,CAAC;AACrE,CAAC;AAED;;;;;;;GAOG;AACH,SAAS,WAAW,CAAC,IAAY,EAAE,QAAgB;IACjD,MAAM,MAAM,GAAG,mBAAI,CAAC,KAAK,CAAC,mBAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;IAClD,MAAM,KAAK,GACT,MAAM,CAAC,IAAI,KAAK,mBAAI,CAAC,GAAG;QACtB,CAAC,CAAC,OAAO;QACT,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,gBAAgB,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC;YAClE,MAAM,CAAC;IACb,MAAM,QAAQ,GAAG,mBAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,EAAE,mBAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;IACpE,OAAO,mBAAI,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC;AAC1C,CAAC"}
|
|
@@ -3,17 +3,52 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const node_module_1 = require("node:module");
|
|
7
6
|
const node_path_1 = __importDefault(require("node:path"));
|
|
8
7
|
const node_url_1 = require("node:url");
|
|
8
|
+
const runtimeHooks_1 = require("./runtimeHooks");
|
|
9
9
|
/**
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* `runtimeHooks` are active for the whole dependency graph.
|
|
10
|
+
* Bootstrap `ttsx` spawns as the child's main module: it installs the runtime
|
|
11
|
+
* module hooks, then loads the TypeScript entry _from source_.
|
|
13
12
|
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
13
|
+
* Why load the entry here instead of passing it as Node's main entry: a
|
|
14
|
+
* CommonJS `require("./x")` chain only reaches `module.registerHooks` when the
|
|
15
|
+
* entry itself is loaded through a CommonJS `require`. Running the `.ts` as
|
|
16
|
+
* Node's ESM-first main entry leaves inner `require`s on the native loader,
|
|
17
|
+
* where they cannot resolve a sibling `.ts`. So the parent invokes `node
|
|
18
|
+
* registerRuntimeHooks.js <entry> [argv...]` and we `require()` (or dynamically
|
|
19
|
+
* `import()`) the entry after the hooks are live.
|
|
20
|
+
*
|
|
21
|
+
* `process.argv` is rewritten to `[node, <entry>, ...argv]` so the program sees
|
|
22
|
+
* the same argv it would under a direct `node <entry>` invocation.
|
|
17
23
|
*/
|
|
18
|
-
|
|
24
|
+
const entry = process.argv[2];
|
|
25
|
+
if (entry === undefined) {
|
|
26
|
+
process.stderr.write("ttsx: internal error — no entry passed to bootstrap\n");
|
|
27
|
+
process.exit(2);
|
|
28
|
+
}
|
|
29
|
+
const forwarded = process.argv.slice(3);
|
|
30
|
+
process.argv = [process.argv[0], entry, ...forwarded];
|
|
31
|
+
(0, runtimeHooks_1.installRuntimeHooks)();
|
|
32
|
+
const kind = (0, runtimeHooks_1.entryModuleFormat)(node_path_1.default.resolve(entry));
|
|
33
|
+
function fail(error) {
|
|
34
|
+
// Match Node's own uncaught-exception surfacing for a thrown entry error.
|
|
35
|
+
process.stderr.write(`${error instanceof Error ? (error.stack ?? error.message) : String(error)}\n`);
|
|
36
|
+
process.exit(1);
|
|
37
|
+
}
|
|
38
|
+
// A genuine dynamic `import()`. Authored directly it would be downlevelled to a
|
|
39
|
+
// `require()` shim under this package's CommonJS emit, which cannot load a
|
|
40
|
+
// `file:` URL or an ESM module — so build it through `Function` to keep it an
|
|
41
|
+
// `import` at runtime.
|
|
42
|
+
const dynamicImport = new Function("specifier", "return import(specifier);");
|
|
43
|
+
if (kind === "module") {
|
|
44
|
+
dynamicImport((0, node_url_1.pathToFileURL)(node_path_1.default.resolve(entry)).href).catch(fail);
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
try {
|
|
48
|
+
require(node_path_1.default.resolve(entry));
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
fail(error);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
19
54
|
//# sourceMappingURL=registerRuntimeHooks.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registerRuntimeHooks.js","sourceRoot":"","sources":["../../../src/launcher/internal/registerRuntimeHooks.ts"],"names":[],"mappings":";;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"registerRuntimeHooks.js","sourceRoot":"","sources":["../../../src/launcher/internal/registerRuntimeHooks.ts"],"names":[],"mappings":";;;;;AAAA,0DAA6B;AAC7B,uCAAyC;AAEzC,iDAAwE;AAExE;;;;;;;;;;;;;;GAcG;AACH,MAAM,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAC9B,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;IACxB,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,uDAAuD,CAAC,CAAC;IAC9E,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC;AAED,MAAM,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACxC,OAAO,CAAC,IAAI,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAE,EAAE,KAAK,EAAE,GAAG,SAAS,CAAC,CAAC;AAEvD,IAAA,kCAAmB,GAAE,CAAC;AAEtB,MAAM,IAAI,GAAG,IAAA,gCAAiB,EAAC,mBAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;AAEp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