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