-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtsdown.config.ts
More file actions
87 lines (81 loc) · 3.57 KB
/
Copy pathtsdown.config.ts
File metadata and controls
87 lines (81 loc) · 3.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import type {Plugin} from 'rolldown'
import {readdir, readFile} from 'node:fs/promises'
import {join} from 'node:path'
import {defineConfig} from 'tsdown'
export type {LicenseEntry} from './scripts/third-party-notices.ts'
export {formatThirdPartyNotices} from './scripts/third-party-notices.ts'
// Guard: the action is code-split, so the OpenCode default version literal can
// land in a shared chunk rather than main.js. A harness default carries a
// `+harness.<sha>` build-metadata suffix that a minifier could strip or collapse
// against the stock fallback; this fails the build if the configured default does
// not survive into the emitted bundle.
/**
* Pure assertion: throws if `expected` is not present in any of the provided chunk contents.
* Exported for unit testing; the plugin calls this after reading chunks from disk.
*/
export function assertVersionPresent(expected: string, chunkContents: readonly string[]): void {
if (!chunkContents.some(c => c.includes(expected))) {
throw new Error(
`[default-version-invariant] DEFAULT_OPENCODE_VERSION '${expected}' is absent from every dist chunk — the bundler likely stripped its build metadata. Aborting to prevent shipping a silent stock default.`,
)
}
}
function defaultVersionInvariantPlugin(): Plugin {
return {
name: 'default-version-invariant',
async writeBundle() {
const constantsSource = await readFile('packages/runtime/src/shared/constants.ts', 'utf8')
const match = /DEFAULT_OPENCODE_VERSION\s*=\s*'([^']+)'/.exec(constantsSource)
if (match?.[1] == null) {
throw new Error('[default-version-invariant] could not read DEFAULT_OPENCODE_VERSION from source')
}
const expected = match[1]
const chunks = (await readdir('dist')).filter(name => name.endsWith('.js'))
const chunkContents = await Promise.all(chunks.map(async name => readFile(join('dist', name), 'utf8')))
assertVersionPresent(expected, chunkContents)
},
}
}
const sharedNoExternal = (id: string): boolean => {
if (id.startsWith('@bfra.me/es')) return true
if (id.startsWith('@actions/')) return true
if (id.startsWith('@octokit/auth-app')) return true
if (id.startsWith('@opencode-ai/sdk')) return true
if (id.startsWith('@aws-sdk/')) return true
if (id.startsWith('@smithy/')) return true
if (id.startsWith('@fro-bot/runtime')) return true
if (id === 'zod' || id.startsWith('zod/')) return true
return false
}
export default defineConfig([
{
entry: ['apps/action/src/main.ts', 'apps/action/src/post.ts'],
fixedExtension: false,
deps: {onlyBundle: false},
minify: true,
// Source maps roughly triple committed dist/ size and the action never reads them.
sourcemap: false,
// Escape runs post-bundle in scripts/build-action-dist.ts (failure-safe) and
// at the root build tail (pnpm run dist:escape-hidden-unicode, full dist).
plugins: [defaultVersionInvariantPlugin()],
noExternal: sharedNoExternal,
},
{
// Dedicated build: session-tools.js is copied standalone into the CI OpenCode
// config dir (U3) as `tool/session.js`, so it must be a single file with no
// sibling-chunk dependency. Building it as its own tsdown config (separate
// rolldown invocation) prevents rolldown from splitting shared helpers into
// chunks shared with main.js/post.js.
entry: ['apps/action/src/session-tools.ts'],
fixedExtension: false,
deps: {onlyBundle: false},
minify: true,
sourcemap: false,
dts: false,
clean: false,
outputOptions: {
inlineDynamicImports: true,
},
noExternal: sharedNoExternal,
},
])