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.
- package/.DS_Store +0 -0
- package/CHANGELOG.md +14 -0
- package/api/actors.ts +2 -3
- package/bundle/cli.js +29 -29
- package/bundle/cli.tgz +0 -0
- package/bundle/declarations/bench/index.js +0 -8
- package/bundle/declarations/storage/storage.did.d.ts +3 -0
- package/bundle/package.json +2 -2
- package/cache.ts +25 -7
- package/check-requirements.ts +3 -2
- package/cli.ts +7 -3
- package/commands/add.ts +9 -7
- package/commands/available-updates.ts +1 -0
- package/commands/bench-replica.ts +1 -0
- package/commands/bench.ts +1 -0
- package/commands/bump.ts +1 -0
- package/commands/docs.ts +1 -0
- package/commands/import-identity.ts +1 -0
- package/commands/init.ts +2 -1
- package/commands/install/install-all.ts +53 -0
- package/commands/install/install-dep.ts +34 -0
- package/commands/install/install-deps.ts +24 -0
- package/commands/install/install-local-dep.ts +31 -0
- package/commands/install/install-mops-dep.ts +122 -0
- package/commands/install/sync-local-cache.ts +34 -0
- package/commands/publish.ts +1 -0
- package/commands/remove.ts +15 -18
- package/commands/search.ts +1 -0
- package/commands/self.ts +1 -0
- package/commands/sources.ts +1 -0
- package/commands/sync.ts +1 -0
- package/commands/test/test.ts +1 -0
- package/commands/toolchain/index.ts +1 -0
- package/commands/toolchain/moc.ts +1 -0
- package/commands/toolchain/pocket-ic.ts +1 -0
- package/commands/toolchain/toolchain-utils.ts +2 -0
- package/commands/toolchain/wasmtime.ts +1 -0
- package/commands/transfer-ownership.ts +1 -0
- package/commands/user.ts +1 -0
- package/declarations/bench/index.js +0 -8
- package/declarations/storage/storage.did.d.ts +3 -0
- package/dist/api/actors.js +2 -2
- package/dist/cache.d.ts +7 -3
- package/dist/cache.js +21 -7
- package/dist/check-requirements.js +3 -2
- package/dist/cli.js +7 -3
- package/dist/commands/add.js +7 -6
- package/dist/commands/available-updates.js +1 -0
- package/dist/commands/bench-replica.js +1 -0
- package/dist/commands/bench.js +1 -0
- package/dist/commands/bump.js +1 -0
- package/dist/commands/docs.js +1 -0
- package/dist/commands/import-identity.js +1 -0
- package/dist/commands/init.js +2 -1
- package/dist/commands/install/install-all.d.ts +8 -0
- package/dist/commands/install/install-all.js +37 -0
- package/dist/commands/install/install-dep.d.ts +8 -0
- package/dist/commands/install/install-dep.js +25 -0
- package/dist/commands/install/install-deps.d.ts +8 -0
- package/dist/commands/install/install-deps.js +14 -0
- package/dist/commands/install/install-local-dep.d.ts +6 -0
- package/dist/commands/install/install-local-dep.js +23 -0
- package/dist/commands/install/install-mops-dep.d.ts +8 -0
- package/dist/commands/install/install-mops-dep.js +97 -0
- package/dist/commands/install/sync-local-cache.d.ts +3 -0
- package/dist/commands/install/sync-local-cache.js +26 -0
- package/dist/commands/publish.js +1 -0
- package/dist/commands/remove.js +15 -18
- package/dist/commands/search.js +1 -0
- package/dist/commands/self.js +1 -0
- package/dist/commands/sources.js +1 -0
- package/dist/commands/sync.js +1 -0
- package/dist/commands/test/test.js +1 -0
- package/dist/commands/toolchain/index.js +1 -0
- package/dist/commands/toolchain/moc.js +1 -0
- package/dist/commands/toolchain/pocket-ic.js +1 -0
- package/dist/commands/toolchain/toolchain-utils.js +2 -0
- package/dist/commands/toolchain/wasmtime.js +1 -0
- package/dist/commands/transfer-ownership.js +1 -0
- package/dist/commands/user.js +1 -0
- package/dist/declarations/bench/index.js +0 -8
- package/dist/declarations/storage/storage.did.d.ts +3 -0
- package/dist/fix-dist.d.ts +1 -0
- package/dist/fix-dist.js +9 -0
- package/dist/helpers/get-moc-path.js +1 -0
- package/dist/integrity.js +1 -0
- package/dist/mops.js +3 -2
- package/dist/notify-installs.d.ts +1 -1
- package/dist/notify-installs.js +8 -5
- package/dist/package.json +5 -5
- package/dist/pem.d.ts +1 -0
- package/dist/pem.js +2 -1
- package/dist/release-cli.js +0 -4
- package/dist/resolve-packages.js +11 -9
- package/dist/vessel.js +11 -16
- package/{remove-scripts.ts → fix-dist.ts} +6 -0
- package/helpers/get-moc-path.ts +1 -0
- package/integrity.ts +1 -0
- package/mops.ts +3 -2
- package/notify-installs.ts +9 -5
- package/package.json +5 -5
- package/pem.ts +2 -1
- package/release-cli.ts +0 -5
- package/resolve-packages.ts +11 -9
- package/tsconfig.json +1 -0
- package/vessel.ts +12 -18
- package/commands/install-all.ts +0 -58
- package/commands/install-local.ts +0 -52
- package/commands/install.ts +0 -126
package/bundle/cli.tgz
CHANGED
|
Binary file
|
|
@@ -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[];
|
package/bundle/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ic-mops",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.42.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"bin": {
|
|
6
6
|
"mops": "bin/mops.js",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"node": ">=18.0.0"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"dhall-to-json-cli": "
|
|
27
|
+
"dhall-to-json-cli": "1.7.6",
|
|
28
28
|
"decomp-tarxz": "0.1.1",
|
|
29
29
|
"buffer": "6.0.3"
|
|
30
30
|
}
|
package/cache.ts
CHANGED
|
@@ -3,15 +3,33 @@ import path from 'node:path';
|
|
|
3
3
|
import ncp from 'ncp';
|
|
4
4
|
import getFolderSize from 'get-folder-size';
|
|
5
5
|
|
|
6
|
-
import {globalCacheDir} from './mops.js';
|
|
6
|
+
import {getDependencyType, globalCacheDir, parseGithubURL} from './mops.js';
|
|
7
7
|
|
|
8
|
-
export let
|
|
9
|
-
|
|
8
|
+
export let getDepCacheDir = (cacheName : string) => {
|
|
9
|
+
return path.join(globalCacheDir, 'packages', cacheName);
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export let isDepCached = (cacheName : string) => {
|
|
13
|
+
let dir = getDepCacheDir(cacheName);
|
|
10
14
|
return fs.existsSync(dir);
|
|
11
15
|
};
|
|
12
16
|
|
|
13
|
-
export
|
|
14
|
-
let
|
|
17
|
+
export function getDepCacheName(name : string, version : string) {
|
|
18
|
+
let depType = getDependencyType(version);
|
|
19
|
+
return depType === 'mops' ? getMopsDepCacheName(name, version) : getGithubDepCacheName(name, version);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function getMopsDepCacheName(name : string, version : string) {
|
|
23
|
+
return `${name}@${version}`;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function getGithubDepCacheName(name : string, repo : string) {
|
|
27
|
+
const {branch, commitHash} = parseGithubURL(repo);
|
|
28
|
+
return `_github/${name}#${branch}` + (commitHash ? `@${commitHash}` : '');
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export let addCache = (cacheName : string, source : string) => {
|
|
32
|
+
let dest = path.join(globalCacheDir, 'packages', cacheName);
|
|
15
33
|
fs.mkdirSync(dest, {recursive: true});
|
|
16
34
|
|
|
17
35
|
return new Promise<void>((resolve, reject) => {
|
|
@@ -24,8 +42,8 @@ export let addCache = (pkgId : string, source : string) => {
|
|
|
24
42
|
});
|
|
25
43
|
};
|
|
26
44
|
|
|
27
|
-
export let copyCache = (
|
|
28
|
-
let source = path.join(globalCacheDir, 'packages',
|
|
45
|
+
export let copyCache = (cacheName : string, dest : string) => {
|
|
46
|
+
let source = path.join(globalCacheDir, 'packages', cacheName);
|
|
29
47
|
fs.mkdirSync(dest, {recursive: true});
|
|
30
48
|
|
|
31
49
|
return new Promise<void>((resolve, reject) => {
|
package/check-requirements.ts
CHANGED
|
@@ -2,7 +2,7 @@ import path from 'node:path';
|
|
|
2
2
|
import {SemVer} from 'semver';
|
|
3
3
|
import chalk from 'chalk';
|
|
4
4
|
|
|
5
|
-
import {getDependencyType, readConfig} from './mops.js';
|
|
5
|
+
import {getDependencyType, getRootDir, readConfig} from './mops.js';
|
|
6
6
|
import {resolvePackages} from './resolve-packages.js';
|
|
7
7
|
import {getMocVersion} from './helpers/get-moc-version.js';
|
|
8
8
|
|
|
@@ -18,12 +18,13 @@ export async function checkRequirements({verbose = false} = {}) {
|
|
|
18
18
|
let installedMoc = new SemVer(mocVersion);
|
|
19
19
|
let highestRequiredMoc = new SemVer('0.0.0');
|
|
20
20
|
let highestRequiredMocPkgId = '';
|
|
21
|
+
let rootDir = getRootDir();
|
|
21
22
|
|
|
22
23
|
let resolvedPackages = await resolvePackages();
|
|
23
24
|
for (let [name, version] of Object.entries(resolvedPackages)) {
|
|
24
25
|
if (getDependencyType(version) === 'mops') {
|
|
25
26
|
let pkgId = `${name}@${version}`;
|
|
26
|
-
let depConfig = readConfig(path.join('.mops', pkgId, 'mops.toml'));
|
|
27
|
+
let depConfig = readConfig(path.join(rootDir, '.mops', pkgId, 'mops.toml'));
|
|
27
28
|
let moc = depConfig.requirements?.moc;
|
|
28
29
|
|
|
29
30
|
if (moc) {
|
package/cli.ts
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';
|
|
@@ -9,7 +10,7 @@ import {sources} from './commands/sources.js';
|
|
|
9
10
|
import {checkApiCompatibility, setNetwork, apiVersion, checkConfigFile, getNetworkFile, version} from './mops.js';
|
|
10
11
|
import {getNetwork} from './api/network.js';
|
|
11
12
|
import {whoami} from './commands/whoami.js';
|
|
12
|
-
import {installAll} from './commands/install-all.js';
|
|
13
|
+
import {installAll} from './commands/install/install-all.js';
|
|
13
14
|
import {search} from './commands/search.js';
|
|
14
15
|
import {add} from './commands/add.js';
|
|
15
16
|
import {cacheSize, cleanCache} from './cache.js';
|
|
@@ -109,8 +110,11 @@ program
|
|
|
109
110
|
await add(pkg, options);
|
|
110
111
|
}
|
|
111
112
|
else {
|
|
112
|
-
await installAll(options);
|
|
113
|
+
let ok = await installAll(options);
|
|
113
114
|
await toolchain.installAll(options);
|
|
115
|
+
if (!ok) {
|
|
116
|
+
process.exit(1);
|
|
117
|
+
}
|
|
114
118
|
}
|
|
115
119
|
});
|
|
116
120
|
|
|
@@ -169,7 +173,7 @@ program
|
|
|
169
173
|
if (!checkConfigFile()) {
|
|
170
174
|
process.exit(1);
|
|
171
175
|
}
|
|
172
|
-
await installAll({silent: true, lock: 'ignore'});
|
|
176
|
+
await installAll({silent: true, lock: 'ignore', threads: 6});
|
|
173
177
|
await toolchain.ensureToolchainInited({strict: false});
|
|
174
178
|
let sourcesArr = await sources(options);
|
|
175
179
|
console.log(sourcesArr.join('\n'));
|
package/commands/add.ts
CHANGED
|
@@ -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
|
|
|
12
14
|
type AddOptions = {
|
|
13
15
|
verbose ?: boolean;
|
|
@@ -86,17 +88,14 @@ export async function add(name : string, {verbose = false, dev = false, lock} :
|
|
|
86
88
|
};
|
|
87
89
|
}
|
|
88
90
|
|
|
89
|
-
let installedPackages = {};
|
|
90
|
-
|
|
91
91
|
if (pkgDetails.repo) {
|
|
92
92
|
await installFromGithub(pkgDetails.name, pkgDetails.repo, {verbose: verbose});
|
|
93
93
|
}
|
|
94
94
|
else if (!pkgDetails.path) {
|
|
95
|
-
let res = await
|
|
95
|
+
let res = await installMopsDep(pkgDetails.name, pkgDetails.version, {verbose: verbose});
|
|
96
96
|
if (res === false) {
|
|
97
97
|
return;
|
|
98
98
|
}
|
|
99
|
-
installedPackages = {...installedPackages, ...res};
|
|
100
99
|
}
|
|
101
100
|
|
|
102
101
|
const depsProp = dev ? 'dev-dependencies' : 'dependencies';
|
|
@@ -115,8 +114,11 @@ export async function add(name : string, {verbose = false, dev = false, lock} :
|
|
|
115
114
|
if (lock !== 'ignore') {
|
|
116
115
|
logUpdate('Checking integrity...');
|
|
117
116
|
}
|
|
117
|
+
|
|
118
|
+
let installedPackages = await syncLocalCache();
|
|
119
|
+
|
|
118
120
|
await Promise.all([
|
|
119
|
-
notifyInstalls(
|
|
121
|
+
notifyInstalls(installedPackages),
|
|
120
122
|
checkIntegrity(lock),
|
|
121
123
|
]);
|
|
122
124
|
|
package/commands/bench.ts
CHANGED
package/commands/bump.ts
CHANGED
package/commands/docs.ts
CHANGED
package/commands/init.ts
CHANGED
|
@@ -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';
|
|
@@ -6,7 +7,7 @@ import prompts from 'prompts';
|
|
|
6
7
|
|
|
7
8
|
import {checkApiCompatibility, writeConfig} from '../mops.js';
|
|
8
9
|
import {mainActor} from '../api/actors.js';
|
|
9
|
-
import {installAll} from './install-all.js';
|
|
10
|
+
import {installAll} from './install/install-all.js';
|
|
10
11
|
import {VesselConfig, readVesselConfig} from '../vessel.js';
|
|
11
12
|
import {Config, Dependencies} from '../types.js';
|
|
12
13
|
import {template} from './template.js';
|
|
@@ -0,0 +1,53 @@
|
|
|
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
|
+
|
|
11
|
+
type InstallAllOptions = {
|
|
12
|
+
verbose ?: boolean;
|
|
13
|
+
silent ?: boolean;
|
|
14
|
+
lock ?: 'check' | 'update' | 'ignore';
|
|
15
|
+
threads ?: number;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export async function installAll({verbose = false, silent = false, threads, lock} : InstallAllOptions = {}) : Promise<boolean> {
|
|
19
|
+
if (!checkConfigFile()) {
|
|
20
|
+
return false;
|
|
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
|
+
|
|
28
|
+
let ok = await installDeps(allDeps, {silent, verbose, threads});
|
|
29
|
+
if (!ok) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
let logUpdate = createLogUpdate(process.stdout, {showCursor: true});
|
|
34
|
+
|
|
35
|
+
if (!silent && lock !== 'ignore') {
|
|
36
|
+
logUpdate('Checking integrity...');
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
let installedPackages = await syncLocalCache();
|
|
40
|
+
|
|
41
|
+
await Promise.all([
|
|
42
|
+
notifyInstalls(installedPackages),
|
|
43
|
+
checkIntegrity(lock),
|
|
44
|
+
]);
|
|
45
|
+
|
|
46
|
+
if (!silent) {
|
|
47
|
+
logUpdate.clear();
|
|
48
|
+
await checkRequirements();
|
|
49
|
+
console.log(chalk.green('Packages installed'));
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import {installFromGithub} from '../../vessel.js';
|
|
3
|
+
import {installMopsDep} from './install-mops-dep.js';
|
|
4
|
+
import {Dependency} from '../../types.js';
|
|
5
|
+
import {installLocalDep} from './install-local-dep.js';
|
|
6
|
+
import {getRootDir} from '../../mops.js';
|
|
7
|
+
|
|
8
|
+
type InstallDepOptions = {
|
|
9
|
+
verbose ?: boolean;
|
|
10
|
+
silent ?: boolean;
|
|
11
|
+
threads ?: number;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
// install dependency
|
|
15
|
+
// returns false if failed
|
|
16
|
+
export async function installDep(dep : Dependency, {verbose, silent, threads} : InstallDepOptions = {}, parentPkgPath ?: string) : Promise<boolean> {
|
|
17
|
+
if (dep.repo) {
|
|
18
|
+
await installFromGithub(dep.name, dep.repo, {silent, verbose});
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
else if (dep.path) {
|
|
22
|
+
let depPath = dep.path;
|
|
23
|
+
parentPkgPath = parentPkgPath || getRootDir();
|
|
24
|
+
if (parentPkgPath) {
|
|
25
|
+
depPath = path.resolve(parentPkgPath, dep.path);
|
|
26
|
+
}
|
|
27
|
+
return installLocalDep(dep.name, depPath, {silent, verbose});
|
|
28
|
+
}
|
|
29
|
+
else if (dep.version) {
|
|
30
|
+
return installMopsDep(dep.name, dep.version, {silent, verbose, threads});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import {Dependency} from '../../types.js';
|
|
2
|
+
import {installDep} from './install-dep.js';
|
|
3
|
+
|
|
4
|
+
type InstallDepsOptions = {
|
|
5
|
+
verbose ?: boolean;
|
|
6
|
+
silent ?: boolean;
|
|
7
|
+
threads ?: number;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
// install all dependencies
|
|
11
|
+
// returns actual installed dependencies
|
|
12
|
+
// returns false if failed
|
|
13
|
+
export async function installDeps(deps : Dependency[], {verbose, silent, threads} : InstallDepsOptions = {}, parentPkgPath ?: string) : Promise<boolean> {
|
|
14
|
+
let ok = true;
|
|
15
|
+
|
|
16
|
+
for (const dep of deps) {
|
|
17
|
+
let res = await installDep(dep, {verbose, silent, threads}, parentPkgPath);
|
|
18
|
+
if (!res) {
|
|
19
|
+
ok = false;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return ok;
|
|
24
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
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
|
+
|
|
7
|
+
type InstallLocalDepOptions = {
|
|
8
|
+
verbose ?: boolean;
|
|
9
|
+
silent ?: boolean;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
// skip install and just find non-local dependencies to install
|
|
13
|
+
// pkgPath should be relative to the current root dir or absolute
|
|
14
|
+
export async function installLocalDep(pkg : string, pkgPath = '', {verbose, silent} : InstallLocalDepOptions = {}) : Promise<boolean> {
|
|
15
|
+
if (!silent) {
|
|
16
|
+
let logUpdate = createLogUpdate(process.stdout, {showCursor: true});
|
|
17
|
+
logUpdate(`Local dependency ${pkg} = "${pkgPath}"`);
|
|
18
|
+
|
|
19
|
+
if (verbose) {
|
|
20
|
+
silent || logUpdate.done();
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
logUpdate.clear();
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// install dependencies
|
|
28
|
+
let dir = path.resolve(getRootDir(), pkgPath);
|
|
29
|
+
let config = readConfig(path.join(dir, 'mops.toml'));
|
|
30
|
+
return installDeps(Object.values(config.dependencies || {}), {silent, verbose}, pkgPath);
|
|
31
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
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
|
+
|
|
16
|
+
type InstallMopsDepOptions = {
|
|
17
|
+
verbose ?: boolean;
|
|
18
|
+
silent ?: boolean;
|
|
19
|
+
dep ?: boolean;
|
|
20
|
+
threads ?: number;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export async function installMopsDep(pkg : string, version = '', {verbose, silent, dep, threads} : InstallMopsDepOptions = {}) : Promise<boolean> {
|
|
24
|
+
threads = threads || 12;
|
|
25
|
+
|
|
26
|
+
if (!checkConfigFile()) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
let logUpdate = createLogUpdate(process.stdout, {showCursor: true});
|
|
30
|
+
|
|
31
|
+
// progress
|
|
32
|
+
let total = Infinity;
|
|
33
|
+
let step = 0;
|
|
34
|
+
let progress = () => {
|
|
35
|
+
step++;
|
|
36
|
+
silent || logUpdate(`${dep ? 'Dependency' : 'Installing'} ${pkg}@${version} ${progressBar(step, total)}`);
|
|
37
|
+
};
|
|
38
|
+
progress();
|
|
39
|
+
|
|
40
|
+
if (!version) {
|
|
41
|
+
let versionRes = await getHighestVersion(pkg);
|
|
42
|
+
if ('err' in versionRes) {
|
|
43
|
+
console.log(chalk.red('Error: ') + versionRes.err);
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
version = versionRes.ok;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
let cacheName = getMopsDepCacheName(pkg, version);
|
|
50
|
+
let cacheDir = getDepCacheDir(cacheName);
|
|
51
|
+
|
|
52
|
+
// global cache hit
|
|
53
|
+
if (isDepCached(cacheName)) {
|
|
54
|
+
silent || logUpdate(`${dep ? 'Dependency' : 'Installing'} ${pkg}@${version} (cache)`);
|
|
55
|
+
}
|
|
56
|
+
// download
|
|
57
|
+
else {
|
|
58
|
+
// GitHub Actions fails with "fetch failed" if there are multiple concurrent actions
|
|
59
|
+
if (process.env.GITHUB_ENV) {
|
|
60
|
+
threads = 4;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
try {
|
|
64
|
+
let {storageId, fileIds} = await getPackageFilesInfo(pkg, version);
|
|
65
|
+
|
|
66
|
+
total = fileIds.length + 2;
|
|
67
|
+
|
|
68
|
+
let filesData = new Map;
|
|
69
|
+
let storage = await storageActor(storageId);
|
|
70
|
+
|
|
71
|
+
await parallel(threads, fileIds, async (fileId : string) => {
|
|
72
|
+
let {path, data} = await downloadFile(storage, fileId);
|
|
73
|
+
filesData.set(path, data);
|
|
74
|
+
progress();
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
let onSigInt = () => {
|
|
78
|
+
deleteSync([cacheDir], {force: true});
|
|
79
|
+
process.exit();
|
|
80
|
+
};
|
|
81
|
+
process.on('SIGINT', onSigInt);
|
|
82
|
+
|
|
83
|
+
// write files to global cache
|
|
84
|
+
try {
|
|
85
|
+
await Promise.all(Array.from(filesData.entries()).map(async ([filePath, data]) => {
|
|
86
|
+
await fs.promises.mkdir(path.join(cacheDir, path.dirname(filePath)), {recursive: true});
|
|
87
|
+
await fs.promises.writeFile(path.join(cacheDir, filePath), Buffer.from(data));
|
|
88
|
+
}));
|
|
89
|
+
}
|
|
90
|
+
catch (err) {
|
|
91
|
+
console.error(chalk.red('Error: ') + err);
|
|
92
|
+
deleteSync([cacheDir], {force: true});
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
process.off('SIGINT', onSigInt);
|
|
97
|
+
}
|
|
98
|
+
catch (err) {
|
|
99
|
+
console.error(chalk.red('Error: ') + err);
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
progress();
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (verbose) {
|
|
107
|
+
silent || logUpdate.done();
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
logUpdate.clear();
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// install dependencies
|
|
114
|
+
let config = readConfig(path.join(cacheDir, 'mops.toml'));
|
|
115
|
+
let res = await installDeps(Object.values(config.dependencies || {}), {silent, verbose});
|
|
116
|
+
|
|
117
|
+
if (!res) {
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return true;
|
|
122
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
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
|
+
|
|
7
|
+
export async function syncLocalCache({verbose = false} = {}) : Promise<Record<string, string>> {
|
|
8
|
+
let resolvedPackages = await resolvePackages();
|
|
9
|
+
let rootDir = getRootDir();
|
|
10
|
+
|
|
11
|
+
verbose && console.log('Syncing local cache...');
|
|
12
|
+
|
|
13
|
+
let installedDeps : Record<string, string> = {};
|
|
14
|
+
|
|
15
|
+
await Promise.all(Object.entries(resolvedPackages).map(([name, value]) => {
|
|
16
|
+
let depType = getDependencyType(value);
|
|
17
|
+
|
|
18
|
+
if (depType === 'mops' || depType === 'github') {
|
|
19
|
+
let cacheName = getDepCacheName(name, value);
|
|
20
|
+
let dest = path.join(rootDir, '.mops', cacheName);
|
|
21
|
+
|
|
22
|
+
if (!fs.existsSync(dest)) {
|
|
23
|
+
if (depType === 'mops') {
|
|
24
|
+
installedDeps[name] = value;
|
|
25
|
+
}
|
|
26
|
+
return copyCache(cacheName, path.join(rootDir, '.mops', cacheName));
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return Promise.resolve();
|
|
31
|
+
}));
|
|
32
|
+
|
|
33
|
+
return installedDeps;
|
|
34
|
+
}
|
package/commands/publish.ts
CHANGED
package/commands/remove.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import {deleteSync} from 'del';
|
|
3
3
|
import chalk from 'chalk';
|
|
4
|
-
import {
|
|
4
|
+
import {checkConfigFile, getRootDir, readConfig, writeConfig} from '../mops.js';
|
|
5
5
|
import {Config, Dependency} from '../types.js';
|
|
6
6
|
import {checkIntegrity} from '../integrity.js';
|
|
7
|
+
import {getDepCacheDir, getDepCacheName} from '../cache.js';
|
|
8
|
+
import path from 'node:path';
|
|
9
|
+
import {syncLocalCache} from './install/sync-local-cache.js';
|
|
7
10
|
|
|
8
11
|
type RemoveOptions = {
|
|
9
12
|
verbose ?: boolean;
|
|
@@ -12,7 +15,6 @@ type RemoveOptions = {
|
|
|
12
15
|
lock ?: 'update' | 'ignore';
|
|
13
16
|
};
|
|
14
17
|
|
|
15
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
16
18
|
export async function remove(name : string, {dev = false, verbose = false, dryRun = false, lock} : RemoveOptions = {}) {
|
|
17
19
|
if (!checkConfigFile()) {
|
|
18
20
|
return;
|
|
@@ -31,13 +33,12 @@ export async function remove(name : string, {dev = false, verbose = false, dryRu
|
|
|
31
33
|
}
|
|
32
34
|
|
|
33
35
|
function getTransitiveDependenciesOf(name : string, version : string | undefined, repo ?: string) {
|
|
34
|
-
let
|
|
35
|
-
if (
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
else if (version) {
|
|
39
|
-
pkgDir = formatDir(name, version);
|
|
36
|
+
let value = version || repo;
|
|
37
|
+
if (!value) {
|
|
38
|
+
return [];
|
|
40
39
|
}
|
|
40
|
+
let cacheName = getDepCacheName(name, value);
|
|
41
|
+
let pkgDir = getDepCacheDir(cacheName);
|
|
41
42
|
let configFile = pkgDir + '/mops.toml';
|
|
42
43
|
if (!fs.existsSync(configFile)) {
|
|
43
44
|
verbose && console.log('no config', configFile);
|
|
@@ -78,16 +79,11 @@ export async function remove(name : string, {dev = false, verbose = false, dryRu
|
|
|
78
79
|
verbose && console.log(`Ignored transitive dependency ${depId} (other deps depend on it)`);
|
|
79
80
|
continue;
|
|
80
81
|
}
|
|
81
|
-
let
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
pkgDir = formatDir(dep.name, dep.version);
|
|
87
|
-
}
|
|
88
|
-
if (pkgDir && fs.existsSync(pkgDir)) {
|
|
89
|
-
dryRun || deleteSync([`${pkgDir}`], {force: true});
|
|
90
|
-
verbose && console.log(`Removed local cache ${pkgDir}`);
|
|
82
|
+
let cacheName = getDepCacheName(dep.name, dep.version || dep.repo || '');
|
|
83
|
+
let localCacheDir = path.join(getRootDir(), '.mops', cacheName);
|
|
84
|
+
if (localCacheDir && fs.existsSync(localCacheDir)) {
|
|
85
|
+
dryRun || deleteSync([localCacheDir], {force: true});
|
|
86
|
+
verbose && console.log(`Removed local cache ${localCacheDir}`);
|
|
91
87
|
}
|
|
92
88
|
}
|
|
93
89
|
|
|
@@ -100,6 +96,7 @@ export async function remove(name : string, {dev = false, verbose = false, dryRu
|
|
|
100
96
|
}
|
|
101
97
|
dryRun || writeConfig(config);
|
|
102
98
|
|
|
99
|
+
await syncLocalCache();
|
|
103
100
|
await checkIntegrity(lock);
|
|
104
101
|
|
|
105
102
|
console.log(chalk.green('Package removed ') + `${name} = "${version}"`);
|
package/commands/search.ts
CHANGED
package/commands/self.ts
CHANGED
package/commands/sources.ts
CHANGED
package/commands/sync.ts
CHANGED