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
package/vessel.ts 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
 
13
14
  const dhallFileToJson = async (filePath : string, silent : boolean) => {
14
15
  if (existsSync(filePath)) {
@@ -149,38 +150,31 @@ export const downloadFromGithub = async (repo : string, dest : string, onProgres
149
150
  };
150
151
 
151
152
  export const installFromGithub = async (name : string, repo : string, {verbose = false, dep = false, silent = false} = {}) => {
152
- let {branch, commitHash} = parseGithubURL(repo);
153
153
  let dir = formatGithubDir(name, repo);
154
- let cacheName = `_github/${name}#${branch}` + (commitHash ? `@${commitHash}` : '');
154
+ let cacheName = getGithubDepCacheName(name, repo);
155
+ let cacheDir = getDepCacheDir(cacheName);
155
156
 
156
157
  let logUpdate = createLogUpdate(process.stdout, {showCursor: true});
157
158
 
158
- if (existsSync(dir)) {
159
- silent || logUpdate(`${dep ? 'Dependency' : 'Installing'} ${repo} (local cache)`);
160
- }
161
- else if (isCached(cacheName)) {
162
- await copyCache(cacheName, dir);
163
- silent || logUpdate(`${dep ? 'Dependency' : 'Installing'} ${repo} (global cache)`);
159
+ if (isDepCached(cacheName)) {
160
+ silent || logUpdate(`${dep ? 'Dependency' : 'Installing'} ${repo} (cache)`);
164
161
  }
165
162
  else {
166
- mkdirSync(dir, {recursive: true});
167
-
168
163
  let progress = (step : number, total : number) => {
169
164
  silent || logUpdate(`${dep ? 'Dependency' : 'Installing'} ${repo} ${progressBar(step, total)}`);
170
165
  };
171
166
 
172
- progress(0, 2 * (1024 ** 2));
167
+ progress(0, 1024 * 500);
168
+
169
+ mkdirSync(cacheDir, {recursive: true});
173
170
 
174
171
  try {
175
- await downloadFromGithub(repo, dir, progress);
172
+ await downloadFromGithub(repo, cacheDir, progress);
176
173
  }
177
174
  catch (err) {
178
- deleteSync([dir]);
175
+ deleteSync([cacheDir]);
179
176
  process.exit(1);
180
177
  }
181
-
182
- // add to cache
183
- await addCache(cacheName, dir);
184
178
  }
185
179
 
186
180
  if (verbose) {
@@ -1,58 +0,0 @@
1
- import chalk from 'chalk';
2
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
3
- import {createLogUpdate} from 'log-update';
4
- import {checkConfigFile, readConfig} from '../mops.js';
5
- import {install} from './install.js';
6
- import {installFromGithub} from '../vessel.js';
7
- import {notifyInstalls} from '../notify-installs.js';
8
- import {checkIntegrity} from '../integrity.js';
9
- import {installLocal} from './install-local.js';
10
- import {checkRequirements} from '../check-requirements.js';
11
-
12
- type InstallAllOptions = {
13
- verbose ?: boolean;
14
- silent ?: boolean;
15
- lock ?: 'check' | 'update' | 'ignore';
16
- }
17
-
18
- export async function installAll({verbose = false, silent = false, lock} : InstallAllOptions = {}) {
19
- if (!checkConfigFile()) {
20
- return;
21
- }
22
-
23
- let config = readConfig();
24
- let deps = Object.values(config.dependencies || {});
25
- let devDeps = Object.values(config['dev-dependencies'] || {});
26
- let allDeps = [...deps, ...devDeps];
27
- let installedPackages = {};
28
-
29
- for (let {name, repo, path, version} of allDeps) {
30
- if (repo) {
31
- await installFromGithub(name, repo, {verbose, silent});
32
- }
33
- else {
34
- let res = await (path ? installLocal(name, path, {silent, verbose}) : install(name, version, {silent, verbose}));
35
- if (res === false) {
36
- return;
37
- }
38
- installedPackages = {...installedPackages, ...res};
39
- }
40
- }
41
-
42
- let logUpdate = createLogUpdate(process.stdout, {showCursor: true});
43
-
44
- if (!silent && lock !== 'ignore') {
45
- logUpdate('Checking integrity...');
46
- }
47
-
48
- await Promise.all([
49
- notifyInstalls(Object.keys(installedPackages)),
50
- checkIntegrity(lock),
51
- ]);
52
-
53
- if (!silent) {
54
- logUpdate.clear();
55
- await checkRequirements();
56
- console.log(chalk.green('Packages installed'));
57
- }
58
- }
@@ -1,52 +0,0 @@
1
- import path from 'node:path';
2
- import {createLogUpdate} from 'log-update';
3
- import {checkConfigFile, getRootDir, readConfig} from '../mops.js';
4
- import {installFromGithub} from '../vessel.js';
5
- import {install} from './install.js';
6
-
7
- // skip install and just find non-local dependencies to install
8
- // pkgPath should be relative to the current root dir or absolute
9
- export async function installLocal(pkg : string, pkgPath = '', {verbose = false, silent = false} = {}) : Promise<Record<string, string> | false> {
10
- if (!checkConfigFile()) {
11
- return false;
12
- }
13
-
14
- if (!silent) {
15
- let logUpdate = createLogUpdate(process.stdout, {showCursor: true});
16
- logUpdate(`Local dependency ${pkg} = "${pkgPath}"`);
17
-
18
- if (verbose) {
19
- silent || logUpdate.done();
20
- }
21
- else {
22
- logUpdate.clear();
23
- }
24
- }
25
-
26
- // install dependencies
27
- let ok = true;
28
- let rootDir = getRootDir();
29
- let dir = path.resolve(rootDir, pkgPath);
30
- let config = readConfig(path.join(dir, 'mops.toml'));
31
- let deps = Object.values(config.dependencies || {});
32
- let installedDeps = {};
33
- for (const {name, repo, version, path: depPath} of deps) {
34
- if (repo) {
35
- await installFromGithub(name, repo, {silent, verbose});
36
- }
37
- else {
38
- let res = await (depPath ? installLocal(name, path.resolve(pkgPath, depPath), {silent, verbose}) : install(name, version, {silent, verbose}));
39
- if (res) {
40
- installedDeps = {...installedDeps, ...res};
41
- }
42
- else {
43
- ok = false;
44
- }
45
- }
46
- }
47
-
48
- if (!ok) {
49
- return false;
50
- }
51
- return installedDeps;
52
- }
@@ -1,126 +0,0 @@
1
- import path from 'node:path';
2
- import fs from 'node:fs';
3
- import {createLogUpdate} from 'log-update';
4
- import chalk from 'chalk';
5
- import {checkConfigFile, formatDir, progressBar, readConfig} from '../mops.js';
6
- import {getHighestVersion} from '../api/getHighestVersion.js';
7
- import {storageActor} from '../api/actors.js';
8
- import {parallel} from '../parallel.js';
9
- import {installFromGithub} from '../vessel.js';
10
- import {addCache, copyCache, isCached} from '../cache.js';
11
- import {downloadFile, getPackageFilesInfo} from '../api/downloadPackageFiles.js';
12
- import {installLocal} from './install-local.js';
13
-
14
- export async function install(pkg : string, version = '', {verbose = false, silent = false, dep = false} = {}) : Promise<Record<string, string> | false> {
15
- if (!checkConfigFile()) {
16
- return false;
17
- }
18
- let logUpdate = createLogUpdate(process.stdout, {showCursor: true});
19
-
20
- // progress
21
- let total = Infinity;
22
- let step = 0;
23
- let progress = () => {
24
- step++;
25
- silent || logUpdate(`${dep ? 'Dependency' : 'Installing'} ${pkg}@${version} ${progressBar(step, total)}`);
26
- };
27
- progress();
28
-
29
- if (!version) {
30
- let versionRes = await getHighestVersion(pkg);
31
- if ('err' in versionRes) {
32
- console.log(chalk.red('Error: ') + versionRes.err);
33
- return false;
34
- }
35
- version = versionRes.ok;
36
- }
37
-
38
- let dir = formatDir(pkg, version);
39
- let alreadyInstalled = false;
40
-
41
- // already installed
42
- if (fs.existsSync(dir)) {
43
- silent || logUpdate(`${dep ? 'Dependency' : 'Installing'} ${pkg}@${version} (local cache)`);
44
- alreadyInstalled = true;
45
- }
46
- // copy from cache
47
- else if (isCached(`${pkg}@${version}`)) {
48
- await copyCache(`${pkg}@${version}`, dir);
49
- silent || logUpdate(`${dep ? 'Dependency' : 'Installing'} ${pkg}@${version} (global cache)`);
50
- }
51
- // download
52
- else {
53
- let threads = 16;
54
-
55
- // GitHub Actions fails with "fetch failed" if there are multiple concurrent actions
56
- if (process.env.GITHUB_ENV) {
57
- threads = 4;
58
- }
59
-
60
- try {
61
- let {storageId, fileIds} = await getPackageFilesInfo(pkg, version);
62
-
63
- total = fileIds.length + 2;
64
-
65
- let filesData = new Map;
66
- let storage = await storageActor(storageId);
67
-
68
- await parallel(threads, fileIds, async (fileId : string) => {
69
- let {path, data} = await downloadFile(storage, fileId);
70
- filesData.set(path, data);
71
- progress();
72
- });
73
-
74
- // write files to disk
75
- for (let [filePath, data] of filesData.entries()) {
76
- fs.mkdirSync(path.join(dir, path.dirname(filePath)), {recursive: true});
77
- fs.writeFileSync(path.join(dir, filePath), Buffer.from(data));
78
- }
79
- }
80
- catch (err) {
81
- console.error(chalk.red('Error: ') + err);
82
- return false;
83
- }
84
-
85
- // add to cache
86
- await addCache(`${pkg}@${version}`, dir);
87
-
88
- progress();
89
- }
90
-
91
- if (verbose) {
92
- silent || logUpdate.done();
93
- }
94
- else {
95
- logUpdate.clear();
96
- }
97
-
98
- // install dependencies
99
- let ok = true;
100
- let config = readConfig(path.join(dir, 'mops.toml'));
101
- let deps = Object.values(config.dependencies || {});
102
- let installedDeps = {};
103
- for (const {name, repo, version, path: depPath} of deps) {
104
- if (repo) {
105
- await installFromGithub(name, repo, {silent, verbose});
106
- }
107
- else {
108
- let res = await (depPath ? installLocal(name, depPath, {silent, verbose}) : install(name, version, {silent, verbose}));
109
- if (res) {
110
- installedDeps = {...installedDeps, ...res};
111
- }
112
- else {
113
- ok = false;
114
- }
115
- }
116
- }
117
-
118
- if (!alreadyInstalled) {
119
- installedDeps = {...installedDeps, [pkg]: version};
120
- }
121
-
122
- if (!ok) {
123
- return false;
124
- }
125
- return installedDeps;
126
- }