typia 15.4.1 → 15.5.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/README.md +7 -2
- package/lib/transform.d.ts +3 -1
- package/lib/transform.js +4 -1
- package/lib/transform.js.map +1 -1
- package/lib/transform.mjs +5 -2
- package/lib/transform.mjs.map +1 -1
- package/native/cmd/ttsc-typia/build.go +185 -125
- package/native/cmd/ttsc-typia/build_no_emit_preserves_analysis_options_test.go +50 -43
- package/native/cmd/ttsc-typia/check.go +92 -0
- package/native/cmd/ttsc-typia/check_serve.go +318 -0
- package/native/cmd/ttsc-typia/check_serve_matches_cold_check_test.go +234 -0
- package/native/cmd/ttsc-typia/check_serve_reloads_with_program_plugin_test.go +56 -0
- package/native/cmd/ttsc-typia/check_transform_leaves_program_untouched_test.go +155 -0
- package/native/cmd/ttsc-typia/main.go +3 -0
- package/native/cmd/ttsc-typia/typia_check_loads_one_program_test.go +125 -0
- package/native/go.mod +2 -1
- package/package.json +5 -5
- package/src/transform.ts +4 -1
package/README.md
CHANGED
|
@@ -15,6 +15,7 @@ export function is<T>(input: unknown): input is T; // returns boolean
|
|
|
15
15
|
export function assert<T>(input: unknown): T; // throws TypeGuardError
|
|
16
16
|
export function assertGuard<T>(input: unknown): asserts input is T;
|
|
17
17
|
export function validate<T>(input: unknown): IValidation<T>; // detailed
|
|
18
|
+
export function shallow<T, N extends number = 2>(input: unknown): input is T; // depth-limited is()
|
|
18
19
|
|
|
19
20
|
// JSON FUNCTIONS
|
|
20
21
|
export namespace json {
|
|
@@ -138,8 +139,8 @@ Check out the document in the [website](https://typia.io/docs/):
|
|
|
138
139
|
- Runtime Validators
|
|
139
140
|
- [`assert()` function](https://typia.io/docs/validators/assert/)
|
|
140
141
|
- [`is()` function](https://typia.io/docs/validators/is/)
|
|
142
|
+
- [`shallow()` function](https://typia.io/docs/validators/shallow/)
|
|
141
143
|
- [`validate()` function](https://typia.io/docs/validators/validate/)
|
|
142
|
-
- [Functional Module](https://typia.io/docs/validators/functional)
|
|
143
144
|
- [Special Tags](https://typia.io/docs/validators/tags/)
|
|
144
145
|
- Enhanced JSON
|
|
145
146
|
- [JSON Schema](https://typia.io/docs/json/schema/)
|
|
@@ -149,6 +150,8 @@ Check out the document in the [website](https://typia.io/docs/):
|
|
|
149
150
|
- [`application()` function](https://typia.io/docs/llm/application/)
|
|
150
151
|
- [`structuredOutput()` function](https://typia.io/docs/llm/structuredOutput/)
|
|
151
152
|
- [`evaluation()` function](https://typia.io/docs/llm/evaluation/)
|
|
153
|
+
- [`parameters()` function](https://typia.io/docs/llm/parameters/)
|
|
154
|
+
- [`schema()` function](https://typia.io/docs/llm/schema/)
|
|
152
155
|
- [`HttpLlm` module](https://typia.io/docs/llm/http/)
|
|
153
156
|
- [`LlmJson` module](https://typia.io/docs/llm/json/)
|
|
154
157
|
- Protocol Buffer
|
|
@@ -157,16 +160,18 @@ Check out the document in the [website](https://typia.io/docs/):
|
|
|
157
160
|
- [`encode()` functions](https://typia.io/docs/protobuf/encode/)
|
|
158
161
|
- [Random Generator](https://typia.io/docs/random/)
|
|
159
162
|
- [Miscellaneous](https://typia.io/docs/misc/)
|
|
163
|
+
- [Functional Module](https://typia.io/docs/misc/#functional)
|
|
160
164
|
|
|
161
165
|
### 🔗 Appendix
|
|
162
166
|
|
|
163
|
-
- [API Documents](https://typia.io/api)
|
|
164
167
|
- Utilization Cases
|
|
165
168
|
- [MCP](https://typia.io/docs/utilization/mcp/)
|
|
166
169
|
- [Vercel AI SDK](https://typia.io/docs/utilization/vercel/)
|
|
170
|
+
- [Jev](https://typia.io/docs/utilization/jev/)
|
|
167
171
|
- [LangChain](https://typia.io/docs/utilization/langchain/)
|
|
168
172
|
- [NestJS](https://typia.io/docs/utilization/nestjs/)
|
|
169
173
|
- [tRPC](https://typia.io/docs/utilization/trpc/)
|
|
174
|
+
- [Hono](https://typia.io/docs/utilization/hono/)
|
|
170
175
|
- [⇲ Benchmark Result](https://github.com/samchon/typia/tree/master/benchmark/results/11th%20Gen%20Intel(R)%20Core(TM)%20i5-1135G7%20%40%202.40GHz)
|
|
171
176
|
- [⇲ `dev.to` Articles](https://dev.to/samchon/series/22474)
|
|
172
177
|
|
package/lib/transform.d.ts
CHANGED
|
@@ -12,7 +12,9 @@ import type { ITtscPlugin, ITtscPluginFactoryContext } from "ttsc";
|
|
|
12
12
|
* and compiler-owned output provenance for ttsc's checked runtime reuse
|
|
13
13
|
* protocol. Its only variable reads outside ttsc's own namespace go through the
|
|
14
14
|
* program's recorded `Env`, so it declares `environmentInputs` and ttsc keys
|
|
15
|
-
* its outputs by the variables it read instead of the whole environment.
|
|
15
|
+
* its outputs by the variables it read instead of the whole environment. The
|
|
16
|
+
* host also answers `check-serve`, so it declares `residentCheck` and a `ttsc
|
|
17
|
+
* --noEmit --watch` keeps one typia process and its program across saves.
|
|
16
18
|
*
|
|
17
19
|
* @param context Plugin factory context of ttsc
|
|
18
20
|
*
|
package/lib/transform.js
CHANGED
|
@@ -19,7 +19,9 @@ const node_path_1 = __importDefault(require("node:path"));
|
|
|
19
19
|
* and compiler-owned output provenance for ttsc's checked runtime reuse
|
|
20
20
|
* protocol. Its only variable reads outside ttsc's own namespace go through the
|
|
21
21
|
* program's recorded `Env`, so it declares `environmentInputs` and ttsc keys
|
|
22
|
-
* its outputs by the variables it read instead of the whole environment.
|
|
22
|
+
* its outputs by the variables it read instead of the whole environment. The
|
|
23
|
+
* host also answers `check-serve`, so it declares `residentCheck` and a `ttsc
|
|
24
|
+
* --noEmit --watch` keeps one typia process and its program across saves.
|
|
23
25
|
*
|
|
24
26
|
* @param context Plugin factory context of ttsc
|
|
25
27
|
*
|
|
@@ -44,6 +46,7 @@ function createTtscPlugin(context) {
|
|
|
44
46
|
emitObservations: true,
|
|
45
47
|
emitProvenance: true,
|
|
46
48
|
environmentInputs: true,
|
|
49
|
+
residentCheck: true,
|
|
47
50
|
},
|
|
48
51
|
};
|
|
49
52
|
}
|
package/lib/transform.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transform.js","sources":["../src/transform.ts"],"names":[],"mappings":";;;;;;AAAA,6CAA4C;AAC5C,0DAA6B;AAG7B
|
|
1
|
+
{"version":3,"file":"transform.js","sources":["../src/transform.ts"],"names":[],"mappings":";;;;;;AAAA,6CAA4C;AAC5C,0DAA6B;AAG7B;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,0BACE,OAAkC;IAElC,oEAAoE;IACpE,wEAAwE;IACxE,2EAA2E;IAC3E,MAAM,WAAW,GAAG,IAAA,2BAAa,EAC/B,mBAAI,CAAC,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,cAAc,CAAC,CAC/C,CAAC;IACF,MAAM,IAAI,GAAW,mBAAI,CAAC,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,oBAAoB,CAAC,CAAC,CAAC;IAC7E,OAAO;QACL,IAAI,EAAE,OAAO;QACb,MAAM,EAAE,mBAAI,CAAC,OAAO,CAAC,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,YAAY,CAAC;QACzD,eAAe,EAAE,EAAE;QACnB,YAAY,EAAE;YACZ,gBAAgB,EAAE,IAAI;YACtB,cAAc,EAAE,IAAI;YACpB,iBAAiB,EAAE,IAAI;YACvB,aAAa,EAAE,IAAI;SACpB;KACF,CAAC;AACJ,CAAC;kBAEc,gBAAgB"}
|
package/lib/transform.mjs
CHANGED
|
@@ -14,7 +14,9 @@ import path from "node:path";
|
|
|
14
14
|
* and compiler-owned output provenance for ttsc's checked runtime reuse
|
|
15
15
|
* protocol. Its only variable reads outside ttsc's own namespace go through the
|
|
16
16
|
* program's recorded `Env`, so it declares `environmentInputs` and ttsc keys
|
|
17
|
-
* its outputs by the variables it read instead of the whole environment.
|
|
17
|
+
* its outputs by the variables it read instead of the whole environment. The
|
|
18
|
+
* host also answers `check-serve`, so it declares `residentCheck` and a `ttsc
|
|
19
|
+
* --noEmit --watch` keeps one typia process and its program across saves.
|
|
18
20
|
*
|
|
19
21
|
* @param context Plugin factory context of ttsc
|
|
20
22
|
*
|
|
@@ -35,7 +37,8 @@ function createTtscPlugin(context) {
|
|
|
35
37
|
capabilities: {
|
|
36
38
|
emitObservations: true,
|
|
37
39
|
emitProvenance: true,
|
|
38
|
-
environmentInputs: true
|
|
40
|
+
environmentInputs: true,
|
|
41
|
+
residentCheck: true
|
|
39
42
|
}
|
|
40
43
|
};
|
|
41
44
|
}
|
package/lib/transform.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transform.mjs","names":[],"sources":["../src/transform.ts"],"sourcesContent":["import { createRequire } from \"node:module\";\nimport path from \"node:path\";\nimport type { ITtscPlugin, ITtscPluginFactoryContext } from \"ttsc\";\n\n/**\n * Describe typia's native transform to ttsc.\n *\n * Ttsc loads this file as an ES module, where `require` is unavailable, so a\n * resolver is anchored on the consuming project to find typia's own package\n * root. The returned descriptor names the plugin and the Go command under\n * `native/cmd/ttsc-typia`; the transform itself is not written in TypeScript.\n * No file is read outside the module graph. Ttsc records the package\n * resolution, so an empty hostInputHashes declaration permits safe descriptor\n * replay. The native build host supplies generation-owned input observations\n * and compiler-owned output provenance for ttsc's checked runtime reuse\n * protocol. Its only variable reads outside ttsc's own namespace go through the\n * program's recorded `Env`, so it declares `environmentInputs` and ttsc keys\n * its outputs by the variables it read instead of the whole environment.\n *\n * @param context Plugin factory context of ttsc\n *\n * @returns Plugin descriptor\n *\n * @evidence contracts/common.md#principled-implementation The ttsc loader runs this file as an ES module where `require` is absent, so the function builds a CommonJS resolver anchored at the consuming project and resolves typia's own `package.json`, whose directory holds the native sources. No external file is read; ttsc records that module lookup and invalidates descriptor replay when its module graph or factory inputs change. The descriptor names the plugin and Go command under `native/cmd/ttsc-typia`.\n * @evidence contracts/common.md#clear-and-simple-design One function returns the plugin name, Go source, supported native protocols and external-input declaration; the default export repeats the same function for loaders that read it.\n * @evidence contracts/common.md#prohibited-implementation-shortcuts The package root comes from the installed typia through the supported resolver and not from path substrings, so it works for npm consumers and workspaces alike; the transform itself stays in Go.\n * @evidence contracts/common.md#meaningful-documentation A comment explains the purpose, the ESM resolution reason and the descriptor.\n */\nexport function createTtscPlugin(\n context: ITtscPluginFactoryContext,\n): ITtscPlugin {\n // ttsc loads this descriptor as ESM, where the ambient `require` is\n // unavailable; anchor a CJS resolver on the consuming project to locate\n // typia's own package root (not the project root, which has no `native/`).\n const requireFrom = createRequire(\n path.join(context.projectRoot, \"package.json\"),\n );\n const root: string = path.dirname(requireFrom.resolve(\"typia/package.json\"));\n return {\n name: \"typia\",\n source: path.resolve(root, \"native\", \"cmd\", \"ttsc-typia\"),\n hostInputHashes: {},\n capabilities: {\n emitObservations: true,\n emitProvenance: true,\n environmentInputs: true,\n },\n };\n}\n\nexport default createTtscPlugin;\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"transform.mjs","names":[],"sources":["../src/transform.ts"],"sourcesContent":["import { createRequire } from \"node:module\";\nimport path from \"node:path\";\nimport type { ITtscPlugin, ITtscPluginFactoryContext } from \"ttsc\";\n\n/**\n * Describe typia's native transform to ttsc.\n *\n * Ttsc loads this file as an ES module, where `require` is unavailable, so a\n * resolver is anchored on the consuming project to find typia's own package\n * root. The returned descriptor names the plugin and the Go command under\n * `native/cmd/ttsc-typia`; the transform itself is not written in TypeScript.\n * No file is read outside the module graph. Ttsc records the package\n * resolution, so an empty hostInputHashes declaration permits safe descriptor\n * replay. The native build host supplies generation-owned input observations\n * and compiler-owned output provenance for ttsc's checked runtime reuse\n * protocol. Its only variable reads outside ttsc's own namespace go through the\n * program's recorded `Env`, so it declares `environmentInputs` and ttsc keys\n * its outputs by the variables it read instead of the whole environment. The\n * host also answers `check-serve`, so it declares `residentCheck` and a `ttsc\n * --noEmit --watch` keeps one typia process and its program across saves.\n *\n * @param context Plugin factory context of ttsc\n *\n * @returns Plugin descriptor\n *\n * @evidence contracts/common.md#principled-implementation The ttsc loader runs this file as an ES module where `require` is absent, so the function builds a CommonJS resolver anchored at the consuming project and resolves typia's own `package.json`, whose directory holds the native sources. No external file is read; ttsc records that module lookup and invalidates descriptor replay when its module graph or factory inputs change. The descriptor names the plugin and Go command under `native/cmd/ttsc-typia`.\n * @evidence contracts/common.md#clear-and-simple-design One function returns the plugin name, Go source, supported native protocols and external-input declaration; the default export repeats the same function for loaders that read it.\n * @evidence contracts/common.md#prohibited-implementation-shortcuts The package root comes from the installed typia through the supported resolver and not from path substrings, so it works for npm consumers and workspaces alike; the transform itself stays in Go.\n * @evidence contracts/common.md#meaningful-documentation A comment explains the purpose, the ESM resolution reason and the descriptor.\n */\nexport function createTtscPlugin(\n context: ITtscPluginFactoryContext,\n): ITtscPlugin {\n // ttsc loads this descriptor as ESM, where the ambient `require` is\n // unavailable; anchor a CJS resolver on the consuming project to locate\n // typia's own package root (not the project root, which has no `native/`).\n const requireFrom = createRequire(\n path.join(context.projectRoot, \"package.json\"),\n );\n const root: string = path.dirname(requireFrom.resolve(\"typia/package.json\"));\n return {\n name: \"typia\",\n source: path.resolve(root, \"native\", \"cmd\", \"ttsc-typia\"),\n hostInputHashes: {},\n capabilities: {\n emitObservations: true,\n emitProvenance: true,\n environmentInputs: true,\n residentCheck: true,\n },\n };\n}\n\nexport default createTtscPlugin;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BA,SAAgB,iBACd,SACa;CAIb,MAAM,cAAc,cAClB,KAAK,KAAK,QAAQ,aAAa,cAAc,CAC/C;CACA,MAAM,OAAe,KAAK,QAAQ,YAAY,QAAQ,oBAAoB,CAAC;CAC3E,OAAO;EACL,MAAM;EACN,QAAQ,KAAK,QAAQ,MAAM,UAAU,OAAO,YAAY;EACxD,iBAAiB,CAAC;EAClB,cAAc;GACZ,kBAAkB;GAClB,gBAAgB;GAChB,mBAAmB;GACnB,eAAe;EACjB;CACF;AACF"}
|
|
@@ -26,25 +26,16 @@ import (
|
|
|
26
26
|
// Failed builds still report observations; buffered or discarded output never
|
|
27
27
|
// acquires provenance. Without the private flags, ordinary command behavior is
|
|
28
28
|
// unchanged.
|
|
29
|
+
//
|
|
30
|
+
// An analysis-only run (`check`, `--noEmit` or a noEmit project) loads one
|
|
31
|
+
// Program and answers through analyzeTypiaProgram; only an emitting run enters
|
|
32
|
+
// the printer.
|
|
29
33
|
func runBuild(args []string) (status int) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
tsconfigPath := fs.String("tsconfig", "tsconfig.json", "path to tsconfig.json")
|
|
33
|
-
cwdOverride := fs.String("cwd", "", "override the working directory")
|
|
34
|
-
quiet := fs.Bool("quiet", true, "suppress the per-call diagnostic summary")
|
|
35
|
-
verbose := fs.Bool("verbose", false, "print the per-call diagnostic summary")
|
|
36
|
-
emit := fs.Bool("emit", false, "force emitted .js files")
|
|
37
|
-
noEmit := fs.Bool("noEmit", false, "force analysis-only run with no file writes")
|
|
38
|
-
outDir := fs.String("outDir", "", "override compilerOptions.outDir")
|
|
39
|
-
manifestPath := fs.String("manifest", "", "write emitted file list as JSON")
|
|
40
|
-
rewriteMode := fs.String("rewrite-mode", "typia", "native rewrite backend id")
|
|
41
|
-
pluginsJSON := fs.String("plugins-json", "", "ordered ttsc plugin payload")
|
|
42
|
-
observationsPath := fs.String("emit-observations-json", "", "private absolute build input result path")
|
|
43
|
-
provenancePath := fs.String("emit-provenance-json", "", "private absolute emit provenance result path")
|
|
44
|
-
if err := fs.Parse(args); err != nil {
|
|
34
|
+
flags, ok := parseBuildFlags("build", args)
|
|
35
|
+
if !ok {
|
|
45
36
|
return 2
|
|
46
37
|
}
|
|
47
|
-
for _, path := range []string{
|
|
38
|
+
for _, path := range []string{flags.observationsPath, flags.provenancePath} {
|
|
48
39
|
if path != "" && !filepath.IsAbs(path) {
|
|
49
40
|
fmt.Fprintln(stderr, "ttsc-typia build: private result path must be absolute")
|
|
50
41
|
return 2
|
|
@@ -55,16 +46,16 @@ func runBuild(args []string) (status int) {
|
|
|
55
46
|
defer func() {
|
|
56
47
|
// Publish while the checker and generation-owned input ledger are live.
|
|
57
48
|
// Even a failed load has an explicit incomplete observation envelope.
|
|
58
|
-
if
|
|
59
|
-
if err := driver.WriteCheckObservationsJSON(
|
|
49
|
+
if flags.observationsPath != "" {
|
|
50
|
+
if err := driver.WriteCheckObservationsJSON(flags.observationsPath, prog); err != nil {
|
|
60
51
|
fmt.Fprintf(stderr, "ttsc-typia build: emit observations write failed: %v\n", err)
|
|
61
52
|
if status == 0 {
|
|
62
53
|
status = 3
|
|
63
54
|
}
|
|
64
55
|
}
|
|
65
56
|
}
|
|
66
|
-
if
|
|
67
|
-
if err := driver.WriteEmitProvenanceJSON(
|
|
57
|
+
if flags.provenancePath != "" {
|
|
58
|
+
if err := driver.WriteEmitProvenanceJSON(flags.provenancePath, snapshot()); err != nil {
|
|
68
59
|
fmt.Fprintf(stderr, "ttsc-typia build: provenance write failed: %v\n", err)
|
|
69
60
|
if status == 0 {
|
|
70
61
|
status = 3
|
|
@@ -75,82 +66,28 @@ func runBuild(args []string) (status int) {
|
|
|
75
66
|
prog.Close()
|
|
76
67
|
}
|
|
77
68
|
}()
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
return
|
|
81
|
-
}
|
|
82
|
-
if *verbose {
|
|
83
|
-
*quiet = false
|
|
84
|
-
}
|
|
85
|
-
if *rewriteMode != "none" && *rewriteMode != "typia" {
|
|
86
|
-
fmt.Fprintf(stderr, "ttsc-typia build: unknown --rewrite-mode value %q\n", *rewriteMode)
|
|
87
|
-
return 2
|
|
88
|
-
}
|
|
89
|
-
// Resolve the options before loading the program: they come from the payload
|
|
90
|
-
// alone, so an unreadable manifest is a usage error to report now rather than
|
|
91
|
-
// after a full compile has already run under the wrong configuration.
|
|
92
|
-
pluginOptions, err := typiaadapter.ReadPluginOptions(*pluginsJSON)
|
|
93
|
-
if err != nil {
|
|
94
|
-
fmt.Fprintf(stderr, "ttsc-typia build: %v\n", err)
|
|
95
|
-
return 2
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
cwd := *cwdOverride
|
|
99
|
-
if cwd == "" {
|
|
100
|
-
if cwd, err = os.Getwd(); err != nil {
|
|
101
|
-
fmt.Fprintf(stderr, "ttsc-typia build: cwd: %v\n", err)
|
|
102
|
-
return 2
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
loadProgram := func(options driver.LoadProgramOptions, diagnose bool) int {
|
|
106
|
-
options.SemanticConfigPath = os.Getenv(driver.SemanticConfigPathEnv)
|
|
107
|
-
loaded, diags, err := driver.LoadProgram(cwd, *tsconfigPath, options)
|
|
108
|
-
prog = loaded
|
|
109
|
-
if err != nil {
|
|
110
|
-
fmt.Fprintf(stderr, "ttsc-typia build: %v\n", err)
|
|
111
|
-
return 2
|
|
112
|
-
}
|
|
113
|
-
if len(diags) > 0 {
|
|
114
|
-
driver.WritePrettyDiagnostics(stderr, diags, cwd)
|
|
115
|
-
return 2
|
|
116
|
-
}
|
|
117
|
-
if diagnose {
|
|
118
|
-
if diags := prog.Diagnostics(); len(diags) > 0 {
|
|
119
|
-
driver.WritePrettyDiagnostics(stderr, diags, cwd)
|
|
120
|
-
return 2
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
return 0
|
|
69
|
+
settings, code := prepareBuild("ttsc-typia build", flags)
|
|
70
|
+
if code != 0 {
|
|
71
|
+
return code
|
|
124
72
|
}
|
|
125
|
-
code
|
|
126
|
-
ForceEmit:
|
|
127
|
-
ForceNoEmit:
|
|
128
|
-
OutDir:
|
|
129
|
-
},
|
|
73
|
+
prog, code = loadTypiaProgram(settings, driver.LoadProgramOptions{
|
|
74
|
+
ForceEmit: flags.emit,
|
|
75
|
+
ForceNoEmit: flags.noEmit,
|
|
76
|
+
OutDir: flags.outDir,
|
|
77
|
+
}, stderr)
|
|
130
78
|
if code != 0 {
|
|
131
79
|
return code
|
|
132
80
|
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
// project's diagnostics; diagnosing the private reload would reject valid
|
|
139
|
-
// analysis-only options such as allowImportingTsExtensions.
|
|
140
|
-
prog.Close()
|
|
141
|
-
code = loadProgram(driver.LoadProgramOptions{
|
|
142
|
-
ForceEmit: true,
|
|
143
|
-
OutDir: *outDir,
|
|
144
|
-
}, false)
|
|
145
|
-
if code != 0 {
|
|
146
|
-
return code
|
|
147
|
-
}
|
|
81
|
+
if code = reportTypiaProgramDiagnostics(prog, settings.cwd, stderr); code != 0 {
|
|
82
|
+
return code
|
|
83
|
+
}
|
|
84
|
+
if prog.ParsedConfig.ParsedConfig.CompilerOptions.NoEmit.IsTrue() {
|
|
85
|
+
return analyzeTypiaProgram(prog, settings, stdout, stderr)
|
|
148
86
|
}
|
|
149
87
|
registerTypiaDefaultLibraryClassifier(prog)
|
|
150
88
|
defer schemametadata.MetadataDefaultLibrary_release(prog.Checker)
|
|
151
89
|
|
|
152
90
|
transformDiags := []typiaTransformDiagnostic{}
|
|
153
|
-
transformOptions := pluginOptions.TransformOptions()
|
|
154
91
|
extras := nativecontext.ITypiaContext_Extras{
|
|
155
92
|
Shared: &sync.Map{},
|
|
156
93
|
AddDiagnostic: func(diag *nativecontext.ITypiaDiagnostic) int {
|
|
@@ -162,20 +99,20 @@ func runBuild(args []string) (status int) {
|
|
|
162
99
|
// pipeline (sharing the EmitContext), so it returns AST and tsgo's module-
|
|
163
100
|
// transform aliases the injected namespace imports. No text-splice RewriteSet.
|
|
164
101
|
typiaTransform := func(ec *shimprinter.EmitContext, sf *shimast.SourceFile) *shimast.SourceFile {
|
|
165
|
-
if
|
|
102
|
+
if settings.rewriteMode != "typia" {
|
|
166
103
|
return sf
|
|
167
104
|
}
|
|
168
|
-
return nativetransform.Transform(prog, &transformOptions, extras, ec)(sf)
|
|
105
|
+
return nativetransform.Transform(prog, &settings.transformOptions, extras, ec)(sf)
|
|
169
106
|
}
|
|
170
|
-
if
|
|
171
|
-
|
|
107
|
+
if !settings.quiet {
|
|
108
|
+
writeTypiaBuildSummary(stdout, settings, true)
|
|
172
109
|
}
|
|
173
110
|
emitted := []string{}
|
|
174
111
|
pending := []buildPendingOutput{}
|
|
175
112
|
publish := shimcompiler.WriteFile(func(name shimtspath.RootedFilePath, text string, _ *shimcompiler.WriteFileData) error {
|
|
176
113
|
return driver.DefaultWriteFile(string(name), text)
|
|
177
114
|
})
|
|
178
|
-
if
|
|
115
|
+
if flags.provenancePath != "" {
|
|
179
116
|
recordedWrite, recordedSnapshot, err := prog.NewEmitProvenanceRecorder(publish)
|
|
180
117
|
if err != nil {
|
|
181
118
|
fmt.Fprintf(stderr, "ttsc-typia build: provenance failed: %v\n", err)
|
|
@@ -185,10 +122,8 @@ func runBuild(args []string) (status int) {
|
|
|
185
122
|
}
|
|
186
123
|
writeFile := shimcompiler.WriteFile(func(name shimtspath.RootedFilePath, text string, data *shimcompiler.WriteFileData) error {
|
|
187
124
|
fileName := string(name)
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
pending = append(pending, buildPendingOutput{FileName: fileName, Text: text, Data: data})
|
|
191
|
-
}
|
|
125
|
+
emitted = append(emitted, fileName)
|
|
126
|
+
pending = append(pending, buildPendingOutput{FileName: fileName, Text: text, Data: data})
|
|
192
127
|
return nil
|
|
193
128
|
})
|
|
194
129
|
eDiags, err := prog.EmitWithPluginTransformers([]driver.PluginTransform{typiaTransform}, writeFile)
|
|
@@ -200,45 +135,170 @@ func runBuild(args []string) (status int) {
|
|
|
200
135
|
fmt.Fprintln(stderr, " -", d.String())
|
|
201
136
|
}
|
|
202
137
|
if len(transformDiags) > 0 {
|
|
203
|
-
writeTypiaTransformDiagnostics(stderr, transformDiags, cwd)
|
|
138
|
+
writeTypiaTransformDiagnostics(stderr, transformDiags, settings.cwd)
|
|
204
139
|
return 3
|
|
205
140
|
}
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
return 3
|
|
211
|
-
}
|
|
141
|
+
for _, output := range pending {
|
|
142
|
+
if err := publish(shimtspath.RootedFilePath(output.FileName), output.Text, output.Data); err != nil {
|
|
143
|
+
fmt.Fprintf(stderr, "ttsc-typia build: emit write failed: %v\n", err)
|
|
144
|
+
return 3
|
|
212
145
|
}
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
fmt.Fprintln(stdout, " +", rel)
|
|
146
|
+
}
|
|
147
|
+
if !settings.quiet {
|
|
148
|
+
fmt.Fprintf(stdout, "// ttsc-typia build: emitted=%d files\n", len(emitted))
|
|
149
|
+
for _, f := range emitted {
|
|
150
|
+
rel := f
|
|
151
|
+
if abs, err := filepath.Rel(settings.cwd, f); err == nil {
|
|
152
|
+
rel = abs
|
|
221
153
|
}
|
|
154
|
+
fmt.Fprintln(stdout, " +", rel)
|
|
222
155
|
}
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
if err := os.MkdirAll(filepath.Dir(*manifestPath), 0o755); err != nil {
|
|
230
|
-
fmt.Fprintf(stderr, "ttsc-typia build: manifest mkdir failed: %v\n", err)
|
|
231
|
-
return 3
|
|
232
|
-
}
|
|
233
|
-
if err := os.WriteFile(*manifestPath, data, 0o644); err != nil {
|
|
234
|
-
fmt.Fprintf(stderr, "ttsc-typia build: manifest write failed: %v\n", err)
|
|
235
|
-
return 3
|
|
236
|
-
}
|
|
156
|
+
}
|
|
157
|
+
if flags.manifest != "" {
|
|
158
|
+
data, err := json.Marshal(emitted)
|
|
159
|
+
if err != nil {
|
|
160
|
+
fmt.Fprintf(stderr, "ttsc-typia build: manifest marshal failed: %v\n", err)
|
|
161
|
+
return 3
|
|
237
162
|
}
|
|
163
|
+
if err := os.MkdirAll(filepath.Dir(flags.manifest), 0o755); err != nil {
|
|
164
|
+
fmt.Fprintf(stderr, "ttsc-typia build: manifest mkdir failed: %v\n", err)
|
|
165
|
+
return 3
|
|
166
|
+
}
|
|
167
|
+
if err := os.WriteFile(flags.manifest, data, 0o644); err != nil {
|
|
168
|
+
fmt.Fprintf(stderr, "ttsc-typia build: manifest write failed: %v\n", err)
|
|
169
|
+
return 3
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return 0
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// buildFlags is the command line shared by `build`, `check` and `check-serve`.
|
|
176
|
+
type buildFlags struct {
|
|
177
|
+
tsconfig string
|
|
178
|
+
cwd string
|
|
179
|
+
quiet bool
|
|
180
|
+
verbose bool
|
|
181
|
+
emit bool
|
|
182
|
+
noEmit bool
|
|
183
|
+
outDir string
|
|
184
|
+
manifest string
|
|
185
|
+
rewriteMode string
|
|
186
|
+
pluginsJSON string
|
|
187
|
+
observationsPath string
|
|
188
|
+
provenancePath string
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// parseBuildFlags parses the shared command line under the given command name,
|
|
192
|
+
// which flag errors and usage print. A parse error has already been reported.
|
|
193
|
+
func parseBuildFlags(command string, args []string) (buildFlags, bool) {
|
|
194
|
+
var flags buildFlags
|
|
195
|
+
fs := flag.NewFlagSet(command, flag.ContinueOnError)
|
|
196
|
+
fs.SetOutput(stderr)
|
|
197
|
+
fs.StringVar(&flags.tsconfig, "tsconfig", "tsconfig.json", "path to tsconfig.json")
|
|
198
|
+
fs.StringVar(&flags.cwd, "cwd", "", "override the working directory")
|
|
199
|
+
fs.BoolVar(&flags.quiet, "quiet", true, "suppress the per-call diagnostic summary")
|
|
200
|
+
fs.BoolVar(&flags.verbose, "verbose", false, "print the per-call diagnostic summary")
|
|
201
|
+
fs.BoolVar(&flags.emit, "emit", false, "force emitted .js files")
|
|
202
|
+
fs.BoolVar(&flags.noEmit, "noEmit", false, "force analysis-only run with no file writes")
|
|
203
|
+
fs.StringVar(&flags.outDir, "outDir", "", "override compilerOptions.outDir")
|
|
204
|
+
fs.StringVar(&flags.manifest, "manifest", "", "write emitted file list as JSON")
|
|
205
|
+
fs.StringVar(&flags.rewriteMode, "rewrite-mode", "typia", "native rewrite backend id")
|
|
206
|
+
fs.StringVar(&flags.pluginsJSON, "plugins-json", "", "ordered ttsc plugin payload")
|
|
207
|
+
fs.StringVar(&flags.observationsPath, "emit-observations-json", "", "private absolute build input result path")
|
|
208
|
+
fs.StringVar(&flags.provenancePath, "emit-provenance-json", "", "private absolute emit provenance result path")
|
|
209
|
+
if err := fs.Parse(args); err != nil {
|
|
210
|
+
return flags, false
|
|
211
|
+
}
|
|
212
|
+
return flags, true
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// buildSettings is what loading and analyzing a project needs from a validated
|
|
216
|
+
// command line.
|
|
217
|
+
type buildSettings struct {
|
|
218
|
+
// cwd is the project anchor diagnostics are rendered against.
|
|
219
|
+
cwd string
|
|
220
|
+
|
|
221
|
+
// tsconfig is the project file as the command line spelled it.
|
|
222
|
+
tsconfig string
|
|
223
|
+
|
|
224
|
+
// quiet suppresses the stdout summary.
|
|
225
|
+
quiet bool
|
|
226
|
+
|
|
227
|
+
// rewriteMode is "typia", or "none" to skip the transform.
|
|
228
|
+
rewriteMode string
|
|
229
|
+
|
|
230
|
+
// transformOptions are typia's options from the plugin payload.
|
|
231
|
+
transformOptions nativecontext.ITransformOptions
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// prepareBuild validates the flags that do not need a Program and resolves the
|
|
235
|
+
// working directory. Messages carry command as their prefix; a failure returns
|
|
236
|
+
// status 2.
|
|
237
|
+
func prepareBuild(command string, flags buildFlags) (buildSettings, int) {
|
|
238
|
+
settings := buildSettings{
|
|
239
|
+
tsconfig: flags.tsconfig,
|
|
240
|
+
quiet: flags.quiet && !flags.verbose,
|
|
241
|
+
rewriteMode: flags.rewriteMode,
|
|
242
|
+
}
|
|
243
|
+
if flags.emit && flags.noEmit {
|
|
244
|
+
fmt.Fprintf(stderr, "%s: --emit and --noEmit are mutually exclusive\n", command)
|
|
245
|
+
return settings, 2
|
|
246
|
+
}
|
|
247
|
+
if flags.rewriteMode != "none" && flags.rewriteMode != "typia" {
|
|
248
|
+
fmt.Fprintf(stderr, "%s: unknown --rewrite-mode value %q\n", command, flags.rewriteMode)
|
|
249
|
+
return settings, 2
|
|
250
|
+
}
|
|
251
|
+
// Resolve the options before loading the program: they come from the payload
|
|
252
|
+
// alone, so an unreadable manifest is a usage error to report now rather than
|
|
253
|
+
// after a full compile has already run under the wrong configuration.
|
|
254
|
+
pluginOptions, err := typiaadapter.ReadPluginOptions(flags.pluginsJSON)
|
|
255
|
+
if err != nil {
|
|
256
|
+
fmt.Fprintf(stderr, "%s: %v\n", command, err)
|
|
257
|
+
return settings, 2
|
|
258
|
+
}
|
|
259
|
+
settings.transformOptions = pluginOptions.TransformOptions()
|
|
260
|
+
settings.cwd = flags.cwd
|
|
261
|
+
if settings.cwd == "" {
|
|
262
|
+
if settings.cwd, err = os.Getwd(); err != nil {
|
|
263
|
+
fmt.Fprintf(stderr, "%s: cwd: %v\n", command, err)
|
|
264
|
+
return settings, 2
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
return settings, 0
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
// loadTypiaProgram loads the project. A load or configuration failure is
|
|
271
|
+
// written to errOut and returns status 2; the Program is returned whenever the
|
|
272
|
+
// driver produced one, so the caller keeps ownership of closing it.
|
|
273
|
+
func loadTypiaProgram(settings buildSettings, options driver.LoadProgramOptions, errOut io.Writer) (*driver.Program, int) {
|
|
274
|
+
options.SemanticConfigPath = os.Getenv(driver.SemanticConfigPathEnv)
|
|
275
|
+
prog, diags, err := driver.LoadProgram(settings.cwd, settings.tsconfig, options)
|
|
276
|
+
if err != nil {
|
|
277
|
+
fmt.Fprintf(errOut, "ttsc-typia build: %v\n", err)
|
|
278
|
+
return prog, 2
|
|
279
|
+
}
|
|
280
|
+
if len(diags) > 0 {
|
|
281
|
+
driver.WritePrettyDiagnostics(errOut, diags, settings.cwd)
|
|
282
|
+
return prog, 2
|
|
283
|
+
}
|
|
284
|
+
return prog, 0
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
// reportTypiaProgramDiagnostics writes the Program's complete diagnostic batch
|
|
288
|
+
// to errOut and returns status 2 when it holds any diagnostic.
|
|
289
|
+
func reportTypiaProgramDiagnostics(prog *driver.Program, cwd string, errOut io.Writer) int {
|
|
290
|
+
if diags := prog.Diagnostics(); len(diags) > 0 {
|
|
291
|
+
driver.WritePrettyDiagnostics(errOut, diags, cwd)
|
|
292
|
+
return 2
|
|
238
293
|
}
|
|
239
294
|
return 0
|
|
240
295
|
}
|
|
241
296
|
|
|
297
|
+
// writeTypiaBuildSummary prints the verbose run header.
|
|
298
|
+
func writeTypiaBuildSummary(out io.Writer, settings buildSettings, emit bool) {
|
|
299
|
+
fmt.Fprintf(out, "// ttsc-typia build: tsconfig=%s cwd=%s emit=%v rewrite=%s\n", settings.tsconfig, settings.cwd, emit, settings.rewriteMode)
|
|
300
|
+
}
|
|
301
|
+
|
|
242
302
|
type buildPendingOutput struct {
|
|
243
303
|
FileName string
|
|
244
304
|
Text string
|
|
@@ -9,58 +9,65 @@ import (
|
|
|
9
9
|
|
|
10
10
|
// TestBuildNoEmitPreservesAnalysisOnlyOptions checks the authored operation results described below.
|
|
11
11
|
//
|
|
12
|
-
// allowImportingTsExtensions is legal for noEmit analysis; an internal traversal override must not invalidate already-valid user options or publish outputs.
|
|
12
|
+
// allowImportingTsExtensions is legal for noEmit analysis; an internal traversal override must not invalidate already-valid user options or publish outputs. noEmitOnError must not turn that override into a failure either: it gates emitted output, and an analysis-only run emits none.
|
|
13
13
|
//
|
|
14
|
-
// 1. A valid typia call uses noEmit together with the analysis-only option; invalid transform noEmit twins are owned by the neighboring diagnostic case.
|
|
14
|
+
// 1. A valid typia call uses noEmit together with the analysis-only option, with and without noEmitOnError; invalid transform noEmit twins are owned by the neighboring diagnostic case.
|
|
15
15
|
// 2. The configured noEmit build succeeds without private emit diagnostics and creates neither dist nor incremental state.
|
|
16
16
|
//
|
|
17
|
-
// @evidence contracts/testing.md#behavioral-verification The configured noEmit build succeeds without private emit diagnostics and creates neither dist nor incremental state.
|
|
18
|
-
// @evidence contracts/testing.md#independent-expectations allowImportingTsExtensions is legal for noEmit analysis; an internal traversal override must not invalidate already-valid user options or publish outputs.
|
|
19
|
-
// @evidence contracts/testing.md#distinguishing-cases A valid typia call uses noEmit together with the analysis-only option;
|
|
17
|
+
// @evidence contracts/testing.md#behavioral-verification The configured noEmit build succeeds without private emit diagnostics and creates neither dist nor incremental state, with and without noEmitOnError.
|
|
18
|
+
// @evidence contracts/testing.md#independent-expectations allowImportingTsExtensions is legal for noEmit analysis; an internal traversal override must not invalidate already-valid user options or publish outputs, and noEmitOnError only withholds output that an analysis-only run never writes.
|
|
19
|
+
// @evidence contracts/testing.md#distinguishing-cases A valid typia call uses noEmit together with the analysis-only option, with noEmitOnError off and on; the second case fails when a private forced-emit Program reaches the pre-emit gate. Invalid transform noEmit twins are owned by the neighboring diagnostic case.
|
|
20
20
|
// @evidence contracts/testing.md#execution-ownership The native Go runner discovers TestBuildNoEmitPreservesAnalysisOnlyOptions as a unit test. Its helpers call the owning Go operations in process; named subcases retain their fixture inputs, assertions and failure identities. Temporary fixtures and captured output are scoped to the test without a compiler or product-host subprocess.
|
|
21
21
|
func TestBuildNoEmitPreservesAnalysisOnlyOptions(t *testing.T) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
22
|
+
for _, tc := range []struct {
|
|
23
|
+
name string
|
|
24
|
+
options string
|
|
25
|
+
}{
|
|
26
|
+
{name: "analysis-only-option", options: `"noEmit": true,
|
|
27
|
+
"allowImportingTsExtensions": true`},
|
|
28
|
+
{name: "no-emit-on-error", options: `"noEmit": true,
|
|
29
|
+
"allowImportingTsExtensions": true,
|
|
30
|
+
"noEmitOnError": true`},
|
|
31
|
+
} {
|
|
32
|
+
t.Run(tc.name, func(t *testing.T) {
|
|
33
|
+
project := buildNoEmitDiagnosticProject(t, true)
|
|
34
|
+
configPath := filepath.Join(project, "tsconfig.json")
|
|
35
|
+
config, err := os.ReadFile(configPath)
|
|
36
|
+
if err != nil {
|
|
37
|
+
t.Fatalf("read tsconfig: %v", err)
|
|
38
|
+
}
|
|
39
|
+
configured := strings.Replace(string(config), `"noEmit": true`, tc.options, 1)
|
|
40
|
+
if err := os.WriteFile(configPath, []byte(configured), 0o644); err != nil {
|
|
41
|
+
t.Fatalf("write tsconfig: %v", err)
|
|
42
|
+
}
|
|
43
|
+
source := `import typia from "typia";
|
|
39
44
|
export const isValue = (input: unknown): input is { value: number } =>
|
|
40
45
|
typia.is<{ value: number }>(input);
|
|
41
46
|
`
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
47
|
+
if err := os.WriteFile(filepath.Join(project, "src", "main.ts"), []byte(source), 0o644); err != nil {
|
|
48
|
+
t.Fatalf("write source: %v", err)
|
|
49
|
+
}
|
|
45
50
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
51
|
+
out, errText, code := ttscTypiaTestCapture(func() int {
|
|
52
|
+
return runBuild([]string{
|
|
53
|
+
"--cwd", project,
|
|
54
|
+
"--tsconfig", "tsconfig.json",
|
|
55
|
+
})
|
|
56
|
+
})
|
|
57
|
+
if code != 0 {
|
|
58
|
+
t.Fatalf("valid analysis-only project failed with code %d\nstdout=%s\nstderr=%s", code, out, errText)
|
|
59
|
+
}
|
|
60
|
+
if strings.TrimSpace(errText) != "" {
|
|
61
|
+
t.Fatalf("valid analysis-only project reported private emit diagnostics:\n%s", errText)
|
|
62
|
+
}
|
|
63
|
+
for _, path := range []string{
|
|
64
|
+
filepath.Join(project, "dist"),
|
|
65
|
+
filepath.Join(project, "cache.tsbuildinfo"),
|
|
66
|
+
} {
|
|
67
|
+
if _, err := os.Stat(path); !os.IsNotExist(err) {
|
|
68
|
+
t.Fatalf("analysis-only traversal published %s: %v", path, err)
|
|
69
|
+
}
|
|
70
|
+
}
|
|
50
71
|
})
|
|
51
|
-
})
|
|
52
|
-
if code != 0 {
|
|
53
|
-
t.Fatalf("valid analysis-only project failed with code %d\nstdout=%s\nstderr=%s", code, out, errText)
|
|
54
|
-
}
|
|
55
|
-
if strings.TrimSpace(errText) != "" {
|
|
56
|
-
t.Fatalf("valid analysis-only project reported private emit diagnostics:\n%s", errText)
|
|
57
|
-
}
|
|
58
|
-
for _, path := range []string{
|
|
59
|
-
filepath.Join(project, "dist"),
|
|
60
|
-
filepath.Join(project, "cache.tsbuildinfo"),
|
|
61
|
-
} {
|
|
62
|
-
if _, err := os.Stat(path); !os.IsNotExist(err) {
|
|
63
|
-
t.Fatalf("analysis-only traversal published %s: %v", path, err)
|
|
64
|
-
}
|
|
65
72
|
}
|
|
66
73
|
}
|