ic-mops 2.1.0 → 2.2.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.
- package/.DS_Store +0 -0
- package/CHANGELOG.md +8 -0
- package/RELEASE.md +19 -0
- package/bundle/bench/bench-canister.mo +130 -0
- package/bundle/bench/user-bench.mo +10 -0
- package/bundle/bin/moc-wrapper.sh +40 -0
- package/bundle/bin/mops.js +3 -0
- package/bundle/cli.js +1569 -0
- package/bundle/cli.tgz +0 -0
- package/bundle/declarations/bench/bench.did +30 -0
- package/bundle/declarations/bench/bench.did.d.ts +33 -0
- package/bundle/declarations/bench/bench.did.js +30 -0
- package/bundle/declarations/bench/index.d.ts +50 -0
- package/bundle/declarations/bench/index.js +40 -0
- package/bundle/declarations/main/index.d.ts +50 -0
- package/bundle/declarations/main/index.js +40 -0
- package/bundle/declarations/main/main.did +428 -0
- package/bundle/declarations/main/main.did.d.ts +348 -0
- package/bundle/declarations/main/main.did.js +406 -0
- package/bundle/declarations/storage/index.d.ts +50 -0
- package/bundle/declarations/storage/index.js +30 -0
- package/bundle/declarations/storage/storage.did +46 -0
- package/bundle/declarations/storage/storage.did.d.ts +40 -0
- package/bundle/declarations/storage/storage.did.js +38 -0
- package/bundle/default-stylesheet.css +415 -0
- package/bundle/package.json +36 -0
- package/bundle/templates/README.md +13 -0
- package/bundle/templates/licenses/Apache-2.0 +202 -0
- package/bundle/templates/licenses/Apache-2.0-NOTICE +13 -0
- package/bundle/templates/licenses/MIT +21 -0
- package/bundle/templates/mops-publish.yml +17 -0
- package/bundle/templates/mops-test.yml +24 -0
- package/bundle/templates/src/lib.mo +15 -0
- package/bundle/templates/test/lib.test.mo +4 -0
- package/bundle/wasm_bg.wasm +0 -0
- package/bundle/xhr-sync-worker.js +51 -0
- package/cli.ts +15 -0
- package/commands/bench.ts +11 -3
- package/commands/build.ts +3 -2
- package/commands/check.ts +4 -0
- package/commands/test/test.ts +3 -1
- package/commands/toolchain/index.ts +4 -0
- package/commands/watch/error-checker.ts +8 -2
- package/commands/watch/warning-checker.ts +8 -2
- package/dist/cli.js +13 -1
- package/dist/commands/bench.js +5 -4
- package/dist/commands/build.js +3 -2
- package/dist/commands/check.js +4 -0
- package/dist/commands/test/test.js +3 -1
- package/dist/commands/toolchain/index.js +3 -0
- package/dist/commands/watch/error-checker.js +8 -2
- package/dist/commands/watch/warning-checker.js +8 -2
- package/dist/error.d.ts +1 -1
- package/dist/helpers/autofix-motoko.js +84 -39
- package/dist/mops.d.ts +1 -0
- package/dist/mops.js +10 -4
- package/dist/package.json +6 -7
- package/dist/tests/check-fix.test.js +16 -0
- package/dist/tests/check.test.js +4 -0
- package/dist/tests/moc-args.test.d.ts +1 -0
- package/dist/tests/moc-args.test.js +17 -0
- package/dist/tests/toolchain.test.js +11 -0
- package/dist/types.d.ts +3 -0
- package/dist/wasm/pkg/bundler/package.json +20 -0
- package/dist/wasm/pkg/bundler/wasm.d.ts +3 -0
- package/dist/wasm/pkg/bundler/wasm.js +5 -0
- package/dist/wasm/pkg/bundler/wasm_bg.js +93 -0
- package/dist/wasm/pkg/bundler/wasm_bg.wasm +0 -0
- package/dist/wasm/pkg/bundler/wasm_bg.wasm.d.ts +8 -0
- package/dist/wasm/pkg/nodejs/wasm_bg.wasm +0 -0
- package/dist/wasm/pkg/web/wasm_bg.wasm +0 -0
- package/error.ts +1 -1
- package/helpers/autofix-motoko.ts +119 -49
- package/mops.ts +13 -6
- package/package.json +8 -9
- package/tests/__snapshots__/check-fix.test.ts.snap +25 -6
- package/tests/__snapshots__/check.test.ts.snap +9 -0
- package/tests/build/success/.dfx/local/canister_ids.json +17 -0
- package/tests/build/success/.dfx/local/canisters/bar/bar.did +3 -0
- package/tests/build/success/.dfx/local/canisters/bar/bar.most +4 -0
- package/tests/build/success/.dfx/local/canisters/bar/bar.wasm +0 -0
- package/tests/build/success/.dfx/local/canisters/bar/constructor.did +3 -0
- package/tests/build/success/.dfx/local/canisters/bar/index.js +42 -0
- package/tests/build/success/.dfx/local/canisters/bar/init_args.txt +1 -0
- package/tests/build/success/.dfx/local/canisters/bar/service.did +3 -0
- package/tests/build/success/.dfx/local/canisters/bar/service.did.d.ts +7 -0
- package/tests/build/success/.dfx/local/canisters/bar/service.did.js +4 -0
- package/tests/build/success/.dfx/local/canisters/foo/constructor.did +3 -0
- package/tests/build/success/.dfx/local/canisters/foo/foo.did +3 -0
- package/tests/build/success/.dfx/local/canisters/foo/foo.most +4 -0
- package/tests/build/success/.dfx/local/canisters/foo/foo.wasm +0 -0
- package/tests/build/success/.dfx/local/canisters/foo/index.js +42 -0
- package/tests/build/success/.dfx/local/canisters/foo/init_args.txt +1 -0
- package/tests/build/success/.dfx/local/canisters/foo/service.did +3 -0
- package/tests/build/success/.dfx/local/canisters/foo/service.did.d.ts +7 -0
- package/tests/build/success/.dfx/local/canisters/foo/service.did.js +4 -0
- package/tests/build/success/.dfx/local/lsp/ucwa4-rx777-77774-qaada-cai.did +3 -0
- package/tests/build/success/.dfx/local/lsp/ulvla-h7777-77774-qaacq-cai.did +3 -0
- package/tests/build/success/.dfx/local/network-id +4 -0
- package/tests/check/fix/overlapping.mo +10 -0
- package/tests/check/moc-args/Warning.mo +5 -0
- package/tests/check/moc-args/mops.toml +2 -0
- package/tests/check-fix.test.ts +23 -0
- package/tests/check.test.ts +5 -0
- package/tests/moc-args.test.ts +19 -0
- package/tests/toolchain-local-subpath/bin/moc +2 -0
- package/tests/toolchain-local-subpath/mops.toml +2 -0
- package/tests/toolchain.test.ts +13 -0
- package/types.ts +3 -0
- package/wasm/Cargo.lock +54 -101
- package/wasm/pkg/bundler/package.json +20 -0
- package/wasm/pkg/bundler/wasm.d.ts +3 -0
- package/wasm/pkg/bundler/wasm.js +5 -0
- package/wasm/pkg/bundler/wasm_bg.js +93 -0
- package/wasm/pkg/bundler/wasm_bg.wasm +0 -0
- package/wasm/pkg/bundler/wasm_bg.wasm.d.ts +8 -0
- package/wasm/pkg/nodejs/wasm_bg.wasm +0 -0
- package/wasm/pkg/web/wasm_bg.wasm +0 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) <year> <copyright-owner>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
name: publish on mops
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
release:
|
|
5
|
+
types: [released]
|
|
6
|
+
|
|
7
|
+
jobs:
|
|
8
|
+
publish:
|
|
9
|
+
runs-on: ubuntu-latest
|
|
10
|
+
|
|
11
|
+
steps:
|
|
12
|
+
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
|
|
13
|
+
- uses: dfinity/setup-mops@v1
|
|
14
|
+
with:
|
|
15
|
+
# Make sure you set the MOPS_IDENTITY_PEM secret in your repository settings https://docs.github.com/en/actions/security-guides/using-secrets-in-github-actions#creating-secrets-for-a-repository
|
|
16
|
+
identity-pem: ${{ secrets.MOPS_IDENTITY_PEM }}
|
|
17
|
+
- run: mops publish
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
name: mops test
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- main
|
|
7
|
+
- master
|
|
8
|
+
pull_request:
|
|
9
|
+
|
|
10
|
+
jobs:
|
|
11
|
+
test:
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
|
|
14
|
+
steps:
|
|
15
|
+
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
|
|
16
|
+
- uses: dfinity/setup-mops@v1
|
|
17
|
+
with:
|
|
18
|
+
mops-version: 1
|
|
19
|
+
|
|
20
|
+
- name: install mops packages
|
|
21
|
+
run: mops install
|
|
22
|
+
|
|
23
|
+
- name: run tests
|
|
24
|
+
run: mops test
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
module {
|
|
2
|
+
// This comment will not be included in the documentation
|
|
3
|
+
// Use triple slash for documentation
|
|
4
|
+
|
|
5
|
+
/// Add two natural numbers
|
|
6
|
+
///
|
|
7
|
+
/// Example:
|
|
8
|
+
/// ```motoko
|
|
9
|
+
/// assert add(1, 2) == 3;
|
|
10
|
+
/// assert add(7, 3) == 10;
|
|
11
|
+
/// ```
|
|
12
|
+
public func add(x : Nat, y : Nat) : Nat {
|
|
13
|
+
return x + y;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
Binary file
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Persistent worker thread for handling synchronous XHR requests.
|
|
3
|
+
//
|
|
4
|
+
// This worker runs in a separate thread and performs async HTTP requests on behalf of the main
|
|
5
|
+
// thread, which blocks on Atomics.wait() until we signal completion. A single JSDOM instance is
|
|
6
|
+
// created at startup and reused across requests to avoid the ~400ms initialization cost each time.
|
|
7
|
+
//
|
|
8
|
+
// The signaling protocol (shared with sendSyncWorkerRequest in XMLHttpRequest-impl.js):
|
|
9
|
+
// 1. Main thread sends us a SharedArrayBuffer, a MessagePort, and the serialized request config.
|
|
10
|
+
// 2. We perform the XHR asynchronously.
|
|
11
|
+
// 3. When done, we post the serialized response to the MessagePort, then signal the main thread
|
|
12
|
+
// by writing 1 to the SharedArrayBuffer with Atomics.store() and waking it with Atomics.notify().
|
|
13
|
+
|
|
14
|
+
const { parentPort } = require("node:worker_threads");
|
|
15
|
+
const { JSDOM } = require("../../../..");
|
|
16
|
+
const idlUtils = require("../../../generated/idl/utils");
|
|
17
|
+
|
|
18
|
+
const dom = new JSDOM();
|
|
19
|
+
const IDLE_TIMEOUT_MS = 5000;
|
|
20
|
+
|
|
21
|
+
let idleTimer = setTimeout(() => process.exit(0), IDLE_TIMEOUT_MS);
|
|
22
|
+
idleTimer.unref();
|
|
23
|
+
|
|
24
|
+
parentPort.on("message", ({ sharedBuffer, responsePort, config }) => {
|
|
25
|
+
clearTimeout(idleTimer);
|
|
26
|
+
|
|
27
|
+
const int32 = new Int32Array(sharedBuffer);
|
|
28
|
+
|
|
29
|
+
const xhr = new dom.window.XMLHttpRequest();
|
|
30
|
+
const xhrImpl = idlUtils.implForWrapper(xhr);
|
|
31
|
+
xhrImpl._adoptSerializedRequest(config);
|
|
32
|
+
|
|
33
|
+
function done() {
|
|
34
|
+
const response = xhrImpl._serializeResponse();
|
|
35
|
+
const transfer = response.responseBytes ? [response.responseBytes.buffer] : [];
|
|
36
|
+
responsePort.postMessage(response, transfer);
|
|
37
|
+
Atomics.store(int32, 0, 1);
|
|
38
|
+
Atomics.notify(int32, 0);
|
|
39
|
+
|
|
40
|
+
idleTimer = setTimeout(() => process.exit(0), IDLE_TIMEOUT_MS);
|
|
41
|
+
idleTimer.unref();
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
try {
|
|
45
|
+
xhr.addEventListener("loadend", done, false);
|
|
46
|
+
xhr.send(xhrImpl._body);
|
|
47
|
+
} catch (error) {
|
|
48
|
+
xhrImpl._error = error;
|
|
49
|
+
done();
|
|
50
|
+
}
|
|
51
|
+
});
|
package/cli.ts
CHANGED
|
@@ -46,7 +46,9 @@ import {
|
|
|
46
46
|
apiVersion,
|
|
47
47
|
checkApiCompatibility,
|
|
48
48
|
checkConfigFile,
|
|
49
|
+
getGlobalMocArgs,
|
|
49
50
|
getNetworkFile,
|
|
51
|
+
readConfig,
|
|
50
52
|
setNetwork,
|
|
51
53
|
version,
|
|
52
54
|
} from "./mops.js";
|
|
@@ -255,6 +257,19 @@ program
|
|
|
255
257
|
console.log(sourcesArr.join("\n"));
|
|
256
258
|
});
|
|
257
259
|
|
|
260
|
+
// moc-args
|
|
261
|
+
program
|
|
262
|
+
.command("moc-args")
|
|
263
|
+
.description("Print global moc compiler flags from [moc] config section")
|
|
264
|
+
.action(async () => {
|
|
265
|
+
checkConfigFile(true);
|
|
266
|
+
let config = readConfig();
|
|
267
|
+
let args = getGlobalMocArgs(config);
|
|
268
|
+
if (args.length) {
|
|
269
|
+
console.log(args.join("\n"));
|
|
270
|
+
}
|
|
271
|
+
});
|
|
272
|
+
|
|
258
273
|
// search
|
|
259
274
|
program
|
|
260
275
|
.command("search <text>")
|
package/commands/bench.ts
CHANGED
|
@@ -12,7 +12,12 @@ import { filesize } from "filesize";
|
|
|
12
12
|
import terminalSize from "terminal-size";
|
|
13
13
|
import { SemVer } from "semver";
|
|
14
14
|
|
|
15
|
-
import {
|
|
15
|
+
import {
|
|
16
|
+
getGlobalMocArgs,
|
|
17
|
+
getRootDir,
|
|
18
|
+
readConfig,
|
|
19
|
+
readDfxJson,
|
|
20
|
+
} from "../mops.js";
|
|
16
21
|
import { parallel } from "../parallel.js";
|
|
17
22
|
import { absToRel } from "./test/utils.js";
|
|
18
23
|
import { getMocVersion } from "../helpers/get-moc-version.js";
|
|
@@ -138,13 +143,15 @@ export async function bench(
|
|
|
138
143
|
|
|
139
144
|
await replica.start({ silent: options.silent });
|
|
140
145
|
|
|
146
|
+
let globalMocArgs = getGlobalMocArgs(config);
|
|
147
|
+
|
|
141
148
|
if (!process.env.CI && !options.silent) {
|
|
142
149
|
console.log("Deploying canisters...");
|
|
143
150
|
}
|
|
144
151
|
|
|
145
152
|
await parallel(os.cpus().length, files, async (file: string) => {
|
|
146
153
|
try {
|
|
147
|
-
await deployBenchFile(file, options, replica);
|
|
154
|
+
await deployBenchFile(file, options, replica, globalMocArgs);
|
|
148
155
|
} catch (err) {
|
|
149
156
|
console.error("Unexpected error. Stopping replica...");
|
|
150
157
|
await replica.stop();
|
|
@@ -267,6 +274,7 @@ async function deployBenchFile(
|
|
|
267
274
|
file: string,
|
|
268
275
|
options: BenchOptions,
|
|
269
276
|
replica: BenchReplica,
|
|
277
|
+
globalMocArgs: string[],
|
|
270
278
|
): Promise<void> {
|
|
271
279
|
let rootDir = getRootDir();
|
|
272
280
|
let tempDir = path.join(rootDir, ".mops/.bench/", path.parse(file).name);
|
|
@@ -294,7 +302,7 @@ async function deployBenchFile(
|
|
|
294
302
|
let mocArgs = getMocArgs(options);
|
|
295
303
|
options.verbose && console.time(`build ${canisterName}`);
|
|
296
304
|
await execaCommand(
|
|
297
|
-
`${mocPath} -c --idl canister.mo ${mocArgs} ${(await sources({ cwd: tempDir })).join(" ")}`,
|
|
305
|
+
`${mocPath} -c --idl canister.mo ${globalMocArgs.join(" ")} ${mocArgs} ${(await sources({ cwd: tempDir })).join(" ")}`,
|
|
298
306
|
{
|
|
299
307
|
cwd: tempDir,
|
|
300
308
|
stdio: options.verbose ? "pipe" : ["pipe", "ignore", "pipe"],
|
package/commands/build.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { join } from "node:path";
|
|
|
6
6
|
import { cliError } from "../error.js";
|
|
7
7
|
import { isCandidCompatible } from "../helpers/is-candid-compatible.js";
|
|
8
8
|
import { CustomSection, getWasmBindings } from "../wasm.js";
|
|
9
|
-
import { readConfig } from "../mops.js";
|
|
9
|
+
import { getGlobalMocArgs, readConfig } from "../mops.js";
|
|
10
10
|
import { CanisterConfig } from "../types.js";
|
|
11
11
|
import { sourcesArgs } from "./sources.js";
|
|
12
12
|
import { toolchain } from "./toolchain/index.js";
|
|
@@ -82,8 +82,8 @@ export async function build(
|
|
|
82
82
|
"-o",
|
|
83
83
|
wasmPath,
|
|
84
84
|
motokoPath,
|
|
85
|
-
...(options.extraArgs ?? []),
|
|
86
85
|
...(await sourcesArgs()).flat(),
|
|
86
|
+
...getGlobalMocArgs(config),
|
|
87
87
|
];
|
|
88
88
|
if (config.build?.args) {
|
|
89
89
|
if (typeof config.build.args === "string") {
|
|
@@ -101,6 +101,7 @@ export async function build(
|
|
|
101
101
|
}
|
|
102
102
|
args.push(...canister.args);
|
|
103
103
|
}
|
|
104
|
+
args.push(...(options.extraArgs ?? []));
|
|
104
105
|
const isPublicCandid = true; // always true for now to reduce corner cases
|
|
105
106
|
const candidVisibility = isPublicCandid ? "icp:public" : "icp:private";
|
|
106
107
|
if (isPublicCandid) {
|
package/commands/check.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { relative } from "node:path";
|
|
|
2
2
|
import chalk from "chalk";
|
|
3
3
|
import { execa } from "execa";
|
|
4
4
|
import { cliError } from "../error.js";
|
|
5
|
+
import { getGlobalMocArgs, readConfig } from "../mops.js";
|
|
5
6
|
import { autofixMotoko } from "../helpers/autofix-motoko.js";
|
|
6
7
|
import { getMocSemVer } from "../helpers/get-moc-version.js";
|
|
7
8
|
import { sourcesArgs } from "./sources.js";
|
|
@@ -30,8 +31,10 @@ export async function check(
|
|
|
30
31
|
cliError("No Motoko files specified for checking");
|
|
31
32
|
}
|
|
32
33
|
|
|
34
|
+
const config = readConfig();
|
|
33
35
|
const mocPath = await toolchain.bin("moc", { fallback: true });
|
|
34
36
|
const sources = await sourcesArgs();
|
|
37
|
+
const globalMocArgs = getGlobalMocArgs(config);
|
|
35
38
|
|
|
36
39
|
// --all-libs enables richer diagnostics with edit suggestions from moc (requires moc >= 1.3.0)
|
|
37
40
|
const allLibs = supportsAllLibsFlag();
|
|
@@ -53,6 +56,7 @@ export async function check(
|
|
|
53
56
|
"--check",
|
|
54
57
|
...(allLibs ? ["--all-libs"] : []),
|
|
55
58
|
...sources.flat(),
|
|
59
|
+
...globalMocArgs,
|
|
56
60
|
...(options.extraArgs ?? []),
|
|
57
61
|
];
|
|
58
62
|
|
package/commands/test/test.ts
CHANGED
|
@@ -13,7 +13,7 @@ import { SemVer } from "semver";
|
|
|
13
13
|
import { ActorMethod } from "@icp-sdk/core/agent";
|
|
14
14
|
|
|
15
15
|
import { sources } from "../sources.js";
|
|
16
|
-
import { getRootDir, readConfig } from "../../mops.js";
|
|
16
|
+
import { getGlobalMocArgs, getRootDir, readConfig } from "../../mops.js";
|
|
17
17
|
import { parallel } from "../../parallel.js";
|
|
18
18
|
|
|
19
19
|
import { MMF1 } from "./mmf1.js";
|
|
@@ -232,6 +232,7 @@ export async function testWithReporter(
|
|
|
232
232
|
|
|
233
233
|
let config = readConfig();
|
|
234
234
|
let sourcesArr = await sources();
|
|
235
|
+
let globalMocArgs = getGlobalMocArgs(config);
|
|
235
236
|
|
|
236
237
|
if (!mocPath) {
|
|
237
238
|
mocPath = await toolchain.bin("moc", { fallback: true });
|
|
@@ -298,6 +299,7 @@ export async function testWithReporter(
|
|
|
298
299
|
"--hide-warnings",
|
|
299
300
|
"--error-detail=2",
|
|
300
301
|
...sourcesArr.join(" ").split(" "),
|
|
302
|
+
...globalMocArgs,
|
|
301
303
|
file,
|
|
302
304
|
].filter((x) => x);
|
|
303
305
|
|
|
@@ -174,6 +174,10 @@ async function download(
|
|
|
174
174
|
version: string,
|
|
175
175
|
{ silent = false, verbose = false } = {},
|
|
176
176
|
) {
|
|
177
|
+
if (version.match(FILE_PATH_REGEX)) {
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
|
|
177
181
|
let toolUtils = getToolUtils(tool);
|
|
178
182
|
let logUpdate = createLogUpdate(process.stdout, { showCursor: true });
|
|
179
183
|
|
|
@@ -4,7 +4,7 @@ import os from "node:os";
|
|
|
4
4
|
import chalk from "chalk";
|
|
5
5
|
|
|
6
6
|
import { getMocPath } from "../../helpers/get-moc-path.js";
|
|
7
|
-
import { getRootDir } from "../../mops.js";
|
|
7
|
+
import { getGlobalMocArgs, getRootDir, readConfig } from "../../mops.js";
|
|
8
8
|
import { sources } from "../sources.js";
|
|
9
9
|
import { parallel } from "../../parallel.js";
|
|
10
10
|
import { globMoFiles } from "./globMoFiles.js";
|
|
@@ -44,6 +44,7 @@ export class ErrorChecker {
|
|
|
44
44
|
let rootDir = getRootDir();
|
|
45
45
|
let mocPath = getMocPath();
|
|
46
46
|
let deps = await sources({ cwd: rootDir });
|
|
47
|
+
let globalMocArgs = getGlobalMocArgs(readConfig());
|
|
47
48
|
|
|
48
49
|
let paths = globMoFiles(rootDir);
|
|
49
50
|
|
|
@@ -54,7 +55,12 @@ export class ErrorChecker {
|
|
|
54
55
|
try {
|
|
55
56
|
await promisify(execFile)(
|
|
56
57
|
mocPath,
|
|
57
|
-
[
|
|
58
|
+
[
|
|
59
|
+
"--check",
|
|
60
|
+
...deps.flatMap((x) => x.split(" ")),
|
|
61
|
+
...globalMocArgs,
|
|
62
|
+
file,
|
|
63
|
+
],
|
|
58
64
|
{ cwd: rootDir },
|
|
59
65
|
);
|
|
60
66
|
} catch (error: any) {
|
|
@@ -4,7 +4,7 @@ import os from "node:os";
|
|
|
4
4
|
import chalk from "chalk";
|
|
5
5
|
|
|
6
6
|
import { getMocPath } from "../../helpers/get-moc-path.js";
|
|
7
|
-
import { getRootDir } from "../../mops.js";
|
|
7
|
+
import { getGlobalMocArgs, getRootDir, readConfig } from "../../mops.js";
|
|
8
8
|
import { sources } from "../sources.js";
|
|
9
9
|
import { ErrorChecker } from "./error-checker.js";
|
|
10
10
|
import { parallel } from "../../parallel.js";
|
|
@@ -70,6 +70,7 @@ export class WarningChecker {
|
|
|
70
70
|
let rootDir = getRootDir();
|
|
71
71
|
let mocPath = getMocPath();
|
|
72
72
|
let deps = await sources({ cwd: rootDir });
|
|
73
|
+
let globalMocArgs = getGlobalMocArgs(readConfig());
|
|
73
74
|
let paths = globMoFiles(rootDir);
|
|
74
75
|
|
|
75
76
|
this.totalFiles = paths.length;
|
|
@@ -82,7 +83,12 @@ export class WarningChecker {
|
|
|
82
83
|
|
|
83
84
|
let { stderr } = await promisify(execFile)(
|
|
84
85
|
mocPath,
|
|
85
|
-
[
|
|
86
|
+
[
|
|
87
|
+
"--check",
|
|
88
|
+
...deps.flatMap((x) => x.split(" ")),
|
|
89
|
+
...globalMocArgs,
|
|
90
|
+
file,
|
|
91
|
+
],
|
|
86
92
|
{ cwd: rootDir, signal },
|
|
87
93
|
).catch((error) => {
|
|
88
94
|
if (error.code === "ABORT_ERR") {
|
package/dist/cli.js
CHANGED
|
@@ -32,7 +32,7 @@ import { toolchain } from "./commands/toolchain/index.js";
|
|
|
32
32
|
import { update } from "./commands/update.js";
|
|
33
33
|
import { getPrincipal, getUserProp, importPem, setUserProp, } from "./commands/user.js";
|
|
34
34
|
import { watch } from "./commands/watch/watch.js";
|
|
35
|
-
import { apiVersion, checkApiCompatibility, checkConfigFile, getNetworkFile, setNetwork, version, } from "./mops.js";
|
|
35
|
+
import { apiVersion, checkApiCompatibility, checkConfigFile, getGlobalMocArgs, getNetworkFile, readConfig, setNetwork, version, } from "./mops.js";
|
|
36
36
|
import { resolvePackages } from "./resolve-packages.js";
|
|
37
37
|
import { TOOLCHAINS } from "./commands/toolchain/toolchain-utils.js";
|
|
38
38
|
events.setMaxListeners(20);
|
|
@@ -193,6 +193,18 @@ program
|
|
|
193
193
|
let sourcesArr = await sources(options);
|
|
194
194
|
console.log(sourcesArr.join("\n"));
|
|
195
195
|
});
|
|
196
|
+
// moc-args
|
|
197
|
+
program
|
|
198
|
+
.command("moc-args")
|
|
199
|
+
.description("Print global moc compiler flags from [moc] config section")
|
|
200
|
+
.action(async () => {
|
|
201
|
+
checkConfigFile(true);
|
|
202
|
+
let config = readConfig();
|
|
203
|
+
let args = getGlobalMocArgs(config);
|
|
204
|
+
if (args.length) {
|
|
205
|
+
console.log(args.join("\n"));
|
|
206
|
+
}
|
|
207
|
+
});
|
|
196
208
|
// search
|
|
197
209
|
program
|
|
198
210
|
.command("search <text>")
|
package/dist/commands/bench.js
CHANGED
|
@@ -11,7 +11,7 @@ import stringWidth from "string-width";
|
|
|
11
11
|
import { filesize } from "filesize";
|
|
12
12
|
import terminalSize from "terminal-size";
|
|
13
13
|
import { SemVer } from "semver";
|
|
14
|
-
import { getRootDir, readConfig, readDfxJson } from "../mops.js";
|
|
14
|
+
import { getGlobalMocArgs, getRootDir, readConfig, readDfxJson, } from "../mops.js";
|
|
15
15
|
import { parallel } from "../parallel.js";
|
|
16
16
|
import { absToRel } from "./test/utils.js";
|
|
17
17
|
import { getMocVersion } from "../helpers/get-moc-version.js";
|
|
@@ -95,12 +95,13 @@ export async function bench(filter = "", optionsArg = {}) {
|
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
97
|
await replica.start({ silent: options.silent });
|
|
98
|
+
let globalMocArgs = getGlobalMocArgs(config);
|
|
98
99
|
if (!process.env.CI && !options.silent) {
|
|
99
100
|
console.log("Deploying canisters...");
|
|
100
101
|
}
|
|
101
102
|
await parallel(os.cpus().length, files, async (file) => {
|
|
102
103
|
try {
|
|
103
|
-
await deployBenchFile(file, options, replica);
|
|
104
|
+
await deployBenchFile(file, options, replica, globalMocArgs);
|
|
104
105
|
}
|
|
105
106
|
catch (err) {
|
|
106
107
|
console.error("Unexpected error. Stopping replica...");
|
|
@@ -191,7 +192,7 @@ function getMocArgs(options) {
|
|
|
191
192
|
}
|
|
192
193
|
return args;
|
|
193
194
|
}
|
|
194
|
-
async function deployBenchFile(file, options, replica) {
|
|
195
|
+
async function deployBenchFile(file, options, replica, globalMocArgs) {
|
|
195
196
|
let rootDir = getRootDir();
|
|
196
197
|
let tempDir = path.join(rootDir, ".mops/.bench/", path.parse(file).name);
|
|
197
198
|
let canisterName = path.parse(file).name;
|
|
@@ -205,7 +206,7 @@ async function deployBenchFile(file, options, replica) {
|
|
|
205
206
|
let mocPath = getMocPath();
|
|
206
207
|
let mocArgs = getMocArgs(options);
|
|
207
208
|
options.verbose && console.time(`build ${canisterName}`);
|
|
208
|
-
await execaCommand(`${mocPath} -c --idl canister.mo ${mocArgs} ${(await sources({ cwd: tempDir })).join(" ")}`, {
|
|
209
|
+
await execaCommand(`${mocPath} -c --idl canister.mo ${globalMocArgs.join(" ")} ${mocArgs} ${(await sources({ cwd: tempDir })).join(" ")}`, {
|
|
209
210
|
cwd: tempDir,
|
|
210
211
|
stdio: options.verbose ? "pipe" : ["pipe", "ignore", "pipe"],
|
|
211
212
|
});
|
package/dist/commands/build.js
CHANGED
|
@@ -6,7 +6,7 @@ import { join } from "node:path";
|
|
|
6
6
|
import { cliError } from "../error.js";
|
|
7
7
|
import { isCandidCompatible } from "../helpers/is-candid-compatible.js";
|
|
8
8
|
import { getWasmBindings } from "../wasm.js";
|
|
9
|
-
import { readConfig } from "../mops.js";
|
|
9
|
+
import { getGlobalMocArgs, readConfig } from "../mops.js";
|
|
10
10
|
import { sourcesArgs } from "./sources.js";
|
|
11
11
|
import { toolchain } from "./toolchain/index.js";
|
|
12
12
|
export const DEFAULT_BUILD_OUTPUT_DIR = ".mops/.build";
|
|
@@ -55,8 +55,8 @@ export async function build(canisterNames, options) {
|
|
|
55
55
|
"-o",
|
|
56
56
|
wasmPath,
|
|
57
57
|
motokoPath,
|
|
58
|
-
...(options.extraArgs ?? []),
|
|
59
58
|
...(await sourcesArgs()).flat(),
|
|
59
|
+
...getGlobalMocArgs(config),
|
|
60
60
|
];
|
|
61
61
|
if (config.build?.args) {
|
|
62
62
|
if (typeof config.build.args === "string") {
|
|
@@ -70,6 +70,7 @@ export async function build(canisterNames, options) {
|
|
|
70
70
|
}
|
|
71
71
|
args.push(...canister.args);
|
|
72
72
|
}
|
|
73
|
+
args.push(...(options.extraArgs ?? []));
|
|
73
74
|
const isPublicCandid = true; // always true for now to reduce corner cases
|
|
74
75
|
const candidVisibility = isPublicCandid ? "icp:public" : "icp:private";
|
|
75
76
|
if (isPublicCandid) {
|
package/dist/commands/check.js
CHANGED
|
@@ -2,6 +2,7 @@ import { relative } from "node:path";
|
|
|
2
2
|
import chalk from "chalk";
|
|
3
3
|
import { execa } from "execa";
|
|
4
4
|
import { cliError } from "../error.js";
|
|
5
|
+
import { getGlobalMocArgs, readConfig } from "../mops.js";
|
|
5
6
|
import { autofixMotoko } from "../helpers/autofix-motoko.js";
|
|
6
7
|
import { getMocSemVer } from "../helpers/get-moc-version.js";
|
|
7
8
|
import { sourcesArgs } from "./sources.js";
|
|
@@ -16,8 +17,10 @@ export async function check(files, options = {}) {
|
|
|
16
17
|
if (fileList.length === 0) {
|
|
17
18
|
cliError("No Motoko files specified for checking");
|
|
18
19
|
}
|
|
20
|
+
const config = readConfig();
|
|
19
21
|
const mocPath = await toolchain.bin("moc", { fallback: true });
|
|
20
22
|
const sources = await sourcesArgs();
|
|
23
|
+
const globalMocArgs = getGlobalMocArgs(config);
|
|
21
24
|
// --all-libs enables richer diagnostics with edit suggestions from moc (requires moc >= 1.3.0)
|
|
22
25
|
const allLibs = supportsAllLibsFlag();
|
|
23
26
|
if (!allLibs) {
|
|
@@ -30,6 +33,7 @@ export async function check(files, options = {}) {
|
|
|
30
33
|
"--check",
|
|
31
34
|
...(allLibs ? ["--all-libs"] : []),
|
|
32
35
|
...sources.flat(),
|
|
36
|
+
...globalMocArgs,
|
|
33
37
|
...(options.extraArgs ?? []),
|
|
34
38
|
];
|
|
35
39
|
if (options.fix) {
|
|
@@ -10,7 +10,7 @@ import chokidar from "chokidar";
|
|
|
10
10
|
import debounce from "debounce";
|
|
11
11
|
import { SemVer } from "semver";
|
|
12
12
|
import { sources } from "../sources.js";
|
|
13
|
-
import { getRootDir, readConfig } from "../../mops.js";
|
|
13
|
+
import { getGlobalMocArgs, getRootDir, readConfig } from "../../mops.js";
|
|
14
14
|
import { parallel } from "../../parallel.js";
|
|
15
15
|
import { MMF1 } from "./mmf1.js";
|
|
16
16
|
import { absToRel, pipeMMF, pipeStderrToMMF, pipeStdoutToMMF, } from "./utils.js";
|
|
@@ -152,6 +152,7 @@ export async function testWithReporter(reporterName, filter = "", defaultMode =
|
|
|
152
152
|
reporter.addFiles(files);
|
|
153
153
|
let config = readConfig();
|
|
154
154
|
let sourcesArr = await sources();
|
|
155
|
+
let globalMocArgs = getGlobalMocArgs(config);
|
|
155
156
|
if (!mocPath) {
|
|
156
157
|
mocPath = await toolchain.bin("moc", { fallback: true });
|
|
157
158
|
}
|
|
@@ -197,6 +198,7 @@ export async function testWithReporter(reporterName, filter = "", defaultMode =
|
|
|
197
198
|
"--hide-warnings",
|
|
198
199
|
"--error-detail=2",
|
|
199
200
|
...sourcesArr.join(" ").split(" "),
|
|
201
|
+
...globalMocArgs,
|
|
200
202
|
file,
|
|
201
203
|
].filter((x) => x);
|
|
202
204
|
// interpret
|
|
@@ -136,6 +136,9 @@ async function init({ reset = false, silent = false } = {}) {
|
|
|
136
136
|
}
|
|
137
137
|
}
|
|
138
138
|
async function download(tool, version, { silent = false, verbose = false } = {}) {
|
|
139
|
+
if (version.match(FILE_PATH_REGEX)) {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
139
142
|
let toolUtils = getToolUtils(tool);
|
|
140
143
|
let logUpdate = createLogUpdate(process.stdout, { showCursor: true });
|
|
141
144
|
silent || logUpdate("Installing", tool, version);
|
|
@@ -3,7 +3,7 @@ import { promisify } from "node:util";
|
|
|
3
3
|
import os from "node:os";
|
|
4
4
|
import chalk from "chalk";
|
|
5
5
|
import { getMocPath } from "../../helpers/get-moc-path.js";
|
|
6
|
-
import { getRootDir } from "../../mops.js";
|
|
6
|
+
import { getGlobalMocArgs, getRootDir, readConfig } from "../../mops.js";
|
|
7
7
|
import { sources } from "../sources.js";
|
|
8
8
|
import { parallel } from "../../parallel.js";
|
|
9
9
|
import { globMoFiles } from "./globMoFiles.js";
|
|
@@ -31,12 +31,18 @@ export class ErrorChecker {
|
|
|
31
31
|
let rootDir = getRootDir();
|
|
32
32
|
let mocPath = getMocPath();
|
|
33
33
|
let deps = await sources({ cwd: rootDir });
|
|
34
|
+
let globalMocArgs = getGlobalMocArgs(readConfig());
|
|
34
35
|
let paths = globMoFiles(rootDir);
|
|
35
36
|
this.totalFiles = paths.length;
|
|
36
37
|
this.processedFiles = 0;
|
|
37
38
|
await parallel(os.cpus().length, paths, async (file) => {
|
|
38
39
|
try {
|
|
39
|
-
await promisify(execFile)(mocPath, [
|
|
40
|
+
await promisify(execFile)(mocPath, [
|
|
41
|
+
"--check",
|
|
42
|
+
...deps.flatMap((x) => x.split(" ")),
|
|
43
|
+
...globalMocArgs,
|
|
44
|
+
file,
|
|
45
|
+
], { cwd: rootDir });
|
|
40
46
|
}
|
|
41
47
|
catch (error) {
|
|
42
48
|
error.message.split("\n").forEach((line) => {
|
|
@@ -3,7 +3,7 @@ import { promisify } from "node:util";
|
|
|
3
3
|
import os from "node:os";
|
|
4
4
|
import chalk from "chalk";
|
|
5
5
|
import { getMocPath } from "../../helpers/get-moc-path.js";
|
|
6
|
-
import { getRootDir } from "../../mops.js";
|
|
6
|
+
import { getGlobalMocArgs, getRootDir, readConfig } from "../../mops.js";
|
|
7
7
|
import { sources } from "../sources.js";
|
|
8
8
|
import { parallel } from "../../parallel.js";
|
|
9
9
|
import { globMoFiles } from "./globMoFiles.js";
|
|
@@ -51,6 +51,7 @@ export class WarningChecker {
|
|
|
51
51
|
let rootDir = getRootDir();
|
|
52
52
|
let mocPath = getMocPath();
|
|
53
53
|
let deps = await sources({ cwd: rootDir });
|
|
54
|
+
let globalMocArgs = getGlobalMocArgs(readConfig());
|
|
54
55
|
let paths = globMoFiles(rootDir);
|
|
55
56
|
this.totalFiles = paths.length;
|
|
56
57
|
this.processedFiles = 0;
|
|
@@ -58,7 +59,12 @@ export class WarningChecker {
|
|
|
58
59
|
let controller = new AbortController();
|
|
59
60
|
let { signal } = controller;
|
|
60
61
|
this.controllers.set(file, controller);
|
|
61
|
-
let { stderr } = await promisify(execFile)(mocPath, [
|
|
62
|
+
let { stderr } = await promisify(execFile)(mocPath, [
|
|
63
|
+
"--check",
|
|
64
|
+
...deps.flatMap((x) => x.split(" ")),
|
|
65
|
+
...globalMocArgs,
|
|
66
|
+
file,
|
|
67
|
+
], { cwd: rootDir, signal }).catch((error) => {
|
|
62
68
|
if (error.code === "ABORT_ERR") {
|
|
63
69
|
return { stderr: "" };
|
|
64
70
|
}
|
package/dist/error.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function cliError(...args: unknown[]):
|
|
1
|
+
export declare function cliError(...args: unknown[]): never;
|