ic-mops 0.39.2 → 0.41.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 (183) hide show
  1. package/.DS_Store +0 -0
  2. package/.eslintrc.json +0 -0
  3. package/.gitignore +1 -0
  4. package/.npmrc +2 -1
  5. package/CHANGELOG.md +8 -0
  6. package/DEVELOPMENT.md +25 -0
  7. package/README.md +0 -0
  8. package/api/actors.ts +2 -2
  9. package/api/downloadPackageFiles.ts +9 -6
  10. package/api/getHighestVersion.ts +1 -1
  11. package/api/index.ts +0 -0
  12. package/api/network.ts +1 -1
  13. package/api/resolveVersion.ts +1 -1
  14. package/bundle/bench/bench-canister.mo +87 -0
  15. package/bundle/bench/user-bench.mo +14 -0
  16. package/bundle/bin/moc-wrapper.sh +3 -0
  17. package/bundle/bin/mops.js +3 -0
  18. package/bundle/cli.js +88 -0
  19. package/bundle/cli.tgz +0 -0
  20. package/bundle/declarations/bench/bench.did +26 -0
  21. package/bundle/declarations/bench/bench.did.d.ts +29 -0
  22. package/bundle/declarations/bench/bench.did.js +26 -0
  23. package/bundle/declarations/bench/index.d.ts +50 -0
  24. package/bundle/declarations/bench/index.js +41 -0
  25. package/bundle/declarations/main/index.d.ts +50 -0
  26. package/bundle/declarations/main/index.js +41 -0
  27. package/bundle/declarations/main/main.did +426 -0
  28. package/bundle/declarations/main/main.did.d.ts +352 -0
  29. package/bundle/declarations/main/main.did.js +404 -0
  30. package/bundle/declarations/storage/index.d.ts +50 -0
  31. package/bundle/declarations/storage/index.js +30 -0
  32. package/bundle/declarations/storage/storage.did +46 -0
  33. package/bundle/declarations/storage/storage.did.d.ts +37 -0
  34. package/bundle/declarations/storage/storage.did.js +38 -0
  35. package/bundle/package.json +31 -0
  36. package/bundle/templates/README.md +13 -0
  37. package/bundle/templates/licenses/Apache-2.0 +202 -0
  38. package/bundle/templates/licenses/Apache-2.0-NOTICE +13 -0
  39. package/bundle/templates/licenses/MIT +21 -0
  40. package/bundle/templates/mops-publish.yml +17 -0
  41. package/bundle/templates/mops-test.yml +22 -0
  42. package/bundle/templates/src/lib.mo +15 -0
  43. package/bundle/templates/test/lib.test.mo +4 -0
  44. package/bundle-package-json.ts +14 -0
  45. package/cache.ts +3 -3
  46. package/cli.ts +25 -21
  47. package/commands/add.ts +6 -6
  48. package/commands/available-updates.ts +2 -2
  49. package/commands/bench/bench-canister.mo +0 -0
  50. package/commands/bench/user-bench.mo +0 -0
  51. package/commands/bench-replica.ts +10 -10
  52. package/commands/bench.ts +96 -56
  53. package/commands/bump.ts +2 -2
  54. package/commands/docs.ts +1 -1
  55. package/commands/import-identity.ts +2 -2
  56. package/commands/init.ts +9 -9
  57. package/commands/install-all.ts +4 -4
  58. package/commands/install-local.ts +1 -1
  59. package/commands/install.ts +2 -2
  60. package/commands/outdated.ts +0 -0
  61. package/commands/publish.ts +34 -35
  62. package/commands/remove.ts +8 -8
  63. package/commands/search.ts +2 -2
  64. package/commands/self.ts +75 -0
  65. package/commands/sources.ts +0 -0
  66. package/commands/sync.ts +8 -8
  67. package/commands/template.ts +11 -12
  68. package/commands/test/mmf1.ts +18 -18
  69. package/commands/test/reporters/compact-reporter.ts +5 -5
  70. package/commands/test/reporters/files-reporter.ts +3 -3
  71. package/commands/test/reporters/reporter.ts +3 -3
  72. package/commands/test/reporters/silent-reporter.ts +4 -4
  73. package/commands/test/reporters/verbose-reporter.ts +3 -3
  74. package/commands/test/test.ts +10 -10
  75. package/commands/test/utils.ts +1 -1
  76. package/commands/toolchain/index.ts +9 -9
  77. package/commands/toolchain/moc.ts +2 -2
  78. package/commands/toolchain/pocket-ic.ts +6 -31
  79. package/commands/toolchain/toolchain-utils.ts +11 -11
  80. package/commands/toolchain/wasmtime.ts +2 -2
  81. package/commands/transfer-ownership.ts +2 -2
  82. package/commands/update.ts +4 -4
  83. package/commands/user.ts +2 -2
  84. package/commands/whoami.ts +0 -0
  85. package/declarations/bench/bench.did.d.ts +3 -0
  86. package/declarations/main/main.did +27 -1
  87. package/declarations/main/main.did.d.ts +26 -1
  88. package/declarations/main/main.did.js +27 -1
  89. package/declarations/storage/index.d.ts +0 -0
  90. package/declarations/storage/index.js +0 -0
  91. package/declarations/storage/storage.did +0 -0
  92. package/declarations/storage/storage.did.d.ts +0 -0
  93. package/declarations/storage/storage.did.js +0 -0
  94. package/dist/api/downloadPackageFiles.d.ts +1 -1
  95. package/dist/api/downloadPackageFiles.js +4 -0
  96. package/dist/bin/moc-wrapper.sh +3 -0
  97. package/dist/bin/mops.d.ts +1 -1
  98. package/dist/bin/mops.js +2 -1
  99. package/dist/bundle-package-json.d.ts +1 -0
  100. package/dist/bundle-package-json.js +11 -0
  101. package/dist/check-requirements.d.ts +3 -0
  102. package/dist/check-requirements.js +39 -0
  103. package/dist/cli.js +19 -18
  104. package/dist/commands/bench/bench-canister.mo +0 -0
  105. package/dist/commands/bench/user-bench.mo +0 -0
  106. package/dist/commands/bench-replica.d.ts +3 -1
  107. package/dist/commands/bench-replica.js +2 -2
  108. package/dist/commands/bench.d.ts +5 -2
  109. package/dist/commands/bench.js +66 -29
  110. package/dist/commands/init.js +1 -1
  111. package/dist/commands/publish.d.ts +1 -0
  112. package/dist/commands/publish.js +25 -25
  113. package/dist/commands/self.d.ts +3 -0
  114. package/dist/commands/self.js +62 -0
  115. package/dist/commands/template.js +9 -10
  116. package/dist/commands/test/mmf1.js +1 -1
  117. package/dist/commands/test/test.js +2 -2
  118. package/dist/commands/toolchain/pocket-ic.d.ts +1 -5
  119. package/dist/commands/toolchain/pocket-ic.js +4 -27
  120. package/dist/commands/toolchain/toolchain-utils.d.ts +1 -1
  121. package/dist/commands/toolchain/toolchain-utils.js +7 -7
  122. package/dist/commands/transfer-ownership.js +1 -1
  123. package/dist/declarations/bench/bench.did.d.ts +3 -0
  124. package/dist/declarations/main/main.did +27 -1
  125. package/dist/declarations/main/main.did.d.ts +26 -1
  126. package/dist/declarations/main/main.did.js +27 -1
  127. package/dist/declarations/storage/index.d.ts +0 -0
  128. package/dist/declarations/storage/index.js +0 -0
  129. package/dist/declarations/storage/storage.did +0 -0
  130. package/dist/declarations/storage/storage.did.d.ts +0 -0
  131. package/dist/declarations/storage/storage.did.js +0 -0
  132. package/dist/helpers/find-changelog-entry.d.ts +1 -0
  133. package/dist/helpers/find-changelog-entry.js +24 -0
  134. package/dist/mops.d.ts +1 -0
  135. package/dist/mops.js +5 -1
  136. package/dist/package.json +20 -26
  137. package/dist/release-cli.d.ts +1 -0
  138. package/dist/release-cli.js +37 -0
  139. package/dist/remove-scripts.d.ts +1 -0
  140. package/dist/remove-scripts.js +5 -0
  141. package/dist/templates/README.md +0 -0
  142. package/dist/templates/licenses/Apache-2.0 +0 -0
  143. package/dist/templates/licenses/Apache-2.0-NOTICE +0 -0
  144. package/dist/templates/licenses/MIT +0 -0
  145. package/dist/templates/mops-publish.yml +0 -0
  146. package/dist/templates/mops-test.yml +0 -0
  147. package/dist/templates/src/lib.mo +0 -0
  148. package/dist/templates/test/lib.test.mo +0 -0
  149. package/dist/templates.d.ts +1 -0
  150. package/dist/templates.js +4 -0
  151. package/dist/vessel.js +1 -1
  152. package/global.d.ts +0 -0
  153. package/helpers/find-changelog-entry.ts +27 -0
  154. package/helpers/get-dfx-version.ts +1 -1
  155. package/helpers/get-moc-path.ts +1 -1
  156. package/helpers/get-moc-version.ts +1 -1
  157. package/integrity.ts +16 -16
  158. package/mops.ts +22 -17
  159. package/notify-installs.ts +2 -2
  160. package/package.json +28 -19
  161. package/parallel.ts +1 -1
  162. package/pem.ts +5 -5
  163. package/release-cli.ts +62 -0
  164. package/remove-scripts.ts +6 -0
  165. package/resolve-packages.ts +9 -9
  166. package/templates/README.md +0 -0
  167. package/templates/licenses/Apache-2.0 +0 -0
  168. package/templates/licenses/Apache-2.0-NOTICE +0 -0
  169. package/templates/licenses/MIT +0 -0
  170. package/templates/mops-publish.yml +0 -0
  171. package/templates/mops-test.yml +0 -0
  172. package/templates/src/lib.mo +0 -0
  173. package/templates/test/lib.test.mo +0 -0
  174. package/templates.ts +5 -0
  175. package/tsconfig.json +1 -1
  176. package/types.ts +25 -25
  177. package/vessel.ts +16 -16
  178. package/commands/self-update.ts +0 -6
  179. package/dist/commands/replica.d.ts +0 -36
  180. package/dist/commands/replica.js +0 -103
  181. package/dist/commands/self-update.d.ts +0 -3
  182. package/dist/commands/self-update.js +0 -5
  183. /package/bin/{mops.ts → mops.js} +0 -0
@@ -1,12 +1,15 @@
1
+ import { Benchmarks } from '../declarations/main/main.did.js';
1
2
  type BenchOptions = {
2
3
  replica: 'dfx' | 'pocket-ic';
3
4
  replicaVersion: string;
4
- moc: string;
5
+ compiler: 'moc';
6
+ compilerVersion: string;
5
7
  gc: 'copying' | 'compacting' | 'generational' | 'incremental';
6
8
  forceGc: boolean;
7
9
  save: boolean;
8
10
  compare: boolean;
9
11
  verbose: boolean;
12
+ silent: boolean;
10
13
  };
11
- export declare function bench(filter?: string, optionsArg?: Partial<BenchOptions>): Promise<boolean>;
14
+ export declare function bench(filter?: string, optionsArg?: Partial<BenchOptions>): Promise<Benchmarks>;
12
15
  export {};
@@ -7,7 +7,7 @@ import { markdownTable } from 'markdown-table';
7
7
  import logUpdate from 'log-update';
8
8
  import { execaCommand } from 'execa';
9
9
  import stringWidth from 'string-width';
10
- import { getRootDir } from '../mops.js';
10
+ import { getRootDir, readConfig } from '../mops.js';
11
11
  import { parallel } from '../parallel.js';
12
12
  import { absToRel } from './test/utils.js';
13
13
  import { getMocVersion } from '../helpers/get-moc-version.js';
@@ -28,16 +28,24 @@ let globConfig = {
28
28
  export async function bench(filter = '', optionsArg = {}) {
29
29
  let defaultOptions = {
30
30
  replica: 'dfx',
31
- moc: getMocVersion(),
32
- replicaVersion: '0.0.0',
31
+ replicaVersion: '',
32
+ compiler: 'moc',
33
+ compilerVersion: getMocVersion(),
33
34
  gc: 'copying',
34
35
  forceGc: true,
35
36
  save: false,
36
37
  compare: false,
37
38
  verbose: false,
39
+ silent: false,
38
40
  };
39
41
  let options = { ...defaultOptions, ...optionsArg };
40
- options.replicaVersion = options.replica == 'dfx' ? getDfxVersion() : '1.0.0';
42
+ if (options.replica == 'dfx') {
43
+ options.replicaVersion = getDfxVersion();
44
+ }
45
+ else if (options.replica == 'pocket-ic') {
46
+ let config = readConfig();
47
+ options.replicaVersion = config.toolchain?.['pocket-ic'] || '';
48
+ }
41
49
  options.verbose && console.log(options);
42
50
  let replica = new BenchReplica(options.replica, options.verbose);
43
51
  let rootDir = getRootDir();
@@ -48,26 +56,30 @@ export async function bench(filter = '', optionsArg = {}) {
48
56
  let files = globSync(path.join(rootDir, globStr), globConfig);
49
57
  if (!files.length) {
50
58
  if (filter) {
51
- console.log(`No benchmark files found for filter '${filter}'`);
52
- return false;
59
+ options.silent || console.log(`No benchmark files found for filter '${filter}'`);
60
+ return [];
61
+ }
62
+ if (!options.silent) {
63
+ console.log('No *.bench.mo files found');
64
+ console.log('Put your benchmark code in \'bench\' directory in *.bench.mo files');
53
65
  }
54
- console.log('No *.bench.mo files found');
55
- console.log('Put your benchmark code in \'bench\' directory in *.bench.mo files');
56
- return false;
66
+ return [];
57
67
  }
58
68
  files.sort();
59
69
  let benchDir = `${getRootDir()}/.mops/.bench/`;
60
70
  fs.rmSync(benchDir, { recursive: true, force: true });
61
71
  fs.mkdirSync(benchDir, { recursive: true });
62
- console.log('Benchmark files:');
63
- for (let file of files) {
64
- console.log(chalk.gray(`• ${absToRel(file)}`));
72
+ if (!options.silent) {
73
+ console.log('Benchmark files:');
74
+ for (let file of files) {
75
+ console.log(chalk.gray(`• ${absToRel(file)}`));
76
+ }
77
+ console.log('');
78
+ console.log('='.repeat(50));
79
+ console.log('');
65
80
  }
66
- console.log('');
67
- console.log('='.repeat(50));
68
- console.log('');
69
- await replica.start();
70
- console.log('Deploying canisters...');
81
+ await replica.start({ silent: options.silent });
82
+ options.silent || console.log('Deploying canisters...');
71
83
  await parallel(os.cpus().length, files, async (file) => {
72
84
  try {
73
85
  await deployBenchFile(file, options, replica);
@@ -78,12 +90,16 @@ export async function bench(filter = '', optionsArg = {}) {
78
90
  throw err;
79
91
  }
80
92
  });
93
+ let benchResults = [];
81
94
  await parallel(1, files, async (file) => {
82
- console.log('\n' + '—'.repeat(50));
83
- console.log(`\nRunning ${chalk.gray(absToRel(file))}...`);
84
- console.log('');
95
+ if (!options.silent) {
96
+ console.log('\n' + '—'.repeat(50));
97
+ console.log(`\nRunning ${chalk.gray(absToRel(file))}...`);
98
+ console.log('');
99
+ }
85
100
  try {
86
- await runBenchFile(file, options, replica);
101
+ let benchResult = await runBenchFile(file, options, replica);
102
+ benchResults.push(benchResult);
87
103
  }
88
104
  catch (err) {
89
105
  console.error('Unexpected error. Stopping replica...');
@@ -91,10 +107,10 @@ export async function bench(filter = '', optionsArg = {}) {
91
107
  throw err;
92
108
  }
93
109
  });
94
- console.log('Stopping replica...');
110
+ options.silent || console.log('Stopping replica...');
95
111
  await replica.stop();
96
112
  fs.rmSync(benchDir, { recursive: true, force: true });
97
- return true;
113
+ return benchResults;
98
114
  }
99
115
  function getMocArgs(options) {
100
116
  let args = '';
@@ -152,6 +168,8 @@ async function runBenchFile(file, options, replica) {
152
168
  }
153
169
  }
154
170
  let results = new Map();
171
+ let instructionsCells = Array.from({ length: schema.rows.length }, () => []);
172
+ let heapCells = Array.from({ length: schema.rows.length }, () => []);
155
173
  let formatNumber = (n) => {
156
174
  return n.toLocaleString('en-US').replaceAll(',', '_');
157
175
  };
@@ -199,17 +217,19 @@ async function runBenchFile(file, options, replica) {
199
217
  \n\n${chalk.blue('Heap')}\n\n${getTable('rts_heap_size')}
200
218
  `);
201
219
  };
202
- if (!process.env.CI) {
220
+ if (!process.env.CI && !options.silent) {
203
221
  printResults();
204
222
  }
205
223
  // run all cells
206
224
  for (let [rowIndex, row] of schema.rows.entries()) {
207
225
  for (let [colIndex, col] of schema.cols.entries()) {
208
- // let res = await actor.runCellQuery(BigInt(rowIndex), BigInt(colIndex));
209
- // let res = await actor.runCellUpdate(BigInt(rowIndex), BigInt(colIndex));
210
226
  let res = await actor.runCellUpdateAwait(BigInt(rowIndex), BigInt(colIndex));
211
227
  results.set(`${row}:${col}`, res);
212
- if (!process.env.CI) {
228
+ // @ts-ignore
229
+ instructionsCells[rowIndex][colIndex] = res.instructions;
230
+ // @ts-ignore
231
+ heapCells[rowIndex][colIndex] = res.rts_heap_size;
232
+ if (!process.env.CI && !options.silent) {
213
233
  printResults();
214
234
  }
215
235
  }
@@ -223,7 +243,7 @@ async function runBenchFile(file, options, replica) {
223
243
  console.log(`Saving results to ${chalk.gray(absToRel(resultsJsonFile))}`);
224
244
  let json = {
225
245
  version: 1,
226
- moc: options.moc,
246
+ moc: options.compilerVersion,
227
247
  replica: options.replica,
228
248
  replicaVersion: options.replicaVersion,
229
249
  gc: options.gc,
@@ -240,5 +260,22 @@ async function runBenchFile(file, options, replica) {
240
260
  }
241
261
  }, 2));
242
262
  }
243
- return { schema, results };
263
+ // for backend
264
+ return {
265
+ name: schema.name,
266
+ description: schema.description,
267
+ file: absToRel(file),
268
+ gc: options.gc,
269
+ forceGC: options.forceGc,
270
+ replica: options.replica,
271
+ replicaVersion: options.replicaVersion,
272
+ compiler: options.compiler,
273
+ compilerVersion: options.compilerVersion,
274
+ rows: schema.rows,
275
+ cols: schema.cols,
276
+ metrics: [
277
+ ['instructions', instructionsCells],
278
+ ['rts_heap_size', heapCells],
279
+ ],
280
+ };
244
281
  }
@@ -51,7 +51,7 @@ export async function init({ yes = false } = {}) {
51
51
  onCancel() {
52
52
  console.log('aborted');
53
53
  process.exit(0);
54
- }
54
+ },
55
55
  };
56
56
  // type
57
57
  let { type } = await prompts({
@@ -1,4 +1,5 @@
1
1
  export declare function publish(options?: {
2
2
  docs?: boolean;
3
3
  test?: boolean;
4
+ bench?: boolean;
4
5
  }): Promise<void>;
@@ -5,14 +5,14 @@ import logUpdate from 'log-update';
5
5
  import { globbySync } from 'globby';
6
6
  import { minimatch } from 'minimatch';
7
7
  import prompts from 'prompts';
8
- import { fromMarkdown } from 'mdast-util-from-markdown';
9
- import { toMarkdown } from 'mdast-util-to-markdown';
10
8
  import { checkConfigFile, getIdentity, getRootDir, progressBar, readConfig } from '../mops.js';
11
9
  import { mainActor } from '../api/actors.js';
12
10
  import { parallel } from '../parallel.js';
13
11
  import { docs } from './docs.js';
14
12
  import { testWithReporter } from './test/test.js';
15
13
  import { SilentReporter } from './test/reporters/silent-reporter.js';
14
+ import { findChangelogEntry } from '../helpers/find-changelog-entry.js';
15
+ import { bench } from './bench.js';
16
16
  export async function publish(options = {}) {
17
17
  if (!checkConfigFile()) {
18
18
  return;
@@ -145,7 +145,7 @@ export async function publish(options = {}) {
145
145
  return {
146
146
  ...dep,
147
147
  version: dep.version || '',
148
- repo: dep.repo || ''
148
+ repo: dep.repo || '',
149
149
  };
150
150
  };
151
151
  // map fields
@@ -231,6 +231,24 @@ export async function publish(options = {}) {
231
231
  process.exit(1);
232
232
  }
233
233
  }
234
+ // bench
235
+ let benchmarks = [];
236
+ if (options.bench) {
237
+ console.log('Running benchmarks...');
238
+ try {
239
+ benchmarks = await bench('', {
240
+ replica: config.toolchain?.['pocket-ic'] ? 'pocket-ic' : 'dfx',
241
+ gc: 'copying',
242
+ forceGc: true,
243
+ silent: true,
244
+ });
245
+ }
246
+ catch (err) {
247
+ console.error(err);
248
+ console.log(chalk.red('Error: ') + 'benchmarks failed');
249
+ process.exit(1);
250
+ }
251
+ }
234
252
  // progress
235
253
  let total = files.length + 2;
236
254
  let step = 0;
@@ -255,6 +273,10 @@ export async function publish(options = {}) {
255
273
  passedNames: reporter.passedNamesFlat,
256
274
  });
257
275
  }
276
+ // upload benchmarks
277
+ if (options.bench) {
278
+ await actor.uploadBenchmarks(puiblishingId, benchmarks);
279
+ }
258
280
  // upload changelog
259
281
  if (changelog) {
260
282
  await actor.uploadNotes(puiblishingId, changelog);
@@ -332,25 +354,3 @@ async function fetchGitHubReleaseNotes(repo, version) {
332
354
  }
333
355
  return release.body;
334
356
  }
335
- function findChangelogEntry(changelog, version) {
336
- let tree = fromMarkdown(changelog);
337
- let found = false;
338
- let nodes = [];
339
- for (let node of tree.children) {
340
- if (found) {
341
- if (node.type === 'heading') {
342
- break;
343
- }
344
- else {
345
- nodes.push(node);
346
- }
347
- }
348
- else if (node.type === 'heading' && toMarkdown(node).match(new RegExp(`\\b${version}\\b`))) {
349
- found = true;
350
- }
351
- }
352
- return toMarkdown({
353
- type: 'root',
354
- children: nodes,
355
- });
356
- }
@@ -0,0 +1,3 @@
1
+ export declare function getLatestVersion(): Promise<string>;
2
+ export declare function update(): Promise<void>;
3
+ export declare function uninstall(): Promise<void>;
@@ -0,0 +1,62 @@
1
+ import child_process, { execSync } from 'node:child_process';
2
+ import chalk from 'chalk';
3
+ import { version, globalConfigDir } from '../mops.js';
4
+ import { cleanCache } from '../cache.js';
5
+ import { toolchain } from './toolchain/index.js';
6
+ let url = 'https://x344g-ziaaa-aaaap-abl7a-cai.icp0.io';
7
+ function detectPackageManager() {
8
+ let res = '';
9
+ try {
10
+ res = execSync('which mops').toString();
11
+ }
12
+ catch (e) { }
13
+ if (!res) {
14
+ console.error(chalk.red('Couldn\'t detect package manager'));
15
+ process.exit(1);
16
+ }
17
+ if (res.includes('pnpm/')) {
18
+ return 'pnpm';
19
+ }
20
+ // else if (res.includes('bun/')) {
21
+ // return 'bun';
22
+ // }
23
+ else {
24
+ return 'npm';
25
+ }
26
+ }
27
+ export async function getLatestVersion() {
28
+ let res = await fetch(url + '/tags/latest');
29
+ return res.text();
30
+ }
31
+ export async function update() {
32
+ let latest = await getLatestVersion();
33
+ let current = version();
34
+ if (latest === current) {
35
+ console.log(chalk.green('You are up to date. Version: ' + current));
36
+ }
37
+ else {
38
+ console.log('Current version: ' + chalk.yellow(current));
39
+ console.log('Updating to version: ' + chalk.green(latest));
40
+ let pm = detectPackageManager();
41
+ let npmArgs = pm === 'npm' ? ['--no-fund', '--silent'] : [];
42
+ let proc = child_process.spawn(pm, ['add', '-g', ...npmArgs, `${url}/versions/${latest}.tgz`], { stdio: 'inherit', detached: false });
43
+ proc.on('exit', (res) => {
44
+ if (res !== 0) {
45
+ console.log(chalk.red('Failed to update.'));
46
+ process.exit(1);
47
+ }
48
+ console.log(chalk.green('Success'));
49
+ });
50
+ }
51
+ }
52
+ export async function uninstall() {
53
+ console.log('Cleaning cache...');
54
+ cleanCache();
55
+ console.log('Resetting toolchain management...');
56
+ toolchain.init({ reset: true, silent: true });
57
+ console.log('Uninstalling mops CLI...');
58
+ let pm = detectPackageManager();
59
+ child_process.spawn(pm, ['remove', '-g', '--silent', 'ic-mops'], { stdio: 'inherit', detached: false });
60
+ console.log(chalk.yellow('Config directory has not been deleted: ' + globalConfigDir));
61
+ console.log('Uninstalled');
62
+ }
@@ -4,6 +4,7 @@ import chalk from 'chalk';
4
4
  import prompts from 'prompts';
5
5
  import camelCase from 'camelcase';
6
6
  import { getRootDir, readConfig } from '../mops.js';
7
+ import { copyTemplateFileSync } from '../templates.js';
7
8
  export async function template(templateName, options = {}) {
8
9
  if (!templateName) {
9
10
  let res = await prompts({
@@ -30,9 +31,8 @@ export async function template(templateName, options = {}) {
30
31
  console.log(chalk.yellow('Workflow already exists:'), path.relative(getRootDir(), dest));
31
32
  return;
32
33
  }
33
- let mopsTestYml = new URL('../templates/mops-test.yml', import.meta.url);
34
34
  fs.mkdirSync(path.resolve(getRootDir(), '.github/workflows'), { recursive: true });
35
- fs.copyFileSync(mopsTestYml, dest);
35
+ copyTemplateFileSync('mops-test.yml', dest);
36
36
  console.log(chalk.green('Created'), path.relative(getRootDir(), dest));
37
37
  }
38
38
  else if (templateName === 'github-workflow:mops-publish') {
@@ -41,9 +41,8 @@ export async function template(templateName, options = {}) {
41
41
  console.log(chalk.yellow('Workflow already exists:'), path.relative(getRootDir(), dest));
42
42
  return;
43
43
  }
44
- let mopsPublishYml = new URL('../templates/mops-publish.yml', import.meta.url);
45
44
  fs.mkdirSync(path.resolve(getRootDir(), '.github/workflows'), { recursive: true });
46
- fs.copyFileSync(mopsPublishYml, dest);
45
+ copyTemplateFileSync('mops-publish.yml', dest);
47
46
  console.log(chalk.green('Created'), path.relative(getRootDir(), dest));
48
47
  }
49
48
  else if (templateName?.startsWith('license:')) {
@@ -61,13 +60,13 @@ export async function template(templateName, options = {}) {
61
60
  fs.writeFileSync(file, license);
62
61
  };
63
62
  if (templateName === 'license:MIT') {
64
- fs.copyFileSync(new URL('../templates/licenses/MIT', import.meta.url), path.resolve(getRootDir(), 'LICENSE'));
63
+ copyTemplateFileSync('licenses/MIT', path.resolve(getRootDir(), 'LICENSE'));
65
64
  setYearAndOwner(path.resolve(getRootDir(), 'LICENSE'));
66
65
  console.log(chalk.green('Created'), path.relative(getRootDir(), 'LICENSE'));
67
66
  }
68
67
  else if (templateName === 'license:Apache-2.0') {
69
- fs.copyFileSync(new URL('../templates/licenses/Apache-2.0', import.meta.url), path.resolve(getRootDir(), 'LICENSE'));
70
- fs.copyFileSync(new URL('../templates/licenses/Apache-2.0-NOTICE', import.meta.url), path.resolve(getRootDir(), 'NOTICE'));
68
+ copyTemplateFileSync('licenses/Apache-2.0', path.resolve(getRootDir(), 'LICENSE'));
69
+ copyTemplateFileSync('licenses/Apache-2.0-NOTICE', path.resolve(getRootDir(), 'NOTICE'));
71
70
  setYearAndOwner(path.resolve(getRootDir(), 'NOTICE'));
72
71
  console.log(chalk.green('Created'), path.relative(getRootDir(), 'LICENSE'));
73
72
  console.log(chalk.green('Created'), path.relative(getRootDir(), 'NOTICE'));
@@ -75,12 +74,12 @@ export async function template(templateName, options = {}) {
75
74
  }
76
75
  else if (templateName === 'lib.mo') {
77
76
  fs.mkdirSync(path.join(getRootDir(), 'src'), { recursive: true });
78
- fs.copyFileSync(new URL('../templates/src/lib.mo', import.meta.url), path.resolve(getRootDir(), 'src/lib.mo'));
77
+ copyTemplateFileSync('src/lib.mo', path.resolve(getRootDir(), 'src/lib.mo'));
79
78
  console.log(chalk.green('Created'), path.relative(getRootDir(), 'src/lib.mo'));
80
79
  }
81
80
  else if (templateName === 'lib.test.mo') {
82
81
  fs.mkdirSync(path.join(getRootDir(), 'test'), { recursive: true });
83
- fs.copyFileSync(new URL('../templates/test/lib.test.mo', import.meta.url), path.resolve(getRootDir(), 'test/lib.test.mo'));
82
+ copyTemplateFileSync('test/lib.test.mo', path.resolve(getRootDir(), 'test/lib.test.mo'));
84
83
  console.log(chalk.green('Created'), path.relative(getRootDir(), 'test/lib.test.mo'));
85
84
  }
86
85
  else if (templateName === 'readme') {
@@ -89,7 +88,7 @@ export async function template(templateName, options = {}) {
89
88
  console.log(chalk.yellow('README.md already exists'));
90
89
  return;
91
90
  }
92
- fs.copyFileSync(new URL('../templates/README.md', import.meta.url), dest);
91
+ copyTemplateFileSync('README.md', dest);
93
92
  let config = readConfig();
94
93
  let data = fs.readFileSync(dest).toString();
95
94
  data = data.replace(/<year>/g, new Date().getFullYear().toString());
@@ -24,7 +24,7 @@ export class MMF1 {
24
24
  if (this.srategy === 'store') {
25
25
  this.output.push({
26
26
  type,
27
- message: args.join(' ')
27
+ message: args.join(' '),
28
28
  });
29
29
  }
30
30
  else if (this.srategy === 'print') {
@@ -142,14 +142,14 @@ export async function testWithReporter(reporter, filter = '', mode = 'interprete
142
142
  '-C', 'cache=n',
143
143
  '-W', 'bulk-memory',
144
144
  '-W', 'multi-memory',
145
- '-W', 'max-wasm-stack=2000000',
145
+ '-W', 'max-wasm-stack=4000000',
146
146
  '-W', 'nan-canonicalization=y',
147
147
  wasmFile,
148
148
  ];
149
149
  }
150
150
  else {
151
151
  wasmtimeArgs = [
152
- '--max-wasm-stack=2000000',
152
+ '--max-wasm-stack=4000000',
153
153
  '--enable-cranelift-nan-canonicalization',
154
154
  '--wasm-features',
155
155
  'multi-memory,bulk-memory',
@@ -1,10 +1,6 @@
1
1
  export declare let repo: string;
2
2
  export declare let getLatestReleaseTag: () => Promise<string>;
3
- export declare let getReleases: () => Promise<{
4
- tag_name: string;
5
- published_at: Date;
6
- draft: boolean;
7
- }[]>;
3
+ export declare let getReleases: () => Promise<any>;
8
4
  export declare let isCached: (version: string) => boolean;
9
5
  export declare let download: (version: string, { silent, verbose }?: {
10
6
  silent?: boolean | undefined;
@@ -5,28 +5,10 @@ import * as toolchainUtils from './toolchain-utils.js';
5
5
  let cacheDir = path.join(globalCacheDir, 'pocket-ic');
6
6
  export let repo = 'dfinity/pocketic';
7
7
  export let getLatestReleaseTag = async () => {
8
- return '1.0.0';
9
- // return toolchainUtils.getLatestReleaseTag(repo);
8
+ return toolchainUtils.getLatestReleaseTag(repo);
10
9
  };
11
10
  export let getReleases = async () => {
12
- // return toolchainUtils.getReleases(repo);
13
- return [
14
- {
15
- tag_name: '2.0.1',
16
- published_at: new Date('2023-11-23'),
17
- draft: false,
18
- },
19
- {
20
- tag_name: '2.0.0',
21
- published_at: new Date('2023-11-21'),
22
- draft: false,
23
- },
24
- {
25
- tag_name: '1.0.0',
26
- published_at: new Date('2023-10-12'),
27
- draft: false,
28
- },
29
- ];
11
+ return toolchainUtils.getReleases(repo);
30
12
  };
31
13
  export let isCached = (version) => {
32
14
  let dir = path.join(cacheDir, version);
@@ -45,14 +27,9 @@ export let download = async (version, { silent = false, verbose = false } = {})
45
27
  }
46
28
  let platfrom = process.platform == 'darwin' ? 'darwin' : 'linux';
47
29
  let arch = 'x86_64';
48
- let hashes = {
49
- '2.0.1': '69e1408347723dbaa7a6cd2faa9b65c42abbe861',
50
- '2.0.0': '29ec86dc9f9ca4691d4d4386c8b2aa41e14d9d16',
51
- '1.0.0': '307d5847c1d2fe1f5e19181c7d0fcec23f4658b3',
52
- };
53
- let url = `https://download.dfinity.systems/ic/${hashes[version]}/openssl-static-binaries/${arch}-${platfrom}/pocket-ic.gz`;
30
+ let url = `https://github.com/dfinity/pocketic/releases/download/${version}/pocket-ic-${arch}-${platfrom}.gz`;
54
31
  if (verbose && !silent) {
55
32
  console.log(`Downloading ${url}`);
56
33
  }
57
- await toolchainUtils.downloadAndExtract(url, path.join(cacheDir, version));
34
+ await toolchainUtils.downloadAndExtract(url, path.join(cacheDir, version), 'pocket-ic');
58
35
  };
@@ -1,3 +1,3 @@
1
- export declare let downloadAndExtract: (url: string, dest: string) => Promise<void>;
1
+ export declare let downloadAndExtract: (url: string, destDir: string, destFileName?: string) => Promise<void>;
2
2
  export declare let getLatestReleaseTag: (repo: string) => Promise<string>;
3
3
  export declare let getReleases: (repo: string) => Promise<any>;
@@ -8,7 +8,7 @@ import { deleteSync } from 'del';
8
8
  import { Octokit } from 'octokit';
9
9
  import tar from 'tar';
10
10
  import { getRootDir } from '../../mops.js';
11
- export let downloadAndExtract = async (url, dest) => {
11
+ export let downloadAndExtract = async (url, destDir, destFileName = '') => {
12
12
  let res = await fetch(url);
13
13
  if (res.status !== 200) {
14
14
  console.error(`ERROR ${res.status} ${url}`);
@@ -20,7 +20,7 @@ export let downloadAndExtract = async (url, dest) => {
20
20
  let archive = path.join(tmpDir, path.basename(url));
21
21
  fs.mkdirSync(tmpDir, { recursive: true });
22
22
  fs.writeFileSync(archive, buffer);
23
- fs.mkdirSync(dest, { recursive: true });
23
+ fs.mkdirSync(destDir, { recursive: true });
24
24
  if (archive.endsWith('.xz')) {
25
25
  let decompressTarxz = await import('decomp-tarxz');
26
26
  await decompress(archive, tmpDir, {
@@ -28,16 +28,16 @@ export let downloadAndExtract = async (url, dest) => {
28
28
  }).catch(() => {
29
29
  deleteSync([tmpDir]);
30
30
  });
31
- fs.cpSync(path.join(tmpDir, path.parse(archive).name.replace('.tar', '')), dest, { recursive: true });
31
+ fs.cpSync(path.join(tmpDir, path.parse(archive).name.replace('.tar', '')), destDir, { recursive: true });
32
32
  }
33
33
  else if (archive.endsWith('tar.gz')) {
34
34
  await tar.extract({
35
35
  file: archive,
36
- cwd: dest,
36
+ cwd: destDir,
37
37
  });
38
38
  }
39
39
  else if (archive.endsWith('.gz')) {
40
- let destFile = path.join(dest, path.parse(archive).name);
40
+ let destFile = path.join(destDir, destFileName || path.parse(archive).name);
41
41
  fs.writeFileSync(destFile, unzipSync(buffer));
42
42
  chmodSync(destFile, 0o700);
43
43
  }
@@ -57,8 +57,8 @@ export let getReleases = async (repo) => {
57
57
  let res = await octokit.request(`GET /repos/${repo}/releases`, {
58
58
  per_page: 10,
59
59
  headers: {
60
- 'X-GitHub-Api-Version': '2022-11-28'
61
- }
60
+ 'X-GitHub-Api-Version': '2022-11-28',
61
+ },
62
62
  });
63
63
  if (res.status !== 200) {
64
64
  console.log('Releases fetch error');
@@ -13,7 +13,7 @@ export async function transferOwnership(toPrincipal) {
13
13
  onCancel() {
14
14
  console.log('aborted');
15
15
  process.exit(0);
16
- }
16
+ },
17
17
  };
18
18
  console.log(chalk.red('Warning: ') + 'This action cannot be undone!');
19
19
  let { confirm } = await prompts({
@@ -1,5 +1,6 @@
1
1
  import type { Principal } from '@dfinity/principal';
2
2
  import type { ActorMethod } from '@dfinity/agent';
3
+ import type { IDL } from '@dfinity/candid';
3
4
 
4
5
  export interface BenchResult {
5
6
  'instructions' : bigint,
@@ -24,3 +25,5 @@ export interface anon_class_10_1 {
24
25
  'runCellUpdateAwait' : ActorMethod<[bigint, bigint], BenchResult>,
25
26
  }
26
27
  export interface _SERVICE extends anon_class_10_1 {}
28
+ export declare const idlFactory: IDL.InterfaceFactory;
29
+ export declare const init: ({ IDL }: { IDL: IDL }) => IDL.Type[];