@mnemonik/shared 7.141.1 → 7.141.3
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/dist/sourceRedaction.d.ts.map +1 -1
- package/dist/sourceRedaction.js +42 -20
- package/dist/sourceRedaction.js.map +1 -1
- package/package.json +1 -1
- package/scripts/vendor-grammars.ts +60 -2
- package/src/sourceRedaction.ts +59 -20
- package/wasm/tsx.wasm +0 -0
- package/wasm/typescript.wasm +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sourceRedaction.d.ts","sourceRoot":"","sources":["../src/sourceRedaction.ts"],"names":[],"mappings":"AAgBA,sGAAsG;AACtG,wBAAsB,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,
|
|
1
|
+
{"version":3,"file":"sourceRedaction.d.ts","sourceRoot":"","sources":["../src/sourceRedaction.ts"],"names":[],"mappings":"AAgBA,sGAAsG;AACtG,wBAAsB,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CA+BxF"}
|
package/dist/sourceRedaction.js
CHANGED
|
@@ -16,7 +16,9 @@ export async function scrubSourceSecrets(text, filePath) {
|
|
|
16
16
|
? 'tsx'
|
|
17
17
|
: ['.js', '.jsx', '.mjs', '.cjs'].includes(extension)
|
|
18
18
|
? 'javascript'
|
|
19
|
-
:
|
|
19
|
+
: ['.py', '.pyi'].includes(extension)
|
|
20
|
+
? 'python'
|
|
21
|
+
: null;
|
|
20
22
|
if (!text || !language || Buffer.byteLength(text, 'utf8') > MAX_AST_PARSE_BYTES) {
|
|
21
23
|
return scrubPayload(text);
|
|
22
24
|
}
|
|
@@ -45,8 +47,11 @@ export async function scrubSourceSecrets(text, filePath) {
|
|
|
45
47
|
function secretLabel(node) {
|
|
46
48
|
if (!node)
|
|
47
49
|
return false;
|
|
48
|
-
const property = node.childForFieldName('property') ?? node;
|
|
49
|
-
const name = property.type === 'string'
|
|
50
|
+
const property = node.childForFieldName('property') ?? node.childForFieldName('attribute') ?? node;
|
|
51
|
+
const name = property.type === 'string'
|
|
52
|
+
? (property.namedChildren.find((child) => child.type === 'string_content')?.text ??
|
|
53
|
+
property.text.slice(1, -1))
|
|
54
|
+
: property.text;
|
|
50
55
|
return SECRET_LABEL_RE.test(name);
|
|
51
56
|
}
|
|
52
57
|
function literalPayload(text, sensitive) {
|
|
@@ -58,11 +63,16 @@ function literalPayload(text, sensitive) {
|
|
|
58
63
|
function redactNode(node, sensitive = false) {
|
|
59
64
|
const original = node.text;
|
|
60
65
|
if (node.type === 'comment') {
|
|
66
|
+
if (original.startsWith('#'))
|
|
67
|
+
return '#' + scrubPayload(original.slice(1));
|
|
61
68
|
return original.startsWith('/*')
|
|
62
69
|
? '/*' + scrubPayload(original.slice(2, -2)) + '*/'
|
|
63
70
|
: '//' + scrubPayload(original.slice(2));
|
|
64
71
|
}
|
|
65
|
-
|
|
72
|
+
const stringStart = node.type === 'string' && node.firstNamedChild?.type === 'string_start'
|
|
73
|
+
? node.firstNamedChild
|
|
74
|
+
: null;
|
|
75
|
+
if (node.type === 'string' && !stringStart) {
|
|
66
76
|
return original[0] + literalPayload(original.slice(1, -1), sensitive) + original.at(-1);
|
|
67
77
|
}
|
|
68
78
|
if (node.type === 'property_identifier' &&
|
|
@@ -71,19 +81,22 @@ function redactNode(node, sensitive = false) {
|
|
|
71
81
|
const payload = literalPayload(original, false);
|
|
72
82
|
return payload === original ? original : '"' + payload + '"';
|
|
73
83
|
}
|
|
74
|
-
if (
|
|
84
|
+
if (['number', 'integer', 'float'].includes(node.type) && sensitive)
|
|
75
85
|
return `'${redactSecretValue(original)}'`;
|
|
76
|
-
if (node.type === 'template_string') {
|
|
77
|
-
|
|
78
|
-
let
|
|
86
|
+
if (node.type === 'template_string' || stringStart) {
|
|
87
|
+
const stringEnd = stringStart ? node.lastNamedChild : null;
|
|
88
|
+
let result = stringStart?.text ?? '`';
|
|
89
|
+
let offset = stringStart?.endIndex ?? node.startIndex + 1;
|
|
79
90
|
for (const child of node.namedChildren) {
|
|
80
|
-
if (child.type !== 'template_substitution')
|
|
91
|
+
if (child.type !== 'template_substitution' && child.type !== 'interpolation')
|
|
81
92
|
continue;
|
|
82
93
|
result += literalPayload(original.slice(offset - node.startIndex, child.startIndex - node.startIndex), sensitive);
|
|
83
94
|
result += redactNode(child);
|
|
84
95
|
offset = child.endIndex;
|
|
85
96
|
}
|
|
86
|
-
return result +
|
|
97
|
+
return (result +
|
|
98
|
+
literalPayload(original.slice(offset - node.startIndex, (stringEnd?.startIndex ?? node.endIndex - 1) - node.startIndex), sensitive) +
|
|
99
|
+
(stringEnd?.text ?? '`'));
|
|
87
100
|
}
|
|
88
101
|
if (node.type === 'regex_pattern' || node.type === 'jsx_text')
|
|
89
102
|
return scrubPayload(original);
|
|
@@ -101,6 +114,9 @@ function redactNode(node, sensitive = false) {
|
|
|
101
114
|
'public_field_definition',
|
|
102
115
|
'assignment_pattern',
|
|
103
116
|
'required_parameter',
|
|
117
|
+
'default_parameter',
|
|
118
|
+
'typed_default_parameter',
|
|
119
|
+
'keyword_argument',
|
|
104
120
|
].includes(node.type)) {
|
|
105
121
|
key =
|
|
106
122
|
node.childForFieldName('name') ??
|
|
@@ -109,7 +125,7 @@ function redactNode(node, sensitive = false) {
|
|
|
109
125
|
node.childForFieldName('left');
|
|
110
126
|
value = node.childForFieldName('value') ?? node.childForFieldName('right');
|
|
111
127
|
}
|
|
112
|
-
else if (
|
|
128
|
+
else if (['assignment_expression', 'assignment', 'augmented_assignment', 'named_expression'].includes(node.type)) {
|
|
113
129
|
key = node.childForFieldName('left');
|
|
114
130
|
value = node.childForFieldName('right');
|
|
115
131
|
}
|
|
@@ -123,16 +139,22 @@ function redactNode(node, sensitive = false) {
|
|
|
123
139
|
result += original.slice(offset - node.startIndex, child.startIndex - node.startIndex);
|
|
124
140
|
// Carry labels through value wrappers, never through call arguments or conditions.
|
|
125
141
|
const carry = sensitive &&
|
|
126
|
-
(
|
|
127
|
-
'
|
|
128
|
-
'
|
|
129
|
-
'
|
|
130
|
-
'
|
|
131
|
-
|
|
132
|
-
|
|
142
|
+
(node.type === 'concatenated_string' ||
|
|
143
|
+
node.type === 'binary_operator' ||
|
|
144
|
+
node.type === 'unary_operator' ||
|
|
145
|
+
(node.type === 'call' && child.id === node.childForFieldName('function')?.id) ||
|
|
146
|
+
(node.type === 'attribute' && child.id === node.childForFieldName('object')?.id) ||
|
|
147
|
+
(node.type === 'conditional_expression' && child.id !== node.namedChildren[1]?.id) ||
|
|
148
|
+
([
|
|
149
|
+
'parenthesized_expression',
|
|
150
|
+
'as_expression',
|
|
151
|
+
'satisfies_expression',
|
|
152
|
+
'non_null_expression',
|
|
153
|
+
].includes(node.type) &&
|
|
154
|
+
child.id === node.firstNamedChild?.id) ||
|
|
133
155
|
(node.type === 'type_assertion' && child.id === node.lastNamedChild?.id) ||
|
|
134
|
-
(node.type
|
|
135
|
-
['+', '||', '&&', '??'].includes(node.childForFieldName('operator')?.text ?? '')) ||
|
|
156
|
+
(['binary_expression', 'boolean_operator'].includes(node.type) &&
|
|
157
|
+
['+', '||', '&&', '??', 'or', 'and'].includes(node.childForFieldName('operator')?.text ?? '')) ||
|
|
136
158
|
(node.type === 'ternary_expression' &&
|
|
137
159
|
child.id !== node.childForFieldName('condition')?.id));
|
|
138
160
|
result += redactNode(child, carry || (labeled && child.id === value?.id));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sourceRedaction.js","sourceRoot":"","sources":["../src/sourceRedaction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,MAAM,EAAwB,MAAM,iBAAiB,CAAC;AAC/D,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,mBAAmB,EAAE,MAA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IAAI,CAAC,UAAU,CAAC,CAAC;AAC3D,CAAC"}
|
package/package.json
CHANGED
|
@@ -33,6 +33,7 @@ import {
|
|
|
33
33
|
readdirSync,
|
|
34
34
|
rmSync,
|
|
35
35
|
statSync,
|
|
36
|
+
writeFileSync,
|
|
36
37
|
} from 'node:fs';
|
|
37
38
|
import { tmpdir } from 'node:os';
|
|
38
39
|
import { basename, join } from 'node:path';
|
|
@@ -88,11 +89,16 @@ interface GrammarSpec {
|
|
|
88
89
|
const GRAMMARS: GrammarSpec[] = [
|
|
89
90
|
{
|
|
90
91
|
id: 'typescript',
|
|
91
|
-
pkg: 'tree-sitter-typescript',
|
|
92
|
+
pkg: 'tree-sitter-typescript@0.23.2',
|
|
92
93
|
wasmFile: 'tree-sitter-typescript.wasm',
|
|
93
94
|
tags: 'upstream',
|
|
94
95
|
},
|
|
95
|
-
{
|
|
96
|
+
{
|
|
97
|
+
id: 'tsx',
|
|
98
|
+
pkg: 'tree-sitter-typescript@0.23.2',
|
|
99
|
+
wasmFile: 'tree-sitter-tsx.wasm',
|
|
100
|
+
tags: 'inherited',
|
|
101
|
+
},
|
|
96
102
|
{ id: 'javascript', pkg: 'tree-sitter-javascript', tags: 'upstream' },
|
|
97
103
|
{ id: 'python', pkg: 'tree-sitter-python', tags: 'upstream' },
|
|
98
104
|
{ id: 'go', pkg: 'tree-sitter-go', tags: 'upstream' },
|
|
@@ -216,6 +222,57 @@ async function checkOnly(): Promise<Problem[]> {
|
|
|
216
222
|
return problems;
|
|
217
223
|
}
|
|
218
224
|
|
|
225
|
+
/**
|
|
226
|
+
* 0.23.2's published WASMs and generated C share these two grammar defects.
|
|
227
|
+
* Keep `unique` contextual, and let GLR distinguish typeof-import type queries
|
|
228
|
+
* from runtime calls instead of discarding the type reading on static precedence.
|
|
229
|
+
* Source: https://github.com/tree-sitter/tree-sitter-typescript/tree/v0.23.2
|
|
230
|
+
* MIT; CLI 0.24.4 uses emscripten/emsdk:3.1.64 for the WASM build.
|
|
231
|
+
*/
|
|
232
|
+
function rebuildTypescript(dir: string, work: string): void {
|
|
233
|
+
const grammarPath = join(dir, 'common', 'define-grammar.js');
|
|
234
|
+
let grammar = readFileSync(grammarPath, 'utf8');
|
|
235
|
+
for (const [before, after] of [
|
|
236
|
+
[
|
|
237
|
+
' _reserved_identifier: (_, previous) => choice(',
|
|
238
|
+
" _reserved_identifier: (_, previous) => choice(\n 'unique',",
|
|
239
|
+
],
|
|
240
|
+
[' [$.call_expression, $._type_query_call_expression],\n', ''],
|
|
241
|
+
[
|
|
242
|
+
' conflicts: ($, previous) => previous.concat([',
|
|
243
|
+
' conflicts: ($, previous) => previous.concat([\n [$.call_expression, $._type_query_call_expression],',
|
|
244
|
+
],
|
|
245
|
+
] as const) {
|
|
246
|
+
if (!grammar.includes(before)) throw new Error('TypeScript grammar patch no longer applies');
|
|
247
|
+
grammar = grammar.replace(before, after);
|
|
248
|
+
}
|
|
249
|
+
writeFileSync(grammarPath, grammar);
|
|
250
|
+
const tools = join(work, 'typescript-build');
|
|
251
|
+
execFileSync('npm', [
|
|
252
|
+
'install',
|
|
253
|
+
'--prefix',
|
|
254
|
+
tools,
|
|
255
|
+
'--no-audit',
|
|
256
|
+
'--no-fund',
|
|
257
|
+
'--no-package-lock',
|
|
258
|
+
'tree-sitter-cli@0.24.4',
|
|
259
|
+
'tree-sitter-javascript@0.23.1',
|
|
260
|
+
]);
|
|
261
|
+
const cli = join(tools, 'node_modules', '.bin', 'tree-sitter');
|
|
262
|
+
for (const dialect of ['typescript', 'tsx']) {
|
|
263
|
+
const options = {
|
|
264
|
+
cwd: join(dir, dialect),
|
|
265
|
+
env: { ...process.env, NODE_PATH: join(tools, 'node_modules') },
|
|
266
|
+
};
|
|
267
|
+
execFileSync(cli, ['generate'], options);
|
|
268
|
+
execFileSync(
|
|
269
|
+
cli,
|
|
270
|
+
['build', '--wasm', '--docker', '--output', join(dir, `tree-sitter-${dialect}.wasm`)],
|
|
271
|
+
options
|
|
272
|
+
);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
219
276
|
function vendor(): Problem[] {
|
|
220
277
|
mkdirSync(WASM_DIR, { recursive: true });
|
|
221
278
|
const work = mkdtempSync(join(tmpdir(), 'ts-grammars-'));
|
|
@@ -247,6 +304,7 @@ function vendor(): Problem[] {
|
|
|
247
304
|
dir,
|
|
248
305
|
'--strip-components=1',
|
|
249
306
|
]);
|
|
307
|
+
if (spec.id === 'typescript') rebuildTypescript(dir, work);
|
|
250
308
|
extracted.set(spec.pkg, dir);
|
|
251
309
|
} catch (err) {
|
|
252
310
|
problems.push({
|
package/src/sourceRedaction.ts
CHANGED
|
@@ -23,7 +23,9 @@ export async function scrubSourceSecrets(text: string, filePath: string): Promis
|
|
|
23
23
|
? 'tsx'
|
|
24
24
|
: ['.js', '.jsx', '.mjs', '.cjs'].includes(extension)
|
|
25
25
|
? 'javascript'
|
|
26
|
-
:
|
|
26
|
+
: ['.py', '.pyi'].includes(extension)
|
|
27
|
+
? 'python'
|
|
28
|
+
: null;
|
|
27
29
|
if (!text || !language || Buffer.byteLength(text, 'utf8') > MAX_AST_PARSE_BYTES) {
|
|
28
30
|
return scrubPayload(text);
|
|
29
31
|
}
|
|
@@ -48,8 +50,13 @@ export async function scrubSourceSecrets(text: string, filePath: string): Promis
|
|
|
48
50
|
|
|
49
51
|
function secretLabel(node: Node | null): boolean {
|
|
50
52
|
if (!node) return false;
|
|
51
|
-
const property =
|
|
52
|
-
|
|
53
|
+
const property =
|
|
54
|
+
node.childForFieldName('property') ?? node.childForFieldName('attribute') ?? node;
|
|
55
|
+
const name =
|
|
56
|
+
property.type === 'string'
|
|
57
|
+
? (property.namedChildren.find((child) => child.type === 'string_content')?.text ??
|
|
58
|
+
property.text.slice(1, -1))
|
|
59
|
+
: property.text;
|
|
53
60
|
return SECRET_LABEL_RE.test(name);
|
|
54
61
|
}
|
|
55
62
|
|
|
@@ -62,11 +69,16 @@ function literalPayload(text: string, sensitive: boolean): string {
|
|
|
62
69
|
function redactNode(node: Node, sensitive = false): string {
|
|
63
70
|
const original = node.text;
|
|
64
71
|
if (node.type === 'comment') {
|
|
72
|
+
if (original.startsWith('#')) return '#' + scrubPayload(original.slice(1));
|
|
65
73
|
return original.startsWith('/*')
|
|
66
74
|
? '/*' + scrubPayload(original.slice(2, -2)) + '*/'
|
|
67
75
|
: '//' + scrubPayload(original.slice(2));
|
|
68
76
|
}
|
|
69
|
-
|
|
77
|
+
const stringStart =
|
|
78
|
+
node.type === 'string' && node.firstNamedChild?.type === 'string_start'
|
|
79
|
+
? node.firstNamedChild
|
|
80
|
+
: null;
|
|
81
|
+
if (node.type === 'string' && !stringStart) {
|
|
70
82
|
return original[0] + literalPayload(original.slice(1, -1), sensitive) + original.at(-1);
|
|
71
83
|
}
|
|
72
84
|
if (
|
|
@@ -77,12 +89,14 @@ function redactNode(node: Node, sensitive = false): string {
|
|
|
77
89
|
const payload = literalPayload(original, false);
|
|
78
90
|
return payload === original ? original : '"' + payload + '"';
|
|
79
91
|
}
|
|
80
|
-
if (
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
92
|
+
if (['number', 'integer', 'float'].includes(node.type) && sensitive)
|
|
93
|
+
return `'${redactSecretValue(original)}'`;
|
|
94
|
+
if (node.type === 'template_string' || stringStart) {
|
|
95
|
+
const stringEnd = stringStart ? node.lastNamedChild : null;
|
|
96
|
+
let result = stringStart?.text ?? '`';
|
|
97
|
+
let offset = stringStart?.endIndex ?? node.startIndex + 1;
|
|
84
98
|
for (const child of node.namedChildren) {
|
|
85
|
-
if (child.type !== 'template_substitution') continue;
|
|
99
|
+
if (child.type !== 'template_substitution' && child.type !== 'interpolation') continue;
|
|
86
100
|
result += literalPayload(
|
|
87
101
|
original.slice(offset - node.startIndex, child.startIndex - node.startIndex),
|
|
88
102
|
sensitive
|
|
@@ -90,7 +104,17 @@ function redactNode(node: Node, sensitive = false): string {
|
|
|
90
104
|
result += redactNode(child);
|
|
91
105
|
offset = child.endIndex;
|
|
92
106
|
}
|
|
93
|
-
return
|
|
107
|
+
return (
|
|
108
|
+
result +
|
|
109
|
+
literalPayload(
|
|
110
|
+
original.slice(
|
|
111
|
+
offset - node.startIndex,
|
|
112
|
+
(stringEnd?.startIndex ?? node.endIndex - 1) - node.startIndex
|
|
113
|
+
),
|
|
114
|
+
sensitive
|
|
115
|
+
) +
|
|
116
|
+
(stringEnd?.text ?? '`')
|
|
117
|
+
);
|
|
94
118
|
}
|
|
95
119
|
if (node.type === 'regex_pattern' || node.type === 'jsx_text') return scrubPayload(original);
|
|
96
120
|
// A bare `token: value` fragment is also a valid JS labeled statement.
|
|
@@ -108,6 +132,9 @@ function redactNode(node: Node, sensitive = false): string {
|
|
|
108
132
|
'public_field_definition',
|
|
109
133
|
'assignment_pattern',
|
|
110
134
|
'required_parameter',
|
|
135
|
+
'default_parameter',
|
|
136
|
+
'typed_default_parameter',
|
|
137
|
+
'keyword_argument',
|
|
111
138
|
].includes(node.type)
|
|
112
139
|
) {
|
|
113
140
|
key =
|
|
@@ -116,7 +143,11 @@ function redactNode(node: Node, sensitive = false): string {
|
|
|
116
143
|
node.childForFieldName('pattern') ??
|
|
117
144
|
node.childForFieldName('left');
|
|
118
145
|
value = node.childForFieldName('value') ?? node.childForFieldName('right');
|
|
119
|
-
} else if (
|
|
146
|
+
} else if (
|
|
147
|
+
['assignment_expression', 'assignment', 'augmented_assignment', 'named_expression'].includes(
|
|
148
|
+
node.type
|
|
149
|
+
)
|
|
150
|
+
) {
|
|
120
151
|
key = node.childForFieldName('left');
|
|
121
152
|
value = node.childForFieldName('right');
|
|
122
153
|
} else if (node.type === 'jsx_attribute') {
|
|
@@ -130,16 +161,24 @@ function redactNode(node: Node, sensitive = false): string {
|
|
|
130
161
|
// Carry labels through value wrappers, never through call arguments or conditions.
|
|
131
162
|
const carry =
|
|
132
163
|
sensitive &&
|
|
133
|
-
(
|
|
134
|
-
'
|
|
135
|
-
'
|
|
136
|
-
'
|
|
137
|
-
'
|
|
138
|
-
|
|
139
|
-
|
|
164
|
+
(node.type === 'concatenated_string' ||
|
|
165
|
+
node.type === 'binary_operator' ||
|
|
166
|
+
node.type === 'unary_operator' ||
|
|
167
|
+
(node.type === 'call' && child.id === node.childForFieldName('function')?.id) ||
|
|
168
|
+
(node.type === 'attribute' && child.id === node.childForFieldName('object')?.id) ||
|
|
169
|
+
(node.type === 'conditional_expression' && child.id !== node.namedChildren[1]?.id) ||
|
|
170
|
+
([
|
|
171
|
+
'parenthesized_expression',
|
|
172
|
+
'as_expression',
|
|
173
|
+
'satisfies_expression',
|
|
174
|
+
'non_null_expression',
|
|
175
|
+
].includes(node.type) &&
|
|
176
|
+
child.id === node.firstNamedChild?.id) ||
|
|
140
177
|
(node.type === 'type_assertion' && child.id === node.lastNamedChild?.id) ||
|
|
141
|
-
(node.type
|
|
142
|
-
['+', '||', '&&', '??'
|
|
178
|
+
(['binary_expression', 'boolean_operator'].includes(node.type) &&
|
|
179
|
+
['+', '||', '&&', '??', 'or', 'and'].includes(
|
|
180
|
+
node.childForFieldName('operator')?.text ?? ''
|
|
181
|
+
)) ||
|
|
143
182
|
(node.type === 'ternary_expression' &&
|
|
144
183
|
child.id !== node.childForFieldName('condition')?.id));
|
|
145
184
|
result += redactNode(child, carry || (labeled && child.id === value?.id));
|
package/wasm/tsx.wasm
CHANGED
|
Binary file
|
package/wasm/typescript.wasm
CHANGED
|
Binary file
|