@prisma/compute-sdk 0.38.0 → 0.40.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +27 -20
- package/dist/config/detect-app.d.ts +4 -0
- package/dist/config/detect-app.d.ts.map +1 -1
- package/dist/config/detect-app.js +27 -8
- package/dist/config/detect-app.js.map +1 -1
- package/dist/config/detect-directory.d.ts +14 -0
- package/dist/config/detect-directory.d.ts.map +1 -0
- package/dist/config/detect-directory.js +80 -0
- package/dist/config/detect-directory.js.map +1 -0
- package/dist/config/detect-repository.d.ts +61 -0
- package/dist/config/detect-repository.d.ts.map +1 -0
- package/dist/config/detect-repository.js +503 -0
- package/dist/config/detect-repository.js.map +1 -0
- package/dist/config/index.d.ts +1 -0
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/index.js +1 -0
- package/dist/config/index.js.map +1 -1
- package/package.json +12 -2
- package/src/config/detect-app.ts +38 -8
- package/src/config/detect-directory.ts +112 -0
- package/src/config/detect-repository.ts +720 -0
- package/src/config/index.ts +7 -0
|
@@ -0,0 +1,720 @@
|
|
|
1
|
+
import picomatch from "picomatch";
|
|
2
|
+
import { parse as parseYaml } from "yaml";
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
type ComputeAppManifest,
|
|
6
|
+
type DetectedComputeApp,
|
|
7
|
+
detectComputeApp,
|
|
8
|
+
} from "./detect-app.ts";
|
|
9
|
+
import { type FrameworkBuildType, frameworkByKey } from "./frameworks.ts";
|
|
10
|
+
import type { ComputeFramework } from "./types.ts";
|
|
11
|
+
|
|
12
|
+
const MAX_PACKAGE_MANIFESTS = 80;
|
|
13
|
+
const PACKAGE_FETCH_BATCH_SIZE = 10;
|
|
14
|
+
const IGNORED_PATH_SEGMENTS = new Set([
|
|
15
|
+
".git",
|
|
16
|
+
".next",
|
|
17
|
+
".output",
|
|
18
|
+
"build",
|
|
19
|
+
"dist",
|
|
20
|
+
"node_modules",
|
|
21
|
+
"vendor",
|
|
22
|
+
]);
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Lockfile filenames in precedence order, paired with their package manager.
|
|
26
|
+
* bun.lock (text format, Bun 1.1+) is checked before bun.lockb (binary).
|
|
27
|
+
*/
|
|
28
|
+
const LOCKFILE_ENTRIES = [
|
|
29
|
+
["bun.lock", "bun"],
|
|
30
|
+
["bun.lockb", "bun"],
|
|
31
|
+
["pnpm-lock.yaml", "pnpm"],
|
|
32
|
+
["yarn.lock", "yarn"],
|
|
33
|
+
["package-lock.json", "npm"],
|
|
34
|
+
] as const satisfies ReadonlyArray<[string, "npm" | "pnpm" | "yarn" | "bun"]>;
|
|
35
|
+
|
|
36
|
+
interface ParsedManifest {
|
|
37
|
+
path: string;
|
|
38
|
+
root: string;
|
|
39
|
+
value: ComputeAppManifest;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface DetectComputeRepositoryInput {
|
|
43
|
+
repositoryName: string;
|
|
44
|
+
filePaths: Iterable<string>;
|
|
45
|
+
readFile: (path: string) => Promise<string | null>;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** Package manager detected for the repository root. */
|
|
49
|
+
export interface DetectedPackageManager {
|
|
50
|
+
/** Package manager name. */
|
|
51
|
+
name: "npm" | "pnpm" | "yarn" | "bun";
|
|
52
|
+
/**
|
|
53
|
+
* Lockfile found at the repository root.
|
|
54
|
+
* null when the package manager was resolved from the packageManager field
|
|
55
|
+
* alone and no lockfile was present.
|
|
56
|
+
*/
|
|
57
|
+
lockfile: string | null;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export interface DetectedComputeRepositoryApp {
|
|
61
|
+
id: string;
|
|
62
|
+
target: string;
|
|
63
|
+
name: string;
|
|
64
|
+
root: string;
|
|
65
|
+
framework: ComputeFramework;
|
|
66
|
+
frameworkName: string;
|
|
67
|
+
httpPort: number;
|
|
68
|
+
entry: string;
|
|
69
|
+
build: {
|
|
70
|
+
command: string | null;
|
|
71
|
+
outputDirectory: string;
|
|
72
|
+
entrypoint: string;
|
|
73
|
+
};
|
|
74
|
+
inferredFrom: string[];
|
|
75
|
+
reviewRequired: boolean;
|
|
76
|
+
/**
|
|
77
|
+
* Prisma Next usage for this app. "Prisma" here means Prisma Next (Prisma 8+),
|
|
78
|
+
* the engine-less, @prisma-next/-scoped client. Earlier Prisma clients
|
|
79
|
+
* (@prisma/client, prisma-client-js) are not part of this system's vocabulary
|
|
80
|
+
* and are not detected.
|
|
81
|
+
*/
|
|
82
|
+
prismaNext: {
|
|
83
|
+
/** True when a Prisma Next config file or a @prisma-next/* package was found. */
|
|
84
|
+
detected: boolean;
|
|
85
|
+
/** Signal that triggered detection, or empty when detected is false. */
|
|
86
|
+
inferredFrom: string[];
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export interface DetectComputeRepositoryResult {
|
|
91
|
+
apps: DetectedComputeRepositoryApp[];
|
|
92
|
+
warnings: string[];
|
|
93
|
+
/**
|
|
94
|
+
* Package manager detected from the repository root's packageManager field
|
|
95
|
+
* and lockfile. null when neither signal is present.
|
|
96
|
+
*/
|
|
97
|
+
packageManager: DetectedPackageManager | null;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Detects every deployable app in a remote repository snapshot, including
|
|
102
|
+
* workspace discovery, root-app ownership, and inferred build settings.
|
|
103
|
+
*/
|
|
104
|
+
export async function detectComputeRepository(
|
|
105
|
+
input: DetectComputeRepositoryInput,
|
|
106
|
+
): Promise<DetectComputeRepositoryResult> {
|
|
107
|
+
const filePaths = new Set(input.filePaths);
|
|
108
|
+
const warnings: string[] = [];
|
|
109
|
+
const manifestPaths = [...filePaths]
|
|
110
|
+
.filter(
|
|
111
|
+
(path) =>
|
|
112
|
+
(path === "package.json" || path.endsWith("/package.json")) &&
|
|
113
|
+
!path.split("/").some((segment) => IGNORED_PATH_SEGMENTS.has(segment)),
|
|
114
|
+
)
|
|
115
|
+
.sort((a, b) => pathDepth(a) - pathDepth(b) || a.localeCompare(b));
|
|
116
|
+
|
|
117
|
+
if (manifestPaths.length > MAX_PACKAGE_MANIFESTS) {
|
|
118
|
+
warnings.push(
|
|
119
|
+
`Only the first ${MAX_PACKAGE_MANIFESTS} package manifests were inspected.`,
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const manifests: ParsedManifest[] = [];
|
|
124
|
+
for (
|
|
125
|
+
let offset = 0;
|
|
126
|
+
offset < Math.min(manifestPaths.length, MAX_PACKAGE_MANIFESTS);
|
|
127
|
+
offset += PACKAGE_FETCH_BATCH_SIZE
|
|
128
|
+
) {
|
|
129
|
+
const batch = manifestPaths.slice(
|
|
130
|
+
offset,
|
|
131
|
+
offset + PACKAGE_FETCH_BATCH_SIZE,
|
|
132
|
+
);
|
|
133
|
+
const fetched = await Promise.all(
|
|
134
|
+
batch.map(async (path) => {
|
|
135
|
+
try {
|
|
136
|
+
return { path, content: await input.readFile(path) };
|
|
137
|
+
} catch {
|
|
138
|
+
warnings.push(`Skipped unreadable ${path}.`);
|
|
139
|
+
return { path, content: undefined };
|
|
140
|
+
}
|
|
141
|
+
}),
|
|
142
|
+
);
|
|
143
|
+
|
|
144
|
+
for (const item of fetched) {
|
|
145
|
+
if (item.content === undefined) continue;
|
|
146
|
+
if (item.content === null) {
|
|
147
|
+
warnings.push(`Skipped unavailable ${item.path}.`);
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
try {
|
|
151
|
+
const value: unknown = JSON.parse(item.content);
|
|
152
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
153
|
+
warnings.push(`Skipped invalid package manifest in ${item.path}.`);
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
manifests.push({
|
|
157
|
+
path: item.path,
|
|
158
|
+
root: directoryName(item.path),
|
|
159
|
+
value: value as ComputeAppManifest,
|
|
160
|
+
});
|
|
161
|
+
} catch {
|
|
162
|
+
warnings.push(`Skipped invalid JSON in ${item.path}.`);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const rootManifest = manifests.find((manifest) => manifest.root === "");
|
|
168
|
+
const workspacePatterns = await readWorkspacePatterns({
|
|
169
|
+
input,
|
|
170
|
+
filePaths,
|
|
171
|
+
rootManifest,
|
|
172
|
+
warnings,
|
|
173
|
+
});
|
|
174
|
+
const candidateManifests = manifests.filter(
|
|
175
|
+
(manifest) =>
|
|
176
|
+
manifest.root === "" ||
|
|
177
|
+
workspacePatterns.length === 0 ||
|
|
178
|
+
matchesWorkspace(manifest.root, workspacePatterns),
|
|
179
|
+
);
|
|
180
|
+
const allDetected = candidateManifests
|
|
181
|
+
.map((manifest) => {
|
|
182
|
+
const detectedApp = detectComputeApp({
|
|
183
|
+
root: manifest.root,
|
|
184
|
+
manifest: manifest.value,
|
|
185
|
+
filePaths,
|
|
186
|
+
});
|
|
187
|
+
return detectedApp ? { manifest, detectedApp } : null;
|
|
188
|
+
})
|
|
189
|
+
.filter((item): item is NonNullable<typeof item> => item !== null);
|
|
190
|
+
const nestedDetected = allDetected.filter(
|
|
191
|
+
(item) => item.manifest.root !== "",
|
|
192
|
+
);
|
|
193
|
+
const nestedAppRoots = nestedDetected.map((item) => item.manifest.root);
|
|
194
|
+
const detected = allDetected.filter(
|
|
195
|
+
(item) =>
|
|
196
|
+
item.manifest.root !== "" ||
|
|
197
|
+
nestedDetected.length === 0 ||
|
|
198
|
+
hasDistinctRootAppSignal(
|
|
199
|
+
item.manifest,
|
|
200
|
+
item.detectedApp,
|
|
201
|
+
filePaths,
|
|
202
|
+
nestedAppRoots,
|
|
203
|
+
),
|
|
204
|
+
);
|
|
205
|
+
|
|
206
|
+
if (detected.length !== allDetected.length) {
|
|
207
|
+
warnings.push(
|
|
208
|
+
"The root package did not identify an application distinct from the detected workspace apps, so it was not added as a separate deploy target.",
|
|
209
|
+
);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
const selected =
|
|
213
|
+
detected.length > 0
|
|
214
|
+
? detected
|
|
215
|
+
: [
|
|
216
|
+
{
|
|
217
|
+
manifest: rootManifest ??
|
|
218
|
+
candidateManifests[0] ?? {
|
|
219
|
+
path: "package.json",
|
|
220
|
+
root: "",
|
|
221
|
+
value: {},
|
|
222
|
+
},
|
|
223
|
+
detectedApp: null,
|
|
224
|
+
},
|
|
225
|
+
];
|
|
226
|
+
|
|
227
|
+
if (detected.length === 0) {
|
|
228
|
+
warnings.push(
|
|
229
|
+
"No supported framework signal was found. Review the Bun entrypoint and build settings.",
|
|
230
|
+
);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
const apps = selected.map((item) =>
|
|
234
|
+
inferApp({
|
|
235
|
+
repositoryName: input.repositoryName,
|
|
236
|
+
filePaths,
|
|
237
|
+
rootManifest,
|
|
238
|
+
manifest: item.manifest,
|
|
239
|
+
detectedApp: item.detectedApp,
|
|
240
|
+
}),
|
|
241
|
+
);
|
|
242
|
+
uniquifyTargets(apps);
|
|
243
|
+
|
|
244
|
+
const packageManager = detectRepoPackageManager({
|
|
245
|
+
rootManifest,
|
|
246
|
+
filePaths,
|
|
247
|
+
warnings,
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
return { apps, warnings, packageManager };
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
async function readWorkspacePatterns(args: {
|
|
254
|
+
input: DetectComputeRepositoryInput;
|
|
255
|
+
filePaths: Set<string>;
|
|
256
|
+
rootManifest: ParsedManifest | undefined;
|
|
257
|
+
warnings: string[];
|
|
258
|
+
}): Promise<string[]> {
|
|
259
|
+
const fromPackageJson = workspacePatternsFromPackageJson(
|
|
260
|
+
args.rootManifest?.value.workspaces,
|
|
261
|
+
);
|
|
262
|
+
if (!args.filePaths.has("pnpm-workspace.yaml")) {
|
|
263
|
+
return fromPackageJson;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
let content: string | null;
|
|
267
|
+
try {
|
|
268
|
+
content = await args.input.readFile("pnpm-workspace.yaml");
|
|
269
|
+
} catch {
|
|
270
|
+
args.warnings.push("Skipped unreadable pnpm-workspace.yaml.");
|
|
271
|
+
return fromPackageJson;
|
|
272
|
+
}
|
|
273
|
+
if (content === null) return fromPackageJson;
|
|
274
|
+
|
|
275
|
+
try {
|
|
276
|
+
const parsed = parseYaml(content) as { packages?: unknown } | null;
|
|
277
|
+
const fromPnpm = Array.isArray(parsed?.packages)
|
|
278
|
+
? parsed.packages.filter(
|
|
279
|
+
(value): value is string => typeof value === "string",
|
|
280
|
+
)
|
|
281
|
+
: [];
|
|
282
|
+
return [...new Set([...fromPackageJson, ...fromPnpm])];
|
|
283
|
+
} catch {
|
|
284
|
+
args.warnings.push("Skipped invalid YAML in pnpm-workspace.yaml.");
|
|
285
|
+
return fromPackageJson;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
function workspacePatternsFromPackageJson(workspaces: unknown): string[] {
|
|
290
|
+
if (Array.isArray(workspaces)) {
|
|
291
|
+
return workspaces.filter(
|
|
292
|
+
(value): value is string => typeof value === "string",
|
|
293
|
+
);
|
|
294
|
+
}
|
|
295
|
+
if (
|
|
296
|
+
workspaces &&
|
|
297
|
+
typeof workspaces === "object" &&
|
|
298
|
+
"packages" in workspaces &&
|
|
299
|
+
Array.isArray(workspaces.packages)
|
|
300
|
+
) {
|
|
301
|
+
return workspaces.packages.filter(
|
|
302
|
+
(value): value is string => typeof value === "string",
|
|
303
|
+
);
|
|
304
|
+
}
|
|
305
|
+
return [];
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
function matchesWorkspace(root: string, patterns: string[]): boolean {
|
|
309
|
+
const included = patterns
|
|
310
|
+
.filter((pattern) => !pattern.startsWith("!"))
|
|
311
|
+
.some((pattern) => picomatch(pattern, { dot: true })(root));
|
|
312
|
+
const excluded = patterns
|
|
313
|
+
.filter((pattern) => pattern.startsWith("!"))
|
|
314
|
+
.some((pattern) => picomatch(pattern.slice(1), { dot: true })(root));
|
|
315
|
+
return included && !excluded;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
function hasDistinctRootAppSignal(
|
|
319
|
+
manifest: ParsedManifest,
|
|
320
|
+
detectedApp: DetectedComputeApp,
|
|
321
|
+
filePaths: Set<string>,
|
|
322
|
+
nestedAppRoots: string[],
|
|
323
|
+
): boolean {
|
|
324
|
+
const descriptor = frameworkByKey(detectedApp.framework);
|
|
325
|
+
if (
|
|
326
|
+
descriptor.detectConfigFiles.some((fileName) => filePaths.has(fileName))
|
|
327
|
+
) {
|
|
328
|
+
return true;
|
|
329
|
+
}
|
|
330
|
+
const entrypoint = detectedApp.entrypoint;
|
|
331
|
+
if (
|
|
332
|
+
entrypoint &&
|
|
333
|
+
!nestedAppRoots.some((root) => isPathInside(entrypoint, root))
|
|
334
|
+
) {
|
|
335
|
+
return true;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
const sourcePaths = [...filePaths].filter(
|
|
339
|
+
(path) => !nestedAppRoots.some((root) => isPathInside(path, root)),
|
|
340
|
+
);
|
|
341
|
+
switch (detectedApp.buildType) {
|
|
342
|
+
case "nextjs":
|
|
343
|
+
if (
|
|
344
|
+
sourcePaths.some((path) =>
|
|
345
|
+
["app/", "pages/", "src/app/", "src/pages/"].some((prefix) =>
|
|
346
|
+
path.startsWith(prefix),
|
|
347
|
+
),
|
|
348
|
+
)
|
|
349
|
+
) {
|
|
350
|
+
return true;
|
|
351
|
+
}
|
|
352
|
+
break;
|
|
353
|
+
case "nuxt":
|
|
354
|
+
if (
|
|
355
|
+
filePaths.has("app.vue") ||
|
|
356
|
+
sourcePaths.some(
|
|
357
|
+
(path) => path.startsWith("pages/") || path.startsWith("server/"),
|
|
358
|
+
)
|
|
359
|
+
) {
|
|
360
|
+
return true;
|
|
361
|
+
}
|
|
362
|
+
break;
|
|
363
|
+
case "astro":
|
|
364
|
+
if (sourcePaths.some((path) => path.startsWith("src/pages/"))) {
|
|
365
|
+
return true;
|
|
366
|
+
}
|
|
367
|
+
break;
|
|
368
|
+
case "nestjs":
|
|
369
|
+
if (filePaths.has("src/main.ts") || filePaths.has("src/main.js")) {
|
|
370
|
+
return true;
|
|
371
|
+
}
|
|
372
|
+
break;
|
|
373
|
+
case "tanstack-start":
|
|
374
|
+
if (
|
|
375
|
+
sourcePaths.some(
|
|
376
|
+
(path) =>
|
|
377
|
+
path.startsWith("app/routes/") || path.startsWith("src/routes/"),
|
|
378
|
+
)
|
|
379
|
+
) {
|
|
380
|
+
return true;
|
|
381
|
+
}
|
|
382
|
+
break;
|
|
383
|
+
case "custom":
|
|
384
|
+
case "bun":
|
|
385
|
+
break;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
const buildScript = readBuildScript(manifest.value.scripts);
|
|
389
|
+
if (!buildScript) return false;
|
|
390
|
+
switch (detectedApp.buildType) {
|
|
391
|
+
case "nextjs":
|
|
392
|
+
return /(^|\s)next\s+build(?:\s|$)/.test(buildScript);
|
|
393
|
+
case "nuxt":
|
|
394
|
+
return /(^|\s)(?:nuxt|nuxi)\s+build(?:\s|$)/.test(buildScript);
|
|
395
|
+
case "astro":
|
|
396
|
+
return /(^|\s)astro\s+build(?:\s|$)/.test(buildScript);
|
|
397
|
+
case "nestjs":
|
|
398
|
+
return /(^|\s)nest\s+build(?:\s|$)/.test(buildScript);
|
|
399
|
+
case "tanstack-start":
|
|
400
|
+
return /(^|\s)vite\s+build(?:\s|$)/.test(buildScript);
|
|
401
|
+
case "custom":
|
|
402
|
+
case "bun":
|
|
403
|
+
return false;
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
function inferApp(args: {
|
|
408
|
+
repositoryName: string;
|
|
409
|
+
filePaths: Set<string>;
|
|
410
|
+
rootManifest: ParsedManifest | undefined;
|
|
411
|
+
manifest: ParsedManifest;
|
|
412
|
+
detectedApp: DetectedComputeApp | null;
|
|
413
|
+
}): DetectedComputeRepositoryApp {
|
|
414
|
+
const packageName =
|
|
415
|
+
typeof args.manifest.value.name === "string"
|
|
416
|
+
? args.manifest.value.name
|
|
417
|
+
: undefined;
|
|
418
|
+
const target = normalizeTarget(
|
|
419
|
+
packageName ?? lastPathSegment(args.manifest.root) ?? args.repositoryName,
|
|
420
|
+
);
|
|
421
|
+
const buildScript = readBuildScript(args.manifest.value.scripts);
|
|
422
|
+
const packageManager = resolveRemotePackageManager({
|
|
423
|
+
manifest: args.manifest,
|
|
424
|
+
rootManifest: args.rootManifest,
|
|
425
|
+
filePaths: args.filePaths,
|
|
426
|
+
});
|
|
427
|
+
const descriptor = frameworkByKey(args.detectedApp?.framework ?? "bun");
|
|
428
|
+
const inferredBuild = inferBuildSettings({
|
|
429
|
+
buildType: args.detectedApp?.buildType ?? descriptor.buildType,
|
|
430
|
+
buildScript,
|
|
431
|
+
packageManager,
|
|
432
|
+
});
|
|
433
|
+
const entry = args.detectedApp?.entrypoint ?? "";
|
|
434
|
+
const detectionSource =
|
|
435
|
+
args.detectedApp?.evidence.kind === "dependency"
|
|
436
|
+
? `${args.detectedApp.evidence.path} dependency ${args.detectedApp.evidence.value}`
|
|
437
|
+
: (args.detectedApp?.evidence.path ?? "Bun fallback");
|
|
438
|
+
|
|
439
|
+
return {
|
|
440
|
+
id: args.manifest.root || "root",
|
|
441
|
+
target,
|
|
442
|
+
name: target,
|
|
443
|
+
root: args.manifest.root ? `./${args.manifest.root}` : "./",
|
|
444
|
+
framework: descriptor.key,
|
|
445
|
+
frameworkName: descriptor.displayName,
|
|
446
|
+
httpPort: descriptor.defaultHttpPort,
|
|
447
|
+
entry,
|
|
448
|
+
build: {
|
|
449
|
+
command: inferredBuild.command,
|
|
450
|
+
outputDirectory: inferredBuild.outputDirectory,
|
|
451
|
+
entrypoint: inferredBuild.entrypoint,
|
|
452
|
+
},
|
|
453
|
+
inferredFrom: [
|
|
454
|
+
detectionSource,
|
|
455
|
+
buildScript
|
|
456
|
+
? `${args.manifest.path} scripts.build`
|
|
457
|
+
: inferredBuild.source,
|
|
458
|
+
].filter((value, index, values) => values.indexOf(value) === index),
|
|
459
|
+
reviewRequired:
|
|
460
|
+
args.detectedApp === null || (descriptor.usesEntrypoint && !entry),
|
|
461
|
+
prismaNext: detectAppPrismaNext({
|
|
462
|
+
manifest: args.manifest.value,
|
|
463
|
+
root: args.manifest.root,
|
|
464
|
+
filePaths: args.filePaths,
|
|
465
|
+
}),
|
|
466
|
+
};
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
/**
|
|
470
|
+
* Detects the package manager declared at the repository root.
|
|
471
|
+
* Reads the root packageManager field and lockfiles; warns on conflict.
|
|
472
|
+
*/
|
|
473
|
+
function detectRepoPackageManager(args: {
|
|
474
|
+
rootManifest: ParsedManifest | undefined;
|
|
475
|
+
filePaths: Set<string>;
|
|
476
|
+
warnings: string[];
|
|
477
|
+
}): DetectedPackageManager | null {
|
|
478
|
+
const nameFromField = packageManagerFromField(
|
|
479
|
+
args.rootManifest?.value.packageManager,
|
|
480
|
+
);
|
|
481
|
+
|
|
482
|
+
let lockfile: string | null = null;
|
|
483
|
+
let nameFromLockfile: "npm" | "pnpm" | "yarn" | "bun" | null = null;
|
|
484
|
+
for (const [file, name] of LOCKFILE_ENTRIES) {
|
|
485
|
+
if (args.filePaths.has(file)) {
|
|
486
|
+
lockfile = file;
|
|
487
|
+
nameFromLockfile = name;
|
|
488
|
+
break;
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
if (nameFromField) {
|
|
493
|
+
if (nameFromLockfile && nameFromField !== nameFromLockfile) {
|
|
494
|
+
args.warnings.push(
|
|
495
|
+
`The packageManager field declares "${nameFromField}" but lockfile "${lockfile}" belongs to "${nameFromLockfile}". Using the packageManager field.`,
|
|
496
|
+
);
|
|
497
|
+
}
|
|
498
|
+
return { name: nameFromField, lockfile };
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
if (nameFromLockfile) {
|
|
502
|
+
return { name: nameFromLockfile, lockfile };
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
return null;
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
/**
|
|
509
|
+
* Detects Prisma Next usage for one app.
|
|
510
|
+
*
|
|
511
|
+
* Signals checked (in order):
|
|
512
|
+
* 1. prisma-next.config.ts at the app root — the definitive Prisma Next config file.
|
|
513
|
+
* 2. Any @prisma-next/* scoped package in dependencies or devDependencies.
|
|
514
|
+
* 3. The prisma-next bare package (CLI tool) in devDependencies.
|
|
515
|
+
*
|
|
516
|
+
* Earlier Prisma clients (@prisma/client, prisma) are not part of this system
|
|
517
|
+
* and are deliberately ignored here.
|
|
518
|
+
*/
|
|
519
|
+
function detectAppPrismaNext(args: {
|
|
520
|
+
manifest: ComputeAppManifest;
|
|
521
|
+
root: string;
|
|
522
|
+
filePaths: Set<string>;
|
|
523
|
+
}): DetectedComputeRepositoryApp["prismaNext"] {
|
|
524
|
+
// Config file is the strongest single-file signal.
|
|
525
|
+
const configFile = joinRepoPath(args.root, "prisma-next.config.ts");
|
|
526
|
+
if (args.filePaths.has(configFile)) {
|
|
527
|
+
return { detected: true, inferredFrom: [configFile] };
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
// Any @prisma-next/* scoped package or the bare prisma-next CLI.
|
|
531
|
+
const deps = asRecord(args.manifest.dependencies);
|
|
532
|
+
const devDeps = asRecord(args.manifest.devDependencies);
|
|
533
|
+
const manifestPath = joinRepoPath(args.root, "package.json");
|
|
534
|
+
|
|
535
|
+
for (const name of [...Object.keys(deps), ...Object.keys(devDeps)]) {
|
|
536
|
+
if (name === "prisma-next" || name.startsWith("@prisma-next/")) {
|
|
537
|
+
return {
|
|
538
|
+
detected: true,
|
|
539
|
+
inferredFrom: [`${manifestPath} dependency ${name}`],
|
|
540
|
+
};
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
return { detected: false, inferredFrom: [] };
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
/** Coerces an unknown value to a string-keyed record, returning {} for non-objects. */
|
|
548
|
+
function asRecord(value: unknown): Record<string, unknown> {
|
|
549
|
+
return value && typeof value === "object" && !Array.isArray(value)
|
|
550
|
+
? (value as Record<string, unknown>)
|
|
551
|
+
: {};
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
function inferBuildSettings(args: {
|
|
555
|
+
buildType: FrameworkBuildType;
|
|
556
|
+
buildScript: string | null;
|
|
557
|
+
packageManager: string | null;
|
|
558
|
+
}): DetectedComputeRepositoryApp["build"] & { source: string } {
|
|
559
|
+
const scriptCommand = args.buildScript
|
|
560
|
+
? args.packageManager
|
|
561
|
+
? `${args.packageManager} run build`
|
|
562
|
+
: args.buildScript
|
|
563
|
+
: null;
|
|
564
|
+
switch (args.buildType) {
|
|
565
|
+
case "nextjs":
|
|
566
|
+
return {
|
|
567
|
+
command: scriptCommand ?? "next build",
|
|
568
|
+
outputDirectory: "",
|
|
569
|
+
entrypoint: "",
|
|
570
|
+
source: "Next.js build strategy",
|
|
571
|
+
};
|
|
572
|
+
case "nuxt":
|
|
573
|
+
return {
|
|
574
|
+
command: scriptCommand ?? "nuxt build",
|
|
575
|
+
outputDirectory: ".output",
|
|
576
|
+
entrypoint: "",
|
|
577
|
+
source: "Nuxt defaults",
|
|
578
|
+
};
|
|
579
|
+
case "astro":
|
|
580
|
+
return {
|
|
581
|
+
command: scriptCommand ?? "astro build",
|
|
582
|
+
outputDirectory: "dist",
|
|
583
|
+
entrypoint: "",
|
|
584
|
+
source: "Astro defaults",
|
|
585
|
+
};
|
|
586
|
+
case "nestjs":
|
|
587
|
+
return {
|
|
588
|
+
command: scriptCommand ?? "nest build",
|
|
589
|
+
outputDirectory: "dist",
|
|
590
|
+
entrypoint: "",
|
|
591
|
+
source: "NestJS defaults",
|
|
592
|
+
};
|
|
593
|
+
case "tanstack-start":
|
|
594
|
+
return {
|
|
595
|
+
command: scriptCommand ?? "vite build",
|
|
596
|
+
outputDirectory: ".output",
|
|
597
|
+
entrypoint: "",
|
|
598
|
+
source: "TanStack Start defaults",
|
|
599
|
+
};
|
|
600
|
+
case "custom":
|
|
601
|
+
return {
|
|
602
|
+
command: scriptCommand,
|
|
603
|
+
outputDirectory: "dist",
|
|
604
|
+
entrypoint: "server.js",
|
|
605
|
+
source: "Custom defaults",
|
|
606
|
+
};
|
|
607
|
+
case "bun":
|
|
608
|
+
return {
|
|
609
|
+
command: scriptCommand,
|
|
610
|
+
outputDirectory: ".",
|
|
611
|
+
entrypoint: "",
|
|
612
|
+
source: "Bun defaults",
|
|
613
|
+
};
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
function resolveRemotePackageManager(args: {
|
|
618
|
+
manifest: ParsedManifest;
|
|
619
|
+
rootManifest: ParsedManifest | undefined;
|
|
620
|
+
filePaths: Set<string>;
|
|
621
|
+
}): "npm" | "pnpm" | "yarn" | "bun" | null {
|
|
622
|
+
const fromField = packageManagerFromField(args.manifest.value.packageManager);
|
|
623
|
+
if (fromField) return fromField;
|
|
624
|
+
const fromRoot = packageManagerFromField(
|
|
625
|
+
args.rootManifest?.value.packageManager,
|
|
626
|
+
);
|
|
627
|
+
if (fromRoot) return fromRoot;
|
|
628
|
+
|
|
629
|
+
for (const root of pathLineage(args.manifest.root)) {
|
|
630
|
+
if (
|
|
631
|
+
args.filePaths.has(joinRepoPath(root, "bun.lock")) ||
|
|
632
|
+
args.filePaths.has(joinRepoPath(root, "bun.lockb"))
|
|
633
|
+
) {
|
|
634
|
+
return "bun";
|
|
635
|
+
}
|
|
636
|
+
if (args.filePaths.has(joinRepoPath(root, "pnpm-lock.yaml"))) return "pnpm";
|
|
637
|
+
if (args.filePaths.has(joinRepoPath(root, "yarn.lock"))) return "yarn";
|
|
638
|
+
if (args.filePaths.has(joinRepoPath(root, "package-lock.json"))) {
|
|
639
|
+
return "npm";
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
return null;
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
function packageManagerFromField(
|
|
646
|
+
value: unknown,
|
|
647
|
+
): "npm" | "pnpm" | "yarn" | "bun" | null {
|
|
648
|
+
if (typeof value !== "string") return null;
|
|
649
|
+
const name = value.split("@", 1)[0];
|
|
650
|
+
return name === "bun" || name === "pnpm" || name === "yarn" || name === "npm"
|
|
651
|
+
? name
|
|
652
|
+
: null;
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
function readBuildScript(scripts: unknown): string | null {
|
|
656
|
+
if (!scripts || typeof scripts !== "object" || !("build" in scripts)) {
|
|
657
|
+
return null;
|
|
658
|
+
}
|
|
659
|
+
return typeof scripts.build === "string" && scripts.build.trim()
|
|
660
|
+
? scripts.build.trim()
|
|
661
|
+
: null;
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
function pathLineage(root: string): string[] {
|
|
665
|
+
const parts = root.split("/").filter(Boolean);
|
|
666
|
+
const lineage: string[] = [];
|
|
667
|
+
for (let length = parts.length; length >= 0; length--) {
|
|
668
|
+
lineage.push(parts.slice(0, length).join("/"));
|
|
669
|
+
}
|
|
670
|
+
return lineage;
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
function directoryName(path: string): string {
|
|
674
|
+
const index = path.lastIndexOf("/");
|
|
675
|
+
return index === -1 ? "" : path.slice(0, index);
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
function lastPathSegment(path: string): string | null {
|
|
679
|
+
return path.split("/").filter(Boolean).at(-1) ?? null;
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
function pathDepth(path: string): number {
|
|
683
|
+
return path.split("/").length;
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
function joinRepoPath(...parts: string[]): string {
|
|
687
|
+
return parts.filter(Boolean).join("/").replace(/\/+/g, "/");
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
function isPathInside(path: string, root: string): boolean {
|
|
691
|
+
return path === root || path.startsWith(`${root}/`);
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
function normalizeTarget(value: string): string {
|
|
695
|
+
const unscoped = value.split("/").filter(Boolean).at(-1) ?? "app";
|
|
696
|
+
const normalized = unscoped
|
|
697
|
+
.toLowerCase()
|
|
698
|
+
.replace(/[^a-z0-9-]+/g, "-")
|
|
699
|
+
.replace(/^-+|-+$/g, "");
|
|
700
|
+
return normalized || "app";
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
function uniquifyTargets(apps: DetectedComputeRepositoryApp[]): void {
|
|
704
|
+
const reservedTargets = new Set(apps.map((app) => app.target));
|
|
705
|
+
const usedTargets = new Set<string>();
|
|
706
|
+
for (const app of apps) {
|
|
707
|
+
const baseTarget = app.target;
|
|
708
|
+
let target = baseTarget;
|
|
709
|
+
let suffix = 2;
|
|
710
|
+
while (usedTargets.has(target)) {
|
|
711
|
+
do {
|
|
712
|
+
target = `${baseTarget}-${suffix}`;
|
|
713
|
+
suffix += 1;
|
|
714
|
+
} while (usedTargets.has(target) || reservedTargets.has(target));
|
|
715
|
+
}
|
|
716
|
+
usedTargets.add(target);
|
|
717
|
+
app.target = target;
|
|
718
|
+
app.name = target;
|
|
719
|
+
}
|
|
720
|
+
}
|