create-m5kdev 0.32.7 → 0.33.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/catalog.cjs +55 -10
- package/dist/src/catalog.cjs.map +1 -1
- package/dist/src/catalog.d.cts +11 -1
- package/dist/src/doctor.cjs +13 -7
- package/dist/src/doctor.cjs.map +1 -1
- package/package.json +1 -1
- package/templates/minimal-app/apps/e2e/package.json.tpl +7 -7
- package/templates/minimal-app/apps/email/package.json.tpl +13 -13
- package/templates/minimal-app/apps/expo/package.json.tpl +59 -59
- package/templates/minimal-app/apps/server/AGENTS.md.tpl +2 -2
- package/templates/minimal-app/apps/server/drizzle/0002_concerned_proudstar.sql +3 -0
- package/templates/minimal-app/apps/server/drizzle/meta/0002_snapshot.json.tpl +1932 -0
- package/templates/minimal-app/apps/server/drizzle/meta/_journal.json.tpl +7 -0
- package/templates/minimal-app/apps/server/package.json.tpl +55 -56
- package/templates/minimal-app/apps/server/src/app.ts.tpl +113 -141
- package/templates/minimal-app/apps/server/src/index.ts.tpl +12 -65
- package/templates/minimal-app/apps/server/src/modules/posts/posts.grants.ts.tpl +5 -7
- package/templates/minimal-app/apps/server/src/modules/posts/posts.service.ts.tpl +6 -5
- package/templates/minimal-app/apps/server/src/modules/posts/posts.trpc.ts.tpl +1 -1
- package/templates/minimal-app/apps/server/src/types.ts.tpl +12 -1
- package/templates/minimal-app/apps/shared/package.json.tpl +5 -5
- package/templates/minimal-app/apps/webapp/package.json.tpl +33 -33
- package/templates/minimal-app/package.json.tpl +3 -3
- package/templates/minimal-app/pnpm-workspace.yaml.tpl +60 -58
- package/templates/minimal-app/apps/server/src/lib/auth.ts.tpl +0 -12
package/dist/src/catalog.cjs
CHANGED
|
@@ -12,6 +12,8 @@ const DEPENDENCY_FIELDS = [
|
|
|
12
12
|
"peerDependencies",
|
|
13
13
|
"optionalDependencies"
|
|
14
14
|
];
|
|
15
|
+
const MANAGED_CATALOG_NAME = "m5kdev";
|
|
16
|
+
const MANAGED_CATALOG_SPECIFIER = `catalog:${MANAGED_CATALOG_NAME}`;
|
|
15
17
|
function walkPackageJsonFiles(directory, out = []) {
|
|
16
18
|
for (const entry of node_fs.default.readdirSync(directory, { withFileTypes: true })) {
|
|
17
19
|
if (entry.name === "node_modules" || entry.name === ".git") continue;
|
|
@@ -24,6 +26,9 @@ function walkPackageJsonFiles(directory, out = []) {
|
|
|
24
26
|
function readJson(filePath) {
|
|
25
27
|
return JSON.parse(node_fs.default.readFileSync(filePath, "utf8"));
|
|
26
28
|
}
|
|
29
|
+
function asCatalog(value) {
|
|
30
|
+
return Object.fromEntries(Object.entries(value ?? {}).map(([name, version]) => [name, String(version)]));
|
|
31
|
+
}
|
|
27
32
|
function collectConsumerDependencyNamesFromManifests(manifests) {
|
|
28
33
|
const names = /* @__PURE__ */ new Set();
|
|
29
34
|
for (const manifest of manifests) for (const field of DEPENDENCY_FIELDS) {
|
|
@@ -35,6 +40,17 @@ function collectConsumerDependencyNamesFromManifests(manifests) {
|
|
|
35
40
|
function collectConsumerDependencyNames(packageFiles) {
|
|
36
41
|
return collectConsumerDependencyNamesFromManifests(packageFiles.map(readJson));
|
|
37
42
|
}
|
|
43
|
+
function collectCatalogProtocolDependenciesFromManifests(manifests) {
|
|
44
|
+
const dependencies = [];
|
|
45
|
+
for (const manifest of manifests) for (const field of DEPENDENCY_FIELDS) for (const [name, specifier] of Object.entries(manifest[field] ?? {})) if (specifier.startsWith("catalog:")) dependencies.push({
|
|
46
|
+
name,
|
|
47
|
+
specifier
|
|
48
|
+
});
|
|
49
|
+
return dependencies;
|
|
50
|
+
}
|
|
51
|
+
function collectCatalogProtocolDependencies(packageFiles) {
|
|
52
|
+
return collectCatalogProtocolDependenciesFromManifests(packageFiles.map(readJson));
|
|
53
|
+
}
|
|
38
54
|
function buildConsumerCatalog(options) {
|
|
39
55
|
const workspacePath = node_path.default.join(options.repoRoot, "pnpm-workspace.yaml");
|
|
40
56
|
const sourceCatalog = (0, yaml.parse)(node_fs.default.readFileSync(workspacePath, "utf8")).catalog ?? {};
|
|
@@ -67,14 +83,25 @@ function buildConsumerCatalog(options) {
|
|
|
67
83
|
if (missing.length > 0) throw new Error(`Missing consumer catalog versions for: ${missing.join(", ")}`);
|
|
68
84
|
return catalog;
|
|
69
85
|
}
|
|
86
|
+
function sortedCatalog(catalog) {
|
|
87
|
+
return Object.fromEntries(Object.entries(catalog).sort(([left], [right]) => left.localeCompare(right)));
|
|
88
|
+
}
|
|
70
89
|
function renderConsumerWorkspace(source, catalog) {
|
|
71
90
|
const workspace = (0, yaml.parse)(source);
|
|
72
|
-
workspace.
|
|
91
|
+
const catalogs = workspace.catalogs && typeof workspace.catalogs === "object" ? { ...workspace.catalogs } : {};
|
|
92
|
+
catalogs[MANAGED_CATALOG_NAME] = sortedCatalog(catalog);
|
|
93
|
+
workspace.catalogs = catalogs;
|
|
94
|
+
if (workspace.catalog === void 0) workspace.catalog = {};
|
|
73
95
|
return (0, yaml.stringify)(workspace, { lineWidth: 0 });
|
|
74
96
|
}
|
|
97
|
+
function readDefaultCatalog(source) {
|
|
98
|
+
return asCatalog((0, yaml.parse)(source).catalog);
|
|
99
|
+
}
|
|
75
100
|
function readCatalog(source) {
|
|
76
101
|
const workspace = (0, yaml.parse)(source);
|
|
77
|
-
|
|
102
|
+
const named = workspace.catalogs?.[MANAGED_CATALOG_NAME];
|
|
103
|
+
if (named !== void 0) return asCatalog(named);
|
|
104
|
+
return asCatalog(workspace.catalog);
|
|
78
105
|
}
|
|
79
106
|
function assertCatalogKeys(catalog, expectedNames, label = "consumer catalog") {
|
|
80
107
|
const expected = new Set(expectedNames);
|
|
@@ -87,16 +114,24 @@ function assertCatalogKeys(catalog, expectedNames, label = "consumer catalog") {
|
|
|
87
114
|
}
|
|
88
115
|
function mergeManagedCatalog(options) {
|
|
89
116
|
const document = (0, yaml.parseDocument)(options.source);
|
|
90
|
-
const
|
|
117
|
+
const workspace = (0, yaml.parse)(options.source);
|
|
118
|
+
const namedPresent = workspace.catalogs?.[MANAGED_CATALOG_NAME] !== void 0;
|
|
119
|
+
const named = asCatalog(workspace.catalogs?.[MANAGED_CATALOG_NAME]);
|
|
120
|
+
const fallback = asCatalog(workspace.catalog);
|
|
91
121
|
const conflicts = [];
|
|
92
122
|
const names = new Set([...Object.keys(options.base), ...Object.keys(options.target)]);
|
|
123
|
+
const managedPath = ["catalogs", MANAGED_CATALOG_NAME];
|
|
124
|
+
if (document.getIn([...managedPath]) === void 0) if (document.get("catalogs") === void 0) document.set("catalogs", document.createNode({ [MANAGED_CATALOG_NAME]: {} }));
|
|
125
|
+
else document.setIn([...managedPath], document.createNode({}));
|
|
93
126
|
for (const name of [...names].sort((left, right) => left.localeCompare(right))) {
|
|
94
127
|
const base = options.base[name];
|
|
95
|
-
const current =
|
|
128
|
+
const current = (namedPresent ? named[name] : void 0) ?? fallback[name];
|
|
96
129
|
const target = options.target[name];
|
|
97
130
|
if (base === void 0) {
|
|
98
|
-
if (current === void 0)
|
|
99
|
-
|
|
131
|
+
if (current === void 0) {
|
|
132
|
+
document.setIn([...managedPath, name], target);
|
|
133
|
+
document.deleteIn(["catalog", name]);
|
|
134
|
+
} else if (current !== target) conflicts.push({
|
|
100
135
|
name,
|
|
101
136
|
local: current,
|
|
102
137
|
target
|
|
@@ -104,16 +139,20 @@ function mergeManagedCatalog(options) {
|
|
|
104
139
|
continue;
|
|
105
140
|
}
|
|
106
141
|
if (target === void 0) {
|
|
107
|
-
if (current === base)
|
|
108
|
-
|
|
142
|
+
if (current === base) {
|
|
143
|
+
document.deleteIn([...managedPath, name]);
|
|
144
|
+
document.deleteIn(["catalog", name]);
|
|
145
|
+
} else if (current !== void 0) conflicts.push({
|
|
109
146
|
name,
|
|
110
147
|
base,
|
|
111
148
|
local: current
|
|
112
149
|
});
|
|
113
150
|
continue;
|
|
114
151
|
}
|
|
115
|
-
if (current === base)
|
|
116
|
-
|
|
152
|
+
if (current === base) {
|
|
153
|
+
document.setIn([...managedPath, name], target);
|
|
154
|
+
document.deleteIn(["catalog", name]);
|
|
155
|
+
} else if (current !== target && target !== base) conflicts.push({
|
|
117
156
|
name,
|
|
118
157
|
base,
|
|
119
158
|
local: current,
|
|
@@ -128,13 +167,19 @@ function mergeManagedCatalog(options) {
|
|
|
128
167
|
};
|
|
129
168
|
}
|
|
130
169
|
//#endregion
|
|
170
|
+
exports.MANAGED_CATALOG_NAME = MANAGED_CATALOG_NAME;
|
|
171
|
+
exports.MANAGED_CATALOG_SPECIFIER = MANAGED_CATALOG_SPECIFIER;
|
|
131
172
|
exports.assertCatalogKeys = assertCatalogKeys;
|
|
132
173
|
exports.buildConsumerCatalog = buildConsumerCatalog;
|
|
174
|
+
exports.collectCatalogProtocolDependencies = collectCatalogProtocolDependencies;
|
|
175
|
+
exports.collectCatalogProtocolDependenciesFromManifests = collectCatalogProtocolDependenciesFromManifests;
|
|
133
176
|
exports.collectConsumerDependencyNames = collectConsumerDependencyNames;
|
|
134
177
|
exports.collectConsumerDependencyNamesFromManifests = collectConsumerDependencyNamesFromManifests;
|
|
135
178
|
exports.mergeManagedCatalog = mergeManagedCatalog;
|
|
136
179
|
exports.readCatalog = readCatalog;
|
|
180
|
+
exports.readDefaultCatalog = readDefaultCatalog;
|
|
137
181
|
exports.renderConsumerWorkspace = renderConsumerWorkspace;
|
|
182
|
+
exports.sortedCatalog = sortedCatalog;
|
|
138
183
|
exports.walkPackageJsonFiles = walkPackageJsonFiles;
|
|
139
184
|
|
|
140
185
|
//# sourceMappingURL=catalog.cjs.map
|
package/dist/src/catalog.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"catalog.cjs","names":["fs","path"],"sources":["../../src/catalog.ts"],"sourcesContent":["import fs from \"node:fs\";\r\nimport path from \"node:path\";\r\nimport { parse, parseDocument, stringify } from \"yaml\";\r\n\r\nconst DEPENDENCY_FIELDS = [\r\n \"dependencies\",\r\n \"devDependencies\",\r\n \"peerDependencies\",\r\n \"optionalDependencies\",\r\n] as const;\r\n\r\nexport type ConsumerCatalog = Record<string, string>;\r\n\r\nexport function walkPackageJsonFiles(directory: string, out: string[] = []): string[] {\r\n for (const entry of fs.readdirSync(directory, { withFileTypes: true })) {\r\n if (entry.name === \"node_modules\" || entry.name === \".git\") continue;\r\n const entryPath = path.join(directory, entry.name);\r\n if (entry.isDirectory()) {\r\n walkPackageJsonFiles(entryPath, out);\r\n } else if (entry.isFile() && entry.name === \"package.json\") {\r\n out.push(entryPath);\r\n }\r\n }\r\n return out;\r\n}\r\n\r\nfunction readJson(filePath: string): Record<string, unknown> {\r\n return JSON.parse(fs.readFileSync(filePath, \"utf8\")) as Record<string, unknown>;\r\n}\r\n\r\nexport function collectConsumerDependencyNamesFromManifests(\r\n manifests: readonly Record<string, unknown>[]\r\n): string[] {\r\n const names = new Set<string>();\r\n\r\n for (const manifest of manifests) {\r\n for (const field of DEPENDENCY_FIELDS) {\r\n const dependencies = manifest[field] as Record<string, string> | undefined;\r\n for (const [name, specifier] of Object.entries(dependencies ?? {})) {\r\n if (\r\n specifier.startsWith(\"catalog:\") ||\r\n (name.startsWith(\"@m5kdev/\") && specifier.startsWith(\"workspace:\"))\r\n ) {\r\n names.add(name);\r\n }\r\n }\r\n }\r\n }\r\n\r\n return [...names].sort((left, right) => left.localeCompare(right));\r\n}\r\n\r\nexport function collectConsumerDependencyNames(packageFiles: readonly string[]): string[] {\r\n return collectConsumerDependencyNamesFromManifests(packageFiles.map(readJson));\r\n}\r\n\r\nexport function buildConsumerCatalog(options: {\r\n repoRoot: string;\r\n starterDirectory: string;\r\n rootTemplatesDirectory: string;\r\n}): ConsumerCatalog {\r\n const workspacePath = path.join(options.repoRoot, \"pnpm-workspace.yaml\");\r\n const workspace = parse(fs.readFileSync(workspacePath, \"utf8\")) as {\r\n catalog?: Record<string, string | number>;\r\n };\r\n const sourceCatalog = workspace.catalog ?? {};\r\n const packageFiles = [\r\n ...walkPackageJsonFiles(options.starterDirectory),\r\n path.join(options.rootTemplatesDirectory, \"package.json.tpl\"),\r\n ];\r\n const names = collectConsumerDependencyNames(packageFiles);\r\n const catalog: ConsumerCatalog = {};\r\n const missing: string[] = [];\r\n\r\n for (const name of names) {\r\n if (name.startsWith(\"@m5kdev/\")) {\r\n const packageName = name.slice(\"@m5kdev/\".length);\r\n const packagePath = path.join(options.repoRoot, \"packages\", packageName, \"package.json\");\r\n if (!fs.existsSync(packagePath)) {\r\n missing.push(name);\r\n continue;\r\n }\r\n const packageManifest = readJson(packagePath);\r\n if (typeof packageManifest.version !== \"string\") {\r\n missing.push(name);\r\n continue;\r\n }\r\n catalog[name] = packageManifest.version;\r\n continue;\r\n }\r\n\r\n const version = sourceCatalog[name];\r\n if (version === undefined) {\r\n missing.push(name);\r\n continue;\r\n }\r\n catalog[name] = String(version);\r\n }\r\n\r\n if (missing.length > 0) {\r\n throw new Error(`Missing consumer catalog versions for: ${missing.join(\", \")}`);\r\n }\r\n\r\n return catalog;\r\n}\r\n\r\nexport function renderConsumerWorkspace(source: string, catalog: ConsumerCatalog): string {\r\n const workspace = parse(source) as Record<string, unknown>;\r\n workspace.catalog = Object.fromEntries(\r\n Object.entries(catalog).sort(([left], [right]) => left.localeCompare(right))\r\n );\r\n return stringify(workspace, { lineWidth: 0 });\r\n}\r\n\r\nexport function readCatalog(source: string): ConsumerCatalog {\r\n const workspace = parse(source) as { catalog?: Record<string, string | number> };\r\n return Object.fromEntries(\r\n Object.entries(workspace.catalog ?? {}).map(([name, version]) => [name, String(version)])\r\n );\r\n}\r\n\r\nexport function assertCatalogKeys(\r\n catalog: ConsumerCatalog,\r\n expectedNames: readonly string[],\r\n label = \"consumer catalog\"\r\n): void {\r\n const expected = new Set(expectedNames);\r\n const missing = expectedNames.filter((name) => !(name in catalog));\r\n const obsolete = Object.keys(catalog).filter((name) => !expected.has(name));\r\n if (missing.length > 0 || obsolete.length > 0) {\r\n const details = [\r\n missing.length > 0 ? `missing: ${missing.join(\", \")}` : undefined,\r\n obsolete.length > 0 ? `obsolete: ${obsolete.join(\", \")}` : undefined,\r\n ].filter(Boolean);\r\n throw new Error(`Invalid ${label} (${details.join(\"; \")})`);\r\n }\r\n}\r\n\r\nexport interface CatalogMergeConflict {\r\n name: string;\r\n base?: string;\r\n local?: string;\r\n target?: string;\r\n}\r\n\r\nexport function mergeManagedCatalog(options: {\r\n source: string;\r\n base: ConsumerCatalog;\r\n target: ConsumerCatalog;\r\n}): { source: string; changed: boolean; conflicts: CatalogMergeConflict[] } {\r\n const document = parseDocument(options.source);\r\n const local = readCatalog(options.source);\r\n const conflicts: CatalogMergeConflict[] = [];\r\n const names = new Set([...Object.keys(options.base), ...Object.keys(options.target)]);\r\n\r\n for (const name of [...names].sort((left, right) => left.localeCompare(right))) {\r\n const base = options.base[name];\r\n const current = local[name];\r\n const target = options.target[name];\r\n\r\n if (base === undefined) {\r\n if (current === undefined) document.setIn([\"catalog\", name], target);\r\n else if (current !== target) conflicts.push({ name, local: current, target });\r\n continue;\r\n }\r\n if (target === undefined) {\r\n if (current === base) document.deleteIn([\"catalog\", name]);\r\n else if (current !== undefined) conflicts.push({ name, base, local: current });\r\n continue;\r\n }\r\n if (current === base) document.setIn([\"catalog\", name], target);\r\n else if (current !== target && target !== base) {\r\n conflicts.push({ name, base, local: current, target });\r\n }\r\n }\r\n\r\n const merged = document.toString({ lineWidth: 0 });\r\n return { source: merged, changed: merged !== options.source, conflicts };\r\n}\r\n"],"mappings":";;;;;;;;AAIA,MAAM,oBAAoB;CACxB;CACA;CACA;CACA;CACD;AAID,SAAgB,qBAAqB,WAAmB,MAAgB,EAAE,EAAY;AACpF,MAAK,MAAM,SAASA,QAAAA,QAAG,YAAY,WAAW,EAAE,eAAe,MAAM,CAAC,EAAE;AACtE,MAAI,MAAM,SAAS,kBAAkB,MAAM,SAAS,OAAQ;EAC5D,MAAM,YAAYC,UAAAA,QAAK,KAAK,WAAW,MAAM,KAAK;AAClD,MAAI,MAAM,aAAa,CACrB,sBAAqB,WAAW,IAAI;WAC3B,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|
+
{"version":3,"file":"catalog.cjs","names":["fs","path"],"sources":["../../src/catalog.ts"],"sourcesContent":["import fs from \"node:fs\";\r\nimport path from \"node:path\";\r\nimport { parse, parseDocument, stringify } from \"yaml\";\r\n\r\nconst DEPENDENCY_FIELDS = [\r\n \"dependencies\",\r\n \"devDependencies\",\r\n \"peerDependencies\",\r\n \"optionalDependencies\",\r\n] as const;\r\n\r\nexport const MANAGED_CATALOG_NAME = \"m5kdev\";\r\nexport const MANAGED_CATALOG_SPECIFIER = `catalog:${MANAGED_CATALOG_NAME}`;\r\n\r\nexport type ConsumerCatalog = Record<string, string>;\r\n\r\ninterface WorkspaceCatalogFile {\r\n catalog?: Record<string, string | number>;\r\n catalogs?: Record<string, Record<string, string | number> | undefined>;\r\n}\r\n\r\nexport function walkPackageJsonFiles(directory: string, out: string[] = []): string[] {\r\n for (const entry of fs.readdirSync(directory, { withFileTypes: true })) {\r\n if (entry.name === \"node_modules\" || entry.name === \".git\") continue;\r\n const entryPath = path.join(directory, entry.name);\r\n if (entry.isDirectory()) {\r\n walkPackageJsonFiles(entryPath, out);\r\n } else if (entry.isFile() && entry.name === \"package.json\") {\r\n out.push(entryPath);\r\n }\r\n }\r\n return out;\r\n}\r\n\r\nfunction readJson(filePath: string): Record<string, unknown> {\r\n return JSON.parse(fs.readFileSync(filePath, \"utf8\")) as Record<string, unknown>;\r\n}\r\n\r\nfunction asCatalog(value: Record<string, string | number> | undefined): ConsumerCatalog {\r\n return Object.fromEntries(\r\n Object.entries(value ?? {}).map(([name, version]) => [name, String(version)])\r\n );\r\n}\r\n\r\nexport function collectConsumerDependencyNamesFromManifests(\r\n manifests: readonly Record<string, unknown>[]\r\n): string[] {\r\n const names = new Set<string>();\r\n\r\n for (const manifest of manifests) {\r\n for (const field of DEPENDENCY_FIELDS) {\r\n const dependencies = manifest[field] as Record<string, string> | undefined;\r\n for (const [name, specifier] of Object.entries(dependencies ?? {})) {\r\n if (\r\n specifier.startsWith(\"catalog:\") ||\r\n (name.startsWith(\"@m5kdev/\") && specifier.startsWith(\"workspace:\"))\r\n ) {\r\n names.add(name);\r\n }\r\n }\r\n }\r\n }\r\n\r\n return [...names].sort((left, right) => left.localeCompare(right));\r\n}\r\n\r\nexport function collectConsumerDependencyNames(packageFiles: readonly string[]): string[] {\r\n return collectConsumerDependencyNamesFromManifests(packageFiles.map(readJson));\r\n}\r\n\r\nexport interface CatalogProtocolDependency {\r\n name: string;\r\n specifier: string;\r\n}\r\n\r\nexport function collectCatalogProtocolDependenciesFromManifests(\r\n manifests: readonly Record<string, unknown>[]\r\n): CatalogProtocolDependency[] {\r\n const dependencies: CatalogProtocolDependency[] = [];\r\n for (const manifest of manifests) {\r\n for (const field of DEPENDENCY_FIELDS) {\r\n for (const [name, specifier] of Object.entries(\r\n (manifest[field] as Record<string, string> | undefined) ?? {}\r\n )) {\r\n if (specifier.startsWith(\"catalog:\")) dependencies.push({ name, specifier });\r\n }\r\n }\r\n }\r\n return dependencies;\r\n}\r\n\r\nexport function collectCatalogProtocolDependencies(\r\n packageFiles: readonly string[]\r\n): CatalogProtocolDependency[] {\r\n return collectCatalogProtocolDependenciesFromManifests(packageFiles.map(readJson));\r\n}\r\n\r\nexport function buildConsumerCatalog(options: {\r\n repoRoot: string;\r\n starterDirectory: string;\r\n rootTemplatesDirectory: string;\r\n}): ConsumerCatalog {\r\n const workspacePath = path.join(options.repoRoot, \"pnpm-workspace.yaml\");\r\n const workspace = parse(fs.readFileSync(workspacePath, \"utf8\")) as {\r\n catalog?: Record<string, string | number>;\r\n };\r\n const sourceCatalog = workspace.catalog ?? {};\r\n const packageFiles = [\r\n ...walkPackageJsonFiles(options.starterDirectory),\r\n path.join(options.rootTemplatesDirectory, \"package.json.tpl\"),\r\n ];\r\n const names = collectConsumerDependencyNames(packageFiles);\r\n const catalog: ConsumerCatalog = {};\r\n const missing: string[] = [];\r\n\r\n for (const name of names) {\r\n if (name.startsWith(\"@m5kdev/\")) {\r\n const packageName = name.slice(\"@m5kdev/\".length);\r\n const packagePath = path.join(options.repoRoot, \"packages\", packageName, \"package.json\");\r\n if (!fs.existsSync(packagePath)) {\r\n missing.push(name);\r\n continue;\r\n }\r\n const packageManifest = readJson(packagePath);\r\n if (typeof packageManifest.version !== \"string\") {\r\n missing.push(name);\r\n continue;\r\n }\r\n catalog[name] = packageManifest.version;\r\n continue;\r\n }\r\n\r\n const version = sourceCatalog[name];\r\n if (version === undefined) {\r\n missing.push(name);\r\n continue;\r\n }\r\n catalog[name] = String(version);\r\n }\r\n\r\n if (missing.length > 0) {\r\n throw new Error(`Missing consumer catalog versions for: ${missing.join(\", \")}`);\r\n }\r\n\r\n return catalog;\r\n}\r\n\r\nexport function sortedCatalog(catalog: ConsumerCatalog): ConsumerCatalog {\r\n return Object.fromEntries(\r\n Object.entries(catalog).sort(([left], [right]) => left.localeCompare(right))\r\n );\r\n}\r\n\r\nexport function renderConsumerWorkspace(source: string, catalog: ConsumerCatalog): string {\r\n const workspace = parse(source) as Record<string, unknown>;\r\n const catalogs =\r\n workspace.catalogs && typeof workspace.catalogs === \"object\"\r\n ? { ...(workspace.catalogs as Record<string, unknown>) }\r\n : {};\r\n catalogs[MANAGED_CATALOG_NAME] = sortedCatalog(catalog);\r\n workspace.catalogs = catalogs;\r\n if (workspace.catalog === undefined) workspace.catalog = {};\r\n return stringify(workspace, { lineWidth: 0 });\r\n}\r\n\r\nexport function readDefaultCatalog(source: string): ConsumerCatalog {\r\n const workspace = parse(source) as WorkspaceCatalogFile;\r\n return asCatalog(workspace.catalog);\r\n}\r\n\r\nexport function readCatalog(source: string): ConsumerCatalog {\r\n const workspace = parse(source) as WorkspaceCatalogFile;\r\n const named = workspace.catalogs?.[MANAGED_CATALOG_NAME];\r\n if (named !== undefined) return asCatalog(named);\r\n return asCatalog(workspace.catalog);\r\n}\r\n\r\nexport function assertCatalogKeys(\r\n catalog: ConsumerCatalog,\r\n expectedNames: readonly string[],\r\n label = \"consumer catalog\"\r\n): void {\r\n const expected = new Set(expectedNames);\r\n const missing = expectedNames.filter((name) => !(name in catalog));\r\n const obsolete = Object.keys(catalog).filter((name) => !expected.has(name));\r\n if (missing.length > 0 || obsolete.length > 0) {\r\n const details = [\r\n missing.length > 0 ? `missing: ${missing.join(\", \")}` : undefined,\r\n obsolete.length > 0 ? `obsolete: ${obsolete.join(\", \")}` : undefined,\r\n ].filter(Boolean);\r\n throw new Error(`Invalid ${label} (${details.join(\"; \")})`);\r\n }\r\n}\r\n\r\nexport interface CatalogMergeConflict {\r\n name: string;\r\n base?: string;\r\n local?: string;\r\n target?: string;\r\n}\r\n\r\nexport function mergeManagedCatalog(options: {\r\n source: string;\r\n base: ConsumerCatalog;\r\n target: ConsumerCatalog;\r\n}): { source: string; changed: boolean; conflicts: CatalogMergeConflict[] } {\r\n const document = parseDocument(options.source);\r\n const workspace = parse(options.source) as WorkspaceCatalogFile;\r\n const namedPresent = workspace.catalogs?.[MANAGED_CATALOG_NAME] !== undefined;\r\n const named = asCatalog(workspace.catalogs?.[MANAGED_CATALOG_NAME]);\r\n const fallback = asCatalog(workspace.catalog);\r\n const conflicts: CatalogMergeConflict[] = [];\r\n const names = new Set([...Object.keys(options.base), ...Object.keys(options.target)]);\r\n const managedPath = [\"catalogs\", MANAGED_CATALOG_NAME] as const;\r\n\r\n if (document.getIn([...managedPath]) === undefined) {\r\n if (document.get(\"catalogs\") === undefined) {\r\n document.set(\"catalogs\", document.createNode({ [MANAGED_CATALOG_NAME]: {} }));\r\n } else {\r\n document.setIn([...managedPath], document.createNode({}));\r\n }\r\n }\r\n\r\n for (const name of [...names].sort((left, right) => left.localeCompare(right))) {\r\n const base = options.base[name];\r\n const current = (namedPresent ? named[name] : undefined) ?? fallback[name];\r\n const target = options.target[name];\r\n\r\n if (base === undefined) {\r\n if (current === undefined) {\r\n document.setIn([...managedPath, name], target);\r\n document.deleteIn([\"catalog\", name]);\r\n } else if (current !== target) conflicts.push({ name, local: current, target });\r\n continue;\r\n }\r\n if (target === undefined) {\r\n if (current === base) {\r\n document.deleteIn([...managedPath, name]);\r\n document.deleteIn([\"catalog\", name]);\r\n } else if (current !== undefined) conflicts.push({ name, base, local: current });\r\n continue;\r\n }\r\n if (current === base) {\r\n document.setIn([...managedPath, name], target);\r\n document.deleteIn([\"catalog\", name]);\r\n } else if (current !== target && target !== base) {\r\n conflicts.push({ name, base, local: current, target });\r\n }\r\n }\r\n\r\n const merged = document.toString({ lineWidth: 0 });\r\n return { source: merged, changed: merged !== options.source, conflicts };\r\n}\r\n"],"mappings":";;;;;;;;AAIA,MAAM,oBAAoB;CACxB;CACA;CACA;CACA;CACD;AAED,MAAa,uBAAuB;AACpC,MAAa,4BAA4B,WAAW;AASpD,SAAgB,qBAAqB,WAAmB,MAAgB,EAAE,EAAY;AACpF,MAAK,MAAM,SAASA,QAAAA,QAAG,YAAY,WAAW,EAAE,eAAe,MAAM,CAAC,EAAE;AACtE,MAAI,MAAM,SAAS,kBAAkB,MAAM,SAAS,OAAQ;EAC5D,MAAM,YAAYC,UAAAA,QAAK,KAAK,WAAW,MAAM,KAAK;AAClD,MAAI,MAAM,aAAa,CACrB,sBAAqB,WAAW,IAAI;WAC3B,MAAM,QAAQ,IAAI,MAAM,SAAS,eAC1C,KAAI,KAAK,UAAU;;AAGvB,QAAO;;AAGT,SAAS,SAAS,UAA2C;AAC3D,QAAO,KAAK,MAAMD,QAAAA,QAAG,aAAa,UAAU,OAAO,CAAC;;AAGtD,SAAS,UAAU,OAAqE;AACtF,QAAO,OAAO,YACZ,OAAO,QAAQ,SAAS,EAAE,CAAC,CAAC,KAAK,CAAC,MAAM,aAAa,CAAC,MAAM,OAAO,QAAQ,CAAC,CAAC,CAC9E;;AAGH,SAAgB,4CACd,WACU;CACV,MAAM,wBAAQ,IAAI,KAAa;AAE/B,MAAK,MAAM,YAAY,UACrB,MAAK,MAAM,SAAS,mBAAmB;EACrC,MAAM,eAAe,SAAS;AAC9B,OAAK,MAAM,CAAC,MAAM,cAAc,OAAO,QAAQ,gBAAgB,EAAE,CAAC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AM,WAAW,eAAe,MAAM,QAAQ,KAAA,MAAc,SAAS;EACrE,MAAM,SAAS,QAAQ,OAAO;AAE9B,MAAI,SAAS,KAAA,GAAW;AACtB,OAAI,YAAY,KAAA,GAAW;AACzB,aAAS,MAAM,CAAC,GAAG,aAAa,KAAK,EAAE,OAAO;AAC9C,aAAS,SAAS,CAAC,WAAW,KAAK,CAAC;cAC3B,YAAY,OAAQ,WAAU,KAAK;IAAE;IAAM,OAAO;IAAS;IAAQ,CAAC;AAC/E;;AAEF,MAAI,WAAW,KAAA,GAAW;AACxB,OAAI,YAAY,MAAM;AACpB,aAAS,SAAS,CAAC,GAAG,aAAa,KAAK,CAAC;AACzC,aAAS,SAAS,CAAC,WAAW,KAAK,CAAC;cAC3B,YAAY,KAAA,EAAW,WAAU,KAAK;IAAE;IAAM;IAAM,OAAO;IAAS,CAAC;AAChF;;AAEF,MAAI,YAAY,MAAM;AACpB,YAAS,MAAM,CAAC,GAAG,aAAa,KAAK,EAAE,OAAO;AAC9C,YAAS,SAAS,CAAC,WAAW,KAAK,CAAC;aAC3B,YAAY,UAAU,WAAW,KAC1C,WAAU,KAAK;GAAE;GAAM;GAAM,OAAO;GAAS;GAAQ,CAAC;;CAI1D,MAAM,SAAS,SAAS,SAAS,EAAE,WAAW,GAAG,CAAC;AAClD,QAAO;EAAE,QAAQ;EAAQ,SAAS,WAAW,QAAQ;EAAQ;EAAW"}
|
package/dist/src/catalog.d.cts
CHANGED
|
@@ -1,14 +1,24 @@
|
|
|
1
1
|
//#region src/catalog.d.ts
|
|
2
|
+
declare const MANAGED_CATALOG_NAME = "m5kdev";
|
|
3
|
+
declare const MANAGED_CATALOG_SPECIFIER = "catalog:m5kdev";
|
|
2
4
|
type ConsumerCatalog = Record<string, string>;
|
|
3
5
|
declare function walkPackageJsonFiles(directory: string, out?: string[]): string[];
|
|
4
6
|
declare function collectConsumerDependencyNamesFromManifests(manifests: readonly Record<string, unknown>[]): string[];
|
|
5
7
|
declare function collectConsumerDependencyNames(packageFiles: readonly string[]): string[];
|
|
8
|
+
interface CatalogProtocolDependency {
|
|
9
|
+
name: string;
|
|
10
|
+
specifier: string;
|
|
11
|
+
}
|
|
12
|
+
declare function collectCatalogProtocolDependenciesFromManifests(manifests: readonly Record<string, unknown>[]): CatalogProtocolDependency[];
|
|
13
|
+
declare function collectCatalogProtocolDependencies(packageFiles: readonly string[]): CatalogProtocolDependency[];
|
|
6
14
|
declare function buildConsumerCatalog(options: {
|
|
7
15
|
repoRoot: string;
|
|
8
16
|
starterDirectory: string;
|
|
9
17
|
rootTemplatesDirectory: string;
|
|
10
18
|
}): ConsumerCatalog;
|
|
19
|
+
declare function sortedCatalog(catalog: ConsumerCatalog): ConsumerCatalog;
|
|
11
20
|
declare function renderConsumerWorkspace(source: string, catalog: ConsumerCatalog): string;
|
|
21
|
+
declare function readDefaultCatalog(source: string): ConsumerCatalog;
|
|
12
22
|
declare function readCatalog(source: string): ConsumerCatalog;
|
|
13
23
|
declare function assertCatalogKeys(catalog: ConsumerCatalog, expectedNames: readonly string[], label?: string): void;
|
|
14
24
|
interface CatalogMergeConflict {
|
|
@@ -27,5 +37,5 @@ declare function mergeManagedCatalog(options: {
|
|
|
27
37
|
conflicts: CatalogMergeConflict[];
|
|
28
38
|
};
|
|
29
39
|
//#endregion
|
|
30
|
-
export { CatalogMergeConflict, ConsumerCatalog, assertCatalogKeys, buildConsumerCatalog, collectConsumerDependencyNames, collectConsumerDependencyNamesFromManifests, mergeManagedCatalog, readCatalog, renderConsumerWorkspace, walkPackageJsonFiles };
|
|
40
|
+
export { CatalogMergeConflict, CatalogProtocolDependency, ConsumerCatalog, MANAGED_CATALOG_NAME, MANAGED_CATALOG_SPECIFIER, assertCatalogKeys, buildConsumerCatalog, collectCatalogProtocolDependencies, collectCatalogProtocolDependenciesFromManifests, collectConsumerDependencyNames, collectConsumerDependencyNamesFromManifests, mergeManagedCatalog, readCatalog, readDefaultCatalog, renderConsumerWorkspace, sortedCatalog, walkPackageJsonFiles };
|
|
31
41
|
//# sourceMappingURL=catalog.d.cts.map
|
package/dist/src/doctor.cjs
CHANGED
|
@@ -102,7 +102,9 @@ async function diagnoseManagedRepo(options) {
|
|
|
102
102
|
const workspaceRelativePath = "pnpm-workspace.yaml";
|
|
103
103
|
const workspacePath = node_path.default.join(options.repoRoot, workspaceRelativePath);
|
|
104
104
|
if (!await require_src_changes.findRepositorySymlink(options.repoRoot, workspaceRelativePath) && await exists(workspacePath)) try {
|
|
105
|
-
const
|
|
105
|
+
const workspaceSource = await node_fs_promises.default.readFile(workspacePath, "utf8");
|
|
106
|
+
const actualCatalog = require_src_catalog.readCatalog(workspaceSource);
|
|
107
|
+
const defaultCatalog = require_src_catalog.readDefaultCatalog(workspaceSource);
|
|
106
108
|
for (const [name, expected] of Object.entries(state.catalog)) {
|
|
107
109
|
if (!semver.default.validRange(expected)) diagnostics.push({
|
|
108
110
|
code: "CATALOG_VERSION_INVALID",
|
|
@@ -128,12 +130,16 @@ async function diagnoseManagedRepo(options) {
|
|
|
128
130
|
const appsDirectory = node_path.default.join(options.repoRoot, "apps");
|
|
129
131
|
const packageFiles = [node_path.default.join(options.repoRoot, "package.json")];
|
|
130
132
|
if (await exists(appsDirectory)) packageFiles.push(...require_src_catalog.walkPackageJsonFiles(appsDirectory));
|
|
131
|
-
for (const
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
133
|
+
for (const { name, specifier } of require_src_catalog.collectCatalogProtocolDependencies(packageFiles)) {
|
|
134
|
+
const catalog = specifier === require_src_catalog.MANAGED_CATALOG_SPECIFIER ? actualCatalog : specifier === "catalog:" ? defaultCatalog : void 0;
|
|
135
|
+
if (catalog === void 0) continue;
|
|
136
|
+
if (!(name in catalog)) diagnostics.push({
|
|
137
|
+
code: "CATALOG_REFERENCE_MISSING",
|
|
138
|
+
severity: "error",
|
|
139
|
+
message: `${name} uses ${specifier} but has no matching catalog entry.`,
|
|
140
|
+
path: "pnpm-workspace.yaml"
|
|
141
|
+
});
|
|
142
|
+
}
|
|
137
143
|
} catch (error) {
|
|
138
144
|
diagnostics.push({
|
|
139
145
|
code: "CATALOG_INVALID",
|
package/dist/src/doctor.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"doctor.cjs","names":["execFile","fs","readManagedState","createDiagnosticReport","getCliVersion","loadTemplateManifest","getTemplateRoot","findRepositorySymlink","path","readCatalog","walkPackageJsonFiles","collectConsumerDependencyNames","sha256","getPendingMigrations","runMigrationValidators","ChangeSet"],"sources":["../../src/doctor.ts"],"sourcesContent":["import { execFile } from \"node:child_process\";\r\nimport fs from \"node:fs/promises\";\r\nimport path from \"node:path\";\r\nimport { promisify } from \"node:util\";\r\nimport semver from \"semver\";\r\nimport { collectConsumerDependencyNames, readCatalog, walkPackageJsonFiles } from \"./catalog\";\r\nimport { ChangeSet, findRepositorySymlink } from \"./changes\";\r\nimport { TEMPLATE_NAME } from \"./constants\";\r\nimport { createDiagnosticReport, type Diagnostic, type DiagnosticReport } from \"./diagnostics\";\r\nimport { getPendingMigrations, runMigrationValidators } from \"./migrations/registry\";\r\nimport { getTemplateRoot } from \"./paths\";\r\nimport { getCliVersion, type ManagedState, readManagedState, sha256 } from \"./state\";\r\nimport { loadTemplateManifest } from \"./template\";\r\n\r\nconst execFileAsync = promisify(execFile);\r\nconst FULL_COMMAND_TIMEOUT_MS = 10 * 60 * 1000;\r\n\r\nexport interface DoctorOptions {\r\n repoRoot: string;\r\n full?: boolean;\r\n state?: ManagedState;\r\n}\r\n\r\nasync function exists(filePath: string): Promise<boolean> {\r\n return fs\r\n .access(filePath)\r\n .then(() => true)\r\n .catch(() => false);\r\n}\r\n\r\nexport async function diagnoseManagedRepo(options: DoctorOptions): Promise<DiagnosticReport> {\r\n const diagnostics: Diagnostic[] = [];\r\n let state = options.state;\r\n if (!state) {\r\n try {\r\n state = await readManagedState(options.repoRoot);\r\n } catch (error) {\r\n diagnostics.push({\r\n code: \"STATE_INVALID\",\r\n severity: \"error\",\r\n message: error instanceof Error ? error.message : \"Unable to read .m5kdev.json.\",\r\n path: \".m5kdev.json\",\r\n suggestion: \"Run m5kdev init to establish a managed baseline.\",\r\n });\r\n return createDiagnosticReport(diagnostics);\r\n }\r\n }\r\n\r\n const cliVersion = getCliVersion();\r\n if (state.template.name !== TEMPLATE_NAME) {\r\n diagnostics.push({\r\n code: \"STATE_TEMPLATE_UNKNOWN\",\r\n severity: \"error\",\r\n message: `Unsupported template name: ${state.template.name}`,\r\n path: \".m5kdev.json\",\r\n });\r\n }\r\n if (!semver.valid(state.template.version)) {\r\n diagnostics.push({\r\n code: \"STATE_VERSION_INVALID\",\r\n severity: \"error\",\r\n message: `Invalid template version: ${state.template.version}`,\r\n path: \".m5kdev.json\",\r\n });\r\n } else if (semver.gt(state.template.version, cliVersion)) {\r\n diagnostics.push({\r\n code: \"CLI_TOO_OLD\",\r\n severity: \"error\",\r\n message: `This repository is managed by ${state.template.version}, but the running CLI is ${cliVersion}.`,\r\n suggestion: `Run pnpm dlx create-m5kdev@${state.template.version} doctor.`,\r\n });\r\n } else if (semver.lt(state.template.version, cliVersion)) {\r\n diagnostics.push({\r\n code: \"UPDATE_AVAILABLE\",\r\n severity: \"warning\",\r\n message: `Template ${cliVersion} is available; this repository is at ${state.template.version}.`,\r\n suggestion: `Preview it with pnpm dlx create-m5kdev@${cliVersion} update --dry-run.`,\r\n });\r\n }\r\n\r\n const manifest = loadTemplateManifest(getTemplateRoot());\r\n const seenFeatures = new Set<string>();\r\n for (const feature of state.template.features) {\r\n if (seenFeatures.has(feature)) {\r\n diagnostics.push({\r\n code: \"FEATURE_DUPLICATE\",\r\n severity: \"error\",\r\n message: `Feature ${feature} is listed more than once.`,\r\n path: \".m5kdev.json\",\r\n });\r\n } else if (!(feature in manifest.features)) {\r\n diagnostics.push({\r\n code: \"FEATURE_UNKNOWN\",\r\n severity: \"error\",\r\n message: `Unknown managed feature: ${feature}`,\r\n path: \".m5kdev.json\",\r\n });\r\n }\r\n seenFeatures.add(feature);\r\n }\r\n const requiredPaths = new Set(manifest.requiredPaths);\r\n if (state.template.features.includes(\"webapp\")) requiredPaths.add(\"apps/webapp/package.json\");\r\n if (state.template.features.includes(\"expo\")) requiredPaths.add(\"apps/expo/package.json\");\r\n if (state.template.features.includes(\"test-harness\")) requiredPaths.add(\"apps/e2e/package.json\");\r\n for (const relativePath of requiredPaths) {\r\n const symlink = await findRepositorySymlink(options.repoRoot, relativePath);\r\n if (symlink) {\r\n diagnostics.push({\r\n code: \"MANAGED_PATH_SYMLINK\",\r\n severity: \"error\",\r\n message: `Required managed path contains symbolic link ${symlink}.`,\r\n path: relativePath,\r\n });\r\n } else if (!(await exists(path.join(options.repoRoot, relativePath)))) {\r\n diagnostics.push({\r\n code: \"REQUIRED_PATH_MISSING\",\r\n severity: \"error\",\r\n message: \"Required managed path is missing.\",\r\n path: relativePath,\r\n suggestion:\r\n \"Restore the path or correct the enabled features before initializing/updating.\",\r\n });\r\n }\r\n }\r\n\r\n const workspaceRelativePath = \"pnpm-workspace.yaml\";\r\n const workspacePath = path.join(options.repoRoot, workspaceRelativePath);\r\n const workspaceSymlink = await findRepositorySymlink(options.repoRoot, workspaceRelativePath);\r\n if (!workspaceSymlink && (await exists(workspacePath))) {\r\n try {\r\n const actualCatalog = readCatalog(await fs.readFile(workspacePath, \"utf8\"));\r\n for (const [name, expected] of Object.entries(state.catalog)) {\r\n if (!semver.validRange(expected)) {\r\n diagnostics.push({\r\n code: \"CATALOG_VERSION_INVALID\",\r\n severity: \"error\",\r\n message: `${name} has an invalid managed SemVer range: ${expected}.`,\r\n path: \".m5kdev.json\",\r\n });\r\n }\r\n if (!(name in actualCatalog)) {\r\n diagnostics.push({\r\n code: \"CATALOG_ENTRY_MISSING\",\r\n severity: \"error\",\r\n message: `Managed catalog entry ${name} is missing.`,\r\n path: \"pnpm-workspace.yaml\",\r\n suggestion: `Restore ${name}: ${expected}.`,\r\n });\r\n } else if (actualCatalog[name] !== expected) {\r\n diagnostics.push({\r\n code: \"CATALOG_VERSION_MISMATCH\",\r\n severity: \"error\",\r\n message: `${name} is ${actualCatalog[name]}, expected managed version ${expected}.`,\r\n path: \"pnpm-workspace.yaml\",\r\n suggestion: `Set ${name} to ${expected} in pnpm-workspace.yaml.`,\r\n });\r\n }\r\n }\r\n\r\n const appsDirectory = path.join(options.repoRoot, \"apps\");\r\n const packageFiles = [path.join(options.repoRoot, \"package.json\")];\r\n if (await exists(appsDirectory)) packageFiles.push(...walkPackageJsonFiles(appsDirectory));\r\n for (const dependency of collectConsumerDependencyNames(packageFiles)) {\r\n if (!(dependency in actualCatalog)) {\r\n diagnostics.push({\r\n code: \"CATALOG_REFERENCE_MISSING\",\r\n severity: \"error\",\r\n message: `${dependency} uses catalog: but has no catalog entry.`,\r\n path: \"pnpm-workspace.yaml\",\r\n });\r\n }\r\n }\r\n } catch (error) {\r\n diagnostics.push({\r\n code: \"CATALOG_INVALID\",\r\n severity: \"error\",\r\n message: error instanceof Error ? error.message : \"Unable to parse the consumer catalog.\",\r\n path: \"pnpm-workspace.yaml\",\r\n });\r\n }\r\n }\r\n\r\n for (const [relativePath, baseline] of Object.entries(state.files)) {\r\n if (baseline.policy === \"ignore\") continue;\r\n const filePath = path.join(options.repoRoot, relativePath);\r\n const symlink = await findRepositorySymlink(options.repoRoot, relativePath);\r\n if (symlink) {\r\n diagnostics.push({\r\n code: \"MANAGED_PATH_SYMLINK\",\r\n severity: \"error\",\r\n message: `Managed path contains symbolic link ${symlink}.`,\r\n path: relativePath,\r\n });\r\n continue;\r\n }\r\n const stat = await fs.lstat(filePath).catch(() => null);\r\n if (!stat) {\r\n if (baseline.policy === \"ensure\") {\r\n diagnostics.push({\r\n code: \"ENSURED_PATH_MISSING\",\r\n severity: \"error\",\r\n message: \"An ensured template path is missing.\",\r\n path: relativePath,\r\n });\r\n }\r\n continue;\r\n }\r\n if (!stat.isFile()) continue;\r\n const content = await fs.readFile(filePath);\r\n if (baseline.sha256 && sha256(content) !== baseline.sha256) {\r\n diagnostics.push({\r\n code: \"TEMPLATE_CUSTOMIZED\",\r\n severity: \"info\",\r\n message: \"Managed template content has local customizations.\",\r\n path: relativePath,\r\n });\r\n }\r\n if (baseline.kind === \"text\") {\r\n const source = content.toString(\"utf8\");\r\n if (\r\n /\\{\\{(?:APP_NAME|APP_DESCRIPTION|APP_SLUG|PACKAGE_SCOPE|BETTER_AUTH_SECRET)\\}\\}/.test(\r\n source\r\n )\r\n ) {\r\n diagnostics.push({\r\n code: \"UNRESOLVED_TEMPLATE_TOKEN\",\r\n severity: \"error\",\r\n message: \"Unresolved template token found.\",\r\n path: relativePath,\r\n });\r\n }\r\n if (/^(<{7}|={7}|>{7})(?: |$)/m.test(source)) {\r\n diagnostics.push({\r\n code: \"MERGE_CONFLICT_MARKER\",\r\n severity: \"error\",\r\n message: \"Unresolved merge conflict marker found.\",\r\n path: relativePath,\r\n });\r\n }\r\n }\r\n }\r\n\r\n const pending = getPendingMigrations(state, cliVersion);\r\n for (const migration of pending) {\r\n diagnostics.push({\r\n code: \"MIGRATION_PENDING\",\r\n severity: \"error\",\r\n message: migration.description,\r\n migrationId: migration.id,\r\n guide: migration.guide,\r\n suggestion: `Run pnpm dlx create-m5kdev@${cliVersion} update.`,\r\n });\r\n }\r\n diagnostics.push(\r\n ...(await runMigrationValidators({\r\n repoRoot: options.repoRoot,\r\n state,\r\n changes: new ChangeSet(options.repoRoot),\r\n }))\r\n );\r\n\r\n if (options.full) {\r\n const packagePath = path.join(options.repoRoot, \"package.json\");\r\n let packageManifest: { scripts?: Record<string, string> } | undefined;\r\n try {\r\n packageManifest = JSON.parse(await fs.readFile(packagePath, \"utf8\")) as {\r\n scripts?: Record<string, string>;\r\n };\r\n } catch (error) {\r\n diagnostics.push({\r\n code: \"PACKAGE_JSON_UNREADABLE\",\r\n severity: \"error\",\r\n message:\r\n error instanceof Error\r\n ? `Unable to read package.json: ${error.message}`\r\n : \"Unable to read package.json.\",\r\n path: \"package.json\",\r\n });\r\n }\r\n if (packageManifest) {\r\n for (const script of [\"check-types\", \"lint\", \"build\"] as const) {\r\n if (!packageManifest.scripts?.[script]) continue;\r\n try {\r\n await execFileAsync(\"pnpm\", [script], {\r\n cwd: options.repoRoot,\r\n env: process.env,\r\n timeout: FULL_COMMAND_TIMEOUT_MS,\r\n });\r\n } catch (error) {\r\n diagnostics.push({\r\n code: `COMMAND_${script.replace(\"-\", \"_\").toUpperCase()}_FAILED`,\r\n severity: \"error\",\r\n message: `${script} failed: ${error instanceof Error ? error.message : String(error)}`,\r\n path: \"package.json\",\r\n });\r\n }\r\n }\r\n }\r\n }\r\n\r\n return createDiagnosticReport(diagnostics);\r\n}\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAcA,MAAM,iBAAA,GAAA,UAAA,WAA0BA,mBAAAA,SAAS;AACzC,MAAM,0BAA0B,MAAU;AAQ1C,eAAe,OAAO,UAAoC;AACxD,QAAOC,iBAAAA,QACJ,OAAO,SAAS,CAChB,WAAW,KAAK,CAChB,YAAY,MAAM;;AAGvB,eAAsB,oBAAoB,SAAmD;CAC3F,MAAM,cAA4B,EAAE;CACpC,IAAI,QAAQ,QAAQ;AACpB,KAAI,CAAC,MACH,KAAI;AACF,UAAQ,MAAMC,kBAAAA,iBAAiB,QAAQ,SAAS;UACzC,OAAO;AACd,cAAY,KAAK;GACf,MAAM;GACN,UAAU;GACV,SAAS,iBAAiB,QAAQ,MAAM,UAAU;GAClD,MAAM;GACN,YAAY;GACb,CAAC;AACF,SAAOC,wBAAAA,uBAAuB,YAAY;;CAI9C,MAAM,aAAaC,kBAAAA,eAAe;AAClC,KAAI,MAAM,SAAS,SAAA,cACjB,aAAY,KAAK;EACf,MAAM;EACN,UAAU;EACV,SAAS,8BAA8B,MAAM,SAAS;EACtD,MAAM;EACP,CAAC;AAEJ,KAAI,CAAC,OAAA,QAAO,MAAM,MAAM,SAAS,QAAQ,CACvC,aAAY,KAAK;EACf,MAAM;EACN,UAAU;EACV,SAAS,6BA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,MAAM;IACP,CAAC;;;CAKR,MAAM,UAAUC,gCAAAA,qBAAqB,OAAO,WAAW;AACvD,MAAK,MAAM,aAAa,QACtB,aAAY,KAAK;EACf,MAAM;EACN,UAAU;EACV,SAAS,UAAU;EACnB,aAAa,UAAU;EACvB,OAAO,UAAU;EACjB,YAAY,8BAA8B,WAAW;EACtD,CAAC;AAEJ,aAAY,KACV,GAAI,MAAMC,gCAAAA,uBAAuB;EAC/B,UAAU,QAAQ;EAClB;EACA,SAAS,IAAIC,oBAAAA,UAAU,QAAQ,SAAS;EACzC,CAAC,CACH;AAED,KAAI,QAAQ,MAAM;EAChB,MAAM,cAAcP,UAAAA,QAAK,KAAK,QAAQ,UAAU,eAAe;EAC/D,IAAI;AACJ,MAAI;AACF,qBAAkB,KAAK,MAAM,MAAMP,iBAAAA,QAAG,SAAS,aAAa,OAAO,CAAC;WAG7D,OAAO;AACd,eAAY,KAAK;IACf,MAAM;IACN,UAAU;IACV,SACE,iBAAiB,QACb,gCAAgC,MAAM,YACtC;IACN,MAAM;IACP,CAAC;;AAEJ,MAAI,gBACF,MAAK,MAAM,UAAU;GAAC;GAAe;GAAQ;GAAQ,EAAW;AAC9D,OAAI,CAAC,gBAAgB,UAAU,QAAS;AACxC,OAAI;AACF,UAAM,cAAc,QAAQ,CAAC,OAAO,EAAE;KACpC,KAAK,QAAQ;KACb,KAAK,QAAQ;KACb,SAAS;KACV,CAAC;YACK,OAAO;AACd,gBAAY,KAAK;KACf,MAAM,WAAW,OAAO,QAAQ,KAAK,IAAI,CAAC,aAAa,CAAC;KACxD,UAAU;KACV,SAAS,GAAG,OAAO,WAAW,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM;KACpF,MAAM;KACP,CAAC;;;;AAMV,QAAOE,wBAAAA,uBAAuB,YAAY"}
|
|
1
|
+
{"version":3,"file":"doctor.cjs","names":["execFile","fs","readManagedState","createDiagnosticReport","getCliVersion","loadTemplateManifest","getTemplateRoot","findRepositorySymlink","path","readCatalog","readDefaultCatalog","walkPackageJsonFiles","collectCatalogProtocolDependencies","MANAGED_CATALOG_SPECIFIER","sha256","getPendingMigrations","runMigrationValidators","ChangeSet"],"sources":["../../src/doctor.ts"],"sourcesContent":["import { execFile } from \"node:child_process\";\r\nimport fs from \"node:fs/promises\";\r\nimport path from \"node:path\";\r\nimport { promisify } from \"node:util\";\r\nimport semver from \"semver\";\r\nimport {\r\n MANAGED_CATALOG_SPECIFIER,\r\n collectCatalogProtocolDependencies,\r\n readCatalog,\r\n readDefaultCatalog,\r\n walkPackageJsonFiles,\r\n} from \"./catalog\";\r\nimport { ChangeSet, findRepositorySymlink } from \"./changes\";\r\nimport { TEMPLATE_NAME } from \"./constants\";\r\nimport { createDiagnosticReport, type Diagnostic, type DiagnosticReport } from \"./diagnostics\";\r\nimport { getPendingMigrations, runMigrationValidators } from \"./migrations/registry\";\r\nimport { getTemplateRoot } from \"./paths\";\r\nimport { getCliVersion, type ManagedState, readManagedState, sha256 } from \"./state\";\r\nimport { loadTemplateManifest } from \"./template\";\r\n\r\nconst execFileAsync = promisify(execFile);\r\nconst FULL_COMMAND_TIMEOUT_MS = 10 * 60 * 1000;\r\n\r\nexport interface DoctorOptions {\r\n repoRoot: string;\r\n full?: boolean;\r\n state?: ManagedState;\r\n}\r\n\r\nasync function exists(filePath: string): Promise<boolean> {\r\n return fs\r\n .access(filePath)\r\n .then(() => true)\r\n .catch(() => false);\r\n}\r\n\r\nexport async function diagnoseManagedRepo(options: DoctorOptions): Promise<DiagnosticReport> {\r\n const diagnostics: Diagnostic[] = [];\r\n let state = options.state;\r\n if (!state) {\r\n try {\r\n state = await readManagedState(options.repoRoot);\r\n } catch (error) {\r\n diagnostics.push({\r\n code: \"STATE_INVALID\",\r\n severity: \"error\",\r\n message: error instanceof Error ? error.message : \"Unable to read .m5kdev.json.\",\r\n path: \".m5kdev.json\",\r\n suggestion: \"Run m5kdev init to establish a managed baseline.\",\r\n });\r\n return createDiagnosticReport(diagnostics);\r\n }\r\n }\r\n\r\n const cliVersion = getCliVersion();\r\n if (state.template.name !== TEMPLATE_NAME) {\r\n diagnostics.push({\r\n code: \"STATE_TEMPLATE_UNKNOWN\",\r\n severity: \"error\",\r\n message: `Unsupported template name: ${state.template.name}`,\r\n path: \".m5kdev.json\",\r\n });\r\n }\r\n if (!semver.valid(state.template.version)) {\r\n diagnostics.push({\r\n code: \"STATE_VERSION_INVALID\",\r\n severity: \"error\",\r\n message: `Invalid template version: ${state.template.version}`,\r\n path: \".m5kdev.json\",\r\n });\r\n } else if (semver.gt(state.template.version, cliVersion)) {\r\n diagnostics.push({\r\n code: \"CLI_TOO_OLD\",\r\n severity: \"error\",\r\n message: `This repository is managed by ${state.template.version}, but the running CLI is ${cliVersion}.`,\r\n suggestion: `Run pnpm dlx create-m5kdev@${state.template.version} doctor.`,\r\n });\r\n } else if (semver.lt(state.template.version, cliVersion)) {\r\n diagnostics.push({\r\n code: \"UPDATE_AVAILABLE\",\r\n severity: \"warning\",\r\n message: `Template ${cliVersion} is available; this repository is at ${state.template.version}.`,\r\n suggestion: `Preview it with pnpm dlx create-m5kdev@${cliVersion} update --dry-run.`,\r\n });\r\n }\r\n\r\n const manifest = loadTemplateManifest(getTemplateRoot());\r\n const seenFeatures = new Set<string>();\r\n for (const feature of state.template.features) {\r\n if (seenFeatures.has(feature)) {\r\n diagnostics.push({\r\n code: \"FEATURE_DUPLICATE\",\r\n severity: \"error\",\r\n message: `Feature ${feature} is listed more than once.`,\r\n path: \".m5kdev.json\",\r\n });\r\n } else if (!(feature in manifest.features)) {\r\n diagnostics.push({\r\n code: \"FEATURE_UNKNOWN\",\r\n severity: \"error\",\r\n message: `Unknown managed feature: ${feature}`,\r\n path: \".m5kdev.json\",\r\n });\r\n }\r\n seenFeatures.add(feature);\r\n }\r\n const requiredPaths = new Set(manifest.requiredPaths);\r\n if (state.template.features.includes(\"webapp\")) requiredPaths.add(\"apps/webapp/package.json\");\r\n if (state.template.features.includes(\"expo\")) requiredPaths.add(\"apps/expo/package.json\");\r\n if (state.template.features.includes(\"test-harness\")) requiredPaths.add(\"apps/e2e/package.json\");\r\n for (const relativePath of requiredPaths) {\r\n const symlink = await findRepositorySymlink(options.repoRoot, relativePath);\r\n if (symlink) {\r\n diagnostics.push({\r\n code: \"MANAGED_PATH_SYMLINK\",\r\n severity: \"error\",\r\n message: `Required managed path contains symbolic link ${symlink}.`,\r\n path: relativePath,\r\n });\r\n } else if (!(await exists(path.join(options.repoRoot, relativePath)))) {\r\n diagnostics.push({\r\n code: \"REQUIRED_PATH_MISSING\",\r\n severity: \"error\",\r\n message: \"Required managed path is missing.\",\r\n path: relativePath,\r\n suggestion:\r\n \"Restore the path or correct the enabled features before initializing/updating.\",\r\n });\r\n }\r\n }\r\n\r\n const workspaceRelativePath = \"pnpm-workspace.yaml\";\r\n const workspacePath = path.join(options.repoRoot, workspaceRelativePath);\r\n const workspaceSymlink = await findRepositorySymlink(options.repoRoot, workspaceRelativePath);\r\n if (!workspaceSymlink && (await exists(workspacePath))) {\r\n try {\r\n const workspaceSource = await fs.readFile(workspacePath, \"utf8\");\r\n const actualCatalog = readCatalog(workspaceSource);\r\n const defaultCatalog = readDefaultCatalog(workspaceSource);\r\n for (const [name, expected] of Object.entries(state.catalog)) {\r\n if (!semver.validRange(expected)) {\r\n diagnostics.push({\r\n code: \"CATALOG_VERSION_INVALID\",\r\n severity: \"error\",\r\n message: `${name} has an invalid managed SemVer range: ${expected}.`,\r\n path: \".m5kdev.json\",\r\n });\r\n }\r\n if (!(name in actualCatalog)) {\r\n diagnostics.push({\r\n code: \"CATALOG_ENTRY_MISSING\",\r\n severity: \"error\",\r\n message: `Managed catalog entry ${name} is missing.`,\r\n path: \"pnpm-workspace.yaml\",\r\n suggestion: `Restore ${name}: ${expected}.`,\r\n });\r\n } else if (actualCatalog[name] !== expected) {\r\n diagnostics.push({\r\n code: \"CATALOG_VERSION_MISMATCH\",\r\n severity: \"error\",\r\n message: `${name} is ${actualCatalog[name]}, expected managed version ${expected}.`,\r\n path: \"pnpm-workspace.yaml\",\r\n suggestion: `Set ${name} to ${expected} in pnpm-workspace.yaml.`,\r\n });\r\n }\r\n }\r\n\r\n const appsDirectory = path.join(options.repoRoot, \"apps\");\r\n const packageFiles = [path.join(options.repoRoot, \"package.json\")];\r\n if (await exists(appsDirectory)) packageFiles.push(...walkPackageJsonFiles(appsDirectory));\r\n for (const { name, specifier } of collectCatalogProtocolDependencies(packageFiles)) {\r\n const catalog =\r\n specifier === MANAGED_CATALOG_SPECIFIER\r\n ? actualCatalog\r\n : specifier === \"catalog:\"\r\n ? defaultCatalog\r\n : undefined;\r\n if (catalog === undefined) continue;\r\n if (!(name in catalog)) {\r\n diagnostics.push({\r\n code: \"CATALOG_REFERENCE_MISSING\",\r\n severity: \"error\",\r\n message: `${name} uses ${specifier} but has no matching catalog entry.`,\r\n path: \"pnpm-workspace.yaml\",\r\n });\r\n }\r\n }\r\n } catch (error) {\r\n diagnostics.push({\r\n code: \"CATALOG_INVALID\",\r\n severity: \"error\",\r\n message: error instanceof Error ? error.message : \"Unable to parse the consumer catalog.\",\r\n path: \"pnpm-workspace.yaml\",\r\n });\r\n }\r\n }\r\n\r\n for (const [relativePath, baseline] of Object.entries(state.files)) {\r\n if (baseline.policy === \"ignore\") continue;\r\n const filePath = path.join(options.repoRoot, relativePath);\r\n const symlink = await findRepositorySymlink(options.repoRoot, relativePath);\r\n if (symlink) {\r\n diagnostics.push({\r\n code: \"MANAGED_PATH_SYMLINK\",\r\n severity: \"error\",\r\n message: `Managed path contains symbolic link ${symlink}.`,\r\n path: relativePath,\r\n });\r\n continue;\r\n }\r\n const stat = await fs.lstat(filePath).catch(() => null);\r\n if (!stat) {\r\n if (baseline.policy === \"ensure\") {\r\n diagnostics.push({\r\n code: \"ENSURED_PATH_MISSING\",\r\n severity: \"error\",\r\n message: \"An ensured template path is missing.\",\r\n path: relativePath,\r\n });\r\n }\r\n continue;\r\n }\r\n if (!stat.isFile()) continue;\r\n const content = await fs.readFile(filePath);\r\n if (baseline.sha256 && sha256(content) !== baseline.sha256) {\r\n diagnostics.push({\r\n code: \"TEMPLATE_CUSTOMIZED\",\r\n severity: \"info\",\r\n message: \"Managed template content has local customizations.\",\r\n path: relativePath,\r\n });\r\n }\r\n if (baseline.kind === \"text\") {\r\n const source = content.toString(\"utf8\");\r\n if (\r\n /\\{\\{(?:APP_NAME|APP_DESCRIPTION|APP_SLUG|PACKAGE_SCOPE|BETTER_AUTH_SECRET)\\}\\}/.test(\r\n source\r\n )\r\n ) {\r\n diagnostics.push({\r\n code: \"UNRESOLVED_TEMPLATE_TOKEN\",\r\n severity: \"error\",\r\n message: \"Unresolved template token found.\",\r\n path: relativePath,\r\n });\r\n }\r\n if (/^(<{7}|={7}|>{7})(?: |$)/m.test(source)) {\r\n diagnostics.push({\r\n code: \"MERGE_CONFLICT_MARKER\",\r\n severity: \"error\",\r\n message: \"Unresolved merge conflict marker found.\",\r\n path: relativePath,\r\n });\r\n }\r\n }\r\n }\r\n\r\n const pending = getPendingMigrations(state, cliVersion);\r\n for (const migration of pending) {\r\n diagnostics.push({\r\n code: \"MIGRATION_PENDING\",\r\n severity: \"error\",\r\n message: migration.description,\r\n migrationId: migration.id,\r\n guide: migration.guide,\r\n suggestion: `Run pnpm dlx create-m5kdev@${cliVersion} update.`,\r\n });\r\n }\r\n diagnostics.push(\r\n ...(await runMigrationValidators({\r\n repoRoot: options.repoRoot,\r\n state,\r\n changes: new ChangeSet(options.repoRoot),\r\n }))\r\n );\r\n\r\n if (options.full) {\r\n const packagePath = path.join(options.repoRoot, \"package.json\");\r\n let packageManifest: { scripts?: Record<string, string> } | undefined;\r\n try {\r\n packageManifest = JSON.parse(await fs.readFile(packagePath, \"utf8\")) as {\r\n scripts?: Record<string, string>;\r\n };\r\n } catch (error) {\r\n diagnostics.push({\r\n code: \"PACKAGE_JSON_UNREADABLE\",\r\n severity: \"error\",\r\n message:\r\n error instanceof Error\r\n ? `Unable to read package.json: ${error.message}`\r\n : \"Unable to read package.json.\",\r\n path: \"package.json\",\r\n });\r\n }\r\n if (packageManifest) {\r\n for (const script of [\"check-types\", \"lint\", \"build\"] as const) {\r\n if (!packageManifest.scripts?.[script]) continue;\r\n try {\r\n await execFileAsync(\"pnpm\", [script], {\r\n cwd: options.repoRoot,\r\n env: process.env,\r\n timeout: FULL_COMMAND_TIMEOUT_MS,\r\n });\r\n } catch (error) {\r\n diagnostics.push({\r\n code: `COMMAND_${script.replace(\"-\", \"_\").toUpperCase()}_FAILED`,\r\n severity: \"error\",\r\n message: `${script} failed: ${error instanceof Error ? error.message : String(error)}`,\r\n path: \"package.json\",\r\n });\r\n }\r\n }\r\n }\r\n }\r\n\r\n return createDiagnosticReport(diagnostics);\r\n}\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAoBA,MAAM,iBAAA,GAAA,UAAA,WAA0BA,mBAAAA,SAAS;AACzC,MAAM,0BAA0B,MAAU;AAQ1C,eAAe,OAAO,UAAoC;AACxD,QAAOC,iBAAAA,QACJ,OAAO,SAAS,CAChB,WAAW,KAAK,CAChB,YAAY,MAAM;;AAGvB,eAAsB,oBAAoB,SAAmD;CAC3F,MAAM,cAA4B,EAAE;CACpC,IAAI,QAAQ,QAAQ;AACpB,KAAI,CAAC,MACH,KAAI;AACF,UAAQ,MAAMC,kBAAAA,iBAAiB,QAAQ,SAAS;UACzC,OAAO;AACd,cAAY,KAAK;GACf,MAAM;GACN,UAAU;GACV,SAAS,iBAAiB,QAAQ,MAAM,UAAU;GAClD,MAAM;GACN,YAAY;GACb,CAAC;AACF,SAAOC,wBAAAA,uBAAuB,YAAY;;CAI9C,MAAM,aAAaC,kBAAAA,eAAe;AAClC,KAAI,MAAM,SAAS,SAAA,cACjB,aAAY,KAAK;EACf,MAAM;EACN,UAAU;EACV,SAAS,8BAA8B,MAAM,SAAS;EACtD,MAAM;EACP,CAAC;AAEJ,KAAI,CAAC,OAAA,QAAO,MAAM,MAAM,SAAS,QAAQ,CACvC,aAAY,KAAK;EACf,MAAM;EACN,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W,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM;KACpF,MAAM;KACP,CAAC;;;;AAMV,QAAOE,wBAAAA,uBAAuB,YAAY"}
|
package/package.json
CHANGED
|
@@ -11,13 +11,13 @@
|
|
|
11
11
|
"test:e2e:expo": "playwright test --config playwright.expo.config.ts --headed"
|
|
12
12
|
},
|
|
13
13
|
"devDependencies": {
|
|
14
|
-
"@m5kdev/backend": "catalog:",
|
|
15
|
-
"@m5kdev/commons": "catalog:",
|
|
16
|
-
"@m5kdev/config": "catalog:",
|
|
17
|
-
"@playwright/test": "catalog:",
|
|
14
|
+
"@m5kdev/backend": "catalog:m5kdev",
|
|
15
|
+
"@m5kdev/commons": "catalog:m5kdev",
|
|
16
|
+
"@m5kdev/config": "catalog:m5kdev",
|
|
17
|
+
"@playwright/test": "catalog:m5kdev",
|
|
18
18
|
"{{PACKAGE_SCOPE}}/shared": "workspace:*",
|
|
19
|
-
"@trpc/client": "catalog:",
|
|
20
|
-
"@types/node": "catalog:",
|
|
21
|
-
"typescript": "catalog:"
|
|
19
|
+
"@trpc/client": "catalog:m5kdev",
|
|
20
|
+
"@types/node": "catalog:m5kdev",
|
|
21
|
+
"typescript": "catalog:m5kdev"
|
|
22
22
|
}
|
|
23
23
|
}
|
|
@@ -10,21 +10,21 @@
|
|
|
10
10
|
"email:dev": "react-email dev --dir src/emails"
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@m5kdev/commons": "catalog:",
|
|
14
|
-
"@m5kdev/email": "catalog:",
|
|
15
|
-
"@react-email/components": "catalog:",
|
|
16
|
-
"react": "catalog:",
|
|
17
|
-
"react-dom": "catalog:"
|
|
13
|
+
"@m5kdev/commons": "catalog:m5kdev",
|
|
14
|
+
"@m5kdev/email": "catalog:m5kdev",
|
|
15
|
+
"@react-email/components": "catalog:m5kdev",
|
|
16
|
+
"react": "catalog:m5kdev",
|
|
17
|
+
"react-dom": "catalog:m5kdev"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
|
-
"@m5kdev/backend": "catalog:",
|
|
21
|
-
"@m5kdev/config": "catalog:",
|
|
22
|
-
"@types/node": "catalog:",
|
|
23
|
-
"@types/react": "catalog:",
|
|
24
|
-
"@types/react-dom": "catalog:",
|
|
25
|
-
"react-email": "catalog:",
|
|
26
|
-
"tslib": "catalog:",
|
|
27
|
-
"typescript": "catalog:"
|
|
20
|
+
"@m5kdev/backend": "catalog:m5kdev",
|
|
21
|
+
"@m5kdev/config": "catalog:m5kdev",
|
|
22
|
+
"@types/node": "catalog:m5kdev",
|
|
23
|
+
"@types/react": "catalog:m5kdev",
|
|
24
|
+
"@types/react-dom": "catalog:m5kdev",
|
|
25
|
+
"react-email": "catalog:m5kdev",
|
|
26
|
+
"tslib": "catalog:m5kdev",
|
|
27
|
+
"typescript": "catalog:m5kdev"
|
|
28
28
|
},
|
|
29
29
|
"main": "./src/index.ts",
|
|
30
30
|
"exports": {
|
|
@@ -1,59 +1,59 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "{{PACKAGE_SCOPE}}/expo",
|
|
3
|
-
"version": "1.5.3",
|
|
4
|
-
"private": true,
|
|
5
|
-
"main": "expo-router/entry",
|
|
6
|
-
"scripts": {
|
|
7
|
-
"build": "expo export --platform web --output-dir dist",
|
|
8
|
-
"start": "expo start",
|
|
9
|
-
"dev:standard": "EXPO_PUBLIC_ENABLE_WAITLIST=false EXPO_PUBLIC_SERVER_URL=http://127.0.0.1:18182 EXPO_PUBLIC_APP_URL=http://127.0.0.1:15183 EXPO_NO_TELEMETRY=1 BROWSER=none expo start --web --port 15183 --host localhost",
|
|
10
|
-
"dev:waitlist": "EXPO_PUBLIC_ENABLE_WAITLIST=true EXPO_PUBLIC_SERVER_URL=http://127.0.0.1:18183 EXPO_PUBLIC_APP_URL=http://127.0.0.1:15184 EXPO_NO_TELEMETRY=1 BROWSER=none expo start --web --port 15184 --host localhost",
|
|
11
|
-
"android": "expo start --android",
|
|
12
|
-
"ios": "expo start --ios",
|
|
13
|
-
"lint": "biome check app.json package.json metro.config.js eslint.config.js src tsconfig.json uniwind-env.d.ts",
|
|
14
|
-
"lint:fix": "biome check app.json package.json metro.config.js eslint.config.js src tsconfig.json uniwind-env.d.ts --write",
|
|
15
|
-
"format": "prettier --write .",
|
|
16
|
-
"format:check": "prettier --check .",
|
|
17
|
-
"check-types": "tsc --noEmit",
|
|
18
|
-
"typecheck": "pnpm check-types"
|
|
19
|
-
},
|
|
20
|
-
"dependencies": {
|
|
21
|
-
"@expo/metro-runtime": "~56.0.13",
|
|
22
|
-
"@gorhom/bottom-sheet": "^5.2.14",
|
|
23
|
-
"@m5kdev/commons": "catalog:",
|
|
24
|
-
"@m5kdev/frontend": "catalog:",
|
|
25
|
-
"@trpc/client": "catalog:",
|
|
26
|
-
"expo": "~56.0.5",
|
|
27
|
-
"expo-constants": "~56.0.16",
|
|
28
|
-
"expo-linking": "~56.0.12",
|
|
29
|
-
"expo-router": "~56.2.7",
|
|
30
|
-
"expo-splash-screen": "~56.0.10",
|
|
31
|
-
"expo-status-bar": "~56.0.4",
|
|
32
|
-
"heroui-native": "^1.0.2",
|
|
33
|
-
"{{PACKAGE_SCOPE}}/shared": "workspace:*",
|
|
34
|
-
"react": "
|
|
35
|
-
"react-dom": "
|
|
36
|
-
"react-native": "0.85.3",
|
|
37
|
-
"react-native-gesture-handler": "~2.31.2",
|
|
38
|
-
"react-native-reanimated": "~4.3.1",
|
|
39
|
-
"react-native-safe-area-context": "~5.7.0",
|
|
40
|
-
"react-native-screens": "~4.25.2",
|
|
41
|
-
"react-native-svg": "15.15.4",
|
|
42
|
-
"react-native-web": "catalog:",
|
|
43
|
-
"react-native-worklets": "0.8.3",
|
|
44
|
-
"tailwind-merge": "
|
|
45
|
-
"tailwind-variants": "^3.2.2",
|
|
46
|
-
"tailwindcss": "
|
|
47
|
-
"uniwind": "^1.5.0"
|
|
48
|
-
},
|
|
49
|
-
"devDependencies": {
|
|
50
|
-
"@biomejs/biome": "catalog:",
|
|
51
|
-
"@m5kdev/backend": "catalog:",
|
|
52
|
-
"@m5kdev/config": "catalog:",
|
|
53
|
-
"@types/react": "
|
|
54
|
-
"eslint": "^9.39.4",
|
|
55
|
-
"eslint-config-expo": "^56.0.4",
|
|
56
|
-
"prettier": "^3.8.3",
|
|
57
|
-
"typescript": "
|
|
58
|
-
}
|
|
59
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "{{PACKAGE_SCOPE}}/expo",
|
|
3
|
+
"version": "1.5.3",
|
|
4
|
+
"private": true,
|
|
5
|
+
"main": "expo-router/entry",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"build": "expo export --platform web --output-dir dist",
|
|
8
|
+
"start": "expo start",
|
|
9
|
+
"dev:standard": "EXPO_PUBLIC_ENABLE_WAITLIST=false EXPO_PUBLIC_SERVER_URL=http://127.0.0.1:18182 EXPO_PUBLIC_APP_URL=http://127.0.0.1:15183 EXPO_NO_TELEMETRY=1 BROWSER=none expo start --web --port 15183 --host localhost",
|
|
10
|
+
"dev:waitlist": "EXPO_PUBLIC_ENABLE_WAITLIST=true EXPO_PUBLIC_SERVER_URL=http://127.0.0.1:18183 EXPO_PUBLIC_APP_URL=http://127.0.0.1:15184 EXPO_NO_TELEMETRY=1 BROWSER=none expo start --web --port 15184 --host localhost",
|
|
11
|
+
"android": "expo start --android",
|
|
12
|
+
"ios": "expo start --ios",
|
|
13
|
+
"lint": "biome check app.json package.json metro.config.js eslint.config.js src tsconfig.json uniwind-env.d.ts",
|
|
14
|
+
"lint:fix": "biome check app.json package.json metro.config.js eslint.config.js src tsconfig.json uniwind-env.d.ts --write",
|
|
15
|
+
"format": "prettier --write .",
|
|
16
|
+
"format:check": "prettier --check .",
|
|
17
|
+
"check-types": "tsc --noEmit",
|
|
18
|
+
"typecheck": "pnpm check-types"
|
|
19
|
+
},
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"@expo/metro-runtime": "~56.0.13",
|
|
22
|
+
"@gorhom/bottom-sheet": "^5.2.14",
|
|
23
|
+
"@m5kdev/commons": "catalog:m5kdev",
|
|
24
|
+
"@m5kdev/frontend": "catalog:m5kdev",
|
|
25
|
+
"@trpc/client": "catalog:m5kdev",
|
|
26
|
+
"expo": "~56.0.5",
|
|
27
|
+
"expo-constants": "~56.0.16",
|
|
28
|
+
"expo-linking": "~56.0.12",
|
|
29
|
+
"expo-router": "~56.2.7",
|
|
30
|
+
"expo-splash-screen": "~56.0.10",
|
|
31
|
+
"expo-status-bar": "~56.0.4",
|
|
32
|
+
"heroui-native": "^1.0.2",
|
|
33
|
+
"{{PACKAGE_SCOPE}}/shared": "workspace:*",
|
|
34
|
+
"react": "catalog:m5kdev",
|
|
35
|
+
"react-dom": "catalog:m5kdev",
|
|
36
|
+
"react-native": "0.85.3",
|
|
37
|
+
"react-native-gesture-handler": "~2.31.2",
|
|
38
|
+
"react-native-reanimated": "~4.3.1",
|
|
39
|
+
"react-native-safe-area-context": "~5.7.0",
|
|
40
|
+
"react-native-screens": "~4.25.2",
|
|
41
|
+
"react-native-svg": "15.15.4",
|
|
42
|
+
"react-native-web": "catalog:m5kdev",
|
|
43
|
+
"react-native-worklets": "0.8.3",
|
|
44
|
+
"tailwind-merge": "catalog:m5kdev",
|
|
45
|
+
"tailwind-variants": "^3.2.2",
|
|
46
|
+
"tailwindcss": "catalog:m5kdev",
|
|
47
|
+
"uniwind": "^1.5.0"
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"@biomejs/biome": "catalog:m5kdev",
|
|
51
|
+
"@m5kdev/backend": "catalog:m5kdev",
|
|
52
|
+
"@m5kdev/config": "catalog:m5kdev",
|
|
53
|
+
"@types/react": "catalog:m5kdev",
|
|
54
|
+
"eslint": "^9.39.4",
|
|
55
|
+
"eslint-config-expo": "^56.0.4",
|
|
56
|
+
"prettier": "^3.8.3",
|
|
57
|
+
"typescript": "catalog:m5kdev"
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -28,7 +28,7 @@ apps/server/src/modules/<module>/
|
|
|
28
28
|
- Repositories own persistence and query construction.
|
|
29
29
|
- Services own business rules, orchestration, and context-aware defaults.
|
|
30
30
|
- tRPC files own transport only and must delegate to services.
|
|
31
|
-
- Register modules in `apps/server/src/app.ts`; use `db.ts`
|
|
31
|
+
- Register modules in `apps/server/src/app.ts`; use `db.ts` only for scripts that need direct DB.
|
|
32
32
|
|
|
33
33
|
## Avoid Trivial Service Delegation
|
|
34
34
|
|
|
@@ -40,7 +40,7 @@ apps/server/src/modules/<module>/
|
|
|
40
40
|
## Workflow, Redis, and push notifications
|
|
41
41
|
|
|
42
42
|
- `WorkflowModule` and `NotificationModule` are registered in `app.ts`. Start **Redis** locally (`REDIS_URL`) before `pnpm dev` on the server, or background jobs will not run.
|
|
43
|
-
- `index.ts` calls `builtBackendApp.start()
|
|
43
|
+
- `index.ts` calls `builtBackendApp.start()`, which listens and handles SIGINT/SIGTERM. Extra shutdown work (telemetry) is `onShutdown` on `createBackendApp`.
|
|
44
44
|
- After changing Drizzle tables, run `pnpm --filter ./apps/server sync` — do not hand-edit SQL migrations in this repo.
|
|
45
45
|
|
|
46
46
|
Push-related server env vars are documented in `apps/shared/.env.example`.
|