@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/cli.js CHANGED
@@ -9,9 +9,11 @@ import {
9
9
  mkdirSync,
10
10
  readdirSync
11
11
  } from "fs";
12
+ import { createRequire } from "module";
12
13
  import { homedir } from "os";
13
14
  import { dirname, join, relative, resolve, sep } from "path";
14
15
  import { spawnSync } from "child_process";
16
+ var nodeRequire = createRequire(import.meta.url);
15
17
  var DEFAULT_INGEST_URL = "https://gg-pixel-server.buzzbeamaustralia.workers.dev";
16
18
  async function install(opts = {}) {
17
19
  const cwd = resolve(opts.cwd ?? process.cwd());
@@ -508,26 +510,85 @@ export default nextConfig;
508
510
  );
509
511
  return;
510
512
  }
511
- const content = readFileSync(configPath, "utf8");
512
- if (content.includes("@kenkaiiii/gg-pixel")) return;
513
+ patchNextConfigViaAst(configPath);
514
+ }
515
+ var PIXEL_PKG = "@kenkaiiii/gg-pixel";
516
+ function patchNextConfigViaAst(configPath) {
517
+ const original = readFileSync(configPath, "utf8");
518
+ if (original.includes(PIXEL_PKG)) return;
519
+ let parseModule;
520
+ let generateCode;
521
+ try {
522
+ const mod = nodeRequire("magicast");
523
+ parseModule = mod.parseModule;
524
+ generateCode = mod.generateCode;
525
+ } catch {
526
+ return patchNextConfigViaRegex(configPath, original);
527
+ }
528
+ let module_;
529
+ try {
530
+ module_ = parseModule(original);
531
+ } catch {
532
+ return patchNextConfigViaRegex(configPath, original);
533
+ }
534
+ const cfg = resolveNextConfigObject(module_);
535
+ if (!cfg) {
536
+ return patchNextConfigViaRegex(configPath, original);
537
+ }
538
+ const existing = cfg.serverExternalPackages;
539
+ const isArrayLike = Array.isArray(existing) || typeof existing === "object" && existing !== null && existing.$type === "array";
540
+ if (isArrayLike) {
541
+ const arr = existing;
542
+ if (arr.includes(PIXEL_PKG)) return;
543
+ arr.push(PIXEL_PKG);
544
+ } else {
545
+ cfg.serverExternalPackages = [PIXEL_PKG];
546
+ }
547
+ const out = generateCode(module_).code;
548
+ if (out !== original) writeFileSync(configPath, out, "utf8");
549
+ }
550
+ function resolveNextConfigObject(mod) {
551
+ const root = mod.exports.default ?? mod.exports;
552
+ if (!root) return null;
553
+ return unwrapWrappers(root);
554
+ }
555
+ function unwrapWrappers(node) {
556
+ let cur = node;
557
+ for (let i = 0; i < 6; i++) {
558
+ if (cur.$type === "function-call") {
559
+ const args = cur.$args ?? [];
560
+ const objArg = args.find(
561
+ (a) => typeof a === "object" && a !== null && a.$type !== "function-call"
562
+ );
563
+ if (!objArg) return null;
564
+ cur = objArg;
565
+ continue;
566
+ }
567
+ if (cur.$type === "object" || cur.$type === void 0) return cur;
568
+ return null;
569
+ }
570
+ return null;
571
+ }
572
+ function patchNextConfigViaRegex(configPath, content) {
573
+ if (content.includes(PIXEL_PKG)) return;
513
574
  if (content.includes("serverExternalPackages")) {
514
575
  const updated = content.replace(
515
576
  /serverExternalPackages\s*:\s*\[([^\]]*)\]/,
516
577
  (_match, inside) => {
517
578
  const trimmed = inside.trim();
518
579
  const sep2 = trimmed.length > 0 ? ", " : "";
519
- return `serverExternalPackages: [${trimmed}${sep2}"@kenkaiiii/gg-pixel"]`;
580
+ return `serverExternalPackages: [${trimmed}${sep2}${JSON.stringify(PIXEL_PKG)}]`;
520
581
  }
521
582
  );
522
583
  if (updated !== content) writeFileSync(configPath, updated, "utf8");
523
584
  return;
524
585
  }
525
- const objStart = /(const\s+\w+\s*:\s*NextConfig\s*=\s*\{|module\.exports\s*=\s*\{|export\s+default\s*\{)/;
586
+ const objStart = /(const\s+\w+\s*(?::\s*\w+)?\s*=\s*\{|module\.exports\s*=\s*\{|export\s+default\s*\{)/;
526
587
  const m = objStart.exec(content);
527
588
  if (m) {
528
589
  const insertAt = m.index + m[0].length;
529
590
  const updated = content.slice(0, insertAt) + `
530
- serverExternalPackages: ["@kenkaiiii/gg-pixel"],` + content.slice(insertAt);
591
+ serverExternalPackages: [${JSON.stringify(PIXEL_PKG)}],` + content.slice(insertAt);
531
592
  writeFileSync(configPath, updated, "utf8");
532
593
  }
533
594
  }