Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

supportRelativeURL bombs when Node "path" object is not present

Đang mở
#197 3 bình luận 1 reaction 0 người được giao Xem trên GitHub

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

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
35/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
javascript
Lĩnh vực
devtools

Hướng nghiên cứu

Bắt đầu tại supportRelativeURL và mapSourcePosition, nơi issue báo cáo lỗi khi Node path object hoặc các phương thức của nó không khả dụng. So sánh cách xử lý này với các kiểm tra fs hiện có và xác định liệu hướng giải quyết dự kiến là hành vi có khả năng chống lỗi hay tài liệu README; công việc được xem là hoàn tất khi môi trường Unreal-style được báo cáo không còn lỗi hoặc các yêu cầu của môi trường đó được ghi lại rõ ràng.

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

Mô tả

I am attempting to use source-map-support with a platform where v8 is embedded directly into an application, which is not Node or a browser (it's a plugin for the Unreal game engine). I do not know if this is a use case you support, but source-map-support does have many options that seem intended for making it work in unusual environments.

The Unreal environment does not have full fs or path objects (both are available through require, but return empty objects). It does have a dedicated function for loading a file into a string from disk. I am currently running this:

    require('source-map-support').install({overrideRetrieveSourceMap: true, retrieveSourceMap: function(source:string) {
        if (!source.startsWith("file:///")) { return null }
        let name = decodeURIComponent(source.substr(8)) + ".map"
        let result = JavascriptLibrary.ReadStringFromFile(null, name)
        if (!result) { return null }
        return { url: source, map: result }
      }
    })

This works except for the supportRelativeURL function, which calls both path.dirname and path.resolve without checking. In my testing, source-map-support fails 100% because supportRelativeURL gets called by mapSourcePosition. (mapSourcePosition actually calls supportRelativeURL twice. In my testing, the second one is the only one that is triggering, comment "Only return the original position if a matching line was found…". As a side note though the first call is interesting, since in cases where it does trigger, it seems to only be about maintaining the fileContentsCache. However if the user is using overrideRetrieveSourceMap— which I am— the fileContentsCache is unused, so this clause is useless work…).

If I replace the contents of supportRelativeURL with return url, source-map-support overall works great.

I am not completely sure how to proceed here. I could potentially add the missing path methods to the environment (although path.resolve concerns me since that involves per-OS support to do properly). It does seem too bad though that source-map-support almost allows me to configure it into no dependence on the filesystem, then falls down in this one function.

I think my expected behavior is that source-map-support should check for the presence of the methods on path it needs, and be resistant to path being null, since after all it already goes to the bother of doing this with fs. If this is not practical, it might help for people in unusual situations to document in the README that the path, path.dirname and path.resolve objects are required (how is it requiring "path" works in the browser, anyway?).

Ngôn ngữ chính
JavaScript
Star
2.2k
Fork
221
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

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

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 evanw/node-source-map-support

Tất cả issue của evanw/node-source-map-support

Issue tương tự

Thêm issue về JavaScript

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.