ic-mops 2.4.0 → 2.5.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.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,11 @@
2
2
 
3
3
  ## Next
4
4
 
5
+ ## 2.5.0
6
+ - Add support for `MOPS_REGISTRY_HOST` and `MOPS_REGISTRY_CANISTER_ID` environment variables for custom registry endpoints
7
+ - Fix `mops build` crashing with `__wbindgen_malloc` error in bundled CLI distribution
8
+ - Fix `parallel()` swallowing errors from concurrent tasks (e.g. `mops publish` uploads), which could hang or leave failures unreported
9
+
5
10
  ## 2.4.0
6
11
  - Support `[build].outputDir` config in `mops.toml` for custom build output directory
7
12
  - Fix `mops build --output` CLI option being silently ignored
package/api/network.ts CHANGED
@@ -3,20 +3,28 @@ export function getNetwork() {
3
3
  }
4
4
 
5
5
  export function getEndpoint(network: string) {
6
+ let endpoint: { host: string; canisterId: string };
6
7
  if (network === "staging") {
7
- return {
8
+ endpoint = {
8
9
  host: "https://icp-api.io",
9
10
  canisterId: "2d2zu-vaaaa-aaaak-qb6pq-cai",
10
11
  };
11
12
  } else if (network === "ic") {
12
- return {
13
+ endpoint = {
13
14
  host: "https://icp-api.io",
14
15
  canisterId: "oknww-riaaa-aaaam-qaf6a-cai",
15
16
  };
16
17
  } else {
17
- return {
18
+ endpoint = {
18
19
  host: "http://127.0.0.1:4943",
19
20
  canisterId: "2d2zu-vaaaa-aaaak-qb6pq-cai",
20
21
  };
21
22
  }
23
+
24
+ const hostOverride = process.env["MOPS_REGISTRY_HOST"]?.trim();
25
+ const canisterOverride = process.env["MOPS_REGISTRY_CANISTER_ID"]?.trim();
26
+ return {
27
+ host: hostOverride || endpoint.host,
28
+ canisterId: canisterOverride || endpoint.canisterId,
29
+ };
22
30
  }
package/bundle/cli.tgz CHANGED
Binary file
@@ -2,22 +2,29 @@ export function getNetwork() {
2
2
  return globalThis.MOPS_NETWORK || "ic";
3
3
  }
4
4
  export function getEndpoint(network) {
5
+ let endpoint;
5
6
  if (network === "staging") {
6
- return {
7
+ endpoint = {
7
8
  host: "https://icp-api.io",
8
9
  canisterId: "2d2zu-vaaaa-aaaak-qb6pq-cai",
9
10
  };
10
11
  }
11
12
  else if (network === "ic") {
12
- return {
13
+ endpoint = {
13
14
  host: "https://icp-api.io",
14
15
  canisterId: "oknww-riaaa-aaaam-qaf6a-cai",
15
16
  };
16
17
  }
17
18
  else {
18
- return {
19
+ endpoint = {
19
20
  host: "http://127.0.0.1:4943",
20
21
  canisterId: "2d2zu-vaaaa-aaaak-qb6pq-cai",
21
22
  };
22
23
  }
24
+ const hostOverride = process.env["MOPS_REGISTRY_HOST"]?.trim();
25
+ const canisterOverride = process.env["MOPS_REGISTRY_CANISTER_ID"]?.trim();
26
+ return {
27
+ host: hostOverride || endpoint.host,
28
+ canisterId: canisterOverride || endpoint.canisterId,
29
+ };
23
30
  }
@@ -1,4 +1,13 @@
1
1
  import * as wasm from "../../wasm/pkg/web/wasm.js";
2
2
  import { setWasmBindings } from "../../wasm.js";
3
+ import { readFileSync } from "node:fs";
4
+ import { resolve } from "node:path";
5
+ // Web wasm-pack target requires explicit initialization (unlike the nodejs
6
+ // target which auto-inits on require). Load the CLI's own WASM binary and
7
+ // call initSync before exposing the bindings.
8
+ // In the bundle __dirname is defined as import.meta.dirname and the binary
9
+ // sits next to cli.js; bundle:fix rewrites the path accordingly.
10
+ const wasmBytes = readFileSync(resolve(__dirname, "../../wasm/pkg/web/wasm_bg.wasm"));
11
+ wasm.initSync({ module: wasmBytes });
3
12
  setWasmBindings(wasm);
4
13
  export * from "../../cli.js";
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ic-mops",
3
- "version": "2.4.0",
3
+ "version": "2.5.0",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "mops": "bin/mops.js",
package/dist/parallel.js CHANGED
@@ -1,8 +1,12 @@
1
1
  export async function parallel(threads, items, fn) {
2
- return new Promise((resolve) => {
2
+ return new Promise((resolve, reject) => {
3
3
  let busyThreads = 0;
4
+ let failed = false;
4
5
  items = items.slice();
5
6
  let loop = () => {
7
+ if (failed) {
8
+ return;
9
+ }
6
10
  if (!items.length) {
7
11
  if (busyThreads === 0) {
8
12
  resolve();
@@ -16,6 +20,10 @@ export async function parallel(threads, items, fn) {
16
20
  fn(items.shift()).then(() => {
17
21
  busyThreads--;
18
22
  loop();
23
+ }, (err) => {
24
+ busyThreads--;
25
+ failed = true;
26
+ reject(err);
19
27
  });
20
28
  loop();
21
29
  };
@@ -1,4 +1,4 @@
1
- import { describe, expect, test } from "@jest/globals";
1
+ import { describe, expect, jest, test } from "@jest/globals";
2
2
  import { execa } from "execa";
3
3
  import { existsSync, rmSync } from "node:fs";
4
4
  import path from "path";
@@ -11,6 +11,8 @@ function cleanFixture(cwd, ...extras) {
11
11
  }
12
12
  }
13
13
  describe("build", () => {
14
+ // Several dfx/pocket-ic builds per test; slow CI (e.g. node 20 matrix) can exceed 60s default.
15
+ jest.setTimeout(120_000);
14
16
  test("ok", async () => {
15
17
  const cwd = path.join(import.meta.dirname, "build/success");
16
18
  try {
@@ -1,5 +1,17 @@
1
1
  import * as wasm from "../../wasm/pkg/web/wasm.js";
2
2
  import { setWasmBindings } from "../../wasm.js";
3
+ import { readFileSync } from "node:fs";
4
+ import { resolve } from "node:path";
5
+
6
+ // Web wasm-pack target requires explicit initialization (unlike the nodejs
7
+ // target which auto-inits on require). Load the CLI's own WASM binary and
8
+ // call initSync before exposing the bindings.
9
+ // In the bundle __dirname is defined as import.meta.dirname and the binary
10
+ // sits next to cli.js; bundle:fix rewrites the path accordingly.
11
+ const wasmBytes = readFileSync(
12
+ resolve(__dirname, "../../wasm/pkg/web/wasm_bg.wasm"),
13
+ );
14
+ wasm.initSync({ module: wasmBytes });
3
15
 
4
16
  setWasmBindings(wasm);
5
17
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ic-mops",
3
- "version": "2.4.0",
3
+ "version": "2.5.0",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "mops": "dist/bin/mops.js",
@@ -36,8 +36,8 @@
36
36
  "build:wasm:web": "wasm-pack build wasm --target web --out-dir pkg/web && rm wasm/pkg/web/.gitignore",
37
37
  "dist": "npm run build:wasm && tsc && mkdir -p dist/wasm && cp -r wasm/pkg dist/wasm",
38
38
  "bundle": "rm -rf ./bundle && bun build ./environments/web/cli.ts --outdir ./bundle --target node --minify --external @napi-rs/lzma --external fsevents --format esm --define '__dirname=import.meta.dirname' && run-s bundle:fix bundle:copy bundle:package-json bundle:tar",
39
- "bundle:fix": "rexreplace 'new URL\\(\"\\.\\./templates' 'new URL(\"./templates' bundle/cli.js && rexreplace 'resolve\\(\".*?/xhr-sync-worker\\.js\"\\)' 'resolve(\"./xhr-sync-worker.js\")' bundle/cli.js && rexreplace '\"import.meta.dirname\",\"wasm_bg.wasm\"' 'import.meta.dirname || new URL(\".\", import.meta.url).pathname,\"wasm_bg.wasm\"' bundle/cli.js && rexreplace 'resolve\\(\"import.meta.dirname\",\".*?/default-stylesheet\\.css\"\\)' 'resolve(import.meta.dirname,\"./default-stylesheet.css\")' bundle/cli.js",
40
- "bundle:copy": "cp -r commands/bench bundle && cp -r bin declarations templates package.json bundle && cp -r node_modules/prettier-plugin-motoko/wasm/pkg/nodejs/wasm_bg.wasm node_modules/jsdom/lib/jsdom/living/xhr/xhr-sync-worker.js node_modules/jsdom/lib/jsdom/browser/default-stylesheet.css bundle",
39
+ "bundle:fix": "rexreplace 'new URL\\(\"\\.\\./templates' 'new URL(\"./templates' bundle/cli.js && rexreplace 'resolve\\(\".*?/xhr-sync-worker\\.js\"\\)' 'resolve(\"./xhr-sync-worker.js\")' bundle/cli.js && rexreplace '\"import.meta.dirname\",\"wasm_bg.wasm\"' 'import.meta.dirname || new URL(\".\", import.meta.url).pathname,\"wasm_bg.wasm\"' bundle/cli.js && rexreplace 'resolve\\(\"import.meta.dirname\",\".*?/default-stylesheet\\.css\"\\)' 'resolve(import.meta.dirname,\"./default-stylesheet.css\")' bundle/cli.js && rexreplace '\"import.meta.dirname\",\"../../wasm/pkg/web/wasm_bg.wasm\"' 'import.meta.dirname || new URL(\".\", import.meta.url).pathname,\"mops_wasm_bg.wasm\"' bundle/cli.js",
40
+ "bundle:copy": "cp -r commands/bench bundle && cp -r bin declarations templates package.json bundle && cp wasm/pkg/web/wasm_bg.wasm bundle/mops_wasm_bg.wasm && cp -r node_modules/prettier-plugin-motoko/wasm/pkg/nodejs/wasm_bg.wasm node_modules/jsdom/lib/jsdom/living/xhr/xhr-sync-worker.js node_modules/jsdom/lib/jsdom/browser/default-stylesheet.css bundle",
41
41
  "bundle:package-json": "tsx bundle-package-json.ts",
42
42
  "bundle:tar": "rm -f bundle/cli.tgz && touch -t 200101010101 bundle/cli.tgz && find bundle -exec touch -d '1970-01-01 00:00:00' {} + && tar --sort name --exclude bundle/cli.tgz -cvf - bundle | gzip -n > bundle/cli.tgz",
43
43
  "copy": "cp -r commands/bench dist/commands && cp -r declarations templates package.json bin dist | true",
package/parallel.ts CHANGED
@@ -3,11 +3,15 @@ export async function parallel<T>(
3
3
  items: T[],
4
4
  fn: (item: T) => Promise<void>,
5
5
  ) {
6
- return new Promise<void>((resolve) => {
6
+ return new Promise<void>((resolve, reject) => {
7
7
  let busyThreads = 0;
8
+ let failed = false;
8
9
  items = items.slice();
9
10
 
10
11
  let loop = () => {
12
+ if (failed) {
13
+ return;
14
+ }
11
15
  if (!items.length) {
12
16
  if (busyThreads === 0) {
13
17
  resolve();
@@ -18,10 +22,17 @@ export async function parallel<T>(
18
22
  return;
19
23
  }
20
24
  busyThreads++;
21
- fn(items.shift() as T).then(() => {
22
- busyThreads--;
23
- loop();
24
- });
25
+ fn(items.shift() as T).then(
26
+ () => {
27
+ busyThreads--;
28
+ loop();
29
+ },
30
+ (err) => {
31
+ busyThreads--;
32
+ failed = true;
33
+ reject(err);
34
+ },
35
+ );
25
36
  loop();
26
37
  };
27
38
  loop();
@@ -1,4 +1,4 @@
1
- import { describe, expect, test } from "@jest/globals";
1
+ import { describe, expect, jest, test } from "@jest/globals";
2
2
  import { execa } from "execa";
3
3
  import { existsSync, rmSync } from "node:fs";
4
4
  import path from "path";
@@ -14,6 +14,9 @@ function cleanFixture(cwd: string, ...extras: string[]) {
14
14
  }
15
15
 
16
16
  describe("build", () => {
17
+ // Several dfx/pocket-ic builds per test; slow CI (e.g. node 20 matrix) can exceed 60s default.
18
+ jest.setTimeout(120_000);
19
+
17
20
  test("ok", async () => {
18
21
  const cwd = path.join(import.meta.dirname, "build/success");
19
22
  try {