Skip to content

Commit

Permalink
feat: add build script with type declaration transforms
Browse files Browse the repository at this point in the history
  • Loading branch information
zmalatrax committed Jun 11, 2024
1 parent 492d497 commit 3c52fd4
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 17 deletions.
Binary file modified bun.lockb
Binary file not shown.
15 changes: 10 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,24 @@
"author": "Clément Walter <[email protected]>",
"license": "Apache-2.0",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"types": "dist/types/index.d.ts",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "echo \"Error: no entrypoint yet\" && exit 1",
"clean": "bunx rimraf dist",
"prebuild": "bun run clean",
"build": "bun build --target=node ./src/index.ts --outfile=dist/index.js && bun run build:declaration",
"build:declaration": "tsc --emitDeclarationOnly --project tsconfig.types.json",
"build:declaration": "tspc --emitDeclarationOnly --project tsconfig.types.json",
"postbuild": "rimraf tsconfig.types.tsbuildinfo"
},
"repository": {
"type": "git",
"url": "https://github.com/kkrt-labs/cairo-vm-ts"
},
"files": [
"src/**/*.ts",
"dist/*.js",
"dist/*.d.ts"
"dist/types/**/*.d.ts"
],
"prettier": {
"proseWrap": "always",
Expand All @@ -41,9 +44,11 @@
},
"devDependencies": {
"bun-types": "^1.1.12",
"typescript": "^5.2.2"
"ts-patch": "^3.2.0",
"typescript": "^5.2.2",
"typescript-transform-paths": "^3.4.7"
},
"bin": {
"cairo-vm-ts": "./bin/cli.ts"
"cairo-vm-ts": "./src/cli.ts"
}
}
43 changes: 41 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,41 @@
import './runners/cairoRunner';
import './vm/program';
export * as PrimitiveErrors from 'errors/primitives';
export * as MemoryErrors from 'errors/memory';
export * as InstructionErrors from 'errors/instruction';
export * as VirtualMachineErrors from 'errors/virtualMachine';
export * as BuiltinErrors from 'errors/builtins';
export * as CairoRunnerErrors from 'errors/cairoRunner';

export { Felt } from 'primitives/felt';
export { Relocatable } from 'primitives/relocatable';
export { SegmentValue, isFelt, isRelocatable } from 'primitives/segmentValue';

export { Memory } from 'memory/memory';
export {
Instruction,
Register,
Op1Src,
ResLogic,
Opcode,
PcUpdate,
ApUpdate,
FpUpdate,
} from 'vm/instruction';
export {
VirtualMachine,
TraceEntry,
RelocatedMemory,
RelocatedTraceEntry,
} from 'vm/virtualMachine';
export { parseProgram, Program, Identifier } from 'vm/program';

export { BuiltinHandler, getBuiltin } from 'builtins/builtin';
export { outputHandler } from 'builtins/output';
export { pedersenHandler } from 'builtins/pedersen';
export { rangeCheckHandler } from 'builtins/rangeCheck';
export { ecdsaHandler, EcdsaSegment, EcdsaSignature } from 'builtins/ecdsa';
export { bitwiseHandler } from 'builtins/bitwise';
export { ecOpHandler } from 'builtins/ecop';
export { keccakHandler } from 'builtins/keccak';
export { poseidonHandler } from 'builtins/poseidon';

export { CairoRunner, RunOptions } from 'runners/cairoRunner';
15 changes: 8 additions & 7 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
{
"compilerOptions": {
"outDir": "./dist",
"rootDir": "./src",
"baseUrl": "./src",
"baseUrl": ".",
"paths": {
"@/*": ["src/*"]
"*": ["./src/*"]
},
"lib": ["esnext"],
"module": "esnext",
"target": "esnext",
// if TS 5.x+
"moduleResolution": "node",
"moduleDetection": "force",
"allowImportingTsExtensions": true,
"noEmit": true,
"strict": true,
"allowJs": false,
"skipLibCheck": true,
"noUnusedLocals": true,
"noImplicitAny": true,
"noUnusedLocals": true,
"noImplicitReturns": true,
"noUnusedParameters": true,
"forceConsistentCasingInFileNames": true,
"allowJs": false, // disallow importing `.js` from `.ts`
"types": ["bun-types"],
"esModuleInterop": true // allow default imports for CommonJS modules
},
"include": ["src/**/*.ts"]
"include": ["src/**/*.ts"],
"exclude": ["node_modules", "dist"]
}
16 changes: 13 additions & 3 deletions tsconfig.types.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,18 @@
"noEmit": false,
"emitDeclarationOnly": true,
"declaration": true,
"outDir": "./dist",
"rootDir": "./src"
"outDir": "./dist/types",
"rootDir": "./src",
"plugins": [
{
"transform": "typescript-transform-paths"
},
{
"transform": "typescript-transform-paths",
"afterDeclarations": true
}
]
},
"include": ["src/**/*.ts"]
"include": ["./src/**/*.ts"],
"exclude": ["node_modules", "./src/**/*.test.ts"]
}

0 comments on commit 3c52fd4

Please sign in to comment.