ic-mops 2.0.0 → 2.1.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 (197) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/RELEASE.md +179 -0
  3. package/bundle/cli.tgz +0 -0
  4. package/check-requirements.ts +3 -8
  5. package/cli.ts +79 -11
  6. package/commands/bench/bench-canister.mo +17 -6
  7. package/commands/bench.ts +2 -13
  8. package/commands/build.ts +42 -17
  9. package/commands/check.ts +117 -0
  10. package/commands/format.ts +3 -18
  11. package/commands/lint.ts +92 -0
  12. package/commands/sync.ts +2 -8
  13. package/commands/test/test.ts +7 -19
  14. package/commands/toolchain/index.ts +21 -8
  15. package/commands/toolchain/lintoko.ts +54 -0
  16. package/commands/toolchain/toolchain-utils.ts +2 -0
  17. package/constants.ts +23 -0
  18. package/dist/check-requirements.js +3 -8
  19. package/dist/cli.js +60 -10
  20. package/dist/commands/bench/bench-canister.mo +17 -6
  21. package/dist/commands/bench.js +2 -11
  22. package/dist/commands/build.js +38 -16
  23. package/dist/commands/check.d.ts +6 -0
  24. package/dist/commands/check.js +78 -0
  25. package/dist/commands/format.js +3 -16
  26. package/dist/commands/lint.d.ts +7 -0
  27. package/dist/commands/lint.js +69 -0
  28. package/dist/commands/sync.js +2 -7
  29. package/dist/commands/test/test.js +7 -17
  30. package/dist/commands/toolchain/index.d.ts +2 -2
  31. package/dist/commands/toolchain/index.js +18 -7
  32. package/dist/commands/toolchain/lintoko.d.ts +8 -0
  33. package/dist/commands/toolchain/lintoko.js +36 -0
  34. package/dist/commands/toolchain/toolchain-utils.d.ts +1 -0
  35. package/dist/commands/toolchain/toolchain-utils.js +1 -0
  36. package/dist/constants.d.ts +15 -0
  37. package/dist/constants.js +21 -0
  38. package/dist/environments/nodejs/cli.js +6 -1
  39. package/dist/helpers/autofix-motoko.d.ts +26 -0
  40. package/dist/helpers/autofix-motoko.js +105 -0
  41. package/dist/helpers/get-moc-version.d.ts +2 -0
  42. package/dist/helpers/get-moc-version.js +10 -1
  43. package/dist/mops.js +2 -1
  44. package/dist/package.json +4 -3
  45. package/dist/tests/build-no-dfx.test.d.ts +1 -0
  46. package/dist/tests/build-no-dfx.test.js +9 -0
  47. package/dist/tests/build.test.d.ts +1 -0
  48. package/dist/tests/build.test.js +18 -0
  49. package/dist/tests/check-candid.test.d.ts +1 -0
  50. package/dist/tests/check-candid.test.js +20 -0
  51. package/dist/tests/check-fix.test.d.ts +1 -0
  52. package/dist/tests/check-fix.test.js +73 -0
  53. package/dist/tests/check.test.d.ts +1 -0
  54. package/dist/tests/check.test.js +33 -0
  55. package/dist/tests/cli.test.js +4 -57
  56. package/dist/tests/helpers.d.ts +22 -0
  57. package/dist/tests/helpers.js +43 -0
  58. package/dist/tests/lint.test.d.ts +1 -0
  59. package/dist/tests/lint.test.js +15 -0
  60. package/dist/tests/toolchain.test.d.ts +1 -0
  61. package/dist/tests/toolchain.test.js +11 -0
  62. package/dist/types.d.ts +6 -1
  63. package/dist/wasm/pkg/nodejs/wasm.d.ts +3 -0
  64. package/dist/wasm/pkg/nodejs/wasm.js +323 -17
  65. package/dist/wasm/pkg/nodejs/wasm_bg.wasm +0 -0
  66. package/dist/wasm/pkg/nodejs/wasm_bg.wasm.d.ts +6 -1
  67. package/dist/wasm/pkg/web/wasm.d.ts +10 -1
  68. package/dist/wasm/pkg/web/wasm.js +300 -21
  69. package/dist/wasm/pkg/web/wasm_bg.wasm +0 -0
  70. package/dist/wasm/pkg/web/wasm_bg.wasm.d.ts +6 -1
  71. package/dist/wasm.d.ts +6 -1
  72. package/environments/nodejs/cli.ts +7 -1
  73. package/helpers/autofix-motoko.ts +170 -0
  74. package/helpers/get-moc-version.ts +12 -1
  75. package/mops.ts +2 -1
  76. package/package.json +4 -3
  77. package/tests/__snapshots__/build-no-dfx.test.ts.snap +11 -0
  78. package/tests/__snapshots__/build.test.ts.snap +77 -0
  79. package/tests/__snapshots__/check-candid.test.ts.snap +73 -0
  80. package/tests/__snapshots__/check-fix.test.ts.snap +242 -0
  81. package/tests/__snapshots__/check.test.ts.snap +72 -0
  82. package/tests/__snapshots__/lint.test.ts.snap +78 -0
  83. package/tests/build/error/src/Bar.mo +2 -2
  84. package/tests/build/no-dfx/mops.toml +5 -0
  85. package/tests/build/no-dfx/src/Main.mo +5 -0
  86. package/tests/build/success/candid/bar.did +1 -0
  87. package/tests/build/success/mops.toml +8 -3
  88. package/tests/build-no-dfx.test.ts +10 -0
  89. package/tests/build.test.ts +24 -0
  90. package/tests/check/error/Error.mo +7 -0
  91. package/tests/check/error/mops.toml +2 -0
  92. package/tests/check/fix/M0223.mo +11 -0
  93. package/tests/check/fix/M0236.mo +11 -0
  94. package/tests/check/fix/M0237.mo +11 -0
  95. package/tests/check/fix/Ok.mo +7 -0
  96. package/tests/check/fix/edit-suggestions.mo +143 -0
  97. package/tests/check/fix/mops.toml +5 -0
  98. package/tests/check/fix/transitive-lib.mo +9 -0
  99. package/tests/check/fix/transitive-main.mo +9 -0
  100. package/tests/check/success/Ok.mo +5 -0
  101. package/tests/check/success/Warning.mo +5 -0
  102. package/tests/check/success/mops.toml +2 -0
  103. package/tests/check-candid.test.ts +22 -0
  104. package/tests/check-fix.test.ts +111 -0
  105. package/tests/check.test.ts +46 -0
  106. package/tests/cli.test.ts +4 -74
  107. package/tests/helpers.ts +58 -0
  108. package/tests/lint/lints/no-bool-switch.toml +9 -0
  109. package/tests/lint/mops.toml +4 -0
  110. package/tests/lint/src/NoBoolSwitch.mo +8 -0
  111. package/tests/lint/src/Ok.mo +5 -0
  112. package/tests/lint.test.ts +17 -0
  113. package/tests/toolchain/mock +2 -0
  114. package/tests/toolchain/mops.toml +2 -0
  115. package/tests/toolchain.test.ts +12 -0
  116. package/types.ts +6 -1
  117. package/wasm/Cargo.lock +101 -54
  118. package/wasm/Cargo.toml +2 -5
  119. package/wasm/pkg/nodejs/wasm.d.ts +3 -0
  120. package/wasm/pkg/nodejs/wasm.js +323 -17
  121. package/wasm/pkg/nodejs/wasm_bg.wasm +0 -0
  122. package/wasm/pkg/nodejs/wasm_bg.wasm.d.ts +6 -1
  123. package/wasm/pkg/web/wasm.d.ts +10 -1
  124. package/wasm/pkg/web/wasm.js +300 -21
  125. package/wasm/pkg/web/wasm_bg.wasm +0 -0
  126. package/wasm/pkg/web/wasm_bg.wasm.d.ts +6 -1
  127. package/wasm/src/lib.rs +10 -5
  128. package/wasm/src/utils.rs +15 -0
  129. package/wasm/src/wasm_utils.rs +79 -0
  130. package/wasm.ts +10 -1
  131. package/.DS_Store +0 -0
  132. package/bundle/bench/bench-canister.mo +0 -121
  133. package/bundle/bench/user-bench.mo +0 -10
  134. package/bundle/bin/moc-wrapper.sh +0 -40
  135. package/bundle/bin/mops.js +0 -3
  136. package/bundle/cli.js +0 -2144
  137. package/bundle/declarations/bench/bench.did +0 -30
  138. package/bundle/declarations/bench/bench.did.d.ts +0 -33
  139. package/bundle/declarations/bench/bench.did.js +0 -30
  140. package/bundle/declarations/bench/index.d.ts +0 -50
  141. package/bundle/declarations/bench/index.js +0 -40
  142. package/bundle/declarations/main/index.d.ts +0 -50
  143. package/bundle/declarations/main/index.js +0 -40
  144. package/bundle/declarations/main/main.did +0 -428
  145. package/bundle/declarations/main/main.did.d.ts +0 -348
  146. package/bundle/declarations/main/main.did.js +0 -406
  147. package/bundle/declarations/storage/index.d.ts +0 -50
  148. package/bundle/declarations/storage/index.js +0 -30
  149. package/bundle/declarations/storage/storage.did +0 -46
  150. package/bundle/declarations/storage/storage.did.d.ts +0 -40
  151. package/bundle/declarations/storage/storage.did.js +0 -38
  152. package/bundle/package.json +0 -36
  153. package/bundle/templates/README.md +0 -13
  154. package/bundle/templates/licenses/Apache-2.0 +0 -202
  155. package/bundle/templates/licenses/Apache-2.0-NOTICE +0 -13
  156. package/bundle/templates/licenses/MIT +0 -21
  157. package/bundle/templates/mops-publish.yml +0 -17
  158. package/bundle/templates/mops-test.yml +0 -24
  159. package/bundle/templates/src/lib.mo +0 -15
  160. package/bundle/templates/test/lib.test.mo +0 -4
  161. package/bundle/wasm_bg.wasm +0 -0
  162. package/bundle/xhr-sync-worker.js +0 -59
  163. package/dist/wasm/pkg/bundler/package.json +0 -20
  164. package/dist/wasm/pkg/bundler/wasm.d.ts +0 -3
  165. package/dist/wasm/pkg/bundler/wasm.js +0 -5
  166. package/dist/wasm/pkg/bundler/wasm_bg.js +0 -93
  167. package/dist/wasm/pkg/bundler/wasm_bg.wasm +0 -0
  168. package/dist/wasm/pkg/bundler/wasm_bg.wasm.d.ts +0 -8
  169. package/tests/__snapshots__/cli.test.ts.snap +0 -202
  170. package/tests/build/success/.dfx/local/canister_ids.json +0 -17
  171. package/tests/build/success/.dfx/local/canisters/bar/bar.did +0 -3
  172. package/tests/build/success/.dfx/local/canisters/bar/bar.most +0 -4
  173. package/tests/build/success/.dfx/local/canisters/bar/bar.wasm +0 -0
  174. package/tests/build/success/.dfx/local/canisters/bar/constructor.did +0 -3
  175. package/tests/build/success/.dfx/local/canisters/bar/index.js +0 -42
  176. package/tests/build/success/.dfx/local/canisters/bar/init_args.txt +0 -1
  177. package/tests/build/success/.dfx/local/canisters/bar/service.did +0 -3
  178. package/tests/build/success/.dfx/local/canisters/bar/service.did.d.ts +0 -7
  179. package/tests/build/success/.dfx/local/canisters/bar/service.did.js +0 -4
  180. package/tests/build/success/.dfx/local/canisters/foo/constructor.did +0 -3
  181. package/tests/build/success/.dfx/local/canisters/foo/foo.did +0 -3
  182. package/tests/build/success/.dfx/local/canisters/foo/foo.most +0 -4
  183. package/tests/build/success/.dfx/local/canisters/foo/foo.wasm +0 -0
  184. package/tests/build/success/.dfx/local/canisters/foo/index.js +0 -42
  185. package/tests/build/success/.dfx/local/canisters/foo/init_args.txt +0 -1
  186. package/tests/build/success/.dfx/local/canisters/foo/service.did +0 -3
  187. package/tests/build/success/.dfx/local/canisters/foo/service.did.d.ts +0 -7
  188. package/tests/build/success/.dfx/local/canisters/foo/service.did.js +0 -4
  189. package/tests/build/success/.dfx/local/lsp/ucwa4-rx777-77774-qaada-cai.did +0 -3
  190. package/tests/build/success/.dfx/local/lsp/ulvla-h7777-77774-qaacq-cai.did +0 -3
  191. package/tests/build/success/.dfx/local/network-id +0 -4
  192. package/wasm/pkg/bundler/package.json +0 -20
  193. package/wasm/pkg/bundler/wasm.d.ts +0 -3
  194. package/wasm/pkg/bundler/wasm.js +0 -5
  195. package/wasm/pkg/bundler/wasm_bg.js +0 -93
  196. package/wasm/pkg/bundler/wasm_bg.wasm +0 -0
  197. package/wasm/pkg/bundler/wasm_bg.wasm.d.ts +0 -8
@@ -1,9 +1,95 @@
1
1
  let wasm;
2
2
 
3
- let WASM_VECTOR_LEN = 0;
3
+ function addToExternrefTable0(obj) {
4
+ const idx = wasm.__externref_table_alloc();
5
+ wasm.__wbindgen_externrefs.set(idx, obj);
6
+ return idx;
7
+ }
4
8
 
5
- let cachedUint8ArrayMemory0 = null;
9
+ function debugString(val) {
10
+ // primitive types
11
+ const type = typeof val;
12
+ if (type == 'number' || type == 'boolean' || val == null) {
13
+ return `${val}`;
14
+ }
15
+ if (type == 'string') {
16
+ return `"${val}"`;
17
+ }
18
+ if (type == 'symbol') {
19
+ const description = val.description;
20
+ if (description == null) {
21
+ return 'Symbol';
22
+ } else {
23
+ return `Symbol(${description})`;
24
+ }
25
+ }
26
+ if (type == 'function') {
27
+ const name = val.name;
28
+ if (typeof name == 'string' && name.length > 0) {
29
+ return `Function(${name})`;
30
+ } else {
31
+ return 'Function';
32
+ }
33
+ }
34
+ // objects
35
+ if (Array.isArray(val)) {
36
+ const length = val.length;
37
+ let debug = '[';
38
+ if (length > 0) {
39
+ debug += debugString(val[0]);
40
+ }
41
+ for(let i = 1; i < length; i++) {
42
+ debug += ', ' + debugString(val[i]);
43
+ }
44
+ debug += ']';
45
+ return debug;
46
+ }
47
+ // Test for built-in
48
+ const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
49
+ let className;
50
+ if (builtInMatches && builtInMatches.length > 1) {
51
+ className = builtInMatches[1];
52
+ } else {
53
+ // Failed to match the standard '[object ClassName]'
54
+ return toString.call(val);
55
+ }
56
+ if (className == 'Object') {
57
+ // we're a user defined class or Object
58
+ // JSON.stringify avoids problems with cycles, and is generally much
59
+ // easier than looping through ownProperties of `val`.
60
+ try {
61
+ return 'Object(' + JSON.stringify(val) + ')';
62
+ } catch (_) {
63
+ return 'Object';
64
+ }
65
+ }
66
+ // errors
67
+ if (val instanceof Error) {
68
+ return `${val.name}: ${val.message}\n${val.stack}`;
69
+ }
70
+ // TODO we could test for more things here, like `Set`s and `Map`s.
71
+ return className;
72
+ }
73
+
74
+ function getArrayU8FromWasm0(ptr, len) {
75
+ ptr = ptr >>> 0;
76
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
77
+ }
78
+
79
+ let cachedDataViewMemory0 = null;
80
+ function getDataViewMemory0() {
81
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
82
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
83
+ }
84
+ return cachedDataViewMemory0;
85
+ }
86
+
87
+ function getStringFromWasm0(ptr, len) {
88
+ ptr = ptr >>> 0;
89
+ return decodeText(ptr, len);
90
+ }
6
91
 
92
+ let cachedUint8ArrayMemory0 = null;
7
93
  function getUint8ArrayMemory0() {
8
94
  if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
9
95
  cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
@@ -11,21 +97,27 @@ function getUint8ArrayMemory0() {
11
97
  return cachedUint8ArrayMemory0;
12
98
  }
13
99
 
14
- const cachedTextEncoder = new TextEncoder();
15
-
16
- if (!('encodeInto' in cachedTextEncoder)) {
17
- cachedTextEncoder.encodeInto = function (arg, view) {
18
- const buf = cachedTextEncoder.encode(arg);
19
- view.set(buf);
20
- return {
21
- read: arg.length,
22
- written: buf.length
23
- };
100
+ function handleError(f, args) {
101
+ try {
102
+ return f.apply(this, args);
103
+ } catch (e) {
104
+ const idx = addToExternrefTable0(e);
105
+ wasm.__wbindgen_exn_store(idx);
24
106
  }
25
107
  }
26
108
 
27
- function passStringToWasm0(arg, malloc, realloc) {
109
+ function isLikeNone(x) {
110
+ return x === undefined || x === null;
111
+ }
28
112
 
113
+ function passArray8ToWasm0(arg, malloc) {
114
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
115
+ getUint8ArrayMemory0().set(arg, ptr / 1);
116
+ WASM_VECTOR_LEN = arg.length;
117
+ return ptr;
118
+ }
119
+
120
+ function passStringToWasm0(arg, malloc, realloc) {
29
121
  if (realloc === undefined) {
30
122
  const buf = cachedTextEncoder.encode(arg);
31
123
  const ptr = malloc(buf.length, 1) >>> 0;
@@ -46,7 +138,6 @@ function passStringToWasm0(arg, malloc, realloc) {
46
138
  if (code > 0x7F) break;
47
139
  mem[ptr + offset] = code;
48
140
  }
49
-
50
141
  if (offset !== len) {
51
142
  if (offset !== 0) {
52
143
  arg = arg.slice(offset);
@@ -62,6 +153,59 @@ function passStringToWasm0(arg, malloc, realloc) {
62
153
  WASM_VECTOR_LEN = offset;
63
154
  return ptr;
64
155
  }
156
+
157
+ function takeFromExternrefTable0(idx) {
158
+ const value = wasm.__wbindgen_externrefs.get(idx);
159
+ wasm.__externref_table_dealloc(idx);
160
+ return value;
161
+ }
162
+
163
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
164
+ cachedTextDecoder.decode();
165
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
166
+ let numBytesDecoded = 0;
167
+ function decodeText(ptr, len) {
168
+ numBytesDecoded += len;
169
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
170
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
171
+ cachedTextDecoder.decode();
172
+ numBytesDecoded = len;
173
+ }
174
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
175
+ }
176
+
177
+ const cachedTextEncoder = new TextEncoder();
178
+
179
+ if (!('encodeInto' in cachedTextEncoder)) {
180
+ cachedTextEncoder.encodeInto = function (arg, view) {
181
+ const buf = cachedTextEncoder.encode(arg);
182
+ view.set(buf);
183
+ return {
184
+ read: arg.length,
185
+ written: buf.length
186
+ };
187
+ }
188
+ }
189
+
190
+ let WASM_VECTOR_LEN = 0;
191
+
192
+ /**
193
+ * @param {Uint8Array} bytes
194
+ * @param {any} custom_sections
195
+ * @returns {Uint8Array}
196
+ */
197
+ export function add_custom_sections(bytes, custom_sections) {
198
+ const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
199
+ const len0 = WASM_VECTOR_LEN;
200
+ const ret = wasm.add_custom_sections(ptr0, len0, custom_sections);
201
+ if (ret[3]) {
202
+ throw takeFromExternrefTable0(ret[2]);
203
+ }
204
+ var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
205
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
206
+ return v2;
207
+ }
208
+
65
209
  /**
66
210
  * @param {string} new_interface
67
211
  * @param {string} original_interface
@@ -83,7 +227,6 @@ async function __wbg_load(module, imports) {
83
227
  if (typeof WebAssembly.instantiateStreaming === 'function') {
84
228
  try {
85
229
  return await WebAssembly.instantiateStreaming(module, imports);
86
-
87
230
  } catch (e) {
88
231
  const validResponse = module.ok && EXPECTED_RESPONSE_TYPES.has(module.type);
89
232
 
@@ -98,13 +241,11 @@ async function __wbg_load(module, imports) {
98
241
 
99
242
  const bytes = await module.arrayBuffer();
100
243
  return await WebAssembly.instantiate(bytes, imports);
101
-
102
244
  } else {
103
245
  const instance = await WebAssembly.instantiate(module, imports);
104
246
 
105
247
  if (instance instanceof WebAssembly.Instance) {
106
248
  return { instance, module };
107
-
108
249
  } else {
109
250
  return instance;
110
251
  }
@@ -114,6 +255,147 @@ async function __wbg_load(module, imports) {
114
255
  function __wbg_get_imports() {
115
256
  const imports = {};
116
257
  imports.wbg = {};
258
+ imports.wbg.__wbg_Error_52673b7de5a0ca89 = function(arg0, arg1) {
259
+ const ret = Error(getStringFromWasm0(arg0, arg1));
260
+ return ret;
261
+ };
262
+ imports.wbg.__wbg_String_8f0eb39a4a4c2f66 = function(arg0, arg1) {
263
+ const ret = String(arg1);
264
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
265
+ const len1 = WASM_VECTOR_LEN;
266
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
267
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
268
+ };
269
+ imports.wbg.__wbg___wbindgen_boolean_get_dea25b33882b895b = function(arg0) {
270
+ const v = arg0;
271
+ const ret = typeof(v) === 'boolean' ? v : undefined;
272
+ return isLikeNone(ret) ? 0xFFFFFF : ret ? 1 : 0;
273
+ };
274
+ imports.wbg.__wbg___wbindgen_debug_string_adfb662ae34724b6 = function(arg0, arg1) {
275
+ const ret = debugString(arg1);
276
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
277
+ const len1 = WASM_VECTOR_LEN;
278
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
279
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
280
+ };
281
+ imports.wbg.__wbg___wbindgen_in_0d3e1e8f0c669317 = function(arg0, arg1) {
282
+ const ret = arg0 in arg1;
283
+ return ret;
284
+ };
285
+ imports.wbg.__wbg___wbindgen_is_function_8d400b8b1af978cd = function(arg0) {
286
+ const ret = typeof(arg0) === 'function';
287
+ return ret;
288
+ };
289
+ imports.wbg.__wbg___wbindgen_is_object_ce774f3490692386 = function(arg0) {
290
+ const val = arg0;
291
+ const ret = typeof(val) === 'object' && val !== null;
292
+ return ret;
293
+ };
294
+ imports.wbg.__wbg___wbindgen_is_undefined_f6b95eab589e0269 = function(arg0) {
295
+ const ret = arg0 === undefined;
296
+ return ret;
297
+ };
298
+ imports.wbg.__wbg___wbindgen_jsval_loose_eq_766057600fdd1b0d = function(arg0, arg1) {
299
+ const ret = arg0 == arg1;
300
+ return ret;
301
+ };
302
+ imports.wbg.__wbg___wbindgen_number_get_9619185a74197f95 = function(arg0, arg1) {
303
+ const obj = arg1;
304
+ const ret = typeof(obj) === 'number' ? obj : undefined;
305
+ getDataViewMemory0().setFloat64(arg0 + 8 * 1, isLikeNone(ret) ? 0 : ret, true);
306
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
307
+ };
308
+ imports.wbg.__wbg___wbindgen_string_get_a2a31e16edf96e42 = function(arg0, arg1) {
309
+ const obj = arg1;
310
+ const ret = typeof(obj) === 'string' ? obj : undefined;
311
+ var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
312
+ var len1 = WASM_VECTOR_LEN;
313
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
314
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
315
+ };
316
+ imports.wbg.__wbg___wbindgen_throw_dd24417ed36fc46e = function(arg0, arg1) {
317
+ throw new Error(getStringFromWasm0(arg0, arg1));
318
+ };
319
+ imports.wbg.__wbg_call_abb4ff46ce38be40 = function() { return handleError(function (arg0, arg1) {
320
+ const ret = arg0.call(arg1);
321
+ return ret;
322
+ }, arguments) };
323
+ imports.wbg.__wbg_done_62ea16af4ce34b24 = function(arg0) {
324
+ const ret = arg0.done;
325
+ return ret;
326
+ };
327
+ imports.wbg.__wbg_get_6b7bd52aca3f9671 = function(arg0, arg1) {
328
+ const ret = arg0[arg1 >>> 0];
329
+ return ret;
330
+ };
331
+ imports.wbg.__wbg_get_af9dab7e9603ea93 = function() { return handleError(function (arg0, arg1) {
332
+ const ret = Reflect.get(arg0, arg1);
333
+ return ret;
334
+ }, arguments) };
335
+ imports.wbg.__wbg_get_with_ref_key_1dc361bd10053bfe = function(arg0, arg1) {
336
+ const ret = arg0[arg1];
337
+ return ret;
338
+ };
339
+ imports.wbg.__wbg_instanceof_ArrayBuffer_f3320d2419cd0355 = function(arg0) {
340
+ let result;
341
+ try {
342
+ result = arg0 instanceof ArrayBuffer;
343
+ } catch (_) {
344
+ result = false;
345
+ }
346
+ const ret = result;
347
+ return ret;
348
+ };
349
+ imports.wbg.__wbg_instanceof_Uint8Array_da54ccc9d3e09434 = function(arg0) {
350
+ let result;
351
+ try {
352
+ result = arg0 instanceof Uint8Array;
353
+ } catch (_) {
354
+ result = false;
355
+ }
356
+ const ret = result;
357
+ return ret;
358
+ };
359
+ imports.wbg.__wbg_isArray_51fd9e6422c0a395 = function(arg0) {
360
+ const ret = Array.isArray(arg0);
361
+ return ret;
362
+ };
363
+ imports.wbg.__wbg_iterator_27b7c8b35ab3e86b = function() {
364
+ const ret = Symbol.iterator;
365
+ return ret;
366
+ };
367
+ imports.wbg.__wbg_length_22ac23eaec9d8053 = function(arg0) {
368
+ const ret = arg0.length;
369
+ return ret;
370
+ };
371
+ imports.wbg.__wbg_length_d45040a40c570362 = function(arg0) {
372
+ const ret = arg0.length;
373
+ return ret;
374
+ };
375
+ imports.wbg.__wbg_new_6421f6084cc5bc5a = function(arg0) {
376
+ const ret = new Uint8Array(arg0);
377
+ return ret;
378
+ };
379
+ imports.wbg.__wbg_next_138a17bbf04e926c = function(arg0) {
380
+ const ret = arg0.next;
381
+ return ret;
382
+ };
383
+ imports.wbg.__wbg_next_3cfe5c0fe2a4cc53 = function() { return handleError(function (arg0) {
384
+ const ret = arg0.next();
385
+ return ret;
386
+ }, arguments) };
387
+ imports.wbg.__wbg_prototypesetcall_dfe9b766cdc1f1fd = function(arg0, arg1, arg2) {
388
+ Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), arg2);
389
+ };
390
+ imports.wbg.__wbg_value_57b7b035e117f7ee = function(arg0) {
391
+ const ret = arg0.value;
392
+ return ret;
393
+ };
394
+ imports.wbg.__wbindgen_cast_2241b6af4c4b2941 = function(arg0, arg1) {
395
+ // Cast intrinsic for `Ref(String) -> Externref`.
396
+ const ret = getStringFromWasm0(arg0, arg1);
397
+ return ret;
398
+ };
117
399
  imports.wbg.__wbindgen_init_externref_table = function() {
118
400
  const table = wasm.__wbindgen_externrefs;
119
401
  const offset = table.grow(4);
@@ -122,7 +404,6 @@ function __wbg_get_imports() {
122
404
  table.set(offset + 1, null);
123
405
  table.set(offset + 2, true);
124
406
  table.set(offset + 3, false);
125
- ;
126
407
  };
127
408
 
128
409
  return imports;
@@ -131,6 +412,7 @@ function __wbg_get_imports() {
131
412
  function __wbg_finalize_init(instance, module) {
132
413
  wasm = instance.exports;
133
414
  __wbg_init.__wbindgen_wasm_module = module;
415
+ cachedDataViewMemory0 = null;
134
416
  cachedUint8ArrayMemory0 = null;
135
417
 
136
418
 
@@ -151,13 +433,10 @@ function initSync(module) {
151
433
  }
152
434
 
153
435
  const imports = __wbg_get_imports();
154
-
155
436
  if (!(module instanceof WebAssembly.Module)) {
156
437
  module = new WebAssembly.Module(module);
157
438
  }
158
-
159
439
  const instance = new WebAssembly.Instance(module, imports);
160
-
161
440
  return __wbg_finalize_init(instance, module);
162
441
  }
163
442
 
Binary file
@@ -2,7 +2,12 @@
2
2
  /* eslint-disable */
3
3
  export const memory: WebAssembly.Memory;
4
4
  export const is_candid_compatible: (a: number, b: number, c: number, d: number) => number;
5
- export const __wbindgen_externrefs: WebAssembly.Table;
5
+ export const add_custom_sections: (a: number, b: number, c: any) => [number, number, number, number];
6
6
  export const __wbindgen_malloc: (a: number, b: number) => number;
7
7
  export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
8
+ export const __wbindgen_exn_store: (a: number) => void;
9
+ export const __externref_table_alloc: () => number;
10
+ export const __wbindgen_externrefs: WebAssembly.Table;
11
+ export const __externref_table_dealloc: (a: number) => void;
12
+ export const __wbindgen_free: (a: number, b: number, c: number) => void;
8
13
  export const __wbindgen_start: () => void;
package/dist/wasm.d.ts CHANGED
@@ -1,5 +1,10 @@
1
+ export interface CustomSection {
2
+ name: string;
3
+ data: string;
4
+ }
1
5
  export interface WasmBindings {
2
- is_candid_compatible: (newText: string, originalText: string) => boolean;
6
+ is_candid_compatible: (newCandid: string, originalCandid: string) => boolean;
7
+ add_custom_sections: (bytes: Uint8Array, customSections: CustomSection[]) => Uint8Array;
3
8
  }
4
9
  export declare function setWasmBindings(newBindings: WasmBindings): void;
5
10
  export declare function getWasmBindings(): WasmBindings;
@@ -1,6 +1,12 @@
1
- import * as wasm from "../../wasm/pkg/nodejs/wasm.js";
1
+ import { createRequire } from "node:module";
2
+ import path from "node:path";
3
+ import { fileURLToPath } from "node:url";
2
4
  import { setWasmBindings } from "../../wasm.js";
3
5
 
6
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
7
+ const require = createRequire(import.meta.url);
8
+ const wasm = require(path.join(__dirname, "../../wasm/pkg/nodejs/wasm.js"));
9
+
4
10
  setWasmBindings(wasm);
5
11
 
6
12
  export * from "../../cli.js";
@@ -0,0 +1,170 @@
1
+ import { readFile, writeFile } from "node:fs/promises";
2
+ import { resolve } from "node:path";
3
+ import { execa } from "execa";
4
+ import {
5
+ TextDocument,
6
+ type TextEdit,
7
+ } from "vscode-languageserver-textdocument";
8
+
9
+ interface Fix {
10
+ file: string;
11
+ code: string;
12
+ edit: TextEdit;
13
+ }
14
+
15
+ interface MocSpan {
16
+ file: string;
17
+ line_start: number;
18
+ column_start: number;
19
+ line_end: number;
20
+ column_end: number;
21
+ is_primary: boolean;
22
+ label: string | null;
23
+ suggested_replacement: string | null;
24
+ suggestion_applicability: string | null;
25
+ }
26
+
27
+ export interface MocDiagnostic {
28
+ message: string;
29
+ code: string;
30
+ level: string;
31
+ spans: MocSpan[];
32
+ notes: string[];
33
+ }
34
+
35
+ export function parseDiagnostics(stdout: string): MocDiagnostic[] {
36
+ return stdout
37
+ .split("\n")
38
+ .filter((l) => l.trim())
39
+ .map((l) => {
40
+ try {
41
+ return JSON.parse(l) as MocDiagnostic;
42
+ } catch {
43
+ return null;
44
+ }
45
+ })
46
+ .filter((d) => d !== null);
47
+ }
48
+
49
+ function extractFixes(diagnostics: MocDiagnostic[]): Fix[] {
50
+ const fixes: Fix[] = [];
51
+ for (const diag of diagnostics) {
52
+ for (const span of diag.spans) {
53
+ if (
54
+ span.suggestion_applicability === "MachineApplicable" &&
55
+ span.suggested_replacement !== null
56
+ ) {
57
+ fixes.push({
58
+ file: span.file,
59
+ code: diag.code,
60
+ edit: {
61
+ range: {
62
+ start: {
63
+ line: span.line_start - 1,
64
+ character: span.column_start - 1,
65
+ },
66
+ end: {
67
+ line: span.line_end - 1,
68
+ character: span.column_end - 1,
69
+ },
70
+ },
71
+ newText: span.suggested_replacement,
72
+ },
73
+ });
74
+ }
75
+ }
76
+ }
77
+ return fixes;
78
+ }
79
+
80
+ const MAX_FIX_ITERATIONS = 10;
81
+
82
+ export interface AutofixResult {
83
+ /** Map of file path → diagnostic codes fixed in that file */
84
+ fixedFiles: Map<string, string[]>;
85
+ totalFixCount: number;
86
+ }
87
+
88
+ export async function autofixMotoko(
89
+ mocPath: string,
90
+ files: string[],
91
+ mocArgs: string[],
92
+ ): Promise<AutofixResult | null> {
93
+ const fixedFilesCodes = new Map<string, string[]>();
94
+
95
+ for (let iteration = 0; iteration < MAX_FIX_ITERATIONS; iteration++) {
96
+ const allFixes: Fix[] = [];
97
+
98
+ for (const file of files) {
99
+ const result = await execa(
100
+ mocPath,
101
+ [file, "--error-format=json", ...mocArgs],
102
+ { stdio: "pipe", reject: false },
103
+ );
104
+
105
+ const diagnostics = parseDiagnostics(result.stdout);
106
+ allFixes.push(...extractFixes(diagnostics));
107
+ }
108
+
109
+ if (allFixes.length === 0) {
110
+ break;
111
+ }
112
+
113
+ const fixesByFile = new Map<string, Fix[]>();
114
+ for (const fix of allFixes) {
115
+ const normalizedPath = resolve(fix.file);
116
+ const existing = fixesByFile.get(normalizedPath) ?? [];
117
+ existing.push(fix);
118
+ fixesByFile.set(normalizedPath, existing);
119
+ }
120
+
121
+ let progress = false;
122
+
123
+ for (const [file, fixes] of fixesByFile) {
124
+ const original = await readFile(file, "utf-8");
125
+ const doc = TextDocument.create(`file://${file}`, "motoko", 0, original);
126
+
127
+ let result: string;
128
+ try {
129
+ result = TextDocument.applyEdits(
130
+ doc,
131
+ fixes.map((f) => f.edit),
132
+ );
133
+ } catch (err) {
134
+ console.warn(`Warning: could not apply fixes to ${file}: ${err}`);
135
+ continue;
136
+ }
137
+
138
+ if (result === original) {
139
+ continue;
140
+ }
141
+
142
+ await writeFile(file, result, "utf-8");
143
+ progress = true;
144
+
145
+ const existing = fixedFilesCodes.get(file) ?? [];
146
+ for (const fix of fixes) {
147
+ existing.push(fix.code);
148
+ }
149
+ fixedFilesCodes.set(file, existing);
150
+ }
151
+
152
+ if (!progress) {
153
+ break;
154
+ }
155
+ }
156
+
157
+ if (fixedFilesCodes.size === 0) {
158
+ return null;
159
+ }
160
+
161
+ let totalFixCount = 0;
162
+ for (const codes of fixedFilesCodes.values()) {
163
+ totalFixCount += codes.length;
164
+ }
165
+
166
+ return {
167
+ fixedFiles: fixedFilesCodes,
168
+ totalFixCount,
169
+ };
170
+ }
@@ -1,8 +1,19 @@
1
1
  import { execFileSync } from "node:child_process";
2
+ import { type SemVer, parse } from "semver";
3
+ import { readConfig } from "../mops.js";
2
4
  import { getMocPath } from "./get-moc-path.js";
3
5
 
6
+ export function getMocSemVer(): SemVer | null {
7
+ return parse(getMocVersion(false));
8
+ }
9
+
4
10
  export function getMocVersion(throwOnError = false): string {
5
- let mocPath = getMocPath(false);
11
+ let configVersion = readConfig().toolchain?.moc;
12
+ if (configVersion) {
13
+ return configVersion;
14
+ }
15
+
16
+ const mocPath = getMocPath(false);
6
17
  if (!mocPath) {
7
18
  return "";
8
19
  }
package/mops.ts CHANGED
@@ -13,6 +13,7 @@ import { mainActor, storageActor } from "./api/actors.js";
13
13
  import { getNetwork } from "./api/network.js";
14
14
  import { getHighestVersion } from "./api/getHighestVersion.js";
15
15
  import { getPackageId } from "./helpers/get-package-id.js";
16
+ import { FILE_PATH_REGEX } from "./constants.js";
16
17
 
17
18
  if (!globalThis.fetch) {
18
19
  globalThis.fetch = fetch as any;
@@ -157,7 +158,7 @@ export function getDependencyType(version: string) {
157
158
  }
158
159
  if (version.startsWith("https://github.com/")) {
159
160
  return "github";
160
- } else if (version.match(/^(\.?\.)?\//)) {
161
+ } else if (version.match(FILE_PATH_REGEX)) {
161
162
  return "local";
162
163
  } else {
163
164
  return "mops";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ic-mops",
3
- "version": "2.0.0",
3
+ "version": "2.1.0",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "mops": "dist/bin/mops.js",
@@ -91,8 +91,9 @@
91
91
  "semver": "7.7.1",
92
92
  "stream-to-promise": "3.0.0",
93
93
  "string-width": "7.2.0",
94
- "tar": "7.4.3",
95
- "terminal-size": "4.0.0"
94
+ "tar": "7.5.6",
95
+ "terminal-size": "4.0.0",
96
+ "vscode-languageserver-textdocument": "1.0.12"
96
97
  },
97
98
  "devDependencies": {
98
99
  "@tsconfig/strictest": "2.0.5",
@@ -0,0 +1,11 @@
1
+ // Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
2
+
3
+ exports[`build without dfx builds using mops toolchain moc 1`] = `
4
+ {
5
+ "exitCode": 0,
6
+ "stderr": "",
7
+ "stdout": "build canister main
8
+
9
+ ✓ Built 1 canister successfully",
10
+ }
11
+ `;