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.
- package/.DS_Store +0 -0
- package/CHANGELOG.md +12 -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/cli.ts +3 -2
- 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 +51 -0
- package/commands/install/install-dep.ts +34 -0
- package/commands/install/install-deps.ts +31 -0
- package/commands/install/install-local-dep.ts +31 -0
- package/commands/{install.ts → install/install-mops-dep.ts} +43 -43
- 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/cli.js +3 -2
- 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 +36 -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 +21 -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 +103 -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 +10 -12
- 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 +11 -13
- package/commands/install-all.ts +0 -58
- package/commands/install-local.ts +0 -52
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/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';
|
|
@@ -169,7 +170,7 @@ program
|
|
|
169
170
|
if (!checkConfigFile()) {
|
|
170
171
|
process.exit(1);
|
|
171
172
|
}
|
|
172
|
-
await installAll({silent: true, lock: 'ignore'});
|
|
173
|
+
await installAll({silent: true, lock: 'ignore', threads: 6});
|
|
173
174
|
await toolchain.ensureToolchainInited({strict: false});
|
|
174
175
|
let sourcesArr = await sources(options);
|
|
175
176
|
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,51 @@
|
|
|
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 = {}) {
|
|
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
|
+
|
|
28
|
+
let res = await installDeps(allDeps, {silent, verbose, threads});
|
|
29
|
+
if (!res) {
|
|
30
|
+
return;
|
|
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
|
+
}
|
|
@@ -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<Record<string, string> | false> {
|
|
17
|
+
if (dep.repo) {
|
|
18
|
+
await installFromGithub(dep.name, dep.repo, {silent, verbose});
|
|
19
|
+
return {};
|
|
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 {};
|
|
34
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
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<Record<string, string> | false> {
|
|
14
|
+
let installedDeps = {};
|
|
15
|
+
let ok = true;
|
|
16
|
+
for (const dep of deps) {
|
|
17
|
+
let res = await installDep(dep, {verbose, silent, threads}, parentPkgPath);
|
|
18
|
+
if (res) {
|
|
19
|
+
installedDeps = {...installedDeps, ...res};
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
ok = false;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (!ok) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return installedDeps;
|
|
31
|
+
}
|
|
@@ -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<Record<string, string> | false> {
|
|
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
|
+
}
|
|
@@ -1,17 +1,28 @@
|
|
|
1
|
-
import
|
|
1
|
+
import process from 'node:process';
|
|
2
2
|
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import {Buffer} from 'node:buffer';
|
|
3
5
|
import {createLogUpdate} from 'log-update';
|
|
4
6
|
import chalk from 'chalk';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {downloadFile, getPackageFilesInfo} from '
|
|
12
|
-
import {
|
|
13
|
-
|
|
14
|
-
|
|
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
|
+
|
|
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<Record<string, string> | false> {
|
|
24
|
+
threads = threads || 12;
|
|
25
|
+
|
|
15
26
|
if (!checkConfigFile()) {
|
|
16
27
|
return false;
|
|
17
28
|
}
|
|
@@ -36,6 +47,8 @@ export async function install(pkg : string, version = '', {verbose = false, sile
|
|
|
36
47
|
}
|
|
37
48
|
|
|
38
49
|
let dir = formatDir(pkg, version);
|
|
50
|
+
let cacheName = getMopsDepCacheName(pkg, version);
|
|
51
|
+
let cacheDir = getDepCacheDir(cacheName);
|
|
39
52
|
let alreadyInstalled = false;
|
|
40
53
|
|
|
41
54
|
// already installed
|
|
@@ -44,14 +57,11 @@ export async function install(pkg : string, version = '', {verbose = false, sile
|
|
|
44
57
|
alreadyInstalled = true;
|
|
45
58
|
}
|
|
46
59
|
// copy from cache
|
|
47
|
-
else if (
|
|
48
|
-
await copyCache(`${pkg}@${version}`, dir);
|
|
60
|
+
else if (isDepCached(cacheName)) {
|
|
49
61
|
silent || logUpdate(`${dep ? 'Dependency' : 'Installing'} ${pkg}@${version} (global cache)`);
|
|
50
62
|
}
|
|
51
63
|
// download
|
|
52
64
|
else {
|
|
53
|
-
let threads = 16;
|
|
54
|
-
|
|
55
65
|
// GitHub Actions fails with "fetch failed" if there are multiple concurrent actions
|
|
56
66
|
if (process.env.GITHUB_ENV) {
|
|
57
67
|
threads = 4;
|
|
@@ -71,10 +81,17 @@ export async function install(pkg : string, version = '', {verbose = false, sile
|
|
|
71
81
|
progress();
|
|
72
82
|
});
|
|
73
83
|
|
|
74
|
-
// write files to
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
84
|
+
// write files to global cache
|
|
85
|
+
try {
|
|
86
|
+
for (let [filePath, data] of filesData.entries()) {
|
|
87
|
+
fs.mkdirSync(path.join(cacheDir, path.dirname(filePath)), {recursive: true});
|
|
88
|
+
fs.writeFileSync(path.join(cacheDir, filePath), Buffer.from(data));
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
catch (err) {
|
|
92
|
+
console.error(chalk.red('Error: ') + err);
|
|
93
|
+
deleteSync([cacheDir], {force: true});
|
|
94
|
+
return false;
|
|
78
95
|
}
|
|
79
96
|
}
|
|
80
97
|
catch (err) {
|
|
@@ -82,9 +99,6 @@ export async function install(pkg : string, version = '', {verbose = false, sile
|
|
|
82
99
|
return false;
|
|
83
100
|
}
|
|
84
101
|
|
|
85
|
-
// add to cache
|
|
86
|
-
await addCache(`${pkg}@${version}`, dir);
|
|
87
|
-
|
|
88
102
|
progress();
|
|
89
103
|
}
|
|
90
104
|
|
|
@@ -96,31 +110,17 @@ export async function install(pkg : string, version = '', {verbose = false, sile
|
|
|
96
110
|
}
|
|
97
111
|
|
|
98
112
|
// install dependencies
|
|
99
|
-
let
|
|
100
|
-
let
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
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
|
-
}
|
|
113
|
+
let config = readConfig(path.join(cacheDir, 'mops.toml'));
|
|
114
|
+
let res = await installDeps(Object.values(config.dependencies || {}), {silent, verbose});
|
|
115
|
+
|
|
116
|
+
if (!res) {
|
|
117
|
+
return false;
|
|
116
118
|
}
|
|
119
|
+
let installedDeps = res;
|
|
117
120
|
|
|
121
|
+
// add self to installed deps
|
|
118
122
|
if (!alreadyInstalled) {
|
|
119
123
|
installedDeps = {...installedDeps, [pkg]: version};
|
|
120
124
|
}
|
|
121
|
-
|
|
122
|
-
if (!ok) {
|
|
123
|
-
return false;
|
|
124
|
-
}
|
|
125
125
|
return installedDeps;
|
|
126
126
|
}
|
|
@@ -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
package/commands/test/test.ts
CHANGED