ic-mops 0.8.12-pre.3 → 0.9.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/.gitignore +1 -2
- package/cli.js +18 -0
- package/commands/remove.js +88 -0
- package/package.json +5 -11
- package/cli.dist.js +0 -1619
package/.gitignore
CHANGED
package/cli.js
CHANGED
|
@@ -17,6 +17,7 @@ import {cacheSize, cleanCache} from './cache.js';
|
|
|
17
17
|
import {test} from './commands/test.js';
|
|
18
18
|
import {template} from './commands/template.js';
|
|
19
19
|
import {selfUpdate} from './commands/self-update.js';
|
|
20
|
+
import {remove} from './commands/remove.js';
|
|
20
21
|
|
|
21
22
|
program.name('mops');
|
|
22
23
|
|
|
@@ -45,6 +46,21 @@ program
|
|
|
45
46
|
await add(pkg, options);
|
|
46
47
|
});
|
|
47
48
|
|
|
49
|
+
// remove
|
|
50
|
+
program
|
|
51
|
+
.command('remove <pkg>')
|
|
52
|
+
.alias('rm')
|
|
53
|
+
.description('Remove package and update mops.toml')
|
|
54
|
+
.option('--dev', 'Remove from dev-dependencies instead of dependencies')
|
|
55
|
+
.option('--verbose', 'Show more information')
|
|
56
|
+
.option('--dry-run', 'Do not actually remove anything')
|
|
57
|
+
.action(async (pkg, options) => {
|
|
58
|
+
if (!checkConfigFile()) {
|
|
59
|
+
process.exit(1);
|
|
60
|
+
}
|
|
61
|
+
await remove(pkg, options);
|
|
62
|
+
});
|
|
63
|
+
|
|
48
64
|
// install
|
|
49
65
|
program
|
|
50
66
|
.command('install [pkg]')
|
|
@@ -87,6 +103,7 @@ program
|
|
|
87
103
|
// set-network
|
|
88
104
|
program
|
|
89
105
|
.command('set-network <network>')
|
|
106
|
+
.alias('sn')
|
|
90
107
|
.description('Set network local|dev|ic')
|
|
91
108
|
.action(async (network) => {
|
|
92
109
|
await setNetwork(network);
|
|
@@ -96,6 +113,7 @@ program
|
|
|
96
113
|
// get-network
|
|
97
114
|
program
|
|
98
115
|
.command('get-network')
|
|
116
|
+
.alias('gn')
|
|
99
117
|
.description('Get network')
|
|
100
118
|
.action(async () => {
|
|
101
119
|
console.log(getNetwork().network);
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import {checkConfigFile, readConfig, writeConfig} from '../mops.js';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import del from 'del';
|
|
4
|
+
import chalk from 'chalk';
|
|
5
|
+
import {formatDir, formatGithubDir} from '../mops.js';
|
|
6
|
+
|
|
7
|
+
export async function remove(name, {dev, verbose, dryRun} = {}) {
|
|
8
|
+
if (!checkConfigFile()) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function getTransitiveDependencies(config, exceptPkgId) {
|
|
13
|
+
let deps = Object.values(config.dependencies || {});
|
|
14
|
+
let devDeps = Object.values(config['dev-dependencies'] || {});
|
|
15
|
+
return [...deps, ...devDeps]
|
|
16
|
+
.filter((dep) => {
|
|
17
|
+
let depId = dep.name + '@' + dep.version;
|
|
18
|
+
return depId !== exceptPkgId;
|
|
19
|
+
}).map((dep) => {
|
|
20
|
+
return [dep, ...getTransitiveDependenciesOf(dep.name, dep.version, dep.repo)];
|
|
21
|
+
}).flat();
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function getTransitiveDependenciesOf(name, version, repo) {
|
|
25
|
+
let pkgDir = repo ? formatGithubDir(name, repo) : formatDir(name, version);
|
|
26
|
+
let configFile = pkgDir + '/mops.toml';
|
|
27
|
+
if (!fs.existsSync(configFile)) {
|
|
28
|
+
verbose && console.log('no config', configFile);
|
|
29
|
+
return [];
|
|
30
|
+
}
|
|
31
|
+
let config = readConfig(configFile);
|
|
32
|
+
let deps = Object.values(config.dependencies || {}).map((dep) => {
|
|
33
|
+
return [dep, ...getTransitiveDependenciesOf(dep.name, dep.version)];
|
|
34
|
+
}).flat();
|
|
35
|
+
return deps;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
let config = readConfig();
|
|
39
|
+
let deps = dev ? config['dev-dependencies'] : config.dependencies;
|
|
40
|
+
let pkgDetails = deps[name];
|
|
41
|
+
|
|
42
|
+
if (!pkgDetails) {
|
|
43
|
+
return console.log(chalk.red('Error: ') + `No ${dev ? 'dev ' : ''}dependency to remove "${name}"`);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
let version = pkgDetails.version;
|
|
47
|
+
let packageId = `${name}@${version}`;
|
|
48
|
+
|
|
49
|
+
// transitive deps ignoring deps of this package
|
|
50
|
+
let transitiveDeps = getTransitiveDependencies(config, packageId);
|
|
51
|
+
let transitiveDepIds = new Set(transitiveDeps.map((dep) => {
|
|
52
|
+
return dep.name + '@' + dep.version;
|
|
53
|
+
}));
|
|
54
|
+
|
|
55
|
+
// transitive deps of this package (including itself)
|
|
56
|
+
let transitiveDepsOfPackage = [pkgDetails, ...getTransitiveDependenciesOf(name, version)];
|
|
57
|
+
|
|
58
|
+
// remove local cache
|
|
59
|
+
for (let dep of transitiveDepsOfPackage) {
|
|
60
|
+
let depId = dep.name + '@' + dep.version;
|
|
61
|
+
if (transitiveDepIds.has(depId)) {
|
|
62
|
+
verbose && console.log(`Ignored transitive dependency ${depId} (other deps depend on it)`);
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
let pkgDir;
|
|
66
|
+
if (dep.repo) {
|
|
67
|
+
pkgDir = formatGithubDir(dep.name, dep.repo);
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
pkgDir = formatDir(dep.name, dep.version);
|
|
71
|
+
}
|
|
72
|
+
if (fs.existsSync(pkgDir)) {
|
|
73
|
+
dryRun || del.sync([`${pkgDir}`]);
|
|
74
|
+
verbose && console.log(`Removed local cache ${pkgDir}`);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// remove from config
|
|
79
|
+
if (dev) {
|
|
80
|
+
delete config['dev-dependencies'][name];
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
delete config.dependencies[name];
|
|
84
|
+
}
|
|
85
|
+
dryRun || writeConfig(config);
|
|
86
|
+
|
|
87
|
+
console.log(chalk.green('Package removed ') + `${name} = "${version}"`);
|
|
88
|
+
}
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ic-mops",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"bin": {
|
|
6
|
-
"mops": "cli.
|
|
6
|
+
"mops": "cli.js"
|
|
7
7
|
},
|
|
8
8
|
"files": [
|
|
9
9
|
"*",
|
|
@@ -11,12 +11,6 @@
|
|
|
11
11
|
"!.mops",
|
|
12
12
|
"/templates"
|
|
13
13
|
],
|
|
14
|
-
"scripts": {
|
|
15
|
-
"esbuild": "esbuild cli.js --bundle --format=esm --platform=node --target=node12 --packages=external --outfile=./cli.dist.js",
|
|
16
|
-
"clean": "rm -rf dist",
|
|
17
|
-
"build": "npm run clean && npm run esbuild",
|
|
18
|
-
"prepublishOnly": "npm run build"
|
|
19
|
-
},
|
|
20
14
|
"homepage": "https://mops.one",
|
|
21
15
|
"repository": {
|
|
22
16
|
"type": "git",
|
|
@@ -24,6 +18,9 @@
|
|
|
24
18
|
},
|
|
25
19
|
"author": "Zen Voich <zen.voich@gmail.com>",
|
|
26
20
|
"license": "MIT",
|
|
21
|
+
"engines": {
|
|
22
|
+
"node": ">=14.0.0"
|
|
23
|
+
},
|
|
27
24
|
"dependencies": {
|
|
28
25
|
"@dfinity/agent": "^0.11.0",
|
|
29
26
|
"@dfinity/candid": "^0.11.0",
|
|
@@ -50,8 +47,5 @@
|
|
|
50
47
|
"node-fetch": "^3.3.0",
|
|
51
48
|
"pem-file": "^1.0.1",
|
|
52
49
|
"prompts": "^2.4.2"
|
|
53
|
-
},
|
|
54
|
-
"devDependencies": {
|
|
55
|
-
"esbuild": "0.17.14"
|
|
56
50
|
}
|
|
57
51
|
}
|