ic-mops 2.13.2 → 2.14.1

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 (70) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/bun.lock +24 -12
  3. package/bundle/cli.tgz +0 -0
  4. package/cache.ts +101 -20
  5. package/cli.ts +40 -14
  6. package/commands/available-updates.ts +4 -2
  7. package/commands/bench.ts +3 -0
  8. package/commands/check.ts +33 -22
  9. package/commands/init.ts +15 -2
  10. package/commands/install/install-mops-dep.ts +14 -9
  11. package/commands/install/sync-local-cache.ts +7 -1
  12. package/commands/lint.ts +11 -0
  13. package/commands/outdated.ts +5 -2
  14. package/commands/publish.ts +0 -1
  15. package/commands/test/test.ts +14 -0
  16. package/commands/update.ts +3 -2
  17. package/commands/watch/tester.ts +5 -1
  18. package/dist/cache.d.ts +3 -0
  19. package/dist/cache.js +98 -18
  20. package/dist/cli.js +16 -12
  21. package/dist/commands/available-updates.d.ts +1 -1
  22. package/dist/commands/available-updates.js +4 -1
  23. package/dist/commands/bench.js +2 -0
  24. package/dist/commands/check.js +27 -18
  25. package/dist/commands/init.js +9 -2
  26. package/dist/commands/install/install-mops-dep.js +12 -9
  27. package/dist/commands/install/sync-local-cache.js +2 -1
  28. package/dist/commands/lint.js +7 -0
  29. package/dist/commands/outdated.d.ts +2 -1
  30. package/dist/commands/outdated.js +2 -2
  31. package/dist/commands/publish.js +0 -1
  32. package/dist/commands/test/test.d.ts +1 -1
  33. package/dist/commands/test/test.js +10 -5
  34. package/dist/commands/update.d.ts +2 -1
  35. package/dist/commands/update.js +2 -2
  36. package/dist/commands/watch/tester.js +4 -1
  37. package/dist/helpers/autofix-motoko.d.ts +1 -1
  38. package/dist/helpers/autofix-motoko.js +10 -8
  39. package/dist/helpers/deprecate-dfx-replica.d.ts +2 -0
  40. package/dist/helpers/deprecate-dfx-replica.js +20 -0
  41. package/dist/helpers/fix-lock.d.ts +1 -0
  42. package/dist/helpers/fix-lock.js +93 -0
  43. package/dist/integrity.d.ts +2 -2
  44. package/dist/integrity.js +22 -6
  45. package/dist/mops.js +1 -1
  46. package/dist/package.json +3 -3
  47. package/dist/tests/check-fix.test.js +40 -0
  48. package/dist/tests/check.test.js +6 -0
  49. package/dist/tests/cli.test.js +136 -1
  50. package/dist/vessel.js +21 -13
  51. package/dist/wasm/pkg/nodejs/package.json +1 -1
  52. package/dist/wasm/pkg/nodejs/wasm_bg.wasm +0 -0
  53. package/dist/wasm/pkg/web/package.json +1 -1
  54. package/dist/wasm/pkg/web/wasm_bg.wasm +0 -0
  55. package/helpers/autofix-motoko.ts +16 -14
  56. package/helpers/deprecate-dfx-replica.ts +32 -0
  57. package/helpers/fix-lock.ts +101 -0
  58. package/integrity.ts +30 -9
  59. package/mops.ts +1 -1
  60. package/package.json +3 -3
  61. package/tests/__snapshots__/check.test.ts.snap +17 -4
  62. package/tests/check-fix.test.ts +46 -0
  63. package/tests/check.test.ts +11 -0
  64. package/tests/cli.test.ts +180 -1
  65. package/tests/install/update-bound-patch/mops.toml +2 -0
  66. package/vessel.ts +31 -14
  67. package/wasm/pkg/nodejs/package.json +1 -1
  68. package/wasm/pkg/nodejs/wasm_bg.wasm +0 -0
  69. package/wasm/pkg/web/package.json +1 -1
  70. package/wasm/pkg/web/wasm_bg.wasm +0 -0
@@ -15,6 +15,17 @@ describe("check", () => {
15
15
  await cliSnapshot(["check", "Ok.mo", "Error.mo"], { cwd }, 1);
16
16
  });
17
17
 
18
+ // The verbose snapshot shows a single "moc ... [both files]" line, proving the
19
+ // whole set is checked in one invocation rather than one moc call per file.
20
+ test("multiple files in a single invocation", async () => {
21
+ const cwd = path.join(import.meta.dirname, "check/success");
22
+ await cliSnapshot(
23
+ ["check", "Ok.mo", "Warning.mo", "--verbose"],
24
+ { cwd },
25
+ 0,
26
+ );
27
+ });
28
+
18
29
  test("warning", async () => {
19
30
  const cwd = path.join(import.meta.dirname, "check/success");
20
31
  const result = await cliSnapshot(["check", "Warning.mo"], { cwd }, 0);
package/tests/cli.test.ts CHANGED
@@ -1,5 +1,14 @@
1
1
  import { describe, expect, jest, test } from "@jest/globals";
2
- import { existsSync, readFileSync, rmSync, writeFileSync } from "node:fs";
2
+ import {
3
+ existsSync,
4
+ mkdtempSync,
5
+ readFileSync,
6
+ readdirSync,
7
+ rmSync,
8
+ statSync,
9
+ writeFileSync,
10
+ } from "node:fs";
11
+ import { tmpdir } from "node:os";
3
12
  import path from "path";
4
13
  import { cli, normalizePaths } from "./helpers";
5
14
 
@@ -128,6 +137,108 @@ describe("install", () => {
128
137
  rmSync(path.join(cwd, ".mops"), { recursive: true, force: true });
129
138
  }
130
139
  });
140
+
141
+ // Regression: when a file under `.mops/` was edited locally (an unsupported
142
+ // but common AI-agent workflow), `--lock update` would regenerate the
143
+ // lockfile from registry hashes, then fail the per-file check, and tell the
144
+ // user to "Run `mops install --lock update` to regenerate it" — the exact
145
+ // command that just failed. The post-regen message now says the local copy
146
+ // was modified and points at the actual fix.
147
+ test("--lock update flags a locally edited .mops/ file with a clear recovery hint", async () => {
148
+ const cwd = path.join(import.meta.dirname, "install/success");
149
+ const lockFile = path.join(cwd, "mops.lock");
150
+ const localDep = path.join(cwd, ".mops", "core@1.0.0", "mops.toml");
151
+ rmSync(lockFile, { force: true });
152
+ rmSync(path.join(cwd, ".mops"), { recursive: true, force: true });
153
+ try {
154
+ const first = await cli(["install"], { cwd, env: { CI: undefined } });
155
+ expect(first.exitCode).toBe(0);
156
+ expect(existsSync(localDep)).toBe(true);
157
+
158
+ writeFileSync(
159
+ localDep,
160
+ readFileSync(localDep, "utf8") + "\n# tampered\n",
161
+ );
162
+
163
+ const result = await cli(["install", "--lock", "update"], {
164
+ cwd,
165
+ env: { CI: undefined },
166
+ });
167
+ expect(result.exitCode).toBe(1);
168
+ expect(result.stderr).toMatch(
169
+ /\.mops\/core@1\.0\.0\/mops\.toml differs from the registry/,
170
+ );
171
+ expect(result.stderr).toMatch(
172
+ /delete the `\.mops\/core@1\.0\.0` directory and run `mops install`/,
173
+ );
174
+ expect(result.stderr).not.toMatch(/Run `mops install --lock update`/);
175
+ } finally {
176
+ rmSync(lockFile, { force: true });
177
+ rmSync(path.join(cwd, ".mops"), { recursive: true, force: true });
178
+ }
179
+ });
180
+
181
+ // Regression: parallel `mops install` runs against the same project used to
182
+ // race in two places — global cache writes (`.mops/<pkg>` populated mid-write)
183
+ // and local `.mops/<pkg>` copies — leaving zero-byte / partially-written
184
+ // files. We isolate the global cache via `XDG_CACHE_HOME` so the global-write
185
+ // path actually executes (cold-cache scenario).
186
+ test("parallel `mops install` produces a complete .mops tree (no zero-byte / staging dirs)", async () => {
187
+ const cwd = path.join(import.meta.dirname, "install/success");
188
+ const lockFile = path.join(cwd, "mops.lock");
189
+ const localCache = path.join(cwd, ".mops");
190
+ const xdgCache = mkdtempSync(path.join(tmpdir(), "mops-test-xdg-"));
191
+ rmSync(lockFile, { force: true });
192
+ rmSync(localCache, { recursive: true, force: true });
193
+ try {
194
+ const N = 5;
195
+ const env = { CI: undefined, XDG_CACHE_HOME: xdgCache };
196
+ const runs = await Promise.all(
197
+ Array.from({ length: N }, () => cli(["install"], { cwd, env })),
198
+ );
199
+ for (const r of runs) {
200
+ if (r.exitCode !== 0) {
201
+ throw new Error(
202
+ `mops install exited ${r.exitCode}\nstdout:\n${r.stdout}\nstderr:\n${r.stderr}`,
203
+ );
204
+ }
205
+ }
206
+
207
+ const walk = (dir: string): string[] => {
208
+ const out: string[] = [];
209
+ for (const entry of readdirSync(dir, { withFileTypes: true })) {
210
+ const p = path.join(dir, entry.name);
211
+ if (entry.isDirectory()) {
212
+ out.push(...walk(p));
213
+ } else if (entry.isFile()) {
214
+ out.push(p);
215
+ }
216
+ }
217
+ return out;
218
+ };
219
+ const files = walk(localCache);
220
+ const empties = files.filter((f) => statSync(f).size === 0);
221
+ expect(empties).toEqual([]);
222
+
223
+ const stagingLeftovers = readdirSync(localCache).filter((e) =>
224
+ e.startsWith(".staging-"),
225
+ );
226
+ expect(stagingLeftovers).toEqual([]);
227
+
228
+ const globalPkg = path.join(
229
+ xdgCache,
230
+ "mops",
231
+ "packages",
232
+ "core@1.0.0",
233
+ "mops.toml",
234
+ );
235
+ expect(existsSync(globalPkg)).toBe(true);
236
+ } finally {
237
+ rmSync(lockFile, { force: true });
238
+ rmSync(localCache, { recursive: true, force: true });
239
+ rmSync(xdgCache, { recursive: true, force: true });
240
+ }
241
+ });
131
242
  });
132
243
 
133
244
  // `mops update` and `mops outdated` default to caret-bound resolution: stay
@@ -214,3 +325,71 @@ describe("update / outdated bounds", () => {
214
325
  }
215
326
  });
216
327
  });
328
+
329
+ // `--patch` restricts updates to patch versions only, never crossing the minor
330
+ // bound. Fixture pins `core = "2.3.0"`; registry has 2.3.1 (patch) and 2.4.0,
331
+ // 2.5.0 (minor). Caret default lets minors through; --patch must not.
332
+ describe("update / outdated --patch bound", () => {
333
+ jest.setTimeout(120_000);
334
+
335
+ const cwd = path.join(import.meta.dirname, "install/update-bound-patch");
336
+ const tomlFile = path.join(cwd, "mops.toml");
337
+ const original = readFileSync(tomlFile, "utf8");
338
+
339
+ const cleanup = () => {
340
+ rmSync(path.join(cwd, "mops.lock"), { force: true });
341
+ rmSync(path.join(cwd, ".mops"), { recursive: true, force: true });
342
+ writeFileSync(tomlFile, original);
343
+ };
344
+
345
+ const coreVersion = (toml: string) =>
346
+ toml.match(/core = "(\d+\.\d+\.\d+)"/)?.[1];
347
+
348
+ test("mops update --patch restricts to patch bumps", async () => {
349
+ cleanup();
350
+ try {
351
+ await cli(["install"], { cwd, env: { CI: undefined } });
352
+ const result = await cli(["update", "--patch"], {
353
+ cwd,
354
+ env: { CI: undefined },
355
+ });
356
+ expect(result.exitCode).toBe(0);
357
+ const after = readFileSync(tomlFile, "utf8");
358
+ // Stays within 2.3.x — must not cross to 2.4.0 / 2.5.0
359
+ expect(coreVersion(after)).toMatch(/^2\.3\./);
360
+ expect(coreVersion(after)).not.toBe("2.3.0");
361
+ } finally {
362
+ cleanup();
363
+ }
364
+ });
365
+
366
+ test("mops outdated --patch reports patch-only updates", async () => {
367
+ cleanup();
368
+ try {
369
+ await cli(["install"], { cwd, env: { CI: undefined } });
370
+ const patch = normalizePaths(
371
+ (await cli(["outdated", "--patch"], { cwd, env: { CI: undefined } }))
372
+ .stdout,
373
+ );
374
+ // Only 2.3.x updates surface, never 2.4.x / 2.5.x
375
+ expect(patch).toMatch(/core 2\.3\.0 -> 2\.3\./);
376
+ expect(patch).not.toMatch(/core 2\.3\.0 -> 2\.[4-9]/);
377
+ } finally {
378
+ cleanup();
379
+ }
380
+ });
381
+
382
+ test.each([["update"], ["outdated"]])(
383
+ "mops %s rejects --major + --patch",
384
+ async (cmd) => {
385
+ const result = await cli([cmd, "--major", "--patch"], {
386
+ cwd,
387
+ env: { CI: undefined },
388
+ });
389
+ expect(result.exitCode).not.toBe(0);
390
+ expect(result.stderr).toMatch(
391
+ /option '--major' cannot be used with option '--patch'/,
392
+ );
393
+ },
394
+ );
395
+ });
@@ -0,0 +1,2 @@
1
+ [dependencies]
2
+ core = "2.3.0"
package/vessel.ts CHANGED
@@ -2,20 +2,28 @@ import process from "node:process";
2
2
  import {
3
3
  existsSync,
4
4
  mkdirSync,
5
+ mkdtempSync,
6
+ rmSync,
5
7
  createWriteStream,
6
8
  readFileSync,
7
9
  writeFileSync,
8
10
  } from "node:fs";
9
11
  import path from "node:path";
10
12
  import { pipeline } from "node:stream";
11
- import { deleteSync } from "del";
12
13
  import { execaCommand } from "execa";
13
14
  import chalk from "chalk";
14
15
  import { createLogUpdate } from "log-update";
15
16
  import got from "got";
16
17
  import decompress from "decompress";
17
- import { parseGithubURL, progressBar } from "./mops.js";
18
- import { getDepCacheDir, getGithubDepCacheName, isDepCached } from "./cache.js";
18
+ import { getRootDir, parseGithubURL, progressBar } from "./mops.js";
19
+ import {
20
+ commitStagingDir,
21
+ createStagingDir,
22
+ getDepCacheDir,
23
+ getGithubDepCacheName,
24
+ isDepCached,
25
+ sweepStaleStagingDirs,
26
+ } from "./cache.js";
19
27
 
20
28
  const dhallFileToJson = async (filePath: string, silent: boolean) => {
21
29
  if (existsSync(filePath)) {
@@ -130,18 +138,23 @@ export const downloadFromGithub = async (
130
138
 
131
139
  // Prevent `onError` being called twice.
132
140
  readStream.off("error", reject);
133
- const tmpDir = path.resolve(process.cwd(), ".mops/_tmp/");
141
+
142
+ // Per-invocation download dir (was a shared `.mops/_tmp/` clobbered
143
+ // by concurrent github installs). `.staging-` prefix lets the sweeper
144
+ // pick up leftovers from a crashed download.
145
+ const parentTmp = path.resolve(getRootDir(), ".mops");
146
+ mkdirSync(parentTmp, { recursive: true });
147
+ const tmpDir = mkdtempSync(path.join(parentTmp, ".staging-github-dl-"));
134
148
  const tmpFile = path.resolve(
135
149
  tmpDir,
136
150
  `${gitName}@${(commitHash || branch).replaceAll("/", "___")}.zip`,
137
151
  );
152
+ const cleanup = () => rmSync(tmpDir, { recursive: true, force: true });
138
153
 
139
154
  try {
140
- mkdirSync(tmpDir, { recursive: true });
141
-
142
155
  pipeline(readStream, createWriteStream(tmpFile), (err) => {
143
156
  if (err) {
144
- deleteSync([tmpDir]);
157
+ cleanup();
145
158
  reject(err);
146
159
  } else {
147
160
  let options = {
@@ -153,17 +166,17 @@ export const downloadFromGithub = async (
153
166
  };
154
167
  decompress(tmpFile, dest, options)
155
168
  .then((unzippedFiles) => {
156
- deleteSync([tmpDir]);
169
+ cleanup();
157
170
  resolve(unzippedFiles);
158
171
  })
159
172
  .catch((err) => {
160
- deleteSync([tmpDir]);
173
+ cleanup();
161
174
  reject(err);
162
175
  });
163
176
  }
164
177
  });
165
178
  } catch (err) {
166
- deleteSync([tmpDir]);
179
+ cleanup();
167
180
  reject(err);
168
181
  }
169
182
  });
@@ -182,6 +195,8 @@ export const installFromGithub = async (
182
195
  ignoreTransitive = false,
183
196
  } = {},
184
197
  ): Promise<boolean> => {
198
+ sweepStaleStagingDirs();
199
+
185
200
  let cacheName = getGithubDepCacheName(name, repo);
186
201
  let cacheDir = getDepCacheDir(cacheName);
187
202
 
@@ -199,12 +214,14 @@ export const installFromGithub = async (
199
214
 
200
215
  progress(0, 1024 * 500);
201
216
 
202
- mkdirSync(cacheDir, { recursive: true });
203
-
217
+ // Stage download in a sibling dir; previously `mkdirSync(cacheDir)`
218
+ // before download made empty dirs look cached to peers.
219
+ let stagingDir = createStagingDir(cacheDir);
204
220
  try {
205
- await downloadFromGithub(repo, cacheDir, progress);
221
+ await downloadFromGithub(repo, stagingDir, progress);
222
+ commitStagingDir(stagingDir, cacheDir);
206
223
  } catch (err) {
207
- deleteSync([cacheDir], { force: true });
224
+ rmSync(stagingDir, { recursive: true, force: true });
208
225
  return false;
209
226
  }
210
227
  }
@@ -11,4 +11,4 @@
11
11
  ],
12
12
  "main": "wasm.js",
13
13
  "types": "wasm.d.ts"
14
- }
14
+ }
Binary file
@@ -15,4 +15,4 @@
15
15
  "sideEffects": [
16
16
  "./snippets/*"
17
17
  ]
18
- }
18
+ }
Binary file