ic-mops 0.28.0-pre.1 → 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/commands/add.ts +1 -1
- package/commands/install-all.ts +1 -1
- package/commands/publish.ts +27 -5
- package/dist/commands/add.js +1 -1
- package/dist/commands/bench.d.ts +3 -0
- package/dist/commands/bench.js +130 -0
- package/dist/commands/install-all.js +1 -1
- package/dist/commands/publish.js +23 -5
- package/dist/notify-installs.js +5 -3
- package/dist/package.json +1 -1
- package/notify-installs.ts +5 -3
- package/package.json +1 -1
package/commands/add.ts
CHANGED
|
@@ -90,7 +90,7 @@ export async function add(name: string, {verbose = false, dev = false} = {}) {
|
|
|
90
90
|
}
|
|
91
91
|
|
|
92
92
|
writeConfig(config);
|
|
93
|
-
notifyInstalls(Object.keys(installedPackages));
|
|
93
|
+
await notifyInstalls(Object.keys(installedPackages));
|
|
94
94
|
|
|
95
95
|
logUpdate.clear();
|
|
96
96
|
console.log(chalk.green('Package installed ') + `${pkgDetails.name} = "${pkgDetails.repo || pkgDetails.path || pkgDetails.version}"`);
|
package/commands/install-all.ts
CHANGED
package/commands/publish.ts
CHANGED
|
@@ -233,6 +233,14 @@ export async function publish(options: {docs?: boolean, test?: boolean} = {}) {
|
|
|
233
233
|
// parse changelog
|
|
234
234
|
console.log('Parsing CHANGELOG.md...');
|
|
235
235
|
let changelog = parseChangelog(config.package.version);
|
|
236
|
+
if (!changelog && config.package.repository) {
|
|
237
|
+
console.log('Fetching release notes from GitHub...');
|
|
238
|
+
changelog = await fetchGitHubReleaseNotes(config.package.repository, config.package.version);
|
|
239
|
+
}
|
|
240
|
+
if (changelog) {
|
|
241
|
+
console.log('Changelog:');
|
|
242
|
+
console.log(chalk.gray(changelog));
|
|
243
|
+
}
|
|
236
244
|
|
|
237
245
|
// test
|
|
238
246
|
let reporter = new SilentReporter;
|
|
@@ -342,17 +350,31 @@ function parseChangelog(version: string): string {
|
|
|
342
350
|
let str = fs.readFileSync(changelogFile, 'utf-8');
|
|
343
351
|
let changelog = findChangelogEntry(str, version);
|
|
344
352
|
|
|
345
|
-
if (changelog) {
|
|
346
|
-
console.log('Changelog:');
|
|
347
|
-
console.log(chalk.gray(changelog));
|
|
348
|
-
}
|
|
349
|
-
else {
|
|
353
|
+
if (!changelog) {
|
|
350
354
|
console.log(chalk.yellow('No changelog entry found'));
|
|
351
355
|
}
|
|
352
356
|
|
|
353
357
|
return changelog || '';
|
|
354
358
|
}
|
|
355
359
|
|
|
360
|
+
async function fetchGitHubReleaseNotes(repo: string, version: string): Promise<string> {
|
|
361
|
+
let repoPath = new URL(repo).pathname;
|
|
362
|
+
let res = await fetch(`https://api.github.com/repos${repoPath}/releases/tags/${version}`);
|
|
363
|
+
let release = await res.json();
|
|
364
|
+
|
|
365
|
+
if (release.message === 'Not Found') {
|
|
366
|
+
res = await fetch(`https://api.github.com/repos${repoPath}/releases/tags/v${version}`);
|
|
367
|
+
release = await res.json();
|
|
368
|
+
|
|
369
|
+
if (release.message === 'Not Found') {
|
|
370
|
+
console.log(chalk.yellow(`No GitHub release found with name ${version} or v${version}`));
|
|
371
|
+
return '';
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
return release.body;
|
|
376
|
+
}
|
|
377
|
+
|
|
356
378
|
function findChangelogEntry(changelog: string, version: string): string {
|
|
357
379
|
let tree = fromMarkdown(changelog);
|
|
358
380
|
let found = false;
|
package/dist/commands/add.js
CHANGED
|
@@ -80,7 +80,7 @@ export async function add(name, { verbose = false, dev = false } = {}) {
|
|
|
80
80
|
throw Error(`Invalid config file: [${depsProp}] not found`);
|
|
81
81
|
}
|
|
82
82
|
writeConfig(config);
|
|
83
|
-
notifyInstalls(Object.keys(installedPackages));
|
|
83
|
+
await notifyInstalls(Object.keys(installedPackages));
|
|
84
84
|
logUpdate.clear();
|
|
85
85
|
console.log(chalk.green('Package installed ') + `${pkgDetails.name} = "${pkgDetails.repo || pkgDetails.path || pkgDetails.version}"`);
|
|
86
86
|
}
|
|
@@ -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
|
+
}
|
|
@@ -25,7 +25,7 @@ export async function installAll({ verbose = false, silent = false } = {}) {
|
|
|
25
25
|
installedPackages = { ...installedPackages, ...res };
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
|
-
notifyInstalls(Object.keys(installedPackages));
|
|
28
|
+
await notifyInstalls(Object.keys(installedPackages));
|
|
29
29
|
if (!silent) {
|
|
30
30
|
logUpdate.clear();
|
|
31
31
|
console.log(chalk.green('All packages installed'));
|
package/dist/commands/publish.js
CHANGED
|
@@ -208,6 +208,14 @@ export async function publish(options = {}) {
|
|
|
208
208
|
// parse changelog
|
|
209
209
|
console.log('Parsing CHANGELOG.md...');
|
|
210
210
|
let changelog = parseChangelog(config.package.version);
|
|
211
|
+
if (!changelog && config.package.repository) {
|
|
212
|
+
console.log('Fetching release notes from GitHub...');
|
|
213
|
+
changelog = await fetchGitHubReleaseNotes(config.package.repository, config.package.version);
|
|
214
|
+
}
|
|
215
|
+
if (changelog) {
|
|
216
|
+
console.log('Changelog:');
|
|
217
|
+
console.log(chalk.gray(changelog));
|
|
218
|
+
}
|
|
211
219
|
// test
|
|
212
220
|
let reporter = new SilentReporter;
|
|
213
221
|
if (options.test) {
|
|
@@ -298,15 +306,25 @@ function parseChangelog(version) {
|
|
|
298
306
|
}
|
|
299
307
|
let str = fs.readFileSync(changelogFile, 'utf-8');
|
|
300
308
|
let changelog = findChangelogEntry(str, version);
|
|
301
|
-
if (changelog) {
|
|
302
|
-
console.log('Changelog:');
|
|
303
|
-
console.log(chalk.gray(changelog));
|
|
304
|
-
}
|
|
305
|
-
else {
|
|
309
|
+
if (!changelog) {
|
|
306
310
|
console.log(chalk.yellow('No changelog entry found'));
|
|
307
311
|
}
|
|
308
312
|
return changelog || '';
|
|
309
313
|
}
|
|
314
|
+
async function fetchGitHubReleaseNotes(repo, version) {
|
|
315
|
+
let repoPath = new URL(repo).pathname;
|
|
316
|
+
let res = await fetch(`https://api.github.com/repos${repoPath}/releases/tags/${version}`);
|
|
317
|
+
let release = await res.json();
|
|
318
|
+
if (release.message === 'Not Found') {
|
|
319
|
+
res = await fetch(`https://api.github.com/repos${repoPath}/releases/tags/v${version}`);
|
|
320
|
+
release = await res.json();
|
|
321
|
+
if (release.message === 'Not Found') {
|
|
322
|
+
console.log(chalk.yellow(`No GitHub release found with name ${version} or v${version}`));
|
|
323
|
+
return '';
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
return release.body;
|
|
327
|
+
}
|
|
310
328
|
function findChangelogEntry(changelog, version) {
|
|
311
329
|
let tree = fromMarkdown(changelog);
|
|
312
330
|
let found = false;
|
package/dist/notify-installs.js
CHANGED
|
@@ -1,8 +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
|
-
let actor = await mainActor();
|
|
5
4
|
let resolvedPackages = await resolvePackages();
|
|
6
5
|
let packages = names.map(name => [name, resolvedPackages[name]]);
|
|
7
|
-
|
|
6
|
+
if (packages.length) {
|
|
7
|
+
let actor = await mainActor();
|
|
8
|
+
await actor.notifyInstalls(packages.filter(([_, version]) => getDependencyType(version) === 'mops'));
|
|
9
|
+
}
|
|
8
10
|
}
|
package/dist/package.json
CHANGED
package/notify-installs.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
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[]) {
|
|
5
|
-
let actor = await mainActor();
|
|
6
5
|
let resolvedPackages = await resolvePackages();
|
|
7
6
|
let packages: [string, string][] = names.map(name => [name, resolvedPackages[name] as string]);
|
|
8
|
-
|
|
7
|
+
if (packages.length) {
|
|
8
|
+
let actor = await mainActor();
|
|
9
|
+
await actor.notifyInstalls(packages.filter(([_, version]) => getDependencyType(version) === 'mops'));
|
|
10
|
+
}
|
|
9
11
|
}
|