@noego/forge 0.0.25 → 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();
@@ -1111,20 +1126,20 @@ ${e.stack}</pre>
1111
1126
  const clientComponentDir = this.isProd ? deriveClientBase(this.componentDir || "") : this.componentDir || "/assets";
1112
1127
  const head_routing = `
1113
1128
  <script type='text/javascript'>
1114
- window.__ROUTING__ = ${JSON.stringify(this.clientRoutes)}
1129
+ window.__ROUTING__ = ${stringify(this.clientRoutes)}
1115
1130
  <\/script>
1116
1131
 
1117
1132
  <script type='text/javascript'>
1118
- window.__MANIFEST__ = ${JSON.stringify(manifest)}
1133
+ window.__MANIFEST__ = ${stringify(manifest)}
1119
1134
  console.log('[MANIFEST INJECTED]', window.__MANIFEST__);
1120
1135
  <\/script>
1121
1136
 
1122
1137
  <script type='text/javascript'>
1123
- window.__INITIAL_DATA__ = ${JSON.stringify(server_data || {}).trim()}
1138
+ window.__INITIAL_DATA__ = ${stringify(server_data || {})}
1124
1139
  <\/script>
1125
1140
 
1126
1141
  <script type='text/javascript'>
1127
- window.__COMPONENT_DIR__ = ${JSON.stringify(clientComponentDir)}
1142
+ window.__COMPONENT_DIR__ = ${stringify(clientComponentDir)}
1128
1143
  <\/script>
1129
1144
  `;
1130
1145
  console.log("[SSR DEBUG] About to render HTML with APP length:", (body_render == null ? void 0 : body_render.length) || 0);