ttsc 0.16.9 → 0.16.11

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.
@@ -1,8 +1,10 @@
1
1
  package driver
2
2
 
3
3
  import (
4
+ "context"
4
5
  "errors"
5
6
  "strings"
7
+ "sync"
6
8
 
7
9
  shimast "github.com/microsoft/typescript-go/shim/ast"
8
10
  shimcompiler "github.com/microsoft/typescript-go/shim/compiler"
@@ -126,16 +128,20 @@ func restoreOriginalDeclarationSymbols(ec *shimprinter.EmitContext, node *shimas
126
128
  })
127
129
  }
128
130
 
129
- // EmitWithPluginTransformers emits every source file by assembling tsgo's emit
130
- // pipeline from shim parts and running the plugin transformers FIRST (in order)
131
- // in the same EmitContext as the builtin chain (type-erase, import-elision,
132
- // module-transform, ...). No text-splice and no hand-rolled import aliasing:
133
- // tsgo's module-transform aliases the plugins' injected imports itself.
131
+ // EmitWithPluginTransformers emits every source file by assembling tsgo's
132
+ // JavaScript emit pipeline from shim parts and running the plugin transformers
133
+ // FIRST (in order) in the same EmitContext as the builtin chain (type-erase,
134
+ // import-elision, module-transform, ...). No text-splice and no hand-rolled
135
+ // import aliasing: tsgo's module-transform aliases the plugins' injected
136
+ // imports itself.
134
137
  //
135
- // Because this bypasses tsgo's own emitter, it reproduces the emitter's
136
- // source-map step via PrintFileWithSourceMap: a `sourceMap` / `inlineSourceMap`
137
- // build emits a `.js.map` (and `//# sourceMappingURL=` trailer) just like a
138
- // plain build, even when a transform expanded one source line into many.
138
+ // Because the JavaScript side bypasses tsgo's own emitter, it reproduces the
139
+ // emitter's source-map step via PrintFileWithSourceMap: a `sourceMap` /
140
+ // `inlineSourceMap` build emits a `.js.map` (and `//# sourceMappingURL=`
141
+ // trailer) just like a plain build, even when a transform expanded one source
142
+ // line into many. All non-JavaScript outputs stay delegated to tsgo's normal
143
+ // dts-only emitter so declaration files, declaration maps, and any future
144
+ // declaration-lane outputs are not silently lost by the hand-assembled JS path.
139
145
  func (p *Program) EmitWithPluginTransformers(transforms []PluginTransform, writeFile shimcompiler.WriteFile) ([]Diagnostic, error) {
140
146
  if p == nil || p.TSProgram == nil {
141
147
  return nil, errors.New("driver: nil program")
@@ -144,54 +150,87 @@ func (p *Program) EmitWithPluginTransformers(transforms []PluginTransform, write
144
150
  options := p.TSProgram.Options()
145
151
  for _, sf := range shimcompiler.GetSourceFilesToEmit(host, nil, false) {
146
152
  paths := shimcompiler.GetOutputPathsFor(sf, options, host, false)
147
- if p.outputEscapesOutDir(paths.JsFilePath()) {
148
- continue
149
- }
150
- ec := shimprinter.NewEmitContext()
151
- out := sf
152
- for _, transform := range transforms {
153
- if transform == nil {
154
- continue
155
- }
156
- if next := transform(ec, out); next != nil {
157
- out = next
153
+ if paths.JsFilePath() != "" && !p.outputEscapesOutDir(paths.JsFilePath()) {
154
+ ec := shimprinter.NewEmitContext()
155
+ out := sf
156
+ for _, transform := range transforms {
157
+ if transform == nil {
158
+ continue
159
+ }
160
+ if next := transform(ec, out); next != nil {
161
+ out = next
162
+ }
158
163
  }
159
- }
160
- shimast.SetParentInChildrenUnset(out.AsNode())
161
- restoreOriginalDeclarationSymbols(ec, out.AsNode())
162
- for _, tr := range shimcompiler.GetScriptTransformers(ec, host, out) {
163
- out = tr.TransformSourceFile(out)
164
- }
165
- // Print through the source-map-aware helper so a `sourceMap` /
166
- // `inlineSourceMap` build still gets its `.js.map` and sourceMappingURL
167
- // trailer: the hand-assembled emit pipeline does not run tsgo's emitter, so
168
- // the source-map step printSourceFile would otherwise perform has to happen
169
- // here. With maps off this is the same bare-printer output as before.
170
- printed := shimcompiler.PrintFileWithSourceMap(ec, out.AsNode(), out, options, host, paths.JsFilePath(), paths.SourceMapFilePath())
171
- // A source-level preamble (e.g. @ttsc/banner linked into a typia host) shifts
172
- // the map's source coordinates; correct them here too, so the
173
- // preamble-plus-transform combination is not left uncorrected the way it
174
- // would be if only the utility host's WriteFile patched maps. Covers both the
175
- // external `.js.map` and an inline base64 map embedded in the JS.
176
- if p.SourcePreamble != "" {
177
- dropLines := strings.Count(p.SourcePreamble, "\n")
178
- if adjusted, ok := AdjustEmittedSourceMap(paths.JsFilePath(), printed.JS, dropLines); ok {
179
- printed.JS = adjusted
164
+ shimast.SetParentInChildrenUnset(out.AsNode())
165
+ restoreOriginalDeclarationSymbols(ec, out.AsNode())
166
+ for _, tr := range shimcompiler.GetScriptTransformers(ec, host, out) {
167
+ out = tr.TransformSourceFile(out)
180
168
  }
181
- if printed.MapPath != "" {
182
- if adjusted, ok := AdjustEmittedSourceMap(printed.MapPath, printed.MapText, dropLines); ok {
183
- printed.MapText = adjusted
169
+ // Print through the source-map-aware helper so a `sourceMap` /
170
+ // `inlineSourceMap` build still gets its `.js.map` and sourceMappingURL
171
+ // trailer: the hand-assembled emit pipeline does not run tsgo's emitter,
172
+ // so the source-map step printSourceFile would otherwise perform has to
173
+ // happen here. With maps off this is the same bare-printer output as
174
+ // before.
175
+ printed := shimcompiler.PrintFileWithSourceMap(ec, out.AsNode(), out, options, host, paths.JsFilePath(), paths.SourceMapFilePath())
176
+ // A source-level preamble (e.g. @ttsc/banner linked into a typia host)
177
+ // shifts the map's source coordinates; correct them here too, so the
178
+ // preamble-plus-transform combination is not left uncorrected the way it
179
+ // would be if only the utility host's WriteFile patched maps. Covers both
180
+ // the external `.js.map` and an inline base64 map embedded in the JS.
181
+ if p.SourcePreamble != "" {
182
+ dropLines := strings.Count(p.SourcePreamble, "\n")
183
+ if adjusted, ok := AdjustEmittedSourceMap(paths.JsFilePath(), printed.JS, dropLines); ok {
184
+ printed.JS = adjusted
185
+ }
186
+ if printed.MapPath != "" {
187
+ if adjusted, ok := AdjustEmittedSourceMap(printed.MapPath, printed.MapText, dropLines); ok {
188
+ printed.MapText = adjusted
189
+ }
184
190
  }
185
191
  }
186
- }
187
- if err := writeFile(paths.JsFilePath(), printed.JS, nil); err != nil {
188
- return nil, err
189
- }
190
- if printed.MapPath != "" {
191
- if err := writeFile(printed.MapPath, printed.MapText, nil); err != nil {
192
+ if err := p.writePluginEmitOutput(paths.JsFilePath(), printed.JS, writeFile); err != nil {
193
+ return nil, err
194
+ }
195
+ if err := p.writePluginEmitOutput(printed.MapPath, printed.MapText, writeFile); err != nil {
192
196
  return nil, err
193
197
  }
194
198
  }
195
199
  }
200
+ if !options.GetEmitDeclarations() {
201
+ return nil, nil
202
+ }
203
+
204
+ var wfMu sync.Mutex
205
+ result := p.TSProgram.Emit(context.Background(), shimcompiler.EmitOptions{
206
+ EmitOnly: shimcompiler.EmitOnlyDts,
207
+ WriteFile: func(fileName string, text string, data *shimcompiler.WriteFileData) error {
208
+ wfMu.Lock()
209
+ defer wfMu.Unlock()
210
+ if p.outputEscapesOutDir(fileName) {
211
+ if data != nil {
212
+ data.SkippedDtsWrite = true
213
+ }
214
+ return nil
215
+ }
216
+ if writeFile != nil {
217
+ return writeFile(fileName, text, data)
218
+ }
219
+ return DefaultWriteFile(fileName, text)
220
+ },
221
+ })
222
+ if result != nil && len(result.Diagnostics) != 0 {
223
+ return convertDiagnostics(result.Diagnostics), nil
224
+ }
196
225
  return nil, nil
197
226
  }
227
+
228
+ func (p *Program) writePluginEmitOutput(fileName, text string, writeFile shimcompiler.WriteFile) error {
229
+ if fileName == "" || p.outputEscapesOutDir(fileName) {
230
+ return nil
231
+ }
232
+ if writeFile != nil {
233
+ return writeFile(fileName, text, nil)
234
+ }
235
+ return DefaultWriteFile(fileName, text)
236
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ttsc",
3
- "version": "0.16.9",
3
+ "version": "0.16.11",
4
4
  "description": "General-purpose TypeScript-Go compiler, runtime, plugin host, and LSP host.",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -32,13 +32,13 @@
32
32
  "typescript": "7.0.1-rc"
33
33
  },
34
34
  "optionalDependencies": {
35
- "@ttsc/linux-x64": "0.16.9",
36
- "@ttsc/linux-arm": "0.16.9",
37
- "@ttsc/linux-arm64": "0.16.9",
38
- "@ttsc/win32-x64": "0.16.9",
39
- "@ttsc/win32-arm64": "0.16.9",
40
- "@ttsc/darwin-x64": "0.16.9",
41
- "@ttsc/darwin-arm64": "0.16.9"
35
+ "@ttsc/linux-x64": "0.16.11",
36
+ "@ttsc/linux-arm": "0.16.11",
37
+ "@ttsc/darwin-x64": "0.16.11",
38
+ "@ttsc/win32-x64": "0.16.11",
39
+ "@ttsc/linux-arm64": "0.16.11",
40
+ "@ttsc/win32-arm64": "0.16.11",
41
+ "@ttsc/darwin-arm64": "0.16.11"
42
42
  },
43
43
  "sideEffects": false,
44
44
  "files": [
package/utility/serve.go CHANGED
@@ -6,10 +6,10 @@ import (
6
6
  "fmt"
7
7
  "io"
8
8
  "os"
9
- "path/filepath"
10
9
  "strings"
11
10
 
12
11
  shimprinter "github.com/microsoft/typescript-go/shim/printer"
12
+ shimtspath "github.com/microsoft/typescript-go/shim/tspath"
13
13
 
14
14
  "github.com/samchon/ttsc/packages/ttsc/driver"
15
15
  )
@@ -147,12 +147,12 @@ func buildServeCache(opts hostOptions) (map[string]string, bool) {
147
147
  return cache, true
148
148
  }
149
149
 
150
- // resolveServePath turns a request's file into an absolute path so apiOutputKey
151
- // computes the same key buildServeCache stored, and so overlay overrides are
152
- // keyed the way the program asks for them.
150
+ // resolveServePath turns a request's file into a normalized absolute path, the
151
+ // same form TypeScript-Go's own SourceFile.FileName() and the OverlayFS key
152
+ // already use, so apiOutputKey and overlay lookups match regardless of how the
153
+ // caller spelled the path. tspath.ResolvePath discards cwd and normalizes in
154
+ // place when file is already rooted, so one call covers both request cases
155
+ // (samchon/ttsc#319).
153
156
  func resolveServePath(cwd, file string) string {
154
- if filepath.IsAbs(file) {
155
- return file
156
- }
157
- return filepath.Join(cwd, file)
157
+ return shimtspath.ResolvePath(cwd, file)
158
158
  }