fix(cli): push workspace deps doesn't depend on wmill-locks

This commit is contained in:
Ruben Fiszel
2025-12-23 16:38:46 +00:00
parent 95790313d3
commit 1c0889b3dc
+49 -35
View File
@@ -4,16 +4,14 @@ import { resolveWorkspace } from "../../core/context.ts";
import { GlobalOptions } from "../../types.ts";
import { colors, Command, log } from "../../../deps.ts";
import * as wmill from "../../../gen/services.gen.ts";
import type { ScriptLang } from "../../../gen/types.gen.ts";
import fs from "node:fs";
import { generateHash } from "../../utils/utils.ts";
import { checkifMetadataUptodate, updateMetadataGlobalLock, workspaceDependenciesPathToLanguageAndFilename } from "../../utils/metadata.ts";
import { workspaceDependenciesPathToLanguageAndFilename } from "../../utils/metadata.ts";
async function push(
opts: GlobalOptions,
filePath: string,
language?: ScriptLang,
name?: string
name?: string,
): Promise<void> {
const workspace = await resolveWorkspace(opts);
await requireLogin(opts);
@@ -25,24 +23,26 @@ async function push(
const content = fs.readFileSync(filePath, "utf8");
// Use the existing pushWorkspaceDependencies function
await pushWorkspaceDependencies(workspace.workspaceId, filePath, null, content);
await pushWorkspaceDependencies(
workspace.workspaceId,
filePath,
null,
content,
);
}
const command = new Command()
.alias("deps")
.description("workspace dependencies related commands")
.command(
"push",
"Push workspace dependencies from a local file"
)
.command("push", "Push workspace dependencies from a local file")
.arguments("<file_path:string>")
.option(
"--language <language:string>",
"Programming language (python3, typescript, go, php). If not specified, will be inferred from file extension."
"Programming language (python3, typescript, go, php). If not specified, will be inferred from file extension.",
)
.option(
"--name <name:string>",
"Name for the dependencies. If not specified, creates workspace default dependencies."
"Name for the dependencies. If not specified, creates workspace default dependencies.",
)
.action(push as any);
@@ -50,34 +50,48 @@ export async function pushWorkspaceDependencies(
workspace: string,
path: string,
_befObj: any,
newDependenciesContent: string
newDependenciesContent: string,
): Promise<void> {
try {
let res = workspaceDependenciesPathToLanguageAndFilename(path);
if (!res) {
throw new Error(`Unknown workspace dependencies file format: ${path}`);
}
let {
language,
name
} = res;
let { language, name } = res;
// TODO: include workspace?
// Generate hash for workspace dependencies content and metadata
const contentHash = await generateHash(newDependenciesContent + path);
const displayName = name
? `named dependencies "${name}"`
: `workspace default dependencies`;
// Check if dependencies are up-to-date using wmill-lock.yaml tracking
const isUpToDate = await checkifMetadataUptodate(path, contentHash, undefined);
// Fetch remote workspace dependencies and compare content directly
try {
const remoteDeps = await wmill.getLatestWorkspaceDependencies({
workspace,
language,
name,
});
if (isUpToDate) {
const displayName = name ? `named dependencies "${name}"` : `workspace default dependencies`;
log.info(colors.green(`${displayName} for ${language} are up-to-date, skipping push`));
return;
if (remoteDeps && remoteDeps.content === newDependenciesContent) {
log.info(
colors.green(
`${displayName} for ${language} are up-to-date, skipping push`,
),
);
return;
}
} catch (e: any) {
// If 404 or not found, the dependency doesn't exist remotely yet - proceed with push
if (e.status !== 404 && !e.message?.includes("not found")) {
throw e;
}
}
log.info(colors.yellow(`Pushing ${name ? 'named' : 'workspace default'} dependencies for ${language}...`));
log.info(
colors.yellow(
`Pushing ${name ? "named" : "workspace default"} dependencies for ${language}...`,
),
);
await wmill.createWorkspaceDependencies({
workspace,
@@ -87,17 +101,17 @@ export async function pushWorkspaceDependencies(
language,
workspace_id: workspace,
// Description is not supported in cli, it will use old description
description: undefined
}
description: undefined,
},
});
// Update wmill-lock.yaml with new hash after successful push
await updateMetadataGlobalLock(path, contentHash);
const displayName = name ? `named dependencies "${name}"` : `workspace default dependencies`;
log.info(colors.green(`Successfully pushed ${displayName} for ${language}`));
log.info(
colors.green(`Successfully pushed ${displayName} for ${language}`),
);
} catch (error: any) {
log.error(colors.red(`Failed to push workspace dependencies: ${error.message}`));
log.error(
colors.red(`Failed to push workspace dependencies: ${error.message}`),
);
throw error;
}
}