Skip to content
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
2 changes: 1 addition & 1 deletion apps/lunarswap-ui/biome.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"extends": ["@midnight-dapps/biome-config/biome"]
"extends": ["@midnight-dapps/biome-config"]
}
2 changes: 1 addition & 1 deletion contracts/access/.lintstagedrc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"*.{js,ts,json,md}": ["biome format --write", "biome check --write"]
"*.{ts,md}": ["biome format --write", "biome check --write"]
}
2 changes: 1 addition & 1 deletion contracts/access/biome.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"extends": ["@midnight-dapps/biome-config/biome"]
"extends": ["@midnight-dapps/biome-config"]
}
4 changes: 1 addition & 3 deletions contracts/access/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{
"extends": "./tsconfig.json",
"exclude": [
"src/test/**/*.ts"
],
"exclude": ["src/test/**/*.ts", "src/artifacts/**/*"],
"compilerOptions": {}
}
2 changes: 1 addition & 1 deletion contracts/math/.lintstagedrc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"*.{js,ts,json,md}": ["biome format --write", "biome check --write"]
"*.{ts,md}": ["biome format --write", "biome check --write"]
}
2 changes: 1 addition & 1 deletion contracts/math/biome.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"extends": ["@midnight-dapps/biome-config/biome"]
"extends": ["@midnight-dapps/biome-config"]
}
2 changes: 1 addition & 1 deletion contracts/math/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "./tsconfig.json",
"exclude": ["src/test/**/*.ts"],
"exclude": ["src/test/**/*.ts", "src/artifacts/**/*"],
"compilerOptions": {}
}
2 changes: 1 addition & 1 deletion contracts/structs/.lintstagedrc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"*.{js,ts,json,md}": ["biome format --write", "biome check --write"]
"*.{ts,md}": ["biome format --write", "biome check --write"]
}
2 changes: 1 addition & 1 deletion contracts/structs/biome.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"extends": ["@midnight-dapps/biome-config/biome"]
"extends": ["@midnight-dapps/biome-config"]
}
2 changes: 1 addition & 1 deletion contracts/structs/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "./tsconfig.json",
"exclude": ["src/test/**/*.ts"],
"exclude": ["src/test/**/*.ts", "src/artifacts/**/*"],
"compilerOptions": {}
}
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/biome-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"type": "module",
"private": true,
"exports": {
"./biome": "./biome.json"
".": "./biome.json"
}
}
2 changes: 1 addition & 1 deletion packages/compact-std/biome.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"extends": ["@midnight-dapps/biome-config/biome"]
"extends": ["@midnight-dapps/biome-config"]
}
4 changes: 4 additions & 0 deletions packages/compact-std/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/compact/biome.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"extends": ["@midnight-dapps/biome-config/biome"]
"extends": ["@midnight-dapps/biome-config"]
}
95 changes: 32 additions & 63 deletions packages/compact/src/Builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 <caption>Successful Build Output</caption>
* ```
* ℹ [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 <caption>Failed Compilation Output</caption>
* ```
* ℹ [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 <caption>Failed Build Step Output</caption>
* ```
* ℹ [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;
Expand All @@ -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',
},
Expand All @@ -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<void> {
// 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);
}
Expand All @@ -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 },
Expand All @@ -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,
Expand All @@ -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')));
}
}
}
Loading