@taqueria/plugin-ligo 0.37.21 → 0.37.34

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 CHANGED
@@ -9,6 +9,7 @@ export interface LigoOpts extends ProxyTaskArgs.t {
9
9
  export interface CompileOpts extends ProxyTaskArgs.t {
10
10
  sourceFile: string;
11
11
  json: boolean;
12
+ module?: string;
12
13
  }
13
14
 
14
15
  export interface CompileAllOpts extends ProxyTaskArgs.t {
@@ -22,10 +23,10 @@ export interface TestOpts extends RequestArgs.t {
22
23
 
23
24
  export type IntersectionOpts = LigoOpts & CompileOpts & CompileAllOpts & TestOpts;
24
25
 
25
- type UnionOpts = LigoOpts | CompileOpts | CompileAllOpts | TestOpts;
26
+ export type UnionOpts = LigoOpts | CompileOpts | CompileAllOpts | TestOpts;
26
27
 
27
28
  // Should point to the latest stable version, so it needs to be updated as part of our release process.
28
- const LIGO_DEFAULT_IMAGE = 'ligolang/ligo:0.69.0';
29
+ const LIGO_DEFAULT_IMAGE = 'ligolang/ligo:0.71.0';
29
30
 
30
31
  const LIGO_IMAGE_ENV_VAR = 'TAQ_LIGO_IMAGE';
31
32
 
package/compile-all.ts CHANGED
@@ -1,103 +1,17 @@
1
1
  import { sendErr, sendJsonRes } from '@taqueria/node-sdk';
2
2
  import glob from 'fast-glob';
3
- import { readFile } from 'fs/promises';
4
3
  import { join } from 'path';
5
- import { CompileAllOpts as Opts, CompileOpts, getInputFilenameAbsPath } from './common';
6
- import { compileContractWithStorageAndParameter, TableRow } from './compile';
7
-
8
- const isMainContract = async (parsedArgs: Opts, contractFilename: string): Promise<boolean> => {
9
- if (/storageList\.\w{0,2}ligo$/.test(contractFilename)) return false;
10
- const fileContent = await readFile(getInputFilenameAbsPath(parsedArgs, contractFilename), 'utf8');
11
- const entryOrMainFunctionRegex = /@entry|((const|let|function)\s+main)/g;
12
- return entryOrMainFunctionRegex.test(fileContent);
13
- };
14
-
15
- // Helper function to parse includes from a LIGO file
16
- const parseIncludes = async (parsedArgs: Opts, contractFilename: string): Promise<string[]> => {
17
- const fileContent = await readFile(getInputFilenameAbsPath(parsedArgs, contractFilename), 'utf8');
18
- const includeRegex = /#include\s+"([^"]+\.m?ligo)"/g;
19
- let match;
20
- const includes: string[] = [];
21
-
22
- while ((match = includeRegex.exec(fileContent)) !== null) {
23
- includes.push(match[1]);
24
- }
25
-
26
- return includes;
27
- };
28
-
29
- // Helper function to build the dependency graph
30
- const buildDependencyGraph = async (
31
- parsedArgs: Opts,
32
- contractFilenames: string[],
33
- ): Promise<Map<string, Set<string>>> => {
34
- const graph = new Map<string, Set<string>>();
35
-
36
- for (const filename of contractFilenames) {
37
- const includes = await parseIncludes(parsedArgs, filename);
38
- graph.set(filename, new Set(includes));
39
- }
40
-
41
- return graph;
42
- };
43
-
44
- const visit = (
45
- node: string,
46
- graph: Map<string, Set<string>>,
47
- visited: Set<string>,
48
- stack: Set<string>,
49
- ): [boolean, Set<string>] => {
50
- if (stack.has(node)) return [true, visited]; // Circular dependency detected
51
-
52
- if (!visited.has(node)) {
53
- const newVisited = new Set(visited).add(node);
54
- const newStack = new Set(stack).add(node);
55
-
56
- const [circular, updatedVisited] = Array.from(graph.get(node) || []).reduce<[boolean, Set<string>]>(
57
- ([circularFound, vSet], dependency) => {
58
- const [result, v] = visit(dependency, graph, vSet, newStack);
59
- return [circularFound || result, v];
60
- },
61
- [false, newVisited],
62
- );
63
-
64
- if (!circular) return [false, updatedVisited];
65
- }
66
-
67
- return [false, visited];
68
- };
69
-
70
- const detectCircularDependencies = (
71
- graph: Map<string, Set<string>>,
72
- ): { safeFiles: string[]; circularFiles: string[] } => {
73
- const { safeFiles, circularFiles, visited } = Array.from(graph.keys()).reduce<{
74
- safeFiles: string[];
75
- circularFiles: string[];
76
- visited: Set<string>;
77
- }>(
78
- (acc, filename) => {
79
- const [isCircular, updatedVisited] = visit(
80
- filename,
81
- graph,
82
- acc.visited,
83
- new Set<string>(),
84
- );
85
- if (isCircular) {
86
- acc.circularFiles.push(filename);
87
- } else {
88
- acc.safeFiles.push(filename);
89
- }
90
- acc.visited = updatedVisited;
91
- return acc;
92
- },
93
- { safeFiles: [], circularFiles: [], visited: new Set<string>() },
94
- );
95
-
96
- return { safeFiles, circularFiles };
97
- };
4
+ import { CompileAllOpts, CompileAllOpts as Opts, CompileOpts } from './common';
5
+ import {
6
+ compileContractWithStorageAndParameter,
7
+ isParameterListFile,
8
+ isStorageListFile,
9
+ listContractModules,
10
+ TableRow,
11
+ } from './compile';
98
12
 
99
13
  const compileAll = async (parsedArgs: Opts): Promise<void> => {
100
- let p: Promise<TableRow[]>[] = [];
14
+ let compilePromises: Promise<TableRow[]>[] = [];
101
15
 
102
16
  const contractFilenames = await glob(
103
17
  ['**/*.ligo', '**/*.religo', '**/*.mligo', '**/*.jsligo'],
@@ -107,26 +21,16 @@ const compileAll = async (parsedArgs: Opts): Promise<void> => {
107
21
  },
108
22
  );
109
23
 
110
- const dependencyGraph = await buildDependencyGraph(parsedArgs, contractFilenames);
111
- const { safeFiles, circularFiles } = detectCircularDependencies(dependencyGraph);
112
-
113
- for (const filename of safeFiles) {
114
- if (await isMainContract(parsedArgs, filename)) {
115
- p.push(compileContractWithStorageAndParameter(parsedArgs as CompileOpts, filename));
24
+ for (const filename of contractFilenames) {
25
+ if (isStorageListFile(filename) || isParameterListFile(filename)) continue;
26
+ const moduleNames = await listContractModules(parsedArgs as unknown as CompileAllOpts, filename);
27
+ for (const moduleName of moduleNames) {
28
+ compilePromises.push(compileContractWithStorageAndParameter(parsedArgs as CompileOpts, filename, moduleName));
116
29
  }
117
30
  }
118
31
 
119
- return Promise.all(p)
32
+ return Promise.all(compilePromises)
120
33
  .then(tables => tables.flat())
121
- .then(table => {
122
- if (circularFiles.length > 0) {
123
- console.warn(
124
- 'Warning: Circular dependencies detected in the following files. They have been skipped:',
125
- );
126
- console.warn(circularFiles.join(', '));
127
- }
128
- return table;
129
- })
130
34
  .then(sendJsonRes)
131
35
  .catch(err => sendErr(err, false));
132
36
  };