@ton/blueprint 0.32.0 → 0.33.0

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.
Files changed (52) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/dist/build.js +19 -14
  3. package/dist/cli/Runner.js +2 -2
  4. package/dist/cli/build.js +4 -5
  5. package/dist/cli/cli.js +17 -7
  6. package/dist/cli/create.js +45 -15
  7. package/dist/cli/help.js +2 -2
  8. package/dist/compile/CompilerConfig.d.ts +6 -25
  9. package/dist/compile/CompilerConfig.js +4 -0
  10. package/dist/compile/SourceSnapshot.d.ts +4 -0
  11. package/dist/compile/SourceSnapshot.js +2 -0
  12. package/dist/compile/compile.d.ts +6 -31
  13. package/dist/compile/compile.js +54 -157
  14. package/dist/compile/func/compile.func.d.ts +14 -0
  15. package/dist/compile/func/compile.func.js +29 -0
  16. package/dist/compile/func/config.d.ts +11 -0
  17. package/dist/compile/func/config.js +2 -0
  18. package/dist/compile/{OverwritableVirtualFileSystem.d.ts → tact/OverwritableVirtualFileSystem.d.ts} +0 -1
  19. package/dist/compile/tact/compile.tact.d.ts +13 -0
  20. package/dist/compile/tact/compile.tact.js +123 -0
  21. package/dist/compile/tact/config.d.ts +7 -0
  22. package/dist/compile/tact/config.js +2 -0
  23. package/dist/compile/tolk/compile.tolk.d.ts +13 -0
  24. package/dist/compile/tolk/compile.tolk.js +25 -0
  25. package/dist/compile/tolk/config.d.ts +8 -0
  26. package/dist/compile/tolk/config.js +2 -0
  27. package/dist/config/tact.config.d.ts +5 -0
  28. package/dist/config/tact.config.js +21 -0
  29. package/dist/config/utils.js +19 -11
  30. package/dist/index.d.ts +2 -1
  31. package/dist/network/createNetworkProvider.js +2 -2
  32. package/dist/network/send/MnemonicProvider.d.ts +0 -1
  33. package/dist/template.js +2 -2
  34. package/dist/templates/tact/counter/scripts/deploy.ts.template +1 -1
  35. package/dist/templates/tact/counter/tests/spec.ts.template +1 -1
  36. package/dist/templates/tact/empty/tests/spec.ts.template +1 -1
  37. package/dist/templates/tolk/common/compilables/compile.ts.template +1 -0
  38. package/dist/templates/tolk/counter/contracts/contract.tolk.template +4 -4
  39. package/dist/templates/tolk/not-separated-common/wrappers/compile.ts.template +1 -0
  40. package/dist/utils/object.utils.d.ts +1 -0
  41. package/dist/utils/object.utils.js +5 -2
  42. package/dist/utils/selection.utils.d.ts +1 -0
  43. package/dist/utils/selection.utils.js +34 -14
  44. package/dist/utils/string.utils.js +2 -3
  45. package/dist/utils/timer.utils.js +1 -2
  46. package/dist/utils/ton.utils.js +2 -2
  47. package/package.json +4 -4
  48. package/dist/templates/tact/common/compilables/compile.ts.template +0 -10
  49. package/dist/templates/tact/common/wrappers/wrapper.ts.template +0 -2
  50. package/dist/templates/tact/not-separated-common/wrappers/compile.ts.template +0 -10
  51. package/dist/templates/tact/not-separated-common/wrappers/wrapper.ts.template +0 -2
  52. /package/dist/compile/{OverwritableVirtualFileSystem.js → tact/OverwritableVirtualFileSystem.js} +0 -0
package/CHANGELOG.md CHANGED
@@ -5,6 +5,23 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [0.33.0] - 2025-05-16
9
+
10
+ ### Added
11
+
12
+ - Added `tact.config.json` support
13
+ - Added tolk v0.12 support
14
+
15
+ ### Fixed
16
+
17
+ - Fixed tact counter deploy script error
18
+
19
+ ## [0.32.1] - 2025-05-06
20
+
21
+ ### Fixed
22
+
23
+ - Fix unexpected code duplication on parralel compile
24
+
8
25
  ## [0.32.0] - 2025-05-02
9
26
 
10
27
  ### Added
package/dist/build.js CHANGED
@@ -3,12 +3,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.buildAllTact = exports.buildAll = exports.buildOne = void 0;
6
+ exports.buildOne = buildOne;
7
+ exports.buildAll = buildAll;
8
+ exports.buildAllTact = buildAllTact;
7
9
  const path_1 = __importDefault(require("path"));
8
10
  const promises_1 = __importDefault(require("fs/promises"));
9
11
  const compile_1 = require("./compile/compile");
10
12
  const paths_1 = require("./paths");
11
13
  const utils_1 = require("./utils");
14
+ const tact_config_1 = require("./config/tact.config");
12
15
  async function buildOne(contract, ui) {
13
16
  ui?.write(`Build script running, compiling ${contract}`);
14
17
  const buildArtifactPath = path_1.default.join(paths_1.BUILD_DIR, `${contract}.compiled.json`);
@@ -67,20 +70,22 @@ async function buildOne(contract, ui) {
67
70
  }
68
71
  }
69
72
  }
70
- exports.buildOne = buildOne;
71
- async function buildAll(ui) {
72
- for (const file of await (0, utils_1.findCompiles)()) {
73
- await buildOne(file.name, ui);
73
+ async function buildContracts(contracts, ui) {
74
+ for (const contract of contracts) {
75
+ await buildOne(contract, ui);
74
76
  }
75
77
  }
76
- exports.buildAll = buildAll;
78
+ async function buildAll(ui) {
79
+ await buildContracts(await (0, utils_1.findContracts)(), ui);
80
+ }
77
81
  async function buildAllTact(ui) {
78
- // TODO: when tact config introduced rewrite to use it
79
- for (const file of await (0, utils_1.findCompiles)()) {
80
- const config = await (0, compile_1.extractCompileConfig)(file.path);
81
- if (config.lang === 'tact') {
82
- await buildOne(file.name, ui);
83
- }
84
- }
82
+ const legacyTactContract = (await (0, utils_1.findCompiles)())
83
+ .filter((file) => (0, compile_1.extractCompilableConfig)(file.path).lang === 'tact')
84
+ .map((file) => file.name);
85
+ const tactConfig = (0, tact_config_1.getRootTactConfig)();
86
+ const tactContracts = [
87
+ ...legacyTactContract,
88
+ ...tactConfig.projects.map((project) => project.name),
89
+ ];
90
+ await buildContracts(tactContracts, ui);
85
91
  }
86
- exports.buildAllTact = buildAllTact;
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.extractFirstArg = exports.argSpec = void 0;
3
+ exports.argSpec = void 0;
4
+ exports.extractFirstArg = extractFirstArg;
4
5
  exports.argSpec = {};
5
6
  function extractFirstArg(args) {
6
7
  return args._.length > 1 && args._[1].trim().length > 0 ? args._[1].trim() : undefined;
7
8
  }
8
- exports.extractFirstArg = extractFirstArg;
package/dist/cli/build.js CHANGED
@@ -3,7 +3,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.build = exports.selectContract = exports.extractBuildFile = void 0;
6
+ exports.build = void 0;
7
+ exports.extractBuildFile = extractBuildFile;
8
+ exports.selectContract = selectContract;
7
9
  const utils_1 = require("../utils");
8
10
  const arg_1 = __importDefault(require("arg"));
9
11
  const build_1 = require("../build");
@@ -11,10 +13,8 @@ const constants_1 = require("./constants");
11
13
  function extractBuildFile(args) {
12
14
  return args._.length > 1 && args._[1].length > 0 ? args._[1] : undefined;
13
15
  }
14
- exports.extractBuildFile = extractBuildFile;
15
16
  async function selectContract(ui, hint, withAllOption = false) {
16
- const compiles = await (0, utils_1.findCompiles)();
17
- const contracts = compiles.map(compile => compile.name);
17
+ const contracts = await (0, utils_1.findContracts)();
18
18
  const options = contracts.map((contract) => ({ name: contract, value: contract }));
19
19
  const allContractsValue = 'all_contracts';
20
20
  if (withAllOption) {
@@ -34,7 +34,6 @@ async function selectContract(ui, hint, withAllOption = false) {
34
34
  }
35
35
  return selectedOption.value;
36
36
  }
37
- exports.selectContract = selectContract;
38
37
  const build = async (args, ui) => {
39
38
  const localArgs = (0, arg_1.default)({
40
39
  '--all': Boolean,
package/dist/cli/cli.js CHANGED
@@ -16,13 +16,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
16
16
  }) : function(o, v) {
17
17
  o["default"] = v;
18
18
  });
19
- var __importStar = (this && this.__importStar) || function (mod) {
20
- if (mod && mod.__esModule) return mod;
21
- var result = {};
22
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
23
- __setModuleDefault(result, mod);
24
- return result;
25
- };
19
+ var __importStar = (this && this.__importStar) || (function () {
20
+ var ownKeys = function(o) {
21
+ ownKeys = Object.getOwnPropertyNames || function (o) {
22
+ var ar = [];
23
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
24
+ return ar;
25
+ };
26
+ return ownKeys(o);
27
+ };
28
+ return function (mod) {
29
+ if (mod && mod.__esModule) return mod;
30
+ var result = {};
31
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
32
+ __setModuleDefault(result, mod);
33
+ return result;
34
+ };
35
+ })();
26
36
  var __importDefault = (this && this.__importDefault) || function (mod) {
27
37
  return (mod && mod.__esModule) ? mod : { "default": mod };
28
38
  };
@@ -4,14 +4,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.create = void 0;
7
- const Runner_1 = require("./Runner");
8
- const promises_1 = require("fs/promises");
9
7
  const path_1 = __importDefault(require("path"));
10
- const template_1 = require("../template");
11
- const utils_1 = require("../utils");
8
+ const promises_1 = require("fs/promises");
12
9
  const arg_1 = __importDefault(require("arg"));
10
+ const utils_1 = require("../config/utils");
11
+ const tact_config_1 = require("../config/tact.config");
12
+ const Runner_1 = require("./Runner");
13
+ const template_1 = require("../template");
14
+ const utils_2 = require("../utils");
13
15
  const build_1 = require("../build");
14
- const utils_2 = require("../config/utils");
15
16
  const constants_1 = require("./constants");
16
17
  function toSnakeCase(v) {
17
18
  const r = v.replace(/[A-Z]/g, (sub) => '_' + sub.toLowerCase());
@@ -48,6 +49,31 @@ async function createFiles(templatePath, realPath, replaces) {
48
49
  }
49
50
  }
50
51
  }
52
+ function getFileExtension(lang) {
53
+ if (lang === 'func')
54
+ return 'fc';
55
+ if (lang === 'tolk')
56
+ return 'tolk';
57
+ return 'tact';
58
+ }
59
+ function addToTactConfig(contractName, contractPath) {
60
+ const tactConfig = (0, tact_config_1.getRootTactConfig)();
61
+ const projectConfig = {
62
+ name: contractName,
63
+ path: contractPath,
64
+ output: path_1.default.join('build', contractName),
65
+ options: {
66
+ debug: false,
67
+ external: false,
68
+ },
69
+ mode: 'full',
70
+ };
71
+ const newConfig = {
72
+ ...tactConfig,
73
+ projects: [...tactConfig.projects, projectConfig],
74
+ };
75
+ (0, tact_config_1.updateRootTactConfig)(newConfig);
76
+ }
51
77
  const create = async (args, ui) => {
52
78
  const localArgs = (0, arg_1.default)({
53
79
  '--type': String,
@@ -57,35 +83,39 @@ const create = async (args, ui) => {
57
83
  ui.write(constants_1.helpMessages['create']);
58
84
  return;
59
85
  }
60
- const name = (0, Runner_1.extractFirstArg)(localArgs)
61
- ?? await ui.input('Contract name (PascalCase)');
86
+ const name = (0, Runner_1.extractFirstArg)(localArgs) ?? (await ui.input('Contract name (PascalCase)'));
62
87
  if (name.length === 0)
63
88
  throw new Error(`Cannot create a contract with an empty name`);
64
89
  if (name.toLowerCase() === 'contract') {
65
90
  throw new Error(`Cannot create a contract with the reserved name 'contract'. Please choose a different name.`);
66
91
  }
67
- if (!(0, utils_1.isPascalCase)(name)) {
68
- throw new Error(`Contract name '${name}' is not in PascalCase. Please try ${(0, utils_1.toPascalCase)(name)}.`);
92
+ if (!(0, utils_2.isPascalCase)(name)) {
93
+ throw new Error(`Contract name '${name}' is not in PascalCase. Please try ${(0, utils_2.toPascalCase)(name)}.`);
69
94
  }
70
- const which = (await (0, utils_1.selectOption)(constants_1.templateTypes, {
95
+ const which = (await (0, utils_2.selectOption)(constants_1.templateTypes, {
71
96
  ui,
72
97
  msg: 'What type of contract do you want to create?',
73
98
  hint: localArgs['--type'],
74
99
  })).value;
75
100
  const [lang, template] = which.split('-');
76
101
  const snakeName = toSnakeCase(name);
102
+ const contractPath = path_1.default.join('contracts', snakeName + '.' + getFileExtension(lang));
77
103
  const replaces = {
78
104
  name,
79
105
  loweredName: name.substring(0, 1).toLowerCase() + name.substring(1),
80
106
  snakeName,
81
- contractPath: 'contracts/' + snakeName + '.' + (lang === 'func' ? 'fc' : (lang === 'tolk' ? 'tolk' : 'tact')),
107
+ contractPath,
82
108
  };
83
- const config = await (0, utils_2.getConfig)();
84
- const commonPath = config?.separateCompilables ? 'common' : 'not-separated-common';
85
- await createFiles(path_1.default.join(template_1.TEMPLATES_DIR, lang, commonPath), process.cwd(), replaces);
86
- await createFiles(path_1.default.join(template_1.TEMPLATES_DIR, lang, template), process.cwd(), replaces);
109
+ const config = await (0, utils_1.getConfig)();
87
110
  if (lang === 'tact') {
111
+ await createFiles(path_1.default.join(template_1.TEMPLATES_DIR, lang, template), process.cwd(), replaces);
112
+ addToTactConfig(name, contractPath);
88
113
  await (0, build_1.buildOne)(name, ui);
89
114
  }
115
+ else {
116
+ const commonPath = config?.separateCompilables ? 'common' : 'not-separated-common';
117
+ await createFiles(path_1.default.join(template_1.TEMPLATES_DIR, lang, commonPath), process.cwd(), replaces);
118
+ await createFiles(path_1.default.join(template_1.TEMPLATES_DIR, lang, template), process.cwd(), replaces);
119
+ }
90
120
  };
91
121
  exports.create = create;
package/dist/cli/help.js CHANGED
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.help = exports.buildHelpMessage = exports.additionalHelpMessages = void 0;
3
+ exports.help = exports.additionalHelpMessages = void 0;
4
+ exports.buildHelpMessage = buildHelpMessage;
4
5
  const constants_1 = require("./constants");
5
6
  exports.additionalHelpMessages = {};
6
7
  function buildHelpMessage(cmd = '') {
@@ -13,7 +14,6 @@ function buildHelpMessage(cmd = '') {
13
14
  }
14
15
  return cmd in effectiveHelpMessages ? effectiveHelpMessages[cmd] : effectiveHelpMessages['help'];
15
16
  }
16
- exports.buildHelpMessage = buildHelpMessage;
17
17
  const help = async (args, ui) => {
18
18
  const cmd = args._.length >= 2 ? args._[1].toLowerCase() : '';
19
19
  const helpMessage = buildHelpMessage(cmd);
@@ -1,6 +1,7 @@
1
- import { SourceResolver, SourcesMap, SourcesArray } from '@ton-community/func-js';
2
1
  import { Cell } from '@ton/core';
3
- import { Options } from '@tact-lang/compiler';
2
+ import { TolkCompilerConfig } from './tolk/config';
3
+ import { FuncCompilerConfig } from './func/config';
4
+ import { TactCompilerConfig, TactLegacyCompilerConfig } from './tact/config';
4
5
  export type HookParams = {
5
6
  userData?: any;
6
7
  };
@@ -33,26 +34,6 @@ export type CommonCompilerConfig = {
33
34
  */
34
35
  postCompileHook?: (code: Cell, params: HookParams) => Promise<void>;
35
36
  };
36
- export type TactCompilerConfig = {
37
- lang: 'tact';
38
- target: string;
39
- options?: Options;
40
- };
41
- export type FuncCompilerConfig = {
42
- lang?: 'func';
43
- optLevel?: number;
44
- } & ({
45
- targets: string[];
46
- sources?: SourceResolver | SourcesMap;
47
- } | {
48
- targets?: string[];
49
- sources: SourcesArray;
50
- });
51
- export type TolkCompilerConfig = {
52
- lang: 'tolk';
53
- entrypoint: string;
54
- optimizationLevel?: number;
55
- withStackComments?: boolean;
56
- experimentalOptions?: string;
57
- };
58
- export type CompilerConfig = (TactCompilerConfig | FuncCompilerConfig | TolkCompilerConfig) & CommonCompilerConfig;
37
+ export type CompilableConfig = (TactLegacyCompilerConfig | FuncCompilerConfig | TolkCompilerConfig) & CommonCompilerConfig;
38
+ export type CompilerConfig = TactCompilerConfig | CompilableConfig;
39
+ export declare function isCompilableConfig(config: CompilerConfig): config is CompilableConfig;
@@ -1,2 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isCompilableConfig = isCompilableConfig;
4
+ function isCompilableConfig(config) {
5
+ return 'lang' in config;
6
+ }
@@ -0,0 +1,4 @@
1
+ export type SourceSnapshot = {
2
+ filename: string;
3
+ content: string;
4
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,38 +1,12 @@
1
- /// <reference types="node" />
2
1
  import { Cell } from '@ton/core';
3
- import { CompilerConfig, TactCompilerConfig } from './CompilerConfig';
2
+ import { CompilableConfig, CompilerConfig } from './CompilerConfig';
3
+ import { FuncCompileResult } from './func/compile.func';
4
+ import { TactCompileResult } from './tact/compile.tact';
5
+ import { TolkCompileResult } from './tolk/compile.tolk';
4
6
  export declare function getCompilablesDirectory(): Promise<string>;
7
+ export declare function extractCompilableConfig(path: string): CompilableConfig;
5
8
  export declare const COMPILE_END = ".compile.ts";
6
- export declare function extractCompileConfig(path: string): Promise<CompilerConfig>;
7
9
  export declare function getCompilerConfigForContract(name: string): Promise<CompilerConfig>;
8
- export type SourceSnapshot = {
9
- filename: string;
10
- content: string;
11
- };
12
- export type TolkCompileResult = {
13
- lang: 'tolk';
14
- stderr: string;
15
- fiftCode: string;
16
- code: Cell;
17
- snapshot: SourceSnapshot[];
18
- version: string;
19
- };
20
- export type FuncCompileResult = {
21
- lang: 'func';
22
- fiftCode: string;
23
- code: Cell;
24
- targets: string[];
25
- snapshot: SourceSnapshot[];
26
- version: string;
27
- };
28
- export type TactCompileResult = {
29
- lang: 'tact';
30
- fs: Map<string, Buffer>;
31
- code: Cell;
32
- options?: TactCompilerConfig['options'];
33
- version: string;
34
- };
35
- export declare function getTactVersion(): Promise<any>;
36
10
  export type CompileResult = TactCompileResult | FuncCompileResult | TolkCompileResult;
37
11
  export declare function getCompilerOptions(config: CompilerConfig): Promise<{
38
12
  lang: 'tact' | 'tolk' | 'func';
@@ -72,3 +46,4 @@ export type CompileOpts = {
72
46
  * main();
73
47
  */
74
48
  export declare function compile(name: string, opts?: CompileOpts): Promise<Cell>;
49
+ export type { TactCompileResult, TolkCompileResult, FuncCompileResult };
@@ -1,42 +1,23 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
26
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
4
  };
28
- var _a, _b;
29
5
  Object.defineProperty(exports, "__esModule", { value: true });
30
- exports.compile = exports.doCompile = exports.getCompilerOptions = exports.getTactVersion = exports.getCompilerConfigForContract = exports.extractCompileConfig = exports.COMPILE_END = exports.getCompilablesDirectory = void 0;
31
- const func_js_1 = require("@ton-community/func-js");
6
+ exports.COMPILE_END = void 0;
7
+ exports.getCompilablesDirectory = getCompilablesDirectory;
8
+ exports.extractCompilableConfig = extractCompilableConfig;
9
+ exports.getCompilerConfigForContract = getCompilerConfigForContract;
10
+ exports.getCompilerOptions = getCompilerOptions;
11
+ exports.doCompile = doCompile;
12
+ exports.compile = compile;
32
13
  const fs_1 = require("fs");
33
14
  const path_1 = __importDefault(require("path"));
34
- const core_1 = require("@ton/core");
35
15
  const paths_1 = require("../paths");
36
- const Tact = __importStar(require("@tact-lang/compiler"));
37
- const OverwritableVirtualFileSystem_1 = require("./OverwritableVirtualFileSystem");
16
+ const CompilerConfig_1 = require("./CompilerConfig");
38
17
  const utils_1 = require("../config/utils");
39
- const tolk_js_1 = require("@ton/tolk-js");
18
+ const compile_func_1 = require("./func/compile.func");
19
+ const compile_tact_1 = require("./tact/compile.tact");
20
+ const compile_tolk_1 = require("./tolk/compile.tolk");
40
21
  async function getCompilablesDirectory() {
41
22
  const config = await (0, utils_1.getConfig)();
42
23
  if (config?.separateCompilables) {
@@ -44,145 +25,64 @@ async function getCompilablesDirectory() {
44
25
  }
45
26
  return paths_1.WRAPPERS_DIR;
46
27
  }
47
- exports.getCompilablesDirectory = getCompilablesDirectory;
48
- exports.COMPILE_END = '.compile.ts';
49
- async function extractCompileConfig(path) {
50
- const mod = await (_a = path, Promise.resolve().then(() => __importStar(require(_a))));
28
+ function extractCompilableConfig(path) {
29
+ const mod = require(path);
51
30
  if (typeof mod.compile !== 'object') {
52
31
  throw new Error(`Object 'compile' is missing`);
53
32
  }
33
+ mod.compile.lang ??= 'func';
54
34
  return mod.compile;
55
35
  }
56
- exports.extractCompileConfig = extractCompileConfig;
36
+ exports.COMPILE_END = '.compile.ts';
37
+ // contracts in tact.config.json and .compile.ts may overlap. In this case configuration from tact.config.json would be taken
57
38
  async function getCompilerConfigForContract(name) {
58
- const compilablesDirectory = await getCompilablesDirectory();
59
- return extractCompileConfig(path_1.default.join(compilablesDirectory, name + exports.COMPILE_END));
60
- }
61
- exports.getCompilerConfigForContract = getCompilerConfigForContract;
62
- async function doCompileTolk(config) {
63
- const res = await (0, tolk_js_1.runTolkCompiler)(config);
64
- if (res.status === 'error') {
65
- throw new Error(res.message);
66
- }
67
- return {
68
- lang: 'tolk',
69
- stderr: res.stderr,
70
- fiftCode: res.fiftCode,
71
- code: core_1.Cell.fromBase64(res.codeBoc64),
72
- snapshot: res.sourcesSnapshot.map((e) => ({
73
- filename: e.filename,
74
- content: e.contents,
75
- })),
76
- version: await (0, tolk_js_1.getTolkCompilerVersion)(),
77
- };
78
- }
79
- async function doCompileFunc(config) {
80
- const cr = await (0, func_js_1.compileFunc)(config);
81
- if (cr.status === 'error')
82
- throw new Error(cr.message);
83
- let targets = [];
84
- if (config.targets) {
85
- targets = config.targets;
39
+ const tactConfig = (0, compile_tact_1.getTactConfigForContract)(name);
40
+ if (tactConfig) {
41
+ return tactConfig;
86
42
  }
87
- else if (Array.isArray(config.sources)) {
88
- targets = config.sources.map((s) => s.filename);
89
- }
90
- return {
91
- lang: 'func',
92
- fiftCode: cr.fiftCode,
93
- code: core_1.Cell.fromBase64(cr.codeBoc),
94
- targets,
95
- snapshot: cr.snapshot,
96
- version: (await (0, func_js_1.compilerVersion)()).funcVersion,
97
- };
43
+ const compilablesDirectory = await getCompilablesDirectory();
44
+ return extractCompilableConfig(path_1.default.join(compilablesDirectory, name + exports.COMPILE_END));
98
45
  }
99
- function findTactBoc(fs) {
100
- let buf = undefined;
101
- for (const [k, v] of fs) {
102
- if (k.endsWith('.code.boc')) {
103
- buf = v;
104
- break;
46
+ async function doCompileInner(name, config) {
47
+ if ((0, CompilerConfig_1.isCompilableConfig)(config)) {
48
+ if (config.lang === 'tact') {
49
+ return await (0, compile_tact_1.doCompileTact)(config, name);
105
50
  }
106
- }
107
- if (buf === undefined) {
108
- throw new Error('Could not find boc in tact compilation result');
109
- }
110
- return core_1.Cell.fromBoc(buf)[0];
111
- }
112
- function getRootTactConfigOptionsForContract(name) {
113
- if (!(0, fs_1.existsSync)(paths_1.TACT_ROOT_CONFIG)) {
114
- return undefined;
115
- }
116
- const config = Tact.parseConfig((0, fs_1.readFileSync)(paths_1.TACT_ROOT_CONFIG).toString());
117
- for (const project of config.projects) {
118
- if (project.name === name) {
119
- return project.options;
51
+ if (config.lang === 'tolk') {
52
+ return await (0, compile_tolk_1.doCompileTolk)({
53
+ entrypointFileName: config.entrypoint,
54
+ fsReadCallback: (path) => (0, fs_1.readFileSync)(path).toString(),
55
+ optimizationLevel: config.optimizationLevel,
56
+ withStackComments: config.withStackComments,
57
+ withSrcLineComments: config.withSrcLineComments,
58
+ experimentalOptions: config.experimentalOptions,
59
+ });
120
60
  }
121
- }
122
- return undefined;
123
- }
124
- async function getTactVersion() {
125
- const packageJsonPath = require.resolve('@tact-lang/compiler/package.json');
126
- const { version } = await (_b = packageJsonPath, Promise.resolve().then(() => __importStar(require(_b))));
127
- return version;
128
- }
129
- exports.getTactVersion = getTactVersion;
130
- async function doCompileTact(config, name) {
131
- const rootConfigOptions = getRootTactConfigOptionsForContract(name);
132
- const fs = new OverwritableVirtualFileSystem_1.OverwritableVirtualFileSystem(process.cwd());
133
- const buildConfig = {
134
- config: {
135
- name: 'tact',
136
- path: config.target,
137
- output: path_1.default.join(paths_1.BUILD_DIR, name),
138
- options: { ...rootConfigOptions, ...config.options },
139
- },
140
- stdlib: Tact.createVirtualFileSystem("@stdlib", Tact.stdLibFiles),
141
- project: fs,
142
- };
143
- const res = await Tact.build(buildConfig);
144
- if (!res.ok) {
145
- throw new Error('Could not compile tact');
146
- }
147
- const code = findTactBoc(fs.overwrites);
148
- return {
149
- lang: 'tact',
150
- fs: fs.overwrites,
151
- code,
152
- options: buildConfig.config.options,
153
- version: await getTactVersion(),
154
- };
155
- }
156
- async function doCompileInner(name, config) {
157
- if (config.lang === 'tact') {
158
- return await doCompileTact(config, name);
159
- }
160
- if (config.lang === 'tolk') {
161
- return await doCompileTolk({
162
- entrypointFileName: config.entrypoint,
163
- fsReadCallback: (path) => (0, fs_1.readFileSync)(path).toString(),
164
- optimizationLevel: config.optimizationLevel,
165
- withStackComments: config.withStackComments,
166
- experimentalOptions: config.experimentalOptions,
61
+ return await (0, compile_func_1.doCompileFunc)({
62
+ targets: config.targets,
63
+ sources: config.sources ?? ((path) => (0, fs_1.readFileSync)(path).toString()),
64
+ optLevel: config.optLevel,
167
65
  });
168
66
  }
169
- return await doCompileFunc({
170
- targets: config.targets,
171
- sources: config.sources ?? ((path) => (0, fs_1.readFileSync)(path).toString()),
172
- optLevel: config.optLevel,
173
- });
67
+ return await (0, compile_tact_1.doCompileTact)(config, name);
174
68
  }
175
69
  function getCompilerName(config) {
176
- return config.lang ?? 'func';
70
+ if ((0, CompilerConfig_1.isCompilableConfig)(config)) {
71
+ return config.lang ?? 'func';
72
+ }
73
+ return 'tact';
177
74
  }
178
75
  async function getCompilerVersion(config) {
179
- if (config.lang === 'tact') {
180
- return getTactVersion();
181
- }
182
- if (config.lang === 'tolk') {
183
- return (0, tolk_js_1.getTolkCompilerVersion)();
76
+ if ((0, CompilerConfig_1.isCompilableConfig)(config)) {
77
+ if (config.lang === 'tact') {
78
+ return (0, compile_tact_1.getTactVersion)();
79
+ }
80
+ if (config.lang === 'tolk') {
81
+ return (0, compile_tolk_1.getTolkVersion)();
82
+ }
83
+ return (0, compile_func_1.getFuncVersion)();
184
84
  }
185
- return (await (0, func_js_1.compilerVersion)()).funcVersion;
85
+ return (0, compile_tact_1.getTactVersion)();
186
86
  }
187
87
  async function getCompilerOptions(config) {
188
88
  return {
@@ -190,23 +90,21 @@ async function getCompilerOptions(config) {
190
90
  version: await getCompilerVersion(config),
191
91
  };
192
92
  }
193
- exports.getCompilerOptions = getCompilerOptions;
194
93
  async function doCompile(name, opts) {
195
94
  const config = await getCompilerConfigForContract(name);
196
- if (config.preCompileHook !== undefined) {
95
+ if ('preCompileHook' in config && config.preCompileHook !== undefined) {
197
96
  await config.preCompileHook({
198
97
  userData: opts?.hookUserData,
199
98
  });
200
99
  }
201
100
  const res = await doCompileInner(name, config);
202
- if (config.postCompileHook !== undefined) {
101
+ if ('postCompileHook' in config && config.postCompileHook !== undefined) {
203
102
  await config.postCompileHook(res.code, {
204
103
  userData: opts?.hookUserData,
205
104
  });
206
105
  }
207
106
  return res;
208
107
  }
209
- exports.doCompile = doCompile;
210
108
  /**
211
109
  * Compiles a contract using the specified configuration for `tact`, `func`, or `tolk` languages.
212
110
  *
@@ -234,4 +132,3 @@ async function compile(name, opts) {
234
132
  const result = await doCompile(name, opts);
235
133
  return result.code;
236
134
  }
237
- exports.compile = compile;