ic-mops 1.1.2-pre.0 → 1.1.2

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,5 +1,8 @@
1
1
  # Mops CLI Changelog
2
2
 
3
+ ## 1.1.2
4
+ - Fixed `{MOPS_ENV}` substitution in local package path
5
+
3
6
  ## 1.1.1
4
7
  - `moc-wrapper` now adds hostname to the moc path cache(`.mops/moc-*` filename) to avoid errors when running in Dev Containers
5
8
  - `mops watch` now deploys canisters with the `--yes` flag to skip data loss confirmation
package/bundle/cli.tgz CHANGED
Binary file
package/cli.ts CHANGED
@@ -214,7 +214,6 @@ program
214
214
  .addOption(new Option('--mode <mode>', 'Test mode').choices(['interpreter', 'wasi', 'replica']).default('interpreter'))
215
215
  .addOption(new Option('--replica <replica>', 'Which replica to use to run tests in replica mode').choices(['dfx', 'pocket-ic']))
216
216
  .option('-w, --watch', 'Enable watch mode')
217
- .option('--debug', 'Show debug logs')
218
217
  .action(async (filter, options) => {
219
218
  checkConfigFile(true);
220
219
  await installAll({silent: true, lock: 'ignore', installFromLockFile: true});
@@ -27,7 +27,7 @@ export async function installLocalDep(pkg : string, pkgPath = '', {verbose, sile
27
27
 
28
28
  // install dependencies
29
29
  if (!ignoreTransitive) {
30
- let dir = path.resolve(getRootDir(), pkgPath);
30
+ let dir = path.resolve(getRootDir(), pkgPath).replaceAll('{MOPS_ENV}', process.env.MOPS_ENV || 'local');
31
31
  let config = readConfig(path.join(dir, 'mops.toml'));
32
32
  return installDeps(Object.values(config.dependencies || {}), {silent, verbose}, pkgPath);
33
33
  }
@@ -8,21 +8,19 @@ import {spawn as spawnAsync} from 'promisify-child-process';
8
8
  import {IDL} from '@dfinity/candid';
9
9
  import {Actor, HttpAgent} from '@dfinity/agent';
10
10
  import {PocketIc, PocketIcServer} from 'pic-ic';
11
- import chalk from 'chalk';
12
11
 
13
12
  import {readConfig} from '../mops.js';
14
13
  import {toolchain} from './toolchain/index.js';
15
- import {getDfxVersion} from '../helpers/get-dfx-version.js';
16
14
 
17
15
  type StartOptions = {
18
- type ?: 'dfx' | 'pocket-ic' | 'dfx-pocket-ic';
16
+ type ?: 'dfx' | 'pocket-ic';
19
17
  dir ?: string;
20
18
  verbose ?: boolean;
21
19
  silent ?: boolean;
22
20
  };
23
21
 
24
22
  export class Replica {
25
- type : 'dfx' | 'pocket-ic' | 'dfx-pocket-ic' = 'dfx';
23
+ type : 'dfx' | 'pocket-ic' = 'dfx';
26
24
  verbose = false;
27
25
  canisters : Record<string, {cwd : string; canisterId : string; actor : any; stream : PassThrough;}> = {};
28
26
  pocketIcServer ?: PocketIcServer;
@@ -38,33 +36,20 @@ export class Replica {
38
36
 
39
37
  silent || console.log(`Starting ${this.type} replica...`);
40
38
 
41
- if (this.type === 'dfx' || this.type === 'dfx-pocket-ic') {
39
+ if (this.type == 'dfx') {
42
40
  fs.mkdirSync(this.dir, {recursive: true});
43
41
  fs.writeFileSync(path.join(this.dir, 'dfx.json'), JSON.stringify(this.dfxJson(''), null, 2));
44
42
  fs.writeFileSync(path.join(this.dir, 'canister.did'), 'service : { runTests: () -> (); }');
45
43
 
46
44
  await this.stop();
47
45
 
48
- this.dfxProcess = spawn('dfx', ['start', this.type === 'dfx-pocket-ic' ? '--pocketic' : '', '--clean', (this.verbose ? '' : '-qqqq'), '--artificial-delay', '0'].filter(x => x).flat(), {cwd: this.dir});
46
+ this.dfxProcess = spawn('dfx', ['start', '--clean', '--artificial-delay', '0', (this.verbose ? '' : '-qqqq')].filter(x => x), {cwd: this.dir});
49
47
 
50
48
  // process canister logs
51
49
  this._attachCanisterLogHandler(this.dfxProcess);
52
50
 
53
51
  this.dfxProcess.stdout.on('data', (data) => {
54
- if (this.verbose) {
55
- console.log('DFX:', data.toString());
56
- }
57
- });
58
-
59
- this.dfxProcess.stderr.on('data', (data) => {
60
- if (this.verbose) {
61
- console.error('DFX:', data.toString());
62
- }
63
- if (data.toString().includes('Failed to bind socket to')) {
64
- console.error(chalk.red(data.toString()));
65
- console.log('Please run again after some time');
66
- process.exit(11);
67
- }
52
+ console.log('DFX:', data.toString());
68
53
  });
69
54
 
70
55
  // await for dfx to start
@@ -130,22 +115,9 @@ export class Replica {
130
115
  }
131
116
 
132
117
  async stop(sigint = false) {
133
- if (this.type === 'dfx' || this.type === 'dfx-pocket-ic') {
134
- if (this.dfxProcess) {
135
- this.dfxProcess.kill();
136
- // give replica some time to stop
137
- await new Promise((resolve) => {
138
- setTimeout(resolve, 1000);
139
- });
140
- }
141
-
142
- // if (!this.dfxProcess) {
143
- // try {
144
- // execSync('dfx killall', {cwd: this.dir, timeout: 3_000, stdio: ['pipe', this.verbose ? 'inherit' : 'ignore', 'pipe']});
145
- // execSync('dfx stop' + (this.verbose ? '' : ' -qqqq'), {cwd: this.dir, timeout: 10_000, stdio: ['pipe', this.verbose ? 'inherit' : 'ignore', 'pipe']});
146
- // }
147
- // catch {}
148
- // }
118
+ if (this.type == 'dfx') {
119
+ this.dfxProcess?.kill();
120
+ // execSync('dfx stop' + (this.verbose ? '' : ' -qqqq'), {cwd: this.dir, timeout: 10_000, stdio: ['pipe', this.verbose ? 'inherit' : 'ignore', 'pipe']});
149
121
  }
150
122
  else if (this.pocketIc && this.pocketIcServer) {
151
123
  if (!sigint) {
@@ -156,7 +128,7 @@ export class Replica {
156
128
  }
157
129
 
158
130
  async deploy(name : string, wasm : string, idlFactory : IDL.InterfaceFactory, cwd : string = process.cwd(), signal ?: AbortSignal) {
159
- if (this.type === 'dfx' || this.type === 'dfx-pocket-ic') {
131
+ if (this.type === 'dfx') {
160
132
  // prepare dfx.json for current canister
161
133
  let dfxJson = path.join(this.dir, 'dfx.json');
162
134
 
@@ -281,7 +253,6 @@ export class Replica {
281
253
  return {
282
254
  version: 1,
283
255
  canisters,
284
- dfx: getDfxVersion(),
285
256
  defaults: {
286
257
  build: {
287
258
  packtool: 'mops sources',
@@ -8,7 +8,6 @@ import chalk from 'chalk';
8
8
  import {globSync} from 'glob';
9
9
  import chokidar from 'chokidar';
10
10
  import debounce from 'debounce';
11
- import {SemVer} from 'semver';
12
11
 
13
12
  import {sources} from '../sources.js';
14
13
  import {getRootDir, readConfig} from '../../mops.js';
@@ -26,7 +25,6 @@ import {Replica} from '../replica.js';
26
25
  import {ActorMethod} from '@dfinity/agent';
27
26
  import {PassThrough, Readable} from 'node:stream';
28
27
  import {TestMode} from '../../types.js';
29
- import {getDfxVersion} from '../../helpers/get-dfx-version.js';
30
28
 
31
29
  let ignore = [
32
30
  '**/node_modules/**',
@@ -41,14 +39,13 @@ let globConfig = {
41
39
  };
42
40
 
43
41
  type ReporterName = 'verbose' | 'files' | 'compact' | 'silent';
44
- type ReplicaName = 'dfx' | 'pocket-ic' | 'dfx-pocket-ic';
42
+ type ReplicaName = 'dfx' | 'pocket-ic';
45
43
 
46
44
  type TestOptions = {
47
45
  watch : boolean;
48
46
  reporter : ReporterName;
49
47
  mode : TestMode;
50
48
  replica : ReplicaName;
51
- debug : boolean;
52
49
  };
53
50
 
54
51
 
@@ -69,20 +66,7 @@ export async function test(filter = '', options : Partial<TestOptions> = {}) {
69
66
  let rootDir = getRootDir();
70
67
 
71
68
  let replicaType = options.replica ?? (config.toolchain?.['pocket-ic'] ? 'pocket-ic' : 'dfx' as ReplicaName);
72
-
73
- if (replicaType === 'pocket-ic' && !config.toolchain?.['pocket-ic']) {
74
- let dfxVersion = getDfxVersion();
75
- if (!dfxVersion || new SemVer(dfxVersion).compare('0.24.1') < 0) {
76
- console.log(chalk.red('Please update dfx to the version >=0.24.1 or specify pocket-ic version in mops.toml'));
77
- process.exit(1);
78
- }
79
- else {
80
- replicaType = 'dfx-pocket-ic';
81
- }
82
- }
83
-
84
69
  replica.type = replicaType;
85
- replica.verbose = !!options.debug;
86
70
 
87
71
  if (options.watch) {
88
72
  replica.ttl = 60 * 15; // 15 minutes
@@ -218,7 +202,6 @@ export async function testWithReporter(reporterName : ReporterName | Reporter |
218
202
  let testTempDir = path.join(getRootDir(), '.mops/.test/');
219
203
  replica.dir = testTempDir;
220
204
 
221
- fs.rmSync(testTempDir, {recursive: true, force: true});
222
205
  fs.mkdirSync(testTempDir, {recursive: true});
223
206
 
224
207
  await parallel(os.cpus().length, files, async (file : string) => {
package/dist/cli.js CHANGED
@@ -183,7 +183,6 @@ program
183
183
  .addOption(new Option('--mode <mode>', 'Test mode').choices(['interpreter', 'wasi', 'replica']).default('interpreter'))
184
184
  .addOption(new Option('--replica <replica>', 'Which replica to use to run tests in replica mode').choices(['dfx', 'pocket-ic']))
185
185
  .option('-w, --watch', 'Enable watch mode')
186
- .option('--debug', 'Show debug logs')
187
186
  .action(async (filter, options) => {
188
187
  checkConfigFile(true);
189
188
  await installAll({ silent: true, lock: 'ignore', installFromLockFile: true });
@@ -18,7 +18,7 @@ export async function installLocalDep(pkg, pkgPath = '', { verbose, silent, igno
18
18
  }
19
19
  // install dependencies
20
20
  if (!ignoreTransitive) {
21
- let dir = path.resolve(getRootDir(), pkgPath);
21
+ let dir = path.resolve(getRootDir(), pkgPath).replaceAll('{MOPS_ENV}', process.env.MOPS_ENV || 'local');
22
22
  let config = readConfig(path.join(dir, 'mops.toml'));
23
23
  return installDeps(Object.values(config.dependencies || {}), { silent, verbose }, pkgPath);
24
24
  }
@@ -3,13 +3,13 @@ import { PassThrough } from 'node:stream';
3
3
  import { IDL } from '@dfinity/candid';
4
4
  import { PocketIc, PocketIcServer } from 'pic-ic';
5
5
  type StartOptions = {
6
- type?: 'dfx' | 'pocket-ic' | 'dfx-pocket-ic';
6
+ type?: 'dfx' | 'pocket-ic';
7
7
  dir?: string;
8
8
  verbose?: boolean;
9
9
  silent?: boolean;
10
10
  };
11
11
  export declare class Replica {
12
- type: 'dfx' | 'pocket-ic' | 'dfx-pocket-ic';
12
+ type: 'dfx' | 'pocket-ic';
13
13
  verbose: boolean;
14
14
  canisters: Record<string, {
15
15
  cwd: string;
@@ -43,7 +43,6 @@ export declare class Replica {
43
43
  dfxJson(canisterName: string, wasmPath?: string, didPath?: string): {
44
44
  version: number;
45
45
  canisters: Record<string, any>;
46
- dfx: string;
47
46
  defaults: {
48
47
  build: {
49
48
  packtool: string;
@@ -6,10 +6,8 @@ import { PassThrough } from 'node:stream';
6
6
  import { spawn as spawnAsync } from 'promisify-child-process';
7
7
  import { Actor, HttpAgent } from '@dfinity/agent';
8
8
  import { PocketIc, PocketIcServer } from 'pic-ic';
9
- import chalk from 'chalk';
10
9
  import { readConfig } from '../mops.js';
11
10
  import { toolchain } from './toolchain/index.js';
12
- import { getDfxVersion } from '../helpers/get-dfx-version.js';
13
11
  export class Replica {
14
12
  constructor() {
15
13
  this.type = 'dfx';
@@ -23,28 +21,16 @@ export class Replica {
23
21
  this.verbose = verbose ?? this.verbose;
24
22
  this.dir = dir ?? this.dir;
25
23
  silent || console.log(`Starting ${this.type} replica...`);
26
- if (this.type === 'dfx' || this.type === 'dfx-pocket-ic') {
24
+ if (this.type == 'dfx') {
27
25
  fs.mkdirSync(this.dir, { recursive: true });
28
26
  fs.writeFileSync(path.join(this.dir, 'dfx.json'), JSON.stringify(this.dfxJson(''), null, 2));
29
27
  fs.writeFileSync(path.join(this.dir, 'canister.did'), 'service : { runTests: () -> (); }');
30
28
  await this.stop();
31
- this.dfxProcess = spawn('dfx', ['start', this.type === 'dfx-pocket-ic' ? '--pocketic' : '', '--clean', (this.verbose ? '' : '-qqqq'), '--artificial-delay', '0'].filter(x => x).flat(), { cwd: this.dir });
29
+ this.dfxProcess = spawn('dfx', ['start', '--clean', '--artificial-delay', '0', (this.verbose ? '' : '-qqqq')].filter(x => x), { cwd: this.dir });
32
30
  // process canister logs
33
31
  this._attachCanisterLogHandler(this.dfxProcess);
34
32
  this.dfxProcess.stdout.on('data', (data) => {
35
- if (this.verbose) {
36
- console.log('DFX:', data.toString());
37
- }
38
- });
39
- this.dfxProcess.stderr.on('data', (data) => {
40
- if (this.verbose) {
41
- console.error('DFX:', data.toString());
42
- }
43
- if (data.toString().includes('Failed to bind socket to')) {
44
- console.error(chalk.red(data.toString()));
45
- console.log('Please run again after some time');
46
- process.exit(11);
47
- }
33
+ console.log('DFX:', data.toString());
48
34
  });
49
35
  // await for dfx to start
50
36
  let ok = false;
@@ -101,21 +87,9 @@ export class Replica {
101
87
  });
102
88
  }
103
89
  async stop(sigint = false) {
104
- if (this.type === 'dfx' || this.type === 'dfx-pocket-ic') {
105
- if (this.dfxProcess) {
106
- this.dfxProcess.kill();
107
- // give replica some time to stop
108
- await new Promise((resolve) => {
109
- setTimeout(resolve, 1000);
110
- });
111
- }
112
- // if (!this.dfxProcess) {
113
- // try {
114
- // execSync('dfx killall', {cwd: this.dir, timeout: 3_000, stdio: ['pipe', this.verbose ? 'inherit' : 'ignore', 'pipe']});
115
- // execSync('dfx stop' + (this.verbose ? '' : ' -qqqq'), {cwd: this.dir, timeout: 10_000, stdio: ['pipe', this.verbose ? 'inherit' : 'ignore', 'pipe']});
116
- // }
117
- // catch {}
118
- // }
90
+ if (this.type == 'dfx') {
91
+ this.dfxProcess?.kill();
92
+ // execSync('dfx stop' + (this.verbose ? '' : ' -qqqq'), {cwd: this.dir, timeout: 10_000, stdio: ['pipe', this.verbose ? 'inherit' : 'ignore', 'pipe']});
119
93
  }
120
94
  else if (this.pocketIc && this.pocketIcServer) {
121
95
  if (!sigint) {
@@ -125,7 +99,7 @@ export class Replica {
125
99
  }
126
100
  }
127
101
  async deploy(name, wasm, idlFactory, cwd = process.cwd(), signal) {
128
- if (this.type === 'dfx' || this.type === 'dfx-pocket-ic') {
102
+ if (this.type === 'dfx') {
129
103
  // prepare dfx.json for current canister
130
104
  let dfxJson = path.join(this.dir, 'dfx.json');
131
105
  let oldDfxJsonData;
@@ -228,7 +202,6 @@ export class Replica {
228
202
  return {
229
203
  version: 1,
230
204
  canisters,
231
- dfx: getDfxVersion(),
232
205
  defaults: {
233
206
  build: {
234
207
  packtool: 'mops sources',
@@ -1,13 +1,12 @@
1
1
  import { Reporter } from './reporters/reporter.js';
2
2
  import { TestMode } from '../../types.js';
3
3
  type ReporterName = 'verbose' | 'files' | 'compact' | 'silent';
4
- type ReplicaName = 'dfx' | 'pocket-ic' | 'dfx-pocket-ic';
4
+ type ReplicaName = 'dfx' | 'pocket-ic';
5
5
  type TestOptions = {
6
6
  watch: boolean;
7
7
  reporter: ReporterName;
8
8
  mode: TestMode;
9
9
  replica: ReplicaName;
10
- debug: boolean;
11
10
  };
12
11
  export declare function test(filter?: string, options?: Partial<TestOptions>): Promise<void>;
13
12
  export declare function testWithReporter(reporterName: ReporterName | Reporter | undefined, filter: string | undefined, defaultMode: TestMode | undefined, replicaType: ReplicaName, watch?: boolean, signal?: AbortSignal): Promise<boolean>;
@@ -7,7 +7,6 @@ import chalk from 'chalk';
7
7
  import { globSync } from 'glob';
8
8
  import chokidar from 'chokidar';
9
9
  import debounce from 'debounce';
10
- import { SemVer } from 'semver';
11
10
  import { sources } from '../sources.js';
12
11
  import { getRootDir, readConfig } from '../../mops.js';
13
12
  import { parallel } from '../../parallel.js';
@@ -20,7 +19,6 @@ import { SilentReporter } from './reporters/silent-reporter.js';
20
19
  import { toolchain } from '../toolchain/index.js';
21
20
  import { Replica } from '../replica.js';
22
21
  import { PassThrough } from 'node:stream';
23
- import { getDfxVersion } from '../../helpers/get-dfx-version.js';
24
22
  let ignore = [
25
23
  '**/node_modules/**',
26
24
  '**/.mops/**',
@@ -45,18 +43,7 @@ export async function test(filter = '', options = {}) {
45
43
  let config = readConfig();
46
44
  let rootDir = getRootDir();
47
45
  let replicaType = options.replica ?? (config.toolchain?.['pocket-ic'] ? 'pocket-ic' : 'dfx');
48
- if (replicaType === 'pocket-ic' && !config.toolchain?.['pocket-ic']) {
49
- let dfxVersion = getDfxVersion();
50
- if (!dfxVersion || new SemVer(dfxVersion).compare('0.24.1') < 0) {
51
- console.log(chalk.red('Please update dfx to the version >=0.24.1 or specify pocket-ic version in mops.toml'));
52
- process.exit(1);
53
- }
54
- else {
55
- replicaType = 'dfx-pocket-ic';
56
- }
57
- }
58
46
  replica.type = replicaType;
59
- replica.verbose = !!options.debug;
60
47
  if (options.watch) {
61
48
  replica.ttl = 60 * 15; // 15 minutes
62
49
  let sigint = false;
@@ -169,7 +156,6 @@ export async function testWithReporter(reporterName, filter = '', defaultMode =
169
156
  }
170
157
  let testTempDir = path.join(getRootDir(), '.mops/.test/');
171
158
  replica.dir = testTempDir;
172
- fs.rmSync(testTempDir, { recursive: true, force: true });
173
159
  fs.mkdirSync(testTempDir, { recursive: true });
174
160
  await parallel(os.cpus().length, files, async (file) => {
175
161
  if (signal?.aborted) {
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ic-mops",
3
- "version": "1.1.2-pre.0",
3
+ "version": "1.1.2",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "mops": "bin/mops.js",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ic-mops",
3
- "version": "1.1.2-pre.0",
3
+ "version": "1.1.2",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "mops": "dist/bin/mops.js",