@slim-lang/core 1.2.5 → 1.2.8

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@slim-lang/core",
3
- "version": "1.2.5",
3
+ "version": "1.2.8",
4
4
  "description": "Slim extends JavaScript with runtime types, structs, operators, and components, compiling to plain Javascript",
5
5
  "main": "index.js",
6
6
  "type": "module",
package/src/bin/cli.js CHANGED
@@ -15,9 +15,7 @@ import pkg from "../../package.json" with { type: "json" };
15
15
  import defaultConfig from "./config.default.json" with { type: "json" };
16
16
 
17
17
  const root = process.cwd()
18
- // Toolchain scripts (compiler, runners) live inside the package, which is only
19
- // the same as the project root during local development. Resolve them from this
20
- // file's location so the commands work when installed from npm too.
18
+
21
19
  const packageRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..", "..")
22
20
  const compileScript = JSON.stringify(path.join(packageRoot, "src", "compile.js"))
23
21
  const runScript = JSON.stringify(path.join(packageRoot, "run-slim.js"))
@@ -296,16 +294,35 @@ program
296
294
 
297
295
  if(params.check) {
298
296
  const githubRepo = pkg.repository.url.split("git+https://github.com/")[1].trim().split(".git")[0]
299
- const res = await fetch("https://raw.githubusercontent.com/" + githubRepo + "/main/package.json")
300
- const githubPkg = await res.json()
297
+ if(!/^[\w.-]+\/[\w.-]+$/.test(githubRepo)) {
298
+ error("Unable to determine a valid GitHub repository for version check")
299
+ return
300
+ }
301
+
302
+ try {
303
+ const res = await fetch("https://raw.githubusercontent.com/" + githubRepo + "/main/package.json")
304
+ if(!res.ok) {
305
+ error(`Version check failed: received HTTP ${res.status} from GitHub`)
306
+ return
307
+ }
301
308
 
302
- if(githubPkg.version != pkg.version) {
303
- log(`Your version is not compatible with the latest version of Slim:
309
+ const githubPkg = await res.json()
310
+ if(typeof githubPkg?.version !== "string" || !/^\d+\.\d+\.\d+/.test(githubPkg.version)) {
311
+ error("Version check failed: unexpected response format")
312
+ return
313
+ }
314
+
315
+ if(githubPkg.version != pkg.version) {
316
+ log(`Your version is not compatible with the latest version of Slim:
304
317
  Current: ${githubPkg.version}
305
318
  Your's: ${pkg.version}`)
319
+ }
320
+ else {
321
+ log(`You on the latest Slim version`)
322
+ }
306
323
  }
307
- else {
308
- log(`You on the latest Slim version`)
324
+ catch (err) {
325
+ error(`Version check failed: ${err?.message ?? err}`)
309
326
  }
310
327
  return
311
328
  }
@@ -555,11 +555,7 @@ function parseTypesEdits(code) {
555
555
  let bodyContent = body.content.trim()
556
556
 
557
557
  const normalizedBody = bodyContent.replace(/;\s*$/, "").trim()
558
- if (!/^return(?:\s+[\s\S]+)?$/.test(normalizedBody)) {
559
- throw new TypeDefError(`The "${typeName}" type body must contain exactly one return statement`)
560
- }
561
-
562
- if (normalizedBody === "return") bodyContent = "return true"
558
+ if (normalizedBody === "" || normalizedBody === "return") bodyContent = "return true"
563
559
 
564
560
  edits.push({
565
561
  start,