fix: make cli backcompatible with respect to lockfile

This commit is contained in:
Ruben Fiszel
2024-01-18 09:01:04 +01:00
parent 36905daef6
commit eb000f1fbc
3 changed files with 61 additions and 28 deletions
+15 -12
View File
@@ -95,16 +95,7 @@ export async function requireLogin(
}
}
export async function tryResolveVersion(
opts: GlobalOptions
): Promise<number | undefined> {
if ((opts as any).__cache_version) {
return (opts as any).__cache_version;
}
const workspaceRes = await tryResolveWorkspace(opts);
if (workspaceRes.isError) return undefined;
export async function fetchVersion(baseUrl: string): Promise<string> {
const requestHeaders: HeadersInit = new Headers();
const extraHeaders = getHeaders();
@@ -115,10 +106,22 @@ export async function tryResolveVersion(
}
const response = await fetch(
new URL(new URL(workspaceRes.value.remote).origin + "/api/version"),
new URL(new URL(baseUrl).origin + "/api/version"),
{ headers: requestHeaders, method: "GET" }
);
const version = await response.text();
return await response.text();
}
export async function tryResolveVersion(
opts: GlobalOptions
): Promise<number | undefined> {
if ((opts as any).__cache_version) {
return (opts as any).__cache_version;
}
const workspaceRes = await tryResolveWorkspace(opts);
if (workspaceRes.isError) return undefined;
const version = await fetchVersion(workspaceRes.value.remote);
try {
return Number.parseInt(
version.split("-", 1)[0].replaceAll(".", "").replace("v", "")
+24 -12
View File
@@ -67,18 +67,26 @@ async function push(opts: PushOptions, filePath: string) {
}
await requireLogin(opts);
await handleFile(filePath, workspace.workspaceId, []);
await handleFile(filePath, workspace.workspaceId, [], undefined, false);
log.info(colors.bold.underline.green(`Script ${filePath} pushed`));
}
export async function handleScriptMetadata(
path: string,
workspace: string,
alreadySynced: string[]
alreadySynced: string[],
message: string | undefined,
lockfileUseArray: boolean
): Promise<boolean> {
if (path.endsWith(".script.json") || path.endsWith(".script.yaml")) {
const contentPath = await findContentFile(path);
return handleFile(contentPath, workspace, alreadySynced);
return handleFile(
contentPath,
workspace,
alreadySynced,
message,
lockfileUseArray
);
} else {
return false;
}
@@ -98,8 +106,12 @@ async function parseMetadataFile(
try {
metadataFilePath = scriptPath + ".script.yaml";
await Deno.stat(metadataFilePath);
let payload: any = yamlParse(await Deno.readTextFile(metadataFilePath));
if (Array.isArray(payload?.["lock"])) {
payload = payload["lock"].join("\n");
}
return {
payload: yamlParse(await Deno.readTextFile(metadataFilePath)),
payload,
isJson: false,
};
} catch {
@@ -124,7 +136,8 @@ export async function handleFile(
path: string,
workspace: string,
alreadySynced: string[],
message?: string
message: string | undefined,
lockfileUseArray: boolean
): Promise<boolean> {
if (
!path.includes(".inline_script.") &&
@@ -169,11 +182,10 @@ export async function handleFile(
(typed.is_template ?? false) === (remote.is_template ?? false) &&
typed.kind == remote.kind &&
!remote.archived &&
(remote?.lock ?? "").trim() ==
(Array.isArray(typed.lock)
? typed.lock.join("\n")
: typed?.lock ?? ""
).trim() &&
(Array.isArray(remote?.lock)
? remote?.lock?.join("\n")
: remote?.lock ?? ""
).trim() == (typed?.lock ?? "").trim() &&
deepEqual(typed.schema, remote.schema) &&
typed.tag == remote.tag &&
(typed.ws_error_handler_muted ?? false) ==
@@ -202,7 +214,7 @@ export async function handleFile(
summary: typed?.summary ?? "",
is_template: typed?.is_template,
kind: typed?.kind,
lock: typed?.lock,
lock: lockfileUseArray ? typed?.lock.split("\n") : typed?.lock,
parent_hash: remote.hash,
schema: typed?.schema,
tag: typed?.tag,
@@ -229,7 +241,7 @@ export async function handleFile(
summary: typed?.summary ?? "",
is_template: typed?.is_template,
kind: typed?.kind,
lock: typed?.lock,
lock: lockfileUseArray ? typed?.lock.split("\n") : typed?.lock,
parent_hash: undefined,
schema: typed?.schema,
tag: typed?.tag,
+22 -4
View File
@@ -1,4 +1,4 @@
import { requireLogin, resolveWorkspace } from "./context.ts";
import { fetchVersion, requireLogin, resolveWorkspace } from "./context.ts";
import {
colors,
Command,
@@ -710,6 +710,19 @@ async function push(
opts
);
const version = await fetchVersion(workspace.remote);
log.info(colors.gray("Remote version: " + version));
const reducedVersion = version
.split(" v")[1]
.split("-")[0]
.split(".")
.map((v) => parseInt(v));
const lockfileUseArray =
reducedVersion[1] < 246 ||
reducedVersion[1] == 246 ||
reducedVersion[2] < 5;
log.info(
`remote (${workspace.name}) <- local: ${changes.length} changes to apply`
);
@@ -726,6 +739,7 @@ async function push(
return;
}
log.info(colors.gray(`Applying changes to files ...`));
const alreadySynced: string[] = [];
for await (const change of changes) {
const stateTarget = path.join(Deno.cwd(), ".wmill", change.path);
@@ -741,7 +755,9 @@ async function push(
await handleScriptMetadata(
change.path,
workspace.workspaceId,
alreadySynced
alreadySynced,
opts.message,
lockfileUseArray
)
) {
if (!opts.raw && stateExists) {
@@ -753,7 +769,8 @@ async function push(
change.path,
workspace.workspaceId,
alreadySynced,
opts.message
opts.message,
lockfileUseArray
)
) {
if (!opts.raw && stateExists) {
@@ -791,7 +808,8 @@ async function push(
change.path,
workspace.workspaceId,
alreadySynced,
opts.message
opts.message,
lockfileUseArray
)
) {
continue;