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,3 +1,4 @@
1
+ import process from 'node:process';
1
2
  import {spawn, ChildProcessWithoutNullStreams} 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
 
@@ -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
 
@@ -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
 
@@ -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';
package/commands/user.ts CHANGED
@@ -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[];
@@ -1,6 +1,6 @@
1
1
  import { Actor, HttpAgent } from '@dfinity/agent';
2
- import { idlFactory } from '../declarations/main/index.js';
3
- import { idlFactory as storageIdlFactory } from '../declarations/storage/index.js';
2
+ import { idlFactory } from '../declarations/main/main.did.js';
3
+ import { idlFactory as storageIdlFactory } from '../declarations/storage/storage.did.js';
4
4
  import { getEndpoint } from './network.js';
5
5
  import { getNetwork } from './network.js';
6
6
  export let mainActor = async (identity) => {
package/dist/cache.d.ts CHANGED
@@ -1,5 +1,9 @@
1
- export declare let isCached: (pkgId: string) => boolean;
2
- export declare let addCache: (pkgId: string, source: string) => Promise<void>;
3
- export declare let copyCache: (pkgId: string, dest: string) => Promise<void>;
1
+ export declare let getDepCacheDir: (cacheName: string) => string;
2
+ export declare let isDepCached: (cacheName: string) => boolean;
3
+ export declare function getDepCacheName(name: string, version: string): string;
4
+ export declare function getMopsDepCacheName(name: string, version: string): string;
5
+ export declare function getGithubDepCacheName(name: string, repo: string): string;
6
+ export declare let addCache: (cacheName: string, source: string) => Promise<void>;
7
+ export declare let copyCache: (cacheName: string, dest: string) => Promise<void>;
4
8
  export declare let cacheSize: () => Promise<string>;
5
9
  export declare let cleanCache: () => Promise<void>;
package/dist/cache.js CHANGED
@@ -2,13 +2,27 @@ import fs from 'node:fs';
2
2
  import path from 'node:path';
3
3
  import ncp from 'ncp';
4
4
  import getFolderSize from 'get-folder-size';
5
- import { globalCacheDir } from './mops.js';
6
- export let isCached = (pkgId) => {
7
- let dir = path.join(globalCacheDir, 'packages', pkgId);
5
+ import { getDependencyType, globalCacheDir, parseGithubURL } from './mops.js';
6
+ export let getDepCacheDir = (cacheName) => {
7
+ return path.join(globalCacheDir, 'packages', cacheName);
8
+ };
9
+ export let isDepCached = (cacheName) => {
10
+ let dir = getDepCacheDir(cacheName);
8
11
  return fs.existsSync(dir);
9
12
  };
10
- export let addCache = (pkgId, source) => {
11
- let dest = path.join(globalCacheDir, 'packages', pkgId);
13
+ export function getDepCacheName(name, version) {
14
+ let depType = getDependencyType(version);
15
+ return depType === 'mops' ? getMopsDepCacheName(name, version) : getGithubDepCacheName(name, version);
16
+ }
17
+ export function getMopsDepCacheName(name, version) {
18
+ return `${name}@${version}`;
19
+ }
20
+ export function getGithubDepCacheName(name, repo) {
21
+ const { branch, commitHash } = parseGithubURL(repo);
22
+ return `_github/${name}#${branch}` + (commitHash ? `@${commitHash}` : '');
23
+ }
24
+ export let addCache = (cacheName, source) => {
25
+ let dest = path.join(globalCacheDir, 'packages', cacheName);
12
26
  fs.mkdirSync(dest, { recursive: true });
13
27
  return new Promise((resolve, reject) => {
14
28
  ncp.ncp(source, dest, { stopOnErr: true }, (err) => {
@@ -19,8 +33,8 @@ export let addCache = (pkgId, source) => {
19
33
  });
20
34
  });
21
35
  };
22
- export let copyCache = (pkgId, dest) => {
23
- let source = path.join(globalCacheDir, 'packages', pkgId);
36
+ export let copyCache = (cacheName, dest) => {
37
+ let source = path.join(globalCacheDir, 'packages', cacheName);
24
38
  fs.mkdirSync(dest, { recursive: true });
25
39
  return new Promise((resolve, reject) => {
26
40
  ncp.ncp(source, dest, { stopOnErr: true }, (err) => {
@@ -1,7 +1,7 @@
1
1
  import path from 'node:path';
2
2
  import { SemVer } from 'semver';
3
3
  import chalk from 'chalk';
4
- import { getDependencyType, readConfig } from './mops.js';
4
+ import { getDependencyType, getRootDir, readConfig } from './mops.js';
5
5
  import { resolvePackages } from './resolve-packages.js';
6
6
  import { getMocVersion } from './helpers/get-moc-version.js';
7
7
  export async function checkRequirements({ verbose = false } = {}) {
@@ -16,11 +16,12 @@ export async function checkRequirements({ verbose = false } = {}) {
16
16
  let installedMoc = new SemVer(mocVersion);
17
17
  let highestRequiredMoc = new SemVer('0.0.0');
18
18
  let highestRequiredMocPkgId = '';
19
+ let rootDir = getRootDir();
19
20
  let resolvedPackages = await resolvePackages();
20
21
  for (let [name, version] of Object.entries(resolvedPackages)) {
21
22
  if (getDependencyType(version) === 'mops') {
22
23
  let pkgId = `${name}@${version}`;
23
- let depConfig = readConfig(path.join('.mops', pkgId, 'mops.toml'));
24
+ let depConfig = readConfig(path.join(rootDir, '.mops', pkgId, 'mops.toml'));
24
25
  let moc = depConfig.requirements?.moc;
25
26
  if (moc) {
26
27
  let requiredMoc = new SemVer(moc);
package/dist/cli.js CHANGED
@@ -1,3 +1,4 @@
1
+ import process from 'node:process';
1
2
  import fs from 'node:fs';
2
3
  import { Command, Argument, Option } from 'commander';
3
4
  import chalk from 'chalk';
@@ -8,7 +9,7 @@ import { sources } from './commands/sources.js';
8
9
  import { checkApiCompatibility, setNetwork, apiVersion, checkConfigFile, getNetworkFile, version } from './mops.js';
9
10
  import { getNetwork } from './api/network.js';
10
11
  import { whoami } from './commands/whoami.js';
11
- import { installAll } from './commands/install-all.js';
12
+ import { installAll } from './commands/install/install-all.js';
12
13
  import { search } from './commands/search.js';
13
14
  import { add } from './commands/add.js';
14
15
  import { cacheSize, cleanCache } from './cache.js';
@@ -90,8 +91,11 @@ program
90
91
  await add(pkg, options);
91
92
  }
92
93
  else {
93
- await installAll(options);
94
+ let ok = await installAll(options);
94
95
  await toolchain.installAll(options);
96
+ if (!ok) {
97
+ process.exit(1);
98
+ }
95
99
  }
96
100
  });
97
101
  // publish
@@ -145,7 +149,7 @@ program
145
149
  if (!checkConfigFile()) {
146
150
  process.exit(1);
147
151
  }
148
- await installAll({ silent: true, lock: 'ignore' });
152
+ await installAll({ silent: true, lock: 'ignore', threads: 6 });
149
153
  await toolchain.ensureToolchainInited({ strict: false });
150
154
  let sourcesArr = await sources(options);
151
155
  console.log(sourcesArr.join('\n'));
@@ -1,13 +1,15 @@
1
+ import process from 'node:process';
1
2
  import path from 'node:path';
2
3
  import chalk from 'chalk';
3
4
  import { createLogUpdate } from 'log-update';
4
5
  import { checkConfigFile, getGithubCommit, parseGithubURL, readConfig, writeConfig } from '../mops.js';
5
6
  import { getHighestVersion } from '../api/getHighestVersion.js';
7
+ import { installMopsDep } from './install/install-mops-dep.js';
6
8
  import { installFromGithub } from '../vessel.js';
7
- import { install } from './install.js';
8
- import { notifyInstalls } from '../notify-installs.js';
9
9
  import { checkIntegrity } from '../integrity.js';
10
10
  import { checkRequirements } from '../check-requirements.js';
11
+ import { syncLocalCache } from './install/sync-local-cache.js';
12
+ import { notifyInstalls } from '../notify-installs.js';
11
13
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
12
14
  export async function add(name, { verbose = false, dev = false, lock } = {}, asName) {
13
15
  if (!checkConfigFile()) {
@@ -72,16 +74,14 @@ export async function add(name, { verbose = false, dev = false, lock } = {}, asN
72
74
  version: ver,
73
75
  };
74
76
  }
75
- let installedPackages = {};
76
77
  if (pkgDetails.repo) {
77
78
  await installFromGithub(pkgDetails.name, pkgDetails.repo, { verbose: verbose });
78
79
  }
79
80
  else if (!pkgDetails.path) {
80
- let res = await install(pkgDetails.name, pkgDetails.version, { verbose: verbose });
81
+ let res = await installMopsDep(pkgDetails.name, pkgDetails.version, { verbose: verbose });
81
82
  if (res === false) {
82
83
  return;
83
84
  }
84
- installedPackages = { ...installedPackages, ...res };
85
85
  }
86
86
  const depsProp = dev ? 'dev-dependencies' : 'dependencies';
87
87
  let deps = config[depsProp];
@@ -96,8 +96,9 @@ export async function add(name, { verbose = false, dev = false, lock } = {}, asN
96
96
  if (lock !== 'ignore') {
97
97
  logUpdate('Checking integrity...');
98
98
  }
99
+ let installedPackages = await syncLocalCache();
99
100
  await Promise.all([
100
- notifyInstalls(Object.keys(installedPackages)),
101
+ notifyInstalls(installedPackages),
101
102
  checkIntegrity(lock),
102
103
  ]);
103
104
  logUpdate.clear();
@@ -1,3 +1,4 @@
1
+ import process from 'node:process';
1
2
  import chalk from 'chalk';
2
3
  import { mainActor } from '../api/actors.js';
3
4
  // [pkg, oldVersion, newVersion]
@@ -1,3 +1,4 @@
1
+ import process from 'node:process';
1
2
  import { execSync } 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 prompts from 'prompts';
2
3
  import chalk from 'chalk';
3
4
  import { checkConfigFile, readConfig, writeConfig } from '../mops.js';
@@ -1,3 +1,4 @@
1
+ import process from 'node:process';
1
2
  import { spawn } from 'node:child_process';
2
3
  import fs from 'node:fs';
3
4
  import path from 'node:path';
@@ -1,5 +1,6 @@
1
1
  import fs from 'node:fs';
2
2
  import path from 'node:path';
3
+ import { Buffer } from 'node:buffer';
3
4
  import chalk from 'chalk';
4
5
  import prompts from 'prompts';
5
6
  import { deleteSync } from 'del';
@@ -1,3 +1,4 @@
1
+ import process from 'node:process';
1
2
  import { execSync } from 'node:child_process';
2
3
  import path from 'node:path';
3
4
  import { existsSync, readFileSync, writeFileSync } from 'node:fs';
@@ -5,7 +6,7 @@ import chalk from 'chalk';
5
6
  import prompts from 'prompts';
6
7
  import { checkApiCompatibility, writeConfig } from '../mops.js';
7
8
  import { mainActor } from '../api/actors.js';
8
- import { installAll } from './install-all.js';
9
+ import { installAll } from './install/install-all.js';
9
10
  import { readVesselConfig } from '../vessel.js';
10
11
  import { template } from './template.js';
11
12
  export async function init({ yes = false } = {}) {
@@ -0,0 +1,8 @@
1
+ type InstallAllOptions = {
2
+ verbose?: boolean;
3
+ silent?: boolean;
4
+ lock?: 'check' | 'update' | 'ignore';
5
+ threads?: number;
6
+ };
7
+ export declare function installAll({ verbose, silent, threads, lock }?: InstallAllOptions): Promise<boolean>;
8
+ export {};
@@ -0,0 +1,37 @@
1
+ import process from 'node:process';
2
+ import chalk from 'chalk';
3
+ import { createLogUpdate } from 'log-update';
4
+ import { checkConfigFile, readConfig } from '../../mops.js';
5
+ import { checkIntegrity } from '../../integrity.js';
6
+ import { installDeps } from './install-deps.js';
7
+ import { checkRequirements } from '../../check-requirements.js';
8
+ import { syncLocalCache } from './sync-local-cache.js';
9
+ import { notifyInstalls } from '../../notify-installs.js';
10
+ export async function installAll({ verbose = false, silent = false, threads, lock } = {}) {
11
+ if (!checkConfigFile()) {
12
+ return false;
13
+ }
14
+ let config = readConfig();
15
+ let deps = Object.values(config.dependencies || {});
16
+ let devDeps = Object.values(config['dev-dependencies'] || {});
17
+ let allDeps = [...deps, ...devDeps];
18
+ let ok = await installDeps(allDeps, { silent, verbose, threads });
19
+ if (!ok) {
20
+ return false;
21
+ }
22
+ let logUpdate = createLogUpdate(process.stdout, { showCursor: true });
23
+ if (!silent && lock !== 'ignore') {
24
+ logUpdate('Checking integrity...');
25
+ }
26
+ let installedPackages = await syncLocalCache();
27
+ await Promise.all([
28
+ notifyInstalls(installedPackages),
29
+ checkIntegrity(lock),
30
+ ]);
31
+ if (!silent) {
32
+ logUpdate.clear();
33
+ await checkRequirements();
34
+ console.log(chalk.green('Packages installed'));
35
+ }
36
+ return true;
37
+ }
@@ -0,0 +1,8 @@
1
+ import { Dependency } from '../../types.js';
2
+ type InstallDepOptions = {
3
+ verbose?: boolean;
4
+ silent?: boolean;
5
+ threads?: number;
6
+ };
7
+ export declare function installDep(dep: Dependency, { verbose, silent, threads }?: InstallDepOptions, parentPkgPath?: string): Promise<boolean>;
8
+ export {};
@@ -0,0 +1,25 @@
1
+ import path from 'node:path';
2
+ import { installFromGithub } from '../../vessel.js';
3
+ import { installMopsDep } from './install-mops-dep.js';
4
+ import { installLocalDep } from './install-local-dep.js';
5
+ import { getRootDir } from '../../mops.js';
6
+ // install dependency
7
+ // returns false if failed
8
+ export async function installDep(dep, { verbose, silent, threads } = {}, parentPkgPath) {
9
+ if (dep.repo) {
10
+ await installFromGithub(dep.name, dep.repo, { silent, verbose });
11
+ return true;
12
+ }
13
+ else if (dep.path) {
14
+ let depPath = dep.path;
15
+ parentPkgPath = parentPkgPath || getRootDir();
16
+ if (parentPkgPath) {
17
+ depPath = path.resolve(parentPkgPath, dep.path);
18
+ }
19
+ return installLocalDep(dep.name, depPath, { silent, verbose });
20
+ }
21
+ else if (dep.version) {
22
+ return installMopsDep(dep.name, dep.version, { silent, verbose, threads });
23
+ }
24
+ return true;
25
+ }
@@ -0,0 +1,8 @@
1
+ import { Dependency } from '../../types.js';
2
+ type InstallDepsOptions = {
3
+ verbose?: boolean;
4
+ silent?: boolean;
5
+ threads?: number;
6
+ };
7
+ export declare function installDeps(deps: Dependency[], { verbose, silent, threads }?: InstallDepsOptions, parentPkgPath?: string): Promise<boolean>;
8
+ export {};
@@ -0,0 +1,14 @@
1
+ import { installDep } from './install-dep.js';
2
+ // install all dependencies
3
+ // returns actual installed dependencies
4
+ // returns false if failed
5
+ export async function installDeps(deps, { verbose, silent, threads } = {}, parentPkgPath) {
6
+ let ok = true;
7
+ for (const dep of deps) {
8
+ let res = await installDep(dep, { verbose, silent, threads }, parentPkgPath);
9
+ if (!res) {
10
+ ok = false;
11
+ }
12
+ }
13
+ return ok;
14
+ }
@@ -0,0 +1,6 @@
1
+ type InstallLocalDepOptions = {
2
+ verbose?: boolean;
3
+ silent?: boolean;
4
+ };
5
+ export declare function installLocalDep(pkg: string, pkgPath?: string, { verbose, silent }?: InstallLocalDepOptions): Promise<boolean>;
6
+ export {};
@@ -0,0 +1,23 @@
1
+ import process from 'node:process';
2
+ import path from 'node:path';
3
+ import { createLogUpdate } from 'log-update';
4
+ import { getRootDir, readConfig } from '../../mops.js';
5
+ import { installDeps } from './install-deps.js';
6
+ // skip install and just find non-local dependencies to install
7
+ // pkgPath should be relative to the current root dir or absolute
8
+ export async function installLocalDep(pkg, pkgPath = '', { verbose, silent } = {}) {
9
+ if (!silent) {
10
+ let logUpdate = createLogUpdate(process.stdout, { showCursor: true });
11
+ logUpdate(`Local dependency ${pkg} = "${pkgPath}"`);
12
+ if (verbose) {
13
+ silent || logUpdate.done();
14
+ }
15
+ else {
16
+ logUpdate.clear();
17
+ }
18
+ }
19
+ // install dependencies
20
+ let dir = path.resolve(getRootDir(), pkgPath);
21
+ let config = readConfig(path.join(dir, 'mops.toml'));
22
+ return installDeps(Object.values(config.dependencies || {}), { silent, verbose }, pkgPath);
23
+ }
@@ -0,0 +1,8 @@
1
+ type InstallMopsDepOptions = {
2
+ verbose?: boolean;
3
+ silent?: boolean;
4
+ dep?: boolean;
5
+ threads?: number;
6
+ };
7
+ export declare function installMopsDep(pkg: string, version?: string, { verbose, silent, dep, threads }?: InstallMopsDepOptions): Promise<boolean>;
8
+ export {};
@@ -0,0 +1,97 @@
1
+ import process from 'node:process';
2
+ import fs from 'node:fs';
3
+ import path from 'node:path';
4
+ import { Buffer } from 'node:buffer';
5
+ import { createLogUpdate } from 'log-update';
6
+ import chalk from 'chalk';
7
+ import { deleteSync } from 'del';
8
+ import { checkConfigFile, progressBar, readConfig } from '../../mops.js';
9
+ import { getHighestVersion } from '../../api/getHighestVersion.js';
10
+ import { storageActor } from '../../api/actors.js';
11
+ import { parallel } from '../../parallel.js';
12
+ import { getDepCacheDir, getMopsDepCacheName, isDepCached } from '../../cache.js';
13
+ import { downloadFile, getPackageFilesInfo } from '../../api/downloadPackageFiles.js';
14
+ import { installDeps } from './install-deps.js';
15
+ export async function installMopsDep(pkg, version = '', { verbose, silent, dep, threads } = {}) {
16
+ threads = threads || 12;
17
+ if (!checkConfigFile()) {
18
+ return false;
19
+ }
20
+ let logUpdate = createLogUpdate(process.stdout, { showCursor: true });
21
+ // progress
22
+ let total = Infinity;
23
+ let step = 0;
24
+ let progress = () => {
25
+ step++;
26
+ silent || logUpdate(`${dep ? 'Dependency' : 'Installing'} ${pkg}@${version} ${progressBar(step, total)}`);
27
+ };
28
+ progress();
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
+ let cacheName = getMopsDepCacheName(pkg, version);
38
+ let cacheDir = getDepCacheDir(cacheName);
39
+ // global cache hit
40
+ if (isDepCached(cacheName)) {
41
+ silent || logUpdate(`${dep ? 'Dependency' : 'Installing'} ${pkg}@${version} (cache)`);
42
+ }
43
+ // download
44
+ else {
45
+ // GitHub Actions fails with "fetch failed" if there are multiple concurrent actions
46
+ if (process.env.GITHUB_ENV) {
47
+ threads = 4;
48
+ }
49
+ try {
50
+ let { storageId, fileIds } = await getPackageFilesInfo(pkg, version);
51
+ total = fileIds.length + 2;
52
+ let filesData = new Map;
53
+ let storage = await storageActor(storageId);
54
+ await parallel(threads, fileIds, async (fileId) => {
55
+ let { path, data } = await downloadFile(storage, fileId);
56
+ filesData.set(path, data);
57
+ progress();
58
+ });
59
+ let onSigInt = () => {
60
+ deleteSync([cacheDir], { force: true });
61
+ process.exit();
62
+ };
63
+ process.on('SIGINT', onSigInt);
64
+ // write files to global cache
65
+ try {
66
+ await Promise.all(Array.from(filesData.entries()).map(async ([filePath, data]) => {
67
+ await fs.promises.mkdir(path.join(cacheDir, path.dirname(filePath)), { recursive: true });
68
+ await fs.promises.writeFile(path.join(cacheDir, filePath), Buffer.from(data));
69
+ }));
70
+ }
71
+ catch (err) {
72
+ console.error(chalk.red('Error: ') + err);
73
+ deleteSync([cacheDir], { force: true });
74
+ return false;
75
+ }
76
+ process.off('SIGINT', onSigInt);
77
+ }
78
+ catch (err) {
79
+ console.error(chalk.red('Error: ') + err);
80
+ return false;
81
+ }
82
+ progress();
83
+ }
84
+ if (verbose) {
85
+ silent || logUpdate.done();
86
+ }
87
+ else {
88
+ logUpdate.clear();
89
+ }
90
+ // install dependencies
91
+ let config = readConfig(path.join(cacheDir, 'mops.toml'));
92
+ let res = await installDeps(Object.values(config.dependencies || {}), { silent, verbose });
93
+ if (!res) {
94
+ return false;
95
+ }
96
+ return true;
97
+ }
@@ -0,0 +1,3 @@
1
+ export declare function syncLocalCache({ verbose }?: {
2
+ verbose?: boolean | undefined;
3
+ }): Promise<Record<string, string>>;
@@ -0,0 +1,26 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { copyCache, getDepCacheName } from '../../cache.js';
4
+ import { getDependencyType, getRootDir } from '../../mops.js';
5
+ import { resolvePackages } from '../../resolve-packages.js';
6
+ export async function syncLocalCache({ verbose = false } = {}) {
7
+ let resolvedPackages = await resolvePackages();
8
+ let rootDir = getRootDir();
9
+ verbose && console.log('Syncing local cache...');
10
+ let installedDeps = {};
11
+ await Promise.all(Object.entries(resolvedPackages).map(([name, value]) => {
12
+ let depType = getDependencyType(value);
13
+ if (depType === 'mops' || depType === 'github') {
14
+ let cacheName = getDepCacheName(name, value);
15
+ let dest = path.join(rootDir, '.mops', cacheName);
16
+ if (!fs.existsSync(dest)) {
17
+ if (depType === 'mops') {
18
+ installedDeps[name] = value;
19
+ }
20
+ return copyCache(cacheName, path.join(rootDir, '.mops', cacheName));
21
+ }
22
+ }
23
+ return Promise.resolve();
24
+ }));
25
+ return installedDeps;
26
+ }
@@ -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 chalk from 'chalk';