ic-mops 0.31.0 → 0.31.2

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 (45) hide show
  1. package/dist/commands/bench/bench-canister.mo +5 -0
  2. package/dist/commands/bench.js +29 -16
  3. package/dist/declarations/bench/bench.did +1 -0
  4. package/dist/declarations/bench/bench.did.d.ts +1 -0
  5. package/dist/declarations/bench/bench.did.js +7 -6
  6. package/dist/package.json +1 -1
  7. package/dist/resolve-packages.js +1 -1
  8. package/dist/vessel.d.ts +2 -1
  9. package/dist/vessel.js +9 -7
  10. package/package.json +1 -1
  11. package/resolve-packages.ts +1 -1
  12. package/vessel.ts +10 -8
  13. package/dist/bench/$USER_BENCH_FILE.mo +0 -45
  14. package/dist/bench/bench-canister.mo +0 -57
  15. package/dist/commands/bench/$USER_BENCH_FILE.mo +0 -45
  16. package/dist/commands/bench/bench/$USER_BENCH_FILE.mo +0 -45
  17. package/dist/commands/bench/bench/bench-canister.mo +0 -57
  18. package/dist/commands/bench/declarations/bench/bench.did.d.ts +0 -6
  19. package/dist/commands/bench/declarations/bench/bench.did.js +0 -22
  20. package/dist/commands/bench/declarations/bench/index.d.ts +0 -2
  21. package/dist/commands/bench/declarations/bench/index.js +0 -30
  22. package/dist/commands/bench/declarations/main/index.d.ts +0 -2
  23. package/dist/commands/bench/declarations/main/index.js +0 -30
  24. package/dist/commands/bench/declarations/main/main.did.d.ts +0 -6
  25. package/dist/commands/bench/declarations/main/main.did.js +0 -242
  26. package/dist/commands/bench/declarations/storage/index.d.ts +0 -4
  27. package/dist/commands/bench/declarations/storage/index.js +0 -26
  28. package/dist/commands/bench/declarations/storage/storage.did.d.ts +0 -6
  29. package/dist/commands/bench/declarations/storage/storage.did.js +0 -34
  30. package/dist/commands/mmf1.d.ts +0 -21
  31. package/dist/commands/mmf1.js +0 -93
  32. package/dist/commands/test/reporter-files.d.ts +0 -10
  33. package/dist/commands/test/reporter-files.js +0 -48
  34. package/dist/commands/test/reporter-verbose.d.ts +0 -10
  35. package/dist/commands/test/reporter-verbose.js +0 -56
  36. package/dist/commands/test.d.ts +0 -4
  37. package/dist/commands/test.js +0 -186
  38. package/dist/integrity.d.ts +0 -4
  39. package/dist/integrity.js +0 -92
  40. package/dist/out/cli.d.ts +0 -2
  41. package/dist/out/cli.js +0 -114581
  42. package/dist/parse-changelog.d.ts +0 -1
  43. package/dist/parse-changelog.js +0 -1435
  44. package/dist/test.d.ts +0 -1
  45. package/dist/test.js +0 -1411
@@ -1,186 +0,0 @@
1
- import { spawn, execSync } from 'node:child_process';
2
- import path from 'node:path';
3
- import fs from 'node:fs';
4
- import os from 'node:os';
5
- import chalk from 'chalk';
6
- import { globSync } from 'glob';
7
- import chokidar from 'chokidar';
8
- import debounce from 'debounce';
9
- import { MMF1 } from './mmf1.js';
10
- import { sources } from './sources.js';
11
- import { getRootDir } from '../mops.js';
12
- import { parallel } from '../parallel.js';
13
- import { absToRel } from './test/utils.js';
14
- import { VerboseReporter } from './test/reporter-verbose.js';
15
- let ignore = [
16
- '**/node_modules/**',
17
- '**/.mops/**',
18
- '**/.vessel/**',
19
- '**/.git/**',
20
- ];
21
- let globConfig = {
22
- nocase: true,
23
- ignore: ignore,
24
- };
25
- export async function test(filter = '', { watch = false } = {}) {
26
- let rootDir = getRootDir();
27
- if (watch) {
28
- // todo: run only changed for *.test.mo?
29
- // todo: run all for *.mo?
30
- let run = debounce(async () => {
31
- console.clear();
32
- process.stdout.write('\x1Bc');
33
- await runAll(filter);
34
- console.log('-'.repeat(50));
35
- console.log('Waiting for file changes...');
36
- console.log(chalk.gray((`Press ${chalk.gray('Ctrl+C')} to exit.`)));
37
- }, 200);
38
- let watcher = chokidar.watch([
39
- path.join(rootDir, '**/*.mo'),
40
- path.join(rootDir, 'mops.toml'),
41
- ], {
42
- ignored: ignore,
43
- ignoreInitial: true,
44
- });
45
- watcher.on('all', () => {
46
- run();
47
- });
48
- run();
49
- }
50
- else {
51
- let passed = await runAll(filter);
52
- if (!passed) {
53
- process.exit(1);
54
- }
55
- }
56
- }
57
- let mocPath = process.env.DFX_MOC_PATH;
58
- export async function runAll(filter = '') {
59
- let reporter = new VerboseReporter;
60
- let rootDir = getRootDir();
61
- let files = [];
62
- let libFiles = globSync('**/test?(s)/lib.mo', globConfig);
63
- if (libFiles[0]) {
64
- files = [libFiles[0]];
65
- }
66
- else {
67
- let globStr = '**/test?(s)/**/*.test.mo';
68
- if (filter) {
69
- globStr = `**/test?(s)/**/*${filter}*.mo`;
70
- }
71
- files = globSync(path.join(rootDir, globStr), globConfig);
72
- }
73
- if (!files.length) {
74
- if (filter) {
75
- console.log(`No test files found for filter '${filter}'`);
76
- return;
77
- }
78
- console.log('No test files found');
79
- console.log('Put your tests in \'test\' directory in *.test.mo files');
80
- return;
81
- }
82
- reporter.addFiles(files);
83
- // console.log('Test files:');
84
- // for (let file of files) {
85
- // console.log(chalk.gray(`• ${absToRel(file)}`));
86
- // }
87
- // console.log('='.repeat(50));
88
- // let failed = 0;
89
- // let passed = 0;
90
- // let skipped = 0;
91
- let sourcesArr = await sources();
92
- if (!mocPath) {
93
- mocPath = execSync('dfx cache show').toString().trim() + '/moc';
94
- }
95
- let wasmDir = `${getRootDir()}/.mops/.test/`;
96
- fs.mkdirSync(wasmDir, { recursive: true });
97
- await parallel(os.cpus().length, files, async (file) => {
98
- let mmf = new MMF1('store');
99
- let wasiMode = fs.readFileSync(file, 'utf8').startsWith('// @testmode wasi');
100
- let promise = new Promise((resolve) => {
101
- if (!mocPath) {
102
- mocPath = 'moc';
103
- }
104
- let mocArgs = ['--hide-warnings', '--error-detail=2', ...sourcesArr.join(' ').split(' '), file].filter(x => x);
105
- // build and run wasm
106
- if (wasiMode) {
107
- let wasmFile = `${path.join(wasmDir, path.parse(file).name)}.wasm`;
108
- // build
109
- let buildProc = spawn(mocPath, [`-o=${wasmFile}`, '-wasi-system-api', ...mocArgs]);
110
- pipeMMF(buildProc, mmf).then(async () => {
111
- if (mmf.failed > 0) {
112
- return;
113
- }
114
- // run
115
- let proc = spawn('wasmtime', [wasmFile]);
116
- await pipeMMF(proc, mmf);
117
- }).finally(() => {
118
- fs.rmSync(wasmFile, { force: true });
119
- }).then(resolve);
120
- }
121
- // interpret
122
- else {
123
- let proc = spawn(mocPath, ['-r', '-ref-system-api', ...mocArgs]);
124
- pipeMMF(proc, mmf).then(resolve);
125
- }
126
- });
127
- reporter.addRun(file, mmf, promise, wasiMode);
128
- await promise;
129
- });
130
- fs.rmSync(wasmDir, { recursive: true, force: true });
131
- return reporter.done();
132
- }
133
- function pipeMMF(proc, mmf) {
134
- return new Promise((resolve) => {
135
- // stdout
136
- proc.stdout.on('data', (data) => {
137
- for (let line of data.toString().split('\n')) {
138
- line = line.trim();
139
- if (line) {
140
- mmf.parseLine(line);
141
- }
142
- }
143
- });
144
- // stderr
145
- proc.stderr.on('data', (data) => {
146
- let text = data.toString().trim();
147
- let failedLine = '';
148
- text = text.replace(/([\w+._/-]+):(\d+).(\d+)(-\d+.\d+)/g, (_m0, m1, m2, m3) => {
149
- // change absolute file path to relative
150
- // change :line:col-line:col to :line:col to work in vscode
151
- let res = `${absToRel(m1)}:${m2}:${m3}`;
152
- if (!fs.existsSync(m1)) {
153
- return res;
154
- }
155
- // show failed line
156
- let content = fs.readFileSync(m1);
157
- let lines = content.toString().split('\n') || [];
158
- failedLine += chalk.dim `\n ...`;
159
- let lineBefore = lines[+m2 - 2];
160
- if (lineBefore) {
161
- failedLine += chalk.dim `\n ${+m2 - 1}\t| ${lineBefore.replaceAll('\t', ' ')}`;
162
- }
163
- failedLine += `\n${chalk.redBright `->`} ${m2}\t| ${lines[+m2 - 1]?.replaceAll('\t', ' ')}`;
164
- if (lines.length > +m2) {
165
- failedLine += chalk.dim `\n ${+m2 + 1}\t| ${lines[+m2]?.replaceAll('\t', ' ')}`;
166
- }
167
- failedLine += chalk.dim `\n ...`;
168
- return res;
169
- });
170
- if (failedLine) {
171
- text += failedLine;
172
- }
173
- mmf.fail(text);
174
- });
175
- // exit
176
- proc.on('close', (code) => {
177
- if (code === 0) {
178
- mmf.pass();
179
- }
180
- else if (code !== 1) {
181
- mmf.fail(`unknown exit code: ${code}`);
182
- }
183
- resolve();
184
- });
185
- });
186
- }
@@ -1,4 +0,0 @@
1
- export declare function getFileHashesFromRegistry(packageIds: string[]): Promise<[string, [string, Uint8Array | number[]][]][]>;
2
- export declare function checkIntegrity(): Promise<void>;
3
- export declare function saveLockFile(): Promise<void>;
4
- export declare function checkLockFile(): Promise<void>;
package/dist/integrity.js DELETED
@@ -1,92 +0,0 @@
1
- import fs from 'node:fs';
2
- import path from 'node:path';
3
- import { sha256 } from '@noble/hashes/sha256';
4
- import { bytesToHex } from '@noble/hashes/utils';
5
- import { getDependencyType, getRootDir, mainActor } from './mops.js';
6
- import { resolvePackages } from './resolve-packages.js';
7
- export async function getFileHashesFromRegistry(packageIds) {
8
- let actor = await mainActor();
9
- let fileHashesByPackageIds = await actor.getFileHashesByPackageIds(packageIds);
10
- return fileHashesByPackageIds;
11
- }
12
- export async function checkIntegrity() {
13
- let rootDir = getRootDir();
14
- let resolvedPackages = await resolvePackages();
15
- let packageIds = Object.entries(resolvedPackages)
16
- .filter(([_, version]) => getDependencyType(version) === 'mops')
17
- .map(([name, version]) => `${name}@${version}`);
18
- let fileHashesFromRegistry = await getFileHashesFromRegistry(packageIds);
19
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
20
- for (let [_packageId, fileHashes] of fileHashesFromRegistry) {
21
- for (let [fileId, hash] of fileHashes) {
22
- let remoteHash = new Uint8Array(hash);
23
- let localData = fs.readFileSync(path.join(rootDir, '.mops', fileId));
24
- let localHash = await sha256(localData);
25
- if (bytesToHex(localHash) !== bytesToHex(remoteHash)) {
26
- console.error('Integrity check failed.');
27
- console.error(`Mismatched hash for ${fileId}: ${bytesToHex(localHash)} vs ${bytesToHex(remoteHash)}`);
28
- process.exit(1);
29
- }
30
- }
31
- }
32
- }
33
- export async function saveLockFile() {
34
- let rootDir = getRootDir();
35
- let resolvedPackages = await resolvePackages();
36
- let packageIds = Object.entries(resolvedPackages)
37
- .filter(([_, version]) => getDependencyType(version) === 'mops')
38
- .map(([name, version]) => `${name}@${version}`);
39
- let fileHashes = await getFileHashesFromRegistry(packageIds);
40
- let lockFileJson = {
41
- version: 1,
42
- hashes: fileHashes.reduce((acc, [packageId, fileHashes]) => {
43
- acc[packageId] = fileHashes.reduce((acc, [fileId, hash]) => {
44
- acc[fileId] = bytesToHex(new Uint8Array(hash));
45
- return acc;
46
- }, {});
47
- return acc;
48
- }, {}),
49
- };
50
- fs.writeFileSync(rootDir + '/mops-lock.json', JSON.stringify(lockFileJson, null, 2));
51
- }
52
- export async function checkLockFile() {
53
- let rootDir = getRootDir();
54
- let resolvedPackages = await resolvePackages();
55
- let packageIds = Object.entries(resolvedPackages)
56
- .filter(([_name, version]) => getDependencyType(version) === 'mops')
57
- .map(([name, version]) => `${name}@${version}`);
58
- let fileHashesFromRegistry = await getFileHashesFromRegistry(packageIds);
59
- let lockFileJson = JSON.parse(fs.readFileSync(rootDir + '/mops-lock.json').toString());
60
- if (lockFileJson.version !== 1) {
61
- console.error(`Invalid lock file version: ${lockFileJson.version}`);
62
- process.exit(1);
63
- }
64
- // if (lockFileJson.packageIds.length !== packageIds.length) {
65
- // console.error(`Mismatched packageIds: ${JSON.stringify(lockFileJson.packageIds)} vs ${JSON.stringify(packageIds)}`);
66
- // process.exit(1);
67
- // }
68
- // for (let i = 0; i < packageIds.length; i++) {
69
- // if (lockFileJson.packageIds[i] !== packageIds[i]) {
70
- // console.error(`Mismatched packageIds: ${JSON.stringify(lockFileJson.packageIds)} vs ${JSON.stringify(packageIds)}`);
71
- // process.exit(1);
72
- // }
73
- // }
74
- for (let [packageId, fileHashes] of fileHashesFromRegistry) {
75
- let hashes = lockFileJson.hashes[packageId];
76
- if (!hashes) {
77
- console.error(`Missing packageId ${packageId} in lock file`);
78
- process.exit(1);
79
- }
80
- for (let [fileId, hash] of fileHashes) {
81
- let lockFileHash = hashes[fileId];
82
- if (!lockFileHash) {
83
- console.error(`Missing fileId ${fileId} in lock file`);
84
- process.exit(1);
85
- }
86
- if (lockFileHash !== bytesToHex(new Uint8Array(hash))) {
87
- console.error(`Mismatched hash for ${fileId}: ${lockFileHash} vs ${bytesToHex(new Uint8Array(hash))}`);
88
- process.exit(1);
89
- }
90
- }
91
- }
92
- }
package/dist/out/cli.d.ts DELETED
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env node
2
- export {};