ic-mops 0.6.4 → 0.6.6

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/cli.js CHANGED
@@ -4,7 +4,6 @@ import fs from 'fs';
4
4
  import path from 'path';
5
5
  import {program} from 'commander';
6
6
  import chalk from 'chalk';
7
- import child_process from 'child_process';
8
7
 
9
8
  import {init} from './commands/init.js';
10
9
  import {publish} from './commands/publish.js';
@@ -16,6 +15,7 @@ import {installAll} from './commands/install-all.js';
16
15
  import {search} from './commands/search.js';
17
16
  import {add} from './commands/add.js';
18
17
  import {cacheSize, cleanCache} from './cache.js';
18
+ import {test} from './commands/test.js';
19
19
  // import {upgrade} from './commands/upgrade.js';
20
20
 
21
21
  let cwd = process.cwd();
@@ -151,6 +151,14 @@ program
151
151
  }
152
152
  });
153
153
 
154
+ // test
155
+ program
156
+ .command('test')
157
+ .description('Run tests')
158
+ .action(async () => {
159
+ await test();
160
+ });
161
+
154
162
  // // upgrade
155
163
  // program
156
164
  // .command('upgrade')
package/commands/add.js CHANGED
@@ -5,7 +5,7 @@ import {checkConfigFile, getHighestVersion, parseGithubURL, readConfig, writeCon
5
5
  import {installFromGithub} from '../vessel.js';
6
6
  import {install} from './install.js';
7
7
 
8
- export async function add(name, {verbose, silent} = {}) {
8
+ export async function add(name, {verbose} = {}) {
9
9
  if (!checkConfigFile()) {
10
10
  return false;
11
11
  }
@@ -16,7 +16,6 @@ export async function add(name, {verbose, silent} = {}) {
16
16
  }
17
17
 
18
18
  let pkgDetails;
19
- let existingPkg = config.dependencies[name];
20
19
 
21
20
  // local package
22
21
  if (name.startsWith('./') || name.startsWith('../') || name.startsWith('/')) {
@@ -36,11 +35,9 @@ export async function add(name, {verbose, silent} = {}) {
36
35
  repo: `https://github.com/${org}/${gitName}#${branch}`,
37
36
  version: '',
38
37
  };
39
-
40
- existingPkg = config.dependencies[pkgDetails.name];
41
38
  }
42
39
  // mops package
43
- else if (!existingPkg || !existingPkg.repo) {
40
+ else {
44
41
  let ver;
45
42
  if (name.includes('@')) {
46
43
  [name, ver] = name.split('@');
@@ -59,25 +56,12 @@ export async function add(name, {verbose, silent} = {}) {
59
56
  repo: '',
60
57
  version: ver,
61
58
  };
62
-
63
- }
64
- else {
65
- silent || logUpdate(`Installing ${existingPkg.name}@${existingPkg.version} (cache) from Github`);
66
- return;
67
59
  }
68
60
 
69
- if (pkgDetails.repo || pkgDetails.path) {
70
- // pkg name conflict with an installed mops pkg
71
- if (existingPkg && !existingPkg.repo) {
72
- console.log(chalk.red('Error: ') + `Conflicting Package Name '${pkgDetails.name}`);
73
- console.log('Consider entering the repo url and assigning a new name in the \'mops.toml\' file');
74
- return;
75
- }
76
- if (pkgDetails.repo) {
77
- await installFromGithub(pkgDetails.name, pkgDetails.repo, {verbose: verbose});
78
- }
61
+ if (pkgDetails.repo) {
62
+ await installFromGithub(pkgDetails.name, pkgDetails.repo, {verbose: verbose});
79
63
  }
80
- else {
64
+ else if (!pkgDetails.path) {
81
65
  let ok = await install(pkgDetails.name, pkgDetails.version, {verbose: verbose});
82
66
  if (!ok) {
83
67
  return;
@@ -112,10 +112,10 @@ export async function install(pkg, version = '', {verbose, silent, dep} = {}) {
112
112
  let config = readConfig(path.join(dir, 'mops.toml'));
113
113
  for (const {name, repo, version} of Object.values(config.dependencies || {})) {
114
114
  if (repo) {
115
- await installFromGithub(name, repo, {verbose});
115
+ await installFromGithub(name, repo, {silent, verbose});
116
116
  }
117
117
  else {
118
- let res = await install(name, version, {verbose});
118
+ let res = await install(name, version, {silent, verbose});
119
119
  if (!res) {
120
120
  ok = false;
121
121
  }
@@ -0,0 +1,61 @@
1
+ import {execSync} from 'child_process';
2
+ import chalk from 'chalk';
3
+ import glob from 'glob';
4
+
5
+ let globConfig = {
6
+ nocase: true,
7
+ ignore: [
8
+ '**/node_modules/**',
9
+ '**/.mops/**',
10
+ '**/.vessel/**',
11
+ ],
12
+ };
13
+
14
+ export async function test() {
15
+ let files = [];
16
+ let libFiles = glob.sync('**/test?(s)/lib.mo', globConfig);
17
+ if (libFiles.length) {
18
+ files = [libFiles[0]];
19
+ }
20
+ else {
21
+ files = glob.sync('**/test?(s)/**/*.test.mo', globConfig);
22
+ }
23
+ if (!files.length) {
24
+ console.log('No test files found');
25
+ return;
26
+ }
27
+
28
+ console.log('Test files:');
29
+ for (let file of files) {
30
+ console.log(chalk.gray(`• ${file}`));
31
+ }
32
+ console.log('-'.repeat(50));
33
+
34
+ let start = Date.now();
35
+ let failed = 0;
36
+ let passed = 0;
37
+ let dfxCache = execSync('dfx cache show').toString().trim();
38
+ let mopsSources = execSync('mops-local sources').toString().trim().replace(/\n/g, ' ');
39
+
40
+ for (let file of files) {
41
+ try {
42
+ console.log(`Running ${chalk.gray(file)}`);
43
+ execSync(`${dfxCache}/moc -r -wasi-system-api --hide-warnings --error-detail 2 ${mopsSources} ${file}`, {stdio: 'pipe'});
44
+ console.log(' ', chalk.green('PASS'));
45
+ passed++;
46
+ }
47
+ catch (err) {
48
+ failed++;
49
+ if (err.status === 1) {
50
+ console.log(' ', chalk.red('FAIL'), err.stderr.toString().trim());
51
+ }
52
+ else {
53
+ console.log(chalk.red('Unknown status:'), err.status);
54
+ console.log(err.message);
55
+ }
56
+ }
57
+ }
58
+
59
+ console.log('-'.repeat(50));
60
+ console.log(`Done in ${chalk.gray(((Date.now() - start) / 1000).toFixed(2) + 's')}, failed ${chalk[failed ? 'redBright' : 'gray'](failed)}, passed ${chalk.greenBright(passed)}`);
61
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ic-mops",
3
- "version": "0.6.4",
3
+ "version": "0.6.6",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "mops": "cli.js"
@@ -26,6 +26,7 @@
26
26
  "eslint": "^8.15.0",
27
27
  "execa": "^6.1.0",
28
28
  "get-folder-size": "^4.0.0",
29
+ "glob": "^8.1.0",
29
30
  "globby": "^13.1.1",
30
31
  "got": "^12.5.3",
31
32
  "log-update": "^5.0.1",