diff --git a/src/commands/dev/dev.ts b/src/commands/dev/dev.ts index 2d79832f92b..7381a4db93c 100644 --- a/src/commands/dev/dev.ts +++ b/src/commands/dev/dev.ts @@ -140,11 +140,14 @@ export const dev = async (options: OptionValues, command: BaseCommand) => { try { settings = await detectServerSettings(devConfig, options, command) - if (process.env.NETLIFY_INCLUDE_DEV_SERVER_PLUGIN) { + const { NETLIFY_INCLUDE_DEV_SERVER_PLUGIN } = process.env + + if (NETLIFY_INCLUDE_DEV_SERVER_PLUGIN) { + const plugins = NETLIFY_INCLUDE_DEV_SERVER_PLUGIN.split(',') if (options.debug) { - log(`${NETLIFYDEVLOG} Including dev server plugin: ${process.env.NETLIFY_INCLUDE_DEV_SERVER_PLUGIN}`) + log(`${NETLIFYDEVLOG} Including dev server plugins: ${NETLIFY_INCLUDE_DEV_SERVER_PLUGIN}`) } - settings.plugins = [...(settings.plugins || []), process.env.NETLIFY_INCLUDE_DEV_SERVER_PLUGIN] + settings.plugins = [...(settings.plugins || []), ...plugins] } cachedConfig.config = getConfigWithPlugins(cachedConfig.config, settings) diff --git a/tests/integration/commands/dev/dev.test.ts b/tests/integration/commands/dev/dev.test.ts index 08e48ee5d4a..95756d5f190 100644 --- a/tests/integration/commands/dev/dev.test.ts +++ b/tests/integration/commands/dev/dev.test.ts @@ -645,6 +645,48 @@ describe.concurrent('command/dev', () => { }) }, ) + + test('ensures installation of dev server plugins', async (t) => { + await withSiteBuilder(t, async (builder) => { + await builder + .withNetlifyToml({ + config: { + plugins: [{ package: '@netlify/plugin-1' }], + }, + }) + .withPackageJson({ + packageJson: { + dependencies: { + '@netlify/plugin-1': '^6.3.0', + '@netlify/plugin-2': '^6.3.0', + }, + }, + }) + .withMockPackage({ + name: '@netlify/plugin-1', + content: '', + }) + .withMockPackage({ + name: '@netlify/plugin-2', + content: '', + }) + .build() + + await withDevServer( + { + cwd: builder.directory, + env: { + NETLIFY_INCLUDE_DEV_SERVER_PLUGIN: '@netlify/plugin-1,@netlify/plugin-2', + }, + }, + async (server) => { + const output = server.outputBuffer.map((buff) => buff.toString()).join('\n') + t.expect(output).toContain('Server now ready') + t.expect(server.errorBuffer).toHaveLength(0) + }, + ) + }) + }) }) }) }) diff --git a/tests/integration/utils/site-builder.ts b/tests/integration/utils/site-builder.ts index b89b1597ac2..d8605776cd5 100644 --- a/tests/integration/utils/site-builder.ts +++ b/tests/integration/utils/site-builder.ts @@ -187,6 +187,18 @@ export class SiteBuilder { return this } + withMockPackage({ content, name }: { name: string; content: string }) { + const dir = path.join(this.directory, 'node_modules', name) + this.tasks.push(async () => { + await ensureDir(dir) + await writeFile(path.join(dir, 'index.js'), content) + await writeFile(path.join(dir, 'package.json'), '{}') + await writeFile(path.join(dir, 'manifest.yml'), `name: '${name}'`) + }) + + return this + } + withCopiedFile({ path: filePath, src }: { path: string; src: string }) { const dest = path.join(this.directory, filePath) this.tasks.push(async () => {