Skip to content

Commit d31bb06

Browse files
committed
[release] Search multiple anchors for --deployFunctions source dirs
A relative --functionPath was previously folded into fn.dirPath and resolved only against the loaded config's directory, so callers whose config lives in a nested folder (e.g. packages/shared/.appwrite/) couldn't pass a path relative to their repo root. The override is now decoupled from dirPath and the resolver tries every sensible anchor (cwd, the config dir, the appwrite sidecar folder) for any relative source string, taking the first existing match. Behavior for absolute paths and the name-based fallbacks is unchanged, and config-declared dirPaths still resolve via their original anchor — the new behavior is a strict superset.
1 parent 2cb0161 commit d31bb06

2 files changed

Lines changed: 30 additions & 10 deletions

File tree

packages/appwrite-utils-cli/src/cli/commands/deployFunctionsFlow.ts

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,18 +82,34 @@ function resolveFunctionSourceDirectory(
8282
fn: AppwriteFunction,
8383
yamlBaseDir: string,
8484
appwriteFolderPath: string | undefined,
85-
cwd: string
85+
cwd: string,
86+
cliFunctionPath?: string
8687
): string | null {
8788
const nameLower = fn.name.toLowerCase().replace(/\s+/g, "-");
8889

8990
const candidates: string[] = [];
9091

91-
if (fn.dirPath) {
92-
const expanded = expandTilde(fn.dirPath);
93-
candidates.push(
94-
isAbsolute(expanded) ? expanded : resolvePath(yamlBaseDir, expanded)
95-
);
96-
}
92+
// Push every sensible anchoring for a user-supplied source string. Absolute
93+
// strings push themselves only; relative strings are tried against cwd,
94+
// yamlBaseDir, and the appwrite sidecar folder so a missing anchor doesn't
95+
// strand the lookup.
96+
const pushAnchored = (s: string) => {
97+
const expanded = expandTilde(s);
98+
if (isAbsolute(expanded)) {
99+
candidates.push(expanded);
100+
return;
101+
}
102+
candidates.push(resolvePath(cwd, expanded));
103+
candidates.push(resolvePath(yamlBaseDir, expanded));
104+
if (appwriteFolderPath) {
105+
candidates.push(resolvePath(appwriteFolderPath, expanded));
106+
}
107+
};
108+
109+
// CLI override wins over the config-declared dirPath when both are set.
110+
if (cliFunctionPath) pushAnchored(cliFunctionPath);
111+
if (fn.dirPath) pushAnchored(fn.dirPath);
112+
97113
if (appwriteFolderPath) {
98114
candidates.push(join(appwriteFolderPath, "functions", nameLower));
99115
candidates.push(join(appwriteFolderPath, "functions", fn.name));
@@ -154,7 +170,10 @@ function applyOverrides(
154170
overrides: DeployFunctionFieldOverrides
155171
): AppwriteFunction {
156172
const next: AppwriteFunction = { ...base };
157-
if (overrides.path !== undefined) next.dirPath = expandTilde(overrides.path);
173+
// overrides.path is intentionally NOT merged into next.dirPath here.
174+
// It's passed separately to resolveFunctionSourceDirectory so a relative
175+
// CLI --functionPath is anchored against cwd first (and other anchors as
176+
// fallbacks), independent of how a config-declared dirPath resolves.
158177
if (overrides.name !== undefined) next.name = overrides.name;
159178
if (overrides.runtime !== undefined) next.runtime = overrides.runtime as any;
160179
if (overrides.entrypoint !== undefined) next.entrypoint = overrides.entrypoint;
@@ -308,7 +327,8 @@ export async function runDeployFunctionsFlow(
308327
fn,
309328
yamlBaseDir,
310329
appwriteFolderPath,
311-
cwd
330+
cwd,
331+
opts.overrides?.path
312332
);
313333
if (!dir) {
314334
MessageFormatter.warning(

packages/appwrite-utils-cli/src/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,7 @@ const argv = yargs(hideBin(process.argv))
624624
alias: ["function-path", "fnPath"],
625625
type: "string",
626626
description:
627-
"Override source directory for the resolved function. With --functionId and no .fnconfig.yaml entry, the function is fetched from the server and deployed from this path; if the server doesn't have that $id, the deploy errors with 'Function not found'.",
627+
"Source directory for the resolved function. Relative paths are searched against cwd, the loaded config's directory, and the appwrite sidecar folder; first existing match wins. With --functionId and no .fnconfig.yaml entry, the function is fetched from the server and deployed from this path; if the server doesn't have that $id, the deploy errors with 'Function not found'.",
628628
})
629629
.option("functionName", {
630630
alias: ["function-name"],

0 commit comments

Comments
 (0)