Compare commits

...

10 Commits

Author SHA1 Message Date
Andy Bitz
4ce0d31688 Publish
- @now/bash@1.0.1
 - @now/go@0.5.5
 - @now/python@0.2.11
2019-07-09 01:09:23 +02:00
Andy
280802615f [now-bash][now-go][now-python] Support zero config (#723)
* [now-bash][now-go][now-python] Support zero config

* Remove default config
2019-07-09 01:01:27 +02:00
Andy Bitz
c7db281065 Publish
- @now/build-utils@0.8.2
2019-07-08 17:14:04 +02:00
Andy
ca00739041 [now-build-utils] Fix default routes on windows and adjust error message (#720)
* [now-build-utils] Fix default routes on windows and adjust error message

* Remove extra condition
2019-07-08 17:13:29 +02:00
Andy Bitz
11f8b17599 Publish
- @now/build-utils@0.8.1
2019-07-08 12:40:23 +02:00
Andy Bitz
970ab7d5c5 Revert "Fixed yarn.lock (#717)"
This reverts commit 5bfbd63e13.
2019-07-08 12:39:19 +02:00
Andy Bitz
71c082dccd Revert "Publish"
This reverts commit 76a185eb90.
2019-07-08 12:34:31 +02:00
Andy Bitz
76a185eb90 Publish
- @now/build-utils@0.8.1
2019-07-08 12:23:30 +02:00
Andy
8c0f3d107d [now-build-utils] Ignore dot and underscore prefix for api directory (#718)
* [now-build-utils] Add support for `_` and `.` prefixes in `api/`

 * Remove log statement

* Ignore dot and underscore prefix for api directory

* Set one builder per file if there are files to ignore

* Always return all builds with their exact match
2019-07-08 12:22:40 +02:00
Leo Lamprecht
5bfbd63e13 Fixed yarn.lock (#717)
This reverts commit d83b09ffbd.
2019-07-07 16:00:20 +00:00
10 changed files with 83 additions and 19 deletions

View File

@@ -10,7 +10,7 @@ const {
} = require('@now/build-utils'); // eslint-disable-line import/no-extraneous-dependencies
exports.config = {
maxLambdaSize: '10mb',
maxLambdaSize: '30mb',
};
// From this list: https://import.pw/importpw/import/docs/config.md

View File

@@ -1,6 +1,6 @@
{
"name": "@now/bash",
"version": "1.0.0",
"version": "1.0.1",
"description": "Now 2.0 builder for HTTP endpoints written in Bash",
"main": "index.js",
"author": "Nathan Rajlich <nate@zeit.co>",

View File

@@ -1,6 +1,6 @@
{
"name": "@now/build-utils",
"version": "0.8.0",
"version": "0.8.2",
"license": "MIT",
"main": "./dist/index.js",
"types": "./dist/index.d.js",

View File

@@ -34,14 +34,30 @@ export async function detectBuilder(pkg: PackageJson): Promise<Builder> {
return { src, use: '@now/static-build', config };
}
// Files that match a specific pattern will get ignored
export function ignoreApiFilter(file: string) {
if (file.includes('/.')) {
return false;
}
if (file.includes('/_')) {
return false;
}
return true;
}
export async function detectApiBuilders(
files: string[]
): Promise<Builder[] | null> {
const builds = files.map(file => {
return API_BUILDERS.find(({ src }): boolean => minimatch(file, src));
const builds = files.filter(ignoreApiFilter).map(file => {
const result = API_BUILDERS.find(
({ src }): boolean => minimatch(file, src)
);
return result ? { ...result, src: file } : null;
});
// We can use `new Set` here since `builds` contains references to `API_BUILDERS`
const finishedBuilds = Array.from(new Set(builds.filter(Boolean)));
const finishedBuilds = builds.filter(Boolean);
return finishedBuilds.length > 0 ? (finishedBuilds as Builder[]) : null;
}

View File

@@ -1,7 +1,17 @@
import path from 'path';
import { Route } from './types';
import { parse as parsePath } from 'path';
import { ignoreApiFilter } from './detect-builder';
function joinPath(...segments: string[]) {
const joinedPath = segments.join('/');
return joinedPath.replace(/\/{2,}/g, '/');
}
function concatArrayOfText(texts: string[]): string {
if (texts.length <= 2) {
return texts.join(' and ');
}
const last = texts.pop();
return `${texts.join(', ')}, and ${last}`;
}
@@ -11,7 +21,7 @@ function concatArrayOfText(texts: string[]): string {
// It will return `null` if there are no brackets
// and therefore no segment.
function getSegmentName(segment: string): string | null {
const { name } = path.parse(segment);
const { name } = parsePath(segment);
if (name.startsWith('[') && name.endsWith(']')) {
return name.slice(1, -1);
@@ -47,7 +57,7 @@ function createRouteFromPath(filePath: string): Route {
} else if (isLast) {
// If it is the last part we want to remove the extension
// and capture everything after that as regex group and append it
const { name: fileName } = path.parse(segment);
const { name: fileName } = parsePath(segment);
append += `$${counter++}`;
return `${fileName}(.*)`;
}
@@ -101,8 +111,8 @@ function partiallyMatches(pathA: string, pathB: string): boolean {
// got resolved, so we can check if they have conflicts
function pathOccurrences(filePath: string, files: string[]): string[] {
const getAbsolutePath = (unresolvedPath: string): string => {
const { dir, name } = path.parse(unresolvedPath);
const parts = path.join(dir, name).split('/');
const { dir, name } = parsePath(unresolvedPath);
const parts = joinPath(dir, name).split('/');
return parts.map(part => part.replace(/\[.*\]/, '1')).join('/');
};
@@ -183,7 +193,9 @@ export async function detectApiRoutes(
// The deepest routes need to be
// the first ones to get handled
const sortedFiles = files.sort(sortFilesBySegmentCount);
const sortedFiles = files
.filter(ignoreApiFilter)
.sort(sortFilesBySegmentCount);
const defaultRoutes: Route[] = [];
@@ -196,8 +208,6 @@ export async function detectApiRoutes(
const conflictingSegment = getConflictingSegment(file);
console.log({ file, conflictingSegment });
if (conflictingSegment) {
return {
defaultRoutes: null,

View File

@@ -207,6 +207,18 @@ it('Test `detectApiBuilders`', async () => {
const builders = await detectApiBuilders(files);
expect(builders).toBe(null);
}
{
const files = [
'api/users/[id].js',
'api/_utils/handler.js',
'api/users/.helper.js',
'api/teams/_helper.js',
];
const builders = await detectApiBuilders(files);
expect(builders.length).toBe(1);
}
});
it('Test `detectApiRoutes`', async () => {
@@ -244,4 +256,15 @@ it('Test `detectApiRoutes`', async () => {
const { defaultRoutes } = await detectApiRoutes(files);
expect(defaultRoutes.length).toBe(2);
}
{
const files = [
'api/_utils/handler.js',
'api/[endpoint]/.helper.js',
'api/[endpoint]/[id].js',
];
const builders = await detectApiBuilders(files);
expect(builders.length).toBe(1);
}
});

View File

@@ -120,7 +120,14 @@ Learn more: https://zeit.co/docs/v2/deployments/official-builders/go-now-go/#ent
const parsedAnalyzed = JSON.parse(analyzed) as Analyzed;
if (meta.isDev) {
const base = dirname(downloadedFiles['now.json'].fsPath);
let base = null;
if (config && config.zeroConfig) {
base = workPath;
} else {
base = dirname(downloadedFiles['now.json'].fsPath);
}
const destNow = join(
base,
'.now',

View File

@@ -1,6 +1,6 @@
{
"name": "@now/go",
"version": "0.5.4",
"version": "0.5.5",
"license": "MIT",
"homepage": "https://zeit.co/docs/v2/deployments/official-builders/go-now-go",
"repository": {

View File

@@ -1,6 +1,6 @@
{
"name": "@now/python",
"version": "0.2.10",
"version": "0.2.11",
"main": "./dist/index.js",
"license": "MIT",
"homepage": "https://zeit.co/docs/v2/deployments/official-builders/python-now-python",

View File

@@ -92,12 +92,20 @@ export const build = async ({
files: originalFiles,
entrypoint,
meta = {},
config,
}: BuildOptions) => {
console.log('downloading files...');
let downloadedFiles = await download(originalFiles, workPath, meta);
if (meta.isDev) {
const base = dirname(downloadedFiles['now.json'].fsPath);
let base = null;
if (config && config.zeroConfig) {
base = workPath;
} else {
base = dirname(downloadedFiles['now.json'].fsPath);
}
const destNow = join(base, '.now', 'cache', basename(entrypoint, '.py'));
await download(downloadedFiles, destNow);
downloadedFiles = await glob('**', destNow);