From 33ba535c9f2dee54bffc936bc924663c833a0273 Mon Sep 17 00:00:00 2001 From: Ludvig Rask <74653458+ludvigrask@users.noreply.github.com> Date: Mon, 9 Nov 2026 11:11:12 -0600 Subject: [PATCH] fix(ui): list types before import in packed exports and export select.css (#62914) --- packages/http-recorder/script/pack.ts | 4 +-- packages/script/src/pack.ts | 3 +- packages/script/test/pack.test.ts | 43 +++++++++++++++++++++++++++ packages/sdk/script/verify-package.ts | 4 +-- packages/ui/package.json | 1 + 5 files changed, 50 insertions(+), 5 deletions(-) create mode 100644 packages/script/test/pack.test.ts diff --git a/packages/http-recorder/script/pack.ts b/packages/http-recorder/script/pack.ts index c40d83c8497..64a47beadd4 100644 --- a/packages/http-recorder/script/pack.ts +++ b/packages/http-recorder/script/pack.ts @@ -11,13 +11,13 @@ export const pack = async () => { // oxlint-disable-next-line typescript-eslint/no-unsafe-type-assertion -- package.json is validated by the package schema and build checks. const pkg = JSON.parse(original) as { readonly version: string - exports: Record + exports: Record } for (const [key, value] of Object.entries(pkg.exports)) { if (typeof value !== "string") continue const file = value.replace("./src/", "./dist/").replace(/\.ts$/, "") - pkg.exports[key] = { import: `${file}.js`, types: `${file}.d.ts` } + pkg.exports[key] = { types: `${file}.d.ts`, import: `${file}.js` } } await Bun.write("package.json", JSON.stringify(pkg, null, 2)) try { diff --git a/packages/script/src/pack.ts b/packages/script/src/pack.ts index 70095ae7dbf..1e39d775b87 100644 --- a/packages/script/src/pack.ts +++ b/packages/script/src/pack.ts @@ -42,7 +42,8 @@ export async function pack( if (!/\.tsx?$/.test(value)) return [key, value] - return [key, { import: options.source ? value : output(value), types: declaration(value) }] + // TypeScript takes the first condition it matches, so `types` goes first or it type-checks the `import` target. + return [key, { types: declaration(value), import: options.source ? value : output(value) }] }), ) const imports = pkg.imports diff --git a/packages/script/test/pack.test.ts b/packages/script/test/pack.test.ts new file mode 100644 index 00000000000..8c0545692e7 --- /dev/null +++ b/packages/script/test/pack.test.ts @@ -0,0 +1,43 @@ +import { $ } from "bun" +import { afterEach, describe, expect, test } from "bun:test" +import { mkdtemp, rm } from "node:fs/promises" +import { tmpdir } from "node:os" +import path from "node:path" +import { pack } from "../src/pack" + +const cleanup: string[] = [] + +afterEach(async () => { + await Promise.all(cleanup.splice(0).map((file) => rm(file, { recursive: true, force: true }))) +}) + +describe("pack", () => { + test("lists each TypeScript export's types before its import", async () => { + const directory = await mkdtemp(path.join(tmpdir(), "opencode-pack-")) + cleanup.push(directory) + await Bun.write(path.join(directory, "src/button.tsx"), "export const Button = 1\n") + await Bun.write(path.join(directory, "src/button.css"), "button {}\n") + await Bun.write( + path.join(directory, "package.json"), + JSON.stringify({ + name: "@opencode/pack-fixture", + version: "0.0.0-test", + type: "module", + scripts: { build: "true" }, + files: ["src"], + exports: { "./button": "./src/button.tsx", "./button.css": "./src/button.css" }, + }), + ) + + const tarball = await pack(directory, { source: true }) + cleanup.push(tarball) + // A relative name, since Windows' GNU tar reads the `C:` in an absolute path as a remote host. + const manifest = JSON.parse( + await $`tar -xOzf ${path.basename(tarball)} package/package.json`.cwd(path.dirname(tarball)).text(), + ) + + expect(manifest.exports["./button"]).toEqual({ types: "./dist/button.d.ts", import: "./src/button.tsx" }) + expect(Object.keys(manifest.exports["./button"])).toEqual(["types", "import"]) + expect(manifest.exports["./button.css"]).toBe("./src/button.css") + }) +}) diff --git a/packages/sdk/script/verify-package.ts b/packages/sdk/script/verify-package.ts index 4d1b6011140..bfc305cdc2d 100644 --- a/packages/sdk/script/verify-package.ts +++ b/packages/sdk/script/verify-package.ts @@ -33,7 +33,7 @@ try { const pkg = JSON.parse(original) as { name: string dependencies?: Record - exports?: Record + exports?: Record imports?: Record> } const archive = join(temporary, `${name}.tgz`) @@ -55,7 +55,7 @@ try { pkg.exports = Object.fromEntries( Object.entries(pkg.exports).map(([key, value]) => { if (typeof value !== "string") return [key, value] - return [key, { import: output(name, value), types: output(name, value, true) }] + return [key, { types: output(name, value, true), import: output(name, value) }] }), ) } diff --git a/packages/ui/package.json b/packages/ui/package.json index ce0955515b9..d42ff170a01 100644 --- a/packages/ui/package.json +++ b/packages/ui/package.json @@ -70,6 +70,7 @@ "./search-list": "./src/forms/search-list/search-list.tsx", "./segmented-control": "./src/navigation/segmented-control/segmented-control.tsx", "./select": "./src/forms/select/select.tsx", + "./select.css": "./src/forms/select/select.css", "./split-button": "./src/actions/split-button/split-button.tsx", "./switch": "./src/forms/switch/switch.tsx", "./tab-state-indicator": "./src/navigation/tab-state-indicator.tsx",