@prisma/cli 3.0.0-beta.3 → 3.0.0-beta.30
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 +6 -15
- package/dist/adapters/local-state.js +15 -4
- package/dist/adapters/mock-api.js +244 -0
- package/dist/adapters/token-storage.js +335 -34
- package/dist/cli.js +7 -7
- package/dist/cli2.js +24 -5
- package/dist/commands/agent/index.js +60 -0
- package/dist/commands/app/index.js +91 -61
- package/dist/commands/auth/index.js +55 -2
- package/dist/commands/branch/index.js +2 -27
- package/dist/commands/bucket/index.js +123 -0
- package/dist/commands/build/index.js +29 -0
- package/dist/commands/database/index.js +249 -0
- package/dist/commands/env.js +8 -4
- package/dist/commands/feedback/index.js +20 -0
- package/dist/commands/git/index.js +1 -1
- package/dist/commands/init/index.js +33 -0
- package/dist/commands/project/index.js +54 -5
- package/dist/controllers/agent-setup.js +52 -0
- package/dist/controllers/agent.js +228 -0
- package/dist/controllers/app-env-api.js +55 -0
- package/dist/controllers/app-env-file.js +181 -0
- package/dist/controllers/app-env.js +227 -104
- package/dist/controllers/app.js +746 -306
- package/dist/controllers/auth.js +247 -3
- package/dist/controllers/branch.js +78 -48
- package/dist/controllers/bucket.js +278 -0
- package/dist/controllers/build.js +88 -0
- package/dist/controllers/database.js +567 -0
- package/dist/controllers/feedback.js +86 -0
- package/dist/controllers/init.js +753 -0
- package/dist/controllers/project.js +377 -22
- package/dist/controllers/select-prompt-port.js +1 -0
- package/dist/lib/agent/cli-command.js +20 -0
- package/dist/lib/agent/constants.js +12 -0
- package/dist/lib/agent/package-manager.js +99 -0
- package/dist/lib/agent/setup-status.js +83 -0
- package/dist/lib/app/{preview-provider.js → app-provider.js} +137 -88
- package/dist/lib/app/branch-database-api.js +102 -0
- package/dist/lib/app/branch-database-deploy.js +326 -0
- package/dist/lib/app/branch-database.js +216 -0
- package/dist/lib/app/build-settings.js +93 -0
- package/dist/lib/app/build.js +83 -0
- package/dist/lib/app/bun-project.js +3 -4
- package/dist/lib/app/compute-config.js +145 -0
- package/dist/lib/app/deploy-plan.js +59 -0
- package/dist/lib/app/{preview-progress.js → deploy-progress.js} +12 -12
- package/dist/lib/app/env-config.js +1 -1
- package/dist/lib/app/env-file.js +82 -0
- package/dist/lib/app/env-vars.js +28 -2
- package/dist/lib/app/local-dev.js +3 -60
- package/dist/lib/app/production-deploy-gate.js +162 -0
- package/dist/lib/app/read-branch.js +30 -0
- package/dist/lib/auth/auth-ops.js +10 -4
- package/dist/lib/auth/guard.js +4 -1
- package/dist/lib/auth/login.js +33 -26
- package/dist/lib/auth/recipient.js +42 -0
- package/dist/lib/bucket/provider.js +139 -0
- package/dist/lib/database/provider.js +378 -0
- package/dist/lib/diagnostics.js +15 -0
- package/dist/lib/fs/home-path.js +24 -0
- package/dist/lib/git/local-branch.js +53 -0
- package/dist/lib/git/local-status.js +57 -0
- package/dist/lib/project/interactive-setup.js +5 -4
- package/dist/lib/project/local-pin.js +171 -41
- package/dist/lib/project/provider.js +92 -0
- package/dist/lib/project/resolution.js +199 -48
- package/dist/lib/project/setup.js +67 -20
- package/dist/output/patterns.js +1 -1
- package/dist/presenters/agent.js +74 -0
- package/dist/presenters/app-env.js +149 -14
- package/dist/presenters/app.js +208 -27
- package/dist/presenters/auth.js +99 -2
- package/dist/presenters/branch.js +37 -102
- package/dist/presenters/bucket.js +174 -0
- package/dist/presenters/database.js +448 -0
- package/dist/presenters/feedback.js +26 -0
- package/dist/presenters/init.js +30 -0
- package/dist/presenters/project.js +139 -27
- package/dist/presenters/verbose-context.js +64 -0
- package/dist/shell/cli-command.js +12 -0
- package/dist/shell/command-arguments.js +7 -1
- package/dist/shell/command-meta.js +458 -17
- package/dist/shell/command-runner.js +58 -18
- package/dist/shell/diagnostics-output.js +57 -0
- package/dist/shell/errors.js +56 -1
- package/dist/shell/help.js +31 -20
- package/dist/shell/output.js +72 -1
- package/dist/shell/prompt.js +12 -5
- package/dist/shell/runtime.js +8 -4
- package/dist/shell/ui.js +42 -3
- package/dist/shell/update-check.js +2 -2
- package/dist/use-cases/auth.js +68 -1
- package/dist/use-cases/branch.js +20 -68
- package/dist/use-cases/create-cli-gateways.js +2 -17
- package/dist/use-cases/project.js +2 -1
- package/package.json +21 -4
- package/dist/lib/app/preview-build.js +0 -312
- package/dist/lib/app/preview-interaction.js +0 -5
|
@@ -29,16 +29,9 @@ function createCliUseCaseGateways(context) {
|
|
|
29
29
|
getProjectForWorkspace: (workspaceId, projectId) => context.api.getProjectForWorkspace(workspaceId, projectId)
|
|
30
30
|
},
|
|
31
31
|
branchGateway: {
|
|
32
|
-
listBranchesForProject: (projectId) => context.api.listBranchesForProject(projectId)
|
|
33
|
-
...branch,
|
|
34
|
-
kind: branch.name === "production" ? "production" : "preview"
|
|
35
|
-
})),
|
|
32
|
+
listBranchesForProject: (projectId) => context.api.listBranchesForProject(projectId),
|
|
36
33
|
getBranchForProject: (projectId, name) => {
|
|
37
|
-
|
|
38
|
-
return branch ? {
|
|
39
|
-
...branch,
|
|
40
|
-
kind: branch.name === "production" ? "production" : "preview"
|
|
41
|
-
} : void 0;
|
|
34
|
+
return context.api.getBranchForProject(projectId, name);
|
|
42
35
|
},
|
|
43
36
|
getDeployment: (deploymentId) => context.api.getDeployment(deploymentId)
|
|
44
37
|
},
|
|
@@ -55,14 +48,6 @@ function createCliUseCaseGateways(context) {
|
|
|
55
48
|
clearAuthSession: async () => {
|
|
56
49
|
await context.stateStore.clearAuthSession();
|
|
57
50
|
}
|
|
58
|
-
},
|
|
59
|
-
branchStateGateway: {
|
|
60
|
-
readActiveBranch: async () => {
|
|
61
|
-
return (await context.stateStore.read()).branch.active;
|
|
62
|
-
},
|
|
63
|
-
writeActiveBranch: async (branchName) => {
|
|
64
|
-
await context.stateStore.setActiveBranch(branchName);
|
|
65
|
-
}
|
|
66
51
|
}
|
|
67
52
|
};
|
|
68
53
|
}
|
|
@@ -23,7 +23,8 @@ function toProjectSummary(project) {
|
|
|
23
23
|
return {
|
|
24
24
|
id: project.id,
|
|
25
25
|
name: project.name,
|
|
26
|
-
...project.url ? { url: project.url } : {}
|
|
26
|
+
...project.url ? { url: project.url } : {},
|
|
27
|
+
...project.defaultRegion != null ? { defaultRegion: project.defaultRegion } : {}
|
|
27
28
|
};
|
|
28
29
|
}
|
|
29
30
|
//#endregion
|
package/package.json
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma/cli",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
3
|
+
"version": "3.0.0-beta.30",
|
|
4
4
|
"description": "Command-line interface for the Prisma Developer Platform.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
7
7
|
"prisma-cli": "./dist/cli.js"
|
|
8
8
|
},
|
|
9
|
+
"exports": {
|
|
10
|
+
"./package.json": "./package.json"
|
|
11
|
+
},
|
|
9
12
|
"files": [
|
|
10
13
|
"dist",
|
|
11
14
|
"README.md",
|
|
@@ -34,18 +37,32 @@
|
|
|
34
37
|
"url": "https://github.com/prisma/prisma-cli/issues"
|
|
35
38
|
},
|
|
36
39
|
"license": "Apache-2.0",
|
|
40
|
+
"scripts": {
|
|
41
|
+
"build": "tsdown",
|
|
42
|
+
"prepack": "pnpm run build",
|
|
43
|
+
"test": "vitest run"
|
|
44
|
+
},
|
|
37
45
|
"dependencies": {
|
|
38
46
|
"@clack/prompts": "^1.5.0",
|
|
39
|
-
"@prisma/compute-sdk": "
|
|
47
|
+
"@prisma/compute-sdk": "0.39.0",
|
|
40
48
|
"@prisma/credentials-store": "^7.8.0",
|
|
41
|
-
"@prisma/management-api-sdk": "^1.
|
|
42
|
-
"
|
|
49
|
+
"@prisma/management-api-sdk": "^1.55.0",
|
|
50
|
+
"better-result": "^2.9.2",
|
|
43
51
|
"colorette": "^2.0.20",
|
|
44
52
|
"commander": "^14.0.3",
|
|
53
|
+
"dotenv": "^17.4.2",
|
|
54
|
+
"execa": "^9.6.1",
|
|
45
55
|
"magicast": "^0.5.3",
|
|
46
56
|
"open": "^11.0.0",
|
|
47
57
|
"string-width": "^8.2.1",
|
|
48
58
|
"strip-ansi": "^7.2.0",
|
|
49
59
|
"wrap-ansi": "^10.0.0"
|
|
60
|
+
},
|
|
61
|
+
"devDependencies": {
|
|
62
|
+
"@types/node": "^22.19.19",
|
|
63
|
+
"tsdown": "^0.21.10",
|
|
64
|
+
"tsx": "^4.22.4",
|
|
65
|
+
"typescript": "^6.0.3",
|
|
66
|
+
"vitest": "^4.1.8"
|
|
50
67
|
}
|
|
51
68
|
}
|
|
@@ -1,312 +0,0 @@
|
|
|
1
|
-
import { resolveBunEntrypoint } from "./bun-project.js";
|
|
2
|
-
import { chmod, copyFile, cp, lstat, mkdir, readFile, readdir, readlink, rm, stat } from "node:fs/promises";
|
|
3
|
-
import path from "node:path";
|
|
4
|
-
import { AstroBuild, BunBuild, NextjsBuild, NuxtBuild, TanstackStartBuild } from "@prisma/compute-sdk";
|
|
5
|
-
//#region src/lib/app/preview-build.ts
|
|
6
|
-
const PREVIEW_BUILD_TYPES = [
|
|
7
|
-
"auto",
|
|
8
|
-
"bun",
|
|
9
|
-
"nextjs",
|
|
10
|
-
"nuxt",
|
|
11
|
-
"astro",
|
|
12
|
-
"tanstack-start"
|
|
13
|
-
];
|
|
14
|
-
const RESOLVED_PREVIEW_BUILD_TYPES = PREVIEW_BUILD_TYPES.filter((buildType) => buildType !== "auto");
|
|
15
|
-
var PreviewBuildStrategy = class {
|
|
16
|
-
#appPath;
|
|
17
|
-
#entrypoint;
|
|
18
|
-
#buildType;
|
|
19
|
-
#signal;
|
|
20
|
-
constructor(options) {
|
|
21
|
-
this.#appPath = options.appPath;
|
|
22
|
-
this.#entrypoint = options.entrypoint;
|
|
23
|
-
this.#buildType = options.buildType ?? "auto";
|
|
24
|
-
this.#signal = options.signal;
|
|
25
|
-
}
|
|
26
|
-
async canBuild(signal = this.#signal) {
|
|
27
|
-
const { strategy } = await resolvePreviewBuildStrategy({
|
|
28
|
-
appPath: this.#appPath,
|
|
29
|
-
entrypoint: this.#entrypoint,
|
|
30
|
-
buildType: this.#buildType,
|
|
31
|
-
signal
|
|
32
|
-
});
|
|
33
|
-
return strategy.canBuild(signal);
|
|
34
|
-
}
|
|
35
|
-
async execute(signal = this.#signal) {
|
|
36
|
-
const { artifact } = await executePreviewBuild({
|
|
37
|
-
appPath: this.#appPath,
|
|
38
|
-
entrypoint: this.#entrypoint,
|
|
39
|
-
buildType: this.#buildType,
|
|
40
|
-
signal
|
|
41
|
-
});
|
|
42
|
-
return artifact;
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
async function executePreviewBuild(options) {
|
|
46
|
-
const { strategy, buildType } = await resolvePreviewBuildStrategy({
|
|
47
|
-
appPath: options.appPath,
|
|
48
|
-
entrypoint: options.entrypoint,
|
|
49
|
-
buildType: options.buildType ?? "auto",
|
|
50
|
-
signal: options.signal
|
|
51
|
-
});
|
|
52
|
-
const artifact = await strategy.execute(options.signal);
|
|
53
|
-
try {
|
|
54
|
-
if (buildType === "nextjs") await restageNextjsArtifact(artifact, options.appPath, options.signal);
|
|
55
|
-
await normalizeArtifactSymlinks(artifact.directory, options.appPath, options.signal);
|
|
56
|
-
return {
|
|
57
|
-
artifact,
|
|
58
|
-
buildType
|
|
59
|
-
};
|
|
60
|
-
} catch (error) {
|
|
61
|
-
await artifact.cleanup?.().catch(() => void 0);
|
|
62
|
-
throw error;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
async function resolvePreviewBuildStrategy(options) {
|
|
66
|
-
if (options.buildType !== "auto") {
|
|
67
|
-
const strategy = await createPreviewBuildStrategy({
|
|
68
|
-
appPath: options.appPath,
|
|
69
|
-
entrypoint: options.entrypoint,
|
|
70
|
-
buildType: options.buildType,
|
|
71
|
-
signal: options.signal
|
|
72
|
-
});
|
|
73
|
-
return {
|
|
74
|
-
buildType: options.buildType,
|
|
75
|
-
strategy
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
for (const buildType of RESOLVED_PREVIEW_BUILD_TYPES) {
|
|
79
|
-
if (buildType === "bun") continue;
|
|
80
|
-
const strategy = await createPreviewBuildStrategy({
|
|
81
|
-
appPath: options.appPath,
|
|
82
|
-
entrypoint: options.entrypoint,
|
|
83
|
-
buildType,
|
|
84
|
-
signal: options.signal
|
|
85
|
-
});
|
|
86
|
-
if (await strategy.canBuild(options.signal)) return {
|
|
87
|
-
buildType,
|
|
88
|
-
strategy
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
return {
|
|
92
|
-
buildType: "bun",
|
|
93
|
-
strategy: await createPreviewBuildStrategy({
|
|
94
|
-
appPath: options.appPath,
|
|
95
|
-
entrypoint: options.entrypoint,
|
|
96
|
-
buildType: "bun",
|
|
97
|
-
signal: options.signal
|
|
98
|
-
})
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
async function createPreviewBuildStrategy(options) {
|
|
102
|
-
switch (options.buildType) {
|
|
103
|
-
case "nextjs": return new NextjsBuild({ appPath: options.appPath });
|
|
104
|
-
case "nuxt": return new NuxtBuild({ appPath: options.appPath });
|
|
105
|
-
case "astro": return new AstroBuild({ appPath: options.appPath });
|
|
106
|
-
case "tanstack-start": return new TanstackStartBuild({ appPath: options.appPath });
|
|
107
|
-
case "bun": {
|
|
108
|
-
const entrypoint = await resolveBunEntrypoint(options.appPath, options.entrypoint, options.signal);
|
|
109
|
-
return new BunBuild({
|
|
110
|
-
appPath: options.appPath,
|
|
111
|
-
entrypoint
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
async function stageNextjsStandaloneArtifact(options) {
|
|
117
|
-
const standaloneRoot = path.resolve(options.standaloneDir);
|
|
118
|
-
const artifactRoot = path.resolve(options.artifactDir);
|
|
119
|
-
const appRoot = path.resolve(options.appPath);
|
|
120
|
-
await copyPathMaterializingSymlinks(standaloneRoot, artifactRoot, {
|
|
121
|
-
standaloneRoot,
|
|
122
|
-
appRoot,
|
|
123
|
-
sourceRoot: await resolveSourceRoot(appRoot, options.signal),
|
|
124
|
-
signal: options.signal
|
|
125
|
-
});
|
|
126
|
-
await hoistPnpmDependencies(path.join(artifactRoot, "node_modules"), options.signal);
|
|
127
|
-
}
|
|
128
|
-
async function restageNextjsArtifact(artifact, appPath, signal) {
|
|
129
|
-
const artifactDir = artifact.directory;
|
|
130
|
-
const standaloneDir = path.join(appPath, ".next", "standalone");
|
|
131
|
-
await unsupportedFilesystemBoundary(signal, () => rm(artifactDir, {
|
|
132
|
-
recursive: true,
|
|
133
|
-
force: true
|
|
134
|
-
}));
|
|
135
|
-
await stageNextjsStandaloneArtifact({
|
|
136
|
-
standaloneDir,
|
|
137
|
-
artifactDir,
|
|
138
|
-
appPath,
|
|
139
|
-
signal
|
|
140
|
-
});
|
|
141
|
-
const serverSubpath = nextjsServerSubpath(artifact.entrypoint);
|
|
142
|
-
const serverDir = serverSubpath ? path.join(artifactDir, serverSubpath) : artifactDir;
|
|
143
|
-
const publicDir = path.join(appPath, "public");
|
|
144
|
-
if (await directoryExists(publicDir, signal)) await unsupportedFilesystemBoundary(signal, () => cp(publicDir, path.join(serverDir, "public"), {
|
|
145
|
-
recursive: true,
|
|
146
|
-
verbatimSymlinks: true
|
|
147
|
-
}));
|
|
148
|
-
const staticDir = path.join(appPath, ".next", "static");
|
|
149
|
-
if (await directoryExists(staticDir, signal)) await unsupportedFilesystemBoundary(signal, () => cp(staticDir, path.join(serverDir, ".next", "static"), {
|
|
150
|
-
recursive: true,
|
|
151
|
-
verbatimSymlinks: true
|
|
152
|
-
}));
|
|
153
|
-
}
|
|
154
|
-
function nextjsServerSubpath(entrypoint) {
|
|
155
|
-
const dir = path.posix.dirname(entrypoint);
|
|
156
|
-
return dir === "." ? "" : dir;
|
|
157
|
-
}
|
|
158
|
-
async function hoistPnpmDependencies(nodeModulesDir, signal) {
|
|
159
|
-
const pnpmNodeModulesDir = path.join(nodeModulesDir, ".pnpm", "node_modules");
|
|
160
|
-
if (!await directoryExists(pnpmNodeModulesDir, signal)) return;
|
|
161
|
-
const entries = await unsupportedFilesystemBoundary(signal, () => readdir(pnpmNodeModulesDir, { withFileTypes: true }));
|
|
162
|
-
for (const entry of entries) {
|
|
163
|
-
const sourcePath = path.join(pnpmNodeModulesDir, entry.name);
|
|
164
|
-
if (entry.name.startsWith("@") && entry.isDirectory()) {
|
|
165
|
-
const scopedEntries = await unsupportedFilesystemBoundary(signal, () => readdir(sourcePath, { withFileTypes: true }));
|
|
166
|
-
for (const scopedEntry of scopedEntries) {
|
|
167
|
-
const scopedDestination = path.join(nodeModulesDir, entry.name, scopedEntry.name);
|
|
168
|
-
if (await pathExists(scopedDestination, signal)) continue;
|
|
169
|
-
await unsupportedFilesystemBoundary(signal, () => mkdir(path.dirname(scopedDestination), { recursive: true }));
|
|
170
|
-
await copyPathMaterializingSymlinks(path.join(sourcePath, scopedEntry.name), scopedDestination, {
|
|
171
|
-
standaloneRoot: pnpmNodeModulesDir,
|
|
172
|
-
appRoot: nodeModulesDir,
|
|
173
|
-
sourceRoot: nodeModulesDir,
|
|
174
|
-
signal
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
continue;
|
|
178
|
-
}
|
|
179
|
-
const destinationPath = path.join(nodeModulesDir, entry.name);
|
|
180
|
-
if (await pathExists(destinationPath, signal)) continue;
|
|
181
|
-
await copyPathMaterializingSymlinks(sourcePath, destinationPath, {
|
|
182
|
-
standaloneRoot: pnpmNodeModulesDir,
|
|
183
|
-
appRoot: nodeModulesDir,
|
|
184
|
-
sourceRoot: nodeModulesDir,
|
|
185
|
-
signal
|
|
186
|
-
});
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
async function normalizeArtifactSymlinks(artifactDir, appPath, signal) {
|
|
190
|
-
const normalizedArtifactDir = path.resolve(artifactDir);
|
|
191
|
-
const normalizedAppPath = path.resolve(appPath);
|
|
192
|
-
await walkDirectory(normalizedArtifactDir);
|
|
193
|
-
async function walkDirectory(directory) {
|
|
194
|
-
const entries = await unsupportedFilesystemBoundary(signal, () => readdir(directory, { withFileTypes: true }));
|
|
195
|
-
for (const entry of entries) {
|
|
196
|
-
const fullPath = path.join(directory, entry.name);
|
|
197
|
-
if (entry.isDirectory()) {
|
|
198
|
-
await walkDirectory(fullPath);
|
|
199
|
-
continue;
|
|
200
|
-
}
|
|
201
|
-
if (!entry.isSymbolicLink()) continue;
|
|
202
|
-
const target = await unsupportedFilesystemBoundary(signal, () => readlink(fullPath));
|
|
203
|
-
const resolvedTarget = path.resolve(path.dirname(fullPath), target);
|
|
204
|
-
if (isPathWithin(normalizedArtifactDir, resolvedTarget)) continue;
|
|
205
|
-
if (!isPathWithin(normalizedAppPath, resolvedTarget)) throw new Error(`Build artifact symlink escapes the app directory: ${resolvedTarget}`);
|
|
206
|
-
const targetStat = await unsupportedFilesystemBoundary(signal, () => stat(resolvedTarget));
|
|
207
|
-
await unsupportedFilesystemBoundary(signal, () => rm(fullPath, {
|
|
208
|
-
force: true,
|
|
209
|
-
recursive: true
|
|
210
|
-
}));
|
|
211
|
-
await unsupportedFilesystemBoundary(signal, () => cp(resolvedTarget, fullPath, {
|
|
212
|
-
recursive: targetStat.isDirectory(),
|
|
213
|
-
dereference: true
|
|
214
|
-
}));
|
|
215
|
-
if (targetStat.isDirectory()) await walkDirectory(fullPath);
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
function isPathWithin(rootPath, candidatePath) {
|
|
220
|
-
const relativePath = path.relative(rootPath, candidatePath);
|
|
221
|
-
return relativePath === "" || !relativePath.startsWith(`..${path.sep}`) && relativePath !== ".." && !path.isAbsolute(relativePath);
|
|
222
|
-
}
|
|
223
|
-
function isPathWithinWorkspaceDependency(sourceRoot, candidatePath) {
|
|
224
|
-
return isPathWithin(path.join(sourceRoot, "node_modules"), candidatePath);
|
|
225
|
-
}
|
|
226
|
-
async function copyPathMaterializingSymlinks(sourcePath, destinationPath, options) {
|
|
227
|
-
const sourceStat = await unsupportedFilesystemBoundary(options.signal, () => lstat(sourcePath));
|
|
228
|
-
if (sourceStat.isSymbolicLink()) {
|
|
229
|
-
const resolvedTarget = await resolveSymlinkTarget(sourcePath, options);
|
|
230
|
-
if (resolvedTarget === null) return;
|
|
231
|
-
await copyPathMaterializingSymlinks(resolvedTarget, destinationPath, options);
|
|
232
|
-
return;
|
|
233
|
-
}
|
|
234
|
-
if (sourceStat.isDirectory()) {
|
|
235
|
-
await unsupportedFilesystemBoundary(options.signal, () => mkdir(destinationPath, { recursive: true }));
|
|
236
|
-
const entries = await unsupportedFilesystemBoundary(options.signal, () => readdir(sourcePath, { withFileTypes: true }));
|
|
237
|
-
for (const entry of entries) await copyPathMaterializingSymlinks(path.join(sourcePath, entry.name), path.join(destinationPath, entry.name), options);
|
|
238
|
-
return;
|
|
239
|
-
}
|
|
240
|
-
if (sourceStat.isFile()) {
|
|
241
|
-
await unsupportedFilesystemBoundary(options.signal, () => mkdir(path.dirname(destinationPath), { recursive: true }));
|
|
242
|
-
await unsupportedFilesystemBoundary(options.signal, () => copyFile(sourcePath, destinationPath));
|
|
243
|
-
await unsupportedFilesystemBoundary(options.signal, () => chmod(destinationPath, sourceStat.mode));
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
async function resolveSymlinkTarget(symlinkPath, options) {
|
|
247
|
-
const linkTarget = await unsupportedFilesystemBoundary(options.signal, () => readlink(symlinkPath));
|
|
248
|
-
const resolvedTarget = path.resolve(path.dirname(symlinkPath), linkTarget);
|
|
249
|
-
if (await pathExists(resolvedTarget, options.signal)) {
|
|
250
|
-
if (!isPathWithin(options.appRoot, resolvedTarget) && !isPathWithinWorkspaceDependency(options.sourceRoot, resolvedTarget)) throw new Error(`Build artifact symlink escapes the app directory: ${resolvedTarget}`);
|
|
251
|
-
return resolvedTarget;
|
|
252
|
-
}
|
|
253
|
-
if (isPathWithin(options.standaloneRoot, resolvedTarget)) {
|
|
254
|
-
const fallbackTarget = path.join(options.appRoot, path.relative(options.standaloneRoot, resolvedTarget));
|
|
255
|
-
if (await pathExists(fallbackTarget, options.signal)) return fallbackTarget;
|
|
256
|
-
}
|
|
257
|
-
if (isPnpmHoistLink(symlinkPath)) return null;
|
|
258
|
-
throw new Error(`Next.js standalone symlink target is missing: ${symlinkPath} -> ${linkTarget} (resolved to ${resolvedTarget})`);
|
|
259
|
-
}
|
|
260
|
-
function isPnpmHoistLink(symlinkPath) {
|
|
261
|
-
const parts = path.dirname(symlinkPath).split(path.sep);
|
|
262
|
-
for (let i = 0; i < parts.length - 1; i++) if (parts[i] === ".pnpm" && parts[i + 1] === "node_modules") return true;
|
|
263
|
-
return false;
|
|
264
|
-
}
|
|
265
|
-
async function pathExists(targetPath, signal) {
|
|
266
|
-
try {
|
|
267
|
-
await unsupportedFilesystemBoundary(signal, () => stat(targetPath));
|
|
268
|
-
return true;
|
|
269
|
-
} catch (error) {
|
|
270
|
-
if (signal?.aborted) throw error;
|
|
271
|
-
return false;
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
async function directoryExists(targetPath, signal) {
|
|
275
|
-
try {
|
|
276
|
-
return (await unsupportedFilesystemBoundary(signal, () => stat(targetPath))).isDirectory();
|
|
277
|
-
} catch (error) {
|
|
278
|
-
if (signal?.aborted) throw error;
|
|
279
|
-
return false;
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
async function resolveSourceRoot(appRoot, signal) {
|
|
283
|
-
let current = path.resolve(appRoot);
|
|
284
|
-
while (true) {
|
|
285
|
-
if (await pathExists(path.join(current, ".git"), signal) || await pathExists(path.join(current, "pnpm-workspace.yaml"), signal) || await pathExists(path.join(current, "bun.lock"), signal) || await pathExists(path.join(current, "bun.lockb"), signal) || await packageJsonDeclaresWorkspaces(current, signal)) return current;
|
|
286
|
-
const parent = path.dirname(current);
|
|
287
|
-
if (parent === current) return path.resolve(appRoot);
|
|
288
|
-
current = parent;
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
async function packageJsonDeclaresWorkspaces(directory, signal) {
|
|
292
|
-
signal?.throwIfAborted();
|
|
293
|
-
try {
|
|
294
|
-
const content = await readFile(path.join(directory, "package.json"), {
|
|
295
|
-
encoding: "utf8",
|
|
296
|
-
signal
|
|
297
|
-
});
|
|
298
|
-
const parsed = JSON.parse(content);
|
|
299
|
-
return Boolean(parsed.workspaces);
|
|
300
|
-
} catch (error) {
|
|
301
|
-
if (signal?.aborted) throw error;
|
|
302
|
-
return false;
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
async function unsupportedFilesystemBoundary(signal, operation) {
|
|
306
|
-
signal?.throwIfAborted();
|
|
307
|
-
const result = await operation();
|
|
308
|
-
signal?.throwIfAborted();
|
|
309
|
-
return result;
|
|
310
|
-
}
|
|
311
|
-
//#endregion
|
|
312
|
-
export { PREVIEW_BUILD_TYPES, PreviewBuildStrategy, RESOLVED_PREVIEW_BUILD_TYPES, executePreviewBuild };
|