Skip to content

Commit

Permalink
feat: Support community nodes on Windows (#3823)
Browse files Browse the repository at this point in the history
* 🐛 Account for `APPDATA` in env

* 🐛 Prevent starter installation

* 🐛 Account for Win-style path delimiter

* 👕 Fix lint
  • Loading branch information
ivov authored Aug 3, 2022
1 parent 74cedd9 commit e8eda74
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/cli/src/CommunityNodes/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ export const executeCommand = async (
env: {
NODE_PATH: process.env.NODE_PATH,
PATH: process.env.PATH,
APPDATA: process.env.APPDATA,
},
};

Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/LoadNodesAndCredentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
17 changes: 16 additions & 1 deletion packages/cli/src/api/nodes.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);

Expand Down
2 changes: 2 additions & 0 deletions packages/cli/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit e8eda74

Please sign in to comment.