ic-mops 0.33.0 → 0.34.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/api/actors.ts +45 -0
- package/api/downloadPackageFiles.ts +78 -0
- package/api/getHighestVersion.ts +6 -0
- package/api/index.ts +4 -0
- package/api/network.ts +24 -0
- package/api/resolveVersion.ts +12 -0
- package/cli.ts +18 -4
- package/commands/add.ts +2 -1
- package/commands/available-updates.ts +1 -1
- package/commands/init.ts +2 -1
- package/commands/install.ts +26 -49
- package/commands/publish.ts +4 -2
- package/commands/search.ts +2 -3
- package/commands/transfer-ownership.ts +4 -2
- package/commands/user.ts +5 -2
- package/dist/api/actors.d.ts +6 -0
- package/dist/api/actors.js +32 -0
- package/dist/api/downloadPackageFiles.d.ts +12 -0
- package/dist/api/downloadPackageFiles.js +62 -0
- package/dist/api/getHighestVersion.d.ts +1 -0
- package/dist/api/getHighestVersion.js +5 -0
- package/dist/api/index.d.ts +4 -0
- package/dist/api/index.js +4 -0
- package/dist/api/network.d.ts +5 -0
- package/dist/api/network.js +23 -0
- package/dist/api/resolveVersion.d.ts +1 -0
- package/dist/api/resolveVersion.js +11 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.js +11 -5
- package/dist/commands/add.js +2 -1
- package/dist/commands/available-updates.js +1 -1
- package/dist/commands/init.js +2 -1
- package/dist/commands/install.js +22 -43
- package/dist/commands/publish.js +4 -2
- package/dist/commands/search.js +2 -3
- package/dist/commands/transfer-ownership.js +4 -2
- package/dist/commands/user.js +4 -2
- package/dist/helpers/download-package-files.d.ts +12 -0
- package/dist/helpers/download-package-files.js +62 -0
- package/dist/helpers/resolve-version.d.ts +1 -0
- package/dist/helpers/resolve-version.js +11 -0
- package/dist/integrity.js +2 -1
- package/dist/mops.d.ts +6 -12
- package/dist/mops.js +15 -70
- package/dist/notify-installs.js +2 -1
- package/dist/package.json +1 -1
- package/integrity.ts +2 -1
- package/mops.ts +24 -85
- package/notify-installs.ts +2 -1
- package/package.json +1 -1
package/mops.ts
CHANGED
|
@@ -1,19 +1,17 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import fs from 'node:fs';
|
|
3
|
-
import {
|
|
3
|
+
import {Identity} from '@dfinity/agent';
|
|
4
4
|
import TOML from '@iarna/toml';
|
|
5
5
|
import chalk from 'chalk';
|
|
6
6
|
import prompts from 'prompts';
|
|
7
7
|
import ncp from 'ncp';
|
|
8
8
|
import fetch from 'node-fetch';
|
|
9
9
|
|
|
10
|
-
import {idlFactory} from './declarations/main/index.js';
|
|
11
|
-
import {_SERVICE} from './declarations/main/main.did.js';
|
|
12
|
-
import {idlFactory as storageIdlFactory} from './declarations/storage/index.js';
|
|
13
|
-
import {_SERVICE as _STORAGE_SERVICE} from './declarations/storage/storage.did.js';
|
|
14
10
|
import {decodeFile} from './pem.js';
|
|
15
11
|
import {Config} from './types.js';
|
|
16
|
-
import {
|
|
12
|
+
import {mainActor, storageActor} from './api/actors.js';
|
|
13
|
+
import {getNetwork} from './api/network.js';
|
|
14
|
+
import {getHighestVersion} from './api/getHighestVersion.js';
|
|
17
15
|
|
|
18
16
|
|
|
19
17
|
if (!global.fetch) {
|
|
@@ -23,14 +21,6 @@ if (!global.fetch) {
|
|
|
23
21
|
// (!) make changes in pair with backend
|
|
24
22
|
export let apiVersion = '1.2';
|
|
25
23
|
|
|
26
|
-
let networkFile: string | URL = '';
|
|
27
|
-
try {
|
|
28
|
-
networkFile = new URL('./network.txt', import.meta.url);
|
|
29
|
-
}
|
|
30
|
-
catch {
|
|
31
|
-
networkFile = path.join(__dirname, 'network.txt');
|
|
32
|
-
}
|
|
33
|
-
|
|
34
24
|
export let globalConfigDir = '';
|
|
35
25
|
export let globalCacheDir = '';
|
|
36
26
|
|
|
@@ -83,37 +73,20 @@ if (fs.existsSync(oldGlobalConfigDir) && !fs.existsSync(globalCacheDir)) {
|
|
|
83
73
|
console.log('Moved cache to ' + chalk.green(globalCacheDir));
|
|
84
74
|
}
|
|
85
75
|
|
|
86
|
-
export function setNetwork(network: string) {
|
|
87
|
-
fs.writeFileSync(networkFile, network);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
export function getNetwork() {
|
|
91
|
-
let network = 'ic';
|
|
92
|
-
if (fs.existsSync(networkFile)) {
|
|
93
|
-
network = fs.readFileSync(networkFile).toString() || 'ic';
|
|
94
|
-
}
|
|
95
76
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
canisterId: '2d2zu-vaaaa-aaaak-qb6pq-cai',
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
else if (network === 'ic') {
|
|
104
|
-
return {
|
|
105
|
-
network,
|
|
106
|
-
host: 'https://icp-api.io',
|
|
107
|
-
canisterId: 'oknww-riaaa-aaaam-qaf6a-cai',
|
|
108
|
-
};
|
|
77
|
+
export function getNetworkFile(): string | URL {
|
|
78
|
+
let networkFile: string | URL = '';
|
|
79
|
+
try {
|
|
80
|
+
networkFile = new URL('./network.txt', import.meta.url);
|
|
109
81
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
network,
|
|
113
|
-
host: 'http://127.0.0.1:4943',
|
|
114
|
-
canisterId: '2d2zu-vaaaa-aaaak-qb6pq-cai',
|
|
115
|
-
};
|
|
82
|
+
catch {
|
|
83
|
+
networkFile = path.join(__dirname, 'network.txt');
|
|
116
84
|
}
|
|
85
|
+
return networkFile;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export function setNetwork(network: string) {
|
|
89
|
+
fs.writeFileSync(getNetworkFile(), network);
|
|
117
90
|
}
|
|
118
91
|
|
|
119
92
|
export let getIdentity = async (): Promise<Identity | undefined> => {
|
|
@@ -133,43 +106,6 @@ export let getIdentity = async (): Promise<Identity | undefined> => {
|
|
|
133
106
|
return undefined;
|
|
134
107
|
};
|
|
135
108
|
|
|
136
|
-
export let mainActor = async (useIdentity = false): Promise<_SERVICE> => {
|
|
137
|
-
let network = getNetwork().network;
|
|
138
|
-
let host = getNetwork().host;
|
|
139
|
-
let canisterId = getNetwork().canisterId;
|
|
140
|
-
|
|
141
|
-
let identity = useIdentity ? await getIdentity() : undefined;
|
|
142
|
-
// @ts-ignore exactOptionalPropertyTypes
|
|
143
|
-
let agent = new HttpAgent({host, identity});
|
|
144
|
-
|
|
145
|
-
if (network === 'local') {
|
|
146
|
-
await agent.fetchRootKey();
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
return Actor.createActor(idlFactory, {
|
|
150
|
-
agent,
|
|
151
|
-
canisterId,
|
|
152
|
-
});
|
|
153
|
-
};
|
|
154
|
-
|
|
155
|
-
export let storageActor = async (storageId: Principal, useIdentity = false): Promise<_STORAGE_SERVICE> => {
|
|
156
|
-
let network = getNetwork().network;
|
|
157
|
-
let host = getNetwork().host;
|
|
158
|
-
|
|
159
|
-
let identity = useIdentity && await getIdentity();
|
|
160
|
-
// @ts-ignore exactOptionalPropertyTypes
|
|
161
|
-
let agent = new HttpAgent({host, identity});
|
|
162
|
-
|
|
163
|
-
if (network === 'local') {
|
|
164
|
-
await agent.fetchRootKey();
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
return Actor.createActor(storageIdlFactory, {
|
|
168
|
-
agent,
|
|
169
|
-
canisterId: storageId,
|
|
170
|
-
});
|
|
171
|
-
};
|
|
172
|
-
|
|
173
109
|
export function getClosestConfigFile(dir = process.cwd()) {
|
|
174
110
|
if (!path.basename(dir)) {
|
|
175
111
|
throw '';
|
|
@@ -203,11 +139,6 @@ export function progressBar(step: number, total: number) {
|
|
|
203
139
|
return `[${':'.repeat(done)}${' '.repeat(Math.max(0, 10 - done))}]`;
|
|
204
140
|
}
|
|
205
141
|
|
|
206
|
-
export async function getHighestVersion(pkgName: string) {
|
|
207
|
-
let actor = await mainActor();
|
|
208
|
-
return actor.getHighestVersion(pkgName);
|
|
209
|
-
}
|
|
210
|
-
|
|
211
142
|
export function parseGithubURL(href: string) {
|
|
212
143
|
const url = new URL(href);
|
|
213
144
|
let branchAndSha = url.hash?.substring(1).split('@');
|
|
@@ -338,4 +269,12 @@ export async function checkApiCompatibility() {
|
|
|
338
269
|
console.log('-'.repeat(50));
|
|
339
270
|
}
|
|
340
271
|
return true;
|
|
341
|
-
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
// compatibility with older versions
|
|
275
|
+
export {
|
|
276
|
+
getNetwork,
|
|
277
|
+
mainActor,
|
|
278
|
+
storageActor,
|
|
279
|
+
getHighestVersion,
|
|
280
|
+
};
|
package/notify-installs.ts
CHANGED