[DOCS] Document web_register_native_module_id_overrides for web native modules

未关闭 适合新手
#225 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
78/100
Issue 类型
文档
描述清晰度
描述清楚
活跃度
活跃
技术栈
typescript
领域
documentation

调研方向

从 docs/docs/core-module.md 中的 web_deps 部分开始,然后检查 GenerateWebNativeModulePackageFilesProcessor.swift 和现有的 coreutils 声明,以确认该属性的映射语义。记录生成的 Web 实现路径、编译后的 Valdi 模块 ID、逗号分隔的映射、归属指导,以及包含 ts_project 和 valdi_module 的完整示例。完成标准是指南解释生成的 package 桥接,并从 Web 开发文档链接到该指南;如果可行,建议添加 troubleshooting 条目。

由索引模型根据 Issue 内容生成。

描述

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.

主要语言
C++
星标
16.4k
派生
539
PR 合并指标
30 天内没有已合并 PR

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

Snapchat/Valdi 的其他 Issue

查看 Snapchat/Valdi 的全部 Issue

相似的 Issue

更多 C++ Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。