Skip to content

Commit 4ac2c5b

Browse files
jenae-janzenLukas Holzer
and
Lukas Holzer
authored
fix(config): ignores an empty config file path (#5037)
* fix(deps): check for config file path and add tests * fix(config): regenerate snapshots --------- Co-authored-by: Lukas Holzer <[email protected]>
1 parent a98aadc commit 4ac2c5b

File tree

13 files changed

+575
-11
lines changed

13 files changed

+575
-11
lines changed

package-lock.json

+8-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[build]
2+
command = "echo not party town"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[build]
2+
command = "echo 'party town'"

packages/build/tests/core/snapshots/tests.js.md

+101
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,107 @@ Generated by [AVA](https://avajs.dev).
175175
(Netlify Build completed in 1ms)␊
176176
Build step duration: Netlify Build completed in 1ms`
177177

178+
## nested --config
179+
180+
> Snapshot 1
181+
182+
`␊
183+
Netlify Build ␊
184+
────────────────────────────────────────────────────────────────␊
185+
186+
> Version␊
187+
@netlify/build 1.0.0␊
188+
189+
> Flags␊
190+
config: packages/build/tests/core/fixtures/toml/apps/nested/netlify.toml␊
191+
debug: true␊
192+
repositoryRoot: packages/build/tests/core/fixtures/toml␊
193+
testOpts:␊
194+
pluginsListUrl: test␊
195+
silentLingeringProcesses: true␊
196+
197+
> Current directory␊
198+
packages/build/tests/core/fixtures/toml␊
199+
200+
> Config file␊
201+
packages/build/tests/core/fixtures/toml/apps/nested/netlify.toml␊
202+
203+
> Resolved config␊
204+
build:␊
205+
command: echo not party town␊
206+
commandOrigin: config␊
207+
publish: packages/build/tests/core/fixtures/toml␊
208+
publishOrigin: default␊
209+
210+
> Context␊
211+
production␊
212+
213+
build.command from netlify.toml ␊
214+
────────────────────────────────────────────────────────────────␊
215+
216+
$ echo not party town␊
217+
not party town␊
218+
219+
(build.command completed in 1ms)␊
220+
Build step duration: build.command completed in 1ms␊
221+
222+
Netlify Build Complete ␊
223+
────────────────────────────────────────────────────────────────␊
224+
225+
(Netlify Build completed in 1ms)␊
226+
Build step duration: Netlify Build completed in 1ms`
227+
228+
## empty --config
229+
230+
> Snapshot 1
231+
232+
`␊
233+
Netlify Build ␊
234+
────────────────────────────────────────────────────────────────␊
235+
236+
> Version␊
237+
@netlify/build 1.0.0␊
238+
239+
> Flags␊
240+
cwd: packages/build/tests/core/fixtures/toml/apps/nested␊
241+
debug: true␊
242+
repositoryRoot: packages/build/tests/core/fixtures/toml␊
243+
testOpts:␊
244+
pluginsListUrl: test␊
245+
silentLingeringProcesses: true␊
246+
247+
> Current directory␊
248+
packages/build/tests/core/fixtures/toml/apps/nested␊
249+
250+
> Config file␊
251+
packages/build/tests/core/fixtures/toml/apps/nested/netlify.toml␊
252+
253+
> Resolved config␊
254+
build:␊
255+
base: packages/build/tests/core/fixtures/toml/apps/nested␊
256+
command: echo not party town␊
257+
commandOrigin: config␊
258+
publish: packages/build/tests/core/fixtures/toml/apps/nested␊
259+
publishOrigin: default␊
260+
261+
> Context␊
262+
production␊
263+
264+
build.command from netlify.toml ␊
265+
────────────────────────────────────────────────────────────────␊
266+
267+
$ echo not party town␊
268+
not party town␊
269+
270+
(build.command completed in 1ms)␊
271+
Build step duration: build.command completed in 1ms␊
272+
273+
Netlify Build Complete ␊
274+
────────────────────────────────────────────────────────────────␊
275+
276+
(Netlify Build completed in 1ms)␊
277+
Build step duration: Netlify Build completed in 1ms`
278+
178279
## --defaultConfig CLI flag
179280

180281
> Snapshot 1
138 Bytes
Binary file not shown.

packages/build/tests/core/tests.js

+14
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,20 @@ test('--config', async (t) => {
132132
t.snapshot(normalizeOutput(output))
133133
})
134134

135+
test('nested --config', async (t) => {
136+
const output = await new Fixture('./fixtures/toml')
137+
.withFlags({ config: `${FIXTURES_DIR}/toml/apps/nested/netlify.toml` })
138+
.runWithBuild()
139+
t.snapshot(normalizeOutput(output))
140+
})
141+
142+
test('empty --config', async (t) => {
143+
const output = await new Fixture('./fixtures/toml')
144+
.withFlags({ config: '', cwd: `${FIXTURES_DIR}/toml/apps/nested` })
145+
.runWithBuild()
146+
t.snapshot(normalizeOutput(output))
147+
})
148+
135149
test('--defaultConfig CLI flag', async (t) => {
136150
const { output } = await new Fixture('./fixtures/empty')
137151
.withFlags({

packages/config/src/main.js

-1
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,6 @@ const getFullConfig = async function ({
216216
featureFlags,
217217
}) {
218218
const configPath = await getConfigPath({ configOpt, cwd, repositoryRoot, configBase })
219-
220219
try {
221220
const config = await parseConfig(configPath)
222221
const configA = mergeAndNormalizeConfig({

packages/config/src/path.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export const getConfigPath = async function ({ configOpt, cwd, repositoryRoot, c
2626

2727
/** --config CLI flag */
2828
const searchConfigOpt = function (cwd: string, configOpt?: string) {
29-
if (configOpt === undefined) {
29+
if (configOpt === undefined || configOpt.length === 0) {
3030
return
3131
}
3232

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[build]
2+
command = "not party town"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[build]
2+
command = "party town"

0 commit comments

Comments
 (0)