@kenkaiiii/gg-pixel 4.3.90 → 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());
@@ -75,6 +77,7 @@ async function install(opts = {}) {
75
77
  projectSecret: created.secret,
76
78
  projectName,
77
79
  projectKind: kind,
80
+ projectRoot: nodeRoot,
78
81
  initFilePath: wired.primaryInitPath,
79
82
  envFilePath,
80
83
  projectsJsonPath,
@@ -507,26 +510,85 @@ export default nextConfig;
507
510
  );
508
511
  return;
509
512
  }
510
- const content = readFileSync(configPath, "utf8");
511
- 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;
512
574
  if (content.includes("serverExternalPackages")) {
513
575
  const updated = content.replace(
514
576
  /serverExternalPackages\s*:\s*\[([^\]]*)\]/,
515
577
  (_match, inside) => {
516
578
  const trimmed = inside.trim();
517
579
  const sep2 = trimmed.length > 0 ? ", " : "";
518
- return `serverExternalPackages: [${trimmed}${sep2}"@kenkaiiii/gg-pixel"]`;
580
+ return `serverExternalPackages: [${trimmed}${sep2}${JSON.stringify(PIXEL_PKG)}]`;
519
581
  }
520
582
  );
521
583
  if (updated !== content) writeFileSync(configPath, updated, "utf8");
522
584
  return;
523
585
  }
524
- 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*\{)/;
525
587
  const m = objStart.exec(content);
526
588
  if (m) {
527
589
  const insertAt = m.index + m[0].length;
528
590
  const updated = content.slice(0, insertAt) + `
529
- serverExternalPackages: ["@kenkaiiii/gg-pixel"],` + content.slice(insertAt);
591
+ serverExternalPackages: [${JSON.stringify(PIXEL_PKG)}],` + content.slice(insertAt);
530
592
  writeFileSync(configPath, updated, "utf8");
531
593
  }
532
594
  }
@@ -1154,6 +1216,7 @@ func init() {
1154
1216
  projectSecret: created.secret,
1155
1217
  projectName,
1156
1218
  projectKind: "go",
1219
+ projectRoot,
1157
1220
  initFilePath,
1158
1221
  envFilePath,
1159
1222
  projectsJsonPath,
@@ -1219,6 +1282,7 @@ GGPixel.init(
1219
1282
  projectSecret: created.secret,
1220
1283
  projectName,
1221
1284
  projectKind: "ruby",
1285
+ projectRoot,
1222
1286
  initFilePath,
1223
1287
  envFilePath,
1224
1288
  projectsJsonPath,
@@ -1288,6 +1352,7 @@ async function installPython(ctx) {
1288
1352
  projectSecret: created.secret,
1289
1353
  projectName,
1290
1354
  projectKind: "python",
1355
+ projectRoot,
1291
1356
  initFilePath,
1292
1357
  envFilePath,
1293
1358
  projectsJsonPath,