@kenkaiiii/gg-pixel 4.3.85 → 4.3.86
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 +35 -33
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +35 -33
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +35 -33
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -787,11 +787,11 @@ function wireNextjs({ projectRoot, projectKey, ingestUrl }) {
|
|
|
787
787
|
}
|
|
788
788
|
function writeNextInstrumentation(path, ingestUrl, projectKey) {
|
|
789
789
|
const existing = existsSync2(path) ? readFileSync2(path, "utf8") : "";
|
|
790
|
-
|
|
791
|
-
const
|
|
792
|
-
writeFileSync(path,
|
|
790
|
+
const block = nextInstrumentationBlock(ingestUrl, projectKey);
|
|
791
|
+
const next = upsertPixelBlock(existing, block);
|
|
792
|
+
if (next !== existing) writeFileSync(path, next, "utf8");
|
|
793
793
|
}
|
|
794
|
-
function
|
|
794
|
+
function nextInstrumentationBlock(ingestUrl, projectKey) {
|
|
795
795
|
const fallback = projectKey ? ` ?? ${JSON.stringify(projectKey)}` : "";
|
|
796
796
|
return `// Next.js auto-loads this file on server start. Pixel hooks the
|
|
797
797
|
// uncaughtExceptionMonitor + unhandledRejection events for API routes,
|
|
@@ -804,20 +804,7 @@ export async function register() {
|
|
|
804
804
|
sink: { kind: "http", ingestUrl: ${JSON.stringify(`${ingestUrl}/ingest`)} },
|
|
805
805
|
});
|
|
806
806
|
}
|
|
807
|
-
}
|
|
808
|
-
`;
|
|
809
|
-
}
|
|
810
|
-
function nextInstrumentationAppend(ingestUrl, projectKey) {
|
|
811
|
-
const fallback = projectKey ? ` ?? ${JSON.stringify(projectKey)}` : "";
|
|
812
|
-
return `// gg-pixel: server-side error tracking
|
|
813
|
-
import { initPixel } from "@kenkaiiii/gg-pixel";
|
|
814
|
-
if (typeof process !== "undefined" && process.env.NEXT_RUNTIME === "nodejs") {
|
|
815
|
-
initPixel({
|
|
816
|
-
projectKey: process.env.GG_PIXEL_KEY${fallback},
|
|
817
|
-
sink: { kind: "http", ingestUrl: ${JSON.stringify(`${ingestUrl}/ingest`)} },
|
|
818
|
-
});
|
|
819
|
-
}
|
|
820
|
-
`;
|
|
807
|
+
}`;
|
|
821
808
|
}
|
|
822
809
|
function findNextLayout(projectRoot) {
|
|
823
810
|
const candidates = [
|
|
@@ -950,25 +937,21 @@ function wireSveltekit({ projectRoot, projectKey, ingestUrl }) {
|
|
|
950
937
|
const serverPath = join2(projectRoot, "src/hooks.server.ts");
|
|
951
938
|
const clientPath = join2(projectRoot, "src/hooks.client.ts");
|
|
952
939
|
if (!existsSync2(dirname2(serverPath))) mkdirSync2(dirname2(serverPath), { recursive: true });
|
|
953
|
-
|
|
940
|
+
upsertPixelBlockInFile(
|
|
954
941
|
serverPath,
|
|
955
942
|
`import { initPixel } from "@kenkaiiii/gg-pixel";
|
|
956
943
|
initPixel({
|
|
957
944
|
projectKey: process.env.GG_PIXEL_KEY ?? ${JSON.stringify(projectKey)},
|
|
958
945
|
sink: { kind: "http", ingestUrl: ${JSON.stringify(`${ingestUrl}/ingest`)} },
|
|
959
|
-
})
|
|
960
|
-
`,
|
|
961
|
-
"@kenkaiiii/gg-pixel"
|
|
946
|
+
});`
|
|
962
947
|
);
|
|
963
|
-
|
|
948
|
+
upsertPixelBlockInFile(
|
|
964
949
|
clientPath,
|
|
965
950
|
`import { initPixel } from "@kenkaiiii/gg-pixel/browser";
|
|
966
951
|
initPixel({
|
|
967
952
|
projectKey: ${JSON.stringify(projectKey)},
|
|
968
953
|
ingestUrl: ${JSON.stringify(ingestUrl)},
|
|
969
|
-
})
|
|
970
|
-
`,
|
|
971
|
-
"@kenkaiiii/gg-pixel/browser"
|
|
954
|
+
});`
|
|
972
955
|
);
|
|
973
956
|
return {
|
|
974
957
|
primaryInitPath: clientPath,
|
|
@@ -1310,14 +1293,33 @@ function pickPath(root, candidates) {
|
|
|
1310
1293
|
}
|
|
1311
1294
|
return null;
|
|
1312
1295
|
}
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1296
|
+
var PIXEL_MARK_BEGIN = "// >>> gg-pixel auto-generated \u2014 do not edit between these markers <<<";
|
|
1297
|
+
var PIXEL_MARK_END = "// >>> /gg-pixel <<<";
|
|
1298
|
+
function wrapPixelBlock(content) {
|
|
1299
|
+
return `${PIXEL_MARK_BEGIN}
|
|
1300
|
+
${content.replace(/\s+$/, "")}
|
|
1301
|
+
${PIXEL_MARK_END}
|
|
1302
|
+
`;
|
|
1303
|
+
}
|
|
1304
|
+
function upsertPixelBlock(existing, block) {
|
|
1305
|
+
const wrapped = wrapPixelBlock(block);
|
|
1306
|
+
const beginIdx = existing.indexOf(PIXEL_MARK_BEGIN);
|
|
1307
|
+
if (beginIdx !== -1) {
|
|
1308
|
+
const endIdx = existing.indexOf(PIXEL_MARK_END, beginIdx);
|
|
1309
|
+
if (endIdx !== -1) {
|
|
1310
|
+
const after = endIdx + PIXEL_MARK_END.length;
|
|
1311
|
+
const trailNL = existing[after] === "\n" ? 1 : 0;
|
|
1312
|
+
return existing.slice(0, beginIdx) + wrapped + existing.slice(after + trailNL);
|
|
1313
|
+
}
|
|
1319
1314
|
}
|
|
1320
|
-
|
|
1315
|
+
if (existing.length === 0) return wrapped;
|
|
1316
|
+
const sep2 = existing.endsWith("\n") ? "" : "\n";
|
|
1317
|
+
return existing + sep2 + "\n" + wrapped;
|
|
1318
|
+
}
|
|
1319
|
+
function upsertPixelBlockInFile(filePath, block) {
|
|
1320
|
+
const existing = existsSync2(filePath) ? readFileSync2(filePath, "utf8") : "";
|
|
1321
|
+
const next = upsertPixelBlock(existing, block);
|
|
1322
|
+
if (next !== existing) writeFileSync(filePath, next, "utf8");
|
|
1321
1323
|
}
|
|
1322
1324
|
function injectImport(entryPath, initFilePath) {
|
|
1323
1325
|
let content;
|