@chainlink/cre-sdk 1.6.0-alpha.2 → 1.6.0-alpha.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/README.md +7 -1
- package/bin/cre-compile.ts +34 -17
- package/dist/generated/capabilities/blockchain/aptos/v1alpha/client_pb.d.ts +1023 -0
- package/dist/generated/capabilities/blockchain/aptos/v1alpha/client_pb.js +290 -0
- package/dist/generated/capabilities/blockchain/solana/v1alpha/client_pb.d.ts +2904 -0
- package/dist/generated/capabilities/blockchain/solana/v1alpha/client_pb.js +506 -0
- package/dist/generated-sdk/capabilities/blockchain/aptos/v1alpha/client_sdk_gen.d.ts +52 -0
- package/dist/generated-sdk/capabilities/blockchain/aptos/v1alpha/client_sdk_gen.js +186 -0
- package/dist/generated-sdk/capabilities/blockchain/solana/v1alpha/client_sdk_gen.d.ts +92 -0
- package/dist/generated-sdk/capabilities/blockchain/solana/v1alpha/client_sdk_gen.js +343 -0
- package/dist/sdk/cre/index.d.ts +6 -0
- package/dist/sdk/cre/index.js +8 -0
- package/dist/sdk/report.js +0 -15
- package/dist/sdk/test/generated/capabilities/blockchain/aptos/v1alpha/aptos_mock_gen.d.ts +25 -0
- package/dist/sdk/test/generated/capabilities/blockchain/aptos/v1alpha/aptos_mock_gen.js +111 -0
- package/dist/sdk/test/generated/capabilities/blockchain/solana/v1alpha/solana_mock_gen.d.ts +33 -0
- package/dist/sdk/test/generated/capabilities/blockchain/solana/v1alpha/solana_mock_gen.js +178 -0
- package/dist/sdk/test/generated/index.d.ts +2 -0
- package/dist/sdk/test/generated/index.js +2 -0
- package/package.json +3 -3
- package/scripts/run-standard-tests.sh +3 -3
- package/scripts/run.ts +6 -1
- package/scripts/src/check-determinism.test.ts +64 -0
- package/scripts/src/check-determinism.ts +32 -0
- package/scripts/src/compile-cli-args.test.ts +32 -0
- package/scripts/src/compile-cli-args.ts +35 -0
- package/scripts/src/compile-to-js.test.ts +90 -0
- package/scripts/src/compile-to-js.ts +53 -7
- package/scripts/src/compile-to-wasm.ts +18 -32
- package/scripts/src/compile-workflow.ts +55 -27
- package/scripts/src/generate-chain-selectors.ts +9 -27
- package/scripts/src/generate-sdks.ts +12 -0
- package/scripts/src/typecheck-workflow.test.ts +77 -0
- package/scripts/src/typecheck-workflow.ts +96 -0
- package/scripts/src/validate-shared.ts +400 -0
- package/scripts/src/validate-workflow-determinism.test.ts +409 -0
- package/scripts/src/validate-workflow-determinism.ts +545 -0
- package/scripts/src/validate-workflow-runtime-compat.ts +25 -377
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export const skipTypeChecksFlag = '--skip-type-checks'
|
|
2
|
+
|
|
3
|
+
export type ParsedCompileArgs = {
|
|
4
|
+
inputPath?: string
|
|
5
|
+
outputPath?: string
|
|
6
|
+
skipTypeChecks: boolean
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const parseCompileCliArgs = (args: string[]): ParsedCompileArgs => {
|
|
10
|
+
const positionalArgs: string[] = []
|
|
11
|
+
let skipTypeChecks = false
|
|
12
|
+
|
|
13
|
+
for (const arg of args) {
|
|
14
|
+
if (arg === skipTypeChecksFlag) {
|
|
15
|
+
skipTypeChecks = true
|
|
16
|
+
continue
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (arg.startsWith('-')) {
|
|
20
|
+
throw new Error(`Unknown option: ${arg}`)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
positionalArgs.push(arg)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (positionalArgs.length > 2) {
|
|
27
|
+
throw new Error('Too many positional arguments.')
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return {
|
|
31
|
+
inputPath: positionalArgs[0],
|
|
32
|
+
outputPath: positionalArgs[1],
|
|
33
|
+
skipTypeChecks,
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, test } from 'bun:test'
|
|
2
|
+
import { existsSync, mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs'
|
|
3
|
+
import path from 'node:path'
|
|
4
|
+
import { main as compileToJs } from './compile-to-js'
|
|
5
|
+
import { WorkflowTypecheckError } from './typecheck-workflow'
|
|
6
|
+
|
|
7
|
+
let tempDir: string
|
|
8
|
+
|
|
9
|
+
beforeEach(() => {
|
|
10
|
+
tempDir = mkdtempSync(path.join(process.cwd(), '.tmp-cre-compile-to-js-test-'))
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
afterEach(() => {
|
|
14
|
+
rmSync(tempDir, { recursive: true, force: true })
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
const writeTemp = (filename: string, content: string): string => {
|
|
18
|
+
const filePath = path.join(tempDir, filename)
|
|
19
|
+
mkdirSync(path.dirname(filePath), { recursive: true })
|
|
20
|
+
writeFileSync(filePath, content, 'utf-8')
|
|
21
|
+
return filePath
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
describe('compile-to-js typecheck behavior', () => {
|
|
25
|
+
test('fails on type errors by default', async () => {
|
|
26
|
+
writeTemp(
|
|
27
|
+
'tsconfig.json',
|
|
28
|
+
JSON.stringify(
|
|
29
|
+
{
|
|
30
|
+
compilerOptions: {
|
|
31
|
+
target: 'ES2022',
|
|
32
|
+
module: 'ESNext',
|
|
33
|
+
moduleResolution: 'Bundler',
|
|
34
|
+
skipLibCheck: true,
|
|
35
|
+
strict: true,
|
|
36
|
+
types: [],
|
|
37
|
+
lib: ['ESNext'],
|
|
38
|
+
},
|
|
39
|
+
include: ['src/**/*.ts'],
|
|
40
|
+
},
|
|
41
|
+
null,
|
|
42
|
+
2,
|
|
43
|
+
),
|
|
44
|
+
)
|
|
45
|
+
const entry = writeTemp('src/workflow.ts', "export const shouldBeNumber: number = 'oops'\n")
|
|
46
|
+
const output = path.join(tempDir, 'dist/workflow.js')
|
|
47
|
+
|
|
48
|
+
await expect(compileToJs(entry, output)).rejects.toBeInstanceOf(WorkflowTypecheckError)
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
test('continues when --skip-type-checks is enabled', async () => {
|
|
52
|
+
writeTemp(
|
|
53
|
+
'tsconfig.json',
|
|
54
|
+
JSON.stringify(
|
|
55
|
+
{
|
|
56
|
+
compilerOptions: {
|
|
57
|
+
target: 'ES2022',
|
|
58
|
+
module: 'ESNext',
|
|
59
|
+
moduleResolution: 'Bundler',
|
|
60
|
+
skipLibCheck: true,
|
|
61
|
+
strict: true,
|
|
62
|
+
types: [],
|
|
63
|
+
lib: ['ESNext'],
|
|
64
|
+
},
|
|
65
|
+
include: ['src/**/*.ts'],
|
|
66
|
+
},
|
|
67
|
+
null,
|
|
68
|
+
2,
|
|
69
|
+
),
|
|
70
|
+
)
|
|
71
|
+
const entry = writeTemp('src/workflow.ts', "export const shouldBeNumber: number = 'oops'\n")
|
|
72
|
+
const output = path.join(tempDir, 'dist/workflow.js')
|
|
73
|
+
|
|
74
|
+
let thrownError: unknown
|
|
75
|
+
let result: string | undefined
|
|
76
|
+
try {
|
|
77
|
+
result = await compileToJs(entry, output, {
|
|
78
|
+
skipTypeChecks: true,
|
|
79
|
+
})
|
|
80
|
+
} catch (error) {
|
|
81
|
+
thrownError = error
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
expect(thrownError).not.toBeInstanceOf(WorkflowTypecheckError)
|
|
85
|
+
if (typeof result === 'string') {
|
|
86
|
+
expect(result).toEqual(output)
|
|
87
|
+
expect(existsSync(output)).toBeTrue()
|
|
88
|
+
}
|
|
89
|
+
})
|
|
90
|
+
})
|
|
@@ -2,25 +2,71 @@ import { existsSync, readFileSync, unlinkSync, writeFileSync } from 'node:fs'
|
|
|
2
2
|
import { mkdir } from 'node:fs/promises'
|
|
3
3
|
import path from 'node:path'
|
|
4
4
|
import { $ } from 'bun'
|
|
5
|
+
import { parseCompileCliArgs, skipTypeChecksFlag } from './compile-cli-args'
|
|
6
|
+
import { assertWorkflowTypecheck } from './typecheck-workflow'
|
|
7
|
+
import { checkWorkflowDeterminism, printDeterminismWarnings } from './validate-workflow-determinism'
|
|
5
8
|
import { assertWorkflowRuntimeCompatibility } from './validate-workflow-runtime-compat'
|
|
6
9
|
import { wrapWorkflowCode } from './workflow-wrapper'
|
|
7
10
|
|
|
8
|
-
|
|
9
|
-
|
|
11
|
+
type CompileToJsOptions = {
|
|
12
|
+
skipTypeChecks?: boolean
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const printUsage = () => {
|
|
16
|
+
console.error(`Usage: bun compile:ts-to-js <path-to-file> [output-file] [${skipTypeChecksFlag}]`)
|
|
17
|
+
console.error('Example:')
|
|
18
|
+
console.error(' bun compile:ts-to-js src/tests/foo.ts dist/tests/foo.bundle.js')
|
|
19
|
+
console.error(
|
|
20
|
+
` bun compile:ts-to-js src/tests/foo.ts dist/tests/foo.bundle.js ${skipTypeChecksFlag}`,
|
|
21
|
+
)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export const main = async (
|
|
25
|
+
tsFilePath?: string,
|
|
26
|
+
outputFilePath?: string,
|
|
27
|
+
options?: CompileToJsOptions,
|
|
28
|
+
) => {
|
|
29
|
+
let parsedInputPath: string | undefined
|
|
30
|
+
let parsedOutputPath: string | undefined
|
|
31
|
+
let parsedSkipTypeChecks = false
|
|
32
|
+
|
|
33
|
+
if (tsFilePath != null || outputFilePath != null || options?.skipTypeChecks != null) {
|
|
34
|
+
parsedInputPath = tsFilePath
|
|
35
|
+
parsedOutputPath = outputFilePath
|
|
36
|
+
parsedSkipTypeChecks = options?.skipTypeChecks ?? false
|
|
37
|
+
} else {
|
|
38
|
+
try {
|
|
39
|
+
const parsed = parseCompileCliArgs(process.argv.slice(3))
|
|
40
|
+
parsedInputPath = parsed.inputPath
|
|
41
|
+
parsedOutputPath = parsed.outputPath
|
|
42
|
+
parsedSkipTypeChecks = parsed.skipTypeChecks
|
|
43
|
+
} catch (error) {
|
|
44
|
+
console.error(error instanceof Error ? error.message : error)
|
|
45
|
+
printUsage()
|
|
46
|
+
process.exit(1)
|
|
47
|
+
}
|
|
48
|
+
}
|
|
10
49
|
|
|
11
50
|
// Prefer function params, fallback to CLI args
|
|
12
|
-
const inputPath =
|
|
13
|
-
const outputPathArg =
|
|
51
|
+
const inputPath = parsedInputPath
|
|
52
|
+
const outputPathArg = parsedOutputPath
|
|
14
53
|
|
|
15
54
|
if (!inputPath) {
|
|
16
|
-
|
|
17
|
-
console.error('Example:')
|
|
18
|
-
console.error(' bun test:standard:compile:js src/tests/foo.ts dist/tests/foo.bundle.js')
|
|
55
|
+
printUsage()
|
|
19
56
|
process.exit(1)
|
|
20
57
|
}
|
|
21
58
|
|
|
22
59
|
const resolvedInput = path.resolve(inputPath)
|
|
60
|
+
if (!parsedSkipTypeChecks) {
|
|
61
|
+
assertWorkflowTypecheck(resolvedInput)
|
|
62
|
+
}
|
|
23
63
|
assertWorkflowRuntimeCompatibility(resolvedInput)
|
|
64
|
+
if (!parsedSkipTypeChecks) {
|
|
65
|
+
const warnings = checkWorkflowDeterminism(resolvedInput)
|
|
66
|
+
if (warnings.length > 0) {
|
|
67
|
+
printDeterminismWarnings(warnings)
|
|
68
|
+
}
|
|
69
|
+
}
|
|
24
70
|
console.info(`📁 Using input file: ${resolvedInput}`)
|
|
25
71
|
|
|
26
72
|
// If no explicit output path → same dir, swap extension to .js
|
|
@@ -2,7 +2,6 @@ import { spawn } from 'node:child_process'
|
|
|
2
2
|
import { existsSync } from 'node:fs'
|
|
3
3
|
import { mkdir } from 'node:fs/promises'
|
|
4
4
|
import path from 'node:path'
|
|
5
|
-
import { parseCompileFlags } from '../../../cre-sdk-javy-plugin/scripts/parse-compile-flags'
|
|
6
5
|
|
|
7
6
|
function runBun(args: string[]): Promise<void> {
|
|
8
7
|
return new Promise((resolve, reject) => {
|
|
@@ -20,29 +19,20 @@ function runBun(args: string[]): Promise<void> {
|
|
|
20
19
|
|
|
21
20
|
const isJsFile = (p: string) => ['.js', '.mjs', '.cjs'].includes(path.extname(p).toLowerCase())
|
|
22
21
|
|
|
23
|
-
export const main = async (
|
|
24
|
-
inputFile?: string,
|
|
25
|
-
outputFile?: string,
|
|
26
|
-
creExportsPaths?: string[],
|
|
27
|
-
pluginPath?: string | null,
|
|
28
|
-
) => {
|
|
22
|
+
export const main = async (inputFile?: string, outputFile?: string) => {
|
|
29
23
|
const cliArgs = process.argv.slice(3)
|
|
30
|
-
const { creExports: cliCreExports, plugin: cliPlugin, rest: cliRest } = parseCompileFlags(cliArgs)
|
|
31
24
|
|
|
32
|
-
|
|
33
|
-
const
|
|
34
|
-
const
|
|
35
|
-
const plugin = pluginPath !== undefined ? pluginPath : cliPlugin
|
|
36
|
-
|
|
37
|
-
if (plugin !== null && plugin !== undefined && creExports.length > 0) {
|
|
38
|
-
console.error('❌ Error: --plugin and --cre-exports are mutually exclusive.')
|
|
39
|
-
process.exit(1)
|
|
40
|
-
}
|
|
25
|
+
// Resolve input/output from params or CLI
|
|
26
|
+
const inputPath = inputFile ?? cliArgs[0]
|
|
27
|
+
const outputPathArg = outputFile ?? cliArgs[1]
|
|
41
28
|
|
|
42
29
|
if (!inputPath) {
|
|
43
30
|
console.error(
|
|
44
31
|
'Usage: bun compile:js-to-wasm <path/to/input.(js|mjs|cjs)> [path/to/output.wasm]',
|
|
45
32
|
)
|
|
33
|
+
console.error('Examples:')
|
|
34
|
+
console.error(' bun compile:js-to-wasm ./build/workflows/test.js')
|
|
35
|
+
console.error(' bun compile:js-to-wasm ./build/workflows/test.mjs ./artifacts/test.wasm')
|
|
46
36
|
process.exit(1)
|
|
47
37
|
}
|
|
48
38
|
|
|
@@ -57,35 +47,31 @@ export const main = async (
|
|
|
57
47
|
process.exit(1)
|
|
58
48
|
}
|
|
59
49
|
|
|
50
|
+
// Default output = same dir, same basename, .wasm extension
|
|
60
51
|
const defaultOut = path.join(
|
|
61
52
|
path.dirname(resolvedInput),
|
|
62
53
|
path.basename(resolvedInput).replace(/\.(m|c)?js$/i, '.wasm'),
|
|
63
54
|
)
|
|
64
55
|
const resolvedOutput = outputPathArg ? path.resolve(outputPathArg) : defaultOut
|
|
65
56
|
|
|
57
|
+
// Ensure output directory exists
|
|
66
58
|
await mkdir(path.dirname(resolvedOutput), { recursive: true })
|
|
67
59
|
|
|
68
|
-
console.info(
|
|
60
|
+
console.info(`🔨 Compiling to WASM`)
|
|
69
61
|
console.info(`📁 Input: ${resolvedInput}`)
|
|
70
62
|
console.info(`🎯 Output: ${resolvedOutput}`)
|
|
71
63
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
compileArgs.push('--plugin', path.resolve(plugin))
|
|
75
|
-
} else {
|
|
76
|
-
compileArgs.push(...creExports.flatMap((p) => ['--cre-exports', path.resolve(p)]))
|
|
77
|
-
}
|
|
78
|
-
compileArgs.push(resolvedInput, resolvedOutput)
|
|
79
|
-
|
|
64
|
+
// Prefer the sibling @chainlink/cre-sdk-javy-plugin install (same as monorepo layout).
|
|
65
|
+
// Bun's shell `$` template can throw EINVAL on some Linux/arm64 Docker setups; use spawn.
|
|
80
66
|
const scriptDir = import.meta.dir
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
67
|
+
const compilerPath = path.resolve(
|
|
68
|
+
scriptDir,
|
|
69
|
+
'../../../cre-sdk-javy-plugin/bin/compile-workflow.ts',
|
|
70
|
+
)
|
|
85
71
|
if (existsSync(compilerPath)) {
|
|
86
|
-
await runBun(['--bun', compilerPath,
|
|
72
|
+
await runBun(['--bun', compilerPath, resolvedInput, resolvedOutput])
|
|
87
73
|
} else {
|
|
88
|
-
await runBun(['x', 'cre-compile-workflow',
|
|
74
|
+
await runBun(['x', 'cre-compile-workflow', resolvedInput, resolvedOutput])
|
|
89
75
|
}
|
|
90
76
|
|
|
91
77
|
console.info(`✅ Compiled: ${resolvedOutput}`)
|
|
@@ -1,31 +1,59 @@
|
|
|
1
1
|
import { existsSync } from 'node:fs'
|
|
2
2
|
import { mkdir } from 'node:fs/promises'
|
|
3
3
|
import path from 'node:path'
|
|
4
|
-
import {
|
|
4
|
+
import { parseCompileCliArgs, skipTypeChecksFlag } from './compile-cli-args'
|
|
5
5
|
import { main as compileToJs } from './compile-to-js'
|
|
6
6
|
import { main as compileToWasm } from './compile-to-wasm'
|
|
7
7
|
|
|
8
|
+
type CompileWorkflowOptions = {
|
|
9
|
+
skipTypeChecks?: boolean
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const printUsage = () => {
|
|
13
|
+
console.error(
|
|
14
|
+
`Usage: bun compile:workflow <path/to/workflow.ts> [path/to/output.wasm] [${skipTypeChecksFlag}]`,
|
|
15
|
+
)
|
|
16
|
+
console.error('Examples:')
|
|
17
|
+
console.error(' bun compile:workflow src/standard_tests/secrets/test.ts')
|
|
18
|
+
console.error(
|
|
19
|
+
' bun compile:workflow src/standard_tests/secrets/test.ts .temp/standard_tests/secrets/test.wasm',
|
|
20
|
+
)
|
|
21
|
+
console.error(
|
|
22
|
+
` bun compile:workflow src/standard_tests/secrets/test.ts .temp/standard_tests/secrets/test.wasm ${skipTypeChecksFlag}`,
|
|
23
|
+
)
|
|
24
|
+
}
|
|
25
|
+
|
|
8
26
|
export const main = async (
|
|
9
27
|
inputFile?: string,
|
|
10
28
|
outputWasmFile?: string,
|
|
11
|
-
|
|
12
|
-
pluginPath?: string | null,
|
|
29
|
+
options?: CompileWorkflowOptions,
|
|
13
30
|
) => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const inputPath = inputFile ?? cliRest[0]
|
|
18
|
-
const outputPathArg = outputWasmFile ?? cliRest[1]
|
|
19
|
-
const creExports = creExportsPaths ?? cliCreExports
|
|
20
|
-
const plugin = pluginPath !== undefined ? pluginPath : cliPlugin
|
|
31
|
+
let parsedInputPath: string | undefined
|
|
32
|
+
let parsedOutputPath: string | undefined
|
|
33
|
+
let parsedSkipTypeChecks = false
|
|
21
34
|
|
|
22
|
-
if (
|
|
23
|
-
|
|
24
|
-
|
|
35
|
+
if (inputFile != null || outputWasmFile != null || options?.skipTypeChecks != null) {
|
|
36
|
+
parsedInputPath = inputFile
|
|
37
|
+
parsedOutputPath = outputWasmFile
|
|
38
|
+
parsedSkipTypeChecks = options?.skipTypeChecks ?? false
|
|
39
|
+
} else {
|
|
40
|
+
try {
|
|
41
|
+
const parsed = parseCompileCliArgs(process.argv.slice(3))
|
|
42
|
+
parsedInputPath = parsed.inputPath
|
|
43
|
+
parsedOutputPath = parsed.outputPath
|
|
44
|
+
parsedSkipTypeChecks = parsed.skipTypeChecks
|
|
45
|
+
} catch (error) {
|
|
46
|
+
console.error(error instanceof Error ? error.message : error)
|
|
47
|
+
printUsage()
|
|
48
|
+
process.exit(1)
|
|
49
|
+
}
|
|
25
50
|
}
|
|
26
51
|
|
|
52
|
+
const inputPath = parsedInputPath
|
|
53
|
+
const outputPathArg = parsedOutputPath
|
|
54
|
+
|
|
27
55
|
if (!inputPath) {
|
|
28
|
-
|
|
56
|
+
printUsage()
|
|
29
57
|
process.exit(1)
|
|
30
58
|
}
|
|
31
59
|
|
|
@@ -35,33 +63,33 @@ export const main = async (
|
|
|
35
63
|
process.exit(1)
|
|
36
64
|
}
|
|
37
65
|
|
|
66
|
+
// Default final output = same dir, same basename, .wasm
|
|
38
67
|
const defaultWasmOut = path.join(
|
|
39
68
|
path.dirname(resolvedInput),
|
|
40
69
|
path.basename(resolvedInput).replace(/\.[^.]+$/, '.wasm'),
|
|
41
70
|
)
|
|
42
71
|
const resolvedWasmOutput = outputPathArg ? path.resolve(outputPathArg) : defaultWasmOut
|
|
72
|
+
|
|
73
|
+
// Put the intermediate JS next to the final wasm (so custom outputs stay together)
|
|
43
74
|
const resolvedJsOutput = resolvedWasmOutput.replace(/\.wasm$/i, '.js')
|
|
44
75
|
|
|
76
|
+
// Ensure directories exist (handles both intermediate JS dir and wasm dir)
|
|
45
77
|
await mkdir(path.dirname(resolvedJsOutput), { recursive: true })
|
|
46
78
|
|
|
47
|
-
console.info(
|
|
48
|
-
console.info(`📁 Input: ${resolvedInput}`)
|
|
49
|
-
|
|
50
|
-
|
|
79
|
+
console.info(`🚀 Compiling workflow`)
|
|
80
|
+
console.info(`📁 Input: ${resolvedInput}\n`)
|
|
81
|
+
if (parsedSkipTypeChecks) {
|
|
82
|
+
console.info(`⚠️ Skipping TypeScript checks (${skipTypeChecksFlag})`)
|
|
83
|
+
}
|
|
51
84
|
|
|
85
|
+
// Step 1: TS/JS → JS (bundled)
|
|
52
86
|
console.info('📦 Step 1: Compiling JS...')
|
|
53
|
-
await compileToJs(resolvedInput, resolvedJsOutput)
|
|
87
|
+
await compileToJs(resolvedInput, resolvedJsOutput, { skipTypeChecks: parsedSkipTypeChecks })
|
|
54
88
|
|
|
89
|
+
// Step 2: JS → WASM
|
|
55
90
|
console.info('\n🔨 Step 2: Compiling to WASM...')
|
|
56
|
-
await compileToWasm(resolvedJsOutput, resolvedWasmOutput
|
|
91
|
+
await compileToWasm(resolvedJsOutput, resolvedWasmOutput)
|
|
57
92
|
|
|
58
93
|
console.info(`\n✅ Workflow built: ${resolvedWasmOutput}`)
|
|
59
94
|
return resolvedWasmOutput
|
|
60
95
|
}
|
|
61
|
-
|
|
62
|
-
if (import.meta.main) {
|
|
63
|
-
main().catch((e) => {
|
|
64
|
-
console.error(e)
|
|
65
|
-
process.exit(1)
|
|
66
|
-
})
|
|
67
|
-
}
|
|
@@ -78,34 +78,16 @@ const CHAIN_CONFIGS: ChainSelectorConfig[] = [
|
|
|
78
78
|
},
|
|
79
79
|
]
|
|
80
80
|
|
|
81
|
-
const
|
|
82
|
-
//
|
|
83
|
-
//
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
// Try 2 levels up (in case cwd is already in scripts/src/)
|
|
88
|
-
join(process.cwd(), '..', '..', 'node_modules', 'chain-selectors', filename),
|
|
89
|
-
// Try current directory's node_modules
|
|
90
|
-
join(process.cwd(), 'node_modules', 'chain-selectors', filename),
|
|
91
|
-
// Try parent directory's node_modules
|
|
92
|
-
join(process.cwd(), '..', 'node_modules', 'chain-selectors', filename),
|
|
93
|
-
]
|
|
94
|
-
|
|
95
|
-
for (const path of possiblePaths) {
|
|
96
|
-
try {
|
|
97
|
-
return readFileSync(path, 'utf-8')
|
|
98
|
-
} catch {
|
|
99
|
-
// Try next path
|
|
100
|
-
continue
|
|
101
|
-
}
|
|
102
|
-
}
|
|
81
|
+
const resolveChainSelectorsDir = (): string => {
|
|
82
|
+
// Use require.resolve to find the package through bun/Node module resolution,
|
|
83
|
+
// which correctly handles workspace hoisting, .bun cache, etc.
|
|
84
|
+
const packageDir = require.resolve('chain-selectors/selectors.yml')
|
|
85
|
+
return join(packageDir, '..')
|
|
86
|
+
}
|
|
103
87
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
)}`,
|
|
108
|
-
)
|
|
88
|
+
const readYamlFile = (filename: string): string => {
|
|
89
|
+
const filePath = join(resolveChainSelectorsDir(), filename)
|
|
90
|
+
return readFileSync(filePath, 'utf-8')
|
|
109
91
|
}
|
|
110
92
|
|
|
111
93
|
const parseChainSelectors = (): NetworkInfo[] => {
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { rmSync } from 'node:fs'
|
|
2
|
+
import { file_capabilities_blockchain_aptos_v1alpha_client } from '@cre/generated/capabilities/blockchain/aptos/v1alpha/client_pb'
|
|
2
3
|
import { file_capabilities_blockchain_evm_v1alpha_client } from '@cre/generated/capabilities/blockchain/evm/v1alpha/client_pb'
|
|
4
|
+
import { file_capabilities_blockchain_solana_v1alpha_client } from '@cre/generated/capabilities/blockchain/solana/v1alpha/client_pb'
|
|
3
5
|
import { file_capabilities_internal_actionandtrigger_v1_action_and_trigger } from '@cre/generated/capabilities/internal/actionandtrigger/v1/action_and_trigger_pb'
|
|
4
6
|
import { file_capabilities_internal_basicaction_v1_basic_action } from '@cre/generated/capabilities/internal/basicaction/v1/basic_action_pb'
|
|
5
7
|
import { file_capabilities_internal_basictrigger_v1_basic_trigger } from '@cre/generated/capabilities/internal/basictrigger/v1/basic_trigger_pb'
|
|
@@ -63,6 +65,16 @@ export const main = () => {
|
|
|
63
65
|
...generateMocks(file_capabilities_blockchain_evm_v1alpha_client, TEST_GENERATED_DIR),
|
|
64
66
|
)
|
|
65
67
|
|
|
68
|
+
generateSdk(file_capabilities_blockchain_aptos_v1alpha_client, './src/generated-sdk')
|
|
69
|
+
allMockExports.push(
|
|
70
|
+
...generateMocks(file_capabilities_blockchain_aptos_v1alpha_client, TEST_GENERATED_DIR),
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
generateSdk(file_capabilities_blockchain_solana_v1alpha_client, './src/generated-sdk')
|
|
74
|
+
allMockExports.push(
|
|
75
|
+
...generateMocks(file_capabilities_blockchain_solana_v1alpha_client, TEST_GENERATED_DIR),
|
|
76
|
+
)
|
|
77
|
+
|
|
66
78
|
generateSdk(file_capabilities_networking_http_v1alpha_client, './src/generated-sdk')
|
|
67
79
|
allMockExports.push(
|
|
68
80
|
...generateMocks(file_capabilities_networking_http_v1alpha_client, TEST_GENERATED_DIR),
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, test } from 'bun:test'
|
|
2
|
+
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs'
|
|
3
|
+
import { tmpdir } from 'node:os'
|
|
4
|
+
import path from 'node:path'
|
|
5
|
+
import { assertWorkflowTypecheck, WorkflowTypecheckError } from './typecheck-workflow'
|
|
6
|
+
|
|
7
|
+
let tempDir: string
|
|
8
|
+
|
|
9
|
+
beforeEach(() => {
|
|
10
|
+
tempDir = mkdtempSync(path.join(tmpdir(), 'cre-typecheck-test-'))
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
afterEach(() => {
|
|
14
|
+
rmSync(tempDir, { recursive: true, force: true })
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
const writeTemp = (filename: string, content: string): string => {
|
|
18
|
+
const filePath = path.join(tempDir, filename)
|
|
19
|
+
mkdirSync(path.dirname(filePath), { recursive: true })
|
|
20
|
+
writeFileSync(filePath, content, 'utf-8')
|
|
21
|
+
return filePath
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
describe('assertWorkflowTypecheck', () => {
|
|
25
|
+
test('passes for valid project using nearby tsconfig', () => {
|
|
26
|
+
writeTemp(
|
|
27
|
+
'tsconfig.json',
|
|
28
|
+
JSON.stringify(
|
|
29
|
+
{
|
|
30
|
+
compilerOptions: {
|
|
31
|
+
target: 'ES2022',
|
|
32
|
+
module: 'ESNext',
|
|
33
|
+
moduleResolution: 'Bundler',
|
|
34
|
+
skipLibCheck: true,
|
|
35
|
+
},
|
|
36
|
+
include: ['src/**/*.ts'],
|
|
37
|
+
},
|
|
38
|
+
null,
|
|
39
|
+
2,
|
|
40
|
+
),
|
|
41
|
+
)
|
|
42
|
+
const entry = writeTemp('src/workflow.ts', 'export const value: number = 42\n')
|
|
43
|
+
expect(() => assertWorkflowTypecheck(entry)).not.toThrow()
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
test('fails when tsconfig cannot be found', () => {
|
|
47
|
+
const entry = writeTemp('src/workflow.ts', 'export const value = 1\n')
|
|
48
|
+
expect(() => assertWorkflowTypecheck(entry)).toThrow(WorkflowTypecheckError)
|
|
49
|
+
expect(() => assertWorkflowTypecheck(entry)).toThrow('Could not find tsconfig.json')
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
test('fails on whole-project type errors outside entry file', () => {
|
|
53
|
+
writeTemp(
|
|
54
|
+
'tsconfig.json',
|
|
55
|
+
JSON.stringify(
|
|
56
|
+
{
|
|
57
|
+
compilerOptions: {
|
|
58
|
+
target: 'ES2022',
|
|
59
|
+
module: 'ESNext',
|
|
60
|
+
moduleResolution: 'Bundler',
|
|
61
|
+
skipLibCheck: true,
|
|
62
|
+
strict: true,
|
|
63
|
+
},
|
|
64
|
+
include: ['src/**/*.ts'],
|
|
65
|
+
},
|
|
66
|
+
null,
|
|
67
|
+
2,
|
|
68
|
+
),
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
const entry = writeTemp('src/workflow.ts', 'export const value: number = 1\n')
|
|
72
|
+
writeTemp('src/unrelated.ts', "export const shouldBeNumber: number = 'not-a-number'\n")
|
|
73
|
+
|
|
74
|
+
expect(() => assertWorkflowTypecheck(entry)).toThrow(WorkflowTypecheckError)
|
|
75
|
+
expect(() => assertWorkflowTypecheck(entry)).toThrow('unrelated.ts')
|
|
76
|
+
})
|
|
77
|
+
})
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import path from 'node:path'
|
|
2
|
+
import * as ts from 'typescript'
|
|
3
|
+
import { skipTypeChecksFlag } from './compile-cli-args'
|
|
4
|
+
|
|
5
|
+
const toAbsolutePath = (filePath: string) => path.resolve(filePath)
|
|
6
|
+
|
|
7
|
+
const formatDiagnostic = (diagnostic: ts.Diagnostic): string => {
|
|
8
|
+
const message = ts.flattenDiagnosticMessageText(diagnostic.messageText, '\n')
|
|
9
|
+
if (!diagnostic.file || diagnostic.start == null) {
|
|
10
|
+
return message
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const absoluteFilePath = toAbsolutePath(diagnostic.file.fileName)
|
|
14
|
+
const relativeFilePath = path.relative(process.cwd(), absoluteFilePath)
|
|
15
|
+
const displayPath = relativeFilePath || absoluteFilePath
|
|
16
|
+
const { line, character } = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start)
|
|
17
|
+
return `${displayPath}:${line + 1}:${character + 1} ${message}`
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
class WorkflowTypecheckError extends Error {
|
|
21
|
+
constructor(message: string) {
|
|
22
|
+
super(message)
|
|
23
|
+
this.name = 'WorkflowTypecheckError'
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const findNearestTsconfigPath = (entryFilePath: string): string | null => {
|
|
28
|
+
const configPath = ts.findConfigFile(
|
|
29
|
+
path.dirname(entryFilePath),
|
|
30
|
+
ts.sys.fileExists,
|
|
31
|
+
'tsconfig.json',
|
|
32
|
+
)
|
|
33
|
+
return configPath ?? null
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export const assertWorkflowTypecheck = (entryFilePath: string) => {
|
|
37
|
+
const rootFile = toAbsolutePath(entryFilePath)
|
|
38
|
+
const configPath = findNearestTsconfigPath(rootFile)
|
|
39
|
+
if (!configPath) {
|
|
40
|
+
throw new WorkflowTypecheckError(
|
|
41
|
+
`TypeScript typecheck failed before workflow compilation.
|
|
42
|
+
Could not find tsconfig.json near: ${rootFile}
|
|
43
|
+
Create a tsconfig.json in your workflow project, or re-run compile with ${skipTypeChecksFlag}.`,
|
|
44
|
+
)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
let unrecoverableDiagnostic: ts.Diagnostic | null = null
|
|
48
|
+
const parsedConfig = ts.getParsedCommandLineOfConfigFile(
|
|
49
|
+
configPath,
|
|
50
|
+
{},
|
|
51
|
+
{
|
|
52
|
+
...ts.sys,
|
|
53
|
+
onUnRecoverableConfigFileDiagnostic: (diagnostic) => {
|
|
54
|
+
unrecoverableDiagnostic = diagnostic
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
if (!parsedConfig) {
|
|
60
|
+
const details = unrecoverableDiagnostic ? formatDiagnostic(unrecoverableDiagnostic) : ''
|
|
61
|
+
throw new WorkflowTypecheckError(
|
|
62
|
+
`TypeScript typecheck failed before workflow compilation.
|
|
63
|
+
Failed to parse tsconfig.json: ${configPath}
|
|
64
|
+
${details}
|
|
65
|
+
Fix your tsconfig.json, or re-run compile with ${skipTypeChecksFlag}.`,
|
|
66
|
+
)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const program = ts.createProgram({
|
|
70
|
+
rootNames: parsedConfig.fileNames,
|
|
71
|
+
options: {
|
|
72
|
+
...parsedConfig.options,
|
|
73
|
+
noEmit: true,
|
|
74
|
+
},
|
|
75
|
+
projectReferences: parsedConfig.projectReferences,
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
const diagnostics = [...parsedConfig.errors, ...ts.getPreEmitDiagnostics(program)].filter(
|
|
79
|
+
(diagnostic) => diagnostic.category === ts.DiagnosticCategory.Error,
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
if (diagnostics.length > 0) {
|
|
83
|
+
const formatted = diagnostics.map(formatDiagnostic).join('\n')
|
|
84
|
+
const relativeConfigPath = path.relative(process.cwd(), toAbsolutePath(configPath))
|
|
85
|
+
const displayConfigPath = relativeConfigPath || toAbsolutePath(configPath)
|
|
86
|
+
throw new WorkflowTypecheckError(
|
|
87
|
+
`TypeScript typecheck failed before workflow compilation.
|
|
88
|
+
Using tsconfig: ${displayConfigPath}
|
|
89
|
+
Fix TypeScript errors, or re-run compile with ${skipTypeChecksFlag}.
|
|
90
|
+
|
|
91
|
+
${formatted}`,
|
|
92
|
+
)
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export { WorkflowTypecheckError }
|