@noego/forge 0.0.24 → 0.0.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,6 +8,7 @@ import deepmerge from "deepmerge";
8
8
  import { pathToFileURL } from "url";
9
9
  import Handlebars from "handlebars";
10
10
  import fs$1 from "fs/promises";
11
+ import { stringify } from "devalue";
11
12
  import yaml from "js-yaml";
12
13
  import "clone-deep";
13
14
  import join from "url-join";
@@ -149,22 +150,29 @@ class BaseHTMLRender {
149
150
  let html = template(data);
150
151
  const configJson = process.env.NOEGO_CONFIGURATION;
151
152
  if (configJson) {
152
- const configScript = `<script>window.__CONFIGURATION__ = ${configJson};<\/script>`;
153
- if (html.includes("</head>")) {
154
- html = html.replace("</head>", `${configScript}
153
+ try {
154
+ const configData = JSON.parse(configJson);
155
+ const safeConfigJson = stringify(configData);
156
+ const configScript = `<script>window.__CONFIGURATION__ = ${safeConfigJson};<\/script>`;
157
+ if (html.includes("</head>")) {
158
+ html = html.replace("</head>", `${configScript}
155
159
  </head>`);
156
- } else if (html.includes("<body")) {
157
- html = html.replace(/(<body[^>]*>)/, `$1
160
+ } else if (html.includes("<body")) {
161
+ html = html.replace(/(<body[^>]*>)/, `$1
158
162
  ${configScript}`);
159
- } else {
160
- html = configScript + "\n" + html;
163
+ } else {
164
+ html = configScript + "\n" + html;
165
+ }
166
+ } catch (e) {
167
+ console.error("Failed to parse NOEGO_CONFIGURATION:", e);
161
168
  }
162
169
  }
163
170
  html = html.replace(
164
171
  /<script\s+type=["']module["']\s+src=["']([^"']+)["'][^>]*><\/script>/gi,
165
- (match, src) => {
172
+ (_match, src) => {
173
+ const safeSrc = src.replace(/'/g, "\\'");
166
174
  return `<script type="module">
167
- import initApp from '${src}';
175
+ import initApp from '${safeSrc}';
168
176
  function initializeApp() {
169
177
  if (typeof initApp === 'function' && typeof window !== 'undefined' && window.__CONFIGURATION__) {
170
178
  const result = initApp();
@@ -202,22 +210,29 @@ class LiveHTMLRender {
202
210
  let html = template(data);
203
211
  const configJson = process.env.NOEGO_CONFIGURATION;
204
212
  if (configJson) {
205
- const configScript = `<script>window.__CONFIGURATION__ = ${configJson};<\/script>`;
206
- if (html.includes("</head>")) {
207
- html = html.replace("</head>", `${configScript}
213
+ try {
214
+ const configData = JSON.parse(configJson);
215
+ const safeConfigJson = stringify(configData);
216
+ const configScript = `<script>window.__CONFIGURATION__ = ${safeConfigJson};<\/script>`;
217
+ if (html.includes("</head>")) {
218
+ html = html.replace("</head>", `${configScript}
208
219
  </head>`);
209
- } else if (html.includes("<body")) {
210
- html = html.replace(/(<body[^>]*>)/, `$1
220
+ } else if (html.includes("<body")) {
221
+ html = html.replace(/(<body[^>]*>)/, `$1
211
222
  ${configScript}`);
212
- } else {
213
- html = configScript + "\n" + html;
223
+ } else {
224
+ html = configScript + "\n" + html;
225
+ }
226
+ } catch (e) {
227
+ console.error("Failed to parse NOEGO_CONFIGURATION:", e);
214
228
  }
215
229
  }
216
230
  html = html.replace(
217
231
  /<script\s+type=["']module["']\s+src=["']([^"']+)["'][^>]*><\/script>/gi,
218
- (match, src) => {
232
+ (_match, src) => {
233
+ const safeSrc = src.replace(/'/g, "\\'");
219
234
  return `<script type="module">
220
- import initApp from '${src}';
235
+ import initApp from '${safeSrc}';
221
236
  function initializeApp() {
222
237
  if (typeof initApp === 'function' && typeof window !== 'undefined' && window.__CONFIGURATION__) {
223
238
  const result = initApp();
@@ -666,16 +681,21 @@ class ComponentManager {
666
681
  continue;
667
682
  }
668
683
  try {
684
+ console.log(`[ComponentManager] Trying loader path: ${loaderFilePath}`);
669
685
  const module = await import(pathToFileURL(loaderFilePath).href);
670
686
  const loader = module == null ? void 0 : module.default;
687
+ console.log(`[ComponentManager] Imported loader module: default=${typeof loader}`);
671
688
  if (typeof loader === "function") {
689
+ console.log(`[ComponentManager] Loaded loader function from: ${loaderFilePath}`);
672
690
  return loader;
673
691
  }
674
692
  } catch (error) {
675
- if ((error == null ? void 0 : error.code) === "MODULE_NOT_FOUND" || (error == null ? void 0 : error.code) === "ERR_MODULE_NOT_FOUND") {
693
+ const code = (error == null ? void 0 : error.code) || (error == null ? void 0 : error.name) || "UNKNOWN_ERROR";
694
+ if (code === "MODULE_NOT_FOUND" || code === "ERR_MODULE_NOT_FOUND") {
695
+ console.warn(`[ComponentManager] Loader not found at ${loaderFilePath} (${ext}): ${(error == null ? void 0 : error.message) || code}`);
676
696
  continue;
677
697
  }
678
- console.error(`[ComponentManager] Failed to load loader for ${componentPath} (${ext}):`, error);
698
+ console.error(`[ComponentManager] Failed to load loader for ${componentPath} (${ext}) at ${loaderFilePath}:`, error);
679
699
  }
680
700
  }
681
701
  return null;
@@ -1083,23 +1103,43 @@ ${e.stack}</pre>
1083
1103
  });
1084
1104
  const body_render = renderedHtml;
1085
1105
  console.log("[SSR DEBUG] render result - body length:", (body_render == null ? void 0 : body_render.length) || 0);
1086
- const clientComponentDir = this.isProd ? "assets" : this.componentDir;
1106
+ const deriveClientBase = (dir) => {
1107
+ try {
1108
+ const norm = String(dir || "").replace(/\\/g, "/");
1109
+ const marker = "/ssr/";
1110
+ const idx = norm.indexOf(marker);
1111
+ if (idx >= 0) {
1112
+ const suffix = norm.slice(idx + marker.length).replace(/^\/+/, "");
1113
+ return suffix ? `/assets/${suffix}` : "/assets";
1114
+ }
1115
+ for (const hint of ["/components", "/pages"]) {
1116
+ const hIdx = norm.indexOf(hint);
1117
+ if (hIdx >= 0) {
1118
+ const suffix = norm.slice(hIdx + 1).replace(/^\/+/, "");
1119
+ return suffix ? `/assets/${suffix}` : "/assets";
1120
+ }
1121
+ }
1122
+ } catch {
1123
+ }
1124
+ return "/assets";
1125
+ };
1126
+ const clientComponentDir = this.isProd ? deriveClientBase(this.componentDir || "") : this.componentDir || "/assets";
1087
1127
  const head_routing = `
1088
1128
  <script type='text/javascript'>
1089
- window.__ROUTING__ = ${JSON.stringify(this.clientRoutes)}
1129
+ window.__ROUTING__ = ${stringify(this.clientRoutes)}
1090
1130
  <\/script>
1091
1131
 
1092
1132
  <script type='text/javascript'>
1093
- window.__MANIFEST__ = ${JSON.stringify(manifest)}
1133
+ window.__MANIFEST__ = ${stringify(manifest)}
1094
1134
  console.log('[MANIFEST INJECTED]', window.__MANIFEST__);
1095
1135
  <\/script>
1096
1136
 
1097
1137
  <script type='text/javascript'>
1098
- window.__INITIAL_DATA__ = ${JSON.stringify(server_data || {}).trim()}
1138
+ window.__INITIAL_DATA__ = ${stringify(server_data || {})}
1099
1139
  <\/script>
1100
1140
 
1101
1141
  <script type='text/javascript'>
1102
- window.__COMPONENT_DIR__ = ${JSON.stringify(clientComponentDir)}
1142
+ window.__COMPONENT_DIR__ = ${stringify(clientComponentDir)}
1103
1143
  <\/script>
1104
1144
  `;
1105
1145
  console.log("[SSR DEBUG] About to render HTML with APP length:", (body_render == null ? void 0 : body_render.length) || 0);
@@ -1224,8 +1264,6 @@ async function createServer(app, options) {
1224
1264
  let componentLoader;
1225
1265
  let vite;
1226
1266
  console.log(`Serving components from ${COMPONENT_DIR}`);
1227
- const rendererFullPath = typeof full_options.renderer === "string" && full_options.renderer !== "default" ? ensureFullPath(root, full_options.renderer) : ensureFullPath(root, "index.html");
1228
- path.dirname(rendererFullPath);
1229
1267
  const resolveAssetRoot = (entry) => {
1230
1268
  if (typeof entry === "function") {
1231
1269
  return entry;