Skip to content

Commit

Permalink
[now-build-utils] Exclude now.json from fallback build src (#4042)
Browse files Browse the repository at this point in the history
  • Loading branch information
styfle committed Apr 10, 2020
1 parent 3af0e99 commit 7ca672a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
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

0 comments on commit 7ca672a

Please sign in to comment.