ic-mops 0.41.1 → 0.42.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.
Files changed (109) hide show
  1. package/.DS_Store +0 -0
  2. package/CHANGELOG.md +14 -0
  3. package/api/actors.ts +2 -3
  4. package/bundle/cli.js +29 -29
  5. package/bundle/cli.tgz +0 -0
  6. package/bundle/declarations/bench/index.js +0 -8
  7. package/bundle/declarations/storage/storage.did.d.ts +3 -0
  8. package/bundle/package.json +2 -2
  9. package/cache.ts +25 -7
  10. package/check-requirements.ts +3 -2
  11. package/cli.ts +7 -3
  12. package/commands/add.ts +9 -7
  13. package/commands/available-updates.ts +1 -0
  14. package/commands/bench-replica.ts +1 -0
  15. package/commands/bench.ts +1 -0
  16. package/commands/bump.ts +1 -0
  17. package/commands/docs.ts +1 -0
  18. package/commands/import-identity.ts +1 -0
  19. package/commands/init.ts +2 -1
  20. package/commands/install/install-all.ts +53 -0
  21. package/commands/install/install-dep.ts +34 -0
  22. package/commands/install/install-deps.ts +24 -0
  23. package/commands/install/install-local-dep.ts +31 -0
  24. package/commands/install/install-mops-dep.ts +122 -0
  25. package/commands/install/sync-local-cache.ts +34 -0
  26. package/commands/publish.ts +1 -0
  27. package/commands/remove.ts +15 -18
  28. package/commands/search.ts +1 -0
  29. package/commands/self.ts +1 -0
  30. package/commands/sources.ts +1 -0
  31. package/commands/sync.ts +1 -0
  32. package/commands/test/test.ts +1 -0
  33. package/commands/toolchain/index.ts +1 -0
  34. package/commands/toolchain/moc.ts +1 -0
  35. package/commands/toolchain/pocket-ic.ts +1 -0
  36. package/commands/toolchain/toolchain-utils.ts +2 -0
  37. package/commands/toolchain/wasmtime.ts +1 -0
  38. package/commands/transfer-ownership.ts +1 -0
  39. package/commands/user.ts +1 -0
  40. package/declarations/bench/index.js +0 -8
  41. package/declarations/storage/storage.did.d.ts +3 -0
  42. package/dist/api/actors.js +2 -2
  43. package/dist/cache.d.ts +7 -3
  44. package/dist/cache.js +21 -7
  45. package/dist/check-requirements.js +3 -2
  46. package/dist/cli.js +7 -3
  47. package/dist/commands/add.js +7 -6
  48. package/dist/commands/available-updates.js +1 -0
  49. package/dist/commands/bench-replica.js +1 -0
  50. package/dist/commands/bench.js +1 -0
  51. package/dist/commands/bump.js +1 -0
  52. package/dist/commands/docs.js +1 -0
  53. package/dist/commands/import-identity.js +1 -0
  54. package/dist/commands/init.js +2 -1
  55. package/dist/commands/install/install-all.d.ts +8 -0
  56. package/dist/commands/install/install-all.js +37 -0
  57. package/dist/commands/install/install-dep.d.ts +8 -0
  58. package/dist/commands/install/install-dep.js +25 -0
  59. package/dist/commands/install/install-deps.d.ts +8 -0
  60. package/dist/commands/install/install-deps.js +14 -0
  61. package/dist/commands/install/install-local-dep.d.ts +6 -0
  62. package/dist/commands/install/install-local-dep.js +23 -0
  63. package/dist/commands/install/install-mops-dep.d.ts +8 -0
  64. package/dist/commands/install/install-mops-dep.js +97 -0
  65. package/dist/commands/install/sync-local-cache.d.ts +3 -0
  66. package/dist/commands/install/sync-local-cache.js +26 -0
  67. package/dist/commands/publish.js +1 -0
  68. package/dist/commands/remove.js +15 -18
  69. package/dist/commands/search.js +1 -0
  70. package/dist/commands/self.js +1 -0
  71. package/dist/commands/sources.js +1 -0
  72. package/dist/commands/sync.js +1 -0
  73. package/dist/commands/test/test.js +1 -0
  74. package/dist/commands/toolchain/index.js +1 -0
  75. package/dist/commands/toolchain/moc.js +1 -0
  76. package/dist/commands/toolchain/pocket-ic.js +1 -0
  77. package/dist/commands/toolchain/toolchain-utils.js +2 -0
  78. package/dist/commands/toolchain/wasmtime.js +1 -0
  79. package/dist/commands/transfer-ownership.js +1 -0
  80. package/dist/commands/user.js +1 -0
  81. package/dist/declarations/bench/index.js +0 -8
  82. package/dist/declarations/storage/storage.did.d.ts +3 -0
  83. package/dist/fix-dist.d.ts +1 -0
  84. package/dist/fix-dist.js +9 -0
  85. package/dist/helpers/get-moc-path.js +1 -0
  86. package/dist/integrity.js +1 -0
  87. package/dist/mops.js +3 -2
  88. package/dist/notify-installs.d.ts +1 -1
  89. package/dist/notify-installs.js +8 -5
  90. package/dist/package.json +5 -5
  91. package/dist/pem.d.ts +1 -0
  92. package/dist/pem.js +2 -1
  93. package/dist/release-cli.js +0 -4
  94. package/dist/resolve-packages.js +11 -9
  95. package/dist/vessel.js +11 -16
  96. package/{remove-scripts.ts → fix-dist.ts} +6 -0
  97. package/helpers/get-moc-path.ts +1 -0
  98. package/integrity.ts +1 -0
  99. package/mops.ts +3 -2
  100. package/notify-installs.ts +9 -5
  101. package/package.json +5 -5
  102. package/pem.ts +2 -1
  103. package/release-cli.ts +0 -5
  104. package/resolve-packages.ts +11 -9
  105. package/tsconfig.json +1 -0
  106. package/vessel.ts +12 -18
  107. package/commands/install-all.ts +0 -58
  108. package/commands/install-local.ts +0 -52
  109. package/commands/install.ts +0 -126
@@ -1,9 +1,11 @@
1
1
  import fs from 'node:fs';
2
2
  import { deleteSync } from 'del';
3
3
  import chalk from 'chalk';
4
- import { formatDir, formatGithubDir, checkConfigFile, readConfig, writeConfig } from '../mops.js';
4
+ import { checkConfigFile, getRootDir, readConfig, writeConfig } from '../mops.js';
5
5
  import { checkIntegrity } from '../integrity.js';
6
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
6
+ import { getDepCacheDir, getDepCacheName } from '../cache.js';
7
+ import path from 'node:path';
8
+ import { syncLocalCache } from './install/sync-local-cache.js';
7
9
  export async function remove(name, { dev = false, verbose = false, dryRun = false, lock } = {}) {
8
10
  if (!checkConfigFile()) {
9
11
  return;
@@ -20,13 +22,12 @@ export async function remove(name, { dev = false, verbose = false, dryRun = fals
20
22
  }).flat();
21
23
  }
22
24
  function getTransitiveDependenciesOf(name, version, repo) {
23
- let pkgDir = '';
24
- if (repo) {
25
- pkgDir = formatGithubDir(name, repo);
26
- }
27
- else if (version) {
28
- pkgDir = formatDir(name, version);
25
+ let value = version || repo;
26
+ if (!value) {
27
+ return [];
29
28
  }
29
+ let cacheName = getDepCacheName(name, value);
30
+ let pkgDir = getDepCacheDir(cacheName);
30
31
  let configFile = pkgDir + '/mops.toml';
31
32
  if (!fs.existsSync(configFile)) {
32
33
  verbose && console.log('no config', configFile);
@@ -61,16 +62,11 @@ export async function remove(name, { dev = false, verbose = false, dryRun = fals
61
62
  verbose && console.log(`Ignored transitive dependency ${depId} (other deps depend on it)`);
62
63
  continue;
63
64
  }
64
- let pkgDir;
65
- if (dep.repo) {
66
- pkgDir = formatGithubDir(dep.name, dep.repo);
67
- }
68
- else if (dep.version) {
69
- pkgDir = formatDir(dep.name, dep.version);
70
- }
71
- if (pkgDir && fs.existsSync(pkgDir)) {
72
- dryRun || deleteSync([`${pkgDir}`], { force: true });
73
- verbose && console.log(`Removed local cache ${pkgDir}`);
65
+ let cacheName = getDepCacheName(dep.name, dep.version || dep.repo || '');
66
+ let localCacheDir = path.join(getRootDir(), '.mops', cacheName);
67
+ if (localCacheDir && fs.existsSync(localCacheDir)) {
68
+ dryRun || deleteSync([localCacheDir], { force: true });
69
+ verbose && console.log(`Removed local cache ${localCacheDir}`);
74
70
  }
75
71
  }
76
72
  // remove from config
@@ -81,6 +77,7 @@ export async function remove(name, { dev = false, verbose = false, dryRun = fals
81
77
  delete config['dev-dependencies'][name];
82
78
  }
83
79
  dryRun || writeConfig(config);
80
+ await syncLocalCache();
84
81
  await checkIntegrity(lock);
85
82
  console.log(chalk.green('Package removed ') + `${name} = "${version}"`);
86
83
  }
@@ -1,3 +1,4 @@
1
+ import process from 'node:process';
1
2
  import asTable from 'as-table';
2
3
  import chalk from 'chalk';
3
4
  import { mainActor } from '../api/actors.js';
@@ -1,3 +1,4 @@
1
+ import process from 'node:process';
1
2
  import child_process, { execSync } from 'node:child_process';
2
3
  import chalk from 'chalk';
3
4
  import { version, globalConfigDir } from '../mops.js';
@@ -1,3 +1,4 @@
1
+ import process from 'node:process';
1
2
  import path from 'node:path';
2
3
  import fs from 'node:fs';
3
4
  import { checkConfigFile, formatDir, formatGithubDir, getDependencyType, readConfig } from '../mops.js';
@@ -1,3 +1,4 @@
1
+ import process from 'node:process';
1
2
  import path from 'node:path';
2
3
  import { execSync } from 'node:child_process';
3
4
  import { globSync } from 'glob';
@@ -1,3 +1,4 @@
1
+ import process from 'node:process';
1
2
  import { spawn } from 'node:child_process';
2
3
  import path from 'node:path';
3
4
  import fs from 'node:fs';
@@ -1,3 +1,4 @@
1
+ import process from 'node:process';
1
2
  import path from 'node:path';
2
3
  import fs from 'node:fs';
3
4
  import os from 'node:os';
@@ -1,3 +1,4 @@
1
+ import process from 'node:process';
1
2
  import path from 'node:path';
2
3
  import fs from 'fs-extra';
3
4
  import { globalCacheDir } from '../../mops.js';
@@ -1,3 +1,4 @@
1
+ import process from 'node:process';
1
2
  import path from 'node:path';
2
3
  import fs from 'node:fs';
3
4
  import { globalCacheDir } from '../../mops.js';
@@ -1,4 +1,6 @@
1
+ import process from 'node:process';
1
2
  import path from 'node:path';
3
+ import { Buffer } from 'node:buffer';
2
4
  import { unzipSync } from 'node:zlib';
3
5
  import { chmodSync } from 'node:fs';
4
6
  import fs from 'fs-extra';
@@ -1,3 +1,4 @@
1
+ import process from 'node:process';
1
2
  import path from 'node:path';
2
3
  import fs from 'fs-extra';
3
4
  import { globalCacheDir } from '../../mops.js';
@@ -1,3 +1,4 @@
1
+ import process from 'node:process';
1
2
  import chalk from 'chalk';
2
3
  import { checkConfigFile, getIdentity, readConfig } from '../mops.js';
3
4
  import { mainActor } from '../api/actors.js';
@@ -1,3 +1,4 @@
1
+ import process from 'node:process';
1
2
  import chalk from 'chalk';
2
3
  import { getIdentity } from '../mops.js';
3
4
  import { mainActor } from '../api/actors.js';
@@ -4,14 +4,6 @@ import { Actor, HttpAgent } from "@dfinity/agent";
4
4
  import { idlFactory } from "./bench.did.js";
5
5
  export { idlFactory } from "./bench.did.js";
6
6
 
7
- /* CANISTER_ID is replaced by webpack based on node environment
8
- * Note: canister environment variable will be standardized as
9
- * process.env.CANISTER_ID_<CANISTER_NAME_UPPERCASE>
10
- * beginning in dfx 0.15.0
11
- */
12
- export const canisterId =
13
- process.env.CANISTER_ID_BENCH;
14
-
15
7
  export const createActor = (canisterId, options = {}) => {
16
8
  const agent = options.agent || new HttpAgent({ ...options.agentOptions });
17
9
 
@@ -1,5 +1,6 @@
1
1
  import type { Principal } from '@dfinity/principal';
2
2
  import type { ActorMethod } from '@dfinity/agent';
3
+ import type { IDL } from '@dfinity/candid';
3
4
 
4
5
  export type Chunk = Array<number>;
5
6
  export type Err = string;
@@ -35,3 +36,5 @@ export interface StorageStats {
35
36
  'memorySize' : bigint,
36
37
  }
37
38
  export interface _SERVICE extends Storage {}
39
+ export declare const idlFactory: IDL.InterfaceFactory;
40
+ export declare const init: (args: { IDL: typeof IDL }) => IDL.Type[];
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,9 @@
1
+ import { readFileSync, writeFileSync } from 'node:fs';
2
+ // remove scripts
3
+ let text = readFileSync('dist/package.json', 'utf8');
4
+ let json = JSON.parse(text);
5
+ delete json.scripts;
6
+ // dist/bin/cli.js -> bin/cli.js
7
+ json.bin.mops = 'bin/mops.js';
8
+ json.bin['ic-mops'] = 'bin/mops.js';
9
+ writeFileSync('dist/package.json', JSON.stringify(json, null, 2));
@@ -1,3 +1,4 @@
1
+ import process from 'node:process';
1
2
  import { execSync } from 'node:child_process';
2
3
  export function getMocPath() {
3
4
  let mocPath = process.env.DFX_MOC_PATH;
package/dist/integrity.js CHANGED
@@ -1,3 +1,4 @@
1
+ import process from 'node:process';
1
2
  import fs from 'node:fs';
2
3
  import path from 'node:path';
3
4
  import { sha256 } from '@noble/hashes/sha256';
package/dist/mops.js CHANGED
@@ -1,3 +1,4 @@
1
+ import process from 'node:process';
1
2
  import path from 'node:path';
2
3
  import fs from 'node:fs';
3
4
  import TOML from '@iarna/toml';
@@ -9,8 +10,8 @@ import { decodeFile } from './pem.js';
9
10
  import { mainActor, storageActor } from './api/actors.js';
10
11
  import { getNetwork } from './api/network.js';
11
12
  import { getHighestVersion } from './api/getHighestVersion.js';
12
- if (!global.fetch) {
13
- global.fetch = fetch;
13
+ if (!globalThis.fetch) {
14
+ globalThis.fetch = fetch;
14
15
  }
15
16
  // (!) make changes in pair with backend
16
17
  export let apiVersion = '1.2';
@@ -1 +1 @@
1
- export declare function notifyInstalls(names: string[]): Promise<void>;
1
+ export declare function notifyInstalls(installedDeps: Record<string, string>): Promise<void>;
@@ -1,11 +1,14 @@
1
1
  import { getDependencyType } from './mops.js';
2
2
  import { mainActor } from './api/actors.js';
3
- import { resolvePackages } from './resolve-packages.js';
4
- export async function notifyInstalls(names) {
5
- let resolvedPackages = await resolvePackages();
6
- let packages = names.map(name => [name, resolvedPackages[name]]);
3
+ export async function notifyInstalls(installedDeps) {
4
+ let packages = Object.entries(installedDeps).filter(([_, version]) => getDependencyType(version) === 'mops');
7
5
  if (packages.length) {
8
6
  let actor = await mainActor();
9
- await actor.notifyInstalls(packages.filter(([_, version]) => getDependencyType(version) === 'mops'));
7
+ try {
8
+ await actor.notifyInstalls(packages);
9
+ }
10
+ catch (err) {
11
+ // verbose && console.error('Failed to notify installs:', err);
12
+ }
10
13
  }
11
14
  }
package/dist/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "ic-mops",
3
- "version": "0.41.1",
3
+ "version": "0.42.1",
4
4
  "type": "module",
5
5
  "bin": {
6
- "mops": "dist/bin/mops.js",
7
- "ic-mops": "dist/bin/mops.js",
6
+ "mops": "bin/mops.js",
7
+ "ic-mops": "bin/mops.js",
8
8
  "moc-wrapper": "bin/moc-wrapper.sh"
9
9
  },
10
10
  "files": [
@@ -42,7 +42,7 @@
42
42
  "decomp-tarxz": "0.1.1",
43
43
  "decompress": "^4.2.1",
44
44
  "del": "7.1.0",
45
- "dhall-to-json-cli": "^1.7.6",
45
+ "dhall-to-json-cli": "1.7.6",
46
46
  "eslint": "8.57.0",
47
47
  "execa": "8.0.1",
48
48
  "fs-extra": "11.2.0",
@@ -81,7 +81,7 @@
81
81
  "bun": "1.0.35",
82
82
  "esbuild": "0.20.1",
83
83
  "tsx": "4.7.1",
84
- "typescript": "5.3.2"
84
+ "typescript": "5.4.3"
85
85
  },
86
86
  "overrides": {
87
87
  "@dfinity/agent": "^0.19.3",
package/dist/pem.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  /// <reference types="node" resolution-mode="require"/>
2
+ import { Buffer } from 'node:buffer';
2
3
  import { Ed25519KeyIdentity } from '@dfinity/identity';
3
4
  import { Secp256k1KeyIdentity } from '@dfinity/identity-secp256k1';
4
5
  export declare function decodeFile(file: string, password?: string): Secp256k1KeyIdentity | Ed25519KeyIdentity;
package/dist/pem.js CHANGED
@@ -1,8 +1,9 @@
1
1
  import fs from 'node:fs';
2
+ import { Buffer } from 'node:buffer';
3
+ import crypto from 'node:crypto';
2
4
  import { Ed25519KeyIdentity } from '@dfinity/identity';
3
5
  import { Secp256k1KeyIdentity } from '@dfinity/identity-secp256k1';
4
6
  import pemfile from 'pem-file';
5
- import crypto from 'crypto';
6
7
  export function decodeFile(file, password) {
7
8
  let rawKey = fs.readFileSync(file);
8
9
  if (password) {
@@ -10,10 +10,6 @@ import { findChangelogEntry } from './helpers/find-changelog-entry.js';
10
10
  let __dirname = new URL('.', import.meta.url).pathname;
11
11
  execSync('npm run prepare', { stdio: 'inherit', cwd: __dirname });
12
12
  execSync('npm run bundle', { stdio: 'inherit', cwd: __dirname });
13
- // fix package.json paths
14
- // let packageJson = fs.readFileSync(path.resolve(__dirname, 'bundle/package.json'), 'utf8');
15
- // packageJson = packageJson.replaceAll('dist/', '');
16
- // fs.writeFileSync(path.resolve(__dirname, 'bundle/package.json'), packageJson);
17
13
  let version = JSON.parse(fs.readFileSync(path.resolve(__dirname, 'package.json'), 'utf8')).version;
18
14
  let major = semver.parse(version)?.major;
19
15
  let tag = semver.parse(version)?.prerelease[0] || 'latest';
@@ -1,7 +1,9 @@
1
+ import process from 'node:process';
1
2
  import path from 'node:path';
2
3
  import chalk from 'chalk';
3
- import { checkConfigFile, formatDir, formatGithubDir, getRootDir, parseGithubURL, readConfig } from './mops.js';
4
+ import { checkConfigFile, getRootDir, parseGithubURL, readConfig } from './mops.js';
4
5
  import { readVesselConfig } from './vessel.js';
6
+ import { getDepCacheDir, getDepCacheName } from './cache.js';
5
7
  export async function resolvePackages({ verbose = false } = {}) {
6
8
  if (!checkConfigFile()) {
7
9
  return {};
@@ -61,23 +63,23 @@ export async function resolvePackages({ verbose = false } = {}) {
61
63
  }
62
64
  }
63
65
  let nestedConfig;
64
- let nestedDir = '';
66
+ let localNestedDir = '';
65
67
  // read nested config
66
68
  if (repo) {
67
- nestedDir = formatGithubDir(name, repo);
68
- nestedConfig = await readVesselConfig(nestedDir, { silent: true }) || {};
69
+ let cacheDir = getDepCacheName(name, repo);
70
+ nestedConfig = await readVesselConfig(getDepCacheDir(cacheDir), { silent: true }) || {};
69
71
  }
70
72
  else if (pkgDetails.path) {
71
- nestedDir = path.resolve(configDir, pkgDetails.path);
72
- nestedConfig = readConfig(nestedDir + '/mops.toml');
73
+ localNestedDir = path.resolve(configDir, pkgDetails.path);
74
+ nestedConfig = readConfig(localNestedDir + '/mops.toml');
73
75
  }
74
76
  else if (version) {
75
- nestedDir = formatDir(name, version);
76
- nestedConfig = readConfig(nestedDir + '/mops.toml');
77
+ let cacheDir = getDepCacheName(name, version);
78
+ nestedConfig = readConfig(getDepCacheDir(cacheDir) + '/mops.toml');
77
79
  }
78
80
  // collect nested deps
79
81
  if (nestedConfig) {
80
- await collectDeps(nestedConfig, nestedDir);
82
+ await collectDeps(nestedConfig, localNestedDir);
81
83
  }
82
84
  if (!versions[name]) {
83
85
  versions[name] = [];
package/dist/vessel.js CHANGED
@@ -1,14 +1,15 @@
1
+ import process from 'node:process';
1
2
  import { existsSync, mkdirSync, createWriteStream, readFileSync, writeFileSync } from 'node:fs';
2
3
  import path from 'node:path';
4
+ import { pipeline } from 'node:stream';
3
5
  import { deleteSync } from 'del';
4
6
  import { execaCommand } from 'execa';
5
7
  import chalk from 'chalk';
6
8
  import { createLogUpdate } from 'log-update';
7
9
  import got from 'got';
8
10
  import decompress from 'decompress';
9
- import { pipeline } from 'stream';
10
11
  import { formatGithubDir, parseGithubURL, progressBar } from './mops.js';
11
- import { addCache, copyCache, isCached } from './cache.js';
12
+ import { getDepCacheDir, getGithubDepCacheName, isDepCached } from './cache.js';
12
13
  const dhallFileToJson = async (filePath, silent) => {
13
14
  if (existsSync(filePath)) {
14
15
  let cwd = new URL(path.dirname(import.meta.url)).pathname;
@@ -116,32 +117,26 @@ export const downloadFromGithub = async (repo, dest, onProgress) => {
116
117
  return promise;
117
118
  };
118
119
  export const installFromGithub = async (name, repo, { verbose = false, dep = false, silent = false } = {}) => {
119
- let { branch, commitHash } = parseGithubURL(repo);
120
120
  let dir = formatGithubDir(name, repo);
121
- let cacheName = `_github/${name}#${branch}` + (commitHash ? `@${commitHash}` : '');
121
+ let cacheName = getGithubDepCacheName(name, repo);
122
+ let cacheDir = getDepCacheDir(cacheName);
122
123
  let logUpdate = createLogUpdate(process.stdout, { showCursor: true });
123
- if (existsSync(dir)) {
124
- silent || logUpdate(`${dep ? 'Dependency' : 'Installing'} ${repo} (local cache)`);
125
- }
126
- else if (isCached(cacheName)) {
127
- await copyCache(cacheName, dir);
128
- silent || logUpdate(`${dep ? 'Dependency' : 'Installing'} ${repo} (global cache)`);
124
+ if (isDepCached(cacheName)) {
125
+ silent || logUpdate(`${dep ? 'Dependency' : 'Installing'} ${repo} (cache)`);
129
126
  }
130
127
  else {
131
- mkdirSync(dir, { recursive: true });
132
128
  let progress = (step, total) => {
133
129
  silent || logUpdate(`${dep ? 'Dependency' : 'Installing'} ${repo} ${progressBar(step, total)}`);
134
130
  };
135
- progress(0, 2 * (1024 ** 2));
131
+ progress(0, 1024 * 500);
132
+ mkdirSync(cacheDir, { recursive: true });
136
133
  try {
137
- await downloadFromGithub(repo, dir, progress);
134
+ await downloadFromGithub(repo, cacheDir, progress);
138
135
  }
139
136
  catch (err) {
140
- deleteSync([dir]);
137
+ deleteSync([cacheDir]);
141
138
  process.exit(1);
142
139
  }
143
- // add to cache
144
- await addCache(cacheName, dir);
145
140
  }
146
141
  if (verbose) {
147
142
  silent || logUpdate.done();
@@ -1,6 +1,12 @@
1
1
  import {readFileSync, writeFileSync} from 'node:fs';
2
2
 
3
+ // remove scripts
3
4
  let text = readFileSync('dist/package.json', 'utf8');
4
5
  let json = JSON.parse(text);
5
6
  delete json.scripts;
7
+
8
+ // dist/bin/cli.js -> bin/cli.js
9
+ json.bin.mops = 'bin/mops.js';
10
+ json.bin['ic-mops'] = 'bin/mops.js';
11
+
6
12
  writeFileSync('dist/package.json', JSON.stringify(json, null, 2));
@@ -1,3 +1,4 @@
1
+ import process from 'node:process';
1
2
  import {execSync} from 'node:child_process';
2
3
 
3
4
  export function getMocPath() : string {
package/integrity.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import process from 'node:process';
1
2
  import fs from 'node:fs';
2
3
  import path from 'node:path';
3
4
  import {sha256} from '@noble/hashes/sha256';
package/mops.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import process from 'node:process';
1
2
  import path from 'node:path';
2
3
  import fs from 'node:fs';
3
4
  import {Identity} from '@dfinity/agent';
@@ -14,8 +15,8 @@ import {getNetwork} from './api/network.js';
14
15
  import {getHighestVersion} from './api/getHighestVersion.js';
15
16
 
16
17
 
17
- if (!global.fetch) {
18
- global.fetch = fetch as any;
18
+ if (!globalThis.fetch) {
19
+ globalThis.fetch = fetch as any;
19
20
  }
20
21
 
21
22
  // (!) make changes in pair with backend
@@ -1,12 +1,16 @@
1
1
  import {getDependencyType} from './mops.js';
2
2
  import {mainActor} from './api/actors.js';
3
- import {resolvePackages} from './resolve-packages.js';
4
3
 
5
- export async function notifyInstalls(names : string[]) {
6
- let resolvedPackages = await resolvePackages();
7
- let packages : [string, string][] = names.map(name => [name, resolvedPackages[name] as string]);
4
+ export async function notifyInstalls(installedDeps : Record<string, string>) {
5
+ let packages = Object.entries(installedDeps).filter(([_, version]) => getDependencyType(version) === 'mops');
8
6
  if (packages.length) {
9
7
  let actor = await mainActor();
10
- await actor.notifyInstalls(packages.filter(([_, version]) => getDependencyType(version) === 'mops'));
8
+
9
+ try {
10
+ await actor.notifyInstalls(packages);
11
+ }
12
+ catch (err) {
13
+ // verbose && console.error('Failed to notify installs:', err);
14
+ }
11
15
  }
12
16
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ic-mops",
3
- "version": "0.41.1",
3
+ "version": "0.42.1",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "mops": "dist/bin/mops.js",
@@ -31,8 +31,8 @@
31
31
  "bundle:package-json": "tsx bundle-package-json.ts",
32
32
  "bundle:tar": "tar -czvf bundle/cli.tgz bundle",
33
33
  "copy": "cp -r commands/bench dist/commands && cp -r declarations templates package.json bin dist | true",
34
- "prepare": "npm run build && npm run copy && npm run remove-scripts",
35
- "remove-scripts": "tsx ./remove-scripts.ts",
34
+ "prepare": "npm run build && npm run copy && npm run fix-dist",
35
+ "fix-dist": "tsx ./fix-dist.ts",
36
36
  "release": "tsx release-cli.ts",
37
37
  "check": "tsc --project tsconfig.json --noEmit",
38
38
  "tsc": "tsc",
@@ -57,7 +57,7 @@
57
57
  "decomp-tarxz": "0.1.1",
58
58
  "decompress": "^4.2.1",
59
59
  "del": "7.1.0",
60
- "dhall-to-json-cli": "^1.7.6",
60
+ "dhall-to-json-cli": "1.7.6",
61
61
  "eslint": "8.57.0",
62
62
  "execa": "8.0.1",
63
63
  "fs-extra": "11.2.0",
@@ -96,7 +96,7 @@
96
96
  "bun": "1.0.35",
97
97
  "esbuild": "0.20.1",
98
98
  "tsx": "4.7.1",
99
- "typescript": "5.3.2"
99
+ "typescript": "5.4.3"
100
100
  },
101
101
  "overrides": {
102
102
  "@dfinity/agent": "^0.19.3",
package/pem.ts CHANGED
@@ -1,8 +1,9 @@
1
1
  import fs from 'node:fs';
2
+ import {Buffer} from 'node:buffer';
3
+ import crypto from 'node:crypto';
2
4
  import {Ed25519KeyIdentity} from '@dfinity/identity';
3
5
  import {Secp256k1KeyIdentity} from '@dfinity/identity-secp256k1';
4
6
  import pemfile from 'pem-file';
5
- import crypto from 'crypto';
6
7
 
7
8
  export function decodeFile(file : string, password ?: string) {
8
9
  let rawKey = fs.readFileSync(file);
package/release-cli.ts CHANGED
@@ -14,11 +14,6 @@ let __dirname = new URL('.', import.meta.url).pathname;
14
14
  execSync('npm run prepare', {stdio: 'inherit', cwd: __dirname});
15
15
  execSync('npm run bundle', {stdio: 'inherit', cwd: __dirname});
16
16
 
17
- // fix package.json paths
18
- // let packageJson = fs.readFileSync(path.resolve(__dirname, 'bundle/package.json'), 'utf8');
19
- // packageJson = packageJson.replaceAll('dist/', '');
20
- // fs.writeFileSync(path.resolve(__dirname, 'bundle/package.json'), packageJson);
21
-
22
17
  let version = JSON.parse(fs.readFileSync(path.resolve(__dirname, 'package.json'), 'utf8')).version;
23
18
  let major = semver.parse(version)?.major;
24
19
  let tag = semver.parse(version)?.prerelease[0] || 'latest';
@@ -1,8 +1,10 @@
1
+ import process from 'node:process';
1
2
  import path from 'node:path';
2
3
  import chalk from 'chalk';
3
- import {checkConfigFile, formatDir, formatGithubDir, getRootDir, parseGithubURL, readConfig} from './mops.js';
4
+ import {checkConfigFile, getRootDir, parseGithubURL, readConfig} from './mops.js';
4
5
  import {VesselConfig, readVesselConfig} from './vessel.js';
5
6
  import {Config, Dependency} from './types.js';
7
+ import {getDepCacheDir, getDepCacheName} from './cache.js';
6
8
 
7
9
  export async function resolvePackages({verbose = false} = {}) : Promise<Record<string, string>> {
8
10
  if (!checkConfigFile()) {
@@ -75,25 +77,25 @@ export async function resolvePackages({verbose = false} = {}) : Promise<Record<s
75
77
  }
76
78
 
77
79
  let nestedConfig;
78
- let nestedDir = '';
80
+ let localNestedDir = '';
79
81
 
80
82
  // read nested config
81
83
  if (repo) {
82
- nestedDir = formatGithubDir(name, repo);
83
- nestedConfig = await readVesselConfig(nestedDir, {silent: true}) || {};
84
+ let cacheDir = getDepCacheName(name, repo);
85
+ nestedConfig = await readVesselConfig(getDepCacheDir(cacheDir), {silent: true}) || {};
84
86
  }
85
87
  else if (pkgDetails.path) {
86
- nestedDir = path.resolve(configDir, pkgDetails.path);
87
- nestedConfig = readConfig(nestedDir + '/mops.toml');
88
+ localNestedDir = path.resolve(configDir, pkgDetails.path);
89
+ nestedConfig = readConfig(localNestedDir + '/mops.toml');
88
90
  }
89
91
  else if (version) {
90
- nestedDir = formatDir(name, version);
91
- nestedConfig = readConfig(nestedDir + '/mops.toml');
92
+ let cacheDir = getDepCacheName(name, version);
93
+ nestedConfig = readConfig(getDepCacheDir(cacheDir) + '/mops.toml');
92
94
  }
93
95
 
94
96
  // collect nested deps
95
97
  if (nestedConfig) {
96
- await collectDeps(nestedConfig, nestedDir);
98
+ await collectDeps(nestedConfig, localNestedDir);
97
99
  }
98
100
 
99
101
  if (!versions[name]) {
package/tsconfig.json CHANGED
@@ -13,6 +13,7 @@
13
13
  "noUnusedLocals": false,
14
14
  "noUnusedParameters": false,
15
15
  "noPropertyAccessFromIndexSignature": false,
16
+ "exactOptionalPropertyTypes": false,
16
17
  "declaration": true
17
18
  }
18
19
  }