@jonsoc/script 1.1.43

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 ADDED
@@ -0,0 +1,15 @@
1
+ {
2
+ "$schema": "https://json.schemastore.org/package",
3
+ "name": "@jonsoc/script",
4
+ "version": "1.1.43",
5
+ "license": "MIT",
6
+ "devDependencies": {
7
+ "@types/bun": "catalog:"
8
+ },
9
+ "exports": {
10
+ ".": "./src/index.ts"
11
+ },
12
+ "publishConfig": {
13
+ "access": "public"
14
+ }
15
+ }
package/src/index.ts ADDED
@@ -0,0 +1,65 @@
1
+ import { $, semver } from "bun"
2
+ import path from "path"
3
+
4
+ const rootPkgPath = path.resolve(import.meta.dir, "../../../package.json")
5
+ const rootPkg = await Bun.file(rootPkgPath).json()
6
+ const expectedBunVersion = rootPkg.packageManager?.split("@")[1]
7
+
8
+ if (!expectedBunVersion) {
9
+ throw new Error("packageManager field not found in root package.json")
10
+ }
11
+
12
+ // relax version requirement
13
+ const expectedBunVersionRange = `^${expectedBunVersion}`
14
+
15
+ if (!semver.satisfies(process.versions.bun, expectedBunVersionRange)) {
16
+ throw new Error(`This script requires bun@${expectedBunVersionRange}, but you are using bun@${process.versions.bun}`)
17
+ }
18
+
19
+ const env = {
20
+ OPENCODE_CHANNEL: process.env["OPENCODE_CHANNEL"] || "latest",
21
+ OPENCODE_BUMP: process.env["OPENCODE_BUMP"],
22
+ OPENCODE_VERSION: process.env["OPENCODE_VERSION"],
23
+ }
24
+ const CHANNEL = await (async () => {
25
+ if (env.OPENCODE_CHANNEL !== "latest") return env.OPENCODE_CHANNEL
26
+ if (env.OPENCODE_BUMP) return "latest"
27
+ if (env.OPENCODE_VERSION && !env.OPENCODE_VERSION.startsWith("0.0.0-")) return "latest"
28
+ return "latest"
29
+ })()
30
+ const IS_PREVIEW = CHANNEL !== "latest"
31
+
32
+ const VERSION = await (async () => {
33
+ if (IS_PREVIEW) return `0.0.0-${CHANNEL}-${new Date().toISOString().slice(0, 16).replace(/[-:T]/g, "")}`
34
+
35
+ const raw = env.OPENCODE_VERSION ?? ""
36
+ const base = raw.trim() ? raw.trim() : "1.1.41"
37
+ const bump = env.OPENCODE_BUMP
38
+ if (!bump) return base
39
+
40
+ const match = base.match(/^(\d+)\.(\d+)\.(\d+)/)
41
+ if (!match) throw new Error(`Cannot bump invalid version: ${base}`)
42
+
43
+ const major = Number(match[1])
44
+ const minor = Number(match[2])
45
+ const patch = Number(match[3])
46
+
47
+ if (bump === "major") return `${major + 1}.0.0`
48
+ if (bump === "minor") return `${major}.${minor + 1}.0`
49
+ if (bump === "patch") return `${major}.${minor}.${patch + 1}`
50
+
51
+ throw new Error(`Unknown bump: ${bump}`)
52
+ })()
53
+
54
+ export const Script = {
55
+ get channel() {
56
+ return CHANNEL
57
+ },
58
+ get version() {
59
+ return VERSION
60
+ },
61
+ get preview() {
62
+ return IS_PREVIEW
63
+ },
64
+ }
65
+ console.log(`jonsoc script`, JSON.stringify(Script, null, 2))
package/sst-env.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ /* This file is auto-generated by SST. Do not edit. */
2
+ /* tslint:disable */
3
+ /* eslint-disable */
4
+ /* deno-fmt-ignore-file */
5
+
6
+ /// <reference path="../../sst-env.d.ts" />
7
+
8
+ import "sst"
9
+ export {}
package/tsconfig.json ADDED
@@ -0,0 +1,8 @@
1
+ {
2
+ "$schema": "https://json.schemastore.org/tsconfig",
3
+ "extends": "@tsconfig/bun/tsconfig.json",
4
+ "compilerOptions": {
5
+ "lib": ["ESNext", "DOM", "DOM.Iterable"],
6
+ "noUncheckedIndexedAccess": false
7
+ }
8
+ }