Skip to content

Commit

Permalink
refactor: extract isTrustedPlugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Skn0tt committed Nov 15, 2023
1 parent 9217662 commit 1610ab4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
7 changes: 3 additions & 4 deletions packages/build/src/plugins/spawn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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,
Expand All @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions packages/build/src/steps/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 {
Expand All @@ -48,7 +48,7 @@ export const firePluginStep = async function ({
event,
error,
envChanges,
featureFlags: isTrustedPlugin ? featureFlags : undefined,
featureFlags: isTrustedPlugin(pluginPackageJson) ? featureFlags : undefined,
netlifyConfig,
constants,
},
Expand Down

0 comments on commit 1610ab4

Please sign in to comment.