ic-mops 0.8.2 → 0.8.3

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/README.md CHANGED
@@ -1,6 +1,6 @@
1
- # MOPS
1
+ # Mops
2
2
 
3
- MOPS is a package manager for the Motoko programming language.
3
+ Mops is a package manager for the Motoko programming language.
4
4
 
5
5
  See https://mops.one
6
6
 
package/cli.js CHANGED
@@ -1,7 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  import fs from 'fs';
4
- import path from 'path';
5
4
  import {program} from 'commander';
6
5
  import chalk from 'chalk';
7
6
 
@@ -9,7 +8,7 @@ import {init} from './commands/init.js';
9
8
  import {publish} from './commands/publish.js';
10
9
  import {importPem} from './commands/import-identity.js';
11
10
  import {sources} from './commands/sources.js';
12
- import {checkApiCompatibility, getNetwork, setNetwork, apiVersion} from './mops.js';
11
+ import {checkApiCompatibility, getNetwork, setNetwork, apiVersion, checkConfigFile} from './mops.js';
13
12
  import {whoami} from './commands/whoami.js';
14
13
  import {installAll} from './commands/install-all.js';
15
14
  import {search} from './commands/search.js';
@@ -19,9 +18,6 @@ import {test} from './commands/test.js';
19
18
  import {template} from './commands/template.js';
20
19
  import {upgrade} from './commands/upgrade.js';
21
20
 
22
- let cwd = process.cwd();
23
- let configFile = path.join(cwd, 'mops.toml');
24
-
25
21
  program.name('mops');
26
22
 
27
23
  // --version
@@ -43,6 +39,9 @@ program
43
39
  .option('--dev')
44
40
  .option('--verbose')
45
41
  .action(async (pkg, options) => {
42
+ if (!checkConfigFile()) {
43
+ process.exit(1);
44
+ }
46
45
  await add(pkg, options);
47
46
  });
48
47
 
@@ -53,9 +52,8 @@ program
53
52
  .description('Install all dependencies specified in mops.toml')
54
53
  .option('--verbose')
55
54
  .action(async (pkg, options) => {
56
- if (!fs.existsSync(configFile)) {
57
- console.log(chalk.red('Error: ') + `mops.toml not found. Please run ${chalk.green('mops init')} first`);
58
- return;
55
+ if (!checkConfigFile()) {
56
+ process.exit(1);
59
57
  }
60
58
 
61
59
  let compatible = await checkApiCompatibility();
@@ -77,6 +75,9 @@ program
77
75
  .command('publish')
78
76
  .description('Publish package to the mops registry')
79
77
  .action(async () => {
78
+ if (!checkConfigFile()) {
79
+ process.exit(1);
80
+ }
80
81
  let compatible = await checkApiCompatibility();
81
82
  if (compatible) {
82
83
  await publish();
@@ -115,6 +116,9 @@ program
115
116
  .description('for dfx packtool')
116
117
  .option('--verbose')
117
118
  .action(async (options) => {
119
+ if (!checkConfigFile()) {
120
+ process.exit(1);
121
+ }
118
122
  await installAll({silent: true});
119
123
  let sourcesArr = await sources(options);
120
124
  console.log(sourcesArr.join('\n'));
@@ -168,6 +172,9 @@ program
168
172
  .command('template')
169
173
  .description('Apply template')
170
174
  .action(async (options) => {
175
+ if (!checkConfigFile()) {
176
+ process.exit(1);
177
+ }
171
178
  await template(options);
172
179
  });
173
180
 
package/commands/init.js CHANGED
@@ -49,7 +49,7 @@ export async function init(name = '') {
49
49
  config.dependencies = vesselDeps;
50
50
  }
51
51
 
52
- writeConfig(config);
52
+ writeConfig(config, configFile);
53
53
 
54
54
  if (Object.keys(config.dependencies || {}).length) {
55
55
  await installAll({verbose: true});
@@ -91,7 +91,7 @@ export async function init(name = '') {
91
91
  config.dependencies[name] = {version};
92
92
  });
93
93
 
94
- writeConfig(config);
94
+ writeConfig(config, configFile);
95
95
 
96
96
  await installAll({verbose: true});
97
97
  }
@@ -1,25 +1,12 @@
1
1
  import path from 'path';
2
2
  import fs from 'fs';
3
3
  import chalk from 'chalk';
4
- import {formatDir, formatGithubDir, parseGithubURL, readConfig} from '../mops.js';
4
+ import {checkConfigFile, formatDir, formatGithubDir, parseGithubURL, readConfig} from '../mops.js';
5
5
  import {readVesselConfig} from '../vessel.js';
6
6
 
7
- function rootDir(cwd = process.cwd()) {
8
- let configFile = path.join(cwd, 'mops.toml');
9
- if (fs.existsSync(configFile)) {
10
- return cwd;
11
- }
12
- if (!path.basename(cwd)) {
13
- console.log(chalk.red('Error: ') + 'Cannot find mops.toml');
14
- return;
15
- }
16
- return rootDir(path.join(cwd, '..'));
17
- }
18
-
19
7
  // TODO: resolve conflicts
20
8
  export async function sources({verbose} = {}) {
21
- let root = rootDir();
22
- if (!root) {
9
+ if (!checkConfigFile()) {
23
10
  return [];
24
11
  }
25
12
 
@@ -108,7 +95,7 @@ export async function sources({verbose} = {}) {
108
95
  }
109
96
  };
110
97
 
111
- let config = readConfig(path.join(root, 'mops.toml'));
98
+ let config = readConfig();
112
99
  await collectDeps(config, true);
113
100
 
114
101
  // show conflicts
@@ -2,6 +2,7 @@ import fs from 'fs';
2
2
  import path from 'path';
3
3
  import chalk from 'chalk';
4
4
  import prompts from 'prompts';
5
+ import {getRootDir} from '../mops.js';
5
6
 
6
7
  export async function template() {
7
8
  let res = await prompts({
@@ -16,13 +17,13 @@ export async function template() {
16
17
  });
17
18
 
18
19
  if (res.value === 'github-workflow:mops-test') {
19
- let dest = path.resolve(process.cwd(), '.github/workflows/mops-test.yml');
20
+ let dest = path.resolve(getRootDir(), '.github/workflows/mops-test.yml');
20
21
  if (fs.existsSync(dest)) {
21
22
  console.log(chalk.yellow('Workflow already exists:'), dest);
22
23
  return;
23
24
  }
24
25
  let mopsTestYml = new URL('../templates/mops-test.yml', import.meta.url);
25
- fs.mkdirSync(path.resolve(process.cwd(), '.github/workflows'), {recursive: true});
26
+ fs.mkdirSync(path.resolve(getRootDir(), '.github/workflows'), {recursive: true});
26
27
  fs.copyFileSync(mopsTestYml, dest);
27
28
  console.log(chalk.green('Workflow created:'), dest);
28
29
  }
package/commands/test.js CHANGED
@@ -3,8 +3,10 @@ import chalk from 'chalk';
3
3
  import glob from 'glob';
4
4
  import chokidar from 'chokidar';
5
5
  import debounce from 'debounce';
6
+ import path from 'path';
6
7
  import {MMF1} from './mmf1.js';
7
8
  import {sources} from './sources.js';
9
+ import {getRootDir} from '../mops.js';
8
10
 
9
11
  let ignore = [
10
12
  '**/node_modules/**',
@@ -31,7 +33,7 @@ export async function test(filter = '', {watch = false} = {}) {
31
33
  console.log(chalk.gray((`Press ${chalk.gray('Ctrl+C')} to exit.`)));
32
34
  }, 200);
33
35
 
34
- let watcher = chokidar.watch('**/*.mo', {
36
+ let watcher = chokidar.watch(path.join(getRootDir(), '**/*.mo'), {
35
37
  ignored: ignore,
36
38
  ignoreInitial: true,
37
39
  });
@@ -64,9 +66,13 @@ export async function runAll(filter = '') {
64
66
  if (filter) {
65
67
  globStr = `**/test?(s)/**/*${filter}*`;
66
68
  }
67
- files = glob.sync(globStr, globConfig);
69
+ files = glob.sync(path.join(getRootDir(), globStr), globConfig);
68
70
  }
69
71
  if (!files.length) {
72
+ if (filter) {
73
+ console.log(`No test files found for filter '${filter}'`);
74
+ return;
75
+ }
70
76
  console.log('No test files found');
71
77
  console.log('Put your tests in \'test\' directory in *.test.mo files');
72
78
  return;
@@ -103,12 +103,12 @@ export interface _SERVICE {
103
103
  'notifyInstall' : ActorMethod<[PackageName__1, Ver], undefined>,
104
104
  'search' : ActorMethod<[Text], Array<PackageDetails>>,
105
105
  'startFileUpload' : ActorMethod<
106
- [PublishingId, Text, bigint, Uint8Array],
106
+ [PublishingId, Text, bigint, Uint8Array | number[]],
107
107
  Result_2
108
108
  >,
109
109
  'startPublish' : ActorMethod<[PackageConfigV2], Result_1>,
110
110
  'uploadFileChunk' : ActorMethod<
111
- [PublishingId, FileId, bigint, Uint8Array],
111
+ [PublishingId, FileId, bigint, Uint8Array | number[]],
112
112
  Result
113
113
  >,
114
114
  }
package/mops.js CHANGED
@@ -88,10 +88,29 @@ export let storageActor = async (storageId) => {
88
88
  });
89
89
  };
90
90
 
91
+ export function getClosestConfigFile(dir = process.cwd()) {
92
+ if (!path.basename(dir)) {
93
+ return null;
94
+ }
95
+ let configFile = path.join(dir, 'mops.toml');
96
+ if (fs.existsSync(configFile)) {
97
+ return configFile;
98
+ }
99
+ return getClosestConfigFile(path.resolve(dir, '..'));
100
+ }
101
+
102
+ export function getRootDir() {
103
+ let configFile = getClosestConfigFile();
104
+ if (!configFile) {
105
+ return null;
106
+ }
107
+ return path.dirname(configFile);
108
+ }
109
+
91
110
  export function checkConfigFile() {
92
- let configFile = path.join(process.cwd(), 'mops.toml');
93
- if (!fs.existsSync(configFile)) {
94
- console.log(chalk.red('Error: ') + `Config file not found ${configFile}`);
111
+ let configFile = getClosestConfigFile();
112
+ if (!configFile) {
113
+ console.log(chalk.red('Error: ') + `Config file 'mops.toml' not found. Please run ${chalk.green('mops init')} first`);
95
114
  return false;
96
115
  }
97
116
  return true;
@@ -120,7 +139,7 @@ export function parseGithubURL(href) {
120
139
  return {org, gitName, branch};
121
140
  }
122
141
 
123
- export function readConfig(configFile = path.join(process.cwd(), 'mops.toml')) {
142
+ export function readConfig(configFile = getClosestConfigFile()) {
124
143
  let text = fs.readFileSync(configFile).toString();
125
144
  let toml = TOML.parse(text);
126
145
 
@@ -147,7 +166,7 @@ export function readConfig(configFile = path.join(process.cwd(), 'mops.toml')) {
147
166
  return toml;
148
167
  }
149
168
 
150
- export function writeConfig(config, configFile = path.join(process.cwd(), 'mops.toml')) {
169
+ export function writeConfig(config, configFile = getClosestConfigFile()) {
151
170
  const deps = config.dependencies || {};
152
171
  Object.entries(deps).forEach(([name, {repo, path, version}]) => {
153
172
  deps[name] = repo || path || version;
@@ -162,12 +181,12 @@ export function writeConfig(config, configFile = path.join(process.cwd(), 'mops.
162
181
  }
163
182
 
164
183
  export function formatDir(name, version) {
165
- return path.join(process.cwd(), '.mops', `${name}@${version}`);
184
+ return path.join(getRootDir(), '.mops', `${name}@${version}`);
166
185
  }
167
186
 
168
187
  export function formatGithubDir(name, repo) {
169
188
  const {branch} = parseGithubURL(repo);
170
- return path.join(process.cwd(), '.mops/_github', `${name}@${branch}`);
189
+ return path.join(getRootDir(), '.mops/_github', `${name}@${branch}`);
171
190
  }
172
191
 
173
192
  export function readDfxJson() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ic-mops",
3
- "version": "0.8.2",
3
+ "version": "0.8.3",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "mops": "cli.js"