ic-mops 0.39.2 → 0.40.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/.eslintrc.json +0 -0
- package/.gitignore +1 -0
- package/README.md +0 -0
- package/api/actors.ts +2 -2
- package/api/downloadPackageFiles.ts +9 -6
- package/api/getHighestVersion.ts +1 -1
- package/api/index.ts +0 -0
- package/api/network.ts +1 -1
- package/api/resolveVersion.ts +1 -1
- package/cache.ts +3 -3
- package/cli.ts +3 -2
- package/commands/add.ts +6 -6
- package/commands/available-updates.ts +2 -2
- package/commands/bench/bench-canister.mo +0 -0
- package/commands/bench/user-bench.mo +0 -0
- package/commands/bench-replica.ts +10 -10
- package/commands/bench.ts +96 -56
- package/commands/bump.ts +2 -2
- package/commands/docs.ts +1 -1
- package/commands/import-identity.ts +2 -2
- package/commands/init.ts +9 -9
- package/commands/install-all.ts +4 -4
- package/commands/install-local.ts +1 -1
- package/commands/install.ts +2 -2
- package/commands/outdated.ts +0 -0
- package/commands/publish.ts +34 -9
- package/commands/remove.ts +8 -8
- package/commands/search.ts +2 -2
- package/commands/sources.ts +0 -0
- package/commands/sync.ts +8 -8
- package/commands/template.ts +2 -2
- package/commands/test/mmf1.ts +18 -18
- package/commands/test/reporters/compact-reporter.ts +5 -5
- package/commands/test/reporters/files-reporter.ts +3 -3
- package/commands/test/reporters/reporter.ts +3 -3
- package/commands/test/reporters/silent-reporter.ts +4 -4
- package/commands/test/reporters/verbose-reporter.ts +3 -3
- package/commands/test/test.ts +10 -10
- package/commands/test/utils.ts +1 -1
- package/commands/toolchain/index.ts +9 -9
- package/commands/toolchain/moc.ts +2 -2
- package/commands/toolchain/pocket-ic.ts +6 -31
- package/commands/toolchain/toolchain-utils.ts +11 -11
- package/commands/toolchain/wasmtime.ts +2 -2
- package/commands/transfer-ownership.ts +2 -2
- package/commands/update.ts +4 -4
- package/commands/user.ts +2 -2
- package/commands/whoami.ts +0 -0
- package/declarations/bench/bench.did.d.ts +3 -0
- package/declarations/main/main.did +27 -1
- package/declarations/main/main.did.d.ts +26 -1
- package/declarations/main/main.did.js +27 -1
- package/declarations/storage/index.d.ts +0 -0
- package/declarations/storage/index.js +0 -0
- package/declarations/storage/storage.did +0 -0
- package/declarations/storage/storage.did.d.ts +0 -0
- package/declarations/storage/storage.did.js +0 -0
- package/dist/api/actors.d.ts +0 -0
- package/dist/api/actors.js +0 -0
- package/dist/api/downloadPackageFiles.d.ts +1 -1
- package/dist/api/downloadPackageFiles.js +4 -0
- package/dist/api/getHighestVersion.d.ts +0 -0
- package/dist/api/getHighestVersion.js +0 -0
- package/dist/api/index.d.ts +0 -0
- package/dist/api/index.js +0 -0
- package/dist/api/network.d.ts +0 -0
- package/dist/api/network.js +0 -0
- package/dist/api/resolveVersion.d.ts +0 -0
- package/dist/api/resolveVersion.js +0 -0
- package/dist/bin/moc-wrapper.sh +3 -0
- package/dist/bin/mops.d.ts +0 -0
- package/dist/bin/mops.js +0 -0
- package/dist/bundle-package-json.d.ts +1 -0
- package/dist/bundle-package-json.js +11 -0
- package/dist/cache.d.ts +0 -0
- package/dist/cache.js +0 -0
- package/dist/cli.d.ts +0 -0
- package/dist/cli.js +1 -0
- package/dist/commands/add.d.ts +0 -0
- package/dist/commands/add.js +0 -0
- package/dist/commands/available-updates.d.ts +0 -0
- package/dist/commands/available-updates.js +0 -0
- package/dist/commands/bench/bench-canister.mo +0 -0
- package/dist/commands/bench/user-bench.mo +0 -0
- package/dist/commands/bench-replica.d.ts +3 -1
- package/dist/commands/bench-replica.js +2 -2
- package/dist/commands/bench.d.ts +5 -2
- package/dist/commands/bench.js +66 -29
- package/dist/commands/bump.d.ts +0 -0
- package/dist/commands/bump.js +0 -0
- package/dist/commands/docs.d.ts +0 -0
- package/dist/commands/docs.js +0 -0
- package/dist/commands/import-identity.d.ts +0 -0
- package/dist/commands/import-identity.js +0 -0
- package/dist/commands/init.d.ts +0 -0
- package/dist/commands/init.js +1 -1
- package/dist/commands/install-all.d.ts +0 -0
- package/dist/commands/install-all.js +0 -0
- package/dist/commands/install-local.d.ts +0 -0
- package/dist/commands/install-local.js +0 -0
- package/dist/commands/install.d.ts +0 -0
- package/dist/commands/install.js +0 -0
- package/dist/commands/outdated.d.ts +0 -0
- package/dist/commands/outdated.js +0 -0
- package/dist/commands/publish.d.ts +1 -0
- package/dist/commands/publish.js +24 -1
- package/dist/commands/remove.d.ts +0 -0
- package/dist/commands/remove.js +0 -0
- package/dist/commands/search.d.ts +0 -0
- package/dist/commands/search.js +0 -0
- package/dist/commands/self-update.d.ts +0 -0
- package/dist/commands/self-update.js +0 -0
- package/dist/commands/self.d.ts +3 -0
- package/dist/commands/self.js +62 -0
- package/dist/commands/sources.d.ts +0 -0
- package/dist/commands/sources.js +0 -0
- package/dist/commands/sync.d.ts +0 -0
- package/dist/commands/sync.js +0 -0
- package/dist/commands/template.d.ts +0 -0
- package/dist/commands/template.js +0 -0
- package/dist/commands/test/mmf1.d.ts +0 -0
- package/dist/commands/test/mmf1.js +1 -1
- package/dist/commands/test/reporters/compact-reporter.d.ts +0 -0
- package/dist/commands/test/reporters/compact-reporter.js +0 -0
- package/dist/commands/test/reporters/files-reporter.d.ts +0 -0
- package/dist/commands/test/reporters/files-reporter.js +0 -0
- package/dist/commands/test/reporters/reporter.d.ts +0 -0
- package/dist/commands/test/reporters/reporter.js +0 -0
- package/dist/commands/test/reporters/silent-reporter.d.ts +0 -0
- package/dist/commands/test/reporters/silent-reporter.js +0 -0
- package/dist/commands/test/reporters/verbose-reporter.d.ts +0 -0
- package/dist/commands/test/reporters/verbose-reporter.js +0 -0
- package/dist/commands/test/test.d.ts +0 -0
- package/dist/commands/test/test.js +2 -2
- package/dist/commands/test/utils.d.ts +0 -0
- package/dist/commands/test/utils.js +0 -0
- package/dist/commands/toolchain/index.d.ts +0 -0
- package/dist/commands/toolchain/index.js +0 -0
- package/dist/commands/toolchain/moc.d.ts +0 -0
- package/dist/commands/toolchain/moc.js +0 -0
- package/dist/commands/toolchain/pocket-ic.d.ts +1 -5
- package/dist/commands/toolchain/pocket-ic.js +4 -27
- package/dist/commands/toolchain/toolchain-utils.d.ts +1 -1
- package/dist/commands/toolchain/toolchain-utils.js +7 -7
- package/dist/commands/toolchain/wasmtime.d.ts +0 -0
- package/dist/commands/toolchain/wasmtime.js +0 -0
- package/dist/commands/transfer-ownership.d.ts +0 -0
- package/dist/commands/transfer-ownership.js +1 -1
- package/dist/commands/update.d.ts +0 -0
- package/dist/commands/update.js +0 -0
- package/dist/commands/user.d.ts +0 -0
- package/dist/commands/user.js +0 -0
- package/dist/commands/whoami.d.ts +0 -0
- package/dist/commands/whoami.js +0 -0
- package/dist/declarations/bench/bench.did +0 -0
- package/dist/declarations/bench/bench.did.d.ts +3 -0
- package/dist/declarations/bench/bench.did.js +0 -0
- package/dist/declarations/bench/index.d.ts +0 -0
- package/dist/declarations/bench/index.js +0 -0
- package/dist/declarations/main/index.d.ts +0 -0
- package/dist/declarations/main/index.js +0 -0
- package/dist/declarations/main/main.did +27 -1
- package/dist/declarations/main/main.did.d.ts +26 -1
- package/dist/declarations/main/main.did.js +27 -1
- package/dist/declarations/storage/index.d.ts +0 -0
- package/dist/declarations/storage/index.js +0 -0
- package/dist/declarations/storage/storage.did +0 -0
- package/dist/declarations/storage/storage.did.d.ts +0 -0
- package/dist/declarations/storage/storage.did.js +0 -0
- package/dist/helpers/find-changelog-entry.d.ts +1 -0
- package/dist/helpers/find-changelog-entry.js +24 -0
- package/dist/helpers/get-dfx-version.d.ts +0 -0
- package/dist/helpers/get-dfx-version.js +0 -0
- package/dist/helpers/get-moc-path.d.ts +0 -0
- package/dist/helpers/get-moc-path.js +0 -0
- package/dist/helpers/get-moc-version.d.ts +0 -0
- package/dist/helpers/get-moc-version.js +0 -0
- package/dist/integrity.d.ts +0 -0
- package/dist/integrity.js +0 -0
- package/dist/mops.d.ts +0 -0
- package/dist/mops.js +1 -1
- package/dist/notify-installs.d.ts +0 -0
- package/dist/notify-installs.js +0 -0
- package/dist/package.json +1 -1
- package/dist/parallel.d.ts +0 -0
- package/dist/parallel.js +0 -0
- package/dist/pem.d.ts +0 -0
- package/dist/pem.js +0 -0
- package/dist/release-cli.d.ts +1 -0
- package/dist/release-cli.js +35 -0
- package/dist/remove-scripts.d.ts +1 -0
- package/dist/remove-scripts.js +5 -0
- package/dist/resolve-packages.d.ts +0 -0
- package/dist/resolve-packages.js +0 -0
- package/dist/templates/README.md +0 -0
- package/dist/templates/licenses/Apache-2.0 +0 -0
- package/dist/templates/licenses/Apache-2.0-NOTICE +0 -0
- package/dist/templates/licenses/MIT +0 -0
- package/dist/templates/mops-publish.yml +0 -0
- package/dist/templates/mops-test.yml +0 -0
- package/dist/templates/src/lib.mo +0 -0
- package/dist/templates/test/lib.test.mo +0 -0
- package/dist/types.d.ts +0 -0
- package/dist/types.js +0 -0
- package/dist/vessel.d.ts +0 -0
- package/dist/vessel.js +1 -1
- package/global.d.ts +0 -0
- package/helpers/get-dfx-version.ts +1 -1
- package/helpers/get-moc-path.ts +1 -1
- package/helpers/get-moc-version.ts +1 -1
- package/integrity.ts +16 -16
- package/mops.ts +17 -17
- package/notify-installs.ts +2 -2
- package/package.json +1 -1
- package/parallel.ts +1 -1
- package/pem.ts +5 -5
- package/resolve-packages.ts +9 -9
- package/templates/README.md +0 -0
- package/templates/licenses/Apache-2.0 +0 -0
- package/templates/licenses/Apache-2.0-NOTICE +0 -0
- package/templates/licenses/MIT +0 -0
- package/templates/mops-publish.yml +0 -0
- package/templates/mops-test.yml +0 -0
- package/templates/src/lib.mo +0 -0
- package/templates/test/lib.test.mo +0 -0
- package/types.ts +25 -25
- package/vessel.ts +16 -16
- package/dist/commands/replica.d.ts +0 -36
- package/dist/commands/replica.js +0 -103
package/mops.ts
CHANGED
|
@@ -74,8 +74,8 @@ if (fs.existsSync(oldGlobalConfigDir) && !fs.existsSync(globalCacheDir)) {
|
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
|
|
77
|
-
export function getNetworkFile(): string | URL {
|
|
78
|
-
let networkFile: string | URL = '';
|
|
77
|
+
export function getNetworkFile() : string | URL {
|
|
78
|
+
let networkFile : string | URL = '';
|
|
79
79
|
try {
|
|
80
80
|
networkFile = new URL('./network.txt', import.meta.url);
|
|
81
81
|
}
|
|
@@ -85,18 +85,18 @@ export function getNetworkFile(): string | URL {
|
|
|
85
85
|
return networkFile;
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
-
export function setNetwork(network: string) {
|
|
88
|
+
export function setNetwork(network : string) {
|
|
89
89
|
fs.writeFileSync(getNetworkFile(), network);
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
-
export let getIdentity = async (): Promise<Identity | undefined> => {
|
|
92
|
+
export let getIdentity = async () : Promise<Identity | undefined> => {
|
|
93
93
|
let identityPem = path.resolve(globalConfigDir, 'identity.pem');
|
|
94
94
|
let identityPemEncrypted = path.resolve(globalConfigDir, 'identity.pem.encrypted');
|
|
95
95
|
if (fs.existsSync(identityPemEncrypted)) {
|
|
96
96
|
let res = await prompts({
|
|
97
97
|
type: 'invisible',
|
|
98
98
|
name: 'value',
|
|
99
|
-
message: 'Enter password:'
|
|
99
|
+
message: 'Enter password:',
|
|
100
100
|
});
|
|
101
101
|
return await decodeFile(identityPemEncrypted, res.value);
|
|
102
102
|
}
|
|
@@ -134,12 +134,12 @@ export function checkConfigFile() {
|
|
|
134
134
|
return true;
|
|
135
135
|
}
|
|
136
136
|
|
|
137
|
-
export function progressBar(step: number, total: number) {
|
|
137
|
+
export function progressBar(step : number, total : number) {
|
|
138
138
|
let done = Math.round(step / total * 10);
|
|
139
139
|
return `[${':'.repeat(done)}${' '.repeat(Math.max(0, 10 - done))}]`;
|
|
140
140
|
}
|
|
141
141
|
|
|
142
|
-
export function parseGithubURL(href: string) {
|
|
142
|
+
export function parseGithubURL(href : string) {
|
|
143
143
|
const url = new URL(href);
|
|
144
144
|
let branchAndSha = url.hash?.substring(1).split('@');
|
|
145
145
|
let branch = branchAndSha[0] || 'master';
|
|
@@ -154,9 +154,9 @@ export function parseGithubURL(href: string) {
|
|
|
154
154
|
return {org, gitName, branch, commitHash};
|
|
155
155
|
}
|
|
156
156
|
|
|
157
|
-
export async function getGithubCommit(repo: string, ref: string): Promise<any> {
|
|
157
|
+
export async function getGithubCommit(repo : string, ref : string) : Promise<any> {
|
|
158
158
|
let res = await fetch(`https://api.github.com/repos/${repo}/commits/${ref}`);
|
|
159
|
-
let json: any = await res.json();
|
|
159
|
+
let json : any = await res.json();
|
|
160
160
|
|
|
161
161
|
// try on main branch
|
|
162
162
|
if (json.message && ref === 'master') {
|
|
@@ -166,7 +166,7 @@ export async function getGithubCommit(repo: string, ref: string): Promise<any> {
|
|
|
166
166
|
return json;
|
|
167
167
|
}
|
|
168
168
|
|
|
169
|
-
export function getDependencyType(version: string) {
|
|
169
|
+
export function getDependencyType(version : string) {
|
|
170
170
|
if (!version || typeof version !== 'string') {
|
|
171
171
|
throw Error(`Invalid dependency value "${version}"`);
|
|
172
172
|
}
|
|
@@ -181,11 +181,11 @@ export function getDependencyType(version: string) {
|
|
|
181
181
|
}
|
|
182
182
|
}
|
|
183
183
|
|
|
184
|
-
export function readConfig(configFile = getClosestConfigFile()): Config {
|
|
184
|
+
export function readConfig(configFile = getClosestConfigFile()) : Config {
|
|
185
185
|
let text = fs.readFileSync(configFile).toString();
|
|
186
186
|
let toml = TOML.parse(text);
|
|
187
187
|
|
|
188
|
-
let processDeps = (deps: any) => {
|
|
188
|
+
let processDeps = (deps : any) => {
|
|
189
189
|
Object.entries(deps).forEach(([name, data]) => {
|
|
190
190
|
if (!data || typeof data !== 'string') {
|
|
191
191
|
throw Error(`Invalid dependency value ${name} = "${data}"`);
|
|
@@ -209,8 +209,8 @@ export function readConfig(configFile = getClosestConfigFile()): Config {
|
|
|
209
209
|
return toml;
|
|
210
210
|
}
|
|
211
211
|
|
|
212
|
-
export function writeConfig(config: Config, configFile = getClosestConfigFile()) {
|
|
213
|
-
let resConfig: any = JSON.parse(JSON.stringify(config));
|
|
212
|
+
export function writeConfig(config : Config, configFile = getClosestConfigFile()) {
|
|
213
|
+
let resConfig : any = JSON.parse(JSON.stringify(config));
|
|
214
214
|
|
|
215
215
|
let deps = resConfig.dependencies || {};
|
|
216
216
|
Object.entries(config.dependencies || {}).forEach(([name, {repo, path, version}]) => {
|
|
@@ -229,16 +229,16 @@ export function writeConfig(config: Config, configFile = getClosestConfigFile())
|
|
|
229
229
|
fs.writeFileSync(configFile, text);
|
|
230
230
|
}
|
|
231
231
|
|
|
232
|
-
export function formatDir(name: string, version: string) {
|
|
232
|
+
export function formatDir(name : string, version : string) {
|
|
233
233
|
return path.join(getRootDir(), '.mops', `${name}@${version}`);
|
|
234
234
|
}
|
|
235
235
|
|
|
236
|
-
export function formatGithubDir(name: string, repo: string) {
|
|
236
|
+
export function formatGithubDir(name : string, repo : string) {
|
|
237
237
|
const {branch, commitHash} = parseGithubURL(repo);
|
|
238
238
|
return path.join(getRootDir(), '.mops/_github', `${name}#${branch}` + (commitHash ? `@${commitHash}` : ''));
|
|
239
239
|
}
|
|
240
240
|
|
|
241
|
-
export function readDfxJson(): any {
|
|
241
|
+
export function readDfxJson() : any {
|
|
242
242
|
let dir = process.cwd();
|
|
243
243
|
let dfxJson = null;
|
|
244
244
|
for (let i = 0; i < 5; i++) {
|
package/notify-installs.ts
CHANGED
|
@@ -2,9 +2,9 @@ import {getDependencyType} from './mops.js';
|
|
|
2
2
|
import {mainActor} from './api/actors.js';
|
|
3
3
|
import {resolvePackages} from './resolve-packages.js';
|
|
4
4
|
|
|
5
|
-
export async function notifyInstalls(names: string[]) {
|
|
5
|
+
export async function notifyInstalls(names : string[]) {
|
|
6
6
|
let resolvedPackages = await resolvePackages();
|
|
7
|
-
let packages: [string, string][] = names.map(name => [name, resolvedPackages[name] as string]);
|
|
7
|
+
let packages : [string, string][] = names.map(name => [name, resolvedPackages[name] as string]);
|
|
8
8
|
if (packages.length) {
|
|
9
9
|
let actor = await mainActor();
|
|
10
10
|
await actor.notifyInstalls(packages.filter(([_, version]) => getDependencyType(version) === 'mops'));
|
package/package.json
CHANGED
package/parallel.ts
CHANGED
package/pem.ts
CHANGED
|
@@ -4,7 +4,7 @@ import {Secp256k1KeyIdentity} from '@dfinity/identity-secp256k1';
|
|
|
4
4
|
import pemfile from 'pem-file';
|
|
5
5
|
import crypto from 'crypto';
|
|
6
6
|
|
|
7
|
-
export function decodeFile(file: string, password?: string) {
|
|
7
|
+
export function decodeFile(file : string, password ?: string) {
|
|
8
8
|
let rawKey = fs.readFileSync(file);
|
|
9
9
|
if (password) {
|
|
10
10
|
return decode(decrypt(rawKey, password));
|
|
@@ -12,8 +12,8 @@ export function decodeFile(file: string, password?: string) {
|
|
|
12
12
|
return decode(rawKey);
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
function decode(rawKey: Buffer) {
|
|
16
|
-
let buf: Buffer = pemfile.decode(rawKey);
|
|
15
|
+
function decode(rawKey : Buffer) {
|
|
16
|
+
let buf : Buffer = pemfile.decode(rawKey);
|
|
17
17
|
if (rawKey.includes('EC PRIVATE KEY')) {
|
|
18
18
|
if (buf.length != 118) {
|
|
19
19
|
throw 'expecting byte length 118 but got ' + buf.length;
|
|
@@ -29,7 +29,7 @@ function decode(rawKey: Buffer) {
|
|
|
29
29
|
|
|
30
30
|
let algorithm = 'aes-256-ctr';
|
|
31
31
|
|
|
32
|
-
export function encrypt(buffer: Buffer, password: string) {
|
|
32
|
+
export function encrypt(buffer : Buffer, password : string) {
|
|
33
33
|
let key = crypto.createHash('sha256').update(password).digest('base64').slice(0, 32);
|
|
34
34
|
// Create an initialization vector
|
|
35
35
|
let iv = crypto.randomBytes(16);
|
|
@@ -40,7 +40,7 @@ export function encrypt(buffer: Buffer, password: string) {
|
|
|
40
40
|
return result;
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
function decrypt(encrypted: Buffer, password: string) {
|
|
43
|
+
function decrypt(encrypted : Buffer, password : string) {
|
|
44
44
|
let key = crypto.createHash('sha256').update(password).digest('base64').slice(0, 32);
|
|
45
45
|
// Get the iv: the first 16 bytes
|
|
46
46
|
let iv = encrypted.subarray(0, 16);
|
package/resolve-packages.ts
CHANGED
|
@@ -4,18 +4,18 @@ import {checkConfigFile, formatDir, formatGithubDir, getRootDir, parseGithubURL,
|
|
|
4
4
|
import {VesselConfig, readVesselConfig} from './vessel.js';
|
|
5
5
|
import {Config, Dependency} from './types.js';
|
|
6
6
|
|
|
7
|
-
export async function resolvePackages({verbose = false} = {}): Promise<Record<string, string>> {
|
|
7
|
+
export async function resolvePackages({verbose = false} = {}) : Promise<Record<string, string>> {
|
|
8
8
|
if (!checkConfigFile()) {
|
|
9
9
|
return {};
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
let rootDir = getRootDir();
|
|
13
|
-
let packages: Record<string, Dependency & {isRoot: boolean;}> = {};
|
|
14
|
-
let versions: Record<string, string[]> = {};
|
|
13
|
+
let packages : Record<string, Dependency & {isRoot : boolean;}> = {};
|
|
14
|
+
let versions : Record<string, string[]> = {};
|
|
15
15
|
|
|
16
|
-
let compareVersions = (a: string = '0.0.0', b: string = '0.0.0') => {
|
|
17
|
-
let ap = a.split('.').map((x: string) => parseInt(x)) as [number, number, number];
|
|
18
|
-
let bp = b.split('.').map((x: string) => parseInt(x)) as [number, number, number];
|
|
16
|
+
let compareVersions = (a : string = '0.0.0', b : string = '0.0.0') => {
|
|
17
|
+
let ap = a.split('.').map((x : string) => parseInt(x)) as [number, number, number];
|
|
18
|
+
let bp = b.split('.').map((x : string) => parseInt(x)) as [number, number, number];
|
|
19
19
|
if (ap[0] - bp[0]) {
|
|
20
20
|
return Math.sign(ap[0] - bp[0]);
|
|
21
21
|
}
|
|
@@ -30,7 +30,7 @@ export async function resolvePackages({verbose = false} = {}): Promise<Record<st
|
|
|
30
30
|
|
|
31
31
|
const gitVerRegex = new RegExp(/v(\d{1,2}\.\d{1,2}\.\d{1,2})(-.*)?$/);
|
|
32
32
|
|
|
33
|
-
const compareGitVersions = (repoA: string, repoB: string) => {
|
|
33
|
+
const compareGitVersions = (repoA : string, repoB : string) => {
|
|
34
34
|
const {branch: a} = parseGithubURL(repoA);
|
|
35
35
|
const {branch: b} = parseGithubURL(repoB);
|
|
36
36
|
|
|
@@ -45,7 +45,7 @@ export async function resolvePackages({verbose = false} = {}): Promise<Record<st
|
|
|
45
45
|
}
|
|
46
46
|
};
|
|
47
47
|
|
|
48
|
-
let collectDeps = async (config: Config | VesselConfig, configDir: string, isRoot = false) => {
|
|
48
|
+
let collectDeps = async (config : Config | VesselConfig, configDir : string, isRoot = false) => {
|
|
49
49
|
let allDeps = [...Object.values(config.dependencies || {})];
|
|
50
50
|
if (isRoot) {
|
|
51
51
|
allDeps = [...allDeps, ...Object.values(config['dev-dependencies'] || {})];
|
|
@@ -124,7 +124,7 @@ export async function resolvePackages({verbose = false} = {}): Promise<Record<st
|
|
|
124
124
|
|
|
125
125
|
return Object.fromEntries(
|
|
126
126
|
Object.entries(packages).map(([name, pkg]) => {
|
|
127
|
-
let version: string;
|
|
127
|
+
let version : string;
|
|
128
128
|
if (pkg.path) {
|
|
129
129
|
version = path.resolve(rootDir, pkg.path).replaceAll('{MOPS_ENV}', process.env.MOPS_ENV || 'local');
|
|
130
130
|
}
|
package/templates/README.md
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/templates/licenses/MIT
CHANGED
|
File without changes
|
|
File without changes
|
package/templates/mops-test.yml
CHANGED
|
File without changes
|
package/templates/src/lib.mo
CHANGED
|
File without changes
|
|
File without changes
|
package/types.ts
CHANGED
|
@@ -1,38 +1,38 @@
|
|
|
1
1
|
export type Config = {
|
|
2
|
-
package?: {
|
|
3
|
-
name: string;
|
|
4
|
-
version: string;
|
|
5
|
-
description?: string;
|
|
6
|
-
license?: string;
|
|
7
|
-
repository?: string;
|
|
8
|
-
keywords?: string[];
|
|
9
|
-
baseDir?: string;
|
|
10
|
-
readme?: string;
|
|
11
|
-
files?: string[];
|
|
12
|
-
homepage?: string;
|
|
13
|
-
documentation?: string;
|
|
14
|
-
dfx?: string;
|
|
15
|
-
moc?: string;
|
|
16
|
-
donation?: string;
|
|
2
|
+
package ?: {
|
|
3
|
+
name : string;
|
|
4
|
+
version : string;
|
|
5
|
+
description ?: string;
|
|
6
|
+
license ?: string;
|
|
7
|
+
repository ?: string;
|
|
8
|
+
keywords ?: string[];
|
|
9
|
+
baseDir ?: string;
|
|
10
|
+
readme ?: string;
|
|
11
|
+
files ?: string[];
|
|
12
|
+
homepage ?: string;
|
|
13
|
+
documentation ?: string;
|
|
14
|
+
dfx ?: string;
|
|
15
|
+
moc ?: string;
|
|
16
|
+
donation ?: string;
|
|
17
17
|
};
|
|
18
|
-
dependencies?: Dependencies;
|
|
19
|
-
'dev-dependencies'?: Dependencies;
|
|
20
|
-
toolchain?: Toolchain;
|
|
18
|
+
dependencies ?: Dependencies;
|
|
19
|
+
'dev-dependencies' ?: Dependencies;
|
|
20
|
+
toolchain ?: Toolchain;
|
|
21
21
|
};
|
|
22
22
|
|
|
23
23
|
export type Dependencies = Record<string, Dependency>;
|
|
24
24
|
|
|
25
25
|
export type Dependency = {
|
|
26
|
-
name: string;
|
|
27
|
-
version?: string; // mops package
|
|
28
|
-
repo?: string; // github package
|
|
29
|
-
path?: string; // local package
|
|
26
|
+
name : string;
|
|
27
|
+
version ?: string; // mops package
|
|
28
|
+
repo ?: string; // github package
|
|
29
|
+
path ?: string; // local package
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
export type Toolchain = {
|
|
33
|
-
moc?: string;
|
|
34
|
-
wasmtime?: string;
|
|
35
|
-
'pocket-ic'?: string;
|
|
33
|
+
moc ?: string;
|
|
34
|
+
wasmtime ?: string;
|
|
35
|
+
'pocket-ic' ?: string;
|
|
36
36
|
};
|
|
37
37
|
|
|
38
38
|
export type Tool = 'moc' | 'wasmtime' | 'pocket-ic';
|
package/vessel.ts
CHANGED
|
@@ -10,14 +10,14 @@ import {pipeline} from 'stream';
|
|
|
10
10
|
import {formatGithubDir, parseGithubURL, progressBar} from './mops.js';
|
|
11
11
|
import {addCache, copyCache, isCached} from './cache.js';
|
|
12
12
|
|
|
13
|
-
const dhallFileToJson = async (filePath: string, silent: boolean) => {
|
|
13
|
+
const dhallFileToJson = async (filePath : string, silent : boolean) => {
|
|
14
14
|
if (existsSync(filePath)) {
|
|
15
15
|
let cwd = new URL(path.dirname(import.meta.url)).pathname;
|
|
16
16
|
let res;
|
|
17
17
|
try {
|
|
18
18
|
res = await execaCommand(`dhall-to-json --file ${filePath}`, {preferLocal:true, cwd});
|
|
19
19
|
}
|
|
20
|
-
catch (err: any) {
|
|
20
|
+
catch (err : any) {
|
|
21
21
|
silent || console.error('dhall-to-json error:', err.message?.split('Message:')[0]);
|
|
22
22
|
return null;
|
|
23
23
|
}
|
|
@@ -34,18 +34,18 @@ const dhallFileToJson = async (filePath: string, silent: boolean) => {
|
|
|
34
34
|
};
|
|
35
35
|
|
|
36
36
|
export type VesselConfig = {
|
|
37
|
-
dependencies: VesselDependencies;
|
|
38
|
-
'dev-dependencies': VesselDependencies;
|
|
37
|
+
dependencies : VesselDependencies;
|
|
38
|
+
'dev-dependencies' : VesselDependencies;
|
|
39
39
|
};
|
|
40
40
|
|
|
41
41
|
export type VesselDependencies = Array<{
|
|
42
|
-
name: string;
|
|
43
|
-
version?: string; // mops package
|
|
44
|
-
repo?: string; // github package
|
|
45
|
-
path?: string; // local package
|
|
42
|
+
name : string;
|
|
43
|
+
version ?: string; // mops package
|
|
44
|
+
repo ?: string; // github package
|
|
45
|
+
path ?: string; // local package
|
|
46
46
|
}>;
|
|
47
47
|
|
|
48
|
-
export const readVesselConfig = async (dir: string, {cache = true, silent = false} = {}): Promise<VesselConfig | null> => {
|
|
48
|
+
export const readVesselConfig = async (dir : string, {cache = true, silent = false} = {}) : Promise<VesselConfig | null> => {
|
|
49
49
|
const cachedFile = (dir || process.cwd()) + '/vessel.json';
|
|
50
50
|
|
|
51
51
|
if (existsSync(cachedFile)) {
|
|
@@ -55,21 +55,21 @@ export const readVesselConfig = async (dir: string, {cache = true, silent = fals
|
|
|
55
55
|
|
|
56
56
|
const [vessel, packageSetArray] = await Promise.all([
|
|
57
57
|
dhallFileToJson((dir || process.cwd()) + '/vessel.dhall', silent),
|
|
58
|
-
dhallFileToJson((dir || process.cwd()) + '/package-set.dhall', silent)
|
|
58
|
+
dhallFileToJson((dir || process.cwd()) + '/package-set.dhall', silent),
|
|
59
59
|
]);
|
|
60
60
|
|
|
61
61
|
if (!vessel || !packageSetArray) {
|
|
62
62
|
return null;
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
let repos: Record<string, string> = {};
|
|
65
|
+
let repos : Record<string, string> = {};
|
|
66
66
|
for (const {name, repo, version} of packageSetArray) {
|
|
67
67
|
const {org, gitName} = parseGithubURL(repo);
|
|
68
68
|
repos[name] = `https://github.com/${org}/${gitName}#${version}`;
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
-
let config: VesselConfig = {
|
|
72
|
-
dependencies: vessel.dependencies.map((name: string) => {
|
|
71
|
+
let config : VesselConfig = {
|
|
72
|
+
dependencies: vessel.dependencies.map((name : string) => {
|
|
73
73
|
return {name, repo: repos[name], version: ''};
|
|
74
74
|
}),
|
|
75
75
|
'dev-dependencies': [],
|
|
@@ -82,7 +82,7 @@ export const readVesselConfig = async (dir: string, {cache = true, silent = fals
|
|
|
82
82
|
return config;
|
|
83
83
|
};
|
|
84
84
|
|
|
85
|
-
export const downloadFromGithub = async (repo: string, dest: string, onProgress: any) => {
|
|
85
|
+
export const downloadFromGithub = async (repo : string, dest : string, onProgress : any) => {
|
|
86
86
|
const {branch, org, gitName, commitHash} = parseGithubURL(repo);
|
|
87
87
|
|
|
88
88
|
const zipFile = `https://github.com/${org}/${gitName}/archive/${commitHash || branch}.zip`;
|
|
@@ -148,7 +148,7 @@ export const downloadFromGithub = async (repo: string, dest: string, onProgress:
|
|
|
148
148
|
return promise;
|
|
149
149
|
};
|
|
150
150
|
|
|
151
|
-
export const installFromGithub = async (name: string, repo: string, {verbose = false, dep = false, silent = false} = {}) => {
|
|
151
|
+
export const installFromGithub = async (name : string, repo : string, {verbose = false, dep = false, silent = false} = {}) => {
|
|
152
152
|
let {branch, commitHash} = parseGithubURL(repo);
|
|
153
153
|
let dir = formatGithubDir(name, repo);
|
|
154
154
|
let cacheName = `_github/${name}#${branch}` + (commitHash ? `@${commitHash}` : '');
|
|
@@ -165,7 +165,7 @@ export const installFromGithub = async (name: string, repo: string, {verbose = f
|
|
|
165
165
|
else {
|
|
166
166
|
mkdirSync(dir, {recursive: true});
|
|
167
167
|
|
|
168
|
-
let progress = (step: number, total: number) => {
|
|
168
|
+
let progress = (step : number, total : number) => {
|
|
169
169
|
silent || logUpdate(`${dep ? 'Dependency' : 'Installing'} ${repo} ${progressBar(step, total)}`);
|
|
170
170
|
};
|
|
171
171
|
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
-
import { ChildProcess, ChildProcessWithoutNullStreams } from 'node:child_process';
|
|
3
|
-
import { PocketIc } from 'pic-ic';
|
|
4
|
-
export declare class Replica {
|
|
5
|
-
type: 'dfx' | 'pocket-ic';
|
|
6
|
-
cwd: string;
|
|
7
|
-
verbose: boolean;
|
|
8
|
-
canisters: Record<string, {
|
|
9
|
-
cwd: string;
|
|
10
|
-
canisterId: string;
|
|
11
|
-
actor: any;
|
|
12
|
-
}>;
|
|
13
|
-
pocketIc?: PocketIc;
|
|
14
|
-
process?: ChildProcess;
|
|
15
|
-
constructor(type: 'dfx' | 'pocket-ic', cwd: string, verbose?: boolean);
|
|
16
|
-
start(): Promise<ChildProcessWithoutNullStreams>;
|
|
17
|
-
stop(): Promise<void>;
|
|
18
|
-
deploy(name: string, wasm: string, cwd?: string): Promise<void>;
|
|
19
|
-
getActor(name: string): unknown;
|
|
20
|
-
getCanisterId(name: string): string;
|
|
21
|
-
dfxJson(canisterName: string): {
|
|
22
|
-
version: number;
|
|
23
|
-
canisters: Record<string, any>;
|
|
24
|
-
defaults: {
|
|
25
|
-
build: {
|
|
26
|
-
packtool: string;
|
|
27
|
-
};
|
|
28
|
-
};
|
|
29
|
-
networks: {
|
|
30
|
-
local: {
|
|
31
|
-
type: string;
|
|
32
|
-
bind: string;
|
|
33
|
-
};
|
|
34
|
-
};
|
|
35
|
-
};
|
|
36
|
-
}
|
package/dist/commands/replica.js
DELETED
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
import { execSync, spawn } 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 'pic-ic';
|
|
6
|
-
import { readConfig } from '../mops.js';
|
|
7
|
-
import { createActor, idlFactory } from '../declarations/bench/index.js';
|
|
8
|
-
import { toolchain } from './toolchain/index.js';
|
|
9
|
-
export class Replica {
|
|
10
|
-
constructor(type, cwd, verbose = false) {
|
|
11
|
-
this.verbose = false;
|
|
12
|
-
this.canisters = {};
|
|
13
|
-
this.type = type;
|
|
14
|
-
this.verbose = verbose;
|
|
15
|
-
this.cwd = cwd;
|
|
16
|
-
}
|
|
17
|
-
async start() {
|
|
18
|
-
console.log(`Starting ${this.type} replica...`);
|
|
19
|
-
if (this.type == 'dfx') {
|
|
20
|
-
await this.stop();
|
|
21
|
-
fs.writeFileSync(path.join(this.cwd, 'dfx.json'), JSON.stringify(this.dfxJson(''), null, 2));
|
|
22
|
-
// this.process = spawn('dfx start --background --clean --artificial-delay 0' + (this.verbose ? '' : ' -qqqq'), {cwd: this.cwd, stdio: ['inherit', this.verbose ? 'inherit' : 'ignore', 'inherit']});
|
|
23
|
-
this.process = spawn('dfx', ['start', '--background', '--clean', '--artificial-delay=0', this.verbose ? '' : ' -qqqq'].filter(x => x), { cwd: this.cwd });
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
let pocketIcBin = await toolchain.bin('pocket-ic');
|
|
27
|
-
let config = readConfig();
|
|
28
|
-
if (config.toolchain?.['pocket-ic'] !== '1.0.0') {
|
|
29
|
-
console.error('Currently only pocket-ic 1.0.0 is supported');
|
|
30
|
-
process.exit(1);
|
|
31
|
-
}
|
|
32
|
-
this.pocketIc = await PocketIc.create(pocketIcBin);
|
|
33
|
-
// @ts-ignore
|
|
34
|
-
this.process = this.pocketIc.server.serverProcess;
|
|
35
|
-
}
|
|
36
|
-
await new Promise((resolve, reject) => {
|
|
37
|
-
console.log(1);
|
|
38
|
-
this.process?.on('data', (data) => {
|
|
39
|
-
console.log(111, data);
|
|
40
|
-
});
|
|
41
|
-
});
|
|
42
|
-
return this.process;
|
|
43
|
-
}
|
|
44
|
-
async stop() {
|
|
45
|
-
if (this.type == 'dfx') {
|
|
46
|
-
execSync('dfx stop' + (this.verbose ? '' : ' -qqqq'), { cwd: this.cwd, stdio: ['pipe', this.verbose ? 'inherit' : 'ignore', 'pipe'] });
|
|
47
|
-
}
|
|
48
|
-
else if (this.pocketIc) {
|
|
49
|
-
await this.pocketIc.tearDown();
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
async deploy(name, wasm, cwd = process.cwd()) {
|
|
53
|
-
if (this.type === 'dfx') {
|
|
54
|
-
await execaCommand(`dfx deploy ${name} --mode reinstall --yes --identity anonymous`, { cwd, stdio: this.verbose ? 'pipe' : ['pipe', 'ignore', 'pipe'] });
|
|
55
|
-
let canisterId = execSync(`dfx canister id ${name}`, { cwd }).toString().trim();
|
|
56
|
-
let actor = await createActor(canisterId, {
|
|
57
|
-
agentOptions: {
|
|
58
|
-
host: 'http://127.0.0.1:4944',
|
|
59
|
-
},
|
|
60
|
-
});
|
|
61
|
-
this.canisters[name] = { cwd, canisterId, actor };
|
|
62
|
-
}
|
|
63
|
-
else if (this.pocketIc) {
|
|
64
|
-
let { canisterId, actor } = await this.pocketIc.setupCanister(idlFactory, wasm);
|
|
65
|
-
this.canisters[name] = {
|
|
66
|
-
cwd,
|
|
67
|
-
canisterId: canisterId.toText(),
|
|
68
|
-
actor,
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
getActor(name) {
|
|
73
|
-
return this.canisters[name]?.actor;
|
|
74
|
-
}
|
|
75
|
-
getCanisterId(name) {
|
|
76
|
-
return this.canisters[name]?.canisterId || '';
|
|
77
|
-
}
|
|
78
|
-
dfxJson(canisterName) {
|
|
79
|
-
let canisters = {};
|
|
80
|
-
if (canisterName) {
|
|
81
|
-
canisters[canisterName] = {
|
|
82
|
-
type: 'custom',
|
|
83
|
-
wasm: 'canister.wasm',
|
|
84
|
-
candid: 'canister.did',
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
return {
|
|
88
|
-
version: 1,
|
|
89
|
-
canisters,
|
|
90
|
-
defaults: {
|
|
91
|
-
build: {
|
|
92
|
-
packtool: 'mops sources',
|
|
93
|
-
},
|
|
94
|
-
},
|
|
95
|
-
networks: {
|
|
96
|
-
local: {
|
|
97
|
-
type: 'ephemeral',
|
|
98
|
-
bind: '127.0.0.1:4944',
|
|
99
|
-
},
|
|
100
|
-
},
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
}
|