ic-mops 0.30.0 → 0.31.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 +12 -3
- package/commands/install.ts +2 -2
- package/commands/update.ts +30 -2
- package/dist/commands/add.js +11 -3
- package/dist/commands/install.js +2 -2
- package/dist/commands/update.js +27 -2
- package/dist/mops.d.ts +4 -2
- package/dist/mops.js +18 -4
- package/dist/package.json +1 -1
- package/dist/vessel.js +10 -10
- package/mops.ts +19 -5
- package/package.json +1 -1
- package/vessel.ts +10 -10
- package/dist/bench/$USER_BENCH_FILE.mo +0 -45
- package/dist/bench/bench-canister.mo +0 -57
- package/dist/commands/bench/$USER_BENCH_FILE.mo +0 -45
- package/dist/commands/bench/bench/$USER_BENCH_FILE.mo +0 -45
- package/dist/commands/bench/bench/bench-canister.mo +0 -57
- package/dist/commands/bench/bench-canister.mo +0 -85
- package/dist/commands/bench/declarations/bench/bench.did.d.ts +0 -6
- package/dist/commands/bench/declarations/bench/bench.did.js +0 -22
- package/dist/commands/bench/declarations/bench/index.d.ts +0 -2
- package/dist/commands/bench/declarations/bench/index.js +0 -30
- package/dist/commands/bench/declarations/main/index.d.ts +0 -2
- package/dist/commands/bench/declarations/main/index.js +0 -30
- package/dist/commands/bench/declarations/main/main.did.d.ts +0 -6
- package/dist/commands/bench/declarations/main/main.did.js +0 -242
- package/dist/commands/bench/declarations/storage/index.d.ts +0 -4
- package/dist/commands/bench/declarations/storage/index.js +0 -26
- package/dist/commands/bench/declarations/storage/storage.did.d.ts +0 -6
- package/dist/commands/bench/declarations/storage/storage.did.js +0 -34
- package/dist/commands/bench/user-bench.mo +0 -14
- package/dist/commands/bench.d.ts +0 -10
- package/dist/commands/bench.js +0 -214
- package/dist/commands/mmf1.d.ts +0 -21
- package/dist/commands/mmf1.js +0 -93
- package/dist/commands/test/reporter-files.d.ts +0 -10
- package/dist/commands/test/reporter-files.js +0 -48
- package/dist/commands/test/reporter-verbose.d.ts +0 -10
- package/dist/commands/test/reporter-verbose.js +0 -56
- package/dist/commands/test.d.ts +0 -4
- package/dist/commands/test.js +0 -186
- package/dist/declarations/bench/bench.did +0 -24
- package/dist/declarations/bench/bench.did.d.ts +0 -24
- package/dist/declarations/bench/bench.did.js +0 -24
- package/dist/declarations/bench/index.d.ts +0 -50
- package/dist/declarations/bench/index.js +0 -41
- package/dist/helpers/get-dfx-version.d.ts +0 -1
- package/dist/helpers/get-dfx-version.js +0 -9
- package/dist/helpers/get-moc-path.d.ts +0 -1
- package/dist/helpers/get-moc-path.js +0 -11
- package/dist/helpers/get-moc-version.d.ts +0 -1
- package/dist/helpers/get-moc-version.js +0 -7
- package/dist/out/cli.d.ts +0 -2
- package/dist/out/cli.js +0 -114581
- package/dist/parse-changelog.d.ts +0 -1
- package/dist/parse-changelog.js +0 -1435
- package/dist/test.d.ts +0 -1
- package/dist/test.js +0 -1411
package/commands/add.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import chalk from 'chalk';
|
|
3
3
|
import logUpdate from 'log-update';
|
|
4
|
-
import {checkConfigFile, getHighestVersion, parseGithubURL, readConfig, writeConfig} from '../mops.js';
|
|
4
|
+
import {checkConfigFile, getGithubCommit, getHighestVersion, parseGithubURL, readConfig, writeConfig} from '../mops.js';
|
|
5
5
|
import {installFromGithub} from '../vessel.js';
|
|
6
6
|
import {install} from './install.js';
|
|
7
7
|
import {notifyInstalls} from '../notify-installs.js';
|
|
@@ -36,11 +36,20 @@ export async function add(name: string, {verbose = false, dev = false} = {}) {
|
|
|
36
36
|
}
|
|
37
37
|
// github package
|
|
38
38
|
else if (name.startsWith('https://github.com') || name.split('/').length > 1) {
|
|
39
|
-
|
|
39
|
+
let {org, gitName, branch, commitHash} = parseGithubURL(name);
|
|
40
|
+
|
|
41
|
+
// fetch latest commit hash of branch if not specified
|
|
42
|
+
if (!commitHash) {
|
|
43
|
+
let commit = await getGithubCommit(`${org}/${gitName}`, branch);
|
|
44
|
+
if (!commit.sha) {
|
|
45
|
+
throw Error(`Could not find commit hash for ${name}`);
|
|
46
|
+
}
|
|
47
|
+
commitHash = commit.sha;
|
|
48
|
+
}
|
|
40
49
|
|
|
41
50
|
pkgDetails = {
|
|
42
51
|
name: parseGithubURL(name).gitName,
|
|
43
|
-
repo: `https://github.com/${org}/${gitName}#${branch}`,
|
|
52
|
+
repo: `https://github.com/${org}/${gitName}#${branch}@${commitHash}`,
|
|
44
53
|
version: '',
|
|
45
54
|
};
|
|
46
55
|
}
|
package/commands/install.ts
CHANGED
|
@@ -36,13 +36,13 @@ export async function install(pkg: string, version = '', {verbose = false, silen
|
|
|
36
36
|
|
|
37
37
|
// already installed
|
|
38
38
|
if (fs.existsSync(dir)) {
|
|
39
|
-
silent || logUpdate(`${dep ? 'Dependency' : 'Installing'} ${pkg}@${version} (
|
|
39
|
+
silent || logUpdate(`${dep ? 'Dependency' : 'Installing'} ${pkg}@${version} (local cache)`);
|
|
40
40
|
alreadyInstalled = true;
|
|
41
41
|
}
|
|
42
42
|
// copy from cache
|
|
43
43
|
else if (isCached(`${pkg}@${version}`)) {
|
|
44
44
|
await copyCache(`${pkg}@${version}`, dir);
|
|
45
|
-
silent || logUpdate(`${dep ? 'Dependency' : 'Installing'} ${pkg}@${version} (cache)`);
|
|
45
|
+
silent || logUpdate(`${dep ? 'Dependency' : 'Installing'} ${pkg}@${version} (global cache)`);
|
|
46
46
|
}
|
|
47
47
|
// download
|
|
48
48
|
else {
|
package/commands/update.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import chalk from 'chalk';
|
|
2
|
-
import {checkConfigFile, readConfig} from '../mops.js';
|
|
2
|
+
import {checkConfigFile, getGithubCommit, parseGithubURL, readConfig} from '../mops.js';
|
|
3
3
|
import {add} from './add.js';
|
|
4
4
|
import {getAvailableUpdates} from './available-updates.js';
|
|
5
5
|
|
|
@@ -9,10 +9,38 @@ export async function update(pkg?: string) {
|
|
|
9
9
|
}
|
|
10
10
|
let config = readConfig();
|
|
11
11
|
|
|
12
|
+
if (pkg && !config.dependencies?.[pkg] && !config['dev-dependencies']?.[pkg]) {
|
|
13
|
+
console.log(chalk.red(`Package "${pkg}" is not installed!`));
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// update github packages
|
|
18
|
+
let deps = Object.values(config.dependencies || {});
|
|
19
|
+
let devDeps = Object.values(config['dev-dependencies'] || {});
|
|
20
|
+
let githubDeps = [...deps, ...devDeps].filter((dep) => dep.repo);
|
|
21
|
+
if (pkg) {
|
|
22
|
+
githubDeps = githubDeps.filter((dep) => dep.name === pkg);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
for (let dep of githubDeps) {
|
|
26
|
+
let {org, gitName, branch, commitHash} = parseGithubURL(dep.repo || '');
|
|
27
|
+
let dev = !!config['dev-dependencies']?.[dep.name];
|
|
28
|
+
let commit = await getGithubCommit(`${org}/${gitName}`, branch);
|
|
29
|
+
if (commit.sha !== commitHash) {
|
|
30
|
+
await add(`https://github.com/${org}/${gitName}#${branch}@${commit.sha}`, {dev});
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// update mops packages
|
|
12
35
|
let available = await getAvailableUpdates(config, pkg);
|
|
13
36
|
|
|
14
37
|
if (available.length === 0) {
|
|
15
|
-
|
|
38
|
+
if (pkg) {
|
|
39
|
+
console.log(chalk.green(`Package "${pkg}" is up to date!`));
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
console.log(chalk.green('All dependencies are up to date!'));
|
|
43
|
+
}
|
|
16
44
|
}
|
|
17
45
|
else {
|
|
18
46
|
for (let dep of available) {
|
package/dist/commands/add.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import chalk from 'chalk';
|
|
3
3
|
import logUpdate from 'log-update';
|
|
4
|
-
import { checkConfigFile, getHighestVersion, parseGithubURL, readConfig, writeConfig } from '../mops.js';
|
|
4
|
+
import { checkConfigFile, getGithubCommit, getHighestVersion, parseGithubURL, readConfig, writeConfig } from '../mops.js';
|
|
5
5
|
import { installFromGithub } from '../vessel.js';
|
|
6
6
|
import { install } from './install.js';
|
|
7
7
|
import { notifyInstalls } from '../notify-installs.js';
|
|
@@ -32,10 +32,18 @@ export async function add(name, { verbose = false, dev = false } = {}) {
|
|
|
32
32
|
}
|
|
33
33
|
// github package
|
|
34
34
|
else if (name.startsWith('https://github.com') || name.split('/').length > 1) {
|
|
35
|
-
|
|
35
|
+
let { org, gitName, branch, commitHash } = parseGithubURL(name);
|
|
36
|
+
// fetch latest commit hash of branch if not specified
|
|
37
|
+
if (!commitHash) {
|
|
38
|
+
let commit = await getGithubCommit(`${org}/${gitName}`, branch);
|
|
39
|
+
if (!commit.sha) {
|
|
40
|
+
throw Error(`Could not find commit hash for ${name}`);
|
|
41
|
+
}
|
|
42
|
+
commitHash = commit.sha;
|
|
43
|
+
}
|
|
36
44
|
pkgDetails = {
|
|
37
45
|
name: parseGithubURL(name).gitName,
|
|
38
|
-
repo: `https://github.com/${org}/${gitName}#${branch}`,
|
|
46
|
+
repo: `https://github.com/${org}/${gitName}#${branch}@${commitHash}`,
|
|
39
47
|
version: '',
|
|
40
48
|
};
|
|
41
49
|
}
|
package/dist/commands/install.js
CHANGED
|
@@ -31,13 +31,13 @@ export async function install(pkg, version = '', { verbose = false, silent = fal
|
|
|
31
31
|
let alreadyInstalled = false;
|
|
32
32
|
// already installed
|
|
33
33
|
if (fs.existsSync(dir)) {
|
|
34
|
-
silent || logUpdate(`${dep ? 'Dependency' : 'Installing'} ${pkg}@${version} (
|
|
34
|
+
silent || logUpdate(`${dep ? 'Dependency' : 'Installing'} ${pkg}@${version} (local cache)`);
|
|
35
35
|
alreadyInstalled = true;
|
|
36
36
|
}
|
|
37
37
|
// copy from cache
|
|
38
38
|
else if (isCached(`${pkg}@${version}`)) {
|
|
39
39
|
await copyCache(`${pkg}@${version}`, dir);
|
|
40
|
-
silent || logUpdate(`${dep ? 'Dependency' : 'Installing'} ${pkg}@${version} (cache)`);
|
|
40
|
+
silent || logUpdate(`${dep ? 'Dependency' : 'Installing'} ${pkg}@${version} (global cache)`);
|
|
41
41
|
}
|
|
42
42
|
// download
|
|
43
43
|
else {
|
package/dist/commands/update.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import chalk from 'chalk';
|
|
2
|
-
import { checkConfigFile, readConfig } from '../mops.js';
|
|
2
|
+
import { checkConfigFile, getGithubCommit, parseGithubURL, readConfig } from '../mops.js';
|
|
3
3
|
import { add } from './add.js';
|
|
4
4
|
import { getAvailableUpdates } from './available-updates.js';
|
|
5
5
|
export async function update(pkg) {
|
|
@@ -7,9 +7,34 @@ export async function update(pkg) {
|
|
|
7
7
|
return;
|
|
8
8
|
}
|
|
9
9
|
let config = readConfig();
|
|
10
|
+
if (pkg && !config.dependencies?.[pkg] && !config['dev-dependencies']?.[pkg]) {
|
|
11
|
+
console.log(chalk.red(`Package "${pkg}" is not installed!`));
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
// update github packages
|
|
15
|
+
let deps = Object.values(config.dependencies || {});
|
|
16
|
+
let devDeps = Object.values(config['dev-dependencies'] || {});
|
|
17
|
+
let githubDeps = [...deps, ...devDeps].filter((dep) => dep.repo);
|
|
18
|
+
if (pkg) {
|
|
19
|
+
githubDeps = githubDeps.filter((dep) => dep.name === pkg);
|
|
20
|
+
}
|
|
21
|
+
for (let dep of githubDeps) {
|
|
22
|
+
let { org, gitName, branch, commitHash } = parseGithubURL(dep.repo || '');
|
|
23
|
+
let dev = !!config['dev-dependencies']?.[dep.name];
|
|
24
|
+
let commit = await getGithubCommit(`${org}/${gitName}`, branch);
|
|
25
|
+
if (commit.sha !== commitHash) {
|
|
26
|
+
await add(`https://github.com/${org}/${gitName}#${branch}@${commit.sha}`, { dev });
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
// update mops packages
|
|
10
30
|
let available = await getAvailableUpdates(config, pkg);
|
|
11
31
|
if (available.length === 0) {
|
|
12
|
-
|
|
32
|
+
if (pkg) {
|
|
33
|
+
console.log(chalk.green(`Package "${pkg}" is up to date!`));
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
console.log(chalk.green('All dependencies are up to date!'));
|
|
37
|
+
}
|
|
13
38
|
}
|
|
14
39
|
else {
|
|
15
40
|
for (let dep of available) {
|
package/dist/mops.d.ts
CHANGED
|
@@ -21,10 +21,12 @@ export declare function checkConfigFile(): boolean;
|
|
|
21
21
|
export declare function progressBar(step: number, total: number): string;
|
|
22
22
|
export declare function getHighestVersion(pkgName: string): Promise<import("./declarations/main/main.did.js").Result_5>;
|
|
23
23
|
export declare function parseGithubURL(href: string): {
|
|
24
|
-
org: string
|
|
25
|
-
gitName: string
|
|
24
|
+
org: string;
|
|
25
|
+
gitName: string;
|
|
26
26
|
branch: string;
|
|
27
|
+
commitHash: string;
|
|
27
28
|
};
|
|
29
|
+
export declare function getGithubCommit(repo: string, ref: string): Promise<any>;
|
|
28
30
|
export declare function getDependencyType(version: string): "mops" | "github" | "local";
|
|
29
31
|
export declare function readConfig(configFile?: string): Config;
|
|
30
32
|
export declare function writeConfig(config: Config, configFile?: string): void;
|
package/dist/mops.js
CHANGED
|
@@ -179,12 +179,26 @@ export async function getHighestVersion(pkgName) {
|
|
|
179
179
|
}
|
|
180
180
|
export function parseGithubURL(href) {
|
|
181
181
|
const url = new URL(href);
|
|
182
|
-
|
|
182
|
+
let branchAndSha = url.hash?.substring(1).split('@');
|
|
183
|
+
let branch = branchAndSha[0] || 'master';
|
|
184
|
+
let commitHash = branchAndSha[1] || '';
|
|
183
185
|
let [org, gitName] = url.pathname.split('/').filter(path => !!path);
|
|
186
|
+
org = org || '';
|
|
187
|
+
gitName = gitName || '';
|
|
184
188
|
if (gitName?.endsWith('.git')) {
|
|
185
189
|
gitName = gitName.substring(0, gitName.length - 4);
|
|
186
190
|
}
|
|
187
|
-
return { org, gitName, branch };
|
|
191
|
+
return { org, gitName, branch, commitHash };
|
|
192
|
+
}
|
|
193
|
+
export async function getGithubCommit(repo, ref) {
|
|
194
|
+
let res = await fetch(`https://api.github.com/repos/${repo}/commits/${ref}`);
|
|
195
|
+
let json = await res.json();
|
|
196
|
+
// try on main branch
|
|
197
|
+
if (json.message && ref === 'master') {
|
|
198
|
+
res = await fetch(`https://api.github.com/repos/${repo}/commits/main`);
|
|
199
|
+
json = await res.json();
|
|
200
|
+
}
|
|
201
|
+
return json;
|
|
188
202
|
}
|
|
189
203
|
export function getDependencyType(version) {
|
|
190
204
|
if (!version || typeof version !== 'string') {
|
|
@@ -244,8 +258,8 @@ export function formatDir(name, version) {
|
|
|
244
258
|
return path.join(getRootDir(), '.mops', `${name}@${version}`);
|
|
245
259
|
}
|
|
246
260
|
export function formatGithubDir(name, repo) {
|
|
247
|
-
const { branch } = parseGithubURL(repo);
|
|
248
|
-
return path.join(getRootDir(), '.mops/_github', `${name}
|
|
261
|
+
const { branch, commitHash } = parseGithubURL(repo);
|
|
262
|
+
return path.join(getRootDir(), '.mops/_github', `${name}#${branch}` + (commitHash ? `@${commitHash}` : ''));
|
|
249
263
|
}
|
|
250
264
|
export function readDfxJson() {
|
|
251
265
|
let dir = process.cwd();
|
package/dist/package.json
CHANGED
package/dist/vessel.js
CHANGED
|
@@ -59,8 +59,8 @@ export const readVesselConfig = async (dir, { cache = true } = {}) => {
|
|
|
59
59
|
return config;
|
|
60
60
|
};
|
|
61
61
|
export const downloadFromGithub = async (repo, dest, onProgress) => {
|
|
62
|
-
const { branch, org, gitName } = parseGithubURL(repo);
|
|
63
|
-
const zipFile = `https://github.com/${org}/${gitName}/archive/${branch}.zip`;
|
|
62
|
+
const { branch, org, gitName, commitHash } = parseGithubURL(repo);
|
|
63
|
+
const zipFile = `https://github.com/${org}/${gitName}/archive/${commitHash || branch}.zip`;
|
|
64
64
|
const readStream = got.stream(zipFile);
|
|
65
65
|
const promise = new Promise((resolve, reject) => {
|
|
66
66
|
readStream.on('error', (err) => {
|
|
@@ -71,7 +71,7 @@ export const downloadFromGithub = async (repo, dest, onProgress) => {
|
|
|
71
71
|
});
|
|
72
72
|
readStream.on('response', (response) => {
|
|
73
73
|
if (response.headers.age > 3600) {
|
|
74
|
-
console.
|
|
74
|
+
console.error(chalk.red('Error: ') + 'Failure - response too old');
|
|
75
75
|
readStream.destroy(); // Destroy the stream to prevent hanging resources.
|
|
76
76
|
reject();
|
|
77
77
|
return;
|
|
@@ -79,7 +79,7 @@ export const downloadFromGithub = async (repo, dest, onProgress) => {
|
|
|
79
79
|
// Prevent `onError` being called twice.
|
|
80
80
|
readStream.off('error', reject);
|
|
81
81
|
const tmpDir = path.resolve(process.cwd(), '.mops/_tmp/');
|
|
82
|
-
const tmpFile = path.resolve(tmpDir, `${gitName}@${branch}.zip`);
|
|
82
|
+
const tmpFile = path.resolve(tmpDir, `${gitName}@${commitHash || branch}.zip`);
|
|
83
83
|
try {
|
|
84
84
|
mkdirSync(tmpDir, { recursive: true });
|
|
85
85
|
pipeline(readStream, createWriteStream(tmpFile), (err) => {
|
|
@@ -114,20 +114,20 @@ export const downloadFromGithub = async (repo, dest, onProgress) => {
|
|
|
114
114
|
return promise;
|
|
115
115
|
};
|
|
116
116
|
export const installFromGithub = async (name, repo, { verbose = false, dep = false, silent = false } = {}) => {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
117
|
+
let { branch, commitHash } = parseGithubURL(repo);
|
|
118
|
+
let dir = formatGithubDir(name, repo);
|
|
119
|
+
let cacheName = `_github/${name}#${branch}` + (commitHash ? `@${commitHash}` : '');
|
|
120
120
|
if (existsSync(dir)) {
|
|
121
|
-
silent || logUpdate(`${dep ? 'Dependency' : 'Installing'} ${
|
|
121
|
+
silent || logUpdate(`${dep ? 'Dependency' : 'Installing'} ${repo} (local cache) from Github`);
|
|
122
122
|
}
|
|
123
123
|
else if (isCached(cacheName)) {
|
|
124
124
|
await copyCache(cacheName, dir);
|
|
125
|
-
silent || logUpdate(`${dep ? 'Dependency' : 'Installing'} ${
|
|
125
|
+
silent || logUpdate(`${dep ? 'Dependency' : 'Installing'} ${repo} (global cache) from Github`);
|
|
126
126
|
}
|
|
127
127
|
else {
|
|
128
128
|
mkdirSync(dir, { recursive: true });
|
|
129
129
|
let progress = (step, total) => {
|
|
130
|
-
silent || logUpdate(`${dep ? 'Dependency' : 'Installing'} ${
|
|
130
|
+
silent || logUpdate(`${dep ? 'Dependency' : 'Installing'} ${repo} ${progressBar(step, total)}`);
|
|
131
131
|
};
|
|
132
132
|
progress(0, 2 * (1024 ** 2));
|
|
133
133
|
try {
|
package/mops.ts
CHANGED
|
@@ -210,15 +210,29 @@ export async function getHighestVersion(pkgName: string) {
|
|
|
210
210
|
|
|
211
211
|
export function parseGithubURL(href: string) {
|
|
212
212
|
const url = new URL(href);
|
|
213
|
-
|
|
214
|
-
|
|
213
|
+
let branchAndSha = url.hash?.substring(1).split('@');
|
|
214
|
+
let branch = branchAndSha[0] || 'master';
|
|
215
|
+
let commitHash = branchAndSha[1] || '';
|
|
215
216
|
let [org, gitName] = url.pathname.split('/').filter(path => !!path);
|
|
217
|
+
org = org || '';
|
|
218
|
+
gitName = gitName || '';
|
|
216
219
|
|
|
217
220
|
if (gitName?.endsWith('.git')) {
|
|
218
221
|
gitName = gitName.substring(0, gitName.length - 4);
|
|
219
222
|
}
|
|
223
|
+
return {org, gitName, branch, commitHash};
|
|
224
|
+
}
|
|
220
225
|
|
|
221
|
-
|
|
226
|
+
export async function getGithubCommit(repo: string, ref: string): Promise<any> {
|
|
227
|
+
let res = await fetch(`https://api.github.com/repos/${repo}/commits/${ref}`);
|
|
228
|
+
let json: any = await res.json();
|
|
229
|
+
|
|
230
|
+
// try on main branch
|
|
231
|
+
if (json.message && ref === 'master') {
|
|
232
|
+
res = await fetch(`https://api.github.com/repos/${repo}/commits/main`);
|
|
233
|
+
json = await res.json();
|
|
234
|
+
}
|
|
235
|
+
return json;
|
|
222
236
|
}
|
|
223
237
|
|
|
224
238
|
export function getDependencyType(version: string) {
|
|
@@ -289,8 +303,8 @@ export function formatDir(name: string, version: string) {
|
|
|
289
303
|
}
|
|
290
304
|
|
|
291
305
|
export function formatGithubDir(name: string, repo: string) {
|
|
292
|
-
const {branch} = parseGithubURL(repo);
|
|
293
|
-
return path.join(getRootDir(), '.mops/_github', `${name}
|
|
306
|
+
const {branch, commitHash} = parseGithubURL(repo);
|
|
307
|
+
return path.join(getRootDir(), '.mops/_github', `${name}#${branch}` + (commitHash ? `@${commitHash}` : ''));
|
|
294
308
|
}
|
|
295
309
|
|
|
296
310
|
export function readDfxJson(): any {
|
package/package.json
CHANGED
package/vessel.ts
CHANGED
|
@@ -83,9 +83,9 @@ export const readVesselConfig = async (dir: string, {cache = true} = {}): Promis
|
|
|
83
83
|
};
|
|
84
84
|
|
|
85
85
|
export const downloadFromGithub = async (repo: string, dest: string, onProgress: any) => {
|
|
86
|
-
const {branch, org, gitName} = parseGithubURL(repo);
|
|
86
|
+
const {branch, org, gitName, commitHash} = parseGithubURL(repo);
|
|
87
87
|
|
|
88
|
-
const zipFile = `https://github.com/${org}/${gitName}/archive/${branch}.zip`;
|
|
88
|
+
const zipFile = `https://github.com/${org}/${gitName}/archive/${commitHash || branch}.zip`;
|
|
89
89
|
const readStream = got.stream(zipFile);
|
|
90
90
|
|
|
91
91
|
const promise = new Promise((resolve, reject) => {
|
|
@@ -99,7 +99,7 @@ export const downloadFromGithub = async (repo: string, dest: string, onProgress:
|
|
|
99
99
|
|
|
100
100
|
readStream.on('response', (response) => {
|
|
101
101
|
if (response.headers.age > 3600) {
|
|
102
|
-
console.
|
|
102
|
+
console.error(chalk.red('Error: ') + 'Failure - response too old');
|
|
103
103
|
readStream.destroy(); // Destroy the stream to prevent hanging resources.
|
|
104
104
|
reject();
|
|
105
105
|
return;
|
|
@@ -108,7 +108,7 @@ export const downloadFromGithub = async (repo: string, dest: string, onProgress:
|
|
|
108
108
|
// Prevent `onError` being called twice.
|
|
109
109
|
readStream.off('error', reject);
|
|
110
110
|
const tmpDir = path.resolve(process.cwd(), '.mops/_tmp/');
|
|
111
|
-
const tmpFile = path.resolve(tmpDir, `${gitName}@${branch}.zip`);
|
|
111
|
+
const tmpFile = path.resolve(tmpDir, `${gitName}@${commitHash || branch}.zip`);
|
|
112
112
|
|
|
113
113
|
try {
|
|
114
114
|
mkdirSync(tmpDir, {recursive: true});
|
|
@@ -147,22 +147,22 @@ export const downloadFromGithub = async (repo: string, dest: string, onProgress:
|
|
|
147
147
|
};
|
|
148
148
|
|
|
149
149
|
export const installFromGithub = async (name: string, repo: string, {verbose = false, dep = false, silent = false} = {}) => {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
150
|
+
let {branch, commitHash} = parseGithubURL(repo);
|
|
151
|
+
let dir = formatGithubDir(name, repo);
|
|
152
|
+
let cacheName = `_github/${name}#${branch}` + (commitHash ? `@${commitHash}` : '');
|
|
153
153
|
|
|
154
154
|
if (existsSync(dir)) {
|
|
155
|
-
silent || logUpdate(`${dep ? 'Dependency' : 'Installing'} ${
|
|
155
|
+
silent || logUpdate(`${dep ? 'Dependency' : 'Installing'} ${repo} (local cache) from Github`);
|
|
156
156
|
}
|
|
157
157
|
else if (isCached(cacheName)) {
|
|
158
158
|
await copyCache(cacheName, dir);
|
|
159
|
-
silent || logUpdate(`${dep ? 'Dependency' : 'Installing'} ${
|
|
159
|
+
silent || logUpdate(`${dep ? 'Dependency' : 'Installing'} ${repo} (global cache) from Github`);
|
|
160
160
|
}
|
|
161
161
|
else {
|
|
162
162
|
mkdirSync(dir, {recursive: true});
|
|
163
163
|
|
|
164
164
|
let progress = (step: number, total: number) => {
|
|
165
|
-
silent || logUpdate(`${dep ? 'Dependency' : 'Installing'} ${
|
|
165
|
+
silent || logUpdate(`${dep ? 'Dependency' : 'Installing'} ${repo} ${progressBar(step, total)}`);
|
|
166
166
|
};
|
|
167
167
|
|
|
168
168
|
progress(0, 2 * (1024 ** 2));
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import Nat "mo:base/Nat";
|
|
2
|
-
import Iter "mo:base/Iter";
|
|
3
|
-
import Buffer "mo:base/Buffer";
|
|
4
|
-
import Vector "mo:vector/Class";
|
|
5
|
-
// import Bench "./bench";
|
|
6
|
-
import Bench "mo:bench";
|
|
7
|
-
|
|
8
|
-
module {
|
|
9
|
-
public func init() : Bench.Bench {
|
|
10
|
-
let bench = Bench.Bench();
|
|
11
|
-
|
|
12
|
-
bench.setName("Add items one-by-one");
|
|
13
|
-
|
|
14
|
-
bench.addRow("Vector");
|
|
15
|
-
bench.addRow("Buffer");
|
|
16
|
-
|
|
17
|
-
bench.addCol("10");
|
|
18
|
-
bench.addCol("10000");
|
|
19
|
-
bench.addCol("1000000");
|
|
20
|
-
|
|
21
|
-
bench.setRunner(func(row, col) {
|
|
22
|
-
let ?n = Nat.fromText(col);
|
|
23
|
-
|
|
24
|
-
// Vector
|
|
25
|
-
if (row == "Vector") {
|
|
26
|
-
let vec = Vector.Vector<Nat>();
|
|
27
|
-
for (i in Iter.range(1, n)) {
|
|
28
|
-
vec.add(i);
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
// Buffer
|
|
32
|
-
else if (row == "Buffer") {
|
|
33
|
-
let buf = Buffer.Buffer<Nat>(0);
|
|
34
|
-
for (i in Iter.range(1, n)) {
|
|
35
|
-
buf.add(i);
|
|
36
|
-
};
|
|
37
|
-
};
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
// bench.table(["Vector", "Buffer"], ["10", "10000", "1000000"], func(row, col) {
|
|
41
|
-
// });
|
|
42
|
-
|
|
43
|
-
bench;
|
|
44
|
-
};
|
|
45
|
-
};
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import Nat64 "mo:base/Nat64";
|
|
2
|
-
import Debug "mo:base/Debug";
|
|
3
|
-
import ExperimentalInternetComputer "mo:base/ExperimentalInternetComputer";
|
|
4
|
-
import Prim "mo:prim";
|
|
5
|
-
|
|
6
|
-
// import Bench "./bench";
|
|
7
|
-
import Bench "mo:bench";
|
|
8
|
-
|
|
9
|
-
import UserBench "$USER_BENCH_FILE";
|
|
10
|
-
|
|
11
|
-
actor class() {
|
|
12
|
-
var benchOpt : ?Bench.Bench = null;
|
|
13
|
-
|
|
14
|
-
public func init() : async Bench.BenchSchema {
|
|
15
|
-
let bench = UserBench.init();
|
|
16
|
-
benchOpt := ?bench;
|
|
17
|
-
bench.getSchema();
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
// public composite query func noop() : async () {};
|
|
21
|
-
|
|
22
|
-
public func runCell(rowIndex : Nat, colIndex : Nat) : async Bench.BenchResult {
|
|
23
|
-
let ?bench = benchOpt else Debug.trap("bench not initialized");
|
|
24
|
-
|
|
25
|
-
let rts_heap_size_before = Prim.rts_heap_size();
|
|
26
|
-
let rts_memory_size_before = Prim.rts_memory_size();
|
|
27
|
-
let rts_total_allocation_before = Prim.rts_total_allocation();
|
|
28
|
-
let rts_mutator_instructions_before = Prim.rts_mutator_instructions();
|
|
29
|
-
let rts_collector_instructions_before = Prim.rts_collector_instructions();
|
|
30
|
-
|
|
31
|
-
let mode : Bench.BenchMode = #replica;
|
|
32
|
-
let instructions = switch(mode) {
|
|
33
|
-
case (#replica) {
|
|
34
|
-
ExperimentalInternetComputer.countInstructions(func() {
|
|
35
|
-
bench.runCell(rowIndex, colIndex, #replica);
|
|
36
|
-
});
|
|
37
|
-
};
|
|
38
|
-
case (#wasi) {
|
|
39
|
-
bench.runCell(rowIndex, colIndex, #replica);
|
|
40
|
-
0 : Nat64;
|
|
41
|
-
};
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
// await noop();
|
|
45
|
-
|
|
46
|
-
// await (func() : async () {})();
|
|
47
|
-
|
|
48
|
-
{
|
|
49
|
-
instructions = Nat64.toNat(instructions);
|
|
50
|
-
rts_heap_size = Prim.rts_heap_size() - rts_heap_size_before;
|
|
51
|
-
rts_memory_size = Prim.rts_memory_size() - rts_memory_size_before;
|
|
52
|
-
rts_total_allocation = Prim.rts_total_allocation() - rts_total_allocation_before;
|
|
53
|
-
rts_mutator_instructions = Prim.rts_mutator_instructions() - rts_mutator_instructions_before;
|
|
54
|
-
rts_collector_instructions = Prim.rts_collector_instructions() - rts_collector_instructions_before;
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
};
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import Nat "mo:base/Nat";
|
|
2
|
-
import Iter "mo:base/Iter";
|
|
3
|
-
import Buffer "mo:base/Buffer";
|
|
4
|
-
import Vector "mo:vector/Class";
|
|
5
|
-
// import Bench "./bench";
|
|
6
|
-
import Bench "mo:bench";
|
|
7
|
-
|
|
8
|
-
module {
|
|
9
|
-
public func init() : Bench.Bench {
|
|
10
|
-
let bench = Bench.Bench();
|
|
11
|
-
|
|
12
|
-
bench.setName("Add items one-by-one");
|
|
13
|
-
|
|
14
|
-
bench.addRow("Vector");
|
|
15
|
-
bench.addRow("Buffer");
|
|
16
|
-
|
|
17
|
-
bench.addCol("10");
|
|
18
|
-
bench.addCol("10000");
|
|
19
|
-
bench.addCol("1000000");
|
|
20
|
-
|
|
21
|
-
bench.setRunner(func(row, col) {
|
|
22
|
-
let ?n = Nat.fromText(col);
|
|
23
|
-
|
|
24
|
-
// Vector
|
|
25
|
-
if (row == "Vector") {
|
|
26
|
-
let vec = Vector.Vector<Nat>();
|
|
27
|
-
for (i in Iter.range(1, n)) {
|
|
28
|
-
vec.add(i);
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
// Buffer
|
|
32
|
-
else if (row == "Buffer") {
|
|
33
|
-
let buf = Buffer.Buffer<Nat>(0);
|
|
34
|
-
for (i in Iter.range(1, n)) {
|
|
35
|
-
buf.add(i);
|
|
36
|
-
};
|
|
37
|
-
};
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
// bench.table(["Vector", "Buffer"], ["10", "10000", "1000000"], func(row, col) {
|
|
41
|
-
// });
|
|
42
|
-
|
|
43
|
-
bench;
|
|
44
|
-
};
|
|
45
|
-
};
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import Nat "mo:base/Nat";
|
|
2
|
-
import Iter "mo:base/Iter";
|
|
3
|
-
import Buffer "mo:base/Buffer";
|
|
4
|
-
import Vector "mo:vector/Class";
|
|
5
|
-
// import Bench "./bench";
|
|
6
|
-
import Bench "mo:bench";
|
|
7
|
-
|
|
8
|
-
module {
|
|
9
|
-
public func init() : Bench.Bench {
|
|
10
|
-
let bench = Bench.Bench();
|
|
11
|
-
|
|
12
|
-
bench.setName("Add items one-by-one");
|
|
13
|
-
|
|
14
|
-
bench.addRow("Vector");
|
|
15
|
-
bench.addRow("Buffer");
|
|
16
|
-
|
|
17
|
-
bench.addCol("10");
|
|
18
|
-
bench.addCol("10000");
|
|
19
|
-
bench.addCol("1000000");
|
|
20
|
-
|
|
21
|
-
bench.setRunner(func(row, col) {
|
|
22
|
-
let ?n = Nat.fromText(col);
|
|
23
|
-
|
|
24
|
-
// Vector
|
|
25
|
-
if (row == "Vector") {
|
|
26
|
-
let vec = Vector.Vector<Nat>();
|
|
27
|
-
for (i in Iter.range(1, n)) {
|
|
28
|
-
vec.add(i);
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
// Buffer
|
|
32
|
-
else if (row == "Buffer") {
|
|
33
|
-
let buf = Buffer.Buffer<Nat>(0);
|
|
34
|
-
for (i in Iter.range(1, n)) {
|
|
35
|
-
buf.add(i);
|
|
36
|
-
};
|
|
37
|
-
};
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
// bench.table(["Vector", "Buffer"], ["10", "10000", "1000000"], func(row, col) {
|
|
41
|
-
// });
|
|
42
|
-
|
|
43
|
-
bench;
|
|
44
|
-
};
|
|
45
|
-
};
|