-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathverify-consumer-pre-release.ts
More file actions
89 lines (75 loc) · 3.21 KB
/
Copy pathverify-consumer-pre-release.ts
File metadata and controls
89 lines (75 loc) · 3.21 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
88
89
import { execSync } from 'node:child_process'
import { createHash } from 'node:crypto'
import { existsSync, readFileSync, rmSync } from 'node:fs'
import path from 'node:path'
import { MongoDBContainer } from '@testcontainers/mongodb'
const ROOT = process.cwd()
const PKG_DIR = path.join(ROOT, 'packages/payload-better-auth')
const DEMO_DIR = path.join(ROOT, 'apps/demo')
const TARBALL = path.join(PKG_DIR, 'release.tgz')
const sha256 = (file: string) =>
existsSync(file)
? createHash('sha256').update(readFileSync(file)).digest('hex')
: 'absent'
const run = (
cmd: string,
cwd: string = ROOT,
env: Record<string, string> = {},
) => {
console.log(`\n$ ${cmd}`)
execSync(cmd, { cwd, stdio: 'inherit', env: { ...process.env, ...env } })
}
async function main() {
const hashBefore = sha256(TARBALL)
console.log(`release.tgz (before): ${hashBefore}`)
// Build and pack the plugin to the fixed tarball path consumed by apps/demo.
// pack applies publishConfig (exports -> dist) and files, so the demo
// installs the exact artifact that pnpm publish would ship.
run('pnpm --filter @b3nab/payload-better-auth build')
run('pnpm pack --out release.tgz', PKG_DIR)
const hashAfter = sha256(TARBALL)
console.log(`\nrelease.tgz (before): ${hashBefore}`)
console.log(`release.tgz (after): ${hashAfter}`)
console.log(
hashBefore === hashAfter
? 'hash comparison: IDENTICAL'
: 'hash comparison: DIFFERENT',
)
// Point the demo at the packed tarball only for the duration of this run;
// the committed dependency stays workspace:*. pnpm add re-resolves the
// tarball content, and the finally below restores manifest and lockfile.
run(
`pnpm add @b3nab/payload-better-auth@file:${path.relative(DEMO_DIR, TARBALL)}`,
DEMO_DIR,
)
try {
run('pnpm typecheck', DEMO_DIR)
// Regenerate import map and payload types from the installed artifact.
// This also exercises the payload CLI loading the plugin through plain Node.
run('pnpm sync', DEMO_DIR)
// Consumer verification: FULL `next build` with both bundlers, exactly as a
// consumer runs it. The page-data collection phase must run: bundler module
// errors (e.g. Turbopack MODULE_UNPARSABLE) only surface when the compiled
// chunks are instantiated there, not during compilation. Payload needs a
// reachable MongoDB in that phase, so boot an ephemeral one via
// testcontainers (same pattern as tests/fixtures/beforeAll.fixtures.ts).
const memoryDB = await new MongoDBContainer('mongo:8').start()
const DATABASE_URI = `${memoryDB.getConnectionString()}/verify-consumer?directConnection=true`
try {
rmSync(path.join(DEMO_DIR, '.next'), { recursive: true, force: true })
run('pnpm exec next build', DEMO_DIR, { DATABASE_URI })
rmSync(path.join(DEMO_DIR, '.next'), { recursive: true, force: true })
run('pnpm exec next build --webpack', DEMO_DIR, { DATABASE_URI })
} finally {
await memoryDB.stop()
}
} finally {
// Restore the committed workspace dependency and lockfile.
run('pnpm add @b3nab/payload-better-auth@workspace:*', DEMO_DIR)
}
console.log('\nverify:pre-release PASSED')
}
main().catch((err) => {
console.error(err)
process.exit(1)
})