1
0
Fork 0
mirror of synced 2024-07-04 22:11:23 +12:00

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() {
return isCypress() || isJest()
}
@ -45,6 +47,35 @@ function httpLogging() {
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 = {
isTest,
isJest,
@ -122,6 +153,7 @@ const environment = {
ENABLE_SSO_MAINTENANCE_MODE: selfHosted
? process.env.ENABLE_SSO_MAINTENANCE_MODE
: false,
VERSION: findVersion(),
_set(key: any, value: any) {
process.env[key] = value
// @ts-ignore

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -4,7 +4,7 @@ import { checkSlashesInUrl } from "../../utilities"
import { request } from "../../utilities/workerRequests"
import { clearLock as redisClearLock } from "../../utilities/redis"
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"
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) {
const version = require("../../../package.json").version
const version = envCore.VERSION
ctx.body = {
version,
}

View file

@ -1,9 +1,8 @@
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 zlib from "zlib"
import { mainRoutes, staticRoutes, publicRoutes } from "./routes"
import pkg from "../../package.json"
import { middleware as pro } from "@budibase/pro"
export { shutdown } from "./routes/public"
const compress = require("koa-compress")
@ -11,7 +10,7 @@ const compress = require("koa-compress")
export const router: Router = new Router()
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)

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -16,7 +16,7 @@
"@budibase/types": ["../packages/types/src"],
"@budibase/backend-core": ["../packages/backend-core/src"],
"@budibase/backend-core/*": ["../packages/backend-core/*"],
"@budibase/server/*": ["../packages/server/src/*"],
"@budibase/server/*": ["../packages/server/src/*"]
}
},
"ts-node": {
@ -24,14 +24,8 @@
},
"references": [
{ "path": "../packages/types" },
{ "path": "../packages/backend-core" },
{ "path": "../packages/backend-core" }
],
"include": [
"src/**/*",
"package.json"
],
"exclude": [
"node_modules",
"dist"
]
}
"include": ["src/**/*"],
"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"
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":
version "0.9.190"
resolved "https://registry.yarnpkg.com/@budibase/bbui/-/bbui-0.9.190.tgz#e1ec400ac90f556bfbc80fc23a04506f1585ea81"
@ -1486,15 +1525,15 @@
pouchdb-promise "^6.0.4"
through2 "^2.0.0"
"@budibase/pro@2.5.6-alpha.19":
version "2.5.6-alpha.19"
resolved "https://registry.yarnpkg.com/@budibase/pro/-/pro-2.5.6-alpha.19.tgz#447019502a3e7dfbd0c946c1bca3e9df9518a748"
integrity sha512-bpKp0bms/XtU093RXYVmldzlsudD1+3g0yprsB6X0wYMJOhedGfAPLrPThSNTYQzC8Ed7YTC9beTryXRyCjNNw==
"@budibase/pro@2.5.6-alpha.20":
version "2.5.6-alpha.20"
resolved "https://registry.yarnpkg.com/@budibase/pro/-/pro-2.5.6-alpha.20.tgz#c0fcd2e96847b83509773575caccb55d12cb7097"
integrity sha512-2OlGwsph3f+yqjIg+OWai2rqQlF++eiBIjPnRMnOzp1hboURu+5tkxOC8ctnhqjD3PD/P18up+lP6RBRz6XdVA==
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/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"
bull "4.10.1"
joi "17.6.0"
@ -1547,6 +1586,13 @@
resolved "https://registry.yarnpkg.com/@budibase/types/-/types-2.4.44-alpha.1.tgz#1679657aa180d9c59afa1dffa611bff0638bd933"
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":
version "3.7.0"
resolved "https://registry.yarnpkg.com/@bull-board/api/-/api-3.7.0.tgz#231f687187c0cb34e0b97f463917b6aaeb4ef6af"