@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
package/src/config/detect-app.ts
CHANGED
|
@@ -7,7 +7,10 @@ import {
|
|
|
7
7
|
import type { ComputeFramework } from "./types.ts";
|
|
8
8
|
|
|
9
9
|
export interface ComputeAppManifest {
|
|
10
|
+
name?: unknown;
|
|
10
11
|
main?: unknown;
|
|
12
|
+
packageManager?: unknown;
|
|
13
|
+
workspaces?: unknown;
|
|
11
14
|
scripts?: unknown;
|
|
12
15
|
dependencies?: unknown;
|
|
13
16
|
devDependencies?: unknown;
|
|
@@ -33,6 +36,17 @@ export interface DetectedComputeApp {
|
|
|
33
36
|
};
|
|
34
37
|
}
|
|
35
38
|
|
|
39
|
+
const DEFAULT_ENTRYPOINT_CANDIDATES = [
|
|
40
|
+
"src/index.ts",
|
|
41
|
+
"src/index.js",
|
|
42
|
+
"src/server.ts",
|
|
43
|
+
"src/server.js",
|
|
44
|
+
"index.ts",
|
|
45
|
+
"index.js",
|
|
46
|
+
"server.ts",
|
|
47
|
+
"server.js",
|
|
48
|
+
] as const;
|
|
49
|
+
|
|
36
50
|
/**
|
|
37
51
|
* Detects one deployable app from an in-memory repository snapshot.
|
|
38
52
|
* Paths are repository-relative so remote consumers do not need a checkout.
|
|
@@ -133,14 +147,7 @@ function inferEntrypoint(
|
|
|
133
147
|
}
|
|
134
148
|
const candidates = [
|
|
135
149
|
framework.defaultEntrypoint,
|
|
136
|
-
|
|
137
|
-
"src/index.js",
|
|
138
|
-
"src/server.ts",
|
|
139
|
-
"src/server.js",
|
|
140
|
-
"index.ts",
|
|
141
|
-
"index.js",
|
|
142
|
-
"server.ts",
|
|
143
|
-
"server.js",
|
|
150
|
+
...DEFAULT_ENTRYPOINT_CANDIDATES,
|
|
144
151
|
].filter((value): value is string => Boolean(value));
|
|
145
152
|
return (
|
|
146
153
|
candidates.find((candidate) =>
|
|
@@ -149,6 +156,29 @@ function inferEntrypoint(
|
|
|
149
156
|
);
|
|
150
157
|
}
|
|
151
158
|
|
|
159
|
+
export function computeAppCandidateFilePaths(
|
|
160
|
+
manifest: ComputeAppManifest,
|
|
161
|
+
): string[] {
|
|
162
|
+
const main =
|
|
163
|
+
typeof manifest.main === "string"
|
|
164
|
+
? normalizeEntrypoint(manifest.main)
|
|
165
|
+
: null;
|
|
166
|
+
const runtimeScript = readRuntimeScript(manifest.scripts);
|
|
167
|
+
const scriptedEntrypoint = runtimeScript
|
|
168
|
+
? extractScriptEntrypoint(runtimeScript.command)
|
|
169
|
+
: null;
|
|
170
|
+
return [
|
|
171
|
+
...FRAMEWORKS.flatMap((framework) => framework.detectConfigFiles),
|
|
172
|
+
...FRAMEWORKS.map((framework) => framework.defaultEntrypoint),
|
|
173
|
+
...DEFAULT_ENTRYPOINT_CANDIDATES,
|
|
174
|
+
main,
|
|
175
|
+
scriptedEntrypoint,
|
|
176
|
+
].filter(
|
|
177
|
+
(value, index, values): value is string =>
|
|
178
|
+
Boolean(value) && values.indexOf(value) === index,
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
|
|
152
182
|
function normalizeEntrypoint(value: string): string | null {
|
|
153
183
|
if (
|
|
154
184
|
!value ||
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { access, readFile } from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
type ComputeAppManifest,
|
|
6
|
+
computeAppCandidateFilePaths,
|
|
7
|
+
type DetectedComputeApp,
|
|
8
|
+
detectComputeApp,
|
|
9
|
+
} from "./detect-app.ts";
|
|
10
|
+
import { frameworkByKey } from "./frameworks.ts";
|
|
11
|
+
|
|
12
|
+
export interface DetectComputeAppFromDirectoryInput {
|
|
13
|
+
appPath: string;
|
|
14
|
+
signal?: AbortSignal;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface DetectedComputeDirectoryApp extends DetectedComputeApp {
|
|
18
|
+
configFile: {
|
|
19
|
+
path: string;
|
|
20
|
+
standaloneOutput: boolean;
|
|
21
|
+
} | null;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** Detects one Compute app from a local directory. */
|
|
25
|
+
export async function detectComputeAppFromDirectory(
|
|
26
|
+
input: DetectComputeAppFromDirectoryInput,
|
|
27
|
+
): Promise<DetectedComputeDirectoryApp | null> {
|
|
28
|
+
const manifest = await readManifest(input.appPath, input.signal);
|
|
29
|
+
const candidates = computeAppCandidateFilePaths(manifest);
|
|
30
|
+
const existingCandidates = await Promise.all(
|
|
31
|
+
candidates.map(async (candidate) =>
|
|
32
|
+
(await fileExists(input.appPath, candidate, input.signal))
|
|
33
|
+
? candidate
|
|
34
|
+
: null,
|
|
35
|
+
),
|
|
36
|
+
);
|
|
37
|
+
const filePaths = new Set(
|
|
38
|
+
existingCandidates.filter((candidate) => candidate !== null),
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
const detected = detectComputeApp({ root: "", manifest, filePaths });
|
|
42
|
+
if (!detected) return null;
|
|
43
|
+
|
|
44
|
+
const descriptor = frameworkByKey(detected.framework);
|
|
45
|
+
const configPath = descriptor.detectConfigFiles.find((candidate) =>
|
|
46
|
+
filePaths.has(candidate),
|
|
47
|
+
);
|
|
48
|
+
if (!configPath) {
|
|
49
|
+
return { ...detected, configFile: null };
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
let content: string;
|
|
53
|
+
try {
|
|
54
|
+
content = await readFile(path.join(input.appPath, configPath), {
|
|
55
|
+
encoding: "utf8",
|
|
56
|
+
signal: input.signal,
|
|
57
|
+
});
|
|
58
|
+
} catch (error) {
|
|
59
|
+
if (input.signal?.aborted) throw error;
|
|
60
|
+
if ((error as NodeJS.ErrnoException).code === "ENOENT") {
|
|
61
|
+
return { ...detected, configFile: null };
|
|
62
|
+
}
|
|
63
|
+
throw error;
|
|
64
|
+
}
|
|
65
|
+
return {
|
|
66
|
+
...detected,
|
|
67
|
+
configFile: {
|
|
68
|
+
path: configPath,
|
|
69
|
+
standaloneOutput:
|
|
70
|
+
detected.framework === "nextjs" &&
|
|
71
|
+
/\boutput\s*:\s*["'`]standalone["'`]/.test(content),
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
async function readManifest(
|
|
77
|
+
appPath: string,
|
|
78
|
+
signal?: AbortSignal,
|
|
79
|
+
): Promise<ComputeAppManifest> {
|
|
80
|
+
signal?.throwIfAborted();
|
|
81
|
+
try {
|
|
82
|
+
const content = await readFile(path.join(appPath, "package.json"), {
|
|
83
|
+
encoding: "utf8",
|
|
84
|
+
signal,
|
|
85
|
+
});
|
|
86
|
+
const parsed = JSON.parse(content) as unknown;
|
|
87
|
+
return parsed && typeof parsed === "object"
|
|
88
|
+
? (parsed as ComputeAppManifest)
|
|
89
|
+
: {};
|
|
90
|
+
} catch (error) {
|
|
91
|
+
if (signal?.aborted) throw error;
|
|
92
|
+
if ((error as NodeJS.ErrnoException).code === "ENOENT") return {};
|
|
93
|
+
throw error;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
async function fileExists(
|
|
98
|
+
appPath: string,
|
|
99
|
+
relativePath: string,
|
|
100
|
+
signal?: AbortSignal,
|
|
101
|
+
): Promise<boolean> {
|
|
102
|
+
signal?.throwIfAborted();
|
|
103
|
+
try {
|
|
104
|
+
await access(path.join(appPath, relativePath));
|
|
105
|
+
signal?.throwIfAborted();
|
|
106
|
+
return true;
|
|
107
|
+
} catch (error) {
|
|
108
|
+
if (signal?.aborted) throw error;
|
|
109
|
+
if ((error as NodeJS.ErrnoException).code === "ENOENT") return false;
|
|
110
|
+
throw error;
|
|
111
|
+
}
|
|
112
|
+
}
|