@ttsc/strip 0.30.3 → 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/plugin/main.go
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
package main
|
|
3
3
|
|
|
4
4
|
import (
|
|
5
|
-
"fmt"
|
|
6
5
|
"os"
|
|
7
6
|
|
|
8
7
|
"github.com/samchon/ttsc/packages/ttsc/utility"
|
|
@@ -10,27 +9,28 @@ import (
|
|
|
10
9
|
|
|
11
10
|
const version = "0.0.1"
|
|
12
11
|
|
|
12
|
+
// main exits the standalone process with its command dispatch status.
|
|
13
|
+
//
|
|
14
|
+
// These review grounds cover this private operation and its actual callees.
|
|
15
|
+
// Go Evidence does not admit private declaration acknowledgment tags.
|
|
16
|
+
//
|
|
17
|
+
// Common: Principled implementation: os.Args excludes the executable name and os.Exit propagates the actual run status to the process consumer.
|
|
18
|
+
// Common: Clear and simple design: The entrypoint binds process lifetime while run owns identity and stream delegation.
|
|
19
|
+
// Common: Prohibited implementation shortcuts: The process uses the real command return status without rewriting failures or bypassing package registration.
|
|
20
|
+
// Common: Meaningful documentation: The native comment names process status propagation separately from these native review grounds.
|
|
21
|
+
// Portability: OS-neutral implementation: Go's os package supplies native argv and process exit semantics without host-specific command quoting.
|
|
13
22
|
func main() {
|
|
14
23
|
os.Exit(run(os.Args[1:]))
|
|
15
24
|
}
|
|
16
25
|
|
|
26
|
+
// run supplies this standalone plugin's identity and process streams to the
|
|
27
|
+
// shared production utility dispatch; linked registration remains in init.
|
|
28
|
+
//
|
|
29
|
+
// Common: Principled implementation: The package identity and unchanged version constant reach the shared actual command owner with original argv and process writers.
|
|
30
|
+
// Common: Clear and simple design: One delegation leaves command semantics with utility.RunCommandWithIO and package registration with the sibling init import.
|
|
31
|
+
// Common: Prohibited implementation shortcuts: Production execution uses the same dispatch as direct units and retains the real host for build, transform and check.
|
|
32
|
+
// Common: Meaningful documentation: Native prose identifies identity, process stream binding and unchanged linked registration separately from these native review grounds.
|
|
33
|
+
// Portability: OS-neutral implementation: os supplies the native process streams and argv values without a shell or path reconstruction.
|
|
17
34
|
func run(args []string) int {
|
|
18
|
-
|
|
19
|
-
fmt.Fprintln(os.Stderr, "@ttsc/strip: command required (expected build|transform|check|version)")
|
|
20
|
-
return 2
|
|
21
|
-
}
|
|
22
|
-
switch args[0] {
|
|
23
|
-
case "-v", "--version", "version":
|
|
24
|
-
fmt.Fprintf(os.Stdout, "@ttsc/strip %s\n", version)
|
|
25
|
-
return 0
|
|
26
|
-
case "build":
|
|
27
|
-
return utility.RunBuild(args[1:])
|
|
28
|
-
case "transform":
|
|
29
|
-
return utility.RunTransform(args[1:])
|
|
30
|
-
case "check":
|
|
31
|
-
return utility.RunCheck(args[1:])
|
|
32
|
-
default:
|
|
33
|
-
fmt.Fprintf(os.Stderr, "@ttsc/strip: unknown command %q\n", args[0])
|
|
34
|
-
return 2
|
|
35
|
-
}
|
|
35
|
+
return utility.RunCommandWithIO("@ttsc/strip", version, args, os.Stdout, os.Stderr)
|
|
36
36
|
}
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import crypto from "node:crypto";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Register the native strip transform and record its config-discovery inputs.
|
|
7
|
+
*
|
|
8
|
+
* The host supplies this module's absolute directory in `context.dirname`.
|
|
9
|
+
* Config discovery starts at `pluginConfigDir`, or the tsconfig directory when
|
|
10
|
+
* that anchor is absent. A nonblank string `plugin.configFile` records only its
|
|
11
|
+
* resolved path; otherwise discovery records all seven candidates at each
|
|
12
|
+
* ancestor through the first directory containing a file, or the volume root.
|
|
13
|
+
*
|
|
14
|
+
* Unknown plugin-entry keys throw so stale inline stripping options cannot
|
|
15
|
+
* silently select defaults. The Go driver validates configFile, rejects
|
|
16
|
+
* ambiguous discoveries and evaluates the selected config. This factory only
|
|
17
|
+
* fingerprints candidate state; it neither evaluates config nor rewrites ASTs.
|
|
18
|
+
*
|
|
19
|
+
* Each evaluation probes seven candidates per visited directory and hashes the
|
|
20
|
+
* bytes of readable files. An explicit path limits discovery to one candidate.
|
|
21
|
+
* Input arrays and maps are fresh per call; the factory retains no watchers,
|
|
22
|
+
* subprocesses or cross-call cache. Host reuse must validate the returned
|
|
23
|
+
* candidate observations, including absent files and physical targets. These
|
|
24
|
+
* observations describe descriptor evaluation, not complete native dependency
|
|
25
|
+
* analysis. This migration makes no measured performance improvement claim.
|
|
26
|
+
*
|
|
27
|
+
* @evidence contracts/common.md#principled-implementation
|
|
28
|
+
* The descriptor registers the Go driver before emit. Discovery observes
|
|
29
|
+
* every supported filename through the first directory with a candidate,
|
|
30
|
+
* including absent alternatives that can change native selection. Content
|
|
31
|
+
* digests and physical targets represent different causes of invalidation;
|
|
32
|
+
* null observations preserve read failures rather than inventing contents.
|
|
33
|
+
* Native evaluation owns config validation and the resulting transformation.
|
|
34
|
+
*
|
|
35
|
+
* @evidence contracts/common.md#clear-and-simple-design
|
|
36
|
+
* Registration returns one descriptor while private helpers own discovery,
|
|
37
|
+
* content observation and physical resolution. Context carries only host
|
|
38
|
+
* anchors and entry data; no option duplicates the native strip config.
|
|
39
|
+
*
|
|
40
|
+
* @evidence contracts/common.md#prohibited-implementation-shortcuts
|
|
41
|
+
* The package name, stage, accepted entry keys and candidate filenames are
|
|
42
|
+
* native contract values, not fixture answers. Discovery reads owned
|
|
43
|
+
* observations without foreign mutation or test-only branches.
|
|
44
|
+
*
|
|
45
|
+
* Shared native config evaluation uses public resolution hooks. When those
|
|
46
|
+
* hooks cannot cover resolution, it reports incomplete observations so the
|
|
47
|
+
* consumer withdraws reuse rather than patching a private resolver.
|
|
48
|
+
*
|
|
49
|
+
* @evidence contracts/common.md#meaningful-documentation
|
|
50
|
+
* Native JSDoc separates host anchoring, candidate observation, validation
|
|
51
|
+
* and native ownership into paragraphs, including error and absent-anchor
|
|
52
|
+
* behavior. Context and result comments explain the consuming watch and
|
|
53
|
+
* reuse protocol. The documentation skill's clear prose, paragraph and
|
|
54
|
+
* rationale guidance governs these comments. Member comments distinguish
|
|
55
|
+
* negative observations, directory markers and physical target changes.
|
|
56
|
+
*/
|
|
57
|
+
export default function createTtscStrip(
|
|
58
|
+
context: TtscStripFactoryContext,
|
|
59
|
+
): TtscStripDescriptor {
|
|
60
|
+
const plugin =
|
|
61
|
+
context && typeof context === "object" && context.plugin != null
|
|
62
|
+
? context.plugin
|
|
63
|
+
: {};
|
|
64
|
+
for (const key of Object.keys(plugin)) {
|
|
65
|
+
if (!ALLOWED_TSCONFIG_KEYS.has(key)) {
|
|
66
|
+
throw new Error(
|
|
67
|
+
`@ttsc/strip: tsconfig plugin entry contains unsupported key ${JSON.stringify(key)}; ` +
|
|
68
|
+
`strip configuration must be supplied via a strip.config.* file ` +
|
|
69
|
+
`(use the "configFile" key to point at a custom path)`,
|
|
70
|
+
);
|
|
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: path.resolve(context.dirname, "..", "driver"),
|
|
81
|
+
stage: "transform",
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** Host fields consumed while constructing this descriptor. */
|
|
86
|
+
type TtscStripFactoryContext = {
|
|
87
|
+
/** Absolute directory of the loaded descriptor module. */
|
|
88
|
+
dirname: string;
|
|
89
|
+
|
|
90
|
+
/** Discovery anchor, including projects with generated wrapper tsconfigs. */
|
|
91
|
+
pluginConfigDir?: string;
|
|
92
|
+
|
|
93
|
+
/** Original plugin entry; unknown keys are rejected rather than ignored. */
|
|
94
|
+
plugin?: Record<string, unknown>;
|
|
95
|
+
|
|
96
|
+
/** Absolute tsconfig path, whose directory supplies the default anchor. */
|
|
97
|
+
tsconfig: string;
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
/** Candidate observations consumed by host watch and descriptor reuse. */
|
|
101
|
+
type TtscStripInputs = {
|
|
102
|
+
/** Content digest, directory marker digest, or null for a failed read. */
|
|
103
|
+
hashes: Record<string, string | null>;
|
|
104
|
+
|
|
105
|
+
/** Absolute candidate paths, including absent and directory candidates. */
|
|
106
|
+
inputs: string[];
|
|
107
|
+
|
|
108
|
+
/** Physical target of each candidate, or null when resolution fails. */
|
|
109
|
+
realpaths: Record<string, string | null>;
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
/** Registration of native source and the descriptor's observed inputs. */
|
|
113
|
+
type TtscStripDescriptor = {
|
|
114
|
+
/** The bundled driver host records actual writes and their physical sources. */
|
|
115
|
+
capabilities: { emitProvenance: true };
|
|
116
|
+
|
|
117
|
+
/** Evaluation-time fingerprints used to validate descriptor reuse. */
|
|
118
|
+
hostInputHashes: TtscStripInputs["hashes"];
|
|
119
|
+
|
|
120
|
+
/** Physical targets that detect candidate symlink or junction changes. */
|
|
121
|
+
hostInputRealpaths: TtscStripInputs["realpaths"];
|
|
122
|
+
|
|
123
|
+
/** Candidate paths the host watches, including negative observations. */
|
|
124
|
+
hostInputs: TtscStripInputs["inputs"];
|
|
125
|
+
|
|
126
|
+
/** Package identity used in plugin registration and diagnostics. */
|
|
127
|
+
name: string;
|
|
128
|
+
|
|
129
|
+
/** Absolute Go driver directory compiled and linked by the host. */
|
|
130
|
+
source: string;
|
|
131
|
+
|
|
132
|
+
/** Source transformation runs before normal JavaScript emit. */
|
|
133
|
+
stage: "transform";
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
// Accept only host-owned entry keys and the explicit package config path.
|
|
137
|
+
const ALLOWED_TSCONFIG_KEYS = new Set([
|
|
138
|
+
"configFile",
|
|
139
|
+
"enabled",
|
|
140
|
+
"name",
|
|
141
|
+
"stage",
|
|
142
|
+
"transform",
|
|
143
|
+
]);
|
|
144
|
+
|
|
145
|
+
const STRIP_CONFIG_FILENAMES = [
|
|
146
|
+
"strip.config.ts",
|
|
147
|
+
"strip.config.mts",
|
|
148
|
+
"strip.config.cts",
|
|
149
|
+
"strip.config.js",
|
|
150
|
+
"strip.config.mjs",
|
|
151
|
+
"strip.config.cjs",
|
|
152
|
+
"strip.config.json",
|
|
153
|
+
];
|
|
154
|
+
|
|
155
|
+
/** Observe discovery candidates without evaluating their exported config. */
|
|
156
|
+
function stripConfigInputs(context: TtscStripFactoryContext): TtscStripInputs {
|
|
157
|
+
const configFile = context.plugin?.configFile;
|
|
158
|
+
const base = path.resolve(
|
|
159
|
+
context.pluginConfigDir ?? path.dirname(context.tsconfig),
|
|
160
|
+
);
|
|
161
|
+
if (typeof configFile === "string" && configFile.trim() !== "") {
|
|
162
|
+
const file = path.isAbsolute(configFile)
|
|
163
|
+
? path.resolve(configFile)
|
|
164
|
+
: path.resolve(base, configFile);
|
|
165
|
+
return {
|
|
166
|
+
hashes: { [file]: hostInputHash(file) },
|
|
167
|
+
inputs: [file],
|
|
168
|
+
realpaths: { [file]: hostInputRealpath(file) },
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
const inputs: string[] = [];
|
|
172
|
+
const hashes: Record<string, string | null> = {};
|
|
173
|
+
const realpaths: Record<string, string | null> = {};
|
|
174
|
+
for (let directory = base; ; directory = path.dirname(directory)) {
|
|
175
|
+
const candidates = STRIP_CONFIG_FILENAMES.map((name) =>
|
|
176
|
+
path.join(directory, name),
|
|
177
|
+
);
|
|
178
|
+
inputs.push(...candidates);
|
|
179
|
+
for (const candidate of candidates) {
|
|
180
|
+
hashes[candidate] = hostInputHash(candidate);
|
|
181
|
+
realpaths[candidate] = hostInputRealpath(candidate);
|
|
182
|
+
}
|
|
183
|
+
if (candidates.some(configCandidateExists)) break;
|
|
184
|
+
const parent = path.dirname(directory);
|
|
185
|
+
if (parent === directory) break;
|
|
186
|
+
}
|
|
187
|
+
return { hashes, inputs, realpaths };
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/** Resolve the candidate's physical target, leaving failures explicit as null. */
|
|
191
|
+
function hostInputRealpath(file: string): string | null {
|
|
192
|
+
try {
|
|
193
|
+
return fs.realpathSync.native(file);
|
|
194
|
+
} catch {
|
|
195
|
+
return null;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/** Hash the exact candidate state observed before discovery selects a file. */
|
|
200
|
+
function hostInputHash(file: string): string | null {
|
|
201
|
+
try {
|
|
202
|
+
if (fs.statSync(file).isDirectory()) {
|
|
203
|
+
return crypto
|
|
204
|
+
.createHash("sha256")
|
|
205
|
+
.update("ttsc:host-input:directory\0")
|
|
206
|
+
.digest("hex");
|
|
207
|
+
}
|
|
208
|
+
return crypto
|
|
209
|
+
.createHash("sha256")
|
|
210
|
+
.update(fs.readFileSync(file))
|
|
211
|
+
.digest("hex");
|
|
212
|
+
} catch {
|
|
213
|
+
return null;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/** Match the native discovery rule: a directory is never a config file. */
|
|
218
|
+
function configCandidateExists(file: string): boolean {
|
|
219
|
+
try {
|
|
220
|
+
return !fs.statSync(file).isDirectory();
|
|
221
|
+
} catch {
|
|
222
|
+
return false;
|
|
223
|
+
}
|
|
224
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
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
|
+
/**
|
|
56
|
+
* Bare statement kinds to remove; only `debugger` is supported.
|
|
57
|
+
*
|
|
58
|
+
* Other names and empty or whitespace-only entries are rejected. An omitted
|
|
59
|
+
* list removes no statement kind when `calls` is supplied; omitting both
|
|
60
|
+
* fields instead activates the interface's documented defaults.
|
|
61
|
+
*/
|
|
62
|
+
statements?: readonly string[];
|
|
63
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./ITtscStripConfig";
|
package/src/index.cjs
DELETED
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
"use strict";
|
|
3
|
-
|
|
4
|
-
const fs = require("node:fs");
|
|
5
|
-
const crypto = require("node:crypto");
|
|
6
|
-
const path = require("node:path");
|
|
7
|
-
|
|
8
|
-
// Keys from the tsconfig plugin entry that @ttsc/strip accepts. All other keys
|
|
9
|
-
// are rejected so that stale inline options (calls, statements) surface as a
|
|
10
|
-
// clear error rather than silently falling back to defaults.
|
|
11
|
-
const ALLOWED_TSCONFIG_KEYS = new Set([
|
|
12
|
-
"configFile",
|
|
13
|
-
"enabled",
|
|
14
|
-
"name",
|
|
15
|
-
"stage",
|
|
16
|
-
"transform",
|
|
17
|
-
]);
|
|
18
|
-
|
|
19
|
-
module.exports = function createTtscStrip(context) {
|
|
20
|
-
const plugin =
|
|
21
|
-
context && typeof context === "object" && context.plugin != null
|
|
22
|
-
? context.plugin
|
|
23
|
-
: {};
|
|
24
|
-
for (const key of Object.keys(plugin)) {
|
|
25
|
-
if (!ALLOWED_TSCONFIG_KEYS.has(key)) {
|
|
26
|
-
throw new Error(
|
|
27
|
-
`@ttsc/strip: tsconfig plugin entry contains unsupported key ${JSON.stringify(key)}; ` +
|
|
28
|
-
`strip configuration must be supplied via a strip.config.* file ` +
|
|
29
|
-
`(use the "configFile" key to point at a custom path)`,
|
|
30
|
-
);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
const configInputs = stripConfigInputs(context);
|
|
34
|
-
return {
|
|
35
|
-
hostInputHashes: configInputs.hashes,
|
|
36
|
-
hostInputRealpaths: configInputs.realpaths,
|
|
37
|
-
hostInputs: configInputs.inputs,
|
|
38
|
-
name: "@ttsc/strip",
|
|
39
|
-
// `context.dirname` is this descriptor's own directory in every load mode —
|
|
40
|
-
// the ESM-safe replacement for `__dirname`.
|
|
41
|
-
source: path.resolve(context.dirname, "..", "driver"),
|
|
42
|
-
stage: "transform",
|
|
43
|
-
};
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
const STRIP_CONFIG_FILENAMES = [
|
|
47
|
-
"strip.config.ts",
|
|
48
|
-
"strip.config.mts",
|
|
49
|
-
"strip.config.cts",
|
|
50
|
-
"strip.config.js",
|
|
51
|
-
"strip.config.mjs",
|
|
52
|
-
"strip.config.cjs",
|
|
53
|
-
"strip.config.json",
|
|
54
|
-
];
|
|
55
|
-
|
|
56
|
-
function stripConfigInputs(context) {
|
|
57
|
-
const configFile = context.plugin?.configFile;
|
|
58
|
-
const base = path.resolve(
|
|
59
|
-
context.pluginConfigDir ?? path.dirname(context.tsconfig),
|
|
60
|
-
);
|
|
61
|
-
if (typeof configFile === "string" && configFile.trim() !== "") {
|
|
62
|
-
const file = path.isAbsolute(configFile)
|
|
63
|
-
? path.resolve(configFile)
|
|
64
|
-
: path.resolve(base, configFile);
|
|
65
|
-
return {
|
|
66
|
-
hashes: { [file]: hostInputHash(file) },
|
|
67
|
-
inputs: [file],
|
|
68
|
-
realpaths: { [file]: hostInputRealpath(file) },
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
const inputs = [];
|
|
72
|
-
const hashes = {};
|
|
73
|
-
const realpaths = {};
|
|
74
|
-
for (let directory = base; ; directory = path.dirname(directory)) {
|
|
75
|
-
const candidates = STRIP_CONFIG_FILENAMES.map((name) =>
|
|
76
|
-
path.join(directory, name),
|
|
77
|
-
);
|
|
78
|
-
inputs.push(...candidates);
|
|
79
|
-
for (const candidate of candidates) {
|
|
80
|
-
hashes[candidate] = hostInputHash(candidate);
|
|
81
|
-
realpaths[candidate] = hostInputRealpath(candidate);
|
|
82
|
-
}
|
|
83
|
-
if (candidates.some(configCandidateExists)) break;
|
|
84
|
-
const parent = path.dirname(directory);
|
|
85
|
-
if (parent === directory) break;
|
|
86
|
-
}
|
|
87
|
-
return { hashes, inputs, realpaths };
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
function hostInputRealpath(file) {
|
|
91
|
-
try {
|
|
92
|
-
return fs.realpathSync.native(file);
|
|
93
|
-
} catch {
|
|
94
|
-
return null;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/** Hash the exact candidate state observed before discovery selects a file. */
|
|
99
|
-
function hostInputHash(file) {
|
|
100
|
-
try {
|
|
101
|
-
if (fs.statSync(file).isDirectory()) {
|
|
102
|
-
return crypto
|
|
103
|
-
.createHash("sha256")
|
|
104
|
-
.update("ttsc:host-input:directory\0")
|
|
105
|
-
.digest("hex");
|
|
106
|
-
}
|
|
107
|
-
return crypto
|
|
108
|
-
.createHash("sha256")
|
|
109
|
-
.update(fs.readFileSync(file))
|
|
110
|
-
.digest("hex");
|
|
111
|
-
} catch {
|
|
112
|
-
return null;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
/** Match the native discovery rule: a directory is never a config file. */
|
|
117
|
-
function configCandidateExists(file) {
|
|
118
|
-
try {
|
|
119
|
-
return !fs.statSync(file).isDirectory();
|
|
120
|
-
} catch {
|
|
121
|
-
return false;
|
|
122
|
-
}
|
|
123
|
-
}
|
package/src/index.d.ts
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Plugin descriptor factory consumed by ttsc's package discovery.
|
|
3
|
-
*
|
|
4
|
-
* `@ttsc/strip` is configured through a `strip.config.*` file, not through
|
|
5
|
-
* inline plugin options. The factory reads only `context.dirname` to locate its
|
|
6
|
-
* own Go `source` (the load-mode-independent replacement for `__dirname`) and
|
|
7
|
-
* returns the native descriptor.
|
|
8
|
-
*
|
|
9
|
-
* @internal
|
|
10
|
-
*/
|
|
11
|
-
declare function createTtscStrip(context: {
|
|
12
|
-
/**
|
|
13
|
-
* Absolute directory of this descriptor module; the Go `source` resolves from
|
|
14
|
-
* it.
|
|
15
|
-
*/
|
|
16
|
-
dirname: string;
|
|
17
|
-
/** Host-declared anchor for implicit strip config discovery. */
|
|
18
|
-
pluginConfigDir?: string;
|
|
19
|
-
/** Original tsconfig plugin entry, validated for unsupported keys. */
|
|
20
|
-
plugin?: Record<string, unknown>;
|
|
21
|
-
/** Absolute resolved tsconfig path. */
|
|
22
|
-
tsconfig: string;
|
|
23
|
-
}): {
|
|
24
|
-
hostInputHashes: Record<string, string | null>;
|
|
25
|
-
hostInputRealpaths: Record<string, string | null>;
|
|
26
|
-
hostInputs: string[];
|
|
27
|
-
name: string;
|
|
28
|
-
source: string;
|
|
29
|
-
stage: "transform";
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
declare namespace createTtscStrip {
|
|
33
|
-
/**
|
|
34
|
-
* Standalone `strip.config.{ts,cts,mts,js,cjs,mjs,json}` file shape consumed
|
|
35
|
-
* by `@ttsc/strip`.
|
|
36
|
-
*
|
|
37
|
-
* Both keys are optional. The built-in defaults (`calls: ["console.log",
|
|
38
|
-
* "console.debug", "assert.*"]`, `statements: ["debugger"]`) apply only when
|
|
39
|
-
* _both_ keys are omitted; declaring either key replaces both defaults with
|
|
40
|
-
* exactly what the file lists.
|
|
41
|
-
*/
|
|
42
|
-
export interface ITtscStripConfig {
|
|
43
|
-
/**
|
|
44
|
-
* Statement-level call patterns to remove, written as dotted names. A
|
|
45
|
-
* trailing `.*` wildcard matches any final property — e.g. `"assert.*"`
|
|
46
|
-
* matches `assert.equal`, `assert.deepStrictEqual`, …
|
|
47
|
-
*/
|
|
48
|
-
calls?: readonly string[];
|
|
49
|
-
|
|
50
|
-
/** Bare statement kinds to remove. Currently only `"debugger"` is supported. */
|
|
51
|
-
statements?: readonly string[];
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export = createTtscStrip;
|