Skip to content

Commit

Permalink
refactor(api): separate feature enabling function (#647)
Browse files Browse the repository at this point in the history
also introduces `index.ts` to define API for third-party tools
  • Loading branch information
byakuren-hijiri authored Aug 2, 2024
1 parent 2524aae commit 9c61afe
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 27 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed

- Removed unsupported iterators API: PR [#633](https://github.com/tact-lang/tact/pull/633)
- Created a separate API function to enable compiler features: PR [#647](https://github.com/tact-lang/tact/pull/647)

### Fixed

Expand Down
2 changes: 1 addition & 1 deletion knip.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "https://unpkg.com/knip@5/schema.json",
"entry": ["src/main.ts", "src/node.ts", "bin/tact.js", "scripts/*.ts"],
"entry": ["src/index.ts", "src/main.ts", "src/node.ts", "bin/tact.js"],
"project": ["src/**/*.ts", "bin/tact.js"],
"ignore": [
"src/grammar/ast.ts",
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { enableFeatures, build } from "./pipeline/build";
52 changes: 26 additions & 26 deletions src/pipeline/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,31 @@ import { getCompilerVersion } from "./version";
import { idText } from "../grammar/ast";
import { TactErrorCollection } from "../errors";

export function enableFeatures(
ctx: CompilerContext,
logger: Logger,
config: ConfigProject,
): CompilerContext {
if (config.options === undefined) {
return ctx;
}
const features = [
{ option: config.options.debug, name: "debug" },
{ option: config.options.masterchain, name: "masterchain" },
{ option: config.options.external, name: "external" },
{ option: config.options.experimental?.inline, name: "inline" },
{ option: config.options.ipfsAbiGetter, name: "ipfsAbiGetter" },
{ option: config.options.interfacesGetter, name: "interfacesGetter" },
];
return features.reduce((currentCtx, { option, name }) => {
if (option) {
logger.debug(` > πŸ‘€ Enabling ${name}`);
return featureEnable(currentCtx, name);
}
return currentCtx;
}, ctx);
}

export async function build(args: {
config: ConfigProject;
project: VirtualFileSystem;
Expand All @@ -41,32 +66,7 @@ export async function build(args: {
entrypoint: posixNormalize(config.path),
options: config.options ?? {},
});
if (config.options) {
if (config.options.debug) {
logger.error(" > πŸ‘€ Enabling debug");
ctx = featureEnable(ctx, "debug");
}
if (config.options.masterchain) {
logger.error(" > πŸ‘€ Enabling masterchain");
ctx = featureEnable(ctx, "masterchain");
}
if (config.options.external) {
logger.error(" > πŸ‘€ Enabling external");
ctx = featureEnable(ctx, "external");
}
if (config.options.experimental?.inline) {
logger.error(" > πŸ‘€ Enabling inline");
ctx = featureEnable(ctx, "inline");
}
if (config.options.ipfsAbiGetter) {
logger.error(" > πŸ‘€ Enabling IPFS ABI getter");
ctx = featureEnable(ctx, "ipfsAbiGetter");
}
if (config.options.interfacesGetter) {
logger.error(" > πŸ‘€ Enabling contract interfaces getter");
ctx = featureEnable(ctx, "interfacesGetter");
}
}
ctx = enableFeatures(ctx, logger, config);

// Precompile
try {
Expand Down

0 comments on commit 9c61afe

Please sign in to comment.