From 0fe114a2379acb5f66c8beb14a43cbc71c9eb177 Mon Sep 17 00:00:00 2001 From: 0xisk Date: Wed, 3 Sep 2025 12:52:07 +0200 Subject: [PATCH 1/3] fix: export biome on root --- apps/lunarswap-ui/biome.json | 2 +- contracts/access/biome.json | 2 +- contracts/math/biome.json | 2 +- contracts/structs/biome.json | 2 +- package.json | 2 + packages/biome-config/package.json | 2 +- packages/compact-std/biome.json | 2 +- packages/compact-std/package.json | 4 ++ packages/compact/biome.json | 2 +- packages/compact/src/Builder.ts | 95 ++++++++++-------------------- 10 files changed, 45 insertions(+), 70 deletions(-) diff --git a/apps/lunarswap-ui/biome.json b/apps/lunarswap-ui/biome.json index 296b1c7a..98ebf7d2 100644 --- a/apps/lunarswap-ui/biome.json +++ b/apps/lunarswap-ui/biome.json @@ -1,3 +1,3 @@ { - "extends": ["@midnight-dapps/biome-config/biome"] + "extends": ["@midnight-dapps/biome-config"] } diff --git a/contracts/access/biome.json b/contracts/access/biome.json index 296b1c7a..98ebf7d2 100644 --- a/contracts/access/biome.json +++ b/contracts/access/biome.json @@ -1,3 +1,3 @@ { - "extends": ["@midnight-dapps/biome-config/biome"] + "extends": ["@midnight-dapps/biome-config"] } diff --git a/contracts/math/biome.json b/contracts/math/biome.json index 296b1c7a..98ebf7d2 100644 --- a/contracts/math/biome.json +++ b/contracts/math/biome.json @@ -1,3 +1,3 @@ { - "extends": ["@midnight-dapps/biome-config/biome"] + "extends": ["@midnight-dapps/biome-config"] } diff --git a/contracts/structs/biome.json b/contracts/structs/biome.json index 296b1c7a..98ebf7d2 100644 --- a/contracts/structs/biome.json +++ b/contracts/structs/biome.json @@ -1,3 +1,3 @@ { - "extends": ["@midnight-dapps/biome-config/biome"] + "extends": ["@midnight-dapps/biome-config"] } diff --git a/package.json b/package.json index 54a0ee70..55c7687c 100644 --- a/package.json +++ b/package.json @@ -10,8 +10,10 @@ "compact:fast": "turbo run compact -- --skip-zk", "compact:version": "turbo run compact -- --version", "compact:language-version": "turbo run compact -- --language-version", + "build": "turbo run build", "build:contracts": "for d in ./contracts/*; do if [ -d \"$d\" ]; then cd \"$d\" && pnpm build && cd - > /dev/null; fi; done", "build:apps": "turbo run build --filter './apps/*'", + "build:packages": "turbo run build --filter './packages/*'", "test:contracts": "turbo run test --filter './contracts/*'", "test:apps": "turbo run test --filter './apps/*'", "fmt": "turbo run fmt", diff --git a/packages/biome-config/package.json b/packages/biome-config/package.json index 6e2a124a..4445617c 100644 --- a/packages/biome-config/package.json +++ b/packages/biome-config/package.json @@ -4,6 +4,6 @@ "type": "module", "private": true, "exports": { - "./biome": "./biome.json" + ".": "./biome.json" } } diff --git a/packages/compact-std/biome.json b/packages/compact-std/biome.json index 296b1c7a..98ebf7d2 100644 --- a/packages/compact-std/biome.json +++ b/packages/compact-std/biome.json @@ -1,3 +1,3 @@ { - "extends": ["@midnight-dapps/biome-config/biome"] + "extends": ["@midnight-dapps/biome-config"] } diff --git a/packages/compact-std/package.json b/packages/compact-std/package.json index eb4fed05..142bdab1 100644 --- a/packages/compact-std/package.json +++ b/packages/compact-std/package.json @@ -6,6 +6,10 @@ "type": "module", "main": "dist/index.js", "types": "dist/index.d.ts", + "exports": { + ".": "./dist/index.js", + "./artifacts": "./dist/artifacts/index.js" + }, "scripts": { "prepare": "pnpm build", "compact": "pnpm exec compact-compiler", diff --git a/packages/compact/biome.json b/packages/compact/biome.json index 296b1c7a..98ebf7d2 100644 --- a/packages/compact/biome.json +++ b/packages/compact/biome.json @@ -1,3 +1,3 @@ { - "extends": ["@midnight-dapps/biome-config/biome"] + "extends": ["@midnight-dapps/biome-config"] } diff --git a/packages/compact/src/Builder.ts b/packages/compact/src/Builder.ts index 3c7ff875..1d797d04 100755 --- a/packages/compact/src/Builder.ts +++ b/packages/compact/src/Builder.ts @@ -12,44 +12,7 @@ const execAsync = promisify(exec); /** * A class to handle the build process for a project. * Runs CompactCompiler as a prerequisite, then executes build steps (TypeScript compilation, - * artifact copying, etc.) - * with progress feedback and colored output for success and error states. - * - * @example - * ```typescript - * const builder = new ProjectBuilder('--skip-zk'); // Optional flags for compactc - * builder.build().catch(err => console.error(err)); - * ``` - * - * @example Successful Build Output - * ``` - * ℹ [COMPILE] Found 2 .compact file(s) to compile - * ✔ [COMPILE] [1/2] Compiled AccessControl.compact - * Compactc version: 0.22.0 - * ✔ [COMPILE] [2/2] Compiled MockAccessControl.compact - * Compactc version: 0.22.0 - * ✔ [BUILD] [1/3] Compiling TypeScript - * ✔ [BUILD] [2/3] Copying artifacts - * ✔ [BUILD] [3/3] Copying and cleaning .compact files - * ``` - * - * @example Failed Compilation Output - * ``` - * ℹ [COMPILE] Found 2 .compact file(s) to compile - * ✖ [COMPILE] [1/2] Failed AccessControl.compact - * Compactc version: 0.22.0 - * Error: Expected ';' at line 5 in AccessControl.compact - * ``` - * - * @example Failed Build Step Output - * ``` - * ℹ [COMPILE] Found 2 .compact file(s) to compile - * ✔ [COMPILE] [1/2] Compiled AccessControl.compact - * ✔ [COMPILE] [2/2] Compiled MockAccessControl.compact - * ✖ [BUILD] [1/3] Failed Compiling TypeScript - * error TS1005: ';' expected at line 10 in file.ts - * [BUILD] ❌ Build failed: Command failed: tsc --project tsconfig.build.json - * ``` + * artifact copying, etc.) with progress feedback and colored output for success and error states. */ export class CompactBuilder { private readonly compilerFlags: string; @@ -65,7 +28,28 @@ export class CompactBuilder { shell: '/bin/bash', }, { - cmd: 'mkdir -p dist && find src -type f -name "*.compact" -exec cp {} dist/ \\; 2>/dev/null && rm dist/Mock*.compact 2>/dev/null || true', + /** + * Shell command to copy and clean `.compact` files from `src` to `dist`. + * - Creates `dist` directory if it doesn't exist. + * - Copies `.compact` files from `src` root to `dist` root (e.g., `src/Math.compact` → `dist/Math.compact`). + * - Copies `.compact` files from `src` subdirectories to `dist` with preserved structure (e.g., `src/interfaces/IMath.compact` → `dist/interfaces/IMath.compact`). + * - Excludes files in `src/test` and `src/src` directories. + * - Removes `Mock*.compact` files from `dist`. + * - Redirects errors to `/dev/null` and ensures the command succeeds with `|| true`. + */ + cmd: [ + 'mkdir -p dist && \\', // Create dist directory if it doesn't exist + 'find src -maxdepth 1 -type f -name "*.compact" -exec cp {} dist/ \\; && \\', // Copy .compact files from src root to dist root + 'find src -type f -name "*.compact" \\', // Find .compact files in src subdirectories + ' -not -path "src/test/*" \\', // Exclude src/test directory + ' -not -path "src/src/*" \\', // Exclude src/src directory + ' -path "src/*/*" \\', // Only include files in subdirectories + ' -exec sh -c \\', // Execute a shell command for each file + ' \'mkdir -p "dist/$(dirname "{}" | sed "s|^src/||")" && \\', // Create subdirectory in dist + ' cp "{}" "dist/$(dirname "{}" | sed "s|^src/||")/"\' \\; \\', // Copy file to matching dist subdirectory + '2>/dev/null && \\', // Suppress error output + 'rm dist/Mock*.compact 2>/dev/null || true', // Remove Mock*.compact files, ignore errors + ].join('\n'), msg: 'Copying and cleaning .compact files', shell: '/bin/bash', }, @@ -82,16 +66,11 @@ export class CompactBuilder { /** * Executes the full build process: compiles .compact files first, then runs build steps. * Displays progress with spinners and outputs results in color. - * - * @returns A promise that resolves when all steps complete successfully - * @throws Error if compilation or any build step fails */ public async build(): Promise { - // Run compact compilation as a prerequisite const compiler = new CompactCompiler(this.compilerFlags); await compiler.compile(); - // Proceed with build steps for (const [index, step] of this.steps.entries()) { await this.executeStep(step, index, this.steps.length); } @@ -100,12 +79,6 @@ export class CompactBuilder { /** * Executes a single build step. * Runs the command, shows a spinner, and prints output with indentation. - * - * @param step - The build step containing command and message - * @param index - Current step index (0-based) for progress display - * @param total - Total number of steps for progress display - * @returns A promise that resolves when the step completes successfully - * @throws Error if the step fails */ private async executeStep( step: { cmd: string; msg: string; shell?: string }, @@ -118,26 +91,23 @@ export class CompactBuilder { try { const { stdout, stderr }: { stdout: string; stderr: string } = await execAsync(step.cmd, { - shell: step.shell, // Only pass shell where needed + shell: step.shell, }); spinner.succeed(`[BUILD] ${stepLabel} ${step.msg}`); this.printOutput(stdout, chalk.cyan); - this.printOutput(stderr, chalk.yellow); // Show stderr (warnings) in yellow if present - } catch (error: any) { - spinner.fail(`[BUILD] ${stepLabel} ${step.msg}`); - this.printOutput(error.stdout, chalk.cyan); - this.printOutput(error.stderr, chalk.red); - console.error(chalk.red('[BUILD] ❌ Build failed:', error.message)); - process.exit(1); + this.printOutput(stderr, chalk.yellow); + } catch (error: unknown) { + if (error instanceof Error) { + spinner.fail(`[BUILD] ${stepLabel} ${step.msg}`); + this.printOutput(error.message, chalk.red); + } + throw error; } } /** * Prints command output with indentation and specified color. * Filters out empty lines and indents each line for readability. - * - * @param output - The command output string to print (stdout or stderr) - * @param colorFn - Chalk color function to style the output (e.g., `chalk.cyan` for success, `chalk.red` for errors) */ private printOutput( output: string | undefined, @@ -148,8 +118,7 @@ export class CompactBuilder { .split('\n') .filter((line: string): boolean => line.trim() !== '') .map((line: string): string => ` ${line}`); - // biome-ignore lint/suspicious/noConsoleLog: needed for debugging - console.log(colorFn(lines.join('\n'))); + console.info(colorFn(lines.join('\n'))); } } } From 131123dbc593270de0ed2b98cd94158be4246aaa Mon Sep 17 00:00:00 2001 From: 0xisk Date: Mon, 22 Sep 2025 15:03:05 +0200 Subject: [PATCH 2/3] fix: build issue --- contracts/access/.lintstagedrc.json | 2 +- contracts/access/tsconfig.build.json | 3 ++- contracts/math/.lintstagedrc.json | 2 +- contracts/math/tsconfig.build.json | 2 +- contracts/structs/.lintstagedrc.json | 2 +- contracts/structs/tsconfig.build.json | 2 +- 6 files changed, 7 insertions(+), 6 deletions(-) diff --git a/contracts/access/.lintstagedrc.json b/contracts/access/.lintstagedrc.json index 64b7ae62..8a7175ab 100644 --- a/contracts/access/.lintstagedrc.json +++ b/contracts/access/.lintstagedrc.json @@ -1,3 +1,3 @@ { - "*.{js,ts,json,md}": ["biome format --write", "biome check --write"] + "*.{ts,md}": ["biome format --write", "biome check --write"] } diff --git a/contracts/access/tsconfig.build.json b/contracts/access/tsconfig.build.json index 4f3919ce..6d69f18f 100644 --- a/contracts/access/tsconfig.build.json +++ b/contracts/access/tsconfig.build.json @@ -1,7 +1,8 @@ { "extends": "./tsconfig.json", "exclude": [ - "src/test/**/*.ts" + "src/test/**/*.ts", + "src/artifacts/**/*" ], "compilerOptions": {} } \ No newline at end of file diff --git a/contracts/math/.lintstagedrc.json b/contracts/math/.lintstagedrc.json index 64b7ae62..8a7175ab 100644 --- a/contracts/math/.lintstagedrc.json +++ b/contracts/math/.lintstagedrc.json @@ -1,3 +1,3 @@ { - "*.{js,ts,json,md}": ["biome format --write", "biome check --write"] + "*.{ts,md}": ["biome format --write", "biome check --write"] } diff --git a/contracts/math/tsconfig.build.json b/contracts/math/tsconfig.build.json index 88af15f8..7024eef6 100644 --- a/contracts/math/tsconfig.build.json +++ b/contracts/math/tsconfig.build.json @@ -1,5 +1,5 @@ { "extends": "./tsconfig.json", - "exclude": ["src/test/**/*.ts"], + "exclude": ["src/test/**/*.ts", "src/artifacts/**/*.ts"], "compilerOptions": {} } \ No newline at end of file diff --git a/contracts/structs/.lintstagedrc.json b/contracts/structs/.lintstagedrc.json index 64b7ae62..8a7175ab 100644 --- a/contracts/structs/.lintstagedrc.json +++ b/contracts/structs/.lintstagedrc.json @@ -1,3 +1,3 @@ { - "*.{js,ts,json,md}": ["biome format --write", "biome check --write"] + "*.{ts,md}": ["biome format --write", "biome check --write"] } diff --git a/contracts/structs/tsconfig.build.json b/contracts/structs/tsconfig.build.json index 8b855b57..c5ac8d0b 100644 --- a/contracts/structs/tsconfig.build.json +++ b/contracts/structs/tsconfig.build.json @@ -1,5 +1,5 @@ { "extends": "./tsconfig.json", - "exclude": ["src/test/**/*.ts"], + "exclude": ["src/test/**/*.ts", "src/artifacts/**/*.ts"], "compilerOptions": {} } From 53574bf4091fbcf4d09fef216b68c48654a737ab Mon Sep 17 00:00:00 2001 From: 0xisk Date: Mon, 22 Sep 2025 15:34:35 +0200 Subject: [PATCH 3/3] fix: build issue --- contracts/access/tsconfig.build.json | 5 +---- contracts/math/tsconfig.build.json | 2 +- contracts/structs/tsconfig.build.json | 2 +- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/contracts/access/tsconfig.build.json b/contracts/access/tsconfig.build.json index 6d69f18f..57859539 100644 --- a/contracts/access/tsconfig.build.json +++ b/contracts/access/tsconfig.build.json @@ -1,8 +1,5 @@ { "extends": "./tsconfig.json", - "exclude": [ - "src/test/**/*.ts", - "src/artifacts/**/*" - ], + "exclude": ["src/test/**/*.ts", "src/artifacts/**/*"], "compilerOptions": {} } \ No newline at end of file diff --git a/contracts/math/tsconfig.build.json b/contracts/math/tsconfig.build.json index 7024eef6..956f0568 100644 --- a/contracts/math/tsconfig.build.json +++ b/contracts/math/tsconfig.build.json @@ -1,5 +1,5 @@ { "extends": "./tsconfig.json", - "exclude": ["src/test/**/*.ts", "src/artifacts/**/*.ts"], + "exclude": ["src/test/**/*.ts", "src/artifacts/**/*"], "compilerOptions": {} } \ No newline at end of file diff --git a/contracts/structs/tsconfig.build.json b/contracts/structs/tsconfig.build.json index c5ac8d0b..e5eb9fd5 100644 --- a/contracts/structs/tsconfig.build.json +++ b/contracts/structs/tsconfig.build.json @@ -1,5 +1,5 @@ { "extends": "./tsconfig.json", - "exclude": ["src/test/**/*.ts", "src/artifacts/**/*.ts"], + "exclude": ["src/test/**/*.ts", "src/artifacts/**/*"], "compilerOptions": {} }