Skip to content

Replace quickjs with val modules for validation - #448

Open
freekh wants to merge 12 commits into
allow-files-in-public-dirfrom
replace-quickjs-with-val-modules-for-validation
Open

Replace quickjs with val modules for validation#448
freekh wants to merge 12 commits into
allow-files-in-public-dirfrom
replace-quickjs-with-val-modules-for-validation

Conversation

@freekh

@freekh freekh commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

No description provided.

@changeset-bot

changeset-bot Bot commented Jun 24, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 94ce8a0

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@valbuild/server Patch
@valbuild/cli Patch
@valbuild/next Patch

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

@freekh
freekh force-pushed the replace-quickjs-with-val-modules-for-validation branch from 19379e7 to 1c50305 Compare June 24, 2026 19:28
@freekh
freekh changed the base branch from main to allow-files-in-public-dir June 24, 2026 19:45

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) with loadValModules() + extractValModules() for server-side module loading/validation.
  • Add module-path → source-range mapping (modulePathMap) and CLI utilities to render clickable locations and code frames (with keyError support).
  • Add --watch mode to val validate, and tighten validation scope to modules registered in val.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);
Comment on lines 51 to 53
}
},
},
Comment on lines 86 to +92
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;
Comment thread packages/server/src/modulePathMap.ts
Comment thread pnpm-lock.yaml
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
Comment on lines +153 to +162
// 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,
};
freekh and others added 4 commits June 25, 2026 08:18
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants