@buenos_andres/compact-builder 0.5.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,76 @@
1
+ import { readdir } from 'node:fs/promises';
2
+ import { join, relative } from 'node:path';
3
+ import { DEFAULT_SRC_DIR } from "../types/options.js";
4
+ import { isExcluded } from "../utils.js";
5
+ /**
6
+ * Service responsible for discovering .compact files in the source directory.
7
+ * Recursively scans directories and filters for .compact file extensions,
8
+ * applying user-supplied exclude patterns.
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * const discovery = new FileDiscovery('src', ['Mock*']);
13
+ * const files = await discovery.getCompactFiles('src/security');
14
+ * ```
15
+ */
16
+ export class FileDiscovery {
17
+ srcDir;
18
+ excludes;
19
+ /**
20
+ * Creates a new FileDiscovery instance.
21
+ *
22
+ * @param srcDir - Base source directory for relative path calculation (default: 'src')
23
+ * @param excludes - Glob-style patterns of `.compact` files to skip.
24
+ * Patterns containing `/` match against the full path
25
+ * (as `find <srcDir>` would emit it); others match against
26
+ * the filename only. Default: `[]`.
27
+ */
28
+ constructor(srcDir = DEFAULT_SRC_DIR, excludes = []) {
29
+ this.srcDir = srcDir;
30
+ this.excludes = excludes;
31
+ }
32
+ /**
33
+ * Recursively discovers all .compact files in a directory.
34
+ * Returns relative paths from the srcDir for consistent processing.
35
+ *
36
+ * @param dir - Directory path to search (relative or absolute)
37
+ * @returns Promise resolving to array of relative file paths
38
+ */
39
+ async getCompactFiles(dir) {
40
+ try {
41
+ const dirents = await readdir(dir, { withFileTypes: true });
42
+ const filePromises = dirents.map(async (entry) => {
43
+ const fullPath = join(dir, entry.name);
44
+ try {
45
+ if (entry.isDirectory()) {
46
+ return await this.getCompactFiles(fullPath);
47
+ }
48
+ if (entry.isFile() && fullPath.endsWith('.compact')) {
49
+ const relPath = relative(this.srcDir, fullPath);
50
+ // Match path-style patterns against fullPath (i.e. the path that
51
+ // `find srcDir` would emit) so users can write `*/archive/*` etc.,
52
+ // identical to what they'd pass to `find -path`.
53
+ if (isExcluded(entry.name, fullPath, this.excludes)) {
54
+ return [];
55
+ }
56
+ return [relPath];
57
+ }
58
+ return [];
59
+ }
60
+ catch (err) {
61
+ // biome-ignore lint/suspicious/noConsole: Needed to display error and file path
62
+ console.warn(`Error accessing ${fullPath}:`, err);
63
+ return [];
64
+ }
65
+ });
66
+ const results = await Promise.all(filePromises);
67
+ return results.flat();
68
+ }
69
+ catch (err) {
70
+ // biome-ignore lint/suspicious/noConsole: Needed to display error and dir path
71
+ console.error(`Failed to read dir: ${dir}`, err);
72
+ return [];
73
+ }
74
+ }
75
+ }
76
+ //# sourceMappingURL=FileDiscovery.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FileDiscovery.js","sourceRoot":"","sources":["../../src/services/FileDiscovery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC;;;;;;;;;;GAUG;AACH,MAAM,OAAO,aAAa;IAChB,MAAM,CAAS;IACf,QAAQ,CAAoB;IAEpC;;;;;;;;OAQG;IACH,YACE,SAAiB,eAAe,EAChC,WAA8B,EAAE;QAEhC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,eAAe,CAAC,GAAW;QAC/B,IAAI,CAAC;YACH,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,GAAG,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC;YAC5D,MAAM,YAAY,GAAG,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,EA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atting for compiler messages and output.
4
+ *
5
+ * @example
6
+ * ```typescript
7
+ * UIService.displayEnvInfo('compact 0.1.0', 'Compactc 0.26.0', 'security');
8
+ * UIService.printOutput('Compilation successful', chalk.green);
9
+ * ```
10
+ */
11
+ export declare const UIService: {
12
+ /**
13
+ * Prints formatted output with consistent indentation and coloring.
14
+ * Filters empty lines and adds consistent indentation for readability.
15
+ *
16
+ * @param output - Raw output text to format
17
+ * @param colorFn - Chalk color function for styling
18
+ */
19
+ printOutput(output: string, colorFn: (text: string) => string): void;
20
+ /**
21
+ * Displays environment information including tool versions and configuration.
22
+ * Shows developer tools version, toolchain version, and optional settings.
23
+ *
24
+ * @param devToolsVersion - Version string of the Compact developer tools
25
+ * @param toolchainVersion - Version string of the Compact toolchain/compiler
26
+ * @param targetDir - Optional target directory being compiled
27
+ * @param version - Optional specific version being used
28
+ */
29
+ displayEnvInfo(devToolsVersion: string, toolchainVersion: string, targetDir?: string, version?: string): void;
30
+ /**
31
+ * Displays compilation start message with file count and optional location.
32
+ *
33
+ * @param fileCount - Number of files to be compiled
34
+ * @param targetDir - Optional target directory being compiled
35
+ */
36
+ showCompilationStart(fileCount: number, targetDir?: string): void;
37
+ /**
38
+ * Displays a warning message when no .compact files are found.
39
+ *
40
+ * @param targetDir - Optional target directory that was searched
41
+ */
42
+ showNoFiles(targetDir?: string): void;
43
+ };
@@ -0,0 +1,70 @@
1
+ import chalk from 'chalk';
2
+ import ora from 'ora';
3
+ /**
4
+ * Utility service for handling user interface output and formatting.
5
+ * Provides consistent styling and formatting for compiler messages and output.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * UIService.displayEnvInfo('compact 0.1.0', 'Compactc 0.26.0', 'security');
10
+ * UIService.printOutput('Compilation successful', chalk.green);
11
+ * ```
12
+ */
13
+ export const UIService = {
14
+ /**
15
+ * Prints formatted output with consistent indentation and coloring.
16
+ * Filters empty lines and adds consistent indentation for readability.
17
+ *
18
+ * @param output - Raw output text to format
19
+ * @param colorFn - Chalk color function for styling
20
+ */
21
+ printOutput(output, colorFn) {
22
+ const lines = output
23
+ .split('\n')
24
+ .filter((line) => line.trim() !== '')
25
+ .map((line) => ` ${line}`);
26
+ console.log(colorFn(lines.join('\n')));
27
+ },
28
+ /**
29
+ * Displays environment information including tool versions and configuration.
30
+ * Shows developer tools version, toolchain version, and optional settings.
31
+ *
32
+ * @param devToolsVersion - Version string of the Compact developer tools
33
+ * @param toolchainVersion - Version string of the Compact toolchain/compiler
34
+ * @param targetDir - Optional target directory being compiled
35
+ * @param version - Optional specific version being used
36
+ */
37
+ displayEnvInfo(devToolsVersion, toolchainVersion, targetDir, version) {
38
+ const spinner = ora();
39
+ if (targetDir) {
40
+ spinner.info(chalk.blue(`[COMPILE] TARGET_DIR: ${targetDir}`));
41
+ }
42
+ spinner.info(chalk.blue(`[COMPILE] Compact developer tools: ${devToolsVersion}`));
43
+ spinner.info(chalk.blue(`[COMPILE] Compact toolchain: ${toolchainVersion}`));
44
+ if (version) {
45
+ spinner.info(chalk.blue(`[COMPILE] Using toolchain version: ${version}`));
46
+ }
47
+ },
48
+ /**
49
+ * Displays compilation start message with file count and optional location.
50
+ *
51
+ * @param fileCount - Number of files to be compiled
52
+ * @param targetDir - Optional target directory being compiled
53
+ */
54
+ showCompilationStart(fileCount, targetDir) {
55
+ const searchLocation = targetDir ? ` in ${targetDir}/` : '';
56
+ const spinner = ora();
57
+ spinner.info(chalk.blue(`[COMPILE] Found ${fileCount} .compact file(s) to compile${searchLocation}`));
58
+ },
59
+ /**
60
+ * Displays a warning message when no .compact files are found.
61
+ *
62
+ * @param targetDir - Optional target directory that was searched
63
+ */
64
+ showNoFiles(targetDir) {
65
+ const searchLocation = targetDir ? `${targetDir}/` : '';
66
+ const spinner = ora();
67
+ spinner.warn(chalk.yellow(`[COMPILE] No .compact files found in ${searchLocation}.`));
68
+ },
69
+ };
70
+ //# sourceMappingURL=UIService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"UIService.js","sourceRoot":"","s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,CAAC,CAAC,CAAC,OAAO,SAAS,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;QAC5D,MAAM,OAAO,GAAG,GAAG,EAAE,CAAC;QACtB,OAAO,CAAC,IAAI,CACV,KAAK,CAAC,IAAI,CACR,mBAAmB,SAAS,+BAA+B,cAAc,EAAE,CAC5E,CACF,CAAC;IACJ,CAAC;IAED;;;;OAIG;IACH,WAAW,CAAC,SAAkB;QAC5B,MAAM,cAAc,GAAG,SAAS,CAAC,CAAC,CAAC,GAAG,SAAS,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;QACxD,MAAM,OAAO,GAAG,GAAG,EAAE,CAAC;QACtB,OAAO,CAAC,IAAI,CACV,KAAK,CAAC,MAAM,CAAC,wCAAwC,cAAc,GAAG,CAAC,CACxE,CAAC;IACJ,CAAC;CACF,CAAC"}
@@ -0,0 +1,75 @@
1
+ /**
2
+ * A custom error that describes the shape of an error returned from a promisfied
3
+ * child_process.exec
4
+ *
5
+ * @interface PromisifiedChildProcessError
6
+ * @typedef {PromisifiedChildProcessError}
7
+ * @extends {Error}
8
+ *
9
+ * @prop {string} stdout stdout of a child process
10
+ * @prop {string} stderr stderr of a child process
11
+ */
12
+ export interface PromisifiedChildProcessError extends Error {
13
+ stdout: string;
14
+ stderr: string;
15
+ }
16
+ /**
17
+ * A type guard function for PromisifiedChildProcessError
18
+ *
19
+ * @param {unknown} error - An error caught in a try catch block
20
+ * @returns {error is PromisifiedChildProcessError} - Informs TS compiler if the understood
21
+ * type is a PromisifiedChildProcessError
22
+ */
23
+ export declare function isPromisifiedChildProcessError(error: unknown): error is PromisifiedChildProcessError;
24
+ /**
25
+ * Custom error thrown when the Compact CLI is not found in the system PATH.
26
+ * This error indicates that the Compact developer tools are not installed
27
+ * or not properly configured in the environment.
28
+ *
29
+ * @class CompactCliNotFoundError
30
+ * @extends Error
31
+ */
32
+ export declare class CompactCliNotFoundError extends Error {
33
+ /**
34
+ * Creates a new CompactCliNotFoundError instance.
35
+ *
36
+ * @param message - Error message describing the CLI availability issue
37
+ */
38
+ constructor(message: string);
39
+ }
40
+ /**
41
+ * Custom error thrown when compilation of a .compact file fails.
42
+ * Contains additional context about which file failed to compile,
43
+ * making it easier to identify and debug compilation issues.
44
+ *
45
+ * @class CompilationError
46
+ * @extends Error
47
+ */
48
+ export declare class CompilationError extends Error {
49
+ readonly file?: string;
50
+ /**
51
+ * Creates a new CompilationError instance.
52
+ *
53
+ * @param message - Error message describing the compilation failure
54
+ * @param file - Optional relative path to the file that failed to compile
55
+ */
56
+ constructor(message: string, file?: string, cause?: unknown);
57
+ }
58
+ /**
59
+ * Custom error thrown when a specified target directory does not exist.
60
+ * Provides specific information about which directory was not found,
61
+ * helping users correct path-related issues.
62
+ *
63
+ * @class DirectoryNotFoundError
64
+ * @extends Error
65
+ */
66
+ export declare class DirectoryNotFoundError extends Error {
67
+ readonly directory: string;
68
+ /**
69
+ * Creates a new DirectoryNotFoundError instance.
70
+ *
71
+ * @param message - Error message describing the directory issue
72
+ * @param directory - The directory path that was not found
73
+ */
74
+ constructor(message: string, directory: string);
75
+ }
@@ -0,0 +1,74 @@
1
+ /**
2
+ * A type guard function for PromisifiedChildProcessError
3
+ *
4
+ * @param {unknown} error - An error caught in a try catch block
5
+ * @returns {error is PromisifiedChildProcessError} - Informs TS compiler if the understood
6
+ * type is a PromisifiedChildProcessError
7
+ */
8
+ export function isPromisifiedChildProcessError(error) {
9
+ return error instanceof Error && 'stdout' in error && 'stderr' in error;
10
+ }
11
+ /**
12
+ * Custom error thrown when the Compact CLI is not found in the system PATH.
13
+ * This error indicates that the Compact developer tools are not installed
14
+ * or not properly configured in the environment.
15
+ *
16
+ * @class CompactCliNotFoundError
17
+ * @extends Error
18
+ */
19
+ export class CompactCliNotFoundError extends Error {
20
+ /**
21
+ * Creates a new CompactCliNotFoundError instance.
22
+ *
23
+ * @param message - Error message describing the CLI availability issue
24
+ */
25
+ constructor(message) {
26
+ super(message);
27
+ this.name = 'CompactCliNotFoundError';
28
+ }
29
+ }
30
+ /**
31
+ * Custom error thrown when compilation of a .compact file fails.
32
+ * Contains additional context about which file failed to compile,
33
+ * making it easier to identify and debug compilation issues.
34
+ *
35
+ * @class CompilationError
36
+ * @extends Error
37
+ */
38
+ export class CompilationError extends Error {
39
+ file;
40
+ /**
41
+ * Creates a new CompilationError instance.
42
+ *
43
+ * @param message - Error message describing the compilation failure
44
+ * @param file - Optional relative path to the file that failed to compile
45
+ */
46
+ constructor(message, file, cause) {
47
+ super(message, { cause });
48
+ this.file = file;
49
+ this.name = 'CompilationError';
50
+ }
51
+ }
52
+ /**
53
+ * Custom error thrown when a specified target directory does not exist.
54
+ * Provides specific information about which directory was not found,
55
+ * helping users correct path-related issues.
56
+ *
57
+ * @class DirectoryNotFoundError
58
+ * @extends Error
59
+ */
60
+ export class DirectoryNotFoundError extends Error {
61
+ directory;
62
+ /**
63
+ * Creates a new DirectoryNotFoundError instance.
64
+ *
65
+ * @param message - Error message describing the directory issue
66
+ * @param directory - The directory path that was not found
67
+ */
68
+ constructor(message, directory) {
69
+ super(message);
70
+ this.directory = directory;
71
+ this.name = 'DirectoryNotFoundError';
72
+ }
73
+ }
74
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/types/errors.ts"],"names":[],"mappings":"AAgBA;;;;;;GAMG;AACH,MAAM,UAAU,8BAA8B,CAC5C,KAAc;IAEd,OAAO,KAAK,YAAY,KAAK,IAAI,QAAQ,IAAI,KAAK,IAAI,QAAQ,IAAI,KAAK,CAAC;AAC1E,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,OAAO,uBAAwB,SAAQ,KAAK;IAChD;;;;OAIG;IACH,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,yBAAyB,CAAC;IACxC,CAAC;CACF;AAED;;;;;;;GAOG;AACH,MAAM,OAAO,gBAAiB,SAAQ,KAAK;IACzB,IAAI,CAAU;IAE9B;;;;;OAKG;IACH,YAAY,OAAe,EAAE,IAAa,EAAE,KAAe;QACzD,KAAK,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;QAE1B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAC;IACjC,CAAC;CACF;AAED;;;;;;;GAOG;AACH,MAAM,OAAO,sBAAuB,SAAQ,KAAK;IAC/B,SAAS,CAAS;IAElC;;;;;OAKG;IACH,YAAY,OAAe,EAAE,SAAiB;QAC5C,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,IAAI,GAAG,wBAAwB,CAAC;IACvC,CAAC;CACF"}
@@ -0,0 +1,128 @@
1
+ /**
2
+ * Shared option/type definitions and defaults for the Compact CLI tools.
3
+ *
4
+ * This module is the canonical home for cross-cutting types (`CompilerOptions`,
5
+ * `BuilderOptions`, `ExecFunction`, …) plus their default constants. Splitting
6
+ * them out keeps `Compiler.ts` and `Builder.ts` focused on behaviour rather
7
+ * than data shapes.
8
+ */
9
+ /** Default source directory containing .compact files. */
10
+ export declare const DEFAULT_SRC_DIR = "src";
11
+ /** Default output directory for compiled artifacts. */
12
+ export declare const DEFAULT_OUT_DIR = "artifacts";
13
+ /**
14
+ * Default `.compact` glob patterns the builder strips from `dist/` when the
15
+ * user hasn't supplied an explicit `--exclude` list. Covers both common mock
16
+ * naming conventions.
17
+ */
18
+ export declare const DEFAULT_EXCLUDE_PATTERNS: readonly string[];
19
+ /**
20
+ * Function type for executing a child process.
21
+ *
22
+ * Matches the shape of `promisify(child_process.execFile)`: the binary name
23
+ * (no shell), followed by positional arguments. This signature is injection-
24
+ * safe by construction — values flow as separate argv entries rather than
25
+ * being interpolated into a shell command string.
26
+ *
27
+ * @param file - The binary to invoke (e.g. `'compact'`)
28
+ * @param args - Positional arguments passed verbatim to the binary
29
+ * @returns Promise resolving to the captured stdout/stderr
30
+ */
31
+ export type ExecFunction = (file: string, args: readonly string[]) => Promise<{
32
+ stdout: string;
33
+ stderr: string;
34
+ }>;
35
+ /**
36
+ * Configuration options for the Compact compiler CLI.
37
+ *
38
+ * @example
39
+ * ```typescript
40
+ * const options: CompilerOptions = {
41
+ * flags: '--skip-zk --verbose',
42
+ * targetDir: 'security',
43
+ * version: '0.26.0',
44
+ * hierarchical: false,
45
+ * };
46
+ * ```
47
+ */
48
+ export interface CompilerOptions {
49
+ /** Compiler flags to pass to the Compact CLI (e.g., '--skip-zk --verbose') */
50
+ flags?: string;
51
+ /** Optional subdirectory within srcDir to compile (e.g., 'security', 'token') */
52
+ targetDir?: string;
53
+ /** Optional toolchain version to use (e.g., '0.26.0') */
54
+ version?: string;
55
+ /**
56
+ * Whether to preserve directory structure in artifacts output.
57
+ * - `false` (default): Flattened output - `<outDir>/<ContractName>/`
58
+ * - `true`: Hierarchical output - `<outDir>/<subdir>/<ContractName>/`
59
+ */
60
+ hierarchical?: boolean;
61
+ /** Source directory containing .compact files (default: 'src') */
62
+ srcDir?: string;
63
+ /** Output directory for compiled artifacts (default: 'artifacts') */
64
+ outDir?: string;
65
+ /**
66
+ * Glob-style patterns to exclude `.compact` files from both the compiler's
67
+ * file discovery and the builder's `.compact` copy step.
68
+ * - Patterns without `/` match against the filename only (e.g. `'Mock*'`).
69
+ * - Patterns with `/` match against the path as `find <srcDir>` would emit
70
+ * it (e.g. `'*\/archive\/*'`, matching `src/archive/Foo.compact`). This is
71
+ * the same semantic as `find -path '<pattern>'`.
72
+ *
73
+ * Default: `undefined` (no excludes for the compiler). The builder
74
+ * substitutes its own default ({@link DEFAULT_EXCLUDE_PATTERNS}) when
75
+ * undefined; pass an explicit `[]` to disable that too.
76
+ */
77
+ exclude?: string[];
78
+ }
79
+ /**
80
+ * Subset of {@link CompilerOptions} consumed by `CompilerService` when
81
+ * compiling individual files.
82
+ */
83
+ export type CompilerServiceOptions = Pick<CompilerOptions, 'hierarchical' | 'srcDir' | 'outDir'>;
84
+ /**
85
+ * Builder-only configuration options that don't apply to the compiler.
86
+ *
87
+ * These control the *distribution* layout produced by `compact-builder`,
88
+ * letting consumers ship a publishable `dist/` directory matching their
89
+ * package's conventions (e.g. copying metadata files for npm publish).
90
+ *
91
+ * Two inherited {@link CompilerOptions} fields also affect builder behaviour:
92
+ * - `hierarchical` — drives both compiler artifacts layout AND `.compact` copy layout.
93
+ * - `exclude` — drives both compiler file discovery AND `.compact` copy filtering.
94
+ * When `exclude` is undefined, the builder substitutes its own default
95
+ * ({@link DEFAULT_EXCLUDE_PATTERNS}) so mocks are stripped from the dist
96
+ * even when the compiler is told to consume them.
97
+ */
98
+ export interface BuilderOnlyOptions {
99
+ /**
100
+ * If true, runs `rm -rf dist && mkdir -p dist` before building.
101
+ * Use when you want a fully clean `dist/` on every build.
102
+ * @default false
103
+ */
104
+ cleanDist?: boolean;
105
+ /**
106
+ * Additional file paths to copy into `dist/` for distribution
107
+ * (e.g. `['package.json', '../README.md']`). Paths are relative to cwd.
108
+ * Each entry is copied individually with `cp <path> dist/`.
109
+ * @default []
110
+ */
111
+ copyToDist?: string[];
112
+ }
113
+ /**
114
+ * Configuration options for the Builder CLI.
115
+ * Extends {@link CompilerOptions} with builder-only distribution controls.
116
+ */
117
+ export type BuilderOptions = CompilerOptions & BuilderOnlyOptions;
118
+ /**
119
+ * Single build step executed by `CompactBuilder`.
120
+ */
121
+ export interface BuildStep {
122
+ /** Shell command to execute. */
123
+ cmd: string;
124
+ /** Human-readable progress message. */
125
+ msg: string;
126
+ /** Optional explicit shell (e.g. `'/bin/bash'`) when bash features are required. */
127
+ shell?: string;
128
+ }
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Shared option/type definitions and defaults for the Compact CLI tools.
3
+ *
4
+ * This module is the canonical home for cross-cutting types (`CompilerOptions`,
5
+ * `BuilderOptions`, `ExecFunction`, …) plus their default constants. Splitting
6
+ * them out keeps `Compiler.ts` and `Builder.ts` focused on behaviour rather
7
+ * than data shapes.
8
+ */
9
+ /** Default source directory containing .compact files. */
10
+ export const DEFAULT_SRC_DIR = 'src';
11
+ /** Default output directory for compiled artifacts. */
12
+ export const DEFAULT_OUT_DIR = 'artifacts';
13
+ /**
14
+ * Default `.compact` glob patterns the builder strips from `dist/` when the
15
+ * user hasn't supplied an explicit `--exclude` list. Covers both common mock
16
+ * naming conventions.
17
+ */
18
+ export const DEFAULT_EXCLUDE_PATTERNS = [
19
+ 'Mock*',
20
+ '*.mock.compact',
21
+ ];
22
+ //# sourceMappingURL=options.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"options.js","sourceRoot":"","sources":["../../src/types/options.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,0DAA0D;AAC1D,MAAM,CAAC,MAAM,eAAe,GAAG,KAAK,CAAC;AAErC,uDAAuD;AACvD,MAAM,CAAC,MAAM,eAAe,GAAG,WAAW,CAAC;AAE3C;;;;GAIG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAsB;IACzD,OAAO;IACP,gBAAgB;CACjB,CAAC"}
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Internal helpers for the Compact CLI tools.
3
+ *
4
+ * - **Glob matching** ({@link globToRegex}, {@link isExcluded}) — used by
5
+ * `FileDiscovery` to skip `.compact` files matching user-supplied patterns.
6
+ * - **Shell quoting** ({@link shellQuote}, {@link buildFindExcludes}) — used by
7
+ * `CompactBuilder` to interpolate user-supplied values into bash commands
8
+ * safely.
9
+ */
10
+ /**
11
+ * Converts a simple glob pattern to a regular expression.
12
+ * Supports `*` (any sequence) and `?` (single char). All other glob features
13
+ * (brace expansion, character classes) are not supported — keep patterns simple.
14
+ */
15
+ export declare function globToRegex(glob: string): RegExp;
16
+ /**
17
+ * Returns true if `filename`/`fullPath` matches any of the given glob patterns.
18
+ *
19
+ * - Patterns containing `/` are matched against `fullPath` (the path as
20
+ * `find srcDir` would emit it, e.g. `'src/archive/Foo.compact'`).
21
+ * - Patterns without `/` are matched against `filename` only.
22
+ *
23
+ * This mirrors the semantic of `find -name <pattern>` vs `find -path <pattern>`.
24
+ */
25
+ export declare function isExcluded(filename: string, fullPath: string, patterns: readonly string[]): boolean;
26
+ /**
27
+ * Shell-quotes a string for safe interpolation into a single-quoted bash arg.
28
+ *
29
+ * @example
30
+ * shellQuote("foo") // "'foo'"
31
+ * shellQuote("it's") // "'it'\\''s'"
32
+ */
33
+ export declare function shellQuote(value: string): string;
34
+ /**
35
+ * Builds the `find`-compatible exclusion fragment for the given patterns.
36
+ * Patterns containing `/` are emitted as `! -path '<pattern>'`; others as
37
+ * `! -name '<pattern>'`. Single-quoting ensures safe shell interpolation.
38
+ *
39
+ * @example
40
+ * buildFindExcludes(['Mock*', '*\/archive\/*'])
41
+ * // "! -name 'Mock*' ! -path '*\/archive\/*'"
42
+ */
43
+ export declare function buildFindExcludes(patterns: readonly string[]): string;
package/dist/utils.js ADDED
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Internal helpers for the Compact CLI tools.
3
+ *
4
+ * - **Glob matching** ({@link globToRegex}, {@link isExcluded}) — used by
5
+ * `FileDiscovery` to skip `.compact` files matching user-supplied patterns.
6
+ * - **Shell quoting** ({@link shellQuote}, {@link buildFindExcludes}) — used by
7
+ * `CompactBuilder` to interpolate user-supplied values into bash commands
8
+ * safely.
9
+ */
10
+ /**
11
+ * Converts a simple glob pattern to a regular expression.
12
+ * Supports `*` (any sequence) and `?` (single char). All other glob features
13
+ * (brace expansion, character classes) are not supported — keep patterns simple.
14
+ */
15
+ export function globToRegex(glob) {
16
+ const escaped = glob.replace(/[\\^$+|.()[\]{}]/g, '\\$&');
17
+ const pattern = escaped.replace(/\*/g, '.*').replace(/\?/g, '.');
18
+ return new RegExp(`^${pattern}$`);
19
+ }
20
+ /**
21
+ * Returns true if `filename`/`fullPath` matches any of the given glob patterns.
22
+ *
23
+ * - Patterns containing `/` are matched against `fullPath` (the path as
24
+ * `find srcDir` would emit it, e.g. `'src/archive/Foo.compact'`).
25
+ * - Patterns without `/` are matched against `filename` only.
26
+ *
27
+ * This mirrors the semantic of `find -name <pattern>` vs `find -path <pattern>`.
28
+ */
29
+ export function isExcluded(filename, fullPath, patterns) {
30
+ return patterns.some((pattern) => {
31
+ const target = pattern.includes('/') ? fullPath : filename;
32
+ return globToRegex(pattern).test(target);
33
+ });
34
+ }
35
+ /**
36
+ * Shell-quotes a string for safe interpolation into a single-quoted bash arg.
37
+ *
38
+ * @example
39
+ * shellQuote("foo") // "'foo'"
40
+ * shellQuote("it's") // "'it'\\''s'"
41
+ */
42
+ export function shellQuote(value) {
43
+ return `'${value.replace(/'/g, `'\\''`)}'`;
44
+ }
45
+ /**
46
+ * Builds the `find`-compatible exclusion fragment for the given patterns.
47
+ * Patterns containing `/` are emitted as `! -path '<pattern>'`; others as
48
+ * `! -name '<pattern>'`. Single-quoting ensures safe shell interpolation.
49
+ *
50
+ * @example
51
+ * buildFindExcludes(['Mock*', '*\/archive\/*'])
52
+ * // "! -name 'Mock*' ! -path '*\/archive\/*'"
53
+ */
54
+ export function buildFindExcludes(patterns) {
55
+ return patterns
56
+ .map((pattern) => pattern.includes('/')
57
+ ? `! -path ${shellQuote(pattern)}`
58
+ : `! -name ${shellQuote(pattern)}`)
59
+ .join(' ');
60
+ }
61
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH;;;;GAIG;AACH,MAAM,UAAU,WAAW,CAAC,IAAY;IACtC,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,mBAAmB,EAAE,MAAM,CAAC,CAAC;IAC1D,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IACjE,OAAO,IAAI,MAAM,CAAC,IAAI,OAAO,GAAG,CAAC,CAAC;AACpC,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,UAAU,CACxB,QAAgB,EAChB,QAAgB,EAChB,QAA2B;IAE3B,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE;QAC/B,MAAM,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC;QAC3D,OAAO,WAAW,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC3C,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,UAAU,CAAC,KAAa;IACtC,OAAO,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC;AAC7C,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,iBAAiB,CAAC,QAA2B;IAC3D,OAAO,QAAQ;SACZ,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CACf,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC;QACnB,CAAC,CAAC,WAAW,UAAU,CAAC,OAAO,CAAC,EAAE;QAClC,CAAC,CAAC,WAAW,UAAU,CAAC,OAAO,CAAC,EAAE,CACrC;SACA,IAAI,CAAC,GAAG,CAAC,CAAC;AACf,CAAC"}
package/package.json ADDED
@@ -0,0 +1,51 @@
1
+ {
2
+ "name": "@buenos_andres/compact-builder",
3
+ "description": "Programmatic library for compiling and building Compact smart contracts",
4
+ "version": "0.5.3",
5
+ "keywords": [
6
+ "compact",
7
+ "midnight",
8
+ "compiler",
9
+ "builder",
10
+ "library"
11
+ ],
12
+ "author": "",
13
+ "license": "MIT",
14
+ "type": "module",
15
+ "main": "./dist/index.js",
16
+ "types": "./dist/index.d.ts",
17
+ "exports": {
18
+ ".": {
19
+ "types": "./dist/index.d.ts",
20
+ "import": "./dist/index.js"
21
+ }
22
+ },
23
+ "files": [
24
+ "dist",
25
+ "README.md",
26
+ "CHANGELOG.md",
27
+ "LICENSE"
28
+ ],
29
+ "engines": {
30
+ "node": ">=20"
31
+ },
32
+ "scripts": {
33
+ "build": "tsc -p .",
34
+ "types": "tsc -p tsconfig.json --noEmit",
35
+ "test": "yarn vitest run",
36
+ "clean": "git clean -fXd"
37
+ },
38
+ "devDependencies": {
39
+ "@tsconfig/node24": "^24.0.3",
40
+ "@types/node": "24.10.1",
41
+ "@types/shell-quote": "^1.7.5",
42
+ "typescript": "^5.9.3",
43
+ "vitest": "^4.0.15"
44
+ },
45
+ "dependencies": {
46
+ "chalk": "^5.6.2",
47
+ "log-symbols": "^7.0.0",
48
+ "ora": "^9.0.0",
49
+ "shell-quote": "^1.8.3"
50
+ }
51
+ }