[DOCS] Document web_register_native_module_id_overrides for web native modules

Đang mở Phù hợp với người mới
#225 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
78/100
Loại issue
Tài liệu
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
typescript
Lĩnh vực
documentation

Hướng nghiên cứu

Bắt đầu với phần web_deps trong docs/docs/core-module.md, sau đó kiểm tra GenerateWebNativeModulePackageFilesProcessor.swift và các khai báo coreutils hiện có để xác nhận ngữ nghĩa ánh xạ của thuộc tính. Tài liệu hóa đường dẫn triển khai web được tạo, ID mô-đun Valdi đã biên dịch, các ánh xạ phân tách bằng dấu phẩy, hướng dẫn về trách nhiệm và ví dụ hoàn chỉnh có ts_project cùng valdi_module. Công việc hoàn tất khi hướng dẫn giải thích cầu nối package được tạo và liên kết đến đó từ tài liệu phát triển web; nếu khả thi, đề xuất thêm mục troubleshooting.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
C++
Star
16.4k
Fork
539
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của Snapchat/Valdi

Tất cả issue của Snapchat/Valdi

Issue tương tự

Thêm issue về C++

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.