@taqueria/lib-ligo 0.44.0 → 0.44.2
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 +67 -10
- package/compile.ts +222 -102
- package/index.d.ts +1 -0
- package/index.js +191 -102
- package/index.js.map +1 -1
- package/index.mjs +195 -106
- package/index.mjs.map +1 -1
- package/index.ts +2 -1
- package/ligo.ts +21 -37
- package/main.ts +20 -18
- package/package.json +2 -2
- package/test.ts +10 -7
package/common.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { getDockerImage, sendErr } from '@taqueria/node-sdk';
|
|
2
2
|
import { ProxyTaskArgs, RequestArgs } from '@taqueria/node-sdk/types';
|
|
3
|
-
import
|
|
3
|
+
import * as fs from 'fs';
|
|
4
|
+
import { delimiter, join } from 'path';
|
|
4
5
|
|
|
5
6
|
export interface LigoOpts extends ProxyTaskArgs.t {
|
|
6
7
|
command: string;
|
|
@@ -21,20 +22,35 @@ export interface TestOpts extends RequestArgs.t {
|
|
|
21
22
|
sourceFile?: string;
|
|
22
23
|
}
|
|
23
24
|
|
|
24
|
-
export type IntersectionOpts =
|
|
25
|
+
export type IntersectionOpts =
|
|
26
|
+
& LigoOpts
|
|
27
|
+
& CompileOpts
|
|
28
|
+
& CompileAllOpts
|
|
29
|
+
& TestOpts;
|
|
25
30
|
|
|
26
31
|
export type UnionOpts = LigoOpts | CompileOpts | CompileAllOpts | TestOpts;
|
|
27
32
|
|
|
28
|
-
export const getInputFilenameAbsPath = (
|
|
29
|
-
|
|
33
|
+
export const getInputFilenameAbsPath = (
|
|
34
|
+
parsedArgs: UnionOpts,
|
|
35
|
+
sourceFile: string,
|
|
36
|
+
): string =>
|
|
37
|
+
join(
|
|
38
|
+
parsedArgs.config.projectDir,
|
|
39
|
+
parsedArgs.config.contractsDir ?? 'contracts',
|
|
40
|
+
sourceFile,
|
|
41
|
+
);
|
|
30
42
|
|
|
31
|
-
export const getInputFilenameRelPath = (
|
|
32
|
-
|
|
43
|
+
export const getInputFilenameRelPath = (
|
|
44
|
+
parsedArgs: UnionOpts,
|
|
45
|
+
sourceFile: string,
|
|
46
|
+
): string => join(parsedArgs.config.contractsDir ?? 'contracts', sourceFile);
|
|
33
47
|
|
|
34
48
|
export const formatLigoError = (err: Error): Error => {
|
|
35
49
|
let result = err.message.replace(/Command failed.+?\n/, '');
|
|
36
50
|
if (
|
|
37
|
-
result.includes(
|
|
51
|
+
result.includes(
|
|
52
|
+
'An internal error ocurred. Please, contact the developers.',
|
|
53
|
+
)
|
|
38
54
|
&& result.includes('Module Contract not found with last Contract.')
|
|
39
55
|
) {
|
|
40
56
|
result =
|
|
@@ -53,7 +69,8 @@ export const formatLigoError = (err: Error): Error => {
|
|
|
53
69
|
.replace(
|
|
54
70
|
'An internal error ocurred. Please, contact the developers.',
|
|
55
71
|
'The LIGO compiler experienced an internal error. Please contact the LIGO developers.',
|
|
56
|
-
)
|
|
72
|
+
)
|
|
73
|
+
.replace(
|
|
57
74
|
/Module ("Contract\.[^"]+") not found/,
|
|
58
75
|
'The module $1 was not found. If your contract is defined within a namespace, please ensure that it has been exported.',
|
|
59
76
|
);
|
|
@@ -61,7 +78,10 @@ export const formatLigoError = (err: Error): Error => {
|
|
|
61
78
|
return err;
|
|
62
79
|
};
|
|
63
80
|
|
|
64
|
-
export const emitExternalError = (
|
|
81
|
+
export const emitExternalError = (
|
|
82
|
+
errs: unknown[] | unknown,
|
|
83
|
+
sourceFile: string,
|
|
84
|
+
): void => {
|
|
65
85
|
sendErr(`\n=== Error messages for ${sourceFile} ===`);
|
|
66
86
|
const errors = Array.isArray(errs) ? errs : [errs];
|
|
67
87
|
errors.map(err => {
|
|
@@ -70,10 +90,47 @@ export const emitExternalError = (errs: unknown[] | unknown, sourceFile: string)
|
|
|
70
90
|
sendErr(`===`);
|
|
71
91
|
};
|
|
72
92
|
|
|
73
|
-
export const configure = (dockerImage: string, dockerImageEnvVar: string) => ({
|
|
93
|
+
export const configure = (dockerImage: string, dockerImageEnvVar: string, canUseLIGOBinary: boolean) => ({
|
|
74
94
|
LIGO_DEFAULT_IMAGE: dockerImage,
|
|
75
95
|
LIGO_IMAGE_ENV_VAR: dockerImageEnvVar,
|
|
76
96
|
getLigoDockerImage: () => getDockerImage(dockerImage, dockerImageEnvVar),
|
|
97
|
+
baseDriverCmd: (projectDir: string) => baseDriverCmd(projectDir, dockerImage, canUseLIGOBinary),
|
|
77
98
|
});
|
|
78
99
|
|
|
79
100
|
export type Common = ReturnType<typeof configure>;
|
|
101
|
+
function exists(path: string): boolean {
|
|
102
|
+
try {
|
|
103
|
+
fs.accessSync(path, fs.constants.X_OK);
|
|
104
|
+
return true;
|
|
105
|
+
} catch {
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function getLigoBinaryFromPath() {
|
|
111
|
+
const { PATH } = process.env;
|
|
112
|
+
if (!PATH) {
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
const paths = PATH.split(delimiter);
|
|
116
|
+
for (const candidatePath of paths) {
|
|
117
|
+
const possibleLigoPath = join(candidatePath, 'ligo');
|
|
118
|
+
if (exists(possibleLigoPath)) {
|
|
119
|
+
return possibleLigoPath;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function baseDriverCmd(
|
|
126
|
+
projectDir: string,
|
|
127
|
+
ligoDockerImage: string,
|
|
128
|
+
canUseLIGOBinary: boolean,
|
|
129
|
+
): string {
|
|
130
|
+
const ligoBinaryFromPath = canUseLIGOBinary ? getLigoBinaryFromPath() : null;
|
|
131
|
+
if (ligoBinaryFromPath !== null) {
|
|
132
|
+
return ligoBinaryFromPath;
|
|
133
|
+
} else {
|
|
134
|
+
return `DOCKER_DEFAULT_PLATFORM=linux/amd64 docker run --rm -v \"${projectDir}\":/project -w /project -u $(id -u):$(id -g) ${ligoDockerImage}`;
|
|
135
|
+
}
|
|
136
|
+
}
|
package/compile.ts
CHANGED
|
@@ -15,7 +15,6 @@ import * as readline from 'readline';
|
|
|
15
15
|
import {
|
|
16
16
|
Common,
|
|
17
17
|
CompileOpts as Opts,
|
|
18
|
-
configure,
|
|
19
18
|
emitExternalError,
|
|
20
19
|
formatLigoError,
|
|
21
20
|
getInputFilenameAbsPath,
|
|
@@ -52,7 +51,9 @@ export const isStorageListFile = (sourceFile: string): boolean =>
|
|
|
52
51
|
/.+\.(storageList|storages)\.(ligo|religo|mligo|jsligo)$/.test(sourceFile);
|
|
53
52
|
|
|
54
53
|
export const isParameterListFile = (sourceFile: string): boolean =>
|
|
55
|
-
/.+\.(parameterList|parameters)\.(ligo|religo|mligo|jsligo)$/.test(
|
|
54
|
+
/.+\.(parameterList|parameters)\.(ligo|religo|mligo|jsligo)$/.test(
|
|
55
|
+
sourceFile,
|
|
56
|
+
);
|
|
56
57
|
|
|
57
58
|
const extractExt = (path: string): string => {
|
|
58
59
|
const matchResult = path.match(/\.(ligo|religo|mligo|jsligo)$/);
|
|
@@ -66,12 +67,20 @@ const removeExt = (path: string): string => {
|
|
|
66
67
|
|
|
67
68
|
const isOutputFormatJSON = (parsedArgs: Opts): boolean => parsedArgs.json;
|
|
68
69
|
|
|
69
|
-
const getOutputContractFilename = (
|
|
70
|
+
const getOutputContractFilename = (
|
|
71
|
+
parsedArgs: Opts,
|
|
72
|
+
module: ModuleInfo,
|
|
73
|
+
): string => {
|
|
70
74
|
const ext = isOutputFormatJSON(parsedArgs) ? '.json' : '.tz';
|
|
71
75
|
return join(getArtifactsDir(parsedArgs), `${module.moduleName}${ext}`);
|
|
72
76
|
};
|
|
73
77
|
|
|
74
|
-
const getOutputExprFilename = (
|
|
78
|
+
const getOutputExprFilename = (
|
|
79
|
+
parsedArgs: Opts,
|
|
80
|
+
module: ModuleInfo,
|
|
81
|
+
exprKind: ExprKind,
|
|
82
|
+
exprName: string,
|
|
83
|
+
): string => {
|
|
75
84
|
const contractName = module.moduleName;
|
|
76
85
|
const ext = isOutputFormatJSON(parsedArgs) ? '.json' : '.tz';
|
|
77
86
|
const outputFile = exprKind === 'default_storage'
|
|
@@ -80,7 +89,10 @@ const getOutputExprFilename = (parsedArgs: Opts, module: ModuleInfo, exprKind: E
|
|
|
80
89
|
return join(getArtifactsDir(parsedArgs), `${outputFile}`);
|
|
81
90
|
};
|
|
82
91
|
|
|
83
|
-
const getExprNames = (
|
|
92
|
+
const getExprNames = (
|
|
93
|
+
parsedArgs: Opts,
|
|
94
|
+
sourceFile: string,
|
|
95
|
+
): Promise<string[]> => {
|
|
84
96
|
return new Promise((resolve, reject) => {
|
|
85
97
|
const inputFilePath = getInputFilenameAbsPath(parsedArgs, sourceFile);
|
|
86
98
|
const readInterface = readline.createInterface({
|
|
@@ -165,18 +177,23 @@ const initContentForParameter = (moduleInfo: ModuleInfo) => getContent(moduleInf
|
|
|
165
177
|
export const inject = (commonObj: Common) => {
|
|
166
178
|
const { getLigoDockerImage } = commonObj;
|
|
167
179
|
|
|
168
|
-
const getListDeclarationsCmd = async (
|
|
180
|
+
const getListDeclarationsCmd = async (
|
|
181
|
+
parsedArgs: UnionOpts,
|
|
182
|
+
sourceFile: string,
|
|
183
|
+
): Promise<string> => {
|
|
169
184
|
const projectDir = process.env.PROJECT_DIR ?? parsedArgs.projectDir;
|
|
170
185
|
if (!projectDir) throw new Error(`No project directory provided`);
|
|
171
|
-
const baseCmd =
|
|
172
|
-
`DOCKER_DEFAULT_PLATFORM=linux/amd64 docker run --rm -v \"${projectDir}\":/project -w /project -u $(id -u):$(id -g) ${getLigoDockerImage()} info list-declarations`;
|
|
186
|
+
const baseCmd = `${commonObj.baseDriverCmd(projectDir)} info list-declarations`;
|
|
173
187
|
const inputFile = getInputFilenameRelPath(parsedArgs, sourceFile);
|
|
174
188
|
const flags = '--display-format json';
|
|
175
189
|
const cmd = `${baseCmd} ${inputFile} ${flags}`;
|
|
176
190
|
return cmd;
|
|
177
191
|
};
|
|
178
192
|
|
|
179
|
-
const listContractModules = async (
|
|
193
|
+
const listContractModules = async (
|
|
194
|
+
parsedArgs: UnionOpts,
|
|
195
|
+
sourceFile: string,
|
|
196
|
+
): Promise<ModuleInfo[]> => {
|
|
180
197
|
try {
|
|
181
198
|
await getArch();
|
|
182
199
|
const cmd = await getListDeclarationsCmd(parsedArgs, sourceFile);
|
|
@@ -195,27 +212,51 @@ export const inject = (commonObj: Common) => {
|
|
|
195
212
|
const syntax = extractExt(sourceFile).replace('.', '');
|
|
196
213
|
|
|
197
214
|
if (decl === 'main') {
|
|
198
|
-
return [
|
|
215
|
+
return [
|
|
216
|
+
...acc,
|
|
217
|
+
{
|
|
218
|
+
moduleName: srcFile,
|
|
219
|
+
sourceName: sourceFile,
|
|
220
|
+
sourceFile,
|
|
221
|
+
type: 'file-main',
|
|
222
|
+
syntax,
|
|
223
|
+
},
|
|
224
|
+
];
|
|
199
225
|
} else if (decl === '$main') {
|
|
200
|
-
return [
|
|
226
|
+
return [
|
|
227
|
+
...acc,
|
|
228
|
+
{
|
|
229
|
+
moduleName: srcFile,
|
|
230
|
+
sourceName: sourceFile,
|
|
231
|
+
sourceFile,
|
|
232
|
+
type: 'file-entry',
|
|
233
|
+
syntax,
|
|
234
|
+
},
|
|
235
|
+
];
|
|
201
236
|
} else if (decl.endsWith('.main')) {
|
|
202
237
|
const moduleName = decl.replace(/\.main$/, '');
|
|
203
|
-
return [
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
238
|
+
return [
|
|
239
|
+
...acc,
|
|
240
|
+
{
|
|
241
|
+
moduleName,
|
|
242
|
+
sourceName: `${sourceFile}/${moduleName}`,
|
|
243
|
+
sourceFile,
|
|
244
|
+
type: 'module-main',
|
|
245
|
+
syntax,
|
|
246
|
+
},
|
|
247
|
+
];
|
|
210
248
|
} else if (decl.endsWith('.$main')) {
|
|
211
249
|
const moduleName = decl.replace(/\.\$main$/, '');
|
|
212
|
-
return [
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
250
|
+
return [
|
|
251
|
+
...acc,
|
|
252
|
+
{
|
|
253
|
+
moduleName,
|
|
254
|
+
sourceName: `${sourceFile}/${moduleName}`,
|
|
255
|
+
sourceFile,
|
|
256
|
+
type: 'module-entry',
|
|
257
|
+
syntax,
|
|
258
|
+
},
|
|
259
|
+
];
|
|
219
260
|
}
|
|
220
261
|
return acc;
|
|
221
262
|
},
|
|
@@ -228,20 +269,31 @@ export const inject = (commonObj: Common) => {
|
|
|
228
269
|
}
|
|
229
270
|
};
|
|
230
271
|
|
|
231
|
-
const getCompileContractCmd = async (
|
|
272
|
+
const getCompileContractCmd = async (
|
|
273
|
+
parsedArgs: Opts,
|
|
274
|
+
sourceFile: string,
|
|
275
|
+
module: ModuleInfo,
|
|
276
|
+
): Promise<string> => {
|
|
232
277
|
const projectDir = process.env.PROJECT_DIR ?? parsedArgs.projectDir;
|
|
233
278
|
if (!projectDir) throw new Error(`No project directory provided`);
|
|
234
|
-
const baseCmd =
|
|
235
|
-
`DOCKER_DEFAULT_PLATFORM=linux/amd64 docker run --rm -v \"${projectDir}\":/project -w /project -u $(id -u):$(id -g) ${getLigoDockerImage()} compile contract`;
|
|
279
|
+
const baseCmd = `${commonObj.baseDriverCmd(projectDir)} compile contract`;
|
|
236
280
|
const inputFile = getInputFilenameRelPath(parsedArgs, sourceFile);
|
|
237
281
|
const outputFile = `-o ${getOutputContractFilename(parsedArgs, module)}`;
|
|
238
|
-
const flags = isOutputFormatJSON(parsedArgs)
|
|
239
|
-
|
|
282
|
+
const flags = isOutputFormatJSON(parsedArgs)
|
|
283
|
+
? ' --michelson-format json '
|
|
284
|
+
: '';
|
|
285
|
+
const moduleFlag = module.type.startsWith('file-')
|
|
286
|
+
? ''
|
|
287
|
+
: `-m ${module.moduleName}`;
|
|
240
288
|
const cmd = `${baseCmd} ${inputFile} ${outputFile} ${flags}${moduleFlag}`;
|
|
241
289
|
return cmd;
|
|
242
290
|
};
|
|
243
291
|
|
|
244
|
-
const compileContract = async (
|
|
292
|
+
const compileContract = async (
|
|
293
|
+
parsedArgs: Opts,
|
|
294
|
+
sourceFile: string,
|
|
295
|
+
module: ModuleInfo,
|
|
296
|
+
): Promise<TableRow> => {
|
|
245
297
|
try {
|
|
246
298
|
await getArch();
|
|
247
299
|
const cmd = await getCompileContractCmd(parsedArgs, sourceFile, module);
|
|
@@ -271,11 +323,19 @@ export const inject = (commonObj: Common) => {
|
|
|
271
323
|
const projectDir = process.env.PROJECT_DIR ?? parsedArgs.projectDir;
|
|
272
324
|
if (!projectDir) throw new Error(`No project directory provided`);
|
|
273
325
|
const compilerType = isStorageKind(exprKind) ? 'storage' : 'parameter';
|
|
274
|
-
const baseCmd =
|
|
275
|
-
`DOCKER_DEFAULT_PLATFORM=linux/amd64 docker run --rm -v \"${projectDir}\":/project -w /project -u $(id -u):$(id -g) ${getLigoDockerImage()} compile ${compilerType}`;
|
|
326
|
+
const baseCmd = `${commonObj.baseDriverCmd(projectDir)} compile ${compilerType}`;
|
|
276
327
|
const inputFile = getInputFilenameRelPath(parsedArgs, sourceFile);
|
|
277
|
-
const outputFile = `-o ${
|
|
278
|
-
|
|
328
|
+
const outputFile = `-o ${
|
|
329
|
+
getOutputExprFilename(
|
|
330
|
+
parsedArgs,
|
|
331
|
+
module,
|
|
332
|
+
exprKind,
|
|
333
|
+
exprName,
|
|
334
|
+
)
|
|
335
|
+
}`;
|
|
336
|
+
const flags = isOutputFormatJSON(parsedArgs)
|
|
337
|
+
? ' --michelson-format json '
|
|
338
|
+
: '';
|
|
279
339
|
|
|
280
340
|
// Parameter and Storage list files are expected to import the smart contract file as the "Contract" module.
|
|
281
341
|
const moduleFlag = (() => {
|
|
@@ -292,28 +352,37 @@ export const inject = (commonObj: Common) => {
|
|
|
292
352
|
return cmd;
|
|
293
353
|
};
|
|
294
354
|
|
|
295
|
-
const compileExpr =
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
355
|
+
const compileExpr = (
|
|
356
|
+
parsedArgs: Opts,
|
|
357
|
+
sourceFile: string,
|
|
358
|
+
module: ModuleInfo,
|
|
359
|
+
exprKind: ExprKind,
|
|
360
|
+
) =>
|
|
361
|
+
(exprName: string): Promise<TableRow> => {
|
|
362
|
+
return getArch()
|
|
363
|
+
.then(() => getCompileExprCmd(parsedArgs, sourceFile, module, exprKind, exprName))
|
|
364
|
+
.then(execCmd)
|
|
365
|
+
.then(({ stderr }) => {
|
|
366
|
+
if (stderr.length > 0) sendWarn(stderr);
|
|
367
|
+
const artifactName = getOutputExprFilename(
|
|
368
|
+
parsedArgs,
|
|
369
|
+
module,
|
|
370
|
+
exprKind,
|
|
371
|
+
exprName,
|
|
372
|
+
);
|
|
373
|
+
return {
|
|
374
|
+
source: module.sourceName,
|
|
375
|
+
artifact: artifactName,
|
|
376
|
+
};
|
|
377
|
+
})
|
|
378
|
+
.catch(err => {
|
|
379
|
+
return {
|
|
380
|
+
source: module.sourceName,
|
|
381
|
+
artifact: `${exprName} in ${sourceFile} not compiled`,
|
|
382
|
+
err,
|
|
383
|
+
};
|
|
384
|
+
});
|
|
385
|
+
};
|
|
317
386
|
|
|
318
387
|
const compileExprs = async (
|
|
319
388
|
parsedArgs: Opts,
|
|
@@ -327,45 +396,51 @@ export const inject = (commonObj: Common) => {
|
|
|
327
396
|
exprs = await getExprNames(parsedArgs, sourceFile);
|
|
328
397
|
} catch (err) {
|
|
329
398
|
emitExternalError(err, sourceFile);
|
|
330
|
-
return [
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
399
|
+
return [
|
|
400
|
+
{
|
|
401
|
+
source: module.sourceName,
|
|
402
|
+
artifact: `No ${isStorageKind(exprKind) ? 'storage' : 'parameter'} expressions compiled`,
|
|
403
|
+
},
|
|
404
|
+
];
|
|
334
405
|
}
|
|
335
406
|
|
|
336
|
-
const results = await Promise.all(
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
407
|
+
const results = await Promise.all(
|
|
408
|
+
exprs.map(async (exprName, index) => {
|
|
409
|
+
const compileResult = await compileExpr(
|
|
410
|
+
parsedArgs,
|
|
411
|
+
sourceFile,
|
|
412
|
+
module,
|
|
413
|
+
exprKind === 'storage' && index === 0 ? 'default_storage' : exprKind,
|
|
414
|
+
)(exprName);
|
|
415
|
+
return compileResult;
|
|
416
|
+
}),
|
|
417
|
+
);
|
|
345
418
|
|
|
346
419
|
// Collect errors
|
|
347
|
-
const errors = results.reduce(
|
|
348
|
-
(
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
if (!(result.err instanceof Error)) return [...acc, result.err];
|
|
420
|
+
const errors = results.reduce((acc, result) => {
|
|
421
|
+
if (result.err) {
|
|
422
|
+
// If its not an Error object, then just add it to the list
|
|
423
|
+
if (!(result.err instanceof Error)) return [...acc, result.err];
|
|
352
424
|
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
425
|
+
// Otherwise, get all ligo errors and ensure that the list is unique
|
|
426
|
+
const ligoErrs = (
|
|
427
|
+
acc.filter(err => err instanceof Error) as Error[]
|
|
428
|
+
).map(err => err.message);
|
|
357
429
|
|
|
358
|
-
|
|
430
|
+
const formattedError = formatLigoError(result.err);
|
|
359
431
|
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
);
|
|
432
|
+
return ligoErrs.includes(formattedError.message)
|
|
433
|
+
? acc
|
|
434
|
+
: [...acc, formattedError];
|
|
435
|
+
}
|
|
436
|
+
return acc;
|
|
437
|
+
}, [] as unknown[]);
|
|
366
438
|
|
|
367
439
|
// Collect table rows
|
|
368
|
-
const retval = results.map(({ source, artifact }) => ({
|
|
440
|
+
const retval = results.map(({ source, artifact }) => ({
|
|
441
|
+
source,
|
|
442
|
+
artifact,
|
|
443
|
+
}));
|
|
369
444
|
|
|
370
445
|
if (errors.length) emitExternalError(errors, sourceFile);
|
|
371
446
|
|
|
@@ -377,39 +452,71 @@ export const inject = (commonObj: Common) => {
|
|
|
377
452
|
sourceFile: string,
|
|
378
453
|
module: ModuleInfo,
|
|
379
454
|
): Promise<TableRow[]> => {
|
|
380
|
-
const contractCompileResult = await compileContract(
|
|
455
|
+
const contractCompileResult = await compileContract(
|
|
456
|
+
parsedArgs,
|
|
457
|
+
sourceFile,
|
|
458
|
+
module,
|
|
459
|
+
);
|
|
381
460
|
if (contractCompileResult.artifact === COMPILE_ERR_MSG) return [contractCompileResult];
|
|
382
461
|
|
|
383
|
-
const storageListFile = `${module.moduleName}.storageList${
|
|
384
|
-
|
|
462
|
+
const storageListFile = `${module.moduleName}.storageList${
|
|
463
|
+
extractExt(
|
|
464
|
+
sourceFile,
|
|
465
|
+
)
|
|
466
|
+
}`;
|
|
467
|
+
const storageListFilename = getInputFilenameAbsPath(
|
|
468
|
+
parsedArgs,
|
|
469
|
+
storageListFile,
|
|
470
|
+
);
|
|
385
471
|
const storageCompileResult = await access(storageListFilename)
|
|
386
472
|
.then(() => compileExprs(parsedArgs, storageListFile, module, 'storage'))
|
|
387
473
|
.catch(() => {
|
|
388
474
|
sendWarn(
|
|
389
475
|
`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\n`,
|
|
390
476
|
);
|
|
391
|
-
return writeFile(
|
|
477
|
+
return writeFile(
|
|
478
|
+
storageListFilename,
|
|
479
|
+
initContentForStorage(module),
|
|
480
|
+
'utf8',
|
|
481
|
+
);
|
|
392
482
|
});
|
|
393
483
|
|
|
394
|
-
const parameterListFile = `${module.moduleName}.parameterList${
|
|
395
|
-
|
|
484
|
+
const parameterListFile = `${module.moduleName}.parameterList${
|
|
485
|
+
extractExt(
|
|
486
|
+
sourceFile,
|
|
487
|
+
)
|
|
488
|
+
}`;
|
|
489
|
+
const parameterListFilename = getInputFilenameAbsPath(
|
|
490
|
+
parsedArgs,
|
|
491
|
+
parameterListFile,
|
|
492
|
+
);
|
|
396
493
|
const parameterCompileResult = await access(parameterListFilename)
|
|
397
494
|
.then(() => compileExprs(parsedArgs, parameterListFile, module, 'parameter'))
|
|
398
495
|
.catch(() => {
|
|
399
496
|
sendWarn(
|
|
400
497
|
`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\n`,
|
|
401
498
|
);
|
|
402
|
-
return writeFile(
|
|
499
|
+
return writeFile(
|
|
500
|
+
parameterListFilename,
|
|
501
|
+
initContentForParameter(module),
|
|
502
|
+
'utf8',
|
|
503
|
+
);
|
|
403
504
|
});
|
|
404
505
|
|
|
405
|
-
const storageArtifacts = storageCompileResult
|
|
406
|
-
|
|
506
|
+
const storageArtifacts = storageCompileResult
|
|
507
|
+
? storageCompileResult.map(res => res.artifact).join('\n')
|
|
508
|
+
: '';
|
|
509
|
+
const parameterArtifacts = parameterCompileResult
|
|
510
|
+
? parameterCompileResult.map(res => res.artifact).join('\n')
|
|
511
|
+
: '';
|
|
407
512
|
|
|
408
513
|
const combinedArtifact = [
|
|
409
514
|
contractCompileResult.artifact,
|
|
410
515
|
storageArtifacts,
|
|
411
516
|
parameterArtifacts,
|
|
412
|
-
]
|
|
517
|
+
]
|
|
518
|
+
.filter(Boolean)
|
|
519
|
+
.join('\n');
|
|
413
520
|
|
|
414
521
|
const combinedRow: TableRow = {
|
|
415
522
|
source: module.sourceName,
|
|
@@ -432,7 +539,10 @@ export const inject = (commonObj: Common) => {
|
|
|
432
539
|
};
|
|
433
540
|
};
|
|
434
541
|
|
|
435
|
-
export const compile = async (
|
|
542
|
+
export const compile = async (
|
|
543
|
+
commonObj: Common,
|
|
544
|
+
parsedArgs: Opts,
|
|
545
|
+
): Promise<void> => {
|
|
436
546
|
const { listContractModules, compileContractWithStorageAndParameter } = inject(commonObj);
|
|
437
547
|
|
|
438
548
|
const sourceFile = parsedArgs.sourceFile;
|
|
@@ -441,11 +551,15 @@ export const compile = async (commonObj: Common, parsedArgs: Opts): Promise<void
|
|
|
441
551
|
return;
|
|
442
552
|
}
|
|
443
553
|
if (isStorageListFile(sourceFile) || isParameterListFile(sourceFile)) {
|
|
444
|
-
sendErr(
|
|
554
|
+
sendErr(
|
|
555
|
+
`Storage and parameter list files are not meant to be compiled directly`,
|
|
556
|
+
);
|
|
445
557
|
return;
|
|
446
558
|
}
|
|
447
559
|
if (isUnsupportedLigoSyntax(sourceFile)) {
|
|
448
|
-
sendErr(
|
|
560
|
+
sendErr(
|
|
561
|
+
`Unsupported LIGO syntax detected in ${sourceFile}. Note, we only support .jsligo and .mligo files.`,
|
|
562
|
+
);
|
|
449
563
|
return;
|
|
450
564
|
}
|
|
451
565
|
|
|
@@ -466,11 +580,17 @@ export const compile = async (commonObj: Common, parsedArgs: Opts): Promise<void
|
|
|
466
580
|
// If we're only to compile a particular module, then we'll skip any that don't match
|
|
467
581
|
if (parsedArgs.module && parsedArgs.module !== module.moduleName) continue;
|
|
468
582
|
|
|
469
|
-
const compileResults = await compileContractWithStorageAndParameter(
|
|
583
|
+
const compileResults = await compileContractWithStorageAndParameter(
|
|
584
|
+
parsedArgs,
|
|
585
|
+
sourceFile,
|
|
586
|
+
module,
|
|
587
|
+
);
|
|
470
588
|
allCompileResults = allCompileResults.concat(compileResults);
|
|
471
589
|
}
|
|
472
590
|
|
|
473
|
-
sendJsonRes(allCompileResults, {
|
|
591
|
+
sendJsonRes(allCompileResults, {
|
|
592
|
+
footer: `\nCompiled ${allCompileResults.length} contract(s) in "${sourceFile}"`,
|
|
593
|
+
});
|
|
474
594
|
} catch (err) {
|
|
475
595
|
sendErr(`Error processing "${sourceFile}": ${err}`);
|
|
476
596
|
}
|
package/index.d.ts
CHANGED