Skip to content

Commit

Permalink
[now-build-utils] Fix api directory detection (#3647)
Browse files Browse the repository at this point in the history
There was an issue where `@now/next` was emitting an api directory with serverless functions but the functions should not be renamed.
  • Loading branch information
styfle authored and kodiakhq[bot] committed Jan 23, 2020
1 parent 8ff747b commit a80a1d0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
6 changes: 4 additions & 2 deletions packages/now-build-utils/src/detect-routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,10 @@ export function detectOutputDirectory(builders: Builder[]): string | null {
export function detectApiDirectory(builders: Builder[]): string | null {
// TODO: We eventually want to save the api directory to
// builder.config.apiDirectory so it is only detected once
const isZeroConfig = builders.some(b => b.config && b.config.zeroConfig);
return isZeroConfig ? 'api' : null;
const found = builders.some(
b => b.config && b.config.zeroConfig && b.src.startsWith('api/')
);
return found ? 'api' : null;
}

export async function detectRoutes(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1877,6 +1877,18 @@ describe('Test `detectApiDirectory`', () => {
const result = detectApiDirectory(builders);
expect(result).toBe('api');
});

it('should be `null` with zero config but without api directory', async () => {
const builders = [
{
use: '@now/next',
src: 'package.json',
config: { zeroConfig: true },
},
];
const result = detectApiDirectory(builders);
expect(result).toBe(null);
});
});

/**
Expand Down

1 comment on commit a80a1d0

@vercel
Copy link

@vercel vercel bot commented on a80a1d0 Jan 23, 2020

Choose a reason for hiding this comment

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

Please sign in to comment.