@ttsc/strip 0.30.4 → 0.31.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/config.go +99 -558
- package/driver/strip.go +65 -33
- package/go.mod +5 -5
- package/lib/createTtscStrip.d.ts +93 -0
- package/lib/createTtscStrip.js +169 -0
- package/lib/createTtscStrip.js.map +1 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +24 -0
- package/lib/index.js.map +1 -0
- package/lib/structures/ITtscStripConfig.d.ts +62 -0
- package/lib/structures/ITtscStripConfig.js +3 -0
- package/lib/structures/ITtscStripConfig.js.map +1 -0
- package/lib/structures/index.d.ts +1 -0
- package/lib/structures/index.js +18 -0
- package/lib/structures/index.js.map +1 -0
- package/package.json +18 -8
- package/plugin/main.go +19 -19
- package/src/createTtscStrip.ts +224 -0
- package/src/index.ts +3 -0
- package/src/structures/ITtscStripConfig.ts +63 -0
- package/src/structures/index.ts +1 -0
- package/src/index.cjs +0 -123
- package/src/index.d.ts +0 -55
package/driver/strip.go
CHANGED
|
@@ -18,8 +18,24 @@ type plugin struct{}
|
|
|
18
18
|
|
|
19
19
|
// ApplyProgram strips configured call expressions and debugger statements from
|
|
20
20
|
// every source file in the program.
|
|
21
|
+
//
|
|
22
|
+
// TypeScript-Go's StatementList and ForEachChild APIs supply the traversal.
|
|
23
|
+
// Filtering only changes the current parent's list or embedded body; recursion
|
|
24
|
+
// belongs to ForEachChild. List filtering does not visit retained subtrees,
|
|
25
|
+
// leaving traversal ownership with one recursive path.
|
|
26
|
+
//
|
|
27
|
+
// Configuration and parsed patterns are shared for this program invocation.
|
|
28
|
+
// Filtering compacts each statement list in its own backing array and clears
|
|
29
|
+
// removed tail references, avoiding a replacement allocation per block. The
|
|
30
|
+
// remaining dominant work is visiting AST nodes and matching configured calls.
|
|
31
|
+
//
|
|
32
|
+
// Only configured expression statements and debugger statements are removed.
|
|
33
|
+
// Matching recognizes dotted identifiers rather than evaluating expressions;
|
|
34
|
+
// argument effects are intentionally deleted with a matched whole statement.
|
|
35
|
+
// Embedded bodies become source-located empty statements so required body
|
|
36
|
+
// slots remain present, while retained AST nodes keep their identity.
|
|
21
37
|
func (plugin) ApplyProgram(prog *driver.Program, ctx driver.PluginContext) error {
|
|
22
|
-
config, err := loadStripConfigMapWithReporters(ctx.Entry.Config, ctx.Cwd, ctx.Tsconfig, ctx.ReportHostInput, ctx.ReportHostInputHash, ctx.ReportHostInputRealpath)
|
|
38
|
+
config, err := loadStripConfigMapWithReporters(ctx.Entry.Config, ctx.Cwd, ctx.Tsconfig, ctx.ReportHostInput, ctx.ReportHostInputHash, ctx.ReportHostInputRealpath, ctx.ReportObservationIncomplete)
|
|
23
39
|
if err != nil {
|
|
24
40
|
return err
|
|
25
41
|
}
|
|
@@ -90,28 +106,30 @@ func parseStrip(config map[string]any) (*stripRewriter, error) {
|
|
|
90
106
|
return out, nil
|
|
91
107
|
}
|
|
92
108
|
|
|
93
|
-
// apply
|
|
109
|
+
// apply filters the file through one recursive traversal. Each parent removes
|
|
110
|
+
// matching list entries or replaces embedded bodies before visiting its children.
|
|
94
111
|
func (s *stripRewriter) apply(file *shimast.SourceFile) {
|
|
95
112
|
if s == nil || file == nil || (len(s.calls) == 0 && !s.stripDebugger) {
|
|
96
113
|
return
|
|
97
114
|
}
|
|
98
|
-
|
|
115
|
+
filterChildStatements(file.AsNode(), s)
|
|
99
116
|
}
|
|
100
117
|
|
|
101
118
|
// filterStatements removes stripped statements from list in-place, preserving
|
|
102
|
-
// order.
|
|
119
|
+
// order. It leaves recursion to filterChildStatements so a retained subtree is
|
|
120
|
+
// not processed once through its statement list and again through ForEachChild.
|
|
103
121
|
func filterStatements(list *shimast.NodeList, strip *stripRewriter) {
|
|
104
122
|
if list == nil || len(list.Nodes) == 0 {
|
|
105
123
|
return
|
|
106
124
|
}
|
|
107
|
-
out :=
|
|
125
|
+
out := list.Nodes[:0]
|
|
108
126
|
for _, stmt := range list.Nodes {
|
|
109
127
|
if shouldStripStatement(stmt, strip) {
|
|
110
128
|
continue
|
|
111
129
|
}
|
|
112
|
-
filterChildStatements(stmt, strip)
|
|
113
130
|
out = append(out, stmt)
|
|
114
131
|
}
|
|
132
|
+
clear(list.Nodes[len(out):])
|
|
115
133
|
list.Nodes = out
|
|
116
134
|
}
|
|
117
135
|
|
|
@@ -161,9 +179,10 @@ func filterEmbeddedStatements(node *shimast.Node, strip *stripRewriter) {
|
|
|
161
179
|
}
|
|
162
180
|
}
|
|
163
181
|
|
|
164
|
-
// filterEmbeddedStatement
|
|
182
|
+
// filterEmbeddedStatement filters a single embedded statement without recursion.
|
|
165
183
|
// Returns an empty synthesized statement when stmt is to be stripped, preserving
|
|
166
|
-
// the original source location for downstream source-map accuracy.
|
|
184
|
+
// the original source location for downstream source-map accuracy. The parent's
|
|
185
|
+
// ForEachChild traversal owns recursion into retained or replacement bodies.
|
|
167
186
|
func filterEmbeddedStatement(stmt *shimast.Statement, strip *stripRewriter) *shimast.Statement {
|
|
168
187
|
if stmt == nil {
|
|
169
188
|
return nil
|
|
@@ -171,7 +190,6 @@ func filterEmbeddedStatement(stmt *shimast.Statement, strip *stripRewriter) *shi
|
|
|
171
190
|
if shouldStripStatement(stmt, strip) {
|
|
172
191
|
return emptyStatement(stmt)
|
|
173
192
|
}
|
|
174
|
-
filterChildStatements(stmt, strip)
|
|
175
193
|
return stmt
|
|
176
194
|
}
|
|
177
195
|
|
|
@@ -205,10 +223,15 @@ func shouldStripStatement(node *shimast.Node, strip *stripRewriter) bool {
|
|
|
205
223
|
}
|
|
206
224
|
}
|
|
207
225
|
|
|
208
|
-
// matchesCall reports whether name matches any
|
|
226
|
+
// matchesCall reports whether name matches any configured call pattern.
|
|
227
|
+
// All patterns share one segmentation of this call's name.
|
|
209
228
|
func (s *stripRewriter) matchesCall(name string) bool {
|
|
229
|
+
if len(s.calls) == 0 {
|
|
230
|
+
return false
|
|
231
|
+
}
|
|
232
|
+
parts := strings.Split(name, ".")
|
|
210
233
|
for _, pattern := range s.calls {
|
|
211
|
-
if pattern.
|
|
234
|
+
if pattern.matchesParts(parts) {
|
|
212
235
|
return true
|
|
213
236
|
}
|
|
214
237
|
}
|
|
@@ -216,30 +239,32 @@ func (s *stripRewriter) matchesCall(name string) bool {
|
|
|
216
239
|
}
|
|
217
240
|
|
|
218
241
|
// parseCallPattern parses a dot-separated call pattern string such as
|
|
219
|
-
// "console.log" or "assert.*". A wildcard ("*")
|
|
220
|
-
// final segment
|
|
242
|
+
// "console.log" or "assert.*". A wildcard ("*") requires a dotted prefix
|
|
243
|
+
// and must be the whole final segment; embedded stars and empty segments are
|
|
244
|
+
// rejected.
|
|
221
245
|
func parseCallPattern(text string) (callPattern, error) {
|
|
222
246
|
parts := strings.Split(text, ".")
|
|
223
247
|
for i, part := range parts {
|
|
224
248
|
if part == "" {
|
|
225
249
|
return callPattern{}, fmt.Errorf("invalid call pattern %q", text)
|
|
226
250
|
}
|
|
227
|
-
if part
|
|
228
|
-
return callPattern{}, fmt.Errorf("wildcard is only supported
|
|
251
|
+
if strings.Contains(part, "*") && (part != "*" || i != len(parts)-1) {
|
|
252
|
+
return callPattern{}, fmt.Errorf("wildcard is only supported as the final segment of call pattern %q", text)
|
|
229
253
|
}
|
|
230
254
|
}
|
|
231
255
|
wildcard := parts[len(parts)-1] == "*"
|
|
232
256
|
if wildcard {
|
|
257
|
+
if len(parts) == 1 {
|
|
258
|
+
return callPattern{}, fmt.Errorf("wildcard requires a dotted call prefix in pattern %q", text)
|
|
259
|
+
}
|
|
233
260
|
parts = parts[:len(parts)-1]
|
|
234
261
|
}
|
|
235
262
|
return callPattern{parts: parts, wildcard: wildcard}, nil
|
|
236
263
|
}
|
|
237
264
|
|
|
238
|
-
//
|
|
239
|
-
//
|
|
240
|
-
|
|
241
|
-
func (p callPattern) matches(name string) bool {
|
|
242
|
-
parts := strings.Split(name, ".")
|
|
265
|
+
// matchesParts compares already segmented names so a multi-pattern search
|
|
266
|
+
// does not allocate the same segments for every candidate pattern.
|
|
267
|
+
func (p callPattern) matchesParts(parts []string) bool {
|
|
243
268
|
if p.wildcard {
|
|
244
269
|
if len(parts) <= len(p.parts) {
|
|
245
270
|
return false
|
|
@@ -260,26 +285,33 @@ func callExpressionName(expr *shimast.Node) (string, bool) {
|
|
|
260
285
|
return dottedName(call.Expression)
|
|
261
286
|
}
|
|
262
287
|
|
|
263
|
-
// dottedName
|
|
288
|
+
// dottedName extracts a dot-joined identifier chain from an
|
|
264
289
|
// expression node. Returns ("", false) for any non-identifier, non-property-
|
|
265
|
-
// access node.
|
|
290
|
+
// access node. Segments are collected from right to left, then emitted once
|
|
291
|
+
// in source order without recursively copying a growing dotted prefix.
|
|
266
292
|
func dottedName(expr *shimast.Node) (string, bool) {
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
}
|
|
270
|
-
switch expr.Kind {
|
|
271
|
-
case shimast.KindIdentifier:
|
|
272
|
-
return expr.Text(), true
|
|
273
|
-
case shimast.KindPropertyAccessExpression:
|
|
293
|
+
var suffix []string
|
|
294
|
+
for expr != nil && expr.Kind == shimast.KindPropertyAccessExpression {
|
|
274
295
|
prop := expr.AsPropertyAccessExpression()
|
|
275
|
-
|
|
276
|
-
if !ok || prop.Name() == nil {
|
|
296
|
+
if prop.Name() == nil {
|
|
277
297
|
return "", false
|
|
278
298
|
}
|
|
279
|
-
|
|
280
|
-
|
|
299
|
+
suffix = append(suffix, prop.Name().Text())
|
|
300
|
+
expr = prop.Expression
|
|
301
|
+
}
|
|
302
|
+
if expr == nil || expr.Kind != shimast.KindIdentifier {
|
|
281
303
|
return "", false
|
|
282
304
|
}
|
|
305
|
+
if len(suffix) == 0 {
|
|
306
|
+
return expr.Text(), true
|
|
307
|
+
}
|
|
308
|
+
var name strings.Builder
|
|
309
|
+
name.WriteString(expr.Text())
|
|
310
|
+
for i := len(suffix) - 1; i >= 0; i-- {
|
|
311
|
+
name.WriteByte('.')
|
|
312
|
+
name.WriteString(suffix[i])
|
|
313
|
+
}
|
|
314
|
+
return name.String(), true
|
|
283
315
|
}
|
|
284
316
|
|
|
285
317
|
// stringArrayConfig reads a string array from config[key]. Returns nil when the
|
package/go.mod
CHANGED
|
@@ -5,11 +5,11 @@ go 1.26
|
|
|
5
5
|
require github.com/samchon/ttsc/packages/ttsc v0.0.0
|
|
6
6
|
|
|
7
7
|
require (
|
|
8
|
-
github.com/go-json-experiment/json v0.0.0-
|
|
8
|
+
github.com/go-json-experiment/json v0.0.0-20260601182631-00ed12fed2a6 // indirect
|
|
9
9
|
github.com/klauspost/cpuid/v2 v2.2.10 // indirect
|
|
10
|
-
github.com/microsoft/typescript-go v0.0.0-
|
|
10
|
+
github.com/microsoft/typescript-go v0.0.0-20260610182825-7fc57c005063 // indirect
|
|
11
11
|
github.com/zeebo/xxh3 v1.1.0 // indirect
|
|
12
|
-
golang.org/x/sync v0.
|
|
13
|
-
golang.org/x/sys v0.
|
|
14
|
-
golang.org/x/text v0.
|
|
12
|
+
golang.org/x/sync v0.21.0 // indirect
|
|
13
|
+
golang.org/x/sys v0.46.0 // indirect
|
|
14
|
+
golang.org/x/text v0.38.0 // indirect
|
|
15
15
|
)
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Register the native strip transform and record its config-discovery inputs.
|
|
3
|
+
*
|
|
4
|
+
* The host supplies this module's absolute directory in `context.dirname`.
|
|
5
|
+
* Config discovery starts at `pluginConfigDir`, or the tsconfig directory when
|
|
6
|
+
* that anchor is absent. A nonblank string `plugin.configFile` records only its
|
|
7
|
+
* resolved path; otherwise discovery records all seven candidates at each
|
|
8
|
+
* ancestor through the first directory containing a file, or the volume root.
|
|
9
|
+
*
|
|
10
|
+
* Unknown plugin-entry keys throw so stale inline stripping options cannot
|
|
11
|
+
* silently select defaults. The Go driver validates configFile, rejects
|
|
12
|
+
* ambiguous discoveries and evaluates the selected config. This factory only
|
|
13
|
+
* fingerprints candidate state; it neither evaluates config nor rewrites ASTs.
|
|
14
|
+
*
|
|
15
|
+
* Each evaluation probes seven candidates per visited directory and hashes the
|
|
16
|
+
* bytes of readable files. An explicit path limits discovery to one candidate.
|
|
17
|
+
* Input arrays and maps are fresh per call; the factory retains no watchers,
|
|
18
|
+
* subprocesses or cross-call cache. Host reuse must validate the returned
|
|
19
|
+
* candidate observations, including absent files and physical targets. These
|
|
20
|
+
* observations describe descriptor evaluation, not complete native dependency
|
|
21
|
+
* analysis. This migration makes no measured performance improvement claim.
|
|
22
|
+
*
|
|
23
|
+
* @evidence contracts/common.md#principled-implementation
|
|
24
|
+
* The descriptor registers the Go driver before emit. Discovery observes
|
|
25
|
+
* every supported filename through the first directory with a candidate,
|
|
26
|
+
* including absent alternatives that can change native selection. Content
|
|
27
|
+
* digests and physical targets represent different causes of invalidation;
|
|
28
|
+
* null observations preserve read failures rather than inventing contents.
|
|
29
|
+
* Native evaluation owns config validation and the resulting transformation.
|
|
30
|
+
*
|
|
31
|
+
* @evidence contracts/common.md#clear-and-simple-design
|
|
32
|
+
* Registration returns one descriptor while private helpers own discovery,
|
|
33
|
+
* content observation and physical resolution. Context carries only host
|
|
34
|
+
* anchors and entry data; no option duplicates the native strip config.
|
|
35
|
+
*
|
|
36
|
+
* @evidence contracts/common.md#prohibited-implementation-shortcuts
|
|
37
|
+
* The package name, stage, accepted entry keys and candidate filenames are
|
|
38
|
+
* native contract values, not fixture answers. Discovery reads owned
|
|
39
|
+
* observations without foreign mutation or test-only branches.
|
|
40
|
+
*
|
|
41
|
+
* Shared native config evaluation uses public resolution hooks. When those
|
|
42
|
+
* hooks cannot cover resolution, it reports incomplete observations so the
|
|
43
|
+
* consumer withdraws reuse rather than patching a private resolver.
|
|
44
|
+
*
|
|
45
|
+
* @evidence contracts/common.md#meaningful-documentation
|
|
46
|
+
* Native JSDoc separates host anchoring, candidate observation, validation
|
|
47
|
+
* and native ownership into paragraphs, including error and absent-anchor
|
|
48
|
+
* behavior. Context and result comments explain the consuming watch and
|
|
49
|
+
* reuse protocol. The documentation skill's clear prose, paragraph and
|
|
50
|
+
* rationale guidance governs these comments. Member comments distinguish
|
|
51
|
+
* negative observations, directory markers and physical target changes.
|
|
52
|
+
*/
|
|
53
|
+
export default function createTtscStrip(context: TtscStripFactoryContext): TtscStripDescriptor;
|
|
54
|
+
/** Host fields consumed while constructing this descriptor. */
|
|
55
|
+
type TtscStripFactoryContext = {
|
|
56
|
+
/** Absolute directory of the loaded descriptor module. */
|
|
57
|
+
dirname: string;
|
|
58
|
+
/** Discovery anchor, including projects with generated wrapper tsconfigs. */
|
|
59
|
+
pluginConfigDir?: string;
|
|
60
|
+
/** Original plugin entry; unknown keys are rejected rather than ignored. */
|
|
61
|
+
plugin?: Record<string, unknown>;
|
|
62
|
+
/** Absolute tsconfig path, whose directory supplies the default anchor. */
|
|
63
|
+
tsconfig: string;
|
|
64
|
+
};
|
|
65
|
+
/** Candidate observations consumed by host watch and descriptor reuse. */
|
|
66
|
+
type TtscStripInputs = {
|
|
67
|
+
/** Content digest, directory marker digest, or null for a failed read. */
|
|
68
|
+
hashes: Record<string, string | null>;
|
|
69
|
+
/** Absolute candidate paths, including absent and directory candidates. */
|
|
70
|
+
inputs: string[];
|
|
71
|
+
/** Physical target of each candidate, or null when resolution fails. */
|
|
72
|
+
realpaths: Record<string, string | null>;
|
|
73
|
+
};
|
|
74
|
+
/** Registration of native source and the descriptor's observed inputs. */
|
|
75
|
+
type TtscStripDescriptor = {
|
|
76
|
+
/** The bundled driver host records actual writes and their physical sources. */
|
|
77
|
+
capabilities: {
|
|
78
|
+
emitProvenance: true;
|
|
79
|
+
};
|
|
80
|
+
/** Evaluation-time fingerprints used to validate descriptor reuse. */
|
|
81
|
+
hostInputHashes: TtscStripInputs["hashes"];
|
|
82
|
+
/** Physical targets that detect candidate symlink or junction changes. */
|
|
83
|
+
hostInputRealpaths: TtscStripInputs["realpaths"];
|
|
84
|
+
/** Candidate paths the host watches, including negative observations. */
|
|
85
|
+
hostInputs: TtscStripInputs["inputs"];
|
|
86
|
+
/** Package identity used in plugin registration and diagnostics. */
|
|
87
|
+
name: string;
|
|
88
|
+
/** Absolute Go driver directory compiled and linked by the host. */
|
|
89
|
+
source: string;
|
|
90
|
+
/** Source transformation runs before normal JavaScript emit. */
|
|
91
|
+
stage: "transform";
|
|
92
|
+
};
|
|
93
|
+
export {};
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.default = createTtscStrip;
|
|
7
|
+
const node_crypto_1 = __importDefault(require("node:crypto"));
|
|
8
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
9
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
10
|
+
/**
|
|
11
|
+
* Register the native strip transform and record its config-discovery inputs.
|
|
12
|
+
*
|
|
13
|
+
* The host supplies this module's absolute directory in `context.dirname`.
|
|
14
|
+
* Config discovery starts at `pluginConfigDir`, or the tsconfig directory when
|
|
15
|
+
* that anchor is absent. A nonblank string `plugin.configFile` records only its
|
|
16
|
+
* resolved path; otherwise discovery records all seven candidates at each
|
|
17
|
+
* ancestor through the first directory containing a file, or the volume root.
|
|
18
|
+
*
|
|
19
|
+
* Unknown plugin-entry keys throw so stale inline stripping options cannot
|
|
20
|
+
* silently select defaults. The Go driver validates configFile, rejects
|
|
21
|
+
* ambiguous discoveries and evaluates the selected config. This factory only
|
|
22
|
+
* fingerprints candidate state; it neither evaluates config nor rewrites ASTs.
|
|
23
|
+
*
|
|
24
|
+
* Each evaluation probes seven candidates per visited directory and hashes the
|
|
25
|
+
* bytes of readable files. An explicit path limits discovery to one candidate.
|
|
26
|
+
* Input arrays and maps are fresh per call; the factory retains no watchers,
|
|
27
|
+
* subprocesses or cross-call cache. Host reuse must validate the returned
|
|
28
|
+
* candidate observations, including absent files and physical targets. These
|
|
29
|
+
* observations describe descriptor evaluation, not complete native dependency
|
|
30
|
+
* analysis. This migration makes no measured performance improvement claim.
|
|
31
|
+
*
|
|
32
|
+
* @evidence contracts/common.md#principled-implementation
|
|
33
|
+
* The descriptor registers the Go driver before emit. Discovery observes
|
|
34
|
+
* every supported filename through the first directory with a candidate,
|
|
35
|
+
* including absent alternatives that can change native selection. Content
|
|
36
|
+
* digests and physical targets represent different causes of invalidation;
|
|
37
|
+
* null observations preserve read failures rather than inventing contents.
|
|
38
|
+
* Native evaluation owns config validation and the resulting transformation.
|
|
39
|
+
*
|
|
40
|
+
* @evidence contracts/common.md#clear-and-simple-design
|
|
41
|
+
* Registration returns one descriptor while private helpers own discovery,
|
|
42
|
+
* content observation and physical resolution. Context carries only host
|
|
43
|
+
* anchors and entry data; no option duplicates the native strip config.
|
|
44
|
+
*
|
|
45
|
+
* @evidence contracts/common.md#prohibited-implementation-shortcuts
|
|
46
|
+
* The package name, stage, accepted entry keys and candidate filenames are
|
|
47
|
+
* native contract values, not fixture answers. Discovery reads owned
|
|
48
|
+
* observations without foreign mutation or test-only branches.
|
|
49
|
+
*
|
|
50
|
+
* Shared native config evaluation uses public resolution hooks. When those
|
|
51
|
+
* hooks cannot cover resolution, it reports incomplete observations so the
|
|
52
|
+
* consumer withdraws reuse rather than patching a private resolver.
|
|
53
|
+
*
|
|
54
|
+
* @evidence contracts/common.md#meaningful-documentation
|
|
55
|
+
* Native JSDoc separates host anchoring, candidate observation, validation
|
|
56
|
+
* and native ownership into paragraphs, including error and absent-anchor
|
|
57
|
+
* behavior. Context and result comments explain the consuming watch and
|
|
58
|
+
* reuse protocol. The documentation skill's clear prose, paragraph and
|
|
59
|
+
* rationale guidance governs these comments. Member comments distinguish
|
|
60
|
+
* negative observations, directory markers and physical target changes.
|
|
61
|
+
*/
|
|
62
|
+
function createTtscStrip(context) {
|
|
63
|
+
const plugin = context && typeof context === "object" && context.plugin != null
|
|
64
|
+
? context.plugin
|
|
65
|
+
: {};
|
|
66
|
+
for (const key of Object.keys(plugin)) {
|
|
67
|
+
if (!ALLOWED_TSCONFIG_KEYS.has(key)) {
|
|
68
|
+
throw new Error(`@ttsc/strip: tsconfig plugin entry contains unsupported key ${JSON.stringify(key)}; ` +
|
|
69
|
+
`strip configuration must be supplied via a strip.config.* file ` +
|
|
70
|
+
`(use the "configFile" key to point at a custom path)`);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
const configInputs = stripConfigInputs(context);
|
|
74
|
+
return {
|
|
75
|
+
capabilities: { emitProvenance: true },
|
|
76
|
+
hostInputHashes: configInputs.hashes,
|
|
77
|
+
hostInputRealpaths: configInputs.realpaths,
|
|
78
|
+
hostInputs: configInputs.inputs,
|
|
79
|
+
name: "@ttsc/strip",
|
|
80
|
+
source: node_path_1.default.resolve(context.dirname, "..", "driver"),
|
|
81
|
+
stage: "transform",
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
// Accept only host-owned entry keys and the explicit package config path.
|
|
85
|
+
const ALLOWED_TSCONFIG_KEYS = new Set([
|
|
86
|
+
"configFile",
|
|
87
|
+
"enabled",
|
|
88
|
+
"name",
|
|
89
|
+
"stage",
|
|
90
|
+
"transform",
|
|
91
|
+
]);
|
|
92
|
+
const STRIP_CONFIG_FILENAMES = [
|
|
93
|
+
"strip.config.ts",
|
|
94
|
+
"strip.config.mts",
|
|
95
|
+
"strip.config.cts",
|
|
96
|
+
"strip.config.js",
|
|
97
|
+
"strip.config.mjs",
|
|
98
|
+
"strip.config.cjs",
|
|
99
|
+
"strip.config.json",
|
|
100
|
+
];
|
|
101
|
+
/** Observe discovery candidates without evaluating their exported config. */
|
|
102
|
+
function stripConfigInputs(context) {
|
|
103
|
+
const configFile = context.plugin?.configFile;
|
|
104
|
+
const base = node_path_1.default.resolve(context.pluginConfigDir ?? node_path_1.default.dirname(context.tsconfig));
|
|
105
|
+
if (typeof configFile === "string" && configFile.trim() !== "") {
|
|
106
|
+
const file = node_path_1.default.isAbsolute(configFile)
|
|
107
|
+
? node_path_1.default.resolve(configFile)
|
|
108
|
+
: node_path_1.default.resolve(base, configFile);
|
|
109
|
+
return {
|
|
110
|
+
hashes: { [file]: hostInputHash(file) },
|
|
111
|
+
inputs: [file],
|
|
112
|
+
realpaths: { [file]: hostInputRealpath(file) },
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
const inputs = [];
|
|
116
|
+
const hashes = {};
|
|
117
|
+
const realpaths = {};
|
|
118
|
+
for (let directory = base;; directory = node_path_1.default.dirname(directory)) {
|
|
119
|
+
const candidates = STRIP_CONFIG_FILENAMES.map((name) => node_path_1.default.join(directory, name));
|
|
120
|
+
inputs.push(...candidates);
|
|
121
|
+
for (const candidate of candidates) {
|
|
122
|
+
hashes[candidate] = hostInputHash(candidate);
|
|
123
|
+
realpaths[candidate] = hostInputRealpath(candidate);
|
|
124
|
+
}
|
|
125
|
+
if (candidates.some(configCandidateExists))
|
|
126
|
+
break;
|
|
127
|
+
const parent = node_path_1.default.dirname(directory);
|
|
128
|
+
if (parent === directory)
|
|
129
|
+
break;
|
|
130
|
+
}
|
|
131
|
+
return { hashes, inputs, realpaths };
|
|
132
|
+
}
|
|
133
|
+
/** Resolve the candidate's physical target, leaving failures explicit as null. */
|
|
134
|
+
function hostInputRealpath(file) {
|
|
135
|
+
try {
|
|
136
|
+
return node_fs_1.default.realpathSync.native(file);
|
|
137
|
+
}
|
|
138
|
+
catch {
|
|
139
|
+
return null;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
/** Hash the exact candidate state observed before discovery selects a file. */
|
|
143
|
+
function hostInputHash(file) {
|
|
144
|
+
try {
|
|
145
|
+
if (node_fs_1.default.statSync(file).isDirectory()) {
|
|
146
|
+
return node_crypto_1.default
|
|
147
|
+
.createHash("sha256")
|
|
148
|
+
.update("ttsc:host-input:directory\0")
|
|
149
|
+
.digest("hex");
|
|
150
|
+
}
|
|
151
|
+
return node_crypto_1.default
|
|
152
|
+
.createHash("sha256")
|
|
153
|
+
.update(node_fs_1.default.readFileSync(file))
|
|
154
|
+
.digest("hex");
|
|
155
|
+
}
|
|
156
|
+
catch {
|
|
157
|
+
return null;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
/** Match the native discovery rule: a directory is never a config file. */
|
|
161
|
+
function configCandidateExists(file) {
|
|
162
|
+
try {
|
|
163
|
+
return !node_fs_1.default.statSync(file).isDirectory();
|
|
164
|
+
}
|
|
165
|
+
catch {
|
|
166
|
+
return false;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
//# sourceMappingURL=createTtscStrip.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createTtscStrip.js","sourceRoot":"","sources":["../src/createTtscStrip.ts"],"names":[],"mappings":";;;;;;AAAA,8DAAiC;AACjC,sDAAyB;AACzB,0DAA6B;AAE7B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmDG;AACH,yBACE,OAAgC;IAEhC,MAAM,MAAM,GACV,OAAO,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,CAAC,MAAM,IAAI,IAAI;QAC9D,CAAC,CAAC,OAAO,CAAC,MAAM;QAChB,CAAC,CAAC,EAAE,CAAC;IACT,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;QACtC,IAAI,CAAC,qBAAqB,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;YACpC,MAAM,IAAI,KAAK,CACb,+DAA+D,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI;gBACpF,iEAAiE;gBACjE,sDAAsD,CACzD,CAAC;QACJ,CAAC;IACH,CAAC;IACD,MAAM,YAAY,GAAG,iBAAiB,CAAC,OAAO,CAAC,CAAC;IAChD,OAAO;QACL,YAAY,EAAE,EAAE,cAAc,EAAE,IAAI,EAAE;QACtC,eAAe,EAAE,YAAY,CAAC,MAAM;QACpC,kBAAkB,EAAE,YAAY,C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,OAAO,qBAAM;iBACV,UAAU,CAAC,QAAQ,CAAC;iBACpB,MAAM,CAAC,6BAA6B,CAAC;iBACrC,MAAM,CAAC,KAAK,CAAC,CAAC;QACnB,CAAC;QACD,OAAO,qBAAM;aACV,UAAU,CAAC,QAAQ,CAAC;aACpB,MAAM,CAAC,iBAAE,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;aAC7B,MAAM,CAAC,KAAK,CAAC,CAAC;IACnB,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED,2EAA2E;AAC3E,SAAS,qBAAqB,CAAC,IAAY;IACzC,IAAI,CAAC;QACH,OAAO,CAAC,iBAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,CAAC;IAC1C,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC"}
|
package/lib/index.d.ts
ADDED
package/lib/index.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
|
+
};
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.default = void 0;
|
|
21
|
+
__exportStar(require("./structures/index"), exports);
|
|
22
|
+
var createTtscStrip_1 = require("./createTtscStrip");
|
|
23
|
+
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(createTtscStrip_1).default; } });
|
|
24
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,qDAAmC;AAEnC,qDAA4C;AAAnC,2HAAA,OAAO,OAAA"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configure intentional statement removal in a standalone strip.config file.
|
|
3
|
+
*
|
|
4
|
+
* Omitting both keys selects calls `console.log`, `console.debug`, `assert.*`
|
|
5
|
+
* and statement `debugger`. Supplying either key replaces both default lists;
|
|
6
|
+
* an omitted counterpart or an empty array removes nothing in that category.
|
|
7
|
+
* The native loader requires an object and validates each configured pattern.
|
|
8
|
+
*
|
|
9
|
+
* Stripping deletes the whole statement, including argument evaluation. Use
|
|
10
|
+
* this only for calls whose removal is intended to change runtime behavior.
|
|
11
|
+
*
|
|
12
|
+
* @evidence contracts/common.md#principled-implementation
|
|
13
|
+
* Optional readonly lists represent omission separately from an empty
|
|
14
|
+
* removal list. The native parser applies defaults only when both keys are
|
|
15
|
+
* absent and validates syntax that TypeScript string types cannot constrain.
|
|
16
|
+
* The representation intentionally permits input construction while runtime
|
|
17
|
+
* validation rejects empty dotted segments, a wildcard without a prefix,
|
|
18
|
+
* stars outside a final wildcard segment and unsupported statement names.
|
|
19
|
+
* Other nonempty spellings may be accepted even when they cannot match a
|
|
20
|
+
* dotted identifier in source.
|
|
21
|
+
*
|
|
22
|
+
* @evidence contracts/common.md#clear-and-simple-design
|
|
23
|
+
* Two independent lists group call patterns and statement kinds by the
|
|
24
|
+
* parser responsibility they configure. Filesystem discovery remains a host
|
|
25
|
+
* entry concern instead of becoming another strip behavior option.
|
|
26
|
+
*
|
|
27
|
+
* @evidence contracts/common.md#prohibited-implementation-shortcuts
|
|
28
|
+
* The whole type is data-only, with no foreign mutation, fixture branch,
|
|
29
|
+
* test-only behavior or alternate runtime implementation.
|
|
30
|
+
*
|
|
31
|
+
* @evidence contracts/common.md#meaningful-documentation
|
|
32
|
+
* Interface and member JSDoc distinguish both-key defaults from one-key
|
|
33
|
+
* replacement, explain exact and deeper prefix matching and its negative
|
|
34
|
+
* boundary, identify rejected shapes and debugger-only statements, and warn
|
|
35
|
+
* that whole-statement removal deletes argument evaluation. Separate native
|
|
36
|
+
* paragraphs follow the documentation skill's clear prose and rationale
|
|
37
|
+
* guidance; field documentation remains alongside the fields while the type
|
|
38
|
+
* owns the checklist answer.
|
|
39
|
+
*/
|
|
40
|
+
export interface ITtscStripConfig {
|
|
41
|
+
/**
|
|
42
|
+
* Dotted callee patterns for whole call-expression statements to remove.
|
|
43
|
+
*
|
|
44
|
+
* An exact name matches that dotted identifier chain. A trailing `.*` matches
|
|
45
|
+
* one or more further property segments, so `assert.*` includes
|
|
46
|
+
* `assert.equal()` and `assert.strict.equal()` but excludes `assert()`.
|
|
47
|
+
* Computed access and calls embedded in other expressions remain untouched.
|
|
48
|
+
* Empty or whitespace-only entries, empty dotted segments, a bare `*` and
|
|
49
|
+
* stars outside a final `.*` are rejected. Other nonempty spellings may be
|
|
50
|
+
* accepted without matching any dotted identifier. A matched statement's
|
|
51
|
+
* arguments are also removed.
|
|
52
|
+
*/
|
|
53
|
+
calls?: readonly string[];
|
|
54
|
+
/**
|
|
55
|
+
* Bare statement kinds to remove; only `debugger` is supported.
|
|
56
|
+
*
|
|
57
|
+
* Other names and empty or whitespace-only entries are rejected. An omitted
|
|
58
|
+
* list removes no statement kind when `calls` is supplied; omitting both
|
|
59
|
+
* fields instead activates the interface's documented defaults.
|
|
60
|
+
*/
|
|
61
|
+
statements?: readonly string[];
|
|
62
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ITtscStripConfig.js","sourceRoot":"","sources":["../../src/structures/ITtscStripConfig.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./ITtscStripConfig";
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./ITtscStripConfig"), exports);
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/structures/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,qDAAmC"}
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ttsc/strip",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.31.0",
|
|
4
4
|
"description": "First-party ttsc plugin that removes configured calls and statements from emitted JavaScript.",
|
|
5
|
-
"main": "
|
|
6
|
-
"types": "
|
|
5
|
+
"main": "lib/index.js",
|
|
6
|
+
"types": "lib/index.d.ts",
|
|
7
7
|
"exports": {
|
|
8
8
|
".": {
|
|
9
|
-
"types": "./
|
|
10
|
-
"default": "./
|
|
9
|
+
"types": "./lib/index.d.ts",
|
|
10
|
+
"default": "./lib/index.js"
|
|
11
11
|
},
|
|
12
12
|
"./package.json": "./package.json"
|
|
13
13
|
},
|
|
@@ -27,12 +27,18 @@
|
|
|
27
27
|
"README.md",
|
|
28
28
|
"driver/config.go",
|
|
29
29
|
"driver/strip.go",
|
|
30
|
-
"
|
|
31
|
-
"src
|
|
30
|
+
"lib",
|
|
31
|
+
"src",
|
|
32
32
|
"go.mod",
|
|
33
33
|
"plugin/main.go",
|
|
34
34
|
"plugin/strip.go"
|
|
35
35
|
],
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@wrtnlabs/evidence": "^0.3.1",
|
|
38
|
+
"@types/node": "^25.3.0",
|
|
39
|
+
"rimraf": "^6.1.2",
|
|
40
|
+
"typescript": "^7.0.2"
|
|
41
|
+
},
|
|
36
42
|
"repository": {
|
|
37
43
|
"type": "git",
|
|
38
44
|
"url": "https://github.com/samchon/ttsc"
|
|
@@ -42,5 +48,9 @@
|
|
|
42
48
|
"bugs": {
|
|
43
49
|
"url": "https://github.com/samchon/ttsc/issues"
|
|
44
50
|
},
|
|
45
|
-
"homepage": "https://ttsc.dev"
|
|
51
|
+
"homepage": "https://ttsc.dev",
|
|
52
|
+
"scripts": {
|
|
53
|
+
"build": "rimraf lib && tsc",
|
|
54
|
+
"evidence": "evidence"
|
|
55
|
+
}
|
|
46
56
|
}
|