ic-mops 0.28.0 → 0.29.0-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.
Files changed (51) hide show
  1. package/commands/add.ts +12 -3
  2. package/commands/update.ts +30 -2
  3. package/declarations/main/main.did +36 -0
  4. package/declarations/main/main.did.d.ts +28 -0
  5. package/declarations/main/main.did.js +32 -0
  6. package/dist/bench/$USER_BENCH_FILE.mo +45 -0
  7. package/dist/bench/bench-canister.mo +57 -0
  8. package/dist/commands/add.js +11 -3
  9. package/dist/commands/bench/$USER_BENCH_FILE.mo +45 -0
  10. package/dist/commands/bench/bench/$USER_BENCH_FILE.mo +45 -0
  11. package/dist/commands/bench/bench/bench-canister.mo +57 -0
  12. package/dist/commands/bench/bench-canister.mo +85 -0
  13. package/dist/commands/bench/declarations/bench/bench.did.d.ts +6 -0
  14. package/dist/commands/bench/declarations/bench/bench.did.js +22 -0
  15. package/dist/commands/bench/declarations/bench/index.d.ts +2 -0
  16. package/dist/commands/bench/declarations/bench/index.js +30 -0
  17. package/dist/commands/bench/declarations/main/index.d.ts +2 -0
  18. package/dist/commands/bench/declarations/main/index.js +30 -0
  19. package/dist/commands/bench/declarations/main/main.did.d.ts +6 -0
  20. package/dist/commands/bench/declarations/main/main.did.js +242 -0
  21. package/dist/commands/bench/declarations/storage/index.d.ts +4 -0
  22. package/dist/commands/bench/declarations/storage/index.js +26 -0
  23. package/dist/commands/bench/declarations/storage/storage.did.d.ts +6 -0
  24. package/dist/commands/bench/declarations/storage/storage.did.js +34 -0
  25. package/dist/commands/bench/user-bench.mo +14 -0
  26. package/dist/commands/bench.d.ts +10 -0
  27. package/dist/commands/bench.js +214 -0
  28. package/dist/commands/update.js +27 -2
  29. package/dist/declarations/bench/bench.did +24 -0
  30. package/dist/declarations/bench/bench.did.d.ts +24 -0
  31. package/dist/declarations/bench/bench.did.js +24 -0
  32. package/dist/declarations/bench/index.d.ts +50 -0
  33. package/dist/declarations/bench/index.js +41 -0
  34. package/dist/declarations/main/main.did +36 -0
  35. package/dist/declarations/main/main.did.d.ts +28 -0
  36. package/dist/declarations/main/main.did.js +32 -0
  37. package/dist/helpers/get-dfx-version.d.ts +1 -0
  38. package/dist/helpers/get-dfx-version.js +9 -0
  39. package/dist/helpers/get-moc-path.d.ts +1 -0
  40. package/dist/helpers/get-moc-path.js +11 -0
  41. package/dist/helpers/get-moc-version.d.ts +1 -0
  42. package/dist/helpers/get-moc-version.js +7 -0
  43. package/dist/mops.d.ts +4 -2
  44. package/dist/mops.js +13 -4
  45. package/dist/notify-installs.js +2 -2
  46. package/dist/package.json +1 -1
  47. package/dist/vessel.js +10 -10
  48. package/mops.ts +13 -5
  49. package/notify-installs.ts +2 -2
  50. package/package.json +1 -1
  51. package/vessel.ts +10 -10
@@ -0,0 +1,24 @@
1
+ import type { Principal } from '@dfinity/principal';
2
+ import type { ActorMethod } from '@dfinity/agent';
3
+
4
+ export interface BenchResult {
5
+ 'instructions' : bigint,
6
+ 'rts_memory_size' : bigint,
7
+ 'rts_total_allocation' : bigint,
8
+ 'rts_collector_instructions' : bigint,
9
+ 'rts_mutator_instructions' : bigint,
10
+ 'rts_heap_size' : bigint,
11
+ }
12
+ export interface BenchSchema {
13
+ 'cols' : Array<string>,
14
+ 'name' : string,
15
+ 'rows' : Array<string>,
16
+ 'description' : string,
17
+ }
18
+ export interface anon_class_10_1 {
19
+ 'getStats' : ActorMethod<[], BenchResult>,
20
+ 'init' : ActorMethod<[], BenchSchema>,
21
+ 'runCellQuery' : ActorMethod<[bigint, bigint], BenchResult>,
22
+ 'runCellUpdate' : ActorMethod<[bigint, bigint], BenchResult>,
23
+ }
24
+ export interface _SERVICE extends anon_class_10_1 {}
@@ -0,0 +1,24 @@
1
+ export const idlFactory = ({ IDL }) => {
2
+ const BenchResult = IDL.Record({
3
+ 'instructions' : IDL.Int,
4
+ 'rts_memory_size' : IDL.Int,
5
+ 'rts_total_allocation' : IDL.Int,
6
+ 'rts_collector_instructions' : IDL.Int,
7
+ 'rts_mutator_instructions' : IDL.Int,
8
+ 'rts_heap_size' : IDL.Int,
9
+ });
10
+ const BenchSchema = IDL.Record({
11
+ 'cols' : IDL.Vec(IDL.Text),
12
+ 'name' : IDL.Text,
13
+ 'rows' : IDL.Vec(IDL.Text),
14
+ 'description' : IDL.Text,
15
+ });
16
+ const anon_class_10_1 = IDL.Service({
17
+ 'getStats' : IDL.Func([], [BenchResult], ['query']),
18
+ 'init' : IDL.Func([], [BenchSchema], []),
19
+ 'runCellQuery' : IDL.Func([IDL.Nat, IDL.Nat], [BenchResult], ['query']),
20
+ 'runCellUpdate' : IDL.Func([IDL.Nat, IDL.Nat], [BenchResult], []),
21
+ });
22
+ return anon_class_10_1;
23
+ };
24
+ export const init = ({ IDL }) => { return []; };
@@ -0,0 +1,50 @@
1
+ import type {
2
+ ActorSubclass,
3
+ HttpAgentOptions,
4
+ ActorConfig,
5
+ Agent,
6
+ } from "@dfinity/agent";
7
+ import type { Principal } from "@dfinity/principal";
8
+ import type { IDL } from "@dfinity/candid";
9
+
10
+ import { _SERVICE } from './bench.did';
11
+
12
+ export declare const idlFactory: IDL.InterfaceFactory;
13
+ export declare const canisterId: string;
14
+
15
+ export declare interface CreateActorOptions {
16
+ /**
17
+ * @see {@link Agent}
18
+ */
19
+ agent?: Agent;
20
+ /**
21
+ * @see {@link HttpAgentOptions}
22
+ */
23
+ agentOptions?: HttpAgentOptions;
24
+ /**
25
+ * @see {@link ActorConfig}
26
+ */
27
+ actorOptions?: ActorConfig;
28
+ }
29
+
30
+ /**
31
+ * Intializes an {@link ActorSubclass}, configured with the provided SERVICE interface of a canister.
32
+ * @constructs {@link ActorSubClass}
33
+ * @param {string | Principal} canisterId - ID of the canister the {@link Actor} will talk to
34
+ * @param {CreateActorOptions} options - see {@link CreateActorOptions}
35
+ * @param {CreateActorOptions["agent"]} options.agent - a pre-configured agent you'd like to use. Supercedes agentOptions
36
+ * @param {CreateActorOptions["agentOptions"]} options.agentOptions - options to set up a new agent
37
+ * @see {@link HttpAgentOptions}
38
+ * @param {CreateActorOptions["actorOptions"]} options.actorOptions - options for the Actor
39
+ * @see {@link ActorConfig}
40
+ */
41
+ export declare const createActor: (
42
+ canisterId: string | Principal,
43
+ options?: CreateActorOptions
44
+ ) => ActorSubclass<_SERVICE>;
45
+
46
+ /**
47
+ * Intialized Actor using default settings, ready to talk to a canister using its candid interface
48
+ * @constructs {@link ActorSubClass}
49
+ */
50
+ export declare const bench: ActorSubclass<_SERVICE>;
@@ -0,0 +1,41 @@
1
+ import { Actor, HttpAgent } from "@dfinity/agent";
2
+
3
+ // Imports and re-exports candid interface
4
+ import { idlFactory } from "./bench.did.js";
5
+ export { idlFactory } from "./bench.did.js";
6
+
7
+ /* CANISTER_ID is replaced by webpack based on node environment
8
+ * Note: canister environment variable will be standardized as
9
+ * process.env.CANISTER_ID_<CANISTER_NAME_UPPERCASE>
10
+ * beginning in dfx 0.15.0
11
+ */
12
+ export const canisterId =
13
+ process.env.CANISTER_ID_BENCH ||
14
+ process.env.BENCH_CANISTER_ID;
15
+
16
+ export const createActor = (canisterId, options = {}) => {
17
+ const agent = options.agent || new HttpAgent({ ...options.agentOptions });
18
+
19
+ if (options.agent && options.agentOptions) {
20
+ console.warn(
21
+ "Detected both agent and agentOptions passed to createActor. Ignoring agentOptions and proceeding with the provided agent."
22
+ );
23
+ }
24
+
25
+ // Fetch root key for certificate validation during development
26
+ if (process.env.DFX_NETWORK !== "ic") {
27
+ agent.fetchRootKey().catch((err) => {
28
+ console.warn(
29
+ "Unable to fetch root key. Check to ensure that your local replica is running"
30
+ );
31
+ console.error(err);
32
+ });
33
+ }
34
+
35
+ // Creates an actor with using the candid interface and the HttpAgent
36
+ return Actor.createActor(idlFactory, {
37
+ agent,
38
+ canisterId,
39
+ ...options.actorOptions,
40
+ });
41
+ };
@@ -41,6 +41,20 @@ type TestStats =
41
41
  passed: nat;
42
42
  passedNames: vec text;
43
43
  };
44
+ type StreamingToken = blob;
45
+ type StreamingStrategy = variant {
46
+ Callback:
47
+ record {
48
+ callback: StreamingCallback;
49
+ token: StreamingToken;
50
+ };};
51
+ type StreamingCallbackResponse =
52
+ record {
53
+ body: blob;
54
+ token: opt StreamingToken;
55
+ };
56
+ type StreamingCallback = func (StreamingToken) ->
57
+ (opt StreamingCallbackResponse) query;
44
58
  type StorageStats =
45
59
  record {
46
60
  cyclesBalance: nat;
@@ -102,6 +116,22 @@ type Result =
102
116
  err: Err;
103
117
  ok;
104
118
  };
119
+ type Response =
120
+ record {
121
+ body: blob;
122
+ headers: vec Header;
123
+ status_code: nat16;
124
+ streaming_strategy: opt StreamingStrategy;
125
+ upgrade: opt bool;
126
+ };
127
+ type Request =
128
+ record {
129
+ body: blob;
130
+ certificate_version: opt nat16;
131
+ headers: vec Header;
132
+ method: text;
133
+ url: text;
134
+ };
105
135
  type PublishingId = text;
106
136
  type PublishingErr = text;
107
137
  type PageCount = nat;
@@ -232,6 +262,11 @@ type PackageChanges =
232
262
  notes: text;
233
263
  tests: TestsChanges;
234
264
  };
265
+ type Header =
266
+ record {
267
+ text;
268
+ text;
269
+ };
235
270
  type FileId = text;
236
271
  type Err = text;
237
272
  type DownloadsSnapshot__1 =
@@ -300,6 +335,7 @@ service : {
300
335
  getTotalDownloads: () -> (nat) query;
301
336
  getTotalPackages: () -> (nat) query;
302
337
  getUser: (principal) -> (opt User__1) query;
338
+ http_request: (Request) -> (Response) query;
303
339
  notifyInstall: (PackageName__1, PackageVersion) -> () oneway;
304
340
  notifyInstalls: (vec record {
305
341
  PackageName__1;
@@ -23,6 +23,7 @@ export interface DownloadsSnapshot__1 {
23
23
  }
24
24
  export type Err = string;
25
25
  export type FileId = string;
26
+ export type Header = [string, string];
26
27
  export interface PackageChanges {
27
28
  'tests' : TestsChanges,
28
29
  'deps' : Array<DepChange>,
@@ -142,6 +143,20 @@ export type PackageVersion = string;
142
143
  export type PageCount = bigint;
143
144
  export type PublishingErr = string;
144
145
  export type PublishingId = string;
146
+ export interface Request {
147
+ 'url' : string,
148
+ 'method' : string,
149
+ 'body' : Uint8Array | number[],
150
+ 'headers' : Array<Header>,
151
+ 'certificate_version' : [] | [number],
152
+ }
153
+ export interface Response {
154
+ 'body' : Uint8Array | number[],
155
+ 'headers' : Array<Header>,
156
+ 'upgrade' : [] | [boolean],
157
+ 'streaming_strategy' : [] | [StreamingStrategy],
158
+ 'status_code' : number,
159
+ }
145
160
  export type Result = { 'ok' : null } |
146
161
  { 'err' : Err };
147
162
  export type Result_1 = { 'ok' : PublishingId } |
@@ -168,6 +183,18 @@ export interface StorageStats {
168
183
  'cyclesBalance' : bigint,
169
184
  'memorySize' : bigint,
170
185
  }
186
+ export type StreamingCallback = ActorMethod<
187
+ [StreamingToken],
188
+ [] | [StreamingCallbackResponse]
189
+ >;
190
+ export interface StreamingCallbackResponse {
191
+ 'token' : [] | [StreamingToken],
192
+ 'body' : Uint8Array | number[],
193
+ }
194
+ export type StreamingStrategy = {
195
+ 'Callback' : { 'token' : StreamingToken, 'callback' : StreamingCallback }
196
+ };
197
+ export type StreamingToken = Uint8Array | number[];
171
198
  export interface TestStats { 'passedNames' : Array<string>, 'passed' : bigint }
172
199
  export interface TestStats__1 {
173
200
  'passedNames' : Array<string>,
@@ -246,6 +273,7 @@ export interface _SERVICE {
246
273
  'getTotalDownloads' : ActorMethod<[], bigint>,
247
274
  'getTotalPackages' : ActorMethod<[], bigint>,
248
275
  'getUser' : ActorMethod<[Principal], [] | [User__1]>,
276
+ 'http_request' : ActorMethod<[Request], Response>,
249
277
  'notifyInstall' : ActorMethod<[PackageName__1, PackageVersion], undefined>,
250
278
  'notifyInstalls' : ActorMethod<
251
279
  [Array<[PackageName__1, PackageVersion]>],
@@ -174,6 +174,37 @@ export const idlFactory = ({ IDL }) => {
174
174
  'githubVerified' : IDL.Bool,
175
175
  'github' : IDL.Text,
176
176
  });
177
+ const Header = IDL.Tuple(IDL.Text, IDL.Text);
178
+ const Request = IDL.Record({
179
+ 'url' : IDL.Text,
180
+ 'method' : IDL.Text,
181
+ 'body' : IDL.Vec(IDL.Nat8),
182
+ 'headers' : IDL.Vec(Header),
183
+ 'certificate_version' : IDL.Opt(IDL.Nat16),
184
+ });
185
+ const StreamingToken = IDL.Vec(IDL.Nat8);
186
+ const StreamingCallbackResponse = IDL.Record({
187
+ 'token' : IDL.Opt(StreamingToken),
188
+ 'body' : IDL.Vec(IDL.Nat8),
189
+ });
190
+ const StreamingCallback = IDL.Func(
191
+ [StreamingToken],
192
+ [IDL.Opt(StreamingCallbackResponse)],
193
+ ['query'],
194
+ );
195
+ const StreamingStrategy = IDL.Variant({
196
+ 'Callback' : IDL.Record({
197
+ 'token' : StreamingToken,
198
+ 'callback' : StreamingCallback,
199
+ }),
200
+ });
201
+ const Response = IDL.Record({
202
+ 'body' : IDL.Vec(IDL.Nat8),
203
+ 'headers' : IDL.Vec(Header),
204
+ 'upgrade' : IDL.Opt(IDL.Bool),
205
+ 'streaming_strategy' : IDL.Opt(StreamingStrategy),
206
+ 'status_code' : IDL.Nat16,
207
+ });
177
208
  const PageCount = IDL.Nat;
178
209
  const Result_3 = IDL.Variant({ 'ok' : IDL.Null, 'err' : IDL.Text });
179
210
  const Result_2 = IDL.Variant({ 'ok' : FileId, 'err' : Err });
@@ -270,6 +301,7 @@ export const idlFactory = ({ IDL }) => {
270
301
  'getTotalDownloads' : IDL.Func([], [IDL.Nat], ['query']),
271
302
  'getTotalPackages' : IDL.Func([], [IDL.Nat], ['query']),
272
303
  'getUser' : IDL.Func([IDL.Principal], [IDL.Opt(User__1)], ['query']),
304
+ 'http_request' : IDL.Func([Request], [Response], ['query']),
273
305
  'notifyInstall' : IDL.Func(
274
306
  [PackageName__1, PackageVersion],
275
307
  [],
@@ -0,0 +1 @@
1
+ export declare function getDfxVersion(): string;
@@ -0,0 +1,9 @@
1
+ import { execSync } from 'node:child_process';
2
+ export function getDfxVersion() {
3
+ try {
4
+ let res = execSync('dfx --version').toString();
5
+ return res.trim().split('dfx ')[1] || '';
6
+ }
7
+ catch { }
8
+ return '';
9
+ }
@@ -0,0 +1 @@
1
+ export declare function getMocPath(): string;
@@ -0,0 +1,11 @@
1
+ import { execSync } from 'node:child_process';
2
+ export function getMocPath() {
3
+ let mocPath = process.env.DFX_MOC_PATH;
4
+ if (!mocPath) {
5
+ mocPath = execSync('dfx cache show').toString().trim() + '/moc';
6
+ }
7
+ if (!mocPath) {
8
+ mocPath = 'moc';
9
+ }
10
+ return mocPath;
11
+ }
@@ -0,0 +1 @@
1
+ export declare function getMocVersion(): string;
@@ -0,0 +1,7 @@
1
+ import { execSync } from 'node:child_process';
2
+ import { getMocPath } from './get-moc-path.js';
3
+ export function getMocVersion() {
4
+ let mocPath = getMocPath();
5
+ let match = execSync(mocPath).toString().trim().match(/Motoko compiler ([^\s]+) .*/);
6
+ return match?.[1] || '';
7
+ }
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 | undefined;
25
- gitName: string | undefined;
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,21 @@ export async function getHighestVersion(pkgName) {
179
179
  }
180
180
  export function parseGithubURL(href) {
181
181
  const url = new URL(href);
182
- const branch = url.hash?.substring(1) || 'master';
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
+ return json;
188
197
  }
189
198
  export function getDependencyType(version) {
190
199
  if (!version || typeof version !== 'string') {
@@ -244,8 +253,8 @@ export function formatDir(name, version) {
244
253
  return path.join(getRootDir(), '.mops', `${name}@${version}`);
245
254
  }
246
255
  export function formatGithubDir(name, repo) {
247
- const { branch } = parseGithubURL(repo);
248
- return path.join(getRootDir(), '.mops/_github', `${name}@${branch}`);
256
+ const { branch, commitHash } = parseGithubURL(repo);
257
+ return path.join(getRootDir(), '.mops/_github', `${name}#${branch}` + (commitHash ? `@${commitHash}` : ''));
249
258
  }
250
259
  export function readDfxJson() {
251
260
  let dir = process.cwd();
@@ -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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ic-mops",
3
- "version": "0.28.0",
3
+ "version": "0.29.0-0",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "mops": "dist/cli.js"
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.log(chalk.red('Error: ') + 'Failure - response too old');
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
- const { branch } = parseGithubURL(repo);
118
- const dir = formatGithubDir(name, repo);
119
- const cacheName = `github_${name}@${branch}`;
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'} ${name}@${branch} (already installed) from Github`);
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'} ${name}@${branch} (cache) from Github`);
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'} ${name}@${branch} ${progressBar(step, total)}`);
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,23 @@ export async function getHighestVersion(pkgName: string) {
210
210
 
211
211
  export function parseGithubURL(href: string) {
212
212
  const url = new URL(href);
213
- const branch = url.hash?.substring(1) || 'master';
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
- return {org, gitName, branch};
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 = await res.json();
229
+ return json;
222
230
  }
223
231
 
224
232
  export function getDependencyType(version: string) {
@@ -289,8 +297,8 @@ export function formatDir(name: string, version: string) {
289
297
  }
290
298
 
291
299
  export function formatGithubDir(name: string, repo: string) {
292
- const {branch} = parseGithubURL(repo);
293
- return path.join(getRootDir(), '.mops/_github', `${name}@${branch}`);
300
+ const {branch, commitHash} = parseGithubURL(repo);
301
+ return path.join(getRootDir(), '.mops/_github', `${name}#${branch}` + (commitHash ? `@${commitHash}` : ''));
294
302
  }
295
303
 
296
304
  export function readDfxJson(): any {
@@ -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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ic-mops",
3
- "version": "0.28.0",
3
+ "version": "0.29.0-0",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "mops": "dist/cli.js"
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.log(chalk.red('Error: ') + 'Failure - response too old');
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
- const {branch} = parseGithubURL(repo);
151
- const dir = formatGithubDir(name, repo);
152
- const cacheName = `github_${name}@${branch}`;
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'} ${name}@${branch} (already installed) from Github`);
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'} ${name}@${branch} (cache) from Github`);
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'} ${name}@${branch} ${progressBar(step, total)}`);
165
+ silent || logUpdate(`${dep ? 'Dependency' : 'Installing'} ${repo} ${progressBar(step, total)}`);
166
166
  };
167
167
 
168
168
  progress(0, 2 * (1024 ** 2));