@kenkaiiii/gg-pixel 4.3.87 → 4.3.88
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.
- package/dist/cli.js +21 -7
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +21 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +21 -7
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1092,13 +1092,12 @@ function wireElectron({ projectRoot, pkg, projectKey, ingestUrl }) {
|
|
|
1092
1092
|
"Could not copy gg-pixel browser IIFE bundle \u2014 install @kenkaiiii/gg-pixel and re-run."
|
|
1093
1093
|
);
|
|
1094
1094
|
}
|
|
1095
|
-
let
|
|
1095
|
+
let wiredAny = false;
|
|
1096
1096
|
for (const html of htmlFiles) {
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
}
|
|
1097
|
+
const r = patchRendererHtml(html, rendererInitPath, projectKey, ingestUrl);
|
|
1098
|
+
if (r === "patched" || r === "already") wiredAny = true;
|
|
1100
1099
|
}
|
|
1101
|
-
if (!
|
|
1100
|
+
if (!wiredAny) {
|
|
1102
1101
|
warnings.push(
|
|
1103
1102
|
`Found HTML files in ${rendererDir} but couldn't patch any \u2014 they may have unusual CSP or no <head>.`
|
|
1104
1103
|
);
|
|
@@ -1217,6 +1216,7 @@ function copyIifeBundle(projectRoot, dest) {
|
|
|
1217
1216
|
}
|
|
1218
1217
|
return false;
|
|
1219
1218
|
}
|
|
1219
|
+
var PIXEL_HTML_MARKER = "<!-- gg-pixel: auto-wired by ggcoder pixel install -->";
|
|
1220
1220
|
function patchRendererHtml(htmlPath, iifePath, projectKey, ingestUrl) {
|
|
1221
1221
|
let content;
|
|
1222
1222
|
try {
|
|
@@ -1224,7 +1224,20 @@ function patchRendererHtml(htmlPath, iifePath, projectKey, ingestUrl) {
|
|
|
1224
1224
|
} catch {
|
|
1225
1225
|
return "not-applicable";
|
|
1226
1226
|
}
|
|
1227
|
-
|
|
1227
|
+
const original = content;
|
|
1228
|
+
const markerIdx = content.indexOf(PIXEL_HTML_MARKER);
|
|
1229
|
+
if (markerIdx !== -1) {
|
|
1230
|
+
const firstScriptEnd = content.indexOf("</script>", markerIdx);
|
|
1231
|
+
const secondScriptEnd = firstScriptEnd !== -1 ? content.indexOf("</script>", firstScriptEnd + "</script>".length) : -1;
|
|
1232
|
+
if (secondScriptEnd !== -1) {
|
|
1233
|
+
let stripEnd = secondScriptEnd + "</script>".length;
|
|
1234
|
+
while (stripEnd < content.length && /\s/.test(content[stripEnd])) stripEnd++;
|
|
1235
|
+
let stripStart = markerIdx;
|
|
1236
|
+
while (stripStart > 0 && /[ \t]/.test(content[stripStart - 1])) stripStart--;
|
|
1237
|
+
if (stripStart > 0 && content[stripStart - 1] === "\n") stripStart--;
|
|
1238
|
+
content = content.slice(0, stripStart) + content.slice(stripEnd);
|
|
1239
|
+
}
|
|
1240
|
+
}
|
|
1228
1241
|
const ingestOrigin = new URL(ingestUrl).origin;
|
|
1229
1242
|
content = content.replace(
|
|
1230
1243
|
/(<meta[^>]+http-equiv=["']?content-security-policy["']?[^>]*content=)("([^"]+)"|'([^']+)')/i,
|
|
@@ -1244,7 +1257,7 @@ function patchRendererHtml(htmlPath, iifePath, projectKey, ingestUrl) {
|
|
|
1244
1257
|
);
|
|
1245
1258
|
const relScript = (0, import_node_path2.relative)((0, import_node_path2.dirname)(htmlPath), iifePath).split(import_node_path2.sep).join("/");
|
|
1246
1259
|
const inject = `
|
|
1247
|
-
|
|
1260
|
+
${PIXEL_HTML_MARKER}
|
|
1248
1261
|
<script src="${relScript}"></script>
|
|
1249
1262
|
<script>
|
|
1250
1263
|
if (window.GGPixel) GGPixel.initPixel({ projectKey: ${JSON.stringify(projectKey)}, ingestUrl: ${JSON.stringify(ingestUrl)} });
|
|
@@ -1257,6 +1270,7 @@ function patchRendererHtml(htmlPath, iifePath, projectKey, ingestUrl) {
|
|
|
1257
1270
|
} else {
|
|
1258
1271
|
return "not-applicable";
|
|
1259
1272
|
}
|
|
1273
|
+
if (content === original) return "already";
|
|
1260
1274
|
(0, import_node_fs3.writeFileSync)(htmlPath, content, "utf8");
|
|
1261
1275
|
return "patched";
|
|
1262
1276
|
}
|