Skip to content

Commit

Permalink
0.7.0 (#561)
Browse files Browse the repository at this point in the history
* changelog

* proper link

* make ./run handle files with internal imports

* make AccountUpdate a valid method argument

* add `this.authorize` to adopt update & witness its children

* restore old ./run behaviour if the new one fails

* fix token example

* use struct

* remove redundant function

* tweak run script again

* wip  callback refactor

* fixup

* update bindings

* Fetch Account's verification key.

* make tx.send async

* add error trace

* helpers for pretty-printing updates

* update changelog

* make tx.send async in all examples and tests

* More details on what to check when a state fetch fails

* fix token test

* tweak witness to just get & return fields

* clone updates when witnessing, so prover doesn't interfere with tx
-> to still be able to identify the same update, give them an id

* fixes

* avert future name clash

* make unit tests rely on existing build
(so that Mina CI can be independent of checked-in bindings)

* merge accountUpdateFromCallback into authorize

* changelog

* make child layout spec more verbose and understandable

* update bindings

* fix returning values in the top-level transactoin case

* reenable having no authorization when calling zkapps

* Dex Application - supplyLiquidity Happy Path

* Use predefined keys for debugging purposes

* Add getBalance function to TokenContract

* Refactor supplyLiquidity methods to remove return type and use getBalance

* Update dex run script to use supplyLiquidity methods

* add enableProofs

* add isDelegateCall and  compute `caller` from it

* fix logic to tompute caller in the prover

* set delegate call in authorize, clone

* wip get dex running

* wip add isDelegateCall to circuit

* caller progress

* label acount updates

* no delegate call from the top level

* make token send go through

* Add failure cases for supply liquidity in DEX

* Add proof verification into the tests.

* Add proof verification into the tests.

* Fix for tests (Proof verification).

* Skipping some tests in CI condition refactoring.

* Commenting out txn signing to allow proving..

* add error for long token symbol & make it a struct

* fix dependency cycle

* make isDelegateCall a Bool

* remove caller hacks from dex/run

* remove unnecessary code

* remove debugging

* fix jest tests

* make SequenceEvents exportable for external use

* delay children hashing until caller is known, fix logic to know when we're at the top level

* update bindings

* instantiate subclass of struct, not base class

* Remove clone for lazyAuthorization

* Update dex example

* better struct fix

* fix dummy proof logic

* fixes to dex contract logic & balance sum

* minor

* handle more cases when making account update a child

* try setting some zkapps to delegate_call, but creates different token owner issues

* typos

* make redeem liquidity work

* minor

* Simplify things by utilizing test fixtures.

* enable changing proofsEnabled

* dex debugging with proofs

* make Circuit.witness create a new unchecked snark context, and only call `exists` in checked mode

* fix assertion about hashed child

* any children

* fix demo

* make tx sending async

* temp fix

* fix integration test

* add verification key test

* minor

* allow children which can't delegate token spending power, as default for authorize

* wip swap happy path

* missing access permission issue repro

* fix dummy proof for child updates

* fix remaining bugs

* fix tests

* remove comment

* swap fix

* refine the logic for when `exists` is called

* Circuit.log

* stop implicitly attaching account updates to tx

* remove debugging

* remove unused z token

* changelog

* remove redundant checks guarding Circuit.witness

* fix precondition tests

* changelog

* fix attach logic

* add edgecase with proof verification

* rm unused code

* fix broken permission and vk tests

* manually specify feepayer nonce

* dont fetch nonce if nonce is specified

* address feedback

* add Uint.toBigInt

* helper to check token balances

* add checks for supply liquidity (happy path)

* checks for redeem liquidity (no vesting)

* fix nonce calculation

* start adding timing, but missing error on repeated liquidity supplying

* pretty printing improvements

* expose account timing

* use ES private class fields instead of `private`

* roll back one private field bc its not inherited

* better interface for setting local global slot

* add vesting

* finish redeem liquidity tests

* swap add checks for happy path

* working on overflow tests

* Add optional assertion failure messages to SnarkyJS methods (#470)

* Add optional error message to Field.assertEquals

* Add optional message for Bool.assertEquals

* Add optional message for Group.assertEquals

* Add optional message to Field.assert compares

* Add optional message to Field.assertBoolean

* Add optional message to Bool.assertTrue/False

* Changelog

* feat: Add optional message for UInt64 assert methods

* feat: Add optional message for UInt32 assert methods

* feat: Add optional message for Int64 assert methods

* Update bindings

* merge in existing supply failures and add the rest

* bonus test for the supplying after lock period

* run tests with and w/o vesting

* fix uint comparisons

* push fix to examples

* add unit test for division in the prover

* fix second run by recreating ledger

* update bindings

* add back setGlobalSlot

* add back setGlobalSlot

* Add args to the callback method invocation (#516)

* Add args to the callback method invocation

* Changelog

* remove static from methods

* remove static definitions for field

* update changelog

* fix internal usage

* start snarky doc comments

* Removes static one/zero/-1 from Field

Part of #511

* Deprecates instead of removes Field members

* Add shutdown to end of primitive unit test (#525)

* Add timeout minutes to github action (#526)

* dump initial mina-signer experiments

* type check mina-signer

* make transaction-helpers generic over base types

* remove most specializations to base types away

* make transaction-helpers fully generic

* lift customTypes to functor level

* rename

* change dir and filenames

* remove undefined from typemap

* remove primitive types from typemap

* autogenerate type map

* move everything to common folder

* update bindings

* fix tests

* Update int.test.ts

* fix tests

* redo merge conflict fix

* Add additional token tests (#522)

* Refactor token tests and add additional tests

* Add comment descriptions

* bump node CI time

* Rename `authorize` to `approve` (#534)

* Rename 'authorize' to 'approve'

We rename 'authorize' to approve in the aims to take advantage of the
concept of 'approve' in Ethereum. We hope that developers will
intuitively understand what it means to 'approve' a AccountUpdate given
that a smart contract in Ethereum must get approval to spend tokens.

* Changelog

* Update tokens test

* Make `JSONValue` internally used only (#536)

* Make JSONValue internally used only

Move the definition of JSONValue into circuit_value.ts since there are
many types that depend on JSONValue inside that file. We also removed
any usages of JSONValue from public fromJSON methods since that type is
intended for internal use.

* Replace JSONValue with any type

* Fix tests

Update int.test.ts

fix tests

redo merge conflict fix

 Fix tests

* Removed all uses of JSONValue with any

* cache nonce

* minor

* make fetch tests run with CI && import from fetch

* make tests abort

* more tests

* add nested escaped string

* add init and show opt-in proving for it in example

* fix init logic so that we can assure its only run once

* tweak error

* fix token test

* better type for numberOfRuns

* swap import order

* adjust tests

* fix dex

* changelog

* fix error parsing logic

* replace links

* enable manually triggering a workflow

* fix yaml

* move Reducer and MerkleStuff off Experimental

* update examples

* move token and approve off this.experimental

* update examples

* changelog

* fix merkle tree tests

* fix token test

* deprecate this.sign and document requireSignature

* changelog

* changelog

* more comments

* more comments

* 0.7.0

* changelog

Co-authored-by: Serhii Shymkiv <sergey@shimkiv.com>
Co-authored-by: Florian <florian@technotro.com>
Co-authored-by: Brandon Kase <brandon.kase@gmail.com>
Co-authored-by: Martin Minkov <minkovlmartin@gmail.com>
Co-authored-by: Comdex <wcomdex@foxmail.com>
  • Loading branch information
6 people authored Nov 15, 2022
1 parent 667dca4 commit 8b2fa6c
Show file tree
Hide file tree
Showing 125 changed files with 175,053 additions and 153,743 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/build-action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,19 @@ on:
branches:
- main
- releases
workflow_dispatch: {}

jobs:
Build-And-Test-Server:
timeout-minutes: 180
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v2
- name: Setup Node
uses: actions/setup-node@v2
with:
node-version: "18"
node-version: '18'
- name: Build SnarkyJS and Execute Tests
run: |
npm ci
Expand All @@ -35,14 +37,15 @@ jobs:
INPUT_TOKEN: ${{ secrets.NPM_TOKEN }}

Build-And-Test-Web:
timeout-minutes: 90
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v2
- name: Setup Node
uses: actions/setup-node@v2
with:
node-version: "18"
node-version: '18'
- name: Install Node Dependencies
run: npm ci
- name: Install Playwright Browsers
Expand Down
58 changes: 52 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,55 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
_Security_ in case of vulnerabilities.
-->

## [Unreleased](https://github.com/o1-labs/snarkyjs/compare/f0837188...HEAD)
## [Unreleased](https://github.com/o1-labs/snarkyjs/compare/9a94231c...HEAD)

(no unreleased changes yet)
## [0.7.0](https://github.com/o1-labs/snarkyjs/compare/f0837188...9a94231c)

### Added

- Added an optional string parameter to certain `assert` methods https://github.com/o1-labs/snarkyjs/pull/470
- `Struct`, a new primitive for declaring composite, SNARK-compatible types https://github.com/o1-labs/snarkyjs/pull/416
- With this, we also added a way to include auxiliary, non-field element data in composite types
- Added `VerificationKey`, which is a `Struct` with auxiliary data, to pass verification keys to a `@method`
- BREAKING CHANGE: Change names related to circuit types: `AsFieldsAndAux<T>` -> `Provable<T>`, `AsFieldElement<T>` -> `ProvablePure<T>`, `circuitValue` -> `provable`
- BREAKING CHANGE: Change all `ofFields` and `ofBits` methods on circuit types to `fromFields` and `fromBits`
- New option `proofsEnabled` for `LocalBlockchain` (default value: `true`), to quickly test transaction logic with proofs disabled https://github.com/o1-labs/snarkyjs/pull/462
- with `proofsEnabled: true`, proofs now get verified locally https://github.com/o1-labs/snarkyjs/pull/423
- `SmartContract.approve()` to approve a tree of child account updates https://github.com/o1-labs/snarkyjs/pull/428 https://github.com/o1-labs/snarkyjs/pull/534
- AccountUpdates are now valid `@method` arguments, and `approve()` is intended to be used on them when passed to a method
- Also replaces `Experimental.accountUpdateFromCallback()`
- `Circuit.log()` to easily log Fields and other provable types inside a method, with the same API as `console.log()` https://github.com/o1-labs/snarkyjs/pull/484
- `SmartContract.init()` is a new method on the base `SmartContract` that will be called only during the first deploy (not if you re-deploy later to upgrade the contract) https://github.com/o1-labs/snarkyjs/pull/543
- Overriding `init()` is the new recommended way to add custom state initialization logic.
- `transaction.toPretty()` and `accountUpdate.toPretty()` for debugging transactions by printing only the pieces that differ from default account updates https://github.com/o1-labs/snarkyjs/pull/428
- `AccountUpdate.attachToTransaction()` for explicitly adding an account update to the current transaction. This replaces some previous behaviour where an account update got attached implicitly https://github.com/o1-labs/snarkyjs/pull/484
- `SmartContract.requireSignature()` and `AccountUpdate.requireSignature()` as a simpler, better-named replacement for `.sign()` https://github.com/o1-labs/snarkyjs/pull/558

### Changed

- BREAKING CHANGE: `tx.send()` is now asynchronous: old: `send(): TransactionId` new: `send(): Promise<TransactionId>` and `tx.send()` now directly waits for the network response, as opposed to `tx.send().wait()` https://github.com/o1-labs/snarkyjs/pull/423
- Sending transactions to `LocalBlockchain` now involves
- `Circuit.witness` can now be called outside circuits, where it will just directly return the callback result https://github.com/o1-labs/snarkyjs/pull/484
- The `FeePayerSpec`, which is used to specify properties of the transaction via `Mina.transaction()`, now has another optional parameter to specify the nonce manually. `Mina.transaction({ feePayerKey: feePayer, nonce: 1 }, () => {})` https://github.com/o1-labs/snarkyjs/pull/497
- BREAKING CHANGE: Static methods of type `.fromString()`, `.fromNumber()` and `.fromBigInt()` on `Field`, `UInt64`, `UInt32` and `Int64` are no longer supported https://github.com/o1-labs/snarkyjs/pull/519
- use `Field(number | string | bigint)` and `UInt64.from(number | string | bigint)`
- Move several features out of 'experimental' https://github.com/o1-labs/snarkyjs/pull/555
- `Reducer` replaces `Experimental.Reducer`
- `MerkleTree` and `MerkleWitness` replace `Experimental.{MerkleTree,MerkleWitness}`
- In a `SmartContract`, `this.token` replaces `this.experimental.token`

### Deprecated

- `CircuitValue` deprecated in favor of `Struct` https://github.com/o1-labs/snarkyjs/pull/416
- Static props `Field.zero`, `Field.one`, `Field.minusOne` deprecated in favor of `Field(number)` https://github.com/o1-labs/snarkyjs/pull/524
- `SmartContract.sign()` and `AccountUpdate.sign()` in favor of `.requireSignature()` https://github.com/o1-labs/snarkyjs/pull/558

### Fixed

- Uint comparisons and division fixed inside the prover https://github.com/o1-labs/snarkyjs/pull/503
- Callback arguments are properly passed into method invocations https://github.com/o1-labs/snarkyjs/pull/516
- Removed internal type `JSONValue` from public interfaces https://github.com/o1-labs/snarkyjs/pull/536
- Returning values from a zkApp https://github.com/o1-labs/snarkyjs/pull/461

## [0.6.1](https://github.com/o1-labs/snarkyjs/compare/ba688523...f0837188)

Expand All @@ -35,10 +81,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

- **Breaking change:** Rename the `Party` class to `AccountUpdate`. Also, rename other occurrences of "party" to "account update". https://github.com/o1-labs/snarkyjs/pull/393
- **Breaking change:** Don't require the account address as input to `SmartContract.compile()`, `SmartContract.digest()` and `SmartContract.analyzeMethods()` https://github.com/o1-labs/snarkyjs/pull/406
- BREAKING CHANGE: Rename the `Party` class to `AccountUpdate`. Also, rename other occurrences of "party" to "account update". https://github.com/o1-labs/snarkyjs/pull/393
- BREAKING CHANGE: Don't require the account address as input to `SmartContract.compile()`, `SmartContract.digest()` and `SmartContract.analyzeMethods()` https://github.com/o1-labs/snarkyjs/pull/406
- This works because the address / public key is now a variable in the method circuit; it used to be a constant
- **Breaking change:** Move `ZkProgram` to `Experimental.ZkProgram`
- BREAKING CHANGE: Move `ZkProgram` to `Experimental.ZkProgram`

## [0.5.4](https://github.com/o1-labs/snarkyjs/compare/3461333...f2ad423)

Expand Down Expand Up @@ -83,7 +129,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `this.account.isNew` to assert that an account did not (or did) exist before the transaction https://github.com/MinaProtocol/mina/pull/11524
- `LocalBlockchain.setTimestamp` and other setters for network state, to test network preconditions locally https://github.com/o1-labs/snarkyjs/pull/329
- **Experimental APIs** are now collected under the `Experimental` import, or on `this.experimental` in a smart contract.
- Custom tokens (_experimental_), via `this.experimental.token`. RFC: https://github.com/o1-labs/snarkyjs/issues/233, PR: https://github.com/o1-labs/snarkyjs/pull/273,
- Custom tokens (_experimental_), via `this.token`. RFC: https://github.com/o1-labs/snarkyjs/issues/233, PR: https://github.com/o1-labs/snarkyjs/pull/273,
- Actions / sequence events support (_experimental_), via `Experimental.Reducer`. RFC: https://github.com/o1-labs/snarkyjs/issues/265, PR: https://github.com/o1-labs/snarkyjs/pull/274
- Merkle tree implementation (_experimental_) via `Experimental.MerkleTree` https://github.com/o1-labs/snarkyjs/pull/343

Expand Down
2 changes: 1 addition & 1 deletion MINA_COMMIT
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
The mina commit used to generate the backends for node and chrome is
778f499316fe439a7a843f91cd3c6e05484b3f7d
73f3e843de3f205ec627598e30971f44ba94ff56
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "snarkyjs",
"description": "JavaScript bindings for SnarkyJS",
"version": "0.6.1",
"version": "0.7.0",
"license": "Apache-2.0",
"type": "module",
"main": "./dist/web/index.js",
Expand Down Expand Up @@ -32,7 +32,7 @@
"dev": "npx tsc -p tsconfig.node.json && cp src/snarky.d.ts dist/node/snarky.d.ts",
"make": "make -C ../../../.. snarkyjs",
"build": "rimraf ./dist/node && npx tsc -p tsconfig.node.json && cp -r src/node_bindings dist/node/_node_bindings && node src/build/buildNode.js && cp src/snarky.d.ts dist/node/snarky.d.ts",
"build:test": "rimraf ./dist/test && npx tsc -p tsconfig.test.json && cp -r src/node_bindings dist/test/_node_bindings && cp src/snarky.d.ts dist/test/snarky.d.ts",
"build:test": "npx tsc -p tsconfig.test.json && cp src/snarky.d.ts dist/node/snarky.d.ts",
"build:node": "npm run build",
"build:web": "rimraf ./dist/web && node src/build/buildWeb.js",
"build:examples": "rimraf ./dist/examples && npx tsc -p tsconfig.examples.json || exit 0",
Expand Down
6 changes: 3 additions & 3 deletions run-integration-tests.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
./run src/examples/zkapps/hello_world/run.ts || exit 1
./run src/examples/zkapps/voting/run.ts || exit 1
./run src/examples/zkapps/hello_world/run.ts --bundle || exit 1
./run src/examples/zkapps/voting/run.ts --bundle || exit 1
./run src/examples/simple_zkapp.ts || exit 1
./run src/examples/zkapps/reducer/reducer_composite.ts || exit 1
./run src/examples/zkapps/composability.ts || exit 1
./run src/examples/zkapps/token_with_proofs.ts || exit 1
./run src/examples/zkapps/dex/run.ts || exit 1
./run src/examples/zkapps/dex/run.ts --bundle || exit 1
4 changes: 2 additions & 2 deletions run-unit-tests.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
npm run build:test
for f in ./dist/test/**/*.unit-test.js; do
for f in ./dist/node/**/*.unit-test.js; do
echo "Running $f"
node $f || (echo 'tests failed' && exit 1)
node $f || exit 1;
done
25 changes: 24 additions & 1 deletion src/build/buildExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import path from 'path';
import ts from 'typescript';
import esbuild from 'esbuild';

export { buildAndImport, build };
export { buildAndImport, build, buildOne };

async function buildAndImport(srcPath, { keepFile = false }) {
let absPath = await build(srcPath);
Expand Down Expand Up @@ -37,6 +37,29 @@ async function build(srcPath) {
return absPath;
}

async function buildOne(srcPath) {
let tsConfig = findTsConfig() ?? defaultTsConfig;

let outfile = path.resolve(
'./dist/node',
srcPath.replace('.ts', '.js').replace('src', '.')
);

await esbuild.build({
entryPoints: [srcPath],
format: 'esm',
platform: 'node',
outfile,
target: 'esnext',
resolveExtensions: ['.node.js', '.ts', '.js'],
logLevel: 'error',
plugins: [typescriptPlugin(tsConfig)],
});

let absPath = path.resolve('.', outfile);
return absPath;
}

const defaultTsConfig = {
compilerOptions: {
module: 'esnext',
Expand Down
47 changes: 40 additions & 7 deletions src/build/jsLayoutToTypes.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ function writeType(typeData, isJson, withTypeMap) {
output += indent + '}';
return { output, dependencies, converters };
}
if (withTypeMap) {
if (withTypeMap & !builtinLeafTypes.has(type)) {
type = `${isJson ? 'Json.' : ''}TypeMap["${type}"]`;
}
// built in type
Expand All @@ -118,7 +118,7 @@ function writeTsContent(types, isJson) {
mergeObject(converters, inner.converters);
output += `type ${Type} = ${inner.output};\n\n`;
if (!isJson) {
output += `let ${Type} = asFieldsAndAux<${Type}, Json.${Type}>(jsLayout.${Type} as any, customTypes);\n\n`;
output += `let ${Type} = provableFromLayout<${Type}, Json.${Type}>(jsLayout.${Type} as any);\n\n`;
}
}

Expand All @@ -127,6 +127,7 @@ function writeTsContent(types, isJson) {
let imports = new Set();
mergeSet(imports, dependencies);
mergeSet(imports, new Set(customTypeNames));
let typeMapKeys = diffSets(dependencies, new Set(customTypeNames));

let importPath = isJson
? '../transaction-leaves-json.js'
Expand All @@ -136,7 +137,8 @@ function writeTsContent(types, isJson) {
import { ${[...imports].join(', ')} } from '${importPath}';
${
!isJson
? "import { asFieldsAndAux, AsFieldsAndAux } from '../transaction-helpers.js';\n" +
? "import { GenericProvableExtended } from '../../provable/generic.js';\n" +
"import { ProvableFromLayout, GenericLayout } from '../../provable/from-layout.js';\n" +
"import * as Json from './transaction-json.js';\n" +
"import { jsLayout } from './js-layout.js';\n"
: ''
Expand All @@ -145,17 +147,41 @@ ${
export { ${[...exports].join(', ')} };
${
!isJson
? 'export { Json };\n' + "export * from '../transaction-leaves.js';\n"
: "export * from '../transaction-leaves-json.js';\n"
? 'export { Json };\n' +
"export * from '../transaction-leaves.js';\n" +
'export { provableFromLayout, toJSONEssential, Layout };\n'
: "export * from '../transaction-leaves-json.js';\n" +
'export { TypeMap };\n'
}
type TypeMap = {
${[...typeMapKeys].map((type) => `${type}: ${type};`).join('\n')}
}
${
(!isJson || '') &&
`
const TypeMap: {
[K in keyof TypeMap]: ProvableExtended<TypeMap[K], Json.TypeMap[K]>;
} = {
${[...typeMapKeys].join(', ')}
}
`
}
${
(!isJson || '') &&
`
type ProvableExtended<T, TJson> = GenericProvableExtended<T, TJson, Field>;
type Layout = GenericLayout<TypeMap>;
type CustomTypes = { ${customTypes
.map((c) => `${c.typeName}: AsFieldsAndAux<${c.type}, ${c.jsonType}>;`)
.map((c) => `${c.typeName}: ProvableExtended<${c.type}, ${c.jsonType}>;`)
.join(' ')} }
let customTypes: CustomTypes = { ${customTypeNames.join(', ')} };
let { provableFromLayout, toJSONEssential } = ProvableFromLayout<
TypeMap,
Json.TypeMap
>(TypeMap, customTypes);
`
}
Expand All @@ -171,7 +197,7 @@ async function writeTsFile(content, relPath) {
await fs.writeFile(absPath, content);
}

let genPath = '../../snarky/gen';
let genPath = '../../provable/gen';
await ensureDir(genPath);

let jsonTypesContent = writeTsContent(jsLayout, true);
Expand All @@ -195,6 +221,13 @@ function mergeSet(target, source) {
target.add(x);
}
}
function diffSets(s0, s1) {
let s = new Set(s0);
for (let x of s1) {
s.delete(x);
}
return s;
}

function mergeObject(target, source) {
if (source === undefined) return;
Expand Down
27 changes: 17 additions & 10 deletions src/build/run.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,33 @@
#!/usr/bin/env node
import minimist from 'minimist';
import { buildAndImport } from './buildExample.js';
import { shutdown } from '../../dist/node/index.js';
import { buildAndImport, buildOne } from './buildExample.js';

let {
_: [filePath],
main,
default: runDefault,
keypair: keyPair,
keep,
bundle,
} = minimist(process.argv.slice(2));

if (!filePath) {
console.log(`Usage:
npx snarky-run [file]`);
process.exit(0);
}

let module = await buildAndImport(filePath, { keepFile: !!keep });
if (main) await module.main();
if (runDefault) await module.default();
if (keyPair) {
console.log(module.default.generateKeypair());
if (!bundle) {
let absPath = await buildOne(filePath);
console.log(`running ${absPath}`);
let module = await import(absPath);
if (main) await module.main();
if (runDefault) await module.default();
let { shutdown } = await import('../../dist/node/index.js');
shutdown();
} else {
let { isReady, shutdown } = await import('../../dist/node/index.js');
await isReady;
let module = await buildAndImport(filePath, { keepFile: !!keep });
if (main) await module.main();
if (runDefault) await module.default();
shutdown();
}
shutdown();
Loading

0 comments on commit 8b2fa6c

Please sign in to comment.