@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.js
CHANGED
|
@@ -501,10 +501,13 @@ function findMappingByPath(projectsJsonPath, projectRoot) {
|
|
|
501
501
|
} catch {
|
|
502
502
|
return null;
|
|
503
503
|
}
|
|
504
|
+
let fallback = null;
|
|
504
505
|
for (const [id, entry] of Object.entries(map)) {
|
|
505
|
-
if (entry.path
|
|
506
|
+
if (entry.path !== projectRoot) continue;
|
|
507
|
+
if (entry.secret) return { id, ...entry };
|
|
508
|
+
if (!fallback) fallback = { id, ...entry };
|
|
506
509
|
}
|
|
507
|
-
return
|
|
510
|
+
return fallback;
|
|
508
511
|
}
|
|
509
512
|
function readEnvKey(envPath, key) {
|
|
510
513
|
if (!existsSync2(envPath)) return null;
|
|
@@ -787,8 +790,9 @@ function wireNextjs({ projectRoot, projectKey, ingestUrl }) {
|
|
|
787
790
|
}
|
|
788
791
|
function writeNextInstrumentation(path, ingestUrl, projectKey) {
|
|
789
792
|
const existing = existsSync2(path) ? readFileSync2(path, "utf8") : "";
|
|
793
|
+
const cleaned = stripLegacyPixelContent(existing);
|
|
790
794
|
const block = nextInstrumentationBlock(ingestUrl, projectKey);
|
|
791
|
-
const next = upsertPixelBlock(
|
|
795
|
+
const next = upsertPixelBlock(cleaned, block);
|
|
792
796
|
if (next !== existing) writeFileSync(path, next, "utf8");
|
|
793
797
|
}
|
|
794
798
|
function nextInstrumentationBlock(ingestUrl, projectKey) {
|
|
@@ -1318,9 +1322,64 @@ function upsertPixelBlock(existing, block) {
|
|
|
1318
1322
|
}
|
|
1319
1323
|
function upsertPixelBlockInFile(filePath, block) {
|
|
1320
1324
|
const existing = existsSync2(filePath) ? readFileSync2(filePath, "utf8") : "";
|
|
1321
|
-
const
|
|
1325
|
+
const cleaned = stripLegacyPixelContent(existing);
|
|
1326
|
+
const next = upsertPixelBlock(cleaned, block);
|
|
1322
1327
|
if (next !== existing) writeFileSync(filePath, next, "utf8");
|
|
1323
1328
|
}
|
|
1329
|
+
function stripLegacyPixelContent(content) {
|
|
1330
|
+
if (!content.includes("@kenkaiiii/gg-pixel")) return content;
|
|
1331
|
+
const beginIdx = content.indexOf(PIXEL_MARK_BEGIN);
|
|
1332
|
+
const endIdx = beginIdx === -1 ? -1 : content.indexOf(PIXEL_MARK_END, beginIdx);
|
|
1333
|
+
const insideMarkers = (start, end) => beginIdx !== -1 && endIdx !== -1 && start >= beginIdx && end <= endIdx + PIXEL_MARK_END.length;
|
|
1334
|
+
const ranges = [];
|
|
1335
|
+
const registerRe = /(?:^|\n)((?:[ \t]*\/\/[^\n]*\n)*)[ \t]*export\s+async\s+function\s+register\s*\(\s*\)\s*\{/g;
|
|
1336
|
+
let m;
|
|
1337
|
+
while ((m = registerRe.exec(content)) !== null) {
|
|
1338
|
+
const blockStart = m.index + (content[m.index] === "\n" ? 1 : 0);
|
|
1339
|
+
const openBraceIdx = m.index + m[0].length - 1;
|
|
1340
|
+
let depth = 1;
|
|
1341
|
+
let i = openBraceIdx + 1;
|
|
1342
|
+
while (i < content.length && depth > 0) {
|
|
1343
|
+
const ch = content[i];
|
|
1344
|
+
if (ch === "{") depth++;
|
|
1345
|
+
else if (ch === "}") depth--;
|
|
1346
|
+
i++;
|
|
1347
|
+
}
|
|
1348
|
+
if (depth !== 0) continue;
|
|
1349
|
+
const blockEnd = i;
|
|
1350
|
+
const blockText = content.slice(blockStart, blockEnd);
|
|
1351
|
+
if (!blockText.includes("@kenkaiiii/gg-pixel")) continue;
|
|
1352
|
+
if (insideMarkers(blockStart, blockEnd)) continue;
|
|
1353
|
+
const trailingNL = content[blockEnd] === "\n" ? 1 : 0;
|
|
1354
|
+
ranges.push({ start: blockStart, end: blockEnd + trailingNL });
|
|
1355
|
+
}
|
|
1356
|
+
const importRe = /(?:^|\n)((?:[ \t]*\/\/[^\n]*\n)*)[ \t]*import\s*\{\s*initPixel[^}]*\}\s*from\s*"@kenkaiiii\/gg-pixel(?:\/[\w-]+)?"\s*;?\s*\n/g;
|
|
1357
|
+
while ((m = importRe.exec(content)) !== null) {
|
|
1358
|
+
const blockStart = m.index + (content[m.index] === "\n" ? 1 : 0);
|
|
1359
|
+
const callIdx = content.indexOf("initPixel(", importRe.lastIndex);
|
|
1360
|
+
if (callIdx === -1 || callIdx - importRe.lastIndex > 2048) continue;
|
|
1361
|
+
const openParen = content.indexOf("(", callIdx);
|
|
1362
|
+
let depth = 1;
|
|
1363
|
+
let i = openParen + 1;
|
|
1364
|
+
while (i < content.length && depth > 0) {
|
|
1365
|
+
const ch = content[i];
|
|
1366
|
+
if (ch === "(" || ch === "{") depth++;
|
|
1367
|
+
else if (ch === ")" || ch === "}") depth--;
|
|
1368
|
+
i++;
|
|
1369
|
+
}
|
|
1370
|
+
if (depth !== 0) continue;
|
|
1371
|
+
while (i < content.length && (content[i] === ";" || content[i] === " ")) i++;
|
|
1372
|
+
const trailingNL = content[i] === "\n" ? 1 : 0;
|
|
1373
|
+
const blockEnd = i + trailingNL;
|
|
1374
|
+
if (insideMarkers(blockStart, blockEnd)) continue;
|
|
1375
|
+
ranges.push({ start: blockStart, end: blockEnd });
|
|
1376
|
+
}
|
|
1377
|
+
if (ranges.length === 0) return content;
|
|
1378
|
+
ranges.sort((a, b) => b.start - a.start);
|
|
1379
|
+
let out = content;
|
|
1380
|
+
for (const r of ranges) out = out.slice(0, r.start) + out.slice(r.end);
|
|
1381
|
+
return out.replace(/\n{3,}/g, "\n\n");
|
|
1382
|
+
}
|
|
1324
1383
|
function injectImport(entryPath, initFilePath) {
|
|
1325
1384
|
let content;
|
|
1326
1385
|
try {
|