@adea-ai/app-framework 0.24.0 → 0.25.0

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.
Files changed (137) hide show
  1. package/README.md +49 -1
  2. package/dist/cli/macos-signing-cli.d.ts +2 -0
  3. package/dist/cli/macos-signing-cli.js +14 -0
  4. package/dist/desktop/channel-proof.js +7 -1
  5. package/dist/framework-source.json +1 -1
  6. package/dist/release/framework-package-publish.js +4 -2
  7. package/dist/release/local-release.d.ts +2 -0
  8. package/dist/release/local-release.js +25 -2
  9. package/dist/release/macos-signing.d.ts +27 -0
  10. package/dist/release/macos-signing.js +101 -0
  11. package/dist/shell/app-shell.js +21 -33
  12. package/dist/shell/navigation-drawer.d.ts +12 -0
  13. package/dist/shell/navigation-drawer.js +42 -0
  14. package/dist/updates/release-feed.d.ts +2 -0
  15. package/dist/updates/release-feed.js +11 -2
  16. package/package.json +16 -4
  17. package/src/shell/app-shell.tsx +29 -20
  18. package/src/shell/navigation-drawer.tsx +36 -0
  19. package/src/app/create-application.ts +0 -245
  20. package/src/app/service-registry.ts +0 -124
  21. package/src/ci/toolchain-identity.ts +0 -244
  22. package/src/cli/cef-helper-cli.ts +0 -21
  23. package/src/cli/cli-runner.ts +0 -29
  24. package/src/cli/create-application-cli.ts +0 -62
  25. package/src/cli/electrobun-shortcut-patch-cli.ts +0 -24
  26. package/src/cli/framework-update-cli.ts +0 -41
  27. package/src/cli/release-assets-plan-cli.ts +0 -14
  28. package/src/cli/release-cut-cli.ts +0 -41
  29. package/src/cli/release-descriptor-staging-cli.ts +0 -57
  30. package/src/cli/release-finalize-cli.ts +0 -34
  31. package/src/cli/release-promote-cli.ts +0 -31
  32. package/src/cli/release-publish-cli.ts +0 -46
  33. package/src/cli/release-sign-cli.ts +0 -24
  34. package/src/cli/release-step-cli.ts +0 -71
  35. package/src/cli/toolchain-identity-cli.ts +0 -12
  36. package/src/cli/update-helper-cli.ts +0 -12
  37. package/src/cli/windows-runtime-patch-cli.ts +0 -17
  38. package/src/desktop/application-command-client.ts +0 -43
  39. package/src/desktop/channel-handshake.ts +0 -136
  40. package/src/desktop/channel-proof.ts +0 -122
  41. package/src/desktop/desktop-client.ts +0 -303
  42. package/src/desktop/desktop-gateway.ts +0 -189
  43. package/src/desktop/desktop-host.ts +0 -335
  44. package/src/desktop/desktop-stream.ts +0 -324
  45. package/src/desktop/loopback-policy.ts +0 -41
  46. package/src/desktop/open-url-channel.ts +0 -79
  47. package/src/desktop/string-policy.ts +0 -9
  48. package/src/installer/archive-entry.ts +0 -32
  49. package/src/installer/command-artifact.ts +0 -307
  50. package/src/installer/command-qualification-command.ts +0 -75
  51. package/src/installer/hosted-runner.ts +0 -11
  52. package/src/installer/installed-payload.ts +0 -408
  53. package/src/installer/installer-ci-bootstrap.ts +0 -199
  54. package/src/installer/installer-ci-preflight.ts +0 -61
  55. package/src/installer/installer-ci-worker.ts +0 -105
  56. package/src/installer/installer-extraction.ts +0 -367
  57. package/src/installer/installer-fetch-guard.ts +0 -75
  58. package/src/installer/installer-identity.ts +0 -331
  59. package/src/installer/installer-layout.ts +0 -167
  60. package/src/installer/installer-observation.ts +0 -671
  61. package/src/installer/installer-process-cleanup.ts +0 -167
  62. package/src/installer/installer-qualification-command.ts +0 -81
  63. package/src/installer/installer-renderer-evidence.ts +0 -268
  64. package/src/installer/installer-upgrade-command.ts +0 -226
  65. package/src/installer/installer-worker-guard.ts +0 -112
  66. package/src/installer/native-executable.ts +0 -37
  67. package/src/installer/upgrade-asset-download.ts +0 -72
  68. package/src/installer/write-all.ts +0 -19
  69. package/src/native/app-bundle.ts +0 -86
  70. package/src/native/cef-helper.ts +0 -471
  71. package/src/native/desktop-build-hook.ts +0 -21
  72. package/src/native/electrobun-source-patch.ts +0 -107
  73. package/src/native/linux-cef-links.ts +0 -14
  74. package/src/native/native-secret-store.ts +0 -99
  75. package/src/native/native-utilities.ts +0 -166
  76. package/src/native/partitioned-window.ts +0 -62
  77. package/src/native/secure-window.ts +0 -115
  78. package/src/native/sidecar-services.ts +0 -71
  79. package/src/native/sidecar.ts +0 -387
  80. package/src/native/window-bootstrap.ts +0 -77
  81. package/src/native/windows-build-hook-internal.ts +0 -49
  82. package/src/native/windows-build-hook.ts +0 -12
  83. package/src/native/windows-runtime-patch-internal.ts +0 -48
  84. package/src/native/windows-runtime-patch.ts +0 -15
  85. package/src/release/feed-release-cut.ts +0 -110
  86. package/src/release/feed-state.ts +0 -135
  87. package/src/release/framework-package-publish.ts +0 -163
  88. package/src/release/framework-update.ts +0 -196
  89. package/src/release/github-cli.ts +0 -27
  90. package/src/release/github-release-assets.ts +0 -36
  91. package/src/release/github-release-cut.ts +0 -237
  92. package/src/release/github-release-lookup.ts +0 -39
  93. package/src/release/github-release-promotion.ts +0 -112
  94. package/src/release/github-release-provenance.ts +0 -65
  95. package/src/release/github-release-publisher.ts +0 -90
  96. package/src/release/github-release-qualification.ts +0 -144
  97. package/src/release/local-provenance.ts +0 -92
  98. package/src/release/local-release.ts +0 -525
  99. package/src/release/macos-dmg.ts +0 -113
  100. package/src/release/release-artifact.ts +0 -53
  101. package/src/release/release-assets-plan.ts +0 -118
  102. package/src/release/release-config.ts +0 -420
  103. package/src/release/release-cut-command.ts +0 -80
  104. package/src/release/release-cut.ts +0 -133
  105. package/src/release/release-descriptor-staging.ts +0 -242
  106. package/src/release/release-finalize.ts +0 -191
  107. package/src/release/release-promotion-command.ts +0 -36
  108. package/src/release/release-promotion.ts +0 -132
  109. package/src/release/release-publication.ts +0 -213
  110. package/src/release/release-publish-command.ts +0 -163
  111. package/src/release/release-qualification.ts +0 -397
  112. package/src/release/release-staging.ts +0 -87
  113. package/src/release/release-steps.ts +0 -173
  114. package/src/release/retained-release-build.ts +0 -217
  115. package/src/shell/application-menu-commands.ts +0 -6
  116. package/src/shell/application-menu.ts +0 -250
  117. package/src/updates/channel-update-manager.ts +0 -127
  118. package/src/updates/desktop-updater.ts +0 -440
  119. package/src/updates/release-feed.ts +0 -187
  120. package/src/updates/release-location.ts +0 -101
  121. package/src/updates/signed-release.ts +0 -311
  122. package/src/updates/stable-file.ts +0 -32
  123. package/src/updates/update-arm.ts +0 -107
  124. package/src/updates/update-channel-store.ts +0 -86
  125. package/src/updates/update-discovery.ts +0 -113
  126. package/src/updates/update-download.ts +0 -82
  127. package/src/updates/update-exclusive-rename.ts +0 -58
  128. package/src/updates/update-extraction.ts +0 -261
  129. package/src/updates/update-handoff-plan.ts +0 -75
  130. package/src/updates/update-helper.ts +0 -87
  131. package/src/updates/update-launch.ts +0 -33
  132. package/src/updates/update-manager.ts +0 -130
  133. package/src/updates/update-process-fence.ts +0 -125
  134. package/src/updates/update-resume.ts +0 -34
  135. package/src/updates/update-shutdown.ts +0 -37
  136. package/src/updates/update-swap-stage.ts +0 -75
  137. package/src/updates/update-swap.ts +0 -30
@@ -1,110 +0,0 @@
1
- import type { FeedRelease, ReleaseLedger } from '../updates/release-feed'
2
- import { gitIsAncestor, type GitRun } from './local-provenance'
3
- import type { CutRelease, ReleaseCutProvider } from './release-cut'
4
-
5
- function checkTag(tag: string) {
6
- if (!/^v\d+\.\d+\.\d+(?:-dev\.\d+)?$/.test(tag) || tag.length > 65)
7
- throw new Error('Invalid release tag')
8
- }
9
-
10
- /**
11
- * Release feed adapter for local release cuts. The feed's ledger replaces the GitHub release
12
- * listing and the local checkout's fetched `origin/main` replaces GitHub's compare API. A dev
13
- * cut lives in memory until its build is published; a daily not yet in the ledger stands for
14
- * the Release Please release of the source manifest's version, as a stageable draft. A release
15
- * is qualified once its published release.json carries every payload this host builds, so a
16
- * second host adds its platform to an existing release. Nothing is built remotely, so a cut
17
- * is never pending and dispatch only hands the tag back to the caller to build.
18
- */
19
- export function createFeedReleaseCutProvider(options: {
20
- ledger: ReleaseLedger
21
- /** The published release.json of a tag, or null. */
22
- release(tag: string): Promise<FeedRelease | null>
23
- git: GitRun
24
- /** The source commit and the version its manifest names. */
25
- sourceSha: string
26
- releasedVersion: string
27
- /** The payload names this host builds for a tag. */
28
- payloads(tag: string): readonly string[]
29
- }): ReleaseCutProvider {
30
- const { ledger, git } = options
31
- const created = new Map<string, string>()
32
- return {
33
- async find(tag): Promise<CutRelease | null> {
34
- checkTag(tag)
35
- const kind = tag.includes('-dev.') ? 'dev' : 'daily'
36
- const entry = ledger.releases.find((item) => item.tag === tag)
37
- if (entry)
38
- return {
39
- tag,
40
- sourceSha: entry.sourceSha,
41
- kind,
42
- draft: false,
43
- prerelease: entry.kind !== 'stable',
44
- }
45
- const sourceSha = created.get(tag)
46
- if (sourceSha) return { tag, sourceSha, kind, draft: false, prerelease: true }
47
- if (kind === 'daily' && tag === `v${options.releasedVersion}`)
48
- return {
49
- tag,
50
- sourceSha: options.sourceSha,
51
- kind,
52
- draft: true,
53
- prerelease: false,
54
- stageableDraft: true,
55
- }
56
- return null
57
- },
58
- isMainAncestor: (sha) => gitIsAncestor(git, sha, 'refs/remotes/origin/main'),
59
- async isAncestor(older, newer) {
60
- return older !== newer && (await gitIsAncestor(git, older, newer))
61
- },
62
- async create(identity) {
63
- checkTag(identity.tag)
64
- if (!identity.tag.includes('-dev.') || created.has(identity.tag))
65
- throw new Error('Only a new dev release is cut locally')
66
- created.set(identity.tag, identity.sourceSha)
67
- },
68
- async qualification(release) {
69
- if (!ledger.releases.some((item) => item.tag === release.tag)) return 'not-qualified'
70
- try {
71
- const published = await options.release(release.tag)
72
- const names = new Set(published?.assets.map((asset) => asset.name))
73
- return options.payloads(release.tag).every((name) => names.has(name))
74
- ? 'qualified'
75
- : 'not-qualified'
76
- } catch {
77
- return 'unknown'
78
- }
79
- },
80
- pendingBuild: async () => 'idle',
81
- async highestDevCounter(version) {
82
- if (
83
- typeof version !== 'string' ||
84
- version.length > 64 ||
85
- !/^(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)$/.test(version)
86
- )
87
- throw new Error('Invalid source version')
88
- const prefix = `v${version}-dev.`
89
- let highest = 0
90
- for (const tag of [...ledger.releases.map((item) => item.tag), ...created.keys()]) {
91
- if (!tag.startsWith(prefix)) continue
92
- const suffix = tag.slice(prefix.length)
93
- if (!/^[1-9]\d{0,15}$/.test(suffix) || !Number.isSafeInteger(Number(suffix)))
94
- throw new Error('Invalid dev release counter')
95
- highest = Math.max(highest, Number(suffix))
96
- }
97
- return highest
98
- },
99
- async tagExists(tag) {
100
- checkTag(tag)
101
- return (
102
- ledger.releases.some((item) => item.tag === tag) ||
103
- (await git(['tag', '--list', tag])) !== ''
104
- )
105
- },
106
- async dispatch(tag) {
107
- checkTag(tag)
108
- },
109
- }
110
- }
@@ -1,135 +0,0 @@
1
- import { createHash } from 'node:crypto'
2
- import {
3
- feedUrl,
4
- parseFeedRelease,
5
- parseReleaseLedger,
6
- type FeedChannel,
7
- type FeedRelease,
8
- type ReleaseFeed,
9
- type ReleaseLedger,
10
- } from '../updates/release-feed'
11
- import {
12
- fetchReleaseLocation,
13
- readReleaseBytes,
14
- type FetchFunction,
15
- } from '../updates/release-location'
16
- import { verifyReleaseDescriptor } from '../updates/signed-release'
17
- import { discoveryPolicies } from './release-config'
18
-
19
- const MAX_LEDGER_BYTES = 1024 * 1024,
20
- MAX_RELEASE_BYTES = 262_144
21
-
22
- /** Read one feed object anonymously over HTTPS; null when the feed answers 404. */
23
- async function readFeedObject(
24
- feed: ReleaseFeed,
25
- path: string,
26
- fetcher: FetchFunction,
27
- maximum: number
28
- ): Promise<Uint8Array | null> {
29
- const response = await fetchReleaseLocation(
30
- `${feedUrl(feed)}${path}`,
31
- feedUrl(feed),
32
- fetcher,
33
- AbortSignal.timeout(60_000)
34
- )
35
- if (response.status === 404) {
36
- await response.body?.cancel()
37
- return null
38
- }
39
- return readReleaseBytes(response, maximum)
40
- }
41
- const json = (bytes: Uint8Array) => {
42
- try {
43
- return JSON.parse(new TextDecoder('utf-8', { fatal: true }).decode(bytes)) as unknown
44
- } catch {
45
- throw new Error('Invalid release feed response')
46
- }
47
- }
48
-
49
- /** The published ledger, or an empty one before the app's first release. */
50
- export async function readFeedLedger(
51
- feed: ReleaseFeed,
52
- fetcher: FetchFunction
53
- ): Promise<ReleaseLedger> {
54
- const bytes = await readFeedObject(feed, 'index.json', fetcher, MAX_LEDGER_BYTES)
55
- return bytes
56
- ? parseReleaseLedger(json(bytes), feed.app)
57
- : { schema: 1, app: feed.app, releases: [] }
58
- }
59
-
60
- /** A tag's published release.json, or null when none is published. */
61
- export async function readFeedRelease(
62
- feed: ReleaseFeed,
63
- tag: string,
64
- fetcher: FetchFunction
65
- ): Promise<FeedRelease | null> {
66
- const bytes = await readFeedObject(feed, `${tag}/release.json`, fetcher, MAX_RELEASE_BYTES)
67
- if (!bytes) return null
68
- const release = parseFeedRelease(json(bytes))
69
- if (release.tag !== tag) throw new Error('Feed release names another tag')
70
- return release
71
- }
72
-
73
- /**
74
- * Verify a published release from the feed: its ledger entry and release.json agree, and every
75
- * signed descriptor it lists for `channels` (all of its channels by default) has the listed
76
- * bytes, authenticates against the app's trust and names a listed payload with the same size
77
- * and digest. Returns the release platforms whose descriptors all verified; a platform whose
78
- * payload is listed but whose descriptors are missing fails.
79
- */
80
- export async function verifyFeedRelease(options: {
81
- config: unknown
82
- feed: ReleaseFeed
83
- tag: string
84
- repository: string
85
- keys: ReadonlyMap<string, string>
86
- fetch: FetchFunction
87
- channels?: readonly FeedChannel[]
88
- }): Promise<{ release: FeedRelease; platforms: string[] }> {
89
- const { config, feed, tag, fetch: fetcher } = options
90
- const [ledger, release] = await Promise.all([
91
- readFeedLedger(feed, fetcher),
92
- readFeedRelease(feed, tag, fetcher),
93
- ])
94
- const entry = ledger.releases.find((item) => item.tag === tag)
95
- if (!release || !entry || entry.kind !== release.channel)
96
- throw new Error('Release is not published consistently')
97
- const policies = discoveryPolicies(config, tag).filter(
98
- (policy) => !options.channels || options.channels.includes(policy.channel)
99
- )
100
- const platforms = new Set<string>()
101
- for (const policy of policies) {
102
- const payload = release.assets.find((asset) => asset.name === policy.payload)
103
- if (!payload) continue
104
- const listed = release.assets.find((asset) => asset.name === policy.name)
105
- if (!listed) throw new Error(`Missing signed descriptor: ${policy.name}`)
106
- const bytes = await readFeedObject(feed, `${tag}/${policy.name}`, fetcher, 65_536)
107
- if (
108
- !bytes ||
109
- bytes.length !== listed.size ||
110
- createHash('sha256').update(bytes).digest('hex') !== listed.sha256
111
- )
112
- throw new Error(`Signed descriptor differs from its release: ${policy.name}`)
113
- const verified = verifyReleaseDescriptor(json(bytes), {
114
- appId: policy.appId,
115
- repository: options.repository,
116
- channel: policy.channel,
117
- platform: policy.os,
118
- arch: policy.arch,
119
- feed: feedUrl(feed),
120
- keys: options.keys,
121
- })
122
- if (
123
- !verified.ok ||
124
- verified.descriptor.tag !== tag ||
125
- verified.descriptor.sourceSha !== entry.sourceSha ||
126
- verified.descriptor.asset.name !== payload.name ||
127
- verified.descriptor.asset.size !== payload.size ||
128
- verified.descriptor.asset.sha256 !== payload.sha256
129
- )
130
- throw new Error(`Untrusted signed descriptor: ${policy.name}`)
131
- platforms.add(policy.platform)
132
- }
133
- if (!platforms.size) throw new Error('Release has no verified platform')
134
- return { release, platforms: [...platforms] }
135
- }
@@ -1,163 +0,0 @@
1
- import { execFile } from 'node:child_process'
2
- import { createHash } from 'node:crypto'
3
- import { lstat, mkdtemp, open, readFile, rm, writeFile } from 'node:fs/promises'
4
- import { tmpdir } from 'node:os'
5
- import { basename, join, resolve } from 'node:path'
6
- import { readPackageFile } from './framework-update'
7
- import { gitCli, resolveLocalProvenance, type GitRun } from './local-provenance'
8
-
9
- const packageName = '@adea-ai/app-framework'
10
- const registryUrl = 'https://registry.npmjs.org/'
11
-
12
- /** Runs `npm` with arguments in the current directory and the caller's environment. */
13
- function npmCli(args: string[]): Promise<number> {
14
- return new Promise((resolveRun) =>
15
- execFile('npm', args, { maxBuffer: 8 * 1024 * 1024 }, (error, stdout, stderr) => {
16
- process.stdout.write(stdout)
17
- process.stderr.write(stderr)
18
- resolveRun(error ? Number(error.code ?? 1) || 1 : 0)
19
- })
20
- )
21
- }
22
-
23
- /** The registry's version document, or null when npm answers 404. */
24
- async function registryVersion(version: string): Promise<unknown> {
25
- const response = await fetch(`${registryUrl}@adea-ai%2fapp-framework/${version}`, {
26
- headers: { accept: 'application/json' },
27
- })
28
- if (response.status === 404) return null
29
- if (!response.ok) throw new Error(`npm answered ${response.status}`)
30
- return response.json()
31
- }
32
-
33
- async function archiveIntegrity(
34
- archive: string
35
- ): Promise<{ bytes: Uint8Array<ArrayBuffer>; integrity: string }> {
36
- const info = await lstat(archive)
37
- if (!info.isFile() || info.isSymbolicLink() || info.size < 1 || info.size > 512 * 1024 * 1024)
38
- throw new Error('Invalid framework package')
39
- const file = await open(archive, 'r')
40
- try {
41
- const bytes = new Uint8Array(await file.readFile())
42
- const after = await file.stat()
43
- if (bytes.length !== info.size || after.size !== info.size || after.ino !== info.ino)
44
- throw new Error('Framework package changed')
45
- return { bytes, integrity: `sha512-${createHash('sha512').update(bytes).digest('base64')}` }
46
- } finally {
47
- await file.close()
48
- }
49
- }
50
-
51
- const publishedIntegrity = (document: unknown) =>
52
- typeof document === 'object' && document !== null
53
- ? (document as { dist?: { integrity?: unknown } }).dist?.integrity
54
- : undefined
55
-
56
- /**
57
- * Publish one tested framework tarball to npm from a clean checkout of a commit on origin/main.
58
- * The tarball must be this checkout's version and record this commit as its source. A version
59
- * npm already has is left alone when its integrity matches the tarball and refused otherwise.
60
- * `NODE_AUTH_TOKEN` authenticates through a temporary npmrc that names the variable, never its
61
- * value; without it npm uses its own configuration (trusted publishing in CI).
62
- */
63
- export async function publishFrameworkPackage(options: {
64
- env: Record<string, string | undefined>
65
- archive: string
66
- dryRun?: boolean
67
- git?: GitRun
68
- npm?: (args: string[]) => Promise<number>
69
- registry?: (version: string) => Promise<unknown>
70
- sleep?: (milliseconds: number) => Promise<unknown>
71
- }): Promise<{
72
- version: string
73
- integrity: string
74
- status: 'published' | 'already-published' | 'dry-run'
75
- }> {
76
- const git = options.git ?? gitCli()
77
- const registry = options.registry ?? registryVersion
78
- const npm = options.npm ?? npmCli
79
- const sleep = options.sleep ?? ((milliseconds: number) => Bun.sleep(milliseconds))
80
- const sha = await git(['rev-parse', '--verify', 'HEAD^{commit}'])
81
- const provenance = await resolveLocalProvenance({
82
- git,
83
- sourceSha: sha,
84
- versionSourcePath: 'package.json',
85
- })
86
- const manifest = JSON.parse(await readFile('package.json', 'utf8')) as {
87
- name?: unknown
88
- version?: unknown
89
- }
90
- const version = provenance.releasedVersion
91
- const archive = resolve(options.archive)
92
- if (
93
- provenance.repository !== 'adea-ai/app-framework' ||
94
- manifest.name !== packageName ||
95
- manifest.version !== version ||
96
- basename(archive) !== `adea-ai-app-framework-${version}.tgz`
97
- )
98
- throw new Error('Framework package source mismatch')
99
- const { bytes, integrity } = await archiveIntegrity(archive)
100
- const packed = readPackageFile(bytes, 'package/package.json') as {
101
- name?: unknown
102
- version?: unknown
103
- }
104
- const source = readPackageFile(bytes, 'package/dist/framework-source.json') as {
105
- version?: unknown
106
- commit?: unknown
107
- }
108
- if (
109
- packed.name !== packageName ||
110
- packed.version !== version ||
111
- source.version !== version ||
112
- source.commit !== sha
113
- )
114
- throw new Error('Framework package was not built from this checkout')
115
-
116
- const existing = await registry(version)
117
- if (existing !== null) {
118
- if (publishedIntegrity(existing) !== integrity)
119
- throw new Error('npm already has this version with other bytes')
120
- return { version, integrity, status: 'already-published' }
121
- }
122
- const args = [
123
- 'publish',
124
- archive,
125
- '--access',
126
- 'public',
127
- '--tag',
128
- 'latest',
129
- '--registry',
130
- registryUrl,
131
- ]
132
- if (options.dryRun) args.push('--dry-run')
133
- const config = options.env.NODE_AUTH_TOKEN
134
- ? await mkdtemp(join(tmpdir(), 'framework-npmrc-'))
135
- : undefined
136
- try {
137
- if (config) {
138
- // npm expands the variable when it reads the file; the token itself is never written.
139
- await writeFile(
140
- join(config, 'npmrc'),
141
- '//registry.npmjs.org/:_authToken=${NODE_AUTH_TOKEN}\n',
142
- {
143
- mode: 0o600,
144
- }
145
- )
146
- args.push('--userconfig', join(config, 'npmrc'))
147
- }
148
- if ((await npm(args)) !== 0) throw new Error('npm publish failed')
149
- } finally {
150
- if (config) await rm(config, { recursive: true, force: true })
151
- }
152
- if (options.dryRun) return { version, integrity, status: 'dry-run' }
153
- for (let attempt = 0; attempt < 10; attempt++) {
154
- const published = await registry(version)
155
- if (published !== null) {
156
- if (publishedIntegrity(published) !== integrity)
157
- throw new Error('npm published other bytes than the tested package')
158
- return { version, integrity, status: 'published' }
159
- }
160
- await sleep(3000)
161
- }
162
- throw new Error('npm does not list the published version yet')
163
- }
@@ -1,196 +0,0 @@
1
- import { createHash } from 'node:crypto'
2
- import { readFile, writeFile } from 'node:fs/promises'
3
- import { join } from 'node:path'
4
-
5
- /** Moves a consumer's app-framework pin to one published npm version in a single step: the
6
- * exact version in every package.json, the bun.lock entry and the reusable-workflow pins
7
- * all name the same release, or nothing is written. */
8
-
9
- const packageName = '@adea-ai/app-framework'
10
- const registry = 'https://registry.npmjs.org'
11
- const workflowPin =
12
- /(adea-ai\/app-framework\/\.github\/workflows\/[\w.-]+\.ya?ml)@(?:[0-9a-f]{40}(?: # v[\w.-]+)?|v\d+\.\d+\.\d+)/g
13
- const version = /^\d+\.\d+\.\d+$/
14
- const manifestPin = /("@adea-ai\/app-framework"\s*:\s*")\d+\.\d+\.\d+"/g
15
-
16
- export type FrameworkRelease = {
17
- version: string
18
- /** The commit the package was built from, which the reusable-workflow pins name. */
19
- commit: string
20
- integrity: string
21
- }
22
-
23
- type FrameworkUpdateIo = {
24
- /** npm registry JSON for a path under registry.npmjs.org. */
25
- registry(path: string): Promise<unknown>
26
- /** The bytes behind a registry tarball URL. */
27
- download(url: string): Promise<Uint8Array<ArrayBuffer>>
28
- /** Run a command in the consumer's root; resolves with its exit code. */
29
- run(command: string[], cwd: string): Promise<number>
30
- /** Repository-relative paths of tracked files. */
31
- files(root: string): Promise<string[]>
32
- }
33
-
34
- type Packument = {
35
- name?: unknown
36
- 'dist-tags'?: { latest?: unknown }
37
- versions?: Record<
38
- string,
39
- { name?: unknown; version?: unknown; dist?: { tarball?: unknown; integrity?: unknown } }
40
- >
41
- }
42
-
43
- /** The npm version to pin: `requested`, or the `latest` dist-tag. The tarball must be the
44
- * registry's own, match its sha512 integrity, contain the version it claims and record the
45
- * commit it was built from. */
46
- export async function resolveFrameworkRelease(
47
- io: Pick<FrameworkUpdateIo, 'registry' | 'download'>,
48
- requested?: string
49
- ): Promise<FrameworkRelease> {
50
- if (requested !== undefined && !version.test(requested))
51
- throw new Error(`Not a release version: ${requested}`)
52
- const packument = (await io.registry('@adea-ai%2fapp-framework')) as Packument
53
- if (packument.name !== packageName) throw new Error(`The registry does not list ${packageName}`)
54
- const resolved = requested ?? packument['dist-tags']?.latest
55
- if (typeof resolved !== 'string' || !version.test(resolved))
56
- throw new Error(`The latest ${packageName} is not a release version`)
57
- const entry = packument.versions?.[resolved]
58
- const tarball = `${registry}/${packageName}/-/app-framework-${resolved}.tgz`
59
- if (!entry || entry.name !== packageName || entry.version !== resolved)
60
- throw new Error(`${packageName}@${resolved} is not published`)
61
- if (entry.dist?.tarball !== tarball)
62
- throw new Error(`${packageName}@${resolved} is not served from ${registry}`)
63
- const integrity = typeof entry.dist.integrity === 'string' ? entry.dist.integrity : ''
64
- if (!/^sha512-[A-Za-z0-9+/]{86}==$/.test(integrity))
65
- throw new Error(`${packageName}@${resolved} has no sha512 integrity`)
66
- const bytes = await io.download(tarball)
67
- if (`sha512-${createHash('sha512').update(bytes).digest('base64')}` !== integrity)
68
- throw new Error(`${packageName}@${resolved} does not match its published integrity`)
69
- const manifest = readPackageFile(bytes, 'package/package.json') as {
70
- name?: unknown
71
- version?: unknown
72
- }
73
- if (manifest.name !== packageName || manifest.version !== resolved)
74
- throw new Error(`The tarball contains ${String(manifest.name)}@${String(manifest.version)}`)
75
- const source = readPackageFile(bytes, 'package/dist/framework-source.json') as {
76
- version?: unknown
77
- commit?: unknown
78
- }
79
- if (
80
- source.version !== resolved ||
81
- typeof source.commit !== 'string' ||
82
- !/^[0-9a-f]{40}$/.test(source.commit)
83
- )
84
- throw new Error(`${packageName}@${resolved} does not record its source commit`)
85
- return { version: resolved, commit: source.commit, integrity }
86
- }
87
-
88
- /** One JSON file from a gzipped npm tarball. */
89
- export function readPackageFile(bytes: Uint8Array<ArrayBuffer>, path: string): unknown {
90
- const tar = Bun.gunzipSync(bytes)
91
- const text = new TextDecoder()
92
- for (let offset = 0; offset + 512 <= tar.length;) {
93
- const header = tar.subarray(offset, offset + 512)
94
- const name = text.decode(header.subarray(0, 100)).replace(/\0.*$/s, '')
95
- if (!name) break
96
- const size = Number.parseInt(text.decode(header.subarray(124, 136)).replace(/\0.*$/s, ''), 8)
97
- if (name === path)
98
- return JSON.parse(text.decode(tar.subarray(offset + 512, offset + 512 + size)))
99
- offset += 512 + Math.ceil(size / 512) * 512
100
- }
101
- throw new Error(`The tarball has no ${path}`)
102
- }
103
-
104
- /** Comments bun drops when it rewrites bun.lock, such as release-please's version marker,
105
- * keyed by the workspace block and the line they trail. */
106
- function lockComments(lock: string): { block: string; line: string; comment: string }[] {
107
- let block = ''
108
- const comments = []
109
- for (const line of lock.split('\n')) {
110
- if (/^ {4}"[^"]*": \{/.test(line)) block = line
111
- const match = /^(.*?,)\s*(\/\/.*)$/.exec(line)
112
- if (match) comments.push({ block, line: match[1]!, comment: match[2]! })
113
- }
114
- return comments
115
- }
116
-
117
- function restoreLockComments(lock: string, comments: ReturnType<typeof lockComments>): string {
118
- const lines = lock.split('\n')
119
- for (const { block, line, comment } of comments) {
120
- const start = lines.indexOf(block)
121
- const index = lines.findIndex((candidate, at) => at > start && candidate === line)
122
- if (start < 0 || index < 0) throw new Error(`bun.lock lost the line for "${comment}"`)
123
- lines[index] = `${line} ${comment}`
124
- }
125
- return lines.join('\n')
126
- }
127
-
128
- type FrameworkUpdate = { release: FrameworkRelease; changed: string[] }
129
-
130
- /** Pin every app-framework reference in `root` to `release`, regenerate bun.lock and prove
131
- * it with a frozen install. Any failure restores every file it touched. */
132
- export async function applyFrameworkUpdate(
133
- root: string,
134
- release: FrameworkRelease,
135
- io: Pick<FrameworkUpdateIo, 'run' | 'files'>
136
- ): Promise<FrameworkUpdate> {
137
- const tracked = await io.files(root)
138
- const manifests = tracked.filter((path) => /(^|\/)package\.json$/.test(path))
139
- const workflows = tracked.filter((path) => /^\.github\/workflows\/[^/]+\.ya?ml$/.test(path))
140
- const original = new Map<string, string>()
141
- for (const path of [...manifests, ...workflows, 'bun.lock'])
142
- original.set(path, await readFile(join(root, path), 'utf8'))
143
-
144
- const next = new Map<string, string>()
145
- for (const path of manifests) {
146
- const text = original.get(path)!
147
- const dependency = JSON.parse(text) as Record<string, Record<string, string> | undefined>
148
- const declared = ['dependencies', 'devDependencies', 'peerDependencies', 'optionalDependencies']
149
- .map((field) => dependency[field]?.[packageName])
150
- .filter((value) => value !== undefined)
151
- if (!declared.length) continue
152
- for (const value of declared)
153
- if (!version.test(value)) throw new Error(`${path} pins ${packageName} to ${value}`)
154
- next.set(path, text.replace(manifestPin, `$1${release.version}"`))
155
- }
156
- for (const path of workflows) {
157
- const text = original.get(path)!
158
- const updated = text.replace(workflowPin, `$1@${release.commit} # v${release.version}`)
159
- if (updated !== text) next.set(path, updated)
160
- }
161
- if (![...next.keys()].some((path) => manifests.includes(path)))
162
- throw new Error(`No package.json depends on ${packageName}`)
163
-
164
- const written: string[] = []
165
- try {
166
- for (const [path, text] of next) {
167
- if (text === original.get(path)) continue
168
- await writeFile(join(root, path), text)
169
- written.push(path)
170
- }
171
- written.push('bun.lock')
172
- if ((await io.run(['bun', 'install'], root)) !== 0) throw new Error('bun install failed')
173
- const lock = restoreLockComments(
174
- await readFile(join(root, 'bun.lock'), 'utf8'),
175
- lockComments(original.get('bun.lock')!)
176
- )
177
- await writeFile(join(root, 'bun.lock'), lock)
178
- const entries = lock
179
- .split('\n')
180
- .filter((line) => line.trimStart().startsWith(`"${packageName}": [`))
181
- if (
182
- entries.length !== 1 ||
183
- !entries[0]!
184
- .trimStart()
185
- .startsWith(`"${packageName}": ["${packageName}@${release.version}", "",`) ||
186
- !entries[0]!.trimEnd().endsWith(`"${release.integrity}"],`)
187
- )
188
- throw new Error('bun.lock does not pin the verified npm package')
189
- if ((await io.run(['bun', 'install', '--frozen-lockfile'], root)) !== 0)
190
- throw new Error('The regenerated bun.lock does not pass a frozen install')
191
- } catch (error) {
192
- for (const path of written) await writeFile(join(root, path), original.get(path)!)
193
- throw error
194
- }
195
- return { release, changed: written }
196
- }
@@ -1,27 +0,0 @@
1
- import { execFile } from 'node:child_process'
2
-
3
- /** Runs `gh` with arguments and optional stdin, resolving its stdout. */
4
- type GitHubRun = (args: string[], input?: string) => Promise<string>
5
-
6
- /** The `gh` CLI runner every release command shares. A failure rejects with
7
- * 'GitHub request failed', carrying stderr and whether GitHub answered 404. */
8
- export function githubCli(env?: NodeJS.ProcessEnv): GitHubRun {
9
- return (args, input) =>
10
- new Promise<string>((resolve, reject) => {
11
- const child = execFile(
12
- 'gh',
13
- args,
14
- { maxBuffer: 8 * 1024 * 1024, ...(env ? { env } : {}) },
15
- (error, stdout, stderr) =>
16
- error
17
- ? reject(
18
- Object.assign(new Error('GitHub request failed'), {
19
- stderr,
20
- notFound: /\bHTTP 404\b/.test(stderr),
21
- })
22
- )
23
- : resolve(stdout)
24
- )
25
- child.stdin?.end(input)
26
- })
27
- }
@@ -1,36 +0,0 @@
1
- import type { Artifact } from './release-qualification'
2
-
3
- /** Read the complete bounded asset inventory; embedded release metadata may be incomplete. */
4
- export async function listGitHubReleaseAssets(
5
- read: (path: string) => Promise<unknown>,
6
- base: string,
7
- releaseId: unknown
8
- ): Promise<Artifact[]> {
9
- if (typeof releaseId !== 'number' || !Number.isSafeInteger(releaseId) || releaseId < 1)
10
- throw new Error('Invalid release identity')
11
- const result: Artifact[] = [],
12
- names = new Set<string>()
13
- for (let page = 1; page <= 10; page++) {
14
- const values = await read(`${base}/releases/${releaseId}/assets?per_page=100&page=${page}`)
15
- if (!Array.isArray(values) || values.length > 100)
16
- throw new Error('Invalid GitHub release assets')
17
- for (const value of values) {
18
- if (typeof value !== 'object' || value === null || Array.isArray(value))
19
- throw new Error('Invalid GitHub release asset')
20
- const asset = value as Record<string, unknown>
21
- if (
22
- typeof asset.name !== 'string' ||
23
- !asset.name ||
24
- !Number.isSafeInteger(asset.size) ||
25
- Number(asset.size) < 0 ||
26
- typeof asset.digest !== 'string' ||
27
- names.has(asset.name)
28
- )
29
- throw new Error('Invalid GitHub release asset')
30
- names.add(asset.name)
31
- result.push({ name: asset.name, size: Number(asset.size), digest: asset.digest })
32
- }
33
- if (values.length < 100) return result
34
- }
35
- throw new Error('Too many release assets')
36
- }