Skip to content

Commit e234d01

Browse files
authoredFeb 20, 2025··
fix: pass config object to devCommand step handler (#6095)
1 parent e5de855 commit e234d01

File tree

5 files changed

+22
-3
lines changed

5 files changed

+22
-3
lines changed
 

‎packages/build/src/steps/get.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@ export const getSteps = function (steps, eventHandlers?: any[]) {
2828
export const getDevSteps = function (command, steps, eventHandlers?: any[]) {
2929
const devCommandStep = {
3030
event: 'onDev',
31-
coreStep: async () => {
32-
await command()
31+
coreStep: async (args) => {
32+
const { constants, event } = args
33+
const utils = getUtils({ event, constants, runState: {} })
34+
await command({ utils, ...args })
3335

3436
return {}
3537
},

‎packages/build/tests/plugins_events/fixtures/dev_and_build/plugin.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
export const onPreDev = function ({ constants }) {
1+
export const onPreDev = function ({ constants, netlifyConfig }) {
22
console.log('onPreDev:', constants)
3+
netlifyConfig.build.environment.TEST_ASSIGN = 'true';
34
}
45

56
export const onDev = function ({ constants }) {

‎packages/build/tests/plugins_events/snapshots/tests.js.md

+2
Original file line numberDiff line numberDiff line change
@@ -1518,6 +1518,7 @@ Generated by [AVA](https://avajs.dev).
15181518
INTERNAL_EDGE_FUNCTIONS_SRC: '.netlify/edge-functions',␊
15191519
PUBLISH_DIR: '.'␊
15201520
}␊
1521+
Netlify configuration property "build.environment.TEST_ASSIGN" value changed.␊
15211522
15221523
(./plugin.js onPreDev completed in 1ms)␊
15231524
@@ -1555,6 +1556,7 @@ Generated by [AVA](https://avajs.dev).
15551556
INTERNAL_EDGE_FUNCTIONS_SRC: '.netlify/edge-functions',␊
15561557
PUBLISH_DIR: '.'␊
15571558
}␊
1559+
Netlify configuration property "build.environment.TEST_ASSIGN" value changed.␊
15581560
onDev: {␊
15591561
CONFIG_PATH: 'netlify.toml',␊
15601562
FUNCTIONS_DIST: '.netlify/functions/',␊
Binary file not shown.

‎packages/build/tests/plugins_events/tests.js

+14
Original file line numberDiff line numberDiff line change
@@ -134,3 +134,17 @@ test('Shows error information in the `startDev` entrypoint even when `quiet: tru
134134

135135
t.is(devCommand.callCount, 0)
136136
})
137+
138+
test('Passes plugin options into dev command', async (t) => {
139+
const devCommand = sinon.stub().resolves()
140+
141+
await new Fixture('./fixtures/dev_and_build')
142+
.withFlags({ debug: false, quiet: true, timeline: 'dev' })
143+
.runDev(devCommand)
144+
145+
t.is(devCommand.callCount, 1)
146+
t.truthy(devCommand.lastCall.args[0])
147+
t.truthy(devCommand.lastCall.args[0].netlifyConfig)
148+
t.truthy(devCommand.lastCall.args[0].childEnv.TEST_ASSIGN)
149+
console.log(devCommand.lastCall.args[0].childEnv)
150+
})

0 commit comments

Comments
 (0)
Please sign in to comment.