|
| 1 | +#pragma once |
| 2 | + |
| 3 | +#include <string> |
| 4 | +#include <vector> |
| 5 | + |
| 6 | +// Forward declare v8 types to keep this header lightweight and avoid |
| 7 | +// requiring V8 headers at include sites. |
| 8 | +namespace v8 { |
| 9 | +class Isolate; |
| 10 | +template <class T> class Local; |
| 11 | +class Object; |
| 12 | +class Function; |
| 13 | +class Context; |
| 14 | +} |
| 15 | + |
| 16 | +namespace tns { |
| 17 | + |
| 18 | +// HMRSupport: Isolated helpers for minimal HMR (import.meta.hot) support. |
| 19 | +// |
| 20 | +// This module contains: |
| 21 | +// - Per-module hot data store |
| 22 | +// - Registration for accept/disable callbacks |
| 23 | +// - Initializer to attach import.meta.hot to a module's import.meta |
| 24 | +// |
| 25 | +// Note: Triggering/dispatch is handled by the HMR system elsewhere. |
| 26 | + |
| 27 | +// Retrieve or create the per-module hot data object. |
| 28 | +v8::Local<v8::Object> GetOrCreateHotData(v8::Isolate* isolate, const std::string& key); |
| 29 | + |
| 30 | +// Register accept and dispose callbacks for a module key. |
| 31 | +void RegisterHotAccept(v8::Isolate* isolate, const std::string& key, v8::Local<v8::Function> cb); |
| 32 | +void RegisterHotDispose(v8::Isolate* isolate, const std::string& key, v8::Local<v8::Function> cb); |
| 33 | + |
| 34 | +// Optional: expose read helpers (may be useful for debugging/integration) |
| 35 | +std::vector<v8::Local<v8::Function>> GetHotAcceptCallbacks(v8::Isolate* isolate, const std::string& key); |
| 36 | +std::vector<v8::Local<v8::Function>> GetHotDisposeCallbacks(v8::Isolate* isolate, const std::string& key); |
| 37 | + |
| 38 | +// Attach a minimal import.meta.hot object to the provided import.meta object. |
| 39 | +// The modulePath should be the canonical path used to key callback/data maps. |
| 40 | +void InitializeImportMetaHot(v8::Isolate* isolate, |
| 41 | + v8::Local<v8::Context> context, |
| 42 | + v8::Local<v8::Object> importMeta, |
| 43 | + const std::string& modulePath); |
| 44 | + |
| 45 | +// ───────────────────────────────────────────────────────────── |
| 46 | +// Dev HTTP loader helpers (used during HMR only) |
| 47 | +// These are isolated here so ModuleInternalCallbacks stays lean. |
| 48 | +// |
| 49 | +// Normalize HTTP(S) URLs for module registry keys. |
| 50 | +// - Preserves versioning params for SFC endpoints (/@ns/sfc, /@ns/asm) |
| 51 | +// - Drops cache-busting segments for /@ns/rt and /@ns/core |
| 52 | +// - Drops query params for general app modules (/@ns/m) |
| 53 | +std::string CanonicalizeHttpUrlKey(const std::string& url); |
| 54 | + |
| 55 | +// Minimal text fetch for dev HTTP ESM loader. Returns true on 2xx with non-empty body. |
| 56 | +// - out: response body |
| 57 | +// - contentType: Content-Type header if present |
| 58 | +// - status: HTTP status code |
| 59 | +bool HttpFetchText(const std::string& url, std::string& out, std::string& contentType, int& status); |
| 60 | + |
| 61 | +} // namespace tns |
0 commit comments