@kenkaiiii/gg-pixel 4.3.86 → 4.3.87
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 +63 -4
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +63 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +63 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -535,10 +535,13 @@ function findMappingByPath(projectsJsonPath, projectRoot) {
|
|
|
535
535
|
} catch {
|
|
536
536
|
return null;
|
|
537
537
|
}
|
|
538
|
+
let fallback = null;
|
|
538
539
|
for (const [id, entry] of Object.entries(map)) {
|
|
539
|
-
if (entry.path
|
|
540
|
+
if (entry.path !== projectRoot) continue;
|
|
541
|
+
if (entry.secret) return { id, ...entry };
|
|
542
|
+
if (!fallback) fallback = { id, ...entry };
|
|
540
543
|
}
|
|
541
|
-
return
|
|
544
|
+
return fallback;
|
|
542
545
|
}
|
|
543
546
|
function readEnvKey(envPath, key) {
|
|
544
547
|
if (!(0, import_node_fs3.existsSync)(envPath)) return null;
|
|
@@ -821,8 +824,9 @@ function wireNextjs({ projectRoot, projectKey, ingestUrl }) {
|
|
|
821
824
|
}
|
|
822
825
|
function writeNextInstrumentation(path, ingestUrl, projectKey) {
|
|
823
826
|
const existing = (0, import_node_fs3.existsSync)(path) ? (0, import_node_fs3.readFileSync)(path, "utf8") : "";
|
|
827
|
+
const cleaned = stripLegacyPixelContent(existing);
|
|
824
828
|
const block = nextInstrumentationBlock(ingestUrl, projectKey);
|
|
825
|
-
const next = upsertPixelBlock(
|
|
829
|
+
const next = upsertPixelBlock(cleaned, block);
|
|
826
830
|
if (next !== existing) (0, import_node_fs3.writeFileSync)(path, next, "utf8");
|
|
827
831
|
}
|
|
828
832
|
function nextInstrumentationBlock(ingestUrl, projectKey) {
|
|
@@ -1352,9 +1356,64 @@ function upsertPixelBlock(existing, block) {
|
|
|
1352
1356
|
}
|
|
1353
1357
|
function upsertPixelBlockInFile(filePath, block) {
|
|
1354
1358
|
const existing = (0, import_node_fs3.existsSync)(filePath) ? (0, import_node_fs3.readFileSync)(filePath, "utf8") : "";
|
|
1355
|
-
const
|
|
1359
|
+
const cleaned = stripLegacyPixelContent(existing);
|
|
1360
|
+
const next = upsertPixelBlock(cleaned, block);
|
|
1356
1361
|
if (next !== existing) (0, import_node_fs3.writeFileSync)(filePath, next, "utf8");
|
|
1357
1362
|
}
|
|
1363
|
+
function stripLegacyPixelContent(content) {
|
|
1364
|
+
if (!content.includes("@kenkaiiii/gg-pixel")) return content;
|
|
1365
|
+
const beginIdx = content.indexOf(PIXEL_MARK_BEGIN);
|
|
1366
|
+
const endIdx = beginIdx === -1 ? -1 : content.indexOf(PIXEL_MARK_END, beginIdx);
|
|
1367
|
+
const insideMarkers = (start, end) => beginIdx !== -1 && endIdx !== -1 && start >= beginIdx && end <= endIdx + PIXEL_MARK_END.length;
|
|
1368
|
+
const ranges = [];
|
|
1369
|
+
const registerRe = /(?:^|\n)((?:[ \t]*\/\/[^\n]*\n)*)[ \t]*export\s+async\s+function\s+register\s*\(\s*\)\s*\{/g;
|
|
1370
|
+
let m;
|
|
1371
|
+
while ((m = registerRe.exec(content)) !== null) {
|
|
1372
|
+
const blockStart = m.index + (content[m.index] === "\n" ? 1 : 0);
|
|
1373
|
+
const openBraceIdx = m.index + m[0].length - 1;
|
|
1374
|
+
let depth = 1;
|
|
1375
|
+
let i = openBraceIdx + 1;
|
|
1376
|
+
while (i < content.length && depth > 0) {
|
|
1377
|
+
const ch = content[i];
|
|
1378
|
+
if (ch === "{") depth++;
|
|
1379
|
+
else if (ch === "}") depth--;
|
|
1380
|
+
i++;
|
|
1381
|
+
}
|
|
1382
|
+
if (depth !== 0) continue;
|
|
1383
|
+
const blockEnd = i;
|
|
1384
|
+
const blockText = content.slice(blockStart, blockEnd);
|
|
1385
|
+
if (!blockText.includes("@kenkaiiii/gg-pixel")) continue;
|
|
1386
|
+
if (insideMarkers(blockStart, blockEnd)) continue;
|
|
1387
|
+
const trailingNL = content[blockEnd] === "\n" ? 1 : 0;
|
|
1388
|
+
ranges.push({ start: blockStart, end: blockEnd + trailingNL });
|
|
1389
|
+
}
|
|
1390
|
+
const importRe = /(?:^|\n)((?:[ \t]*\/\/[^\n]*\n)*)[ \t]*import\s*\{\s*initPixel[^}]*\}\s*from\s*"@kenkaiiii\/gg-pixel(?:\/[\w-]+)?"\s*;?\s*\n/g;
|
|
1391
|
+
while ((m = importRe.exec(content)) !== null) {
|
|
1392
|
+
const blockStart = m.index + (content[m.index] === "\n" ? 1 : 0);
|
|
1393
|
+
const callIdx = content.indexOf("initPixel(", importRe.lastIndex);
|
|
1394
|
+
if (callIdx === -1 || callIdx - importRe.lastIndex > 2048) continue;
|
|
1395
|
+
const openParen = content.indexOf("(", callIdx);
|
|
1396
|
+
let depth = 1;
|
|
1397
|
+
let i = openParen + 1;
|
|
1398
|
+
while (i < content.length && depth > 0) {
|
|
1399
|
+
const ch = content[i];
|
|
1400
|
+
if (ch === "(" || ch === "{") depth++;
|
|
1401
|
+
else if (ch === ")" || ch === "}") depth--;
|
|
1402
|
+
i++;
|
|
1403
|
+
}
|
|
1404
|
+
if (depth !== 0) continue;
|
|
1405
|
+
while (i < content.length && (content[i] === ";" || content[i] === " ")) i++;
|
|
1406
|
+
const trailingNL = content[i] === "\n" ? 1 : 0;
|
|
1407
|
+
const blockEnd = i + trailingNL;
|
|
1408
|
+
if (insideMarkers(blockStart, blockEnd)) continue;
|
|
1409
|
+
ranges.push({ start: blockStart, end: blockEnd });
|
|
1410
|
+
}
|
|
1411
|
+
if (ranges.length === 0) return content;
|
|
1412
|
+
ranges.sort((a, b) => b.start - a.start);
|
|
1413
|
+
let out = content;
|
|
1414
|
+
for (const r of ranges) out = out.slice(0, r.start) + out.slice(r.end);
|
|
1415
|
+
return out.replace(/\n{3,}/g, "\n\n");
|
|
1416
|
+
}
|
|
1358
1417
|
function injectImport(entryPath, initFilePath) {
|
|
1359
1418
|
let content;
|
|
1360
1419
|
try {
|