ic-mops 0.29.0-0 → 0.29.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.
@@ -0,0 +1,35 @@
1
+ import chalk from 'chalk';
2
+ import { checkConfigFile, mainActor, readConfig } from '../mops.js';
3
+ import { Principal } from '@dfinity/principal';
4
+ import prompts from 'prompts';
5
+ export async function transferOwnership(toPrincipal) {
6
+ if (!checkConfigFile()) {
7
+ return;
8
+ }
9
+ let config = readConfig();
10
+ let principal = Principal.fromText(toPrincipal);
11
+ let promptsConfig = {
12
+ onCancel() {
13
+ console.log('aborted');
14
+ process.exit(0);
15
+ }
16
+ };
17
+ console.log(chalk.red('Warning: ') + 'This action cannot be undone!');
18
+ let { confirm } = await prompts({
19
+ type: 'confirm',
20
+ name: 'confirm',
21
+ message: `Are you sure you want to transfer ownership of ${chalk.yellow(config.package?.name)} to ${chalk.yellow(toPrincipal)}?`,
22
+ initial: false,
23
+ }, promptsConfig);
24
+ if (!confirm) {
25
+ return;
26
+ }
27
+ let actor = await mainActor(true);
28
+ let res = await actor.transferOwnership(config.package?.name || '', principal);
29
+ if ('ok' in res) {
30
+ console.log(chalk.green('Success!'));
31
+ }
32
+ else {
33
+ console.log(chalk.red('Error: ') + res.err);
34
+ }
35
+ }
@@ -1,5 +1,5 @@
1
1
  import chalk from 'chalk';
2
- import { checkConfigFile, getGithubCommit, parseGithubURL, readConfig } from '../mops.js';
2
+ import { checkConfigFile, 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,34 +7,9 @@ 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}@${commitHash}`, { dev });
27
- }
28
- }
29
- // update mops packages
30
10
  let available = await getAvailableUpdates(config, pkg);
31
11
  if (available.length === 0) {
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
- }
12
+ console.log(chalk.green('All dependencies are up to date!'));
38
13
  }
39
14
  else {
40
15
  for (let dep of available) {
@@ -82,7 +82,7 @@ type Result_6 =
82
82
  variant {
83
83
  err: Err;
84
84
  ok: vec record {
85
- PackageName__1;
85
+ PackageName;
86
86
  PackageVersion;
87
87
  };
88
88
  };
@@ -97,20 +97,20 @@ type Result_4 =
97
97
  ok: PackageDetails;
98
98
  };
99
99
  type Result_3 =
100
- variant {
101
- err: text;
102
- ok;
103
- };
104
- type Result_2 =
105
100
  variant {
106
101
  err: Err;
107
102
  ok: FileId;
108
103
  };
109
- type Result_1 =
104
+ type Result_2 =
110
105
  variant {
111
106
  err: PublishingErr;
112
107
  ok: PublishingId;
113
108
  };
109
+ type Result_1 =
110
+ variant {
111
+ err: text;
112
+ ok;
113
+ };
114
114
  type Result =
115
115
  variant {
116
116
  err: Err;
@@ -223,7 +223,7 @@ type PackageConfigV2__1 =
223
223
  keywords: vec text;
224
224
  license: text;
225
225
  moc: text;
226
- name: PackageName;
226
+ name: PackageName__1;
227
227
  readme: text;
228
228
  repository: text;
229
229
  scripts: vec Script;
@@ -242,7 +242,7 @@ type PackageConfigV2 =
242
242
  keywords: vec text;
243
243
  license: text;
244
244
  moc: text;
245
- name: PackageName;
245
+ name: PackageName__1;
246
246
  readme: text;
247
247
  repository: text;
248
248
  scripts: vec Script;
@@ -283,7 +283,7 @@ type DownloadsSnapshot =
283
283
  };
284
284
  type DependencyV2 =
285
285
  record {
286
- name: PackageName;
286
+ name: PackageName__1;
287
287
  repo: text;
288
288
  version: text;
289
289
  };
@@ -304,25 +304,25 @@ service : {
304
304
  getBackupCanisterId: () -> (principal) query;
305
305
  getDefaultPackages: (text) ->
306
306
  (vec record {
307
- PackageName__1;
307
+ PackageName;
308
308
  PackageVersion;
309
309
  }) query;
310
310
  getDownloadTrendByPackageId: (PackageId) ->
311
311
  (vec DownloadsSnapshot__1) query;
312
- getDownloadTrendByPackageName: (PackageName__1) ->
312
+ getDownloadTrendByPackageName: (PackageName) ->
313
313
  (vec DownloadsSnapshot__1) query;
314
- getFileIds: (PackageName__1, PackageVersion) -> (Result_7) query;
314
+ getFileIds: (PackageName, PackageVersion) -> (Result_7) query;
315
315
  getHighestSemverBatch:
316
316
  (vec record {
317
- PackageName__1;
317
+ PackageName;
318
318
  PackageVersion;
319
319
  SemverPart;
320
320
  }) -> (Result_6) query;
321
- getHighestVersion: (PackageName__1) -> (Result_5) query;
321
+ getHighestVersion: (PackageName) -> (Result_5) query;
322
322
  getMostDownloadedPackages: () -> (vec PackageSummary) query;
323
323
  getMostDownloadedPackagesIn7Days: () -> (vec PackageSummary) query;
324
324
  getNewPackages: () -> (vec PackageSummary) query;
325
- getPackageDetails: (PackageName__1, PackageVersion) -> (Result_4) query;
325
+ getPackageDetails: (PackageName, PackageVersion) -> (Result_4) query;
326
326
  getPackagesByCategory: () -> (vec record {
327
327
  text;
328
328
  vec PackageSummary;
@@ -336,17 +336,18 @@ service : {
336
336
  getTotalPackages: () -> (nat) query;
337
337
  getUser: (principal) -> (opt User__1) query;
338
338
  http_request: (Request) -> (Response) query;
339
- notifyInstall: (PackageName__1, PackageVersion) -> () oneway;
339
+ notifyInstall: (PackageName, PackageVersion) -> () oneway;
340
340
  notifyInstalls: (vec record {
341
- PackageName__1;
341
+ PackageName;
342
342
  PackageVersion;
343
343
  }) -> () oneway;
344
344
  restore: (nat, nat) -> ();
345
345
  search: (Text, opt nat, opt nat) -> (vec PackageSummary, PageCount) query;
346
- setUserProp: (text, text) -> (Result_3);
347
- startFileUpload: (PublishingId, Text, nat, blob) -> (Result_2);
348
- startPublish: (PackageConfigV2) -> (Result_1);
346
+ setUserProp: (text, text) -> (Result_1);
347
+ startFileUpload: (PublishingId, Text, nat, blob) -> (Result_3);
348
+ startPublish: (PackageConfigV2) -> (Result_2);
349
349
  takeAirdropSnapshot: () -> () oneway;
350
+ transferOwnership: (PackageName, principal) -> (Result_1);
350
351
  uploadFileChunk: (PublishingId, FileId, nat, blob) -> (Result);
351
352
  uploadNotes: (PublishingId, text) -> (Result);
352
353
  uploadTestStats: (PublishingId, TestStats) -> (Result);
@@ -7,7 +7,7 @@ export interface DepChange {
7
7
  'newVersion' : string,
8
8
  }
9
9
  export interface DependencyV2 {
10
- 'name' : PackageName,
10
+ 'name' : PackageName__1,
11
11
  'repo' : string,
12
12
  'version' : string,
13
13
  }
@@ -42,7 +42,7 @@ export interface PackageConfigV2 {
42
42
  'scripts' : Array<Script>,
43
43
  'baseDir' : string,
44
44
  'documentation' : string,
45
- 'name' : PackageName,
45
+ 'name' : PackageName__1,
46
46
  'homepage' : string,
47
47
  'description' : string,
48
48
  'version' : string,
@@ -60,7 +60,7 @@ export interface PackageConfigV2__1 {
60
60
  'scripts' : Array<Script>,
61
61
  'baseDir' : string,
62
62
  'documentation' : string,
63
- 'name' : PackageName,
63
+ 'name' : PackageName__1,
64
64
  'homepage' : string,
65
65
  'description' : string,
66
66
  'version' : string,
@@ -159,17 +159,17 @@ export interface Response {
159
159
  }
160
160
  export type Result = { 'ok' : null } |
161
161
  { 'err' : Err };
162
- export type Result_1 = { 'ok' : PublishingId } |
162
+ export type Result_1 = { 'ok' : null } |
163
+ { 'err' : string };
164
+ export type Result_2 = { 'ok' : PublishingId } |
163
165
  { 'err' : PublishingErr };
164
- export type Result_2 = { 'ok' : FileId } |
166
+ export type Result_3 = { 'ok' : FileId } |
165
167
  { 'err' : Err };
166
- export type Result_3 = { 'ok' : null } |
167
- { 'err' : string };
168
168
  export type Result_4 = { 'ok' : PackageDetails } |
169
169
  { 'err' : Err };
170
170
  export type Result_5 = { 'ok' : PackageVersion } |
171
171
  { 'err' : Err };
172
- export type Result_6 = { 'ok' : Array<[PackageName__1, PackageVersion]> } |
172
+ export type Result_6 = { 'ok' : Array<[PackageName, PackageVersion]> } |
173
173
  { 'err' : Err };
174
174
  export type Result_7 = { 'ok' : Array<FileId> } |
175
175
  { 'err' : Err };
@@ -241,26 +241,26 @@ export interface _SERVICE {
241
241
  'getBackupCanisterId' : ActorMethod<[], Principal>,
242
242
  'getDefaultPackages' : ActorMethod<
243
243
  [string],
244
- Array<[PackageName__1, PackageVersion]>
244
+ Array<[PackageName, PackageVersion]>
245
245
  >,
246
246
  'getDownloadTrendByPackageId' : ActorMethod<
247
247
  [PackageId],
248
248
  Array<DownloadsSnapshot__1>
249
249
  >,
250
250
  'getDownloadTrendByPackageName' : ActorMethod<
251
- [PackageName__1],
251
+ [PackageName],
252
252
  Array<DownloadsSnapshot__1>
253
253
  >,
254
- 'getFileIds' : ActorMethod<[PackageName__1, PackageVersion], Result_7>,
254
+ 'getFileIds' : ActorMethod<[PackageName, PackageVersion], Result_7>,
255
255
  'getHighestSemverBatch' : ActorMethod<
256
- [Array<[PackageName__1, PackageVersion, SemverPart]>],
256
+ [Array<[PackageName, PackageVersion, SemverPart]>],
257
257
  Result_6
258
258
  >,
259
- 'getHighestVersion' : ActorMethod<[PackageName__1], Result_5>,
259
+ 'getHighestVersion' : ActorMethod<[PackageName], Result_5>,
260
260
  'getMostDownloadedPackages' : ActorMethod<[], Array<PackageSummary>>,
261
261
  'getMostDownloadedPackagesIn7Days' : ActorMethod<[], Array<PackageSummary>>,
262
262
  'getNewPackages' : ActorMethod<[], Array<PackageSummary>>,
263
- 'getPackageDetails' : ActorMethod<[PackageName__1, PackageVersion], Result_4>,
263
+ 'getPackageDetails' : ActorMethod<[PackageName, PackageVersion], Result_4>,
264
264
  'getPackagesByCategory' : ActorMethod<
265
265
  [],
266
266
  Array<[string, Array<PackageSummary>]>
@@ -274,9 +274,9 @@ export interface _SERVICE {
274
274
  'getTotalPackages' : ActorMethod<[], bigint>,
275
275
  'getUser' : ActorMethod<[Principal], [] | [User__1]>,
276
276
  'http_request' : ActorMethod<[Request], Response>,
277
- 'notifyInstall' : ActorMethod<[PackageName__1, PackageVersion], undefined>,
277
+ 'notifyInstall' : ActorMethod<[PackageName, PackageVersion], undefined>,
278
278
  'notifyInstalls' : ActorMethod<
279
- [Array<[PackageName__1, PackageVersion]>],
279
+ [Array<[PackageName, PackageVersion]>],
280
280
  undefined
281
281
  >,
282
282
  'restore' : ActorMethod<[bigint, bigint], undefined>,
@@ -284,13 +284,14 @@ export interface _SERVICE {
284
284
  [Text, [] | [bigint], [] | [bigint]],
285
285
  [Array<PackageSummary>, PageCount]
286
286
  >,
287
- 'setUserProp' : ActorMethod<[string, string], Result_3>,
287
+ 'setUserProp' : ActorMethod<[string, string], Result_1>,
288
288
  'startFileUpload' : ActorMethod<
289
289
  [PublishingId, Text, bigint, Uint8Array | number[]],
290
- Result_2
290
+ Result_3
291
291
  >,
292
- 'startPublish' : ActorMethod<[PackageConfigV2], Result_1>,
292
+ 'startPublish' : ActorMethod<[PackageConfigV2], Result_2>,
293
293
  'takeAirdropSnapshot' : ActorMethod<[], undefined>,
294
+ 'transferOwnership' : ActorMethod<[PackageName, Principal], Result_1>,
294
295
  'uploadFileChunk' : ActorMethod<
295
296
  [PublishingId, FileId, bigint, Uint8Array | number[]],
296
297
  Result
@@ -18,7 +18,7 @@ export const idlFactory = ({ IDL }) => {
18
18
  const Err = IDL.Text;
19
19
  const Result = IDL.Variant({ 'ok' : IDL.Null, 'err' : Err });
20
20
  const Text = IDL.Text;
21
- const PackageName__1 = IDL.Text;
21
+ const PackageName = IDL.Text;
22
22
  const PackageVersion = IDL.Text;
23
23
  const PackageId = IDL.Text;
24
24
  const Time = IDL.Int;
@@ -35,7 +35,7 @@ export const idlFactory = ({ IDL }) => {
35
35
  'patch' : IDL.Null,
36
36
  });
37
37
  const Result_6 = IDL.Variant({
38
- 'ok' : IDL.Vec(IDL.Tuple(PackageName__1, PackageVersion)),
38
+ 'ok' : IDL.Vec(IDL.Tuple(PackageName, PackageVersion)),
39
39
  'err' : Err,
40
40
  });
41
41
  const Result_5 = IDL.Variant({ 'ok' : PackageVersion, 'err' : Err });
@@ -52,9 +52,9 @@ export const idlFactory = ({ IDL }) => {
52
52
  'github' : IDL.Text,
53
53
  });
54
54
  const Script = IDL.Record({ 'value' : IDL.Text, 'name' : IDL.Text });
55
- const PackageName = IDL.Text;
55
+ const PackageName__1 = IDL.Text;
56
56
  const DependencyV2 = IDL.Record({
57
- 'name' : PackageName,
57
+ 'name' : PackageName__1,
58
58
  'repo' : IDL.Text,
59
59
  'version' : IDL.Text,
60
60
  });
@@ -64,7 +64,7 @@ export const idlFactory = ({ IDL }) => {
64
64
  'scripts' : IDL.Vec(Script),
65
65
  'baseDir' : IDL.Text,
66
66
  'documentation' : IDL.Text,
67
- 'name' : PackageName,
67
+ 'name' : PackageName__1,
68
68
  'homepage' : IDL.Text,
69
69
  'description' : IDL.Text,
70
70
  'version' : IDL.Text,
@@ -206,15 +206,15 @@ export const idlFactory = ({ IDL }) => {
206
206
  'status_code' : IDL.Nat16,
207
207
  });
208
208
  const PageCount = IDL.Nat;
209
- const Result_3 = IDL.Variant({ 'ok' : IDL.Null, 'err' : IDL.Text });
210
- const Result_2 = IDL.Variant({ 'ok' : FileId, 'err' : Err });
209
+ const Result_1 = IDL.Variant({ 'ok' : IDL.Null, 'err' : IDL.Text });
210
+ const Result_3 = IDL.Variant({ 'ok' : FileId, 'err' : Err });
211
211
  const PackageConfigV2 = IDL.Record({
212
212
  'dfx' : IDL.Text,
213
213
  'moc' : IDL.Text,
214
214
  'scripts' : IDL.Vec(Script),
215
215
  'baseDir' : IDL.Text,
216
216
  'documentation' : IDL.Text,
217
- 'name' : PackageName,
217
+ 'name' : PackageName__1,
218
218
  'homepage' : IDL.Text,
219
219
  'description' : IDL.Text,
220
220
  'version' : IDL.Text,
@@ -227,7 +227,7 @@ export const idlFactory = ({ IDL }) => {
227
227
  'readme' : IDL.Text,
228
228
  });
229
229
  const PublishingErr = IDL.Text;
230
- const Result_1 = IDL.Variant({ 'ok' : PublishingId, 'err' : PublishingErr });
230
+ const Result_2 = IDL.Variant({ 'ok' : PublishingId, 'err' : PublishingErr });
231
231
  const TestStats = IDL.Record({
232
232
  'passedNames' : IDL.Vec(IDL.Text),
233
233
  'passed' : IDL.Nat,
@@ -243,7 +243,7 @@ export const idlFactory = ({ IDL }) => {
243
243
  'getBackupCanisterId' : IDL.Func([], [IDL.Principal], ['query']),
244
244
  'getDefaultPackages' : IDL.Func(
245
245
  [IDL.Text],
246
- [IDL.Vec(IDL.Tuple(PackageName__1, PackageVersion))],
246
+ [IDL.Vec(IDL.Tuple(PackageName, PackageVersion))],
247
247
  ['query'],
248
248
  ),
249
249
  'getDownloadTrendByPackageId' : IDL.Func(
@@ -252,21 +252,21 @@ export const idlFactory = ({ IDL }) => {
252
252
  ['query'],
253
253
  ),
254
254
  'getDownloadTrendByPackageName' : IDL.Func(
255
- [PackageName__1],
255
+ [PackageName],
256
256
  [IDL.Vec(DownloadsSnapshot__1)],
257
257
  ['query'],
258
258
  ),
259
259
  'getFileIds' : IDL.Func(
260
- [PackageName__1, PackageVersion],
260
+ [PackageName, PackageVersion],
261
261
  [Result_7],
262
262
  ['query'],
263
263
  ),
264
264
  'getHighestSemverBatch' : IDL.Func(
265
- [IDL.Vec(IDL.Tuple(PackageName__1, PackageVersion, SemverPart))],
265
+ [IDL.Vec(IDL.Tuple(PackageName, PackageVersion, SemverPart))],
266
266
  [Result_6],
267
267
  ['query'],
268
268
  ),
269
- 'getHighestVersion' : IDL.Func([PackageName__1], [Result_5], ['query']),
269
+ 'getHighestVersion' : IDL.Func([PackageName], [Result_5], ['query']),
270
270
  'getMostDownloadedPackages' : IDL.Func(
271
271
  [],
272
272
  [IDL.Vec(PackageSummary)],
@@ -279,7 +279,7 @@ export const idlFactory = ({ IDL }) => {
279
279
  ),
280
280
  'getNewPackages' : IDL.Func([], [IDL.Vec(PackageSummary)], ['query']),
281
281
  'getPackageDetails' : IDL.Func(
282
- [PackageName__1, PackageVersion],
282
+ [PackageName, PackageVersion],
283
283
  [Result_4],
284
284
  ['query'],
285
285
  ),
@@ -302,13 +302,9 @@ export const idlFactory = ({ IDL }) => {
302
302
  'getTotalPackages' : IDL.Func([], [IDL.Nat], ['query']),
303
303
  'getUser' : IDL.Func([IDL.Principal], [IDL.Opt(User__1)], ['query']),
304
304
  'http_request' : IDL.Func([Request], [Response], ['query']),
305
- 'notifyInstall' : IDL.Func(
306
- [PackageName__1, PackageVersion],
307
- [],
308
- ['oneway'],
309
- ),
305
+ 'notifyInstall' : IDL.Func([PackageName, PackageVersion], [], ['oneway']),
310
306
  'notifyInstalls' : IDL.Func(
311
- [IDL.Vec(IDL.Tuple(PackageName__1, PackageVersion))],
307
+ [IDL.Vec(IDL.Tuple(PackageName, PackageVersion))],
312
308
  [],
313
309
  ['oneway'],
314
310
  ),
@@ -318,14 +314,19 @@ export const idlFactory = ({ IDL }) => {
318
314
  [IDL.Vec(PackageSummary), PageCount],
319
315
  ['query'],
320
316
  ),
321
- 'setUserProp' : IDL.Func([IDL.Text, IDL.Text], [Result_3], []),
317
+ 'setUserProp' : IDL.Func([IDL.Text, IDL.Text], [Result_1], []),
322
318
  'startFileUpload' : IDL.Func(
323
319
  [PublishingId, Text, IDL.Nat, IDL.Vec(IDL.Nat8)],
324
- [Result_2],
320
+ [Result_3],
325
321
  [],
326
322
  ),
327
- 'startPublish' : IDL.Func([PackageConfigV2], [Result_1], []),
323
+ 'startPublish' : IDL.Func([PackageConfigV2], [Result_2], []),
328
324
  'takeAirdropSnapshot' : IDL.Func([], [], ['oneway']),
325
+ 'transferOwnership' : IDL.Func(
326
+ [PackageName, IDL.Principal],
327
+ [Result_1],
328
+ [],
329
+ ),
329
330
  'uploadFileChunk' : IDL.Func(
330
331
  [PublishingId, FileId, IDL.Nat, IDL.Vec(IDL.Nat8)],
331
332
  [Result],
package/dist/mops.d.ts CHANGED
@@ -21,12 +21,10 @@ 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 | undefined;
25
+ gitName: string | undefined;
26
26
  branch: string;
27
- commitHash: string;
28
27
  };
29
- export declare function getGithubCommit(repo: string, ref: string): Promise<any>;
30
28
  export declare function getDependencyType(version: string): "mops" | "github" | "local";
31
29
  export declare function readConfig(configFile?: string): Config;
32
30
  export declare function writeConfig(config: Config, configFile?: string): void;
package/dist/mops.js CHANGED
@@ -179,21 +179,12 @@ export async function getHighestVersion(pkgName) {
179
179
  }
180
180
  export function parseGithubURL(href) {
181
181
  const url = new URL(href);
182
- let branchAndSha = url.hash?.substring(1).split('@');
183
- let branch = branchAndSha[0] || 'master';
184
- let commitHash = branchAndSha[1] || '';
182
+ const branch = url.hash?.substring(1) || 'master';
185
183
  let [org, gitName] = url.pathname.split('/').filter(path => !!path);
186
- org = org || '';
187
- gitName = gitName || '';
188
184
  if (gitName?.endsWith('.git')) {
189
185
  gitName = gitName.substring(0, gitName.length - 4);
190
186
  }
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;
187
+ return { org, gitName, branch };
197
188
  }
198
189
  export function getDependencyType(version) {
199
190
  if (!version || typeof version !== 'string') {
@@ -253,8 +244,8 @@ export function formatDir(name, version) {
253
244
  return path.join(getRootDir(), '.mops', `${name}@${version}`);
254
245
  }
255
246
  export function formatGithubDir(name, repo) {
256
- const { branch, commitHash } = parseGithubURL(repo);
257
- return path.join(getRootDir(), '.mops/_github', `${name}#${branch}` + (commitHash ? `@${commitHash}` : ''));
247
+ const { branch } = parseGithubURL(repo);
248
+ return path.join(getRootDir(), '.mops/_github', `${name}@${branch}`);
258
249
  }
259
250
  export function readDfxJson() {
260
251
  let dir = process.cwd();
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ic-mops",
3
- "version": "0.29.0-0",
3
+ "version": "0.29.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, commitHash } = parseGithubURL(repo);
63
- const zipFile = `https://github.com/${org}/${gitName}/archive/${commitHash || branch}.zip`;
62
+ const { branch, org, gitName } = parseGithubURL(repo);
63
+ const zipFile = `https://github.com/${org}/${gitName}/archive/${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.error(chalk.red('Error: ') + 'Failure - response too old');
74
+ console.log(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}@${commitHash || branch}.zip`);
82
+ const tmpFile = path.resolve(tmpDir, `${gitName}@${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
- let { branch, commitHash } = parseGithubURL(repo);
118
- let dir = formatGithubDir(name, repo);
119
- let cacheName = `_github/${name}#${branch}` + (commitHash ? `@${commitHash}` : '');
117
+ const { branch } = parseGithubURL(repo);
118
+ const dir = formatGithubDir(name, repo);
119
+ const cacheName = `github_${name}@${branch}`;
120
120
  if (existsSync(dir)) {
121
- silent || logUpdate(`${dep ? 'Dependency' : 'Installing'} ${repo} (local cache) from Github`);
121
+ silent || logUpdate(`${dep ? 'Dependency' : 'Installing'} ${name}@${branch} (already installed) from Github`);
122
122
  }
123
123
  else if (isCached(cacheName)) {
124
124
  await copyCache(cacheName, dir);
125
- silent || logUpdate(`${dep ? 'Dependency' : 'Installing'} ${repo} (global cache) from Github`);
125
+ silent || logUpdate(`${dep ? 'Dependency' : 'Installing'} ${name}@${branch} (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'} ${repo} ${progressBar(step, total)}`);
130
+ silent || logUpdate(`${dep ? 'Dependency' : 'Installing'} ${name}@${branch} ${progressBar(step, total)}`);
131
131
  };
132
132
  progress(0, 2 * (1024 ** 2));
133
133
  try {
package/mops.ts CHANGED
@@ -210,23 +210,15 @@ export async function getHighestVersion(pkgName: string) {
210
210
 
211
211
  export function parseGithubURL(href: string) {
212
212
  const url = new URL(href);
213
- let branchAndSha = url.hash?.substring(1).split('@');
214
- let branch = branchAndSha[0] || 'master';
215
- let commitHash = branchAndSha[1] || '';
213
+ const branch = url.hash?.substring(1) || 'master';
214
+
216
215
  let [org, gitName] = url.pathname.split('/').filter(path => !!path);
217
- org = org || '';
218
- gitName = gitName || '';
219
216
 
220
217
  if (gitName?.endsWith('.git')) {
221
218
  gitName = gitName.substring(0, gitName.length - 4);
222
219
  }
223
- return {org, gitName, branch, commitHash};
224
- }
225
220
 
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;
221
+ return {org, gitName, branch};
230
222
  }
231
223
 
232
224
  export function getDependencyType(version: string) {
@@ -297,8 +289,8 @@ export function formatDir(name: string, version: string) {
297
289
  }
298
290
 
299
291
  export function formatGithubDir(name: string, repo: string) {
300
- const {branch, commitHash} = parseGithubURL(repo);
301
- return path.join(getRootDir(), '.mops/_github', `${name}#${branch}` + (commitHash ? `@${commitHash}` : ''));
292
+ const {branch} = parseGithubURL(repo);
293
+ return path.join(getRootDir(), '.mops/_github', `${name}@${branch}`);
302
294
  }
303
295
 
304
296
  export function readDfxJson(): any {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ic-mops",
3
- "version": "0.29.0-0",
3
+ "version": "0.29.0",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "mops": "dist/cli.js"