@zyro-sec/script 1.0.1 → 1.0.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/package.json CHANGED
@@ -13,7 +13,12 @@
13
13
  "@types/bun": "1.4.3",
14
14
  "@types/semver": "^7.5.8"
15
15
  },
16
- "version": "1.0.1",
16
+ "exports": {
17
+ ".": "./src/index.ts",
18
+ "./highlights": "./src/highlights.ts",
19
+ "./pack": "./src/pack.ts"
20
+ },
21
+ "version": "1.0.3",
17
22
  "publishConfig": {
18
23
  "access": "public"
19
24
  },
package/src/highlights.ts CHANGED
@@ -1,68 +1,68 @@
1
- export type Highlight = { title: string; body: string }
2
-
3
- const LIMIT = { items: 5, title: 60, body: 300 }
4
-
5
- /**
6
- * Extracts the `### Highlights` bullets from reviewed release notes. Each bullet is expected to look like
7
- * `- **Title**: One or two sentences. ([#123](https://github.com/...))`; trailing pull request links are dropped and
8
- * inline Markdown is reduced to plain text, keeping backticks for code spans. Problems are reported instead of thrown
9
- * so a formatting mistake never fails a release build.
10
- */
11
- export function parse(notes: string) {
12
- const problems: string[] = []
13
- const lines = notes.replace(/\r\n/g, "\n").split("\n")
14
- const start = lines.findIndex((line) => /^###\s+Highlights\s*$/i.test(line.trim()))
15
- if (start === -1) return { items: [] as Highlight[], problems }
16
- const end = lines.findIndex((line, index) => index > start && /^#{1,3}\s/.test(line))
17
- const bullets = lines.slice(start + 1, end === -1 ? undefined : end).reduce(
18
- (state, line) => {
19
- if (line.trim().startsWith("```")) return { ...state, fenced: !state.fenced }
20
- if (state.fenced) return state
21
- const bullet = line.match(/^[-*]\s+(.*)$/)
22
- if (bullet) return { ...state, items: [...state.items, bullet[1]] }
23
- if (state.items.length && /^\s+\S/.test(line))
24
- return { ...state, items: [...state.items.slice(0, -1), `${state.items.at(-1)} ${line.trim()}`] }
25
- return state
26
- },
27
- { fenced: false, items: [] as string[] },
28
- ).items
29
-
30
- const items = bullets.flatMap((bullet) => {
31
- const match = bullet.match(/^\*\*(.+?)\*\*:?\s*(.*)$/)
32
- const title = match && plain(match[1].replace(/:$/, ""))
33
- const body = match && plain(match[2].replace(/\s*\((?:\[[^\]]*\]\([^)]*\)(?:,\s*)?)+\)\s*$/, ""))
34
- if (!title || !body) {
35
- problems.push(`Skipped a highlight without a bold title and description: ${bullet.slice(0, 80)}`)
36
- return []
37
- }
38
- return [{ title: truncate(title, LIMIT.title), body: truncate(body, LIMIT.body) }]
39
- })
40
-
41
- if (items.length > LIMIT.items) problems.push(`Kept the first ${LIMIT.items} of ${items.length} highlights`)
42
- if (!items.length) problems.push("The Highlights section has no highlights in the expected format")
43
- return { items: items.slice(0, LIMIT.items), problems }
44
- }
45
-
46
- function plain(value: string) {
47
- return value
48
- .replace(/\*\*(.+?)\*\*/g, "$1")
49
- .replace(/\[([^\]]+)\]\([^)]+\)/g, "$1")
50
- .replace(/\s+/g, " ")
51
- .trim()
52
- }
53
-
54
- function truncate(value: string, limit: number) {
55
- if (value.length <= limit) return value
56
- const cut = value.slice(0, limit - 1)
57
- const space = cut.lastIndexOf(" ")
58
- return `${(space > limit / 2 ? cut.slice(0, space) : cut).trimEnd()}…`
59
- }
60
-
61
- /** Returns the JSON a stable release build embeds as `OPENCODE_RELEASE_HIGHLIGHTS`, warning about malformed notes. */
62
- export function embed(notes: string | undefined) {
63
- if (!notes?.trim()) return
64
- const result = parse(notes)
65
- result.problems.forEach((problem) => console.warn(`release highlights: ${problem}`))
66
- if (!result.items.length) return
67
- return JSON.stringify(result.items)
68
- }
1
+ export type Highlight = { title: string; body: string }
2
+
3
+ const LIMIT = { items: 5, title: 60, body: 300 }
4
+
5
+ /**
6
+ * Extracts the `### Highlights` bullets from reviewed release notes. Each bullet is expected to look like
7
+ * `- **Title**: One or two sentences. ([#123](https://github.com/...))`; trailing pull request links are dropped and
8
+ * inline Markdown is reduced to plain text, keeping backticks for code spans. Problems are reported instead of thrown
9
+ * so a formatting mistake never fails a release build.
10
+ */
11
+ export function parse(notes: string) {
12
+ const problems: string[] = []
13
+ const lines = notes.replace(/\r\n/g, "\n").split("\n")
14
+ const start = lines.findIndex((line) => /^###\s+Highlights\s*$/i.test(line.trim()))
15
+ if (start === -1) return { items: [] as Highlight[], problems }
16
+ const end = lines.findIndex((line, index) => index > start && /^#{1,3}\s/.test(line))
17
+ const bullets = lines.slice(start + 1, end === -1 ? undefined : end).reduce(
18
+ (state, line) => {
19
+ if (line.trim().startsWith("```")) return { ...state, fenced: !state.fenced }
20
+ if (state.fenced) return state
21
+ const bullet = line.match(/^[-*]\s+(.*)$/)
22
+ if (bullet) return { ...state, items: [...state.items, bullet[1]] }
23
+ if (state.items.length && /^\s+\S/.test(line))
24
+ return { ...state, items: [...state.items.slice(0, -1), `${state.items.at(-1)} ${line.trim()}`] }
25
+ return state
26
+ },
27
+ { fenced: false, items: [] as string[] },
28
+ ).items
29
+
30
+ const items = bullets.flatMap((bullet) => {
31
+ const match = bullet.match(/^\*\*(.+?)\*\*:?\s*(.*)$/)
32
+ const title = match && plain(match[1].replace(/:$/, ""))
33
+ const body = match && plain(match[2].replace(/\s*\((?:\[[^\]]*\]\([^)]*\)(?:,\s*)?)+\)\s*$/, ""))
34
+ if (!title || !body) {
35
+ problems.push(`Skipped a highlight without a bold title and description: ${bullet.slice(0, 80)}`)
36
+ return []
37
+ }
38
+ return [{ title: truncate(title, LIMIT.title), body: truncate(body, LIMIT.body) }]
39
+ })
40
+
41
+ if (items.length > LIMIT.items) problems.push(`Kept the first ${LIMIT.items} of ${items.length} highlights`)
42
+ if (!items.length) problems.push("The Highlights section has no highlights in the expected format")
43
+ return { items: items.slice(0, LIMIT.items), problems }
44
+ }
45
+
46
+ function plain(value: string) {
47
+ return value
48
+ .replace(/\*\*(.+?)\*\*/g, "$1")
49
+ .replace(/\[([^\]]+)\]\([^)]+\)/g, "$1")
50
+ .replace(/\s+/g, " ")
51
+ .trim()
52
+ }
53
+
54
+ function truncate(value: string, limit: number) {
55
+ if (value.length <= limit) return value
56
+ const cut = value.slice(0, limit - 1)
57
+ const space = cut.lastIndexOf(" ")
58
+ return `${(space > limit / 2 ? cut.slice(0, space) : cut).trimEnd()}…`
59
+ }
60
+
61
+ /** Returns the JSON a stable release build embeds as `OPENCODE_RELEASE_HIGHLIGHTS`, warning about malformed notes. */
62
+ export function embed(notes: string | undefined) {
63
+ if (!notes?.trim()) return
64
+ const result = parse(notes)
65
+ result.problems.forEach((problem) => console.warn(`release highlights: ${problem}`))
66
+ if (!result.items.length) return
67
+ return JSON.stringify(result.items)
68
+ }
package/src/index.ts CHANGED
@@ -1,74 +1,74 @@
1
- import { $ } from "bun"
2
- import semver from "semver"
3
- import path from "path"
4
-
5
- const rootPkgPath = path.resolve(import.meta.dir, "../../../package.json")
6
- const rootPkg = await Bun.file(rootPkgPath).json()
7
- const expectedBunVersion = rootPkg.packageManager?.split("@")[1]
8
-
9
- if (!expectedBunVersion) {
10
- throw new Error("packageManager field not found in root package.json")
11
- }
12
-
13
- // relax version requirement
14
- const expectedBunVersionRange = `^${expectedBunVersion}`
15
-
16
- if (!semver.satisfies(process.versions.bun, expectedBunVersionRange)) {
17
- throw new Error(`This script requires bun@${expectedBunVersionRange}, but you are using bun@${process.versions.bun}`)
18
- }
19
-
20
- const env = {
21
- OPENCODE_CHANNEL: process.env["OPENCODE_CHANNEL"],
22
- OPENCODE_VERSION: process.env["OPENCODE_VERSION"],
23
- }
24
- const CHANNEL = await (async () => {
25
- if (env.OPENCODE_CHANNEL) return env.OPENCODE_CHANNEL
26
- if (env.OPENCODE_VERSION && !env.OPENCODE_VERSION.startsWith("0.0.0-")) return "latest"
27
- const branch = await $`git branch --show-current`.text().then((x) => x.trim())
28
- if (!branch) return "detached"
29
- const channel = branch.replace(/[^a-zA-Z0-9._-]/g, "-")
30
- if (/^[a-zA-Z0-9]/.test(channel)) return channel
31
- return `branch-${channel}`
32
- })()
33
- const IS_PREVIEW = CHANNEL !== "latest"
34
-
35
- // The release workflow's plan job owns release versions; builds only read them.
36
- const VERSION = (() => {
37
- if (env.OPENCODE_VERSION) return env.OPENCODE_VERSION
38
- if (!IS_PREVIEW) throw new Error("OPENCODE_VERSION is required for latest-channel builds")
39
- return `0.0.0-${CHANNEL}-${previewBuildNumber()}`
40
- })()
41
-
42
- function previewBuildNumber() {
43
- const runNumber = process.env["GITHUB_RUN_NUMBER"]
44
- if (!runNumber) return new Date().toISOString().slice(0, 16).replace(/[-:T]/g, "")
45
- const runAttempt = process.env["GITHUB_RUN_ATTEMPT"]
46
- if (runAttempt && runAttempt !== "1") return `${runNumber}.${runAttempt}`
47
- return runNumber
48
- }
49
-
50
- const bot = ["actions-user", "opencode", "opencode-agent[bot]"]
51
- const teamPath = path.resolve(import.meta.dir, "../../../.github/TEAM_MEMBERS")
52
- const team = [
53
- ...(await Bun.file(teamPath)
54
- .text()
55
- .then((x) => x.split(/\r?\n/).map((x) => x.trim()))
56
- .then((x) => x.filter((x) => x && !x.startsWith("#")))),
57
- ...bot,
58
- ]
59
-
60
- export const Script = {
61
- get channel() {
62
- return CHANNEL
63
- },
64
- get version() {
65
- return VERSION
66
- },
67
- get preview() {
68
- return IS_PREVIEW
69
- },
70
- get team() {
71
- return team
72
- },
73
- }
74
- console.log(`opencode script`, JSON.stringify(Script, null, 2))
1
+ import { $ } from "bun"
2
+ import semver from "semver"
3
+ import path from "path"
4
+
5
+ const rootPkgPath = path.resolve(import.meta.dir, "../../../package.json")
6
+ const rootPkg = await Bun.file(rootPkgPath).json()
7
+ const expectedBunVersion = rootPkg.packageManager?.split("@")[1]
8
+
9
+ if (!expectedBunVersion) {
10
+ throw new Error("packageManager field not found in root package.json")
11
+ }
12
+
13
+ // relax version requirement
14
+ const expectedBunVersionRange = `^${expectedBunVersion}`
15
+
16
+ if (!semver.satisfies(process.versions.bun, expectedBunVersionRange)) {
17
+ throw new Error(`This script requires bun@${expectedBunVersionRange}, but you are using bun@${process.versions.bun}`)
18
+ }
19
+
20
+ const env = {
21
+ OPENCODE_CHANNEL: process.env["OPENCODE_CHANNEL"],
22
+ OPENCODE_VERSION: process.env["OPENCODE_VERSION"],
23
+ }
24
+ const CHANNEL = await (async () => {
25
+ if (env.OPENCODE_CHANNEL) return env.OPENCODE_CHANNEL
26
+ if (env.OPENCODE_VERSION && !env.OPENCODE_VERSION.startsWith("0.0.0-")) return "latest"
27
+ const branch = await $`git branch --show-current`.text().then((x) => x.trim())
28
+ if (!branch) return "detached"
29
+ const channel = branch.replace(/[^a-zA-Z0-9._-]/g, "-")
30
+ if (/^[a-zA-Z0-9]/.test(channel)) return channel
31
+ return `branch-${channel}`
32
+ })()
33
+ const IS_PREVIEW = CHANNEL !== "latest"
34
+
35
+ // The release workflow's plan job owns release versions; builds only read them.
36
+ const VERSION = (() => {
37
+ if (env.OPENCODE_VERSION) return env.OPENCODE_VERSION
38
+ if (!IS_PREVIEW) throw new Error("OPENCODE_VERSION is required for latest-channel builds")
39
+ return `0.0.0-${CHANNEL}-${previewBuildNumber()}`
40
+ })()
41
+
42
+ function previewBuildNumber() {
43
+ const runNumber = process.env["GITHUB_RUN_NUMBER"]
44
+ if (!runNumber) return new Date().toISOString().slice(0, 16).replace(/[-:T]/g, "")
45
+ const runAttempt = process.env["GITHUB_RUN_ATTEMPT"]
46
+ if (runAttempt && runAttempt !== "1") return `${runNumber}.${runAttempt}`
47
+ return runNumber
48
+ }
49
+
50
+ const bot = ["actions-user", "opencode", "opencode-agent[bot]"]
51
+ const teamPath = path.resolve(import.meta.dir, "../../../.github/TEAM_MEMBERS")
52
+ const team = [
53
+ ...(await Bun.file(teamPath)
54
+ .text()
55
+ .then((x) => x.split(/\r?\n/).map((x) => x.trim()))
56
+ .then((x) => x.filter((x) => x && !x.startsWith("#")))),
57
+ ...bot,
58
+ ]
59
+
60
+ export const Script = {
61
+ get channel() {
62
+ return CHANNEL
63
+ },
64
+ get version() {
65
+ return VERSION
66
+ },
67
+ get preview() {
68
+ return IS_PREVIEW
69
+ },
70
+ get team() {
71
+ return team
72
+ },
73
+ }
74
+ console.log(`opencode script`, JSON.stringify(Script, null, 2))
package/src/pack.ts CHANGED
@@ -1,74 +1,74 @@
1
- import { $ } from "bun"
2
- import { mkdir, rm } from "node:fs/promises"
3
- import path from "node:path"
4
-
5
- const root = path.resolve(import.meta.dir, "../../..")
6
-
7
- // Release outputs land at the repository root, where the release workflow uploads them.
8
- export const npmDir = path.join(root, "dist", "npm")
9
- export const archiveDir = path.join(root, "dist", "archives")
10
-
11
- type Manifest = {
12
- name: string
13
- version: string
14
- exports: Record<string, string | null>
15
- imports?: Record<string, Record<string, string>>
16
- }
17
-
18
- /**
19
- * Builds the package in `directory`, points its TypeScript exports at the build output, and packs it
20
- * into dist/npm. `types` is where the build writes declarations; `source` keeps `import` on the
21
- * TypeScript sources for packages that ship them. `workspaceOnly` exports map to null, so the published package
22
- * resolves none of them, even through a wildcard export.
23
- */
24
- export async function pack(
25
- directory: string,
26
- options: { types?: string; source?: boolean; workspaceOnly?: readonly string[] } = {},
27
- ) {
28
- const types = options.types ?? "./dist/"
29
- const file = path.join(directory, "package.json")
30
- const original = await Bun.file(file).text()
31
- // SAFETY: release packages declare a name, a version, and string export targets.
32
- const pkg = JSON.parse(original) as Manifest
33
- const declaration = (value: string) => value.replace("./src/", types).replace(/\.tsx?$/, ".d.ts")
34
- const output = (value: string) => value.replace("./src/", "./dist/").replace(/\.tsx?$/, ".js")
35
- const tarball = path.join(npmDir, `${pkg.name.replace("@", "").replace("/", "-")}-${pkg.version}.tgz`)
36
-
37
- await $`bun run build`.cwd(directory)
38
-
39
- const exports = Object.fromEntries(
40
- Object.entries(pkg.exports).map(([key, value]) => {
41
- if (value === null || options.workspaceOnly?.includes(key)) return [key, null]
42
-
43
- if (!/\.tsx?$/.test(value)) return [key, value]
44
-
45
- // TypeScript takes the first condition it matches, so `types` goes first or it type-checks the `import` target.
46
- return [key, { types: declaration(value), import: options.source ? value : output(value) }]
47
- }),
48
- )
49
- const imports = pkg.imports
50
- ? Object.fromEntries(
51
- Object.entries(pkg.imports).map(([key, conditions]) => [
52
- key,
53
- Object.fromEntries(
54
- Object.entries(conditions).map(([condition, value]) => [
55
- condition,
56
- condition === "types" ? declaration(value) : output(value),
57
- ]),
58
- ),
59
- ]),
60
- )
61
- : undefined
62
-
63
- await mkdir(npmDir, { recursive: true })
64
- await rm(tarball, { force: true })
65
- await Bun.write(file, JSON.stringify({ ...pkg, exports, ...(imports ? { imports } : {}) }, null, 2) + "\n")
66
-
67
- try {
68
- await $`bun pm pack --destination ${npmDir}`.cwd(directory)
69
- } finally {
70
- await Bun.write(file, original)
71
- }
72
-
73
- return tarball
74
- }
1
+ import { $ } from "bun"
2
+ import { mkdir, rm } from "node:fs/promises"
3
+ import path from "node:path"
4
+
5
+ const root = path.resolve(import.meta.dir, "../../..")
6
+
7
+ // Release outputs land at the repository root, where the release workflow uploads them.
8
+ export const npmDir = path.join(root, "dist", "npm")
9
+ export const archiveDir = path.join(root, "dist", "archives")
10
+
11
+ type Manifest = {
12
+ name: string
13
+ version: string
14
+ exports: Record<string, string | null>
15
+ imports?: Record<string, Record<string, string>>
16
+ }
17
+
18
+ /**
19
+ * Builds the package in `directory`, points its TypeScript exports at the build output, and packs it
20
+ * into dist/npm. `types` is where the build writes declarations; `source` keeps `import` on the
21
+ * TypeScript sources for packages that ship them. `workspaceOnly` exports map to null, so the published package
22
+ * resolves none of them, even through a wildcard export.
23
+ */
24
+ export async function pack(
25
+ directory: string,
26
+ options: { types?: string; source?: boolean; workspaceOnly?: readonly string[] } = {},
27
+ ) {
28
+ const types = options.types ?? "./dist/"
29
+ const file = path.join(directory, "package.json")
30
+ const original = await Bun.file(file).text()
31
+ // SAFETY: release packages declare a name, a version, and string export targets.
32
+ const pkg = JSON.parse(original) as Manifest
33
+ const declaration = (value: string) => value.replace("./src/", types).replace(/\.tsx?$/, ".d.ts")
34
+ const output = (value: string) => value.replace("./src/", "./dist/").replace(/\.tsx?$/, ".js")
35
+ const tarball = path.join(npmDir, `${pkg.name.replace("@", "").replace("/", "-")}-${pkg.version}.tgz`)
36
+
37
+ await $`bun run build`.cwd(directory)
38
+
39
+ const exports = Object.fromEntries(
40
+ Object.entries(pkg.exports).map(([key, value]) => {
41
+ if (value === null || options.workspaceOnly?.includes(key)) return [key, null]
42
+
43
+ if (!/\.tsx?$/.test(value)) return [key, value]
44
+
45
+ // TypeScript takes the first condition it matches, so `types` goes first or it type-checks the `import` target.
46
+ return [key, { types: declaration(value), import: options.source ? value : output(value) }]
47
+ }),
48
+ )
49
+ const imports = pkg.imports
50
+ ? Object.fromEntries(
51
+ Object.entries(pkg.imports).map(([key, conditions]) => [
52
+ key,
53
+ Object.fromEntries(
54
+ Object.entries(conditions).map(([condition, value]) => [
55
+ condition,
56
+ condition === "types" ? declaration(value) : output(value),
57
+ ]),
58
+ ),
59
+ ]),
60
+ )
61
+ : undefined
62
+
63
+ await mkdir(npmDir, { recursive: true })
64
+ await rm(tarball, { force: true })
65
+ await Bun.write(file, JSON.stringify({ ...pkg, exports, ...(imports ? { imports } : {}) }, null, 2) + "\n")
66
+
67
+ try {
68
+ await $`bun pm pack --destination ${npmDir}`.cwd(directory)
69
+ } finally {
70
+ await Bun.write(file, original)
71
+ }
72
+
73
+ return tarball
74
+ }
package/tsconfig.json CHANGED
@@ -1,10 +1,10 @@
1
- {
2
- "$schema": "https://json.schemastore.org/tsconfig",
3
- "extends": "@tsconfig/bun/tsconfig.json",
4
- "compilerOptions": {
5
- "types": ["bun"],
6
- "noUnusedLocals": true,
7
- "lib": ["ESNext", "DOM", "DOM.Iterable"],
8
- "noUncheckedIndexedAccess": false
9
- }
10
- }
1
+ {
2
+ "$schema": "https://json.schemastore.org/tsconfig",
3
+ "extends": "@tsconfig/bun/tsconfig.json",
4
+ "compilerOptions": {
5
+ "types": ["bun"],
6
+ "noUnusedLocals": true,
7
+ "lib": ["ESNext", "DOM", "DOM.Iterable"],
8
+ "noUncheckedIndexedAccess": false
9
+ }
10
+ }
@@ -1,80 +0,0 @@
1
- import { describe, expect, test } from "bun:test"
2
- import path from "path"
3
- import { parse } from "../src/highlights"
4
-
5
- describe("highlights", () => {
6
- test("parses the v2.0.27 release notes", async () => {
7
- const changelog = await Bun.file(path.resolve(import.meta.dir, "../../../CHANGELOG.md")).text()
8
- const notes = changelog.split(/^## v2\.0\.27 .*$/m)[1].split(/^## /m)[0]
9
- const result = parse(notes)
10
-
11
- expect(result.problems).toEqual([])
12
- expect(result.items.map((item) => item.title)).toEqual([
13
- "Built-In Worktree Tools",
14
- "Safer Remote Pairing",
15
- "Installable Web App",
16
- "Clear Session Failures",
17
- "Automatic Project Cleanup",
18
- ])
19
- expect(result.items[0].body).toBe(
20
- "Ask OpenCode to use `worktree_create`, `worktree_list`, and `worktree_remove` in Code Mode. You can create " +
21
- "isolated worktrees, move sessions into them, and remove them with normal edit approval.",
22
- )
23
- expect(result.items[2].body).toBe(
24
- "Use Chrome or Edge’s Install button to install the OpenCode web app, including when it runs behind an " +
25
- "authenticating proxy.",
26
- )
27
- expect(result.items.some((item) => item.body.includes("github.com") || item.body.includes("(["))).toBe(false)
28
- })
29
-
30
- test("joins wrapped lines and drops multiple trailing links", () => {
31
- const result = parse(
32
- [
33
- "### Highlights",
34
- "",
35
- "- **Reopen Closed Tabs:** Right-click the new-session button to bring back a session you closed by",
36
- " mistake. ([#123](https://github.com/anomalyco/opencode/pull/123), [#124](https://github.com/anomalyco/opencode/pull/124))",
37
- "* **Faster [Search](https://example.com)**: Results now stream in.",
38
- "",
39
- "### Core",
40
- "",
41
- "- **Not a Highlight**: Ignored.",
42
- ].join("\n"),
43
- )
44
-
45
- expect(result).toEqual({
46
- items: [
47
- {
48
- title: "Reopen Closed Tabs",
49
- body: "Right-click the new-session button to bring back a session you closed by mistake.",
50
- },
51
- { title: "Faster Search", body: "Results now stream in." },
52
- ],
53
- problems: [],
54
- })
55
- })
56
-
57
- test("returns nothing without a Highlights section", () => {
58
- expect(parse("### Core\n\n- Fixed a bug.")).toEqual({ items: [], problems: [] })
59
- })
60
-
61
- test("reports malformed highlights instead of failing", () => {
62
- const result = parse("### Highlights\n\n- Plain bullet without a title.\n")
63
- expect(result.items).toEqual([])
64
- expect(result.problems).toHaveLength(2)
65
- })
66
-
67
- test("limits the number and length of highlights", () => {
68
- const result = parse(
69
- [
70
- "### Highlights",
71
- ...Array.from({ length: 7 }, (_, index) => `- **Item ${index}**: ${"word ".repeat(100)}`),
72
- ].join("\n"),
73
- )
74
-
75
- expect(result.items).toHaveLength(5)
76
- expect(result.items[0].body.length).toBeLessThanOrEqual(300)
77
- expect(result.items[0].body.endsWith("…")).toBe(true)
78
- expect(result.problems).toEqual(["Kept the first 5 of 7 highlights"])
79
- })
80
- })
package/test/pack.test.ts DELETED
@@ -1,43 +0,0 @@
1
- import { $ } from "bun"
2
- import { afterEach, describe, expect, test } from "bun:test"
3
- import { mkdtemp, rm } from "node:fs/promises"
4
- import { tmpdir } from "node:os"
5
- import path from "node:path"
6
- import { pack } from "../src/pack"
7
-
8
- const cleanup: string[] = []
9
-
10
- afterEach(async () => {
11
- await Promise.all(cleanup.splice(0).map((file) => rm(file, { recursive: true, force: true })))
12
- })
13
-
14
- describe("pack", () => {
15
- test("lists each TypeScript export's types before its import", async () => {
16
- const directory = await mkdtemp(path.join(tmpdir(), "opencode-pack-"))
17
- cleanup.push(directory)
18
- await Bun.write(path.join(directory, "src/button.tsx"), "export const Button = 1\n")
19
- await Bun.write(path.join(directory, "src/button.css"), "button {}\n")
20
- await Bun.write(
21
- path.join(directory, "package.json"),
22
- JSON.stringify({
23
- name: "@zyro-sec/pack-fixture",
24
- version: "0.0.0-test",
25
- type: "module",
26
- scripts: { build: "true" },
27
- files: ["src"],
28
- exports: { "./button": "./src/button.tsx", "./button.css": "./src/button.css" },
29
- }),
30
- )
31
-
32
- const tarball = await pack(directory, { source: true })
33
- cleanup.push(tarball)
34
- // A relative name, since Windows' GNU tar reads the `C:` in an absolute path as a remote host.
35
- const manifest = JSON.parse(
36
- await $`tar -xOzf ${path.basename(tarball)} package/package.json`.cwd(path.dirname(tarball)).text(),
37
- )
38
-
39
- expect(manifest.exports["./button"]).toEqual({ types: "./dist/button.d.ts", import: "./src/button.tsx" })
40
- expect(Object.keys(manifest.exports["./button"])).toEqual(["types", "import"])
41
- expect(manifest.exports["./button.css"]).toBe("./src/button.css")
42
- })
43
- })