@kenkaiiii/gg-pixel 4.3.91 → 4.3.92

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/index.cjs CHANGED
@@ -456,9 +456,12 @@ var LocalSqliteSink = class {
456
456
 
457
457
  // src/install.ts
458
458
  var import_node_fs3 = require("fs");
459
+ var import_node_module2 = require("module");
459
460
  var import_node_os2 = require("os");
460
461
  var import_node_path2 = require("path");
461
462
  var import_node_child_process2 = require("child_process");
463
+ var import_meta2 = {};
464
+ var nodeRequire = (0, import_node_module2.createRequire)(import_meta2.url);
462
465
  var DEFAULT_INGEST_URL = "https://gg-pixel-server.buzzbeamaustralia.workers.dev";
463
466
  async function install(opts = {}) {
464
467
  const cwd = (0, import_node_path2.resolve)(opts.cwd ?? process.cwd());
@@ -955,26 +958,85 @@ export default nextConfig;
955
958
  );
956
959
  return;
957
960
  }
958
- const content = (0, import_node_fs3.readFileSync)(configPath, "utf8");
959
- if (content.includes("@kenkaiiii/gg-pixel")) return;
961
+ patchNextConfigViaAst(configPath);
962
+ }
963
+ var PIXEL_PKG = "@kenkaiiii/gg-pixel";
964
+ function patchNextConfigViaAst(configPath) {
965
+ const original = (0, import_node_fs3.readFileSync)(configPath, "utf8");
966
+ if (original.includes(PIXEL_PKG)) return;
967
+ let parseModule;
968
+ let generateCode;
969
+ try {
970
+ const mod = nodeRequire("magicast");
971
+ parseModule = mod.parseModule;
972
+ generateCode = mod.generateCode;
973
+ } catch {
974
+ return patchNextConfigViaRegex(configPath, original);
975
+ }
976
+ let module_;
977
+ try {
978
+ module_ = parseModule(original);
979
+ } catch {
980
+ return patchNextConfigViaRegex(configPath, original);
981
+ }
982
+ const cfg = resolveNextConfigObject(module_);
983
+ if (!cfg) {
984
+ return patchNextConfigViaRegex(configPath, original);
985
+ }
986
+ const existing = cfg.serverExternalPackages;
987
+ const isArrayLike = Array.isArray(existing) || typeof existing === "object" && existing !== null && existing.$type === "array";
988
+ if (isArrayLike) {
989
+ const arr = existing;
990
+ if (arr.includes(PIXEL_PKG)) return;
991
+ arr.push(PIXEL_PKG);
992
+ } else {
993
+ cfg.serverExternalPackages = [PIXEL_PKG];
994
+ }
995
+ const out = generateCode(module_).code;
996
+ if (out !== original) (0, import_node_fs3.writeFileSync)(configPath, out, "utf8");
997
+ }
998
+ function resolveNextConfigObject(mod) {
999
+ const root = mod.exports.default ?? mod.exports;
1000
+ if (!root) return null;
1001
+ return unwrapWrappers(root);
1002
+ }
1003
+ function unwrapWrappers(node) {
1004
+ let cur = node;
1005
+ for (let i = 0; i < 6; i++) {
1006
+ if (cur.$type === "function-call") {
1007
+ const args = cur.$args ?? [];
1008
+ const objArg = args.find(
1009
+ (a) => typeof a === "object" && a !== null && a.$type !== "function-call"
1010
+ );
1011
+ if (!objArg) return null;
1012
+ cur = objArg;
1013
+ continue;
1014
+ }
1015
+ if (cur.$type === "object" || cur.$type === void 0) return cur;
1016
+ return null;
1017
+ }
1018
+ return null;
1019
+ }
1020
+ function patchNextConfigViaRegex(configPath, content) {
1021
+ if (content.includes(PIXEL_PKG)) return;
960
1022
  if (content.includes("serverExternalPackages")) {
961
1023
  const updated = content.replace(
962
1024
  /serverExternalPackages\s*:\s*\[([^\]]*)\]/,
963
1025
  (_match, inside) => {
964
1026
  const trimmed = inside.trim();
965
1027
  const sep2 = trimmed.length > 0 ? ", " : "";
966
- return `serverExternalPackages: [${trimmed}${sep2}"@kenkaiiii/gg-pixel"]`;
1028
+ return `serverExternalPackages: [${trimmed}${sep2}${JSON.stringify(PIXEL_PKG)}]`;
967
1029
  }
968
1030
  );
969
1031
  if (updated !== content) (0, import_node_fs3.writeFileSync)(configPath, updated, "utf8");
970
1032
  return;
971
1033
  }
972
- const objStart = /(const\s+\w+\s*:\s*NextConfig\s*=\s*\{|module\.exports\s*=\s*\{|export\s+default\s*\{)/;
1034
+ const objStart = /(const\s+\w+\s*(?::\s*\w+)?\s*=\s*\{|module\.exports\s*=\s*\{|export\s+default\s*\{)/;
973
1035
  const m = objStart.exec(content);
974
1036
  if (m) {
975
1037
  const insertAt = m.index + m[0].length;
976
1038
  const updated = content.slice(0, insertAt) + `
977
- serverExternalPackages: ["@kenkaiiii/gg-pixel"],` + content.slice(insertAt);
1039
+ serverExternalPackages: [${JSON.stringify(PIXEL_PKG)}],` + content.slice(insertAt);
978
1040
  (0, import_node_fs3.writeFileSync)(configPath, updated, "utf8");
979
1041
  }
980
1042
  }