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
|
@@ -16,75 +16,120 @@ export function parseDiagnostics(stdout) {
|
|
|
16
16
|
})
|
|
17
17
|
.filter((d) => d !== null);
|
|
18
18
|
}
|
|
19
|
-
function
|
|
20
|
-
const
|
|
19
|
+
function extractDiagnosticFixes(diagnostics) {
|
|
20
|
+
const result = new Map();
|
|
21
21
|
for (const diag of diagnostics) {
|
|
22
|
+
const editsByFile = new Map();
|
|
22
23
|
for (const span of diag.spans) {
|
|
23
24
|
if (span.suggestion_applicability === "MachineApplicable" &&
|
|
24
25
|
span.suggested_replacement !== null) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
character: span.column_end - 1,
|
|
37
|
-
},
|
|
26
|
+
const file = resolve(span.file);
|
|
27
|
+
const edits = editsByFile.get(file) ?? [];
|
|
28
|
+
edits.push({
|
|
29
|
+
range: {
|
|
30
|
+
start: {
|
|
31
|
+
line: span.line_start - 1,
|
|
32
|
+
character: span.column_start - 1,
|
|
33
|
+
},
|
|
34
|
+
end: {
|
|
35
|
+
line: span.line_end - 1,
|
|
36
|
+
character: span.column_end - 1,
|
|
38
37
|
},
|
|
39
|
-
newText: span.suggested_replacement,
|
|
40
38
|
},
|
|
39
|
+
newText: span.suggested_replacement,
|
|
41
40
|
});
|
|
41
|
+
editsByFile.set(file, edits);
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
|
+
for (const [file, edits] of editsByFile) {
|
|
45
|
+
const existing = result.get(file) ?? [];
|
|
46
|
+
existing.push({ code: diag.code, edits });
|
|
47
|
+
result.set(file, existing);
|
|
48
|
+
}
|
|
44
49
|
}
|
|
45
|
-
return
|
|
50
|
+
return result;
|
|
51
|
+
}
|
|
52
|
+
function normalizeRange(range) {
|
|
53
|
+
const { start, end } = range;
|
|
54
|
+
if (start.line > end.line ||
|
|
55
|
+
(start.line === end.line && start.character > end.character)) {
|
|
56
|
+
return { start: end, end: start };
|
|
57
|
+
}
|
|
58
|
+
return range;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Applies diagnostic fixes to a document, processing each diagnostic as
|
|
62
|
+
* an atomic unit. If any edit from a diagnostic overlaps with an already-accepted
|
|
63
|
+
* edit, the entire diagnostic is skipped (picked up in subsequent iterations).
|
|
64
|
+
* Based on vscode-languageserver-textdocument's TextDocument.applyEdits.
|
|
65
|
+
*/
|
|
66
|
+
function applyDiagnosticFixes(doc, fixes) {
|
|
67
|
+
const acceptedEdits = [];
|
|
68
|
+
const appliedCodes = [];
|
|
69
|
+
for (const fix of fixes) {
|
|
70
|
+
const offsets = fix.edits.map((e) => {
|
|
71
|
+
const range = normalizeRange(e.range);
|
|
72
|
+
return {
|
|
73
|
+
start: doc.offsetAt(range.start),
|
|
74
|
+
end: doc.offsetAt(range.end),
|
|
75
|
+
newText: e.newText,
|
|
76
|
+
};
|
|
77
|
+
});
|
|
78
|
+
const overlaps = offsets.some((o) => acceptedEdits.some((a) => o.start < a.end && o.end > a.start));
|
|
79
|
+
if (overlaps) {
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
acceptedEdits.push(...offsets);
|
|
83
|
+
appliedCodes.push(fix.code);
|
|
84
|
+
}
|
|
85
|
+
acceptedEdits.sort((a, b) => a.start - b.start);
|
|
86
|
+
const text = doc.getText();
|
|
87
|
+
const spans = [];
|
|
88
|
+
let lastOffset = 0;
|
|
89
|
+
for (const edit of acceptedEdits) {
|
|
90
|
+
if (edit.start < lastOffset) {
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
if (edit.start > lastOffset) {
|
|
94
|
+
spans.push(text.substring(lastOffset, edit.start));
|
|
95
|
+
}
|
|
96
|
+
if (edit.newText.length) {
|
|
97
|
+
spans.push(edit.newText);
|
|
98
|
+
}
|
|
99
|
+
lastOffset = edit.end;
|
|
100
|
+
}
|
|
101
|
+
spans.push(text.substring(lastOffset));
|
|
102
|
+
return { text: spans.join(""), appliedCodes };
|
|
46
103
|
}
|
|
47
104
|
const MAX_FIX_ITERATIONS = 10;
|
|
48
105
|
export async function autofixMotoko(mocPath, files, mocArgs) {
|
|
49
106
|
const fixedFilesCodes = new Map();
|
|
50
107
|
for (let iteration = 0; iteration < MAX_FIX_ITERATIONS; iteration++) {
|
|
51
|
-
const
|
|
108
|
+
const fixesByFile = new Map();
|
|
52
109
|
for (const file of files) {
|
|
53
|
-
const result = await execa(mocPath, [file, "--error-format=json"
|
|
110
|
+
const result = await execa(mocPath, [file, ...mocArgs, "--error-format=json"], { stdio: "pipe", reject: false });
|
|
54
111
|
const diagnostics = parseDiagnostics(result.stdout);
|
|
55
|
-
|
|
112
|
+
for (const [targetFile, fixes] of extractDiagnosticFixes(diagnostics)) {
|
|
113
|
+
const existing = fixesByFile.get(targetFile) ?? [];
|
|
114
|
+
existing.push(...fixes);
|
|
115
|
+
fixesByFile.set(targetFile, existing);
|
|
116
|
+
}
|
|
56
117
|
}
|
|
57
|
-
if (
|
|
118
|
+
if (fixesByFile.size === 0) {
|
|
58
119
|
break;
|
|
59
120
|
}
|
|
60
|
-
const fixesByFile = new Map();
|
|
61
|
-
for (const fix of allFixes) {
|
|
62
|
-
const normalizedPath = resolve(fix.file);
|
|
63
|
-
const existing = fixesByFile.get(normalizedPath) ?? [];
|
|
64
|
-
existing.push(fix);
|
|
65
|
-
fixesByFile.set(normalizedPath, existing);
|
|
66
|
-
}
|
|
67
121
|
let progress = false;
|
|
68
122
|
for (const [file, fixes] of fixesByFile) {
|
|
69
123
|
const original = await readFile(file, "utf-8");
|
|
70
124
|
const doc = TextDocument.create(`file://${file}`, "motoko", 0, original);
|
|
71
|
-
|
|
72
|
-
try {
|
|
73
|
-
result = TextDocument.applyEdits(doc, fixes.map((f) => f.edit));
|
|
74
|
-
}
|
|
75
|
-
catch (err) {
|
|
76
|
-
console.warn(`Warning: could not apply fixes to ${file}: ${err}`);
|
|
77
|
-
continue;
|
|
78
|
-
}
|
|
125
|
+
const { text: result, appliedCodes } = applyDiagnosticFixes(doc, fixes);
|
|
79
126
|
if (result === original) {
|
|
80
127
|
continue;
|
|
81
128
|
}
|
|
82
129
|
await writeFile(file, result, "utf-8");
|
|
83
130
|
progress = true;
|
|
84
131
|
const existing = fixedFilesCodes.get(file) ?? [];
|
|
85
|
-
|
|
86
|
-
existing.push(fix.code);
|
|
87
|
-
}
|
|
132
|
+
existing.push(...appliedCodes);
|
|
88
133
|
fixedFilesCodes.set(file, existing);
|
|
89
134
|
}
|
|
90
135
|
if (!progress) {
|
package/dist/mops.d.ts
CHANGED
|
@@ -23,6 +23,7 @@ export declare function getGithubCommit(repo: string, ref: string): Promise<any>
|
|
|
23
23
|
export declare function getDependencyType(version: string): "local" | "mops" | "github";
|
|
24
24
|
export declare function parseDepValue(name: string, value: string): Dependency;
|
|
25
25
|
export declare function readConfig(configFile?: string): Config;
|
|
26
|
+
export declare function getGlobalMocArgs(config: Config): string[];
|
|
26
27
|
export declare function writeConfig(config: Config, configFile?: string): void;
|
|
27
28
|
export declare function formatDir(name: string, version: string): string;
|
|
28
29
|
export declare function formatGithubDir(name: string, repo: string): string;
|
package/dist/mops.js
CHANGED
|
@@ -4,16 +4,13 @@ import fs from "node:fs";
|
|
|
4
4
|
import TOML from "@iarna/toml";
|
|
5
5
|
import chalk from "chalk";
|
|
6
6
|
import prompts from "prompts";
|
|
7
|
-
import fetch from "node-fetch";
|
|
8
7
|
import { decodeFile } from "./pem.js";
|
|
8
|
+
import { cliError } from "./error.js";
|
|
9
9
|
import { mainActor, storageActor } from "./api/actors.js";
|
|
10
10
|
import { getNetwork } from "./api/network.js";
|
|
11
11
|
import { getHighestVersion } from "./api/getHighestVersion.js";
|
|
12
12
|
import { getPackageId } from "./helpers/get-package-id.js";
|
|
13
13
|
import { FILE_PATH_REGEX } from "./constants.js";
|
|
14
|
-
if (!globalThis.fetch) {
|
|
15
|
-
globalThis.fetch = fetch;
|
|
16
|
-
}
|
|
17
14
|
// (!) make changes in pair with backend
|
|
18
15
|
export let apiVersion = "1.3";
|
|
19
16
|
export let globalConfigDir = "";
|
|
@@ -177,6 +174,15 @@ export function readConfig(configFile = getClosestConfigFile()) {
|
|
|
177
174
|
});
|
|
178
175
|
return config;
|
|
179
176
|
}
|
|
177
|
+
export function getGlobalMocArgs(config) {
|
|
178
|
+
if (!config.moc?.args) {
|
|
179
|
+
return [];
|
|
180
|
+
}
|
|
181
|
+
if (typeof config.moc.args === "string") {
|
|
182
|
+
cliError(`[moc] config 'args' should be an array of strings in mops.toml config file`);
|
|
183
|
+
}
|
|
184
|
+
return config.moc.args;
|
|
185
|
+
}
|
|
180
186
|
export function writeConfig(config, configFile = getClosestConfigFile()) {
|
|
181
187
|
let resConfig = JSON.parse(JSON.stringify(config));
|
|
182
188
|
let deps = resConfig.dependencies || {};
|
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ic-mops",
|
|
3
|
-
"version": "2.1
|
|
3
|
+
"version": "2.2.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"bin": {
|
|
6
6
|
"mops": "bin/mops.js",
|
|
@@ -48,29 +48,28 @@
|
|
|
48
48
|
"filesize": "10.1.6",
|
|
49
49
|
"fs-extra": "11.2.0",
|
|
50
50
|
"get-folder-size": "5.0.0",
|
|
51
|
-
"glob": "
|
|
51
|
+
"glob": "13.0.6",
|
|
52
52
|
"globby": "14.0.2",
|
|
53
53
|
"got": "14.4.6",
|
|
54
|
-
"jsdom": "
|
|
54
|
+
"jsdom": "28.1.0",
|
|
55
55
|
"log-update": "6.1.0",
|
|
56
56
|
"markdown-table": "3.0.4",
|
|
57
57
|
"mdast-util-from-markdown": "2.0.2",
|
|
58
58
|
"mdast-util-to-markdown": "2.1.2",
|
|
59
59
|
"minimatch": "10.0.1",
|
|
60
60
|
"ncp": "2.0.0",
|
|
61
|
-
"node-fetch": "3.3.2",
|
|
62
61
|
"octokit": "3.1.2",
|
|
63
62
|
"pem-file": "1.0.1",
|
|
64
63
|
"pic-ic": "0.5.4",
|
|
65
64
|
"pic-js-mops": "0.14.8",
|
|
66
65
|
"prettier": "3.5.3",
|
|
67
|
-
"prettier-plugin-motoko": "0.
|
|
66
|
+
"prettier-plugin-motoko": "0.12.5",
|
|
68
67
|
"promisify-child-process": "4.1.2",
|
|
69
68
|
"prompts": "2.4.2",
|
|
70
69
|
"semver": "7.7.1",
|
|
71
70
|
"stream-to-promise": "3.0.0",
|
|
72
71
|
"string-width": "7.2.0",
|
|
73
|
-
"tar": "7.5.
|
|
72
|
+
"tar": "7.5.9",
|
|
74
73
|
"terminal-size": "4.0.0",
|
|
75
74
|
"vscode-languageserver-textdocument": "1.0.12"
|
|
76
75
|
},
|
|
@@ -80,7 +79,7 @@
|
|
|
80
79
|
"@types/decompress": "4.2.7",
|
|
81
80
|
"@types/fs-extra": "11.0.4",
|
|
82
81
|
"@types/glob": "8.1.0",
|
|
83
|
-
"@types/jsdom": "
|
|
82
|
+
"@types/jsdom": "28.0.0",
|
|
84
83
|
"@types/ncp": "2.0.8",
|
|
85
84
|
"@types/node": "24.0.3",
|
|
86
85
|
"@types/prompts": "2.4.9",
|
|
@@ -52,6 +52,9 @@ describe("check --fix", () => {
|
|
|
52
52
|
M0237: 17,
|
|
53
53
|
});
|
|
54
54
|
});
|
|
55
|
+
test("overlapping edits", async () => {
|
|
56
|
+
await testCheckFix("overlapping.mo", { M0223: 1, M0236: 2 });
|
|
57
|
+
});
|
|
55
58
|
test("transitive imports", async () => {
|
|
56
59
|
const runMainPath = copyFixture("transitive-main.mo");
|
|
57
60
|
const runLibPath = copyFixture("transitive-lib.mo");
|
|
@@ -62,6 +65,19 @@ describe("check --fix", () => {
|
|
|
62
65
|
const afterResult = await cli(["check", runMainPath, "--", ...diagnosticFlags], { cwd: fixDir });
|
|
63
66
|
expect(countCodes(afterResult.stdout)).toEqual({});
|
|
64
67
|
});
|
|
68
|
+
test("--error-format=human does not break --fix", async () => {
|
|
69
|
+
const runFilePath = copyFixture("M0223.mo");
|
|
70
|
+
const fixResult = await cli([
|
|
71
|
+
"check",
|
|
72
|
+
runFilePath,
|
|
73
|
+
"--fix",
|
|
74
|
+
"--",
|
|
75
|
+
warningFlags,
|
|
76
|
+
"--error-format=human",
|
|
77
|
+
], { cwd: fixDir });
|
|
78
|
+
expect(fixResult.stdout).toContain("1 fix applied");
|
|
79
|
+
expect(readFileSync(runFilePath, "utf-8")).not.toContain("<Nat>");
|
|
80
|
+
});
|
|
65
81
|
test("verbose", async () => {
|
|
66
82
|
const result = await cli(["check", "Ok.mo", "--fix", "--verbose"], {
|
|
67
83
|
cwd: fixDir,
|
package/dist/tests/check.test.js
CHANGED
|
@@ -30,4 +30,8 @@ describe("check", () => {
|
|
|
30
30
|
expect(result.stderr).toMatch(/warning \[M0194\]/);
|
|
31
31
|
expect(result.stderr).toMatch(/unused identifier/);
|
|
32
32
|
});
|
|
33
|
+
test("[moc] args are passed to moc", async () => {
|
|
34
|
+
const cwd = path.join(import.meta.dirname, "check/moc-args");
|
|
35
|
+
await cliSnapshot(["check", "Warning.mo"], { cwd }, 1);
|
|
36
|
+
});
|
|
33
37
|
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { describe, expect, test } from "@jest/globals";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { cli } from "./helpers";
|
|
4
|
+
describe("moc-args", () => {
|
|
5
|
+
test("prints moc args from [moc] config", async () => {
|
|
6
|
+
const cwd = path.join(import.meta.dirname, "check/moc-args");
|
|
7
|
+
const result = await cli(["moc-args"], { cwd });
|
|
8
|
+
expect(result.exitCode).toBe(0);
|
|
9
|
+
expect(result.stdout).toBe("-Werror");
|
|
10
|
+
});
|
|
11
|
+
test("prints nothing when no [moc] config", async () => {
|
|
12
|
+
const cwd = path.join(import.meta.dirname, "check/success");
|
|
13
|
+
const result = await cli(["moc-args"], { cwd });
|
|
14
|
+
expect(result.exitCode).toBe(0);
|
|
15
|
+
expect(result.stdout).toBe("");
|
|
16
|
+
});
|
|
17
|
+
});
|
|
@@ -8,4 +8,15 @@ describe("toolchain", () => {
|
|
|
8
8
|
expect(result.exitCode).toBe(0);
|
|
9
9
|
expect(result.stdout.trim()).toBe("./mock");
|
|
10
10
|
});
|
|
11
|
+
test("file URI with subdirectory path", async () => {
|
|
12
|
+
const cwd = path.join(import.meta.dirname, "toolchain-local-subpath");
|
|
13
|
+
const result = await cli(["toolchain", "bin", "moc"], { cwd });
|
|
14
|
+
expect(result.exitCode).toBe(0);
|
|
15
|
+
expect(result.stdout.trim()).toBe("./bin/moc");
|
|
16
|
+
});
|
|
17
|
+
test("file URI does not trigger download during install", async () => {
|
|
18
|
+
const cwd = path.join(import.meta.dirname, "toolchain-local-subpath");
|
|
19
|
+
const result = await cli(["install"], { cwd });
|
|
20
|
+
expect(result.stderr).not.toContain("Invalid Version");
|
|
21
|
+
});
|
|
11
22
|
});
|
package/dist/types.d.ts
CHANGED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "wasm",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"collaborators": [
|
|
5
|
+
"Ryan Vandersmith <ryan.vandersmith@dfinity.org>"
|
|
6
|
+
],
|
|
7
|
+
"version": "0.1.0",
|
|
8
|
+
"files": [
|
|
9
|
+
"wasm_bg.wasm",
|
|
10
|
+
"wasm.js",
|
|
11
|
+
"wasm_bg.js",
|
|
12
|
+
"wasm.d.ts"
|
|
13
|
+
],
|
|
14
|
+
"main": "wasm.js",
|
|
15
|
+
"types": "wasm.d.ts",
|
|
16
|
+
"sideEffects": [
|
|
17
|
+
"./wasm.js",
|
|
18
|
+
"./snippets/*"
|
|
19
|
+
]
|
|
20
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
let wasm;
|
|
2
|
+
export function __wbg_set_wasm(val) {
|
|
3
|
+
wasm = val;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
let WASM_VECTOR_LEN = 0;
|
|
8
|
+
|
|
9
|
+
let cachedUint8ArrayMemory0 = null;
|
|
10
|
+
|
|
11
|
+
function getUint8ArrayMemory0() {
|
|
12
|
+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
13
|
+
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
14
|
+
}
|
|
15
|
+
return cachedUint8ArrayMemory0;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const cachedTextEncoder = new TextEncoder();
|
|
19
|
+
|
|
20
|
+
if (!('encodeInto' in cachedTextEncoder)) {
|
|
21
|
+
cachedTextEncoder.encodeInto = function (arg, view) {
|
|
22
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
23
|
+
view.set(buf);
|
|
24
|
+
return {
|
|
25
|
+
read: arg.length,
|
|
26
|
+
written: buf.length
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function passStringToWasm0(arg, malloc, realloc) {
|
|
32
|
+
|
|
33
|
+
if (realloc === undefined) {
|
|
34
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
35
|
+
const ptr = malloc(buf.length, 1) >>> 0;
|
|
36
|
+
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
|
|
37
|
+
WASM_VECTOR_LEN = buf.length;
|
|
38
|
+
return ptr;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
let len = arg.length;
|
|
42
|
+
let ptr = malloc(len, 1) >>> 0;
|
|
43
|
+
|
|
44
|
+
const mem = getUint8ArrayMemory0();
|
|
45
|
+
|
|
46
|
+
let offset = 0;
|
|
47
|
+
|
|
48
|
+
for (; offset < len; offset++) {
|
|
49
|
+
const code = arg.charCodeAt(offset);
|
|
50
|
+
if (code > 0x7F) break;
|
|
51
|
+
mem[ptr + offset] = code;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (offset !== len) {
|
|
55
|
+
if (offset !== 0) {
|
|
56
|
+
arg = arg.slice(offset);
|
|
57
|
+
}
|
|
58
|
+
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
|
59
|
+
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
|
60
|
+
const ret = cachedTextEncoder.encodeInto(arg, view);
|
|
61
|
+
|
|
62
|
+
offset += ret.written;
|
|
63
|
+
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
WASM_VECTOR_LEN = offset;
|
|
67
|
+
return ptr;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* @param {string} new_interface
|
|
71
|
+
* @param {string} original_interface
|
|
72
|
+
* @returns {boolean}
|
|
73
|
+
*/
|
|
74
|
+
export function is_candid_compatible(new_interface, original_interface) {
|
|
75
|
+
const ptr0 = passStringToWasm0(new_interface, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
76
|
+
const len0 = WASM_VECTOR_LEN;
|
|
77
|
+
const ptr1 = passStringToWasm0(original_interface, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
78
|
+
const len1 = WASM_VECTOR_LEN;
|
|
79
|
+
const ret = wasm.is_candid_compatible(ptr0, len0, ptr1, len1);
|
|
80
|
+
return ret !== 0;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function __wbindgen_init_externref_table() {
|
|
84
|
+
const table = wasm.__wbindgen_externrefs;
|
|
85
|
+
const offset = table.grow(4);
|
|
86
|
+
table.set(0, undefined);
|
|
87
|
+
table.set(offset + 0, undefined);
|
|
88
|
+
table.set(offset + 1, null);
|
|
89
|
+
table.set(offset + 2, true);
|
|
90
|
+
table.set(offset + 3, false);
|
|
91
|
+
;
|
|
92
|
+
};
|
|
93
|
+
|
|
Binary file
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
export const memory: WebAssembly.Memory;
|
|
4
|
+
export const is_candid_compatible: (a: number, b: number, c: number, d: number) => number;
|
|
5
|
+
export const __wbindgen_externrefs: WebAssembly.Table;
|
|
6
|
+
export const __wbindgen_malloc: (a: number, b: number) => number;
|
|
7
|
+
export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
8
|
+
export const __wbindgen_start: () => void;
|
|
Binary file
|
|
Binary file
|