@marktiderman/genesis-cli 1.5.0 → 1.6.0
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/README.md +68 -2
- package/dist/cli.js +894 -43
- package/dist/cli.js.map +1 -1
- package/dist/{config-Ci-_Ue-1.d.ts → config-CUdwT-nY.d.ts} +29 -3
- package/dist/doctor.d.ts +31 -4
- package/dist/doctor.js +846 -28
- package/dist/doctor.js.map +1 -1
- package/dist/expo.d.ts +2 -2
- package/dist/expo.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +850 -32
- package/dist/index.js.map +1 -1
- package/dist/scaffolder.js +2 -2
- package/dist/scaffolder.js.map +1 -1
- package/dist/vite.js +845 -27
- package/dist/vite.js.map +1 -1
- package/package.json +1 -1
package/dist/doctor.js
CHANGED
|
@@ -63,11 +63,26 @@ var KNOWN = /* @__PURE__ */ new Set([
|
|
|
63
63
|
"allow",
|
|
64
64
|
"patterns",
|
|
65
65
|
"plugins",
|
|
66
|
+
"packs",
|
|
67
|
+
"native",
|
|
68
|
+
"supabase",
|
|
66
69
|
"$schema",
|
|
67
70
|
"$comment"
|
|
68
71
|
]);
|
|
69
72
|
var LEVELS = /* @__PURE__ */ new Set(["error", "warn", "off"]);
|
|
70
73
|
var PATTERN_KEYS = /* @__PURE__ */ new Set(["id", "level", "files", "exclude", "forbid", "require", "path", "message"]);
|
|
74
|
+
var PACKS = /* @__PURE__ */ new Set(["native", "supabase"]);
|
|
75
|
+
var PACK_KEYS = {
|
|
76
|
+
native: { routerRoot: "path" },
|
|
77
|
+
supabase: { migrations: "path", base: "string", exposedSchemas: "list", since: "string" }
|
|
78
|
+
};
|
|
79
|
+
function appPath(v, where, fail) {
|
|
80
|
+
if (typeof v !== "string" || !v.trim()) return fail(`${where} must be a non-empty path`);
|
|
81
|
+
if (path3.isAbsolute(v) || /^[A-Za-z]:[\\/]/.test(v)) fail(`${where} must be relative to the app, not absolute ("${v}")`);
|
|
82
|
+
const norm = path3.posix.normalize(v.replace(/\\/g, "/")).replace(/\/+$/, "");
|
|
83
|
+
if (norm === "." || norm === ".." || norm.startsWith("../")) fail(`${where} must be a folder inside the app ("${v}")`);
|
|
84
|
+
return norm;
|
|
85
|
+
}
|
|
71
86
|
function loadConfig(root, configPath) {
|
|
72
87
|
if (configPath) {
|
|
73
88
|
const file = path3.resolve(root, configPath);
|
|
@@ -191,6 +206,27 @@ function validateConfig(raw, source = "config") {
|
|
|
191
206
|
}
|
|
192
207
|
});
|
|
193
208
|
}
|
|
209
|
+
if (c.packs !== void 0) {
|
|
210
|
+
if (!isStringList(c.packs)) fail(`"packs" must be a list, e.g. ["native", "supabase"]`);
|
|
211
|
+
for (const p of c.packs) if (!PACKS.has(p)) fail(`packs: unknown pack "${p}" (known: ${[...PACKS].join(", ")})`);
|
|
212
|
+
if (new Set(c.packs).size !== c.packs.length) fail(`packs: lists a pack twice`);
|
|
213
|
+
}
|
|
214
|
+
for (const [pack, keys] of Object.entries(PACK_KEYS)) {
|
|
215
|
+
const block = c[pack];
|
|
216
|
+
if (block === void 0) continue;
|
|
217
|
+
if (!isObject(block)) fail(`"${pack}" must be an object`);
|
|
218
|
+
if (!(c.packs ?? []).includes(pack)) fail(`"${pack}" settings are set but the ${pack} pack is not in "packs"`);
|
|
219
|
+
for (const [k, v] of Object.entries(block)) {
|
|
220
|
+
const want = keys[k];
|
|
221
|
+
if (!want) fail(`${pack}: unknown setting "${k}"`);
|
|
222
|
+
if (want === "string" && typeof v !== "string") fail(`${pack}.${k} must be a string`);
|
|
223
|
+
if (want === "list" && !isStringList(v)) fail(`${pack}.${k} must be a list of strings`);
|
|
224
|
+
if (want === "string" && !v.trim()) fail(`${pack}.${k} must not be empty`);
|
|
225
|
+
if (want === "path") block[k] = appPath(v, `${pack}.${k}`, fail);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
const supa = c.supabase;
|
|
229
|
+
if (Array.isArray(supa?.exposedSchemas)) supa.exposedSchemas = supa.exposedSchemas.map((s) => s.toLowerCase());
|
|
194
230
|
if (c.plugins !== void 0) {
|
|
195
231
|
const ok = Array.isArray(c.plugins) && c.plugins.every((p) => typeof p === "string" || Array.isArray(p) && p.length === 2 && typeof p[0] === "string");
|
|
196
232
|
if (!ok) fail(`"plugins" must be a list of module paths or [path, options] pairs`);
|
|
@@ -236,9 +272,10 @@ function globToRegExp(glob) {
|
|
|
236
272
|
}
|
|
237
273
|
function globMatcher(globs) {
|
|
238
274
|
const res = (globs ?? []).filter((g) => g.trim()).map(globToRegExp);
|
|
239
|
-
return (
|
|
275
|
+
return (path13) => res.some((re) => re.test(path13));
|
|
240
276
|
}
|
|
241
277
|
var DEFAULT_UI_PACKAGE = "@marktiderman/genesis-ui";
|
|
278
|
+
var NATIVE_UI_PACKAGE = "@marktiderman/genesis-ui-native";
|
|
242
279
|
var DESIGN_SYSTEM_PACKAGE = "@marktiderman/genesis-design-system";
|
|
243
280
|
var TAGS = ["button", "input", "textarea", "select", "label", "table", "dialog", "progress", "details", "summary"];
|
|
244
281
|
var TAG_ALIASES = { hr: "Separator" };
|
|
@@ -283,10 +320,39 @@ function findPackageDir(from, name) {
|
|
|
283
320
|
dir = parent;
|
|
284
321
|
}
|
|
285
322
|
}
|
|
323
|
+
function uiPackageFor(config) {
|
|
324
|
+
return config.uiPackage ?? (config.packs?.includes("native") ? NATIVE_UI_PACKAGE : DEFAULT_UI_PACKAGE);
|
|
325
|
+
}
|
|
286
326
|
function loadGenesis(root, config) {
|
|
287
|
-
const uiPackage = config
|
|
327
|
+
const uiPackage = uiPackageFor(config);
|
|
328
|
+
const pkg = readPackageExports(root, uiPackage);
|
|
329
|
+
if (!pkg) throw new DoctorConfigError(`${uiPackage} is not installed here. Install it, or set doctor.uiPackage.`);
|
|
330
|
+
const { dir: uiDir, exports: exportNames, values, components } = pkg;
|
|
331
|
+
const tokens = /* @__PURE__ */ new Set();
|
|
332
|
+
const themeFiles = resolveThemeFiles(root, config, uiDir);
|
|
333
|
+
for (const file of themeFiles) for (const t of declaredTokens(readFileSync(file, "utf8"))) tokens.add(t);
|
|
334
|
+
const byLower = new Map(components.map((c) => [c.toLowerCase(), c]));
|
|
335
|
+
const rawTags = /* @__PURE__ */ new Map();
|
|
336
|
+
for (const tag of TAGS) if (byLower.has(tag)) rawTags.set(tag, byLower.get(tag));
|
|
337
|
+
for (const [tag, comp] of Object.entries(TAG_ALIASES)) if (values.has(comp)) rawTags.set(tag, comp);
|
|
338
|
+
for (const [tag, comp] of Object.entries(config.rawTags ?? {})) {
|
|
339
|
+
if (comp === false) rawTags.delete(tag);
|
|
340
|
+
else rawTags.set(tag, comp);
|
|
341
|
+
}
|
|
342
|
+
return {
|
|
343
|
+
uiPackage,
|
|
344
|
+
uiVersion: pkg.version,
|
|
345
|
+
exports: exportNames,
|
|
346
|
+
values,
|
|
347
|
+
components,
|
|
348
|
+
tokens,
|
|
349
|
+
rawTags,
|
|
350
|
+
palette: loadPalette(root)
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
function readPackageExports(root, uiPackage) {
|
|
288
354
|
const uiDir = findPackageDir(root, uiPackage);
|
|
289
|
-
if (!uiDir)
|
|
355
|
+
if (!uiDir) return null;
|
|
290
356
|
const uiPkg = JSON.parse(readFileSync(path3.join(uiDir, "package.json"), "utf8"));
|
|
291
357
|
const typeEntries = /* @__PURE__ */ new Set();
|
|
292
358
|
const mainTypes = uiPkg.types ?? uiPkg.typings ?? exportTypes(uiPkg.exports?.["."] ?? uiPkg.exports);
|
|
@@ -327,27 +393,7 @@ function loadGenesis(root, config) {
|
|
|
327
393
|
const isTypeOnly = (n) => typeDecls.has(n) && !valueDecls.has(n);
|
|
328
394
|
const values = new Set([...exportNames].filter((n) => !isTypeOnly(n)));
|
|
329
395
|
const components = [...values].filter((n) => /^[A-Z][A-Za-z0-9]*$/.test(n) && !(n.length > 2 && n === n.toUpperCase()) && !NON_COMPONENT_SUFFIX.test(n)).sort();
|
|
330
|
-
|
|
331
|
-
const themeFiles = resolveThemeFiles(root, config, uiDir);
|
|
332
|
-
for (const file of themeFiles) for (const t of declaredTokens(readFileSync(file, "utf8"))) tokens.add(t);
|
|
333
|
-
const byLower = new Map(components.map((c) => [c.toLowerCase(), c]));
|
|
334
|
-
const rawTags = /* @__PURE__ */ new Map();
|
|
335
|
-
for (const tag of TAGS) if (byLower.has(tag)) rawTags.set(tag, byLower.get(tag));
|
|
336
|
-
for (const [tag, comp] of Object.entries(TAG_ALIASES)) if (values.has(comp)) rawTags.set(tag, comp);
|
|
337
|
-
for (const [tag, comp] of Object.entries(config.rawTags ?? {})) {
|
|
338
|
-
if (comp === false) rawTags.delete(tag);
|
|
339
|
-
else rawTags.set(tag, comp);
|
|
340
|
-
}
|
|
341
|
-
return {
|
|
342
|
-
uiPackage,
|
|
343
|
-
uiVersion: String(uiPkg.version ?? "unknown"),
|
|
344
|
-
exports: exportNames,
|
|
345
|
-
values,
|
|
346
|
-
components,
|
|
347
|
-
tokens,
|
|
348
|
-
rawTags,
|
|
349
|
-
palette: loadPalette(root)
|
|
350
|
-
};
|
|
396
|
+
return { dir: uiDir, version: String(uiPkg.version ?? "unknown"), exports: exportNames, values, components };
|
|
351
397
|
}
|
|
352
398
|
function parseExportNames(dts) {
|
|
353
399
|
const names = [];
|
|
@@ -600,6 +646,7 @@ function findColorFunctions(line) {
|
|
|
600
646
|
|
|
601
647
|
// src/doctor/scan.ts
|
|
602
648
|
var DEFAULT_SRC = ["src"];
|
|
649
|
+
var DEFAULT_NATIVE_SRC = ["app", "src", "components"];
|
|
603
650
|
var DEFAULT_EXTENSIONS = [".ts", ".tsx", ".js", ".jsx", ".mts", ".cts", ".css"];
|
|
604
651
|
var DEFAULT_IGNORE = [
|
|
605
652
|
"**/*.d.ts",
|
|
@@ -637,7 +684,7 @@ function scanFiles(root, config) {
|
|
|
637
684
|
}
|
|
638
685
|
}
|
|
639
686
|
};
|
|
640
|
-
for (const src of config.src ?? DEFAULT_SRC) {
|
|
687
|
+
for (const src of config.src ?? (config.packs?.includes("native") ? DEFAULT_NATIVE_SRC : DEFAULT_SRC)) {
|
|
641
688
|
const abs = path3.resolve(root, src);
|
|
642
689
|
if (!existsSync(abs)) continue;
|
|
643
690
|
if (statSync(abs).isDirectory()) walk(abs);
|
|
@@ -793,7 +840,18 @@ var BUILTIN_RULES = [
|
|
|
793
840
|
"raw-color",
|
|
794
841
|
"undefined-token",
|
|
795
842
|
"shadowed-export",
|
|
796
|
-
"version-skew"
|
|
843
|
+
"version-skew",
|
|
844
|
+
// native pack
|
|
845
|
+
"native-raw-primitive",
|
|
846
|
+
"native-literal-color",
|
|
847
|
+
"native-custom-header",
|
|
848
|
+
"native-screen-layout",
|
|
849
|
+
"store-readiness",
|
|
850
|
+
// supabase pack
|
|
851
|
+
"migration-grants",
|
|
852
|
+
"migration-rls",
|
|
853
|
+
"migration-definer-search-path",
|
|
854
|
+
"migration-edited"
|
|
797
855
|
];
|
|
798
856
|
var DEFAULT_LOCAL_PRIMITIVE_DIRS = ["src/components/ui"];
|
|
799
857
|
var STARTER_LEFTOVERS = ["components.json", "src/lib/utils.ts"];
|
|
@@ -869,7 +927,10 @@ function checkColors(ctx) {
|
|
|
869
927
|
`(?<![\\w-])(?:${COLOR_UTILITIES})-(?:${ctx.genesis.palette.join("|")})(?:-\\d{2,3})?(?:\\/\\d{1,3})?(?![\\w-])`,
|
|
870
928
|
"g"
|
|
871
929
|
);
|
|
930
|
+
const native = ctx.config.packs?.includes("native") ?? false;
|
|
931
|
+
const themeRoles = ctx.genesis.values.has("useThemeRoles") ? "a theme role (useThemeRoles())" : "a theme role";
|
|
872
932
|
for (const file of ctx.files) {
|
|
933
|
+
const nativeCode = native && SCRIPT_EXTS.has(file.ext);
|
|
873
934
|
file.code.split("\n").forEach((text, i) => {
|
|
874
935
|
const line = i + 1;
|
|
875
936
|
for (const m of text.matchAll(palette)) {
|
|
@@ -883,6 +944,16 @@ function checkColors(ctx) {
|
|
|
883
944
|
for (const hit of [...findHexLiterals(text), ...findColorFunctions(text)]) {
|
|
884
945
|
const at = hit.column - 1;
|
|
885
946
|
if (arbitrary.some(([a, b]) => at >= a && at < b)) continue;
|
|
947
|
+
if (nativeCode) {
|
|
948
|
+
ctx.report({
|
|
949
|
+
rule: "native-literal-color",
|
|
950
|
+
file: file.path,
|
|
951
|
+
line,
|
|
952
|
+
subject: hit.literal,
|
|
953
|
+
message: `hardcodes the color ${hit.literal}; use ${themeRoles}, a token className (bg-primary, text-muted-foreground) or PlatformColor(...)`
|
|
954
|
+
});
|
|
955
|
+
continue;
|
|
956
|
+
}
|
|
886
957
|
ctx.report({ rule: "raw-color", file: file.path, line, subject: hit.literal, message: `hardcodes the color ${hit.literal}; color values come from Genesis tokens` });
|
|
887
958
|
}
|
|
888
959
|
});
|
|
@@ -939,6 +1010,751 @@ function unusedComponents(ctx) {
|
|
|
939
1010
|
}
|
|
940
1011
|
return ctx.genesis.components.filter((c) => !used.has(c));
|
|
941
1012
|
}
|
|
1013
|
+
|
|
1014
|
+
// ../../scripts/lib/native-primitives.mjs
|
|
1015
|
+
var NATIVE_WRAPPED_PRIMITIVES = Object.freeze({
|
|
1016
|
+
Modal: Object.freeze(["NativeDialog", "NativeSheet", "NativeDrawer"]),
|
|
1017
|
+
ActivityIndicator: Object.freeze(["NativeSkeleton", "NativeProgress"])
|
|
1018
|
+
});
|
|
1019
|
+
function wrappedPrimitivesIn(namedImports) {
|
|
1020
|
+
return namedImports.split(",").map((n) => n.trim()).filter((n) => n && !/^type\s/.test(n)).map((n) => n.split(/\s+as\s+/)[0].trim()).filter((n) => n && Object.hasOwn(NATIVE_WRAPPED_PRIMITIVES, n));
|
|
1021
|
+
}
|
|
1022
|
+
var PRIVACY_APIS = {
|
|
1023
|
+
"@react-native-async-storage/async-storage": [
|
|
1024
|
+
{ NSPrivacyAccessedAPIType: "NSPrivacyAccessedAPICategoryFileTimestamp", NSPrivacyAccessedAPITypeReasons: ["C617.1"] }
|
|
1025
|
+
]
|
|
1026
|
+
};
|
|
1027
|
+
function privacyApisFor(dependencies2) {
|
|
1028
|
+
return Object.keys(PRIVACY_APIS).filter((pkg) => pkg in dependencies2).flatMap((pkg) => PRIVACY_APIS[pkg]);
|
|
1029
|
+
}
|
|
1030
|
+
|
|
1031
|
+
// src/doctor/native.ts
|
|
1032
|
+
var SCRIPT_EXTS2 = /* @__PURE__ */ new Set([".ts", ".tsx", ".js", ".jsx", ".mts", ".cts", ".mjs", ".cjs"]);
|
|
1033
|
+
var JSX_EXTS2 = /* @__PURE__ */ new Set([".tsx", ".jsx"]);
|
|
1034
|
+
var RESOLVE_EXTS = [".tsx", ".ts", ".jsx", ".js"];
|
|
1035
|
+
var LAYOUT_NAME = /(?:Page|Screen|ScreenContainer)$/;
|
|
1036
|
+
var NON_SCREEN_ROUTE = /(?:^|\/)(?:_layout|\+html|\+native-intent|\+middleware)\.[jt]sx?$|\+api\.[jt]sx?$/;
|
|
1037
|
+
var PART_HEADER = /(?:Section|List|Card|Dialog|Table|Group|Column|Row|Cell|Accordion|Sheet|Drawer|Modal|Popover|Menu|Panel|Form)Header$/;
|
|
1038
|
+
var HIDES_HEADER = /\bheaderShown\s*(?::|=\s*\{)\s*false\b/;
|
|
1039
|
+
function nativePackage(ctx) {
|
|
1040
|
+
const pkg = readPackageExports(ctx.root, NATIVE_UI_PACKAGE);
|
|
1041
|
+
if (!pkg) throw new DoctorConfigError(`the native pack needs ${NATIVE_UI_PACKAGE}; install it, or remove "native" from doctor.packs`);
|
|
1042
|
+
return pkg;
|
|
1043
|
+
}
|
|
1044
|
+
function nativeLayouts(pkg) {
|
|
1045
|
+
return pkg.components.filter((n) => LAYOUT_NAME.test(n));
|
|
1046
|
+
}
|
|
1047
|
+
function checkNativePack(ctx) {
|
|
1048
|
+
const pkg = nativePackage(ctx);
|
|
1049
|
+
checkRawPrimitives(ctx, pkg);
|
|
1050
|
+
checkCustomHeaders(ctx, pkg);
|
|
1051
|
+
checkScreenLayouts(ctx, pkg);
|
|
1052
|
+
checkStoreReadiness(ctx);
|
|
1053
|
+
}
|
|
1054
|
+
var RN = String.raw`["']react-native["']`;
|
|
1055
|
+
function checkRawPrimitives(ctx, pkg) {
|
|
1056
|
+
const wrapped = Object.keys(NATIVE_WRAPPED_PRIMITIVES);
|
|
1057
|
+
const named = [
|
|
1058
|
+
// import { Modal } / import RN, { Modal }; `import type { … }` doesn't match.
|
|
1059
|
+
new RegExp(String.raw`\bimport\s+(?:[\w$]+\s*,\s*)?\{([^}]*)\}\s*from\s*${RN}`, "g"),
|
|
1060
|
+
new RegExp(String.raw`\bexport\s+\{([^}]*)\}\s*from\s*${RN}`, "g"),
|
|
1061
|
+
new RegExp(String.raw`\b(?:const|let|var)\s*\{([^}]*)\}\s*=\s*require\(\s*${RN}\s*\)`, "g")
|
|
1062
|
+
];
|
|
1063
|
+
const namespaces = [
|
|
1064
|
+
new RegExp(String.raw`\bimport\s+\*\s+as\s+([\w$]+)\s+from\s*${RN}`, "g"),
|
|
1065
|
+
new RegExp(String.raw`\b(?:const|let|var)\s+([\w$]+)\s*=\s*require\(\s*${RN}\s*\)`, "g")
|
|
1066
|
+
];
|
|
1067
|
+
const member = new RegExp(String.raw`\brequire\(\s*${RN}\s*\)\.(${wrapped.join("|")})\b`, "g");
|
|
1068
|
+
for (const file of ctx.files) {
|
|
1069
|
+
if (!SCRIPT_EXTS2.has(file.ext)) continue;
|
|
1070
|
+
const code = file.code;
|
|
1071
|
+
const report = (name, at) => {
|
|
1072
|
+
const use = NATIVE_WRAPPED_PRIMITIVES[name].filter((c) => pkg.values.has(c));
|
|
1073
|
+
ctx.report({
|
|
1074
|
+
rule: "native-raw-primitive",
|
|
1075
|
+
file: file.path,
|
|
1076
|
+
line: lineAt(code, at),
|
|
1077
|
+
subject: name,
|
|
1078
|
+
message: `uses ${name} from react-native, which Genesis wraps; use ${use.length ? use.join(" or ") : "the Genesis wrapper"} from ${NATIVE_UI_PACKAGE}`
|
|
1079
|
+
});
|
|
1080
|
+
};
|
|
1081
|
+
for (const re of named) {
|
|
1082
|
+
for (const m of code.matchAll(re)) {
|
|
1083
|
+
for (const name of wrappedPrimitivesIn(m[1].replace(/:/g, " as "))) report(name, m.index + m[0].indexOf(name));
|
|
1084
|
+
}
|
|
1085
|
+
}
|
|
1086
|
+
for (const re of namespaces) {
|
|
1087
|
+
for (const m of code.matchAll(re)) {
|
|
1088
|
+
for (const use of code.matchAll(new RegExp(String.raw`\b${m[1].replace(/\$/g, "\\$")}\.(${wrapped.join("|")})\b`, "g"))) report(use[1], use.index);
|
|
1089
|
+
}
|
|
1090
|
+
}
|
|
1091
|
+
for (const m of code.matchAll(member)) report(m[1], m.index);
|
|
1092
|
+
}
|
|
1093
|
+
}
|
|
1094
|
+
function customElement(code, re, pkg) {
|
|
1095
|
+
for (const m of code.matchAll(re)) {
|
|
1096
|
+
const name = m[1];
|
|
1097
|
+
if (!pkg.values.has(name.split(".")[0]) && !PART_HEADER.test(name)) return { name, index: m.index };
|
|
1098
|
+
}
|
|
1099
|
+
return null;
|
|
1100
|
+
}
|
|
1101
|
+
function ownHeader(code, pkg) {
|
|
1102
|
+
const el = customElement(code, /<([A-Z][\w$]*Header)\b/g, pkg);
|
|
1103
|
+
if (el) return el;
|
|
1104
|
+
const style = /\bstyle=\{\s*styles\.header\s*\}/.exec(code);
|
|
1105
|
+
return style ? { name: "styles.header", index: style.index } : null;
|
|
1106
|
+
}
|
|
1107
|
+
function checkCustomHeaders(ctx, pkg) {
|
|
1108
|
+
const layouts = nativeLayouts(pkg);
|
|
1109
|
+
if (layouts.length === 0) return;
|
|
1110
|
+
const headerWay = pkg.values.has("ScreenContainer") ? `ScreenContainer's header props${pkg.values.has("composeHeaderOptions") ? " (composeHeaderOptions)" : ""}` : `a Genesis layout's header (${layouts.join(", ")})`;
|
|
1111
|
+
const rootDir = routerRoot(ctx);
|
|
1112
|
+
const reported = /* @__PURE__ */ new Set();
|
|
1113
|
+
const hidingLayouts = /* @__PURE__ */ new Map();
|
|
1114
|
+
for (const file of ctx.files) {
|
|
1115
|
+
if (!JSX_EXTS2.has(file.ext)) continue;
|
|
1116
|
+
const code = file.code;
|
|
1117
|
+
const hidden = HIDES_HEADER.exec(code);
|
|
1118
|
+
if (hidden && /(?:^|\/)_layout\.[jt]sx$/.test(file.path)) hidingLayouts.set(path3.posix.dirname(file.path), file.path);
|
|
1119
|
+
const own = hidden ? ownHeader(code, pkg) : null;
|
|
1120
|
+
if (hidden && own) {
|
|
1121
|
+
reported.add(file.path);
|
|
1122
|
+
ctx.report({
|
|
1123
|
+
rule: "native-custom-header",
|
|
1124
|
+
level: "warn",
|
|
1125
|
+
file: file.path,
|
|
1126
|
+
line: lineAt(code, hidden.index),
|
|
1127
|
+
subject: own.name,
|
|
1128
|
+
message: `hides the navigator header and draws its own (${own.name}); use ${headerWay} so the title, back button and large-title behavior stay native`
|
|
1129
|
+
});
|
|
1130
|
+
}
|
|
1131
|
+
const tabBarProp = /<Tabs\b/.test(code) ? /\btabBar\s*=\s*\{/.exec(code) : null;
|
|
1132
|
+
const tabBar = tabBarProp ? { name: "tabBar prop", index: tabBarProp.index } : customElement(code, /<([A-Z][\w$]*TabBar)\b/g, pkg);
|
|
1133
|
+
if (tabBar) {
|
|
1134
|
+
ctx.report({
|
|
1135
|
+
rule: "native-custom-header",
|
|
1136
|
+
level: "warn",
|
|
1137
|
+
file: file.path,
|
|
1138
|
+
line: lineAt(code, tabBar.index),
|
|
1139
|
+
subject: tabBar.name,
|
|
1140
|
+
message: `builds a tab bar by hand (${tabBar.name}); use the router's native <Tabs> bar, themed through Genesis screenOptions`
|
|
1141
|
+
});
|
|
1142
|
+
}
|
|
1143
|
+
}
|
|
1144
|
+
for (const file of ctx.files) {
|
|
1145
|
+
if (!JSX_EXTS2.has(file.ext) || reported.has(file.path) || !file.path.startsWith(`${rootDir}/`) || NON_SCREEN_ROUTE.test(file.path)) continue;
|
|
1146
|
+
const layout = hidingLayouts.get(path3.posix.dirname(file.path));
|
|
1147
|
+
const own = layout ? ownHeader(file.code, pkg) : null;
|
|
1148
|
+
if (!layout || !own) continue;
|
|
1149
|
+
ctx.report({
|
|
1150
|
+
rule: "native-custom-header",
|
|
1151
|
+
level: "warn",
|
|
1152
|
+
file: file.path,
|
|
1153
|
+
line: lineAt(file.code, own.index),
|
|
1154
|
+
subject: own.name,
|
|
1155
|
+
message: `draws its own header (${own.name}) while ${layout} hides the navigator's; use ${headerWay} so the title, back button and large-title behavior stay native`
|
|
1156
|
+
});
|
|
1157
|
+
}
|
|
1158
|
+
}
|
|
1159
|
+
function routerRoot(ctx) {
|
|
1160
|
+
if (ctx.config.native?.routerRoot) return ctx.config.native.routerRoot.replace(/\/+$/, "");
|
|
1161
|
+
return existsSync(path3.join(ctx.root, "src", "app")) ? "src/app" : "app";
|
|
1162
|
+
}
|
|
1163
|
+
function checkScreenLayouts(ctx, pkg) {
|
|
1164
|
+
const layouts = nativeLayouts(pkg);
|
|
1165
|
+
if (layouts.length === 0) return;
|
|
1166
|
+
const rootDir = routerRoot(ctx);
|
|
1167
|
+
if (!existsSync(path3.join(ctx.root, rootDir))) {
|
|
1168
|
+
ctx.report({ rule: "native-screen-layout", level: "warn", file: rootDir, message: `no Expo Router root at ${rootDir}; set doctor.native.routerRoot` });
|
|
1169
|
+
return;
|
|
1170
|
+
}
|
|
1171
|
+
const routes = ctx.files.filter((f) => f.path.startsWith(`${rootDir}/`));
|
|
1172
|
+
if (routes.length === 0) {
|
|
1173
|
+
ctx.report({
|
|
1174
|
+
rule: "native-screen-layout",
|
|
1175
|
+
level: "warn",
|
|
1176
|
+
file: rootDir,
|
|
1177
|
+
message: `no scanned file is under the router root ${rootDir}, so no screen was checked; add it to doctor.src`
|
|
1178
|
+
});
|
|
1179
|
+
return;
|
|
1180
|
+
}
|
|
1181
|
+
const renders = new RegExp(`<(?:${layouts.join("|")}|Redirect)\\b`);
|
|
1182
|
+
const byPath = new Map(ctx.files.map((f) => [f.absolutePath, f]));
|
|
1183
|
+
for (const file of routes) {
|
|
1184
|
+
if (!JSX_EXTS2.has(file.ext) || NON_SCREEN_ROUTE.test(file.path)) continue;
|
|
1185
|
+
if (!/\bexport\s+default\b/.test(file.code) || !/<[A-Za-z]/.test(file.code)) continue;
|
|
1186
|
+
if (renders.test(file.code)) continue;
|
|
1187
|
+
const viaImport = localImports(ctx.root, file).some((abs) => {
|
|
1188
|
+
const target = byPath.get(abs) ?? readSource(abs);
|
|
1189
|
+
return target !== null && renders.test(target.code);
|
|
1190
|
+
});
|
|
1191
|
+
if (viaImport) continue;
|
|
1192
|
+
ctx.report({
|
|
1193
|
+
rule: "native-screen-layout",
|
|
1194
|
+
level: "warn",
|
|
1195
|
+
file: file.path,
|
|
1196
|
+
message: `doesn't render a Genesis screen layout (${layouts.join(", ")}); wrap the screen in one so the header, safe area and scrolling match every other screen`
|
|
1197
|
+
});
|
|
1198
|
+
}
|
|
1199
|
+
}
|
|
1200
|
+
function localImports(root, file) {
|
|
1201
|
+
const out = [];
|
|
1202
|
+
for (const m of file.code.matchAll(/\bfrom\s*["']((?:\.{1,2}|[@~])\/[^"']+)["']/g)) {
|
|
1203
|
+
const spec = m[1];
|
|
1204
|
+
const bases = spec.startsWith(".") ? [path3.resolve(path3.dirname(file.absolutePath), spec)] : [path3.join(root, spec.slice(2)), path3.join(root, "src", spec.slice(2))];
|
|
1205
|
+
for (const base of bases) {
|
|
1206
|
+
const hit = [base, ...RESOLVE_EXTS.map((e) => base + e), ...RESOLVE_EXTS.map((e) => path3.join(base, `index${e}`))].find(
|
|
1207
|
+
(p) => SCRIPT_EXTS2.has(path3.extname(p)) && existsSync(p)
|
|
1208
|
+
);
|
|
1209
|
+
if (hit) {
|
|
1210
|
+
out.push(hit);
|
|
1211
|
+
break;
|
|
1212
|
+
}
|
|
1213
|
+
}
|
|
1214
|
+
}
|
|
1215
|
+
return out;
|
|
1216
|
+
}
|
|
1217
|
+
function readSource(abs) {
|
|
1218
|
+
try {
|
|
1219
|
+
return { code: readFileSync(abs, "utf8") };
|
|
1220
|
+
} catch {
|
|
1221
|
+
return null;
|
|
1222
|
+
}
|
|
1223
|
+
}
|
|
1224
|
+
var PERMISSIONS = [
|
|
1225
|
+
{ module: "expo-camera", key: "NSCameraUsageDescription", option: "cameraPermission" },
|
|
1226
|
+
{ module: "expo-image-picker", key: "NSPhotoLibraryUsageDescription", option: "photosPermission" },
|
|
1227
|
+
{ module: "expo-image-picker", key: "NSCameraUsageDescription", option: "cameraPermission", maybe: "takes photos with the camera" },
|
|
1228
|
+
{ module: "expo-media-library", key: "NSPhotoLibraryUsageDescription", option: "photosPermission" },
|
|
1229
|
+
{ module: "expo-location", key: "NSLocationWhenInUseUsageDescription", option: "locationWhenInUsePermission" },
|
|
1230
|
+
{ module: "expo-av", key: "NSMicrophoneUsageDescription", option: "microphonePermission", maybe: "records audio" },
|
|
1231
|
+
{ module: "expo-audio", key: "NSMicrophoneUsageDescription", option: "microphonePermission", maybe: "records audio" },
|
|
1232
|
+
{ module: "expo-contacts", key: "NSContactsUsageDescription", option: "contactsPermission" },
|
|
1233
|
+
{ module: "expo-local-authentication", key: "NSFaceIDUsageDescription", option: "faceIDPermission" }
|
|
1234
|
+
];
|
|
1235
|
+
var SOCIAL_SIGN_IN = ["@react-native-google-signin/google-signin", "react-native-fbsdk-next"];
|
|
1236
|
+
var WEAK_SOCIAL_SIGN_IN = ["expo-auth-session"];
|
|
1237
|
+
var APPLE_SIGN_IN = ["expo-apple-authentication", "@invertase/react-native-apple-authentication"];
|
|
1238
|
+
var EXPO_CONFIGS = ["app.json", "app.config.json", "app.config.ts", "app.config.js", "app.config.mjs", "app.config.cjs"];
|
|
1239
|
+
var SUPABASE_SIGN_IN = /\bsignInWith(?:OAuth|IdToken)\s*\(\s*\{\s*provider\s*:\s*["']([\w-]+)["']/g;
|
|
1240
|
+
var GENESIS_PLUGIN = "@marktiderman/genesis-cli";
|
|
1241
|
+
var GENESIS_PLUGIN_TEXT = /["']@marktiderman\/genesis-cli(?:\/expo)?["']|\bwithGenesis\s*\(/;
|
|
1242
|
+
var GENESIS_PLUGIN_IMPORT = /\bfrom\s*["']@marktiderman\/genesis-cli[^"']*["']|\b(?:require|import)\s*\(\s*["']@marktiderman\/genesis-cli[^"']*["']\s*\)/g;
|
|
1243
|
+
function readExpoConfigs(root) {
|
|
1244
|
+
const out = [];
|
|
1245
|
+
for (const name of EXPO_CONFIGS) {
|
|
1246
|
+
const abs = path3.join(root, name);
|
|
1247
|
+
if (!existsSync(abs)) continue;
|
|
1248
|
+
const text = readFileSync(abs, "utf8");
|
|
1249
|
+
let json = null;
|
|
1250
|
+
if (name.endsWith(".json")) {
|
|
1251
|
+
try {
|
|
1252
|
+
const raw = JSON.parse(text);
|
|
1253
|
+
json = raw.expo ?? raw;
|
|
1254
|
+
} catch (err) {
|
|
1255
|
+
throw new DoctorConfigError(`${name} is not valid JSON: ${err.message}`);
|
|
1256
|
+
}
|
|
1257
|
+
}
|
|
1258
|
+
out.push({ file: name, json, text });
|
|
1259
|
+
}
|
|
1260
|
+
return out;
|
|
1261
|
+
}
|
|
1262
|
+
function get(obj, keys) {
|
|
1263
|
+
let cur = obj;
|
|
1264
|
+
for (const k of keys) {
|
|
1265
|
+
if (!cur || typeof cur !== "object") return void 0;
|
|
1266
|
+
cur = cur[k];
|
|
1267
|
+
}
|
|
1268
|
+
return cur;
|
|
1269
|
+
}
|
|
1270
|
+
function pluginOptions(json, module) {
|
|
1271
|
+
const plugins = json?.plugins;
|
|
1272
|
+
if (!Array.isArray(plugins)) return null;
|
|
1273
|
+
for (const p of plugins) {
|
|
1274
|
+
if (p === module) return {};
|
|
1275
|
+
if (Array.isArray(p) && p[0] === module) return p[1] && typeof p[1] === "object" ? p[1] : {};
|
|
1276
|
+
}
|
|
1277
|
+
return null;
|
|
1278
|
+
}
|
|
1279
|
+
function dependencies(root) {
|
|
1280
|
+
const file = path3.join(root, "package.json");
|
|
1281
|
+
if (!existsSync(file)) return /* @__PURE__ */ new Set();
|
|
1282
|
+
const pkg = JSON.parse(readFileSync(file, "utf8"));
|
|
1283
|
+
return /* @__PURE__ */ new Set([...Object.keys(pkg.dependencies ?? {}), ...Object.keys(pkg.devDependencies ?? {})]);
|
|
1284
|
+
}
|
|
1285
|
+
function runtimeDependencies(root) {
|
|
1286
|
+
const file = path3.join(root, "package.json");
|
|
1287
|
+
if (!existsSync(file)) return {};
|
|
1288
|
+
return JSON.parse(readFileSync(file, "utf8")).dependencies ?? {};
|
|
1289
|
+
}
|
|
1290
|
+
function checkStoreReadiness(ctx) {
|
|
1291
|
+
const configs = readExpoConfigs(ctx.root);
|
|
1292
|
+
if (configs.length === 0) {
|
|
1293
|
+
ctx.report({ rule: "store-readiness", level: "warn", file: "app.json", message: "no app.json or app.config.* found; the store checks read the Expo config" });
|
|
1294
|
+
return;
|
|
1295
|
+
}
|
|
1296
|
+
const file = configs[0].file;
|
|
1297
|
+
const deps = dependencies(ctx.root);
|
|
1298
|
+
const has = (keys, word) => configs.some((c) => c.json ? get(c.json, keys) !== void 0 : new RegExp(`\\b${word}\\b`).test(c.text));
|
|
1299
|
+
const genesisPluginDoes = (option) => configs.some((c) => {
|
|
1300
|
+
if (c.json) {
|
|
1301
|
+
const options = pluginOptions(c.json, GENESIS_PLUGIN) ?? pluginOptions(c.json, `${GENESIS_PLUGIN}/expo`);
|
|
1302
|
+
return options !== null && options[option] !== false;
|
|
1303
|
+
}
|
|
1304
|
+
const listed = c.text.replace(GENESIS_PLUGIN_IMPORT, "");
|
|
1305
|
+
return GENESIS_PLUGIN_TEXT.test(listed) && !new RegExp(`\\b${option}\\s*:\\s*false\\b`).test(c.text);
|
|
1306
|
+
});
|
|
1307
|
+
const exportCompliance = has(["ios", "config", "usesNonExemptEncryption"], "usesNonExemptEncryption") || has(["ios", "infoPlist", "ITSAppUsesNonExemptEncryption"], "ITSAppUsesNonExemptEncryption") || genesisPluginDoes("exportCompliance");
|
|
1308
|
+
if (!exportCompliance) {
|
|
1309
|
+
ctx.report({
|
|
1310
|
+
rule: "store-readiness",
|
|
1311
|
+
level: "warn",
|
|
1312
|
+
file,
|
|
1313
|
+
subject: "usesNonExemptEncryption",
|
|
1314
|
+
message: "sets neither ios.config.usesNonExemptEncryption nor ios.infoPlist.ITSAppUsesNonExemptEncryption; set it (false for HTTPS-only apps) so App Store Connect doesn't hold every build for the export-compliance question"
|
|
1315
|
+
});
|
|
1316
|
+
}
|
|
1317
|
+
const social = SOCIAL_SIGN_IN.filter((d) => deps.has(d));
|
|
1318
|
+
let apple = APPLE_SIGN_IN.some((d) => deps.has(d));
|
|
1319
|
+
for (const f of ctx.files) {
|
|
1320
|
+
for (const m of f.code.matchAll(SUPABASE_SIGN_IN)) {
|
|
1321
|
+
if (m[1] === "apple") apple = true;
|
|
1322
|
+
else if (!social.includes(`Supabase ${m[1]} sign-in`)) social.push(`Supabase ${m[1]} sign-in`);
|
|
1323
|
+
}
|
|
1324
|
+
}
|
|
1325
|
+
if (social.length > 0 && !apple) {
|
|
1326
|
+
const weak = WEAK_SOCIAL_SIGN_IN.filter((d) => deps.has(d));
|
|
1327
|
+
ctx.report({
|
|
1328
|
+
rule: "store-readiness",
|
|
1329
|
+
level: "warn",
|
|
1330
|
+
file: "package.json",
|
|
1331
|
+
subject: "sign-in-with-apple",
|
|
1332
|
+
message: `offers third-party sign-in (${[...social, ...weak].join(", ")}) and no Sign in with Apple. App Store guideline 4.8 asks for an equivalent login that limits data collection to name and email, lets people keep their email private and doesn't track them; Sign in with Apple (expo-apple-authentication, or Supabase's apple provider) is the usual one. If another option qualifies, allow this with the reason.`
|
|
1333
|
+
});
|
|
1334
|
+
}
|
|
1335
|
+
const generic = /* @__PURE__ */ new Map();
|
|
1336
|
+
for (const p of PERMISSIONS) {
|
|
1337
|
+
if (!deps.has(p.module)) continue;
|
|
1338
|
+
const set = configs.some((c) => {
|
|
1339
|
+
if (!c.json) return new RegExp(`\\b(?:${p.key}|${p.option})\\b`).test(c.text);
|
|
1340
|
+
const plist = get(c.json, ["ios", "infoPlist", p.key]);
|
|
1341
|
+
const option = pluginOptions(c.json, p.module)?.[p.option];
|
|
1342
|
+
return typeof plist === "string" && plist.trim() !== "" || typeof option === "string" && option.trim() !== "" || option === false;
|
|
1343
|
+
});
|
|
1344
|
+
if (!set) generic.set(p.key, [...generic.get(p.key) ?? [], `${p.module}${p.maybe ? `, if the app ${p.maybe}` : ""}`]);
|
|
1345
|
+
}
|
|
1346
|
+
for (const [key, modules] of generic) {
|
|
1347
|
+
const opt = PERMISSIONS.find((p) => p.key === key).option;
|
|
1348
|
+
ctx.report({
|
|
1349
|
+
rule: "store-readiness",
|
|
1350
|
+
level: "warn",
|
|
1351
|
+
file,
|
|
1352
|
+
subject: key,
|
|
1353
|
+
message: `leaves ${key} to Expo's generic default string (${modules.join("; ")}), and App Review rejects generic purpose strings; set the plugin's ${opt} (or ios.infoPlist.${key}) to a sentence saying why the app needs it, or ${opt}: false if it doesn't`
|
|
1354
|
+
});
|
|
1355
|
+
}
|
|
1356
|
+
const pluginManifest = genesisPluginDoes("privacyManifest") && privacyApisFor(runtimeDependencies(ctx.root)).length > 0;
|
|
1357
|
+
if (!has(["ios", "privacyManifests"], "privacyManifests") && !pluginManifest) {
|
|
1358
|
+
ctx.report({
|
|
1359
|
+
rule: "store-readiness",
|
|
1360
|
+
level: "warn",
|
|
1361
|
+
file,
|
|
1362
|
+
subject: "privacyManifests",
|
|
1363
|
+
message: "has no ios.privacyManifests; declare the required-reason APIs the app uses (NSPrivacyAccessedAPITypes) so uploads aren't rejected for a missing privacy manifest"
|
|
1364
|
+
});
|
|
1365
|
+
}
|
|
1366
|
+
}
|
|
1367
|
+
var DEFAULT_MIGRATIONS = "supabase/migrations";
|
|
1368
|
+
var DEFAULT_BASE = "origin/main";
|
|
1369
|
+
var DEFAULT_EXPOSED = ["public"];
|
|
1370
|
+
function sqlStatements(text) {
|
|
1371
|
+
const out = [];
|
|
1372
|
+
let buf = "";
|
|
1373
|
+
let bodies = [];
|
|
1374
|
+
let line = 1;
|
|
1375
|
+
let start = 0;
|
|
1376
|
+
const flush = () => {
|
|
1377
|
+
const sql = buf.replace(/\s+/g, " ").trim().toLowerCase();
|
|
1378
|
+
if (sql) out.push({ sql, line: start, bodies });
|
|
1379
|
+
buf = "";
|
|
1380
|
+
bodies = [];
|
|
1381
|
+
start = 0;
|
|
1382
|
+
};
|
|
1383
|
+
const put = (s) => {
|
|
1384
|
+
if (!start && /\S/.test(s)) start = line;
|
|
1385
|
+
buf += s;
|
|
1386
|
+
};
|
|
1387
|
+
let i = 0;
|
|
1388
|
+
while (i < text.length) {
|
|
1389
|
+
const ch = text[i];
|
|
1390
|
+
const two = text.slice(i, i + 2);
|
|
1391
|
+
if (ch === "\n") {
|
|
1392
|
+
buf += " ";
|
|
1393
|
+
line++;
|
|
1394
|
+
i++;
|
|
1395
|
+
} else if (two === "--") {
|
|
1396
|
+
while (i < text.length && text[i] !== "\n") i++;
|
|
1397
|
+
} else if (two === "/*") {
|
|
1398
|
+
let depth = 0;
|
|
1399
|
+
while (i < text.length) {
|
|
1400
|
+
if (text.startsWith("/*", i)) {
|
|
1401
|
+
depth++;
|
|
1402
|
+
i += 2;
|
|
1403
|
+
} else if (text.startsWith("*/", i)) {
|
|
1404
|
+
depth--;
|
|
1405
|
+
i += 2;
|
|
1406
|
+
if (depth === 0) break;
|
|
1407
|
+
} else {
|
|
1408
|
+
if (text[i] === "\n") line++;
|
|
1409
|
+
i++;
|
|
1410
|
+
}
|
|
1411
|
+
}
|
|
1412
|
+
buf += " ";
|
|
1413
|
+
} else if (ch === "'") {
|
|
1414
|
+
const escapes = /[eE]/.test(text[i - 1] ?? "") && !/[\w$]/.test(text[i - 2] ?? "");
|
|
1415
|
+
put("'");
|
|
1416
|
+
i++;
|
|
1417
|
+
while (i < text.length) {
|
|
1418
|
+
if (escapes && text[i] === "\\") i += 2;
|
|
1419
|
+
else if (text[i] === "'" && text[i + 1] === "'") i += 2;
|
|
1420
|
+
else if (text[i] === "'") break;
|
|
1421
|
+
else {
|
|
1422
|
+
if (text[i] === "\n") line++;
|
|
1423
|
+
i++;
|
|
1424
|
+
}
|
|
1425
|
+
}
|
|
1426
|
+
put("'");
|
|
1427
|
+
i++;
|
|
1428
|
+
} else if (ch === '"') {
|
|
1429
|
+
i++;
|
|
1430
|
+
while (i < text.length && text[i] !== '"') put(text[i++]);
|
|
1431
|
+
i++;
|
|
1432
|
+
} else if (ch === "$" && !/[\w$]/.test(text[i - 1] ?? "") && /^\$(?:[A-Za-z_]\w*)?\$/.test(text.slice(i))) {
|
|
1433
|
+
const tag = /^\$(?:[A-Za-z_]\w*)?\$/.exec(text.slice(i))[0];
|
|
1434
|
+
const end = text.indexOf(tag, i + tag.length);
|
|
1435
|
+
const stop = end === -1 ? text.length : end + tag.length;
|
|
1436
|
+
bodies.push(text.slice(i + tag.length, end === -1 ? text.length : end).toLowerCase());
|
|
1437
|
+
for (let k = i; k < stop; k++) if (text[k] === "\n") line++;
|
|
1438
|
+
put(`${tag} ${tag}`);
|
|
1439
|
+
i = stop;
|
|
1440
|
+
} else if (ch === ";") {
|
|
1441
|
+
flush();
|
|
1442
|
+
i++;
|
|
1443
|
+
} else {
|
|
1444
|
+
put(ch);
|
|
1445
|
+
i++;
|
|
1446
|
+
}
|
|
1447
|
+
}
|
|
1448
|
+
flush();
|
|
1449
|
+
return out;
|
|
1450
|
+
}
|
|
1451
|
+
function qualify(name) {
|
|
1452
|
+
const n = name.trim().toLowerCase();
|
|
1453
|
+
return n.includes(".") ? n : `public.${n}`;
|
|
1454
|
+
}
|
|
1455
|
+
var schemaOf = (name) => name.split(".")[0];
|
|
1456
|
+
function parenthesized(sql, open) {
|
|
1457
|
+
let depth = 0;
|
|
1458
|
+
for (let k = open; k < sql.length; k++) {
|
|
1459
|
+
if (sql[k] === "(") depth++;
|
|
1460
|
+
else if (sql[k] === ")" && --depth === 0) return { inner: sql.slice(open + 1, k), end: k + 1 };
|
|
1461
|
+
}
|
|
1462
|
+
return { inner: sql.slice(open + 1), end: sql.length };
|
|
1463
|
+
}
|
|
1464
|
+
function stripParens(s) {
|
|
1465
|
+
let out = "";
|
|
1466
|
+
let depth = 0;
|
|
1467
|
+
for (const c of s) {
|
|
1468
|
+
if (c === "(") depth++;
|
|
1469
|
+
else if (c === ")") depth = Math.max(0, depth - 1);
|
|
1470
|
+
else if (depth === 0) out += c;
|
|
1471
|
+
}
|
|
1472
|
+
return out;
|
|
1473
|
+
}
|
|
1474
|
+
function splitTop(s) {
|
|
1475
|
+
const parts = [];
|
|
1476
|
+
let depth = 0;
|
|
1477
|
+
let cur = "";
|
|
1478
|
+
for (const c of s) {
|
|
1479
|
+
if (c === "(") depth++;
|
|
1480
|
+
if (c === ")") depth--;
|
|
1481
|
+
if (c === "," && depth === 0) {
|
|
1482
|
+
parts.push(cur);
|
|
1483
|
+
cur = "";
|
|
1484
|
+
} else cur += c;
|
|
1485
|
+
}
|
|
1486
|
+
if (cur.trim()) parts.push(cur);
|
|
1487
|
+
return parts.map((p) => p.trim()).filter(Boolean);
|
|
1488
|
+
}
|
|
1489
|
+
var TYPE_ALIASES = {
|
|
1490
|
+
int: "integer",
|
|
1491
|
+
int4: "integer",
|
|
1492
|
+
int8: "bigint",
|
|
1493
|
+
int2: "smallint",
|
|
1494
|
+
bool: "boolean",
|
|
1495
|
+
varchar: "character varying",
|
|
1496
|
+
timestamptz: "timestamp with time zone",
|
|
1497
|
+
float8: "double precision"
|
|
1498
|
+
};
|
|
1499
|
+
var MULTIWORD_TYPE = /^(?:double precision|character varying|character|bit varying|timestamp|time|interval)\b/;
|
|
1500
|
+
function argTypes(args) {
|
|
1501
|
+
const types = [];
|
|
1502
|
+
for (const raw of splitTop(args)) {
|
|
1503
|
+
let tokens = stripParens(raw.replace(/\s+(?:default\b|=).*$/, "")).trim().split(/\s+/).filter(Boolean);
|
|
1504
|
+
const mode = tokens[0];
|
|
1505
|
+
if (mode === "out") continue;
|
|
1506
|
+
if (mode === "in" || mode === "inout" || mode === "variadic") tokens = tokens.slice(1);
|
|
1507
|
+
const joined = tokens.join(" ");
|
|
1508
|
+
const type = tokens.length > 1 && !MULTIWORD_TYPE.test(joined) ? tokens.slice(1).join(" ") : joined;
|
|
1509
|
+
types.push(TYPE_ALIASES[type] ?? type);
|
|
1510
|
+
}
|
|
1511
|
+
return types;
|
|
1512
|
+
}
|
|
1513
|
+
function git(root, args) {
|
|
1514
|
+
const r = spawnSync("git", args, { cwd: root, encoding: "utf8" });
|
|
1515
|
+
return r.status === 0 ? r.stdout : null;
|
|
1516
|
+
}
|
|
1517
|
+
function gitView(root, dir, base) {
|
|
1518
|
+
if (git(root, ["rev-parse", "--is-inside-work-tree"])?.trim() !== "true") return { reason: "not a git repository", repo: false };
|
|
1519
|
+
if (git(root, ["rev-parse", "--verify", "--quiet", `${base}^{commit}`]) === null) {
|
|
1520
|
+
return { reason: `the git ref ${base} isn't available (fetch it, or set doctor.supabase.base)`, repo: true };
|
|
1521
|
+
}
|
|
1522
|
+
const mergeBase = git(root, ["merge-base", "HEAD", base])?.trim();
|
|
1523
|
+
if (!mergeBase) return { reason: `HEAD has no merge base with ${base} (a shallow clone? fetch with depth 0)`, repo: true };
|
|
1524
|
+
const diff = git(root, ["diff", "--relative", "--name-status", "-M", mergeBase, "--", dir]);
|
|
1525
|
+
const untracked = git(root, ["ls-files", "--others", "--exclude-standard", "--", dir]);
|
|
1526
|
+
if (diff === null || untracked === null) return { reason: `git diff against ${base} failed`, repo: true };
|
|
1527
|
+
const sql = (p) => p !== void 0 && p.endsWith(".sql");
|
|
1528
|
+
const touched = new Set(untracked.split("\n").filter(sql));
|
|
1529
|
+
const edited = [];
|
|
1530
|
+
for (const row of diff.split("\n").filter(Boolean)) {
|
|
1531
|
+
const [status, a, b] = row.split(" ");
|
|
1532
|
+
if (status.startsWith("R")) {
|
|
1533
|
+
if (sql(b)) touched.add(b);
|
|
1534
|
+
if (sql(a)) edited.push({ file: a, status: "renamed" });
|
|
1535
|
+
continue;
|
|
1536
|
+
}
|
|
1537
|
+
if (!sql(a)) continue;
|
|
1538
|
+
if (status.startsWith("A")) touched.add(a);
|
|
1539
|
+
else if (status.startsWith("M") || status.startsWith("T")) {
|
|
1540
|
+
touched.add(a);
|
|
1541
|
+
edited.push({ file: a, status: "modified" });
|
|
1542
|
+
} else if (status.startsWith("D")) edited.push({ file: a, status: "deleted" });
|
|
1543
|
+
}
|
|
1544
|
+
return { touched, edited };
|
|
1545
|
+
}
|
|
1546
|
+
function checkSupabasePack(ctx) {
|
|
1547
|
+
const settings = ctx.config.supabase ?? {};
|
|
1548
|
+
const dir = settings.migrations ?? DEFAULT_MIGRATIONS;
|
|
1549
|
+
const abs = path3.join(ctx.root, dir);
|
|
1550
|
+
if (!existsSync(abs)) throw new DoctorConfigError(`the supabase pack reads ${dir}, which doesn't exist; set doctor.supabase.migrations`);
|
|
1551
|
+
const migrations = readdirSync(abs).filter((n) => n.endsWith(".sql")).sort().map((n) => ({ file: `${dir}/${n}`, statements: sqlStatements(readFileSync(path3.join(abs, n), "utf8")) }));
|
|
1552
|
+
const exposed = new Set((settings.exposedSchemas ?? DEFAULT_EXPOSED).map((s) => s.toLowerCase()));
|
|
1553
|
+
const base = settings.base ?? DEFAULT_BASE;
|
|
1554
|
+
const view = gitView(ctx.root, dir, base);
|
|
1555
|
+
if ("reason" in view) {
|
|
1556
|
+
if (view.repo) ctx.report({ rule: "migration-edited", level: "warn", file: dir, message: `can't check for edited migrations: ${view.reason}` });
|
|
1557
|
+
} else {
|
|
1558
|
+
for (const e of view.edited) {
|
|
1559
|
+
ctx.report({
|
|
1560
|
+
rule: "migration-edited",
|
|
1561
|
+
file: e.file,
|
|
1562
|
+
subject: e.file,
|
|
1563
|
+
message: `${e.status === "modified" ? "edits" : e.status === "deleted" ? "deletes" : "renames"} a migration that already exists on ${base}, so it has been applied; put the change in a new migration instead`
|
|
1564
|
+
});
|
|
1565
|
+
}
|
|
1566
|
+
}
|
|
1567
|
+
const since = settings.since;
|
|
1568
|
+
const afterSince = (file) => since === void 0 || path3.posix.basename(file) >= since;
|
|
1569
|
+
if ("reason" in view && since === void 0) {
|
|
1570
|
+
ctx.report({
|
|
1571
|
+
rule: "migration-grants",
|
|
1572
|
+
level: "warn",
|
|
1573
|
+
file: dir,
|
|
1574
|
+
message: `skipped: can't tell new migrations from applied ones (${view.reason}); fetch the base ref (CI: fetch-depth 0) or set doctor.supabase.since`
|
|
1575
|
+
});
|
|
1576
|
+
} else {
|
|
1577
|
+
const isNew = (file) => afterSince(file) && ("reason" in view || view.touched.has(file));
|
|
1578
|
+
checkGrants(ctx, migrations.filter((m) => isNew(m.file)), exposed);
|
|
1579
|
+
}
|
|
1580
|
+
checkRls(ctx, migrations, exposed);
|
|
1581
|
+
checkDefinerSearchPath(ctx, migrations);
|
|
1582
|
+
}
|
|
1583
|
+
function granteesOf(s) {
|
|
1584
|
+
return s.replace(/\s+granted by .*$/, "").replace(/\s+with grant option$/, "").split(/\s*,\s*/).map((r) => r.replace(/^group\s+/, "").trim()).filter(Boolean);
|
|
1585
|
+
}
|
|
1586
|
+
function checkGrants(ctx, migrations, exposed) {
|
|
1587
|
+
const fix = "grant by name (grant execute on function schema.fn(args) to role) so an earlier revoke survives";
|
|
1588
|
+
const open = (roles) => roles.filter((r) => r === "anon" || r === "public");
|
|
1589
|
+
const blanket = (roles) => {
|
|
1590
|
+
const o = open(roles);
|
|
1591
|
+
if (o.length) return { level: "error", who: o.join(" and ") };
|
|
1592
|
+
if (roles.includes("authenticated")) return { level: "warn", who: "authenticated" };
|
|
1593
|
+
return null;
|
|
1594
|
+
};
|
|
1595
|
+
for (const { file, statements } of migrations) {
|
|
1596
|
+
for (const { sql, line } of statements) {
|
|
1597
|
+
const all = /^grant\b.*\bon all (?:functions|routines|procedures) in schema .+? to (.+)$/.exec(sql);
|
|
1598
|
+
if (all) {
|
|
1599
|
+
const hit = blanket(granteesOf(all[1]));
|
|
1600
|
+
if (hit) {
|
|
1601
|
+
ctx.report({ rule: "migration-grants", level: hit.level, file, line, subject: "on all functions", message: `grants every function in a schema to ${hit.who}, which re-grants functions an earlier migration revoked; ${fix}` });
|
|
1602
|
+
}
|
|
1603
|
+
continue;
|
|
1604
|
+
}
|
|
1605
|
+
const defaults = /^alter default privileges\b.*?\bgrant\b.*\bon (?:functions|routines) to (.+)$/.exec(sql);
|
|
1606
|
+
if (defaults) {
|
|
1607
|
+
const hit = blanket(granteesOf(defaults[1]));
|
|
1608
|
+
if (hit) {
|
|
1609
|
+
ctx.report({ rule: "migration-grants", level: hit.level, file, line, subject: "alter default privileges", message: `grants default privileges on functions to ${hit.who}, so every future function is callable by them; ${fix}` });
|
|
1610
|
+
}
|
|
1611
|
+
continue;
|
|
1612
|
+
}
|
|
1613
|
+
const fn = /^grant\b.*?\bon (?:function|procedure|routine)s? (.+?) to (.+)$/.exec(sql);
|
|
1614
|
+
if (fn) {
|
|
1615
|
+
const roles = open(granteesOf(fn[2]));
|
|
1616
|
+
if (!roles.length) continue;
|
|
1617
|
+
for (const name of splitTop(fn[1]).map((n) => qualify(stripParens(n)))) {
|
|
1618
|
+
if (exposed.has(schemaOf(name))) continue;
|
|
1619
|
+
ctx.report({
|
|
1620
|
+
rule: "migration-grants",
|
|
1621
|
+
file,
|
|
1622
|
+
line,
|
|
1623
|
+
subject: name,
|
|
1624
|
+
message: `grants ${name} to ${roles.join(" and ")}; a function outside the exposed schemas is never callable by anon or public (grant it to authenticated, or expose a wrapper)`
|
|
1625
|
+
});
|
|
1626
|
+
}
|
|
1627
|
+
continue;
|
|
1628
|
+
}
|
|
1629
|
+
const schema = /^grant\b.*?\bon schema (.+?) to (.+)$/.exec(sql);
|
|
1630
|
+
if (schema) {
|
|
1631
|
+
const roles = open(granteesOf(schema[2]));
|
|
1632
|
+
if (!roles.length) continue;
|
|
1633
|
+
for (const s of schema[1].split(/\s*,\s*/).map((x) => x.trim())) {
|
|
1634
|
+
if (exposed.has(s)) continue;
|
|
1635
|
+
ctx.report({
|
|
1636
|
+
rule: "migration-grants",
|
|
1637
|
+
file,
|
|
1638
|
+
line,
|
|
1639
|
+
subject: `schema ${s}`,
|
|
1640
|
+
message: `grants schema ${s} to ${roles.join(" and ")}; a schema outside the exposed ones stays closed to anon and public`
|
|
1641
|
+
});
|
|
1642
|
+
}
|
|
1643
|
+
}
|
|
1644
|
+
}
|
|
1645
|
+
}
|
|
1646
|
+
}
|
|
1647
|
+
function checkRls(ctx, migrations, exposed) {
|
|
1648
|
+
const tables = /* @__PURE__ */ new Map();
|
|
1649
|
+
const name = String.raw`([\w$.]+)`;
|
|
1650
|
+
const target = String.raw`^alter table (?:if exists )?(?:only )?${name}`;
|
|
1651
|
+
for (const { file, statements } of migrations) {
|
|
1652
|
+
for (const { sql, line, bodies } of statements) {
|
|
1653
|
+
if (bodies.some((b) => /\benable row level security\b/.test(b))) for (const t of tables.values()) t.rls = true;
|
|
1654
|
+
const create = new RegExp(String.raw`^create (?:(?:global |local )?(?:temp|temporary) |unlogged )?table (?:if not exists )?${name}`).exec(sql);
|
|
1655
|
+
if (create) {
|
|
1656
|
+
if (!/^create (?:global |local )?(?:temp|temporary) /.test(sql)) tables.set(qualify(create[1]), { rls: false, file, line, disabled: false });
|
|
1657
|
+
continue;
|
|
1658
|
+
}
|
|
1659
|
+
const rename = new RegExp(`${target} rename to ([\\w$]+)$`).exec(sql);
|
|
1660
|
+
const move = new RegExp(`${target} set schema ([\\w$]+)$`).exec(sql);
|
|
1661
|
+
if (rename || move) {
|
|
1662
|
+
const from = qualify((rename ?? move)[1]);
|
|
1663
|
+
const to = rename ? `${schemaOf(from)}.${rename[2]}` : `${move[2]}.${from.split(".")[1]}`;
|
|
1664
|
+
const state = tables.get(from);
|
|
1665
|
+
if (state) {
|
|
1666
|
+
tables.delete(from);
|
|
1667
|
+
tables.set(to, state);
|
|
1668
|
+
}
|
|
1669
|
+
continue;
|
|
1670
|
+
}
|
|
1671
|
+
const alter = new RegExp(target).exec(sql);
|
|
1672
|
+
if (alter && /\b(?:enable|disable) row level security\b/.test(sql)) {
|
|
1673
|
+
const t = qualify(alter[1]);
|
|
1674
|
+
if (/\bdisable row level security\b/.test(sql)) tables.set(t, { rls: false, file, line, disabled: true });
|
|
1675
|
+
else {
|
|
1676
|
+
const state = tables.get(t);
|
|
1677
|
+
if (state) state.rls = true;
|
|
1678
|
+
}
|
|
1679
|
+
continue;
|
|
1680
|
+
}
|
|
1681
|
+
const drop = /^drop table (?:if exists )?(.+?)(?: cascade| restrict)?$/.exec(sql);
|
|
1682
|
+
if (drop) for (const n of drop[1].split(",")) tables.delete(qualify(n));
|
|
1683
|
+
}
|
|
1684
|
+
}
|
|
1685
|
+
for (const [t, at] of tables) {
|
|
1686
|
+
if (at.rls || !exposed.has(schemaOf(t))) continue;
|
|
1687
|
+
ctx.report({
|
|
1688
|
+
rule: "migration-rls",
|
|
1689
|
+
file: at.file,
|
|
1690
|
+
line: at.line,
|
|
1691
|
+
subject: t,
|
|
1692
|
+
message: at.disabled ? `disables row level security on ${t}, and no later migration turns it back on; anyone with the API key can read and write it` : `creates ${t} without enabling row level security in any migration; add "alter table ${t} enable row level security;" and its policies`
|
|
1693
|
+
});
|
|
1694
|
+
}
|
|
1695
|
+
}
|
|
1696
|
+
function checkDefinerSearchPath(ctx, migrations) {
|
|
1697
|
+
const fns = /* @__PURE__ */ new Map();
|
|
1698
|
+
const keysFor = (sql, nameEnd, fnName) => {
|
|
1699
|
+
const rest = sql.slice(nameEnd).trimStart();
|
|
1700
|
+
if (rest.startsWith("(")) {
|
|
1701
|
+
const { inner } = parenthesized(rest, 0);
|
|
1702
|
+
return [`${fnName}(${argTypes(inner).join(",")})`];
|
|
1703
|
+
}
|
|
1704
|
+
return [...fns.keys()].filter((k) => k.startsWith(`${fnName}(`));
|
|
1705
|
+
};
|
|
1706
|
+
for (const { file, statements } of migrations) {
|
|
1707
|
+
for (const { sql, line } of statements) {
|
|
1708
|
+
const create = /^create (?:or replace )?(?:function|procedure) ([\w$.]+)\s*/.exec(sql);
|
|
1709
|
+
if (create) {
|
|
1710
|
+
const [key] = keysFor(sql, create[0].length, qualify(create[1]));
|
|
1711
|
+
fns.set(key, { definer: /\bsecurity definer\b/.test(sql), searchPath: /\bset search_path\b/.test(sql), file, line });
|
|
1712
|
+
continue;
|
|
1713
|
+
}
|
|
1714
|
+
const alter = /^alter (?:function|procedure|routine) ([\w$.]+)\s*/.exec(sql);
|
|
1715
|
+
if (alter) {
|
|
1716
|
+
const fnName = qualify(alter[1]);
|
|
1717
|
+
const keys = keysFor(sql, alter[0].length, fnName);
|
|
1718
|
+
const rename = / rename to ([\w$]+)$/.exec(sql);
|
|
1719
|
+
const move = / set schema ([\w$]+)$/.exec(sql);
|
|
1720
|
+
for (const key of keys) {
|
|
1721
|
+
const state = fns.get(key);
|
|
1722
|
+
if (rename || move) {
|
|
1723
|
+
if (!state) continue;
|
|
1724
|
+
fns.delete(key);
|
|
1725
|
+
const newName = rename ? `${schemaOf(fnName)}.${rename[1]}` : `${move[1]}.${fnName.split(".")[1]}`;
|
|
1726
|
+
fns.set(newName + key.slice(fnName.length), state);
|
|
1727
|
+
continue;
|
|
1728
|
+
}
|
|
1729
|
+
const next = state ?? { definer: false, searchPath: false, file, line };
|
|
1730
|
+
if (/\bsecurity definer\b/.test(sql)) Object.assign(next, { definer: true, file, line });
|
|
1731
|
+
if (/\bsecurity invoker\b/.test(sql)) next.definer = false;
|
|
1732
|
+
if (/\bset search_path\b/.test(sql)) next.searchPath = true;
|
|
1733
|
+
if (/\breset (?:search_path|all)\b/.test(sql)) Object.assign(next, { searchPath: false, file, line });
|
|
1734
|
+
fns.set(key, next);
|
|
1735
|
+
}
|
|
1736
|
+
continue;
|
|
1737
|
+
}
|
|
1738
|
+
const drop = /^drop (?:function|procedure|routine) (?:if exists )?(.+?)(?: cascade| restrict)?$/.exec(sql);
|
|
1739
|
+
if (drop) {
|
|
1740
|
+
for (const part of splitTop(drop[1])) {
|
|
1741
|
+
const m = /^([\w$.]+)\s*/.exec(part);
|
|
1742
|
+
if (m) for (const key of keysFor(part, m[0].length, qualify(m[1]))) fns.delete(key);
|
|
1743
|
+
}
|
|
1744
|
+
}
|
|
1745
|
+
}
|
|
1746
|
+
}
|
|
1747
|
+
for (const [key, at] of fns) {
|
|
1748
|
+
if (!at.definer || at.searchPath) continue;
|
|
1749
|
+
ctx.report({
|
|
1750
|
+
rule: "migration-definer-search-path",
|
|
1751
|
+
file: at.file,
|
|
1752
|
+
line: at.line,
|
|
1753
|
+
subject: key,
|
|
1754
|
+
message: `${key} is security definer without "set search_path"; add set search_path = '' and schema-qualify the names in its body, so a caller's objects can't stand in for yours`
|
|
1755
|
+
});
|
|
1756
|
+
}
|
|
1757
|
+
}
|
|
942
1758
|
var UMBRELLA_PACKAGE = "@marktiderman/genesis";
|
|
943
1759
|
function readReleaseManifest(root) {
|
|
944
1760
|
const dir = findPackageDir(root, UMBRELLA_PACKAGE);
|
|
@@ -986,7 +1802,9 @@ async function runDoctor(options = {}) {
|
|
|
986
1802
|
{ name: "colors", check: checkColors },
|
|
987
1803
|
{ name: "tokens", check: checkTokens },
|
|
988
1804
|
{ name: "shadowed-exports", check: checkShadowedExports },
|
|
989
|
-
{ name: "version-skew", check: checkVersionSkew }
|
|
1805
|
+
{ name: "version-skew", check: checkVersionSkew },
|
|
1806
|
+
...config.packs?.includes("native") ? [{ name: "native", check: checkNativePack }] : [],
|
|
1807
|
+
...config.packs?.includes("supabase") ? [{ name: "supabase", check: checkSupabasePack }] : []
|
|
990
1808
|
];
|
|
991
1809
|
for (const plugin of [...builtins, ...patterns ? [patterns.plugin] : [], ...plugins]) {
|
|
992
1810
|
try {
|
|
@@ -1083,6 +1901,6 @@ function genesisSummary(g) {
|
|
|
1083
1901
|
};
|
|
1084
1902
|
}
|
|
1085
1903
|
|
|
1086
|
-
export { BUILTIN_RULES, DoctorConfigError, GenesisConfigError, defineDoctorPlugin, findPackageDir, formatReport, genesisSummary, globToRegExp, loadConfig, loadGenesis, parseExportNames, parseRulesMarkdown, readGenesisConfig, readReleaseManifest, runDoctor, toJson, validateConfig, validateLinks };
|
|
1904
|
+
export { BUILTIN_RULES, DoctorConfigError, GenesisConfigError, defineDoctorPlugin, findPackageDir, formatReport, genesisSummary, globToRegExp, loadConfig, loadGenesis, nativeLayouts, parseExportNames, parseRulesMarkdown, readGenesisConfig, readPackageExports, readReleaseManifest, runDoctor, sqlStatements, toJson, validateConfig, validateLinks };
|
|
1087
1905
|
//# sourceMappingURL=doctor.js.map
|
|
1088
1906
|
//# sourceMappingURL=doctor.js.map
|