Merge pull request #10324 from Budibase/chore/remove_package.json_dependency

Chore - Remove package.json dependency
This commit is contained in:
Adria Navarro 2023-04-24 19:34:15 +02:00 committed by GitHub
commit 640bb2004b
18 changed files with 122 additions and 74 deletions

View File

@ -1,3 +1,5 @@
import { existsSync, readFileSync } from "fs"
function isTest() { function isTest() {
return isCypress() || isJest() return isCypress() || isJest()
} }
@ -45,6 +47,35 @@ function httpLogging() {
return process.env.HTTP_LOGGING return process.env.HTTP_LOGGING
} }
function findVersion() {
function findFileInAncestors(
fileName: string,
currentDir: string
): string | null {
const filePath = `${currentDir}/${fileName}`
if (existsSync(filePath)) {
return filePath
}
const parentDir = `${currentDir}/..`
if (parentDir === currentDir) {
// reached root directory
return null
}
return findFileInAncestors(fileName, parentDir)
}
try {
const packageJsonFile = findFileInAncestors("package.json", process.cwd())
const content = readFileSync(packageJsonFile!, "utf-8")
const version = JSON.parse(content).version
return version
} catch {
throw new Error("Cannot find a valid version in its package.json")
}
}
const environment = { const environment = {
isTest, isTest,
isJest, isJest,
@ -122,6 +153,7 @@ const environment = {
ENABLE_SSO_MAINTENANCE_MODE: selfHosted ENABLE_SSO_MAINTENANCE_MODE: selfHosted
? process.env.ENABLE_SSO_MAINTENANCE_MODE ? process.env.ENABLE_SSO_MAINTENANCE_MODE
: false, : false,
VERSION: findVersion(),
_set(key: any, value: any) { _set(key: any, value: any) {
process.env[key] = value process.env[key] = value
// @ts-ignore // @ts-ignore

View File

@ -23,8 +23,6 @@ import * as installation from "../installation"
import * as configs from "../configs" import * as configs from "../configs"
import { withCache, TTL, CacheKey } from "../cache/generic" import { withCache, TTL, CacheKey } from "../cache/generic"
const pkg = require("../../package.json")
/** /**
* An identity can be: * An identity can be:
* - account user (Self host) * - account user (Self host)
@ -102,7 +100,7 @@ const identifyInstallationGroup = async (
const id = installId const id = installId
const type = IdentityType.INSTALLATION const type = IdentityType.INSTALLATION
const hosting = getHostingFromEnv() const hosting = getHostingFromEnv()
const version = pkg.version const version = env.VERSION
const environment = getDeploymentEnvironment() const environment = getDeploymentEnvironment()
const group: InstallationGroup = { const group: InstallationGroup = {

View File

@ -4,7 +4,6 @@ import { EventProcessor } from "../types"
import env from "../../../environment" import env from "../../../environment"
import * as context from "../../../context" import * as context from "../../../context"
import * as rateLimiting from "./rateLimiting" import * as rateLimiting from "./rateLimiting"
const pkg = require("../../../../package.json")
const EXCLUDED_EVENTS: Event[] = [ const EXCLUDED_EVENTS: Event[] = [
Event.USER_UPDATED, Event.USER_UPDATED,
@ -49,7 +48,7 @@ export default class PosthogProcessor implements EventProcessor {
properties = this.clearPIIProperties(properties) properties = this.clearPIIProperties(properties)
properties.version = pkg.version properties.version = env.VERSION
properties.service = env.SERVICE properties.service = env.SERVICE
properties.environment = identity.environment properties.environment = identity.environment
properties.hosting = identity.hosting properties.hosting = identity.hosting

View File

@ -6,8 +6,7 @@ import { Installation, IdentityType, Database } from "@budibase/types"
import * as context from "./context" import * as context from "./context"
import semver from "semver" import semver from "semver"
import { bustCache, withCache, TTL, CacheKey } from "./cache/generic" import { bustCache, withCache, TTL, CacheKey } from "./cache/generic"
import environment from "./environment"
const pkg = require("../package.json")
export const getInstall = async (): Promise<Installation> => { export const getInstall = async (): Promise<Installation> => {
return withCache(CacheKey.INSTALLATION, TTL.ONE_DAY, getInstallFromDB, { return withCache(CacheKey.INSTALLATION, TTL.ONE_DAY, getInstallFromDB, {
@ -18,7 +17,7 @@ async function createInstallDoc(platformDb: Database) {
const install: Installation = { const install: Installation = {
_id: StaticDatabases.PLATFORM_INFO.docs.install, _id: StaticDatabases.PLATFORM_INFO.docs.install,
installId: newid(), installId: newid(),
version: pkg.version, version: environment.VERSION,
} }
try { try {
const resp = await platformDb.put(install) const resp = await platformDb.put(install)
@ -80,7 +79,7 @@ export const checkInstallVersion = async (): Promise<void> => {
const install = await getInstall() const install = await getInstall()
const currentVersion = install.version const currentVersion = install.version
const newVersion = pkg.version const newVersion = environment.VERSION
if (currentVersion !== newVersion) { if (currentVersion !== newVersion) {
const isUpgrade = semver.gt(newVersion, currentVersion) const isUpgrade = semver.gt(newVersion, currentVersion)

View File

@ -10,15 +10,11 @@
"incremental": true, "incremental": true,
"sourceMap": true, "sourceMap": true,
"declaration": true, "declaration": true,
"types": [ "node", "jest" ], "types": ["node", "jest"],
"outDir": "dist", "outDir": "dist",
"skipLibCheck": true "skipLibCheck": true
}, },
"include": [ "include": ["**/*.js", "**/*.ts"],
"**/*.js",
"**/*.ts",
"package.json"
],
"exclude": [ "exclude": [
"node_modules", "node_modules",
"dist", "dist",
@ -26,4 +22,4 @@
"**/*.spec.js", "**/*.spec.js",
"__mocks__" "__mocks__"
] ]
} }

View File

@ -3,17 +3,17 @@ import { logging } from "@budibase/backend-core"
logging.disableLogger() logging.disableLogger()
import "./prebuilds" import "./prebuilds"
import "./environment" import "./environment"
import { env } from "@budibase/backend-core"
import { getCommands } from "./options" import { getCommands } from "./options"
import { Command } from "commander" import { Command } from "commander"
import { getHelpDescription } from "./utils" import { getHelpDescription } from "./utils"
const json = require("../package.json")
// add hosting config // add hosting config
async function init() { async function init() {
const program = new Command() const program = new Command()
.addHelpCommand("help", getHelpDescription("Help with Budibase commands.")) .addHelpCommand("help", getHelpDescription("Help with Budibase commands."))
.helpOption(false) .helpOption(false)
.version(json.version) .version(env.VERSION)
// add commands // add commands
for (let command of getCommands()) { for (let command of getCommands()) {
command.configure(program) command.configure(program)

View File

@ -8,23 +8,14 @@
"paths": { "paths": {
"@budibase/types": ["../types/src"], "@budibase/types": ["../types/src"],
"@budibase/backend-core": ["../backend-core/src"], "@budibase/backend-core": ["../backend-core/src"],
"@budibase/backend-core/*": ["../backend-core/*"], "@budibase/backend-core/*": ["../backend-core/*"]
} }
}, },
"ts-node": { "ts-node": {
"require": ["tsconfig-paths/register"], "require": ["tsconfig-paths/register"],
"swc": true "swc": true
}, },
"references": [ "references": [{ "path": "../types" }, { "path": "../backend-core" }],
{ "path": "../types" }, "include": ["src/**/*"],
{ "path": "../backend-core" }, "exclude": ["node_modules", "dist"]
], }
"include": [
"src/**/*",
"package.json"
],
"exclude": [
"node_modules",
"dist"
]
}

View File

@ -1,5 +1,4 @@
import env from "../../environment" import env from "../../environment"
import packageJson from "../../../package.json"
import { import {
createLinkView, createLinkView,
createRoutingView, createRoutingView,
@ -24,6 +23,7 @@ import {
migrations, migrations,
objectStore, objectStore,
ErrorCode, ErrorCode,
env as envCore,
} from "@budibase/backend-core" } from "@budibase/backend-core"
import { USERS_TABLE_SCHEMA } from "../../constants" import { USERS_TABLE_SCHEMA } from "../../constants"
import { buildDefaultDocs } from "../../db/defaultData/datasource_bb_default" import { buildDefaultDocs } from "../../db/defaultData/datasource_bb_default"
@ -264,7 +264,7 @@ async function performAppCreate(ctx: UserCtx) {
_rev: undefined, _rev: undefined,
appId, appId,
type: "app", type: "app",
version: packageJson.version, version: envCore.VERSION,
componentLibraries: ["@budibase/standard-components"], componentLibraries: ["@budibase/standard-components"],
name: name, name: name,
url: url, url: url,
@ -433,7 +433,7 @@ export async function updateClient(ctx: UserCtx) {
} }
// Update versions in app package // Update versions in app package
const updatedToVersion = packageJson.version const updatedToVersion = envCore.VERSION
const appPackageUpdates = { const appPackageUpdates = {
version: updatedToVersion, version: updatedToVersion,
revertableVersion: currentVersion, revertableVersion: currentVersion,

View File

@ -4,7 +4,7 @@ import { checkSlashesInUrl } from "../../utilities"
import { request } from "../../utilities/workerRequests" import { request } from "../../utilities/workerRequests"
import { clearLock as redisClearLock } from "../../utilities/redis" import { clearLock as redisClearLock } from "../../utilities/redis"
import { DocumentType } from "../../db/utils" import { DocumentType } from "../../db/utils"
import { context } from "@budibase/backend-core" import { context, env as envCore } from "@budibase/backend-core"
import { events, db as dbCore, cache } from "@budibase/backend-core" import { events, db as dbCore, cache } from "@budibase/backend-core"
async function redirect(ctx: any, method: string, path: string = "global") { async function redirect(ctx: any, method: string, path: string = "global") {
@ -121,7 +121,7 @@ export async function revert(ctx: any) {
} }
export async function getBudibaseVersion(ctx: any) { export async function getBudibaseVersion(ctx: any) {
const version = require("../../../package.json").version const version = envCore.VERSION
ctx.body = { ctx.body = {
version, version,
} }

View File

@ -1,9 +1,8 @@
import Router from "@koa/router" import Router from "@koa/router"
import { auth, middleware } from "@budibase/backend-core" import { auth, middleware, env as envCore } from "@budibase/backend-core"
import currentApp from "../middleware/currentapp" import currentApp from "../middleware/currentapp"
import zlib from "zlib" import zlib from "zlib"
import { mainRoutes, staticRoutes, publicRoutes } from "./routes" import { mainRoutes, staticRoutes, publicRoutes } from "./routes"
import pkg from "../../package.json"
import { middleware as pro } from "@budibase/pro" import { middleware as pro } from "@budibase/pro"
export { shutdown } from "./routes/public" export { shutdown } from "./routes/public"
const compress = require("koa-compress") const compress = require("koa-compress")
@ -11,7 +10,7 @@ const compress = require("koa-compress")
export const router: Router = new Router() export const router: Router = new Router()
router.get("/health", ctx => (ctx.status = 200)) router.get("/health", ctx => (ctx.status = 200))
router.get("/version", ctx => (ctx.body = pkg.version)) router.get("/version", ctx => (ctx.body = envCore.VERSION))
router.use(middleware.errorHandling) router.use(middleware.errorHandling)

View File

@ -8,13 +8,11 @@
"esModuleInterop": true, "esModuleInterop": true,
"resolveJsonModule": true, "resolveJsonModule": true,
"incremental": true, "incremental": true,
"types": [ "node", "jest" ], "types": ["node", "jest"],
"outDir": "dist", "outDir": "dist/src",
"skipLibCheck": true "skipLibCheck": true
}, },
"include": [ "include": ["src/**/*"],
"src/**/*"
],
"exclude": [ "exclude": [
"node_modules", "node_modules",
"dist", "dist",

View File

@ -5,6 +5,7 @@
"declaration": true, "declaration": true,
"sourceMap": true, "sourceMap": true,
"baseUrl": ".", "baseUrl": ".",
"outDir": "dist",
"paths": { "paths": {
"@budibase/types": ["../types/src"], "@budibase/types": ["../types/src"],
"@budibase/backend-core": ["../backend-core/src"], "@budibase/backend-core": ["../backend-core/src"],
@ -23,6 +24,6 @@
{ "path": "../shared-core" }, { "path": "../shared-core" },
{ "path": "../../../budibase-pro/packages/pro" } { "path": "../../../budibase-pro/packages/pro" }
], ],
"include": ["src/**/*", "specs", "package.json"], "include": ["src/**/*", "specs"],
"exclude": ["node_modules", "dist"] "exclude": ["node_modules", "dist"]
} }

View File

@ -14,7 +14,7 @@
"outDir": "dist", "outDir": "dist",
"skipLibCheck": true "skipLibCheck": true
}, },
"include": ["**/*.js", "**/*.ts", "package.json"], "include": ["**/*.js", "**/*.ts"],
"exclude": [ "exclude": [
"node_modules", "node_modules",
"dist", "dist",

View File

@ -2,7 +2,7 @@
"extends": "./tsconfig-base.build.json", "extends": "./tsconfig-base.build.json",
"compilerOptions": { "compilerOptions": {
"module": "commonjs", "module": "commonjs",
"outDir": "dist/cjs", "outDir": "dist/cjs/src",
"target": "es2015" "target": "es2015"
} }
} }

View File

@ -2,7 +2,7 @@
"extends": "./tsconfig-base.build.json", "extends": "./tsconfig-base.build.json",
"compilerOptions": { "compilerOptions": {
"module": "esnext", "module": "esnext",
"outDir": "dist/mjs", "outDir": "dist/mjs/src",
"target": "esnext" "target": "esnext"
} }
} }

View File

@ -21,11 +21,6 @@
{ "path": "../backend-core" }, { "path": "../backend-core" },
{ "path": "../../../budibase-pro/packages/pro" } { "path": "../../../budibase-pro/packages/pro" }
], ],
"include": [ "include": ["src/**/*"],
"src/**/*", "exclude": ["dist"]
"package.json" }
],
"exclude": [
"dist"
]
}

View File

@ -16,7 +16,7 @@
"@budibase/types": ["../packages/types/src"], "@budibase/types": ["../packages/types/src"],
"@budibase/backend-core": ["../packages/backend-core/src"], "@budibase/backend-core": ["../packages/backend-core/src"],
"@budibase/backend-core/*": ["../packages/backend-core/*"], "@budibase/backend-core/*": ["../packages/backend-core/*"],
"@budibase/server/*": ["../packages/server/src/*"], "@budibase/server/*": ["../packages/server/src/*"]
} }
}, },
"ts-node": { "ts-node": {
@ -24,14 +24,8 @@
}, },
"references": [ "references": [
{ "path": "../packages/types" }, { "path": "../packages/types" },
{ "path": "../packages/backend-core" }, { "path": "../packages/backend-core" }
], ],
"include": [ "include": ["src/**/*"],
"src/**/*", "exclude": ["node_modules", "dist"]
"package.json" }
],
"exclude": [
"node_modules",
"dist"
]
}

View File

@ -1386,6 +1386,45 @@
resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39" resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39"
integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw== integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==
"@budibase/backend-core@2.5.6-alpha.20":
version "2.5.6-alpha.20"
resolved "https://registry.yarnpkg.com/@budibase/backend-core/-/backend-core-2.5.6-alpha.20.tgz#6c651cb7bc18cd6bc5fcdfdcae23a9413b0e44c5"
integrity sha512-zShGSvWajARe5MpIE+b+ZzqLzRpG4iylPbT692QnZ23Iia6Iz320H3UfrsiM3eQlVCc71Hh2+wcxSsFuNBqEvg==
dependencies:
"@budibase/nano" "10.1.2"
"@budibase/pouchdb-replication-stream" "1.2.10"
"@budibase/types" "2.5.6-alpha.20"
"@shopify/jest-koa-mocks" "5.0.1"
"@techpass/passport-openidconnect" "0.3.2"
aws-cloudfront-sign "2.2.0"
aws-sdk "2.1030.0"
bcrypt "5.0.1"
bcryptjs "2.4.3"
bull "4.10.1"
correlation-id "4.0.0"
dotenv "16.0.1"
emitter-listener "1.1.2"
ioredis "4.28.0"
joi "17.6.0"
jsonwebtoken "9.0.0"
koa-passport "4.1.4"
koa-pino-logger "4.0.0"
lodash "4.17.21"
lodash.isarguments "3.1.0"
node-fetch "2.6.7"
passport-google-oauth "2.0.0"
passport-jwt "4.0.0"
passport-local "1.0.0"
passport-oauth2-refresh "^2.1.0"
posthog-node "1.3.0"
pouchdb "7.3.0"
pouchdb-find "7.2.2"
redlock "4.2.0"
sanitize-s3-objectkey "0.0.1"
semver "7.3.7"
tar-fs "2.1.1"
uuid "8.3.2"
"@budibase/bbui@^0.9.139": "@budibase/bbui@^0.9.139":
version "0.9.190" version "0.9.190"
resolved "https://registry.yarnpkg.com/@budibase/bbui/-/bbui-0.9.190.tgz#e1ec400ac90f556bfbc80fc23a04506f1585ea81" resolved "https://registry.yarnpkg.com/@budibase/bbui/-/bbui-0.9.190.tgz#e1ec400ac90f556bfbc80fc23a04506f1585ea81"
@ -1486,15 +1525,15 @@
pouchdb-promise "^6.0.4" pouchdb-promise "^6.0.4"
through2 "^2.0.0" through2 "^2.0.0"
"@budibase/pro@2.5.6-alpha.19": "@budibase/pro@2.5.6-alpha.20":
version "2.5.6-alpha.19" version "2.5.6-alpha.20"
resolved "https://registry.yarnpkg.com/@budibase/pro/-/pro-2.5.6-alpha.19.tgz#447019502a3e7dfbd0c946c1bca3e9df9518a748" resolved "https://registry.yarnpkg.com/@budibase/pro/-/pro-2.5.6-alpha.20.tgz#c0fcd2e96847b83509773575caccb55d12cb7097"
integrity sha512-bpKp0bms/XtU093RXYVmldzlsudD1+3g0yprsB6X0wYMJOhedGfAPLrPThSNTYQzC8Ed7YTC9beTryXRyCjNNw== integrity sha512-2OlGwsph3f+yqjIg+OWai2rqQlF++eiBIjPnRMnOzp1hboURu+5tkxOC8ctnhqjD3PD/P18up+lP6RBRz6XdVA==
dependencies: dependencies:
"@budibase/backend-core" "2.5.6-alpha.19" "@budibase/backend-core" "2.5.6-alpha.20"
"@budibase/shared-core" "2.4.44-alpha.1" "@budibase/shared-core" "2.4.44-alpha.1"
"@budibase/string-templates" "2.4.44-alpha.1" "@budibase/string-templates" "2.4.44-alpha.1"
"@budibase/types" "2.5.6-alpha.19" "@budibase/types" "2.5.6-alpha.20"
"@koa/router" "8.0.8" "@koa/router" "8.0.8"
bull "4.10.1" bull "4.10.1"
joi "17.6.0" joi "17.6.0"
@ -1547,6 +1586,13 @@
resolved "https://registry.yarnpkg.com/@budibase/types/-/types-2.4.44-alpha.1.tgz#1679657aa180d9c59afa1dffa611bff0638bd933" resolved "https://registry.yarnpkg.com/@budibase/types/-/types-2.4.44-alpha.1.tgz#1679657aa180d9c59afa1dffa611bff0638bd933"
integrity sha512-Sq+8HfM75EBMoOvKYFwELdlxmVN6wNZMofDjT/2G+9aF+Zfe5Tzw69C+unmdBgcGGjGCHEYWSz4mF0v8FPAGbg== integrity sha512-Sq+8HfM75EBMoOvKYFwELdlxmVN6wNZMofDjT/2G+9aF+Zfe5Tzw69C+unmdBgcGGjGCHEYWSz4mF0v8FPAGbg==
"@budibase/types@2.5.6-alpha.20":
version "2.5.6-alpha.20"
resolved "https://registry.yarnpkg.com/@budibase/types/-/types-2.5.6-alpha.20.tgz#f2e44c873c5a7998f7011b1bb0c245c5af14b409"
integrity sha512-UEV++5bMHcH+0j9oI8R//7xoDDvv08cmSaZ9++/64cYSkjxQPDfsCmbQxztFHXZvDaZxu/LlCR4erT2gqJx1bA==
dependencies:
scim-patch "^0.7.0"
"@bull-board/api@3.7.0": "@bull-board/api@3.7.0":
version "3.7.0" version "3.7.0"
resolved "https://registry.yarnpkg.com/@bull-board/api/-/api-3.7.0.tgz#231f687187c0cb34e0b97f463917b6aaeb4ef6af" resolved "https://registry.yarnpkg.com/@bull-board/api/-/api-3.7.0.tgz#231f687187c0cb34e0b97f463917b6aaeb4ef6af"