@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 +66 -5
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +67 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +66 -5
- package/dist/index.js.map +1 -1
- package/package.json +4 -1
package/dist/index.js
CHANGED
|
@@ -429,9 +429,11 @@ import {
|
|
|
429
429
|
mkdirSync as mkdirSync2,
|
|
430
430
|
readdirSync
|
|
431
431
|
} from "fs";
|
|
432
|
+
import { createRequire as createRequire2 } from "module";
|
|
432
433
|
import { homedir as homedir2 } from "os";
|
|
433
434
|
import { dirname as dirname2, join as join2, relative, resolve, sep } from "path";
|
|
434
435
|
import { spawnSync as spawnSync2 } from "child_process";
|
|
436
|
+
var nodeRequire = createRequire2(import.meta.url);
|
|
435
437
|
var DEFAULT_INGEST_URL = "https://gg-pixel-server.buzzbeamaustralia.workers.dev";
|
|
436
438
|
async function install(opts = {}) {
|
|
437
439
|
const cwd = resolve(opts.cwd ?? process.cwd());
|
|
@@ -928,26 +930,85 @@ export default nextConfig;
|
|
|
928
930
|
);
|
|
929
931
|
return;
|
|
930
932
|
}
|
|
931
|
-
|
|
932
|
-
|
|
933
|
+
patchNextConfigViaAst(configPath);
|
|
934
|
+
}
|
|
935
|
+
var PIXEL_PKG = "@kenkaiiii/gg-pixel";
|
|
936
|
+
function patchNextConfigViaAst(configPath) {
|
|
937
|
+
const original = readFileSync2(configPath, "utf8");
|
|
938
|
+
if (original.includes(PIXEL_PKG)) return;
|
|
939
|
+
let parseModule;
|
|
940
|
+
let generateCode;
|
|
941
|
+
try {
|
|
942
|
+
const mod = nodeRequire("magicast");
|
|
943
|
+
parseModule = mod.parseModule;
|
|
944
|
+
generateCode = mod.generateCode;
|
|
945
|
+
} catch {
|
|
946
|
+
return patchNextConfigViaRegex(configPath, original);
|
|
947
|
+
}
|
|
948
|
+
let module_;
|
|
949
|
+
try {
|
|
950
|
+
module_ = parseModule(original);
|
|
951
|
+
} catch {
|
|
952
|
+
return patchNextConfigViaRegex(configPath, original);
|
|
953
|
+
}
|
|
954
|
+
const cfg = resolveNextConfigObject(module_);
|
|
955
|
+
if (!cfg) {
|
|
956
|
+
return patchNextConfigViaRegex(configPath, original);
|
|
957
|
+
}
|
|
958
|
+
const existing = cfg.serverExternalPackages;
|
|
959
|
+
const isArrayLike = Array.isArray(existing) || typeof existing === "object" && existing !== null && existing.$type === "array";
|
|
960
|
+
if (isArrayLike) {
|
|
961
|
+
const arr = existing;
|
|
962
|
+
if (arr.includes(PIXEL_PKG)) return;
|
|
963
|
+
arr.push(PIXEL_PKG);
|
|
964
|
+
} else {
|
|
965
|
+
cfg.serverExternalPackages = [PIXEL_PKG];
|
|
966
|
+
}
|
|
967
|
+
const out = generateCode(module_).code;
|
|
968
|
+
if (out !== original) writeFileSync(configPath, out, "utf8");
|
|
969
|
+
}
|
|
970
|
+
function resolveNextConfigObject(mod) {
|
|
971
|
+
const root = mod.exports.default ?? mod.exports;
|
|
972
|
+
if (!root) return null;
|
|
973
|
+
return unwrapWrappers(root);
|
|
974
|
+
}
|
|
975
|
+
function unwrapWrappers(node) {
|
|
976
|
+
let cur = node;
|
|
977
|
+
for (let i = 0; i < 6; i++) {
|
|
978
|
+
if (cur.$type === "function-call") {
|
|
979
|
+
const args = cur.$args ?? [];
|
|
980
|
+
const objArg = args.find(
|
|
981
|
+
(a) => typeof a === "object" && a !== null && a.$type !== "function-call"
|
|
982
|
+
);
|
|
983
|
+
if (!objArg) return null;
|
|
984
|
+
cur = objArg;
|
|
985
|
+
continue;
|
|
986
|
+
}
|
|
987
|
+
if (cur.$type === "object" || cur.$type === void 0) return cur;
|
|
988
|
+
return null;
|
|
989
|
+
}
|
|
990
|
+
return null;
|
|
991
|
+
}
|
|
992
|
+
function patchNextConfigViaRegex(configPath, content) {
|
|
993
|
+
if (content.includes(PIXEL_PKG)) return;
|
|
933
994
|
if (content.includes("serverExternalPackages")) {
|
|
934
995
|
const updated = content.replace(
|
|
935
996
|
/serverExternalPackages\s*:\s*\[([^\]]*)\]/,
|
|
936
997
|
(_match, inside) => {
|
|
937
998
|
const trimmed = inside.trim();
|
|
938
999
|
const sep2 = trimmed.length > 0 ? ", " : "";
|
|
939
|
-
return `serverExternalPackages: [${trimmed}${sep2}
|
|
1000
|
+
return `serverExternalPackages: [${trimmed}${sep2}${JSON.stringify(PIXEL_PKG)}]`;
|
|
940
1001
|
}
|
|
941
1002
|
);
|
|
942
1003
|
if (updated !== content) writeFileSync(configPath, updated, "utf8");
|
|
943
1004
|
return;
|
|
944
1005
|
}
|
|
945
|
-
const objStart = /(const\s+\w+\s
|
|
1006
|
+
const objStart = /(const\s+\w+\s*(?::\s*\w+)?\s*=\s*\{|module\.exports\s*=\s*\{|export\s+default\s*\{)/;
|
|
946
1007
|
const m = objStart.exec(content);
|
|
947
1008
|
if (m) {
|
|
948
1009
|
const insertAt = m.index + m[0].length;
|
|
949
1010
|
const updated = content.slice(0, insertAt) + `
|
|
950
|
-
serverExternalPackages: [
|
|
1011
|
+
serverExternalPackages: [${JSON.stringify(PIXEL_PKG)}],` + content.slice(insertAt);
|
|
951
1012
|
writeFileSync(configPath, updated, "utf8");
|
|
952
1013
|
}
|
|
953
1014
|
}
|