ic-mops 0.41.1 → 0.42.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 (106) hide show
  1. package/.DS_Store +0 -0
  2. package/CHANGELOG.md +12 -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/cli.ts +3 -2
  11. package/commands/add.ts +9 -7
  12. package/commands/available-updates.ts +1 -0
  13. package/commands/bench-replica.ts +1 -0
  14. package/commands/bench.ts +1 -0
  15. package/commands/bump.ts +1 -0
  16. package/commands/docs.ts +1 -0
  17. package/commands/import-identity.ts +1 -0
  18. package/commands/init.ts +2 -1
  19. package/commands/install/install-all.ts +51 -0
  20. package/commands/install/install-dep.ts +34 -0
  21. package/commands/install/install-deps.ts +31 -0
  22. package/commands/install/install-local-dep.ts +31 -0
  23. package/commands/{install.ts → install/install-mops-dep.ts} +43 -43
  24. package/commands/install/sync-local-cache.ts +34 -0
  25. package/commands/publish.ts +1 -0
  26. package/commands/remove.ts +15 -18
  27. package/commands/search.ts +1 -0
  28. package/commands/self.ts +1 -0
  29. package/commands/sources.ts +1 -0
  30. package/commands/sync.ts +1 -0
  31. package/commands/test/test.ts +1 -0
  32. package/commands/toolchain/index.ts +1 -0
  33. package/commands/toolchain/moc.ts +1 -0
  34. package/commands/toolchain/pocket-ic.ts +1 -0
  35. package/commands/toolchain/toolchain-utils.ts +2 -0
  36. package/commands/toolchain/wasmtime.ts +1 -0
  37. package/commands/transfer-ownership.ts +1 -0
  38. package/commands/user.ts +1 -0
  39. package/declarations/bench/index.js +0 -8
  40. package/declarations/storage/storage.did.d.ts +3 -0
  41. package/dist/api/actors.js +2 -2
  42. package/dist/cache.d.ts +7 -3
  43. package/dist/cache.js +21 -7
  44. package/dist/cli.js +3 -2
  45. package/dist/commands/add.js +7 -6
  46. package/dist/commands/available-updates.js +1 -0
  47. package/dist/commands/bench-replica.js +1 -0
  48. package/dist/commands/bench.js +1 -0
  49. package/dist/commands/bump.js +1 -0
  50. package/dist/commands/docs.js +1 -0
  51. package/dist/commands/import-identity.js +1 -0
  52. package/dist/commands/init.js +2 -1
  53. package/dist/commands/install/install-all.d.ts +8 -0
  54. package/dist/commands/install/install-all.js +36 -0
  55. package/dist/commands/install/install-dep.d.ts +8 -0
  56. package/dist/commands/install/install-dep.js +25 -0
  57. package/dist/commands/install/install-deps.d.ts +8 -0
  58. package/dist/commands/install/install-deps.js +21 -0
  59. package/dist/commands/install/install-local-dep.d.ts +6 -0
  60. package/dist/commands/install/install-local-dep.js +23 -0
  61. package/dist/commands/install/install-mops-dep.d.ts +8 -0
  62. package/dist/commands/install/install-mops-dep.js +103 -0
  63. package/dist/commands/install/sync-local-cache.d.ts +3 -0
  64. package/dist/commands/install/sync-local-cache.js +26 -0
  65. package/dist/commands/publish.js +1 -0
  66. package/dist/commands/remove.js +15 -18
  67. package/dist/commands/search.js +1 -0
  68. package/dist/commands/self.js +1 -0
  69. package/dist/commands/sources.js +1 -0
  70. package/dist/commands/sync.js +1 -0
  71. package/dist/commands/test/test.js +1 -0
  72. package/dist/commands/toolchain/index.js +1 -0
  73. package/dist/commands/toolchain/moc.js +1 -0
  74. package/dist/commands/toolchain/pocket-ic.js +1 -0
  75. package/dist/commands/toolchain/toolchain-utils.js +2 -0
  76. package/dist/commands/toolchain/wasmtime.js +1 -0
  77. package/dist/commands/transfer-ownership.js +1 -0
  78. package/dist/commands/user.js +1 -0
  79. package/dist/declarations/bench/index.js +0 -8
  80. package/dist/declarations/storage/storage.did.d.ts +3 -0
  81. package/dist/fix-dist.d.ts +1 -0
  82. package/dist/fix-dist.js +9 -0
  83. package/dist/helpers/get-moc-path.js +1 -0
  84. package/dist/integrity.js +1 -0
  85. package/dist/mops.js +3 -2
  86. package/dist/notify-installs.d.ts +1 -1
  87. package/dist/notify-installs.js +8 -5
  88. package/dist/package.json +5 -5
  89. package/dist/pem.d.ts +1 -0
  90. package/dist/pem.js +2 -1
  91. package/dist/release-cli.js +0 -4
  92. package/dist/resolve-packages.js +11 -9
  93. package/dist/vessel.js +10 -12
  94. package/{remove-scripts.ts → fix-dist.ts} +6 -0
  95. package/helpers/get-moc-path.ts +1 -0
  96. package/integrity.ts +1 -0
  97. package/mops.ts +3 -2
  98. package/notify-installs.ts +9 -5
  99. package/package.json +5 -5
  100. package/pem.ts +2 -1
  101. package/release-cli.ts +0 -5
  102. package/resolve-packages.ts +11 -9
  103. package/tsconfig.json +1 -0
  104. package/vessel.ts +11 -13
  105. package/commands/install-all.ts +0 -58
  106. package/commands/install-local.ts +0 -52
@@ -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) => {
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';
@@ -145,7 +146,7 @@ program
145
146
  if (!checkConfigFile()) {
146
147
  process.exit(1);
147
148
  }
148
- await installAll({ silent: true, lock: 'ignore' });
149
+ await installAll({ silent: true, lock: 'ignore', threads: 6 });
149
150
  await toolchain.ensureToolchainInited({ strict: false });
150
151
  let sourcesArr = await sources(options);
151
152
  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<void>;
8
+ export {};
@@ -0,0 +1,36 @@
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;
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 res = await installDeps(allDeps, { silent, verbose, threads });
19
+ if (!res) {
20
+ return;
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
+ }
@@ -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<Record<string, string> | false>;
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 {};
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 {};
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<Record<string, string> | false>;
8
+ export {};
@@ -0,0 +1,21 @@
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 installedDeps = {};
7
+ let ok = true;
8
+ for (const dep of deps) {
9
+ let res = await installDep(dep, { verbose, silent, threads }, parentPkgPath);
10
+ if (res) {
11
+ installedDeps = { ...installedDeps, ...res };
12
+ }
13
+ else {
14
+ ok = false;
15
+ }
16
+ }
17
+ if (!ok) {
18
+ return false;
19
+ }
20
+ return installedDeps;
21
+ }
@@ -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<Record<string, string> | false>;
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<Record<string, string> | false>;
8
+ export {};
@@ -0,0 +1,103 @@
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, formatDir, 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 dir = formatDir(pkg, version);
38
+ let cacheName = getMopsDepCacheName(pkg, version);
39
+ let cacheDir = getDepCacheDir(cacheName);
40
+ let alreadyInstalled = false;
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 (isDepCached(cacheName)) {
48
+ silent || logUpdate(`${dep ? 'Dependency' : 'Installing'} ${pkg}@${version} (global cache)`);
49
+ }
50
+ // download
51
+ else {
52
+ // GitHub Actions fails with "fetch failed" if there are multiple concurrent actions
53
+ if (process.env.GITHUB_ENV) {
54
+ threads = 4;
55
+ }
56
+ try {
57
+ let { storageId, fileIds } = await getPackageFilesInfo(pkg, version);
58
+ total = fileIds.length + 2;
59
+ let filesData = new Map;
60
+ let storage = await storageActor(storageId);
61
+ await parallel(threads, fileIds, async (fileId) => {
62
+ let { path, data } = await downloadFile(storage, fileId);
63
+ filesData.set(path, data);
64
+ progress();
65
+ });
66
+ // write files to global cache
67
+ try {
68
+ for (let [filePath, data] of filesData.entries()) {
69
+ fs.mkdirSync(path.join(cacheDir, path.dirname(filePath)), { recursive: true });
70
+ fs.writeFileSync(path.join(cacheDir, filePath), Buffer.from(data));
71
+ }
72
+ }
73
+ catch (err) {
74
+ console.error(chalk.red('Error: ') + err);
75
+ deleteSync([cacheDir], { force: true });
76
+ return false;
77
+ }
78
+ }
79
+ catch (err) {
80
+ console.error(chalk.red('Error: ') + err);
81
+ return false;
82
+ }
83
+ progress();
84
+ }
85
+ if (verbose) {
86
+ silent || logUpdate.done();
87
+ }
88
+ else {
89
+ logUpdate.clear();
90
+ }
91
+ // install dependencies
92
+ let config = readConfig(path.join(cacheDir, 'mops.toml'));
93
+ let res = await installDeps(Object.values(config.dependencies || {}), { silent, verbose });
94
+ if (!res) {
95
+ return false;
96
+ }
97
+ let installedDeps = res;
98
+ // add self to installed deps
99
+ if (!alreadyInstalled) {
100
+ installedDeps = { ...installedDeps, [pkg]: version };
101
+ }
102
+ return installedDeps;
103
+ }
@@ -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';
@@ -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';