ic-mops 0.42.0 → 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/CHANGELOG.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # Mops CLI Changelog
2
2
 
3
3
  ## unreleased
4
+ - Fix package requirements check from subdirectories
5
+ - Fix local and global cache inconsistency
4
6
 
5
7
  ## 0.42.0
6
8
  - Package requirements support ([docs](https://docs.mops.one/mops.toml#requirements))
@@ -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
@@ -110,8 +110,11 @@ program
110
110
  await add(pkg, options);
111
111
  }
112
112
  else {
113
- await installAll(options);
113
+ let ok = await installAll(options);
114
114
  await toolchain.installAll(options);
115
+ if (!ok) {
116
+ process.exit(1);
117
+ }
115
118
  }
116
119
  });
117
120
 
@@ -15,9 +15,9 @@ type InstallAllOptions = {
15
15
  threads ?: number;
16
16
  }
17
17
 
18
- export async function installAll({verbose = false, silent = false, threads, lock} : InstallAllOptions = {}) {
18
+ export async function installAll({verbose = false, silent = false, threads, lock} : InstallAllOptions = {}) : Promise<boolean> {
19
19
  if (!checkConfigFile()) {
20
- return;
20
+ return false;
21
21
  }
22
22
 
23
23
  let config = readConfig();
@@ -25,9 +25,9 @@ export async function installAll({verbose = false, silent = false, threads, lock
25
25
  let devDeps = Object.values(config['dev-dependencies'] || {});
26
26
  let allDeps = [...deps, ...devDeps];
27
27
 
28
- let res = await installDeps(allDeps, {silent, verbose, threads});
29
- if (!res) {
30
- return;
28
+ let ok = await installDeps(allDeps, {silent, verbose, threads});
29
+ if (!ok) {
30
+ return false;
31
31
  }
32
32
 
33
33
  let logUpdate = createLogUpdate(process.stdout, {showCursor: true});
@@ -48,4 +48,6 @@ export async function installAll({verbose = false, silent = false, threads, lock
48
48
  await checkRequirements();
49
49
  console.log(chalk.green('Packages installed'));
50
50
  }
51
+
52
+ return true;
51
53
  }
@@ -13,10 +13,10 @@ type InstallDepOptions = {
13
13
 
14
14
  // install dependency
15
15
  // returns false if failed
16
- export async function installDep(dep : Dependency, {verbose, silent, threads} : InstallDepOptions = {}, parentPkgPath ?: string) : Promise<Record<string, string> | false> {
16
+ export async function installDep(dep : Dependency, {verbose, silent, threads} : InstallDepOptions = {}, parentPkgPath ?: string) : Promise<boolean> {
17
17
  if (dep.repo) {
18
18
  await installFromGithub(dep.name, dep.repo, {silent, verbose});
19
- return {};
19
+ return true;
20
20
  }
21
21
  else if (dep.path) {
22
22
  let depPath = dep.path;
@@ -30,5 +30,5 @@ export async function installDep(dep : Dependency, {verbose, silent, threads} :
30
30
  return installMopsDep(dep.name, dep.version, {silent, verbose, threads});
31
31
  }
32
32
 
33
- return {};
33
+ return true;
34
34
  }
@@ -10,22 +10,15 @@ type InstallDepsOptions = {
10
10
  // install all dependencies
11
11
  // returns actual installed dependencies
12
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 = {};
13
+ export async function installDeps(deps : Dependency[], {verbose, silent, threads} : InstallDepsOptions = {}, parentPkgPath ?: string) : Promise<boolean> {
15
14
  let ok = true;
15
+
16
16
  for (const dep of deps) {
17
17
  let res = await installDep(dep, {verbose, silent, threads}, parentPkgPath);
18
- if (res) {
19
- installedDeps = {...installedDeps, ...res};
20
- }
21
- else {
18
+ if (!res) {
22
19
  ok = false;
23
20
  }
24
21
  }
25
22
 
26
- if (!ok) {
27
- return false;
28
- }
29
-
30
- return installedDeps;
23
+ return ok;
31
24
  }
@@ -11,7 +11,7 @@ type InstallLocalDepOptions = {
11
11
 
12
12
  // skip install and just find non-local dependencies to install
13
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> {
14
+ export async function installLocalDep(pkg : string, pkgPath = '', {verbose, silent} : InstallLocalDepOptions = {}) : Promise<boolean> {
15
15
  if (!silent) {
16
16
  let logUpdate = createLogUpdate(process.stdout, {showCursor: true});
17
17
  logUpdate(`Local dependency ${pkg} = "${pkgPath}"`);
@@ -5,7 +5,7 @@ import {Buffer} from 'node:buffer';
5
5
  import {createLogUpdate} from 'log-update';
6
6
  import chalk from 'chalk';
7
7
  import {deleteSync} from 'del';
8
- import {checkConfigFile, formatDir, progressBar, readConfig} from '../../mops.js';
8
+ import {checkConfigFile, progressBar, readConfig} from '../../mops.js';
9
9
  import {getHighestVersion} from '../../api/getHighestVersion.js';
10
10
  import {storageActor} from '../../api/actors.js';
11
11
  import {parallel} from '../../parallel.js';
@@ -20,7 +20,7 @@ type InstallMopsDepOptions = {
20
20
  threads ?: number;
21
21
  };
22
22
 
23
- export async function installMopsDep(pkg : string, version = '', {verbose, silent, dep, threads} : InstallMopsDepOptions = {}) : Promise<Record<string, string> | false> {
23
+ export async function installMopsDep(pkg : string, version = '', {verbose, silent, dep, threads} : InstallMopsDepOptions = {}) : Promise<boolean> {
24
24
  threads = threads || 12;
25
25
 
26
26
  if (!checkConfigFile()) {
@@ -46,19 +46,12 @@ export async function installMopsDep(pkg : string, version = '', {verbose, silen
46
46
  version = versionRes.ok;
47
47
  }
48
48
 
49
- let dir = formatDir(pkg, version);
50
49
  let cacheName = getMopsDepCacheName(pkg, version);
51
50
  let cacheDir = getDepCacheDir(cacheName);
52
- let alreadyInstalled = false;
53
51
 
54
- // already installed
55
- if (fs.existsSync(dir)) {
56
- silent || logUpdate(`${dep ? 'Dependency' : 'Installing'} ${pkg}@${version} (local cache)`);
57
- alreadyInstalled = true;
58
- }
59
- // copy from cache
60
- else if (isDepCached(cacheName)) {
61
- silent || logUpdate(`${dep ? 'Dependency' : 'Installing'} ${pkg}@${version} (global cache)`);
52
+ // global cache hit
53
+ if (isDepCached(cacheName)) {
54
+ silent || logUpdate(`${dep ? 'Dependency' : 'Installing'} ${pkg}@${version} (cache)`);
62
55
  }
63
56
  // download
64
57
  else {
@@ -81,18 +74,26 @@ export async function installMopsDep(pkg : string, version = '', {verbose, silen
81
74
  progress();
82
75
  });
83
76
 
77
+ let onSigInt = () => {
78
+ deleteSync([cacheDir], {force: true});
79
+ process.exit();
80
+ };
81
+ process.on('SIGINT', onSigInt);
82
+
84
83
  // write files to global cache
85
84
  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
- }
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
+ }));
90
89
  }
91
90
  catch (err) {
92
91
  console.error(chalk.red('Error: ') + err);
93
92
  deleteSync([cacheDir], {force: true});
94
93
  return false;
95
94
  }
95
+
96
+ process.off('SIGINT', onSigInt);
96
97
  }
97
98
  catch (err) {
98
99
  console.error(chalk.red('Error: ') + err);
@@ -116,11 +117,6 @@ export async function installMopsDep(pkg : string, version = '', {verbose, silen
116
117
  if (!res) {
117
118
  return false;
118
119
  }
119
- let installedDeps = res;
120
120
 
121
- // add self to installed deps
122
- if (!alreadyInstalled) {
123
- installedDeps = {...installedDeps, [pkg]: version};
124
- }
125
- return installedDeps;
121
+ return true;
126
122
  }
@@ -1,7 +1,7 @@
1
1
  import path from 'node:path';
2
2
  import { SemVer } from 'semver';
3
3
  import chalk from 'chalk';
4
- import { getDependencyType, readConfig } from './mops.js';
4
+ import { getDependencyType, getRootDir, readConfig } from './mops.js';
5
5
  import { resolvePackages } from './resolve-packages.js';
6
6
  import { getMocVersion } from './helpers/get-moc-version.js';
7
7
  export async function checkRequirements({ verbose = false } = {}) {
@@ -16,11 +16,12 @@ export async function checkRequirements({ verbose = false } = {}) {
16
16
  let installedMoc = new SemVer(mocVersion);
17
17
  let highestRequiredMoc = new SemVer('0.0.0');
18
18
  let highestRequiredMocPkgId = '';
19
+ let rootDir = getRootDir();
19
20
  let resolvedPackages = await resolvePackages();
20
21
  for (let [name, version] of Object.entries(resolvedPackages)) {
21
22
  if (getDependencyType(version) === 'mops') {
22
23
  let pkgId = `${name}@${version}`;
23
- let depConfig = readConfig(path.join('.mops', pkgId, 'mops.toml'));
24
+ let depConfig = readConfig(path.join(rootDir, '.mops', pkgId, 'mops.toml'));
24
25
  let moc = depConfig.requirements?.moc;
25
26
  if (moc) {
26
27
  let requiredMoc = new SemVer(moc);
package/dist/cli.js CHANGED
@@ -91,8 +91,11 @@ program
91
91
  await add(pkg, options);
92
92
  }
93
93
  else {
94
- await installAll(options);
94
+ let ok = await installAll(options);
95
95
  await toolchain.installAll(options);
96
+ if (!ok) {
97
+ process.exit(1);
98
+ }
96
99
  }
97
100
  });
98
101
  // publish
@@ -4,5 +4,5 @@ type InstallAllOptions = {
4
4
  lock?: 'check' | 'update' | 'ignore';
5
5
  threads?: number;
6
6
  };
7
- export declare function installAll({ verbose, silent, threads, lock }?: InstallAllOptions): Promise<void>;
7
+ export declare function installAll({ verbose, silent, threads, lock }?: InstallAllOptions): Promise<boolean>;
8
8
  export {};
@@ -9,15 +9,15 @@ import { syncLocalCache } from './sync-local-cache.js';
9
9
  import { notifyInstalls } from '../../notify-installs.js';
10
10
  export async function installAll({ verbose = false, silent = false, threads, lock } = {}) {
11
11
  if (!checkConfigFile()) {
12
- return;
12
+ return false;
13
13
  }
14
14
  let config = readConfig();
15
15
  let deps = Object.values(config.dependencies || {});
16
16
  let devDeps = Object.values(config['dev-dependencies'] || {});
17
17
  let allDeps = [...deps, ...devDeps];
18
- let res = await installDeps(allDeps, { silent, verbose, threads });
19
- if (!res) {
20
- return;
18
+ let ok = await installDeps(allDeps, { silent, verbose, threads });
19
+ if (!ok) {
20
+ return false;
21
21
  }
22
22
  let logUpdate = createLogUpdate(process.stdout, { showCursor: true });
23
23
  if (!silent && lock !== 'ignore') {
@@ -33,4 +33,5 @@ export async function installAll({ verbose = false, silent = false, threads, loc
33
33
  await checkRequirements();
34
34
  console.log(chalk.green('Packages installed'));
35
35
  }
36
+ return true;
36
37
  }
@@ -4,5 +4,5 @@ type InstallDepOptions = {
4
4
  silent?: boolean;
5
5
  threads?: number;
6
6
  };
7
- export declare function installDep(dep: Dependency, { verbose, silent, threads }?: InstallDepOptions, parentPkgPath?: string): Promise<Record<string, string> | false>;
7
+ export declare function installDep(dep: Dependency, { verbose, silent, threads }?: InstallDepOptions, parentPkgPath?: string): Promise<boolean>;
8
8
  export {};
@@ -8,7 +8,7 @@ import { getRootDir } from '../../mops.js';
8
8
  export async function installDep(dep, { verbose, silent, threads } = {}, parentPkgPath) {
9
9
  if (dep.repo) {
10
10
  await installFromGithub(dep.name, dep.repo, { silent, verbose });
11
- return {};
11
+ return true;
12
12
  }
13
13
  else if (dep.path) {
14
14
  let depPath = dep.path;
@@ -21,5 +21,5 @@ export async function installDep(dep, { verbose, silent, threads } = {}, parentP
21
21
  else if (dep.version) {
22
22
  return installMopsDep(dep.name, dep.version, { silent, verbose, threads });
23
23
  }
24
- return {};
24
+ return true;
25
25
  }
@@ -4,5 +4,5 @@ type InstallDepsOptions = {
4
4
  silent?: boolean;
5
5
  threads?: number;
6
6
  };
7
- export declare function installDeps(deps: Dependency[], { verbose, silent, threads }?: InstallDepsOptions, parentPkgPath?: string): Promise<Record<string, string> | false>;
7
+ export declare function installDeps(deps: Dependency[], { verbose, silent, threads }?: InstallDepsOptions, parentPkgPath?: string): Promise<boolean>;
8
8
  export {};
@@ -3,19 +3,12 @@ import { installDep } from './install-dep.js';
3
3
  // returns actual installed dependencies
4
4
  // returns false if failed
5
5
  export async function installDeps(deps, { verbose, silent, threads } = {}, parentPkgPath) {
6
- let installedDeps = {};
7
6
  let ok = true;
8
7
  for (const dep of deps) {
9
8
  let res = await installDep(dep, { verbose, silent, threads }, parentPkgPath);
10
- if (res) {
11
- installedDeps = { ...installedDeps, ...res };
12
- }
13
- else {
9
+ if (!res) {
14
10
  ok = false;
15
11
  }
16
12
  }
17
- if (!ok) {
18
- return false;
19
- }
20
- return installedDeps;
13
+ return ok;
21
14
  }
@@ -2,5 +2,5 @@ type InstallLocalDepOptions = {
2
2
  verbose?: boolean;
3
3
  silent?: boolean;
4
4
  };
5
- export declare function installLocalDep(pkg: string, pkgPath?: string, { verbose, silent }?: InstallLocalDepOptions): Promise<Record<string, string> | false>;
5
+ export declare function installLocalDep(pkg: string, pkgPath?: string, { verbose, silent }?: InstallLocalDepOptions): Promise<boolean>;
6
6
  export {};
@@ -4,5 +4,5 @@ type InstallMopsDepOptions = {
4
4
  dep?: boolean;
5
5
  threads?: number;
6
6
  };
7
- export declare function installMopsDep(pkg: string, version?: string, { verbose, silent, dep, threads }?: InstallMopsDepOptions): Promise<Record<string, string> | false>;
7
+ export declare function installMopsDep(pkg: string, version?: string, { verbose, silent, dep, threads }?: InstallMopsDepOptions): Promise<boolean>;
8
8
  export {};
@@ -5,7 +5,7 @@ import { Buffer } from 'node:buffer';
5
5
  import { createLogUpdate } from 'log-update';
6
6
  import chalk from 'chalk';
7
7
  import { deleteSync } from 'del';
8
- import { checkConfigFile, formatDir, progressBar, readConfig } from '../../mops.js';
8
+ import { checkConfigFile, progressBar, readConfig } from '../../mops.js';
9
9
  import { getHighestVersion } from '../../api/getHighestVersion.js';
10
10
  import { storageActor } from '../../api/actors.js';
11
11
  import { parallel } from '../../parallel.js';
@@ -34,18 +34,11 @@ export async function installMopsDep(pkg, version = '', { verbose, silent, dep,
34
34
  }
35
35
  version = versionRes.ok;
36
36
  }
37
- let dir = formatDir(pkg, version);
38
37
  let cacheName = getMopsDepCacheName(pkg, version);
39
38
  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)`);
39
+ // global cache hit
40
+ if (isDepCached(cacheName)) {
41
+ silent || logUpdate(`${dep ? 'Dependency' : 'Installing'} ${pkg}@${version} (cache)`);
49
42
  }
50
43
  // download
51
44
  else {
@@ -63,18 +56,24 @@ export async function installMopsDep(pkg, version = '', { verbose, silent, dep,
63
56
  filesData.set(path, data);
64
57
  progress();
65
58
  });
59
+ let onSigInt = () => {
60
+ deleteSync([cacheDir], { force: true });
61
+ process.exit();
62
+ };
63
+ process.on('SIGINT', onSigInt);
66
64
  // write files to global cache
67
65
  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
- }
66
+ await Promise.all(Array.from(filesData.entries()).map(async ([filePath, data]) => {
67
+ await fs.promises.mkdir(path.join(cacheDir, path.dirname(filePath)), { recursive: true });
68
+ await fs.promises.writeFile(path.join(cacheDir, filePath), Buffer.from(data));
69
+ }));
72
70
  }
73
71
  catch (err) {
74
72
  console.error(chalk.red('Error: ') + err);
75
73
  deleteSync([cacheDir], { force: true });
76
74
  return false;
77
75
  }
76
+ process.off('SIGINT', onSigInt);
78
77
  }
79
78
  catch (err) {
80
79
  console.error(chalk.red('Error: ') + err);
@@ -94,10 +93,5 @@ export async function installMopsDep(pkg, version = '', { verbose, silent, dep,
94
93
  if (!res) {
95
94
  return false;
96
95
  }
97
- let installedDeps = res;
98
- // add self to installed deps
99
- if (!alreadyInstalled) {
100
- installedDeps = { ...installedDeps, [pkg]: version };
101
- }
102
- return installedDeps;
96
+ return true;
103
97
  }
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ic-mops",
3
- "version": "0.42.0",
3
+ "version": "0.42.1",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "mops": "bin/mops.js",
package/dist/vessel.js CHANGED
@@ -121,11 +121,8 @@ export const installFromGithub = async (name, repo, { verbose = false, dep = fal
121
121
  let cacheName = getGithubDepCacheName(name, repo);
122
122
  let cacheDir = getDepCacheDir(cacheName);
123
123
  let logUpdate = createLogUpdate(process.stdout, { showCursor: true });
124
- if (existsSync(dir)) {
125
- silent || logUpdate(`${dep ? 'Dependency' : 'Installing'} ${repo} (local cache)`);
126
- }
127
- else if (isDepCached(cacheName)) {
128
- silent || logUpdate(`${dep ? 'Dependency' : 'Installing'} ${repo} (global cache)`);
124
+ if (isDepCached(cacheName)) {
125
+ silent || logUpdate(`${dep ? 'Dependency' : 'Installing'} ${repo} (cache)`);
129
126
  }
130
127
  else {
131
128
  let progress = (step, total) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ic-mops",
3
- "version": "0.42.0",
3
+ "version": "0.42.1",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "mops": "dist/bin/mops.js",
package/vessel.ts CHANGED
@@ -156,14 +156,10 @@ export const installFromGithub = async (name : string, repo : string, {verbose =
156
156
 
157
157
  let logUpdate = createLogUpdate(process.stdout, {showCursor: true});
158
158
 
159
- if (existsSync(dir)) {
160
- silent || logUpdate(`${dep ? 'Dependency' : 'Installing'} ${repo} (local cache)`);
161
- }
162
- else if (isDepCached(cacheName)) {
163
- silent || logUpdate(`${dep ? 'Dependency' : 'Installing'} ${repo} (global cache)`);
159
+ if (isDepCached(cacheName)) {
160
+ silent || logUpdate(`${dep ? 'Dependency' : 'Installing'} ${repo} (cache)`);
164
161
  }
165
162
  else {
166
-
167
163
  let progress = (step : number, total : number) => {
168
164
  silent || logUpdate(`${dep ? 'Dependency' : 'Installing'} ${repo} ${progressBar(step, total)}`);
169
165
  };