Replace quickjs with val modules for validation - #448
Conversation
🦋 Changeset detectedLatest commit: 94ce8a0 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
19379e7 to
1c50305
Compare
…and more practical validation errors
…key (looks nice IMO)
There was a problem hiding this comment.
Pull request overview
This PR removes the QuickJS-based runtime previously used for loading/validating Val modules and replaces it with a Node vm-based loader plus a “val.modules-driven” extraction flow. It also improves CLI validation UX by resolving validation sourcePaths to concrete file:line:col locations and printing code frames, including correct key-vs-value targeting for record/gallery errors.
Changes:
- Replace QuickJS evaluation (
quickjs-emscripten,ValQuickJSRuntime,readValFile) withloadValModules()+extractValModules()for server-side module loading/validation. - Add module-path → source-range mapping (
modulePathMap) and CLI utilities to render clickable locations and code frames (withkeyErrorsupport). - Add
--watchmode toval validate, and tighten validation scope to modules registered inval.modules.
Reviewed changes
Copilot reviewed 24 out of 25 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| pnpm-lock.yaml | Updates dependency graph: adds chokidar, removes quickjs-emscripten. |
| packages/server/src/ValQuickJSRuntime.ts | Removed QuickJS runtime wrapper and module stubs. |
| packages/server/src/Service.ts | Switches service to loadValModules + extractValModules; adds registry-based module listing. |
| packages/server/src/readValFile.ts | Removed QuickJS-based .val file reader. |
| packages/server/src/readValFile.test.ts | Removes tests tied to QuickJS reader/runtime. |
| packages/server/src/patchValFile.ts | Drops the now-unused QuickJS runtime parameter from patching flow. |
| packages/server/src/modulePathMap.ts | Adds AST traversal to map module paths to source ranges (key/value targeting). |
| packages/server/src/modulePathMap.test.ts | Adds tests for module path mapping and graceful handling of malformed paths. |
| packages/server/src/loadValModules.ts | Introduces Node vm-based loader for val.modules.* and recursively loaded Val files. |
| packages/server/src/index.ts | Exposes modulePathMap utilities from @valbuild/server. |
| packages/server/src/createFixPatch.ts | Enhances remaining errors with optional sourcePath and sets keyError for gallery entry issues. |
| packages/server/package.json | Removes quickjs-emscripten dependency. |
| packages/react/src/stega/index.ts | Updates comment to reference new stub location (loadValModules). |
| packages/react/src/internal/index.ts | Updates comment to reference new stub location (loadValModules). |
| packages/core/src/selector/file.ts | Fixes conditional type precedence in FileSelector metadata typing. |
| packages/core/src/schema/record.ts | Marks gallery/media collection entry errors as keyError to point diagnostics at keys. |
| packages/cli/src/validate.ts | Adds watch mode, code-frame output, and key/value-aware location formatting. |
| packages/cli/src/utils/sourcePathToFileLocation.ts | Adds sourcePath → file location & code frame rendering using server-exported range mapping. |
| packages/cli/src/runValidation.ts | Adds keyError propagation, validates only registered modules, and supports per-entry gallery error source paths. |
| packages/cli/src/listUnusedFiles.ts | Skips non-registered .val files when determining files used by Val. |
| packages/cli/src/cli.ts | Adds --watch/-w flag for validate and rejects --watch with --fix. |
| packages/cli/src/fixtures/basic/val.modules.ts | Adds fixture val.modules.ts registry for CLI fixtures. |
| packages/cli/src/fixtures/basic/val.config.ts | Exposes config from initVal() for use with modules registry. |
| packages/cli/package.json | Adds chokidar dependency for watch mode. |
| .changeset/validation-error-code-frames.md | Changeset documenting new CLI error locations + code frames and new server exports. |
Files not reviewed (1)
- pnpm-lock.yaml: Generated file
| if (existing !== undefined) { | ||
| return existing; | ||
| } | ||
| const filePath = path.join(projectRoot, moduleFilePath); |
| } | ||
| }, | ||
| }, |
| async get( | ||
| moduleFilePath: ModuleFilePath, | ||
| modulePath: ModulePath, | ||
| options?: { validate: boolean; source: boolean; schema: boolean }, | ||
| ): Promise<SerializedModuleContent> { | ||
| const valModule = await readValFile( | ||
| moduleFilePath, | ||
| this.projectRoot, | ||
| this.runtime, | ||
| options ?? { validate: true, source: true, schema: true }, | ||
| const opts = options ?? { validate: true, source: true, schema: true }; | ||
| const source = this.extracted.sources[moduleFilePath] as Source | undefined; |
| resolution: {integrity: sha512-DZ4yORTwrbTj/7MZYq2w+/ZFdI6OZ/f9SFHR+71gIVUZhOQPHzVCLpvRnPgyaMpfWxxk/4ONva3GQSyNIKRv6A==} | ||
| engines: {node: '>=10'} | ||
| deprecated: Old versions of tar are not supported, and contain widely publicized security vulnerabilities, which have been fixed in the current version. Please update. Support for old versions may be purchased (at exorbitant rates) by contacting i@izs.me | ||
| deprecated: Old versions of tar are not supported, and contain widely publicized security vulnerabilities, which have been fixed in the current version. Please update. Support for old versions may be purchased (at exhorbitant rates) by contacting i@izs.me |
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| const sandbox: Record<string, any> = { | ||
| exports: moduleObj.exports, | ||
| module: moduleObj, | ||
| require: customRequire, | ||
| __filename: absPath, | ||
| __dirname: dirName, | ||
| console, | ||
| process, | ||
| }; |
After moving to in-memory val.modules extraction, Service.get only honors `validate`; `source`/`schema` were accepted but ignored. Remove them from the options type and update all call sites so the API is honest. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…oundary - Remove the dangling/inaccurate "+1" TODO in modulePathMap (no +1 happens). - Add a SECURITY note to loadValModules clarifying the vm context is not a sandbox and must only evaluate trusted first-party project files. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
No description provided.