@kenkaiiii/gg-pixel 4.3.80 → 4.3.81
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/browser.iife.global.js +4 -0
- package/dist/browser.iife.global.js.map +1 -0
- package/dist/cli.js +168 -37
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +168 -37
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +168 -37
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1076,6 +1076,7 @@ function wireRemix({ projectRoot, projectKey, ingestUrl }) {
|
|
|
1076
1076
|
};
|
|
1077
1077
|
}
|
|
1078
1078
|
function wireElectron({ projectRoot, pkg, projectKey, ingestUrl }) {
|
|
1079
|
+
const warnings = [];
|
|
1079
1080
|
const isMainEsm = pkg.type === "module";
|
|
1080
1081
|
const mainInitPath = isMainEsm ? (0, import_node_path2.join)(projectRoot, "gg-pixel.main.mjs") : (0, import_node_path2.join)(projectRoot, "gg-pixel.main.cjs");
|
|
1081
1082
|
(0, import_node_fs3.writeFileSync)(
|
|
@@ -1083,50 +1084,62 @@ function wireElectron({ projectRoot, pkg, projectKey, ingestUrl }) {
|
|
|
1083
1084
|
isMainEsm ? renderInitFile(ingestUrl, projectKey) : renderInitFileCjs(ingestUrl, projectKey),
|
|
1084
1085
|
"utf8"
|
|
1085
1086
|
);
|
|
1086
|
-
const
|
|
1087
|
-
(0, import_node_fs3.writeFileSync)(rendererInitPath, renderBrowserInitFile(ingestUrl, projectKey), "utf8");
|
|
1088
|
-
const mainEntry = pkg.main ? (0, import_node_path2.join)(projectRoot, pkg.main) : pickPath(projectRoot, [
|
|
1089
|
-
"main.js",
|
|
1090
|
-
"main.ts",
|
|
1091
|
-
"src/main.js",
|
|
1092
|
-
"src/main.ts",
|
|
1093
|
-
"electron/main.js",
|
|
1094
|
-
"electron/main.ts"
|
|
1095
|
-
]);
|
|
1087
|
+
const mainEntry = resolveMainEntryFromPkg(projectRoot, pkg);
|
|
1096
1088
|
let mainWiring = { kind: "no_entry_found" };
|
|
1097
1089
|
if (mainEntry && (0, import_node_fs3.existsSync)(mainEntry)) {
|
|
1098
1090
|
mainWiring = injectImport(mainEntry, mainInitPath);
|
|
1099
1091
|
}
|
|
1100
|
-
const
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
"
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1092
|
+
const htmlFiles = findRendererHtmlFiles(projectRoot);
|
|
1093
|
+
let rendererInitPath;
|
|
1094
|
+
if (htmlFiles.length > 0) {
|
|
1095
|
+
const rendererDir = (0, import_node_path2.dirname)(htmlFiles[0]);
|
|
1096
|
+
rendererInitPath = (0, import_node_path2.join)(rendererDir, "gg-pixel.browser.iife.js");
|
|
1097
|
+
if (!copyIifeBundle(projectRoot, rendererInitPath)) {
|
|
1098
|
+
warnings.push(
|
|
1099
|
+
"Could not copy gg-pixel browser IIFE bundle \u2014 install @kenkaiiii/gg-pixel and re-run."
|
|
1100
|
+
);
|
|
1101
|
+
}
|
|
1102
|
+
let patchedAny = false;
|
|
1103
|
+
for (const html of htmlFiles) {
|
|
1104
|
+
if (patchRendererHtml(html, rendererInitPath, projectKey, ingestUrl) === "patched") {
|
|
1105
|
+
patchedAny = true;
|
|
1106
|
+
}
|
|
1107
|
+
}
|
|
1108
|
+
if (!patchedAny) {
|
|
1109
|
+
warnings.push(
|
|
1110
|
+
`Found HTML files in ${rendererDir} but couldn't patch any \u2014 they may have unusual CSP or no <head>.`
|
|
1111
|
+
);
|
|
1112
|
+
}
|
|
1113
|
+
} else {
|
|
1114
|
+
rendererInitPath = (0, import_node_path2.join)(projectRoot, "gg-pixel.renderer.mjs");
|
|
1115
|
+
(0, import_node_fs3.writeFileSync)(rendererInitPath, renderBrowserInitFile(ingestUrl, projectKey), "utf8");
|
|
1116
|
+
const rendererEntry = pickPath(projectRoot, [
|
|
1117
|
+
"src/renderer/index.ts",
|
|
1118
|
+
"src/renderer/index.tsx",
|
|
1119
|
+
"src/renderer/index.js",
|
|
1120
|
+
"src/renderer/main.ts",
|
|
1121
|
+
"src/renderer/main.tsx",
|
|
1122
|
+
"src/renderer/main.js",
|
|
1123
|
+
"renderer/index.ts",
|
|
1124
|
+
"renderer/index.tsx",
|
|
1125
|
+
"renderer/index.js",
|
|
1126
|
+
"renderer.ts",
|
|
1127
|
+
"renderer.tsx",
|
|
1128
|
+
"renderer.js",
|
|
1129
|
+
"src/index.tsx",
|
|
1130
|
+
"src/index.jsx",
|
|
1131
|
+
"src/main.tsx",
|
|
1132
|
+
"src/main.jsx"
|
|
1133
|
+
]);
|
|
1134
|
+
if (rendererEntry) injectImport(rendererEntry, rendererInitPath);
|
|
1135
|
+
else
|
|
1136
|
+
warnings.push(
|
|
1137
|
+
'Could not auto-detect the Electron renderer entry. Add `import "./gg-pixel.renderer.mjs";` to the top of your renderer entry file.'
|
|
1138
|
+
);
|
|
1126
1139
|
}
|
|
1127
1140
|
return {
|
|
1128
1141
|
primaryInitPath: rendererInitPath,
|
|
1129
|
-
entryWiring:
|
|
1142
|
+
entryWiring: { kind: "injected", entryPath: rendererInitPath },
|
|
1130
1143
|
secondaryInit: {
|
|
1131
1144
|
path: mainInitPath,
|
|
1132
1145
|
description: "Electron main-process init" + (mainWiring.kind === "injected" ? ` (wired into ${mainEntry})` : "")
|
|
@@ -1134,6 +1147,124 @@ function wireElectron({ projectRoot, pkg, projectKey, ingestUrl }) {
|
|
|
1134
1147
|
warnings
|
|
1135
1148
|
};
|
|
1136
1149
|
}
|
|
1150
|
+
function resolveMainEntryFromPkg(projectRoot, pkg) {
|
|
1151
|
+
if (pkg.main) {
|
|
1152
|
+
const sourceCandidates = [];
|
|
1153
|
+
const main = pkg.main;
|
|
1154
|
+
if (/^(dist|build|\.next|out)\//.test(main)) {
|
|
1155
|
+
const swap = main.replace(/^(dist|build|\.next|out)\//, "src/");
|
|
1156
|
+
if (swap.endsWith(".js")) {
|
|
1157
|
+
sourceCandidates.push(swap.replace(/\.js$/, ".ts"));
|
|
1158
|
+
sourceCandidates.push(swap.replace(/\.js$/, ".tsx"));
|
|
1159
|
+
}
|
|
1160
|
+
sourceCandidates.push(swap);
|
|
1161
|
+
}
|
|
1162
|
+
if (main.endsWith(".js")) {
|
|
1163
|
+
sourceCandidates.push(main.replace(/\.js$/, ".ts"));
|
|
1164
|
+
sourceCandidates.push(main.replace(/\.js$/, ".tsx"));
|
|
1165
|
+
}
|
|
1166
|
+
for (const c of sourceCandidates) {
|
|
1167
|
+
const p = (0, import_node_path2.join)(projectRoot, c);
|
|
1168
|
+
if ((0, import_node_fs3.existsSync)(p)) return p;
|
|
1169
|
+
}
|
|
1170
|
+
const literal = (0, import_node_path2.join)(projectRoot, main);
|
|
1171
|
+
if ((0, import_node_fs3.existsSync)(literal)) return literal;
|
|
1172
|
+
}
|
|
1173
|
+
return pickPath(projectRoot, [
|
|
1174
|
+
"main.js",
|
|
1175
|
+
"main.ts",
|
|
1176
|
+
"src/main.js",
|
|
1177
|
+
"src/main.ts",
|
|
1178
|
+
"src/main/index.ts",
|
|
1179
|
+
"src/main/index.js",
|
|
1180
|
+
"electron/main.js",
|
|
1181
|
+
"electron/main.ts"
|
|
1182
|
+
]);
|
|
1183
|
+
}
|
|
1184
|
+
var RENDERER_HTML_DIRS = ["ui", "renderer", "src/renderer", "public", "static"];
|
|
1185
|
+
function findRendererHtmlFiles(projectRoot) {
|
|
1186
|
+
for (const dir of RENDERER_HTML_DIRS) {
|
|
1187
|
+
const root = (0, import_node_path2.join)(projectRoot, dir);
|
|
1188
|
+
if (!(0, import_node_fs3.existsSync)(root)) continue;
|
|
1189
|
+
const html = [];
|
|
1190
|
+
let entries;
|
|
1191
|
+
try {
|
|
1192
|
+
entries = (0, import_node_fs3.readdirSync)(root);
|
|
1193
|
+
} catch {
|
|
1194
|
+
continue;
|
|
1195
|
+
}
|
|
1196
|
+
for (const e of entries) {
|
|
1197
|
+
if (!e.endsWith(".html")) continue;
|
|
1198
|
+
const p = (0, import_node_path2.join)(root, e);
|
|
1199
|
+
try {
|
|
1200
|
+
const c = (0, import_node_fs3.readFileSync)(p, "utf8");
|
|
1201
|
+
if (/<meta[^>]+content-security-policy/i.test(c) || /<script[\s>]/i.test(c)) {
|
|
1202
|
+
html.push(p);
|
|
1203
|
+
}
|
|
1204
|
+
} catch {
|
|
1205
|
+
}
|
|
1206
|
+
}
|
|
1207
|
+
if (html.length > 0) return html;
|
|
1208
|
+
}
|
|
1209
|
+
return [];
|
|
1210
|
+
}
|
|
1211
|
+
function copyIifeBundle(projectRoot, dest) {
|
|
1212
|
+
const candidates = [
|
|
1213
|
+
(0, import_node_path2.join)(projectRoot, "node_modules/@kenkaiiii/gg-pixel/dist/browser.iife.global.js"),
|
|
1214
|
+
(0, import_node_path2.join)(projectRoot, "node_modules/@kenkaiiii/gg-pixel/dist/browser.iife.js")
|
|
1215
|
+
];
|
|
1216
|
+
for (const c of candidates) {
|
|
1217
|
+
if ((0, import_node_fs3.existsSync)(c)) {
|
|
1218
|
+
try {
|
|
1219
|
+
(0, import_node_fs3.writeFileSync)(dest, (0, import_node_fs3.readFileSync)(c, "utf8"), "utf8");
|
|
1220
|
+
return true;
|
|
1221
|
+
} catch {
|
|
1222
|
+
}
|
|
1223
|
+
}
|
|
1224
|
+
}
|
|
1225
|
+
return false;
|
|
1226
|
+
}
|
|
1227
|
+
function patchRendererHtml(htmlPath, iifePath, projectKey, ingestUrl) {
|
|
1228
|
+
let content;
|
|
1229
|
+
try {
|
|
1230
|
+
content = (0, import_node_fs3.readFileSync)(htmlPath, "utf8");
|
|
1231
|
+
} catch {
|
|
1232
|
+
return "not-applicable";
|
|
1233
|
+
}
|
|
1234
|
+
if (content.includes("gg-pixel.browser.iife")) return "already";
|
|
1235
|
+
const ingestOrigin = new URL(ingestUrl).origin;
|
|
1236
|
+
content = content.replace(
|
|
1237
|
+
/(<meta[^>]+http-equiv=["']?content-security-policy["']?[^>]+content=["'])([^"']+)(["'])/i,
|
|
1238
|
+
(_match, before, csp, after) => {
|
|
1239
|
+
let updated = csp;
|
|
1240
|
+
if (/connect-src\s/i.test(csp)) {
|
|
1241
|
+
if (!csp.includes(ingestOrigin)) {
|
|
1242
|
+
updated = csp.replace(/(connect-src[^;]*)/i, `$1 ${ingestOrigin}`);
|
|
1243
|
+
}
|
|
1244
|
+
} else {
|
|
1245
|
+
updated = csp.trim().replace(/;?$/, `; connect-src 'self' ${ingestOrigin};`);
|
|
1246
|
+
}
|
|
1247
|
+
return before + updated + after;
|
|
1248
|
+
}
|
|
1249
|
+
);
|
|
1250
|
+
const relScript = (0, import_node_path2.relative)((0, import_node_path2.dirname)(htmlPath), iifePath).split(import_node_path2.sep).join("/");
|
|
1251
|
+
const inject = `
|
|
1252
|
+
<!-- gg-pixel: auto-wired by ggcoder pixel install -->
|
|
1253
|
+
<script src="${relScript}"></script>
|
|
1254
|
+
<script>
|
|
1255
|
+
if (window.GGPixel) GGPixel.initPixel({ projectKey: ${JSON.stringify(projectKey)}, ingestUrl: ${JSON.stringify(ingestUrl)} });
|
|
1256
|
+
</script>
|
|
1257
|
+
`;
|
|
1258
|
+
if (/<head[^>]*>/i.test(content)) {
|
|
1259
|
+
content = content.replace(/(<head[^>]*>)/i, `$1${inject}`);
|
|
1260
|
+
} else if (/<html[^>]*>/i.test(content)) {
|
|
1261
|
+
content = content.replace(/(<html[^>]*>)/i, `$1<head>${inject}</head>`);
|
|
1262
|
+
} else {
|
|
1263
|
+
return "not-applicable";
|
|
1264
|
+
}
|
|
1265
|
+
(0, import_node_fs3.writeFileSync)(htmlPath, content, "utf8");
|
|
1266
|
+
return "patched";
|
|
1267
|
+
}
|
|
1137
1268
|
function wireTauri({ projectRoot, pkg, projectKey, ingestUrl }) {
|
|
1138
1269
|
const initPath = (0, import_node_path2.join)(projectRoot, "gg-pixel.init.mjs");
|
|
1139
1270
|
(0, import_node_fs3.writeFileSync)(initPath, renderBrowserInitFile(ingestUrl, projectKey), "utf8");
|