@matatbread/matbot-tool-types 0.5.0 → 0.5.1
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/package.json +5 -5
- package/src/checker.ts +18 -3
- package/src/parameters.cts +3 -2
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"matbotRuntime": [
|
|
4
4
|
"node"
|
|
5
5
|
],
|
|
6
|
-
"version": "0.5.
|
|
6
|
+
"version": "0.5.1",
|
|
7
7
|
"engines": {
|
|
8
8
|
"node": ">=24.0.0"
|
|
9
9
|
},
|
|
@@ -38,13 +38,13 @@
|
|
|
38
38
|
"typescript": "^6.0.3"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
|
-
"@matatbread/matbot-plugin-api": "^0.5.
|
|
42
|
-
"@matatbread/matbot-core": "^0.5.
|
|
41
|
+
"@matatbread/matbot-plugin-api": "^0.5.1",
|
|
42
|
+
"@matatbread/matbot-core": "^0.5.1"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"typescript": "^6.0.3",
|
|
46
|
-
"@matatbread/matbot-plugin-api": "^0.5.
|
|
47
|
-
"@matatbread/matbot-core": "^0.5.
|
|
46
|
+
"@matatbread/matbot-plugin-api": "^0.5.1",
|
|
47
|
+
"@matatbread/matbot-core": "^0.5.1"
|
|
48
48
|
},
|
|
49
49
|
"scripts": {
|
|
50
50
|
"typecheck": "tsc --noEmit"
|
package/src/checker.ts
CHANGED
|
@@ -9,7 +9,6 @@
|
|
|
9
9
|
// own virtual file, the same resolved typescript module), so a checker failure is a plumbing bug
|
|
10
10
|
// that must surface as the caller's error, not be absorbed by a quieter path.
|
|
11
11
|
|
|
12
|
-
import { fileURLToPath } from 'node:url';
|
|
13
12
|
import { renderToolCheckOmitted } from '@matatbread/matbot-plugin-api';
|
|
14
13
|
import type { ToolCheckDiagnostic, ToolCheckReport } from '@matatbread/matbot-plugin-api';
|
|
15
14
|
|
|
@@ -178,6 +177,17 @@ function reportOf(diags: DiagnosticRecord[], mode: Mode): ToolCheckReport {
|
|
|
178
177
|
|
|
179
178
|
type CheckParameters = NonNullable<ToolCheckReport['parameters']>;
|
|
180
179
|
|
|
180
|
+
// Handed to the worker as stripped text, never as a path to require: installed, this file is under
|
|
181
|
+
// node_modules, where node refuses to strip types (#118), and the worker loads no hooks to do it instead.
|
|
182
|
+
let parametersJs: string | undefined;
|
|
183
|
+
async function parametersSource(): Promise<string> {
|
|
184
|
+
if (parametersJs === undefined) {
|
|
185
|
+
const [{ readFile }, { stripTypeScriptTypes }] = await Promise.all([import('node:fs/promises'), import('node:module')]);
|
|
186
|
+
parametersJs = stripTypeScriptTypes(await readFile(new URL('./parameters.cts', import.meta.url), 'utf8'));
|
|
187
|
+
}
|
|
188
|
+
return parametersJs;
|
|
189
|
+
}
|
|
190
|
+
|
|
181
191
|
async function runWorker(data: Record<string, unknown>, importRefused?: (spec: string) => boolean): Promise<{ diags: DiagnosticRecord[] | null; parameters?: CheckParameters }> {
|
|
182
192
|
const { Worker } = await import('node:worker_threads');
|
|
183
193
|
const { createRequire } = await import('node:module');
|
|
@@ -293,7 +303,7 @@ export async function checkSnippetAgainst(opts: {
|
|
|
293
303
|
...(opts.importRefused !== undefined ? { askImports: true } : {}),
|
|
294
304
|
...(opts.withheldGlobals !== undefined ? { withheldGlobals: opts.withheldGlobals } : {}),
|
|
295
305
|
...(opts.parametersOf !== undefined && opts.parametersOf.length > 0
|
|
296
|
-
? { parametersOf: [...opts.parametersOf],
|
|
306
|
+
? { parametersOf: [...opts.parametersOf], parametersSource: await parametersSource() }
|
|
297
307
|
: {}),
|
|
298
308
|
}, opts.importRefused);
|
|
299
309
|
const report = reportOf(diags ?? [], 'snippet');
|
|
@@ -769,9 +779,14 @@ try {
|
|
|
769
779
|
}
|
|
770
780
|
return out;
|
|
771
781
|
};
|
|
782
|
+
const parametersModule = function () {
|
|
783
|
+
const m = { exports: {} };
|
|
784
|
+
new Function('module', 'exports', 'require', workerData.parametersSource)(m, m.exports, require);
|
|
785
|
+
return m.exports;
|
|
786
|
+
};
|
|
772
787
|
// Read from the program just checked, so a schema describes exactly the types that were graded.
|
|
773
788
|
const parameters = workerData.parametersOf && virtual !== null
|
|
774
|
-
?
|
|
789
|
+
? parametersModule().parametersOf(ts, program.getTypeChecker(), program.getSourceFile(virtual), workerData.parametersOf)
|
|
775
790
|
: undefined;
|
|
776
791
|
parentPort.postMessage({ ok: errors.length === 0, diagnostics: errors.map(rec), ...(parameters ? { parameters } : {}) });
|
|
777
792
|
} catch (e) {
|
package/src/parameters.cts
CHANGED
|
@@ -5,8 +5,9 @@ import type TS from 'typescript';
|
|
|
5
5
|
// all the browser has; that derivation cannot see a named type, an imported one, an alias, `Omit<…>` or an
|
|
6
6
|
// indexed access, and degrades each to `{}`. Here every one of them arrives already evaluated.
|
|
7
7
|
//
|
|
8
|
-
//
|
|
9
|
-
//
|
|
8
|
+
// Run in the checker's worker, which is CommonJS with no loader hooks: hence `.cts` and `module.exports`
|
|
9
|
+
// rather than an `export`. The checker strips it and hands the worker the text, since node strips nothing
|
|
10
|
+
// under node_modules, where this file is once installed.
|
|
10
11
|
//
|
|
11
12
|
// The conventions are the hand path's, so the two agree wherever both can answer: the JSON projection of the
|
|
12
13
|
// type (`toJSON` wins, a method is absent), a union of scalars as a `type`/`enum` pair, and anything a
|