Beautiful Open-Source Form Builder
Fix public form bundle check for Amplify builds (#1297)
Julien Nahumf789d774def2
diff --git a/README.md b/README.mdindex 851356829..cc0840f73 100644--- a/README.md+++ b/README.md@@ -47,6 +47,8 @@ The easiest way to get started with OpnForm is through our [official managed serFor self-hosted installations, please refer to our [Deployment Guides](https://docs.opnform.com/deployment). For local development, we provide a minimal Docker-based setup - check out our [Docker Development Guide](https://docs.opnform.com/deployment/docker-development).+The client `npm run build` also checks the public form bundle size and eager dependencies. This check reads `.nuxt/dist/client/_nuxt`, independently of Nitro's deployment output directory (including AWS Amplify's `.amplify-hosting`). Run its regression tests from `client/` with `node --test scripts/check-public-form-bundle.test.mjs`.+## Codex worktreesCodex creates an isolated local environment for each worktree. It uses a dedicated PostgreSQL Docker volume and local Laravel/Nuxt processes, so sibling worktrees do not share ports, data, or API configuration.diff --git a/client/scripts/check-public-form-bundle.mjs b/client/scripts/check-public-form-bundle.mjsindex e446ebe5e..85e73adfc 100644--- a/client/scripts/check-public-form-bundle.mjs+++ b/client/scripts/check-public-form-bundle.mjs@@ -2,7 +2,8 @@ import { readFileSync, existsSync } from 'node:fs'import { gzipSync } from 'node:zlib'const manifestPath = new URL('../.nuxt/dist/server/client.manifest.json', import.meta.url)-const publicAssetsUrl = new URL('../.output/public/_nuxt/', import.meta.url)+// Inspect Vite's client output, shared by all Nitro deployment presets.+// Amplify publishes to .amplify-hosting instead of .output/public.const buildAssetsUrl = new URL('../.nuxt/dist/client/_nuxt/', import.meta.url)const maximumGzipBytes = 420 * 1024const routeEntry = 'pages/forms/[slug]/index.vue'@@ -59,7 +60,7 @@ function inspectScenario(scenarioName, componentNames) {const entry = manifest[key]if (entry.resourceType !== 'script' || !entry.file) continue- const assetUrl = new URL(entry.file, publicAssetsUrl)+ const assetUrl = new URL(entry.file, buildAssetsUrl)if (!existsSync(assetUrl)) {throw new Error(`Missing built asset for ${key}: ${entry.file}`)}diff --git a/client/scripts/check-public-form-bundle.test.mjs b/client/scripts/check-public-form-bundle.test.mjsnew file mode 100644index 000000000..5ac5847de--- /dev/null+++ b/client/scripts/check-public-form-bundle.test.mjs@@ -0,0 +1,60 @@+import { test } from 'node:test'+import assert from 'node:assert/strict'+import { mkdtempSync, mkdirSync, copyFileSync, writeFileSync, rmSync } from 'node:fs'+import { tmpdir } from 'node:os'+import { join } from 'node:path'+import { spawnSync } from 'node:child_process'+import { randomBytes } from 'node:crypto'++function runCheck(t, { preset = 'amplify', missingAsset = false, forbidden = false, oversized = false } = {}) {+ const root = mkdtempSync(join(tmpdir(), 'opnform-bundle-'))+ t.after(() => rmSync(root, { recursive: true, force: true }))+ const assets = join(root, '.nuxt/dist/client/_nuxt')+ const output = join(root, preset === 'amplify' ? '.amplify-hosting/static/_nuxt' : '.output/public/_nuxt')+ for (const directory of ['scripts', '.nuxt/dist/server', assets, output]) {+ mkdirSync(directory.startsWith(root) ? directory : join(root, directory), { recursive: true })+ }+ copyFileSync(new URL('./check-public-form-bundle.mjs', import.meta.url), join(root, 'scripts/check.mjs'))+ const names = ['OpenForm', 'TextInput', 'SelectInput', 'OpenFormFocused', 'FocusedSelectorInput', 'FocusedToggleInput']+ const manifest = Object.fromEntries(['pages/forms/[slug]/index.vue', ...names].map((name) => [name, {+ name, resourceType: 'script', file: `${names.includes(name) ? name : 'route'}.js`,+ }]))+ writeFileSync(join(root, '.nuxt/dist/server/client.manifest.json'), JSON.stringify(manifest))+ for (const entry of Object.values(manifest)) {+ if (missingAsset && entry.file === 'route.js') continue+ const contents = oversized ? randomBytes(450 * 1024) : 'export default {}'+ writeFileSync(join(assets, entry.file), contents)+ writeFileSync(join(output, entry.file), contents)+ writeFileSync(join(assets, `${entry.file}.map`), JSON.stringify({+ sources: forbidden ? ['../../node_modules/crisp-sdk-web/index.js'] : ['../../components/forms/TextInput.vue'],+ }))+ }+ return spawnSync(process.execPath, [join(root, 'scripts/check.mjs')], { encoding: 'utf8' })+}++for (const preset of ['amplify', 'node']) {+ test(`checks both public form bundles with the ${preset} output layout`, (t) => {+ const result = runCheck(t, { preset })+ assert.equal(result.status, 0, result.stderr)+ assert.match(result.stdout, /Public classic form bundle:/)+ assert.match(result.stdout, /Public focused form bundle:/)+ })+}++test('fails when a referenced asset is missing', (t) => {+ const result = runCheck(t, { missingAsset: true })+ assert.notEqual(result.status, 0)+ assert.match(result.stderr, /Missing built asset/)+})++test('still rejects forbidden eager dependencies', (t) => {+ const result = runCheck(t, { forbidden: true })+ assert.notEqual(result.status, 0)+ assert.match(result.stderr, /forbidden eager sources: \/crisp-sdk-web\//)+})++test('still enforces the gzip budget', (t) => {+ const result = runCheck(t, { oversized: true })+ assert.notEqual(result.status, 0)+ assert.match(result.stderr, /exceeds the 420 KiB gzip budget/)+})