mirror of
https://github.com/fsolla/teqo.git
synced 2026-11-13 06:25:20 +00:00
Generate the Payload importMap at build time (Dockerfile) and dev time (predev hook) with dummy S3_* envs, eliminating the class of bugs where the admin goes blank because the S3ClientUploadHandler entry is missing (OPS69/OPS72/OPS73). Changes: - Dockerfile: add pnpm generate:importmap with dummy S3_* envs before next build - scripts/predev-importmap.mjs: predev hook that generates importMap if missing or stale - Delete scripts/check-importmap-s3.mjs (guard no longer needed) - Delete tests/unit/importMapS3UploadHandler.unit.spec.ts (unit pin no longer needed) - Remove check-importmap-s3.mjs step from CI workflows - Add importMap.js to .gitignore (build artifact, not committed) - Update AGENTS.md with new contract Closes #928
64 lines
2.1 KiB
JavaScript
64 lines
2.1 KiB
JavaScript
#!/usr/bin/env node
|
|
/**
|
|
* Predev hook: generate importMap if missing or stale (OPS99).
|
|
*
|
|
* The importMap is now a build artifact, not committed to git. This script
|
|
* ensures it exists before `pnpm dev` starts, using dummy S3_* envs.
|
|
*
|
|
* Checks if the file exists and is newer than payload.config.ts.
|
|
* If missing or stale, regenerates with dummy S3_* envs.
|
|
*/
|
|
import { execFileSync } from 'node:child_process'
|
|
import { existsSync, statSync } from 'node:fs'
|
|
import path from 'node:path'
|
|
import { fileURLToPath } from 'node:url'
|
|
|
|
const repoRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..')
|
|
const importMapPath = path.join(repoRoot, 'src/app/(payload)/admin/importMap.js')
|
|
const payloadConfigPath = path.join(repoRoot, 'payload.config.ts')
|
|
|
|
// Dummy S3_* envs for generation (same as Dockerfile and CI guard)
|
|
const DUMMY_S3_ENV = {
|
|
S3_BUCKET: 'dev-dummy',
|
|
S3_ENDPOINT: 'http://127.0.0.1:3900',
|
|
S3_ACCESS_KEY_ID: 'dev-dummy',
|
|
S3_SECRET_ACCESS_KEY: 'dev-dummy',
|
|
}
|
|
|
|
function needsRegeneration() {
|
|
if (!existsSync(importMapPath)) return true
|
|
if (!existsSync(payloadConfigPath)) return false
|
|
|
|
const importMapMtime = statSync(importMapPath).mtimeMs
|
|
const configMtime = statSync(payloadConfigPath).mtimeMs
|
|
return configMtime > importMapMtime
|
|
}
|
|
|
|
function generateImportMap() {
|
|
console.log('[predev-importmap] generating importMap with dummy S3_* envs...')
|
|
const env = {
|
|
...process.env,
|
|
NODE_OPTIONS: '--no-deprecation --conditions=react-server',
|
|
PAYLOAD_SECRET: process.env.PAYLOAD_SECRET || 'dev-secret',
|
|
DATABASE_URL: process.env.DATABASE_URL || 'postgresql://dev:dev@127.0.0.1:5432/teqo',
|
|
...DUMMY_S3_ENV,
|
|
}
|
|
|
|
try {
|
|
execFileSync('pnpm', ['exec', 'payload', 'generate:importmap'], {
|
|
cwd: repoRoot,
|
|
env,
|
|
stdio: 'inherit',
|
|
})
|
|
console.log('[predev-importmap] importMap generated successfully')
|
|
} catch (_error) {
|
|
console.error('[predev-importmap] failed to generate importMap')
|
|
process.exit(1)
|
|
}
|
|
}
|
|
|
|
if (needsRegeneration()) {
|
|
generateImportMap()
|
|
} else {
|
|
console.log('[predev-importmap] importMap is up to date')
|
|
}
|