Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(dev): update dev server plugin env variable to be an array of pl… #6811

Merged
merged 1 commit into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how are we verifying that @netlify/plugin-2 plugin is also included?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If some plugin is not there, the tests are failing

},
},
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
Loading