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

[all] Fix types for Route vs Source #3450

Merged
merged 2 commits into from Dec 18, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 2 additions & 1 deletion packages/now-build-utils/src/detect-routes-legacy.ts
@@ -1,5 +1,6 @@
import { parse as parsePath } from 'path';
import { Route, Builder } from './types';
import { Route } from '@now/routing-utils';
import { Builder } from './types';
import { getIgnoreApiFilter, sortFiles } from './detect-builders-legacy';

function escapeName(name: string) {
Expand Down
3 changes: 2 additions & 1 deletion packages/now-build-utils/src/detect-routes.ts
@@ -1,5 +1,6 @@
import { parse as parsePath } from 'path';
import { Route, Builder } from './types';
import { Route } from '@now/routing-utils';
import { Builder } from './types';
import { getIgnoreApiFilter, sortFiles } from './detect-builders';

function escapeName(name: string) {
Expand Down
13 changes: 1 addition & 12 deletions packages/now-build-utils/src/types.ts
@@ -1,6 +1,7 @@
import FileRef from './file-ref';
import FileFsRef from './file-fs-ref';
import DetectorFilesystem from './detectors/filesystem';
import { Route } from '@now/routing-utils';

export interface Env {
[name: string]: string | undefined;
Expand All @@ -21,18 +22,6 @@ export interface Files {
[filePath: string]: File;
}

export interface Route {
src?: string;
dest?: string;
handle?: string;
type?: string;
headers?: {
[key: string]: string;
};
continue?: boolean;
status?: number;
}

export interface Config {
[key: string]:
| string
Expand Down
2 changes: 1 addition & 1 deletion packages/now-next/src/index.ts
Expand Up @@ -15,10 +15,10 @@ import {
PackageJson,
PrepareCacheOptions,
Prerender,
Route,
runNpmInstall,
runPackageJsonScript,
} from '@now/build-utils';
import { Route } from '@now/routing-utils';
import {
convertRedirects,
convertRewrites,
Expand Down
6 changes: 3 additions & 3 deletions packages/now-next/src/utils.ts
Expand Up @@ -11,9 +11,9 @@ import {
FileFsRef,
streamToBuffer,
Lambda,
Route,
isSymbolicLink,
} from '@now/build-utils';
import { Route, Source } from '@now/routing-utils';

type stringMap = { [key: string]: string };

Expand Down Expand Up @@ -279,13 +279,13 @@ async function getRoutes(
if (!isPublic) continue;

const fileName = path.relative('public', relativePath);
const route = {
const route: Source = {
src: `${prefix}${fileName}`,
dest: `${url}/${fileName}`,
};

// Only add the route if a page is not already using it
if (!routes.some(r => r.src === route.src)) {
if (!routes.some(r => (r as Source).src === route.src)) {
routes.push(route);
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/now-static-build/src/frameworks.ts
@@ -1,7 +1,7 @@
import { readdir, stat, readFile, unlink } from 'fs';
import { promisify } from 'util';
import { join } from 'path';
import { Route } from '@now/build-utils';
import { Route } from '@now/routing-utils';

const readirPromise = promisify(readdir);
const readFilePromise = promisify(readFile);
Expand Down
6 changes: 3 additions & 3 deletions packages/now-static-build/src/index.ts
Expand Up @@ -21,13 +21,13 @@ import {
getSpawnOptions,
Files,
FileFsRef,
Route,
BuildOptions,
Config,
debug,
PackageJson,
PrepareCacheOptions,
} from '@now/build-utils';
import { Route, Source } from '@now/routing-utils';

const sleep = (n: number) => new Promise(resolve => setTimeout(resolve, n));

Expand Down Expand Up @@ -120,8 +120,8 @@ const nowDevChildProcesses = new Set<ChildProcess>();
});
});

const getDevRoute = (srcBase: string, devPort: number, route: Route) => {
const basic: Route = {
const getDevRoute = (srcBase: string, devPort: number, route: Source) => {
const basic: Source = {
src: `${srcBase}${route.src}`,
dest: `http://localhost:${devPort}${route.dest}`,
};
Expand Down
14 changes: 10 additions & 4 deletions run.js
Expand Up @@ -42,14 +42,20 @@ async function main() {
}

// Sort the matches such that `utils` modules are compiled first,
// because other packages may rely on them
// We also need to ensure that `now-client` is built before the CLI
// because other packages may rely on them.
// We also need to ensure that `now-client` is built last.

matches.sort((a, b) => {
if (a.endsWith('-utils') && !b.endsWith('-utils')) {
if (a === 'now-routing-utils' && b !== 'now-routing-utils') {
return -1;
}
if (b.endsWith('-utils') && !a.endsWith('-utils')) {
if (b === 'now-routing-utils' && a !== 'now-routing-utils') {
return 1;
}
if (a === 'now-build-utils' && b !== 'now-build-utils') {
return -1;
}
if (b === 'now-build-utils' && a !== 'now-build-utils') {
return 1;
}
if (a === 'now-cli' && b !== 'now-cli') {
Expand Down