From 583d3a7acba6edcb5801972d2cc470f5cab0edde Mon Sep 17 00:00:00 2001 From: Ricardo Espinoza Date: Fri, 20 Sep 2024 10:38:52 -0400 Subject: [PATCH] refactor: Clean all instances of `isNpmAvailable` (#10891) --- .../@n8n/api-types/src/frontend-settings.ts | 1 - packages/cli/src/server.ts | 7 ------ packages/cli/src/services/frontend.service.ts | 1 - packages/editor-ui/src/Interface.ts | 2 -- packages/editor-ui/src/__tests__/defaults.ts | 1 - packages/editor-ui/src/constants.ts | 2 -- packages/editor-ui/src/stores/root.store.ts | 6 ----- .../editor-ui/src/stores/settings.store.ts | 4 --- .../src/views/SettingsCommunityNodesView.vue | 25 +++---------------- 9 files changed, 3 insertions(+), 46 deletions(-) diff --git a/packages/@n8n/api-types/src/frontend-settings.ts b/packages/@n8n/api-types/src/frontend-settings.ts index 8815f14f05..d50408bc3c 100644 --- a/packages/@n8n/api-types/src/frontend-settings.ts +++ b/packages/@n8n/api-types/src/frontend-settings.ts @@ -109,7 +109,6 @@ export interface FrontendSettings { deployment: { type: string; }; - isNpmAvailable: boolean; allowedModules: { builtIn?: string[]; external?: string[]; diff --git a/packages/cli/src/server.ts b/packages/cli/src/server.ts index 12bf5e6b40..08f74b2936 100644 --- a/packages/cli/src/server.ts +++ b/packages/cli/src/server.ts @@ -1,5 +1,4 @@ import type { FrontendSettings } from '@n8n/api-types'; -import { exec as callbackExec } from 'child_process'; import cookieParser from 'cookie-parser'; import express from 'express'; import { access as fsAccess } from 'fs/promises'; @@ -7,7 +6,6 @@ import helmet from 'helmet'; import { InstanceSettings } from 'n8n-core'; import { resolve } from 'path'; import { Container, Service } from 'typedi'; -import { promisify } from 'util'; import { AbstractServer } from '@/abstract-server'; import config from '@/config'; @@ -67,8 +65,6 @@ import '@/workflows/workflow-history/workflow-history.controller.ee'; import '@/workflows/workflows.controller'; import { EventService } from './events/event.service'; -const exec = promisify(callbackExec); - @Service() export class Server extends AbstractServer { private endpointPresetCredentials: string; @@ -174,9 +170,6 @@ export class Server extends AbstractServer { const { frontendService } = this; if (frontendService) { frontendService.addToSettings({ - isNpmAvailable: await exec('npm --version') - .then(() => true) - .catch(() => false), versionCli: N8N_VERSION, }); diff --git a/packages/cli/src/services/frontend.service.ts b/packages/cli/src/services/frontend.service.ts index 25758e9537..1693aa939a 100644 --- a/packages/cli/src/services/frontend.service.ts +++ b/packages/cli/src/services/frontend.service.ts @@ -170,7 +170,6 @@ export class FrontendService { deployment: { type: config.getEnv('deployment.type'), }, - isNpmAvailable: false, allowedModules: { builtIn: process.env.NODE_FUNCTION_ALLOW_BUILTIN?.split(',') ?? undefined, external: process.env.NODE_FUNCTION_ALLOW_EXTERNAL?.split(',') ?? undefined, diff --git a/packages/editor-ui/src/Interface.ts b/packages/editor-ui/src/Interface.ts index e8bc05bec9..f6587e8e3b 100644 --- a/packages/editor-ui/src/Interface.ts +++ b/packages/editor-ui/src/Interface.ts @@ -887,7 +887,6 @@ export interface RootState { urlBaseWebhook: string; urlBaseEditor: string; instanceId: string; - isNpmAvailable: boolean; binaryDataMode: 'default' | 'filesystem' | 's3'; } @@ -935,7 +934,6 @@ export interface IRootState { sidebarMenuItems: IMenuItem[]; instanceId: string; nodeMetadata: NodeMetadataMap; - isNpmAvailable: boolean; subworkflowExecutionError: Error | null; binaryDataMode: string; } diff --git a/packages/editor-ui/src/__tests__/defaults.ts b/packages/editor-ui/src/__tests__/defaults.ts index d2134ebf55..a8f6f6ca05 100644 --- a/packages/editor-ui/src/__tests__/defaults.ts +++ b/packages/editor-ui/src/__tests__/defaults.ts @@ -46,7 +46,6 @@ export const defaultSettings: FrontendSettings = { hideUsagePage: false, hiringBannerEnabled: false, instanceId: '', - isNpmAvailable: false, license: { environment: 'development', consumerId: 'unknown' }, logLevel: 'info', maxExecutionTimeout: 0, diff --git a/packages/editor-ui/src/constants.ts b/packages/editor-ui/src/constants.ts index 638675ca7c..c6acae7916 100644 --- a/packages/editor-ui/src/constants.ts +++ b/packages/editor-ui/src/constants.ts @@ -98,8 +98,6 @@ export const NPM_KEYWORD_SEARCH_URL = 'https://www.npmjs.com/search?q=keywords%3An8n-community-node-package'; export const N8N_QUEUE_MODE_DOCS_URL = `https://${DOCS_DOMAIN}/hosting/scaling/queue-mode/`; export const COMMUNITY_NODES_INSTALLATION_DOCS_URL = `https://${DOCS_DOMAIN}/integrations/community-nodes/installation/gui-install/`; -export const COMMUNITY_NODES_NPM_INSTALLATION_URL = - 'https://docs.npmjs.com/downloading-and-installing-node-js-and-npm'; export const COMMUNITY_NODES_RISKS_DOCS_URL = `https://${DOCS_DOMAIN}/integrations/community-nodes/risks/`; export const COMMUNITY_NODES_BLOCKLIST_DOCS_URL = `https://${DOCS_DOMAIN}/integrations/community-nodes/blocklist/`; export const CUSTOM_NODES_DOCS_URL = `https://${DOCS_DOMAIN}/integrations/creating-nodes/code/create-n8n-nodes-module/`; diff --git a/packages/editor-ui/src/stores/root.store.ts b/packages/editor-ui/src/stores/root.store.ts index 339b40dd41..be9ba9080c 100644 --- a/packages/editor-ui/src/stores/root.store.ts +++ b/packages/editor-ui/src/stores/root.store.ts @@ -29,7 +29,6 @@ export const useRootStore = defineStore(STORES.ROOT, () => { pushRef: randomString(10).toLowerCase(), urlBaseWebhook: 'http://localhost:5678/', urlBaseEditor: 'http://localhost:5678', - isNpmAvailable: false, instanceId: '', binaryDataMode: 'default', }); @@ -165,10 +164,6 @@ export const useRootStore = defineStore(STORES.ROOT, () => { state.value.defaultLocale = locale; }; - const setIsNpmAvailable = (isNpmAvailable: boolean) => { - state.value.isNpmAvailable = isNpmAvailable; - }; - const setBinaryDataMode = (binaryDataMode: string) => { state.value.binaryDataMode = binaryDataMode; }; @@ -213,7 +208,6 @@ export const useRootStore = defineStore(STORES.ROOT, () => { setOauthCallbackUrls, setN8nMetadata, setDefaultLocale, - setIsNpmAvailable, setBinaryDataMode, }; }); diff --git a/packages/editor-ui/src/stores/settings.store.ts b/packages/editor-ui/src/stores/settings.store.ts index d9601479d4..7a0cf1c2ab 100644 --- a/packages/editor-ui/src/stores/settings.store.ts +++ b/packages/editor-ui/src/stores/settings.store.ts @@ -128,8 +128,6 @@ export const useSettingsStore = defineStore(STORES.SETTINGS, () => { const isCommunityNodesFeatureEnabled = computed(() => settings.value.communityNodesEnabled); - const isNpmAvailable = computed(() => settings.value.isNpmAvailable); - const allowedModules = computed(() => settings.value.allowedModules); const isQueueModeEnabled = computed(() => settings.value.executionMode === 'queue'); @@ -245,7 +243,6 @@ export const useSettingsStore = defineStore(STORES.SETTINGS, () => { rootStore.setOauthCallbackUrls(fetchedSettings.oauthCallbackUrls); rootStore.setN8nMetadata(fetchedSettings.n8nMetadata || {}); rootStore.setDefaultLocale(fetchedSettings.defaultLocale); - rootStore.setIsNpmAvailable(fetchedSettings.isNpmAvailable); rootStore.setBinaryDataMode(fetchedSettings.binaryDataMode); useVersionsStore().setVersionNotificationSettings(fetchedSettings.versionNotifications); }; @@ -406,7 +403,6 @@ export const useSettingsStore = defineStore(STORES.SETTINGS, () => { templatesHost, pushBackend, isCommunityNodesFeatureEnabled, - isNpmAvailable, allowedModules, isQueueModeEnabled, isWorkerViewAvailable, diff --git a/packages/editor-ui/src/views/SettingsCommunityNodesView.vue b/packages/editor-ui/src/views/SettingsCommunityNodesView.vue index c443ad2e9a..0c0ceafbb1 100644 --- a/packages/editor-ui/src/views/SettingsCommunityNodesView.vue +++ b/packages/editor-ui/src/views/SettingsCommunityNodesView.vue @@ -2,7 +2,6 @@ import { COMMUNITY_PACKAGE_INSTALL_MODAL_KEY, COMMUNITY_NODES_INSTALLATION_DOCS_URL, - COMMUNITY_NODES_NPM_INSTALLATION_URL, } from '@/constants'; import CommunityPackageCard from '@/components/CommunityPackageCard.vue'; import { useToast } from '@/composables/useToast'; @@ -10,7 +9,6 @@ import type { PublicInstalledPackage } from 'n8n-workflow'; import { useCommunityNodesStore } from '@/stores/communityNodes.store'; import { useUIStore } from '@/stores/ui.store'; -import { useSettingsStore } from '@/stores/settings.store'; import { onBeforeUnmount, ref } from 'vue'; import { useExternalHooks } from '@/composables/useExternalHooks'; import { useRouter } from 'vue-router'; @@ -35,7 +33,6 @@ const telemetry = useTelemetry(); const toast = useToast(); const communityNodesStore = useCommunityNodesStore(); -const settingsStore = useSettingsStore(); const uiStore = useUIStore(); const getEmptyStateDescription = computed(() => { @@ -55,27 +52,11 @@ const getEmptyStateDescription = computed(() => { }); }); -const shouldShowInstallButton = computed(() => { - return settingsStore.isNpmAvailable; -}); - -const getEmptyStateButtonText = computed(() => { - return shouldShowInstallButton.value - ? i18n.baseText('settings.communityNodes.empty.installPackageLabel') - : ''; -}); +const getEmptyStateButtonText = computed(() => + i18n.baseText('settings.communityNodes.empty.installPackageLabel'), +); const actionBoxConfig = computed(() => { - if (!settingsStore.isNpmAvailable) { - return { - calloutText: i18n.baseText('settings.communityNodes.npmUnavailable.warning', { - interpolate: { npmUrl: COMMUNITY_NODES_NPM_INSTALLATION_URL }, - }), - calloutTheme: 'warning', - hideButton: true, - }; - } - return { calloutText: '', calloutTheme: '',