mirror of
https://github.com/LukeHagar/vercel.git
synced 2025-12-10 04:22:12 +00:00
[@now/build-utils] Add support for includeFiles and excludeFiles to Functions (#3285)
Add support for `includeFiles` and `excludeFiles` to Functions. [PRODUCT-27] [PRODUCT-27]: https://zeit.atlassian.net/browse/PRODUCT-27
This commit is contained in:
@@ -83,6 +83,11 @@ function getApiFunctionBuilder(
|
||||
});
|
||||
}
|
||||
|
||||
const { includeFiles, excludeFiles } = fn;
|
||||
|
||||
if (includeFiles) Object.assign(config, { includeFiles });
|
||||
if (excludeFiles) Object.assign(config, { excludeFiles });
|
||||
|
||||
return use ? { use, src, config } : prevBuilder;
|
||||
}
|
||||
|
||||
@@ -308,6 +313,24 @@ function validateFunctions(files: string[], { functions = {} }: Options) {
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
if (func.includeFiles !== undefined) {
|
||||
if (typeof func.includeFiles !== 'string') {
|
||||
return {
|
||||
code: 'invalid_function_property',
|
||||
message: `The property \`includeFiles\` must be a string.`
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
if (func.excludeFiles !== undefined) {
|
||||
if (typeof func.excludeFiles !== 'string') {
|
||||
return {
|
||||
code: 'invalid_function_property',
|
||||
message: `The property \`excludeFiles\` must be a string.`
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
@@ -316,5 +316,7 @@ export interface BuilderFunctions {
|
||||
memory?: number;
|
||||
maxDuration?: number;
|
||||
runtime?: string;
|
||||
includeFiles?: string;
|
||||
excludeFiles?: string;
|
||||
};
|
||||
}
|
||||
|
||||
79
packages/now-build-utils/test/unit.test.js
vendored
79
packages/now-build-utils/test/unit.test.js
vendored
@@ -634,6 +634,85 @@ describe('Test `detectBuilders`', () => {
|
||||
expect(errors).toBeDefined();
|
||||
expect(errors[0].code).toBe('invalid_function_runtime');
|
||||
});
|
||||
|
||||
it('Must include includeFiles config property', async () => {
|
||||
const functions = {
|
||||
'api/test.js': { includeFiles: 'text/include.txt' }
|
||||
}
|
||||
const files = ['api/test.js'];
|
||||
|
||||
const { builders, errors } = await detectBuilders(files, null, { functions });
|
||||
|
||||
expect(errors).toBe(null);
|
||||
expect(builders).not.toBe(null);
|
||||
expect(builders[0].use).toBe('@now/node');
|
||||
expect(builders[0].config).toMatchObject({
|
||||
functions,
|
||||
zeroConfig: true,
|
||||
includeFiles: 'text/include.txt'
|
||||
});
|
||||
});
|
||||
|
||||
it('Must include excludeFiles config property', async () => {
|
||||
const functions = {
|
||||
'api/test.js': { excludeFiles: 'text/exclude.txt' }
|
||||
}
|
||||
const files = ['api/test.js'];
|
||||
|
||||
const { builders, errors } = await detectBuilders(files, null, { functions });
|
||||
|
||||
expect(errors).toBe(null);
|
||||
expect(builders).not.toBe(null);
|
||||
expect(builders[0].use).toBe('@now/node');
|
||||
expect(builders[0].config).toMatchObject({
|
||||
functions,
|
||||
zeroConfig: true,
|
||||
excludeFiles: 'text/exclude.txt'
|
||||
});
|
||||
});
|
||||
|
||||
it('Must include excludeFiles and includeFiles config property', async () => {
|
||||
const functions = {
|
||||
'api/test.js': { excludeFiles: 'text/exclude.txt', includeFiles: 'text/include.txt' }
|
||||
}
|
||||
const files = ['api/test.js'];
|
||||
|
||||
const { builders, errors } = await detectBuilders(files, null, { functions });
|
||||
|
||||
expect(errors).toBe(null);
|
||||
expect(builders).not.toBe(null);
|
||||
expect(builders[0].use).toBe('@now/node');
|
||||
expect(builders[0].config).toMatchObject({
|
||||
functions,
|
||||
zeroConfig: true,
|
||||
excludeFiles: 'text/exclude.txt',
|
||||
includeFiles: 'text/include.txt'
|
||||
});
|
||||
});
|
||||
|
||||
it('Must fail for includeFiles config property', async () => {
|
||||
const functions = {
|
||||
'api/test.js': { includeFiles: { test: 1 } }
|
||||
}
|
||||
const files = ['api/test.js'];
|
||||
|
||||
const { errors } = await detectBuilders(files, null, { functions });
|
||||
|
||||
expect(errors).not.toBe(null);
|
||||
expect(errors[0].code).toBe('invalid_function_property');
|
||||
});
|
||||
|
||||
it('Must fail for excludeFiles config property', async () => {
|
||||
const functions = {
|
||||
'api/test.js': { excludeFiles: { test: 1 } }
|
||||
}
|
||||
const files = ['api/test.js'];
|
||||
|
||||
const { errors } = await detectBuilders(files, null, { functions });
|
||||
|
||||
expect(errors).not.toBe(null);
|
||||
expect(errors[0].code).toBe('invalid_function_property');
|
||||
});
|
||||
});
|
||||
|
||||
it('Test `detectRoutes`', async () => {
|
||||
|
||||
@@ -29,8 +29,8 @@ import getUser from './util/get-user.ts';
|
||||
import Client from './util/client.ts';
|
||||
import NowTeams from './util/teams';
|
||||
import cmd from './util/output/cmd';
|
||||
import highlight from './util/output/highlight';
|
||||
import { handleError } from './util/error';
|
||||
import highlight from './util/output/highlight';
|
||||
import reportError from './util/report-error';
|
||||
import getConfig from './util/get-config';
|
||||
import * as ERRORS from './util/errors-ts';
|
||||
|
||||
Reference in New Issue
Block a user