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.
- package/README.md +1 -1
- package/dist/cli/build-watch.d.ts.map +1 -1
- package/dist/cli/build-watch.js +4 -24
- package/dist/cli/build-watch.js.map +1 -1
- package/dist/cli/build.d.ts.map +1 -1
- package/dist/cli/build.js +3 -58
- package/dist/cli/build.js.map +1 -1
- package/dist/cli/check-policy.d.ts +9 -0
- package/dist/cli/check-policy.d.ts.map +1 -0
- package/dist/cli/check-policy.js +39 -0
- package/dist/cli/check-policy.js.map +1 -0
- package/dist/cli/check.d.ts.map +1 -1
- package/dist/cli/check.js +16 -30
- package/dist/cli/check.js.map +1 -1
- package/dist/cli/commands.d.ts.map +1 -1
- package/dist/cli/commands.js +11 -0
- package/dist/cli/commands.js.map +1 -1
- package/dist/cli/doctor.d.ts.map +1 -1
- package/dist/cli/doctor.js +2 -6
- package/dist/cli/doctor.js.map +1 -1
- package/dist/cli/index.js +3 -0
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/query.d.ts +3 -0
- package/dist/cli/query.d.ts.map +1 -0
- package/dist/cli/query.js +152 -0
- package/dist/cli/query.js.map +1 -0
- package/dist/cli/run.d.ts.map +1 -1
- package/dist/cli/run.js +2 -29
- package/dist/cli/run.js.map +1 -1
- package/dist/cli/tsc.d.ts.map +1 -1
- package/dist/cli/tsc.js +2 -6
- package/dist/cli/tsc.js.map +1 -1
- package/dist/compiler/check.d.ts.map +1 -1
- package/dist/compiler/check.js +18 -28
- package/dist/compiler/check.js.map +1 -1
- package/dist/compiler/diagnostics-json.d.ts +73 -0
- package/dist/compiler/diagnostics-json.d.ts.map +1 -0
- package/dist/compiler/diagnostics-json.js +957 -0
- package/dist/compiler/diagnostics-json.js.map +1 -0
- package/dist/compiler/escape-audit.d.ts +46 -0
- package/dist/compiler/escape-audit.d.ts.map +1 -0
- package/dist/compiler/escape-audit.js +682 -0
- package/dist/compiler/escape-audit.js.map +1 -0
- package/dist/compiler/modules/output-plan.d.ts.map +1 -1
- package/dist/compiler/modules/output-plan.js +10 -5
- package/dist/compiler/modules/output-plan.js.map +1 -1
- package/dist/compiler/modules/source-files.d.ts +2 -0
- package/dist/compiler/modules/source-files.d.ts.map +1 -1
- package/dist/compiler/modules/source-files.js +8 -0
- package/dist/compiler/modules/source-files.js.map +1 -1
- package/dist/compiler/numeric-comparisons.d.ts.map +1 -1
- package/dist/compiler/numeric-comparisons.js +13 -7
- package/dist/compiler/numeric-comparisons.js.map +1 -1
- package/dist/compiler/pipelines/resolution.d.ts.map +1 -1
- package/dist/compiler/pipelines/resolution.js +24 -23
- package/dist/compiler/pipelines/resolution.js.map +1 -1
- package/dist/compiler/query.d.ts +53 -0
- package/dist/compiler/query.d.ts.map +1 -0
- package/dist/compiler/query.js +781 -0
- package/dist/compiler/query.js.map +1 -0
- package/dist/compiler/source-map.d.ts.map +1 -1
- package/dist/compiler/source-map.js +2 -7
- package/dist/compiler/source-map.js.map +1 -1
- package/dist/compiler/type-view-paths.d.ts +2 -0
- package/dist/compiler/type-view-paths.d.ts.map +1 -1
- package/dist/compiler/type-view-paths.js +8 -0
- package/dist/compiler/type-view-paths.js.map +1 -1
- package/dist/compiler/typescript-context.d.ts.map +1 -1
- package/dist/compiler/typescript-context.js +5 -7
- package/dist/compiler/typescript-context.js.map +1 -1
- package/dist/emitter/assemblyscript.d.ts.map +1 -1
- package/dist/emitter/assemblyscript.js +120 -136
- package/dist/emitter/assemblyscript.js.map +1 -1
- package/dist/formatter/index.d.ts +9 -0
- package/dist/formatter/index.d.ts.map +1 -1
- package/dist/formatter/index.js +158 -2
- package/dist/formatter/index.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/lsp/completion.d.ts +25 -0
- package/dist/lsp/completion.d.ts.map +1 -1
- package/dist/lsp/completion.js +1114 -51
- package/dist/lsp/completion.js.map +1 -1
- package/dist/lsp/definition.d.ts +2 -0
- package/dist/lsp/definition.d.ts.map +1 -1
- package/dist/lsp/definition.js +52 -58
- package/dist/lsp/definition.js.map +1 -1
- package/dist/lsp/hover.d.ts +5 -1
- package/dist/lsp/hover.d.ts.map +1 -1
- package/dist/lsp/hover.js +1000 -41
- package/dist/lsp/hover.js.map +1 -1
- package/dist/lsp/imports.d.ts +2 -0
- package/dist/lsp/imports.d.ts.map +1 -1
- package/dist/lsp/imports.js +35 -20
- package/dist/lsp/imports.js.map +1 -1
- package/dist/lsp/navigation.d.ts +1 -1
- package/dist/lsp/navigation.d.ts.map +1 -1
- package/dist/lsp/navigation.js +30 -12
- package/dist/lsp/navigation.js.map +1 -1
- package/dist/lsp/range-format.d.ts +4 -0
- package/dist/lsp/range-format.d.ts.map +1 -0
- package/dist/lsp/range-format.js +88 -0
- package/dist/lsp/range-format.js.map +1 -0
- package/dist/lsp/schema-import-hover.d.ts +8 -0
- package/dist/lsp/schema-import-hover.d.ts.map +1 -0
- package/dist/lsp/schema-import-hover.js +52 -0
- package/dist/lsp/schema-import-hover.js.map +1 -0
- package/dist/lsp/server.d.ts +1 -0
- package/dist/lsp/server.d.ts.map +1 -1
- package/dist/lsp/server.js +53 -48
- package/dist/lsp/server.js.map +1 -1
- package/dist/lsp/workspace.d.ts +3 -1
- package/dist/lsp/workspace.d.ts.map +1 -1
- package/dist/lsp/workspace.js +66 -10
- package/dist/lsp/workspace.js.map +1 -1
- package/dist/plugins/bun.d.ts +2 -18
- package/dist/plugins/bun.d.ts.map +1 -1
- package/dist/plugins/bun.js +5 -30
- package/dist/plugins/bun.js.map +1 -1
- package/dist/plugins/esbuild.d.ts +1 -1
- package/dist/plugins/esbuild.d.ts.map +1 -1
- package/dist/plugins/esbuild.js +10 -36
- package/dist/plugins/esbuild.js.map +1 -1
- package/dist/plugins/server-boundary.d.ts +14 -0
- package/dist/plugins/server-boundary.d.ts.map +1 -0
- package/dist/plugins/server-boundary.js +25 -0
- package/dist/plugins/server-boundary.js.map +1 -0
- package/dist/plugins/vite.d.ts +2 -18
- package/dist/plugins/vite.d.ts.map +1 -1
- package/dist/plugins/vite.js +4 -29
- package/dist/plugins/vite.js.map +1 -1
- package/package.json +1 -1
- package/src/cli/build-watch.ts +4 -26
- package/src/cli/build.ts +9 -60
- package/src/cli/check-policy.ts +54 -0
- package/src/cli/check.ts +19 -31
- package/src/cli/commands.ts +13 -0
- package/src/cli/doctor.ts +2 -5
- package/src/cli/index.ts +3 -0
- package/src/cli/query.ts +191 -0
- package/src/cli/run.ts +5 -30
- package/src/cli/tsc.ts +2 -5
- package/src/compiler/check.ts +28 -48
- package/src/compiler/diagnostics-json.ts +1205 -0
- package/src/compiler/escape-audit.ts +913 -0
- package/src/compiler/modules/output-plan.ts +11 -9
- package/src/compiler/modules/source-files.ts +9 -0
- package/src/compiler/numeric-comparisons.ts +14 -8
- package/src/compiler/pipelines/resolution.ts +30 -26
- package/src/compiler/query.ts +1177 -0
- package/src/compiler/source-map.ts +3 -7
- package/src/compiler/type-view-paths.ts +7 -0
- package/src/compiler/typescript-context.ts +6 -7
- package/src/emitter/assemblyscript.ts +101 -147
- package/src/formatter/index.ts +229 -2
- package/src/index.ts +3 -0
- package/src/lsp/completion.ts +1452 -66
- package/src/lsp/definition.ts +50 -58
- package/src/lsp/hover.ts +1442 -40
- package/src/lsp/imports.ts +55 -21
- package/src/lsp/navigation.ts +41 -22
- package/src/lsp/range-format.ts +102 -0
- package/src/lsp/schema-import-hover.ts +76 -0
- package/src/lsp/server.ts +69 -69
- package/src/lsp/workspace.ts +63 -9
- package/src/plugins/bun.ts +14 -66
- package/src/plugins/esbuild.ts +16 -55
- package/src/plugins/server-boundary.ts +41 -0
- package/src/plugins/vite.ts +12 -62
package/src/cli/build-watch.ts
CHANGED
|
@@ -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
|
|
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
|
-
|
|
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(
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
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(
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
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(
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
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) {
|
package/src/cli/commands.ts
CHANGED
|
@@ -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 =
|
|
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":
|
package/src/cli/query.ts
ADDED
|
@@ -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(
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
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 =
|
|
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);
|