Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
013aa80
feat(deploy): send deno.json to the console on every deploy
piscisaureus Oct 1, 2026
5732066
feat(create): warn when deno.json overrides the build config given to…
piscisaureus Oct 1, 2026
0b2870a
fix(create): keep --json stderr to the JSON envelope
piscisaureus Oct 1, 2026
475550f
fix(deploy): send the root deno.json even when the upload excludes it
piscisaureus Oct 1, 2026
3f99929
fix(create): don't prompt for a timeout deno.json decides; warn for c…
piscisaureus Oct 1, 2026
2257afc
Merge remote-tracking branch 'origin/main' into send-deno-json-on-deploy
piscisaureus Oct 1, 2026
1a0df03
fix(deploy): send the config selected with --config as the root deno.…
piscisaureus Oct 1, 2026
d08cca4
fix(deploy): send the app directory's deno.json, and warn for custom …
piscisaureus Oct 1, 2026
83f112d
fix(deploy): ignore a stored build directory that leaves the deploy root
piscisaureus Oct 1, 2026
727debf
fix(deploy): keep app config reads inside the deploy root on Windows too
piscisaureus Oct 1, 2026
5039027
fix(deploy): handle a filesystem-root deploy root; let a failed app l…
piscisaureus Oct 1, 2026
e794f13
refactor(deploy): send only the app directory's deno.json
piscisaureus Oct 1, 2026
ca25625
refactor(deploy): type the apps.get build directory through AppDetail
piscisaureus Oct 1, 2026
1a2af44
test(deploy): cover which deno.json files a deploy sends
piscisaureus Oct 1, 2026
b47aae5
fix(deploy): resolve symlinks before reading an excluded config; dete…
piscisaureus Oct 1, 2026
0a22989
fix(create): don't let the custom-directory deno.json check fail create
piscisaureus Oct 1, 2026
c9eac00
fix(create): detect a custom app directory with the root's package ma…
piscisaureus Oct 1, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions deploy/apps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,17 @@ interface AppItem {
layers: Array<{ slug: string }>;
}

interface AppDetail {
/** The app row `apps.get` returns, as far as the CLI reads it. */
export interface AppDetail {
id: string;
slug: string;
created_at: Date;
updated_at: Date;
build_config: { frameworkPreset?: string | null } | null;
build_config: {
frameworkPreset?: string | null;
/** The app directory, relative to the repository or deploy root. */
buildDirectory?: string;
} | null;
}

interface TimelineEntry {
Expand Down
64 changes: 63 additions & 1 deletion deploy/create/flow.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { createTrpcClient, type TRPCClient } from "../../auth.ts";
import { resolve } from "@std/path";
import { green } from "@std/fmt/colors";
import { error } from "../../util.ts";
import {
Expand All @@ -7,7 +8,9 @@ import {
} from "@std/cli/unstable-prompt-select";
import {
type BuildConfig,
detectBuildConfig,
type DetectedBuildConfig,
detectPackageManager,
detectWorkspace,
FrameworkFileSystemReader,
SUPPORTED_FRAMEWORK_PRESETS,
Expand Down Expand Up @@ -44,6 +47,33 @@ export function parseBuildTimeoutFlag(value: string): number | null {
return AVAILABLE_BUILD_TIMEOUTS.includes(minutes) ? minutes : null;
}

/**
* The build config detected in a local app directory that is not a detected
* workspace member: a deploy still applies its deno.json `deploy` section, so
* `create` must know about it. Not attempted for a GitHub repo, where it would
* need a request whose failure exits the CLI, for what is only a warning.
*/
export async function customDirectoryBuildConfig(
rootPath: string,
repo: Repo,
path: string,
): Promise<DetectedBuildConfig | null> {
if (repo !== undefined) return null;
try {
// As `detectWorkspace` does: a lockfile at the root decides the package
// manager of a nested app.
const packageManager = await detectPackageManager(
new FrameworkFileSystemReader(rootPath),
);
return await detectBuildConfig(
new FrameworkFileSystemReader(resolve(rootPath, path)),
packageManager,
);
} catch {
return null;
}
}

/**
* The build timeout a detected build config asks for (deno.json
* `deploy.buildTimeout`), as the largest available step not above it or
Expand Down Expand Up @@ -85,6 +115,16 @@ export async function detectedBuildTimeoutForOrg(
return detectedBuildTimeout(buildConfig, maxBuildTimeout);
}

/**
* The `deploy` section of deno.json takes precedence over the app's stored
* build configuration on every deploy, so settings given to `create` that
* differ from it would never be used.
*/
export const DENO_JSON_PRECEDENCE_WARNING =
"This app's deno.json has a `deploy` section, which takes precedence over " +
"the build configuration given here on every deploy. To change the build " +
"configuration, edit deno.json instead.";

const NA = "(n/a)";
const TITLES = {
organization: "organization",
Expand Down Expand Up @@ -221,7 +261,12 @@ export async function createFlow(
if (typeof selectedAppDirectory === "string") {
buildConfig = appDirectories.members.find((member) =>
member.path === selectedAppDirectory
)?.buildConfig ?? null;
)?.buildConfig ??
await customDirectoryBuildConfig(
rootPath,
repo,
selectedAppDirectory,
);
} else {
buildConfig = selectedAppDirectory.buildConfig;
}
Expand All @@ -244,6 +289,9 @@ export async function createFlow(
clearPreviousLines(renderedBuildConfigLines + 1);

if (!useDetected) {
if (buildConfig.from === "deno.json") {
console.warn(DENO_JSON_PRECEDENCE_WARNING);
}
finalBuildConfig = getBuildConfig(context, buildConfig);
} else {
finalBuildConfig = buildConfig;
Expand All @@ -268,11 +316,25 @@ export async function createFlow(
finalBuildConfig = getBuildConfig(context, buildConfig);
}

if (
explicitBuildTimeout !== undefined && finalBuildConfig === buildConfig &&
buildConfig?.from === "deno.json"
) {
console.warn(DENO_JSON_PRECEDENCE_WARNING);
}
let buildTimeout = explicitBuildTimeout ?? await detectedBuildTimeoutForOrg(
trpcClient,
org,
finalBuildConfig,
);
// A deno.json `deploy` section decides the timeout on every deploy, an
// omitted one meaning the default, so there is nothing to ask for.
if (
buildTimeout === undefined && buildConfig?.from === "deno.json" &&
finalBuildConfig === buildConfig
) {
buildTimeout = AVAILABLE_BUILD_TIMEOUTS[0];
}
if (buildTimeout === undefined) {
// TODO: check pro
const selectedBuildTimeout = promptSelect(
Expand Down
21 changes: 21 additions & 0 deletions deploy/create/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import {
AVAILABLE_BUILD_MEMORY_LIMITS,
AVAILABLE_BUILD_TIMEOUTS,
createFlow,
customDirectoryBuildConfig,
DENO_JSON_PRECEDENCE_WARNING,
detectedBuildTimeoutForOrg,
parseBuildTimeoutFlag,
REGIONS,
Expand Down Expand Up @@ -250,6 +252,25 @@ export const createCommand = new Command<GlobalContext>()
buildDirectory = options.appDirectory || "";
}

// Build settings given here are overridden by a deno.json `deploy`
// section: those passed as flags, or all of them for a custom app
// directory, whose config is synthesized from the flags below.
if (
!options.json &&
(options.doNotUseDetectedBuildConfig ||
options.buildTimeout !== undefined || member === undefined)
) {
const detected = member?.buildConfig ??
await customDirectoryBuildConfig(
rootPath,
repo,
buildDirectory,
);
if (detected?.from === "deno.json") {
console.warn(DENO_JSON_PRECEDENCE_WARNING);
}
}

let buildConfig;
if (!options.doNotUseDetectedBuildConfig) {
if (member?.buildConfig) {
Expand Down
107 changes: 104 additions & 3 deletions deploy/publish.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { TarStream, type TarStreamFile } from "@std/tar";
import { ProgressBar } from "@std/cli/unstable-progress-bar";
import { Spinner } from "@std/cli/unstable-spinner";
import { join, relative, resolve, SEPARATOR } from "@std/path";
import { isAbsolute, join, relative, resolve, SEPARATOR } from "@std/path";
import { green, red, yellow } from "@std/fmt/colors";
import { authedFetch, createTrpcClient } from "../auth.ts";
import {
Expand All @@ -12,6 +12,7 @@ import {
} from "../util.ts";
import type { GlobalContext } from "../main.ts";
import type { ConfigContext } from "../config.ts";
import type { AppDetail } from "./apps.ts";

interface Revision {
labels: Record<string, string>;
Expand All @@ -26,6 +27,93 @@ type Chunk = {
data: Uint8Array;
};

const DENO_JSON_NAMES = new Set(["deno.json", "deno.jsonc"]);

/**
* Normalizes an app's stored build directory as the console does: `.` and
* empty segments are dropped, and a path leaving the deploy root (which the
* console rejects) becomes the root, "".
*/
export function normalizeBuildDirectory(buildDirectory: string): string {
const segments = buildDirectory.split(/[\\/]/).filter((p) =>
p !== "" && p !== "."
);
return segments.includes("..") ? "" : segments.join("/");
}

/**
* The deno.json files to send with a CLI revision. The console reads the
* `deploy` section of the deno.json in the app's build directory, as it does
* for GitHub deployments, so it applies on every deploy rather than only when
* the app is created; it reads no other config, so only that directory's are
* sent. A config selected with `--config` stands in for it, and one the upload
* leaves out through `deploy.include`/`exclude` (e.g. `"include": ["dist/**"]`)
* still applies, so it is read from disk.
*/
export async function collectDenoJsonFiles(
{ rootPath, buildDirectory, uploaded, configPath }: {
rootPath: string;
/** The app's stored build directory, as stored. */
buildDirectory: string;
/** The uploaded deno.json/deno.jsonc files, by `/`-separated path. */
uploaded: Record<string, string>;
configPath?: string;
},
): Promise<Record<string, string>> {
const appDir = normalizeBuildDirectory(buildDirectory);
const prefix = appDir === "" ? "" : `${appDir}/`;
const files: Record<string, string> = {};
for (const name of DENO_JSON_NAMES) {
if (`${prefix}${name}` in uploaded) {
files[`${prefix}${name}`] = uploaded[`${prefix}${name}`];
}
}
if (configPath) {
delete files[`${prefix}deno.jsonc`];
files[`${prefix}deno.json`] = await Deno.readTextFile(configPath);
return files;
}
// Symlinks are resolved first, so that neither the app directory nor the
// config can point outside the deploy root.
const root = await Deno.realPath(rootPath);
for (const name of DENO_JSON_NAMES) {
if (`${prefix}${name}` in files) continue;
let path;
try {
path = await Deno.realPath(join(rootPath, appDir, name));
} catch (err) {
if (err instanceof Deno.errors.NotFound) continue;
throw err;
}
const fromRoot = relative(root, path);
if (
fromRoot === ".." || fromRoot.startsWith(`..${SEPARATOR}`) ||
isAbsolute(fromRoot)
) {
continue;
}
files[`${prefix}${name}`] = await Deno.readTextFile(path);
}
return files;
}

/**
* The app's stored build directory, as stored (see `normalizeBuildDirectory`).
* A failure here (e.g. a missing app) is reported and exits just as
* `apps.initiateCliRevision` would have.
*/
async function appBuildDirectory(
context: GlobalContext,
org: string,
app: string,
): Promise<string> {
const fullApp = await createTrpcClient(context).query("apps.get", {
org,
app,
}) as AppDetail;
return fullApp.build_config?.buildDirectory ?? "";
}

export async function publish(
context: GlobalContext,
configContext: ConfigContext,
Expand Down Expand Up @@ -83,13 +171,25 @@ export async function publish(
const [counter, body] = stream.tee();

const manifest: Record<string, string> = {};
const uploadedDenoJsonFiles: Record<string, string> = {};

spinner.message = "Generating hashes...";

for await (const { hash, relativePath } of counter) {
manifest[relativePath.replaceAll(SEPARATOR, "/")] = hash;
for await (const { hash, relativePath, data } of counter) {
const path = relativePath.replaceAll(SEPARATOR, "/");
manifest[path] = hash;
if (DENO_JSON_NAMES.has(path.slice(path.lastIndexOf("/") + 1))) {
uploadedDenoJsonFiles[path] = new TextDecoder().decode(data);
}
}

const denoJsonFiles = await collectDenoJsonFiles({
rootPath,
buildDirectory: await appBuildDirectory(context, org, app),
uploaded: uploadedDenoJsonFiles,
configPath: context.config,
});

if (context.debug) {
console.error("Manifest", manifest);
}
Expand All @@ -103,6 +203,7 @@ export async function publish(
app,
production: prod,
manifest,
denoJsonFiles,
},
) as string;

Expand Down
Loading
Loading