Skip to content

Commit 59191d3

Browse files
authored
feat: http loaded es module realms + HMR DX enrichments (#312)
1 parent 14355d5 commit 59191d3

File tree

19 files changed

+2899
-180
lines changed

19 files changed

+2899
-180
lines changed

NativeScript/NativeScript-Prefix.pch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef NativeScript_Prefix_pch
22
#define NativeScript_Prefix_pch
33

4-
#define NATIVESCRIPT_VERSION "8.9.3"
4+
#define NATIVESCRIPT_VERSION "9.0.0-alpha.11"
55

66
#ifdef DEBUG
77
#define SIZEOF_OFF_T 8

NativeScript/runtime/DevFlags.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#pragma once
2+
3+
// Centralized development/runtime flags helpers usable across runtime sources.
4+
// These read from app package.json via Runtime::GetAppConfigValue and other
5+
// runtime configuration to determine behavior of dev features.
6+
7+
namespace tns {
8+
9+
// Returns true when verbose script/module loading logs should be emitted.
10+
// Controlled by package.json setting: "logScriptLoading": true|false
11+
bool IsScriptLoadingLogEnabled();
12+
13+
} // namespace tns

NativeScript/runtime/DevFlags.mm

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#import <Foundation/Foundation.h>
2+
3+
#include "DevFlags.h"
4+
#include "Runtime.h"
5+
#include "RuntimeConfig.h"
6+
7+
namespace tns {
8+
9+
bool IsScriptLoadingLogEnabled() {
10+
id value = Runtime::GetAppConfigValue("logScriptLoading");
11+
return value ? [value boolValue] : false;
12+
}
13+
14+
} // namespace tns

NativeScript/runtime/HMRSupport.h

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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

Comments
 (0)