ic-mops 0.28.0 → 0.28.1
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/dist/commands/bench.d.ts +3 -0
- package/dist/commands/bench.js +130 -0
- package/dist/notify-installs.js +2 -2
- package/dist/package.json +1 -1
- package/notify-installs.ts +2 -2
- package/package.json +1 -1
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { execSync } from 'node:child_process';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import os from 'node:os';
|
|
5
|
+
// import chalk from 'chalk';
|
|
6
|
+
import { globSync } from 'glob';
|
|
7
|
+
// import chokidar from 'chokidar';
|
|
8
|
+
// import debounce from 'debounce';
|
|
9
|
+
// import {sources} from './sources.js';
|
|
10
|
+
import { getRootDir } from '../mops.js';
|
|
11
|
+
import { parallel } from '../parallel.js';
|
|
12
|
+
let ignore = [
|
|
13
|
+
'**/node_modules/**',
|
|
14
|
+
'**/.mops/**',
|
|
15
|
+
'**/.vessel/**',
|
|
16
|
+
'**/.git/**',
|
|
17
|
+
];
|
|
18
|
+
let globConfig = {
|
|
19
|
+
nocase: true,
|
|
20
|
+
ignore: ignore,
|
|
21
|
+
};
|
|
22
|
+
let mocPath = process.env.DFX_MOC_PATH;
|
|
23
|
+
export async function bench(filter = '', mode = 'replica') {
|
|
24
|
+
let rootDir = getRootDir();
|
|
25
|
+
let globStr = '**/bench?(mark)/**/*.bench.mo';
|
|
26
|
+
if (filter) {
|
|
27
|
+
globStr = `**/bench?(mark)/**/*${filter}*.mo`;
|
|
28
|
+
}
|
|
29
|
+
let files = globSync(path.join(rootDir, globStr), globConfig);
|
|
30
|
+
if (!files.length) {
|
|
31
|
+
if (filter) {
|
|
32
|
+
console.log(`No benchmark files found for filter '${filter}'`);
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
console.log('No *.bench.mo files found');
|
|
36
|
+
console.log('Put your benchmark files in \'bench\' directory in *.bench.mo files');
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
if (!mocPath) {
|
|
40
|
+
mocPath = execSync('dfx cache show').toString().trim() + '/moc';
|
|
41
|
+
}
|
|
42
|
+
let benchDir = `${getRootDir()}/.mops/.bench/`;
|
|
43
|
+
fs.mkdirSync(benchDir, { recursive: true });
|
|
44
|
+
console.log(files);
|
|
45
|
+
console.log('Running dfx replica...');
|
|
46
|
+
startDfx();
|
|
47
|
+
await parallel(os.cpus().length, files, async (file) => {
|
|
48
|
+
console.log(`Running ${file}...`);
|
|
49
|
+
await runBenchFile(file, mode);
|
|
50
|
+
});
|
|
51
|
+
console.log('Stopping dfx replica...');
|
|
52
|
+
stopDfx();
|
|
53
|
+
// fs.rmSync(benchDir, {recursive: true, force: true});
|
|
54
|
+
return true;
|
|
55
|
+
}
|
|
56
|
+
function dfxJson(canisterName) {
|
|
57
|
+
return {
|
|
58
|
+
version: 1,
|
|
59
|
+
canisters: {
|
|
60
|
+
[canisterName]: {
|
|
61
|
+
type: 'motoko',
|
|
62
|
+
main: 'canister.mo',
|
|
63
|
+
args: '--force-gc --generational-gc',
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
defaults: {
|
|
67
|
+
build: {
|
|
68
|
+
packtool: 'mops sources',
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
// networks: {
|
|
72
|
+
// local: {
|
|
73
|
+
// type: 'ephemeral',
|
|
74
|
+
// bind: '127.0.0.1:4941',
|
|
75
|
+
// },
|
|
76
|
+
// },
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
function startDfx() {
|
|
80
|
+
// stopDfx();
|
|
81
|
+
// let dir = path.join(getRootDir(), '.mops/.bench');
|
|
82
|
+
// fs.writeFileSync(path.join(dir, 'dfx.json'), JSON.stringify(dfxJson(''), null, 2));
|
|
83
|
+
// execSync('dfx start --background', {cwd: dir});
|
|
84
|
+
}
|
|
85
|
+
function stopDfx() {
|
|
86
|
+
// let dir = path.join(getRootDir(), '.mops/.bench');
|
|
87
|
+
// execSync('dfx stop', {cwd: dir});
|
|
88
|
+
}
|
|
89
|
+
async function runBenchFile(file, mode = 'replica') {
|
|
90
|
+
let tempDir = path.join(getRootDir(), '.mops/.bench/', path.parse(file).name);
|
|
91
|
+
fs.mkdirSync(tempDir, { recursive: true });
|
|
92
|
+
if (fs.readFileSync(file, 'utf8').startsWith('// @benchmode wasi')) {
|
|
93
|
+
mode = 'wasi';
|
|
94
|
+
}
|
|
95
|
+
if (!mocPath) {
|
|
96
|
+
mocPath = 'moc';
|
|
97
|
+
}
|
|
98
|
+
// replica mode
|
|
99
|
+
if (mode === 'replica') {
|
|
100
|
+
let canisterName = Date.now().toString(36);
|
|
101
|
+
fs.writeFileSync(path.join(tempDir, 'dfx.json'), JSON.stringify(dfxJson(canisterName), null, 2));
|
|
102
|
+
fs.cpSync(file, path.join(tempDir, 'canister.mo'));
|
|
103
|
+
execSync(`dfx deploy ${canisterName} --mode reinstall --yes`, { cwd: tempDir });
|
|
104
|
+
let res = execSync(`dfx canister call ${canisterName} run 1`, { cwd: tempDir });
|
|
105
|
+
console.log(res.toString());
|
|
106
|
+
}
|
|
107
|
+
// wasi mode
|
|
108
|
+
else if (mode === 'wasi') {
|
|
109
|
+
// let sourcesArr = await sources();
|
|
110
|
+
// let mocArgs = ['--hide-warnings', '--error-detail=2', ...sourcesArr.join(' ').split(' '), file].filter(x => x);
|
|
111
|
+
// let wasmFile = `${path.join(tempDir, path.parse(file).name)}.wasm`;
|
|
112
|
+
// // build
|
|
113
|
+
// let buildProc = spawn(mocPath, [`-o=${wasmFile}`, '-wasi-system-api', ...mocArgs]);
|
|
114
|
+
// buildProc.on('close', (code) => {
|
|
115
|
+
// if (code !== 0) {
|
|
116
|
+
// throw new Error(`unknown exit code: ${code}`);
|
|
117
|
+
// }
|
|
118
|
+
// resolve();
|
|
119
|
+
// });
|
|
120
|
+
// // run
|
|
121
|
+
// let proc = spawn('wasmtime', ['--max-wasm-stack=2000000', wasmFile]);
|
|
122
|
+
// proc.on('close', (code) => {
|
|
123
|
+
// if (code !== 0) {
|
|
124
|
+
// throw new Error(`unknown exit code: ${code}`);
|
|
125
|
+
// }
|
|
126
|
+
// resolve();
|
|
127
|
+
// });
|
|
128
|
+
// fs.rmSync(wasmFile, {force: true});
|
|
129
|
+
}
|
|
130
|
+
}
|
package/dist/notify-installs.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { mainActor } from './mops.js';
|
|
1
|
+
import { getDependencyType, mainActor } from './mops.js';
|
|
2
2
|
import { resolvePackages } from './resolve-packages.js';
|
|
3
3
|
export async function notifyInstalls(names) {
|
|
4
4
|
let resolvedPackages = await resolvePackages();
|
|
5
5
|
let packages = names.map(name => [name, resolvedPackages[name]]);
|
|
6
6
|
if (packages.length) {
|
|
7
7
|
let actor = await mainActor();
|
|
8
|
-
await actor.notifyInstalls(packages);
|
|
8
|
+
await actor.notifyInstalls(packages.filter(([_, version]) => getDependencyType(version) === 'mops'));
|
|
9
9
|
}
|
|
10
10
|
}
|
package/dist/package.json
CHANGED
package/notify-installs.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {mainActor} from './mops.js';
|
|
1
|
+
import {getDependencyType, mainActor} from './mops.js';
|
|
2
2
|
import {resolvePackages} from './resolve-packages.js';
|
|
3
3
|
|
|
4
4
|
export async function notifyInstalls(names: string[]) {
|
|
@@ -6,6 +6,6 @@ export async function notifyInstalls(names: string[]) {
|
|
|
6
6
|
let packages: [string, string][] = names.map(name => [name, resolvedPackages[name] as string]);
|
|
7
7
|
if (packages.length) {
|
|
8
8
|
let actor = await mainActor();
|
|
9
|
-
await actor.notifyInstalls(packages);
|
|
9
|
+
await actor.notifyInstalls(packages.filter(([_, version]) => getDependencyType(version) === 'mops'));
|
|
10
10
|
}
|
|
11
11
|
}
|