Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[now-build-utils] Exclude now.json from fallback build src #4042

Merged
merged 3 commits into from Apr 10, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion packages/now-build-utils/src/detect-builders.ts
Expand Up @@ -190,7 +190,12 @@ export async function detectBuilders(
hasNextApiFiles = true;
}

if (!fallbackEntrypoint && buildCommand && !fileName.includes('/')) {
if (
!fallbackEntrypoint &&
buildCommand &&
!fileName.includes('/') &&
fileName !== 'now.json'
) {
fallbackEntrypoint = fileName;
}
}
Expand Down
Expand Up @@ -7,6 +7,19 @@ import {
} from '../';

describe('Test `detectBuilders`', () => {
it('should never select now.json src', async () => {
const files = ['docs/index.md', 'mkdocs.yml', 'now.json'];
const { builders, errors } = await detectBuilders(files, null, {
projectSettings: {
buildCommand: 'mkdocs build',
outputDirectory: 'site',
},
});
expect(errors).toBe(null);
expect(builders).toBeDefined();
expect(builders![0].src).not.toBe('now.json');
});

it('package.json + no build', async () => {
const pkg = { dependencies: { next: '9.0.0' } };
const files = ['package.json', 'pages/index.js', 'public/index.html'];
Expand Down Expand Up @@ -817,6 +830,21 @@ describe('Test `detectBuilders`', () => {

describe('Test `detectBuilders` with `featHandleMiss=true`', () => {
const featHandleMiss = true;

it('should never select now.json src', async () => {
const files = ['docs/index.md', 'mkdocs.yml', 'now.json'];
const { builders, errors } = await detectBuilders(files, null, {
featHandleMiss,
projectSettings: {
buildCommand: 'mkdocs build',
outputDirectory: 'site',
},
});
expect(errors).toBe(null);
expect(builders).toBeDefined();
expect(builders![0].src).not.toBe('now.json');
});

it('package.json + no build', async () => {
const pkg = { dependencies: { next: '9.0.0' } };
const files = ['package.json', 'pages/index.js', 'public/index.html'];
Expand Down
2 changes: 0 additions & 2 deletions packages/now-build-utils/test/unit.walk.test.ts
Expand Up @@ -21,7 +21,6 @@ describe('Test `walkParentDirs`', () => {
await walkParentDirs({ base, start, filename });
fail('Expected error');
} catch (error) {
console.log(error);
deepEqual(
(error as Error).message,
'Expected "base" to be absolute path'
Expand All @@ -36,7 +35,6 @@ describe('Test `walkParentDirs`', () => {
await walkParentDirs({ base, start, filename });
fail('Expected error');
} catch (error) {
console.log(error);
deepEqual(
(error as Error).message,
'Expected "start" to be absolute path'
Expand Down