Skip to content

Commit

Permalink
[cli] fail when local config is missing (#7516)
Browse files Browse the repository at this point in the history
Currently, when the path is not found in a `vc deploy -A SOME_PATH` command, the fallback config is used, which is unexpected behavior. This PR changes that to throw an error that says the path was not found.

---

Card: https://linear.app/vercel/issue/BUI-32/vc-deploy-a-should-fail-when-path-not-found
  • Loading branch information
EndangeredMassa committed Mar 4, 2022
1 parent c4ab0eb commit 1e54d60
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
11 changes: 7 additions & 4 deletions packages/cli/src/util/get-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,14 @@ export default async function getConfig(
if (localConfig instanceof CantParseJSONFile) {
return localConfig;
}
if (localConfig !== null) {
config = localConfig;
config[fileNameSymbol] = configFile;
return config;

if (localConfig === null) {
return new CantFindConfig([humanizePath(localFilePath)]);
}

config = localConfig;
config[fileNameSymbol] = configFile;
return config;
}

// Then try with `vercel.json` or `now.json` in the same directory
Expand Down
24 changes: 24 additions & 0 deletions packages/cli/test/integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,30 @@ test('deploy using --local-config flag v2', async t => {
t.is(anotherMainRes.status, 404, 'Should not deploy/build main now.json');
});

test('deploy fails using --local-config flag with non-existent path', async t => {
const target = fixture('local-config-v2');

const { exitCode, stderr, stdout } = await execa(
binaryPath,
[
'deploy',
target,
'--local-config',
'does-not-exist.json',
...defaultArgs,
'--confirm',
],
{
reject: false,
}
);

t.is(exitCode, 1, formatOutput({ stderr, stdout }));

t.regex(stderr, /Error! Couldn't find a project configuration file at/);
t.regex(stderr, /does-not-exist\.json/);
});

test('deploy using --local-config flag above target', async t => {
const root = fixture('local-config-above-target');
const target = path.join(root, 'dir');
Expand Down

0 comments on commit 1e54d60

Please sign in to comment.