funkscript 0.2.6 → 0.2.7

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.
Files changed (171) hide show
  1. package/README.md +1 -1
  2. package/dist/cli/build-watch.d.ts.map +1 -1
  3. package/dist/cli/build-watch.js +4 -24
  4. package/dist/cli/build-watch.js.map +1 -1
  5. package/dist/cli/build.d.ts.map +1 -1
  6. package/dist/cli/build.js +3 -58
  7. package/dist/cli/build.js.map +1 -1
  8. package/dist/cli/check-policy.d.ts +9 -0
  9. package/dist/cli/check-policy.d.ts.map +1 -0
  10. package/dist/cli/check-policy.js +39 -0
  11. package/dist/cli/check-policy.js.map +1 -0
  12. package/dist/cli/check.d.ts.map +1 -1
  13. package/dist/cli/check.js +16 -30
  14. package/dist/cli/check.js.map +1 -1
  15. package/dist/cli/commands.d.ts.map +1 -1
  16. package/dist/cli/commands.js +11 -0
  17. package/dist/cli/commands.js.map +1 -1
  18. package/dist/cli/doctor.d.ts.map +1 -1
  19. package/dist/cli/doctor.js +2 -6
  20. package/dist/cli/doctor.js.map +1 -1
  21. package/dist/cli/index.js +3 -0
  22. package/dist/cli/index.js.map +1 -1
  23. package/dist/cli/query.d.ts +3 -0
  24. package/dist/cli/query.d.ts.map +1 -0
  25. package/dist/cli/query.js +152 -0
  26. package/dist/cli/query.js.map +1 -0
  27. package/dist/cli/run.d.ts.map +1 -1
  28. package/dist/cli/run.js +2 -29
  29. package/dist/cli/run.js.map +1 -1
  30. package/dist/cli/tsc.d.ts.map +1 -1
  31. package/dist/cli/tsc.js +2 -6
  32. package/dist/cli/tsc.js.map +1 -1
  33. package/dist/compiler/check.d.ts.map +1 -1
  34. package/dist/compiler/check.js +18 -28
  35. package/dist/compiler/check.js.map +1 -1
  36. package/dist/compiler/diagnostics-json.d.ts +73 -0
  37. package/dist/compiler/diagnostics-json.d.ts.map +1 -0
  38. package/dist/compiler/diagnostics-json.js +957 -0
  39. package/dist/compiler/diagnostics-json.js.map +1 -0
  40. package/dist/compiler/escape-audit.d.ts +46 -0
  41. package/dist/compiler/escape-audit.d.ts.map +1 -0
  42. package/dist/compiler/escape-audit.js +682 -0
  43. package/dist/compiler/escape-audit.js.map +1 -0
  44. package/dist/compiler/modules/output-plan.d.ts.map +1 -1
  45. package/dist/compiler/modules/output-plan.js +10 -5
  46. package/dist/compiler/modules/output-plan.js.map +1 -1
  47. package/dist/compiler/modules/source-files.d.ts +2 -0
  48. package/dist/compiler/modules/source-files.d.ts.map +1 -1
  49. package/dist/compiler/modules/source-files.js +8 -0
  50. package/dist/compiler/modules/source-files.js.map +1 -1
  51. package/dist/compiler/numeric-comparisons.d.ts.map +1 -1
  52. package/dist/compiler/numeric-comparisons.js +13 -7
  53. package/dist/compiler/numeric-comparisons.js.map +1 -1
  54. package/dist/compiler/pipelines/resolution.d.ts.map +1 -1
  55. package/dist/compiler/pipelines/resolution.js +24 -23
  56. package/dist/compiler/pipelines/resolution.js.map +1 -1
  57. package/dist/compiler/query.d.ts +53 -0
  58. package/dist/compiler/query.d.ts.map +1 -0
  59. package/dist/compiler/query.js +781 -0
  60. package/dist/compiler/query.js.map +1 -0
  61. package/dist/compiler/source-map.d.ts.map +1 -1
  62. package/dist/compiler/source-map.js +2 -7
  63. package/dist/compiler/source-map.js.map +1 -1
  64. package/dist/compiler/type-view-paths.d.ts +2 -0
  65. package/dist/compiler/type-view-paths.d.ts.map +1 -1
  66. package/dist/compiler/type-view-paths.js +8 -0
  67. package/dist/compiler/type-view-paths.js.map +1 -1
  68. package/dist/compiler/typescript-context.d.ts.map +1 -1
  69. package/dist/compiler/typescript-context.js +5 -7
  70. package/dist/compiler/typescript-context.js.map +1 -1
  71. package/dist/emitter/assemblyscript.d.ts.map +1 -1
  72. package/dist/emitter/assemblyscript.js +120 -136
  73. package/dist/emitter/assemblyscript.js.map +1 -1
  74. package/dist/formatter/index.d.ts +9 -0
  75. package/dist/formatter/index.d.ts.map +1 -1
  76. package/dist/formatter/index.js +158 -2
  77. package/dist/formatter/index.js.map +1 -1
  78. package/dist/index.d.ts +3 -0
  79. package/dist/index.d.ts.map +1 -1
  80. package/dist/index.js +3 -0
  81. package/dist/index.js.map +1 -1
  82. package/dist/lsp/completion.d.ts +25 -0
  83. package/dist/lsp/completion.d.ts.map +1 -1
  84. package/dist/lsp/completion.js +1114 -51
  85. package/dist/lsp/completion.js.map +1 -1
  86. package/dist/lsp/definition.d.ts +2 -0
  87. package/dist/lsp/definition.d.ts.map +1 -1
  88. package/dist/lsp/definition.js +52 -58
  89. package/dist/lsp/definition.js.map +1 -1
  90. package/dist/lsp/hover.d.ts +5 -1
  91. package/dist/lsp/hover.d.ts.map +1 -1
  92. package/dist/lsp/hover.js +1000 -41
  93. package/dist/lsp/hover.js.map +1 -1
  94. package/dist/lsp/imports.d.ts +2 -0
  95. package/dist/lsp/imports.d.ts.map +1 -1
  96. package/dist/lsp/imports.js +35 -20
  97. package/dist/lsp/imports.js.map +1 -1
  98. package/dist/lsp/navigation.d.ts +1 -1
  99. package/dist/lsp/navigation.d.ts.map +1 -1
  100. package/dist/lsp/navigation.js +30 -12
  101. package/dist/lsp/navigation.js.map +1 -1
  102. package/dist/lsp/range-format.d.ts +4 -0
  103. package/dist/lsp/range-format.d.ts.map +1 -0
  104. package/dist/lsp/range-format.js +88 -0
  105. package/dist/lsp/range-format.js.map +1 -0
  106. package/dist/lsp/schema-import-hover.d.ts +8 -0
  107. package/dist/lsp/schema-import-hover.d.ts.map +1 -0
  108. package/dist/lsp/schema-import-hover.js +52 -0
  109. package/dist/lsp/schema-import-hover.js.map +1 -0
  110. package/dist/lsp/server.d.ts +1 -0
  111. package/dist/lsp/server.d.ts.map +1 -1
  112. package/dist/lsp/server.js +53 -48
  113. package/dist/lsp/server.js.map +1 -1
  114. package/dist/lsp/workspace.d.ts +3 -1
  115. package/dist/lsp/workspace.d.ts.map +1 -1
  116. package/dist/lsp/workspace.js +66 -10
  117. package/dist/lsp/workspace.js.map +1 -1
  118. package/dist/plugins/bun.d.ts +2 -18
  119. package/dist/plugins/bun.d.ts.map +1 -1
  120. package/dist/plugins/bun.js +5 -30
  121. package/dist/plugins/bun.js.map +1 -1
  122. package/dist/plugins/esbuild.d.ts +1 -1
  123. package/dist/plugins/esbuild.d.ts.map +1 -1
  124. package/dist/plugins/esbuild.js +10 -36
  125. package/dist/plugins/esbuild.js.map +1 -1
  126. package/dist/plugins/server-boundary.d.ts +14 -0
  127. package/dist/plugins/server-boundary.d.ts.map +1 -0
  128. package/dist/plugins/server-boundary.js +25 -0
  129. package/dist/plugins/server-boundary.js.map +1 -0
  130. package/dist/plugins/vite.d.ts +2 -18
  131. package/dist/plugins/vite.d.ts.map +1 -1
  132. package/dist/plugins/vite.js +4 -29
  133. package/dist/plugins/vite.js.map +1 -1
  134. package/package.json +1 -1
  135. package/src/cli/build-watch.ts +4 -26
  136. package/src/cli/build.ts +9 -60
  137. package/src/cli/check-policy.ts +54 -0
  138. package/src/cli/check.ts +19 -31
  139. package/src/cli/commands.ts +13 -0
  140. package/src/cli/doctor.ts +2 -5
  141. package/src/cli/index.ts +3 -0
  142. package/src/cli/query.ts +191 -0
  143. package/src/cli/run.ts +5 -30
  144. package/src/cli/tsc.ts +2 -5
  145. package/src/compiler/check.ts +28 -48
  146. package/src/compiler/diagnostics-json.ts +1205 -0
  147. package/src/compiler/escape-audit.ts +913 -0
  148. package/src/compiler/modules/output-plan.ts +11 -9
  149. package/src/compiler/modules/source-files.ts +9 -0
  150. package/src/compiler/numeric-comparisons.ts +14 -8
  151. package/src/compiler/pipelines/resolution.ts +30 -26
  152. package/src/compiler/query.ts +1177 -0
  153. package/src/compiler/source-map.ts +3 -7
  154. package/src/compiler/type-view-paths.ts +7 -0
  155. package/src/compiler/typescript-context.ts +6 -7
  156. package/src/emitter/assemblyscript.ts +101 -147
  157. package/src/formatter/index.ts +229 -2
  158. package/src/index.ts +3 -0
  159. package/src/lsp/completion.ts +1452 -66
  160. package/src/lsp/definition.ts +50 -58
  161. package/src/lsp/hover.ts +1442 -40
  162. package/src/lsp/imports.ts +55 -21
  163. package/src/lsp/navigation.ts +41 -22
  164. package/src/lsp/range-format.ts +102 -0
  165. package/src/lsp/schema-import-hover.ts +76 -0
  166. package/src/lsp/server.ts +69 -69
  167. package/src/lsp/workspace.ts +63 -9
  168. package/src/plugins/bun.ts +14 -66
  169. package/src/plugins/esbuild.ts +16 -55
  170. package/src/plugins/server-boundary.ts +41 -0
  171. package/src/plugins/vite.ts +12 -62
@@ -3,7 +3,6 @@ import { createHash } from "node:crypto";
3
3
  import * as fs from "node:fs/promises";
4
4
  import * as path from "node:path";
5
5
  import { uniq } from "es-toolkit";
6
- import type { CheckOptions } from "../compiler/check.js";
7
6
  import { IncrementalBuildSession } from "../compiler/incremental-build.js";
8
7
  import { incrementalDependencyKeys } from "../compiler/incremental-dependencies.js";
9
8
  import {
@@ -11,6 +10,7 @@ import {
11
10
  type FunScriptProjectConfig,
12
11
  } from "../compiler/project-config.js";
13
12
  import { collectCliFiles } from "./typecheck.js";
13
+ import { checkOptionsFromPolicy } from "./check-policy.js";
14
14
  import { sourceOutputCollision } from "../compiler/modules/output-collisions.js";
15
15
  import { planBuildOutputs } from "../compiler/modules/output-plan.js";
16
16
  import { isFunSourceFile } from "../compiler/modules/source-files.js";
@@ -143,36 +143,14 @@ export async function watchBuild(
143
143
  ) {
144
144
  if (signal.aborted) break;
145
145
  if (!session || nextPolicyKey !== policyKey) {
146
- const checks: Omit<CheckOptions, "cwd" | "cache"> = {
146
+ const checks = checkOptionsFromPolicy(policy, {
147
147
  noTs: options.flags.noTs || policy.noTs === true,
148
148
  noGlobalThis:
149
149
  options.flags.noGlobalThis || policy.noGlobalThis === true,
150
150
  barePipelines:
151
151
  options.flags.barePipelines || policy.barePipelines === true,
152
- noDeepDestructure:
153
- options.flags.noDeepDestructure ||
154
- policy.noDeepDestructure === true,
155
- maxDestructureDepth: policy.maxDestructureDepth,
156
- noTsPaths: Array.isArray(policy.noTs) ? policy.noTs : undefined,
157
- noGlobalThisPaths: Array.isArray(policy.noGlobalThis)
158
- ? policy.noGlobalThis
159
- : undefined,
160
- barePipelinesPaths: Array.isArray(policy.barePipelines)
161
- ? policy.barePipelines
162
- : undefined,
163
- noDeepDestructurePaths: Array.isArray(policy.noDeepDestructure)
164
- ? policy.noDeepDestructure
165
- : undefined,
166
- allowHoles: policy.allowHoles === true,
167
- allowHolesPaths: Array.isArray(policy.allowHoles)
168
- ? policy.allowHoles
169
- : undefined,
170
- allowEarlyReturns: policy.allowEarlyReturns === true,
171
- allowEarlyReturnsPaths: Array.isArray(policy.allowEarlyReturns)
172
- ? policy.allowEarlyReturns
173
- : undefined,
174
- effectOnly: policy.effectOnly,
175
- };
152
+ noDeepDestructure: options.flags.noDeepDestructure,
153
+ });
176
154
  session = new IncrementalBuildSession(cwd, checks);
177
155
  policyKey = nextPolicyKey;
178
156
  }
package/src/cli/build.ts CHANGED
@@ -17,6 +17,7 @@ import { buildBunExecutable } from "./build-bun.js";
17
17
  import { watchBuild } from "./build-watch.js";
18
18
  import { checkNoTsPaths, findFunFiles, readFile, writeFile } from "./io.js";
19
19
  import { checkCliFiles, collectCliFiles } from "./typecheck.js";
20
+ import { commandCheckOptions } from "./check-policy.js";
20
21
 
21
22
  let projectPolicy: FunScriptProjectConfig = {};
22
23
  const checkNoTsPathsProxy = (
@@ -257,36 +258,10 @@ export const buildCommand = (
257
258
  );
258
259
  if (
259
260
  !args.includes("--no-check") &&
260
- !(yield* checkCliFiles([entryFile], {
261
- noTs: args.includes("--no-ts"),
262
- noGlobalThis: args.includes("--no-global-this"),
263
- barePipelines: args.includes("--bare-pipelines"),
264
- noDeepDestructure:
265
- args.includes("--no-deep-destructure") ||
266
- projectPolicy.noDeepDestructure === true,
267
- maxDestructureDepth: projectPolicy.maxDestructureDepth,
268
- effectOnly: projectPolicy.effectOnly,
269
- noTsPaths: Array.isArray(projectPolicy.noTs)
270
- ? projectPolicy.noTs
271
- : undefined,
272
- noGlobalThisPaths: Array.isArray(projectPolicy.noGlobalThis)
273
- ? projectPolicy.noGlobalThis
274
- : undefined,
275
- barePipelinesPaths: Array.isArray(projectPolicy.barePipelines)
276
- ? projectPolicy.barePipelines
277
- : undefined,
278
- noDeepDestructurePaths: Array.isArray(projectPolicy.noDeepDestructure)
279
- ? projectPolicy.noDeepDestructure
280
- : undefined,
281
- allowHoles: projectPolicy.allowHoles === true,
282
- allowHolesPaths: Array.isArray(projectPolicy.allowHoles)
283
- ? projectPolicy.allowHoles
284
- : undefined,
285
- allowEarlyReturns: projectPolicy.allowEarlyReturns === true,
286
- allowEarlyReturnsPaths: Array.isArray(projectPolicy.allowEarlyReturns)
287
- ? projectPolicy.allowEarlyReturns
288
- : undefined,
289
- }))
261
+ !(yield* checkCliFiles(
262
+ [entryFile],
263
+ commandCheckOptions(projectPolicy, args),
264
+ ))
290
265
  )
291
266
  return;
292
267
  yield* Effect.tryPromise({
@@ -340,36 +315,10 @@ export const buildCommand = (
340
315
 
341
316
  if (
342
317
  !args.includes("--no-check") &&
343
- !(yield* checkCliFiles(filesToBuild, {
344
- noTs: args.includes("--no-ts"),
345
- noGlobalThis: args.includes("--no-global-this"),
346
- barePipelines: args.includes("--bare-pipelines"),
347
- noDeepDestructure:
348
- args.includes("--no-deep-destructure") ||
349
- projectPolicy.noDeepDestructure === true,
350
- maxDestructureDepth: projectPolicy.maxDestructureDepth,
351
- effectOnly: projectPolicy.effectOnly,
352
- noTsPaths: Array.isArray(projectPolicy.noTs)
353
- ? projectPolicy.noTs
354
- : undefined,
355
- noGlobalThisPaths: Array.isArray(projectPolicy.noGlobalThis)
356
- ? projectPolicy.noGlobalThis
357
- : undefined,
358
- barePipelinesPaths: Array.isArray(projectPolicy.barePipelines)
359
- ? projectPolicy.barePipelines
360
- : undefined,
361
- noDeepDestructurePaths: Array.isArray(projectPolicy.noDeepDestructure)
362
- ? projectPolicy.noDeepDestructure
363
- : undefined,
364
- allowHoles: projectPolicy.allowHoles === true,
365
- allowHolesPaths: Array.isArray(projectPolicy.allowHoles)
366
- ? projectPolicy.allowHoles
367
- : undefined,
368
- allowEarlyReturns: projectPolicy.allowEarlyReturns === true,
369
- allowEarlyReturnsPaths: Array.isArray(projectPolicy.allowEarlyReturns)
370
- ? projectPolicy.allowEarlyReturns
371
- : undefined,
372
- }))
318
+ !(yield* checkCliFiles(
319
+ filesToBuild,
320
+ commandCheckOptions(projectPolicy, args),
321
+ ))
373
322
  )
374
323
  return;
375
324
 
@@ -0,0 +1,54 @@
1
+ import type { CheckOptions } from "../compiler/check.js";
2
+ import type { FunScriptProjectConfig } from "../compiler/project-config.js";
3
+
4
+ type PolicyFlags = Pick<
5
+ CheckOptions,
6
+ "noTs" | "noGlobalThis" | "barePipelines" | "noDeepDestructure"
7
+ >;
8
+
9
+ /** Translate project policy and explicit caller flags into checker options. */
10
+ export function checkOptionsFromPolicy(
11
+ policy: FunScriptProjectConfig,
12
+ flags: PolicyFlags,
13
+ ): Omit<CheckOptions, "cwd" | "cache" | "compilerOptions" | "highlightCode"> {
14
+ return {
15
+ noTs: flags.noTs,
16
+ noGlobalThis: flags.noGlobalThis,
17
+ barePipelines: flags.barePipelines,
18
+ noDeepDestructure:
19
+ flags.noDeepDestructure || policy.noDeepDestructure === true,
20
+ maxDestructureDepth: policy.maxDestructureDepth,
21
+ effectOnly: policy.effectOnly,
22
+ noTsPaths: Array.isArray(policy.noTs) ? policy.noTs : undefined,
23
+ noGlobalThisPaths: Array.isArray(policy.noGlobalThis)
24
+ ? policy.noGlobalThis
25
+ : undefined,
26
+ barePipelinesPaths: Array.isArray(policy.barePipelines)
27
+ ? policy.barePipelines
28
+ : undefined,
29
+ noDeepDestructurePaths: Array.isArray(policy.noDeepDestructure)
30
+ ? policy.noDeepDestructure
31
+ : undefined,
32
+ allowHoles: policy.allowHoles === true,
33
+ allowHolesPaths: Array.isArray(policy.allowHoles)
34
+ ? policy.allowHoles
35
+ : undefined,
36
+ allowEarlyReturns: policy.allowEarlyReturns === true,
37
+ allowEarlyReturnsPaths: Array.isArray(policy.allowEarlyReturns)
38
+ ? policy.allowEarlyReturns
39
+ : undefined,
40
+ };
41
+ }
42
+
43
+ /** Resolve command flags from the argument list supplied by the caller. */
44
+ export function commandCheckOptions(
45
+ policy: FunScriptProjectConfig,
46
+ args: readonly string[],
47
+ ) {
48
+ return checkOptionsFromPolicy(policy, {
49
+ noTs: args.includes("--no-ts"),
50
+ noGlobalThis: args.includes("--no-global-this"),
51
+ barePipelines: args.includes("--bare-pipelines"),
52
+ noDeepDestructure: args.includes("--no-deep-destructure"),
53
+ });
54
+ }
package/src/cli/check.ts CHANGED
@@ -4,6 +4,7 @@ import * as fs from "node:fs/promises";
4
4
  import * as path from "node:path";
5
5
  import { pathToFileURL } from "node:url";
6
6
  import { typeCheckFiles, type TypeCheckDiagnostic } from "../compiler/check.js";
7
+ import { attachRepairHints } from "../compiler/diagnostics-json.js";
7
8
  import { FunScriptError, toErrorMessage } from "../errors.js";
8
9
  import {
9
10
  loadFormatConfigForFile,
@@ -14,6 +15,7 @@ import { auditIdiomaticFunScript } from "../tooling/idiomatic.js";
14
15
  import { convertPipelineStyle } from "../tooling/pipeline-style.js";
15
16
  import { checkNoTsPaths, findFunFiles } from "./io.js";
16
17
  import { collectCliFiles } from "./typecheck.js";
18
+ import { commandCheckOptions } from "./check-policy.js";
17
19
 
18
20
  let projectPolicy: FunScriptProjectConfig = {};
19
21
  const checkNoTsPathsProxy = (
@@ -197,36 +199,10 @@ export const checkCommand = (
197
199
  }
198
200
 
199
201
  const allFiles = yield* collectCliFiles(filesToCheck);
200
- const result = yield* typeCheckFiles(allFiles, {
201
- noTs: args.includes("--no-ts"),
202
- noGlobalThis: args.includes("--no-global-this"),
203
- barePipelines: args.includes("--bare-pipelines"),
204
- noDeepDestructure:
205
- args.includes("--no-deep-destructure") ||
206
- projectPolicy.noDeepDestructure === true,
207
- maxDestructureDepth: projectPolicy.maxDestructureDepth,
208
- effectOnly: projectPolicy.effectOnly,
209
- noTsPaths: Array.isArray(projectPolicy.noTs)
210
- ? projectPolicy.noTs
211
- : undefined,
212
- noGlobalThisPaths: Array.isArray(projectPolicy.noGlobalThis)
213
- ? projectPolicy.noGlobalThis
214
- : undefined,
215
- barePipelinesPaths: Array.isArray(projectPolicy.barePipelines)
216
- ? projectPolicy.barePipelines
217
- : undefined,
218
- noDeepDestructurePaths: Array.isArray(projectPolicy.noDeepDestructure)
219
- ? projectPolicy.noDeepDestructure
220
- : undefined,
221
- allowHoles: projectPolicy.allowHoles === true,
222
- allowHolesPaths: Array.isArray(projectPolicy.allowHoles)
223
- ? projectPolicy.allowHoles
224
- : undefined,
225
- allowEarlyReturns: projectPolicy.allowEarlyReturns === true,
226
- allowEarlyReturnsPaths: Array.isArray(projectPolicy.allowEarlyReturns)
227
- ? projectPolicy.allowEarlyReturns
228
- : undefined,
229
- });
202
+ const result = yield* typeCheckFiles(
203
+ allFiles,
204
+ commandCheckOptions(projectPolicy, args),
205
+ );
230
206
  const success =
231
207
  result.success &&
232
208
  idiomaticPassed &&
@@ -260,12 +236,24 @@ export const checkCommand = (
260
236
  );
261
237
  if (jsonOutput) {
262
238
  if (!success) process.exitCode = 1;
239
+ const sourcesByFile = new Map<string, string>();
240
+ for (const diagnostic of diagnostics) {
241
+ if (!diagnostic.file || sourcesByFile.has(diagnostic.file)) continue;
242
+ const content = yield* Effect.tryPromise({
243
+ try: () => fs.readFile(diagnostic.file, "utf-8"),
244
+ catch: () => "",
245
+ });
246
+ if (content) sourcesByFile.set(diagnostic.file, content);
247
+ }
248
+ const enrichedDiagnostics = diagnostics.map((diagnostic) =>
249
+ attachRepairHints(diagnostic, sourcesByFile.get(diagnostic.file)),
250
+ );
263
251
  yield* Console.log(
264
252
  JSON.stringify({
265
253
  success,
266
254
  errorCount: result.errorCount + idiomaticDiagnostics.length,
267
255
  warningCount: result.warningCount,
268
- diagnostics,
256
+ diagnostics: enrichedDiagnostics,
269
257
  }),
270
258
  );
271
259
  } else if (sarifOutput) {
@@ -64,6 +64,7 @@ const commandOptions: Record<string, ReadonlySet<string>> = {
64
64
  fmt: new Set(["--check", "--diff", "--stdin", "--stdin-filepath"]),
65
65
  doctor: new Set(["--json"]),
66
66
  explain: new Set(["--list", "--json"]),
67
+ query: new Set(["--symbol", "--escapes", "--json"]),
67
68
  doc: new Set(["--outDir", "--format", "--open", "--json"]),
68
69
  lsp: new Set(["--stdio"]),
69
70
  init: new Set(["--template", "--force"]),
@@ -76,6 +77,7 @@ const valueOptions: Record<string, ReadonlySet<string>> = {
76
77
  test: new Set(["--engine", "--reporter"]),
77
78
  init: new Set(["--template"]),
78
79
  doc: new Set(["--outDir", "--format"]),
80
+ query: new Set(["--symbol"]),
79
81
  };
80
82
 
81
83
  export function validateCliArgs(
@@ -232,6 +234,17 @@ export const CLI_COMMANDS: readonly CliCommand[] = [
232
234
  "funkscript doc --open",
233
235
  ],
234
236
  },
237
+ {
238
+ name: "query",
239
+ usage:
240
+ "query [files or directories...] [--symbol <name>] [--escapes] [--json]",
241
+ description:
242
+ "Inspect resolved types, Effect<A, E, R> channels, typed holes, or AST escape hatches.",
243
+ examples: [
244
+ "funkscript query examples/greeter-service.fun --json",
245
+ "funkscript query examples/shapes.fun --escapes",
246
+ ],
247
+ },
235
248
  {
236
249
  name: "pipeline-style",
237
250
  usage: "pipeline-style <bare|qualified> <file or directory...>",
package/src/cli/doctor.ts CHANGED
@@ -8,6 +8,7 @@ import { loadProjectConfig } from "../compiler/project-config.js";
8
8
  import {
9
9
  DEFAULT_TYPE_VIEW_DIR,
10
10
  TYPE_VIEW_MANIFEST,
11
+ typeViewManifestSources,
11
12
  } from "../compiler/type-view-paths.js";
12
13
  import { isFunSourceFile } from "../compiler/modules/source-files.js";
13
14
  import { isModuleNotFoundError, toErrorMessage } from "../errors.js";
@@ -136,11 +137,7 @@ export const doctorCommand = (args: string[]) =>
136
137
  if (manifestText === undefined)
137
138
  throw Object.assign(new Error("file not found"), { code: "ENOENT" });
138
139
  const manifest: unknown = JSON.parse(manifestText);
139
- const sourcePaths = Array.isArray(manifest)
140
- ? manifest
141
- : manifest && typeof manifest === "object"
142
- ? Object.keys(manifest)
143
- : [];
140
+ const sourcePaths = typeViewManifestSources(manifest);
144
141
  const stale = sourcePaths.filter(
145
142
  (source): source is string =>
146
143
  typeof source === "string" &&
package/src/cli/index.ts CHANGED
@@ -17,6 +17,7 @@ import { doctorCommand } from "./doctor.js";
17
17
  import { emitCommand } from "./emit.js";
18
18
  import { explainCommand } from "./explain.js";
19
19
  import { fmtCommand } from "./fmt.js";
20
+ import { queryCommand } from "./query.js";
20
21
  import { initProject } from "./init.js";
21
22
  import { toErrorMessage } from "../errors.js";
22
23
  import { findFunFiles } from "./io.js";
@@ -204,6 +205,8 @@ const program = Effect.gen(function* () {
204
205
  return yield* doctorCommand(commandArgs);
205
206
  case "explain":
206
207
  return yield* explainCommand(commandArgs);
208
+ case "query":
209
+ return yield* queryCommand(commandArgs);
207
210
  case "doc":
208
211
  return yield* docCommand(commandArgs);
209
212
  case "version":
@@ -0,0 +1,191 @@
1
+ import * as Console from "effect/Console";
2
+ import * as Effect from "effect/Effect";
3
+ import * as fs from "node:fs/promises";
4
+ import {
5
+ auditEscapeHatchesFiles,
6
+ formatEscapeAudit,
7
+ type EscapeAuditReport,
8
+ } from "../compiler/escape-audit.js";
9
+ import { formatQueryReport, queryFiles } from "../compiler/query.js";
10
+ import { toErrorMessage } from "../errors.js";
11
+ import { findFunFiles } from "./io.js";
12
+
13
+ const USAGE =
14
+ "Usage: funkscript query [file.fun|file.funx...] [--symbol <name>] [--escapes] [--json]";
15
+
16
+ interface ParsedQueryArgs {
17
+ files: string[];
18
+ symbol?: string;
19
+ escapes: boolean;
20
+ json: boolean;
21
+ }
22
+
23
+ function parseQueryArgs(args: string[]): ParsedQueryArgs | string {
24
+ const files: string[] = [];
25
+ let symbol: string | undefined;
26
+ let escapes = false;
27
+ let json = false;
28
+
29
+ for (let i = 0; i < args.length; i++) {
30
+ const arg = args[i];
31
+ if (arg === "--json") {
32
+ json = true;
33
+ } else if (arg === "--escapes") {
34
+ escapes = true;
35
+ } else if (arg === "--symbol") {
36
+ const value = args[i + 1];
37
+ if (!value || value.startsWith("-")) {
38
+ return "Option '--symbol' requires a value.";
39
+ }
40
+ symbol = value;
41
+ i++;
42
+ } else if (arg.startsWith("--symbol=")) {
43
+ const value = arg.slice("--symbol=".length);
44
+ if (!value) {
45
+ return "Option '--symbol' requires a value.";
46
+ }
47
+ symbol = value;
48
+ } else if (arg.startsWith("-")) {
49
+ return `Unknown option '${arg}' for 'query'. ${USAGE}`;
50
+ } else {
51
+ files.push(arg);
52
+ }
53
+ }
54
+
55
+ return { files, symbol, escapes, json };
56
+ }
57
+
58
+ function filterEscapeReportBySymbol(
59
+ report: EscapeAuditReport,
60
+ symbol: string,
61
+ ): EscapeAuditReport {
62
+ const counts = {
63
+ rawTs: 0,
64
+ jsInterop: 0,
65
+ wildcardMatch: 0,
66
+ typedHole: 0,
67
+ total: 0,
68
+ };
69
+ const files = report.files.map((fileReport) => {
70
+ const findings = fileReport.findings.filter(
71
+ (f) => f.declaration === symbol,
72
+ );
73
+ const fileCounts = {
74
+ rawTs: 0,
75
+ jsInterop: 0,
76
+ wildcardMatch: 0,
77
+ typedHole: 0,
78
+ total: findings.length,
79
+ };
80
+ for (const finding of findings) {
81
+ switch (finding.kind) {
82
+ case "raw-ts":
83
+ fileCounts.rawTs += 1;
84
+ counts.rawTs += 1;
85
+ break;
86
+ case "js-interop":
87
+ fileCounts.jsInterop += 1;
88
+ counts.jsInterop += 1;
89
+ break;
90
+ case "wildcard-match":
91
+ fileCounts.wildcardMatch += 1;
92
+ counts.wildcardMatch += 1;
93
+ break;
94
+ case "typed-hole":
95
+ fileCounts.typedHole += 1;
96
+ counts.typedHole += 1;
97
+ break;
98
+ }
99
+ }
100
+ counts.total += fileCounts.total;
101
+ return {
102
+ file: fileReport.file,
103
+ counts: fileCounts,
104
+ findings,
105
+ };
106
+ });
107
+
108
+ return {
109
+ schemaVersion: 1,
110
+ counts,
111
+ files,
112
+ };
113
+ }
114
+
115
+ function resolveQueryTargets(
116
+ rawTargets: string[],
117
+ ): Effect.Effect<string[], Error> {
118
+ return Effect.gen(function* () {
119
+ if (rawTargets.length === 0) {
120
+ const hasSrc = yield* Effect.promise(() =>
121
+ fs
122
+ .stat("src")
123
+ .then((stat) => stat.isDirectory())
124
+ .catch(() => false),
125
+ );
126
+ const searchDir = hasSrc ? "src" : ".";
127
+ return yield* Effect.tryPromise({
128
+ try: () => findFunFiles(searchDir),
129
+ catch: (error: unknown) =>
130
+ new Error(
131
+ `Failed to scan files in '${searchDir}': ${toErrorMessage(error)}`,
132
+ ),
133
+ });
134
+ }
135
+
136
+ const resolved: string[] = [];
137
+ for (const target of rawTargets) {
138
+ const stat = yield* Effect.tryPromise({
139
+ try: () => fs.stat(target),
140
+ catch: (error: unknown) =>
141
+ new Error(
142
+ `File or directory '${target}' not found: ${toErrorMessage(error)}`,
143
+ ),
144
+ });
145
+ if (stat.isDirectory()) {
146
+ const nested = yield* Effect.tryPromise({
147
+ try: () => findFunFiles(target),
148
+ catch: (error: unknown) =>
149
+ new Error(
150
+ `Failed to scan files in '${target}': ${toErrorMessage(error)}`,
151
+ ),
152
+ });
153
+ resolved.push(...nested);
154
+ } else {
155
+ resolved.push(target);
156
+ }
157
+ }
158
+ return resolved;
159
+ });
160
+ }
161
+
162
+ export const queryCommand = (args: string[]): Effect.Effect<void, Error> =>
163
+ Effect.gen(function* () {
164
+ const parsed = parseQueryArgs(args);
165
+ if (typeof parsed === "string") {
166
+ process.exitCode = 1;
167
+ yield* Console.error(parsed);
168
+ return;
169
+ }
170
+
171
+ const filesToQuery = yield* resolveQueryTargets(parsed.files);
172
+ if (filesToQuery.length === 0) {
173
+ yield* Console.error(USAGE);
174
+ return;
175
+ }
176
+
177
+ if (parsed.escapes) {
178
+ const rawReport = yield* auditEscapeHatchesFiles(filesToQuery);
179
+ const report = parsed.symbol
180
+ ? filterEscapeReportBySymbol(rawReport, parsed.symbol)
181
+ : rawReport;
182
+ yield* Console.log(formatEscapeAudit(report, { json: parsed.json }));
183
+ return;
184
+ }
185
+
186
+ const report = yield* queryFiles(
187
+ filesToQuery,
188
+ parsed.symbol ? { symbol: parsed.symbol } : undefined,
189
+ );
190
+ yield* Console.log(formatQueryReport(report, { json: parsed.json }));
191
+ });
package/src/cli/run.ts CHANGED
@@ -10,6 +10,7 @@ import {
10
10
  import { buildRunBundle, isBunAvailable } from "./build-bun.js";
11
11
  import { checkNoTsPaths } from "./io.js";
12
12
  import { checkCliFiles } from "./typecheck.js";
13
+ import { commandCheckOptions } from "./check-policy.js";
13
14
 
14
15
  let projectPolicy: FunScriptProjectConfig = {};
15
16
  const checkNoTsPathsProxy = (
@@ -69,36 +70,10 @@ export const runCommand = (
69
70
  return;
70
71
  if (
71
72
  !commandArgs.includes("--no-check") &&
72
- !(yield* checkCliFiles([filePath], {
73
- noTs: commandArgs.includes("--no-ts"),
74
- noGlobalThis: commandArgs.includes("--no-global-this"),
75
- barePipelines: commandArgs.includes("--bare-pipelines"),
76
- noDeepDestructure:
77
- commandArgs.includes("--no-deep-destructure") ||
78
- projectPolicy.noDeepDestructure === true,
79
- maxDestructureDepth: projectPolicy.maxDestructureDepth,
80
- effectOnly: projectPolicy.effectOnly,
81
- noTsPaths: Array.isArray(projectPolicy.noTs)
82
- ? projectPolicy.noTs
83
- : undefined,
84
- noGlobalThisPaths: Array.isArray(projectPolicy.noGlobalThis)
85
- ? projectPolicy.noGlobalThis
86
- : undefined,
87
- barePipelinesPaths: Array.isArray(projectPolicy.barePipelines)
88
- ? projectPolicy.barePipelines
89
- : undefined,
90
- noDeepDestructurePaths: Array.isArray(projectPolicy.noDeepDestructure)
91
- ? projectPolicy.noDeepDestructure
92
- : undefined,
93
- allowHoles: projectPolicy.allowHoles === true,
94
- allowHolesPaths: Array.isArray(projectPolicy.allowHoles)
95
- ? projectPolicy.allowHoles
96
- : undefined,
97
- allowEarlyReturns: projectPolicy.allowEarlyReturns === true,
98
- allowEarlyReturnsPaths: Array.isArray(projectPolicy.allowEarlyReturns)
99
- ? projectPolicy.allowEarlyReturns
100
- : undefined,
101
- }))
73
+ !(yield* checkCliFiles(
74
+ [filePath],
75
+ commandCheckOptions(projectPolicy, commandArgs),
76
+ ))
102
77
  )
103
78
  return;
104
79
 
package/src/cli/tsc.ts CHANGED
@@ -15,6 +15,7 @@ import { FunScriptError, isFileNotFoundError } from "../errors.js";
15
15
  import {
16
16
  DEFAULT_TYPE_VIEW_DIR,
17
17
  TYPE_VIEW_MANIFEST,
18
+ typeViewManifestSources,
18
19
  } from "../compiler/type-view-paths.js";
19
20
  import { isFunSourceFile } from "../compiler/modules/source-files.js";
20
21
  import { rewriteRelativeImports } from "../plugins/type-view.js";
@@ -66,11 +67,7 @@ export async function runTsc(
66
67
  () => [],
67
68
  );
68
69
  const views = new Map<string, string>();
69
- const manifestFiles = Array.isArray(manifest)
70
- ? manifest
71
- : manifest && typeof manifest === "object"
72
- ? Object.keys(manifest)
73
- : [];
70
+ const manifestFiles = typeViewManifestSources(manifest);
74
71
  for (const item of manifestFiles) {
75
72
  if (typeof item !== "string" || !isFunSourceFile(item)) continue;
76
73
  const original = path.resolve(cwd, item);