Merge pull request #14845 from Budibase/chore/allow-serving-old-apps-locally
Allow serving old apps on local dev
This commit is contained in:
commit
44fbe70740
|
@ -83,7 +83,7 @@ function getPackageJsonFields(): {
|
|||
if (isDev() && !isTest()) {
|
||||
try {
|
||||
const lerna = getParentFile("lerna.json")
|
||||
localVersion = lerna.version
|
||||
localVersion = `${lerna.version}+local`
|
||||
} catch {
|
||||
//
|
||||
}
|
||||
|
|
|
@ -2,11 +2,12 @@ import { InvalidFileExtensions } from "@budibase/shared-core"
|
|||
import AppComponent from "./templates/BudibaseApp.svelte"
|
||||
import { join } from "../../../utilities/centralPath"
|
||||
import * as uuid from "uuid"
|
||||
import { devClientVersion, ObjectStoreBuckets } from "../../../constants"
|
||||
import { ObjectStoreBuckets } from "../../../constants"
|
||||
import { processString } from "@budibase/string-templates"
|
||||
import {
|
||||
loadHandlebarsFile,
|
||||
NODE_MODULES_PATH,
|
||||
shouldServeLocally,
|
||||
TOP_LEVEL_PATH,
|
||||
} from "../../../utilities/fileSystem"
|
||||
import env from "../../../environment"
|
||||
|
@ -257,25 +258,29 @@ export const serveBuilderPreview = async function (ctx: Ctx) {
|
|||
export const serveClientLibrary = async function (ctx: Ctx) {
|
||||
const version = ctx.request.query.version
|
||||
|
||||
if (Array.isArray(version)) {
|
||||
ctx.throw(400)
|
||||
}
|
||||
|
||||
const appId = context.getAppId() || (ctx.request.query.appId as string)
|
||||
let rootPath = join(NODE_MODULES_PATH, "@budibase", "client", "dist")
|
||||
if (!appId) {
|
||||
ctx.throw(400, "No app ID provided - cannot fetch client library.")
|
||||
}
|
||||
if (env.isProd() || (env.isDev() && version !== devClientVersion)) {
|
||||
|
||||
const serveLocally = shouldServeLocally(version || "")
|
||||
if (!serveLocally) {
|
||||
ctx.body = await objectStore.getReadStream(
|
||||
ObjectStoreBuckets.APPS,
|
||||
objectStore.clientLibraryPath(appId!)
|
||||
)
|
||||
ctx.set("Content-Type", "application/javascript")
|
||||
} else if (env.isDev() && version === devClientVersion) {
|
||||
} else {
|
||||
// incase running from TS directly
|
||||
const tsPath = join(require.resolve("@budibase/client"), "..")
|
||||
return send(ctx, "budibase-client.js", {
|
||||
root: !fs.existsSync(rootPath) ? tsPath : rootPath,
|
||||
})
|
||||
} else {
|
||||
ctx.throw(500, "Unable to retrieve client library.")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -152,8 +152,6 @@ export enum AutomationErrors {
|
|||
FAILURE_CONDITION = "FAILURE_CONDITION_MET",
|
||||
}
|
||||
|
||||
export const devClientVersion = "0.0.0"
|
||||
|
||||
// pass through the list from the auth/core lib
|
||||
export const ObjectStoreBuckets = objectStore.ObjectStoreBuckets
|
||||
export const MAX_AUTOMATION_RECURRING_ERRORS = 5
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import { budibaseTempDir } from "../budibaseDir"
|
||||
import fs from "fs"
|
||||
import { join } from "path"
|
||||
import { ObjectStoreBuckets, devClientVersion } from "../../constants"
|
||||
import { updateClientLibrary } from "./clientLibrary"
|
||||
import { ObjectStoreBuckets } from "../../constants"
|
||||
import { shouldServeLocally, updateClientLibrary } from "./clientLibrary"
|
||||
import env from "../../environment"
|
||||
import { objectStore, context } from "@budibase/backend-core"
|
||||
import { TOP_LEVEL_PATH } from "./filesystem"
|
||||
|
@ -40,7 +40,7 @@ export const getComponentLibraryManifest = async (library: string) => {
|
|||
const db = context.getAppDB()
|
||||
const app = await db.get<App>(DocumentType.APP_METADATA)
|
||||
|
||||
if (app.version === devClientVersion || env.isTest()) {
|
||||
if (shouldServeLocally(app.version) || env.isTest()) {
|
||||
const paths = [
|
||||
join(TOP_LEVEL_PATH, "packages/client", filename),
|
||||
join(process.cwd(), "client", filename),
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import semver from "semver"
|
||||
import path, { join } from "path"
|
||||
import { ObjectStoreBuckets } from "../../constants"
|
||||
import fs from "fs"
|
||||
|
@ -183,3 +184,19 @@ export async function revertClientLibrary(appId: string) {
|
|||
|
||||
return JSON.parse(await manifestSrc)
|
||||
}
|
||||
|
||||
export function shouldServeLocally(version: string) {
|
||||
if (env.isProd() || !env.isDev()) {
|
||||
return false
|
||||
}
|
||||
|
||||
if (version === "0.0.0") {
|
||||
return true
|
||||
}
|
||||
|
||||
const parsedSemver = semver.parse(version)
|
||||
if (parsedSemver?.build?.[0] === "local") {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue