ic-mops 0.39.2 → 0.41.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.
Files changed (183) hide show
  1. package/.DS_Store +0 -0
  2. package/.eslintrc.json +0 -0
  3. package/.gitignore +1 -0
  4. package/.npmrc +2 -1
  5. package/CHANGELOG.md +8 -0
  6. package/DEVELOPMENT.md +25 -0
  7. package/README.md +0 -0
  8. package/api/actors.ts +2 -2
  9. package/api/downloadPackageFiles.ts +9 -6
  10. package/api/getHighestVersion.ts +1 -1
  11. package/api/index.ts +0 -0
  12. package/api/network.ts +1 -1
  13. package/api/resolveVersion.ts +1 -1
  14. package/bundle/bench/bench-canister.mo +87 -0
  15. package/bundle/bench/user-bench.mo +14 -0
  16. package/bundle/bin/moc-wrapper.sh +3 -0
  17. package/bundle/bin/mops.js +3 -0
  18. package/bundle/cli.js +88 -0
  19. package/bundle/cli.tgz +0 -0
  20. package/bundle/declarations/bench/bench.did +26 -0
  21. package/bundle/declarations/bench/bench.did.d.ts +29 -0
  22. package/bundle/declarations/bench/bench.did.js +26 -0
  23. package/bundle/declarations/bench/index.d.ts +50 -0
  24. package/bundle/declarations/bench/index.js +41 -0
  25. package/bundle/declarations/main/index.d.ts +50 -0
  26. package/bundle/declarations/main/index.js +41 -0
  27. package/bundle/declarations/main/main.did +426 -0
  28. package/bundle/declarations/main/main.did.d.ts +352 -0
  29. package/bundle/declarations/main/main.did.js +404 -0
  30. package/bundle/declarations/storage/index.d.ts +50 -0
  31. package/bundle/declarations/storage/index.js +30 -0
  32. package/bundle/declarations/storage/storage.did +46 -0
  33. package/bundle/declarations/storage/storage.did.d.ts +37 -0
  34. package/bundle/declarations/storage/storage.did.js +38 -0
  35. package/bundle/package.json +31 -0
  36. package/bundle/templates/README.md +13 -0
  37. package/bundle/templates/licenses/Apache-2.0 +202 -0
  38. package/bundle/templates/licenses/Apache-2.0-NOTICE +13 -0
  39. package/bundle/templates/licenses/MIT +21 -0
  40. package/bundle/templates/mops-publish.yml +17 -0
  41. package/bundle/templates/mops-test.yml +22 -0
  42. package/bundle/templates/src/lib.mo +15 -0
  43. package/bundle/templates/test/lib.test.mo +4 -0
  44. package/bundle-package-json.ts +14 -0
  45. package/cache.ts +3 -3
  46. package/cli.ts +25 -21
  47. package/commands/add.ts +6 -6
  48. package/commands/available-updates.ts +2 -2
  49. package/commands/bench/bench-canister.mo +0 -0
  50. package/commands/bench/user-bench.mo +0 -0
  51. package/commands/bench-replica.ts +10 -10
  52. package/commands/bench.ts +96 -56
  53. package/commands/bump.ts +2 -2
  54. package/commands/docs.ts +1 -1
  55. package/commands/import-identity.ts +2 -2
  56. package/commands/init.ts +9 -9
  57. package/commands/install-all.ts +4 -4
  58. package/commands/install-local.ts +1 -1
  59. package/commands/install.ts +2 -2
  60. package/commands/outdated.ts +0 -0
  61. package/commands/publish.ts +34 -35
  62. package/commands/remove.ts +8 -8
  63. package/commands/search.ts +2 -2
  64. package/commands/self.ts +75 -0
  65. package/commands/sources.ts +0 -0
  66. package/commands/sync.ts +8 -8
  67. package/commands/template.ts +11 -12
  68. package/commands/test/mmf1.ts +18 -18
  69. package/commands/test/reporters/compact-reporter.ts +5 -5
  70. package/commands/test/reporters/files-reporter.ts +3 -3
  71. package/commands/test/reporters/reporter.ts +3 -3
  72. package/commands/test/reporters/silent-reporter.ts +4 -4
  73. package/commands/test/reporters/verbose-reporter.ts +3 -3
  74. package/commands/test/test.ts +10 -10
  75. package/commands/test/utils.ts +1 -1
  76. package/commands/toolchain/index.ts +9 -9
  77. package/commands/toolchain/moc.ts +2 -2
  78. package/commands/toolchain/pocket-ic.ts +6 -31
  79. package/commands/toolchain/toolchain-utils.ts +11 -11
  80. package/commands/toolchain/wasmtime.ts +2 -2
  81. package/commands/transfer-ownership.ts +2 -2
  82. package/commands/update.ts +4 -4
  83. package/commands/user.ts +2 -2
  84. package/commands/whoami.ts +0 -0
  85. package/declarations/bench/bench.did.d.ts +3 -0
  86. package/declarations/main/main.did +27 -1
  87. package/declarations/main/main.did.d.ts +26 -1
  88. package/declarations/main/main.did.js +27 -1
  89. package/declarations/storage/index.d.ts +0 -0
  90. package/declarations/storage/index.js +0 -0
  91. package/declarations/storage/storage.did +0 -0
  92. package/declarations/storage/storage.did.d.ts +0 -0
  93. package/declarations/storage/storage.did.js +0 -0
  94. package/dist/api/downloadPackageFiles.d.ts +1 -1
  95. package/dist/api/downloadPackageFiles.js +4 -0
  96. package/dist/bin/moc-wrapper.sh +3 -0
  97. package/dist/bin/mops.d.ts +1 -1
  98. package/dist/bin/mops.js +2 -1
  99. package/dist/bundle-package-json.d.ts +1 -0
  100. package/dist/bundle-package-json.js +11 -0
  101. package/dist/check-requirements.d.ts +3 -0
  102. package/dist/check-requirements.js +39 -0
  103. package/dist/cli.js +19 -18
  104. package/dist/commands/bench/bench-canister.mo +0 -0
  105. package/dist/commands/bench/user-bench.mo +0 -0
  106. package/dist/commands/bench-replica.d.ts +3 -1
  107. package/dist/commands/bench-replica.js +2 -2
  108. package/dist/commands/bench.d.ts +5 -2
  109. package/dist/commands/bench.js +66 -29
  110. package/dist/commands/init.js +1 -1
  111. package/dist/commands/publish.d.ts +1 -0
  112. package/dist/commands/publish.js +25 -25
  113. package/dist/commands/self.d.ts +3 -0
  114. package/dist/commands/self.js +62 -0
  115. package/dist/commands/template.js +9 -10
  116. package/dist/commands/test/mmf1.js +1 -1
  117. package/dist/commands/test/test.js +2 -2
  118. package/dist/commands/toolchain/pocket-ic.d.ts +1 -5
  119. package/dist/commands/toolchain/pocket-ic.js +4 -27
  120. package/dist/commands/toolchain/toolchain-utils.d.ts +1 -1
  121. package/dist/commands/toolchain/toolchain-utils.js +7 -7
  122. package/dist/commands/transfer-ownership.js +1 -1
  123. package/dist/declarations/bench/bench.did.d.ts +3 -0
  124. package/dist/declarations/main/main.did +27 -1
  125. package/dist/declarations/main/main.did.d.ts +26 -1
  126. package/dist/declarations/main/main.did.js +27 -1
  127. package/dist/declarations/storage/index.d.ts +0 -0
  128. package/dist/declarations/storage/index.js +0 -0
  129. package/dist/declarations/storage/storage.did +0 -0
  130. package/dist/declarations/storage/storage.did.d.ts +0 -0
  131. package/dist/declarations/storage/storage.did.js +0 -0
  132. package/dist/helpers/find-changelog-entry.d.ts +1 -0
  133. package/dist/helpers/find-changelog-entry.js +24 -0
  134. package/dist/mops.d.ts +1 -0
  135. package/dist/mops.js +5 -1
  136. package/dist/package.json +20 -26
  137. package/dist/release-cli.d.ts +1 -0
  138. package/dist/release-cli.js +37 -0
  139. package/dist/remove-scripts.d.ts +1 -0
  140. package/dist/remove-scripts.js +5 -0
  141. package/dist/templates/README.md +0 -0
  142. package/dist/templates/licenses/Apache-2.0 +0 -0
  143. package/dist/templates/licenses/Apache-2.0-NOTICE +0 -0
  144. package/dist/templates/licenses/MIT +0 -0
  145. package/dist/templates/mops-publish.yml +0 -0
  146. package/dist/templates/mops-test.yml +0 -0
  147. package/dist/templates/src/lib.mo +0 -0
  148. package/dist/templates/test/lib.test.mo +0 -0
  149. package/dist/templates.d.ts +1 -0
  150. package/dist/templates.js +4 -0
  151. package/dist/vessel.js +1 -1
  152. package/global.d.ts +0 -0
  153. package/helpers/find-changelog-entry.ts +27 -0
  154. package/helpers/get-dfx-version.ts +1 -1
  155. package/helpers/get-moc-path.ts +1 -1
  156. package/helpers/get-moc-version.ts +1 -1
  157. package/integrity.ts +16 -16
  158. package/mops.ts +22 -17
  159. package/notify-installs.ts +2 -2
  160. package/package.json +28 -19
  161. package/parallel.ts +1 -1
  162. package/pem.ts +5 -5
  163. package/release-cli.ts +62 -0
  164. package/remove-scripts.ts +6 -0
  165. package/resolve-packages.ts +9 -9
  166. package/templates/README.md +0 -0
  167. package/templates/licenses/Apache-2.0 +0 -0
  168. package/templates/licenses/Apache-2.0-NOTICE +0 -0
  169. package/templates/licenses/MIT +0 -0
  170. package/templates/mops-publish.yml +0 -0
  171. package/templates/mops-test.yml +0 -0
  172. package/templates/src/lib.mo +0 -0
  173. package/templates/test/lib.test.mo +0 -0
  174. package/templates.ts +5 -0
  175. package/tsconfig.json +1 -1
  176. package/types.ts +25 -25
  177. package/vessel.ts +16 -16
  178. package/commands/self-update.ts +0 -6
  179. package/dist/commands/replica.d.ts +0 -36
  180. package/dist/commands/replica.js +0 -103
  181. package/dist/commands/self-update.d.ts +0 -3
  182. package/dist/commands/self-update.js +0 -5
  183. /package/bin/{mops.ts → mops.js} +0 -0
package/mops.ts CHANGED
@@ -74,8 +74,8 @@ if (fs.existsSync(oldGlobalConfigDir) && !fs.existsSync(globalCacheDir)) {
74
74
  }
75
75
 
76
76
 
77
- export function getNetworkFile(): string | URL {
78
- let networkFile: string | URL = '';
77
+ export function getNetworkFile() : string | URL {
78
+ let networkFile : string | URL = '';
79
79
  try {
80
80
  networkFile = new URL('./network.txt', import.meta.url);
81
81
  }
@@ -85,18 +85,18 @@ export function getNetworkFile(): string | URL {
85
85
  return networkFile;
86
86
  }
87
87
 
88
- export function setNetwork(network: string) {
88
+ export function setNetwork(network : string) {
89
89
  fs.writeFileSync(getNetworkFile(), network);
90
90
  }
91
91
 
92
- export let getIdentity = async (): Promise<Identity | undefined> => {
92
+ export let getIdentity = async () : Promise<Identity | undefined> => {
93
93
  let identityPem = path.resolve(globalConfigDir, 'identity.pem');
94
94
  let identityPemEncrypted = path.resolve(globalConfigDir, 'identity.pem.encrypted');
95
95
  if (fs.existsSync(identityPemEncrypted)) {
96
96
  let res = await prompts({
97
97
  type: 'invisible',
98
98
  name: 'value',
99
- message: 'Enter password:'
99
+ message: 'Enter password:',
100
100
  });
101
101
  return await decodeFile(identityPemEncrypted, res.value);
102
102
  }
@@ -134,12 +134,12 @@ export function checkConfigFile() {
134
134
  return true;
135
135
  }
136
136
 
137
- export function progressBar(step: number, total: number) {
137
+ export function progressBar(step : number, total : number) {
138
138
  let done = Math.round(step / total * 10);
139
139
  return `[${':'.repeat(done)}${' '.repeat(Math.max(0, 10 - done))}]`;
140
140
  }
141
141
 
142
- export function parseGithubURL(href: string) {
142
+ export function parseGithubURL(href : string) {
143
143
  const url = new URL(href);
144
144
  let branchAndSha = url.hash?.substring(1).split('@');
145
145
  let branch = branchAndSha[0] || 'master';
@@ -154,9 +154,9 @@ export function parseGithubURL(href: string) {
154
154
  return {org, gitName, branch, commitHash};
155
155
  }
156
156
 
157
- export async function getGithubCommit(repo: string, ref: string): Promise<any> {
157
+ export async function getGithubCommit(repo : string, ref : string) : Promise<any> {
158
158
  let res = await fetch(`https://api.github.com/repos/${repo}/commits/${ref}`);
159
- let json: any = await res.json();
159
+ let json : any = await res.json();
160
160
 
161
161
  // try on main branch
162
162
  if (json.message && ref === 'master') {
@@ -166,7 +166,7 @@ export async function getGithubCommit(repo: string, ref: string): Promise<any> {
166
166
  return json;
167
167
  }
168
168
 
169
- export function getDependencyType(version: string) {
169
+ export function getDependencyType(version : string) {
170
170
  if (!version || typeof version !== 'string') {
171
171
  throw Error(`Invalid dependency value "${version}"`);
172
172
  }
@@ -181,11 +181,11 @@ export function getDependencyType(version: string) {
181
181
  }
182
182
  }
183
183
 
184
- export function readConfig(configFile = getClosestConfigFile()): Config {
184
+ export function readConfig(configFile = getClosestConfigFile()) : Config {
185
185
  let text = fs.readFileSync(configFile).toString();
186
186
  let toml = TOML.parse(text);
187
187
 
188
- let processDeps = (deps: any) => {
188
+ let processDeps = (deps : any) => {
189
189
  Object.entries(deps).forEach(([name, data]) => {
190
190
  if (!data || typeof data !== 'string') {
191
191
  throw Error(`Invalid dependency value ${name} = "${data}"`);
@@ -209,8 +209,8 @@ export function readConfig(configFile = getClosestConfigFile()): Config {
209
209
  return toml;
210
210
  }
211
211
 
212
- export function writeConfig(config: Config, configFile = getClosestConfigFile()) {
213
- let resConfig: any = JSON.parse(JSON.stringify(config));
212
+ export function writeConfig(config : Config, configFile = getClosestConfigFile()) {
213
+ let resConfig : any = JSON.parse(JSON.stringify(config));
214
214
 
215
215
  let deps = resConfig.dependencies || {};
216
216
  Object.entries(config.dependencies || {}).forEach(([name, {repo, path, version}]) => {
@@ -229,16 +229,16 @@ export function writeConfig(config: Config, configFile = getClosestConfigFile())
229
229
  fs.writeFileSync(configFile, text);
230
230
  }
231
231
 
232
- export function formatDir(name: string, version: string) {
232
+ export function formatDir(name : string, version : string) {
233
233
  return path.join(getRootDir(), '.mops', `${name}@${version}`);
234
234
  }
235
235
 
236
- export function formatGithubDir(name: string, repo: string) {
236
+ export function formatGithubDir(name : string, repo : string) {
237
237
  const {branch, commitHash} = parseGithubURL(repo);
238
238
  return path.join(getRootDir(), '.mops/_github', `${name}#${branch}` + (commitHash ? `@${commitHash}` : ''));
239
239
  }
240
240
 
241
- export function readDfxJson(): any {
241
+ export function readDfxJson() : any {
242
242
  let dir = process.cwd();
243
243
  let dfxJson = null;
244
244
  for (let i = 0; i < 5; i++) {
@@ -271,6 +271,11 @@ export async function checkApiCompatibility() {
271
271
  return true;
272
272
  }
273
273
 
274
+ export function version() {
275
+ let packageJson = JSON.parse(fs.readFileSync(new URL('./package.json', import.meta.url)).toString());
276
+ return packageJson.version;
277
+ }
278
+
274
279
  // compatibility with older versions
275
280
  export {
276
281
  getNetwork,
@@ -2,9 +2,9 @@ import {getDependencyType} from './mops.js';
2
2
  import {mainActor} from './api/actors.js';
3
3
  import {resolvePackages} from './resolve-packages.js';
4
4
 
5
- export async function notifyInstalls(names: string[]) {
5
+ export async function notifyInstalls(names : string[]) {
6
6
  let resolvedPackages = await resolvePackages();
7
- let packages: [string, string][] = names.map(name => [name, resolvedPackages[name] as string]);
7
+ let packages : [string, string][] = names.map(name => [name, resolvedPackages[name] as string]);
8
8
  if (packages.length) {
9
9
  let actor = await mainActor();
10
10
  await actor.notifyInstalls(packages.filter(([_, version]) => getDependencyType(version) === 'mops'));
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "ic-mops",
3
- "version": "0.39.2",
3
+ "version": "0.41.0",
4
4
  "type": "module",
5
5
  "bin": {
6
- "mops": "dist/bin/mops.js",
7
- "ic-mops": "dist/bin/mops.js",
6
+ "mops": "bin/mops.js",
7
+ "ic-mops": "bin/mops.js",
8
8
  "moc-wrapper": "bin/moc-wrapper.sh"
9
9
  },
10
10
  "files": [
@@ -25,10 +25,15 @@
25
25
  },
26
26
  "scripts": {
27
27
  "build": "tsc",
28
- "bundle": "esbuild --bundle --outfile=cli.js --platform=node --packages=external --target=node16 --format=esm ./dist/cli.js",
29
- "copy": "cp -r commands/bench dist/commands && cp -r declarations templates network.txt package.json dist | true",
30
- "save-network": "cp -r dist/network.txt . | true",
31
- "prepare": "npm run save-network && npm run build && npm run copy",
28
+ "bundle": "rm -rf ./bundle && bun build ./cli.ts --outdir ./bundle --target node --minify --external @napi-rs/lzma --external fsevents --format esm --define '__dirname=import.meta.dirname' && npm run bundle:fix && npm run bundle:copy && npm run bundle:package-json && npm run bundle:tar",
29
+ "bundle:fix": "npx -y rexreplace 'new URL\\(\"\\.\\./templates' 'new URL(\"./templates' bundle/cli.js",
30
+ "bundle:copy": "cp -r commands/bench bundle && cp -r bin declarations templates package.json bundle",
31
+ "bundle:package-json": "tsx bundle-package-json.ts",
32
+ "bundle:tar": "tar -czvf bundle/cli.tgz bundle",
33
+ "copy": "cp -r commands/bench dist/commands && cp -r declarations templates package.json bin dist | true",
34
+ "prepare": "npm run build && npm run copy && npm run remove-scripts",
35
+ "remove-scripts": "tsx ./remove-scripts.ts",
36
+ "release": "tsx release-cli.ts",
32
37
  "check": "tsc --project tsconfig.json --noEmit",
33
38
  "tsc": "tsc",
34
39
  "esbuild": "esbuild"
@@ -42,18 +47,19 @@
42
47
  "@iarna/toml": "^2.2.5",
43
48
  "@noble/hashes": "1.3.2",
44
49
  "as-table": "^1.0.55",
50
+ "buffer": "6.0.3",
45
51
  "cacheable-request": "10.2.12",
46
52
  "camelcase": "^7.0.1",
47
53
  "chalk": "^5.3.0",
48
- "chokidar": "^3.5.3",
49
- "commander": "11.1.0",
54
+ "chokidar": "3.6.0",
55
+ "commander": "12.0.0",
50
56
  "debounce": "^1.2.1",
51
57
  "decomp-tarxz": "0.1.1",
52
58
  "decompress": "^4.2.1",
53
- "del": "^7.0.0",
59
+ "del": "7.1.0",
54
60
  "dhall-to-json-cli": "^1.7.6",
55
- "eslint": "^8.45.0",
56
- "execa": "7.1.1",
61
+ "eslint": "8.57.0",
62
+ "execa": "8.0.1",
57
63
  "fs-extra": "11.2.0",
58
64
  "get-folder-size": "^4.0.0",
59
65
  "glob": "^10.3.3",
@@ -70,24 +76,27 @@
70
76
  "pem-file": "^1.0.1",
71
77
  "pic-ic": "0.3.2",
72
78
  "prompts": "^2.4.2",
79
+ "semver": "7.6.0",
73
80
  "stream-to-promise": "^3.0.0",
74
- "string-width": "7.0.0",
75
- "tar": "^6.1.15"
81
+ "string-width": "7.1.0",
82
+ "tar": "6.2.0"
76
83
  },
77
84
  "devDependencies": {
78
- "@tsconfig/strictest": "^2.0.1",
85
+ "@tsconfig/strictest": "2.0.2",
79
86
  "@types/debounce": "^1.2.1",
80
87
  "@types/decompress": "^4.2.4",
81
88
  "@types/fs-extra": "11.0.4",
82
89
  "@types/glob": "^8.1.0",
83
90
  "@types/ncp": "^2.0.5",
84
- "@types/node": "^20.4.4",
91
+ "@types/node": "20.11.24",
85
92
  "@types/prompts": "^2.4.4",
93
+ "@types/semver": "7.5.8",
86
94
  "@types/stream-to-promise": "^2.2.1",
87
95
  "@types/tar": "^6.1.5",
88
- "esbuild": "^0.18.16",
89
- "tsx": "4.6.2",
90
- "typescript": "^5.1.6"
96
+ "bun": "1.0.35",
97
+ "esbuild": "0.20.1",
98
+ "tsx": "4.7.1",
99
+ "typescript": "5.3.2"
91
100
  },
92
101
  "overrides": {
93
102
  "@dfinity/agent": "^0.19.3",
package/parallel.ts CHANGED
@@ -1,4 +1,4 @@
1
- export async function parallel(threads: number, items: any[], fn: CallableFunction) {
1
+ export async function parallel(threads : number, items : any[], fn : CallableFunction) {
2
2
  return new Promise<void>((resolve) => {
3
3
  let busyThreads = 0;
4
4
  items = items.slice();
package/pem.ts CHANGED
@@ -4,7 +4,7 @@ import {Secp256k1KeyIdentity} from '@dfinity/identity-secp256k1';
4
4
  import pemfile from 'pem-file';
5
5
  import crypto from 'crypto';
6
6
 
7
- export function decodeFile(file: string, password?: string) {
7
+ export function decodeFile(file : string, password ?: string) {
8
8
  let rawKey = fs.readFileSync(file);
9
9
  if (password) {
10
10
  return decode(decrypt(rawKey, password));
@@ -12,8 +12,8 @@ export function decodeFile(file: string, password?: string) {
12
12
  return decode(rawKey);
13
13
  }
14
14
 
15
- function decode(rawKey: Buffer) {
16
- let buf: Buffer = pemfile.decode(rawKey);
15
+ function decode(rawKey : Buffer) {
16
+ let buf : Buffer = pemfile.decode(rawKey);
17
17
  if (rawKey.includes('EC PRIVATE KEY')) {
18
18
  if (buf.length != 118) {
19
19
  throw 'expecting byte length 118 but got ' + buf.length;
@@ -29,7 +29,7 @@ function decode(rawKey: Buffer) {
29
29
 
30
30
  let algorithm = 'aes-256-ctr';
31
31
 
32
- export function encrypt(buffer: Buffer, password: string) {
32
+ export function encrypt(buffer : Buffer, password : string) {
33
33
  let key = crypto.createHash('sha256').update(password).digest('base64').slice(0, 32);
34
34
  // Create an initialization vector
35
35
  let iv = crypto.randomBytes(16);
@@ -40,7 +40,7 @@ export function encrypt(buffer: Buffer, password: string) {
40
40
  return result;
41
41
  }
42
42
 
43
- function decrypt(encrypted: Buffer, password: string) {
43
+ function decrypt(encrypted : Buffer, password : string) {
44
44
  let key = crypto.createHash('sha256').update(password).digest('base64').slice(0, 32);
45
45
  // Get the iv: the first 16 bytes
46
46
  let iv = encrypted.subarray(0, 16);
package/release-cli.ts ADDED
@@ -0,0 +1,62 @@
1
+ /* eslint-disable no-undef */
2
+ import fs from 'node:fs';
3
+ import path from 'node:path';
4
+ import {URL} from 'node:url';
5
+ import {execSync} from 'node:child_process';
6
+ import semver from 'semver';
7
+ import {sha256} from '@noble/hashes/sha256';
8
+ import {bytesToHex} from '@noble/hashes/utils';
9
+
10
+ import {findChangelogEntry} from './helpers/find-changelog-entry.js';
11
+
12
+ let __dirname = new URL('.', import.meta.url).pathname;
13
+
14
+ execSync('npm run prepare', {stdio: 'inherit', cwd: __dirname});
15
+ execSync('npm run bundle', {stdio: 'inherit', cwd: __dirname});
16
+
17
+ let version = JSON.parse(fs.readFileSync(path.resolve(__dirname, 'package.json'), 'utf8')).version;
18
+ let major = semver.parse(version)?.major;
19
+ let tag = semver.parse(version)?.prerelease[0] || 'latest';
20
+ let releaseNotes = findChangelogEntry(fs.readFileSync(path.resolve(__dirname, 'CHANGELOG.md'), 'utf8'), version);
21
+ let data = fs.readFileSync(path.resolve(__dirname, 'bundle/cli.tgz'));
22
+ let hash = bytesToHex(sha256(data));
23
+ let size = data.byteLength;
24
+
25
+ fs.cpSync(path.resolve(__dirname, 'bundle/cli.tgz'), path.resolve(__dirname, `../cli-releases/versions/${version}.tgz`), {force: false, errorOnExist: true});
26
+
27
+ fs.cpSync(path.resolve(__dirname, `../cli-releases/versions/${version}.tgz`), path.resolve(__dirname, `../cli-releases/versions/${tag}.tgz`), {force: true, errorOnExist: false, recursive: true});
28
+ fs.cpSync(path.resolve(__dirname, `../cli-releases/versions/${version}.tgz`), path.resolve(__dirname, `../cli-releases/versions/${major}.tgz`), {force: true, errorOnExist: false, recursive: true});
29
+
30
+ fs.writeFileSync(path.resolve(__dirname, `../cli-releases/tags/${tag}`), version);
31
+
32
+ console.log(`Release '${version}' created with tag '${tag}'`);
33
+
34
+
35
+ // releases.json
36
+ type Releases = {
37
+ tags : Record<string, string>;
38
+ versions : Record<string, {
39
+ time : number;
40
+ size : number;
41
+ hash : string;
42
+ url : string;
43
+ relseaseNotes : string;
44
+ }>;
45
+ };
46
+
47
+ if (!fs.existsSync(path.resolve(__dirname, '../cli-releases/releases.json'))) {
48
+ fs.writeFileSync(path.resolve(__dirname, '../cli-releases/releases.json'), JSON.stringify({tags: {}, versions: {}}, null, 2));
49
+ }
50
+
51
+ let releases : Releases = JSON.parse(fs.readFileSync(path.resolve(__dirname, '../cli-releases/releases.json'), 'utf8'));
52
+
53
+ releases.tags[tag] = version;
54
+ releases.versions[version] = {
55
+ time: new Date().getTime(),
56
+ size,
57
+ relseaseNotes: releaseNotes,
58
+ url: `https://cli.mops.one/versions/${version}.tgz`,
59
+ hash,
60
+ };
61
+
62
+ fs.writeFileSync(path.resolve(__dirname, '../cli-releases/releases.json'), JSON.stringify(releases, null, 2));
@@ -0,0 +1,6 @@
1
+ import {readFileSync, writeFileSync} from 'node:fs';
2
+
3
+ let text = readFileSync('dist/package.json', 'utf8');
4
+ let json = JSON.parse(text);
5
+ delete json.scripts;
6
+ writeFileSync('dist/package.json', JSON.stringify(json, null, 2));
@@ -4,18 +4,18 @@ import {checkConfigFile, formatDir, formatGithubDir, getRootDir, parseGithubURL,
4
4
  import {VesselConfig, readVesselConfig} from './vessel.js';
5
5
  import {Config, Dependency} from './types.js';
6
6
 
7
- export async function resolvePackages({verbose = false} = {}): Promise<Record<string, string>> {
7
+ export async function resolvePackages({verbose = false} = {}) : Promise<Record<string, string>> {
8
8
  if (!checkConfigFile()) {
9
9
  return {};
10
10
  }
11
11
 
12
12
  let rootDir = getRootDir();
13
- let packages: Record<string, Dependency & {isRoot: boolean;}> = {};
14
- let versions: Record<string, string[]> = {};
13
+ let packages : Record<string, Dependency & {isRoot : boolean;}> = {};
14
+ let versions : Record<string, string[]> = {};
15
15
 
16
- let compareVersions = (a: string = '0.0.0', b: string = '0.0.0') => {
17
- let ap = a.split('.').map((x: string) => parseInt(x)) as [number, number, number];
18
- let bp = b.split('.').map((x: string) => parseInt(x)) as [number, number, number];
16
+ let compareVersions = (a : string = '0.0.0', b : string = '0.0.0') => {
17
+ let ap = a.split('.').map((x : string) => parseInt(x)) as [number, number, number];
18
+ let bp = b.split('.').map((x : string) => parseInt(x)) as [number, number, number];
19
19
  if (ap[0] - bp[0]) {
20
20
  return Math.sign(ap[0] - bp[0]);
21
21
  }
@@ -30,7 +30,7 @@ export async function resolvePackages({verbose = false} = {}): Promise<Record<st
30
30
 
31
31
  const gitVerRegex = new RegExp(/v(\d{1,2}\.\d{1,2}\.\d{1,2})(-.*)?$/);
32
32
 
33
- const compareGitVersions = (repoA: string, repoB: string) => {
33
+ const compareGitVersions = (repoA : string, repoB : string) => {
34
34
  const {branch: a} = parseGithubURL(repoA);
35
35
  const {branch: b} = parseGithubURL(repoB);
36
36
 
@@ -45,7 +45,7 @@ export async function resolvePackages({verbose = false} = {}): Promise<Record<st
45
45
  }
46
46
  };
47
47
 
48
- let collectDeps = async (config: Config | VesselConfig, configDir: string, isRoot = false) => {
48
+ let collectDeps = async (config : Config | VesselConfig, configDir : string, isRoot = false) => {
49
49
  let allDeps = [...Object.values(config.dependencies || {})];
50
50
  if (isRoot) {
51
51
  allDeps = [...allDeps, ...Object.values(config['dev-dependencies'] || {})];
@@ -124,7 +124,7 @@ export async function resolvePackages({verbose = false} = {}): Promise<Record<st
124
124
 
125
125
  return Object.fromEntries(
126
126
  Object.entries(packages).map(([name, pkg]) => {
127
- let version: string;
127
+ let version : string;
128
128
  if (pkg.path) {
129
129
  version = path.resolve(rootDir, pkg.path).replaceAll('{MOPS_ENV}', process.env.MOPS_ENV || 'local');
130
130
  }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
package/templates.ts ADDED
@@ -0,0 +1,5 @@
1
+ import fs from 'node:fs';
2
+
3
+ export function copyTemplateFileSync(file : string, dest : string) {
4
+ fs.copyFileSync(new URL(`./templates/${file}`, import.meta.url), dest);
5
+ }
package/tsconfig.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "extends": ["@tsconfig/strictest/tsconfig.json"],
3
3
  "include": ["**/*.ts", "**/*.js"],
4
- "exclude": ["node_modules", "dist", "dist.js", "declarations/**/*.js"],
4
+ "exclude": ["node_modules", "dist", "bundle", "dist.js", "declarations/**/*.js"],
5
5
  "compilerOptions": {
6
6
  "types": ["node"],
7
7
  "target": "ES2021",
package/types.ts CHANGED
@@ -1,38 +1,38 @@
1
1
  export type Config = {
2
- package?: {
3
- name: string;
4
- version: string;
5
- description?: string;
6
- license?: string;
7
- repository?: string;
8
- keywords?: string[];
9
- baseDir?: string;
10
- readme?: string;
11
- files?: string[];
12
- homepage?: string;
13
- documentation?: string;
14
- dfx?: string;
15
- moc?: string;
16
- donation?: string;
2
+ package ?: {
3
+ name : string;
4
+ version : string;
5
+ description ?: string;
6
+ license ?: string;
7
+ repository ?: string;
8
+ keywords ?: string[];
9
+ baseDir ?: string;
10
+ readme ?: string;
11
+ files ?: string[];
12
+ homepage ?: string;
13
+ documentation ?: string;
14
+ dfx ?: string;
15
+ moc ?: string;
16
+ donation ?: string;
17
17
  };
18
- dependencies?: Dependencies;
19
- 'dev-dependencies'?: Dependencies;
20
- toolchain?: Toolchain;
18
+ dependencies ?: Dependencies;
19
+ 'dev-dependencies' ?: Dependencies;
20
+ toolchain ?: Toolchain;
21
21
  };
22
22
 
23
23
  export type Dependencies = Record<string, Dependency>;
24
24
 
25
25
  export type Dependency = {
26
- name: string;
27
- version?: string; // mops package
28
- repo?: string; // github package
29
- path?: string; // local package
26
+ name : string;
27
+ version ?: string; // mops package
28
+ repo ?: string; // github package
29
+ path ?: string; // local package
30
30
  }
31
31
 
32
32
  export type Toolchain = {
33
- moc?: string;
34
- wasmtime?: string;
35
- 'pocket-ic'?: string;
33
+ moc ?: string;
34
+ wasmtime ?: string;
35
+ 'pocket-ic' ?: string;
36
36
  };
37
37
 
38
38
  export type Tool = 'moc' | 'wasmtime' | 'pocket-ic';
package/vessel.ts CHANGED
@@ -10,14 +10,14 @@ import {pipeline} from 'stream';
10
10
  import {formatGithubDir, parseGithubURL, progressBar} from './mops.js';
11
11
  import {addCache, copyCache, isCached} from './cache.js';
12
12
 
13
- const dhallFileToJson = async (filePath: string, silent: boolean) => {
13
+ const dhallFileToJson = async (filePath : string, silent : boolean) => {
14
14
  if (existsSync(filePath)) {
15
15
  let cwd = new URL(path.dirname(import.meta.url)).pathname;
16
16
  let res;
17
17
  try {
18
18
  res = await execaCommand(`dhall-to-json --file ${filePath}`, {preferLocal:true, cwd});
19
19
  }
20
- catch (err: any) {
20
+ catch (err : any) {
21
21
  silent || console.error('dhall-to-json error:', err.message?.split('Message:')[0]);
22
22
  return null;
23
23
  }
@@ -34,18 +34,18 @@ const dhallFileToJson = async (filePath: string, silent: boolean) => {
34
34
  };
35
35
 
36
36
  export type VesselConfig = {
37
- dependencies: VesselDependencies;
38
- 'dev-dependencies': VesselDependencies;
37
+ dependencies : VesselDependencies;
38
+ 'dev-dependencies' : VesselDependencies;
39
39
  };
40
40
 
41
41
  export type VesselDependencies = Array<{
42
- name: string;
43
- version?: string; // mops package
44
- repo?: string; // github package
45
- path?: string; // local package
42
+ name : string;
43
+ version ?: string; // mops package
44
+ repo ?: string; // github package
45
+ path ?: string; // local package
46
46
  }>;
47
47
 
48
- export const readVesselConfig = async (dir: string, {cache = true, silent = false} = {}): Promise<VesselConfig | null> => {
48
+ export const readVesselConfig = async (dir : string, {cache = true, silent = false} = {}) : Promise<VesselConfig | null> => {
49
49
  const cachedFile = (dir || process.cwd()) + '/vessel.json';
50
50
 
51
51
  if (existsSync(cachedFile)) {
@@ -55,21 +55,21 @@ export const readVesselConfig = async (dir: string, {cache = true, silent = fals
55
55
 
56
56
  const [vessel, packageSetArray] = await Promise.all([
57
57
  dhallFileToJson((dir || process.cwd()) + '/vessel.dhall', silent),
58
- dhallFileToJson((dir || process.cwd()) + '/package-set.dhall', silent)
58
+ dhallFileToJson((dir || process.cwd()) + '/package-set.dhall', silent),
59
59
  ]);
60
60
 
61
61
  if (!vessel || !packageSetArray) {
62
62
  return null;
63
63
  }
64
64
 
65
- let repos: Record<string, string> = {};
65
+ let repos : Record<string, string> = {};
66
66
  for (const {name, repo, version} of packageSetArray) {
67
67
  const {org, gitName} = parseGithubURL(repo);
68
68
  repos[name] = `https://github.com/${org}/${gitName}#${version}`;
69
69
  }
70
70
 
71
- let config: VesselConfig = {
72
- dependencies: vessel.dependencies.map((name: string) => {
71
+ let config : VesselConfig = {
72
+ dependencies: vessel.dependencies.map((name : string) => {
73
73
  return {name, repo: repos[name], version: ''};
74
74
  }),
75
75
  'dev-dependencies': [],
@@ -82,7 +82,7 @@ export const readVesselConfig = async (dir: string, {cache = true, silent = fals
82
82
  return config;
83
83
  };
84
84
 
85
- export const downloadFromGithub = async (repo: string, dest: string, onProgress: any) => {
85
+ export const downloadFromGithub = async (repo : string, dest : string, onProgress : any) => {
86
86
  const {branch, org, gitName, commitHash} = parseGithubURL(repo);
87
87
 
88
88
  const zipFile = `https://github.com/${org}/${gitName}/archive/${commitHash || branch}.zip`;
@@ -148,7 +148,7 @@ export const downloadFromGithub = async (repo: string, dest: string, onProgress:
148
148
  return promise;
149
149
  };
150
150
 
151
- export const installFromGithub = async (name: string, repo: string, {verbose = false, dep = false, silent = false} = {}) => {
151
+ export const installFromGithub = async (name : string, repo : string, {verbose = false, dep = false, silent = false} = {}) => {
152
152
  let {branch, commitHash} = parseGithubURL(repo);
153
153
  let dir = formatGithubDir(name, repo);
154
154
  let cacheName = `_github/${name}#${branch}` + (commitHash ? `@${commitHash}` : '');
@@ -165,7 +165,7 @@ export const installFromGithub = async (name: string, repo: string, {verbose = f
165
165
  else {
166
166
  mkdirSync(dir, {recursive: true});
167
167
 
168
- let progress = (step: number, total: number) => {
168
+ let progress = (step : number, total : number) => {
169
169
  silent || logUpdate(`${dep ? 'Dependency' : 'Installing'} ${repo} ${progressBar(step, total)}`);
170
170
  };
171
171
 
@@ -1,6 +0,0 @@
1
- import child_process from 'node:child_process';
2
-
3
- export function selfUpdate({detached = false} = {}) {
4
- console.log('Updating mops CLI...');
5
- child_process.spawn('npm', ['install', 'ic-mops', '-g'], {stdio: 'inherit', detached});
6
- }
@@ -1,36 +0,0 @@
1
- /// <reference types="node" resolution-mode="require"/>
2
- import { ChildProcess, ChildProcessWithoutNullStreams } from 'node:child_process';
3
- import { PocketIc } from 'pic-ic';
4
- export declare class Replica {
5
- type: 'dfx' | 'pocket-ic';
6
- cwd: string;
7
- verbose: boolean;
8
- canisters: Record<string, {
9
- cwd: string;
10
- canisterId: string;
11
- actor: any;
12
- }>;
13
- pocketIc?: PocketIc;
14
- process?: ChildProcess;
15
- constructor(type: 'dfx' | 'pocket-ic', cwd: string, verbose?: boolean);
16
- start(): Promise<ChildProcessWithoutNullStreams>;
17
- stop(): Promise<void>;
18
- deploy(name: string, wasm: string, cwd?: string): Promise<void>;
19
- getActor(name: string): unknown;
20
- getCanisterId(name: string): string;
21
- dfxJson(canisterName: string): {
22
- version: number;
23
- canisters: Record<string, any>;
24
- defaults: {
25
- build: {
26
- packtool: string;
27
- };
28
- };
29
- networks: {
30
- local: {
31
- type: string;
32
- bind: string;
33
- };
34
- };
35
- };
36
- }