Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: set ts relative paths #140

Merged
merged 2 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/small-turkeys-check.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@zk-kit/artifacts": patch
---

Relative paths have been set in TS config files.
2 changes: 1 addition & 1 deletion packages/artifacts/src/cli/cli.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Command } from '@commander-js/extra-typings'
import { error } from 'node:console'
import { exit } from 'node:process'
import COMMANDS from './commands/index.ts'
import COMMANDS from './commands/index'

export class Cli {
cli: Command
Expand Down
14 changes: 7 additions & 7 deletions packages/artifacts/src/cli/commands/download/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Argument, Command } from '@commander-js/extra-typings'
import { spinner } from 'cli/spinner'
import { validateNonEmptyInput, validateOrThrow, validateProject } from 'cli/validators'
import { maybeGetSnarkArtifacts } from 'index.node'
import { Project, projects } from 'projects'
import { spinner } from '../../../cli/spinner'
import { validateNonEmptyInput, validateOrThrow, validateProject } from '../../../cli/validators'
import { maybeGetSnarkArtifacts } from '../../../index.node'
import { Project, projects } from '../../../projects'
import { getParametersInput, getProjectInput } from './prompts'

export const download = new Command('download').alias('d').description(
'Download all available artifacts for a given project',
)
export const download = new Command('download')
.alias('d')
.description('Download all available artifacts for a given project')
.addArgument(new Argument('<project>', 'Project name').argOptional().choices(projects))
.option('-p,--parameters <params...>', 'Parameters of the circuit you want to download artifacts for')
.action(async (project, { parameters }) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/artifacts/src/cli/commands/download/prompts.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import input from '@inquirer/input'
import select from '@inquirer/select'
import { validateNonEmptyInput } from 'cli/validators'
import { projects as choices } from 'projects'
import { validateNonEmptyInput } from '../../../cli/validators'
import { projects as choices } from '../../../projects'

export const getProjectInput = async () =>
select({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { spinner } from 'cli/spinner'
import { readFileSync } from 'node:fs'
import { exit } from 'node:process'
import { spinner } from '../../../cli/spinner'
import { generateActionNoExit } from '../generate/action'

export default async function generateBatch(optionsPath: string, destination: string) {
Expand All @@ -10,10 +10,8 @@ export default async function generateBatch(optionsPath: string, destination: st
>

spinner.start()
for (const [config, { circuit, paramsList }] of Object.entries(options)) {
for (const params of paramsList)
await generateActionNoExit(circuit, params, { config, destination })
}
for (const [config, { circuit, paramsList }] of Object.entries(options))
for (const params of paramsList) await generateActionNoExit(circuit, params, { config, destination })

spinner.succeed(`All snark artifacts generated successfully in ${destination}`)
exit(0)
Expand Down
8 changes: 4 additions & 4 deletions packages/artifacts/src/cli/commands/generate-batch/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Command } from '@commander-js/extra-typings'
import generateBatchAction from './action.ts'
import generateBatchAction from './action'

export const generateBatch = new Command('generate-batch').alias('gb').description(
'Generate snark artifacts for a list of circom circuits',
)
export const generateBatch = new Command('generate-batch')
.alias('gb')
.description('Generate snark artifacts for a list of circom circuits')
.argument(
'<optionsPath>',
'Path to the options definition json file: { [circomkitJsonPath]: { circuit:string, params: string[][] }}',
Expand Down
10 changes: 4 additions & 6 deletions packages/artifacts/src/cli/commands/generate/action.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Circomkit, type CircomkitConfig, type CircuitConfig } from 'circomkit'
import { spinner } from 'cli/spinner'
import { validateJsonFileInput, validateOrThrow } from 'cli/validators'
import { existsSync, readFileSync, writeFileSync } from 'node:fs'
import { tmpdir } from 'node:os'
import { dirname } from 'node:path'
import { chdir, cwd, exit } from 'node:process'
import { Writable } from 'node:stream'
import { spinner } from '../../../cli/spinner'
import { validateJsonFileInput, validateOrThrow } from '../../../cli/validators'
import { getCircomkitConfigInput, getDestinationInput, selectCircuit } from './prompts'

class SilentStream extends Writable {
Expand Down Expand Up @@ -62,7 +62,7 @@ export async function generateActionNoExit(
validateOrThrow(destination, existsSync)

config ??= await getCircomkitConfigInput()
const dirBuild = destination ?? await getDestinationInput(`${cwd()}/snark-artifacts`)
const dirBuild = destination ?? (await getDestinationInput(`${cwd()}/snark-artifacts`))
const result = await setup(circuit, params, config, dirBuild)

spinner.succeed(
Expand All @@ -72,9 +72,7 @@ export async function generateActionNoExit(
)
}

async function generateAction(
...params: Parameters<typeof generateActionNoExit>
) {
async function generateAction(...params: Parameters<typeof generateActionNoExit>) {
await generateActionNoExit(...params)
exit(0)
}
Expand Down
34 changes: 14 additions & 20 deletions packages/artifacts/src/cli/commands/generate/prompts.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,22 @@
import input from '@inquirer/input'
import select from '@inquirer/select'
import { validateJsonFileInput } from 'cli/validators'
import { validateJsonFileInput } from '../../../cli/validators'

export const getCircomkitConfigInput = async () =>
input(
{
message: 'Enter the source circomkit file path:',
default: 'circomkit.json',
validate: validateJsonFileInput,
},
)
input({
message: 'Enter the source circomkit file path:',
default: 'circomkit.json',
validate: validateJsonFileInput,
})

export const getDestinationInput = async (defaultDestination: string) =>
input(
{
message: 'Enter the destination path for the generated artifacts:',
default: defaultDestination,
},
)
input({
message: 'Enter the destination path for the generated artifacts:',
default: defaultDestination,
})

export const selectCircuit = async (circuits: string[]) =>
select(
{
message: 'Select the circuit to generate snark artifacts for:',
choices: circuits.map((circuit) => ({ name: circuit, value: circuit })),
},
)
select({
message: 'Select the circuit to generate snark artifacts for:',
choices: circuits.map((circuit) => ({ name: circuit, value: circuit })),
})
38 changes: 19 additions & 19 deletions packages/artifacts/src/cli/commands/list.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import { Command } from '@commander-js/extra-typings'
import { exit } from 'node:process'
import { getAvailableVersions, projects } from 'projects'
import { getAvailableVersions, projects } from '../../projects'
import { spinner } from '../spinner'

export const list = new Command('list').alias('l').description(
'List all projects and their available packages versions',
).action(async () => {
spinner.start()
let output = ''
for (const project of projects) {
output += `${project}\n`
try {
const versions = await getAvailableVersions(project)
for (const version of versions)
output += ` ${version}\n`
} catch (error) {
spinner.fail(error.message)
exit(1)
export const list = new Command('list')
.alias('l')
.description('List all projects and their available packages versions')
.action(async () => {
spinner.start()
let output = ''
for (const project of projects) {
output += `${project}\n`
try {
const versions = await getAvailableVersions(project)
for (const version of versions) output += ` ${version}\n`
} catch (error) {
spinner.fail(error.message)
exit(1)
}
}
}
spinner.succeed()
console.log(output)
})
spinner.succeed()
console.log(output)
})
2 changes: 1 addition & 1 deletion packages/artifacts/src/cli/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { run } from './cli.ts'
import { run } from './cli'

run()
2 changes: 1 addition & 1 deletion packages/artifacts/src/cli/validators.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { existsSync } from 'node:fs'
import { extname } from 'node:path'
import { type Project, projects } from 'projects'
import { type Project, projects } from '../projects'
import { CliError } from './errors'

export function validateFilePath(input: string) {
Expand Down
9 changes: 3 additions & 6 deletions packages/artifacts/src/download/index.browser.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type Project, projects } from 'projects'
import { type Project, projects } from '../projects'
import type { SnarkArtifacts, Version } from './types'
import { getBaseUrl } from './urls'

Expand All @@ -9,14 +9,11 @@ export default async function maybeGetSnarkArtifacts(
version?: Version
} = {},
): Promise<SnarkArtifacts> {
if (!projects.includes(project))
throw new Error(`Project '${project}' is not supported`)
if (!projects.includes(project)) throw new Error(`Project '${project}' is not supported`)

options.version ??= 'latest'
const url = getBaseUrl(project, options.version)
const parameters = options.parameters
? `-${options.parameters.join('-')}`
: ''
const parameters = options.parameters ? `-${options.parameters.join('-')}` : ''

return {
wasm: `${url}${parameters}.wasm`,
Expand Down
8 changes: 3 additions & 5 deletions packages/artifacts/src/download/index.node.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { tmpdir } from 'node:os'
import { maybeDownload } from './download.ts'
import _maybeGetSnarkArtifacts from './index.browser.ts'
import { maybeDownload } from './download'
import _maybeGetSnarkArtifacts from './index.browser'
import type { SnarkArtifacts } from './types'

const extractEndPath = (url: string) => url.split('pse.dev/')[1]
Expand All @@ -19,9 +19,7 @@ const extractEndPath = (url: string) => url.split('pse.dev/')[1]
export default async function maybeGetSnarkArtifacts(
...pars: Parameters<typeof _maybeGetSnarkArtifacts>
): Promise<SnarkArtifacts> {
const urls = await _maybeGetSnarkArtifacts(
...pars,
)
const urls = await _maybeGetSnarkArtifacts(...pars)

const outputPath = `${tmpdir()}/snark-artifacts/${extractEndPath(urls.wasm)}`

Expand Down
2 changes: 1 addition & 1 deletion packages/artifacts/src/download/urls.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Project } from 'projects'
import type { Project } from '../projects'
import type { Version } from './types'

const BASE_URL = 'https://snark-artifacts.pse.dev'
Expand Down
4 changes: 2 additions & 2 deletions packages/artifacts/src/index.browser.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from 'index.shared'
import maybeGetSnarkArtifacts from 'download/index.browser'
export * from './index.shared'
import maybeGetSnarkArtifacts from './download/index.browser'
export { maybeGetSnarkArtifacts }
6 changes: 3 additions & 3 deletions packages/artifacts/src/index.node.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export { download, maybeDownload } from 'download/download'
export * from 'index.shared'
import maybeGetSnarkArtifacts from 'download/index.node'
export { download, maybeDownload } from './download/download'
export * from './index.shared'
import maybeGetSnarkArtifacts from './download/index.node'
export { maybeGetSnarkArtifacts }
4 changes: 2 additions & 2 deletions packages/artifacts/src/index.shared.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from 'download/types'
export { Project, projects } from 'projects'
export * from './download/types'
export { Project, projects } from './projects'
2 changes: 1 addition & 1 deletion packages/artifacts/test/cli/jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { JestConfigWithTsJest } from 'ts-jest'
import _sharedJestConf from '../../../../jest.config.ts'
import _sharedJestConf from '../../../../jest.config'

const { collectCoverage, projects, ...sharedJestConf } = _sharedJestConf

Expand Down
8 changes: 5 additions & 3 deletions packages/artifacts/test/cli/unit/validators.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { writeFileSync } from 'node:fs'
import { rm } from 'node:fs/promises'
import { CliError } from '../../../src/cli/errors.ts'
import { validateFilePath, validateJsonFileInput, validateOrThrow } from '../../../src/cli/validators.ts'
import { CliError } from '../../../src/cli/errors'
import { validateFilePath, validateJsonFileInput, validateOrThrow } from '../../../src/cli/validators'

describe('validateFilePath', () => {
it('should return true if the file exists', () => {
Expand All @@ -16,7 +16,9 @@ describe('validateFilePath', () => {
describe('validateJsonFileInput', () => {
const jsonFile = 'file.json'
afterAll(async () => {
await rm(jsonFile).catch(() => {/* swallow */})
await rm(jsonFile).catch(() => {
/* swallow */
})
})

it('should return true if the file exists and has a .json extension', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/artifacts/test/jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { JestConfigWithTsJest } from 'ts-jest'
import _sharedJestConf from '../../../jest.config.ts'
import _sharedJestConf from '../../../jest.config'

const { collectCoverage, projects, ...sharedJestConf } = _sharedJestConf

Expand Down
9 changes: 4 additions & 5 deletions packages/artifacts/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
{
"extends": "./tsconfig.json",
"include": ["src"],
"extends": "../../tsconfig.json",
"compilerOptions": {
"baseUrl": "src",
"declaration": true,
"baseUrl": ".",
"outDir": "dist/types"
}
},
"include": ["src"]
}
5 changes: 1 addition & 4 deletions packages/artifacts/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{
"extends": "../../tsconfig.json",
"include": ["src", "test", "rollup.config.ts"],
"compilerOptions": {
"baseUrl": "src"
}
"include": ["src", "test", "rollup.config.ts"]
}
Loading