From a3d6cbe404d13f49c87f7b246c73cf55a05b32a8 Mon Sep 17 00:00:00 2001 From: Do Siki Date: Tue, 29 Sep 2026 21:55:31 +0200 Subject: [PATCH] build(proto): mark the package as ESM so the Payload CLI loads the config (MITHOME-136) The Payload CLI failed with ERR_REQUIRE_ASYNC_MODULE on Node 22 and 26 alike: without "type": "module" it loaded payload.config.ts as CommonJS and could not require the top-level-await ESM @payloadcms/richtext-lexical. Following the official Payload template: "type": "module", CommonJS jest files and the content schema renamed to .cjs, ESLint globs updated. Next's standalone server.js is ESM and starts; 516 unit tests, tsc, lint and build are green. Co-Authored-By: Claude Opus 5.5 --- .agent/steering/testing.md | 8 ++++---- docs/content-editor-recovery.md | 2 +- .../postgres-migration-mithome-136/design.md | 3 ++- .../postgres-migration-mithome-136/proposal.md | 2 +- .../postgres-migration-mithome-136/tasks.md | 2 +- proto/eslint.config.mjs | 8 +++++--- proto/{jest.config.js => jest.config.cjs} | 2 +- ...integration.js => jest.config.integration.cjs} | 6 +++--- .../{jest.config.unit.js => jest.config.unit.cjs} | 2 +- ...ration.js => jest.globalSetup.integration.cjs} | 0 ...ion.js => jest.globalTeardown.integration.cjs} | 0 proto/{jest.setup.js => jest.setup.cjs} | 0 ....integration.js => jest.setup.integration.cjs} | 0 proto/package.json | 15 ++++++++------- proto/src/content/index.ts | 2 +- proto/src/content/{schema.js => schema.cjs} | 0 scripts/test-content-schema.js | 2 +- 17 files changed, 29 insertions(+), 25 deletions(-) rename proto/{jest.config.js => jest.config.cjs} (93%) rename proto/{jest.config.integration.js => jest.config.integration.cjs} (81%) rename proto/{jest.config.unit.js => jest.config.unit.cjs} (95%) rename proto/{jest.globalSetup.integration.js => jest.globalSetup.integration.cjs} (100%) rename proto/{jest.globalTeardown.integration.js => jest.globalTeardown.integration.cjs} (100%) rename proto/{jest.setup.js => jest.setup.cjs} (100%) rename proto/{jest.setup.integration.js => jest.setup.integration.cjs} (100%) rename proto/src/content/{schema.js => schema.cjs} (100%) diff --git a/.agent/steering/testing.md b/.agent/steering/testing.md index 696a575..4e7c8aa 100644 --- a/.agent/steering/testing.md +++ b/.agent/steering/testing.md @@ -9,9 +9,9 @@ Ez a fájl automatikusan betöltődik tesztfájlok érintésekor, és segít a t ## Stratégia és Prioritások -1. **Unit tesztek**: Logikai egységek, tiszta függvények, komponensek tesztelése (`jest.config.unit.js`) -2. **Browser integration**: jsdom + mocked API-k (`jest.config.js`) -3. **Docker integration**: Valódi HTTP hívások a futó Docker stack-hez (`jest.config.integration.js`) +1. **Unit tesztek**: Logikai egységek, tiszta függvények, komponensek tesztelése (`jest.config.unit.cjs`) +2. **Browser integration**: jsdom + mocked API-k (`jest.config.cjs`) +3. **Docker integration**: Valódi HTTP hívások a futó Docker stack-hez (`jest.config.integration.cjs`) 4. **E2E tesztek**: Teljes user flow-ok (`src/__tests__/e2e-docker.test.ts`) ## Elvárások @@ -38,7 +38,7 @@ Ez a fájl automatikusan betöltődik tesztfájlok érintésekor, és segít a t ## Futtatás (`proto/` mappából) ```bash -npm test # unit tesztek (alapértelmezett, jest.config.unit.js) +npm test # unit tesztek (alapértelmezett, jest.config.unit.cjs) npm run test:watch # watch mode npm run test:coverage # lefedettség riport npm run test:browser # browser integration diff --git a/docs/content-editor-recovery.md b/docs/content-editor-recovery.md index 435fe86..7b57681 100644 --- a/docs/content-editor-recovery.md +++ b/docs/content-editor-recovery.md @@ -38,7 +38,7 @@ A teszt egy beágyazott tömböket és objektumokat, valamint string-, boolean- ## Szerveroldali védelmi réteg -A `MITHOME-41` részeként a `proto/src/content/schema.js` az összes szerkeszthető content-fájl kötelező mezőit, típusait és megengedett kulcsait írja le. A Next.js loader és a Content Editor ezt az egy közös validátort használja. +A `MITHOME-41` részeként a `proto/src/content/schema.cjs` az összes szerkeszthető content-fájl kötelező mezőit, típusait és megengedett kulcsait írja le. A Next.js loader és a Content Editor ezt az egy közös validátort használja. A mentés csak sikeres validáció után történik. Az Editor legfeljebb 256 KiB-os request body-t fogad; hibás JSON vagy sémahiba `422` választ ad, és az eredeti fájlt érintetlenül hagyja. Érvényes mentéskor: diff --git a/openspec/changes/postgres-migration-mithome-136/design.md b/openspec/changes/postgres-migration-mithome-136/design.md index 437034e..492a030 100644 --- a/openspec/changes/postgres-migration-mithome-136/design.md +++ b/openspec/changes/postgres-migration-mithome-136/design.md @@ -37,7 +37,8 @@ ### D2: Sémamigrációk és eszközök - A kiinduló migráció a teljes jelenlegi config sémája: `payload migrate:create initial`. A `src/migrations/index.ts` ezzel indul újra. -- A Payload parancssori eszköze helyben `npx -y node@22 ./node_modules/.bin/payload …` alakban fut. Ehhez kerül egy npm script (`payload:node22`). A típus- és import-map-generálás is erre áll át; a mostani `--input-type=module` kerülőút megszűnik. +- **A parancssori eszköz hibájának valódi oka** (az 1.1-es feladatban derült ki): nem a Node-verzió. A `proto/package.json`-ban nem volt `"type": "module"`, ezért a Payload parancssori eszköze a configot CommonJS-ként töltötte be, és nem tudta behúzni az ESM-es, top-level await-es `@payloadcms/richtext-lexical`-t. Node 22 alatt is ugyanez a hiba jött. +- **Megoldás:** `"type": "module"`, ahogy a Payload hivatalos sablonja is csinálja. A CommonJS jest-fájlok és a `src/content/schema.js` `.cjs` kiterjesztést kaptak. Ellenőrizve: a parancssori eszköz Node 26-on is betölti a configot; a Next `standalone` `server.js` ESM-es, és elindul. A `--input-type=module` kerülőút megszűnik. - A Mongo-adatmigrációk (8 fájl) és a segédfüggvényeik törlődnek. Az általuk elért állapot a stagingadatban van, és azt a D3 hozza át. ### D3: Egyszeri adatmigráció (`proto/scripts/migrate-mongo-to-postgres.ts`) diff --git a/openspec/changes/postgres-migration-mithome-136/proposal.md b/openspec/changes/postgres-migration-mithome-136/proposal.md index 178a70d..d59b8e3 100644 --- a/openspec/changes/postgres-migration-mithome-136/proposal.md +++ b/openspec/changes/postgres-migration-mithome-136/proposal.md @@ -24,7 +24,7 @@ A tulajdonos 2026-09-29-én döntött: - PostgreSQL 16 szolgáltatás a staging és a prod Compose-ban, csak belső hálózaton; - új változó: `DATABASE_URI` (a `MONGODB_URI` helyett); - a `deploy.sh` a deploy előtt `pg_dump` mentést készít. -- **Eszközök:** a Payload parancssori eszköze helyben `npx node@22`-vel fut (a Node 26-os `ERR_REQUIRE_ASYNC_MODULE` hiba miatt). A konténer Node 20-at használ, ott nincs változás. +- **Eszközök:** `"type": "module"` a `proto/package.json`-ban (a CommonJS jest-fájlok `.cjs`-re nevezve). Ezzel a Payload parancssori eszköze Node 26-on is működik; az `ERR_REQUIRE_ASYNC_MODULE` oka a CommonJS-betöltés volt, nem a Node-verzió. - **Kivezetés:** a halott `src/lib/mongodb.ts`, a `mongodb` és a `@payloadcms/db-mongodb` csomag, a Mongo-utánzatos tesztek, valamint a MongoDB-szolgáltatás a Compose-ból egy kiadással később, sikeres ellenőrzés után. - **Dokumentáció:** `CLAUDE.md` (stack, környezeti változók), `.agent/steering/architecture.md`, `DOCKER.md`, `deploy.md`. diff --git a/openspec/changes/postgres-migration-mithome-136/tasks.md b/openspec/changes/postgres-migration-mithome-136/tasks.md index 6dc703a..594f865 100644 --- a/openspec/changes/postgres-migration-mithome-136/tasks.md +++ b/openspec/changes/postgres-migration-mithome-136/tasks.md @@ -2,7 +2,7 @@ ## 1. Eszközök és illesztő -- [ ] 1.1 `payload:node22` npm script (D2); a típus- és import-map-generálás erre áll át. Ellenőrzés: a `generate:types` és a `migrate:status` fut helyben. +- [x] 1.1 `"type": "module"`, a CommonJS jest-fájlok és a `schema` `.cjs`-re nevezve, az ESLint-globok frissítve (D2). Ellenőrzés: a `payload migrate:status` betölti a configot; 516 unit teszt, tsc, lint, build és a `standalone` `server.js` indítása zöld. - [ ] 1.2 `@payloadcms/db-postgres` (Payload-verzióval azonos), `postgresAdapter({ idType: 'uuid', push: false })`, `DATABASE_URI`. Ellenőrzés: `tsc`, `npm test`. - [ ] 1.3 Kiinduló migráció (`migrate:create initial`), új `src/migrations/index.ts`; a 8 Mongo-migráció, a `migrate-global-docs`, a `localize-paths`, a `mongodb.ts` és a fake-Mongo tesztek törlése. Ellenőrzés: eldobható PostgreSQL-en a migráció kétszer fut, a második 0 lépés. diff --git a/proto/eslint.config.mjs b/proto/eslint.config.mjs index 996d4d8..17663f6 100755 --- a/proto/eslint.config.mjs +++ b/proto/eslint.config.mjs @@ -29,9 +29,11 @@ const eslintConfig = [ files: [ "**/*.test.ts", "**/*.test.tsx", - "jest.config*.js", - "jest.setup*.js", - "jest.globalSetup*.js", + // MITHOME-136: package is "type": "module", so the CommonJS jest files are .cjs. + "jest.config*.cjs", + "jest.setup*.cjs", + "jest.globalSetup*.cjs", + "jest.globalTeardown*.cjs", "playwright.config.ts", ], rules: { diff --git a/proto/jest.config.js b/proto/jest.config.cjs similarity index 93% rename from proto/jest.config.js rename to proto/jest.config.cjs index 340589b..9ff5a86 100755 --- a/proto/jest.config.js +++ b/proto/jest.config.cjs @@ -7,7 +7,7 @@ const createJestConfig = nextJest({ // Add any custom config to be passed to Jest const customJestConfig = { - setupFilesAfterEnv: ['/jest.setup.js'], + setupFilesAfterEnv: ['/jest.setup.cjs'], moduleNameMapper: { // Handle module aliases (this will be automatically configured for you based on your tsconfig.json paths) '^@/(.*)$': '/src/$1', diff --git a/proto/jest.config.integration.js b/proto/jest.config.integration.cjs similarity index 81% rename from proto/jest.config.integration.js rename to proto/jest.config.integration.cjs index f31b162..bcfe7f7 100755 --- a/proto/jest.config.integration.js +++ b/proto/jest.config.integration.cjs @@ -8,7 +8,7 @@ const createJestConfig = nextJest({ // Integration tests configuration - runs in Node.js environment with fetch polyfill const integrationJestConfig = { displayName: 'Integration Tests', - setupFilesAfterEnv: ['/jest.setup.integration.js'], + setupFilesAfterEnv: ['/jest.setup.integration.cjs'], moduleNameMapper: { // Handle module aliases '^@/(.*)$': '/src/$1', @@ -19,8 +19,8 @@ const integrationJestConfig = { '/src/__tests__/e2e-docker.test.ts' ], testTimeout: 30000, // Longer timeout for integration tests - globalSetup: '/jest.globalSetup.integration.js', - globalTeardown: '/jest.globalTeardown.integration.js' + globalSetup: '/jest.globalSetup.integration.cjs', + globalTeardown: '/jest.globalTeardown.integration.cjs' } // createJestConfig is exported this way to ensure that next/jest can load the Next.js config which is async diff --git a/proto/jest.config.unit.js b/proto/jest.config.unit.cjs similarity index 95% rename from proto/jest.config.unit.js rename to proto/jest.config.unit.cjs index c8fa342..33ad946 100755 --- a/proto/jest.config.unit.js +++ b/proto/jest.config.unit.cjs @@ -8,7 +8,7 @@ const createJestConfig = nextJest({ // Unit tests configuration - runs in Node.js environment const unitJestConfig = { displayName: 'Unit Tests', - setupFilesAfterEnv: ['/jest.setup.js'], + setupFilesAfterEnv: ['/jest.setup.cjs'], moduleNameMapper: { // Handle module aliases '^@/(.*)$': '/src/$1', diff --git a/proto/jest.globalSetup.integration.js b/proto/jest.globalSetup.integration.cjs similarity index 100% rename from proto/jest.globalSetup.integration.js rename to proto/jest.globalSetup.integration.cjs diff --git a/proto/jest.globalTeardown.integration.js b/proto/jest.globalTeardown.integration.cjs similarity index 100% rename from proto/jest.globalTeardown.integration.js rename to proto/jest.globalTeardown.integration.cjs diff --git a/proto/jest.setup.js b/proto/jest.setup.cjs similarity index 100% rename from proto/jest.setup.js rename to proto/jest.setup.cjs diff --git a/proto/jest.setup.integration.js b/proto/jest.setup.integration.cjs similarity index 100% rename from proto/jest.setup.integration.js rename to proto/jest.setup.integration.cjs diff --git a/proto/package.json b/proto/package.json index 43882fc..3a13794 100755 --- a/proto/package.json +++ b/proto/package.json @@ -2,18 +2,19 @@ "name": "proto", "version": "0.1.0", "private": true, + "type": "module", "scripts": { "dev": "next dev --turbopack", "build": "next build --turbopack", "start": "next start", "lint": "eslint", - "test": "jest --config jest.config.unit.js", - "test:watch": "jest --config jest.config.unit.js --watch", - "test:coverage": "jest --config jest.config.unit.js --coverage", - "test:unit": "jest --config jest.config.unit.js", - "test:browser": "jest --config jest.config.js src/__tests__/browser-integration.test.ts", - "test:integration": "INTEGRATION_TESTS=1 jest --config jest.config.integration.js src/__tests__/integration.test.ts", - "test:e2e": "E2E_TESTS=1 jest --config jest.config.integration.js src/__tests__/e2e-docker.test.ts", + "test": "jest --config jest.config.unit.cjs", + "test:watch": "jest --config jest.config.unit.cjs --watch", + "test:coverage": "jest --config jest.config.unit.cjs --coverage", + "test:unit": "jest --config jest.config.unit.cjs", + "test:browser": "jest --config jest.config.cjs src/__tests__/browser-integration.test.ts", + "test:integration": "INTEGRATION_TESTS=1 jest --config jest.config.integration.cjs src/__tests__/integration.test.ts", + "test:e2e": "E2E_TESTS=1 jest --config jest.config.integration.cjs src/__tests__/e2e-docker.test.ts", "test:smoke:staging": "playwright test --config=playwright.config.ts --project=staging", "test:seo:production": "playwright test --config=playwright.config.ts --project=production-seo", "test:docker": "npm run test:integration && npm run test:e2e", diff --git a/proto/src/content/index.ts b/proto/src/content/index.ts index 695c339..6721f76 100755 --- a/proto/src/content/index.ts +++ b/proto/src/content/index.ts @@ -23,7 +23,7 @@ import type { ContactPageContent, LegalPageContent } from './types' -import { validateContent } from './schema' +import { validateContent } from './schema.cjs' // Import JSON files import commonJson from './common.json' diff --git a/proto/src/content/schema.js b/proto/src/content/schema.cjs similarity index 100% rename from proto/src/content/schema.js rename to proto/src/content/schema.cjs diff --git a/scripts/test-content-schema.js b/scripts/test-content-schema.js index aaa4ed6..276d4fc 100644 --- a/scripts/test-content-schema.js +++ b/scripts/test-content-schema.js @@ -2,7 +2,7 @@ const assert = require('assert/strict'); const fs = require('fs'); -const { validateContent } = require('../proto/src/content/schema'); +const { validateContent } = require('../proto/src/content/schema.cjs'); const files = { common: 'proto/src/content/common.json',