Skip to content

Commit e466c3c

Browse files
committed
fix: pass config object to devCommand step handler
1 parent e5de855 commit e466c3c

File tree

5 files changed

+23
-4
lines changed

5 files changed

+23
-4
lines changed

packages/build/src/steps/get.ts

Lines changed: 4 additions & 2 deletions
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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Snapshot report for `tests/plugins_events/tests.js`
1+
# Snapshot report for `packages/build/tests/plugins_events/tests.js`
22

33
The actual snapshot is saved in `tests.js.snap`.
44

@@ -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

Lines changed: 14 additions & 0 deletions
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)