@marktiderman/genesis-cli 1.11.3 → 1.12.1
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 +57 -1
- package/dist/cli.js +1657 -1231
- package/dist/cli.js.map +1 -1
- package/dist/{config-QC_Ewwwp.d.ts → config-4MhgqkFT.d.ts} +10 -2
- package/dist/doctor.d.ts +5 -3
- package/dist/doctor.js +1611 -1036
- package/dist/doctor.js.map +1 -1
- package/dist/expo.d.ts +2 -2
- package/dist/expo.js.map +1 -1
- package/dist/genesis-catalog.json +10 -10
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1620 -1045
- package/dist/index.js.map +1 -1
- package/dist/vite.js +1611 -1036
- package/dist/vite.js.map +1 -1
- package/package.json +3 -3
package/dist/vite.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import * as path14 from 'path';
|
|
2
2
|
import { spawnSync } from 'child_process';
|
|
3
|
-
import { existsSync, readFileSync, statSync, readdirSync, realpathSync } from 'fs';
|
|
4
|
-
import { createRequire } from 'module';
|
|
3
|
+
import { existsSync, readFileSync, statSync, readdirSync, realpathSync, lstatSync } from 'fs';
|
|
4
|
+
import { builtinModules, createRequire } from 'module';
|
|
5
|
+
import 'crypto';
|
|
6
|
+
import { FEATURE_PLATFORMS, defineBlock, BlockError } from '@marktiderman/genesis-features/blocks';
|
|
5
7
|
import { pathToFileURL } from 'url';
|
|
6
8
|
|
|
7
9
|
// src/vite.ts
|
|
@@ -114,16 +116,18 @@ var KNOWN = /* @__PURE__ */ new Set([
|
|
|
114
116
|
"packs",
|
|
115
117
|
"native",
|
|
116
118
|
"supabase",
|
|
119
|
+
"packages",
|
|
117
120
|
"routesDir",
|
|
118
121
|
"$schema",
|
|
119
122
|
"$comment"
|
|
120
123
|
]);
|
|
121
124
|
var LEVELS = /* @__PURE__ */ new Set(["error", "warn", "info", "off"]);
|
|
122
125
|
var PATTERN_KEYS = /* @__PURE__ */ new Set(["id", "level", "files", "exclude", "forbid", "require", "path", "message"]);
|
|
123
|
-
var PACKS = /* @__PURE__ */ new Set(["native", "supabase"]);
|
|
126
|
+
var PACKS = /* @__PURE__ */ new Set(["native", "supabase", "packages"]);
|
|
124
127
|
var PACK_KEYS = {
|
|
125
128
|
native: { routerRoot: "path" },
|
|
126
|
-
supabase: { migrations: "path", base: "string", exposedSchemas: "list", since: "string" }
|
|
129
|
+
supabase: { migrations: "path", base: "string", exposedSchemas: "list", since: "string" },
|
|
130
|
+
packages: { base: "string" }
|
|
127
131
|
};
|
|
128
132
|
function appPath(v, where, fail) {
|
|
129
133
|
if (typeof v !== "string" || !v.trim()) return fail(`${where} must be a non-empty path`);
|
|
@@ -362,7 +366,7 @@ function globToRegExp(glob) {
|
|
|
362
366
|
}
|
|
363
367
|
function globMatcher(globs) {
|
|
364
368
|
const res = (globs ?? []).filter((g) => g.trim()).map(globToRegExp);
|
|
365
|
-
return (
|
|
369
|
+
return (path21) => res.some((re) => re.test(path21));
|
|
366
370
|
}
|
|
367
371
|
var DEFAULT_UI_PACKAGE = "@marktiderman/genesis-ui";
|
|
368
372
|
var NATIVE_UI_PACKAGE = "@marktiderman/genesis-ui-native";
|
|
@@ -588,6 +592,276 @@ function loadPalette(root) {
|
|
|
588
592
|
}
|
|
589
593
|
return [...names].sort();
|
|
590
594
|
}
|
|
595
|
+
var GENESIS_PACKAGE = /^@marktiderman\/genesis(-[a-z0-9-]+)?$/;
|
|
596
|
+
var BLOCK_ID = /^[a-z][a-z0-9]*(?:[-_.][a-z0-9]+)*$/;
|
|
597
|
+
var MIGRATION_FILE = /^(\d{4})_([a-z0-9_]+)\.sql$/;
|
|
598
|
+
var FUNCTION_NAME = /^[a-z0-9][a-z0-9_-]*$/;
|
|
599
|
+
var ROUTE = /^\/(?:[A-Za-z0-9_\-[\]().]+\/?)*$/;
|
|
600
|
+
var INSTALL_SPEC = /^(@[a-z0-9][a-z0-9._-]*\/)?[a-z0-9][a-z0-9._-]*(@[A-Za-z0-9.^~<>=|* -]+)?$/;
|
|
601
|
+
var SECRET = /^[A-Z][A-Z0-9_]*$/;
|
|
602
|
+
var ManifestError = class extends Error {
|
|
603
|
+
constructor(problems) {
|
|
604
|
+
super(`Invalid block manifest:
|
|
605
|
+
${problems.map((p) => ` - ${p}`).join("\n")}`);
|
|
606
|
+
this.problems = problems;
|
|
607
|
+
this.name = "ManifestError";
|
|
608
|
+
}
|
|
609
|
+
problems;
|
|
610
|
+
};
|
|
611
|
+
function safeRelative(value) {
|
|
612
|
+
if (typeof value !== "string" || !value || value.length > 300) return null;
|
|
613
|
+
if (/[\0\\:]/.test(value) || value.startsWith("/") || value.startsWith("~")) return null;
|
|
614
|
+
const segments = value.split("/");
|
|
615
|
+
if (segments.some((s) => s === "" || s === "." || s === ".." || s.startsWith("-"))) return null;
|
|
616
|
+
return value;
|
|
617
|
+
}
|
|
618
|
+
var isObject2 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
619
|
+
var strings = (v) => Array.isArray(v) && v.every((s) => typeof s === "string");
|
|
620
|
+
function parseManifest(home, id, raw, version, options = {}) {
|
|
621
|
+
const problems = [];
|
|
622
|
+
const at = `${home} genesis.blocks.${id}`;
|
|
623
|
+
if (!GENESIS_PACKAGE.test(home) && !options.local) problems.push(`${home}: only Genesis packages (@marktiderman/genesis*) and the app's local packages declare blocks`);
|
|
624
|
+
if (!BLOCK_ID.test(id)) problems.push(`${at}: "${id}" is not a feature id`);
|
|
625
|
+
if (!isObject2(raw)) throw new ManifestError([...problems, `${at}: must be an object`]);
|
|
626
|
+
const pkgOf = (value, where) => {
|
|
627
|
+
if (value === void 0) return home;
|
|
628
|
+
if (typeof value !== "string" || !(GENESIS_PACKAGE.test(value) || options.local && value === home)) {
|
|
629
|
+
problems.push(`${where}: package must be a Genesis package${options.local ? " or this local package" : ""}, not ${JSON.stringify(value)}`);
|
|
630
|
+
return home;
|
|
631
|
+
}
|
|
632
|
+
return value;
|
|
633
|
+
};
|
|
634
|
+
const pathOf = (value, where) => {
|
|
635
|
+
const safe = safeRelative(value);
|
|
636
|
+
if (!safe) problems.push(`${where}: ${JSON.stringify(value)} is not a plain path inside the package`);
|
|
637
|
+
return safe ?? "";
|
|
638
|
+
};
|
|
639
|
+
const list = (key2) => {
|
|
640
|
+
const v = raw[key2];
|
|
641
|
+
if (v === void 0) return [];
|
|
642
|
+
if (!Array.isArray(v)) {
|
|
643
|
+
problems.push(`${at}.${key2}: must be a list`);
|
|
644
|
+
return [];
|
|
645
|
+
}
|
|
646
|
+
return v;
|
|
647
|
+
};
|
|
648
|
+
const requires = list("requires").filter((r) => {
|
|
649
|
+
const ok = typeof r === "string" && BLOCK_ID.test(r);
|
|
650
|
+
if (!ok) problems.push(`${at}.requires: ${JSON.stringify(r)} is not a feature id`);
|
|
651
|
+
return ok;
|
|
652
|
+
});
|
|
653
|
+
let platforms;
|
|
654
|
+
if (raw["platforms"] !== void 0) {
|
|
655
|
+
platforms = list("platforms").filter((p) => {
|
|
656
|
+
const ok = typeof p === "string" && FEATURE_PLATFORMS.includes(p);
|
|
657
|
+
if (!ok) problems.push(`${at}.platforms: ${JSON.stringify(p)} is not one of ${FEATURE_PLATFORMS.join(", ")}`);
|
|
658
|
+
return ok;
|
|
659
|
+
});
|
|
660
|
+
}
|
|
661
|
+
const packages = list("packages").map((p, i) => pkgOf(p, `${at}.packages[${i}]`));
|
|
662
|
+
const install = list("install").filter((s) => {
|
|
663
|
+
const ok = typeof s === "string" && INSTALL_SPEC.test(s) && !s.startsWith("-");
|
|
664
|
+
if (!ok) problems.push(`${at}.install: ${JSON.stringify(s)} is not a package name with an optional range`);
|
|
665
|
+
return ok;
|
|
666
|
+
});
|
|
667
|
+
const migrations = list("migrations").map((m, i) => {
|
|
668
|
+
const where = `${at}.migrations[${i}]`;
|
|
669
|
+
if (!isObject2(m)) {
|
|
670
|
+
problems.push(`${where}: must be an object`);
|
|
671
|
+
return { package: home, file: "" };
|
|
672
|
+
}
|
|
673
|
+
const file = pathOf(m["file"], `${where}.file`);
|
|
674
|
+
if (file && !MIGRATION_FILE.test(file.split("/").pop())) problems.push(`${where}.file: "${file}" must be named NNNN_name.sql (lowercase letters, digits, _)`);
|
|
675
|
+
const out = { package: pkgOf(m["package"], where), file };
|
|
676
|
+
if (m["test"] !== void 0) {
|
|
677
|
+
out.test = pathOf(m["test"], `${where}.test`);
|
|
678
|
+
if (out.test && !/^[a-z0-9_]+\.test\.sql$/.test(out.test.split("/").pop().replace(/^\d{4}_/, ""))) problems.push(`${where}.test: "${out.test}" must be named [NNNN_]name.test.sql`);
|
|
679
|
+
}
|
|
680
|
+
return out;
|
|
681
|
+
});
|
|
682
|
+
const functions = list("functions").map((f, i) => {
|
|
683
|
+
const where = `${at}.functions[${i}]`;
|
|
684
|
+
if (!isObject2(f)) {
|
|
685
|
+
problems.push(`${where}: must be an object`);
|
|
686
|
+
return { package: home, dir: "" };
|
|
687
|
+
}
|
|
688
|
+
const dir = pathOf(f["dir"], `${where}.dir`);
|
|
689
|
+
if (dir && !FUNCTION_NAME.test(dir.split("/").pop())) problems.push(`${where}.dir: the folder's name "${dir.split("/").pop()}" is not a function name`);
|
|
690
|
+
const out = { package: pkgOf(f["package"], where), dir };
|
|
691
|
+
if (f["verifyJwt"] !== void 0) {
|
|
692
|
+
if (typeof f["verifyJwt"] !== "boolean") problems.push(`${where}.verifyJwt: must be true or false`);
|
|
693
|
+
else out.verifyJwt = f["verifyJwt"];
|
|
694
|
+
}
|
|
695
|
+
if (f["secrets"] !== void 0) {
|
|
696
|
+
if (!strings(f["secrets"]) || f["secrets"].some((s) => !SECRET.test(s))) problems.push(`${where}.secrets: must be a list of UPPER_CASE names`);
|
|
697
|
+
else out.secrets = f["secrets"];
|
|
698
|
+
}
|
|
699
|
+
return out;
|
|
700
|
+
});
|
|
701
|
+
const routes = list("routes").map((r, i) => {
|
|
702
|
+
const where = `${at}.routes[${i}]`;
|
|
703
|
+
if (!isObject2(r) || typeof r["path"] !== "string" || !ROUTE.test(r["path"]) || r["path"].split("/").includes("..")) {
|
|
704
|
+
problems.push(`${where}: needs a path like /settings/notifications`);
|
|
705
|
+
return { path: "/" };
|
|
706
|
+
}
|
|
707
|
+
const out = { path: r["path"] };
|
|
708
|
+
if (typeof r["description"] === "string") out.description = r["description"];
|
|
709
|
+
if (typeof r["signedIn"] === "boolean") out.signedIn = r["signedIn"];
|
|
710
|
+
return out;
|
|
711
|
+
});
|
|
712
|
+
const skills = list("skills").map((s, i) => {
|
|
713
|
+
if (isObject2(s)) return { package: pkgOf(s["package"], `${at}.skills[${i}]`), path: pathOf(s["path"], `${at}.skills[${i}].path`) };
|
|
714
|
+
return { package: home, path: pathOf(s, `${at}.skills[${i}]`) };
|
|
715
|
+
});
|
|
716
|
+
for (const s of skills) if (s.path && !s.path.endsWith("SKILL.md")) problems.push(`${at}.skills: "${s.path}" must point at a SKILL.md`);
|
|
717
|
+
let agents;
|
|
718
|
+
if (raw["agents"] !== void 0) {
|
|
719
|
+
const a = raw["agents"];
|
|
720
|
+
agents = isObject2(a) ? { package: pkgOf(a["package"], `${at}.agents`), path: pathOf(a["path"], `${at}.agents.path`) } : { package: home, path: pathOf(a, `${at}.agents`) };
|
|
721
|
+
if (agents.path && !agents.path.endsWith(".md")) problems.push(`${at}.agents: "${agents.path}" must be a Markdown file`);
|
|
722
|
+
}
|
|
723
|
+
let feature;
|
|
724
|
+
if (raw["feature"] !== void 0) {
|
|
725
|
+
const f = raw["feature"];
|
|
726
|
+
if (!isObject2(f) || typeof f["name"] !== "string" || typeof f["summary"] !== "string") problems.push(`${at}.feature: needs a name and a summary`);
|
|
727
|
+
else {
|
|
728
|
+
feature = { name: f["name"], summary: f["summary"] };
|
|
729
|
+
if (typeof f["layer"] === "string") feature.layer = f["layer"];
|
|
730
|
+
if (strings(f["keywords"])) feature.keywords = f["keywords"];
|
|
731
|
+
if (strings(f["audience"])) feature.audience = f["audience"];
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
const steps = list("steps").filter((s) => {
|
|
735
|
+
if (typeof s !== "string") problems.push(`${at}.steps: every step is a sentence`);
|
|
736
|
+
return typeof s === "string";
|
|
737
|
+
});
|
|
738
|
+
const privacy = isObject2(raw["privacy"]) ? raw["privacy"] : void 0;
|
|
739
|
+
try {
|
|
740
|
+
const def = { id, requires, contributes: { routes, migrations: migrations.filter((m) => m.file), skills: skills.map((s) => s.path).filter(Boolean), ...privacy ? { privacy } : {} } };
|
|
741
|
+
if (platforms) def.platforms = platforms;
|
|
742
|
+
defineBlock(def);
|
|
743
|
+
} catch (err) {
|
|
744
|
+
if (err instanceof BlockError) problems.push(...err.problems.map((p) => `${at}: ${p}`));
|
|
745
|
+
else throw err;
|
|
746
|
+
}
|
|
747
|
+
if (problems.length) throw new ManifestError(problems);
|
|
748
|
+
return {
|
|
749
|
+
id,
|
|
750
|
+
package: home,
|
|
751
|
+
...version ? { version } : {},
|
|
752
|
+
requires,
|
|
753
|
+
...platforms ? { platforms } : {},
|
|
754
|
+
packages: packages.length ? [...new Set(packages)] : [home],
|
|
755
|
+
install,
|
|
756
|
+
migrations,
|
|
757
|
+
functions,
|
|
758
|
+
routes,
|
|
759
|
+
skills,
|
|
760
|
+
...agents ? { agents } : {},
|
|
761
|
+
...feature ? { feature } : {},
|
|
762
|
+
steps,
|
|
763
|
+
...privacy ? { privacy } : {}
|
|
764
|
+
};
|
|
765
|
+
}
|
|
766
|
+
function rawBlocksOf(packageJson) {
|
|
767
|
+
if (!isObject2(packageJson) || !isObject2(packageJson["genesis"])) return {};
|
|
768
|
+
const blocks = packageJson["genesis"]["blocks"];
|
|
769
|
+
return isObject2(blocks) ? blocks : {};
|
|
770
|
+
}
|
|
771
|
+
|
|
772
|
+
// src/blocks/files.ts
|
|
773
|
+
function inside(parent, child) {
|
|
774
|
+
const rel = path14.relative(parent, child);
|
|
775
|
+
return rel === "" || !rel.startsWith("..") && !path14.isAbsolute(rel);
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
// src/blocks/local.ts
|
|
779
|
+
var LOCAL_PACKAGES_KEY = "localPackages";
|
|
780
|
+
var LocalPackagesError = class extends Error {
|
|
781
|
+
name = "LocalPackagesError";
|
|
782
|
+
};
|
|
783
|
+
function validateLocalPackages(raw, source = "genesis.config.json") {
|
|
784
|
+
if (!Array.isArray(raw)) throw new LocalPackagesError(`${source}: ${LOCAL_PACKAGES_KEY} must be a list of folders`);
|
|
785
|
+
return raw.map((entry, i) => {
|
|
786
|
+
const where = `${source}: ${LOCAL_PACKAGES_KEY}[${i}]`;
|
|
787
|
+
if (typeof entry !== "string" || !entry.trim()) throw new LocalPackagesError(`${where} must be a non-empty folder`);
|
|
788
|
+
if (path14.isAbsolute(entry) || /^[A-Za-z]:[\\/]/.test(entry)) throw new LocalPackagesError(`${where} must be relative to the app ("${entry}")`);
|
|
789
|
+
const norm = path14.posix.normalize(entry.replace(/\\/g, "/")).replace(/\/+$/, "");
|
|
790
|
+
if (norm === "." || /^(\.\.\/)*\.\.$/.test(norm)) throw new LocalPackagesError(`${where} must name a package folder, not the app or a parent of it ("${entry}")`);
|
|
791
|
+
const parts = norm.split("/");
|
|
792
|
+
if (parts.some((p, k) => p.includes("*") && (p !== "*" || k !== parts.length - 1))) {
|
|
793
|
+
throw new LocalPackagesError(`${where}: only a final "/*" is supported ("${entry}")`);
|
|
794
|
+
}
|
|
795
|
+
if (parts.includes("node_modules")) throw new LocalPackagesError(`${where} can't point into node_modules ("${entry}")`);
|
|
796
|
+
return norm;
|
|
797
|
+
});
|
|
798
|
+
}
|
|
799
|
+
function localPackageGlobs(root) {
|
|
800
|
+
const file = path14.join(root, "genesis.config.json");
|
|
801
|
+
if (!existsSync(file)) return [];
|
|
802
|
+
let raw;
|
|
803
|
+
try {
|
|
804
|
+
raw = JSON.parse(readFileSync(file, "utf8"));
|
|
805
|
+
} catch (err) {
|
|
806
|
+
throw new LocalPackagesError(`${file} is not valid JSON: ${err.message}`);
|
|
807
|
+
}
|
|
808
|
+
const value = raw && typeof raw === "object" ? raw[LOCAL_PACKAGES_KEY] : void 0;
|
|
809
|
+
return value === void 0 ? [] : validateLocalPackages(value, file);
|
|
810
|
+
}
|
|
811
|
+
var cache = /* @__PURE__ */ new Map();
|
|
812
|
+
function repositoryRoot(appRoot) {
|
|
813
|
+
for (let dir = appRoot; ; ) {
|
|
814
|
+
if (existsSync(path14.join(dir, ".git"))) return dir;
|
|
815
|
+
const parent = path14.dirname(dir);
|
|
816
|
+
if (parent === dir) return appRoot;
|
|
817
|
+
dir = parent;
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
function localPackages(root) {
|
|
821
|
+
const appRoot = path14.resolve(root);
|
|
822
|
+
const globs = localPackageGlobs(appRoot);
|
|
823
|
+
const key2 = `${appRoot}
|
|
824
|
+
${globs.join("\n")}`;
|
|
825
|
+
const hit = cache.get(key2);
|
|
826
|
+
if (hit) return hit;
|
|
827
|
+
const dirs = /* @__PURE__ */ new Set();
|
|
828
|
+
for (const glob of globs) {
|
|
829
|
+
if (glob.endsWith("/*") || glob === "*") {
|
|
830
|
+
const parent = path14.join(appRoot, glob === "*" ? "" : glob.slice(0, -2));
|
|
831
|
+
if (!existsSync(parent) || !statSync(parent).isDirectory()) continue;
|
|
832
|
+
for (const entry of readdirSync(parent).sort()) {
|
|
833
|
+
if (entry.startsWith(".") || entry === "node_modules") continue;
|
|
834
|
+
dirs.add(path14.join(parent, entry));
|
|
835
|
+
}
|
|
836
|
+
} else {
|
|
837
|
+
dirs.add(path14.join(appRoot, glob));
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
const real2 = realpathSync(repositoryRoot(appRoot));
|
|
841
|
+
const out = [];
|
|
842
|
+
const byName = /* @__PURE__ */ new Map();
|
|
843
|
+
for (const dir of [...dirs].sort()) {
|
|
844
|
+
const manifest = path14.join(dir, "package.json");
|
|
845
|
+
if (!existsSync(manifest)) continue;
|
|
846
|
+
if (!inside(real2, realpathSync(dir))) {
|
|
847
|
+
throw new LocalPackagesError(`${path14.relative(appRoot, dir) || dir} is outside the repository; localPackages may only list folders inside it`);
|
|
848
|
+
}
|
|
849
|
+
let pkg;
|
|
850
|
+
try {
|
|
851
|
+
pkg = JSON.parse(readFileSync(manifest, "utf8"));
|
|
852
|
+
} catch {
|
|
853
|
+
continue;
|
|
854
|
+
}
|
|
855
|
+
if (typeof pkg.name !== "string" || !pkg.name) continue;
|
|
856
|
+
const rel = path14.relative(appRoot, dir).split(path14.sep).join("/");
|
|
857
|
+
const other = byName.get(pkg.name);
|
|
858
|
+
if (other) throw new LocalPackagesError(`${other} and ${rel} are both named ${pkg.name}`);
|
|
859
|
+
byName.set(pkg.name, rel);
|
|
860
|
+
out.push({ name: pkg.name, dir, rel, ...typeof pkg.version === "string" ? { version: pkg.version } : {} });
|
|
861
|
+
}
|
|
862
|
+
cache.set(key2, out);
|
|
863
|
+
return out;
|
|
864
|
+
}
|
|
591
865
|
|
|
592
866
|
// ../../scripts/lib/color-literals.mjs
|
|
593
867
|
var LINE_COMMENT_EXTS = /* @__PURE__ */ new Set([".ts", ".tsx", ".jsx", ".js", ".mjs", ".cjs", ".scss", ".less"]);
|
|
@@ -795,6 +1069,13 @@ function scanFiles(root, config) {
|
|
|
795
1069
|
if (statSync(abs).isDirectory()) walk(abs);
|
|
796
1070
|
else visit(abs);
|
|
797
1071
|
}
|
|
1072
|
+
let local = [];
|
|
1073
|
+
try {
|
|
1074
|
+
local = localPackages(root);
|
|
1075
|
+
} catch {
|
|
1076
|
+
local = [];
|
|
1077
|
+
}
|
|
1078
|
+
for (const pkg of local) walk(pkg.dir);
|
|
798
1079
|
return files;
|
|
799
1080
|
}
|
|
800
1081
|
function lineAt(text, index) {
|
|
@@ -964,7 +1245,18 @@ var BUILTIN_RULES = [
|
|
|
964
1245
|
"migration-definer-search-path",
|
|
965
1246
|
"migration-edited",
|
|
966
1247
|
"migration-testing-kit",
|
|
967
|
-
"migration-view-rls"
|
|
1248
|
+
"migration-view-rls",
|
|
1249
|
+
// packages pack
|
|
1250
|
+
"package-app-import",
|
|
1251
|
+
"package-undeclared-dependency",
|
|
1252
|
+
"package-migration-test",
|
|
1253
|
+
"package-migration-number",
|
|
1254
|
+
"package-migration-edited",
|
|
1255
|
+
"package-unregistered",
|
|
1256
|
+
"package-unversioned-change",
|
|
1257
|
+
"package-export-missing",
|
|
1258
|
+
"package-block-invalid",
|
|
1259
|
+
"package-untagged-tests"
|
|
968
1260
|
];
|
|
969
1261
|
var DEFAULT_LOCAL_PRIMITIVE_DIRS = ["src/components/ui"];
|
|
970
1262
|
var STARTER_LEFTOVERS = ["components.json", "src/lib/utils.ts"];
|
|
@@ -1587,1134 +1879,1416 @@ function checkStoreReadiness(ctx) {
|
|
|
1587
1879
|
});
|
|
1588
1880
|
}
|
|
1589
1881
|
}
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
var
|
|
1593
|
-
function
|
|
1594
|
-
const
|
|
1595
|
-
|
|
1596
|
-
let bodies = [];
|
|
1597
|
-
let line = 1;
|
|
1598
|
-
let start = 0;
|
|
1599
|
-
const flush = () => {
|
|
1600
|
-
const sql = buf.replace(/\s+/g, " ").trim().toLowerCase();
|
|
1601
|
-
if (sql) out.push({ sql, line: start, bodies });
|
|
1602
|
-
buf = "";
|
|
1603
|
-
bodies = [];
|
|
1604
|
-
start = 0;
|
|
1605
|
-
};
|
|
1606
|
-
const put = (s) => {
|
|
1607
|
-
if (!start && /\S/.test(s)) start = line;
|
|
1608
|
-
buf += s;
|
|
1609
|
-
};
|
|
1610
|
-
let i = 0;
|
|
1611
|
-
while (i < text.length) {
|
|
1612
|
-
const ch = text[i];
|
|
1613
|
-
const two = text.slice(i, i + 2);
|
|
1614
|
-
if (ch === "\n") {
|
|
1615
|
-
buf += " ";
|
|
1616
|
-
line++;
|
|
1617
|
-
i++;
|
|
1618
|
-
} else if (two === "--") {
|
|
1619
|
-
while (i < text.length && text[i] !== "\n") i++;
|
|
1620
|
-
} else if (two === "/*") {
|
|
1621
|
-
let depth = 0;
|
|
1622
|
-
while (i < text.length) {
|
|
1623
|
-
if (text.startsWith("/*", i)) {
|
|
1624
|
-
depth++;
|
|
1625
|
-
i += 2;
|
|
1626
|
-
} else if (text.startsWith("*/", i)) {
|
|
1627
|
-
depth--;
|
|
1628
|
-
i += 2;
|
|
1629
|
-
if (depth === 0) break;
|
|
1630
|
-
} else {
|
|
1631
|
-
if (text[i] === "\n") line++;
|
|
1632
|
-
i++;
|
|
1633
|
-
}
|
|
1634
|
-
}
|
|
1635
|
-
buf += " ";
|
|
1636
|
-
} else if (ch === "'") {
|
|
1637
|
-
const escapes = /[eE]/.test(text[i - 1] ?? "") && !/[\w$]/.test(text[i - 2] ?? "");
|
|
1638
|
-
put("'");
|
|
1639
|
-
i++;
|
|
1640
|
-
while (i < text.length) {
|
|
1641
|
-
if (escapes && text[i] === "\\") i += 2;
|
|
1642
|
-
else if (text[i] === "'" && text[i + 1] === "'") i += 2;
|
|
1643
|
-
else if (text[i] === "'") break;
|
|
1644
|
-
else {
|
|
1645
|
-
if (text[i] === "\n") line++;
|
|
1646
|
-
i++;
|
|
1647
|
-
}
|
|
1648
|
-
}
|
|
1649
|
-
put("'");
|
|
1650
|
-
i++;
|
|
1651
|
-
} else if (ch === '"') {
|
|
1652
|
-
i++;
|
|
1653
|
-
while (i < text.length && text[i] !== '"') put(text[i++]);
|
|
1654
|
-
i++;
|
|
1655
|
-
} else if (ch === "$" && !/[\w$]/.test(text[i - 1] ?? "") && /^\$(?:[A-Za-z_]\w*)?\$/.test(text.slice(i))) {
|
|
1656
|
-
const tag = /^\$(?:[A-Za-z_]\w*)?\$/.exec(text.slice(i))[0];
|
|
1657
|
-
const end = text.indexOf(tag, i + tag.length);
|
|
1658
|
-
const stop = end === -1 ? text.length : end + tag.length;
|
|
1659
|
-
bodies.push(text.slice(i + tag.length, end === -1 ? text.length : end).toLowerCase());
|
|
1660
|
-
for (let k = i; k < stop; k++) if (text[k] === "\n") line++;
|
|
1661
|
-
put(`${tag} ${tag}`);
|
|
1662
|
-
i = stop;
|
|
1663
|
-
} else if (ch === ";") {
|
|
1664
|
-
flush();
|
|
1665
|
-
i++;
|
|
1666
|
-
} else {
|
|
1667
|
-
put(ch);
|
|
1668
|
-
i++;
|
|
1669
|
-
}
|
|
1670
|
-
}
|
|
1671
|
-
flush();
|
|
1672
|
-
return out;
|
|
1882
|
+
|
|
1883
|
+
// src/doctor/semver.ts
|
|
1884
|
+
var VERSION = /^v?(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/;
|
|
1885
|
+
function parseVersion(v) {
|
|
1886
|
+
const m = VERSION.exec(v.trim());
|
|
1887
|
+
return m ? { major: +m[1], minor: +m[2], patch: +m[3], pre: m[4] ? m[4].split(".") : [] } : null;
|
|
1673
1888
|
}
|
|
1674
|
-
function
|
|
1675
|
-
const
|
|
1676
|
-
|
|
1889
|
+
function compareVersions(a, b) {
|
|
1890
|
+
for (const k of ["major", "minor", "patch"]) if (a[k] !== b[k]) return a[k] < b[k] ? -1 : 1;
|
|
1891
|
+
if (!a.pre.length || !b.pre.length) return a.pre.length ? -1 : b.pre.length ? 1 : 0;
|
|
1892
|
+
for (let i = 0; i < Math.max(a.pre.length, b.pre.length); i++) {
|
|
1893
|
+
const x = a.pre[i];
|
|
1894
|
+
const y = b.pre[i];
|
|
1895
|
+
if (x === void 0) return -1;
|
|
1896
|
+
if (y === void 0) return 1;
|
|
1897
|
+
if (x === y) continue;
|
|
1898
|
+
const nx = /^\d+$/.test(x);
|
|
1899
|
+
const ny = /^\d+$/.test(y);
|
|
1900
|
+
if (nx && ny) return +x < +y ? -1 : 1;
|
|
1901
|
+
if (nx !== ny) return nx ? -1 : 1;
|
|
1902
|
+
return x < y ? -1 : 1;
|
|
1903
|
+
}
|
|
1904
|
+
return 0;
|
|
1677
1905
|
}
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1906
|
+
function partial(s) {
|
|
1907
|
+
const m = /^v?(\d+|[xX*])(?:\.(\d+|[xX*]))?(?:\.(\d+|[xX*]))?(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/.exec(s);
|
|
1908
|
+
if (!m) return null;
|
|
1909
|
+
const nums = [];
|
|
1910
|
+
let wild = false;
|
|
1911
|
+
for (const part of [m[1], m[2], m[3]]) {
|
|
1912
|
+
if (wild || part === void 0 || /^[xX*]$/.test(part)) {
|
|
1913
|
+
wild = true;
|
|
1914
|
+
nums.push(null);
|
|
1915
|
+
} else nums.push(+part);
|
|
1684
1916
|
}
|
|
1685
|
-
return {
|
|
1917
|
+
return { nums, pre: m[4] && !wild ? m[4].split(".") : [] };
|
|
1686
1918
|
}
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1919
|
+
var ver = (major, minor, patch, pre = []) => ({ major, minor, patch, pre });
|
|
1920
|
+
function comparators(token) {
|
|
1921
|
+
const m = /^(\^|~>?|>=|<=|>|<|=)?\s*(.+)$/.exec(token);
|
|
1922
|
+
if (!m) return null;
|
|
1923
|
+
const op = m[1] ?? "";
|
|
1924
|
+
const p = partial(m[2]);
|
|
1925
|
+
if (!p) return null;
|
|
1926
|
+
const [major, mi, pa] = p.nums;
|
|
1927
|
+
if (major === null) return op === "<" || op === ">" ? [{ op: "<", v: ver(0, 0, 0, ["0"]) }] : [];
|
|
1928
|
+
const M = major;
|
|
1929
|
+
const lo = ver(M, mi ?? 0, pa ?? 0, p.pre);
|
|
1930
|
+
const next = (kind) => kind === "major" ? ver(M + 1, 0, 0, ["0"]) : kind === "minor" ? ver(M, (mi ?? 0) + 1, 0, ["0"]) : ver(M, mi ?? 0, (pa ?? 0) + 1, ["0"]);
|
|
1931
|
+
const upper = mi === null ? next("major") : pa === null ? next("minor") : null;
|
|
1932
|
+
const out = switchOp();
|
|
1933
|
+
if (p.pre.length) {
|
|
1934
|
+
for (const c of out) if (c.v === lo) c.pre = true;
|
|
1694
1935
|
}
|
|
1695
1936
|
return out;
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1937
|
+
function switchOp() {
|
|
1938
|
+
switch (op) {
|
|
1939
|
+
case "^": {
|
|
1940
|
+
const bound = M > 0 || mi === null ? next("major") : (mi ?? 0) > 0 || pa === null ? next("minor") : next("patch");
|
|
1941
|
+
return [
|
|
1942
|
+
{ op: ">=", v: lo },
|
|
1943
|
+
{ op: "<", v: bound }
|
|
1944
|
+
];
|
|
1945
|
+
}
|
|
1946
|
+
case "~":
|
|
1947
|
+
case "~>":
|
|
1948
|
+
return [
|
|
1949
|
+
{ op: ">=", v: lo },
|
|
1950
|
+
{ op: "<", v: mi === null ? next("major") : next("minor") }
|
|
1951
|
+
];
|
|
1952
|
+
case ">":
|
|
1953
|
+
return upper ? [{ op: ">=", v: upper }] : [{ op: ">", v: lo }];
|
|
1954
|
+
case ">=":
|
|
1955
|
+
return [{ op: ">=", v: lo }];
|
|
1956
|
+
case "<":
|
|
1957
|
+
return [{ op: "<", v: lo.pre.length ? lo : ver(M, mi ?? 0, pa ?? 0, ["0"]) }];
|
|
1958
|
+
case "<=":
|
|
1959
|
+
return upper ? [{ op: "<", v: upper }] : [{ op: "<=", v: lo }];
|
|
1960
|
+
default:
|
|
1961
|
+
return upper ? [
|
|
1962
|
+
{ op: ">=", v: lo },
|
|
1963
|
+
{ op: "<", v: upper }
|
|
1964
|
+
] : [{ op: "=", v: lo }];
|
|
1965
|
+
}
|
|
1708
1966
|
}
|
|
1709
|
-
if (cur.trim()) parts.push(cur);
|
|
1710
|
-
return parts.map((p) => p.trim()).filter(Boolean);
|
|
1711
1967
|
}
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
int8: "bigint",
|
|
1716
|
-
int2: "smallint",
|
|
1717
|
-
bool: "boolean",
|
|
1718
|
-
varchar: "character varying",
|
|
1719
|
-
timestamptz: "timestamp with time zone",
|
|
1720
|
-
float8: "double precision"
|
|
1721
|
-
};
|
|
1722
|
-
var MULTIWORD_TYPE = /^(?:double precision|character varying|character|bit varying|timestamp|time|interval)\b/;
|
|
1723
|
-
function argTypes(args) {
|
|
1724
|
-
const types = [];
|
|
1725
|
-
for (const raw of splitTop(args)) {
|
|
1726
|
-
let tokens = stripParens(raw.replace(/\s+(?:default\b|=).*$/, "")).trim().split(/\s+/).filter(Boolean);
|
|
1727
|
-
const mode = tokens[0];
|
|
1728
|
-
if (mode === "out") continue;
|
|
1729
|
-
if (mode === "in" || mode === "inout" || mode === "variadic") tokens = tokens.slice(1);
|
|
1730
|
-
const joined = tokens.join(" ");
|
|
1731
|
-
const type = tokens.length > 1 && !MULTIWORD_TYPE.test(joined) ? tokens.slice(1).join(" ") : joined;
|
|
1732
|
-
types.push(TYPE_ALIASES[type] ?? type);
|
|
1733
|
-
}
|
|
1734
|
-
return types;
|
|
1735
|
-
}
|
|
1736
|
-
function git(root, args) {
|
|
1737
|
-
const r = spawnSync("git", args, { cwd: root, encoding: "utf8" });
|
|
1738
|
-
return r.status === 0 ? r.stdout : null;
|
|
1968
|
+
function test(c, v) {
|
|
1969
|
+
const d = compareVersions(v, c.v);
|
|
1970
|
+
return c.op === ">=" ? d >= 0 : c.op === "<=" ? d <= 0 : c.op === ">" ? d > 0 : c.op === "<" ? d < 0 : d === 0;
|
|
1739
1971
|
}
|
|
1740
|
-
function
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
const sql = (p) => p !== void 0 && p.endsWith(".sql");
|
|
1751
|
-
const touched = new Set(untracked.split("\n").filter(sql));
|
|
1752
|
-
const edited = [];
|
|
1753
|
-
for (const row of diff.split("\n").filter(Boolean)) {
|
|
1754
|
-
const [status, a, b] = row.split(" ");
|
|
1755
|
-
if (status.startsWith("R")) {
|
|
1756
|
-
if (sql(b)) touched.add(b);
|
|
1757
|
-
if (sql(a)) edited.push({ file: a, status: "renamed" });
|
|
1972
|
+
function parseRange(range) {
|
|
1973
|
+
const alts = [];
|
|
1974
|
+
for (const raw of range.trim().split("||")) {
|
|
1975
|
+
const alt = raw.trim();
|
|
1976
|
+
const hyphen = /^(\S+)\s+-\s+(\S+)$/.exec(alt);
|
|
1977
|
+
if (hyphen) {
|
|
1978
|
+
const from = comparators(`>=${hyphen[1]}`);
|
|
1979
|
+
const to = comparators(`<=${hyphen[2]}`);
|
|
1980
|
+
if (!from || !to) return null;
|
|
1981
|
+
alts.push([...from, ...to]);
|
|
1758
1982
|
continue;
|
|
1759
1983
|
}
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
} else if (status.startsWith("D")) edited.push({ file: a, status: "deleted" });
|
|
1766
|
-
}
|
|
1767
|
-
return { touched, edited };
|
|
1768
|
-
}
|
|
1769
|
-
function checkSupabasePack(ctx) {
|
|
1770
|
-
const settings = ctx.config.supabase ?? {};
|
|
1771
|
-
const dir = settings.migrations ?? DEFAULT_MIGRATIONS;
|
|
1772
|
-
const abs = path14.join(ctx.root, dir);
|
|
1773
|
-
if (!existsSync(abs)) throw new DoctorConfigError(`the supabase pack reads ${dir}, which doesn't exist; set doctor.supabase.migrations`);
|
|
1774
|
-
const migrations = readdirSync(abs).filter((n) => n.endsWith(".sql")).sort().map((n) => ({ file: `${dir}/${n}`, statements: sqlStatements(readFileSync(path14.join(abs, n), "utf8")) }));
|
|
1775
|
-
const exposed = new Set((settings.exposedSchemas ?? DEFAULT_EXPOSED).map((s) => s.toLowerCase()));
|
|
1776
|
-
const base = settings.base ?? DEFAULT_BASE;
|
|
1777
|
-
const view = gitView(ctx.root, dir, base);
|
|
1778
|
-
if ("reason" in view) {
|
|
1779
|
-
if (view.repo) ctx.report({ rule: "migration-edited", level: "warn", file: dir, message: `can't check for edited migrations: ${view.reason}` });
|
|
1780
|
-
} else {
|
|
1781
|
-
for (const e of view.edited) {
|
|
1782
|
-
ctx.report({
|
|
1783
|
-
rule: "migration-edited",
|
|
1784
|
-
file: e.file,
|
|
1785
|
-
subject: e.file,
|
|
1786
|
-
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`
|
|
1787
|
-
});
|
|
1984
|
+
const set = [];
|
|
1985
|
+
for (const token of alt.replace(/(\^|~>?|>=|<=|>|<|=)\s+/g, "$1").split(/\s+/).filter(Boolean)) {
|
|
1986
|
+
const cs = comparators(token);
|
|
1987
|
+
if (!cs) return null;
|
|
1988
|
+
set.push(...cs);
|
|
1788
1989
|
}
|
|
1990
|
+
alts.push(set);
|
|
1789
1991
|
}
|
|
1790
|
-
|
|
1791
|
-
const afterSince = (file) => since === void 0 || path14.posix.basename(file) >= since;
|
|
1792
|
-
if ("reason" in view && since === void 0) {
|
|
1793
|
-
ctx.report({
|
|
1794
|
-
rule: "migration-grants",
|
|
1795
|
-
level: "warn",
|
|
1796
|
-
file: dir,
|
|
1797
|
-
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`
|
|
1798
|
-
});
|
|
1799
|
-
} else {
|
|
1800
|
-
const isNew = (file) => afterSince(file) && ("reason" in view || view.touched.has(file));
|
|
1801
|
-
checkGrants(ctx, migrations.filter((m) => isNew(m.file)), exposed);
|
|
1802
|
-
}
|
|
1803
|
-
checkRls(ctx, migrations, exposed);
|
|
1804
|
-
checkViewInvoker(ctx, migrations, exposed);
|
|
1805
|
-
checkDefinerSearchPath(ctx, migrations);
|
|
1806
|
-
checkTestingKit(ctx, migrations);
|
|
1807
|
-
}
|
|
1808
|
-
function checkTestingKit(ctx, migrations) {
|
|
1809
|
-
for (const { file, statements } of migrations) {
|
|
1810
|
-
const hit = statements.find(({ sql }) => /\bgenesis_testing\b/.test(sql));
|
|
1811
|
-
if (!hit) continue;
|
|
1812
|
-
ctx.report({
|
|
1813
|
-
rule: "migration-testing-kit",
|
|
1814
|
-
file,
|
|
1815
|
-
line: hit.line,
|
|
1816
|
-
subject: "genesis_testing",
|
|
1817
|
-
message: "a migration uses genesis_testing, the pgTAP kit for test databases only; move it to supabase/tests/database/000_genesis_testing.test.sql"
|
|
1818
|
-
});
|
|
1819
|
-
}
|
|
1992
|
+
return alts;
|
|
1820
1993
|
}
|
|
1821
|
-
function
|
|
1822
|
-
|
|
1994
|
+
function satisfies(version, range) {
|
|
1995
|
+
const v = parseVersion(version);
|
|
1996
|
+
const alts = parseRange(range);
|
|
1997
|
+
if (!v || !alts) return null;
|
|
1998
|
+
return alts.some(
|
|
1999
|
+
(set) => set.every((c) => test(c, v)) && (!v.pre.length || set.some((c) => c.pre && c.v.major === v.major && c.v.minor === v.minor && c.v.patch === v.patch))
|
|
2000
|
+
);
|
|
1823
2001
|
}
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
2002
|
+
var TRAIL_DEPTH = 6;
|
|
2003
|
+
var RESOLVE_EXTS2 = [".tsx", ".ts", ".jsx", ".js", ".mts", ".mjs"];
|
|
2004
|
+
var IMPORT_FROM = /^[ \t]*import\s+(type\s+)?([^;"'`]*?)\s*from\s*["']([^"']+)["']/gm;
|
|
2005
|
+
var EXPORT_FROM = /^[ \t]*export\s+(type\s+)?[^;"'`]*?\bfrom\s*["']([^"']+)["']/gm;
|
|
2006
|
+
var DYNAMIC = /\bimport\s*\(\s*["']([^"']+)["']/g;
|
|
2007
|
+
function stripForImports(code) {
|
|
2008
|
+
const out = [];
|
|
2009
|
+
const blank = (ch) => ch === "\n" ? "\n" : " ";
|
|
2010
|
+
const n = code.length;
|
|
2011
|
+
const templates = [];
|
|
2012
|
+
let depth = 0;
|
|
2013
|
+
let i = 0;
|
|
2014
|
+
let sure = true;
|
|
2015
|
+
const isSpecifier = () => /(?:\bfrom|(?:^|[;{}\n])\s*import|\bimport\s*\(|\brequire\s*\()\s*$/.test(out.slice(-40).join(""));
|
|
2016
|
+
const before = () => out.slice(-24).join("");
|
|
2017
|
+
const KEYWORD = /(?:^|[^\w$.])(?:return|typeof|instanceof|case|do|else|in|of|new|delete|void|throw|yield|await|from|import|export|default|require)\s*$/;
|
|
2018
|
+
const startsExpression = (b) => {
|
|
2019
|
+
const t = b.replace(/\s+$/, "");
|
|
2020
|
+
if (!t) return true;
|
|
2021
|
+
if (KEYWORD.test(b)) return true;
|
|
2022
|
+
return /[([{,;:=!&|?+\-*%<>~^}]$/.test(t);
|
|
1832
2023
|
};
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
2024
|
+
const exprStart = () => startsExpression(before());
|
|
2025
|
+
const taggedTemplate = () => {
|
|
2026
|
+
const b = out.slice(-48).join("");
|
|
2027
|
+
const m = /([A-Za-z_$][\w$.]*)$/.exec(b);
|
|
2028
|
+
return m !== null && startsExpression(b.slice(0, b.length - m[1].length));
|
|
2029
|
+
};
|
|
2030
|
+
const templateBody = () => {
|
|
2031
|
+
while (i < n) {
|
|
2032
|
+
const ch = code[i];
|
|
2033
|
+
if (ch === "\\") {
|
|
2034
|
+
out.push(" ", blank(code[i + 1] ?? ""));
|
|
2035
|
+
i += 2;
|
|
2036
|
+
} else if (ch === "`") {
|
|
2037
|
+
out.push("`");
|
|
2038
|
+
i++;
|
|
2039
|
+
return;
|
|
2040
|
+
} else if (ch === "$" && code[i + 1] === "{") {
|
|
2041
|
+
out.push("${");
|
|
2042
|
+
i += 2;
|
|
2043
|
+
templates.push(depth);
|
|
2044
|
+
depth++;
|
|
2045
|
+
return;
|
|
2046
|
+
} else {
|
|
2047
|
+
out.push(blank(ch));
|
|
2048
|
+
i++;
|
|
1850
2049
|
}
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
subject: name,
|
|
1862
|
-
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)`
|
|
1863
|
-
});
|
|
1864
|
-
}
|
|
1865
|
-
continue;
|
|
2050
|
+
}
|
|
2051
|
+
sure = false;
|
|
2052
|
+
};
|
|
2053
|
+
while (i < n && sure) {
|
|
2054
|
+
const ch = code[i];
|
|
2055
|
+
const next = code[i + 1];
|
|
2056
|
+
if (ch === "/" && next === "/") {
|
|
2057
|
+
while (i < n && code[i] !== "\n") {
|
|
2058
|
+
out.push(" ");
|
|
2059
|
+
i++;
|
|
1866
2060
|
}
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
ctx.report({
|
|
1874
|
-
rule: "migration-grants",
|
|
1875
|
-
file,
|
|
1876
|
-
line,
|
|
1877
|
-
subject: `schema ${s}`,
|
|
1878
|
-
message: `grants schema ${s} to ${roles.join(" and ")}; a schema outside the exposed ones stays closed to anon and public`
|
|
1879
|
-
});
|
|
1880
|
-
}
|
|
2061
|
+
} else if (ch === "/" && next === "*") {
|
|
2062
|
+
out.push(" ");
|
|
2063
|
+
i += 2;
|
|
2064
|
+
while (i < n && !(code[i] === "*" && code[i + 1] === "/")) {
|
|
2065
|
+
out.push(blank(code[i]));
|
|
2066
|
+
i++;
|
|
1881
2067
|
}
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
function checkRls(ctx, migrations, exposed) {
|
|
1886
|
-
const tables = /* @__PURE__ */ new Map();
|
|
1887
|
-
const name = String.raw`([\w$.]+)`;
|
|
1888
|
-
const target = String.raw`^alter table (?:if exists )?(?:only )?${name}`;
|
|
1889
|
-
for (const { file, statements } of migrations) {
|
|
1890
|
-
for (const { sql, line, bodies } of statements) {
|
|
1891
|
-
if (bodies.some((b) => /\benable row level security\b/.test(b))) for (const t of tables.values()) t.rls = true;
|
|
1892
|
-
const create = new RegExp(String.raw`^create (?:(?:global |local )?(?:temp|temporary) |unlogged )?table (?:if not exists )?${name}`).exec(sql);
|
|
1893
|
-
if (create) {
|
|
1894
|
-
if (!/^create (?:global |local )?(?:temp|temporary) /.test(sql)) tables.set(qualify(create[1]), { rls: false, file, line, disabled: false });
|
|
1895
|
-
continue;
|
|
2068
|
+
if (i < n) {
|
|
2069
|
+
out.push(" ");
|
|
2070
|
+
i += 2;
|
|
1896
2071
|
}
|
|
1897
|
-
|
|
1898
|
-
const
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
2072
|
+
} else if (ch === "/" && next !== ">" && code[i - 1] !== "<" && exprStart()) {
|
|
2073
|
+
const afterBrace = /[}>]\s*$/.test(before());
|
|
2074
|
+
const start = i;
|
|
2075
|
+
const mark = out.length;
|
|
2076
|
+
out.push("/");
|
|
2077
|
+
i++;
|
|
2078
|
+
let inClass = false;
|
|
2079
|
+
for (; ; ) {
|
|
2080
|
+
const c = code[i];
|
|
2081
|
+
if (c === void 0 || c === "\n") {
|
|
2082
|
+
if (afterBrace) {
|
|
2083
|
+
out.length = mark;
|
|
2084
|
+
out.push("/");
|
|
2085
|
+
i = start + 1;
|
|
2086
|
+
} else sure = false;
|
|
2087
|
+
break;
|
|
1906
2088
|
}
|
|
1907
|
-
|
|
2089
|
+
if (c === "\\") {
|
|
2090
|
+
out.push(" ", blank(code[i + 1] ?? ""));
|
|
2091
|
+
i += 2;
|
|
2092
|
+
continue;
|
|
2093
|
+
}
|
|
2094
|
+
i++;
|
|
2095
|
+
if (c === "[") inClass = true;
|
|
2096
|
+
else if (c === "]") inClass = false;
|
|
2097
|
+
else if (c === "/" && !inClass) {
|
|
2098
|
+
if (afterBrace && /[<>]/.test(code.slice(start + 1, i - 1))) {
|
|
2099
|
+
out.length = mark;
|
|
2100
|
+
out.push("/");
|
|
2101
|
+
i = start + 1;
|
|
2102
|
+
break;
|
|
2103
|
+
}
|
|
2104
|
+
out.push("/");
|
|
2105
|
+
break;
|
|
2106
|
+
}
|
|
2107
|
+
out.push(" ");
|
|
1908
2108
|
}
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
2109
|
+
if (out.length > mark + 1 || i > start + 1) while (i < n && /[a-z]/.test(code[i])) out.push(code[i++]);
|
|
2110
|
+
} else if ((ch === '"' || ch === "'") && exprStart()) {
|
|
2111
|
+
const keep = isSpecifier();
|
|
2112
|
+
out.push(ch);
|
|
2113
|
+
i++;
|
|
2114
|
+
while (i < n && code[i] !== ch && code[i] !== "\n") {
|
|
2115
|
+
if (code[i] === "\\") {
|
|
2116
|
+
out.push(keep ? code[i] : " ", keep ? code[i + 1] ?? "" : blank(code[i + 1] ?? ""));
|
|
2117
|
+
i += 2;
|
|
2118
|
+
} else {
|
|
2119
|
+
out.push(keep ? code[i] : blank(code[i]));
|
|
2120
|
+
i++;
|
|
1916
2121
|
}
|
|
1917
|
-
continue;
|
|
1918
2122
|
}
|
|
1919
|
-
|
|
1920
|
-
|
|
2123
|
+
if (code[i] !== ch) sure = false;
|
|
2124
|
+
else {
|
|
2125
|
+
out.push(code[i]);
|
|
2126
|
+
i++;
|
|
2127
|
+
}
|
|
2128
|
+
} else if (ch === "`" && (exprStart() || taggedTemplate())) {
|
|
2129
|
+
out.push("`");
|
|
2130
|
+
i++;
|
|
2131
|
+
templateBody();
|
|
2132
|
+
} else if (ch === "}" && templates.length && depth - 1 === templates[templates.length - 1]) {
|
|
2133
|
+
templates.pop();
|
|
2134
|
+
depth--;
|
|
2135
|
+
out.push("}");
|
|
2136
|
+
i++;
|
|
2137
|
+
templateBody();
|
|
2138
|
+
} else {
|
|
2139
|
+
if (ch === "{") depth++;
|
|
2140
|
+
else if (ch === "}") depth--;
|
|
2141
|
+
out.push(ch);
|
|
2142
|
+
i++;
|
|
1921
2143
|
}
|
|
1922
2144
|
}
|
|
1923
|
-
|
|
1924
|
-
if (at.rls || !exposed.has(schemaOf(t))) continue;
|
|
1925
|
-
ctx.report({
|
|
1926
|
-
rule: "migration-rls",
|
|
1927
|
-
file: at.file,
|
|
1928
|
-
line: at.line,
|
|
1929
|
-
subject: t,
|
|
1930
|
-
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`
|
|
1931
|
-
});
|
|
1932
|
-
}
|
|
2145
|
+
return sure && templates.length === 0 ? out.join("") : null;
|
|
1933
2146
|
}
|
|
1934
|
-
function
|
|
1935
|
-
const
|
|
1936
|
-
const
|
|
1937
|
-
const
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
if (create) {
|
|
1942
|
-
if (/^create (?:or replace )?(?:temp|temporary) /.test(sql)) continue;
|
|
1943
|
-
const options = /^[^(]*?\bwith\s*(\([^)]*\))\s*as\b/.exec(sql)?.[1] ?? "";
|
|
1944
|
-
views.set(qualify(create[1]), { invoker: invokerOn.test(options), file, line });
|
|
1945
|
-
continue;
|
|
1946
|
-
}
|
|
1947
|
-
const alter = new RegExp(String.raw`^alter view (?:if exists )?${name} (set|reset) (\([^)]*\))`).exec(sql);
|
|
1948
|
-
if (alter && /\bsecurity_invoker\b/.test(alter[3])) {
|
|
1949
|
-
const state = views.get(qualify(alter[1]));
|
|
1950
|
-
if (state) state.invoker = alter[2] === "set" && invokerOn.test(alter[3]);
|
|
1951
|
-
continue;
|
|
1952
|
-
}
|
|
1953
|
-
const rename = new RegExp(String.raw`^alter view (?:if exists )?${name} rename to ([\w$]+)$`).exec(sql);
|
|
1954
|
-
if (rename) {
|
|
1955
|
-
const from = qualify(rename[1]);
|
|
1956
|
-
const state = views.get(from);
|
|
1957
|
-
if (state) {
|
|
1958
|
-
views.delete(from);
|
|
1959
|
-
views.set(`${schemaOf(from)}.${rename[2]}`, state);
|
|
1960
|
-
}
|
|
1961
|
-
continue;
|
|
1962
|
-
}
|
|
1963
|
-
const drop = /^drop view (?:if exists )?(.+?)(?: cascade| restrict)?$/.exec(sql);
|
|
1964
|
-
if (drop) for (const n of drop[1].split(",")) views.delete(qualify(n));
|
|
1965
|
-
}
|
|
2147
|
+
function bindings(clause) {
|
|
2148
|
+
const out = [];
|
|
2149
|
+
const named = /\{([^}]*)\}/.exec(clause);
|
|
2150
|
+
for (const part of named?.[1].split(",") ?? []) {
|
|
2151
|
+
const p = part.trim();
|
|
2152
|
+
if (!p || p.startsWith("type ")) continue;
|
|
2153
|
+
out.push(p.split(/\s+as\s+/).pop().trim());
|
|
1966
2154
|
}
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
2155
|
+
const rest = clause.replace(/\{[^}]*\}/, "");
|
|
2156
|
+
const ns = /\*\s*as\s+([\w$]+)/.exec(rest);
|
|
2157
|
+
if (ns) out.push(ns[1]);
|
|
2158
|
+
const def = /^\s*([\w$]+)/.exec(rest);
|
|
2159
|
+
if (def && def[1] !== "as") out.push(def[1]);
|
|
2160
|
+
return out;
|
|
2161
|
+
}
|
|
2162
|
+
function readJsonc(file) {
|
|
2163
|
+
try {
|
|
2164
|
+
const text = readFileSync(file, "utf8").replace(/("(?:\\.|[^"\\])*")|\/\/[^\n]*|\/\*[\s\S]*?\*\//g, (m, str) => str ?? "").replace(/,(\s*[}\]])/g, "$1");
|
|
2165
|
+
return JSON.parse(text);
|
|
2166
|
+
} catch {
|
|
2167
|
+
return null;
|
|
1976
2168
|
}
|
|
1977
2169
|
}
|
|
1978
|
-
function
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
const
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
const
|
|
1999
|
-
|
|
2000
|
-
const rename = / rename to ([\w$]+)$/.exec(sql);
|
|
2001
|
-
const move = / set schema ([\w$]+)$/.exec(sql);
|
|
2002
|
-
for (const key2 of keys) {
|
|
2003
|
-
const state = fns.get(key2);
|
|
2004
|
-
if (rename || move) {
|
|
2005
|
-
if (!state) continue;
|
|
2006
|
-
fns.delete(key2);
|
|
2007
|
-
const newName = rename ? `${schemaOf(fnName)}.${rename[1]}` : `${move[1]}.${fnName.split(".")[1]}`;
|
|
2008
|
-
fns.set(newName + key2.slice(fnName.length), state);
|
|
2009
|
-
continue;
|
|
2010
|
-
}
|
|
2011
|
-
const next = state ?? { definer: false, searchPath: false, file, line };
|
|
2012
|
-
if (/\bsecurity definer\b/.test(sql)) Object.assign(next, { definer: true, file, line });
|
|
2013
|
-
if (/\bsecurity invoker\b/.test(sql)) next.definer = false;
|
|
2014
|
-
if (/\bset search_path\b/.test(sql)) next.searchPath = true;
|
|
2015
|
-
if (/\breset (?:search_path|all)\b/.test(sql)) Object.assign(next, { searchPath: false, file, line });
|
|
2016
|
-
fns.set(key2, next);
|
|
2017
|
-
}
|
|
2018
|
-
continue;
|
|
2019
|
-
}
|
|
2020
|
-
const drop = /^drop (?:function|procedure|routine) (?:if exists )?(.+?)(?: cascade| restrict)?$/.exec(sql);
|
|
2021
|
-
if (drop) {
|
|
2022
|
-
for (const part of splitTop(drop[1])) {
|
|
2023
|
-
const m = /^([\w$.]+)\s*/.exec(part);
|
|
2024
|
-
if (m) for (const key2 of keysFor(part, m[0].length, qualify(m[1]))) fns.delete(key2);
|
|
2025
|
-
}
|
|
2170
|
+
function readTsconfig(root, file, seen = /* @__PURE__ */ new Set()) {
|
|
2171
|
+
if (seen.has(file) || seen.size > 10) return {};
|
|
2172
|
+
seen.add(file);
|
|
2173
|
+
const json = readJsonc(file);
|
|
2174
|
+
if (!json) return {};
|
|
2175
|
+
const dir = path14.dirname(file);
|
|
2176
|
+
let merged = {};
|
|
2177
|
+
const parents = typeof json.extends === "string" ? [json.extends] : Array.isArray(json.extends) ? json.extends : [];
|
|
2178
|
+
for (const ext of parents) {
|
|
2179
|
+
if (typeof ext !== "string") continue;
|
|
2180
|
+
let target = null;
|
|
2181
|
+
if (ext.startsWith(".") || path14.isAbsolute(ext)) {
|
|
2182
|
+
const abs = path14.resolve(dir, ext);
|
|
2183
|
+
target = existsSync(abs) && statSync(abs).isFile() ? abs : existsSync(`${abs}.json`) ? `${abs}.json` : null;
|
|
2184
|
+
} else {
|
|
2185
|
+
const parts = ext.split("/");
|
|
2186
|
+
const nameLength = ext.startsWith("@") ? 2 : 1;
|
|
2187
|
+
const pkgDir = findPackageDir(root, parts.slice(0, nameLength).join("/"));
|
|
2188
|
+
if (pkgDir) {
|
|
2189
|
+
const sub = parts.slice(nameLength).join("/");
|
|
2190
|
+
const abs = path14.join(pkgDir, sub || "tsconfig.json");
|
|
2191
|
+
target = existsSync(abs) && statSync(abs).isFile() ? abs : existsSync(`${abs}.json`) ? `${abs}.json` : null;
|
|
2026
2192
|
}
|
|
2027
2193
|
}
|
|
2194
|
+
if (target) merged = { ...merged, ...readTsconfig(root, target, seen) };
|
|
2028
2195
|
}
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
line: at.line,
|
|
2035
|
-
subject: key2,
|
|
2036
|
-
message: `${key2} 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`
|
|
2037
|
-
});
|
|
2196
|
+
const opts = json.compilerOptions ?? {};
|
|
2197
|
+
if (typeof opts.baseUrl === "string") merged.baseUrl = path14.resolve(dir, opts.baseUrl);
|
|
2198
|
+
if (opts.paths && typeof opts.paths === "object") {
|
|
2199
|
+
merged.paths = opts.paths;
|
|
2200
|
+
merged.pathsDir = dir;
|
|
2038
2201
|
}
|
|
2202
|
+
return merged;
|
|
2039
2203
|
}
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
const
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
if (have === want) continue;
|
|
2055
|
-
ctx.report({
|
|
2056
|
-
rule: "version-skew",
|
|
2057
|
-
level: "warn",
|
|
2058
|
-
file: "package.json",
|
|
2059
|
-
subject: name,
|
|
2060
|
-
message: `${name} is ${have}, but ${UMBRELLA_PACKAGE} ${manifest.version} was released with ${want}. Install ${name}@${want}, or move every Genesis package to one release.`
|
|
2061
|
-
});
|
|
2204
|
+
function aliases(root) {
|
|
2205
|
+
const table = [];
|
|
2206
|
+
let baseUrl = null;
|
|
2207
|
+
for (const name of ["tsconfig.json", "tsconfig.app.json", "jsconfig.json"]) {
|
|
2208
|
+
const file = path14.join(root, name);
|
|
2209
|
+
if (!existsSync(file)) continue;
|
|
2210
|
+
const config = readTsconfig(root, file);
|
|
2211
|
+
baseUrl ??= config.baseUrl ?? null;
|
|
2212
|
+
const base = config.baseUrl ?? config.pathsDir ?? root;
|
|
2213
|
+
for (const [pattern, targets] of Object.entries(config.paths ?? {})) {
|
|
2214
|
+
if (!Array.isArray(targets)) continue;
|
|
2215
|
+
const exact = !pattern.endsWith("*");
|
|
2216
|
+
table.push({ prefix: pattern.replace(/\*$/, ""), exact, targets: targets.map((t) => path14.join(base, String(t).replace(/\*$/, ""))) });
|
|
2217
|
+
}
|
|
2062
2218
|
}
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
function parseVersion(v) {
|
|
2068
|
-
const m = VERSION.exec(v.trim());
|
|
2069
|
-
return m ? { major: +m[1], minor: +m[2], patch: +m[3], pre: m[4] ? m[4].split(".") : [] } : null;
|
|
2070
|
-
}
|
|
2071
|
-
function compareVersions(a, b) {
|
|
2072
|
-
for (const k of ["major", "minor", "patch"]) if (a[k] !== b[k]) return a[k] < b[k] ? -1 : 1;
|
|
2073
|
-
if (!a.pre.length || !b.pre.length) return a.pre.length ? -1 : b.pre.length ? 1 : 0;
|
|
2074
|
-
for (let i = 0; i < Math.max(a.pre.length, b.pre.length); i++) {
|
|
2075
|
-
const x = a.pre[i];
|
|
2076
|
-
const y = b.pre[i];
|
|
2077
|
-
if (x === void 0) return -1;
|
|
2078
|
-
if (y === void 0) return 1;
|
|
2079
|
-
if (x === y) continue;
|
|
2080
|
-
const nx = /^\d+$/.test(x);
|
|
2081
|
-
const ny = /^\d+$/.test(y);
|
|
2082
|
-
if (nx && ny) return +x < +y ? -1 : 1;
|
|
2083
|
-
if (nx !== ny) return nx ? -1 : 1;
|
|
2084
|
-
return x < y ? -1 : 1;
|
|
2219
|
+
const pkg = readJsonc(path14.join(root, "package.json"));
|
|
2220
|
+
for (const [pattern, target] of Object.entries(pkg?.imports ?? {})) {
|
|
2221
|
+
if (typeof target !== "string") continue;
|
|
2222
|
+
table.push({ prefix: pattern.replace(/\*.*$/, ""), exact: !pattern.includes("*"), targets: [path14.join(root, target.replace(/\*.*$/, ""))] });
|
|
2085
2223
|
}
|
|
2086
|
-
|
|
2224
|
+
for (const prefix of ["@/", "~/", "#/"]) table.push({ prefix, exact: false, targets: [path14.join(root, "src") + path14.sep, root + path14.sep] });
|
|
2225
|
+
return { table, baseUrl };
|
|
2087
2226
|
}
|
|
2088
|
-
function
|
|
2089
|
-
const
|
|
2090
|
-
if (
|
|
2091
|
-
const
|
|
2092
|
-
|
|
2093
|
-
for (const part of [m[1], m[2], m[3]]) {
|
|
2094
|
-
if (wild || part === void 0 || /^[xX*]$/.test(part)) {
|
|
2095
|
-
wild = true;
|
|
2096
|
-
nums.push(null);
|
|
2097
|
-
} else nums.push(+part);
|
|
2227
|
+
function resolveFile(base) {
|
|
2228
|
+
const tries = [base, ...RESOLVE_EXTS2.map((e) => base + e), ...RESOLVE_EXTS2.map((e) => path14.join(base, `index${e}`))];
|
|
2229
|
+
if (/\.[mc]?js$/.test(base)) tries.push(...[".ts", ".tsx"].map((e) => base.replace(/\.[mc]?js$/, e)));
|
|
2230
|
+
for (const p of tries) {
|
|
2231
|
+
if (SCRIPT_EXTS2.has(path14.extname(p)) && existsSync(p) && statSync(p).isFile()) return p;
|
|
2098
2232
|
}
|
|
2099
|
-
return
|
|
2233
|
+
return null;
|
|
2100
2234
|
}
|
|
2101
|
-
var
|
|
2102
|
-
function
|
|
2103
|
-
|
|
2104
|
-
if (!
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
const
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
if (p.pre.length) {
|
|
2116
|
-
for (const c of out) if (c.v === lo) c.pre = true;
|
|
2235
|
+
var trails = /* @__PURE__ */ new WeakMap();
|
|
2236
|
+
function trailFor(ctx) {
|
|
2237
|
+
let t = trails.get(ctx.files);
|
|
2238
|
+
if (!t) trails.set(ctx.files, t = createTrail(ctx));
|
|
2239
|
+
return t;
|
|
2240
|
+
}
|
|
2241
|
+
function createTrail(ctx) {
|
|
2242
|
+
const { table, baseUrl } = aliases(ctx.root);
|
|
2243
|
+
let declared = null;
|
|
2244
|
+
try {
|
|
2245
|
+
const pkg = JSON.parse(readFileSync(path14.join(ctx.root, "package.json"), "utf8"));
|
|
2246
|
+
declared = new Set(["dependencies", "devDependencies", "peerDependencies", "optionalDependencies"].flatMap((k) => Object.keys(pkg[k] ?? {})));
|
|
2247
|
+
} catch {
|
|
2248
|
+
declared = null;
|
|
2117
2249
|
}
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2250
|
+
const byPath = new Map(ctx.files.map((f) => [f.absolutePath, f]));
|
|
2251
|
+
const read = (abs) => byPath.get(abs) ?? readSource(abs);
|
|
2252
|
+
const importsCache = /* @__PURE__ */ new Map();
|
|
2253
|
+
const importsOf = (file) => {
|
|
2254
|
+
const hit = importsCache.get(file.absolutePath);
|
|
2255
|
+
if (hit) return hit;
|
|
2256
|
+
const files = [];
|
|
2257
|
+
let lost = false;
|
|
2258
|
+
const code = stripped(file);
|
|
2259
|
+
if (code === null) {
|
|
2260
|
+
const out2 = { files: [], lost: true };
|
|
2261
|
+
importsCache.set(file.absolutePath, out2);
|
|
2262
|
+
return out2;
|
|
2263
|
+
}
|
|
2264
|
+
const used = new Set(renderedElements(code).map((e) => e.split(".")[0]));
|
|
2265
|
+
for (const m of code.matchAll(/\b\w*[cC]omponent\s*:\s*([A-Za-z_$][\w$]*)/g)) used.add(m[1]);
|
|
2266
|
+
for (const m of code.matchAll(/\bexport\s+default\s+([A-Za-z_$][\w$]*)/g)) used.add(m[1]);
|
|
2267
|
+
for (const m of code.matchAll(/\bexport\s*\{([^}]*)\}\s*;/g)) for (const n of m[1].split(",")) used.add(n.trim().split(/\s+as\s+/)[0]);
|
|
2268
|
+
const specs = [];
|
|
2269
|
+
for (const m of code.matchAll(IMPORT_FROM)) if (!m[1] && bindings(m[2]).some((b) => used.has(b))) specs.push(m[3]);
|
|
2270
|
+
for (const m of code.matchAll(EXPORT_FROM)) if (!m[1]) specs.push(m[2]);
|
|
2271
|
+
for (const m of code.matchAll(DYNAMIC)) specs.push(m[1]);
|
|
2272
|
+
for (const spec of specs) {
|
|
2273
|
+
if (/^(?:node:|https?:|data:|virtual:)/.test(spec) || /\.(?:css|scss|sass|less|svg|png|jpe?g|gif|webp|json|md|mdx)(?:\?.*)?$/.test(spec)) continue;
|
|
2274
|
+
let resolved = null;
|
|
2275
|
+
if (spec.startsWith(".")) {
|
|
2276
|
+
resolved = resolveFile(path14.resolve(path14.dirname(file.absolutePath), spec));
|
|
2277
|
+
if (!resolved) lost = true;
|
|
2278
|
+
} else {
|
|
2279
|
+
const alias = table.find((a) => a.exact ? spec === a.prefix : spec.startsWith(a.prefix));
|
|
2280
|
+
if (alias) {
|
|
2281
|
+
for (const t of alias.targets) {
|
|
2282
|
+
resolved = resolveFile(alias.exact ? t : path14.join(t, spec.slice(alias.prefix.length)));
|
|
2283
|
+
if (resolved) break;
|
|
2284
|
+
}
|
|
2285
|
+
}
|
|
2286
|
+
if (!resolved && baseUrl && !spec.startsWith("#")) resolved = resolveFile(path14.join(baseUrl, spec));
|
|
2287
|
+
if (!resolved) {
|
|
2288
|
+
const pkg = spec.split("/").slice(0, spec.startsWith("@") ? 2 : 1).join("/");
|
|
2289
|
+
if (spec.startsWith("#") || declared && !declared.has(pkg) && !findPackageDir(ctx.root, pkg)) lost = true;
|
|
2290
|
+
}
|
|
2127
2291
|
}
|
|
2128
|
-
|
|
2129
|
-
case "~>":
|
|
2130
|
-
return [
|
|
2131
|
-
{ op: ">=", v: lo },
|
|
2132
|
-
{ op: "<", v: mi === null ? next("major") : next("minor") }
|
|
2133
|
-
];
|
|
2134
|
-
case ">":
|
|
2135
|
-
return upper ? [{ op: ">=", v: upper }] : [{ op: ">", v: lo }];
|
|
2136
|
-
case ">=":
|
|
2137
|
-
return [{ op: ">=", v: lo }];
|
|
2138
|
-
case "<":
|
|
2139
|
-
return [{ op: "<", v: lo.pre.length ? lo : ver(M, mi ?? 0, pa ?? 0, ["0"]) }];
|
|
2140
|
-
case "<=":
|
|
2141
|
-
return upper ? [{ op: "<", v: upper }] : [{ op: "<=", v: lo }];
|
|
2142
|
-
default:
|
|
2143
|
-
return upper ? [
|
|
2144
|
-
{ op: ">=", v: lo },
|
|
2145
|
-
{ op: "<", v: upper }
|
|
2146
|
-
] : [{ op: "=", v: lo }];
|
|
2292
|
+
if (resolved && !files.includes(resolved)) files.push(resolved);
|
|
2147
2293
|
}
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2294
|
+
const out = { files, lost };
|
|
2295
|
+
importsCache.set(file.absolutePath, out);
|
|
2296
|
+
return out;
|
|
2297
|
+
};
|
|
2298
|
+
const strippedCache = /* @__PURE__ */ new Map();
|
|
2299
|
+
const stripped = (file) => {
|
|
2300
|
+
if (!strippedCache.has(file.absolutePath)) strippedCache.set(file.absolutePath, stripForImports(file.code));
|
|
2301
|
+
return strippedCache.get(file.absolutePath);
|
|
2302
|
+
};
|
|
2303
|
+
const memo = /* @__PURE__ */ new WeakMap();
|
|
2304
|
+
const reach = (file, test2, depth, seen) => {
|
|
2305
|
+
let cache2 = memo.get(test2);
|
|
2306
|
+
if (!cache2) memo.set(test2, cache2 = { free: /* @__PURE__ */ new Map(), cut: /* @__PURE__ */ new Map() });
|
|
2307
|
+
const k = `${file.absolutePath}\0${depth}`;
|
|
2308
|
+
const free = cache2.free.get(k);
|
|
2309
|
+
if (free) return [free, /* @__PURE__ */ new Set()];
|
|
2310
|
+
const reusable = cache2.cut.get(k)?.find((e) => e.cut.every((m) => seen.has(m)));
|
|
2311
|
+
if (reusable) return [reusable.result, new Set(reusable.cut)];
|
|
2312
|
+
let result;
|
|
2313
|
+
const cut = /* @__PURE__ */ new Set();
|
|
2314
|
+
const code = stripped(file);
|
|
2315
|
+
if (code === null) result = "unknown";
|
|
2316
|
+
else if (test2(code)) result = "yes";
|
|
2317
|
+
else {
|
|
2318
|
+
const { files, lost } = importsOf(file);
|
|
2319
|
+
let unknown = lost && depth > 0;
|
|
2320
|
+
result = "no";
|
|
2321
|
+
if (depth > 0) {
|
|
2322
|
+
seen.add(file.absolutePath);
|
|
2323
|
+
for (const abs of files) {
|
|
2324
|
+
if (seen.has(abs)) {
|
|
2325
|
+
cut.add(abs);
|
|
2326
|
+
continue;
|
|
2327
|
+
}
|
|
2328
|
+
const target = read(abs);
|
|
2329
|
+
if (!target) {
|
|
2330
|
+
unknown = true;
|
|
2331
|
+
continue;
|
|
2332
|
+
}
|
|
2333
|
+
const [r, c] = reach(target, test2, depth - 1, seen);
|
|
2334
|
+
for (const m of c) cut.add(m);
|
|
2335
|
+
if (r === "yes") {
|
|
2336
|
+
result = "yes";
|
|
2337
|
+
break;
|
|
2338
|
+
}
|
|
2339
|
+
if (r === "unknown") unknown = true;
|
|
2340
|
+
}
|
|
2341
|
+
seen.delete(file.absolutePath);
|
|
2342
|
+
cut.delete(file.absolutePath);
|
|
2343
|
+
}
|
|
2344
|
+
if (result === "no" && unknown) result = "unknown";
|
|
2165
2345
|
}
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
if (!cs) return null;
|
|
2170
|
-
set.push(...cs);
|
|
2346
|
+
if (result === "yes" || cut.size === 0) {
|
|
2347
|
+
cache2.free.set(k, result);
|
|
2348
|
+
return [result, /* @__PURE__ */ new Set()];
|
|
2171
2349
|
}
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
const alts = parseRange(range);
|
|
2179
|
-
if (!v || !alts) return null;
|
|
2180
|
-
return alts.some(
|
|
2181
|
-
(set) => set.every((c) => test(c, v)) && (!v.pre.length || set.some((c) => c.pre && c.v.major === v.major && c.v.minor === v.minor && c.v.patch === v.patch))
|
|
2182
|
-
);
|
|
2350
|
+
const entries = cache2.cut.get(k) ?? [];
|
|
2351
|
+
entries.push({ cut: [...cut], result });
|
|
2352
|
+
cache2.cut.set(k, entries);
|
|
2353
|
+
return [result, cut];
|
|
2354
|
+
};
|
|
2355
|
+
return { reach: (file, test2, depth = TRAIL_DEPTH) => reach(file, test2, depth, /* @__PURE__ */ new Set())[0] };
|
|
2183
2356
|
}
|
|
2184
2357
|
|
|
2185
|
-
// src/doctor/
|
|
2186
|
-
var
|
|
2187
|
-
var
|
|
2188
|
-
var
|
|
2189
|
-
var
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2358
|
+
// src/doctor/packages.ts
|
|
2359
|
+
var SOURCE = /\.(?:[cm]?[jt]sx?)$/;
|
|
2360
|
+
var SKIP_DIRS2 = /* @__PURE__ */ new Set(["node_modules", "dist", "build", "coverage", ".turbo"]);
|
|
2361
|
+
var BUILTINS = new Set(builtinModules.flatMap((m) => [m, `node:${m}`]));
|
|
2362
|
+
var IMPORT = /(?:\bfrom\s*|\bimport\s*\(\s*|\bimport\s+|\brequire\s*\(\s*)["']([^"']+)["']/g;
|
|
2363
|
+
var TYPE_ONLY = /\b(?:import|export)\s+type\s+(?:\{[^}]*\}|\*\s+as\s+[\w$]+|\*|[\w$]+)\s*from\s*["'][^"']+["']/g;
|
|
2364
|
+
function sourceFiles(dir, rel = "") {
|
|
2365
|
+
const out = [];
|
|
2366
|
+
for (const entry of readdirSync(path14.join(dir, rel)).sort()) {
|
|
2367
|
+
if (entry.startsWith(".") || SKIP_DIRS2.has(entry)) continue;
|
|
2368
|
+
const child = rel ? `${rel}/${entry}` : entry;
|
|
2369
|
+
const stat = lstatSync(path14.join(dir, child));
|
|
2370
|
+
if (stat.isSymbolicLink()) continue;
|
|
2371
|
+
if (stat.isDirectory()) out.push(...sourceFiles(dir, child));
|
|
2372
|
+
else if (SOURCE.test(entry) && !entry.endsWith(".d.ts")) out.push(child);
|
|
2194
2373
|
}
|
|
2195
|
-
|
|
2196
|
-
|
|
2374
|
+
return out;
|
|
2375
|
+
}
|
|
2376
|
+
function packageName2(specifier) {
|
|
2377
|
+
const parts = specifier.split("/");
|
|
2378
|
+
return specifier.startsWith("@") ? parts.slice(0, 2).join("/") : parts[0];
|
|
2379
|
+
}
|
|
2380
|
+
function git(root, args) {
|
|
2381
|
+
const r = spawnSync("git", args, { cwd: root, encoding: "utf8" });
|
|
2382
|
+
return r.status === 0 ? r.stdout : null;
|
|
2383
|
+
}
|
|
2384
|
+
function matchPattern(pattern, spec) {
|
|
2385
|
+
const star = pattern.indexOf("*");
|
|
2386
|
+
if (star < 0) return pattern === spec ? "" : null;
|
|
2387
|
+
const head = pattern.slice(0, star);
|
|
2388
|
+
const tail = pattern.slice(star + 1);
|
|
2389
|
+
return spec.startsWith(head) && spec.endsWith(tail) && spec.length >= head.length + tail.length ? spec.slice(head.length, spec.length - tail.length) : null;
|
|
2390
|
+
}
|
|
2391
|
+
function tsconfigPaths(dir) {
|
|
2392
|
+
const file = path14.join(dir, "tsconfig.json");
|
|
2393
|
+
if (!existsSync(file)) return [];
|
|
2197
2394
|
try {
|
|
2198
|
-
|
|
2395
|
+
const text = readFileSync(file, "utf8").replace(/\/\*[\s\S]*?\*\//g, "").replace(/(^|[\s{,[])\/\/[^\n]*/g, "$1").replace(/,(\s*[}\]])/g, "$1");
|
|
2396
|
+
const options = JSON.parse(text).compilerOptions ?? {};
|
|
2397
|
+
const base = path14.resolve(dir, options.baseUrl ?? ".");
|
|
2398
|
+
return Object.entries(options.paths ?? {}).map(([pattern, targets]) => ({ pattern, targets: targets.map((t) => path14.resolve(base, t)) }));
|
|
2199
2399
|
} catch {
|
|
2200
|
-
return
|
|
2400
|
+
return [];
|
|
2401
|
+
}
|
|
2402
|
+
}
|
|
2403
|
+
function checkImports2(ctx, pkg, json) {
|
|
2404
|
+
const aliases2 = tsconfigPaths(pkg.dir);
|
|
2405
|
+
const subpathImports = Object.keys(json.imports ?? {});
|
|
2406
|
+
const viaAlias = (spec) => {
|
|
2407
|
+
if (spec.startsWith("#")) return subpathImports.some((k) => matchPattern(k, spec) !== null) ? true : null;
|
|
2408
|
+
for (const { pattern, targets } of aliases2) {
|
|
2409
|
+
const hit = matchPattern(pattern, spec);
|
|
2410
|
+
if (hit === null) continue;
|
|
2411
|
+
return targets.some((t) => {
|
|
2412
|
+
const rel = path14.relative(pkg.dir, t.replace("*", hit));
|
|
2413
|
+
return !rel.startsWith("..") && !path14.isAbsolute(rel);
|
|
2414
|
+
});
|
|
2415
|
+
}
|
|
2416
|
+
return null;
|
|
2417
|
+
};
|
|
2418
|
+
const declared = /* @__PURE__ */ new Set([
|
|
2419
|
+
json.name,
|
|
2420
|
+
...Object.keys(json.dependencies ?? {}),
|
|
2421
|
+
...Object.keys(json.peerDependencies ?? {}),
|
|
2422
|
+
...Object.keys(json.devDependencies ?? {}),
|
|
2423
|
+
...Object.keys(json.optionalDependencies ?? {})
|
|
2424
|
+
]);
|
|
2425
|
+
for (const file of sourceFiles(pkg.dir)) {
|
|
2426
|
+
const code = stripForImports(readFileSync(path14.join(pkg.dir, file), "utf8"));
|
|
2427
|
+
if (code === null) continue;
|
|
2428
|
+
const at = `${pkg.rel}/${file}`;
|
|
2429
|
+
const typeOnly = [...code.matchAll(TYPE_ONLY)].map((m) => [m.index, m.index + m[0].length]);
|
|
2430
|
+
let offset = 0;
|
|
2431
|
+
code.split("\n").forEach((text, i) => {
|
|
2432
|
+
const lineStart = offset;
|
|
2433
|
+
offset += text.length + 1;
|
|
2434
|
+
for (const m of text.matchAll(IMPORT)) {
|
|
2435
|
+
const spec = m[1];
|
|
2436
|
+
const line = i + 1;
|
|
2437
|
+
const at0 = lineStart + m.index;
|
|
2438
|
+
if (typeOnly.some(([a, b]) => at0 >= a && at0 < b)) continue;
|
|
2439
|
+
const alias = viaAlias(spec);
|
|
2440
|
+
if (alias === true) continue;
|
|
2441
|
+
if (alias === false) {
|
|
2442
|
+
ctx.report({ rule: "package-app-import", file: at, line, subject: spec, message: `${pkg.name} imports ${spec}, an alias that points outside the package` });
|
|
2443
|
+
continue;
|
|
2444
|
+
}
|
|
2445
|
+
if (spec.startsWith("#")) continue;
|
|
2446
|
+
if (spec.startsWith("@/") || spec.startsWith("~/")) {
|
|
2447
|
+
ctx.report({ rule: "package-app-import", file: at, line, subject: spec, message: `${pkg.name} imports the app's own code (${spec}); a package may only use its own files and its declared dependencies` });
|
|
2448
|
+
continue;
|
|
2449
|
+
}
|
|
2450
|
+
if (spec.startsWith(".")) {
|
|
2451
|
+
const target = path14.resolve(pkg.dir, path14.dirname(file), spec);
|
|
2452
|
+
const rel = path14.relative(pkg.dir, target);
|
|
2453
|
+
if (rel.startsWith("..") || path14.isAbsolute(rel)) {
|
|
2454
|
+
ctx.report({ rule: "package-app-import", file: at, line, subject: spec, message: `${pkg.name} reaches outside its folder (${spec}); move what it needs into the package or a dependency` });
|
|
2455
|
+
}
|
|
2456
|
+
continue;
|
|
2457
|
+
}
|
|
2458
|
+
if (BUILTINS.has(spec) || spec.startsWith("node:") || spec.startsWith("virtual:") || /^[a-z]+:/.test(spec)) continue;
|
|
2459
|
+
const name = packageName2(spec);
|
|
2460
|
+
if (!declared.has(name)) {
|
|
2461
|
+
ctx.report({ rule: "package-undeclared-dependency", file: at, line, subject: name, message: `${pkg.name} imports ${name}, which its package.json doesn't list; add it to dependencies or peerDependencies` });
|
|
2462
|
+
}
|
|
2463
|
+
}
|
|
2464
|
+
});
|
|
2201
2465
|
}
|
|
2202
|
-
};
|
|
2203
|
-
var LOCKFILES = ["bun.lock", "bun.lockb", "package-lock.json", "npm-shrinkwrap.json", "yarn.lock", "pnpm-lock.yaml"];
|
|
2204
|
-
function nodeModulesOf(dir) {
|
|
2205
|
-
const parent = path14.dirname(dir);
|
|
2206
|
-
return path14.basename(parent).startsWith("@") ? path14.dirname(parent) : parent;
|
|
2207
2466
|
}
|
|
2208
|
-
function
|
|
2209
|
-
|
|
2210
|
-
const
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2467
|
+
function checkMigrations(ctx, pkg, json) {
|
|
2468
|
+
const declaredFiles = /* @__PURE__ */ new Set();
|
|
2469
|
+
for (const [id, raw] of Object.entries(rawBlocksOf(json))) {
|
|
2470
|
+
const migrations = raw.migrations ?? [];
|
|
2471
|
+
for (const m of migrations) {
|
|
2472
|
+
if (typeof m.file === "string" && typeof m.test === "string") declaredFiles.add(m.file);
|
|
2473
|
+
if (typeof m.file === "string" && typeof m.test !== "string") {
|
|
2474
|
+
ctx.report({ rule: "package-migration-test", file: `${pkg.rel}/package.json`, subject: m.file, message: `${pkg.name} block ${id}: ${m.file} has no pgTAP test; declare one as "test" beside it` });
|
|
2475
|
+
} else if (typeof m.test === "string" && !existsSync(path14.join(pkg.dir, m.test))) {
|
|
2476
|
+
ctx.report({ rule: "package-migration-test", file: `${pkg.rel}/package.json`, subject: m.test, message: `${pkg.name} block ${id}: its test ${m.test} doesn't exist` });
|
|
2218
2477
|
}
|
|
2219
|
-
} else {
|
|
2220
|
-
out.push(p);
|
|
2221
2478
|
}
|
|
2222
2479
|
}
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
const
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
if (!
|
|
2233
|
-
|
|
2234
|
-
copies.set(real2, copy);
|
|
2235
|
-
via.set(real2, /* @__PURE__ */ new Set());
|
|
2480
|
+
const dir = path14.join(pkg.dir, "migrations");
|
|
2481
|
+
if (!existsSync(dir)) return;
|
|
2482
|
+
const seen = /* @__PURE__ */ new Map();
|
|
2483
|
+
for (const name of readdirSync(dir).sort()) {
|
|
2484
|
+
const m = MIGRATION_FILE.exec(name);
|
|
2485
|
+
if (!m) continue;
|
|
2486
|
+
const other = seen.get(m[1]);
|
|
2487
|
+
if (other) ctx.report({ rule: "package-migration-number", file: `${pkg.rel}/migrations/${name}`, subject: m[1], message: `${pkg.name}: ${name} and ${other} share the number ${m[1]}; give each migration its own` });
|
|
2488
|
+
else seen.set(m[1], name);
|
|
2489
|
+
if (!declaredFiles.has(`migrations/${name}`) && !existsSync(path14.join(dir, "tests", name.replace(/\.sql$/, ".test.sql")))) {
|
|
2490
|
+
ctx.report({ rule: "package-migration-test", file: `${pkg.rel}/migrations/${name}`, subject: name, message: `${pkg.name}: ${name} has no pgTAP test (migrations/tests/${name.replace(/\.sql$/, ".test.sql")})` });
|
|
2236
2491
|
}
|
|
2237
|
-
|
|
2238
|
-
|
|
2492
|
+
}
|
|
2493
|
+
}
|
|
2494
|
+
function checkExports(ctx, pkg, json) {
|
|
2495
|
+
const targets = [];
|
|
2496
|
+
const walk = (v) => {
|
|
2497
|
+
if (typeof v === "string") targets.push(v);
|
|
2498
|
+
else if (v && typeof v === "object") for (const x of Object.values(v)) walk(x);
|
|
2239
2499
|
};
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
if (!manifest?.name) return;
|
|
2246
|
-
if (kind !== "dev" && DEV_TOOLS.has(manifest.name)) return;
|
|
2247
|
-
const realDir = real(dir);
|
|
2248
|
-
if (GENESIS.test(manifest.name)) record(realDir, manifest, by, range, kind);
|
|
2249
|
-
if (expanded.has(realDir)) return;
|
|
2250
|
-
expanded.add(realDir);
|
|
2251
|
-
queue.push({ real: realDir, manifest, label: `${manifest.name}@${manifest.version ?? "?"}` });
|
|
2252
|
-
};
|
|
2253
|
-
for (const r of roots) visit(r.dir, r.by, r.range);
|
|
2254
|
-
while (queue.length) {
|
|
2255
|
-
const { real: from, manifest, label } = queue.shift();
|
|
2256
|
-
const deps = { ...manifest.optionalDependencies, ...manifest.dependencies };
|
|
2257
|
-
for (const [name, range] of Object.entries(deps)) {
|
|
2258
|
-
const dir = findPackageDir(from, name);
|
|
2259
|
-
if (dir) visit(dir, label, range);
|
|
2260
|
-
}
|
|
2261
|
-
for (const [name, range] of Object.entries(manifest.peerDependencies ?? {})) {
|
|
2262
|
-
if (name in deps) continue;
|
|
2263
|
-
const dir = peerOf(from, name);
|
|
2264
|
-
if (dir) visit(dir, label, range);
|
|
2265
|
-
}
|
|
2500
|
+
walk(json.exports);
|
|
2501
|
+
for (const t of targets) {
|
|
2502
|
+
if (!t.startsWith("./") || t.includes("*") || !/\.(?:[cm]?tsx?|json)$/.test(t) || /\.d\.[cm]?ts$/.test(t)) continue;
|
|
2503
|
+
if (!existsSync(path14.join(pkg.dir, t))) {
|
|
2504
|
+
ctx.report({ rule: "package-export-missing", file: `${pkg.rel}/package.json`, subject: t, message: `${pkg.name} exports ${t}, which doesn't exist` });
|
|
2266
2505
|
}
|
|
2267
|
-
}
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
const
|
|
2281
|
-
|
|
2282
|
-
const
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2506
|
+
}
|
|
2507
|
+
}
|
|
2508
|
+
function checkBlocks(ctx, pkg, json) {
|
|
2509
|
+
for (const [id, raw] of Object.entries(rawBlocksOf(json))) {
|
|
2510
|
+
try {
|
|
2511
|
+
parseManifest(json.name, id, raw, json.version, { local: true });
|
|
2512
|
+
} catch (err) {
|
|
2513
|
+
if (!(err instanceof ManifestError)) throw err;
|
|
2514
|
+
for (const problem of err.problems) ctx.report({ rule: "package-block-invalid", file: `${pkg.rel}/package.json`, subject: id, message: problem });
|
|
2515
|
+
}
|
|
2516
|
+
}
|
|
2517
|
+
}
|
|
2518
|
+
function checkTaggedTests(ctx, pkg) {
|
|
2519
|
+
const tests = sourceFiles(pkg.dir).filter((f) => /\.(test|spec)\.[cm]?[jt]sx?$/.test(f));
|
|
2520
|
+
if (!tests.length) return;
|
|
2521
|
+
const tagged = tests.some((f) => /@feat:[a-z]/.test(readFileSync(path14.join(pkg.dir, f), "utf8")));
|
|
2522
|
+
if (!tagged) ctx.report({ rule: "package-untagged-tests", level: "warn", file: pkg.rel, message: `${pkg.name}'s tests name no feature; tag them with // @feat:<feature id>` });
|
|
2523
|
+
}
|
|
2524
|
+
function checkRegistered(ctx, pkg) {
|
|
2525
|
+
const file = path14.join(ctx.root, "features.json");
|
|
2526
|
+
if (!existsSync(file)) return;
|
|
2527
|
+
let doc;
|
|
2528
|
+
try {
|
|
2529
|
+
doc = JSON.parse(readFileSync(file, "utf8"));
|
|
2530
|
+
} catch {
|
|
2531
|
+
return;
|
|
2532
|
+
}
|
|
2533
|
+
const top = git(ctx.root, ["rev-parse", "--show-toplevel"])?.trim();
|
|
2534
|
+
const forms = /* @__PURE__ */ new Set([pkg.rel]);
|
|
2535
|
+
if (top) forms.add(path14.relative(top, realpathSync(pkg.dir)).split(path14.sep).join("/"));
|
|
2536
|
+
const covered = (doc.features ?? []).some(
|
|
2537
|
+
(f) => (f.links?.code ?? []).some((c) => {
|
|
2538
|
+
const norm = c.replace(/^\.\//, "").replace(/\/+$/, "");
|
|
2539
|
+
return [...forms].some((rel) => norm === rel || norm.startsWith(`${rel}/`) || rel.startsWith(`${norm}/`));
|
|
2540
|
+
})
|
|
2299
2541
|
);
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
walk("dev", rootsOf(devRoots, "the app (dev)"));
|
|
2303
|
-
for (const [key2, copy] of copies) {
|
|
2304
|
-
const kinds = via.get(key2);
|
|
2305
|
-
copy.runtime = kinds.has("runtime");
|
|
2306
|
-
copy.devOnly = kinds.size === 1 && kinds.has("dev");
|
|
2542
|
+
if (!covered) {
|
|
2543
|
+
ctx.report({ rule: "package-unregistered", level: "warn", file: pkg.rel, message: `no feature in features.ts lists ${pkg.rel} in links.code; add the package to the feature it implements` });
|
|
2307
2544
|
}
|
|
2308
|
-
const byName = /* @__PURE__ */ new Map();
|
|
2309
|
-
for (const copy of copies.values()) byName.set(copy.name, [...byName.get(copy.name) ?? [], copy]);
|
|
2310
|
-
for (const list of byName.values()) list.sort((a, b) => a.dir.split("/").length - b.dir.split("/").length || a.dir.localeCompare(b.dir));
|
|
2311
|
-
return byName;
|
|
2312
2545
|
}
|
|
2313
|
-
function
|
|
2314
|
-
const
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
|
|
2546
|
+
function changesetNames(text) {
|
|
2547
|
+
const m = /^---\r?\n([\s\S]*?)\r?\n---/.exec(text);
|
|
2548
|
+
const names = /* @__PURE__ */ new Set();
|
|
2549
|
+
if (!m) return names;
|
|
2550
|
+
for (const line of m[1].split(/\r?\n/)) {
|
|
2551
|
+
const entry = /^\s*(?:"([^"]+)"|'([^']+)'|([^\s:'"]+))\s*:\s*(major|minor|patch)\s*$/.exec(line);
|
|
2552
|
+
if (entry) names.add(entry[1] ?? entry[2] ?? entry[3]);
|
|
2553
|
+
}
|
|
2554
|
+
return names;
|
|
2555
|
+
}
|
|
2556
|
+
function mergeBaseOf(root, base) {
|
|
2557
|
+
if (git(root, ["rev-parse", "--is-inside-work-tree"])?.trim() !== "true") return { reason: "not a git repository" };
|
|
2558
|
+
if (git(root, ["rev-parse", "--verify", "--quiet", `${base}^{commit}`]) === null) return { reason: `the git ref ${base} isn't available (fetch it)` };
|
|
2559
|
+
const sha = git(root, ["merge-base", "HEAD", base])?.trim();
|
|
2560
|
+
return sha ? { sha } : { reason: `HEAD has no merge base with ${base} (fetch with depth 0)` };
|
|
2561
|
+
}
|
|
2562
|
+
function checkChanges(ctx, pkg, json, base, mergeBase) {
|
|
2563
|
+
const top = git(ctx.root, ["rev-parse", "--show-toplevel"])?.trim();
|
|
2564
|
+
if (!top) return;
|
|
2565
|
+
const appRelative = (fromTop) => path14.relative(realpathSync(ctx.root), path14.join(top, fromTop)).split(path14.sep).join("/");
|
|
2566
|
+
const inRepo = path14.relative(top, realpathSync(pkg.dir)).split(path14.sep).join("/");
|
|
2567
|
+
const diff = (git(top, ["diff", "--name-status", "-M", mergeBase, "--", inRepo]) ?? "").split("\n").filter(Boolean).map((row) => row.split(" ").map((cell, i) => i === 0 ? cell : appRelative(cell)).join(" ")).join("\n");
|
|
2568
|
+
const untracked = (git(top, ["ls-files", "--others", "--exclude-standard", "--", inRepo]) ?? "").split("\n").filter(Boolean).map(appRelative);
|
|
2569
|
+
const changed = [...diff.split("\n").filter(Boolean).map((row) => row.split(" ").at(-1)), ...untracked].filter(
|
|
2570
|
+
(f) => !/(^|\/)(CHANGELOG\.md|node_modules\/)/.test(f)
|
|
2571
|
+
);
|
|
2572
|
+
for (const row of diff.split("\n").filter(Boolean)) {
|
|
2573
|
+
const [status, a] = row.split(" ");
|
|
2574
|
+
if (a && /\/migrations\/\d{4}_[a-z0-9_]+\.sql$/.test(a) && /^[MDRT]/.test(status)) {
|
|
2575
|
+
ctx.report({ rule: "package-migration-edited", level: "warn", file: a, message: `${a} existed on ${base} and was ${status.startsWith("D") ? "deleted" : "changed"}; once a migration may have been applied, add a new one instead` });
|
|
2327
2576
|
}
|
|
2577
|
+
}
|
|
2578
|
+
if (!changed.length) return;
|
|
2579
|
+
const before = git(ctx.root, ["show", `${mergeBase}:./${pkg.rel}/package.json`]);
|
|
2580
|
+
let versionBefore;
|
|
2581
|
+
try {
|
|
2582
|
+
versionBefore = before ? JSON.parse(before).version : void 0;
|
|
2583
|
+
} catch {
|
|
2584
|
+
versionBefore = void 0;
|
|
2585
|
+
}
|
|
2586
|
+
const now = typeof json.version === "string" ? parseVersion(json.version) : null;
|
|
2587
|
+
const was = typeof versionBefore === "string" ? parseVersion(versionBefore) : null;
|
|
2588
|
+
const bumped = before === null || now !== null && was !== null && compareVersions(now, was) > 0;
|
|
2589
|
+
const changesets = top ? (git(top, ["diff", "--name-only", "--diff-filter=A", mergeBase, "--", ".changeset"]) ?? "").split("\n").concat((git(top, ["ls-files", "--others", "--exclude-standard", "--", ".changeset"]) ?? "").split("\n")).filter((f) => f.endsWith(".md")).map((f) => path14.join(top, f)) : [];
|
|
2590
|
+
const naming = changesets.filter((p) => existsSync(p) && changesetNames(readFileSync(p, "utf8")).has(json.name));
|
|
2591
|
+
const named = naming.length > 0;
|
|
2592
|
+
if (named && !naming.some((p) => /^Features:\s*\S/m.test(readFileSync(p, "utf8")))) {
|
|
2593
|
+
ctx.report({ rule: "package-unversioned-change", level: "warn", file: path14.relative(realpathSync(ctx.root), naming[0]), message: `the changeset for ${pkg.name} has no "Features:" line; name the features it changes` });
|
|
2594
|
+
}
|
|
2595
|
+
let jsonBefore = null;
|
|
2596
|
+
try {
|
|
2597
|
+
jsonBefore = before ? JSON.parse(before) : null;
|
|
2598
|
+
} catch {
|
|
2599
|
+
jsonBefore = null;
|
|
2600
|
+
}
|
|
2601
|
+
const raw = json;
|
|
2602
|
+
if (jsonBefore && (JSON.stringify(jsonBefore.genesis) !== JSON.stringify(raw.genesis) || JSON.stringify(jsonBefore.exports) !== JSON.stringify(raw.exports))) {
|
|
2603
|
+
const registry = (git(ctx.root, ["diff", "--relative", "--name-only", mergeBase, "--", "features.ts", "src/features.ts"]) ?? "").trim();
|
|
2604
|
+
if (!registry) ctx.report({ rule: "package-unversioned-change", level: "warn", file: `${pkg.rel}/package.json`, message: `${pkg.name}'s blocks or exports changed but features.ts didn't; update the features they belong to` });
|
|
2605
|
+
}
|
|
2606
|
+
if (bumped && !named && before !== null) {
|
|
2607
|
+
ctx.report({ rule: "package-unversioned-change", level: "warn", file: `${pkg.rel}/package.json`, message: `${pkg.name}'s version went up without a changeset; add one with a "Features:" line so the change is recorded` });
|
|
2608
|
+
}
|
|
2609
|
+
if (!bumped && !named) {
|
|
2328
2610
|
ctx.report({
|
|
2329
|
-
rule: "
|
|
2330
|
-
level: "
|
|
2331
|
-
file:
|
|
2332
|
-
|
|
2333
|
-
message: `${name} has dev-only copies beside the one the app loads: ${copies.filter((c) => c.devOnly).map(describe).join(", ")}. They run in tooling, not the app, so they can't split its contexts; upgrade the tool to drop them`
|
|
2611
|
+
rule: "package-unversioned-change",
|
|
2612
|
+
level: "warn",
|
|
2613
|
+
file: `${pkg.rel}/package.json`,
|
|
2614
|
+
message: `${pkg.name} changed since ${base} (${changed.length} file${changed.length === 1 ? "" : "s"}) but neither its version nor a new changeset naming it did; add a changeset (or bump "version") saying what changed`
|
|
2334
2615
|
});
|
|
2335
2616
|
}
|
|
2336
2617
|
}
|
|
2337
|
-
function
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
|
|
2618
|
+
function checkPackagesPack(ctx) {
|
|
2619
|
+
let packages;
|
|
2620
|
+
try {
|
|
2621
|
+
packages = localPackages(ctx.root);
|
|
2622
|
+
} catch (err) {
|
|
2623
|
+
ctx.report({ rule: "package-block-invalid", file: "genesis.config.json", message: err.message });
|
|
2624
|
+
return;
|
|
2625
|
+
}
|
|
2626
|
+
if (!packages.length) return;
|
|
2627
|
+
const base = ctx.base ?? ctx.config.packages?.base;
|
|
2628
|
+
const merge = base ? mergeBaseOf(ctx.root, base) : { reason: "no base ref (pass --base <ref>, e.g. --base origin/main)" };
|
|
2629
|
+
if ("reason" in merge) {
|
|
2630
|
+
ctx.report({ rule: "package-unversioned-change", level: base ? "warn" : "info", file: "genesis.config.json", message: `change gate skipped: ${merge.reason}` });
|
|
2631
|
+
}
|
|
2632
|
+
for (const pkg of packages) {
|
|
2633
|
+
const json = JSON.parse(readFileSync(path14.join(pkg.dir, "package.json"), "utf8"));
|
|
2634
|
+
checkImports2(ctx, pkg, json);
|
|
2635
|
+
checkExports(ctx, pkg, json);
|
|
2636
|
+
checkBlocks(ctx, pkg, json);
|
|
2637
|
+
checkMigrations(ctx, pkg, json);
|
|
2638
|
+
checkTaggedTests(ctx, pkg);
|
|
2639
|
+
checkRegistered(ctx, pkg);
|
|
2640
|
+
if (base && "sha" in merge) checkChanges(ctx, pkg, json, base, merge.sha);
|
|
2359
2641
|
}
|
|
2360
2642
|
}
|
|
2361
|
-
var
|
|
2362
|
-
var
|
|
2363
|
-
var
|
|
2364
|
-
|
|
2365
|
-
var DYNAMIC = /\bimport\s*\(\s*["']([^"']+)["']/g;
|
|
2366
|
-
function stripForImports(code) {
|
|
2643
|
+
var DEFAULT_MIGRATIONS = "supabase/migrations";
|
|
2644
|
+
var DEFAULT_BASE = "origin/main";
|
|
2645
|
+
var DEFAULT_EXPOSED = ["public"];
|
|
2646
|
+
function sqlStatements(text) {
|
|
2367
2647
|
const out = [];
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
let
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
const t = b.replace(/\s+$/, "");
|
|
2379
|
-
if (!t) return true;
|
|
2380
|
-
if (KEYWORD.test(b)) return true;
|
|
2381
|
-
return /[([{,;:=!&|?+\-*%<>~^}]$/.test(t);
|
|
2648
|
+
let buf = "";
|
|
2649
|
+
let bodies = [];
|
|
2650
|
+
let line = 1;
|
|
2651
|
+
let start = 0;
|
|
2652
|
+
const flush = () => {
|
|
2653
|
+
const sql = buf.replace(/\s+/g, " ").trim().toLowerCase();
|
|
2654
|
+
if (sql) out.push({ sql, line: start, bodies });
|
|
2655
|
+
buf = "";
|
|
2656
|
+
bodies = [];
|
|
2657
|
+
start = 0;
|
|
2382
2658
|
};
|
|
2383
|
-
const
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
const m = /([A-Za-z_$][\w$.]*)$/.exec(b);
|
|
2387
|
-
return m !== null && startsExpression(b.slice(0, b.length - m[1].length));
|
|
2659
|
+
const put = (s) => {
|
|
2660
|
+
if (!start && /\S/.test(s)) start = line;
|
|
2661
|
+
buf += s;
|
|
2388
2662
|
};
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
out.push("`");
|
|
2397
|
-
i++;
|
|
2398
|
-
return;
|
|
2399
|
-
} else if (ch === "$" && code[i + 1] === "{") {
|
|
2400
|
-
out.push("${");
|
|
2401
|
-
i += 2;
|
|
2402
|
-
templates.push(depth);
|
|
2403
|
-
depth++;
|
|
2404
|
-
return;
|
|
2405
|
-
} else {
|
|
2406
|
-
out.push(blank(ch));
|
|
2407
|
-
i++;
|
|
2408
|
-
}
|
|
2409
|
-
}
|
|
2410
|
-
sure = false;
|
|
2411
|
-
};
|
|
2412
|
-
while (i < n && sure) {
|
|
2413
|
-
const ch = code[i];
|
|
2414
|
-
const next = code[i + 1];
|
|
2415
|
-
if (ch === "/" && next === "/") {
|
|
2416
|
-
while (i < n && code[i] !== "\n") {
|
|
2417
|
-
out.push(" ");
|
|
2418
|
-
i++;
|
|
2419
|
-
}
|
|
2420
|
-
} else if (ch === "/" && next === "*") {
|
|
2421
|
-
out.push(" ");
|
|
2422
|
-
i += 2;
|
|
2423
|
-
while (i < n && !(code[i] === "*" && code[i + 1] === "/")) {
|
|
2424
|
-
out.push(blank(code[i]));
|
|
2425
|
-
i++;
|
|
2426
|
-
}
|
|
2427
|
-
if (i < n) {
|
|
2428
|
-
out.push(" ");
|
|
2429
|
-
i += 2;
|
|
2430
|
-
}
|
|
2431
|
-
} else if (ch === "/" && next !== ">" && code[i - 1] !== "<" && exprStart()) {
|
|
2432
|
-
const afterBrace = /[}>]\s*$/.test(before());
|
|
2433
|
-
const start = i;
|
|
2434
|
-
const mark = out.length;
|
|
2435
|
-
out.push("/");
|
|
2663
|
+
let i = 0;
|
|
2664
|
+
while (i < text.length) {
|
|
2665
|
+
const ch = text[i];
|
|
2666
|
+
const two = text.slice(i, i + 2);
|
|
2667
|
+
if (ch === "\n") {
|
|
2668
|
+
buf += " ";
|
|
2669
|
+
line++;
|
|
2436
2670
|
i++;
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
i = start + 1;
|
|
2445
|
-
} else sure = false;
|
|
2446
|
-
break;
|
|
2447
|
-
}
|
|
2448
|
-
if (c === "\\") {
|
|
2449
|
-
out.push(" ", blank(code[i + 1] ?? ""));
|
|
2671
|
+
} else if (two === "--") {
|
|
2672
|
+
while (i < text.length && text[i] !== "\n") i++;
|
|
2673
|
+
} else if (two === "/*") {
|
|
2674
|
+
let depth = 0;
|
|
2675
|
+
while (i < text.length) {
|
|
2676
|
+
if (text.startsWith("/*", i)) {
|
|
2677
|
+
depth++;
|
|
2450
2678
|
i += 2;
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
i++;
|
|
2454
|
-
if (c === "[") inClass = true;
|
|
2455
|
-
else if (c === "]") inClass = false;
|
|
2456
|
-
else if (c === "/" && !inClass) {
|
|
2457
|
-
if (afterBrace && /[<>]/.test(code.slice(start + 1, i - 1))) {
|
|
2458
|
-
out.length = mark;
|
|
2459
|
-
out.push("/");
|
|
2460
|
-
i = start + 1;
|
|
2461
|
-
break;
|
|
2462
|
-
}
|
|
2463
|
-
out.push("/");
|
|
2464
|
-
break;
|
|
2465
|
-
}
|
|
2466
|
-
out.push(" ");
|
|
2467
|
-
}
|
|
2468
|
-
if (out.length > mark + 1 || i > start + 1) while (i < n && /[a-z]/.test(code[i])) out.push(code[i++]);
|
|
2469
|
-
} else if ((ch === '"' || ch === "'") && exprStart()) {
|
|
2470
|
-
const keep = isSpecifier();
|
|
2471
|
-
out.push(ch);
|
|
2472
|
-
i++;
|
|
2473
|
-
while (i < n && code[i] !== ch && code[i] !== "\n") {
|
|
2474
|
-
if (code[i] === "\\") {
|
|
2475
|
-
out.push(keep ? code[i] : " ", keep ? code[i + 1] ?? "" : blank(code[i + 1] ?? ""));
|
|
2679
|
+
} else if (text.startsWith("*/", i)) {
|
|
2680
|
+
depth--;
|
|
2476
2681
|
i += 2;
|
|
2682
|
+
if (depth === 0) break;
|
|
2477
2683
|
} else {
|
|
2478
|
-
|
|
2684
|
+
if (text[i] === "\n") line++;
|
|
2479
2685
|
i++;
|
|
2480
2686
|
}
|
|
2481
2687
|
}
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
|
|
2485
|
-
|
|
2688
|
+
buf += " ";
|
|
2689
|
+
} else if (ch === "'") {
|
|
2690
|
+
const escapes = /[eE]/.test(text[i - 1] ?? "") && !/[\w$]/.test(text[i - 2] ?? "");
|
|
2691
|
+
put("'");
|
|
2692
|
+
i++;
|
|
2693
|
+
while (i < text.length) {
|
|
2694
|
+
if (escapes && text[i] === "\\") i += 2;
|
|
2695
|
+
else if (text[i] === "'" && text[i + 1] === "'") i += 2;
|
|
2696
|
+
else if (text[i] === "'") break;
|
|
2697
|
+
else {
|
|
2698
|
+
if (text[i] === "\n") line++;
|
|
2699
|
+
i++;
|
|
2700
|
+
}
|
|
2486
2701
|
}
|
|
2487
|
-
|
|
2488
|
-
out.push("`");
|
|
2702
|
+
put("'");
|
|
2489
2703
|
i++;
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
|
|
2704
|
+
} else if (ch === '"') {
|
|
2705
|
+
i++;
|
|
2706
|
+
while (i < text.length && text[i] !== '"') put(text[i++]);
|
|
2707
|
+
i++;
|
|
2708
|
+
} else if (ch === "$" && !/[\w$]/.test(text[i - 1] ?? "") && /^\$(?:[A-Za-z_]\w*)?\$/.test(text.slice(i))) {
|
|
2709
|
+
const tag = /^\$(?:[A-Za-z_]\w*)?\$/.exec(text.slice(i))[0];
|
|
2710
|
+
const end = text.indexOf(tag, i + tag.length);
|
|
2711
|
+
const stop = end === -1 ? text.length : end + tag.length;
|
|
2712
|
+
bodies.push(text.slice(i + tag.length, end === -1 ? text.length : end).toLowerCase());
|
|
2713
|
+
for (let k = i; k < stop; k++) if (text[k] === "\n") line++;
|
|
2714
|
+
put(`${tag} ${tag}`);
|
|
2715
|
+
i = stop;
|
|
2716
|
+
} else if (ch === ";") {
|
|
2717
|
+
flush();
|
|
2495
2718
|
i++;
|
|
2496
|
-
templateBody();
|
|
2497
2719
|
} else {
|
|
2498
|
-
|
|
2499
|
-
else if (ch === "}") depth--;
|
|
2500
|
-
out.push(ch);
|
|
2720
|
+
put(ch);
|
|
2501
2721
|
i++;
|
|
2502
2722
|
}
|
|
2503
2723
|
}
|
|
2504
|
-
|
|
2505
|
-
}
|
|
2506
|
-
function bindings(clause) {
|
|
2507
|
-
const out = [];
|
|
2508
|
-
const named = /\{([^}]*)\}/.exec(clause);
|
|
2509
|
-
for (const part of named?.[1].split(",") ?? []) {
|
|
2510
|
-
const p = part.trim();
|
|
2511
|
-
if (!p || p.startsWith("type ")) continue;
|
|
2512
|
-
out.push(p.split(/\s+as\s+/).pop().trim());
|
|
2513
|
-
}
|
|
2514
|
-
const rest = clause.replace(/\{[^}]*\}/, "");
|
|
2515
|
-
const ns = /\*\s*as\s+([\w$]+)/.exec(rest);
|
|
2516
|
-
if (ns) out.push(ns[1]);
|
|
2517
|
-
const def = /^\s*([\w$]+)/.exec(rest);
|
|
2518
|
-
if (def && def[1] !== "as") out.push(def[1]);
|
|
2724
|
+
flush();
|
|
2519
2725
|
return out;
|
|
2520
2726
|
}
|
|
2521
|
-
function
|
|
2522
|
-
|
|
2523
|
-
|
|
2524
|
-
return JSON.parse(text);
|
|
2525
|
-
} catch {
|
|
2526
|
-
return null;
|
|
2527
|
-
}
|
|
2727
|
+
function qualify(name) {
|
|
2728
|
+
const n = name.trim().toLowerCase();
|
|
2729
|
+
return n.includes(".") ? n : `public.${n}`;
|
|
2528
2730
|
}
|
|
2529
|
-
|
|
2530
|
-
|
|
2531
|
-
|
|
2532
|
-
|
|
2533
|
-
|
|
2534
|
-
|
|
2535
|
-
let merged = {};
|
|
2536
|
-
const parents = typeof json.extends === "string" ? [json.extends] : Array.isArray(json.extends) ? json.extends : [];
|
|
2537
|
-
for (const ext of parents) {
|
|
2538
|
-
if (typeof ext !== "string") continue;
|
|
2539
|
-
let target = null;
|
|
2540
|
-
if (ext.startsWith(".") || path14.isAbsolute(ext)) {
|
|
2541
|
-
const abs = path14.resolve(dir, ext);
|
|
2542
|
-
target = existsSync(abs) && statSync(abs).isFile() ? abs : existsSync(`${abs}.json`) ? `${abs}.json` : null;
|
|
2543
|
-
} else {
|
|
2544
|
-
const parts = ext.split("/");
|
|
2545
|
-
const nameLength = ext.startsWith("@") ? 2 : 1;
|
|
2546
|
-
const pkgDir = findPackageDir(root, parts.slice(0, nameLength).join("/"));
|
|
2547
|
-
if (pkgDir) {
|
|
2548
|
-
const sub = parts.slice(nameLength).join("/");
|
|
2549
|
-
const abs = path14.join(pkgDir, sub || "tsconfig.json");
|
|
2550
|
-
target = existsSync(abs) && statSync(abs).isFile() ? abs : existsSync(`${abs}.json`) ? `${abs}.json` : null;
|
|
2551
|
-
}
|
|
2552
|
-
}
|
|
2553
|
-
if (target) merged = { ...merged, ...readTsconfig(root, target, seen) };
|
|
2554
|
-
}
|
|
2555
|
-
const opts = json.compilerOptions ?? {};
|
|
2556
|
-
if (typeof opts.baseUrl === "string") merged.baseUrl = path14.resolve(dir, opts.baseUrl);
|
|
2557
|
-
if (opts.paths && typeof opts.paths === "object") {
|
|
2558
|
-
merged.paths = opts.paths;
|
|
2559
|
-
merged.pathsDir = dir;
|
|
2731
|
+
var schemaOf = (name) => name.split(".")[0];
|
|
2732
|
+
function parenthesized(sql, open) {
|
|
2733
|
+
let depth = 0;
|
|
2734
|
+
for (let k = open; k < sql.length; k++) {
|
|
2735
|
+
if (sql[k] === "(") depth++;
|
|
2736
|
+
else if (sql[k] === ")" && --depth === 0) return { inner: sql.slice(open + 1, k), end: k + 1 };
|
|
2560
2737
|
}
|
|
2561
|
-
return
|
|
2738
|
+
return { inner: sql.slice(open + 1), end: sql.length };
|
|
2562
2739
|
}
|
|
2563
|
-
function
|
|
2564
|
-
|
|
2565
|
-
let
|
|
2566
|
-
for (const
|
|
2567
|
-
|
|
2568
|
-
if (
|
|
2569
|
-
|
|
2570
|
-
baseUrl ??= config.baseUrl ?? null;
|
|
2571
|
-
const base = config.baseUrl ?? config.pathsDir ?? root;
|
|
2572
|
-
for (const [pattern, targets] of Object.entries(config.paths ?? {})) {
|
|
2573
|
-
if (!Array.isArray(targets)) continue;
|
|
2574
|
-
const exact = !pattern.endsWith("*");
|
|
2575
|
-
table.push({ prefix: pattern.replace(/\*$/, ""), exact, targets: targets.map((t) => path14.join(base, String(t).replace(/\*$/, ""))) });
|
|
2576
|
-
}
|
|
2577
|
-
}
|
|
2578
|
-
const pkg = readJsonc(path14.join(root, "package.json"));
|
|
2579
|
-
for (const [pattern, target] of Object.entries(pkg?.imports ?? {})) {
|
|
2580
|
-
if (typeof target !== "string") continue;
|
|
2581
|
-
table.push({ prefix: pattern.replace(/\*.*$/, ""), exact: !pattern.includes("*"), targets: [path14.join(root, target.replace(/\*.*$/, ""))] });
|
|
2740
|
+
function stripParens(s) {
|
|
2741
|
+
let out = "";
|
|
2742
|
+
let depth = 0;
|
|
2743
|
+
for (const c of s) {
|
|
2744
|
+
if (c === "(") depth++;
|
|
2745
|
+
else if (c === ")") depth = Math.max(0, depth - 1);
|
|
2746
|
+
else if (depth === 0) out += c;
|
|
2582
2747
|
}
|
|
2583
|
-
|
|
2584
|
-
return { table, baseUrl };
|
|
2748
|
+
return out;
|
|
2585
2749
|
}
|
|
2586
|
-
function
|
|
2587
|
-
const
|
|
2588
|
-
|
|
2589
|
-
|
|
2590
|
-
|
|
2750
|
+
function splitTop(s) {
|
|
2751
|
+
const parts = [];
|
|
2752
|
+
let depth = 0;
|
|
2753
|
+
let cur = "";
|
|
2754
|
+
for (const c of s) {
|
|
2755
|
+
if (c === "(") depth++;
|
|
2756
|
+
if (c === ")") depth--;
|
|
2757
|
+
if (c === "," && depth === 0) {
|
|
2758
|
+
parts.push(cur);
|
|
2759
|
+
cur = "";
|
|
2760
|
+
} else cur += c;
|
|
2591
2761
|
}
|
|
2592
|
-
|
|
2762
|
+
if (cur.trim()) parts.push(cur);
|
|
2763
|
+
return parts.map((p) => p.trim()).filter(Boolean);
|
|
2593
2764
|
}
|
|
2594
|
-
var
|
|
2595
|
-
|
|
2596
|
-
|
|
2597
|
-
|
|
2598
|
-
|
|
2765
|
+
var TYPE_ALIASES = {
|
|
2766
|
+
int: "integer",
|
|
2767
|
+
int4: "integer",
|
|
2768
|
+
int8: "bigint",
|
|
2769
|
+
int2: "smallint",
|
|
2770
|
+
bool: "boolean",
|
|
2771
|
+
varchar: "character varying",
|
|
2772
|
+
timestamptz: "timestamp with time zone",
|
|
2773
|
+
float8: "double precision"
|
|
2774
|
+
};
|
|
2775
|
+
var MULTIWORD_TYPE = /^(?:double precision|character varying|character|bit varying|timestamp|time|interval)\b/;
|
|
2776
|
+
function argTypes(args) {
|
|
2777
|
+
const types = [];
|
|
2778
|
+
for (const raw of splitTop(args)) {
|
|
2779
|
+
let tokens = stripParens(raw.replace(/\s+(?:default\b|=).*$/, "")).trim().split(/\s+/).filter(Boolean);
|
|
2780
|
+
const mode = tokens[0];
|
|
2781
|
+
if (mode === "out") continue;
|
|
2782
|
+
if (mode === "in" || mode === "inout" || mode === "variadic") tokens = tokens.slice(1);
|
|
2783
|
+
const joined = tokens.join(" ");
|
|
2784
|
+
const type = tokens.length > 1 && !MULTIWORD_TYPE.test(joined) ? tokens.slice(1).join(" ") : joined;
|
|
2785
|
+
types.push(TYPE_ALIASES[type] ?? type);
|
|
2786
|
+
}
|
|
2787
|
+
return types;
|
|
2599
2788
|
}
|
|
2600
|
-
function
|
|
2601
|
-
const
|
|
2602
|
-
|
|
2789
|
+
function git2(root, args) {
|
|
2790
|
+
const r = spawnSync("git", args, { cwd: root, encoding: "utf8" });
|
|
2791
|
+
return r.status === 0 ? r.stdout : null;
|
|
2792
|
+
}
|
|
2793
|
+
function gitView(root, dir, base) {
|
|
2794
|
+
if (git2(root, ["rev-parse", "--is-inside-work-tree"])?.trim() !== "true") return { reason: "not a git repository", repo: false };
|
|
2795
|
+
if (git2(root, ["rev-parse", "--verify", "--quiet", `${base}^{commit}`]) === null) {
|
|
2796
|
+
return { reason: `the git ref ${base} isn't available (fetch it, or set doctor.supabase.base)`, repo: true };
|
|
2797
|
+
}
|
|
2798
|
+
const mergeBase = git2(root, ["merge-base", "HEAD", base])?.trim();
|
|
2799
|
+
if (!mergeBase) return { reason: `HEAD has no merge base with ${base} (a shallow clone? fetch with depth 0)`, repo: true };
|
|
2800
|
+
const diff = git2(root, ["diff", "--relative", "--name-status", "-M", mergeBase, "--", dir]);
|
|
2801
|
+
const untracked = git2(root, ["ls-files", "--others", "--exclude-standard", "--", dir]);
|
|
2802
|
+
if (diff === null || untracked === null) return { reason: `git diff against ${base} failed`, repo: true };
|
|
2803
|
+
const sql = (p) => p !== void 0 && p.endsWith(".sql");
|
|
2804
|
+
const touched = new Set(untracked.split("\n").filter(sql));
|
|
2805
|
+
const edited = [];
|
|
2806
|
+
for (const row of diff.split("\n").filter(Boolean)) {
|
|
2807
|
+
const [status, a, b] = row.split(" ");
|
|
2808
|
+
if (status.startsWith("R")) {
|
|
2809
|
+
if (sql(b)) touched.add(b);
|
|
2810
|
+
if (sql(a)) edited.push({ file: a, status: "renamed" });
|
|
2811
|
+
continue;
|
|
2812
|
+
}
|
|
2813
|
+
if (!sql(a)) continue;
|
|
2814
|
+
if (status.startsWith("A")) touched.add(a);
|
|
2815
|
+
else if (status.startsWith("M") || status.startsWith("T")) {
|
|
2816
|
+
touched.add(a);
|
|
2817
|
+
edited.push({ file: a, status: "modified" });
|
|
2818
|
+
} else if (status.startsWith("D")) edited.push({ file: a, status: "deleted" });
|
|
2819
|
+
}
|
|
2820
|
+
return { touched, edited };
|
|
2821
|
+
}
|
|
2822
|
+
function checkSupabasePack(ctx) {
|
|
2823
|
+
const settings = ctx.config.supabase ?? {};
|
|
2824
|
+
const dir = settings.migrations ?? DEFAULT_MIGRATIONS;
|
|
2825
|
+
const abs = path14.join(ctx.root, dir);
|
|
2826
|
+
if (!existsSync(abs)) throw new DoctorConfigError(`the supabase pack reads ${dir}, which doesn't exist; set doctor.supabase.migrations`);
|
|
2827
|
+
const migrations = readdirSync(abs).filter((n) => n.endsWith(".sql")).sort().map((n) => ({ file: `${dir}/${n}`, statements: sqlStatements(readFileSync(path14.join(abs, n), "utf8")) }));
|
|
2828
|
+
const exposed = new Set((settings.exposedSchemas ?? DEFAULT_EXPOSED).map((s) => s.toLowerCase()));
|
|
2829
|
+
const base = settings.base ?? DEFAULT_BASE;
|
|
2830
|
+
const view = gitView(ctx.root, dir, base);
|
|
2831
|
+
if ("reason" in view) {
|
|
2832
|
+
if (view.repo) ctx.report({ rule: "migration-edited", level: "warn", file: dir, message: `can't check for edited migrations: ${view.reason}` });
|
|
2833
|
+
} else {
|
|
2834
|
+
for (const e of view.edited) {
|
|
2835
|
+
ctx.report({
|
|
2836
|
+
rule: "migration-edited",
|
|
2837
|
+
file: e.file,
|
|
2838
|
+
subject: e.file,
|
|
2839
|
+
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`
|
|
2840
|
+
});
|
|
2841
|
+
}
|
|
2842
|
+
}
|
|
2843
|
+
const since = settings.since;
|
|
2844
|
+
const afterSince = (file) => since === void 0 || path14.posix.basename(file) >= since;
|
|
2845
|
+
if ("reason" in view && since === void 0) {
|
|
2846
|
+
ctx.report({
|
|
2847
|
+
rule: "migration-grants",
|
|
2848
|
+
level: "warn",
|
|
2849
|
+
file: dir,
|
|
2850
|
+
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`
|
|
2851
|
+
});
|
|
2852
|
+
} else {
|
|
2853
|
+
const isNew = (file) => afterSince(file) && ("reason" in view || view.touched.has(file));
|
|
2854
|
+
checkGrants(ctx, migrations.filter((m) => isNew(m.file)), exposed);
|
|
2855
|
+
}
|
|
2856
|
+
checkRls(ctx, migrations, exposed);
|
|
2857
|
+
checkViewInvoker(ctx, migrations, exposed);
|
|
2858
|
+
checkDefinerSearchPath(ctx, migrations);
|
|
2859
|
+
checkTestingKit(ctx, migrations);
|
|
2860
|
+
}
|
|
2861
|
+
function checkTestingKit(ctx, migrations) {
|
|
2862
|
+
for (const { file, statements } of migrations) {
|
|
2863
|
+
const hit = statements.find(({ sql }) => /\bgenesis_testing\b/.test(sql));
|
|
2864
|
+
if (!hit) continue;
|
|
2865
|
+
ctx.report({
|
|
2866
|
+
rule: "migration-testing-kit",
|
|
2867
|
+
file,
|
|
2868
|
+
line: hit.line,
|
|
2869
|
+
subject: "genesis_testing",
|
|
2870
|
+
message: "a migration uses genesis_testing, the pgTAP kit for test databases only; move it to supabase/tests/database/000_genesis_testing.test.sql"
|
|
2871
|
+
});
|
|
2872
|
+
}
|
|
2873
|
+
}
|
|
2874
|
+
function granteesOf(s) {
|
|
2875
|
+
return s.replace(/\s+granted by .*$/, "").replace(/\s+with grant option$/, "").split(/\s*,\s*/).map((r) => r.replace(/^group\s+/, "").trim()).filter(Boolean);
|
|
2876
|
+
}
|
|
2877
|
+
function checkGrants(ctx, migrations, exposed) {
|
|
2878
|
+
const fix = "grant by name (grant execute on function schema.fn(args) to role) so an earlier revoke survives";
|
|
2879
|
+
const open = (roles) => roles.filter((r) => r === "anon" || r === "public");
|
|
2880
|
+
const blanket = (roles) => {
|
|
2881
|
+
const o = open(roles);
|
|
2882
|
+
if (o.length) return { level: "error", who: o.join(" and ") };
|
|
2883
|
+
if (roles.includes("authenticated")) return { level: "warn", who: "authenticated" };
|
|
2884
|
+
return null;
|
|
2885
|
+
};
|
|
2886
|
+
for (const { file, statements } of migrations) {
|
|
2887
|
+
for (const { sql, line } of statements) {
|
|
2888
|
+
const all = /^grant\b.*\bon all (?:functions|routines|procedures) in schema .+? to (.+)$/.exec(sql);
|
|
2889
|
+
if (all) {
|
|
2890
|
+
const hit = blanket(granteesOf(all[1]));
|
|
2891
|
+
if (hit) {
|
|
2892
|
+
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}` });
|
|
2893
|
+
}
|
|
2894
|
+
continue;
|
|
2895
|
+
}
|
|
2896
|
+
const defaults = /^alter default privileges\b.*?\bgrant\b.*\bon (?:functions|routines) to (.+)$/.exec(sql);
|
|
2897
|
+
if (defaults) {
|
|
2898
|
+
const hit = blanket(granteesOf(defaults[1]));
|
|
2899
|
+
if (hit) {
|
|
2900
|
+
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}` });
|
|
2901
|
+
}
|
|
2902
|
+
continue;
|
|
2903
|
+
}
|
|
2904
|
+
const fn = /^grant\b.*?\bon (?:function|procedure|routine)s? (.+?) to (.+)$/.exec(sql);
|
|
2905
|
+
if (fn) {
|
|
2906
|
+
const roles = open(granteesOf(fn[2]));
|
|
2907
|
+
if (!roles.length) continue;
|
|
2908
|
+
for (const name of splitTop(fn[1]).map((n) => qualify(stripParens(n)))) {
|
|
2909
|
+
if (exposed.has(schemaOf(name))) continue;
|
|
2910
|
+
ctx.report({
|
|
2911
|
+
rule: "migration-grants",
|
|
2912
|
+
file,
|
|
2913
|
+
line,
|
|
2914
|
+
subject: name,
|
|
2915
|
+
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)`
|
|
2916
|
+
});
|
|
2917
|
+
}
|
|
2918
|
+
continue;
|
|
2919
|
+
}
|
|
2920
|
+
const schema = /^grant\b.*?\bon schema (.+?) to (.+)$/.exec(sql);
|
|
2921
|
+
if (schema) {
|
|
2922
|
+
const roles = open(granteesOf(schema[2]));
|
|
2923
|
+
if (!roles.length) continue;
|
|
2924
|
+
for (const s of schema[1].split(/\s*,\s*/).map((x) => x.trim())) {
|
|
2925
|
+
if (exposed.has(s)) continue;
|
|
2926
|
+
ctx.report({
|
|
2927
|
+
rule: "migration-grants",
|
|
2928
|
+
file,
|
|
2929
|
+
line,
|
|
2930
|
+
subject: `schema ${s}`,
|
|
2931
|
+
message: `grants schema ${s} to ${roles.join(" and ")}; a schema outside the exposed ones stays closed to anon and public`
|
|
2932
|
+
});
|
|
2933
|
+
}
|
|
2934
|
+
}
|
|
2935
|
+
}
|
|
2936
|
+
}
|
|
2937
|
+
}
|
|
2938
|
+
function checkRls(ctx, migrations, exposed) {
|
|
2939
|
+
const tables = /* @__PURE__ */ new Map();
|
|
2940
|
+
const name = String.raw`([\w$.]+)`;
|
|
2941
|
+
const target = String.raw`^alter table (?:if exists )?(?:only )?${name}`;
|
|
2942
|
+
for (const { file, statements } of migrations) {
|
|
2943
|
+
for (const { sql, line, bodies } of statements) {
|
|
2944
|
+
if (bodies.some((b) => /\benable row level security\b/.test(b))) for (const t of tables.values()) t.rls = true;
|
|
2945
|
+
const create = new RegExp(String.raw`^create (?:(?:global |local )?(?:temp|temporary) |unlogged )?table (?:if not exists )?${name}`).exec(sql);
|
|
2946
|
+
if (create) {
|
|
2947
|
+
if (!/^create (?:global |local )?(?:temp|temporary) /.test(sql)) tables.set(qualify(create[1]), { rls: false, file, line, disabled: false });
|
|
2948
|
+
continue;
|
|
2949
|
+
}
|
|
2950
|
+
const rename = new RegExp(`${target} rename to ([\\w$]+)$`).exec(sql);
|
|
2951
|
+
const move = new RegExp(`${target} set schema ([\\w$]+)$`).exec(sql);
|
|
2952
|
+
if (rename || move) {
|
|
2953
|
+
const from = qualify((rename ?? move)[1]);
|
|
2954
|
+
const to = rename ? `${schemaOf(from)}.${rename[2]}` : `${move[2]}.${from.split(".")[1]}`;
|
|
2955
|
+
const state = tables.get(from);
|
|
2956
|
+
if (state) {
|
|
2957
|
+
tables.delete(from);
|
|
2958
|
+
tables.set(to, state);
|
|
2959
|
+
}
|
|
2960
|
+
continue;
|
|
2961
|
+
}
|
|
2962
|
+
const alter = new RegExp(target).exec(sql);
|
|
2963
|
+
if (alter && /\b(?:enable|disable) row level security\b/.test(sql)) {
|
|
2964
|
+
const t = qualify(alter[1]);
|
|
2965
|
+
if (/\bdisable row level security\b/.test(sql)) tables.set(t, { rls: false, file, line, disabled: true });
|
|
2966
|
+
else {
|
|
2967
|
+
const state = tables.get(t);
|
|
2968
|
+
if (state) state.rls = true;
|
|
2969
|
+
}
|
|
2970
|
+
continue;
|
|
2971
|
+
}
|
|
2972
|
+
const drop = /^drop table (?:if exists )?(.+?)(?: cascade| restrict)?$/.exec(sql);
|
|
2973
|
+
if (drop) for (const n of drop[1].split(",")) tables.delete(qualify(n));
|
|
2974
|
+
}
|
|
2975
|
+
}
|
|
2976
|
+
for (const [t, at] of tables) {
|
|
2977
|
+
if (at.rls || !exposed.has(schemaOf(t))) continue;
|
|
2978
|
+
ctx.report({
|
|
2979
|
+
rule: "migration-rls",
|
|
2980
|
+
file: at.file,
|
|
2981
|
+
line: at.line,
|
|
2982
|
+
subject: t,
|
|
2983
|
+
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`
|
|
2984
|
+
});
|
|
2985
|
+
}
|
|
2986
|
+
}
|
|
2987
|
+
function checkViewInvoker(ctx, migrations, exposed) {
|
|
2988
|
+
const views = /* @__PURE__ */ new Map();
|
|
2989
|
+
const name = String.raw`([\w$.]+)`;
|
|
2990
|
+
const invokerOn = /\bsecurity_invoker\s*(?:=\s*(?:true|on|yes|1|'true'|'on'))?\s*(?:,|\))/;
|
|
2991
|
+
for (const { file, statements } of migrations) {
|
|
2992
|
+
for (const { sql, line } of statements) {
|
|
2993
|
+
const create = new RegExp(String.raw`^create (?:or replace )?(?:temp |temporary )?(?:recursive )?view ${name}`).exec(sql);
|
|
2994
|
+
if (create) {
|
|
2995
|
+
if (/^create (?:or replace )?(?:temp|temporary) /.test(sql)) continue;
|
|
2996
|
+
const options = /^[^(]*?\bwith\s*(\([^)]*\))\s*as\b/.exec(sql)?.[1] ?? "";
|
|
2997
|
+
views.set(qualify(create[1]), { invoker: invokerOn.test(options), file, line });
|
|
2998
|
+
continue;
|
|
2999
|
+
}
|
|
3000
|
+
const alter = new RegExp(String.raw`^alter view (?:if exists )?${name} (set|reset) (\([^)]*\))`).exec(sql);
|
|
3001
|
+
if (alter && /\bsecurity_invoker\b/.test(alter[3])) {
|
|
3002
|
+
const state = views.get(qualify(alter[1]));
|
|
3003
|
+
if (state) state.invoker = alter[2] === "set" && invokerOn.test(alter[3]);
|
|
3004
|
+
continue;
|
|
3005
|
+
}
|
|
3006
|
+
const rename = new RegExp(String.raw`^alter view (?:if exists )?${name} rename to ([\w$]+)$`).exec(sql);
|
|
3007
|
+
if (rename) {
|
|
3008
|
+
const from = qualify(rename[1]);
|
|
3009
|
+
const state = views.get(from);
|
|
3010
|
+
if (state) {
|
|
3011
|
+
views.delete(from);
|
|
3012
|
+
views.set(`${schemaOf(from)}.${rename[2]}`, state);
|
|
3013
|
+
}
|
|
3014
|
+
continue;
|
|
3015
|
+
}
|
|
3016
|
+
const drop = /^drop view (?:if exists )?(.+?)(?: cascade| restrict)?$/.exec(sql);
|
|
3017
|
+
if (drop) for (const n of drop[1].split(",")) views.delete(qualify(n));
|
|
3018
|
+
}
|
|
3019
|
+
}
|
|
3020
|
+
for (const [v, at] of views) {
|
|
3021
|
+
if (at.invoker || !exposed.has(schemaOf(v))) continue;
|
|
3022
|
+
ctx.report({
|
|
3023
|
+
rule: "migration-view-rls",
|
|
3024
|
+
file: at.file,
|
|
3025
|
+
line: at.line,
|
|
3026
|
+
subject: v,
|
|
3027
|
+
message: `${v} runs as its owner, so it reads past row level security; create it "with (security_invoker = true)" or add "alter view ${v} set (security_invoker = true);"`
|
|
3028
|
+
});
|
|
3029
|
+
}
|
|
3030
|
+
}
|
|
3031
|
+
function checkDefinerSearchPath(ctx, migrations) {
|
|
3032
|
+
const fns = /* @__PURE__ */ new Map();
|
|
3033
|
+
const keysFor = (sql, nameEnd, fnName) => {
|
|
3034
|
+
const rest = sql.slice(nameEnd).trimStart();
|
|
3035
|
+
if (rest.startsWith("(")) {
|
|
3036
|
+
const { inner } = parenthesized(rest, 0);
|
|
3037
|
+
return [`${fnName}(${argTypes(inner).join(",")})`];
|
|
3038
|
+
}
|
|
3039
|
+
return [...fns.keys()].filter((k) => k.startsWith(`${fnName}(`));
|
|
3040
|
+
};
|
|
3041
|
+
for (const { file, statements } of migrations) {
|
|
3042
|
+
for (const { sql, line } of statements) {
|
|
3043
|
+
const create = /^create (?:or replace )?(?:function|procedure) ([\w$.]+)\s*/.exec(sql);
|
|
3044
|
+
if (create) {
|
|
3045
|
+
const [key2] = keysFor(sql, create[0].length, qualify(create[1]));
|
|
3046
|
+
fns.set(key2, { definer: /\bsecurity definer\b/.test(sql), searchPath: /\bset search_path\b/.test(sql), file, line });
|
|
3047
|
+
continue;
|
|
3048
|
+
}
|
|
3049
|
+
const alter = /^alter (?:function|procedure|routine) ([\w$.]+)\s*/.exec(sql);
|
|
3050
|
+
if (alter) {
|
|
3051
|
+
const fnName = qualify(alter[1]);
|
|
3052
|
+
const keys = keysFor(sql, alter[0].length, fnName);
|
|
3053
|
+
const rename = / rename to ([\w$]+)$/.exec(sql);
|
|
3054
|
+
const move = / set schema ([\w$]+)$/.exec(sql);
|
|
3055
|
+
for (const key2 of keys) {
|
|
3056
|
+
const state = fns.get(key2);
|
|
3057
|
+
if (rename || move) {
|
|
3058
|
+
if (!state) continue;
|
|
3059
|
+
fns.delete(key2);
|
|
3060
|
+
const newName = rename ? `${schemaOf(fnName)}.${rename[1]}` : `${move[1]}.${fnName.split(".")[1]}`;
|
|
3061
|
+
fns.set(newName + key2.slice(fnName.length), state);
|
|
3062
|
+
continue;
|
|
3063
|
+
}
|
|
3064
|
+
const next = state ?? { definer: false, searchPath: false, file, line };
|
|
3065
|
+
if (/\bsecurity definer\b/.test(sql)) Object.assign(next, { definer: true, file, line });
|
|
3066
|
+
if (/\bsecurity invoker\b/.test(sql)) next.definer = false;
|
|
3067
|
+
if (/\bset search_path\b/.test(sql)) next.searchPath = true;
|
|
3068
|
+
if (/\breset (?:search_path|all)\b/.test(sql)) Object.assign(next, { searchPath: false, file, line });
|
|
3069
|
+
fns.set(key2, next);
|
|
3070
|
+
}
|
|
3071
|
+
continue;
|
|
3072
|
+
}
|
|
3073
|
+
const drop = /^drop (?:function|procedure|routine) (?:if exists )?(.+?)(?: cascade| restrict)?$/.exec(sql);
|
|
3074
|
+
if (drop) {
|
|
3075
|
+
for (const part of splitTop(drop[1])) {
|
|
3076
|
+
const m = /^([\w$.]+)\s*/.exec(part);
|
|
3077
|
+
if (m) for (const key2 of keysFor(part, m[0].length, qualify(m[1]))) fns.delete(key2);
|
|
3078
|
+
}
|
|
3079
|
+
}
|
|
3080
|
+
}
|
|
3081
|
+
}
|
|
3082
|
+
for (const [key2, at] of fns) {
|
|
3083
|
+
if (!at.definer || at.searchPath) continue;
|
|
3084
|
+
ctx.report({
|
|
3085
|
+
rule: "migration-definer-search-path",
|
|
3086
|
+
file: at.file,
|
|
3087
|
+
line: at.line,
|
|
3088
|
+
subject: key2,
|
|
3089
|
+
message: `${key2} 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`
|
|
3090
|
+
});
|
|
3091
|
+
}
|
|
3092
|
+
}
|
|
3093
|
+
var UMBRELLA_PACKAGE = "@marktiderman/genesis";
|
|
3094
|
+
function readReleaseManifest(root) {
|
|
3095
|
+
const dir = findPackageDir(root, UMBRELLA_PACKAGE);
|
|
3096
|
+
const file = dir && path14.join(dir, "dist", "versions.json");
|
|
3097
|
+
if (!file || !existsSync(file)) return null;
|
|
3098
|
+
return JSON.parse(readFileSync(file, "utf8"));
|
|
3099
|
+
}
|
|
3100
|
+
function checkVersionSkew(ctx) {
|
|
3101
|
+
const manifest = readReleaseManifest(ctx.root);
|
|
3102
|
+
if (!manifest) return;
|
|
3103
|
+
for (const [name, want] of Object.entries(manifest.packages)) {
|
|
3104
|
+
const dir = findPackageDir(ctx.root, name);
|
|
3105
|
+
if (!dir) continue;
|
|
3106
|
+
const have = JSON.parse(readFileSync(path14.join(dir, "package.json"), "utf8")).version;
|
|
3107
|
+
if (have === want) continue;
|
|
3108
|
+
ctx.report({
|
|
3109
|
+
rule: "version-skew",
|
|
3110
|
+
level: "warn",
|
|
3111
|
+
file: "package.json",
|
|
3112
|
+
subject: name,
|
|
3113
|
+
message: `${name} is ${have}, but ${UMBRELLA_PACKAGE} ${manifest.version} was released with ${want}. Install ${name}@${want}, or move every Genesis package to one release.`
|
|
3114
|
+
});
|
|
3115
|
+
}
|
|
3116
|
+
}
|
|
3117
|
+
var GENESIS = /^@marktiderman\/genesis(?:-[\w.-]+)?$/;
|
|
3118
|
+
var DEV_TOOLS = /* @__PURE__ */ new Set(["@marktiderman/genesis-cli"]);
|
|
3119
|
+
var NON_SHIPPING = /^(?:@marktiderman\/genesis-cli|vitest|@vitest\/.+|jest|jest-.+|@jest\/.+|ts-jest|babel-jest|mocha|ava|c8|nyc|@playwright\/test|playwright|cypress|@testing-library\/.+|happy-dom|jsdom|msw|@types\/.+|typescript|tsx|ts-node|eslint|eslint-.+|@eslint\/.+|@typescript-eslint\/.+|typescript-eslint|prettier|prettier-.+|@biomejs\/.+|oxlint|vite|@vitejs\/.+|vite-plugin-.+|webpack|webpack-.+|rollup|@rollup\/.+|esbuild|tsup|turbo|@storybook\/.+|storybook|@changesets\/.+|husky|lint-staged|wrangler|knip|concurrently|npm-run-all2?|rimraf|cross-env|dotenv-cli)$/;
|
|
3120
|
+
var readManifest = (dir) => {
|
|
2603
3121
|
try {
|
|
2604
|
-
|
|
2605
|
-
declared = new Set(["dependencies", "devDependencies", "peerDependencies", "optionalDependencies"].flatMap((k) => Object.keys(pkg[k] ?? {})));
|
|
3122
|
+
return JSON.parse(readFileSync(path14.join(dir, "package.json"), "utf8"));
|
|
2606
3123
|
} catch {
|
|
2607
|
-
|
|
3124
|
+
return null;
|
|
2608
3125
|
}
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
|
|
2612
|
-
|
|
2613
|
-
|
|
2614
|
-
|
|
2615
|
-
|
|
2616
|
-
|
|
2617
|
-
|
|
2618
|
-
|
|
2619
|
-
|
|
2620
|
-
|
|
2621
|
-
|
|
3126
|
+
};
|
|
3127
|
+
var real = (p) => {
|
|
3128
|
+
try {
|
|
3129
|
+
return realpathSync(p);
|
|
3130
|
+
} catch {
|
|
3131
|
+
return p;
|
|
3132
|
+
}
|
|
3133
|
+
};
|
|
3134
|
+
var LOCKFILES = ["bun.lock", "bun.lockb", "package-lock.json", "npm-shrinkwrap.json", "yarn.lock", "pnpm-lock.yaml"];
|
|
3135
|
+
function nodeModulesOf(dir) {
|
|
3136
|
+
const parent = path14.dirname(dir);
|
|
3137
|
+
return path14.basename(parent).startsWith("@") ? path14.dirname(parent) : parent;
|
|
3138
|
+
}
|
|
3139
|
+
function packagesIn(nodeModules) {
|
|
3140
|
+
if (!existsSync(nodeModules)) return [];
|
|
3141
|
+
const out = [];
|
|
3142
|
+
for (const entry of readdirSync(nodeModules)) {
|
|
3143
|
+
if (entry.startsWith(".")) continue;
|
|
3144
|
+
const p = path14.join(nodeModules, entry);
|
|
3145
|
+
if (entry.startsWith("@")) {
|
|
3146
|
+
try {
|
|
3147
|
+
for (const sub of readdirSync(p)) out.push(path14.join(p, sub));
|
|
3148
|
+
} catch {
|
|
3149
|
+
}
|
|
3150
|
+
} else {
|
|
3151
|
+
out.push(p);
|
|
2622
3152
|
}
|
|
2623
|
-
|
|
2624
|
-
|
|
2625
|
-
|
|
2626
|
-
|
|
2627
|
-
|
|
2628
|
-
|
|
2629
|
-
|
|
2630
|
-
|
|
2631
|
-
|
|
2632
|
-
|
|
2633
|
-
|
|
2634
|
-
|
|
2635
|
-
|
|
2636
|
-
|
|
2637
|
-
|
|
2638
|
-
|
|
2639
|
-
|
|
2640
|
-
|
|
2641
|
-
|
|
2642
|
-
|
|
2643
|
-
|
|
2644
|
-
|
|
2645
|
-
|
|
2646
|
-
|
|
2647
|
-
|
|
2648
|
-
|
|
2649
|
-
|
|
3153
|
+
}
|
|
3154
|
+
return out;
|
|
3155
|
+
}
|
|
3156
|
+
function genesisInstalls(root) {
|
|
3157
|
+
const copies = /* @__PURE__ */ new Map();
|
|
3158
|
+
const realRoot = real(root);
|
|
3159
|
+
const rel = (abs) => path14.relative(realRoot, abs).split(path14.sep).join("/") || ".";
|
|
3160
|
+
const via = /* @__PURE__ */ new Map();
|
|
3161
|
+
const record = (real2, manifest, by, range, root2) => {
|
|
3162
|
+
let copy = copies.get(real2);
|
|
3163
|
+
if (!copy) {
|
|
3164
|
+
copy = { name: manifest.name, version: String(manifest.version ?? "unknown"), dir: rel(real2), absolutePath: real2, requiredBy: [], devOnly: false, runtime: false };
|
|
3165
|
+
copies.set(real2, copy);
|
|
3166
|
+
via.set(real2, /* @__PURE__ */ new Set());
|
|
3167
|
+
}
|
|
3168
|
+
via.get(real2).add(root2);
|
|
3169
|
+
if (!copy.requiredBy.some((r) => r.by === by)) copy.requiredBy.push({ by, ...range ? { range } : {} });
|
|
3170
|
+
};
|
|
3171
|
+
const walk = (kind, roots) => {
|
|
3172
|
+
const expanded = /* @__PURE__ */ new Set();
|
|
3173
|
+
const queue = [];
|
|
3174
|
+
const visit = (dir, by, range) => {
|
|
3175
|
+
const manifest = readManifest(dir);
|
|
3176
|
+
if (!manifest?.name) return;
|
|
3177
|
+
if (kind !== "dev" && DEV_TOOLS.has(manifest.name)) return;
|
|
3178
|
+
const realDir = real(dir);
|
|
3179
|
+
if (GENESIS.test(manifest.name)) record(realDir, manifest, by, range, kind);
|
|
3180
|
+
if (expanded.has(realDir)) return;
|
|
3181
|
+
expanded.add(realDir);
|
|
3182
|
+
queue.push({ real: realDir, manifest, label: `${manifest.name}@${manifest.version ?? "?"}` });
|
|
3183
|
+
};
|
|
3184
|
+
for (const r of roots) visit(r.dir, r.by, r.range);
|
|
3185
|
+
while (queue.length) {
|
|
3186
|
+
const { real: from, manifest, label } = queue.shift();
|
|
3187
|
+
const deps = { ...manifest.optionalDependencies, ...manifest.dependencies };
|
|
3188
|
+
for (const [name, range] of Object.entries(deps)) {
|
|
3189
|
+
const dir = findPackageDir(from, name);
|
|
3190
|
+
if (dir) visit(dir, label, range);
|
|
3191
|
+
}
|
|
3192
|
+
for (const [name, range] of Object.entries(manifest.peerDependencies ?? {})) {
|
|
3193
|
+
if (name in deps) continue;
|
|
3194
|
+
const dir = peerOf(from, name);
|
|
3195
|
+
if (dir) visit(dir, label, range);
|
|
2650
3196
|
}
|
|
2651
|
-
if (resolved && !files.includes(resolved)) files.push(resolved);
|
|
2652
3197
|
}
|
|
2653
|
-
const out = { files, lost };
|
|
2654
|
-
importsCache.set(file.absolutePath, out);
|
|
2655
|
-
return out;
|
|
2656
3198
|
};
|
|
2657
|
-
const
|
|
2658
|
-
|
|
2659
|
-
if (!
|
|
2660
|
-
|
|
3199
|
+
const peerOf = (from, name) => {
|
|
3200
|
+
const dir = findPackageDir(from, name);
|
|
3201
|
+
if (!dir) return null;
|
|
3202
|
+
if (!ownInstall || name in declared) return dir;
|
|
3203
|
+
const realDir = real(dir);
|
|
3204
|
+
if (realDir.startsWith(realRoot + path14.sep)) return dir;
|
|
3205
|
+
return nodeModulesOf(realDir) === nodeModulesOf(from) ? dir : null;
|
|
2661
3206
|
};
|
|
2662
|
-
const
|
|
2663
|
-
|
|
2664
|
-
|
|
2665
|
-
|
|
2666
|
-
|
|
2667
|
-
|
|
2668
|
-
|
|
2669
|
-
|
|
2670
|
-
|
|
2671
|
-
|
|
2672
|
-
|
|
2673
|
-
|
|
2674
|
-
|
|
2675
|
-
|
|
2676
|
-
|
|
2677
|
-
|
|
2678
|
-
|
|
2679
|
-
|
|
2680
|
-
|
|
2681
|
-
|
|
2682
|
-
|
|
2683
|
-
|
|
2684
|
-
|
|
2685
|
-
|
|
2686
|
-
|
|
2687
|
-
|
|
2688
|
-
|
|
2689
|
-
|
|
2690
|
-
|
|
2691
|
-
|
|
2692
|
-
|
|
2693
|
-
|
|
2694
|
-
|
|
2695
|
-
|
|
2696
|
-
|
|
2697
|
-
|
|
2698
|
-
|
|
2699
|
-
|
|
2700
|
-
|
|
2701
|
-
|
|
2702
|
-
|
|
2703
|
-
|
|
3207
|
+
const rootsOf = (deps, by) => Object.entries(deps).flatMap(([name, range]) => {
|
|
3208
|
+
const dir = findPackageDir(root, name);
|
|
3209
|
+
return dir ? [{ dir, by, ...range ? { range } : {} }] : [];
|
|
3210
|
+
});
|
|
3211
|
+
const app = readManifest(root);
|
|
3212
|
+
const ownInstall = LOCKFILES.some((f) => existsSync(path14.join(root, f)));
|
|
3213
|
+
const declared = { ...app?.devDependencies, ...app?.peerDependencies, ...app?.optionalDependencies, ...app?.dependencies };
|
|
3214
|
+
const declaredDev = Object.entries(app?.devDependencies ?? {});
|
|
3215
|
+
const runtimeDeps = {
|
|
3216
|
+
...Object.fromEntries(declaredDev.filter(([n]) => !NON_SHIPPING.test(n))),
|
|
3217
|
+
...app?.peerDependencies,
|
|
3218
|
+
...app?.optionalDependencies,
|
|
3219
|
+
...app?.dependencies
|
|
3220
|
+
};
|
|
3221
|
+
const devDeps = Object.fromEntries(declaredDev.filter(([n]) => NON_SHIPPING.test(n) && !(n in runtimeDeps)));
|
|
3222
|
+
walk("runtime", rootsOf(runtimeDeps, "the app"));
|
|
3223
|
+
const top = path14.join(root, "node_modules");
|
|
3224
|
+
walk(
|
|
3225
|
+
"hoisted",
|
|
3226
|
+
packagesIn(top).filter((dir) => {
|
|
3227
|
+
const name = path14.relative(top, dir).split(path14.sep).join("/");
|
|
3228
|
+
return !(name in runtimeDeps) && !(name in devDeps);
|
|
3229
|
+
}).map((dir) => ({ dir, by: "hoisted, not a direct dependency" }))
|
|
3230
|
+
);
|
|
3231
|
+
const devRoots = { ...devDeps };
|
|
3232
|
+
for (const tool of DEV_TOOLS) if (!(tool in devRoots) && tool in runtimeDeps) devRoots[tool] = runtimeDeps[tool];
|
|
3233
|
+
walk("dev", rootsOf(devRoots, "the app (dev)"));
|
|
3234
|
+
for (const [key2, copy] of copies) {
|
|
3235
|
+
const kinds = via.get(key2);
|
|
3236
|
+
copy.runtime = kinds.has("runtime");
|
|
3237
|
+
copy.devOnly = kinds.size === 1 && kinds.has("dev");
|
|
3238
|
+
}
|
|
3239
|
+
const byName = /* @__PURE__ */ new Map();
|
|
3240
|
+
for (const copy of copies.values()) byName.set(copy.name, [...byName.get(copy.name) ?? [], copy]);
|
|
3241
|
+
for (const list of byName.values()) list.sort((a, b) => a.dir.split("/").length - b.dir.split("/").length || a.dir.localeCompare(b.dir));
|
|
3242
|
+
return byName;
|
|
3243
|
+
}
|
|
3244
|
+
function checkDuplicatePackages(ctx) {
|
|
3245
|
+
const describe = (c) => `${c.version} at ${c.dir} (${c.requiredBy.map((r) => `${r.by}${r.range ? ` wants ${r.range}` : ""}`).join("; ")})`;
|
|
3246
|
+
for (const [name, copies] of genesisInstalls(ctx.root)) {
|
|
3247
|
+
if (copies.length < 2) continue;
|
|
3248
|
+
const shipping = copies.filter((c) => c.runtime);
|
|
3249
|
+
if (!(shipping.length === 1 && copies.every((c) => c === shipping[0] || c.devOnly))) {
|
|
3250
|
+
ctx.report({
|
|
3251
|
+
rule: "duplicate-genesis-package",
|
|
3252
|
+
level: "warn",
|
|
3253
|
+
file: "package.json",
|
|
3254
|
+
subject: name,
|
|
3255
|
+
message: `${name} is installed ${copies.length} times: ${copies.map((c) => `${describe(c)}${c.devOnly ? " [dev only]" : ""}`).join(", ")}. Each copy is its own module, so a provider from one (DataProvider, the shell's contexts) is invisible to hooks from another. Align the ranges so one copy satisfies them all, or add an override/resolution`
|
|
3256
|
+
});
|
|
3257
|
+
continue;
|
|
2704
3258
|
}
|
|
2705
|
-
|
|
2706
|
-
|
|
2707
|
-
|
|
3259
|
+
ctx.report({
|
|
3260
|
+
rule: "duplicate-genesis-package",
|
|
3261
|
+
level: "info",
|
|
3262
|
+
file: "package.json",
|
|
3263
|
+
subject: name,
|
|
3264
|
+
message: `${name} has dev-only copies beside the one the app loads: ${copies.filter((c) => c.devOnly).map(describe).join(", ")}. They run in tooling, not the app, so they can't split its contexts; upgrade the tool to drop them`
|
|
3265
|
+
});
|
|
3266
|
+
}
|
|
3267
|
+
}
|
|
3268
|
+
function checkPeerRanges(ctx) {
|
|
3269
|
+
const rel = (abs) => path14.relative(ctx.root, abs).split(path14.sep).join("/");
|
|
3270
|
+
for (const copies of genesisInstalls(ctx.root).values()) {
|
|
3271
|
+
for (const copy of copies) {
|
|
3272
|
+
const dir = copy.absolutePath;
|
|
3273
|
+
const peers = readManifest(dir)?.peerDependencies ?? {};
|
|
3274
|
+
for (const [peer, range] of Object.entries(peers)) {
|
|
3275
|
+
if (!GENESIS.test(peer)) continue;
|
|
3276
|
+
const peerDir = findPackageDir(dir, peer);
|
|
3277
|
+
const installed = peerDir && readManifest(peerDir)?.version;
|
|
3278
|
+
if (!peerDir || !installed) continue;
|
|
3279
|
+
if (satisfies(installed, range) !== false) continue;
|
|
3280
|
+
ctx.report({
|
|
3281
|
+
rule: "peer-range-mismatch",
|
|
3282
|
+
// A dev tool's own tree (the CLI's) doesn't run in the app.
|
|
3283
|
+
level: copy.devOnly ? "info" : "warn",
|
|
3284
|
+
file: "package.json",
|
|
3285
|
+
subject: `${copy.name}>${peer}`,
|
|
3286
|
+
message: `${copy.name}@${copy.version} (${copy.dir}) wants ${peer} ${range}, but ${installed} is installed (${rel(peerDir)}). Install a ${peer} in that range, or a ${copy.name} release built against ${installed}`
|
|
3287
|
+
});
|
|
3288
|
+
}
|
|
2708
3289
|
}
|
|
2709
|
-
|
|
2710
|
-
entries.push({ cut: [...cut], result });
|
|
2711
|
-
cache.cut.set(k, entries);
|
|
2712
|
-
return [result, cut];
|
|
2713
|
-
};
|
|
2714
|
-
return { reach: (file, test2, depth = TRAIL_DEPTH) => reach(file, test2, depth, /* @__PURE__ */ new Set())[0] };
|
|
3290
|
+
}
|
|
2715
3291
|
}
|
|
2716
|
-
|
|
2717
|
-
// src/doctor/routes.ts
|
|
2718
3292
|
var ROUTES_DIR_CANDIDATES = ["src/routes", "src/app", "app", "src/pages", "pages"];
|
|
2719
3293
|
var STEMS = {
|
|
2720
3294
|
tanstack: { layout: /* @__PURE__ */ new Set(["route", "__root"]), index: /* @__PURE__ */ new Set(["index"]), skip: /^$/ },
|
|
@@ -2827,7 +3401,7 @@ var SUB_NAV_DOCS = "https://github.com/marktiderman/genesis/blob/main/packages/u
|
|
|
2827
3401
|
var CONTAINER = /(?:Card|CardContent|Dialog|DialogContent|Sheet|SheetContent|Drawer|DrawerContent|Popover|PopoverContent|Modal|Accordion|AccordionContent|AccordionItem|Collapsible|CollapsibleContent|Tooltip|Menu|MenuContent|Panel|Table|TabsContent)$/;
|
|
2828
3402
|
var SWITCHER = /<(TabsList|SubNavTabs)(?=[\s>/])/g;
|
|
2829
3403
|
var SHELL = /<AppShell(?=[\s>/])/;
|
|
2830
|
-
var
|
|
3404
|
+
var GENESIS_PACKAGE2 = /^@marktiderman\/genesis(?:-[\w-]+)?(?:\/|$)/;
|
|
2831
3405
|
var PAGE_LAYOUT = /^(?!Breadcrumb)[A-Z]\w*(?:Page|PageShell)$/;
|
|
2832
3406
|
var PACKAGE_SCREEN = /^(?!Breadcrumb)[A-Z]\w*(?:Page|PageShell|Screen|Workspace)$/;
|
|
2833
3407
|
var isNative = (ctx) => ctx.config.packs?.includes("native") ?? false;
|
|
@@ -2883,7 +3457,7 @@ function checkLocalGenesisCopies(ctx) {
|
|
|
2883
3457
|
const routes = routesDir(ctx);
|
|
2884
3458
|
for (const file of ctx.files) {
|
|
2885
3459
|
if (!JSX_EXTS2.has(file.ext)) continue;
|
|
2886
|
-
const imported = new Set(namedImportsFrom(file.code,
|
|
3460
|
+
const imported = new Set(namedImportsFrom(file.code, GENESIS_PACKAGE2));
|
|
2887
3461
|
const inRoutes = routes !== null && file.path.startsWith(`${routes}/`);
|
|
2888
3462
|
const routeComponents = new Set([...file.code.matchAll(/\b\w*[cC]omponent\s*:\s*([A-Z][\w$]*)\b/g)].map((r) => r[1]));
|
|
2889
3463
|
const decls = [...file.code.matchAll(decl)];
|
|
@@ -2942,13 +3516,13 @@ function checkPageLayouts(ctx) {
|
|
|
2942
3516
|
const inShell = insideShell(ctx, routes);
|
|
2943
3517
|
const rendersLayout = (code) => {
|
|
2944
3518
|
const names = new Set(layouts);
|
|
2945
|
-
for (const n of namedImportsFrom(code,
|
|
3519
|
+
for (const n of namedImportsFrom(code, GENESIS_PACKAGE2)) if (PACKAGE_SCREEN.test(n)) names.add(n);
|
|
2946
3520
|
return rendersRe(names)?.test(code) ?? false;
|
|
2947
3521
|
};
|
|
2948
|
-
const
|
|
3522
|
+
const cache2 = /* @__PURE__ */ new Map();
|
|
2949
3523
|
const provides = (r) => {
|
|
2950
|
-
if (!
|
|
2951
|
-
return
|
|
3524
|
+
if (!cache2.has(r)) cache2.set(r, routeReach(ctx, r, rendersLayout));
|
|
3525
|
+
return cache2.get(r);
|
|
2952
3526
|
};
|
|
2953
3527
|
const list = [...layouts].sort();
|
|
2954
3528
|
const named = list.length > 4 ? `${list.slice(0, 4).join(", ")}, \u2026` : list.join(", ");
|
|
@@ -2997,7 +3571,7 @@ async function runDoctor(options = {}) {
|
|
|
2997
3571
|
if (builtinIds.has(p.id)) throw new DoctorConfigError(`doctor.patterns: "${p.id}" is a built-in rule id; pick another`);
|
|
2998
3572
|
}
|
|
2999
3573
|
const raw = [];
|
|
3000
|
-
const ctx = { root, files, genesis, config, report: (f) => raw.push(f) };
|
|
3574
|
+
const ctx = { root, files, genesis, config, ...options.base ? { base: options.base } : {}, report: (f) => raw.push(f) };
|
|
3001
3575
|
for (const plugin of [...builtinChecks(config), ...patterns ? [patterns.plugin] : [], ...plugins]) {
|
|
3002
3576
|
try {
|
|
3003
3577
|
await plugin.check(ctx);
|
|
@@ -3029,7 +3603,8 @@ async function runDoctor(options = {}) {
|
|
|
3029
3603
|
function builtinChecks(config) {
|
|
3030
3604
|
const packs = {
|
|
3031
3605
|
native: { name: "native", check: checkNativePack },
|
|
3032
|
-
supabase: { name: "supabase", check: checkSupabasePack }
|
|
3606
|
+
supabase: { name: "supabase", check: checkSupabasePack },
|
|
3607
|
+
packages: { name: "packages", check: checkPackagesPack }
|
|
3033
3608
|
};
|
|
3034
3609
|
return [
|
|
3035
3610
|
{ name: "layout", check: checkProjectLayout },
|