ic-mops 0.19.1 → 0.20.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.
Files changed (96) hide show
  1. package/.gitignore +3 -0
  2. package/{cache.js → cache.ts} +8 -8
  3. package/{cli.js → cli.ts} +5 -5
  4. package/commands/{add.js → add.ts} +16 -8
  5. package/commands/{bump.js → bump.ts} +5 -5
  6. package/commands/{docs.js → docs.ts} +10 -10
  7. package/commands/{import-identity.js → import-identity.ts} +7 -7
  8. package/commands/{init.js → init.ts} +20 -17
  9. package/commands/{install-all.js → install-all.ts} +1 -1
  10. package/commands/{install.js → install.ts} +11 -11
  11. package/commands/{mmf1.js → mmf1.ts} +20 -18
  12. package/commands/{publish.js → publish.ts} +28 -15
  13. package/commands/{remove.js → remove.ts} +23 -16
  14. package/commands/{search.js → search.ts} +2 -2
  15. package/commands/self-update.ts +6 -0
  16. package/commands/{sources.js → sources.ts} +30 -24
  17. package/commands/{template.js → template.ts} +2 -2
  18. package/commands/{test.js → test.ts} +24 -19
  19. package/commands/{user.js → user.ts} +7 -2
  20. package/declarations/main/index.js +0 -2
  21. package/declarations/main/main.did +4 -1
  22. package/declarations/main/main.did.d.ts +4 -4
  23. package/declarations/main/main.did.js +20 -20
  24. package/declarations/storage/index.d.ts +50 -0
  25. package/declarations/storage/index.js +3 -11
  26. package/dist/cache.d.ts +5 -0
  27. package/dist/cache.js +46 -0
  28. package/dist/cli.d.ts +2 -0
  29. package/dist/cli.js +265 -0
  30. package/dist/commands/add.d.ts +4 -0
  31. package/dist/commands/add.js +82 -0
  32. package/dist/commands/bump.d.ts +1 -0
  33. package/dist/commands/bump.js +50 -0
  34. package/dist/commands/docs.d.ts +3 -0
  35. package/dist/commands/docs.js +78 -0
  36. package/dist/commands/import-identity.d.ts +1 -0
  37. package/dist/commands/import-identity.js +47 -0
  38. package/dist/commands/init.d.ts +1 -0
  39. package/dist/commands/init.js +82 -0
  40. package/dist/commands/install-all.d.ts +4 -0
  41. package/dist/commands/install-all.js +29 -0
  42. package/dist/commands/install.d.ts +5 -0
  43. package/dist/commands/install.js +110 -0
  44. package/dist/commands/mmf1.d.ts +21 -0
  45. package/dist/commands/mmf1.js +93 -0
  46. package/dist/commands/publish.d.ts +3 -0
  47. package/dist/commands/publish.js +254 -0
  48. package/dist/commands/remove.d.ts +5 -0
  49. package/dist/commands/remove.js +83 -0
  50. package/dist/commands/search.d.ts +1 -0
  51. package/dist/commands/search.js +36 -0
  52. package/dist/commands/self-update.d.ts +3 -0
  53. package/dist/commands/self-update.js +5 -0
  54. package/dist/commands/sources.d.ts +3 -0
  55. package/dist/commands/sources.js +124 -0
  56. package/dist/commands/template.d.ts +1 -0
  57. package/dist/commands/template.js +28 -0
  58. package/dist/commands/test.d.ts +4 -0
  59. package/dist/commands/test.js +201 -0
  60. package/dist/commands/user.d.ts +2 -0
  61. package/dist/commands/user.js +23 -0
  62. package/dist/commands/whoami.d.ts +1 -0
  63. package/dist/commands/whoami.js +11 -0
  64. package/dist/declarations/main/index.d.ts +50 -0
  65. package/dist/declarations/main/index.js +41 -0
  66. package/dist/declarations/main/main.did +222 -0
  67. package/dist/declarations/main/main.did.d.ts +198 -0
  68. package/dist/declarations/main/main.did.js +218 -0
  69. package/dist/declarations/storage/index.d.ts +50 -0
  70. package/dist/declarations/storage/index.js +30 -0
  71. package/dist/declarations/storage/storage.did +46 -0
  72. package/dist/declarations/storage/storage.did.d.ts +37 -0
  73. package/dist/declarations/storage/storage.did.js +38 -0
  74. package/dist/mops.d.ts +33 -0
  75. package/dist/mops.js +259 -0
  76. package/dist/package.json +79 -0
  77. package/dist/parallel.d.ts +1 -0
  78. package/dist/parallel.js +24 -0
  79. package/dist/pem.d.ts +5 -0
  80. package/dist/pem.js +49 -0
  81. package/dist/templates/mops-test.yml +30 -0
  82. package/dist/types.d.ts +27 -0
  83. package/dist/types.js +1 -0
  84. package/dist/vessel.d.ts +19 -0
  85. package/dist/vessel.js +154 -0
  86. package/global.d.ts +2 -0
  87. package/{mops.js → mops.ts} +56 -45
  88. package/package.json +44 -19
  89. package/{parallel.js → parallel.ts} +2 -2
  90. package/{pem.js → pem.ts} +12 -11
  91. package/templates/mops-test.yml +1 -1
  92. package/tsconfig.json +16 -0
  93. package/types.ts +29 -0
  94. package/{vessel.js → vessel.ts} +37 -25
  95. package/commands/self-update.js +0 -6
  96. /package/commands/{whoami.js → whoami.ts} +0 -0
package/.gitignore CHANGED
@@ -1,2 +1,5 @@
1
+ node_modules
2
+ dist
3
+ cli.js
1
4
  identity.pem
2
5
  network.txt
@@ -1,34 +1,34 @@
1
- import fs from 'fs';
2
- import path from 'path';
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
3
  import ncp from 'ncp';
4
4
  import getFolderSize from 'get-folder-size';
5
5
 
6
6
  import {globalCacheDir} from './mops.js';
7
7
 
8
- export let isCached = (pkgId) => {
8
+ export let isCached = (pkgId: string) => {
9
9
  let dir = path.join(globalCacheDir, 'packages', pkgId);
10
10
  return fs.existsSync(dir);
11
11
  };
12
12
 
13
- export let addCache = (pkgId, source) => {
13
+ export let addCache = (pkgId: string, source: string) => {
14
14
  let dest = path.join(globalCacheDir, 'packages', pkgId);
15
15
  fs.mkdirSync(dest, {recursive: true});
16
16
 
17
- return new Promise((resolve, reject) => {
17
+ return new Promise<void>((resolve, reject) => {
18
18
  ncp.ncp(source, dest, {stopOnErr: true}, (err) => {
19
19
  if (err) {
20
- reject(err[0]);
20
+ reject(err);
21
21
  }
22
22
  resolve();
23
23
  });
24
24
  });
25
25
  };
26
26
 
27
- export let copyCache = (pkgId, dest) => {
27
+ export let copyCache = (pkgId: string, dest: string) => {
28
28
  let source = path.join(globalCacheDir, 'packages', pkgId);
29
29
  fs.mkdirSync(dest, {recursive: true});
30
30
 
31
- return new Promise((resolve, reject) => {
31
+ return new Promise<void>((resolve, reject) => {
32
32
  ncp.ncp(source, dest, {stopOnErr: true}, (err) => {
33
33
  if (err) {
34
34
  reject(err);
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import fs from 'fs';
3
+ import fs from 'node:fs';
4
4
  import {program} from 'commander';
5
5
  import chalk from 'chalk';
6
6
  import {Principal} from '@dfinity/principal';
@@ -26,14 +26,14 @@ import {bump} from './commands/bump.js';
26
26
  program.name('mops');
27
27
 
28
28
  // --version
29
- let packageJson = JSON.parse(fs.readFileSync(new URL('package.json', import.meta.url)));
29
+ let packageJson = JSON.parse(fs.readFileSync(new URL('package.json', import.meta.url)).toString());
30
30
  program.version(`CLI ${packageJson.version}\nAPI ${apiVersion}`, '-v --version');
31
31
 
32
32
  // init
33
33
  program
34
34
  .command('init [name]')
35
35
  .description('Create mops.toml')
36
- .action(async (name) => {
36
+ .action(async (name: string) => {
37
37
  await init(name);
38
38
  });
39
39
 
@@ -195,11 +195,11 @@ program
195
195
  program
196
196
  .command('template')
197
197
  .description('Apply template')
198
- .action(async (options) => {
198
+ .action(async () => {
199
199
  if (!checkConfigFile()) {
200
200
  process.exit(1);
201
201
  }
202
- await template(options);
202
+ await template();
203
203
  });
204
204
 
205
205
  // docs
@@ -1,13 +1,13 @@
1
- import path from 'path';
1
+ import path from 'node:path';
2
2
  import chalk from 'chalk';
3
3
  import logUpdate from 'log-update';
4
4
  import {checkConfigFile, getHighestVersion, parseGithubURL, readConfig, writeConfig} from '../mops.js';
5
5
  import {installFromGithub} from '../vessel.js';
6
6
  import {install} from './install.js';
7
7
 
8
- export async function add(name, {verbose, dev} = {}) {
8
+ export async function add(name: string, {verbose = false, dev = false} = {}) {
9
9
  if (!checkConfigFile()) {
10
- return false;
10
+ return;
11
11
  }
12
12
 
13
13
  let config = readConfig();
@@ -22,7 +22,7 @@ export async function add(name, {verbose, dev} = {}) {
22
22
  }
23
23
  }
24
24
 
25
- let pkgDetails;
25
+ let pkgDetails: any;
26
26
 
27
27
  // local package
28
28
  if (name.startsWith('./') || name.startsWith('../') || name.startsWith('/')) {
@@ -34,7 +34,7 @@ export async function add(name, {verbose, dev} = {}) {
34
34
  };
35
35
  }
36
36
  // github package
37
- else if (name.startsWith('https://github.com') || name.split('/') > 1) {
37
+ else if (name.startsWith('https://github.com') || name.split('/').length > 1) {
38
38
  const {org, gitName, branch} = parseGithubURL(name);
39
39
 
40
40
  pkgDetails = {
@@ -45,13 +45,14 @@ export async function add(name, {verbose, dev} = {}) {
45
45
  }
46
46
  // mops package
47
47
  else {
48
- let ver;
48
+ let ver: string;
49
49
  if (name.includes('@')) {
50
+ // @ts-ignore
50
51
  [name, ver] = name.split('@');
51
52
  }
52
53
  else {
53
54
  let versionRes = await getHighestVersion(name);
54
- if (versionRes.err) {
55
+ if ('err' in versionRes) {
55
56
  console.log(chalk.red('Error: ') + versionRes.err);
56
57
  return;
57
58
  }
@@ -75,7 +76,14 @@ export async function add(name, {verbose, dev} = {}) {
75
76
  }
76
77
  }
77
78
 
78
- config[dev ? 'dev-dependencies' : 'dependencies'][pkgDetails.name] = pkgDetails;
79
+ const depsProp = dev ? 'dev-dependencies' : 'dependencies';
80
+ let deps = config[depsProp];
81
+ if (deps) {
82
+ deps[pkgDetails.name] = pkgDetails;
83
+ }
84
+ else {
85
+ throw Error(`Invalid config file: [${depsProp}] not found`);
86
+ }
79
87
  writeConfig(config);
80
88
 
81
89
  logUpdate.clear();
@@ -2,7 +2,7 @@ import prompts from 'prompts';
2
2
  import chalk from 'chalk';
3
3
  import {checkConfigFile, readConfig, writeConfig} from '../mops.js';
4
4
 
5
- export async function bump(part) {
5
+ export async function bump(part: string) {
6
6
  if (!checkConfigFile()) {
7
7
  return;
8
8
  }
@@ -44,15 +44,15 @@ export async function bump(part) {
44
44
  console.log(`Updated version: ${chalk.green.bold(config.package.version)}`);
45
45
  }
46
46
 
47
- function updateVersion(version, part) {
47
+ function updateVersion(version: string, part: string) {
48
48
  let parts = version.split('.');
49
49
  let idx = ['major', 'minor', 'patch'].indexOf(part);
50
- if (idx < 0) {
50
+ if (!parts[idx]) {
51
51
  throw new Error(`Invalid version part: ${part}`);
52
52
  }
53
- parts[idx] = parseInt(parts[idx]) + 1;
53
+ parts[idx] = String(parseInt(parts[idx] || '0') + 1);
54
54
  for (let i = idx + 1; i < parts.length; i++) {
55
- parts[i] = 0;
55
+ parts[i] = '0';
56
56
  }
57
57
  return parts.join('.');
58
58
  }
@@ -1,22 +1,22 @@
1
- import {spawn, execSync} from 'child_process';
2
- import fs from 'fs';
3
- import path from 'path';
1
+ import {spawn, execSync} from 'node:child_process';
2
+ import fs from 'node:fs';
3
+ import path from 'node:path';
4
4
  import chalk from 'chalk';
5
- import glob from 'glob';
6
- import del from 'del';
5
+ import {globSync} from 'glob';
6
+ import {deleteSync} from 'del';
7
7
  import tar from 'tar';
8
8
  import streamToPromise from 'stream-to-promise';
9
9
 
10
10
  import {getRootDir} from '../mops.js';
11
11
 
12
- let moDoc;
12
+ let moDoc: string;
13
13
 
14
- export async function docs({silent} = {}) {
14
+ export async function docs({silent = false} = {}) {
15
15
  let rootDir = getRootDir();
16
16
  let docsDir = path.join(rootDir, '.mops/.docs');
17
17
  let docsDirRelative = path.relative(process.cwd(), docsDir);
18
18
 
19
- del.sync([docsDir], {force: true});
19
+ deleteSync([docsDir], {force: true});
20
20
 
21
21
  // detect mocv
22
22
  if (process.env.DFX_MOC_PATH && process.env.DFX_MOC_PATH.includes('mocv/versions')) {
@@ -27,7 +27,7 @@ export async function docs({silent} = {}) {
27
27
  }
28
28
 
29
29
  // generate docs
30
- await new Promise((resolve) => {
30
+ await new Promise<void>((resolve) => {
31
31
  let proc = spawn(moDoc, [`--source=${path.join(rootDir, 'src')}`, `--output=${docsDirRelative}`, '--format=adoc']);
32
32
 
33
33
  // stdout
@@ -75,7 +75,7 @@ export async function docs({silent} = {}) {
75
75
  `${docsDir}/**/*.test.adoc`,
76
76
  `${docsDir}/test/**/*`,
77
77
  ];
78
- let files = glob.sync(`${docsDir}/**/*.adoc`, {ignore}).map(f => path.relative(docsDir, f));
78
+ let files = globSync(`${docsDir}/**/*.adoc`, {ignore}).map(f => path.relative(docsDir, f));
79
79
  if (files.length) {
80
80
  let stream = tar.create(
81
81
  {
@@ -1,12 +1,12 @@
1
- import fs from 'fs';
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
2
3
  import chalk from 'chalk';
3
- import path from 'path';
4
4
  import prompts from 'prompts';
5
- import del from 'del';
5
+ import {deleteSync} from 'del';
6
6
  import {globalConfigDir} from '../mops.js';
7
7
  import {encrypt} from '../pem.js';
8
8
 
9
- export async function importPem(data) {
9
+ export async function importPem(data: string) {
10
10
  try {
11
11
  if (!fs.existsSync(globalConfigDir)) {
12
12
  fs.mkdirSync(globalConfigDir);
@@ -34,12 +34,12 @@ export async function importPem(data) {
34
34
  let identityPem = path.resolve(globalConfigDir, 'identity.pem');
35
35
  let identityPemEncrypted = path.resolve(globalConfigDir, 'identity.pem.encrypted');
36
36
 
37
- del.sync([identityPem, identityPemEncrypted], {force: true});
37
+ deleteSync([identityPem, identityPemEncrypted], {force: true});
38
38
 
39
39
  // encrypted
40
40
  if (password) {
41
- data = await encrypt(Buffer.from(data), password);
42
- fs.writeFileSync(identityPemEncrypted, data);
41
+ let encrypted = await encrypt(Buffer.from(data), password);
42
+ fs.writeFileSync(identityPemEncrypted, encrypted);
43
43
  }
44
44
  // unencrypted
45
45
  else {
@@ -1,10 +1,11 @@
1
+ import {execSync} from 'node:child_process';
2
+ import path from 'node:path';
3
+ import fs from 'node:fs';
1
4
  import chalk from 'chalk';
2
- import path from 'path';
3
- import fs from 'fs';
4
5
  import {checkApiCompatibility, mainActor, readDfxJson, writeConfig} from '../mops.js';
5
6
  import {installAll} from './install-all.js';
6
- import {readVesselConfig} from '../vessel.js';
7
- import {execSync} from 'child_process';
7
+ import {VesselConfig, readVesselConfig} from '../vessel.js';
8
+ import {Config, Dependencies} from '../types.js';
8
9
 
9
10
  export async function init(name = '') {
10
11
  let configFile = path.join(process.cwd(), 'mops.toml');
@@ -16,23 +17,25 @@ export async function init(name = '') {
16
17
 
17
18
  console.log('Initializing...');
18
19
 
19
- let config = {};
20
- let vesselConfig = {};
21
- let vesselDeps;
20
+ let config: Config = {};
21
+ let vesselConfig: VesselConfig = {dependencies: [], 'dev-dependencies': []};
22
+ let deps: Dependencies = {};
22
23
 
23
24
  const vesselFile = path.join(process.cwd(), 'vessel.dhall');
24
25
 
25
26
  if (fs.existsSync(vesselFile)) {
26
27
  console.log('Reading vessel.dhall file');
27
28
  const res = await readVesselConfig(process.cwd(), {cache: false});
28
- vesselConfig = {...res};
29
+ if (res) {
30
+ vesselConfig = {...res};
31
+ }
29
32
  }
30
33
 
31
34
  if (vesselConfig.dependencies) {
32
- vesselDeps = {};
35
+ deps = {};
33
36
 
34
37
  for (const dep of (vesselConfig.dependencies || [])) {
35
- vesselDeps[dep.name] = dep;
38
+ deps[dep.name] = dep;
36
39
  }
37
40
  }
38
41
 
@@ -45,8 +48,8 @@ export async function init(name = '') {
45
48
  repository: '',
46
49
  };
47
50
 
48
- if (vesselDeps) {
49
- config.dependencies = vesselDeps;
51
+ if (deps) {
52
+ config.dependencies = deps;
50
53
  }
51
54
 
52
55
  writeConfig(config, configFile);
@@ -83,13 +86,13 @@ export async function init(name = '') {
83
86
  config.dependencies = {};
84
87
  }
85
88
 
86
- if (vesselDeps) {
87
- config.dependencies = vesselDeps;
89
+ if (deps) {
90
+ config.dependencies = deps;
88
91
  }
89
92
 
90
- defaultPackages.forEach(([name, version]) => {
91
- config.dependencies[name] = {version};
92
- });
93
+ for (let [name, version] of defaultPackages) {
94
+ config.dependencies[name] = {name, version};
95
+ }
93
96
 
94
97
  writeConfig(config, configFile);
95
98
 
@@ -4,7 +4,7 @@ import {checkConfigFile, readConfig} from '../mops.js';
4
4
  import {install} from './install.js';
5
5
  import {installFromGithub} from '../vessel.js';
6
6
 
7
- export async function installAll({verbose, silent} = {}) {
7
+ export async function installAll({verbose = false, silent = false} = {}) {
8
8
  if (!checkConfigFile()) {
9
9
  return;
10
10
  }
@@ -1,13 +1,13 @@
1
- import path from 'path';
2
- import fs from 'fs';
1
+ import path from 'node:path';
2
+ import fs from 'node:fs';
3
3
  import logUpdate from 'log-update';
4
+ import chalk from 'chalk';
4
5
  import {checkConfigFile, formatDir, getHighestVersion, mainActor, progressBar, readConfig, storageActor} from '../mops.js';
5
6
  import {parallel} from '../parallel.js';
6
- import chalk from 'chalk';
7
7
  import {installFromGithub} from '../vessel.js';
8
8
  import {addCache, copyCache, isCached} from '../cache.js';
9
9
 
10
- export async function install(pkg, version = '', {verbose, silent, dep} = {}) {
10
+ export async function install(pkg: string, version = '', {verbose = false, silent = false, dep = false} = {}) {
11
11
  if (!checkConfigFile()) {
12
12
  return false;
13
13
  }
@@ -23,7 +23,7 @@ export async function install(pkg, version = '', {verbose, silent, dep} = {}) {
23
23
 
24
24
  if (!version) {
25
25
  let versionRes = await getHighestVersion(pkg);
26
- if (versionRes.err) {
26
+ if ('err' in versionRes) {
27
27
  console.log(chalk.red('Error: ') + versionRes.err);
28
28
  return false;
29
29
  }
@@ -50,13 +50,13 @@ export async function install(pkg, version = '', {verbose, silent, dep} = {}) {
50
50
  actor.getFileIds(pkg, version),
51
51
  ]);
52
52
 
53
- if (packageDetailsRes.err) {
53
+ if ('err' in packageDetailsRes) {
54
54
  console.log(chalk.red('Error: ') + packageDetailsRes.err);
55
55
  return false;
56
56
  }
57
57
  let packageDetails = packageDetailsRes.ok;
58
58
 
59
- if (filesIdsRes.err) {
59
+ if ('err' in filesIdsRes) {
60
60
  console.log(chalk.red('Error: ') + filesIdsRes.err);
61
61
  return false;
62
62
  }
@@ -69,18 +69,18 @@ export async function install(pkg, version = '', {verbose, silent, dep} = {}) {
69
69
 
70
70
  // download files
71
71
  let filesData = new Map;
72
- await parallel(16, filesIds, async (fileId) => {
72
+ await parallel(16, filesIds, async (fileId: string) => {
73
73
  let fileMetaRes = await storage.getFileMeta(fileId);
74
- if (fileMetaRes.err) {
74
+ if ('err' in fileMetaRes) {
75
75
  console.log(chalk.red('ERR: ') + fileMetaRes.err);
76
76
  return;
77
77
  }
78
78
  let fileMeta = fileMetaRes.ok;
79
79
 
80
80
  let buffer = Buffer.from([]);
81
- for (let i = 0; i < fileMeta.chunkCount; i++) {
81
+ for (let i = 0n; i < fileMeta.chunkCount; i++) {
82
82
  let chunkRes = await storage.downloadChunk(fileId, i);
83
- if (chunkRes.err) {
83
+ if ('err' in chunkRes) {
84
84
  console.log(chalk.red('ERR: ') + chunkRes.err);
85
85
  return;
86
86
  }
@@ -4,20 +4,22 @@
4
4
  // mops:1:skip
5
5
  import chalk from 'chalk';
6
6
 
7
+ type Strategy = 'store' | 'print';
8
+
7
9
  export class MMF1 {
8
- stack = [];
9
- currSuite = '';
10
+ stack: string[] = [];
11
+ currSuite: string = '';
10
12
  failed = 0;
11
13
  passed = 0;
12
14
  skipped = 0;
13
- srategy; // 'store' | 'print'
14
- output = [];
15
+ srategy: Strategy;
16
+ output: string[] = [];
15
17
 
16
- constructor(srategy) {
18
+ constructor(srategy: Strategy) {
17
19
  this.srategy = srategy;
18
20
  }
19
21
 
20
- _log(...args) {
22
+ _log(...args: string[]) {
21
23
  if (this.srategy === 'store') {
22
24
  this.output.push(args.join(' '));
23
25
  }
@@ -30,27 +32,27 @@ export class MMF1 {
30
32
  for (let out of this.output) {
31
33
  console.log(out);
32
34
  }
33
- this.store = [];
35
+ this.output = [];
34
36
  }
35
37
 
36
- parseLine(line) {
38
+ parseLine(line: string) {
37
39
  if (line.startsWith('mops:1:start ')) {
38
- this._testStart(line.split('mops:1:start ')[1]);
40
+ this._testStart(line.split('mops:1:start ')[1] || '');
39
41
  }
40
42
  else if (line.startsWith('mops:1:end ')) {
41
- this._testEnd(line.split('mops:1:end ')[1]);
43
+ this._testEnd(line.split('mops:1:end ')[1] || '');
42
44
  }
43
45
  else if (line.startsWith('mops:1:skip ')) {
44
- this._testSkip(line.split('mops:1:skip ')[1]);
46
+ this._testSkip(line.split('mops:1:skip ')[1] || '');
45
47
  }
46
48
  else {
47
49
  this._log(' '.repeat(this.stack.length * 2), chalk.gray('stdout'), line);
48
50
  }
49
51
  }
50
52
 
51
- _testStart(name) {
52
- if (this.stack.length) {
53
- let suite = this.stack[this.stack.length - 1];
53
+ _testStart(name: string) {
54
+ let suite = this.stack[this.stack.length - 1];
55
+ if (suite) {
54
56
  if (this.currSuite !== suite) {
55
57
  this.currSuite = suite;
56
58
  this._log(' '.repeat((this.stack.length - 1) * 2), (chalk.gray('•')) + '', suite);
@@ -59,18 +61,18 @@ export class MMF1 {
59
61
  this.stack.push(name);
60
62
  }
61
63
 
62
- _testEnd(name) {
64
+ _testEnd(name: string) {
63
65
  if (name !== this.stack.pop()) {
64
66
  throw 'mmf1._testEnd: start and end test mismatch';
65
67
  }
66
68
  this._status(name, 'pass');
67
69
  }
68
70
 
69
- _testSkip(name) {
71
+ _testSkip(name: string) {
70
72
  this._status(name, 'skip');
71
73
  }
72
74
 
73
- _status(name, status) {
75
+ _status(name: string, status: string) {
74
76
  if (status === 'pass') {
75
77
  // do not print suite at the end
76
78
  if (name === this.currSuite) {
@@ -89,7 +91,7 @@ export class MMF1 {
89
91
  }
90
92
  }
91
93
 
92
- fail(stderr) {
94
+ fail(stderr: string) {
93
95
  let name = this.stack.pop() || '';
94
96
  this._status(name, 'fail');
95
97
  this._log(' '.repeat(this.stack.length * 2), chalk.red('FAIL'), stderr);
@@ -1,15 +1,17 @@
1
- import fs from 'fs';
2
- import path from 'path';
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
3
  import chalk from 'chalk';
4
4
  import logUpdate from 'log-update';
5
5
  import {globbySync} from 'globby';
6
- import minimatch from 'minimatch';
6
+ import {minimatch} from 'minimatch';
7
7
  import prompts from 'prompts';
8
8
  import {checkConfigFile, getRootDir, mainActor, progressBar, readConfig} from '../mops.js';
9
9
  import {parallel} from '../parallel.js';
10
10
  import {docs} from './docs.js';
11
+ import {DependencyV2, PackageConfigV2} from '../declarations/main/main.did.js';
12
+ import {Dependency} from '../types.js';
11
13
 
12
- export async function publish({noDocs} = {}) {
14
+ export async function publish({noDocs = false} = {}) {
13
15
  if (!checkConfigFile()) {
14
16
  return;
15
17
  }
@@ -31,6 +33,7 @@ export async function publish({noDocs} = {}) {
31
33
  return;
32
34
  }
33
35
  for (let key of ['name', 'version']) {
36
+ // @ts-ignore
34
37
  if (!config.package[key]) {
35
38
  console.log(chalk.red('Error: ') + `Please specify "${key}" in [config] section in your mops.toml`);
36
39
  return;
@@ -39,6 +42,7 @@ export async function publish({noDocs} = {}) {
39
42
 
40
43
  // desired fields
41
44
  for (let key of ['description', 'repository']) {
45
+ // @ts-ignore
42
46
  if (!config.package[key]) {
43
47
  let res = await prompts({
44
48
  type: 'confirm',
@@ -93,6 +97,7 @@ export async function publish({noDocs} = {}) {
93
97
  };
94
98
 
95
99
  for (let [key, max] of Object.entries(keysMax)) {
100
+ // @ts-ignore
96
101
  if (config.package[key] && config.package[key].length > max) {
97
102
  console.log(chalk.red('Error: ') + `package.${key} value max length is ${max}`);
98
103
  return;
@@ -147,8 +152,16 @@ export async function publish({noDocs} = {}) {
147
152
  }
148
153
  }
149
154
 
155
+ let toBackendDep = (dep: Dependency): DependencyV2 => {
156
+ return {
157
+ ...dep,
158
+ version: dep.version || '',
159
+ repo: dep.repo || ''
160
+ };
161
+ };
162
+
150
163
  // map fields
151
- let backendPkgConfig = {
164
+ let backendPkgConfig: PackageConfigV2 = {
152
165
  name: config.package.name,
153
166
  version: config.package.version,
154
167
  keywords: config.package.keywords || [],
@@ -162,8 +175,8 @@ export async function publish({noDocs} = {}) {
162
175
  dfx: config.package.dfx || '',
163
176
  moc: config.package.moc || '',
164
177
  donation: config.package.donation || '',
165
- dependencies: Object.values(config.dependencies || {}),
166
- devDependencies: Object.values(config['dev-dependencies'] || {}),
178
+ dependencies: Object.values(config.dependencies || {}).map(toBackendDep),
179
+ devDependencies: Object.values(config['dev-dependencies'] || {}).map(toBackendDep),
167
180
  scripts: [],
168
181
  };
169
182
 
@@ -214,7 +227,7 @@ export async function publish({noDocs} = {}) {
214
227
  let step = 0;
215
228
  function progress() {
216
229
  step++;
217
- logUpdate(`Publishing ${config.package.name}@${config.package.version} ${progressBar(step, total)}`);
230
+ logUpdate(`Publishing ${config.package?.name}@${config.package?.version} ${progressBar(step, total)}`);
218
231
  }
219
232
 
220
233
  // upload config
@@ -222,14 +235,14 @@ export async function publish({noDocs} = {}) {
222
235
 
223
236
  progress();
224
237
  let publishing = await actor.startPublish(backendPkgConfig);
225
- if (publishing.err) {
238
+ if ('err' in publishing) {
226
239
  console.log(chalk.red('Error: ') + publishing.err);
227
240
  return;
228
241
  }
229
242
  let puiblishingId = publishing.ok;
230
243
 
231
244
  // upload files
232
- await parallel(8, files, async (file) => {
245
+ await parallel(8, files, async (file: string) => {
233
246
  progress();
234
247
 
235
248
  let chunkSize = 1024 * 1024 + 512 * 1024; // 1.5mb
@@ -242,8 +255,8 @@ export async function publish({noDocs} = {}) {
242
255
  file = path.basename(file);
243
256
  }
244
257
 
245
- let res = await actor.startFileUpload(puiblishingId, file, chunkCount, firstChunk);
246
- if (res.err) {
258
+ let res = await actor.startFileUpload(puiblishingId, file, BigInt(chunkCount), firstChunk);
259
+ if ('err' in res) {
247
260
  console.log(chalk.red('Error: ') + res.err);
248
261
  return;
249
262
  }
@@ -252,8 +265,8 @@ export async function publish({noDocs} = {}) {
252
265
  for (let i = 1; i < chunkCount; i++) {
253
266
  let start = i * chunkSize;
254
267
  let chunk = Array.from(content.slice(start, start + chunkSize));
255
- let res = await actor.uploadFileChunk(puiblishingId, fileId, i, chunk);
256
- if (res.err) {
268
+ let res = await actor.uploadFileChunk(puiblishingId, fileId, BigInt(i), chunk);
269
+ if ('err' in res) {
257
270
  console.log(chalk.red('Error: ') + res.err);
258
271
  return;
259
272
  }
@@ -265,7 +278,7 @@ export async function publish({noDocs} = {}) {
265
278
  // finish
266
279
  progress();
267
280
  let res = await actor.finishPublish(puiblishingId);
268
- if (res.err) {
281
+ if ('err' in res) {
269
282
  console.log(chalk.red('Error: ') + res.err);
270
283
  return;
271
284
  }