@taqueria/lib-ligo 0.40.10
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.
- package/LICENSE +201 -0
- package/README.md +5 -0
- package/common.ts +67 -0
- package/compile-all.ts +34 -0
- package/compile.ts +478 -0
- package/createContract.ts +38 -0
- package/index.d.ts +2 -0
- package/index.js +728 -0
- package/index.js.map +1 -0
- package/index.mjs +700 -0
- package/index.mjs.map +1 -0
- package/index.ts +121 -0
- package/ligo.ts +73 -0
- package/ligo_templates.ts +31 -0
- package/main.ts +27 -0
- package/package.json +68 -0
- package/postinstall.js +19 -0
- package/test.ts +55 -0
- package/tsconfig.json +103 -0
package/index.js
ADDED
|
@@ -0,0 +1,728 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// index.ts
|
|
31
|
+
var taqueria_lib_ligo_exports = {};
|
|
32
|
+
__export(taqueria_lib_ligo_exports, {
|
|
33
|
+
configurePlugin: () => configurePlugin
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(taqueria_lib_ligo_exports);
|
|
36
|
+
var import_node_sdk9 = require("@taqueria/node-sdk");
|
|
37
|
+
|
|
38
|
+
// createContract.ts
|
|
39
|
+
var import_node_sdk = require("@taqueria/node-sdk");
|
|
40
|
+
var import_promises = require("fs/promises");
|
|
41
|
+
|
|
42
|
+
// ligo_templates.ts
|
|
43
|
+
var mligo_template = `
|
|
44
|
+
type storage = int
|
|
45
|
+
type return = operation list * storage
|
|
46
|
+
|
|
47
|
+
(* Three entrypoints *)
|
|
48
|
+
[@entry] let increment (delta : int) (store : storage) : return =
|
|
49
|
+
[], store + delta
|
|
50
|
+
[@entry] let decrement (delta : int) (store : storage) : return =
|
|
51
|
+
[], store - delta
|
|
52
|
+
[@entry] let reset (() : unit) (_ : storage) : return =
|
|
53
|
+
[], 0
|
|
54
|
+
`;
|
|
55
|
+
var jsligo_template = `
|
|
56
|
+
type storage = int;
|
|
57
|
+
type ret = [list<operation>, storage];
|
|
58
|
+
|
|
59
|
+
// Three entrypoints
|
|
60
|
+
|
|
61
|
+
// @entry
|
|
62
|
+
const increment = (delta : int, store : storage) : ret =>
|
|
63
|
+
[list([]), store + delta];
|
|
64
|
+
|
|
65
|
+
// @entry
|
|
66
|
+
const decrement = (delta : int, store : storage) : ret =>
|
|
67
|
+
[list([]), store - delta];
|
|
68
|
+
|
|
69
|
+
// @entry
|
|
70
|
+
const reset = (_ : unit, _ : storage) : ret =>
|
|
71
|
+
[list([]), 0];
|
|
72
|
+
`;
|
|
73
|
+
|
|
74
|
+
// createContract.ts
|
|
75
|
+
var getLigoTemplate = async (contractName, syntax) => {
|
|
76
|
+
const matchResult = contractName.match(/\.[^.]+$/);
|
|
77
|
+
const ext = matchResult ? matchResult[0].substring(1) : null;
|
|
78
|
+
if (syntax === "mligo")
|
|
79
|
+
return mligo_template;
|
|
80
|
+
if (syntax === "jsligo")
|
|
81
|
+
return jsligo_template;
|
|
82
|
+
if (syntax === void 0) {
|
|
83
|
+
if (ext === "mligo")
|
|
84
|
+
return mligo_template;
|
|
85
|
+
if (ext === "jsligo")
|
|
86
|
+
return jsligo_template;
|
|
87
|
+
return (0, import_node_sdk.sendAsyncErr)(
|
|
88
|
+
`Unable to infer LIGO syntax from "${contractName}". Please specify a LIGO syntax via the --syntax option`
|
|
89
|
+
);
|
|
90
|
+
} else {
|
|
91
|
+
return (0, import_node_sdk.sendAsyncErr)(`"${syntax}" is not a valid syntax. Please specify a valid LIGO syntax`);
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
var createContract = (args) => {
|
|
95
|
+
const unsafeOpts = args;
|
|
96
|
+
const contractName = unsafeOpts.sourceFileName;
|
|
97
|
+
const syntax = unsafeOpts.syntax;
|
|
98
|
+
const contractsDir = `${args.config.projectDir}/${args.config.contractsDir}`;
|
|
99
|
+
return getLigoTemplate(contractName, syntax).then((ligo_template) => (0, import_promises.writeFile)(`${contractsDir}/${contractName}`, ligo_template));
|
|
100
|
+
};
|
|
101
|
+
var createContract_default = createContract;
|
|
102
|
+
|
|
103
|
+
// main.ts
|
|
104
|
+
var import_node_sdk8 = require("@taqueria/node-sdk");
|
|
105
|
+
|
|
106
|
+
// common.ts
|
|
107
|
+
var import_node_sdk2 = require("@taqueria/node-sdk");
|
|
108
|
+
var import_path = require("path");
|
|
109
|
+
var getInputFilenameAbsPath = (parsedArgs, sourceFile) => (0, import_path.join)(parsedArgs.config.projectDir, parsedArgs.config.contractsDir ?? "contracts", sourceFile);
|
|
110
|
+
var getInputFilenameRelPath = (parsedArgs, sourceFile) => (0, import_path.join)(parsedArgs.config.contractsDir ?? "contracts", sourceFile);
|
|
111
|
+
var formatLigoError = (err) => {
|
|
112
|
+
let result = err.message.replace(/Command failed.+?\n/, "");
|
|
113
|
+
if (result.includes("An internal error ocurred. Please, contact the developers.") && result.includes("Module Contract not found with last Contract.")) {
|
|
114
|
+
result = `By convention, Taqueria expects you to import your contract with Contract as the module name.
|
|
115
|
+
For instance, if you have a contract in a file called "increment.mligo", in your parameter/storage list file you must include #import "Increment.mligo" "Contract" for compilation to be successful.`;
|
|
116
|
+
}
|
|
117
|
+
err.message = result.replace(
|
|
118
|
+
"An internal error ocurred. Please, contact the developers.",
|
|
119
|
+
"The LIGO compiler experienced an internal error. Please contact the LIGO developers."
|
|
120
|
+
);
|
|
121
|
+
return err;
|
|
122
|
+
};
|
|
123
|
+
var emitExternalError = (errs, sourceFile) => {
|
|
124
|
+
(0, import_node_sdk2.sendErr)(`
|
|
125
|
+
=== Error messages for ${sourceFile} ===`);
|
|
126
|
+
const errors = Array.isArray(errs) ? errs : [errs];
|
|
127
|
+
errors.map((err) => {
|
|
128
|
+
err instanceof Error ? (0, import_node_sdk2.sendErr)(err.message) : (0, import_node_sdk2.sendErr)(err);
|
|
129
|
+
});
|
|
130
|
+
(0, import_node_sdk2.sendErr)(`===`);
|
|
131
|
+
};
|
|
132
|
+
var configure = (dockerImage, dockerImageEnvVar) => ({
|
|
133
|
+
LIGO_DEFAULT_IMAGE: dockerImage,
|
|
134
|
+
LIGO_IMAGE_ENV_VAR: dockerImageEnvVar,
|
|
135
|
+
getLigoDockerImage: () => (0, import_node_sdk2.getDockerImage)(dockerImage, dockerImageEnvVar)
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
// compile.ts
|
|
139
|
+
var import_node_sdk3 = require("@taqueria/node-sdk");
|
|
140
|
+
var import_fs = require("fs");
|
|
141
|
+
var import_promises2 = require("fs/promises");
|
|
142
|
+
var import_path2 = require("path");
|
|
143
|
+
var readline = __toESM(require("readline"));
|
|
144
|
+
var COMPILE_ERR_MSG = "Not compiled";
|
|
145
|
+
var isStorageKind = (exprKind) => exprKind === "storage" || exprKind === "default_storage";
|
|
146
|
+
var isSupportedLigoSyntax = (sourceFile) => /\.(mligo|jsligo)$/.test(sourceFile);
|
|
147
|
+
var isUnsupportedLigoSyntax = (sourceFile) => /\.(ligo|religo)$/.test(sourceFile);
|
|
148
|
+
var isLIGOFile = (sourceFile) => isSupportedLigoSyntax(sourceFile) || isUnsupportedLigoSyntax(sourceFile);
|
|
149
|
+
var isStorageListFile = (sourceFile) => /.+\.(storageList|storages)\.(ligo|religo|mligo|jsligo)$/.test(sourceFile);
|
|
150
|
+
var isParameterListFile = (sourceFile) => /.+\.(parameterList|parameters)\.(ligo|religo|mligo|jsligo)$/.test(sourceFile);
|
|
151
|
+
var extractExt = (path) => {
|
|
152
|
+
const matchResult = path.match(/\.(ligo|religo|mligo|jsligo)$/);
|
|
153
|
+
return matchResult ? matchResult[0] : "";
|
|
154
|
+
};
|
|
155
|
+
var removeExt = (path) => {
|
|
156
|
+
const extRegex = new RegExp(extractExt(path));
|
|
157
|
+
return path.replace(extRegex, "");
|
|
158
|
+
};
|
|
159
|
+
var isOutputFormatJSON = (parsedArgs) => parsedArgs.json;
|
|
160
|
+
var getOutputContractFilename = (parsedArgs, module2) => {
|
|
161
|
+
const ext = isOutputFormatJSON(parsedArgs) ? ".json" : ".tz";
|
|
162
|
+
return (0, import_path2.join)((0, import_node_sdk3.getArtifactsDir)(parsedArgs), `${module2.moduleName}${ext}`);
|
|
163
|
+
};
|
|
164
|
+
var getOutputExprFilename = (parsedArgs, module2, exprKind, exprName) => {
|
|
165
|
+
const contractName = module2.moduleName;
|
|
166
|
+
const ext = isOutputFormatJSON(parsedArgs) ? ".json" : ".tz";
|
|
167
|
+
const outputFile = exprKind === "default_storage" ? `${contractName}.default_storage${ext}` : `${contractName}.${exprKind}.${exprName}${ext}`;
|
|
168
|
+
return (0, import_path2.join)((0, import_node_sdk3.getArtifactsDir)(parsedArgs), `${outputFile}`);
|
|
169
|
+
};
|
|
170
|
+
var getExprNames = (parsedArgs, sourceFile) => {
|
|
171
|
+
return new Promise((resolve, reject) => {
|
|
172
|
+
const inputFilePath = getInputFilenameAbsPath(parsedArgs, sourceFile);
|
|
173
|
+
const readInterface = readline.createInterface({
|
|
174
|
+
input: (0, import_fs.createReadStream)(inputFilePath),
|
|
175
|
+
output: process.stdout
|
|
176
|
+
});
|
|
177
|
+
const variableNames = [];
|
|
178
|
+
readInterface.on("line", function(line) {
|
|
179
|
+
if (!line.trim().startsWith("//")) {
|
|
180
|
+
const matches = line.match(/(?<=\s*(let|const)\s+)[a-zA-Z0-9_]+/g);
|
|
181
|
+
if (matches) {
|
|
182
|
+
variableNames.push(...matches);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
readInterface.on("close", function() {
|
|
187
|
+
resolve(variableNames);
|
|
188
|
+
});
|
|
189
|
+
});
|
|
190
|
+
};
|
|
191
|
+
var getInitialMessage = (pair, module2) => {
|
|
192
|
+
const messages = {
|
|
193
|
+
"mligo-file-main": `// When this file was created, the smart contract was defined with a main function that was not within a named module. As such, the examples below are written with that assumption in mind.`,
|
|
194
|
+
"mligo-file-entry": `// When this file was created, the smart contract was defined with an entrypoint using \`@entry\` that was not within a named module. As such, the examples below are written with that assumption in mind.`,
|
|
195
|
+
"mligo-module-main": `// When this file was created, the smart contract was defined with a main function that was within a named module. As such, the examples below are written with that assumption in mind.`,
|
|
196
|
+
"mligo-module-entry": `// When this file was created, the smart contract was defined with an entrypoint using \`@entry\` that was within a named module. As such, the examples below are written with that assumption in mind.`,
|
|
197
|
+
"jsligo-file-main": `// When this file was created, the smart contract was defined with a main function that was not within a namespace. As such, the examples below are written with that assumption in mind.
|
|
198
|
+
// NOTE: The "storage" type should be exported from the contract file (${module2.sourceFile})`,
|
|
199
|
+
"jsligo-file-entry": `// When this file was created, the smart contract was defined with an entrypoint using \`@entry\` that was not within a namespace. As such, the examples below are written with that assumption in mind.`,
|
|
200
|
+
"jsligo-module-main": `// When this file was created, the smart contract was defined with a main function that was within a namespace. As such, the examples below are written with that assumption in mind.
|
|
201
|
+
// NOTE: The "storage" type should be exported from the contract file (${module2.sourceFile})`,
|
|
202
|
+
"jsligo-module-entry": `// When this file was created, the smart contract was defined with an entrypoint using \`@entry\` that was within a namespace. As such, the examples below are written with that assumption in mind.`
|
|
203
|
+
// ... any other combinations
|
|
204
|
+
};
|
|
205
|
+
return messages[pair] || "// This file was created by Taqueria.";
|
|
206
|
+
};
|
|
207
|
+
var getCommonMsg = (langType, listType) => {
|
|
208
|
+
const varKeyword = langType === "mligo" ? "let" : "const";
|
|
209
|
+
const commonMsgForStorage = `// IMPORTANT: We suggest always explicitly typing your storage values:
|
|
210
|
+
// E.g.: \`${varKeyword} storage: int = 10\` or \`${varKeyword} storage: Contract.storage = 10\``;
|
|
211
|
+
const commonMsgForParameter = `// IMPORTANT: We suggest always explicitly typing your parameter values:
|
|
212
|
+
// E.g.: \`${varKeyword} parameter: int = 10\` or \`${varKeyword} parameter: Contract.parameter = 10\``;
|
|
213
|
+
return listType === "storage" ? commonMsgForStorage : commonMsgForParameter;
|
|
214
|
+
};
|
|
215
|
+
var getContent = (moduleInfo, listType) => {
|
|
216
|
+
const linkToContract = `#import "${moduleInfo.sourceFile}" "Contract"`;
|
|
217
|
+
const pair = `${moduleInfo.syntax}-${moduleInfo.type}`;
|
|
218
|
+
const initialMsg = getInitialMessage(pair, moduleInfo);
|
|
219
|
+
const commonMsg = getCommonMsg(moduleInfo.syntax, listType);
|
|
220
|
+
return `${linkToContract}
|
|
221
|
+
|
|
222
|
+
${initialMsg}
|
|
223
|
+
|
|
224
|
+
${commonMsg}`;
|
|
225
|
+
};
|
|
226
|
+
var initContentForStorage = (moduleInfo) => getContent(moduleInfo, "storage");
|
|
227
|
+
var initContentForParameter = (moduleInfo) => getContent(moduleInfo, "parameter");
|
|
228
|
+
var inject = (commonObj) => {
|
|
229
|
+
const { getLigoDockerImage } = commonObj;
|
|
230
|
+
const getListDeclarationsCmd = async (parsedArgs, sourceFile) => {
|
|
231
|
+
const projectDir = process.env.PROJECT_DIR ?? parsedArgs.projectDir;
|
|
232
|
+
if (!projectDir)
|
|
233
|
+
throw new Error(`No project directory provided`);
|
|
234
|
+
const baseCmd = `DOCKER_DEFAULT_PLATFORM=linux/amd64 docker run --rm -v "${projectDir}":/project -w /project -u $(id -u):$(id -g) ${getLigoDockerImage()} info list-declarations`;
|
|
235
|
+
const inputFile = getInputFilenameRelPath(parsedArgs, sourceFile);
|
|
236
|
+
const flags = "--display-format json";
|
|
237
|
+
const cmd = `${baseCmd} ${inputFile} ${flags}`;
|
|
238
|
+
return cmd;
|
|
239
|
+
};
|
|
240
|
+
const listContractModules = async (parsedArgs, sourceFile) => {
|
|
241
|
+
try {
|
|
242
|
+
await (0, import_node_sdk3.getArch)();
|
|
243
|
+
const cmd = await getListDeclarationsCmd(parsedArgs, sourceFile);
|
|
244
|
+
const { stderr, stdout } = await (0, import_node_sdk3.execCmd)(cmd);
|
|
245
|
+
if (stderr.length > 0)
|
|
246
|
+
return Promise.reject(stderr);
|
|
247
|
+
return JSON.parse(stdout).declarations.reduce(
|
|
248
|
+
(acc, decl) => {
|
|
249
|
+
const srcFile = removeExt((0, import_path2.basename)(sourceFile));
|
|
250
|
+
const syntax = extractExt(sourceFile).replace(".", "");
|
|
251
|
+
if (decl === "main") {
|
|
252
|
+
return [...acc, { moduleName: srcFile, sourceName: sourceFile, sourceFile, type: "file-main", syntax }];
|
|
253
|
+
} else if (decl === "$main") {
|
|
254
|
+
return [...acc, { moduleName: srcFile, sourceName: sourceFile, sourceFile, type: "file-entry", syntax }];
|
|
255
|
+
} else if (decl.endsWith(".main")) {
|
|
256
|
+
const moduleName = decl.replace(/\.main$/, "");
|
|
257
|
+
return [...acc, {
|
|
258
|
+
moduleName,
|
|
259
|
+
sourceName: `${sourceFile}/${moduleName}`,
|
|
260
|
+
sourceFile,
|
|
261
|
+
type: "module-main",
|
|
262
|
+
syntax
|
|
263
|
+
}];
|
|
264
|
+
} else if (decl.endsWith(".$main")) {
|
|
265
|
+
const moduleName = decl.replace(/\.\$main$/, "");
|
|
266
|
+
return [...acc, {
|
|
267
|
+
moduleName,
|
|
268
|
+
sourceName: `${sourceFile}/${moduleName}`,
|
|
269
|
+
sourceFile,
|
|
270
|
+
type: "module-entry",
|
|
271
|
+
syntax
|
|
272
|
+
}];
|
|
273
|
+
}
|
|
274
|
+
return acc;
|
|
275
|
+
},
|
|
276
|
+
[]
|
|
277
|
+
);
|
|
278
|
+
} catch (err) {
|
|
279
|
+
emitExternalError(err, sourceFile);
|
|
280
|
+
return [];
|
|
281
|
+
}
|
|
282
|
+
};
|
|
283
|
+
const getCompileContractCmd = async (parsedArgs, sourceFile, module2) => {
|
|
284
|
+
const projectDir = process.env.PROJECT_DIR ?? parsedArgs.projectDir;
|
|
285
|
+
if (!projectDir)
|
|
286
|
+
throw new Error(`No project directory provided`);
|
|
287
|
+
const baseCmd = `DOCKER_DEFAULT_PLATFORM=linux/amd64 docker run --rm -v "${projectDir}":/project -w /project -u $(id -u):$(id -g) ${getLigoDockerImage()} compile contract`;
|
|
288
|
+
const inputFile = getInputFilenameRelPath(parsedArgs, sourceFile);
|
|
289
|
+
const outputFile = `-o ${getOutputContractFilename(parsedArgs, module2)}`;
|
|
290
|
+
const flags = isOutputFormatJSON(parsedArgs) ? " --michelson-format json " : "";
|
|
291
|
+
const moduleFlag = module2.type.startsWith("file-") ? "" : `-m ${module2.moduleName}`;
|
|
292
|
+
const cmd = `${baseCmd} ${inputFile} ${outputFile} ${flags}${moduleFlag}`;
|
|
293
|
+
return cmd;
|
|
294
|
+
};
|
|
295
|
+
const compileContract = async (parsedArgs, sourceFile, module2) => {
|
|
296
|
+
try {
|
|
297
|
+
await (0, import_node_sdk3.getArch)();
|
|
298
|
+
const cmd = await getCompileContractCmd(parsedArgs, sourceFile, module2);
|
|
299
|
+
const { stderr } = await (0, import_node_sdk3.execCmd)(cmd);
|
|
300
|
+
if (stderr.length > 0)
|
|
301
|
+
(0, import_node_sdk3.sendWarn)(stderr);
|
|
302
|
+
return {
|
|
303
|
+
source: module2.sourceName,
|
|
304
|
+
artifact: getOutputContractFilename(parsedArgs, module2)
|
|
305
|
+
};
|
|
306
|
+
} catch (err) {
|
|
307
|
+
emitExternalError(err, sourceFile);
|
|
308
|
+
return {
|
|
309
|
+
source: module2.sourceName,
|
|
310
|
+
artifact: COMPILE_ERR_MSG
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
};
|
|
314
|
+
const getCompileExprCmd = (parsedArgs, sourceFile, module2, exprKind, exprName) => {
|
|
315
|
+
const projectDir = process.env.PROJECT_DIR ?? parsedArgs.projectDir;
|
|
316
|
+
if (!projectDir)
|
|
317
|
+
throw new Error(`No project directory provided`);
|
|
318
|
+
const compilerType = isStorageKind(exprKind) ? "storage" : "parameter";
|
|
319
|
+
const baseCmd = `DOCKER_DEFAULT_PLATFORM=linux/amd64 docker run --rm -v "${projectDir}":/project -w /project -u $(id -u):$(id -g) ${getLigoDockerImage()} compile ${compilerType}`;
|
|
320
|
+
const inputFile = getInputFilenameRelPath(parsedArgs, sourceFile);
|
|
321
|
+
const outputFile = `-o ${getOutputExprFilename(parsedArgs, module2, exprKind, exprName)}`;
|
|
322
|
+
const flags = isOutputFormatJSON(parsedArgs) ? " --michelson-format json " : "";
|
|
323
|
+
const moduleFlag = (() => {
|
|
324
|
+
switch (module2.type) {
|
|
325
|
+
case "file-main":
|
|
326
|
+
case "file-entry":
|
|
327
|
+
return "-m Contract";
|
|
328
|
+
default:
|
|
329
|
+
return `-m Contract.${module2.moduleName}`;
|
|
330
|
+
}
|
|
331
|
+
})();
|
|
332
|
+
const cmd = `${baseCmd} ${inputFile} ${exprName} ${outputFile} ${flags} ${moduleFlag}`;
|
|
333
|
+
return cmd;
|
|
334
|
+
};
|
|
335
|
+
const compileExpr = (parsedArgs, sourceFile, module2, exprKind) => (exprName) => {
|
|
336
|
+
return (0, import_node_sdk3.getArch)().then(() => getCompileExprCmd(parsedArgs, sourceFile, module2, exprKind, exprName)).then(import_node_sdk3.execCmd).then(({ stderr }) => {
|
|
337
|
+
if (stderr.length > 0)
|
|
338
|
+
(0, import_node_sdk3.sendWarn)(stderr);
|
|
339
|
+
const artifactName = getOutputExprFilename(parsedArgs, module2, exprKind, exprName);
|
|
340
|
+
return {
|
|
341
|
+
source: module2.sourceName,
|
|
342
|
+
artifact: artifactName
|
|
343
|
+
};
|
|
344
|
+
}).catch((err) => {
|
|
345
|
+
return {
|
|
346
|
+
source: module2.sourceName,
|
|
347
|
+
artifact: `${exprName} in ${sourceFile} not compiled`,
|
|
348
|
+
err
|
|
349
|
+
};
|
|
350
|
+
});
|
|
351
|
+
};
|
|
352
|
+
const compileExprs = async (parsedArgs, sourceFile, module2, exprKind) => {
|
|
353
|
+
let exprs = [];
|
|
354
|
+
try {
|
|
355
|
+
exprs = await getExprNames(parsedArgs, sourceFile);
|
|
356
|
+
} catch (err) {
|
|
357
|
+
emitExternalError(err, sourceFile);
|
|
358
|
+
return [{
|
|
359
|
+
source: module2.sourceName,
|
|
360
|
+
artifact: `No ${isStorageKind(exprKind) ? "storage" : "parameter"} expressions compiled`
|
|
361
|
+
}];
|
|
362
|
+
}
|
|
363
|
+
const results = await Promise.all(exprs.map(async (exprName, index) => {
|
|
364
|
+
const compileResult = await compileExpr(
|
|
365
|
+
parsedArgs,
|
|
366
|
+
sourceFile,
|
|
367
|
+
module2,
|
|
368
|
+
exprKind === "storage" && index === 0 ? "default_storage" : exprKind
|
|
369
|
+
)(exprName);
|
|
370
|
+
return compileResult;
|
|
371
|
+
}));
|
|
372
|
+
const errors = results.reduce(
|
|
373
|
+
(acc, result) => {
|
|
374
|
+
if (result.err) {
|
|
375
|
+
if (!(result.err instanceof Error))
|
|
376
|
+
return [...acc, result.err];
|
|
377
|
+
const ligoErrs = acc.filter((err) => err instanceof Error).map((err) => err.message);
|
|
378
|
+
const formattedError = formatLigoError(result.err);
|
|
379
|
+
return ligoErrs.includes(formattedError.message) ? acc : [...acc, formattedError];
|
|
380
|
+
}
|
|
381
|
+
return acc;
|
|
382
|
+
},
|
|
383
|
+
[]
|
|
384
|
+
);
|
|
385
|
+
const retval = results.map(({ source, artifact }) => ({ source, artifact }));
|
|
386
|
+
if (errors.length)
|
|
387
|
+
emitExternalError(errors, sourceFile);
|
|
388
|
+
return retval;
|
|
389
|
+
};
|
|
390
|
+
const compileContractWithStorageAndParameter = async (parsedArgs, sourceFile, module2) => {
|
|
391
|
+
const contractCompileResult = await compileContract(parsedArgs, sourceFile, module2);
|
|
392
|
+
if (contractCompileResult.artifact === COMPILE_ERR_MSG)
|
|
393
|
+
return [contractCompileResult];
|
|
394
|
+
debugger;
|
|
395
|
+
const storageListFile = `${module2.moduleName}.storageList${extractExt(sourceFile)}`;
|
|
396
|
+
const storageListFilename = getInputFilenameAbsPath(parsedArgs, storageListFile);
|
|
397
|
+
const storageCompileResult = await (0, import_promises2.access)(storageListFilename).then(() => compileExprs(parsedArgs, storageListFile, module2, "storage")).catch(() => {
|
|
398
|
+
(0, import_node_sdk3.sendWarn)(
|
|
399
|
+
`Note: storage file associated with "${module2.moduleName}" can't be found, so "${storageListFile}" has been created for you. Use this file to define all initial storage values for this contract
|
|
400
|
+
`
|
|
401
|
+
);
|
|
402
|
+
return (0, import_promises2.writeFile)(storageListFilename, initContentForStorage(module2), "utf8");
|
|
403
|
+
});
|
|
404
|
+
const parameterListFile = `${module2.moduleName}.parameterList${extractExt(sourceFile)}`;
|
|
405
|
+
const parameterListFilename = getInputFilenameAbsPath(parsedArgs, parameterListFile);
|
|
406
|
+
const parameterCompileResult = await (0, import_promises2.access)(parameterListFilename).then(() => compileExprs(parsedArgs, parameterListFile, module2, "parameter")).catch(() => {
|
|
407
|
+
(0, import_node_sdk3.sendWarn)(
|
|
408
|
+
`Note: parameter file associated with "${module2.moduleName}" can't be found, so "${parameterListFile}" has been created for you. Use this file to define all parameter values for this contract
|
|
409
|
+
`
|
|
410
|
+
);
|
|
411
|
+
return (0, import_promises2.writeFile)(parameterListFilename, initContentForParameter(module2), "utf8");
|
|
412
|
+
});
|
|
413
|
+
const storageArtifacts = storageCompileResult ? storageCompileResult.map((res) => res.artifact).join("\n") : "";
|
|
414
|
+
const parameterArtifacts = parameterCompileResult ? parameterCompileResult.map((res) => res.artifact).join("\n") : "";
|
|
415
|
+
const combinedArtifact = [
|
|
416
|
+
contractCompileResult.artifact,
|
|
417
|
+
storageArtifacts,
|
|
418
|
+
parameterArtifacts
|
|
419
|
+
].filter(Boolean).join("\n");
|
|
420
|
+
const combinedRow = {
|
|
421
|
+
source: module2.sourceName,
|
|
422
|
+
artifact: combinedArtifact
|
|
423
|
+
};
|
|
424
|
+
return [combinedRow];
|
|
425
|
+
};
|
|
426
|
+
return {
|
|
427
|
+
getLigoDockerImage,
|
|
428
|
+
getListDeclarationsCmd,
|
|
429
|
+
listContractModules,
|
|
430
|
+
getCompileContractCmd,
|
|
431
|
+
compileContract,
|
|
432
|
+
getCompileExprCmd,
|
|
433
|
+
compileExpr,
|
|
434
|
+
compileExprs,
|
|
435
|
+
compileContractWithStorageAndParameter
|
|
436
|
+
};
|
|
437
|
+
};
|
|
438
|
+
var compile = async (commonObj, parsedArgs) => {
|
|
439
|
+
const { listContractModules, compileContractWithStorageAndParameter } = inject(commonObj);
|
|
440
|
+
const sourceFile = parsedArgs.sourceFile;
|
|
441
|
+
if (!isLIGOFile(sourceFile)) {
|
|
442
|
+
(0, import_node_sdk3.sendErr)(`${sourceFile} is not a LIGO file`);
|
|
443
|
+
return;
|
|
444
|
+
}
|
|
445
|
+
if (isStorageListFile(sourceFile) || isParameterListFile(sourceFile)) {
|
|
446
|
+
(0, import_node_sdk3.sendErr)(`Storage and parameter list files are not meant to be compiled directly`);
|
|
447
|
+
return;
|
|
448
|
+
}
|
|
449
|
+
if (isUnsupportedLigoSyntax(sourceFile)) {
|
|
450
|
+
(0, import_node_sdk3.sendErr)(`Unsupported LIGO syntax detected in ${sourceFile}. Note, we only support .jsligo and .mligo files.`);
|
|
451
|
+
return;
|
|
452
|
+
}
|
|
453
|
+
try {
|
|
454
|
+
const modules = await listContractModules(parsedArgs, sourceFile);
|
|
455
|
+
if (modules.length === 0) {
|
|
456
|
+
return (0, import_node_sdk3.sendJsonRes)([
|
|
457
|
+
{
|
|
458
|
+
source: sourceFile,
|
|
459
|
+
artifact: `No contract modules found in "${sourceFile}"`
|
|
460
|
+
}
|
|
461
|
+
]);
|
|
462
|
+
}
|
|
463
|
+
let allCompileResults = [];
|
|
464
|
+
for (const module2 of modules) {
|
|
465
|
+
if (parsedArgs.module && parsedArgs.module !== module2.moduleName)
|
|
466
|
+
continue;
|
|
467
|
+
const compileResults = await compileContractWithStorageAndParameter(parsedArgs, sourceFile, module2);
|
|
468
|
+
allCompileResults = allCompileResults.concat(compileResults);
|
|
469
|
+
}
|
|
470
|
+
(0, import_node_sdk3.sendJsonRes)(allCompileResults, { footer: `
|
|
471
|
+
Compiled ${allCompileResults.length} contract(s) in "${sourceFile}"` });
|
|
472
|
+
} catch (err) {
|
|
473
|
+
(0, import_node_sdk3.sendErr)(`Error processing "${sourceFile}": ${err}`);
|
|
474
|
+
}
|
|
475
|
+
};
|
|
476
|
+
var compile_default = compile;
|
|
477
|
+
|
|
478
|
+
// compile-all.ts
|
|
479
|
+
var import_node_sdk4 = require("@taqueria/node-sdk");
|
|
480
|
+
var import_fast_glob = __toESM(require("fast-glob"));
|
|
481
|
+
var import_path3 = require("path");
|
|
482
|
+
var compileAll = async (commonObj, parsedArgs) => {
|
|
483
|
+
const { listContractModules, compileContractWithStorageAndParameter } = inject(commonObj);
|
|
484
|
+
let compilePromises = [];
|
|
485
|
+
const contractFilenames = await (0, import_fast_glob.default)(
|
|
486
|
+
["**/*.ligo", "**/*.religo", "**/*.mligo", "**/*.jsligo"],
|
|
487
|
+
{
|
|
488
|
+
cwd: (0, import_path3.join)(parsedArgs.config.projectDir, parsedArgs.config.contractsDir ?? "contracts"),
|
|
489
|
+
absolute: false
|
|
490
|
+
}
|
|
491
|
+
);
|
|
492
|
+
for (const filename of contractFilenames) {
|
|
493
|
+
if (isStorageListFile(filename) || isParameterListFile(filename))
|
|
494
|
+
continue;
|
|
495
|
+
const moduleNames = await listContractModules(parsedArgs, filename);
|
|
496
|
+
for (const moduleName of moduleNames) {
|
|
497
|
+
compilePromises.push(compileContractWithStorageAndParameter(parsedArgs, filename, moduleName));
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
return Promise.all(compilePromises).then((tables) => tables.flat()).then(import_node_sdk4.sendJsonRes).catch((err) => (0, import_node_sdk4.sendErr)(err, false));
|
|
501
|
+
};
|
|
502
|
+
var compile_all_default = compileAll;
|
|
503
|
+
|
|
504
|
+
// ligo.ts
|
|
505
|
+
var import_node_sdk5 = require("@taqueria/node-sdk");
|
|
506
|
+
var import_node_sdk6 = require("@taqueria/node-sdk");
|
|
507
|
+
var import_path4 = require("path");
|
|
508
|
+
var getArbitraryLigoCmd = (commonObj, parsedArgs, uid, gid, userArgs) => {
|
|
509
|
+
const projectDir = process.env.PROJECT_DIR ?? parsedArgs.projectDir;
|
|
510
|
+
if (!projectDir)
|
|
511
|
+
throw `No project directory provided`;
|
|
512
|
+
const userMap = uid && gid ? `${uid}:${gid}` : uid;
|
|
513
|
+
const userMapArgs = uid ? ["-u", userMap] : [];
|
|
514
|
+
const binary = "docker";
|
|
515
|
+
const baseArgs = [
|
|
516
|
+
"run",
|
|
517
|
+
"--rm",
|
|
518
|
+
"-v",
|
|
519
|
+
`${projectDir}:/project`,
|
|
520
|
+
"-w",
|
|
521
|
+
"/project",
|
|
522
|
+
...userMapArgs,
|
|
523
|
+
commonObj.getLigoDockerImage()
|
|
524
|
+
];
|
|
525
|
+
const processedUserArgs = userArgs.split(" ").map((arg) => arg.startsWith("\\-") ? arg.substring(1) : arg).filter(
|
|
526
|
+
(arg) => arg
|
|
527
|
+
);
|
|
528
|
+
const args = [...baseArgs, ...processedUserArgs, "--skip-analytics"];
|
|
529
|
+
const envVars = { "DOCKER_DEFAULT_PLATFORM": "linux/amd64" };
|
|
530
|
+
return [
|
|
531
|
+
[binary, ...args].join(" "),
|
|
532
|
+
envVars
|
|
533
|
+
];
|
|
534
|
+
};
|
|
535
|
+
var ensureEsyExists = async (parsedArgs) => {
|
|
536
|
+
const esyJsonPath = (0, import_path4.join)(parsedArgs.projectDir, "esy.json");
|
|
537
|
+
try {
|
|
538
|
+
return await (0, import_node_sdk6.readJsonFile)(esyJsonPath);
|
|
539
|
+
} catch {
|
|
540
|
+
return await (0, import_node_sdk6.writeJsonFile)(esyJsonPath)({});
|
|
541
|
+
}
|
|
542
|
+
};
|
|
543
|
+
var runArbitraryLigoCmd = (commonObj, parsedArgs, cmd) => ensureEsyExists(parsedArgs).then(import_node_sdk5.getArch).then(async () => {
|
|
544
|
+
const uid = await (0, import_node_sdk5.execCmd)("id -u");
|
|
545
|
+
const gid = await (0, import_node_sdk5.execCmd)("id -g");
|
|
546
|
+
return [uid.stdout.trim(), gid.stdout.trim()];
|
|
547
|
+
}).then(([uid, gid]) => getArbitraryLigoCmd(commonObj, parsedArgs, uid, gid, cmd)).then(([cmd2, envVars]) => (0, import_node_sdk5.spawnCmd)(cmd2, envVars)).then(
|
|
548
|
+
(code) => code !== null && code === 0 ? `Command "${cmd}" ran successfully by LIGO` : `Command "${cmd}" failed. Please check your command`
|
|
549
|
+
).catch((err) => (0, import_node_sdk5.sendAsyncErr)(`An internal error has occurred: ${err.message}`));
|
|
550
|
+
var ligo = (commonObj, parsedArgs) => {
|
|
551
|
+
const args = parsedArgs.command;
|
|
552
|
+
return runArbitraryLigoCmd(commonObj, parsedArgs, args).then(import_node_sdk5.sendRes).catch((err) => (0, import_node_sdk5.sendAsyncErr)(err, false));
|
|
553
|
+
};
|
|
554
|
+
var ligo_default = ligo;
|
|
555
|
+
|
|
556
|
+
// test.ts
|
|
557
|
+
var import_node_sdk7 = require("@taqueria/node-sdk");
|
|
558
|
+
var inject2 = (commonObj) => {
|
|
559
|
+
const { getLigoDockerImage } = commonObj;
|
|
560
|
+
const getTestContractCmd = (parsedArgs, sourceFile) => {
|
|
561
|
+
const projectDir = process.env.PROJECT_DIR ?? parsedArgs.projectDir;
|
|
562
|
+
if (!projectDir)
|
|
563
|
+
throw `No project directory provided`;
|
|
564
|
+
const baseCmd = `DOCKER_DEFAULT_PLATFORM=linux/amd64 docker run --rm -v "${projectDir}":/project -w /project -u $(id -u):$(id -g) ${getLigoDockerImage()} run test`;
|
|
565
|
+
const inputFile = getInputFilenameRelPath(parsedArgs, sourceFile);
|
|
566
|
+
const cmd = `${baseCmd} ${inputFile}`;
|
|
567
|
+
return cmd;
|
|
568
|
+
};
|
|
569
|
+
const testContract = (parsedArgs, sourceFile) => (0, import_node_sdk7.getArch)().then(() => getTestContractCmd(parsedArgs, sourceFile)).then(import_node_sdk7.execCmd).then(({ stdout, stderr }) => {
|
|
570
|
+
if (stderr.length > 0)
|
|
571
|
+
(0, import_node_sdk7.sendWarn)(stderr);
|
|
572
|
+
const result = "\u{1F389} All tests passed \u{1F389}";
|
|
573
|
+
return {
|
|
574
|
+
contract: sourceFile,
|
|
575
|
+
testResults: stdout.length > 0 ? `${stdout}
|
|
576
|
+
${result}` : result
|
|
577
|
+
};
|
|
578
|
+
}).catch((err) => {
|
|
579
|
+
emitExternalError(err, sourceFile);
|
|
580
|
+
return {
|
|
581
|
+
contract: sourceFile,
|
|
582
|
+
testResults: "Some tests failed :("
|
|
583
|
+
};
|
|
584
|
+
});
|
|
585
|
+
return {
|
|
586
|
+
testContract,
|
|
587
|
+
getTestContractCmd
|
|
588
|
+
};
|
|
589
|
+
};
|
|
590
|
+
var test = (commonObj, parsedArgs) => {
|
|
591
|
+
const { testContract } = inject2(commonObj);
|
|
592
|
+
const sourceFile = parsedArgs.sourceFile;
|
|
593
|
+
if (!sourceFile)
|
|
594
|
+
return (0, import_node_sdk7.sendAsyncErr)(`No source file provided`);
|
|
595
|
+
return testContract(parsedArgs, sourceFile).then((result) => [result]).then(import_node_sdk7.sendJsonRes).catch(
|
|
596
|
+
(err) => (0, import_node_sdk7.sendAsyncErr)(err, false)
|
|
597
|
+
);
|
|
598
|
+
};
|
|
599
|
+
var test_default = test;
|
|
600
|
+
|
|
601
|
+
// main.ts
|
|
602
|
+
var main = (dockerImage, dockerImageEnvVar) => (parsedArgs) => {
|
|
603
|
+
const commonObj = configure(dockerImage, dockerImageEnvVar);
|
|
604
|
+
const unsafeOpts = parsedArgs;
|
|
605
|
+
switch (unsafeOpts.task) {
|
|
606
|
+
case "ligo":
|
|
607
|
+
return ligo_default(commonObj, unsafeOpts);
|
|
608
|
+
case "compile":
|
|
609
|
+
return compile_default(commonObj, unsafeOpts);
|
|
610
|
+
case "compile-all":
|
|
611
|
+
return compile_all_default(commonObj, unsafeOpts);
|
|
612
|
+
case "test":
|
|
613
|
+
return test_default(commonObj, parsedArgs);
|
|
614
|
+
case "get-image":
|
|
615
|
+
return (0, import_node_sdk8.sendAsyncRes)(commonObj.getLigoDockerImage());
|
|
616
|
+
default:
|
|
617
|
+
return (0, import_node_sdk8.sendAsyncErr)(`${unsafeOpts.task} is not an understood task by the LIGO plugin`);
|
|
618
|
+
}
|
|
619
|
+
};
|
|
620
|
+
var main_default = main;
|
|
621
|
+
|
|
622
|
+
// index.ts
|
|
623
|
+
var configurePlugin = (settings) => {
|
|
624
|
+
const schema = {
|
|
625
|
+
name: settings.name,
|
|
626
|
+
schema: "1.0",
|
|
627
|
+
version: "0.1",
|
|
628
|
+
alias: settings.alias,
|
|
629
|
+
tasks: [
|
|
630
|
+
import_node_sdk9.Task.create({
|
|
631
|
+
task: "ligo",
|
|
632
|
+
command: "ligo",
|
|
633
|
+
description: "This task allows you to run arbitrary LIGO native commands. Note that they might not benefit from the abstractions provided by Taqueria",
|
|
634
|
+
options: [
|
|
635
|
+
import_node_sdk9.Option.create({
|
|
636
|
+
shortFlag: "c",
|
|
637
|
+
flag: "command",
|
|
638
|
+
type: "string",
|
|
639
|
+
description: "The command to be passed to the underlying LIGO binary, wrapped in quotes",
|
|
640
|
+
required: true
|
|
641
|
+
})
|
|
642
|
+
],
|
|
643
|
+
handler: "proxy",
|
|
644
|
+
encoding: "none"
|
|
645
|
+
}),
|
|
646
|
+
import_node_sdk9.Task.create({
|
|
647
|
+
task: "compile",
|
|
648
|
+
command: "compile <sourceFile>",
|
|
649
|
+
aliases: ["c", "compile-ligo"],
|
|
650
|
+
description: "Compile a smart contract written in a LIGO syntax to Michelson code, along with its associated storage/parameter list files if they are found",
|
|
651
|
+
options: [
|
|
652
|
+
import_node_sdk9.Option.create({
|
|
653
|
+
flag: "json",
|
|
654
|
+
boolean: true,
|
|
655
|
+
description: "Emit JSON-encoded Michelson"
|
|
656
|
+
}),
|
|
657
|
+
import_node_sdk9.Option.create({
|
|
658
|
+
flag: "module",
|
|
659
|
+
shortFlag: "m",
|
|
660
|
+
type: "string",
|
|
661
|
+
description: "The LIGO module to be compiled"
|
|
662
|
+
})
|
|
663
|
+
],
|
|
664
|
+
handler: "proxy",
|
|
665
|
+
encoding: "json"
|
|
666
|
+
}),
|
|
667
|
+
import_node_sdk9.Task.create({
|
|
668
|
+
task: "compile-all",
|
|
669
|
+
command: "compile-all",
|
|
670
|
+
description: "Compile all main smart contracts written in a LIGO syntax to Michelson code, along with their associated storage/parameter list files if they are found",
|
|
671
|
+
options: [
|
|
672
|
+
import_node_sdk9.Option.create({
|
|
673
|
+
flag: "json",
|
|
674
|
+
boolean: true,
|
|
675
|
+
description: "Emit JSON-encoded Michelson"
|
|
676
|
+
})
|
|
677
|
+
],
|
|
678
|
+
handler: "proxy",
|
|
679
|
+
encoding: "json"
|
|
680
|
+
}),
|
|
681
|
+
import_node_sdk9.Task.create({
|
|
682
|
+
task: "test",
|
|
683
|
+
command: "test <sourceFile>",
|
|
684
|
+
description: "Test a smart contract written in LIGO",
|
|
685
|
+
handler: "proxy",
|
|
686
|
+
encoding: "json"
|
|
687
|
+
}),
|
|
688
|
+
import_node_sdk9.Task.create({
|
|
689
|
+
task: "get-image",
|
|
690
|
+
command: "get-image",
|
|
691
|
+
description: "Gets the name of the image to be used",
|
|
692
|
+
handler: "proxy",
|
|
693
|
+
hidden: true
|
|
694
|
+
})
|
|
695
|
+
],
|
|
696
|
+
templates: [
|
|
697
|
+
import_node_sdk9.Template.create({
|
|
698
|
+
template: "contract",
|
|
699
|
+
command: "contract <sourceFileName>",
|
|
700
|
+
description: "Create a LIGO contract with boilerplate code",
|
|
701
|
+
positionals: [
|
|
702
|
+
import_node_sdk9.PositionalArg.create({
|
|
703
|
+
placeholder: "sourceFileName",
|
|
704
|
+
type: "string",
|
|
705
|
+
description: "The name of the LIGO contract to generate"
|
|
706
|
+
})
|
|
707
|
+
],
|
|
708
|
+
options: [
|
|
709
|
+
import_node_sdk9.Option.create({
|
|
710
|
+
shortFlag: "s",
|
|
711
|
+
flag: "syntax",
|
|
712
|
+
type: "string",
|
|
713
|
+
description: "The syntax used in the contract"
|
|
714
|
+
})
|
|
715
|
+
],
|
|
716
|
+
handler: createContract_default
|
|
717
|
+
})
|
|
718
|
+
],
|
|
719
|
+
proxy: main_default(settings.dockerImage, settings.dockerImageEnvVar),
|
|
720
|
+
postInstall: `node ${__dirname}/postinstall.js`
|
|
721
|
+
};
|
|
722
|
+
return import_node_sdk9.Plugin.create(() => settings.configurator ? settings.configurator(schema) : schema, settings.unparsedArgs);
|
|
723
|
+
};
|
|
724
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
725
|
+
0 && (module.exports = {
|
|
726
|
+
configurePlugin
|
|
727
|
+
});
|
|
728
|
+
//# sourceMappingURL=index.js.map
|