@electric-sql/client 1.5.12 → 1.5.13

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.
@@ -0,0 +1,81 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { execFileSync } from 'node:child_process'
4
+ import {
5
+ analyzeTypeScriptClient,
6
+ filterFindingsToChangedFiles,
7
+ filterFindingsToChangedLines,
8
+ formatAnalysisResult,
9
+ loadChangedLines,
10
+ } from './lib/shape-stream-static-analysis.mjs'
11
+
12
+ const args = process.argv.slice(2)
13
+ const failOnFindings = args.includes(`--fail-on-findings`)
14
+ const json = args.includes(`--json`)
15
+
16
+ const explicitRangeIndex = args.findIndex((arg) => arg === `--range`)
17
+ const explicitRange =
18
+ explicitRangeIndex >= 0 ? args[explicitRangeIndex + 1] : undefined
19
+ const explicitScopeIndex = args.findIndex((arg) => arg === `--scope`)
20
+ const scope = explicitScopeIndex >= 0 ? args[explicitScopeIndex + 1] : `file`
21
+
22
+ const result = analyzeTypeScriptClient()
23
+ const range = explicitRange ?? getDefaultRange()
24
+ const changedLines = loadChangedLines(range, [
25
+ result.clientFile,
26
+ result.stateMachineFile,
27
+ ])
28
+ const findings =
29
+ scope === `line`
30
+ ? filterFindingsToChangedLines(result.findings, changedLines)
31
+ : filterFindingsToChangedFiles(result.findings, changedLines)
32
+
33
+ if (json) {
34
+ console.log(
35
+ JSON.stringify(
36
+ {
37
+ range,
38
+ scope,
39
+ findings,
40
+ },
41
+ null,
42
+ 2
43
+ )
44
+ )
45
+ } else {
46
+ console.log(`Range: ${range}`)
47
+ console.log(`Scope: ${scope}`)
48
+ if (scope === `line`) {
49
+ console.log(formatAnalysisResult(result, { changedLines }))
50
+ } else {
51
+ console.log(
52
+ formatAnalysisResult({
53
+ ...result,
54
+ findings,
55
+ })
56
+ )
57
+ }
58
+ }
59
+
60
+ if (failOnFindings && findings.length > 0) {
61
+ process.exitCode = 1
62
+ }
63
+
64
+ function getDefaultRange() {
65
+ try {
66
+ const mergeBase = execFileSync(
67
+ `git`,
68
+ [`merge-base`, `origin/main`, `HEAD`],
69
+ {
70
+ encoding: `utf8`,
71
+ stdio: [`ignore`, `pipe`, `ignore`],
72
+ }
73
+ ).trim()
74
+
75
+ if (mergeBase.length > 0) {
76
+ return `${mergeBase}...HEAD`
77
+ }
78
+ } catch {}
79
+
80
+ return `HEAD~1..HEAD`
81
+ }
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env node
2
+
3
+ import {
4
+ analyzeTypeScriptClient,
5
+ formatAnalysisResult,
6
+ } from './lib/shape-stream-static-analysis.mjs'
7
+
8
+ const args = new Set(process.argv.slice(2))
9
+ const result = analyzeTypeScriptClient()
10
+ const findings = result.findings
11
+
12
+ if (args.has(`--json`)) {
13
+ console.log(JSON.stringify(result, null, 2))
14
+ } else {
15
+ console.log(formatAnalysisResult(result))
16
+ }
17
+
18
+ if (args.has(`--fail-on-findings`) && findings.length > 0) {
19
+ process.exitCode = 1
20
+ }