From 52808ea460fb585609996b613c36c7779bfbdd50 Mon Sep 17 00:00:00 2001 From: Jan Oberhauser Date: Thu, 19 Sep 2019 13:21:10 +0200 Subject: [PATCH] :bug: Fix issue that reading version caused problems with build --- packages/cli/src/ActiveWorkflowRunner.ts | 1 - packages/cli/src/GenericHelpers.ts | 28 ++++++++++++++++++++++++ packages/cli/src/Interfaces.ts | 5 +++++ packages/cli/src/Server.ts | 14 +++++++----- packages/cli/tsconfig.json | 1 - 5 files changed, 42 insertions(+), 7 deletions(-) diff --git a/packages/cli/src/ActiveWorkflowRunner.ts b/packages/cli/src/ActiveWorkflowRunner.ts index a3b45adb2d..a1e4d41273 100644 --- a/packages/cli/src/ActiveWorkflowRunner.ts +++ b/packages/cli/src/ActiveWorkflowRunner.ts @@ -17,7 +17,6 @@ import { ActiveWorkflows, ActiveWebhooks, NodeExecuteFunctions, - WorkflowExecute, } from 'n8n-core'; import { diff --git a/packages/cli/src/GenericHelpers.ts b/packages/cli/src/GenericHelpers.ts index 53cbcefc6d..aea159302d 100644 --- a/packages/cli/src/GenericHelpers.ts +++ b/packages/cli/src/GenericHelpers.ts @@ -1,13 +1,19 @@ import * as config from '../config'; import * as express from 'express'; +import { join as pathJoin } from 'path'; import { readFile as fsReadFile, } from 'fs'; import { promisify } from "util"; import { IDataObject } from 'n8n-workflow'; +import { IPackageVersions } from './'; + const fsReadFileAsync = promisify(fsReadFile); +let versionCache: IPackageVersions | undefined; + + /** * Displays a message to the user * @@ -54,6 +60,28 @@ export function getSessionId(req: express.Request): string | undefined { } +/** + * Returns information which version of the packages are installed + * + * @export + * @returns {Promise} + */ +export async function getVersions(): Promise { + if (versionCache !== undefined) { + return versionCache; + } + + const packageFile = await fsReadFileAsync(pathJoin(__dirname, '../../package.json'), 'utf8') as string; + const packageData = JSON.parse(packageFile); + + versionCache = { + cli: packageData.version, + }; + + return versionCache; +} + + /** * Gets value from config with support for "_FILE" environment variables * diff --git a/packages/cli/src/Interfaces.ts b/packages/cli/src/Interfaces.ts index 1dfe02c2c8..5e5e32730d 100644 --- a/packages/cli/src/Interfaces.ts +++ b/packages/cli/src/Interfaces.ts @@ -259,6 +259,11 @@ export interface IN8nUISettings { } +export interface IPackageVersions { + cli: string; +} + + export interface IPushData { data: IPushDataExecutionFinished | IPushDataNodeExecuteAfter | IPushDataNodeExecuteBefore | IPushDataTestWebhook; type: IPushDataType; diff --git a/packages/cli/src/Server.ts b/packages/cli/src/Server.ts index e3490e0f49..e38573fec0 100644 --- a/packages/cli/src/Server.ts +++ b/packages/cli/src/Server.ts @@ -6,7 +6,6 @@ import { import * as bodyParser from 'body-parser'; import * as history from 'connect-history-api-fallback'; import * as requestPromise from 'request-promise-native'; -import { version as versionCli } from '../package.json'; import { ActiveExecutions, @@ -28,6 +27,7 @@ import { IExecutionsStopData, IExecutionsSummary, IN8nUISettings, + IPackageVersions, IWorkflowBase, IWorkflowShortResponse, IWorkflowResponse, @@ -74,7 +74,6 @@ import * as config from '../config'; // @ts-ignore import * as timezones from 'google-timezones-json'; import * as parseUrl from 'parseurl'; -import { version } from '@oclif/command/lib/flags'; class App { @@ -90,6 +89,7 @@ class App { timezone: string; activeExecutionsInstance: ActiveExecutions.ActiveExecutions; push: Push.Push; + versions: IPackageVersions | undefined; constructor() { this.app = express(); @@ -122,6 +122,8 @@ class App { async config(): Promise { + this.versions = await GenericHelpers.getVersions(); + // Check for basic auth credentials if activated const basicAuthActive = config.get('security.basicAuth.active') as boolean; if (basicAuthActive === true) { @@ -1005,7 +1007,7 @@ class App { saveManualExecutions: this.saveManualExecutions, timezone: this.timezone, urlBaseWebhook: WebhookHelpers.getWebhookBaseUrl(), - versionCli, + versionCli: this.versions!.cli, }; })); @@ -1118,7 +1120,9 @@ export async function start(): Promise { await app.config(); - app.app.listen(PORT, () => { - console.log('n8n ready on port ' + PORT); + app.app.listen(PORT, async () => { + const versions = await GenericHelpers.getVersions(); + console.log(`n8n ready on port ${PORT}`); + console.log(`Version: ${versions.cli}`); }); } diff --git a/packages/cli/tsconfig.json b/packages/cli/tsconfig.json index a4f672cecd..4aaf4747fc 100644 --- a/packages/cli/tsconfig.json +++ b/packages/cli/tsconfig.json @@ -14,7 +14,6 @@ "forceConsistentCasingInFileNames": true, "noImplicitReturns": true, "preserveConstEnums": true, - "resolveJsonModule": true, "declaration": true, "outDir": "./dist/", "target": "es2017",