From 1610ab4d2331f618d427d507e9521b6cd158b613 Mon Sep 17 00:00:00 2001 From: Simon Knott Date: Wed, 15 Nov 2023 16:47:37 +0100 Subject: [PATCH] refactor: extract isTrustedPlugin --- packages/build/src/plugins/spawn.ts | 7 +++---- packages/build/src/steps/plugin.js | 6 +++--- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/packages/build/src/plugins/spawn.ts b/packages/build/src/plugins/spawn.ts index 516fceea98..eb6f430e68 100644 --- a/packages/build/src/plugins/spawn.ts +++ b/packages/build/src/plugins/spawn.ts @@ -10,6 +10,7 @@ import { logIncompatiblePlugins, logLoadingIntegration, } from '../log/messages/compatibility.js' +import { isTrustedPlugin } from '../steps/plugin.js' import { measureDuration } from '../time/main.js' import { getEventFromChild } from './ipc.js' @@ -44,9 +45,6 @@ const tStartPlugins = async function ({ pluginsOptions, buildDir, childEnv, logs export const startPlugins = measureDuration(tStartPlugins, 'start_plugins') const startPlugin = async function ({ pluginDir, nodePath, buildDir, childEnv, systemLogFile, pluginPackageJson }) { - // todo: extract this into a function that's shared with the feature flag impl - const isTrustedPlugin = pluginPackageJson?.name?.startsWith('@netlify/') - const childProcess = execaNode(CHILD_MAIN_FILE, [], { cwd: buildDir, preferLocal: true, @@ -55,7 +53,8 @@ const startPlugin = async function ({ pluginDir, nodePath, buildDir, childEnv, s execPath: nodePath, env: childEnv, extendEnv: false, - stdio: isTrustedPlugin && systemLogFile ? ['pipe', 'pipe', 'pipe', 'ipc', systemLogFile] : undefined, + stdio: + isTrustedPlugin(pluginPackageJson) && systemLogFile ? ['pipe', 'pipe', 'pipe', 'ipc', systemLogFile] : undefined, }) try { diff --git a/packages/build/src/steps/plugin.js b/packages/build/src/steps/plugin.js index e34dd98d81..4d9efef0d9 100644 --- a/packages/build/src/steps/plugin.js +++ b/packages/build/src/steps/plugin.js @@ -7,6 +7,8 @@ import { getSuccessStatus } from '../status/success.js' import { getPluginErrorType } from './error.js' import { updateNetlifyConfig, listConfigSideFiles } from './update_config.js' +export const isTrustedPlugin = (pluginPackageJson) => pluginPackageJson?.name?.startsWith('@netlify/') + // Fire a plugin step export const firePluginStep = async function ({ event, @@ -33,8 +35,6 @@ export const firePluginStep = async function ({ }) { const listeners = pipePluginOutput(childProcess, logs) - const isTrustedPlugin = pluginPackageJson?.name?.startsWith('@netlify/') - try { const configSideFiles = await listConfigSideFiles([headersPath, redirectsPath]) const { @@ -48,7 +48,7 @@ export const firePluginStep = async function ({ event, error, envChanges, - featureFlags: isTrustedPlugin ? featureFlags : undefined, + featureFlags: isTrustedPlugin(pluginPackageJson) ? featureFlags : undefined, netlifyConfig, constants, },