[DOCS] Document web_register_native_module_id_overrides for web native modules

Open Beginner friendly
#225 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
78/100
Issue type
Documentation
Clarity
Clearly specified
Activity status
Active
Tech stack
typescript
Domain
documentation

Research direction

Start with the web_deps section in docs/docs/core-module.md, then inspect GenerateWebNativeModulePackageFilesProcessor.swift and existing coreutils declarations to confirm the attribute’s mapping semantics. Document the emitted web implementation path, compiled Valdi module ID, comma-separated mappings, ownership guidance, and a complete ts_project plus valdi_module example. Done means the guide explains the generated package bridge and links to it from the web-development documentation; a troubleshooting entry is suggested if feasible.

Written by the indexing model from the issue text.

Description

What documentation needs improvement?

The valdi_module documentation in docs/docs/core-module.md, particularly the section covering web_deps.

The web-development documentation should also link to this information when describing browser-specific implementations.

What's unclear or missing?

web_deps is documented, but web_register_native_module_id_overrides is not.

When a Valdi module declares a native TypeScript API such as:

import { doSomething } from './ExampleNative';

and provides its browser implementation through a ts_project in web_deps, adding the web dependency alone does not make the compiled source import resolve.

The module must also declare the mapping:

valdi_module(
    name = "example",
    # ...
    web_deps = [":example_web"],
    web_register_native_module_id_overrides = {
        "example/web/ExampleNative.js": "example/src/ExampleNative",
    },
)

Without this mapping, the browser implementation may be included under native/, but no package file is generated at the module ID imported by the compiled Valdi source. Consumers then receive a generic bundler error such as:

Module not found: Can't resolve './ExampleNative.js'

This makes the problem look like a webpack or package-collapse bug, even though Valdi already has a supported mechanism for it.

The behavior is implemented by:

  • GenerateWebNativeModulePackageFilesProcessor.swift
  • web_register_native_module_id_overrides in valdi_module
  • Existing modules such as coreutils

Suggested changes:

  1. Add web_register_native_module_id_overrides immediately after web_deps in docs/docs/core-module.md.

  2. Document that:

    • The key is the emitted web implementation path supplied by web_deps.
    • The value is the compiled Valdi module ID that imports the native API.
    • Multiple module IDs may be supplied as a comma-separated string.
    • The mapping should be declared by the module that owns the web implementation, not by each consuming application.
  3. Include a complete ts_project plus valdi_module example.

  4. Explain that Valdi generates a package bridge similar to:

    // AUTO-GENERATED by Valdi. Do not edit.
    module.exports = require('../../../native/example/web/ExampleNative.js');
    
  5. If feasible, add a compiler diagnostic—or at least a troubleshooting entry—for modules that provide a web-native implementation but omit the mapping.

Additional context:

The intended feature already works correctly once the override is declared. The issue is discoverability: the public documentation currently describes web_deps without explaining the companion attribute required for native-module imports.

Dominant language
C++
Stars
16.4k
Forks
539
PR merge metrics
No merged PRs in 30d

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Snapchat/Valdi

All issues in Snapchat/Valdi

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.