Skip to content

Commit

Permalink
feat(dev): update dev server plugin env variable to be an array of pl…
Browse files Browse the repository at this point in the history
…ugins
  • Loading branch information
VitaliyR committed Sep 9, 2024
1 parent 4d1a481 commit f0357e1
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/commands/dev/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
42 changes: 42 additions & 0 deletions tests/integration/commands/dev/dev.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
},
)
})
})
})
})
})
12 changes: 12 additions & 0 deletions tests/integration/utils/site-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down

0 comments on commit f0357e1

Please sign in to comment.