Skip to content

Commit

Permalink
Merge pull request #96 from novusnota-forks/tact.config.json
Browse files Browse the repository at this point in the history
feat: Auto-sourcing of `tact.config.json` if it's present and updating Tact to v1.3.0
  • Loading branch information
krigga authored May 7, 2024
2 parents 97b97e6 + 7ce8cc4 commit 1503538
Show file tree
Hide file tree
Showing 9 changed files with 200 additions and 78 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,19 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Added

- Added auto-sourcing of root `tact.config.json` files for merging compilation options with `wrappers/*.compile.ts`
- Added a warning for disabling `debug` in contract wrappers of Tact before doing production deployments

### Changed

- Changed `@tact-lang/compiler` dependency to be `^1.3.0` instead of `^1.2.0`
- Changed `compile.ts.template` template for Tact to have `debug` set to `true` by default
- Changed `contract.tact.template` empty template for Tact to mention implicit empty `init()` function

## [0.19.1] - 2024-04-12

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ npm create ton@latest
### Requirements

* [Node.js](https://nodejs.org) with a recent version like v18, verify version with `node -v`
* IDE with TypeScript and FunC support like [Visual Studio Code](https://code.visualstudio.com/) with the [FunC plugin](https://marketplace.visualstudio.com/items?itemName=tonwhales.func-vscode) or [IntelliJ Idea](https://www.jetbrains.com/idea/) with the [TON Development plugin](https://plugins.jetbrains.com/plugin/18541-ton-development)
* IDE with TypeScript and FunC support like [Visual Studio Code](https://code.visualstudio.com/) with the [FunC plugin](https://marketplace.visualstudio.com/items?itemName=tonwhales.func-vscode) or [IntelliJ IDEA](https://www.jetbrains.com/idea/) with the [TON Development plugin](https://plugins.jetbrains.com/plugin/23382-ton)

 

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
},
"dependencies": {
"@orbs-network/ton-access": "^2.3.3",
"@tact-lang/compiler": "^1.2.0",
"@tact-lang/compiler": "^1.3.0",
"@ton-community/func-js": "^0.7.0",
"@tonconnect/sdk": "^2.2.0",
"arg": "^5.0.2",
Expand Down
16 changes: 10 additions & 6 deletions src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,29 @@ export async function buildOne(contract: string, ui?: UIProvider) {
});
await fs.writeFile(k, v);
}

if (result.options !== undefined && result.options?.debug === true) {
ui?.clearActionPrompt();
ui?.write(
'\n⚠️ Make sure to disable debug mode in contract wrappers before doing production deployments!',
);
}
}

const cell = result.code;
const rHash = cell.hash();
const res = {
const res = {
hash: rHash.toString('hex'),
hashBase64: rHash.toString('base64'),
hex: cell.toBoc().toString('hex')
hex: cell.toBoc().toString('hex'),
};
ui?.clearActionPrompt();
ui?.write('\n✅ Compiled successfully! Cell BOC result:\n\n');
ui?.write(JSON.stringify(res, null, 2));

await fs.mkdir(BUILD_DIR, { recursive: true });

await fs.writeFile(
buildArtifactPath,
JSON.stringify(res)
);
await fs.writeFile(buildArtifactPath, JSON.stringify(res));

ui?.write(`\n✅ Wrote compilation artifact to ${path.relative(process.cwd(), buildArtifactPath)}`);
} catch (e) {
Expand Down
33 changes: 27 additions & 6 deletions src/compile/compile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import {
CompilerConfig as FuncCompilerConfig,
SourcesArray,
} from '@ton-community/func-js';
import { readFileSync } from 'fs';
import { existsSync, readFileSync } from 'fs';
import path from 'path';
import { Cell } from '@ton/core';
import { BUILD_DIR, WRAPPERS_DIR } from '../paths';
import { TACT_ROOT_CONFIG, BUILD_DIR, WRAPPERS_DIR } from '../paths';
import { CompilerConfig, TactCompilerConfig } from './CompilerConfig';
import { build } from '@tact-lang/compiler';
import * as Tact from '@tact-lang/compiler';
import { OverwritableVirtualFileSystem } from './OverwritableVirtualFileSystem';

async function getCompilerConfigForContract(name: string): Promise<CompilerConfig> {
Expand Down Expand Up @@ -55,6 +55,7 @@ export type TactCompileResult = {
lang: 'tact';
fs: Map<string, Buffer>;
code: Cell;
options?: TactCompilerConfig['options'];
};

function findTactBoc(fs: Map<string, Buffer>): Cell {
Expand All @@ -71,19 +72,38 @@ function findTactBoc(fs: Map<string, Buffer>): Cell {
return Cell.fromBoc(buf)[0];
}

function getRootTactConfigOptionsForContract(name: string): TactCompilerConfig['options'] | undefined {
if (!existsSync(TACT_ROOT_CONFIG)) {
return undefined;
}

const config: Tact.Config = Tact.parseConfig(readFileSync(TACT_ROOT_CONFIG).toString());

for (const project of config.projects) {
if (project.name === name) {
return project.options;
}
}

return undefined;
}

async function doCompileTact(config: TactCompilerConfig, name: string): Promise<TactCompileResult> {
const rootConfigOptions = getRootTactConfigOptionsForContract(name);
const fs = new OverwritableVirtualFileSystem(process.cwd());

const res = await build({
const buildConfig = {
config: {
name: 'tact',
path: config.target,
output: path.join(BUILD_DIR, name),
options: config.options,
options: { ...rootConfigOptions, ...config.options },
},
stdlib: '/stdlib',
project: fs,
});
};

const res = await Tact.build(buildConfig);

if (!res) {
throw new Error('Could not compile tact');
Expand All @@ -95,6 +115,7 @@ async function doCompileTact(config: TactCompilerConfig, name: string): Promise<
lang: 'tact',
fs: fs.overwrites,
code,
options: buildConfig.config.options,
};
}

Expand Down
2 changes: 2 additions & 0 deletions src/paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ export const BUILD_DIR = path.join(process.cwd(), BUILD);
export const TEMP_DIR = path.join(process.cwd(), TEMP);
export const CONTRACTS_DIR = path.join(process.cwd(), CONTRACTS);
export const TESTS_DIR = path.join(process.cwd(), TESTS);

export const TACT_ROOT_CONFIG = path.join(process.cwd(), 'tact.config.json');
3 changes: 3 additions & 0 deletions src/templates/tact/common/wrappers/compile.ts.template
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ import { CompilerConfig } from '@ton/blueprint';
export const compile: CompilerConfig = {
lang: 'tact',
target: '{{contractPath}}',
options: {
debug: true,
},
};
7 changes: 4 additions & 3 deletions src/templates/tact/empty/contracts/contract.tact.template
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
import "@stdlib/deploy";

contract {{name}} with Deployable {
init() {

}
// Empty init() function is present by default in all Tact contracts
// since v1.3.0, so the following may be omitted:
//
// init() {}
}
Loading

0 comments on commit 1503538

Please sign in to comment.