@chainlink/cre-sdk 1.4.0-alpha.1 → 1.5.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -7
- package/bin/cre-compile.ts +4 -25
- package/dist/generated/capabilities/blockchain/evm/v1alpha/client_pb.js +1 -1
- package/dist/generated-sdk/capabilities/blockchain/evm/v1alpha/client_sdk_gen.d.ts +2 -0
- package/dist/generated-sdk/capabilities/blockchain/evm/v1alpha/client_sdk_gen.js +2 -0
- package/package.json +3 -3
- package/scripts/run.ts +1 -5
- package/scripts/src/compile-to-js.ts +7 -46
- package/scripts/src/compile-to-wasm.ts +26 -14
- package/scripts/src/compile-workflow.ts +12 -51
- package/scripts/src/compile-cli-args.test.ts +0 -32
- package/scripts/src/compile-cli-args.ts +0 -35
- package/scripts/src/compile-to-js.test.ts +0 -90
- package/scripts/src/typecheck-workflow.test.ts +0 -77
- package/scripts/src/typecheck-workflow.ts +0 -96
package/README.md
CHANGED
|
@@ -58,16 +58,10 @@ CRE workflows are compiled to WASM and executed through Javy (QuickJS). This is
|
|
|
58
58
|
|
|
59
59
|
- Node built-ins like `node:fs`, `node:crypto`, `node:http`, `node:net`, etc. are not supported in workflows.
|
|
60
60
|
- Browser globals like `fetch`, `window`, and `setTimeout` are also not available in workflow runtime.
|
|
61
|
-
- `cre compile:workflow` / `cre-compile` now
|
|
61
|
+
- `cre compile:workflow` / `cre-compile` now validates workflow source and fails fast when unsupported APIs are used.
|
|
62
62
|
|
|
63
63
|
Use CRE capabilities (for example, `cre.capabilities.HTTPClient`) instead of direct Node/browser APIs.
|
|
64
64
|
|
|
65
|
-
If you need to compile despite TypeScript errors, pass `--skip-type-checks`:
|
|
66
|
-
|
|
67
|
-
```bash
|
|
68
|
-
bun x cre-compile src/workflow.ts dist/workflow.wasm --skip-type-checks
|
|
69
|
-
```
|
|
70
|
-
|
|
71
65
|
## Getting Started
|
|
72
66
|
|
|
73
67
|
We recommend you consult the [getting started docs](https://docs.chain.link/cre/getting-started/cli-installation) and install the CRE CLI.
|
package/bin/cre-compile.ts
CHANGED
|
@@ -1,50 +1,29 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
|
|
3
3
|
import { main as compileWorkflow } from "../scripts/src/compile-workflow";
|
|
4
|
-
import { parseCompileCliArgs, skipTypeChecksFlag } from "../scripts/src/compile-cli-args";
|
|
5
|
-
import { WorkflowTypecheckError } from "../scripts/src/typecheck-workflow";
|
|
6
4
|
import { WorkflowRuntimeCompatibilityError } from "../scripts/src/validate-workflow-runtime-compat";
|
|
7
5
|
|
|
8
6
|
const main = async () => {
|
|
9
|
-
|
|
10
|
-
let outputPathArg: string | undefined;
|
|
11
|
-
let skipTypeChecks = false;
|
|
12
|
-
|
|
13
|
-
try {
|
|
14
|
-
const parsed = parseCompileCliArgs(process.argv.slice(2));
|
|
15
|
-
inputPath = parsed.inputPath;
|
|
16
|
-
outputPathArg = parsed.outputPath;
|
|
17
|
-
skipTypeChecks = parsed.skipTypeChecks;
|
|
18
|
-
} catch (error) {
|
|
19
|
-
console.error(error instanceof Error ? error.message : error);
|
|
20
|
-
console.error(
|
|
21
|
-
`Usage: cre-compile <path/to/workflow.ts> [path/to/output.wasm] [${skipTypeChecksFlag}]`
|
|
22
|
-
);
|
|
23
|
-
process.exit(1);
|
|
24
|
-
}
|
|
7
|
+
const [inputPath, outputPathArg] = process.argv.slice(2);
|
|
25
8
|
|
|
26
9
|
if (!inputPath) {
|
|
27
10
|
console.error(
|
|
28
|
-
|
|
11
|
+
"Usage: cre-compile <path/to/workflow.ts> [path/to/output.wasm]"
|
|
29
12
|
);
|
|
30
13
|
console.error("Examples:");
|
|
31
14
|
console.error(" cre-compile src/standard_tests/secrets/test.ts");
|
|
32
15
|
console.error(
|
|
33
16
|
" cre-compile src/standard_tests/secrets/test.ts .temp/standard_tests/secrets/test.wasm"
|
|
34
17
|
);
|
|
35
|
-
console.error(
|
|
36
|
-
` cre-compile src/standard_tests/secrets/test.ts .temp/standard_tests/secrets/test.wasm ${skipTypeChecksFlag}`
|
|
37
|
-
);
|
|
38
18
|
process.exit(1);
|
|
39
19
|
}
|
|
40
20
|
|
|
41
|
-
|
|
42
|
-
await compileWorkflow(inputPath, outputPathArg, { skipTypeChecks });
|
|
21
|
+
await compileWorkflow(inputPath, outputPathArg);
|
|
43
22
|
};
|
|
44
23
|
|
|
45
24
|
// CLI entry point
|
|
46
25
|
main().catch((e) => {
|
|
47
|
-
if (e instanceof WorkflowRuntimeCompatibilityError
|
|
26
|
+
if (e instanceof WorkflowRuntimeCompatibilityError) {
|
|
48
27
|
console.error(`\n❌ ${e.message}`);
|
|
49
28
|
} else {
|
|
50
29
|
console.error(e);
|
|
@@ -10,7 +10,7 @@ import { file_values_v1_values } from '../../../../values/v1/values_pb';
|
|
|
10
10
|
*/
|
|
11
11
|
export const file_capabilities_blockchain_evm_v1alpha_client =
|
|
12
12
|
/*@__PURE__*/
|
|
13
|
-
fileDesc('
|
|
13
|
+
fileDesc('CjBjYXBhYmlsaXRpZXMvYmxvY2tjaGFpbi9ldm0vdjFhbHBoYS9jbGllbnQucHJvdG8SI2NhcGFiaWxpdGllcy5ibG9ja2NoYWluLmV2bS52MWFscGhhIh0KC1RvcGljVmFsdWVzEg4KBnZhbHVlcxgBIAMoDCK4AQoXRmlsdGVyTG9nVHJpZ2dlclJlcXVlc3QSEQoJYWRkcmVzc2VzGAEgAygMEkAKBnRvcGljcxgCIAMoCzIwLmNhcGFiaWxpdGllcy5ibG9ja2NoYWluLmV2bS52MWFscGhhLlRvcGljVmFsdWVzEkgKCmNvbmZpZGVuY2UYAyABKA4yNC5jYXBhYmlsaXRpZXMuYmxvY2tjaGFpbi5ldm0udjFhbHBoYS5Db25maWRlbmNlTGV2ZWwiegoTQ2FsbENvbnRyYWN0UmVxdWVzdBI6CgRjYWxsGAEgASgLMiwuY2FwYWJpbGl0aWVzLmJsb2NrY2hhaW4uZXZtLnYxYWxwaGEuQ2F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SmyFQKHgoRbWVnYWV0aC10ZXN0bmV0LTIQ443eiLGP/ZP9AQokChdwaGFyb3MtYXRsYW50aWMtdGVzdG5ldBDMme3gzryvtN8BChoKDnBoYXJvcy1tYWlubmV0EMjBh571782hbAobCg5wbGFzbWEtbWFpbm5ldBD4m/HR2snVxoEBChoKDnBsYXNtYS10ZXN0bmV0ENWbv6XDtJmHNwobCg9wb2x5Z29uLW1haW5uZXQQsavk8JqShp04CiEKFHBvbHlnb24tdGVzdG5ldC1hbW95EM2P1t/xx5D64QEKJAoYcHJpdmF0ZS10ZXN0bmV0LWFuZGVzaXRlENSmmKXBj9z8XwoZCg1zb25pYy1tYWlubmV0ENGy5e3ZoLKdFwoZCg1zb25pYy10ZXN0bmV0EMiI+9S0xvq8GAoYCgt0YWMtdGVzdG5ldBDV243j+5+T14MBChsKDnhsYXllci10ZXN0bmV0EMm+obStzLzdjQFC5QEKJ2NvbS5jYXBhYmlsaXRpZXMuYmxvY2tjaGFpbi5ldm0udjFhbHBoYUILQ2xpZW50UHJvdG9QAaICA0NCRaoCI0NhcGFiaWxpdGllcy5CbG9ja2NoYWluLkV2bS5WMWFscGhhygIjQ2FwYWJpbGl0aWVzXEJsb2NrY2hhaW5cRXZtXFYxYWxwaGHiAi9DYXBhYmlsaXRpZXNcQmxvY2tjaGFpblxFdm1cVjFhbHBoYVxHUEJNZXRhZGF0YeoCJkNhcGFiaWxpdGllczo6QmxvY2tjaGFpbjo6RXZtOjpWMWFscGhhYgZwcm90bzM', [file_sdk_v1alpha_sdk, file_tools_generator_v1alpha_cre_metadata, file_values_v1_values]);
|
|
14
14
|
/**
|
|
15
15
|
* Describes the message capabilities.blockchain.evm.v1alpha.TopicValues.
|
|
16
16
|
* Use `create(TopicValuesSchema)` to create a new message.
|
|
@@ -63,6 +63,8 @@ export declare class ClientCapability {
|
|
|
63
63
|
readonly 'ethereum-testnet-sepolia-worldchain-1': 5299555114858065850n;
|
|
64
64
|
readonly 'ethereum-testnet-sepolia-zksync-1': 6898391096552792247n;
|
|
65
65
|
readonly 'gnosis_chain-mainnet': 465200170687744372n;
|
|
66
|
+
readonly 'gnosis_chain-testnet-chiado': 8871595565390010547n;
|
|
67
|
+
readonly 'hyperliquid-mainnet': 2442541497099098535n;
|
|
66
68
|
readonly 'hyperliquid-testnet': 4286062357653186312n;
|
|
67
69
|
readonly 'ink-testnet-sepolia': 9763904284804119144n;
|
|
68
70
|
readonly 'jovay-mainnet': 1523760397290643893n;
|
|
@@ -73,6 +73,8 @@ export class ClientCapability {
|
|
|
73
73
|
'ethereum-testnet-sepolia-worldchain-1': 5299555114858065850n,
|
|
74
74
|
'ethereum-testnet-sepolia-zksync-1': 6898391096552792247n,
|
|
75
75
|
'gnosis_chain-mainnet': 465200170687744372n,
|
|
76
|
+
'gnosis_chain-testnet-chiado': 8871595565390010547n,
|
|
77
|
+
'hyperliquid-mainnet': 2442541497099098535n,
|
|
76
78
|
'hyperliquid-testnet': 4286062357653186312n,
|
|
77
79
|
'ink-testnet-sepolia': 9763904284804119144n,
|
|
78
80
|
'jovay-mainnet': 1523760397290643893n,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chainlink/cre-sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0-alpha.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"compile:workflow": "bun scripts/run.ts compile-workflow",
|
|
48
48
|
"fix-imports": "bun scripts/run.ts fix-imports",
|
|
49
49
|
"format": "biome format --write ${BIOME_PATHS:-.}",
|
|
50
|
-
"full-checks": "bun generate:sdk && bun build && bun typecheck && bun check && bun test && bun test:standard",
|
|
50
|
+
"full-checks": "bun generate:sdk && bun run build && bun typecheck && bun check && bun test && bun test:standard",
|
|
51
51
|
"generate:chain-selectors": "bun scripts/run.ts generate-chain-selectors && BIOME_PATHS=\"src/generated\" bun check",
|
|
52
52
|
"generate:proto": "bunx @bufbuild/buf generate && BIOME_PATHS=\"src/generated\" bun check",
|
|
53
53
|
"generate:sdk": "bun generate:proto && bun generate:chain-selectors && bun scripts/run generate-sdks && BIOME_PATHS=\"src/generated src/generated-sdk src/sdk/test/generated\" bun check",
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"dependencies": {
|
|
61
61
|
"@bufbuild/protobuf": "2.6.3",
|
|
62
62
|
"@bufbuild/protoc-gen-es": "2.6.3",
|
|
63
|
-
"@chainlink/cre-sdk-javy-plugin": "1.
|
|
63
|
+
"@chainlink/cre-sdk-javy-plugin": "1.5.0-alpha.1",
|
|
64
64
|
"@standard-schema/spec": "1.0.0",
|
|
65
65
|
"viem": "2.34.0",
|
|
66
66
|
"zod": "3.25.76"
|
package/scripts/run.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
|
|
3
|
-
import { WorkflowTypecheckError } from './src/typecheck-workflow'
|
|
4
3
|
import { WorkflowRuntimeCompatibilityError } from './src/validate-workflow-runtime-compat'
|
|
5
4
|
|
|
6
5
|
const availableScripts = [
|
|
@@ -40,10 +39,7 @@ const main = async () => {
|
|
|
40
39
|
process.exit(1)
|
|
41
40
|
}
|
|
42
41
|
} catch (error) {
|
|
43
|
-
if (
|
|
44
|
-
error instanceof WorkflowRuntimeCompatibilityError ||
|
|
45
|
-
error instanceof WorkflowTypecheckError
|
|
46
|
-
) {
|
|
42
|
+
if (error instanceof WorkflowRuntimeCompatibilityError) {
|
|
47
43
|
console.error(`\n❌ ${error.message}`)
|
|
48
44
|
} else {
|
|
49
45
|
console.error(`Failed to run script ${scriptName}:`, error)
|
|
@@ -2,63 +2,24 @@ 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
5
|
import { assertWorkflowRuntimeCompatibility } from './validate-workflow-runtime-compat'
|
|
8
6
|
import { wrapWorkflowCode } from './workflow-wrapper'
|
|
9
7
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
const printUsage = () => {
|
|
15
|
-
console.error(`Usage: bun compile:ts-to-js <path-to-file> [output-file] [${skipTypeChecksFlag}]`)
|
|
16
|
-
console.error('Example:')
|
|
17
|
-
console.error(' bun compile:ts-to-js src/tests/foo.ts dist/tests/foo.bundle.js')
|
|
18
|
-
console.error(
|
|
19
|
-
` bun compile:ts-to-js src/tests/foo.ts dist/tests/foo.bundle.js ${skipTypeChecksFlag}`,
|
|
20
|
-
)
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export const main = async (
|
|
24
|
-
tsFilePath?: string,
|
|
25
|
-
outputFilePath?: string,
|
|
26
|
-
options?: CompileToJsOptions,
|
|
27
|
-
) => {
|
|
28
|
-
let parsedInputPath: string | undefined
|
|
29
|
-
let parsedOutputPath: string | undefined
|
|
30
|
-
let parsedSkipTypeChecks = false
|
|
31
|
-
|
|
32
|
-
if (tsFilePath != null || outputFilePath != null || options?.skipTypeChecks != null) {
|
|
33
|
-
parsedInputPath = tsFilePath
|
|
34
|
-
parsedOutputPath = outputFilePath
|
|
35
|
-
parsedSkipTypeChecks = options?.skipTypeChecks ?? false
|
|
36
|
-
} else {
|
|
37
|
-
try {
|
|
38
|
-
const parsed = parseCompileCliArgs(process.argv.slice(3))
|
|
39
|
-
parsedInputPath = parsed.inputPath
|
|
40
|
-
parsedOutputPath = parsed.outputPath
|
|
41
|
-
parsedSkipTypeChecks = parsed.skipTypeChecks
|
|
42
|
-
} catch (error) {
|
|
43
|
-
console.error(error instanceof Error ? error.message : error)
|
|
44
|
-
printUsage()
|
|
45
|
-
process.exit(1)
|
|
46
|
-
}
|
|
47
|
-
}
|
|
8
|
+
export const main = async (tsFilePath?: string, outputFilePath?: string) => {
|
|
9
|
+
const cliArgs = process.argv.slice(3)
|
|
48
10
|
|
|
49
11
|
// Prefer function params, fallback to CLI args
|
|
50
|
-
const inputPath =
|
|
51
|
-
const outputPathArg =
|
|
12
|
+
const inputPath = tsFilePath ?? cliArgs[0]
|
|
13
|
+
const outputPathArg = outputFilePath ?? cliArgs[1]
|
|
52
14
|
|
|
53
15
|
if (!inputPath) {
|
|
54
|
-
|
|
16
|
+
console.error('Usage: bun test:standard:compile:js <path-to-file> [output-file]')
|
|
17
|
+
console.error('Example:')
|
|
18
|
+
console.error(' bun test:standard:compile:js src/tests/foo.ts dist/tests/foo.bundle.js')
|
|
55
19
|
process.exit(1)
|
|
56
20
|
}
|
|
57
21
|
|
|
58
22
|
const resolvedInput = path.resolve(inputPath)
|
|
59
|
-
if (!parsedSkipTypeChecks) {
|
|
60
|
-
assertWorkflowTypecheck(resolvedInput)
|
|
61
|
-
}
|
|
62
23
|
assertWorkflowRuntimeCompatibility(resolvedInput)
|
|
63
24
|
console.info(`📁 Using input file: ${resolvedInput}`)
|
|
64
25
|
|
|
@@ -1,7 +1,21 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process'
|
|
1
2
|
import { existsSync } from 'node:fs'
|
|
2
3
|
import { mkdir } from 'node:fs/promises'
|
|
3
4
|
import path from 'node:path'
|
|
4
|
-
|
|
5
|
+
|
|
6
|
+
function runBun(args: string[]): Promise<void> {
|
|
7
|
+
return new Promise((resolve, reject) => {
|
|
8
|
+
const child = spawn('bun', args, {
|
|
9
|
+
stdio: 'inherit',
|
|
10
|
+
env: process.env,
|
|
11
|
+
})
|
|
12
|
+
child.on('error', reject)
|
|
13
|
+
child.on('exit', (code) => {
|
|
14
|
+
if (code === 0) resolve()
|
|
15
|
+
else reject(new Error(`bun exited with code ${code ?? 'unknown'}`))
|
|
16
|
+
})
|
|
17
|
+
})
|
|
18
|
+
}
|
|
5
19
|
|
|
6
20
|
const isJsFile = (p: string) => ['.js', '.mjs', '.cjs'].includes(path.extname(p).toLowerCase())
|
|
7
21
|
|
|
@@ -47,19 +61,17 @@ export const main = async (inputFile?: string, outputFile?: string) => {
|
|
|
47
61
|
console.info(`📁 Input: ${resolvedInput}`)
|
|
48
62
|
console.info(`🎯 Output: ${resolvedOutput}`)
|
|
49
63
|
|
|
50
|
-
//
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
)
|
|
62
|
-
await $`bun --bun ${compilerPath} ${resolvedInput} ${resolvedOutput}`
|
|
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.
|
|
66
|
+
const scriptDir = import.meta.dir
|
|
67
|
+
const compilerPath = path.resolve(
|
|
68
|
+
scriptDir,
|
|
69
|
+
'../../../cre-sdk-javy-plugin/bin/compile-workflow.ts',
|
|
70
|
+
)
|
|
71
|
+
if (existsSync(compilerPath)) {
|
|
72
|
+
await runBun(['--bun', compilerPath, resolvedInput, resolvedOutput])
|
|
73
|
+
} else {
|
|
74
|
+
await runBun(['x', 'cre-compile-workflow', resolvedInput, resolvedOutput])
|
|
63
75
|
}
|
|
64
76
|
|
|
65
77
|
console.info(`✅ Compiled: ${resolvedOutput}`)
|
|
@@ -1,59 +1,23 @@
|
|
|
1
1
|
import { existsSync } from 'node:fs'
|
|
2
2
|
import { mkdir } from 'node:fs/promises'
|
|
3
3
|
import path from 'node:path'
|
|
4
|
-
import { parseCompileCliArgs, skipTypeChecksFlag } from './compile-cli-args'
|
|
5
4
|
import { main as compileToJs } from './compile-to-js'
|
|
6
5
|
import { main as compileToWasm } from './compile-to-wasm'
|
|
7
6
|
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
|
|
26
|
-
export const main = async (
|
|
27
|
-
inputFile?: string,
|
|
28
|
-
outputWasmFile?: string,
|
|
29
|
-
options?: CompileWorkflowOptions,
|
|
30
|
-
) => {
|
|
31
|
-
let parsedInputPath: string | undefined
|
|
32
|
-
let parsedOutputPath: string | undefined
|
|
33
|
-
let parsedSkipTypeChecks = false
|
|
7
|
+
export const main = async (inputFile?: string, outputWasmFile?: string) => {
|
|
8
|
+
const cliArgs = process.argv.slice(3)
|
|
34
9
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
const inputPath = parsedInputPath
|
|
53
|
-
const outputPathArg = parsedOutputPath
|
|
10
|
+
// Resolve input/output from params or CLI
|
|
11
|
+
const inputPath = inputFile ?? cliArgs[0]
|
|
12
|
+
const outputPathArg = outputWasmFile ?? cliArgs[1]
|
|
54
13
|
|
|
55
14
|
if (!inputPath) {
|
|
56
|
-
|
|
15
|
+
console.error('Usage: bun compile:workflow <path/to/workflow.ts> [path/to/output.wasm]')
|
|
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
|
+
)
|
|
57
21
|
process.exit(1)
|
|
58
22
|
}
|
|
59
23
|
|
|
@@ -78,13 +42,10 @@ export const main = async (
|
|
|
78
42
|
|
|
79
43
|
console.info(`🚀 Compiling workflow`)
|
|
80
44
|
console.info(`📁 Input: ${resolvedInput}\n`)
|
|
81
|
-
if (parsedSkipTypeChecks) {
|
|
82
|
-
console.info(`⚠️ Skipping TypeScript checks (${skipTypeChecksFlag})`)
|
|
83
|
-
}
|
|
84
45
|
|
|
85
46
|
// Step 1: TS/JS → JS (bundled)
|
|
86
47
|
console.info('📦 Step 1: Compiling JS...')
|
|
87
|
-
await compileToJs(resolvedInput, resolvedJsOutput
|
|
48
|
+
await compileToJs(resolvedInput, resolvedJsOutput)
|
|
88
49
|
|
|
89
50
|
// Step 2: JS → WASM
|
|
90
51
|
console.info('\n🔨 Step 2: Compiling to WASM...')
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from 'bun:test'
|
|
2
|
-
import { parseCompileCliArgs } from './compile-cli-args'
|
|
3
|
-
|
|
4
|
-
describe('parseCompileCliArgs', () => {
|
|
5
|
-
test('parses positional input and output', () => {
|
|
6
|
-
const parsed = parseCompileCliArgs(['src/workflow.ts', 'dist/workflow.wasm'])
|
|
7
|
-
expect(parsed).toEqual({
|
|
8
|
-
inputPath: 'src/workflow.ts',
|
|
9
|
-
outputPath: 'dist/workflow.wasm',
|
|
10
|
-
skipTypeChecks: false,
|
|
11
|
-
})
|
|
12
|
-
})
|
|
13
|
-
|
|
14
|
-
test('parses --skip-type-checks flag', () => {
|
|
15
|
-
const parsed = parseCompileCliArgs(['src/workflow.ts', '--skip-type-checks'])
|
|
16
|
-
expect(parsed).toEqual({
|
|
17
|
-
inputPath: 'src/workflow.ts',
|
|
18
|
-
outputPath: undefined,
|
|
19
|
-
skipTypeChecks: true,
|
|
20
|
-
})
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
test('throws on unknown flags', () => {
|
|
24
|
-
expect(() => parseCompileCliArgs(['src/workflow.ts', '--foo'])).toThrow('Unknown option: --foo')
|
|
25
|
-
})
|
|
26
|
-
|
|
27
|
-
test('throws on too many positional args', () => {
|
|
28
|
-
expect(() => parseCompileCliArgs(['src/workflow.ts', 'dist/workflow.wasm', 'extra'])).toThrow(
|
|
29
|
-
'Too many positional arguments.',
|
|
30
|
-
)
|
|
31
|
-
})
|
|
32
|
-
})
|
|
@@ -1,35 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,90 +0,0 @@
|
|
|
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
|
-
})
|
|
@@ -1,77 +0,0 @@
|
|
|
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
|
-
})
|
|
@@ -1,96 +0,0 @@
|
|
|
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 }
|