ic-mops 2.13.1 → 2.14.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 (90) hide show
  1. package/CHANGELOG.md +25 -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-stable.ts +27 -23
  9. package/commands/check.ts +11 -1
  10. package/commands/init.ts +15 -2
  11. package/commands/install/install-mops-dep.ts +14 -9
  12. package/commands/install/sync-local-cache.ts +7 -1
  13. package/commands/lint.ts +11 -0
  14. package/commands/outdated.ts +5 -2
  15. package/commands/publish.ts +0 -1
  16. package/commands/test/test.ts +14 -0
  17. package/commands/update.ts +3 -2
  18. package/commands/watch/tester.ts +5 -1
  19. package/dist/cache.d.ts +3 -0
  20. package/dist/cache.js +98 -18
  21. package/dist/cli.js +16 -12
  22. package/dist/commands/available-updates.d.ts +1 -1
  23. package/dist/commands/available-updates.js +4 -1
  24. package/dist/commands/bench.js +2 -0
  25. package/dist/commands/check-stable.d.ts +0 -1
  26. package/dist/commands/check-stable.js +21 -18
  27. package/dist/commands/check.js +7 -1
  28. package/dist/commands/init.js +9 -2
  29. package/dist/commands/install/install-mops-dep.js +12 -9
  30. package/dist/commands/install/sync-local-cache.js +2 -1
  31. package/dist/commands/lint.js +7 -0
  32. package/dist/commands/outdated.d.ts +2 -1
  33. package/dist/commands/outdated.js +2 -2
  34. package/dist/commands/publish.js +0 -1
  35. package/dist/commands/test/test.d.ts +1 -1
  36. package/dist/commands/test/test.js +10 -5
  37. package/dist/commands/update.d.ts +2 -1
  38. package/dist/commands/update.js +2 -2
  39. package/dist/commands/watch/tester.js +4 -1
  40. package/dist/helpers/autofix-motoko.d.ts +1 -1
  41. package/dist/helpers/autofix-motoko.js +3 -0
  42. package/dist/helpers/deprecate-dfx-replica.d.ts +2 -0
  43. package/dist/helpers/deprecate-dfx-replica.js +20 -0
  44. package/dist/helpers/fix-lock.d.ts +1 -0
  45. package/dist/helpers/fix-lock.js +93 -0
  46. package/dist/helpers/migrations.js +7 -5
  47. package/dist/integrity.d.ts +2 -2
  48. package/dist/integrity.js +22 -6
  49. package/dist/mops.js +1 -1
  50. package/dist/package.json +3 -3
  51. package/dist/tests/check-fix.test.js +40 -0
  52. package/dist/tests/check-stable.test.js +17 -0
  53. package/dist/tests/check.test.js +4 -3
  54. package/dist/tests/cli.test.js +136 -1
  55. package/dist/tests/helpers.js +5 -1
  56. package/dist/tests/migrate.test.js +2 -2
  57. package/dist/types.d.ts +1 -0
  58. package/dist/vessel.js +21 -13
  59. package/dist/wasm/pkg/nodejs/package.json +1 -1
  60. package/dist/wasm/pkg/nodejs/wasm_bg.wasm +0 -0
  61. package/dist/wasm/pkg/web/package.json +1 -1
  62. package/dist/wasm/pkg/web/wasm_bg.wasm +0 -0
  63. package/helpers/autofix-motoko.ts +4 -1
  64. package/helpers/deprecate-dfx-replica.ts +32 -0
  65. package/helpers/fix-lock.ts +101 -0
  66. package/helpers/migrations.ts +7 -4
  67. package/integrity.ts +30 -9
  68. package/mops.ts +1 -1
  69. package/package.json +3 -3
  70. package/tests/__snapshots__/migrate.test.ts.snap +1 -2
  71. package/tests/check-fix.test.ts +46 -0
  72. package/tests/check-stable/migrations-chain/deployed.most +14 -0
  73. package/tests/check-stable/migrations-chain/migrations/20250101_000000_Init.mo +8 -0
  74. package/tests/check-stable/migrations-chain/migrations/20250201_000000_AddField.mo +9 -0
  75. package/tests/check-stable/migrations-chain/migrations/20250301_000000_AddD.mo +10 -0
  76. package/tests/check-stable/migrations-chain/migrations/20250401_000000_AddE.mo +11 -0
  77. package/tests/check-stable/migrations-chain/mops.toml +15 -0
  78. package/tests/check-stable/migrations-chain/src/main.mo +13 -0
  79. package/tests/check-stable.test.ts +20 -0
  80. package/tests/check.test.ts +4 -3
  81. package/tests/cli.test.ts +180 -1
  82. package/tests/helpers.ts +5 -1
  83. package/tests/install/update-bound-patch/mops.toml +2 -0
  84. package/tests/migrate.test.ts +2 -2
  85. package/types.ts +1 -0
  86. package/vessel.ts +31 -14
  87. package/wasm/pkg/nodejs/package.json +1 -1
  88. package/wasm/pkg/nodejs/wasm_bg.wasm +0 -0
  89. package/wasm/pkg/web/package.json +1 -1
  90. package/wasm/pkg/web/wasm_bg.wasm +0 -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