From e8eda7470a17deec1f5eab8cded6e74a8e3aee39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Ovejero?= Date: Wed, 3 Aug 2022 18:10:59 +0200 Subject: [PATCH] feat: Support community nodes on Windows (#3823) * :bug: Account for `APPDATA` in env * :bug: Prevent starter installation * :bug: Account for Win-style path delimiter * :shirt: Fix lint --- packages/cli/src/CommunityNodes/helpers.ts | 1 + packages/cli/src/LoadNodesAndCredentials.ts | 3 ++- packages/cli/src/api/nodes.api.ts | 17 ++++++++++++++++- packages/cli/src/constants.ts | 2 ++ 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/packages/cli/src/CommunityNodes/helpers.ts b/packages/cli/src/CommunityNodes/helpers.ts index b70546ec5cb78..5fb30eb200d8e 100644 --- a/packages/cli/src/CommunityNodes/helpers.ts +++ b/packages/cli/src/CommunityNodes/helpers.ts @@ -89,6 +89,7 @@ export const executeCommand = async ( env: { NODE_PATH: process.env.NODE_PATH, PATH: process.env.PATH, + APPDATA: process.env.APPDATA, }, }; diff --git a/packages/cli/src/LoadNodesAndCredentials.ts b/packages/cli/src/LoadNodesAndCredentials.ts index abc3d3b09293c..c561a14917909 100644 --- a/packages/cli/src/LoadNodesAndCredentials.ts +++ b/packages/cli/src/LoadNodesAndCredentials.ts @@ -64,7 +64,8 @@ class LoadNodesAndCredentialsClass { LoggerProxy.init(this.logger); // Make sure the imported modules can resolve dependencies fine. - process.env.NODE_PATH = module.paths.join(':'); + const delimiter = process.platform === 'win32' ? ';' : ':'; + process.env.NODE_PATH = module.paths.join(delimiter); // @ts-ignore module.constructor._initPaths(); diff --git a/packages/cli/src/api/nodes.api.ts b/packages/cli/src/api/nodes.api.ts index 7948489534a00..845cbc4c78e82 100644 --- a/packages/cli/src/api/nodes.api.ts +++ b/packages/cli/src/api/nodes.api.ts @@ -5,7 +5,11 @@ import { PublicInstalledPackage } from 'n8n-workflow'; import config from '../../config'; import { ResponseHelper, LoadNodesAndCredentials, Push, InternalHooksManager } from '..'; -import { RESPONSE_ERROR_MESSAGES, UNKNOWN_FAILURE_REASON } from '../constants'; +import { + RESPONSE_ERROR_MESSAGES, + UNKNOWN_FAILURE_REASON, + STARTER_TEMPLATE_NAME, +} from '../constants'; import { matchMissingPackages, matchPackagesWithUpdates, @@ -80,6 +84,17 @@ nodesController.post( ); } + if (parsed.packageName === STARTER_TEMPLATE_NAME) { + throw new ResponseHelper.ResponseError( + [ + `Package "${parsed.packageName}" is only a template`, + 'Please enter an actual package to install', + ].join('.'), + undefined, + 400, + ); + } + const isInstalled = await isPackageInstalled(parsed.packageName); const hasLoaded = hasPackageLoaded(name); diff --git a/packages/cli/src/constants.ts b/packages/cli/src/constants.ts index b6cd214f6210f..bd4047b0cef65 100644 --- a/packages/cli/src/constants.ts +++ b/packages/cli/src/constants.ts @@ -6,6 +6,8 @@ import { RESPONSE_ERROR_MESSAGES as CORE_RESPONSE_ERROR_MESSAGES } from 'n8n-cor export const NODE_PACKAGE_PREFIX = 'n8n-nodes-'; +export const STARTER_TEMPLATE_NAME = `${NODE_PACKAGE_PREFIX}starter`; + export const RESPONSE_ERROR_MESSAGES = { NO_CREDENTIAL: 'Credential not found', NO_ENCRYPTION_KEY: CORE_RESPONSE_ERROR_MESSAGES.NO_ENCRYPTION_KEY,