ic-mops 0.34.4 → 0.36.0
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/cli.ts +11 -45
- package/commands/add.ts +7 -5
- package/commands/bench-replica.ts +99 -0
- package/commands/bench.ts +57 -90
- package/commands/install-all.ts +4 -4
- package/commands/remove.ts +4 -4
- package/commands/sync.ts +5 -5
- package/commands/update.ts +3 -3
- package/declarations/main/main.did +67 -78
- package/declarations/main/main.did.d.ts +72 -83
- package/declarations/main/main.did.js +12 -23
- package/dist/bin/mops.d.ts +2 -0
- package/dist/bin/mops.js +2 -0
- package/dist/cli.js +11 -44
- package/dist/commands/add.d.ts +2 -2
- package/dist/commands/add.js +6 -3
- package/dist/commands/bench-replica.d.ts +32 -0
- package/dist/commands/bench-replica.js +87 -0
- package/dist/commands/bench.d.ts +9 -8
- package/dist/commands/bench.js +44 -76
- package/dist/commands/install-all.d.ts +2 -2
- package/dist/commands/install-all.js +3 -3
- package/dist/commands/remove.d.ts +2 -2
- package/dist/commands/remove.js +3 -2
- package/dist/commands/sync.d.ts +2 -2
- package/dist/commands/sync.js +4 -4
- package/dist/commands/toolchain/moc.d.ts +4 -0
- package/dist/commands/toolchain/moc.js +36 -0
- package/dist/commands/toolchain/mocv.d.ts +1 -0
- package/dist/commands/toolchain/mocv.js +272 -0
- package/dist/commands/toolchain/toolchain-utils.d.ts +3 -0
- package/dist/commands/toolchain/toolchain-utils.js +56 -0
- package/dist/commands/toolchain/wasmtime.d.ts +4 -0
- package/dist/commands/toolchain/wasmtime.js +23 -0
- package/dist/commands/update.d.ts +2 -2
- package/dist/commands/update.js +2 -2
- package/dist/declarations/main/main.did +67 -78
- package/dist/declarations/main/main.did.d.ts +72 -83
- package/dist/declarations/main/main.did.js +12 -23
- package/dist/integrity.d.ts +2 -2
- package/dist/integrity.js +4 -4
- package/dist/moc-wrapper.d.ts +2 -0
- package/dist/moc-wrapper.js +8 -0
- package/dist/out/cli.d.ts +2 -0
- package/dist/out/cli.js +115242 -0
- package/dist/package.json +12 -4
- package/dist/templates/cli.d.ts +2 -0
- package/dist/templates/cli.js +3660 -0
- package/integrity.ts +5 -5
- package/package.json +12 -4
- package/dist/helpers/download-package-files.d.ts +0 -12
- package/dist/helpers/download-package-files.js +0 -62
- package/dist/helpers/resolve-version.d.ts +0 -1
- package/dist/helpers/resolve-version.js +0 -11
package/cli.ts
CHANGED
|
@@ -3,15 +3,13 @@
|
|
|
3
3
|
import fs from 'node:fs';
|
|
4
4
|
import {program, Argument, Option} from 'commander';
|
|
5
5
|
import chalk from 'chalk';
|
|
6
|
-
import {Principal} from '@dfinity/principal';
|
|
7
6
|
|
|
8
7
|
import {init} from './commands/init.js';
|
|
9
8
|
import {publish} from './commands/publish.js';
|
|
10
9
|
import {importPem} from './commands/import-identity.js';
|
|
11
10
|
import {sources} from './commands/sources.js';
|
|
12
|
-
import {checkApiCompatibility, setNetwork, apiVersion, checkConfigFile, getNetworkFile
|
|
11
|
+
import {checkApiCompatibility, setNetwork, apiVersion, checkConfigFile, getNetworkFile} from './mops.js';
|
|
13
12
|
import {getNetwork} from './api/network.js';
|
|
14
|
-
import {mainActor} from './api/actors.js';
|
|
15
13
|
import {whoami} from './commands/whoami.js';
|
|
16
14
|
import {installAll} from './commands/install-all.js';
|
|
17
15
|
import {search} from './commands/search.js';
|
|
@@ -62,7 +60,7 @@ program
|
|
|
62
60
|
.description('Install the package and save it to mops.toml')
|
|
63
61
|
.option('--dev')
|
|
64
62
|
.option('--verbose')
|
|
65
|
-
.addOption(new Option('--
|
|
63
|
+
.addOption(new Option('--lock <action>', 'Lockfile action').choices(['update', 'ignore']))
|
|
66
64
|
.action(async (pkg, options) => {
|
|
67
65
|
if (!checkConfigFile()) {
|
|
68
66
|
process.exit(1);
|
|
@@ -78,7 +76,7 @@ program
|
|
|
78
76
|
.option('--dev', 'Remove from dev-dependencies instead of dependencies')
|
|
79
77
|
.option('--verbose', 'Show more information')
|
|
80
78
|
.option('--dry-run', 'Do not actually remove anything')
|
|
81
|
-
.addOption(new Option('--
|
|
79
|
+
.addOption(new Option('--lock <action>', 'Lockfile action').choices(['update', 'ignore']))
|
|
82
80
|
.action(async (pkg, options) => {
|
|
83
81
|
if (!checkConfigFile()) {
|
|
84
82
|
process.exit(1);
|
|
@@ -92,7 +90,7 @@ program
|
|
|
92
90
|
.alias('i')
|
|
93
91
|
.description('Install all dependencies specified in mops.toml')
|
|
94
92
|
.option('--verbose')
|
|
95
|
-
.addOption(new Option('--
|
|
93
|
+
.addOption(new Option('--lock <action>', 'Lockfile action').choices(['check', 'update', 'ignore']))
|
|
96
94
|
.action(async (pkg, options) => {
|
|
97
95
|
if (!checkConfigFile()) {
|
|
98
96
|
process.exit(1);
|
|
@@ -167,7 +165,7 @@ program
|
|
|
167
165
|
if (!checkConfigFile()) {
|
|
168
166
|
process.exit(1);
|
|
169
167
|
}
|
|
170
|
-
await installAll({silent: true,
|
|
168
|
+
await installAll({silent: true, lock: 'ignore'});
|
|
171
169
|
let sourcesArr = await sources(options);
|
|
172
170
|
console.log(sourcesArr.join('\n'));
|
|
173
171
|
});
|
|
@@ -212,7 +210,7 @@ program
|
|
|
212
210
|
.addOption(new Option('--mode <mode>', 'Test mode').choices(['interpreter', 'wasi']).default('interpreter'))
|
|
213
211
|
.option('-w, --watch', 'Enable watch mode')
|
|
214
212
|
.action(async (filter, options) => {
|
|
215
|
-
await installAll({silent: true,
|
|
213
|
+
await installAll({silent: true, lock: 'ignore'});
|
|
216
214
|
await test(filter, options);
|
|
217
215
|
});
|
|
218
216
|
|
|
@@ -220,13 +218,14 @@ program
|
|
|
220
218
|
program
|
|
221
219
|
.command('bench [filter]')
|
|
222
220
|
.description('Run benchmarks')
|
|
221
|
+
.addOption(new Option('--replica <replica>', 'Which replica to use to run benchmarks').choices(['dfx', 'pocket-ic']).default('dfx'))
|
|
222
|
+
.addOption(new Option('--gc <gc>', 'Garbage collector').choices(['copying', 'compacting', 'generational', 'incremental']).default('copying'))
|
|
223
223
|
.addOption(new Option('--save', 'Save benchmark results to .bench/<filename>.json'))
|
|
224
224
|
.addOption(new Option('--compare', 'Run benchmark and compare results with .bench/<filename>.json'))
|
|
225
|
-
.addOption(new Option('--gc <gc>', 'Garbage collector').choices(['copying', 'compacting', 'generational', 'incremental']).default('incremental'))
|
|
226
225
|
// .addOption(new Option('--force-gc', 'Force GC'))
|
|
227
226
|
.addOption(new Option('--verbose', 'Show more information'))
|
|
228
227
|
.action(async (filter, options) => {
|
|
229
|
-
await installAll({silent: true,
|
|
228
|
+
await installAll({silent: true, lock: 'ignore'});
|
|
230
229
|
await bench(filter, options);
|
|
231
230
|
});
|
|
232
231
|
|
|
@@ -287,39 +286,6 @@ program
|
|
|
287
286
|
}
|
|
288
287
|
});
|
|
289
288
|
|
|
290
|
-
// temp: airdrop
|
|
291
|
-
program
|
|
292
|
-
.command('airdrop <check|claim> [canister]')
|
|
293
|
-
.action(async (sub, canister) => {
|
|
294
|
-
let identity = await getIdentity();
|
|
295
|
-
let main = await mainActor(identity);
|
|
296
|
-
if (sub === 'check') {
|
|
297
|
-
let amount = await main.getAirdropAmount();
|
|
298
|
-
if (amount === 0n) {
|
|
299
|
-
console.log('No airdrop available');
|
|
300
|
-
return;
|
|
301
|
-
}
|
|
302
|
-
console.log(`You can claim ${Number(amount) / 1_000_000_000_000} TCycles`);
|
|
303
|
-
}
|
|
304
|
-
else if (sub === 'claim') {
|
|
305
|
-
let principal;
|
|
306
|
-
try {
|
|
307
|
-
principal = Principal.fromText(canister);
|
|
308
|
-
}
|
|
309
|
-
catch (err) {
|
|
310
|
-
console.log('Invalid canister id');
|
|
311
|
-
console.log(err);
|
|
312
|
-
return;
|
|
313
|
-
}
|
|
314
|
-
console.log('Sending cycles to the canister ' + canister);
|
|
315
|
-
let res = await main.claimAirdrop(principal);
|
|
316
|
-
console.log(res);
|
|
317
|
-
}
|
|
318
|
-
else {
|
|
319
|
-
console.log('Unknown sub command. Available sub commands: check, claim');
|
|
320
|
-
}
|
|
321
|
-
});
|
|
322
|
-
|
|
323
289
|
// bump
|
|
324
290
|
program
|
|
325
291
|
.command('bump [major|minor|patch]')
|
|
@@ -332,7 +298,7 @@ program
|
|
|
332
298
|
program
|
|
333
299
|
.command('sync')
|
|
334
300
|
.description('Add missing packages and remove unused packages')
|
|
335
|
-
.addOption(new Option('--
|
|
301
|
+
.addOption(new Option('--lock <action>', 'Lockfile action').choices(['update', 'ignore']))
|
|
336
302
|
.action(async (options) => {
|
|
337
303
|
await sync(options);
|
|
338
304
|
});
|
|
@@ -349,7 +315,7 @@ program
|
|
|
349
315
|
program
|
|
350
316
|
.command('update [pkg]')
|
|
351
317
|
.description('Update dependencies specified in mops.toml')
|
|
352
|
-
.addOption(new Option('--
|
|
318
|
+
.addOption(new Option('--lock <action>', 'Lockfile action').choices(['update', 'ignore']))
|
|
353
319
|
.action(async (pkg, options) => {
|
|
354
320
|
await update(pkg, options);
|
|
355
321
|
});
|
package/commands/add.ts
CHANGED
|
@@ -6,16 +6,16 @@ import {getHighestVersion} from '../api/getHighestVersion.js';
|
|
|
6
6
|
import {installFromGithub} from '../vessel.js';
|
|
7
7
|
import {install} from './install.js';
|
|
8
8
|
import {notifyInstalls} from '../notify-installs.js';
|
|
9
|
-
|
|
9
|
+
import {checkIntegrity} from '../integrity.js';
|
|
10
10
|
|
|
11
11
|
type AddOptions = {
|
|
12
12
|
verbose?: boolean;
|
|
13
13
|
dev?: boolean;
|
|
14
|
-
|
|
14
|
+
lock?: 'update' | 'ignore';
|
|
15
15
|
};
|
|
16
16
|
|
|
17
17
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
18
|
-
export async function add(name: string, {verbose = false, dev = false,
|
|
18
|
+
export async function add(name: string, {verbose = false, dev = false, lock}: AddOptions = {}, asName?: string) {
|
|
19
19
|
if (!checkConfigFile()) {
|
|
20
20
|
return;
|
|
21
21
|
}
|
|
@@ -109,10 +109,12 @@ export async function add(name: string, {verbose = false, dev = false, lockfile}
|
|
|
109
109
|
|
|
110
110
|
writeConfig(config);
|
|
111
111
|
|
|
112
|
-
|
|
112
|
+
if (lock !== 'ignore') {
|
|
113
|
+
logUpdate('Checking integrity...');
|
|
114
|
+
}
|
|
113
115
|
await Promise.all([
|
|
114
116
|
notifyInstalls(Object.keys(installedPackages)),
|
|
115
|
-
|
|
117
|
+
checkIntegrity(lock),
|
|
116
118
|
]);
|
|
117
119
|
|
|
118
120
|
logUpdate.clear();
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import {execSync} from 'node:child_process';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import {execaCommand} from 'execa';
|
|
5
|
+
import {PocketIc} from '@hadronous/pic';
|
|
6
|
+
import {getRootDir} from '../mops.js';
|
|
7
|
+
import {createActor, idlFactory} from '../declarations/bench/index.js';
|
|
8
|
+
|
|
9
|
+
export class BenchReplica {
|
|
10
|
+
type : 'dfx' | 'pocket-ic';
|
|
11
|
+
verbose = false;
|
|
12
|
+
canisters: Record<string, {cwd: string; canisterId: string; actor: any;}> = {};
|
|
13
|
+
pocketIc?: PocketIc;
|
|
14
|
+
|
|
15
|
+
constructor(type: 'dfx' | 'pocket-ic', verbose = false) {
|
|
16
|
+
this.type = type;
|
|
17
|
+
this.verbose = verbose;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
async start() {
|
|
21
|
+
console.log(`Starting ${this.type} replica...`);
|
|
22
|
+
|
|
23
|
+
if (this.type == 'dfx') {
|
|
24
|
+
await this.stop();
|
|
25
|
+
let dir = path.join(getRootDir(), '.mops/.bench');
|
|
26
|
+
fs.writeFileSync(path.join(dir, 'dfx.json'), JSON.stringify(this.dfxJson(''), null, 2));
|
|
27
|
+
execSync('dfx start --background --clean --artificial-delay 0' + (this.verbose ? '' : ' -qqqq'), {cwd: dir, stdio: ['inherit', this.verbose ? 'inherit' : 'ignore', 'inherit']});
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
this.pocketIc = await PocketIc.create();
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async stop() {
|
|
35
|
+
if (this.type == 'dfx') {
|
|
36
|
+
let dir = path.join(getRootDir(), '.mops/.bench');
|
|
37
|
+
execSync('dfx stop' + (this.verbose ? '' : ' -qqqq'), {cwd: dir, stdio: ['pipe', this.verbose ? 'inherit' : 'ignore', 'pipe']});
|
|
38
|
+
}
|
|
39
|
+
else if (this.pocketIc) {
|
|
40
|
+
this.pocketIc.tearDown();
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
async deploy(name: string, wasm: string, cwd: string = process.cwd()) {
|
|
45
|
+
if (this.type === 'dfx') {
|
|
46
|
+
await execaCommand(`dfx deploy ${name} --mode reinstall --yes --identity anonymous`, {cwd, stdio: this.verbose ? 'pipe' : ['pipe', 'ignore', 'pipe']});
|
|
47
|
+
let canisterId = execSync(`dfx canister id ${name}`, {cwd}).toString().trim();
|
|
48
|
+
let actor = await createActor(canisterId, {
|
|
49
|
+
agentOptions: {
|
|
50
|
+
host: 'http://127.0.0.1:4944',
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
this.canisters[name] = {cwd, canisterId, actor};
|
|
54
|
+
}
|
|
55
|
+
else if (this.pocketIc) {
|
|
56
|
+
let {canisterId, actor} = await this.pocketIc.setupCanister(idlFactory, wasm);
|
|
57
|
+
this.canisters[name] = {
|
|
58
|
+
cwd,
|
|
59
|
+
canisterId: canisterId.toText(),
|
|
60
|
+
actor,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
getActor(name: string): unknown {
|
|
66
|
+
return this.canisters[name]?.actor;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
getCanisterId(name: string): string {
|
|
70
|
+
return this.canisters[name]?.canisterId || '';
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
dfxJson(canisterName: string) {
|
|
74
|
+
let canisters: Record<string, any> = {};
|
|
75
|
+
if (canisterName) {
|
|
76
|
+
canisters[canisterName] = {
|
|
77
|
+
type: 'custom',
|
|
78
|
+
wasm: 'canister.wasm',
|
|
79
|
+
candid: 'canister.did',
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return {
|
|
84
|
+
version: 1,
|
|
85
|
+
canisters,
|
|
86
|
+
defaults: {
|
|
87
|
+
build: {
|
|
88
|
+
packtool: 'mops sources',
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
networks: {
|
|
92
|
+
local: {
|
|
93
|
+
type: 'ephemeral',
|
|
94
|
+
bind: '127.0.0.1:4944',
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
}
|
package/commands/bench.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import {execSync} from 'node:child_process';
|
|
2
1
|
import path from 'node:path';
|
|
3
2
|
import fs from 'node:fs';
|
|
4
3
|
import os from 'node:os';
|
|
@@ -6,17 +5,19 @@ import chalk from 'chalk';
|
|
|
6
5
|
import {globSync} from 'glob';
|
|
7
6
|
import {markdownTable} from 'markdown-table';
|
|
8
7
|
import logUpdate from 'log-update';
|
|
8
|
+
import {execaCommand} from 'execa';
|
|
9
|
+
import stringWidth from 'string-width';
|
|
9
10
|
|
|
10
11
|
import {getRootDir} from '../mops.js';
|
|
11
12
|
import {parallel} from '../parallel.js';
|
|
12
|
-
import {createActor} from '../declarations/bench/index.js';
|
|
13
|
-
import {BenchResult, BenchSchema, _SERVICE} from '../declarations/bench/bench.did.js';
|
|
14
13
|
import {absToRel} from './test/utils.js';
|
|
15
14
|
import {getMocVersion} from '../helpers/get-moc-version.js';
|
|
16
15
|
import {getDfxVersion} from '../helpers/get-dfx-version.js';
|
|
17
16
|
import {getMocPath} from '../helpers/get-moc-path.js';
|
|
18
17
|
import {sources} from './sources.js';
|
|
19
|
-
|
|
18
|
+
|
|
19
|
+
import {BenchResult, BenchSchema, _SERVICE} from '../declarations/bench/bench.did.js';
|
|
20
|
+
import {BenchReplica} from './bench-replica.js';
|
|
20
21
|
|
|
21
22
|
let ignore = [
|
|
22
23
|
'**/node_modules/**',
|
|
@@ -31,30 +32,36 @@ let globConfig = {
|
|
|
31
32
|
};
|
|
32
33
|
|
|
33
34
|
type BenchOptions = {
|
|
34
|
-
dfx
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
35
|
+
replica: 'dfx' | 'pocket-ic',
|
|
36
|
+
replicaVersion: string,
|
|
37
|
+
moc: string,
|
|
38
|
+
gc: 'copying' | 'compacting' | 'generational' | 'incremental',
|
|
39
|
+
forceGc: boolean,
|
|
40
|
+
save: boolean,
|
|
41
|
+
compare: boolean,
|
|
42
|
+
verbose: boolean,
|
|
41
43
|
};
|
|
42
44
|
|
|
43
|
-
export async function bench(filter = '',
|
|
45
|
+
export async function bench(filter = '', optionsArg: Partial<BenchOptions> = {}): Promise<boolean> {
|
|
44
46
|
let defaultOptions: BenchOptions = {
|
|
47
|
+
replica: 'dfx',
|
|
45
48
|
moc: getMocVersion(),
|
|
46
|
-
|
|
47
|
-
gc: '
|
|
49
|
+
replicaVersion: '0.0.0',
|
|
50
|
+
gc: 'copying',
|
|
48
51
|
forceGc: true,
|
|
49
52
|
save: false,
|
|
50
53
|
compare: false,
|
|
51
54
|
verbose: false,
|
|
52
55
|
};
|
|
53
56
|
|
|
54
|
-
options = {...defaultOptions, ...
|
|
57
|
+
let options: BenchOptions = {...defaultOptions, ...optionsArg};
|
|
58
|
+
|
|
59
|
+
options.replicaVersion = options.replica == 'dfx' ? getDfxVersion() : '1.0.0';
|
|
55
60
|
|
|
56
61
|
options.verbose && console.log(options);
|
|
57
62
|
|
|
63
|
+
let replica = new BenchReplica(options.replica, options.verbose);
|
|
64
|
+
|
|
58
65
|
let rootDir = getRootDir();
|
|
59
66
|
let globStr = '**/bench?(mark)/**/*.bench.mo';
|
|
60
67
|
if (filter) {
|
|
@@ -85,17 +92,16 @@ export async function bench(filter = '', options: BenchOptions = {}): Promise<bo
|
|
|
85
92
|
console.log('='.repeat(50));
|
|
86
93
|
console.log('');
|
|
87
94
|
|
|
88
|
-
|
|
89
|
-
startDfx(options.verbose);
|
|
95
|
+
await replica.start();
|
|
90
96
|
|
|
91
97
|
console.log('Deploying canisters...');
|
|
92
98
|
await parallel(os.cpus().length, files, async (file: string) => {
|
|
93
99
|
try {
|
|
94
|
-
await deployBenchFile(file, options);
|
|
100
|
+
await deployBenchFile(file, options, replica);
|
|
95
101
|
}
|
|
96
102
|
catch (err) {
|
|
97
|
-
console.error('Unexpected error. Stopping
|
|
98
|
-
|
|
103
|
+
console.error('Unexpected error. Stopping replica...');
|
|
104
|
+
await replica.stop();
|
|
99
105
|
throw err;
|
|
100
106
|
}
|
|
101
107
|
});
|
|
@@ -105,17 +111,17 @@ export async function bench(filter = '', options: BenchOptions = {}): Promise<bo
|
|
|
105
111
|
console.log(`\nRunning ${chalk.gray(absToRel(file))}...`);
|
|
106
112
|
console.log('');
|
|
107
113
|
try {
|
|
108
|
-
await runBenchFile(file, options);
|
|
114
|
+
await runBenchFile(file, options, replica);
|
|
109
115
|
}
|
|
110
116
|
catch (err) {
|
|
111
|
-
console.error('Unexpected error. Stopping
|
|
112
|
-
|
|
117
|
+
console.error('Unexpected error. Stopping replica...');
|
|
118
|
+
await replica.stop();
|
|
113
119
|
throw err;
|
|
114
120
|
}
|
|
115
121
|
});
|
|
116
122
|
|
|
117
|
-
console.log('Stopping
|
|
118
|
-
|
|
123
|
+
console.log('Stopping replica...');
|
|
124
|
+
await replica.stop();
|
|
119
125
|
|
|
120
126
|
fs.rmSync(benchDir, {recursive: true, force: true});
|
|
121
127
|
|
|
@@ -133,55 +139,14 @@ function getMocArgs(options: BenchOptions): string {
|
|
|
133
139
|
return args;
|
|
134
140
|
}
|
|
135
141
|
|
|
136
|
-
function
|
|
137
|
-
options || console.log(options);
|
|
138
|
-
|
|
139
|
-
let canisters: Record<string, any> = {};
|
|
140
|
-
if (canisterName) {
|
|
141
|
-
canisters[canisterName] = {
|
|
142
|
-
type: 'custom',
|
|
143
|
-
wasm: 'canister.wasm',
|
|
144
|
-
candid: 'canister.did',
|
|
145
|
-
};
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
return {
|
|
149
|
-
version: 1,
|
|
150
|
-
canisters,
|
|
151
|
-
defaults: {
|
|
152
|
-
build: {
|
|
153
|
-
packtool: 'mops sources',
|
|
154
|
-
},
|
|
155
|
-
},
|
|
156
|
-
networks: {
|
|
157
|
-
local: {
|
|
158
|
-
type: 'ephemeral',
|
|
159
|
-
bind: '127.0.0.1:4944',
|
|
160
|
-
},
|
|
161
|
-
},
|
|
162
|
-
};
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
function startDfx(verbose = false) {
|
|
166
|
-
stopDfx(verbose);
|
|
167
|
-
let dir = path.join(getRootDir(), '.mops/.bench');
|
|
168
|
-
fs.writeFileSync(path.join(dir, 'dfx.json'), JSON.stringify(dfxJson(''), null, 2));
|
|
169
|
-
execSync('dfx start --background --clean --artificial-delay 0' + (verbose ? '' : ' -qqqq'), {cwd: dir, stdio: ['inherit', verbose ? 'inherit' : 'ignore', 'inherit']});
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
function stopDfx(verbose = false) {
|
|
173
|
-
let dir = path.join(getRootDir(), '.mops/.bench');
|
|
174
|
-
execSync('dfx stop' + (verbose ? '' : ' -qqqq'), {cwd: dir, stdio: ['pipe', verbose ? 'inherit' : 'ignore', 'pipe']});
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
async function deployBenchFile(file: string, options: BenchOptions = {}): Promise<void> {
|
|
142
|
+
async function deployBenchFile(file: string, options: BenchOptions, replica: BenchReplica): Promise<void> {
|
|
178
143
|
let rootDir = getRootDir();
|
|
179
144
|
let tempDir = path.join(rootDir, '.mops/.bench/', path.parse(file).name);
|
|
180
145
|
let canisterName = path.parse(file).name;
|
|
181
146
|
|
|
182
147
|
// prepare temp files
|
|
183
148
|
fs.mkdirSync(tempDir, {recursive: true});
|
|
184
|
-
fs.writeFileSync(path.join(tempDir, 'dfx.json'), JSON.stringify(dfxJson(canisterName
|
|
149
|
+
fs.writeFileSync(path.join(tempDir, 'dfx.json'), JSON.stringify(replica.dfxJson(canisterName), null, 2));
|
|
185
150
|
|
|
186
151
|
let benchCanisterData = fs.readFileSync(new URL('./bench/bench-canister.mo', import.meta.url), 'utf8');
|
|
187
152
|
benchCanisterData = benchCanisterData.replace('./user-bench', path.relative(tempDir, file).replace(/.mo$/g, ''));
|
|
@@ -195,18 +160,15 @@ async function deployBenchFile(file: string, options: BenchOptions = {}): Promis
|
|
|
195
160
|
options.verbose && console.timeEnd(`build ${canisterName}`);
|
|
196
161
|
|
|
197
162
|
// deploy canister
|
|
163
|
+
let wasm = path.join(tempDir, 'canister.wasm');
|
|
198
164
|
options.verbose && console.time(`deploy ${canisterName}`);
|
|
199
|
-
await execaCommand(`dfx deploy ${canisterName} --mode reinstall --yes --identity anonymous`, {cwd: tempDir, stdio: options.verbose ? 'pipe' : ['pipe', 'ignore', 'pipe']});
|
|
165
|
+
// await execaCommand(`dfx deploy ${canisterName} --mode reinstall --yes --identity anonymous`, {cwd: tempDir, stdio: options.verbose ? 'pipe' : ['pipe', 'ignore', 'pipe']});
|
|
166
|
+
await replica.deploy(canisterName, wasm, tempDir);
|
|
200
167
|
options.verbose && console.timeEnd(`deploy ${canisterName}`);
|
|
201
168
|
|
|
202
169
|
// init bench
|
|
203
170
|
options.verbose && console.time(`init ${canisterName}`);
|
|
204
|
-
let
|
|
205
|
-
let actor: _SERVICE = await createActor(canisterId, {
|
|
206
|
-
agentOptions: {
|
|
207
|
-
host: 'http://127.0.0.1:4944',
|
|
208
|
-
},
|
|
209
|
-
});
|
|
171
|
+
let actor = await replica.getActor(canisterName) as _SERVICE;
|
|
210
172
|
await actor.init();
|
|
211
173
|
options.verbose && console.timeEnd(`init ${canisterName}`);
|
|
212
174
|
}
|
|
@@ -216,18 +178,11 @@ type RunBenchFileResult = {
|
|
|
216
178
|
results: Map<string, BenchResult>,
|
|
217
179
|
};
|
|
218
180
|
|
|
219
|
-
async function runBenchFile(file: string, options: BenchOptions
|
|
181
|
+
async function runBenchFile(file: string, options: BenchOptions, replica: BenchReplica): Promise<RunBenchFileResult> {
|
|
220
182
|
let rootDir = getRootDir();
|
|
221
|
-
let tempDir = path.join(rootDir, '.mops/.bench/', path.parse(file).name);
|
|
222
183
|
let canisterName = path.parse(file).name;
|
|
223
184
|
|
|
224
|
-
let
|
|
225
|
-
let actor: _SERVICE = await createActor(canisterId, {
|
|
226
|
-
agentOptions: {
|
|
227
|
-
host: 'http://127.0.0.1:4944',
|
|
228
|
-
},
|
|
229
|
-
});
|
|
230
|
-
|
|
185
|
+
let actor = await replica.getActor(canisterName) as _SERVICE;
|
|
231
186
|
let schema = await actor.getSchema();
|
|
232
187
|
|
|
233
188
|
// load previous results
|
|
@@ -267,8 +222,8 @@ async function runBenchFile(file: string, options: BenchOptions = {}): Promise<R
|
|
|
267
222
|
let percent = (Number(res[prop]) - Number(prevRes[prop])) / Number(prevRes[prop]) * 100;
|
|
268
223
|
let sign = percent > 0 ? '+' : '';
|
|
269
224
|
let percentText = percent == 0 ? '0%' : sign + percent.toFixed(2) + '%';
|
|
270
|
-
|
|
271
|
-
diff =
|
|
225
|
+
let color: keyof typeof chalk = percent == 0 ? 'gray' : (percent > 0 ? 'red' : 'green');
|
|
226
|
+
diff = ` (${chalk[color](percentText)})`;
|
|
272
227
|
}
|
|
273
228
|
else {
|
|
274
229
|
diff = chalk.yellow(' (no previous results)');
|
|
@@ -285,7 +240,10 @@ async function runBenchFile(file: string, options: BenchOptions = {}): Promise<R
|
|
|
285
240
|
resArr.push(curRow);
|
|
286
241
|
}
|
|
287
242
|
|
|
288
|
-
return markdownTable(resArr, {
|
|
243
|
+
return markdownTable(resArr, {
|
|
244
|
+
align: ['l', ...'r'.repeat(schema.cols.length)],
|
|
245
|
+
stringLength: stringWidth,
|
|
246
|
+
});
|
|
289
247
|
};
|
|
290
248
|
|
|
291
249
|
let printResults = () => {
|
|
@@ -297,7 +255,9 @@ async function runBenchFile(file: string, options: BenchOptions = {}): Promise<R
|
|
|
297
255
|
`);
|
|
298
256
|
};
|
|
299
257
|
|
|
300
|
-
|
|
258
|
+
if (!process.env.CI) {
|
|
259
|
+
printResults();
|
|
260
|
+
}
|
|
301
261
|
|
|
302
262
|
// run all cells
|
|
303
263
|
for (let [rowIndex, row] of schema.rows.entries()) {
|
|
@@ -306,9 +266,15 @@ async function runBenchFile(file: string, options: BenchOptions = {}): Promise<R
|
|
|
306
266
|
// let res = await actor.runCellUpdate(BigInt(rowIndex), BigInt(colIndex));
|
|
307
267
|
let res = await actor.runCellUpdateAwait(BigInt(rowIndex), BigInt(colIndex));
|
|
308
268
|
results.set(`${row}:${col}`, res);
|
|
309
|
-
|
|
269
|
+
if (!process.env.CI) {
|
|
270
|
+
printResults();
|
|
271
|
+
}
|
|
310
272
|
}
|
|
311
273
|
}
|
|
274
|
+
|
|
275
|
+
if (process.env.CI) {
|
|
276
|
+
printResults();
|
|
277
|
+
}
|
|
312
278
|
logUpdate.done();
|
|
313
279
|
|
|
314
280
|
// save results
|
|
@@ -317,7 +283,8 @@ async function runBenchFile(file: string, options: BenchOptions = {}): Promise<R
|
|
|
317
283
|
let json: Record<any, any> = {
|
|
318
284
|
version: 1,
|
|
319
285
|
moc: options.moc,
|
|
320
|
-
|
|
286
|
+
replica: options.replica,
|
|
287
|
+
replicaVersion: options.replicaVersion,
|
|
321
288
|
gc: options.gc,
|
|
322
289
|
forceGc: options.forceGc,
|
|
323
290
|
results: Array.from(results.entries()),
|
package/commands/install-all.ts
CHANGED
|
@@ -9,10 +9,10 @@ import {checkIntegrity} from '../integrity.js';
|
|
|
9
9
|
type InstallAllOptions = {
|
|
10
10
|
verbose?: boolean;
|
|
11
11
|
silent?: boolean;
|
|
12
|
-
|
|
12
|
+
lock?: 'check' | 'update' | 'ignore';
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
export async function installAll({verbose = false, silent = false,
|
|
15
|
+
export async function installAll({verbose = false, silent = false, lock}: InstallAllOptions = {}) {
|
|
16
16
|
if (!checkConfigFile()) {
|
|
17
17
|
return;
|
|
18
18
|
}
|
|
@@ -36,12 +36,12 @@ export async function installAll({verbose = false, silent = false, lockfile}: In
|
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
if (!silent &&
|
|
39
|
+
if (!silent && lock !== 'ignore') {
|
|
40
40
|
logUpdate('Checking integrity...');
|
|
41
41
|
}
|
|
42
42
|
await Promise.all([
|
|
43
43
|
notifyInstalls(Object.keys(installedPackages)),
|
|
44
|
-
checkIntegrity(
|
|
44
|
+
checkIntegrity(lock),
|
|
45
45
|
]);
|
|
46
46
|
|
|
47
47
|
if (!silent) {
|
package/commands/remove.ts
CHANGED
|
@@ -3,17 +3,17 @@ import {deleteSync} from 'del';
|
|
|
3
3
|
import chalk from 'chalk';
|
|
4
4
|
import {formatDir, formatGithubDir, checkConfigFile, readConfig, writeConfig} from '../mops.js';
|
|
5
5
|
import {Config, Dependency} from '../types.js';
|
|
6
|
-
|
|
6
|
+
import {checkIntegrity} from '../integrity.js';
|
|
7
7
|
|
|
8
8
|
type RemoveOptions = {
|
|
9
9
|
verbose?: boolean;
|
|
10
10
|
dev?: boolean;
|
|
11
11
|
dryRun?: boolean;
|
|
12
|
-
|
|
12
|
+
lock?: 'update' | 'ignore';
|
|
13
13
|
};
|
|
14
14
|
|
|
15
15
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
16
|
-
export async function remove(name: string, {dev = false, verbose = false, dryRun = false,
|
|
16
|
+
export async function remove(name: string, {dev = false, verbose = false, dryRun = false, lock}: RemoveOptions = {}) {
|
|
17
17
|
if (!checkConfigFile()) {
|
|
18
18
|
return;
|
|
19
19
|
}
|
|
@@ -100,7 +100,7 @@ export async function remove(name: string, {dev = false, verbose = false, dryRun
|
|
|
100
100
|
}
|
|
101
101
|
dryRun || writeConfig(config);
|
|
102
102
|
|
|
103
|
-
|
|
103
|
+
await checkIntegrity(lock);
|
|
104
104
|
|
|
105
105
|
console.log(chalk.green('Package removed ') + `${name} = "${version}"`);
|
|
106
106
|
}
|
package/commands/sync.ts
CHANGED
|
@@ -8,10 +8,10 @@ import {remove} from './remove.js';
|
|
|
8
8
|
import {checkIntegrity} from '../integrity.js';
|
|
9
9
|
|
|
10
10
|
type SyncOptions = {
|
|
11
|
-
|
|
11
|
+
lock?: 'update' | 'ignore';
|
|
12
12
|
};
|
|
13
13
|
|
|
14
|
-
export async function sync({
|
|
14
|
+
export async function sync({lock}: SyncOptions = {}) {
|
|
15
15
|
if (!checkConfigFile()) {
|
|
16
16
|
return;
|
|
17
17
|
}
|
|
@@ -28,16 +28,16 @@ export async function sync({lockfile}: SyncOptions = {}) {
|
|
|
28
28
|
|
|
29
29
|
// add missing packages
|
|
30
30
|
for (let pkg of missing) {
|
|
31
|
-
await add(pkg, {
|
|
31
|
+
await add(pkg, {lock: 'ignore'});
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
// remove unused packages
|
|
35
35
|
for (let pkg of unused) {
|
|
36
36
|
let dev = devDeps.has(pkg) && !deps.has(pkg);
|
|
37
|
-
await remove(pkg, {dev,
|
|
37
|
+
await remove(pkg, {dev, lock: 'ignore'});
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
await checkIntegrity(
|
|
40
|
+
await checkIntegrity(lock);
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
let ignore = [
|
package/commands/update.ts
CHANGED
|
@@ -7,10 +7,10 @@ import {checkIntegrity} from '../integrity.js';
|
|
|
7
7
|
type UpdateOptions = {
|
|
8
8
|
verbose?: boolean;
|
|
9
9
|
dev?: boolean;
|
|
10
|
-
|
|
10
|
+
lock?: 'update' | 'ignore';
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
-
export async function update(pkg?: string, {
|
|
13
|
+
export async function update(pkg?: string, {lock}: UpdateOptions = {}) {
|
|
14
14
|
if (!checkConfigFile()) {
|
|
15
15
|
return;
|
|
16
16
|
}
|
|
@@ -56,5 +56,5 @@ export async function update(pkg?: string, {lockfile}: UpdateOptions = {}) {
|
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
await checkIntegrity(
|
|
59
|
+
await checkIntegrity(lock);
|
|
60
60
|
}
|