refactor(cli): unified module loading with validation at the load boundary#3293
Merged
ejhammond merged 1 commit intoJun 30, 2026
Merged
Conversation
…ndary
Add a single shared loadModuleWithSchema(file, schema, {label}) that imports a
user-authored module, takes its default export, and validates it against a zod
schema. Route all four user-module loaders (config, integration, codemod,
template) through it so loading and validation are uniform and happen at the
load/discovery boundary.
The create* factories (createConfig, createIntegration, createCodemod,
createConfigCodemod, createPageTemplate, createBlockTemplate) become pure typed
identity helpers: they stamp the type discriminator where applicable and return
the definition unchanged, performing no runtime validation. Their value is the
exported TypeScript surface for editor DX.
Define the metadata envelope schemas the loader validates: AstryxConfigSchema
and AstryxIntegrationSchema (existing), CodemodEnvelopeSchema (a discriminated
union over the stamped type), and TemplateEnvelopeSchema (BaseTemplateSchema +
type). The bespoke 'must default-export a createCodemod result' structural
check is removed in favor of schema validation, so a plain object matching the
envelope is accepted regardless of how it was produced.
Config strictness at the load boundary is preserved (unknown keys still
rejected). The built-in core .doc.mjs / template.doc.mjs loader and convention
are untouched; only the integration template path moves to loadModuleWithSchema.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Makes loading external user-authored JS uniform and moves validation to the load boundary.
Previously, four loaders each imported-and-picked-and-validated differently, and the
create*factories also validated. This change:loadModuleWithSchema(file, schema, {label})inlib/module-loader.mjs— "execute the module, take the default export, validate it against the expected schema."create*factories pure typed identity (stamp-only, no runtime validation). Their value is the exported TypeScript surface for editor DX.Behavior stays equivalent — genuinely invalid inputs are still rejected, just at load, not in the factory.
Envelope schemas (the load-boundary contract)
AstryxConfigSchema(unchanged; strict — unknown keys still rejected)AstryxIntegrationSchema(unchanged)CodemodEnvelopeSchema— discriminated union over the stampedtype('code'may carryfileExtensions;'config'may not)TemplateEnvelopeSchema—BaseTemplateSchema+type: 'page' | 'block'A plain object matching an envelope is accepted regardless of how it was produced (no more factory-identity coupling).
Migrated loaders
lib/project.mjsProject.load→loadModuleWithSchema(configPath, AstryxConfigSchema, {label: 'astryx.config'})(strict config validation preserved)lib/integrations.mjsloadManifestObject+loadIntegrations→loadModuleWithSchema(..., AstryxIntegrationSchema, ...)(default-export only; dropped the?? mod.integration ?? modfallback)codemods/integration-discovery.mjs→loadModuleWithSchema(file, CodemodEnvelopeSchema, ...)(replaces bespokevalidateCodemodExport)api/template.mjsloadIntegrationDoc→loadModuleWithSchema(file, TemplateEnvelopeSchema, ...)(default-export only; dropped?? mod.docfallback)The built-in core
.doc.mjs/template.doc.mjsloader (loadDocModule→docModule.doc) is untouched.Out of scope
No changes to the upgrade command ordering or dry-run (separate follow-up). Config strictness at load is not loosened.
Test changes
loadModuleWithSchematests (valid default export passes; missing default export throws; schema mismatch throws with a readable message; hermetic repo-local temp module).Green gate
npx vitest run packages/cli→ 1596 passed (97 files)node scripts/sync-exports.js --check→ 0./scripts/add-copyright.sh --check→ 0pnpm -F @astryxdesign/cli typecheck:json-api→ 0pnpm build+node scripts/verify-exports.mjs→ 0npx eslinton changed files → 0--helpOK;component --list --jsonvalid envelope;upgrade --list --jsonlists codemodsnode scripts/check-changesets.mjs→ 0