Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(build): Separate Feature Enabling Function #647

Merged
merged 11 commits into from
Aug 2, 2024
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");
byakuren-hijiri marked this conversation as resolved.
Show resolved Hide resolved
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
Loading