@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.js
CHANGED
|
@@ -1058,13 +1058,12 @@ function wireElectron({ projectRoot, pkg, projectKey, ingestUrl }) {
|
|
|
1058
1058
|
"Could not copy gg-pixel browser IIFE bundle \u2014 install @kenkaiiii/gg-pixel and re-run."
|
|
1059
1059
|
);
|
|
1060
1060
|
}
|
|
1061
|
-
let
|
|
1061
|
+
let wiredAny = false;
|
|
1062
1062
|
for (const html of htmlFiles) {
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
}
|
|
1063
|
+
const r = patchRendererHtml(html, rendererInitPath, projectKey, ingestUrl);
|
|
1064
|
+
if (r === "patched" || r === "already") wiredAny = true;
|
|
1066
1065
|
}
|
|
1067
|
-
if (!
|
|
1066
|
+
if (!wiredAny) {
|
|
1068
1067
|
warnings.push(
|
|
1069
1068
|
`Found HTML files in ${rendererDir} but couldn't patch any \u2014 they may have unusual CSP or no <head>.`
|
|
1070
1069
|
);
|
|
@@ -1183,6 +1182,7 @@ function copyIifeBundle(projectRoot, dest) {
|
|
|
1183
1182
|
}
|
|
1184
1183
|
return false;
|
|
1185
1184
|
}
|
|
1185
|
+
var PIXEL_HTML_MARKER = "<!-- gg-pixel: auto-wired by ggcoder pixel install -->";
|
|
1186
1186
|
function patchRendererHtml(htmlPath, iifePath, projectKey, ingestUrl) {
|
|
1187
1187
|
let content;
|
|
1188
1188
|
try {
|
|
@@ -1190,7 +1190,20 @@ function patchRendererHtml(htmlPath, iifePath, projectKey, ingestUrl) {
|
|
|
1190
1190
|
} catch {
|
|
1191
1191
|
return "not-applicable";
|
|
1192
1192
|
}
|
|
1193
|
-
|
|
1193
|
+
const original = content;
|
|
1194
|
+
const markerIdx = content.indexOf(PIXEL_HTML_MARKER);
|
|
1195
|
+
if (markerIdx !== -1) {
|
|
1196
|
+
const firstScriptEnd = content.indexOf("</script>", markerIdx);
|
|
1197
|
+
const secondScriptEnd = firstScriptEnd !== -1 ? content.indexOf("</script>", firstScriptEnd + "</script>".length) : -1;
|
|
1198
|
+
if (secondScriptEnd !== -1) {
|
|
1199
|
+
let stripEnd = secondScriptEnd + "</script>".length;
|
|
1200
|
+
while (stripEnd < content.length && /\s/.test(content[stripEnd])) stripEnd++;
|
|
1201
|
+
let stripStart = markerIdx;
|
|
1202
|
+
while (stripStart > 0 && /[ \t]/.test(content[stripStart - 1])) stripStart--;
|
|
1203
|
+
if (stripStart > 0 && content[stripStart - 1] === "\n") stripStart--;
|
|
1204
|
+
content = content.slice(0, stripStart) + content.slice(stripEnd);
|
|
1205
|
+
}
|
|
1206
|
+
}
|
|
1194
1207
|
const ingestOrigin = new URL(ingestUrl).origin;
|
|
1195
1208
|
content = content.replace(
|
|
1196
1209
|
/(<meta[^>]+http-equiv=["']?content-security-policy["']?[^>]*content=)("([^"]+)"|'([^']+)')/i,
|
|
@@ -1210,7 +1223,7 @@ function patchRendererHtml(htmlPath, iifePath, projectKey, ingestUrl) {
|
|
|
1210
1223
|
);
|
|
1211
1224
|
const relScript = relative(dirname2(htmlPath), iifePath).split(sep).join("/");
|
|
1212
1225
|
const inject = `
|
|
1213
|
-
|
|
1226
|
+
${PIXEL_HTML_MARKER}
|
|
1214
1227
|
<script src="${relScript}"></script>
|
|
1215
1228
|
<script>
|
|
1216
1229
|
if (window.GGPixel) GGPixel.initPixel({ projectKey: ${JSON.stringify(projectKey)}, ingestUrl: ${JSON.stringify(ingestUrl)} });
|
|
@@ -1223,6 +1236,7 @@ function patchRendererHtml(htmlPath, iifePath, projectKey, ingestUrl) {
|
|
|
1223
1236
|
} else {
|
|
1224
1237
|
return "not-applicable";
|
|
1225
1238
|
}
|
|
1239
|
+
if (content === original) return "already";
|
|
1226
1240
|
writeFileSync(htmlPath, content, "utf8");
|
|
1227
1241
|
return "patched";
|
|
1228
1242
|
}
|