@taqueria/plugin-ligo 0.37.21 → 0.37.31
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/common.ts +3 -2
- package/compile-all.ts +15 -111
- package/compile.ts +413 -174
- package/index.js +379 -228
- package/index.js.map +1 -1
- package/index.mjs +390 -232
- package/index.mjs.map +1 -1
- package/index.ts +7 -0
- package/ligo.ts +1 -1
- package/package.json +3 -3
- package/postinstall.js +19 -0
package/index.js
CHANGED
|
@@ -176,7 +176,7 @@ var import_node_sdk8 = require("@taqueria/node-sdk");
|
|
|
176
176
|
// common.ts
|
|
177
177
|
var import_node_sdk2 = require("@taqueria/node-sdk");
|
|
178
178
|
var import_path = require("path");
|
|
179
|
-
var LIGO_DEFAULT_IMAGE = "ligolang/ligo:0.
|
|
179
|
+
var LIGO_DEFAULT_IMAGE = "ligolang/ligo:0.71.0";
|
|
180
180
|
var LIGO_IMAGE_ENV_VAR = "TAQ_LIGO_IMAGE";
|
|
181
181
|
var getLigoDockerImage = () => (0, import_node_sdk2.getDockerImage)(LIGO_DEFAULT_IMAGE, LIGO_IMAGE_ENV_VAR);
|
|
182
182
|
var getInputFilenameAbsPath = (parsedArgs, sourceFile) => (0, import_path.join)(parsedArgs.config.projectDir, parsedArgs.config.contractsDir ?? "contracts", sourceFile);
|
|
@@ -195,17 +195,63 @@ var import_promises2 = require("fs/promises");
|
|
|
195
195
|
var import_path2 = require("path");
|
|
196
196
|
var COMPILE_ERR_MSG = "Not compiled";
|
|
197
197
|
var isStorageKind = (exprKind) => exprKind === "storage" || exprKind === "default_storage";
|
|
198
|
-
var
|
|
198
|
+
var isSupportedLigoSyntax = (sourceFile) => /\.(mligo|jsligo)$/.test(sourceFile);
|
|
199
|
+
var isUnsupportedLigoSyntax = (sourceFile) => /\.(ligo|religo)$/.test(sourceFile);
|
|
200
|
+
var isLIGOFile = (sourceFile) => isSupportedLigoSyntax(sourceFile) || isUnsupportedLigoSyntax(sourceFile);
|
|
199
201
|
var isStorageListFile = (sourceFile) => /.+\.(storageList|storages)\.(ligo|religo|mligo|jsligo)$/.test(sourceFile);
|
|
200
202
|
var isParameterListFile = (sourceFile) => /.+\.(parameterList|parameters)\.(ligo|religo|mligo|jsligo)$/.test(sourceFile);
|
|
201
|
-
var
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
const
|
|
206
|
-
|
|
203
|
+
var listContractModules = async (parsedArgs, sourceFile) => {
|
|
204
|
+
try {
|
|
205
|
+
await (0, import_node_sdk3.getArch)();
|
|
206
|
+
const cmd = await getListDeclarationsCmd(parsedArgs, sourceFile);
|
|
207
|
+
const { stderr, stdout } = await (0, import_node_sdk3.execCmd)(cmd);
|
|
208
|
+
if (stderr.length > 0)
|
|
209
|
+
return Promise.reject(stderr);
|
|
210
|
+
return JSON.parse(stdout).declarations.reduce(
|
|
211
|
+
(acc, decl) => {
|
|
212
|
+
const srcFile = removeExt((0, import_path2.basename)(sourceFile));
|
|
213
|
+
const syntax = extractExt(sourceFile).replace(".", "");
|
|
214
|
+
if (decl === "main") {
|
|
215
|
+
return [...acc, { moduleName: srcFile, sourceName: sourceFile, sourceFile, type: "file-main", syntax }];
|
|
216
|
+
} else if (decl === "$main") {
|
|
217
|
+
return [...acc, { moduleName: srcFile, sourceName: sourceFile, sourceFile, type: "file-entry", syntax }];
|
|
218
|
+
} else if (decl.endsWith(".main")) {
|
|
219
|
+
const moduleName = decl.replace(/\.main$/, "");
|
|
220
|
+
return [...acc, {
|
|
221
|
+
moduleName,
|
|
222
|
+
sourceName: `${sourceFile}/${moduleName}`,
|
|
223
|
+
sourceFile,
|
|
224
|
+
type: "module-main",
|
|
225
|
+
syntax
|
|
226
|
+
}];
|
|
227
|
+
} else if (decl.endsWith(".$main")) {
|
|
228
|
+
const moduleName = decl.replace(/\.\$main$/, "");
|
|
229
|
+
return [...acc, {
|
|
230
|
+
moduleName,
|
|
231
|
+
sourceName: `${sourceFile}/${moduleName}`,
|
|
232
|
+
sourceFile,
|
|
233
|
+
type: "module-entry",
|
|
234
|
+
syntax
|
|
235
|
+
}];
|
|
236
|
+
}
|
|
237
|
+
return acc;
|
|
238
|
+
},
|
|
239
|
+
[]
|
|
240
|
+
);
|
|
241
|
+
} catch (err) {
|
|
242
|
+
emitExternalError(err, sourceFile);
|
|
243
|
+
return [];
|
|
207
244
|
}
|
|
208
|
-
|
|
245
|
+
};
|
|
246
|
+
var getListDeclarationsCmd = async (parsedArgs, sourceFile) => {
|
|
247
|
+
const projectDir = process.env.PROJECT_DIR ?? parsedArgs.projectDir;
|
|
248
|
+
if (!projectDir)
|
|
249
|
+
throw new Error(`No project directory provided`);
|
|
250
|
+
const baseCmd = `DOCKER_DEFAULT_PLATFORM=linux/amd64 docker run --rm -v "${projectDir}":/project -w /project -u $(id -u):$(id -g) ${getLigoDockerImage()} info list-declarations`;
|
|
251
|
+
const inputFile = getInputFilenameRelPath(parsedArgs, sourceFile);
|
|
252
|
+
const flags = "--display-format json";
|
|
253
|
+
const cmd = `${baseCmd} ${inputFile} ${flags}`;
|
|
254
|
+
return cmd;
|
|
209
255
|
};
|
|
210
256
|
var extractExt = (path) => {
|
|
211
257
|
const matchResult = path.match(/\.(ligo|religo|mligo|jsligo)$/);
|
|
@@ -216,291 +262,396 @@ var removeExt = (path) => {
|
|
|
216
262
|
return path.replace(extRegex, "");
|
|
217
263
|
};
|
|
218
264
|
var isOutputFormatJSON = (parsedArgs) => parsedArgs.json;
|
|
219
|
-
var getOutputContractFilename = (parsedArgs,
|
|
220
|
-
const outputFile = (0, import_path2.basename)(sourceFile, (0, import_path2.extname)(sourceFile));
|
|
265
|
+
var getOutputContractFilename = (parsedArgs, module2) => {
|
|
221
266
|
const ext = isOutputFormatJSON(parsedArgs) ? ".json" : ".tz";
|
|
222
|
-
return (0, import_path2.join)((0, import_node_sdk3.getArtifactsDir)(parsedArgs), `${
|
|
223
|
-
};
|
|
224
|
-
var getContractNameForExpr = (sourceFile, exprKind) => {
|
|
225
|
-
try {
|
|
226
|
-
return isStorageKind(exprKind) ? sourceFile.match(/.+(?=\.(?:storageList|storages)\.(ligo|religo|mligo|jsligo))/).join(".") : sourceFile.match(/.+(?=\.(?:parameterList|parameters)\.(ligo|religo|mligo|jsligo))/).join(".");
|
|
227
|
-
} catch (err) {
|
|
228
|
-
throw new Error(`Something went wrong internally when dealing with filename format: ${err}`);
|
|
229
|
-
}
|
|
267
|
+
return (0, import_path2.join)((0, import_node_sdk3.getArtifactsDir)(parsedArgs), `${module2.moduleName}${ext}`);
|
|
230
268
|
};
|
|
231
|
-
var getOutputExprFilename = (parsedArgs,
|
|
232
|
-
const contractName =
|
|
269
|
+
var getOutputExprFilename = (parsedArgs, module2, exprKind, exprName) => {
|
|
270
|
+
const contractName = module2.moduleName;
|
|
233
271
|
const ext = isOutputFormatJSON(parsedArgs) ? ".json" : ".tz";
|
|
234
272
|
const outputFile = exprKind === "default_storage" ? `${contractName}.default_storage${ext}` : `${contractName}.${exprKind}.${exprName}${ext}`;
|
|
235
273
|
return (0, import_path2.join)((0, import_node_sdk3.getArtifactsDir)(parsedArgs), `${outputFile}`);
|
|
236
274
|
};
|
|
237
|
-
var getCompileContractCmd = async (parsedArgs, sourceFile) => {
|
|
275
|
+
var getCompileContractCmd = async (parsedArgs, sourceFile, module2) => {
|
|
238
276
|
const projectDir = process.env.PROJECT_DIR ?? parsedArgs.projectDir;
|
|
239
277
|
if (!projectDir)
|
|
240
|
-
throw `No project directory provided
|
|
278
|
+
throw new Error(`No project directory provided`);
|
|
241
279
|
const baseCmd = `DOCKER_DEFAULT_PLATFORM=linux/amd64 docker run --rm -v "${projectDir}":/project -w /project -u $(id -u):$(id -g) ${getLigoDockerImage()} compile contract`;
|
|
242
280
|
const inputFile = getInputFilenameRelPath(parsedArgs, sourceFile);
|
|
243
|
-
const outputFile = `-o ${getOutputContractFilename(parsedArgs,
|
|
281
|
+
const outputFile = `-o ${getOutputContractFilename(parsedArgs, module2)}`;
|
|
244
282
|
const flags = isOutputFormatJSON(parsedArgs) ? " --michelson-format json " : "";
|
|
245
|
-
const
|
|
246
|
-
const
|
|
247
|
-
const cmd = `${baseCmd} ${inputFile} ${outputFile} ${flags}${entryFlag}`;
|
|
283
|
+
const moduleFlag = module2.type.startsWith("file-") ? "" : `-m ${module2.moduleName}`;
|
|
284
|
+
const cmd = `${baseCmd} ${inputFile} ${outputFile} ${flags}${moduleFlag}`;
|
|
248
285
|
return cmd;
|
|
249
286
|
};
|
|
250
|
-
var getCompileExprCmd = (parsedArgs, sourceFile, exprKind, exprName) => {
|
|
287
|
+
var getCompileExprCmd = (parsedArgs, sourceFile, module2, exprKind, exprName) => {
|
|
251
288
|
const projectDir = process.env.PROJECT_DIR ?? parsedArgs.projectDir;
|
|
252
289
|
if (!projectDir)
|
|
253
|
-
throw `No project directory provided
|
|
290
|
+
throw new Error(`No project directory provided`);
|
|
254
291
|
const compilerType = isStorageKind(exprKind) ? "storage" : "parameter";
|
|
255
292
|
const baseCmd = `DOCKER_DEFAULT_PLATFORM=linux/amd64 docker run --rm -v "${projectDir}":/project -w /project -u $(id -u):$(id -g) ${getLigoDockerImage()} compile ${compilerType}`;
|
|
256
293
|
const inputFile = getInputFilenameRelPath(parsedArgs, sourceFile);
|
|
257
|
-
const outputFile = `-o ${getOutputExprFilename(parsedArgs,
|
|
294
|
+
const outputFile = `-o ${getOutputExprFilename(parsedArgs, module2, exprKind, exprName)}`;
|
|
258
295
|
const flags = isOutputFormatJSON(parsedArgs) ? " --michelson-format json " : "";
|
|
259
|
-
const
|
|
296
|
+
const moduleFlag = (() => {
|
|
297
|
+
switch (module2.type) {
|
|
298
|
+
case "file-main":
|
|
299
|
+
case "file-entry":
|
|
300
|
+
return "-m Contract";
|
|
301
|
+
default:
|
|
302
|
+
return `-m Contract.${module2.moduleName}`;
|
|
303
|
+
}
|
|
304
|
+
})();
|
|
305
|
+
const cmd = `${baseCmd} ${inputFile} ${exprName} ${outputFile} ${flags} ${moduleFlag}`;
|
|
260
306
|
return cmd;
|
|
261
307
|
};
|
|
262
|
-
var compileContract = async (parsedArgs, sourceFile) => {
|
|
308
|
+
var compileContract = async (parsedArgs, sourceFile, module2) => {
|
|
263
309
|
try {
|
|
264
310
|
await (0, import_node_sdk3.getArch)();
|
|
265
|
-
const cmd = await getCompileContractCmd(parsedArgs, sourceFile);
|
|
311
|
+
const cmd = await getCompileContractCmd(parsedArgs, sourceFile, module2);
|
|
266
312
|
const { stderr } = await (0, import_node_sdk3.execCmd)(cmd);
|
|
267
313
|
if (stderr.length > 0)
|
|
268
314
|
(0, import_node_sdk3.sendWarn)(stderr);
|
|
269
315
|
return {
|
|
270
|
-
|
|
271
|
-
artifact: getOutputContractFilename(parsedArgs,
|
|
316
|
+
source: module2.sourceName,
|
|
317
|
+
artifact: getOutputContractFilename(parsedArgs, module2)
|
|
272
318
|
};
|
|
273
319
|
} catch (err) {
|
|
274
320
|
emitExternalError(err, sourceFile);
|
|
275
321
|
return {
|
|
276
|
-
|
|
322
|
+
source: module2.sourceName,
|
|
277
323
|
artifact: COMPILE_ERR_MSG
|
|
278
324
|
};
|
|
279
325
|
}
|
|
280
326
|
};
|
|
281
|
-
var compileExpr = (parsedArgs, sourceFile,
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
}
|
|
327
|
+
var compileExpr = (parsedArgs, sourceFile, module2, exprKind) => (exprName) => {
|
|
328
|
+
return (0, import_node_sdk3.getArch)().then(() => getCompileExprCmd(parsedArgs, sourceFile, module2, exprKind, exprName)).then(import_node_sdk3.execCmd).then(({ stderr }) => {
|
|
329
|
+
if (stderr.length > 0)
|
|
330
|
+
(0, import_node_sdk3.sendWarn)(stderr);
|
|
331
|
+
const artifactName = getOutputExprFilename(parsedArgs, module2, exprKind, exprName);
|
|
332
|
+
return {
|
|
333
|
+
source: module2.sourceName,
|
|
334
|
+
artifact: artifactName
|
|
335
|
+
};
|
|
336
|
+
}).catch((err) => {
|
|
337
|
+
emitExternalError(err, sourceFile);
|
|
338
|
+
return {
|
|
339
|
+
source: module2.sourceName,
|
|
340
|
+
artifact: `${sourceFile} not compiled`
|
|
341
|
+
};
|
|
342
|
+
});
|
|
343
|
+
};
|
|
296
344
|
var getExprNames = (parsedArgs, sourceFile) => (0, import_promises2.readFile)(getInputFilenameAbsPath(parsedArgs, sourceFile), "utf8").then((data) => data.match(/(?<=\n\s*(let|const)\s+)[a-zA-Z0-9_]+/g) ?? []);
|
|
297
|
-
var compileExprs = (parsedArgs, sourceFile, exprKind) => getExprNames(parsedArgs, sourceFile).then((exprNames) => {
|
|
345
|
+
var compileExprs = (parsedArgs, sourceFile, module2, exprKind) => getExprNames(parsedArgs, sourceFile).then((exprNames) => {
|
|
298
346
|
if (exprNames.length === 0)
|
|
299
347
|
return [];
|
|
300
348
|
const firstExprName = exprNames.slice(0, 1)[0];
|
|
301
349
|
const restExprNames = exprNames.slice(1, exprNames.length);
|
|
302
350
|
const firstExprKind = isStorageKind(exprKind) ? "default_storage" : "parameter";
|
|
303
351
|
const restExprKind = isStorageKind(exprKind) ? "storage" : "parameter";
|
|
304
|
-
const firstExprResult = compileExpr(parsedArgs, sourceFile, firstExprKind)(firstExprName);
|
|
305
|
-
const restExprResults = restExprNames.map(compileExpr(parsedArgs, sourceFile, restExprKind));
|
|
352
|
+
const firstExprResult = compileExpr(parsedArgs, sourceFile, module2, firstExprKind)(firstExprName);
|
|
353
|
+
const restExprResults = restExprNames.map(compileExpr(parsedArgs, sourceFile, module2, restExprKind));
|
|
306
354
|
return Promise.all([firstExprResult].concat(restExprResults));
|
|
307
355
|
}).catch((err) => {
|
|
308
356
|
emitExternalError(err, sourceFile);
|
|
309
357
|
return [{
|
|
310
|
-
|
|
358
|
+
source: module2.sourceName,
|
|
311
359
|
artifact: `No ${isStorageKind(exprKind) ? "storage" : "parameter"} expressions compiled`
|
|
312
360
|
}];
|
|
313
361
|
}).then(
|
|
314
362
|
(results) => results.length > 0 ? results : [{
|
|
315
|
-
|
|
363
|
+
source: module2.sourceName,
|
|
316
364
|
artifact: `No ${isStorageKind(exprKind) ? "storage" : "parameter"} expressions found`
|
|
317
365
|
}]
|
|
318
|
-
)
|
|
319
|
-
var
|
|
320
|
-
const
|
|
321
|
-
const storageListFilename = getInputFilenameAbsPath(parsedArgs, storageListFile);
|
|
322
|
-
return (0, import_promises2.access)(storageListFilename).then(() => {
|
|
323
|
-
(0, import_node_sdk3.sendWarn)(
|
|
324
|
-
`Warning: The naming convention of "<CONTRACT>.storages.<EXTENSION>" is deprecated and renamed to "<CONTRACT>.storageList.<EXTENSION>". Please adjust your storage file names accordingly
|
|
325
|
-
`
|
|
326
|
-
);
|
|
327
|
-
return compileExprs(parsedArgs, storageListFile, "storage");
|
|
328
|
-
});
|
|
329
|
-
};
|
|
330
|
-
var tryLegacyParameterNamingConvention = (parsedArgs, sourceFile) => {
|
|
331
|
-
const parameterListFile = `${removeExt(sourceFile)}.parameters${extractExt(sourceFile)}`;
|
|
332
|
-
const parameterListFilename = getInputFilenameAbsPath(parsedArgs, parameterListFile);
|
|
333
|
-
return (0, import_promises2.access)(parameterListFilename).then(() => {
|
|
334
|
-
(0, import_node_sdk3.sendWarn)(
|
|
335
|
-
`Warning: The naming convention of "<CONTRACT>.parameters.<EXTENSION>" is deprecated and renamed to "<CONTRACT>.parameterList.<EXTENSION>". Please adjust your parameter file names accordingly
|
|
336
|
-
`
|
|
337
|
-
);
|
|
338
|
-
return compileExprs(parsedArgs, parameterListFile, "parameter");
|
|
339
|
-
});
|
|
340
|
-
};
|
|
341
|
-
var initContentForStorage = (sourceFile) => {
|
|
342
|
-
const linkToContract = `#include "${sourceFile}"
|
|
366
|
+
);
|
|
367
|
+
var initContentForStorage = (module2) => {
|
|
368
|
+
const linkToContract = `#import "${module2.sourceFile}" "Contract"
|
|
343
369
|
|
|
344
370
|
`;
|
|
345
|
-
const instruction = "// Define your initial storage values as a list of LIGO variable definitions
|
|
346
|
-
const
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
371
|
+
const instruction = "// Define your initial storage values as a list of LIGO variable definitions, the first of which will be considered the default value to be used for origination later on\n";
|
|
372
|
+
const syntax = (() => {
|
|
373
|
+
const pair = [module2.syntax, module2.type].join("-");
|
|
374
|
+
switch (pair) {
|
|
375
|
+
case "mligo-file-main":
|
|
376
|
+
return [
|
|
377
|
+
"// 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.",
|
|
378
|
+
"",
|
|
379
|
+
"// If your storage is a simple value, you can define it directly",
|
|
380
|
+
"// E.g. let storage = 10",
|
|
381
|
+
"",
|
|
382
|
+
"// For added type-safety, you can reference the type of your storage from the contract",
|
|
383
|
+
"// E.g. let storage : Contract.storage = 10"
|
|
384
|
+
];
|
|
385
|
+
break;
|
|
386
|
+
case "mligo-file-entry":
|
|
387
|
+
return [
|
|
388
|
+
"// 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.",
|
|
389
|
+
"",
|
|
390
|
+
"// If your storage is a simple value, you can define it directly",
|
|
391
|
+
"// E.g. let storage = 10",
|
|
392
|
+
"",
|
|
393
|
+
"// For added type-safety, you can reference the type of your storage from the contract",
|
|
394
|
+
"// E.g. let storage : Contract.storage = 10"
|
|
395
|
+
];
|
|
396
|
+
break;
|
|
397
|
+
case "mligo-module-main":
|
|
398
|
+
return [
|
|
399
|
+
"// 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.",
|
|
400
|
+
"",
|
|
401
|
+
"// If your storage is a simple value, you can define it directly",
|
|
402
|
+
"// E.g. let storage = 10",
|
|
403
|
+
"",
|
|
404
|
+
"// For added type-safety, you can reference the type of your storage from the contract",
|
|
405
|
+
`// E.g. let storage : Contract.${module2.moduleName}.storage = 10`
|
|
406
|
+
];
|
|
407
|
+
break;
|
|
408
|
+
case "mligo-module-entry":
|
|
409
|
+
return [
|
|
410
|
+
"// 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.",
|
|
411
|
+
"",
|
|
412
|
+
"// If your storage is a simple value, you can define it directly",
|
|
413
|
+
"// E.g. let storage = 10",
|
|
414
|
+
"",
|
|
415
|
+
"// For added type-safety, you can reference the type of your storage from the contract",
|
|
416
|
+
`// E.g. let storage : Contract.${module2.moduleName}.storage = 10`
|
|
417
|
+
];
|
|
418
|
+
break;
|
|
419
|
+
case "jsligo-file-main":
|
|
420
|
+
return [
|
|
421
|
+
"// 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.",
|
|
422
|
+
`// NOTE: The "storage" type should be exported from the contract file (${module2.sourceFile})`,
|
|
423
|
+
"",
|
|
424
|
+
"// If your storage is a simple value, you can define it directly",
|
|
425
|
+
"// E.g. const storage = 10",
|
|
426
|
+
"",
|
|
427
|
+
"// For added type-safety, you can reference the type of your storage from the contract. This assumes that you have exported your `storage` type from the contract file.",
|
|
428
|
+
"// E.g. const storage : Contract.storage = 10"
|
|
429
|
+
];
|
|
430
|
+
break;
|
|
431
|
+
case "jsligo-file-entry":
|
|
432
|
+
return [
|
|
433
|
+
"// 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.",
|
|
434
|
+
"",
|
|
435
|
+
"// If your storage is a simple value, you can define it directly",
|
|
436
|
+
"// E.g. const storage = 10",
|
|
437
|
+
"",
|
|
438
|
+
"// For added type-safety, you can reference the type of your storage from the contract. This assumes that you have exported your `storage` type from the contract file.",
|
|
439
|
+
"// E.g. const storage : Contract.storage = 10"
|
|
440
|
+
];
|
|
441
|
+
break;
|
|
442
|
+
case "jsligo-module-main":
|
|
443
|
+
return [
|
|
444
|
+
"// 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.",
|
|
445
|
+
`// NOTE: The "storage" type should be exported from the contract file (${module2.sourceFile})`,
|
|
446
|
+
"",
|
|
447
|
+
"// If your storage is a simple value, you can define it directly",
|
|
448
|
+
"// E.g. const storage = 10",
|
|
449
|
+
"",
|
|
450
|
+
"// For added type-safety, you can reference the type of your storage from the contract. This assumes that you have exported your `storage` type from the contract file.",
|
|
451
|
+
`// E.g. const storage : Contract.${module2.moduleName}.storage = 10`
|
|
452
|
+
];
|
|
453
|
+
break;
|
|
454
|
+
case "jsligo-module-entry":
|
|
455
|
+
return [
|
|
456
|
+
"// 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.",
|
|
457
|
+
"",
|
|
458
|
+
"// If your storage is a simple value, you can define it directly",
|
|
459
|
+
"// E.g. const storage = 10",
|
|
460
|
+
"",
|
|
461
|
+
"// For added type-safety, you can reference the type of your storage from the contract. This assumes that you have exported your `storage` type from the contract file.",
|
|
462
|
+
`// E.g. const storage : Contract.${module2.moduleName}.storage = 10`
|
|
463
|
+
];
|
|
464
|
+
break;
|
|
465
|
+
default:
|
|
466
|
+
return [];
|
|
467
|
+
}
|
|
468
|
+
})();
|
|
469
|
+
return linkToContract + instruction + syntax.join("\n");
|
|
357
470
|
};
|
|
358
|
-
var initContentForParameter = (
|
|
359
|
-
const linkToContract = `#
|
|
471
|
+
var initContentForParameter = (module2) => {
|
|
472
|
+
const linkToContract = `#import "${module2.sourceFile}" "Contract"
|
|
360
473
|
|
|
361
474
|
`;
|
|
362
475
|
const instruction = "// Define your parameter values as a list of LIGO variable definitions\n";
|
|
363
|
-
const
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
476
|
+
const syntax = (() => {
|
|
477
|
+
const pair = [module2.syntax, module2.type].join("-");
|
|
478
|
+
switch (pair) {
|
|
479
|
+
case "mligo-file-main":
|
|
480
|
+
return [
|
|
481
|
+
"// 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.",
|
|
482
|
+
"",
|
|
483
|
+
"// If your parameter is a simple value, you can define it directly",
|
|
484
|
+
"// E.g. let default_parameter = 10",
|
|
485
|
+
"",
|
|
486
|
+
"// For added type-safety, you can reference the type of your parameter from the contract",
|
|
487
|
+
"// E.g. let default_parameter : Contract.parameter = 10"
|
|
488
|
+
];
|
|
489
|
+
break;
|
|
490
|
+
case "mligo-file-entry":
|
|
491
|
+
return [
|
|
492
|
+
"// 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.",
|
|
493
|
+
"",
|
|
494
|
+
"// If your parameter is a simple value, you can define it directly",
|
|
495
|
+
"// E.g. let default_parameter = 10",
|
|
496
|
+
"",
|
|
497
|
+
"// For added type-safety, you can reference the type of your parameter from the contract",
|
|
498
|
+
"// E.g. let default_parameter : parameter_of Contract = 10"
|
|
499
|
+
];
|
|
500
|
+
break;
|
|
501
|
+
case "mligo-module-main":
|
|
502
|
+
return [
|
|
503
|
+
"// 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.",
|
|
504
|
+
"",
|
|
505
|
+
"// If your parameter is a simple value, you can define it directly",
|
|
506
|
+
"// E.g. let default_parameter = 10",
|
|
507
|
+
"",
|
|
508
|
+
"// For added type-safety, you can reference the type of your parameter from the contract",
|
|
509
|
+
`// E.g. let default_parameter : Contract.${module2.moduleName}.parameter = 10`
|
|
510
|
+
];
|
|
511
|
+
break;
|
|
512
|
+
case "mligo-module-entry":
|
|
513
|
+
return [
|
|
514
|
+
"// 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.",
|
|
515
|
+
"",
|
|
516
|
+
"// If your parameter is a simple value, you can define it directly",
|
|
517
|
+
"// E.g. let default_parameter = 10",
|
|
518
|
+
"",
|
|
519
|
+
"// For added type-safety, you can reference the type of your parameter from the contract",
|
|
520
|
+
`// E.g. let default_parameter : parameter_of Contract.${module2.moduleName} = 10`
|
|
521
|
+
];
|
|
522
|
+
break;
|
|
523
|
+
case "jsligo-file-main":
|
|
524
|
+
return [
|
|
525
|
+
"// 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.",
|
|
526
|
+
`// NOTE: The "parameter" type should be exported from the contract file (${module2.sourceFile})`,
|
|
527
|
+
"",
|
|
528
|
+
"// If your parameter is a simple value, you can define it directly",
|
|
529
|
+
"// E.g. const default_parameter = 10",
|
|
530
|
+
"",
|
|
531
|
+
"// For added type-safety, you can reference the type of your parameter from the contract",
|
|
532
|
+
"// E.g. const default_parameter : Contract.parameter = 10"
|
|
533
|
+
];
|
|
534
|
+
break;
|
|
535
|
+
case "jsligo-file-entry":
|
|
536
|
+
return [
|
|
537
|
+
"// 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.",
|
|
538
|
+
"",
|
|
539
|
+
"// If your parameter is a simple value, you can define it directly",
|
|
540
|
+
"// E.g. const default_parameter = 10",
|
|
541
|
+
"",
|
|
542
|
+
"// For added type-safety, you can reference the type of your parameter from the contract",
|
|
543
|
+
"// E.g. const default_parameter : parameter_of Contract = 10"
|
|
544
|
+
];
|
|
545
|
+
break;
|
|
546
|
+
case "jsligo-module-main":
|
|
547
|
+
return [
|
|
548
|
+
"// 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.",
|
|
549
|
+
`// NOTE: The "parameter" type should be exported from the contract file (${module2.sourceFile})`,
|
|
550
|
+
"",
|
|
551
|
+
"// If your parameter is a simple value, you can define it directly",
|
|
552
|
+
"// E.g. const default_parameter = 10",
|
|
553
|
+
"",
|
|
554
|
+
"// For added type-safety, you can reference the type of your parameter from the contract",
|
|
555
|
+
`// E.g. const default_parameter : Contract.${module2.moduleName}.parameter = 10`
|
|
556
|
+
];
|
|
557
|
+
break;
|
|
558
|
+
case "jsligo-module-entry":
|
|
559
|
+
return [
|
|
560
|
+
"// 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.",
|
|
561
|
+
"",
|
|
562
|
+
"// If your parameter is a simple value, you can define it directly",
|
|
563
|
+
"// E.g. const default_parameter = 10",
|
|
564
|
+
"",
|
|
565
|
+
"// For added type-safety, you can reference the type of your parameter from the contract",
|
|
566
|
+
`// E.g. const default_parameter : parameter_of Contract.${module2.moduleName} = 10`
|
|
567
|
+
];
|
|
568
|
+
break;
|
|
569
|
+
default:
|
|
570
|
+
return [];
|
|
571
|
+
}
|
|
572
|
+
})();
|
|
573
|
+
return linkToContract + instruction + syntax.join("\n");
|
|
374
574
|
};
|
|
375
|
-
var compileContractWithStorageAndParameter = async (parsedArgs, sourceFile) => {
|
|
376
|
-
const contractCompileResult = await compileContract(parsedArgs, sourceFile);
|
|
575
|
+
var compileContractWithStorageAndParameter = async (parsedArgs, sourceFile, module2) => {
|
|
576
|
+
const contractCompileResult = await compileContract(parsedArgs, sourceFile, module2);
|
|
377
577
|
if (contractCompileResult.artifact === COMPILE_ERR_MSG)
|
|
378
578
|
return [contractCompileResult];
|
|
379
|
-
const storageListFile = `${
|
|
579
|
+
const storageListFile = `${module2.moduleName}.storageList${extractExt(sourceFile)}`;
|
|
380
580
|
const storageListFilename = getInputFilenameAbsPath(parsedArgs, storageListFile);
|
|
381
|
-
const storageCompileResult = await (0, import_promises2.access)(storageListFilename).then(() => compileExprs(parsedArgs, storageListFile, "storage")).catch(() =>
|
|
581
|
+
const storageCompileResult = await (0, import_promises2.access)(storageListFilename).then(() => compileExprs(parsedArgs, storageListFile, module2, "storage")).catch(() => {
|
|
382
582
|
(0, import_node_sdk3.sendWarn)(
|
|
383
|
-
`Note: storage file associated with "${
|
|
583
|
+
`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
|
|
384
584
|
`
|
|
385
585
|
);
|
|
386
|
-
(0, import_promises2.writeFile)(storageListFilename, initContentForStorage(
|
|
586
|
+
return (0, import_promises2.writeFile)(storageListFilename, initContentForStorage(module2), "utf8");
|
|
387
587
|
});
|
|
388
|
-
const parameterListFile = `${
|
|
588
|
+
const parameterListFile = `${module2.moduleName}.parameterList${extractExt(sourceFile)}`;
|
|
389
589
|
const parameterListFilename = getInputFilenameAbsPath(parsedArgs, parameterListFile);
|
|
390
|
-
const parameterCompileResult = await (0, import_promises2.access)(parameterListFilename).then(() => compileExprs(parsedArgs, parameterListFile, "parameter")).catch(() =>
|
|
590
|
+
const parameterCompileResult = await (0, import_promises2.access)(parameterListFilename).then(() => compileExprs(parsedArgs, parameterListFile, module2, "parameter")).catch(() => {
|
|
391
591
|
(0, import_node_sdk3.sendWarn)(
|
|
392
|
-
`Note: parameter file associated with "${
|
|
592
|
+
`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
|
|
393
593
|
`
|
|
394
594
|
);
|
|
395
|
-
(0, import_promises2.writeFile)(parameterListFilename, initContentForParameter(
|
|
595
|
+
return (0, import_promises2.writeFile)(parameterListFilename, initContentForParameter(module2), "utf8");
|
|
396
596
|
});
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
);
|
|
410
|
-
return [{
|
|
411
|
-
contract: sourceFile,
|
|
412
|
-
artifact: artifactsOutput
|
|
413
|
-
}];
|
|
597
|
+
const storageArtifacts = storageCompileResult ? storageCompileResult.map((res) => res.artifact).join("\n") : "";
|
|
598
|
+
const parameterArtifacts = parameterCompileResult ? parameterCompileResult.map((res) => res.artifact).join("\n") : "";
|
|
599
|
+
const combinedArtifact = [
|
|
600
|
+
contractCompileResult.artifact,
|
|
601
|
+
storageArtifacts,
|
|
602
|
+
parameterArtifacts
|
|
603
|
+
].filter(Boolean).join("\n");
|
|
604
|
+
const combinedRow = {
|
|
605
|
+
source: module2.sourceName,
|
|
606
|
+
artifact: combinedArtifact
|
|
607
|
+
};
|
|
608
|
+
return [combinedRow];
|
|
414
609
|
};
|
|
415
|
-
var compile = (parsedArgs) => {
|
|
610
|
+
var compile = async (parsedArgs) => {
|
|
416
611
|
const sourceFile = parsedArgs.sourceFile;
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
612
|
+
if (!isLIGOFile(sourceFile)) {
|
|
613
|
+
(0, import_node_sdk3.sendErr)(`${sourceFile} is not a LIGO file`);
|
|
614
|
+
return;
|
|
615
|
+
}
|
|
616
|
+
if (isStorageListFile(sourceFile) || isParameterListFile(sourceFile)) {
|
|
617
|
+
(0, import_node_sdk3.sendErr)(`Storage and parameter list files are not meant to be compiled directly`);
|
|
618
|
+
return;
|
|
619
|
+
}
|
|
620
|
+
if (isUnsupportedLigoSyntax(sourceFile)) {
|
|
621
|
+
(0, import_node_sdk3.sendErr)(`Unsupported LIGO syntax detected in ${sourceFile}. Note, we only support .jsligo and .mligo files.`);
|
|
622
|
+
return;
|
|
623
|
+
}
|
|
624
|
+
try {
|
|
625
|
+
const modules = await listContractModules(parsedArgs, sourceFile);
|
|
626
|
+
if (modules.length === 0) {
|
|
627
|
+
return (0, import_node_sdk3.sendJsonRes)([
|
|
628
|
+
{
|
|
629
|
+
source: sourceFile,
|
|
630
|
+
artifact: `No contract modules found in "${sourceFile}"`
|
|
631
|
+
}
|
|
632
|
+
]);
|
|
633
|
+
}
|
|
634
|
+
let allCompileResults = [];
|
|
635
|
+
for (const module2 of modules) {
|
|
636
|
+
if (parsedArgs.module && parsedArgs.module !== module2.moduleName)
|
|
637
|
+
continue;
|
|
638
|
+
const compileResults = await compileContractWithStorageAndParameter(parsedArgs, sourceFile, module2);
|
|
639
|
+
allCompileResults = allCompileResults.concat(compileResults);
|
|
640
|
+
}
|
|
641
|
+
(0, import_node_sdk3.sendJsonRes)(allCompileResults, { footer: `
|
|
642
|
+
Compiled ${allCompileResults.length} contract(s) in "${sourceFile}"` });
|
|
643
|
+
} catch (err) {
|
|
644
|
+
(0, import_node_sdk3.sendErr)(`Error processing "${sourceFile}": ${err}`);
|
|
428
645
|
}
|
|
429
|
-
return p.then(import_node_sdk3.sendJsonRes).catch((err) => (0, import_node_sdk3.sendErr)(err, false));
|
|
430
646
|
};
|
|
431
647
|
var compile_default = compile;
|
|
432
648
|
|
|
433
649
|
// compile-all.ts
|
|
434
650
|
var import_node_sdk4 = require("@taqueria/node-sdk");
|
|
435
651
|
var import_fast_glob = __toESM(require("fast-glob"));
|
|
436
|
-
var import_promises3 = require("fs/promises");
|
|
437
652
|
var import_path3 = require("path");
|
|
438
|
-
var isMainContract = async (parsedArgs, contractFilename) => {
|
|
439
|
-
if (/storageList\.\w{0,2}ligo$/.test(contractFilename))
|
|
440
|
-
return false;
|
|
441
|
-
const fileContent = await (0, import_promises3.readFile)(getInputFilenameAbsPath(parsedArgs, contractFilename), "utf8");
|
|
442
|
-
const entryOrMainFunctionRegex = /@entry|((const|let|function)\s+main)/g;
|
|
443
|
-
return entryOrMainFunctionRegex.test(fileContent);
|
|
444
|
-
};
|
|
445
|
-
var parseIncludes = async (parsedArgs, contractFilename) => {
|
|
446
|
-
const fileContent = await (0, import_promises3.readFile)(getInputFilenameAbsPath(parsedArgs, contractFilename), "utf8");
|
|
447
|
-
const includeRegex = /#include\s+"([^"]+\.m?ligo)"/g;
|
|
448
|
-
let match;
|
|
449
|
-
const includes = [];
|
|
450
|
-
while ((match = includeRegex.exec(fileContent)) !== null) {
|
|
451
|
-
includes.push(match[1]);
|
|
452
|
-
}
|
|
453
|
-
return includes;
|
|
454
|
-
};
|
|
455
|
-
var buildDependencyGraph = async (parsedArgs, contractFilenames) => {
|
|
456
|
-
const graph = /* @__PURE__ */ new Map();
|
|
457
|
-
for (const filename of contractFilenames) {
|
|
458
|
-
const includes = await parseIncludes(parsedArgs, filename);
|
|
459
|
-
graph.set(filename, new Set(includes));
|
|
460
|
-
}
|
|
461
|
-
return graph;
|
|
462
|
-
};
|
|
463
|
-
var visit = (node, graph, visited, stack) => {
|
|
464
|
-
if (stack.has(node))
|
|
465
|
-
return [true, visited];
|
|
466
|
-
if (!visited.has(node)) {
|
|
467
|
-
const newVisited = new Set(visited).add(node);
|
|
468
|
-
const newStack = new Set(stack).add(node);
|
|
469
|
-
const [circular, updatedVisited] = Array.from(graph.get(node) || []).reduce(
|
|
470
|
-
([circularFound, vSet], dependency) => {
|
|
471
|
-
const [result, v] = visit(dependency, graph, vSet, newStack);
|
|
472
|
-
return [circularFound || result, v];
|
|
473
|
-
},
|
|
474
|
-
[false, newVisited]
|
|
475
|
-
);
|
|
476
|
-
if (!circular)
|
|
477
|
-
return [false, updatedVisited];
|
|
478
|
-
}
|
|
479
|
-
return [false, visited];
|
|
480
|
-
};
|
|
481
|
-
var detectCircularDependencies = (graph) => {
|
|
482
|
-
const { safeFiles, circularFiles, visited } = Array.from(graph.keys()).reduce(
|
|
483
|
-
(acc, filename) => {
|
|
484
|
-
const [isCircular, updatedVisited] = visit(
|
|
485
|
-
filename,
|
|
486
|
-
graph,
|
|
487
|
-
acc.visited,
|
|
488
|
-
/* @__PURE__ */ new Set()
|
|
489
|
-
);
|
|
490
|
-
if (isCircular) {
|
|
491
|
-
acc.circularFiles.push(filename);
|
|
492
|
-
} else {
|
|
493
|
-
acc.safeFiles.push(filename);
|
|
494
|
-
}
|
|
495
|
-
acc.visited = updatedVisited;
|
|
496
|
-
return acc;
|
|
497
|
-
},
|
|
498
|
-
{ safeFiles: [], circularFiles: [], visited: /* @__PURE__ */ new Set() }
|
|
499
|
-
);
|
|
500
|
-
return { safeFiles, circularFiles };
|
|
501
|
-
};
|
|
502
653
|
var compileAll = async (parsedArgs) => {
|
|
503
|
-
let
|
|
654
|
+
let compilePromises = [];
|
|
504
655
|
const contractFilenames = await (0, import_fast_glob.default)(
|
|
505
656
|
["**/*.ligo", "**/*.religo", "**/*.mligo", "**/*.jsligo"],
|
|
506
657
|
{
|
|
@@ -508,22 +659,15 @@ var compileAll = async (parsedArgs) => {
|
|
|
508
659
|
absolute: false
|
|
509
660
|
}
|
|
510
661
|
);
|
|
511
|
-
const
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
662
|
+
for (const filename of contractFilenames) {
|
|
663
|
+
if (isStorageListFile(filename) || isParameterListFile(filename))
|
|
664
|
+
continue;
|
|
665
|
+
const moduleNames = await listContractModules(parsedArgs, filename);
|
|
666
|
+
for (const moduleName of moduleNames) {
|
|
667
|
+
compilePromises.push(compileContractWithStorageAndParameter(parsedArgs, filename, moduleName));
|
|
516
668
|
}
|
|
517
669
|
}
|
|
518
|
-
return Promise.all(
|
|
519
|
-
if (circularFiles.length > 0) {
|
|
520
|
-
console.warn(
|
|
521
|
-
"Warning: Circular dependencies detected in the following files. They have been skipped:"
|
|
522
|
-
);
|
|
523
|
-
console.warn(circularFiles.join(", "));
|
|
524
|
-
}
|
|
525
|
-
return table;
|
|
526
|
-
}).then(import_node_sdk4.sendJsonRes).catch((err) => (0, import_node_sdk4.sendErr)(err, false));
|
|
670
|
+
return Promise.all(compilePromises).then((tables) => tables.flat()).then(import_node_sdk4.sendJsonRes).catch((err) => (0, import_node_sdk4.sendErr)(err, false));
|
|
527
671
|
};
|
|
528
672
|
var compile_all_default = compileAll;
|
|
529
673
|
|
|
@@ -551,7 +695,7 @@ var getArbitraryLigoCmd = (parsedArgs, uid, gid, userArgs) => {
|
|
|
551
695
|
const processedUserArgs = userArgs.split(" ").map((arg) => arg.startsWith("\\-") ? arg.substring(1) : arg).filter(
|
|
552
696
|
(arg) => arg
|
|
553
697
|
);
|
|
554
|
-
const args = baseArgs
|
|
698
|
+
const args = [...baseArgs, ...processedUserArgs, "--skip-analytics"];
|
|
555
699
|
const envVars = { "DOCKER_DEFAULT_PLATFORM": "linux/amd64" };
|
|
556
700
|
return [
|
|
557
701
|
[binary, ...args].join(" "),
|
|
@@ -668,6 +812,12 @@ import_node_sdk9.Plugin.create((i18n) => ({
|
|
|
668
812
|
flag: "json",
|
|
669
813
|
boolean: true,
|
|
670
814
|
description: "Emit JSON-encoded Michelson"
|
|
815
|
+
}),
|
|
816
|
+
import_node_sdk9.Option.create({
|
|
817
|
+
flag: "module",
|
|
818
|
+
shortFlag: "m",
|
|
819
|
+
type: "string",
|
|
820
|
+
description: "The LIGO module to be compiled"
|
|
671
821
|
})
|
|
672
822
|
],
|
|
673
823
|
handler: "proxy",
|
|
@@ -725,6 +875,7 @@ import_node_sdk9.Plugin.create((i18n) => ({
|
|
|
725
875
|
handler: createContract_default
|
|
726
876
|
})
|
|
727
877
|
],
|
|
728
|
-
proxy: main_default
|
|
878
|
+
proxy: main_default,
|
|
879
|
+
postInstall: `node ${__dirname}/postinstall.js`
|
|
729
880
|
}), process.argv);
|
|
730
881
|
//# sourceMappingURL=index.js.map
|