ic-mops 0.36.1 → 0.37.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/bin/moc-wrapper.sh +3 -0
- package/bin/mops.ts +3 -0
- package/cache.ts +2 -2
- package/cli.ts +61 -4
- package/commands/add.ts +3 -1
- package/commands/bench-replica.ts +5 -3
- package/commands/docs.ts +9 -6
- package/commands/install-all.ts +7 -2
- package/commands/install.ts +5 -1
- package/commands/publish.ts +2 -0
- package/commands/test/test.ts +42 -19
- package/commands/toolchain/index.ts +325 -0
- package/commands/toolchain/moc.ts +58 -0
- package/commands/toolchain/pocket-ic.ts +74 -0
- package/commands/toolchain/toolchain-utils.ts +83 -0
- package/commands/toolchain/wasmtime.ts +45 -0
- package/dist/bin/mops.d.ts +1 -1
- package/dist/cache.js +2 -2
- package/dist/cli.d.ts +0 -1
- package/dist/cli.js +52 -3
- package/dist/commands/add.js +2 -1
- package/dist/commands/bench-replica.d.ts +1 -1
- package/dist/commands/bench-replica.js +5 -3
- package/dist/commands/docs.js +9 -6
- package/dist/commands/install-all.js +5 -2
- package/dist/commands/install.js +5 -1
- package/dist/commands/publish.js +1 -0
- package/dist/commands/test/test.js +41 -19
- package/dist/commands/toolchain/index.d.ts +26 -0
- package/dist/commands/toolchain/index.js +274 -0
- package/dist/commands/toolchain/moc.d.ts +5 -1
- package/dist/commands/toolchain/moc.js +18 -6
- package/dist/commands/toolchain/mocv.js +0 -1
- package/dist/commands/toolchain/pocket-ic.d.ts +12 -0
- package/dist/commands/toolchain/pocket-ic.js +62 -0
- package/dist/commands/toolchain/toolchain-utils.d.ts +2 -2
- package/dist/commands/toolchain/toolchain-utils.js +22 -6
- package/dist/commands/toolchain/wasmtime.d.ts +5 -1
- package/dist/commands/toolchain/wasmtime.js +16 -4
- package/dist/integrity.js +40 -15
- package/dist/mops.js +2 -2
- package/dist/package.json +9 -4
- package/dist/pic-js/examples/clock/tests/clock/index.d.ts +1 -0
- package/dist/pic-js/examples/clock/tests/clock/index.js +5 -0
- package/dist/pic-js/examples/clock/tests/jest.config.d.ts +3 -0
- package/dist/pic-js/examples/clock/tests/jest.config.js +8 -0
- package/dist/pic-js/examples/clock/tests/src/clock.spec.d.ts +1 -0
- package/dist/pic-js/examples/clock/tests/src/clock.spec.js +48 -0
- package/dist/pic-js/examples/counter/tests/counter/index.d.ts +1 -0
- package/dist/pic-js/examples/counter/tests/counter/index.js +5 -0
- package/dist/pic-js/examples/counter/tests/jest.config.d.ts +3 -0
- package/dist/pic-js/examples/counter/tests/jest.config.js +8 -0
- package/dist/pic-js/examples/counter/tests/src/counter.spec.d.ts +1 -0
- package/dist/pic-js/examples/counter/tests/src/counter.spec.js +80 -0
- package/dist/pic-js/examples/todo/tests/jest.config.d.ts +3 -0
- package/dist/pic-js/examples/todo/tests/jest.config.js +8 -0
- package/dist/pic-js/examples/todo/tests/src/todo.spec.d.ts +1 -0
- package/dist/pic-js/examples/todo/tests/src/todo.spec.js +211 -0
- package/dist/pic-js/examples/todo/tests/todo/index.d.ts +1 -0
- package/dist/pic-js/examples/todo/tests/todo/index.js +5 -0
- package/dist/pic-js/packages/pic/src/error.d.ts +12 -0
- package/dist/pic-js/packages/pic/src/error.js +36 -0
- package/dist/pic-js/packages/pic/src/http-client.d.ts +15 -0
- package/dist/pic-js/packages/pic/src/http-client.js +37 -0
- package/dist/pic-js/packages/pic/src/identity.d.ts +66 -0
- package/dist/pic-js/packages/pic/src/identity.js +86 -0
- package/dist/pic-js/packages/pic/src/index.d.ts +4 -0
- package/dist/pic-js/packages/pic/src/index.js +8 -0
- package/dist/pic-js/packages/pic/src/management-canister.d.ts +30 -0
- package/dist/pic-js/packages/pic/src/management-canister.js +43 -0
- package/dist/pic-js/packages/pic/src/pocket-ic-actor.d.ts +83 -0
- package/dist/pic-js/packages/pic/src/pocket-ic-actor.js +58 -0
- package/dist/pic-js/packages/pic/src/pocket-ic-client-types.d.ts +61 -0
- package/dist/pic-js/packages/pic/src/pocket-ic-client-types.js +2 -0
- package/dist/pic-js/packages/pic/src/pocket-ic-client.d.ts +24 -0
- package/dist/pic-js/packages/pic/src/pocket-ic-client.js +123 -0
- package/dist/pic-js/packages/pic/src/pocket-ic-server.d.ts +10 -0
- package/dist/pic-js/packages/pic/src/pocket-ic-server.js +55 -0
- package/dist/pic-js/packages/pic/src/pocket-ic-types.d.ts +40 -0
- package/dist/pic-js/packages/pic/src/pocket-ic-types.js +2 -0
- package/dist/pic-js/packages/pic/src/pocket-ic.d.ts +447 -0
- package/dist/pic-js/packages/pic/src/pocket-ic.js +551 -0
- package/dist/pic-js/packages/pic/src/util/candid.d.ts +1 -0
- package/dist/pic-js/packages/pic/src/util/candid.js +7 -0
- package/dist/pic-js/packages/pic/src/util/encoding.d.ts +5 -0
- package/dist/pic-js/packages/pic/src/util/encoding.js +19 -0
- package/dist/pic-js/packages/pic/src/util/fs.d.ts +4 -0
- package/dist/pic-js/packages/pic/src/util/fs.js +29 -0
- package/dist/pic-js/packages/pic/src/util/index.d.ts +5 -0
- package/dist/pic-js/packages/pic/src/util/index.js +21 -0
- package/dist/pic-js/packages/pic/src/util/os.d.ts +4 -0
- package/dist/pic-js/packages/pic/src/util/os.js +19 -0
- package/dist/pic-js/packages/pic/src/util/poll.d.ts +5 -0
- package/dist/pic-js/packages/pic/src/util/poll.js +28 -0
- package/dist/templates/mops-test.yml +4 -4
- package/dist/types.d.ts +7 -0
- package/dist/vessel.js +5 -1
- package/global.d.ts +2 -1
- package/integrity.ts +57 -17
- package/mops.ts +3 -3
- package/package.json +9 -4
- package/templates/mops-test.yml +4 -4
- package/types.ts +10 -1
- package/vessel.ts +6 -1
- package/bun.lockb +0 -0
- package/cli-local.ts +0 -3
package/bin/mops.ts
ADDED
package/cache.ts
CHANGED
|
@@ -39,7 +39,7 @@ export let copyCache = (pkgId: string, dest: string) => {
|
|
|
39
39
|
};
|
|
40
40
|
|
|
41
41
|
export let cacheSize = async () => {
|
|
42
|
-
let dir = path.join(globalCacheDir
|
|
42
|
+
let dir = path.join(globalCacheDir);
|
|
43
43
|
fs.mkdirSync(dir, {recursive: true});
|
|
44
44
|
|
|
45
45
|
let size = await getFolderSize.strict(dir);
|
|
@@ -50,6 +50,6 @@ export let cacheSize = async () => {
|
|
|
50
50
|
};
|
|
51
51
|
|
|
52
52
|
export let cleanCache = async () => {
|
|
53
|
-
let dir = path.join(globalCacheDir
|
|
53
|
+
let dir = path.join(globalCacheDir);
|
|
54
54
|
fs.rmSync(dir, {recursive: true, force: true});
|
|
55
55
|
};
|
package/cli.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
1
|
import fs from 'node:fs';
|
|
4
|
-
import {
|
|
2
|
+
import {Command, Argument, Option} from 'commander';
|
|
5
3
|
import chalk from 'chalk';
|
|
6
4
|
|
|
7
5
|
import {init} from './commands/init.js';
|
|
@@ -26,6 +24,8 @@ import {outdated} from './commands/outdated.js';
|
|
|
26
24
|
import {update} from './commands/update.js';
|
|
27
25
|
import {bench} from './commands/bench.js';
|
|
28
26
|
import {transferOwnership} from './commands/transfer-ownership.js';
|
|
27
|
+
import {toolchain} from './commands/toolchain/index.js';
|
|
28
|
+
import {Tool} from './types.js';
|
|
29
29
|
// import {docs} from './commands/docs.js';
|
|
30
30
|
|
|
31
31
|
declare global {
|
|
@@ -38,6 +38,7 @@ if (fs.existsSync(networkFile)) {
|
|
|
38
38
|
globalThis.MOPS_NETWORK = fs.readFileSync(networkFile).toString() || 'ic';
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
+
let program = new Command();
|
|
41
42
|
|
|
42
43
|
program.name('mops');
|
|
43
44
|
|
|
@@ -58,7 +59,7 @@ program
|
|
|
58
59
|
program
|
|
59
60
|
.command('add <pkg>')
|
|
60
61
|
.description('Install the package and save it to mops.toml')
|
|
61
|
-
.option('--dev')
|
|
62
|
+
.option('--dev', 'Add to [dev-dependencies] section')
|
|
62
63
|
.option('--verbose')
|
|
63
64
|
.addOption(new Option('--lock <action>', 'Lockfile action').choices(['update', 'ignore']))
|
|
64
65
|
.action(async (pkg, options) => {
|
|
@@ -101,6 +102,8 @@ program
|
|
|
101
102
|
return;
|
|
102
103
|
}
|
|
103
104
|
|
|
105
|
+
await toolchain.ensureToolchainInited({strict: false});
|
|
106
|
+
|
|
104
107
|
if (pkg) {
|
|
105
108
|
// @deprecated
|
|
106
109
|
console.log(chalk.yellow('Consider using the \'mops add\' command to install a specific package.'));
|
|
@@ -108,6 +111,7 @@ program
|
|
|
108
111
|
}
|
|
109
112
|
else {
|
|
110
113
|
await installAll(options);
|
|
114
|
+
await toolchain.installAll(options);
|
|
111
115
|
}
|
|
112
116
|
});
|
|
113
117
|
|
|
@@ -166,6 +170,7 @@ program
|
|
|
166
170
|
process.exit(1);
|
|
167
171
|
}
|
|
168
172
|
await installAll({silent: true, lock: 'ignore'});
|
|
173
|
+
await toolchain.ensureToolchainInited({strict: false});
|
|
169
174
|
let sourcesArr = await sources(options);
|
|
170
175
|
console.log(sourcesArr.join('\n'));
|
|
171
176
|
});
|
|
@@ -328,4 +333,56 @@ program
|
|
|
328
333
|
await transferOwnership(toPrincipal);
|
|
329
334
|
});
|
|
330
335
|
|
|
336
|
+
// toolchain
|
|
337
|
+
const toolchainCommand = new Command('toolchain').description('Toolchain management');
|
|
338
|
+
|
|
339
|
+
toolchainCommand
|
|
340
|
+
.command('init')
|
|
341
|
+
.description('One-time initialization of toolchain management')
|
|
342
|
+
.action(async () => {
|
|
343
|
+
await toolchain.init();
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
toolchainCommand
|
|
347
|
+
.command('reset')
|
|
348
|
+
.description('Uninstall toolchain management')
|
|
349
|
+
.action(async () => {
|
|
350
|
+
await toolchain.init({reset: true});
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
toolchainCommand
|
|
354
|
+
.command('use')
|
|
355
|
+
.description('Install specified tool version and update mops.toml')
|
|
356
|
+
.addArgument(new Argument('<tool>').choices(['moc', 'wasmtime', 'pocket-ic']))
|
|
357
|
+
.addArgument(new Argument('[version]'))
|
|
358
|
+
.action(async (tool, version) => {
|
|
359
|
+
if (!checkConfigFile()) {
|
|
360
|
+
process.exit(1);
|
|
361
|
+
}
|
|
362
|
+
await toolchain.use(tool, version);
|
|
363
|
+
});
|
|
364
|
+
|
|
365
|
+
toolchainCommand
|
|
366
|
+
.command('update')
|
|
367
|
+
.description('Update specified tool or all tools to the latest version and update mops.toml')
|
|
368
|
+
.addArgument(new Argument('[tool]').choices(['moc', 'wasmtime', 'pocket-ic']))
|
|
369
|
+
.action(async (tool?: Tool) => {
|
|
370
|
+
if (!checkConfigFile()) {
|
|
371
|
+
process.exit(1);
|
|
372
|
+
}
|
|
373
|
+
await toolchain.update(tool);
|
|
374
|
+
});
|
|
375
|
+
|
|
376
|
+
toolchainCommand
|
|
377
|
+
.command('bin')
|
|
378
|
+
.description('Get path to the tool binary\n<tool> can be one of "moc", "wasmtime", "pocket-ic"')
|
|
379
|
+
.addArgument(new Argument('<tool>').choices(['moc', 'wasmtime', 'pocket-ic']))
|
|
380
|
+
.addOption(new Option('--fallback', 'Fallback to the moc that comes with dfx if moc is not specified in the [toolchain] section'))
|
|
381
|
+
.action(async (tool, options) => {
|
|
382
|
+
let bin = await toolchain.bin(tool, options);
|
|
383
|
+
console.log(bin);
|
|
384
|
+
});
|
|
385
|
+
|
|
386
|
+
program.addCommand(toolchainCommand);
|
|
387
|
+
|
|
331
388
|
program.parse();
|
package/commands/add.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import chalk from 'chalk';
|
|
3
|
-
import
|
|
3
|
+
import {createLogUpdate} from 'log-update';
|
|
4
4
|
import {checkConfigFile, getGithubCommit, parseGithubURL, readConfig, writeConfig} from '../mops.js';
|
|
5
5
|
import {getHighestVersion} from '../api/getHighestVersion.js';
|
|
6
6
|
import {installFromGithub} from '../vessel.js';
|
|
@@ -109,6 +109,8 @@ export async function add(name: string, {verbose = false, dev = false, lock}: Ad
|
|
|
109
109
|
|
|
110
110
|
writeConfig(config);
|
|
111
111
|
|
|
112
|
+
let logUpdate = createLogUpdate(process.stdout, {showCursor: true});
|
|
113
|
+
|
|
112
114
|
if (lock !== 'ignore') {
|
|
113
115
|
logUpdate('Checking integrity...');
|
|
114
116
|
}
|
|
@@ -2,9 +2,10 @@ import {execSync} from 'node:child_process';
|
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import fs from 'node:fs';
|
|
4
4
|
import {execaCommand} from 'execa';
|
|
5
|
-
import {PocketIc} from '
|
|
5
|
+
import {PocketIc} from 'pic-ic';
|
|
6
6
|
import {getRootDir} from '../mops.js';
|
|
7
7
|
import {createActor, idlFactory} from '../declarations/bench/index.js';
|
|
8
|
+
import {toolchain} from './toolchain/index.js';
|
|
8
9
|
|
|
9
10
|
export class BenchReplica {
|
|
10
11
|
type : 'dfx' | 'pocket-ic';
|
|
@@ -27,7 +28,8 @@ export class BenchReplica {
|
|
|
27
28
|
execSync('dfx start --background --clean --artificial-delay 0' + (this.verbose ? '' : ' -qqqq'), {cwd: dir, stdio: ['inherit', this.verbose ? 'inherit' : 'ignore', 'inherit']});
|
|
28
29
|
}
|
|
29
30
|
else {
|
|
30
|
-
|
|
31
|
+
let pocketIcBin = await toolchain.bin('pocket-ic');
|
|
32
|
+
this.pocketIc = await PocketIc.create(pocketIcBin);
|
|
31
33
|
}
|
|
32
34
|
}
|
|
33
35
|
|
|
@@ -37,7 +39,7 @@ export class BenchReplica {
|
|
|
37
39
|
execSync('dfx stop' + (this.verbose ? '' : ' -qqqq'), {cwd: dir, stdio: ['pipe', this.verbose ? 'inherit' : 'ignore', 'pipe']});
|
|
38
40
|
}
|
|
39
41
|
else if (this.pocketIc) {
|
|
40
|
-
this.pocketIc.tearDown();
|
|
42
|
+
await this.pocketIc.tearDown();
|
|
41
43
|
}
|
|
42
44
|
}
|
|
43
45
|
|
package/commands/docs.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {spawn
|
|
1
|
+
import {spawn} from 'node:child_process';
|
|
2
2
|
import fs from 'node:fs';
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import chalk from 'chalk';
|
|
@@ -8,8 +8,9 @@ import tar from 'tar';
|
|
|
8
8
|
import streamToPromise from 'stream-to-promise';
|
|
9
9
|
|
|
10
10
|
import {getRootDir} from '../mops.js';
|
|
11
|
+
import {toolchain} from './toolchain/index.js';
|
|
11
12
|
|
|
12
|
-
let
|
|
13
|
+
let moDocPath: string;
|
|
13
14
|
|
|
14
15
|
export async function docs({silent = false} = {}) {
|
|
15
16
|
let rootDir = getRootDir();
|
|
@@ -18,17 +19,19 @@ export async function docs({silent = false} = {}) {
|
|
|
18
19
|
|
|
19
20
|
deleteSync([docsDir], {force: true});
|
|
20
21
|
|
|
21
|
-
// detect mocv
|
|
22
|
+
// detect mocv (legacy)
|
|
22
23
|
if (process.env.DFX_MOC_PATH && process.env.DFX_MOC_PATH.includes('mocv/versions')) {
|
|
23
|
-
|
|
24
|
+
moDocPath = process.env.DFX_MOC_PATH.replace(/\/moc$/, '/mo-doc');
|
|
24
25
|
}
|
|
25
26
|
else {
|
|
26
|
-
|
|
27
|
+
// fallbacks to dfx moc if not specified in config
|
|
28
|
+
let mocPath = await toolchain.bin('moc');
|
|
29
|
+
moDocPath = mocPath.replace(/\/moc$/, '/mo-doc');
|
|
27
30
|
}
|
|
28
31
|
|
|
29
32
|
// generate docs
|
|
30
33
|
await new Promise<void>((resolve) => {
|
|
31
|
-
let proc = spawn(
|
|
34
|
+
let proc = spawn(moDocPath, [`--source=${path.join(rootDir, 'src')}`, `--output=${docsDirRelative}`, '--format=adoc']);
|
|
32
35
|
|
|
33
36
|
// stdout
|
|
34
37
|
proc.stdout.on('data', (data) => {
|
package/commands/install-all.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import chalk from 'chalk';
|
|
2
|
-
|
|
2
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
3
|
+
import {createLogUpdate} from 'log-update';
|
|
3
4
|
import {checkConfigFile, readConfig} from '../mops.js';
|
|
4
5
|
import {install} from './install.js';
|
|
5
6
|
import {installFromGithub} from '../vessel.js';
|
|
@@ -36,9 +37,13 @@ export async function installAll({verbose = false, silent = false, lock}: Instal
|
|
|
36
37
|
}
|
|
37
38
|
}
|
|
38
39
|
|
|
40
|
+
let logUpdate = createLogUpdate(process.stdout, {showCursor: true});
|
|
41
|
+
// let logUpdate = l;
|
|
42
|
+
|
|
39
43
|
if (!silent && lock !== 'ignore') {
|
|
40
44
|
logUpdate('Checking integrity...');
|
|
41
45
|
}
|
|
46
|
+
|
|
42
47
|
await Promise.all([
|
|
43
48
|
notifyInstalls(Object.keys(installedPackages)),
|
|
44
49
|
checkIntegrity(lock),
|
|
@@ -46,6 +51,6 @@ export async function installAll({verbose = false, silent = false, lock}: Instal
|
|
|
46
51
|
|
|
47
52
|
if (!silent) {
|
|
48
53
|
logUpdate.clear();
|
|
49
|
-
console.log(chalk.green('
|
|
54
|
+
console.log(chalk.green('Packages installed'));
|
|
50
55
|
}
|
|
51
56
|
}
|
package/commands/install.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import fs from 'node:fs';
|
|
3
|
-
import
|
|
3
|
+
import {createLogUpdate} from 'log-update';
|
|
4
4
|
import chalk from 'chalk';
|
|
5
5
|
import {checkConfigFile, formatDir, progressBar, readConfig} from '../mops.js';
|
|
6
6
|
import {getHighestVersion} from '../api/getHighestVersion.js';
|
|
@@ -14,6 +14,7 @@ export async function install(pkg: string, version = '', {verbose = false, silen
|
|
|
14
14
|
if (!checkConfigFile()) {
|
|
15
15
|
return false;
|
|
16
16
|
}
|
|
17
|
+
let logUpdate = createLogUpdate(process.stdout, {showCursor: true});
|
|
17
18
|
|
|
18
19
|
// progress
|
|
19
20
|
let total = Infinity;
|
|
@@ -89,6 +90,9 @@ export async function install(pkg: string, version = '', {verbose = false, silen
|
|
|
89
90
|
if (verbose) {
|
|
90
91
|
silent || logUpdate.done();
|
|
91
92
|
}
|
|
93
|
+
else {
|
|
94
|
+
logUpdate.clear();
|
|
95
|
+
}
|
|
92
96
|
|
|
93
97
|
// install dependencies
|
|
94
98
|
let ok = true;
|
package/commands/publish.ts
CHANGED
|
@@ -327,6 +327,8 @@ export async function publish(options: {docs?: boolean, test?: boolean} = {}) {
|
|
|
327
327
|
|
|
328
328
|
// finish
|
|
329
329
|
progress();
|
|
330
|
+
logUpdate.done();
|
|
331
|
+
|
|
330
332
|
let res = await actor.finishPublish(puiblishingId);
|
|
331
333
|
if ('err' in res) {
|
|
332
334
|
console.log(chalk.red('Error: ') + res.err);
|
package/commands/test/test.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {spawn,
|
|
1
|
+
import {spawn, ChildProcessWithoutNullStreams} from 'node:child_process';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import fs from 'node:fs';
|
|
4
4
|
import os from 'node:os';
|
|
@@ -8,7 +8,7 @@ import chokidar from 'chokidar';
|
|
|
8
8
|
import debounce from 'debounce';
|
|
9
9
|
|
|
10
10
|
import {sources} from '../sources.js';
|
|
11
|
-
import {getRootDir} from '../../mops.js';
|
|
11
|
+
import {getRootDir, readConfig} from '../../mops.js';
|
|
12
12
|
import {parallel} from '../../parallel.js';
|
|
13
13
|
|
|
14
14
|
import {MMF1} from './mmf1.js';
|
|
@@ -18,6 +18,7 @@ import {VerboseReporter} from './reporters/verbose-reporter.js';
|
|
|
18
18
|
import {FilesReporter} from './reporters/files-reporter.js';
|
|
19
19
|
import {CompactReporter} from './reporters/compact-reporter.js';
|
|
20
20
|
import {SilentReporter} from './reporters/silent-reporter.js';
|
|
21
|
+
import {toolchain} from '../toolchain/index.js';
|
|
21
22
|
|
|
22
23
|
let ignore = [
|
|
23
24
|
'**/node_modules/**',
|
|
@@ -70,7 +71,8 @@ export async function test(filter = '', {watch = false, reporter = 'verbose' as
|
|
|
70
71
|
}
|
|
71
72
|
}
|
|
72
73
|
|
|
73
|
-
let mocPath =
|
|
74
|
+
let mocPath = '';
|
|
75
|
+
let wasmtimePath = '';
|
|
74
76
|
|
|
75
77
|
export async function runAll(reporterName: ReporterName = 'verbose', filter = '', mode: TestMode = 'interpreter'): Promise<boolean> {
|
|
76
78
|
let reporter: Reporter;
|
|
@@ -116,10 +118,11 @@ export async function testWithReporter(reporter: Reporter, filter = '', mode: Te
|
|
|
116
118
|
|
|
117
119
|
reporter.addFiles(files);
|
|
118
120
|
|
|
121
|
+
let config = readConfig();
|
|
119
122
|
let sourcesArr = await sources();
|
|
120
123
|
|
|
121
124
|
if (!mocPath) {
|
|
122
|
-
mocPath =
|
|
125
|
+
mocPath = await toolchain.bin('moc');
|
|
123
126
|
}
|
|
124
127
|
|
|
125
128
|
let wasmDir = `${getRootDir()}/.mops/.test/`;
|
|
@@ -129,11 +132,20 @@ export async function testWithReporter(reporter: Reporter, filter = '', mode: Te
|
|
|
129
132
|
let mmf = new MMF1('store', absToRel(file));
|
|
130
133
|
let wasiMode = mode === 'wasi' || fs.readFileSync(file, 'utf8').startsWith('// @testmode wasi');
|
|
131
134
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
+
if (wasiMode && !wasmtimePath) {
|
|
136
|
+
// ensure wasmtime is installed or specified in config
|
|
137
|
+
if (config.toolchain?.wasmtime) {
|
|
138
|
+
wasmtimePath = await toolchain.bin('wasmtime');
|
|
139
|
+
}
|
|
140
|
+
// fallback wasmtime to global binary if not specified in config (legacy)
|
|
141
|
+
else {
|
|
142
|
+
wasmtimePath = 'wasmtime';
|
|
143
|
+
console.log(chalk.yellow('Warning:'), 'Wasmtime is not specified in config. Using global binary "wasmtime". This will be removed in the future.');
|
|
144
|
+
console.log(`Run ${chalk.green('mops toolchain use wasmtime')} or add ${chalk.green('wasmtime = "<version>"')} in mops.toml to avoid breaking changes with future versions of mops.`);
|
|
135
145
|
}
|
|
146
|
+
}
|
|
136
147
|
|
|
148
|
+
let promise = new Promise<void>((resolve) => {
|
|
137
149
|
let mocArgs = ['--hide-warnings', '--error-detail=2', ...sourcesArr.join(' ').split(' '), file].filter(x => x);
|
|
138
150
|
|
|
139
151
|
// build and run wasm
|
|
@@ -147,18 +159,29 @@ export async function testWithReporter(reporter: Reporter, filter = '', mode: Te
|
|
|
147
159
|
return;
|
|
148
160
|
}
|
|
149
161
|
// run
|
|
150
|
-
let
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
}
|
|
162
|
+
let wasmtimeArgs = [];
|
|
163
|
+
if (config.toolchain?.wasmtime && config.toolchain?.wasmtime >= '14.0.0') {
|
|
164
|
+
wasmtimeArgs = [
|
|
165
|
+
'-S', 'preview2=n',
|
|
166
|
+
'-C', 'cache=n',
|
|
167
|
+
'-W', 'bulk-memory',
|
|
168
|
+
'-W', 'multi-memory',
|
|
169
|
+
'-W', 'max-wasm-stack=2000000',
|
|
170
|
+
'-W', 'nan-canonicalization=y',
|
|
171
|
+
wasmFile,
|
|
172
|
+
];
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
wasmtimeArgs = [
|
|
176
|
+
'--max-wasm-stack=2000000',
|
|
177
|
+
'--enable-cranelift-nan-canonicalization',
|
|
178
|
+
'--wasm-features',
|
|
179
|
+
'multi-memory,bulk-memory',
|
|
180
|
+
wasmFile,
|
|
181
|
+
];
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
let proc = spawn(wasmtimePath, wasmtimeArgs);
|
|
162
185
|
await pipeMMF(proc, mmf);
|
|
163
186
|
}).finally(() => {
|
|
164
187
|
fs.rmSync(wasmFile, {force: true});
|