@kenkaiiii/gg-pixel 4.3.92 → 4.3.94
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 +110 -1
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +111 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +111 -2
- package/dist/index.js.map +1 -1
- package/package.json +5 -10
package/dist/index.cjs
CHANGED
|
@@ -387,7 +387,7 @@ function loadBetterSqlite3() {
|
|
|
387
387
|
return typeof mod === "function" ? mod : mod.default;
|
|
388
388
|
} catch (err) {
|
|
389
389
|
throw new Error(
|
|
390
|
-
`@kenkaiiii/gg-pixel: \`kind: "local"\` requires
|
|
390
|
+
`@kenkaiiii/gg-pixel: \`kind: "local"\` requires \`better-sqlite3\` to be installed. Install it with \`npm install better-sqlite3\` (or your package manager's equivalent). Underlying error: ${err.message}`,
|
|
391
391
|
{ cause: err }
|
|
392
392
|
);
|
|
393
393
|
}
|
|
@@ -597,7 +597,9 @@ async function safeText(r) {
|
|
|
597
597
|
}
|
|
598
598
|
function detectPackageManager(projectRoot) {
|
|
599
599
|
if ((0, import_node_fs3.existsSync)((0, import_node_path2.join)(projectRoot, "pnpm-lock.yaml"))) return "pnpm";
|
|
600
|
-
if ((0, import_node_fs3.existsSync)((0, import_node_path2.join)(projectRoot, "bun.
|
|
600
|
+
if ((0, import_node_fs3.existsSync)((0, import_node_path2.join)(projectRoot, "bun.lock")) || (0, import_node_fs3.existsSync)((0, import_node_path2.join)(projectRoot, "bun.lockb"))) {
|
|
601
|
+
return "bun";
|
|
602
|
+
}
|
|
601
603
|
if ((0, import_node_fs3.existsSync)((0, import_node_path2.join)(projectRoot, "yarn.lock"))) return "yarn";
|
|
602
604
|
return "npm";
|
|
603
605
|
}
|
|
@@ -909,6 +911,113 @@ function injectNextClientComponent(layoutPath, clientInitPath) {
|
|
|
909
911
|
let spec = (0, import_node_path2.relative)(fromDir, clientInitPath).split(import_node_path2.sep).join("/");
|
|
910
912
|
if (!spec.startsWith(".")) spec = "./" + spec;
|
|
911
913
|
spec = spec.replace(/\.tsx$/, "");
|
|
914
|
+
const astResult = injectClientComponentViaAst(layoutPath, content, spec);
|
|
915
|
+
if (astResult) return astResult;
|
|
916
|
+
return injectClientComponentViaRegex(layoutPath, content, spec);
|
|
917
|
+
}
|
|
918
|
+
function injectClientComponentViaAst(layoutPath, content, importSpec) {
|
|
919
|
+
let recast;
|
|
920
|
+
let bp;
|
|
921
|
+
let bt;
|
|
922
|
+
try {
|
|
923
|
+
recast = nodeRequire("recast");
|
|
924
|
+
bp = nodeRequire("@babel/parser");
|
|
925
|
+
bt = nodeRequire("@babel/types");
|
|
926
|
+
} catch {
|
|
927
|
+
return null;
|
|
928
|
+
}
|
|
929
|
+
let ast;
|
|
930
|
+
try {
|
|
931
|
+
ast = recast.parse(content, {
|
|
932
|
+
parser: {
|
|
933
|
+
parse: (src) => bp.parse(src, {
|
|
934
|
+
sourceType: "module",
|
|
935
|
+
plugins: ["jsx", "typescript"],
|
|
936
|
+
allowImportExportEverywhere: true,
|
|
937
|
+
tokens: true
|
|
938
|
+
})
|
|
939
|
+
}
|
|
940
|
+
});
|
|
941
|
+
} catch {
|
|
942
|
+
return null;
|
|
943
|
+
}
|
|
944
|
+
const program = ast.program;
|
|
945
|
+
if (!program || !Array.isArray(program.body)) return null;
|
|
946
|
+
const bodyEl = findFirstJsxElementByName(ast, "body");
|
|
947
|
+
if (!bodyEl) return null;
|
|
948
|
+
const newComponent = bt.jsxElement(
|
|
949
|
+
bt.jsxOpeningElement(bt.jsxIdentifier("GGPixelClient"), [], true),
|
|
950
|
+
null,
|
|
951
|
+
[],
|
|
952
|
+
true
|
|
953
|
+
);
|
|
954
|
+
const leadingText = bt.jsxText("\n ");
|
|
955
|
+
const trailingText = bt.jsxText("\n ");
|
|
956
|
+
bodyEl.children = [leadingText, newComponent, trailingText, ...bodyEl.children];
|
|
957
|
+
const importDecl = bt.importDeclaration(
|
|
958
|
+
[bt.importDefaultSpecifier(bt.identifier("GGPixelClient"))],
|
|
959
|
+
bt.stringLiteral(importSpec)
|
|
960
|
+
);
|
|
961
|
+
const body = program.body;
|
|
962
|
+
let insertAt = 0;
|
|
963
|
+
for (let i = 0; i < body.length; i++) {
|
|
964
|
+
if (body[i]?.type === "ImportDeclaration") insertAt = i + 1;
|
|
965
|
+
}
|
|
966
|
+
body.splice(insertAt, 0, importDecl);
|
|
967
|
+
let out;
|
|
968
|
+
try {
|
|
969
|
+
out = recast.print(ast).code;
|
|
970
|
+
} catch {
|
|
971
|
+
return null;
|
|
972
|
+
}
|
|
973
|
+
(0, import_node_fs3.writeFileSync)(layoutPath, out, "utf8");
|
|
974
|
+
return { kind: "injected", entryPath: layoutPath };
|
|
975
|
+
}
|
|
976
|
+
function findFirstJsxElementByName(ast, name) {
|
|
977
|
+
let found = null;
|
|
978
|
+
const seen = /* @__PURE__ */ new WeakSet();
|
|
979
|
+
const MAX_DEPTH = 500;
|
|
980
|
+
const SKIP_KEYS = /* @__PURE__ */ new Set([
|
|
981
|
+
"loc",
|
|
982
|
+
"tokens",
|
|
983
|
+
"original",
|
|
984
|
+
"comments",
|
|
985
|
+
"leadingComments",
|
|
986
|
+
"trailingComments",
|
|
987
|
+
"innerComments",
|
|
988
|
+
"range",
|
|
989
|
+
"start",
|
|
990
|
+
"end"
|
|
991
|
+
]);
|
|
992
|
+
function walk(node, depth) {
|
|
993
|
+
if (found || !node || typeof node !== "object") return;
|
|
994
|
+
if (depth > MAX_DEPTH) return;
|
|
995
|
+
if (seen.has(node)) return;
|
|
996
|
+
seen.add(node);
|
|
997
|
+
if (Array.isArray(node)) {
|
|
998
|
+
for (const c of node) walk(c, depth + 1);
|
|
999
|
+
return;
|
|
1000
|
+
}
|
|
1001
|
+
const n = node;
|
|
1002
|
+
if (n.type === "JSXElement") {
|
|
1003
|
+
const opening = n.openingElement;
|
|
1004
|
+
if (opening?.type === "JSXOpeningElement" && opening.name) {
|
|
1005
|
+
const namedNode = opening.name;
|
|
1006
|
+
if (namedNode.type === "JSXIdentifier" && namedNode.name === name) {
|
|
1007
|
+
found = n;
|
|
1008
|
+
return;
|
|
1009
|
+
}
|
|
1010
|
+
}
|
|
1011
|
+
}
|
|
1012
|
+
for (const key of Object.keys(n)) {
|
|
1013
|
+
if (SKIP_KEYS.has(key)) continue;
|
|
1014
|
+
walk(n[key], depth + 1);
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
1017
|
+
walk(ast, 0);
|
|
1018
|
+
return found;
|
|
1019
|
+
}
|
|
1020
|
+
function injectClientComponentViaRegex(layoutPath, content, spec) {
|
|
912
1021
|
const importLine = `import GGPixelClient from ${JSON.stringify(spec)};`;
|
|
913
1022
|
const lines = content.split("\n");
|
|
914
1023
|
let insertImportAt = 0;
|