mirror of
https://github.com/LukeHagar/vercel.git
synced 2025-12-24 11:49:13 +00:00
Compare commits
45 Commits
@vercel/cl
...
@vercel/ne
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4eb5ad625c | ||
|
|
7164f6e58e | ||
|
|
a36d084b3e | ||
|
|
8a16447fed | ||
|
|
efda4ab6b9 | ||
|
|
16060a71a9 | ||
|
|
b18e0a7415 | ||
|
|
1251f11a97 | ||
|
|
07235e22f6 | ||
|
|
81011df816 | ||
|
|
c8d31bdcf7 | ||
|
|
5e7f1158ad | ||
|
|
df5aa1f10d | ||
|
|
eb1ba97309 | ||
|
|
8047d6de49 | ||
|
|
7470ff3724 | ||
|
|
8340d9327c | ||
|
|
d278425810 | ||
|
|
8b26bbe643 | ||
|
|
fa8e1e73c8 | ||
|
|
f8abcbcd9f | ||
|
|
e18ff683b2 | ||
|
|
f28293a5a8 | ||
|
|
a4963a89c7 | ||
|
|
21df39fe8c | ||
|
|
5ad9d61451 | ||
|
|
8b5a2aa44f | ||
|
|
d0da1ce195 | ||
|
|
fd5d3b2921 | ||
|
|
d22bdeb8d0 | ||
|
|
c120fd82f9 | ||
|
|
2474a80ff1 | ||
|
|
cc1cdbe610 | ||
|
|
0b92f8ceee | ||
|
|
be82a88d1a | ||
|
|
64da08f0f2 | ||
|
|
2e957fce55 | ||
|
|
c7ead151f5 | ||
|
|
e2baf9b00f | ||
|
|
ba8ef7bc98 | ||
|
|
c5d04e0d4f | ||
|
|
b4f849418d | ||
|
|
b37c4f211e | ||
|
|
f06efe167c | ||
|
|
296d8da676 |
4
.github/CONTRIBUTING.md
vendored
4
.github/CONTRIBUTING.md
vendored
@@ -73,8 +73,8 @@ The logs of this deployment will contain the actual error which may help you to
|
||||
Some of the Builders use `@vercel/nft` to tree-shake files before deployment. If you suspect an error with this tree-shaking mechanism, you can create the following script in your project:
|
||||
|
||||
```js
|
||||
const trace = require('@vercel/nft');
|
||||
trace(['path/to/entrypoint.js'], {
|
||||
const { nodeFileTrace } = require('@vercel/nft');
|
||||
nodeFileTrace(['path/to/entrypoint.js'], {
|
||||
ts: true,
|
||||
mixedModules: true,
|
||||
})
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
"start": "next start"
|
||||
},
|
||||
"dependencies": {
|
||||
"next": "9.5.1",
|
||||
"react": "16.13.1",
|
||||
"react-dom": "16.13.1"
|
||||
"next": "10.0.0",
|
||||
"react": "17.0.1",
|
||||
"react-dom": "17.0.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,7 +56,13 @@
|
||||
"outputDirectory": {
|
||||
"placeholder": "Next.js default"
|
||||
}
|
||||
}
|
||||
},
|
||||
"recommendedIntegrations": [
|
||||
{
|
||||
"id": "oac_5lUsiANun1DEzgLg0NZx5Es3",
|
||||
"dependencies": ["next-plugin-sentry", "next-sentry-source-maps"]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "Gatsby.js",
|
||||
|
||||
4
packages/frameworks/index.d.ts
vendored
4
packages/frameworks/index.d.ts
vendored
@@ -31,4 +31,8 @@ export interface Framework {
|
||||
devCommand: Setting;
|
||||
outputDirectory: Setting;
|
||||
};
|
||||
recommendedIntegrations?: {
|
||||
id: string;
|
||||
dependencies: string[];
|
||||
}[];
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@vercel/frameworks",
|
||||
"version": "0.1.1",
|
||||
"version": "0.1.2-canary.0",
|
||||
"main": "frameworks.json",
|
||||
"license": "UNLICENSED",
|
||||
"scripts": {
|
||||
|
||||
19
packages/frameworks/test/frameworks.unit.test.ts
vendored
19
packages/frameworks/test/frameworks.unit.test.ts
vendored
@@ -97,6 +97,25 @@ const Schema = {
|
||||
outputDirectory: SchemaSettings,
|
||||
},
|
||||
},
|
||||
recommendedIntegrations: {
|
||||
type: 'array',
|
||||
items: {
|
||||
type: 'object',
|
||||
required: ['id', 'dependencies'],
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
id: {
|
||||
type: 'string',
|
||||
},
|
||||
dependencies: {
|
||||
type: 'array',
|
||||
items: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@vercel/build-utils",
|
||||
"version": "2.5.4",
|
||||
"version": "2.5.5-canary.0",
|
||||
"license": "MIT",
|
||||
"main": "./dist/index.js",
|
||||
"types": "./dist/index.d.js",
|
||||
@@ -29,7 +29,7 @@
|
||||
"@types/node-fetch": "^2.1.6",
|
||||
"@types/semver": "6.0.0",
|
||||
"@types/yazl": "^2.4.1",
|
||||
"@vercel/frameworks": "0.1.1",
|
||||
"@vercel/frameworks": "0.1.2-canary.0",
|
||||
"@vercel/ncc": "0.24.0",
|
||||
"aggregate-error": "3.0.1",
|
||||
"async-retry": "1.2.3",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "vercel",
|
||||
"version": "20.1.2",
|
||||
"version": "20.1.3-canary.2",
|
||||
"preferGlobal": true,
|
||||
"license": "Apache-2.0",
|
||||
"description": "The command-line interface for Vercel",
|
||||
@@ -61,7 +61,7 @@
|
||||
"node": ">= 10"
|
||||
},
|
||||
"dependencies": {
|
||||
"@vercel/build-utils": "2.5.4",
|
||||
"@vercel/build-utils": "2.5.5-canary.0",
|
||||
"@vercel/go": "1.1.6",
|
||||
"@vercel/node": "1.8.4",
|
||||
"@vercel/python": "1.2.3",
|
||||
@@ -100,7 +100,7 @@
|
||||
"@types/universal-analytics": "0.4.2",
|
||||
"@types/which": "1.3.2",
|
||||
"@types/write-json-file": "2.2.1",
|
||||
"@vercel/frameworks": "0.1.1",
|
||||
"@vercel/frameworks": "0.1.2-canary.0",
|
||||
"@vercel/ncc": "0.24.0",
|
||||
"@zeit/fun": "0.11.2",
|
||||
"@zeit/source-map-support": "0.6.2",
|
||||
|
||||
@@ -7,7 +7,7 @@ import getScope from '../../util/get-scope.ts';
|
||||
import removeAliasById from '../../util/alias/remove-alias-by-id';
|
||||
import stamp from '../../util/output/stamp.ts';
|
||||
import strlen from '../../util/strlen.ts';
|
||||
import promptBool from '../../util/prompt-bool';
|
||||
import confirm from '../../util/input/confirm';
|
||||
import { isValidName } from '../../util/is-valid-name';
|
||||
import findAliasByAliasOrId from '../../util/alias/find-alias-by-alias-or-id';
|
||||
import { getCommandName } from '../../util/pkg-name.ts';
|
||||
@@ -108,5 +108,5 @@ async function confirmAliasRemove(output, alias) {
|
||||
|
||||
output.log(`The following alias will be removed permanently`);
|
||||
output.print(` ${tbl}\n`);
|
||||
return promptBool(output, chalk.red('Are you sure?'));
|
||||
return confirm(chalk.red('Are you sure?'), false);
|
||||
}
|
||||
|
||||
2
packages/now-cli/src/commands/env/add.ts
vendored
2
packages/now-cli/src/commands/env/add.ts
vendored
@@ -77,7 +77,7 @@ export default async function add(
|
||||
}
|
||||
}
|
||||
|
||||
const envs = await getEnvVariables(output, client, project.id, 4);
|
||||
const { envs } = await getEnvVariables(output, client, project.id);
|
||||
const existing = new Set(
|
||||
envs.filter(r => r.key === envName).map(r => r.target)
|
||||
);
|
||||
|
||||
9
packages/now-cli/src/commands/env/index.ts
vendored
9
packages/now-cli/src/commands/env/index.ts
vendored
@@ -42,7 +42,6 @@ const help = () => {
|
||||
-t ${chalk.bold.underline('TOKEN')}, --token=${chalk.bold.underline(
|
||||
'TOKEN'
|
||||
)} Login token
|
||||
-N, --next Show next page of results
|
||||
|
||||
${chalk.dim('Examples:')}
|
||||
|
||||
@@ -73,12 +72,6 @@ const help = () => {
|
||||
|
||||
${chalk.cyan(`$ ${getPkgName()} env rm <name> ${placeholder}`)}
|
||||
${chalk.cyan(`$ ${getPkgName()} env rm NPM_RC preview`)}
|
||||
|
||||
${chalk.gray('–')} Paginate results, where ${chalk.dim(
|
||||
'`1584722256178`'
|
||||
)} is the time in milliseconds since the UNIX epoch.
|
||||
|
||||
${chalk.cyan(`$ ${getPkgName()} env ls --next 1584722256178`)}
|
||||
`);
|
||||
};
|
||||
|
||||
@@ -96,8 +89,6 @@ export default async function main(ctx: NowContext) {
|
||||
argv = getArgs(ctx.argv.slice(2), {
|
||||
'--yes': Boolean,
|
||||
'-y': '--yes',
|
||||
'--next': Number,
|
||||
'-N': '--next',
|
||||
});
|
||||
} catch (error) {
|
||||
handleError(error);
|
||||
|
||||
74
packages/now-cli/src/commands/env/ls.ts
vendored
74
packages/now-cli/src/commands/env/ls.ts
vendored
@@ -1,7 +1,7 @@
|
||||
import chalk from 'chalk';
|
||||
import ms from 'ms';
|
||||
import { Output } from '../../util/output';
|
||||
import { ProjectEnvVariable, ProjectEnvTarget, Project } from '../../types';
|
||||
import { ProjectEnvTarget, Project, ProjectEnvVariableV5 } from '../../types';
|
||||
import Client from '../../util/client';
|
||||
import formatTable from '../../util/format-table';
|
||||
import getEnvVariables from '../../util/env/get-env-records';
|
||||
@@ -11,12 +11,11 @@ import {
|
||||
} from '../../util/env/env-target';
|
||||
import stamp from '../../util/output/stamp';
|
||||
import param from '../../util/output/param';
|
||||
import getCommandFlags from '../../util/get-command-flags';
|
||||
import { getCommandName } from '../../util/pkg-name';
|
||||
import ellipsis from '../../util/output/ellipsis';
|
||||
|
||||
type Options = {
|
||||
'--debug': boolean;
|
||||
'--next'?: number;
|
||||
};
|
||||
|
||||
export default async function ls(
|
||||
@@ -26,8 +25,6 @@ export default async function ls(
|
||||
args: string[],
|
||||
output: Output
|
||||
) {
|
||||
const { '--next': nextTimestamp } = opts;
|
||||
|
||||
if (args.length > 1) {
|
||||
output.error(
|
||||
`Invalid number of arguments. Usage: ${getCommandName(
|
||||
@@ -50,40 +47,31 @@ export default async function ls(
|
||||
|
||||
const lsStamp = stamp();
|
||||
|
||||
if (typeof nextTimestamp !== 'undefined' && Number.isNaN(nextTimestamp)) {
|
||||
output.error('Please provide a number for flag --next');
|
||||
return 1;
|
||||
const data = await getEnvVariables(output, client, project.id, envTarget);
|
||||
|
||||
// we expand env vars with multiple targets
|
||||
const envs: ProjectEnvVariableV5[] = [];
|
||||
for (let env of data.envs) {
|
||||
if (Array.isArray(env.target)) {
|
||||
for (let target of env.target) {
|
||||
envs.push({ ...env, target });
|
||||
}
|
||||
} else {
|
||||
envs.push({ ...env, target: env.target });
|
||||
}
|
||||
}
|
||||
|
||||
const data = await getEnvVariables(
|
||||
output,
|
||||
client,
|
||||
project.id,
|
||||
5,
|
||||
envTarget,
|
||||
nextTimestamp
|
||||
);
|
||||
const { envs: records, pagination } = data;
|
||||
output.log(
|
||||
`${
|
||||
records.length > 0 ? 'Environment Variables' : 'No Environment Variables'
|
||||
envs.length > 0 ? 'Environment Variables' : 'No Environment Variables'
|
||||
} found in Project ${chalk.bold(project.name)} ${chalk.gray(lsStamp())}`
|
||||
);
|
||||
console.log(getTable(records));
|
||||
|
||||
if (pagination && pagination.count === 20) {
|
||||
const flags = getCommandFlags(opts, ['_', '--next']);
|
||||
output.log(
|
||||
`To display the next page run ${getCommandName(
|
||||
`env ls${flags} --next ${pagination.next}`
|
||||
)}`
|
||||
);
|
||||
}
|
||||
console.log(getTable(envs));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
function getTable(records: ProjectEnvVariable[]) {
|
||||
function getTable(records: ProjectEnvVariableV5[]) {
|
||||
return formatTable(
|
||||
['name', 'value', 'environment', 'created'],
|
||||
['l', 'l', 'l', 'l', 'l'],
|
||||
@@ -96,17 +84,25 @@ function getTable(records: ProjectEnvVariable[]) {
|
||||
);
|
||||
}
|
||||
|
||||
function getRow({
|
||||
key,
|
||||
system = false,
|
||||
target,
|
||||
createdAt = 0,
|
||||
}: ProjectEnvVariable) {
|
||||
function getRow(env: ProjectEnvVariableV5) {
|
||||
let value: string;
|
||||
if (env.type === 'plain') {
|
||||
// replace space characters (line-break, etc.) with simple spaces
|
||||
// to make sure the displayed value is a single line
|
||||
const singleLineValue = env.value.replace(/\s/g, ' ');
|
||||
|
||||
value = chalk.gray(ellipsis(singleLineValue, 19));
|
||||
} else if (env.type === 'system') {
|
||||
value = chalk.gray.italic('Populated by System');
|
||||
} else {
|
||||
value = chalk.gray.italic('Encrypted');
|
||||
}
|
||||
|
||||
const now = Date.now();
|
||||
return [
|
||||
chalk.bold(key),
|
||||
chalk.gray(chalk.italic(system ? 'Populated by System' : 'Encrypted')),
|
||||
target || '',
|
||||
`${ms(now - createdAt)} ago`,
|
||||
chalk.bold(env.key),
|
||||
value,
|
||||
env.target || '',
|
||||
env.createdAt ? `${ms(now - env.createdAt)} ago` : '',
|
||||
];
|
||||
}
|
||||
|
||||
8
packages/now-cli/src/commands/env/pull.ts
vendored
8
packages/now-cli/src/commands/env/pull.ts
vendored
@@ -1,7 +1,7 @@
|
||||
import chalk from 'chalk';
|
||||
import { ProjectEnvTarget, Project } from '../../types';
|
||||
import { Output } from '../../util/output';
|
||||
import promptBool from '../../util/prompt-bool';
|
||||
import confirm from '../../util/input/confirm';
|
||||
import Client from '../../util/client';
|
||||
import stamp from '../../util/output/stamp';
|
||||
import getDecryptedEnvRecords from '../../util/get-decrypted-env-records';
|
||||
@@ -68,9 +68,9 @@ export default async function pull(
|
||||
} else if (
|
||||
exists &&
|
||||
!skipConfirmation &&
|
||||
!(await promptBool(
|
||||
output,
|
||||
`Found existing file ${param(filename)}. Do you want to overwrite?`
|
||||
!(await confirm(
|
||||
`Found existing file ${param(filename)}. Do you want to overwrite?`,
|
||||
false
|
||||
))
|
||||
) {
|
||||
output.log('Aborted');
|
||||
|
||||
10
packages/now-cli/src/commands/env/rm.ts
vendored
10
packages/now-cli/src/commands/env/rm.ts
vendored
@@ -2,7 +2,7 @@ import chalk from 'chalk';
|
||||
import inquirer from 'inquirer';
|
||||
import { ProjectEnvTarget, Project } from '../../types';
|
||||
import { Output } from '../../util/output';
|
||||
import promptBool from '../../util/prompt-bool';
|
||||
import confirm from '../../util/input/confirm';
|
||||
import removeEnvRecord from '../../util/env/remove-env-record';
|
||||
import getEnvVariables from '../../util/env/get-env-records';
|
||||
import {
|
||||
@@ -69,7 +69,7 @@ export default async function rm(
|
||||
envName = inputName;
|
||||
}
|
||||
|
||||
const envs = await getEnvVariables(output, client, project.id, 4);
|
||||
const { envs } = await getEnvVariables(output, client, project.id);
|
||||
const existing = new Set(
|
||||
envs.filter(r => r.key === envName).map(r => r.target)
|
||||
);
|
||||
@@ -104,11 +104,11 @@ export default async function rm(
|
||||
const skipConfirmation = opts['--yes'];
|
||||
if (
|
||||
!skipConfirmation &&
|
||||
!(await promptBool(
|
||||
output,
|
||||
!(await confirm(
|
||||
`Removing Environment Variable ${param(
|
||||
envName
|
||||
)} from Project ${chalk.bold(project.name)}. Are you sure?`
|
||||
)} from Project ${chalk.bold(project.name)}. Are you sure?`,
|
||||
false
|
||||
))
|
||||
) {
|
||||
output.log('Aborted');
|
||||
|
||||
@@ -203,12 +203,19 @@ export enum ProjectEnvTarget {
|
||||
Development = 'development',
|
||||
}
|
||||
|
||||
export type ProjectEnvVariableType = 'system' | 'secret' | 'plain';
|
||||
|
||||
export interface ProjectEnvVariable {
|
||||
key: string;
|
||||
value: string;
|
||||
type: ProjectEnvVariableType;
|
||||
configurationId?: string | null;
|
||||
createdAt?: number;
|
||||
updatedAt?: number;
|
||||
target?: ProjectEnvTarget | ProjectEnvTarget[];
|
||||
}
|
||||
|
||||
export interface ProjectEnvVariableV5 extends ProjectEnvVariable {
|
||||
target?: ProjectEnvTarget;
|
||||
system?: boolean;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Output } from '../output';
|
||||
import Client from '../client';
|
||||
import { Secret, ProjectEnvTarget, ProjectEnvVariable } from '../../types';
|
||||
import { Secret, ProjectEnvTarget, ProjectEnvVariableV5 } from '../../types';
|
||||
import { customAlphabet } from 'nanoid';
|
||||
import slugify from '@sindresorhus/slugify';
|
||||
|
||||
@@ -42,7 +42,7 @@ export default async function addEnvRecord(
|
||||
}));
|
||||
|
||||
const urlProject = `/v4/projects/${projectId}/env`;
|
||||
await client.fetch<ProjectEnvVariable>(urlProject, {
|
||||
await client.fetch<ProjectEnvVariableV5>(urlProject, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
|
||||
51
packages/now-cli/src/util/env/get-env-records.ts
vendored
51
packages/now-cli/src/util/env/get-env-records.ts
vendored
@@ -1,69 +1,24 @@
|
||||
import { Output } from '../output';
|
||||
import Client from '../client';
|
||||
import {
|
||||
ProjectEnvVariable,
|
||||
ProjectEnvTarget,
|
||||
PaginationOptions,
|
||||
} from '../../types';
|
||||
import { ProjectEnvVariable, ProjectEnvTarget } from '../../types';
|
||||
import { URLSearchParams } from 'url';
|
||||
|
||||
type ApiVersion = 4 | 5;
|
||||
|
||||
type APIV4Response = ProjectEnvVariable[];
|
||||
|
||||
interface APIV5Response {
|
||||
pagination: PaginationOptions;
|
||||
envs: ProjectEnvVariable[];
|
||||
}
|
||||
|
||||
export default async function getEnvVariables(
|
||||
output: Output,
|
||||
client: Client,
|
||||
projectId: string,
|
||||
apiVersion: 4,
|
||||
target?: ProjectEnvTarget
|
||||
): Promise<APIV4Response>;
|
||||
|
||||
export default async function getEnvVariables(
|
||||
output: Output,
|
||||
client: Client,
|
||||
projectId: string,
|
||||
apiVersion: 5,
|
||||
target?: ProjectEnvTarget,
|
||||
next?: number
|
||||
): Promise<APIV5Response>;
|
||||
|
||||
export default async function getEnvVariables<V extends ApiVersion>(
|
||||
output: Output,
|
||||
client: Client,
|
||||
projectId: string,
|
||||
apiVersion: V,
|
||||
target?: ProjectEnvTarget,
|
||||
next?: number
|
||||
) {
|
||||
output.debug(
|
||||
`Fetching Environment Variables of project ${projectId} and target ${target}`
|
||||
);
|
||||
const query = new URLSearchParams();
|
||||
if (apiVersion >= 5) {
|
||||
query.set('limit', String(20));
|
||||
}
|
||||
|
||||
if (target) {
|
||||
query.set('target', target);
|
||||
}
|
||||
|
||||
if (next) {
|
||||
query.set('until', String(next));
|
||||
}
|
||||
const url = `/v6/projects/${projectId}/env?${query}`;
|
||||
|
||||
const url = `/v${apiVersion}/projects/${projectId}/env?${query}`;
|
||||
|
||||
if (apiVersion === 5) {
|
||||
return client.fetch<APIV5Response>(url);
|
||||
} else if (apiVersion === 4) {
|
||||
return client.fetch<APIV4Response>(url);
|
||||
} else {
|
||||
throw new Error('Unknown version: ' + apiVersion);
|
||||
}
|
||||
return client.fetch<{ envs: ProjectEnvVariable[] }>(url);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Output } from '../output';
|
||||
import Client from '../client';
|
||||
import { ProjectEnvTarget, Secret, ProjectEnvVariable } from '../../types';
|
||||
import { ProjectEnvTarget, Secret, ProjectEnvVariableV5 } from '../../types';
|
||||
|
||||
export default async function removeEnvRecord(
|
||||
output: Output,
|
||||
@@ -18,7 +18,7 @@ export default async function removeEnvRecord(
|
||||
envName
|
||||
)}${qs}`;
|
||||
|
||||
const env = await client.fetch<ProjectEnvVariable>(urlProject, {
|
||||
const env = await client.fetch<ProjectEnvVariableV5>(urlProject, {
|
||||
method: 'DELETE',
|
||||
});
|
||||
|
||||
|
||||
@@ -12,9 +12,15 @@ export default async function getDecryptedEnvRecords(
|
||||
project: Project,
|
||||
target: ProjectEnvTarget
|
||||
): Promise<Env> {
|
||||
const envs = await getEnvVariables(output, client, project.id, 4, target);
|
||||
const { envs } = await getEnvVariables(output, client, project.id, target);
|
||||
const decryptedValues = await Promise.all(
|
||||
envs.map(async env => {
|
||||
if (env.type === 'system') {
|
||||
return { value: '', found: true };
|
||||
} else if (env.type === 'plain') {
|
||||
return { value: env.value, found: true };
|
||||
}
|
||||
|
||||
try {
|
||||
const value = await getDecryptedSecret(output, client, env.value);
|
||||
return { value, found: true };
|
||||
|
||||
3
packages/now-cli/src/util/output/ellipsis.ts
Normal file
3
packages/now-cli/src/util/output/ellipsis.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export default function ellipsis(str: string, length: number) {
|
||||
return str.length > length ? `${str.slice(0, length - 1)}…` : str;
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
import chalk from 'chalk';
|
||||
import { Output } from './output';
|
||||
|
||||
async function promptBool(output: Output, message: string): Promise<boolean> {
|
||||
return new Promise<boolean>(resolve => {
|
||||
output.print(`${chalk.gray('>')} ${message} ${chalk.gray('[y/N] ')}`);
|
||||
process.stdin
|
||||
.on('data', d => {
|
||||
process.stdin.pause();
|
||||
resolve(
|
||||
d
|
||||
.toString()
|
||||
.trim()
|
||||
.toLowerCase() === 'y'
|
||||
);
|
||||
})
|
||||
.resume();
|
||||
});
|
||||
}
|
||||
|
||||
export default promptBool;
|
||||
42
packages/now-cli/test/integration.js
vendored
42
packages/now-cli/test/integration.js
vendored
@@ -422,6 +422,34 @@ test('Deploy `api-env` fixture and test `vercel env` command', async t => {
|
||||
t.is(exitCode, 0, formatOutput({ stderr, stdout }));
|
||||
}
|
||||
|
||||
function withPlainTextEnv(fn) {
|
||||
return async function (...args) {
|
||||
const link = require(path.join(target, '.vercel/project.json'));
|
||||
const postRes = await apiFetch(`/v6/projects/${link.projectId}/env`, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
type: 'plain',
|
||||
key: 'MY_PLAIN_VAR',
|
||||
value: 'hello',
|
||||
target: ['development'],
|
||||
}),
|
||||
});
|
||||
t.is(postRes.status, 200);
|
||||
|
||||
try {
|
||||
return await fn(...args);
|
||||
} finally {
|
||||
const deleteRes = await apiFetch(
|
||||
`/v4/projects/${link.projectId}/env/MY_PLAIN_VAR?target=development`,
|
||||
{
|
||||
method: 'DELETE',
|
||||
}
|
||||
);
|
||||
t.is(deleteRes.status, 200);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
async function nowEnvLsIsEmpty() {
|
||||
const { exitCode, stderr, stdout } = await execa(
|
||||
binaryPath,
|
||||
@@ -530,6 +558,11 @@ test('Deploy `api-env` fixture and test `vercel env` command', async t => {
|
||||
t.regex(vercelVars.join('\n'), /development/gm);
|
||||
t.regex(vercelVars.join('\n'), /preview/gm);
|
||||
t.regex(vercelVars.join('\n'), /production/gm);
|
||||
|
||||
const myPlainVars = lines.filter(line => line.includes('MY_PLAIN_VAR'));
|
||||
t.is(myPlainVars.length, 1);
|
||||
t.regex(myPlainVars.join('\n'), /development/gm);
|
||||
t.regex(myPlainVars.join('\n'), /hello/gm);
|
||||
}
|
||||
|
||||
async function nowEnvPull() {
|
||||
@@ -552,6 +585,7 @@ test('Deploy `api-env` fixture and test `vercel env` command', async t => {
|
||||
t.true(lines.has('MY_ENV_VAR="MY_VALUE"'));
|
||||
t.true(lines.has('MY_STDIN_VAR="{"expect":"quotes"}"'));
|
||||
t.true(lines.has('VERCEL_URL=""'));
|
||||
t.true(lines.has('MY_PLAIN_VAR="hello"'));
|
||||
}
|
||||
|
||||
async function nowEnvPullOverwrite() {
|
||||
@@ -681,12 +715,14 @@ test('Deploy `api-env` fixture and test `vercel env` command', async t => {
|
||||
|
||||
t.is(apiJson['VERCEL_URL'], localhostNoProtocol);
|
||||
t.is(apiJson['MY_ENV_VAR'], 'MY_VALUE');
|
||||
t.is(apiJson['MY_PLAIN_VAR'], 'hello');
|
||||
|
||||
const homeUrl = localhost[0];
|
||||
const homeRes = await fetch(homeUrl);
|
||||
const homeJson = await homeRes.json();
|
||||
t.is(homeJson['MY_ENV_VAR'], 'MY_VALUE');
|
||||
t.is(homeJson['VERCEL_URL'], localhostNoProtocol);
|
||||
t.is(homeJson['MY_PLAIN_VAR'], 'hello');
|
||||
|
||||
vc.kill('SIGTERM', { forceKillAfterTimeout: 2000 });
|
||||
|
||||
@@ -755,14 +791,14 @@ test('Deploy `api-env` fixture and test `vercel env` command', async t => {
|
||||
await nowEnvAdd();
|
||||
await nowEnvAddFromStdin();
|
||||
await nowEnvAddSystemEnv();
|
||||
await nowEnvLsIncludesVar();
|
||||
await nowEnvPull();
|
||||
await withPlainTextEnv(nowEnvLsIncludesVar)();
|
||||
await withPlainTextEnv(nowEnvPull)();
|
||||
await nowEnvPullOverwrite();
|
||||
await nowEnvPullConfirm();
|
||||
await nowDeployWithVar();
|
||||
await nowDevWithEnv();
|
||||
fs.unlinkSync(path.join(target, '.env'));
|
||||
await nowDevAndFetchCloudVars();
|
||||
await withPlainTextEnv(nowDevAndFetchCloudVars)();
|
||||
await nowEnvRemove();
|
||||
await nowEnvRemoveWithArgs();
|
||||
await nowEnvRemoveWithNameOnly();
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@vercel/client",
|
||||
"version": "9.0.3",
|
||||
"version": "9.0.4-canary.0",
|
||||
"main": "dist/index.js",
|
||||
"typings": "dist/index.d.ts",
|
||||
"homepage": "https://vercel.com",
|
||||
@@ -37,7 +37,7 @@
|
||||
]
|
||||
},
|
||||
"dependencies": {
|
||||
"@vercel/build-utils": "2.5.4",
|
||||
"@vercel/build-utils": "2.5.5-canary.0",
|
||||
"@zeit/fetch": "5.2.0",
|
||||
"async-retry": "1.2.3",
|
||||
"async-sema": "3.0.0",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@vercel/next",
|
||||
"version": "2.6.26",
|
||||
"version": "2.6.35",
|
||||
"license": "MIT",
|
||||
"main": "./dist/index",
|
||||
"homepage": "https://vercel.com/docs/runtimes#official-runtimes/next-js",
|
||||
@@ -29,7 +29,7 @@
|
||||
"@vercel/nft": "0.9.2",
|
||||
"async-sema": "3.0.1",
|
||||
"buffer-crc32": "0.2.13",
|
||||
"escape-string-regexp": "3.0.0",
|
||||
"escape-string-regexp": "2.0.0",
|
||||
"execa": "2.0.4",
|
||||
"find-up": "4.1.0",
|
||||
"fs-extra": "7.0.0",
|
||||
|
||||
@@ -59,7 +59,7 @@ export default async function createServerlessConfig(
|
||||
|
||||
const primaryConfigPath = path.join(entryPath, 'next.config.js');
|
||||
const secondaryConfigPath = path.join(workPath, 'next.config.js');
|
||||
const backupConfigName = `next.config.original.${Date.now()}.js`;
|
||||
const backupConfigName = `next.config.__vercel_builder_backup__.js`;
|
||||
|
||||
const hasPrimaryConfig = fs.existsSync(primaryConfigPath);
|
||||
const hasSecondaryConfig = fs.existsSync(secondaryConfigPath);
|
||||
|
||||
@@ -10,7 +10,7 @@ import {
|
||||
PrepareCacheOptions,
|
||||
Prerender,
|
||||
} from '@vercel/build-utils';
|
||||
import { Handler, Route } from '@vercel/routing-utils';
|
||||
import { Handler, Route, Source } from '@vercel/routing-utils';
|
||||
import {
|
||||
convertHeaders,
|
||||
convertRedirects,
|
||||
@@ -19,6 +19,7 @@ import {
|
||||
import { nodeFileTrace, NodeFileTraceReasons } from '@vercel/nft';
|
||||
import { Sema } from 'async-sema';
|
||||
import { ChildProcess, fork } from 'child_process';
|
||||
// escape-string-regexp version must match Next.js version
|
||||
import escapeStringRegexp from 'escape-string-regexp';
|
||||
import findUp from 'find-up';
|
||||
import { lstat, pathExists, readFile, remove, writeFile } from 'fs-extra';
|
||||
@@ -31,6 +32,7 @@ import buildUtils from './build-utils';
|
||||
import createServerlessConfig from './create-serverless-config';
|
||||
import nextLegacyVersions from './legacy-versions';
|
||||
import {
|
||||
addLocaleOrDefault,
|
||||
createLambdaFromPseudoLayers,
|
||||
createPseudoLayer,
|
||||
EnvConfig,
|
||||
@@ -39,6 +41,7 @@ import {
|
||||
getDynamicRoutes,
|
||||
getExportIntent,
|
||||
getExportStatus,
|
||||
getImagesManifest,
|
||||
getNextConfig,
|
||||
getPathsInside,
|
||||
getPrerenderManifest,
|
||||
@@ -46,6 +49,7 @@ import {
|
||||
getRoutesManifest,
|
||||
getSourceFilePathFromPage,
|
||||
isDynamicRoute,
|
||||
normalizeLocalePath,
|
||||
normalizePackageJson,
|
||||
normalizePage,
|
||||
PseudoLayer,
|
||||
@@ -219,7 +223,12 @@ export const build = async ({
|
||||
meta = {} as BuildParamsMeta,
|
||||
}: BuildParamsType): Promise<{
|
||||
routes: Route[];
|
||||
images?: { domains: string[]; sizes: number[] };
|
||||
output: Files;
|
||||
wildcard?: Array<{
|
||||
domain: string;
|
||||
value: string;
|
||||
}>;
|
||||
watch?: string[];
|
||||
childProcesses: ChildProcess[];
|
||||
}> => {
|
||||
@@ -302,6 +311,7 @@ export const build = async ({
|
||||
|
||||
return {
|
||||
output: {},
|
||||
images: undefined,
|
||||
routes: await getRoutes(
|
||||
entryPath,
|
||||
entryDirectory,
|
||||
@@ -367,7 +377,7 @@ export const build = async ({
|
||||
}
|
||||
|
||||
console.log('Installing dependencies...');
|
||||
await runNpmInstall(entryPath, ['--prefer-offline'], spawnOpts, meta);
|
||||
await runNpmInstall(entryPath, [], spawnOpts, meta);
|
||||
|
||||
// Refetch Next version now that dependencies are installed.
|
||||
// This will now resolve the actual installed Next version,
|
||||
@@ -420,6 +430,7 @@ export const build = async ({
|
||||
outputDirectory,
|
||||
nextVersion
|
||||
);
|
||||
const imagesManifest = await getImagesManifest(entryPath, outputDirectory);
|
||||
const prerenderManifest = await getPrerenderManifest(entryPath);
|
||||
const headers: Route[] = [];
|
||||
const rewrites: Route[] = [];
|
||||
@@ -428,6 +439,24 @@ export const build = async ({
|
||||
let dynamicRoutes: Route[] = [];
|
||||
// whether they have enabled pages/404.js as the custom 404 page
|
||||
let hasPages404 = false;
|
||||
let buildId = '';
|
||||
let escapedBuildId = '';
|
||||
|
||||
if (isLegacy || isSharedLambdas) {
|
||||
try {
|
||||
buildId = await readFile(
|
||||
path.join(entryPath, outputDirectory, 'BUILD_ID'),
|
||||
'utf8'
|
||||
);
|
||||
escapedBuildId = escapeStringRegexp(buildId);
|
||||
} catch (err) {
|
||||
throw new NowBuildError({
|
||||
code: 'NOW_NEXT_NO_BUILD_ID',
|
||||
message:
|
||||
'The BUILD_ID file was not found in the Output Directory. Did you forget to run "next build" in your Build Command?',
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (routesManifest) {
|
||||
switch (routesManifest.version) {
|
||||
@@ -458,7 +487,7 @@ export const build = async ({
|
||||
continue;
|
||||
}
|
||||
|
||||
dataRoutes.push({
|
||||
const route = {
|
||||
src: (
|
||||
dataRoute.namedDataRouteRegex || dataRoute.dataRouteRegex
|
||||
).replace(/^\^/, `^${appMountPrefixNoTrailingSlash}`),
|
||||
@@ -477,7 +506,47 @@ export const build = async ({
|
||||
}`
|
||||
),
|
||||
check: true,
|
||||
});
|
||||
};
|
||||
|
||||
const { i18n } = routesManifest;
|
||||
|
||||
if (i18n) {
|
||||
const origSrc = route.src;
|
||||
route.src = route.src.replace(
|
||||
// we need to double escape the build ID here
|
||||
// to replace it properly
|
||||
`/${escapedBuildId}/`,
|
||||
`/${escapedBuildId}/(?${
|
||||
ssgDataRoute ? '<nextLocale>' : ':'
|
||||
}${i18n.locales
|
||||
.map(locale => escapeStringRegexp(locale))
|
||||
.join('|')})/`
|
||||
);
|
||||
|
||||
// optional-catchall routes don't have slash between
|
||||
// build-id and the regex
|
||||
if (route.src === origSrc) {
|
||||
route.src = route.src.replace(
|
||||
// we need to double escape the build ID here
|
||||
// to replace it properly
|
||||
`/${escapedBuildId}`,
|
||||
`/${escapedBuildId}/(?${
|
||||
ssgDataRoute ? '<nextLocale>' : ':'
|
||||
}${i18n.locales
|
||||
.map(locale => escapeStringRegexp(locale))
|
||||
.join('|')})[/]?`
|
||||
);
|
||||
}
|
||||
|
||||
// make sure to route to the correct prerender output
|
||||
if (ssgDataRoute) {
|
||||
route.dest = route.dest.replace(
|
||||
`/${buildId}/`,
|
||||
`/${buildId}/$nextLocale/`
|
||||
);
|
||||
}
|
||||
}
|
||||
dataRoutes.push(route);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -519,6 +588,44 @@ export const build = async ({
|
||||
}
|
||||
}
|
||||
|
||||
if (imagesManifest) {
|
||||
switch (imagesManifest.version) {
|
||||
case 1: {
|
||||
if (!imagesManifest.images) {
|
||||
throw new NowBuildError({
|
||||
code: 'NEXT_IMAGES_MISSING',
|
||||
message:
|
||||
'image-manifest.json "images" is required. Contact support if this continues to happen.',
|
||||
});
|
||||
}
|
||||
const { images } = imagesManifest;
|
||||
if (!Array.isArray(images.domains)) {
|
||||
throw new NowBuildError({
|
||||
code: 'NEXT_IMAGES_DOMAINS',
|
||||
message:
|
||||
'image-manifest.json "images.domains" must be an array. Contact support if this continues to happen.',
|
||||
});
|
||||
}
|
||||
if (!Array.isArray(images.sizes)) {
|
||||
throw new NowBuildError({
|
||||
code: 'NEXT_IMAGES_DOMAINS',
|
||||
message:
|
||||
'image-manifest.json "images.sizes" must be an array. Contact support if this continues to happen.',
|
||||
});
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
throw new NowBuildError({
|
||||
code: 'NEXT_IMAGES_VERSION_UNKNOWN',
|
||||
message:
|
||||
'This version of `@vercel/next` does not support the version of Next.js you are trying to deploy.\n' +
|
||||
'Please upgrade your `@vercel/next` builder and try again. Contact support if this continues to happen.',
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const userExport = await getExportStatus(entryPath);
|
||||
|
||||
if (userExport) {
|
||||
@@ -564,6 +671,13 @@ export const build = async ({
|
||||
|
||||
return {
|
||||
output,
|
||||
images:
|
||||
imagesManifest?.images?.loader === 'default'
|
||||
? {
|
||||
domains: imagesManifest.images.domains,
|
||||
sizes: imagesManifest.images.sizes,
|
||||
}
|
||||
: undefined,
|
||||
routes: [
|
||||
// User headers
|
||||
...headers,
|
||||
@@ -645,12 +759,7 @@ export const build = async ({
|
||||
|
||||
if (isLegacy) {
|
||||
debug('Running npm install --production...');
|
||||
await runNpmInstall(
|
||||
entryPath,
|
||||
['--prefer-offline', '--production'],
|
||||
spawnOpts,
|
||||
meta
|
||||
);
|
||||
await runNpmInstall(entryPath, ['--production'], spawnOpts, meta);
|
||||
}
|
||||
|
||||
if (process.env.NPM_AUTH_TOKEN) {
|
||||
@@ -667,27 +776,7 @@ export const build = async ({
|
||||
const staticPages: { [key: string]: FileFsRef } = {};
|
||||
const dynamicPages: string[] = [];
|
||||
let static404Page: string | undefined;
|
||||
let buildId = '';
|
||||
let page404Path = '';
|
||||
let escapedBuildId = '';
|
||||
|
||||
if (isLegacy || isSharedLambdas) {
|
||||
try {
|
||||
buildId = await readFile(
|
||||
path.join(entryPath, outputDirectory, 'BUILD_ID'),
|
||||
'utf8'
|
||||
);
|
||||
escapedBuildId = escapeStringRegexp(buildId);
|
||||
} catch (err) {
|
||||
console.error(
|
||||
'BUILD_ID not found in ".next". The "package.json" "build" script did not run "next build"'
|
||||
);
|
||||
throw new NowBuildError({
|
||||
code: 'NOW_NEXT_NO_BUILD_ID',
|
||||
message: 'Missing BUILD_ID',
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (isLegacy) {
|
||||
const filesAfterBuild = await glob('**', entryPath);
|
||||
@@ -796,7 +885,10 @@ export const build = async ({
|
||||
|
||||
Object.keys(staticPageFiles).forEach((page: string) => {
|
||||
const pathname = page.replace(/\.html$/, '');
|
||||
const routeName = normalizePage(pathname);
|
||||
const routeName = normalizeLocalePath(
|
||||
normalizePage(pathname),
|
||||
routesManifest?.i18n?.locales
|
||||
).pathname;
|
||||
|
||||
// Prerendered routes emit a `.html` file but should not be treated as a
|
||||
// static page.
|
||||
@@ -804,7 +896,9 @@ export const build = async ({
|
||||
// Next.js versions so we need to also not treat it as a static page here.
|
||||
if (
|
||||
prerenderManifest.staticRoutes[routeName] ||
|
||||
prerenderManifest.fallbackRoutes[routeName]
|
||||
prerenderManifest.fallbackRoutes[routeName] ||
|
||||
prerenderManifest.staticRoutes[normalizePage(pathname)] ||
|
||||
prerenderManifest.fallbackRoutes[normalizePage(pathname)]
|
||||
) {
|
||||
return;
|
||||
}
|
||||
@@ -829,6 +923,17 @@ export const build = async ({
|
||||
? path.join(entryDirectory, '_errors/404')
|
||||
: undefined;
|
||||
|
||||
// TODO: locale specific 404s
|
||||
const { i18n } = routesManifest || {};
|
||||
|
||||
if (!static404Page && i18n) {
|
||||
static404Page = staticPages[
|
||||
path.join(entryDirectory, i18n.defaultLocale, '404')
|
||||
]
|
||||
? path.join(entryDirectory, i18n.defaultLocale, '404')
|
||||
: undefined;
|
||||
}
|
||||
|
||||
// > 1 because _error is a lambda but isn't used if a static 404 is available
|
||||
const pageKeys = Object.keys(pages);
|
||||
let hasLambdas = !static404Page || pageKeys.length > 1;
|
||||
@@ -1141,25 +1246,36 @@ export const build = async ({
|
||||
};
|
||||
}
|
||||
|
||||
const pageLambdaRoute: Route = {
|
||||
src: `^${escapeStringRegexp(outputName).replace(
|
||||
/\/index$/,
|
||||
'(/|/index|)'
|
||||
)}/?$`,
|
||||
dest: `${path.join('/', currentLambdaGroup.lambdaIdentifier)}`,
|
||||
headers: {
|
||||
'x-nextjs-page': outputName,
|
||||
},
|
||||
check: true,
|
||||
const addPageLambdaRoute = (escapedOutputPath: string) => {
|
||||
const pageLambdaRoute: Route = {
|
||||
src: `^${escapedOutputPath.replace(/\/index$/, '(/|/index|)')}/?$`,
|
||||
dest: `${path.join('/', currentLambdaGroup.lambdaIdentifier)}`,
|
||||
headers: {
|
||||
'x-nextjs-page': outputName,
|
||||
},
|
||||
check: true,
|
||||
};
|
||||
|
||||
// we only need to add the additional routes if shared lambdas
|
||||
// is enabled
|
||||
if (routeIsDynamic) {
|
||||
dynamicPageLambdaRoutes.push(pageLambdaRoute);
|
||||
dynamicPageLambdaRoutesMap[outputName] = pageLambdaRoute;
|
||||
} else {
|
||||
pageLambdaRoutes.push(pageLambdaRoute);
|
||||
}
|
||||
};
|
||||
|
||||
// we only need to add the additional routes if shared lambdas
|
||||
// is enabled
|
||||
if (routeIsDynamic) {
|
||||
dynamicPageLambdaRoutes.push(pageLambdaRoute);
|
||||
dynamicPageLambdaRoutesMap[outputName] = pageLambdaRoute;
|
||||
const { i18n } = routesManifest || {};
|
||||
|
||||
if (i18n) {
|
||||
addPageLambdaRoute(
|
||||
`[/]?(?:${i18n.locales
|
||||
.map(locale => escapeStringRegexp(locale))
|
||||
.join('|')})?${escapeStringRegexp(outputName)}`
|
||||
);
|
||||
} else {
|
||||
pageLambdaRoutes.push(pageLambdaRoute);
|
||||
addPageLambdaRoute(escapeStringRegexp(outputName));
|
||||
}
|
||||
|
||||
if (page === '_error.js' || (hasPages404 && page === '404.js')) {
|
||||
@@ -1288,7 +1404,34 @@ export const build = async ({
|
||||
new Set(prerenderManifest.omittedRoutes)
|
||||
).then(arr =>
|
||||
arr.map(route => {
|
||||
route.src = route.src.replace('^', `^${dynamicPrefix}`);
|
||||
const { i18n } = routesManifest || {};
|
||||
|
||||
if (i18n) {
|
||||
const { pathname } = url.parse(route.dest!);
|
||||
const isFallback = prerenderManifest.fallbackRoutes[pathname!];
|
||||
const isBlocking =
|
||||
prerenderManifest.blockingFallbackRoutes[pathname!];
|
||||
|
||||
route.src = route.src.replace(
|
||||
'^',
|
||||
`^${dynamicPrefix ? `${dynamicPrefix}[/]?` : '[/]?'}(?${
|
||||
isFallback || isBlocking ? '<nextLocale>' : ':'
|
||||
}${i18n.locales
|
||||
.map(locale => escapeStringRegexp(locale))
|
||||
.join('|')})?`
|
||||
);
|
||||
|
||||
if (isFallback || isBlocking) {
|
||||
// ensure destination has locale prefix to match prerender output
|
||||
// path so that the prerender object is used
|
||||
route.dest = route.dest!.replace(
|
||||
`${path.join('/', entryDirectory, '/')}`,
|
||||
`${path.join('/', entryDirectory, '$nextLocale', '/')}`
|
||||
);
|
||||
}
|
||||
} else {
|
||||
route.src = route.src.replace('^', `^${dynamicPrefix}`);
|
||||
}
|
||||
return route;
|
||||
})
|
||||
);
|
||||
@@ -1321,6 +1464,31 @@ export const build = async ({
|
||||
/\/\/ __LAUNCHER_PAGE_HANDLER__/g,
|
||||
`
|
||||
const url = require('url');
|
||||
|
||||
${
|
||||
routesManifest?.i18n
|
||||
? `
|
||||
function stripLocalePath(pathname) {
|
||||
// first item will be empty string from splitting at first char
|
||||
const pathnameParts = pathname.split('/')
|
||||
|
||||
;(${JSON.stringify(
|
||||
routesManifest.i18n.locales
|
||||
)}).some((locale) => {
|
||||
if (pathnameParts[1].toLowerCase() === locale.toLowerCase()) {
|
||||
pathnameParts.splice(1, 1)
|
||||
pathname = pathnameParts.join('/') || '/index'
|
||||
return true
|
||||
}
|
||||
return false
|
||||
})
|
||||
|
||||
return pathname
|
||||
}
|
||||
`
|
||||
: `function stripLocalePath(pathname) { return pathname }`
|
||||
}
|
||||
|
||||
page = function(req, res) {
|
||||
try {
|
||||
const pages = {
|
||||
@@ -1345,7 +1513,7 @@ export const build = async ({
|
||||
if (!toRender) {
|
||||
try {
|
||||
const { pathname } = url.parse(req.url)
|
||||
toRender = pathname.replace(/\\/$/, '')
|
||||
toRender = stripLocalePath(pathname).replace(/\\/$/, '') || '/index'
|
||||
} catch (_) {
|
||||
// handle failing to parse url
|
||||
res.statusCode = 400
|
||||
@@ -1364,6 +1532,7 @@ export const build = async ({
|
||||
.replace(new RegExp('/_next/data/${escapedBuildId}/'), '/')
|
||||
.replace(/\\.json$/, '')
|
||||
|
||||
toRender = stripLocalePath(toRender) || '/index'
|
||||
currentPage = pages[toRender]
|
||||
}
|
||||
|
||||
@@ -1391,8 +1560,9 @@ export const build = async ({
|
||||
|
||||
if (!currentPage) {
|
||||
console.error(
|
||||
"Failed to find matching page for", toRender, "in lambda"
|
||||
"Failed to find matching page for", {toRender, header: req.headers['x-nextjs-page'], url: req.url }, "in lambda"
|
||||
)
|
||||
console.error('pages in lambda', Object.keys(pages))
|
||||
res.statusCode = 500
|
||||
return res.end('internal server error')
|
||||
}
|
||||
@@ -1474,7 +1644,15 @@ export const build = async ({
|
||||
let prerenderGroup = 1;
|
||||
const onPrerenderRoute = (
|
||||
routeKey: string,
|
||||
{ isBlocking, isFallback }: { isBlocking: boolean; isFallback: boolean }
|
||||
{
|
||||
isBlocking,
|
||||
isFallback,
|
||||
locale,
|
||||
}: {
|
||||
isBlocking: boolean;
|
||||
isFallback: boolean;
|
||||
locale?: string;
|
||||
}
|
||||
) => {
|
||||
if (isBlocking && isFallback) {
|
||||
throw new NowBuildError({
|
||||
@@ -1484,7 +1662,27 @@ export const build = async ({
|
||||
}
|
||||
|
||||
// Get the route file as it'd be mounted in the builder output
|
||||
const routeFileNoExt = routeKey === '/' ? '/index' : routeKey;
|
||||
let routeFileNoExt = routeKey === '/' ? '/index' : routeKey;
|
||||
const origRouteFileNoExt = routeFileNoExt;
|
||||
|
||||
const nonDynamicSsg =
|
||||
!isFallback &&
|
||||
!isBlocking &&
|
||||
!prerenderManifest.staticRoutes[routeKey].srcRoute;
|
||||
|
||||
// if there isn't a srcRoute then it's a non-dynamic SSG page and
|
||||
if (nonDynamicSsg || isFallback) {
|
||||
routeFileNoExt = addLocaleOrDefault(
|
||||
// root index files are located without folder/index.html
|
||||
routeFileNoExt,
|
||||
routesManifest,
|
||||
locale
|
||||
);
|
||||
}
|
||||
|
||||
const isNotFound = prerenderManifest.notFoundRoutes.includes(
|
||||
routeFileNoExt
|
||||
);
|
||||
|
||||
const htmlFsRef = isBlocking
|
||||
? // Blocking pages do not have an HTML fallback
|
||||
@@ -1494,7 +1692,11 @@ export const build = async ({
|
||||
pagesDir,
|
||||
isFallback
|
||||
? // Fallback pages have a special file.
|
||||
prerenderManifest.fallbackRoutes[routeKey].fallback
|
||||
addLocaleOrDefault(
|
||||
prerenderManifest.fallbackRoutes[routeKey].fallback,
|
||||
routesManifest,
|
||||
locale
|
||||
)
|
||||
: // Otherwise, the route itself should exist as a static HTML
|
||||
// file.
|
||||
`${routeFileNoExt}.html`
|
||||
@@ -1533,14 +1735,30 @@ export const build = async ({
|
||||
}
|
||||
|
||||
const outputPathPage = path.posix.join(entryDirectory, routeFileNoExt);
|
||||
const outputPathPageOrig = path.posix.join(
|
||||
entryDirectory,
|
||||
origRouteFileNoExt
|
||||
);
|
||||
let lambda: undefined | Lambda;
|
||||
const outputPathData = path.posix.join(entryDirectory, dataRoute);
|
||||
let outputPathData = path.posix.join(entryDirectory, dataRoute);
|
||||
|
||||
if (nonDynamicSsg || isFallback) {
|
||||
outputPathData = outputPathData.replace(
|
||||
new RegExp(`${escapeStringRegexp(origRouteFileNoExt)}.json$`),
|
||||
`${routeFileNoExt}${
|
||||
routeFileNoExt !== origRouteFileNoExt &&
|
||||
origRouteFileNoExt === '/index'
|
||||
? '/index'
|
||||
: ''
|
||||
}.json`
|
||||
);
|
||||
}
|
||||
|
||||
if (isSharedLambdas) {
|
||||
const outputSrcPathPage = path.join(
|
||||
'/',
|
||||
srcRoute == null
|
||||
? outputPathPage
|
||||
? outputPathPageOrig
|
||||
: path.join(entryDirectory, srcRoute === '/' ? '/index' : srcRoute)
|
||||
);
|
||||
|
||||
@@ -1549,7 +1767,7 @@ export const build = async ({
|
||||
} else {
|
||||
const outputSrcPathPage =
|
||||
srcRoute == null
|
||||
? outputPathPage
|
||||
? outputPathPageOrig
|
||||
: path.posix.join(
|
||||
entryDirectory,
|
||||
srcRoute === '/' ? '/index' : srcRoute
|
||||
@@ -1558,7 +1776,7 @@ export const build = async ({
|
||||
lambda = lambdas[outputSrcPathPage];
|
||||
}
|
||||
|
||||
if (initialRevalidate === false) {
|
||||
if (!isNotFound && initialRevalidate === false) {
|
||||
if (htmlFsRef == null || jsonFsRef == null) {
|
||||
throw new NowBuildError({
|
||||
code: 'NEXT_HTMLFSREF_JSONFSREF',
|
||||
@@ -1573,7 +1791,7 @@ export const build = async ({
|
||||
}
|
||||
}
|
||||
|
||||
if (prerenders[outputPathPage] == null) {
|
||||
if (prerenders[outputPathPage] == null && !isNotFound) {
|
||||
if (lambda == null) {
|
||||
throw new NowBuildError({
|
||||
code: 'NEXT_MISSING_LAMBDA',
|
||||
@@ -1597,6 +1815,56 @@ export const build = async ({
|
||||
});
|
||||
|
||||
++prerenderGroup;
|
||||
|
||||
if (routesManifest?.i18n && isBlocking) {
|
||||
for (const locale of routesManifest.i18n.locales) {
|
||||
const localeRouteFileNoExt = addLocaleOrDefault(
|
||||
routeFileNoExt,
|
||||
routesManifest,
|
||||
locale
|
||||
);
|
||||
const localeOutputPathPage = path.posix.join(
|
||||
entryDirectory,
|
||||
localeRouteFileNoExt
|
||||
);
|
||||
const localeOutputPathData = outputPathData.replace(
|
||||
new RegExp(`${escapeStringRegexp(origRouteFileNoExt)}.json$`),
|
||||
`${localeRouteFileNoExt}${
|
||||
localeRouteFileNoExt !== origRouteFileNoExt &&
|
||||
origRouteFileNoExt === '/index'
|
||||
? '/index'
|
||||
: ''
|
||||
}.json`
|
||||
);
|
||||
|
||||
const origPrerenderPage = prerenders[outputPathPage];
|
||||
const origPrerenderData = prerenders[outputPathData];
|
||||
|
||||
prerenders[localeOutputPathPage] = {
|
||||
...origPrerenderPage,
|
||||
group: prerenderGroup,
|
||||
} as Prerender;
|
||||
|
||||
prerenders[localeOutputPathData] = {
|
||||
...origPrerenderData,
|
||||
group: prerenderGroup,
|
||||
} as Prerender;
|
||||
|
||||
++prerenderGroup;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ((nonDynamicSsg || isFallback) && routesManifest?.i18n && !locale) {
|
||||
// load each locale
|
||||
for (const locale of routesManifest.i18n.locales) {
|
||||
if (locale === routesManifest.i18n.defaultLocale) continue;
|
||||
onPrerenderRoute(routeKey, {
|
||||
isBlocking,
|
||||
isFallback,
|
||||
locale,
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1726,6 +1994,8 @@ export const build = async ({
|
||||
}
|
||||
}
|
||||
|
||||
const { i18n } = routesManifest || {};
|
||||
|
||||
return {
|
||||
output: {
|
||||
...publicDirectoryFiles,
|
||||
@@ -1736,6 +2006,24 @@ export const build = async ({
|
||||
...staticFiles,
|
||||
...staticDirectoryFiles,
|
||||
},
|
||||
wildcard: i18n?.domains
|
||||
? i18n?.domains.map(item => {
|
||||
return {
|
||||
domain: item.domain,
|
||||
value:
|
||||
item.defaultLocale === i18n.defaultLocale
|
||||
? ''
|
||||
: `/${item.defaultLocale}`,
|
||||
};
|
||||
})
|
||||
: undefined,
|
||||
images:
|
||||
imagesManifest?.images?.loader === 'default'
|
||||
? {
|
||||
domains: imagesManifest.images.domains,
|
||||
sizes: imagesManifest.images.sizes,
|
||||
}
|
||||
: undefined,
|
||||
/*
|
||||
Desired routes order
|
||||
- Runtime headers
|
||||
@@ -1751,24 +2039,174 @@ export const build = async ({
|
||||
...headers,
|
||||
|
||||
// redirects
|
||||
...redirects,
|
||||
...redirects.map(_redir => {
|
||||
if (i18n) {
|
||||
const redir = _redir as Source;
|
||||
// detect the trailing slash redirect and make sure it's
|
||||
// kept above the wildcard mapping to prevent erroneous redirects
|
||||
// since non-continue routes come after continue the $wildcard
|
||||
// route will come before the redirect otherwise and if the
|
||||
// redirect is triggered it breaks locale mapping
|
||||
|
||||
const location =
|
||||
redir.headers && (redir.headers.location || redir.headers.Location);
|
||||
|
||||
if (
|
||||
redir.status === 308 &&
|
||||
(location === '/$1' || location === '/$1/')
|
||||
) {
|
||||
// we set continue true
|
||||
redir.continue = true;
|
||||
}
|
||||
}
|
||||
return _redir;
|
||||
}),
|
||||
|
||||
...(i18n
|
||||
? [
|
||||
// Handle auto-adding current default locale to path based on $wildcard
|
||||
{
|
||||
src: `^${path.join(
|
||||
'/',
|
||||
entryDirectory,
|
||||
'/'
|
||||
)}(?!(?:_next/.*|${i18n.locales
|
||||
.map(locale => escapeStringRegexp(locale))
|
||||
.join('|')})(?:/.*|$))(.*)$`,
|
||||
// TODO: this needs to contain or not contain a trailing slash
|
||||
// to prevent the trailing slash redirect from being triggered
|
||||
dest: '$wildcard/$1',
|
||||
continue: true,
|
||||
},
|
||||
|
||||
// Handle redirecting to locale specific domains
|
||||
...(i18n.domains
|
||||
? [
|
||||
{
|
||||
// TODO: enable redirecting between domains, will require
|
||||
// updating the src with the desired locales to redirect
|
||||
src: `^${path.join(
|
||||
'/',
|
||||
entryDirectory
|
||||
)}/?(?:${i18n.locales
|
||||
.map(locale => escapeStringRegexp(locale))
|
||||
.join('|')})?/?$`,
|
||||
locale: {
|
||||
redirect: i18n.domains.reduce(
|
||||
(prev: Record<string, string>, item) => {
|
||||
prev[item.defaultLocale] = `http${
|
||||
item.http ? '' : 's'
|
||||
}://${item.domain}/`;
|
||||
|
||||
if (item.locales) {
|
||||
item.locales.map(locale => {
|
||||
prev[locale] = `http${item.http ? '' : 's'}://${
|
||||
item.domain
|
||||
}/${locale}`;
|
||||
});
|
||||
}
|
||||
return prev;
|
||||
},
|
||||
{}
|
||||
),
|
||||
cookie: 'NEXT_LOCALE',
|
||||
},
|
||||
continue: true,
|
||||
},
|
||||
]
|
||||
: []),
|
||||
|
||||
// Handle redirecting to locale paths
|
||||
{
|
||||
// TODO: enable redirecting between paths, will require
|
||||
// updating the src with the desired locales to redirect.
|
||||
// if default locale is included in this src it won't be visitable
|
||||
// by users who prefer another language since the cookie isn't set
|
||||
// on redirect currently like in `next start`
|
||||
src: '/',
|
||||
locale: {
|
||||
redirect: i18n.locales.reduce(
|
||||
(prev: Record<string, string>, locale) => {
|
||||
prev[locale] =
|
||||
locale === i18n.defaultLocale ? `/` : `/${locale}`;
|
||||
return prev;
|
||||
},
|
||||
{}
|
||||
),
|
||||
cookie: 'NEXT_LOCALE',
|
||||
},
|
||||
continue: true,
|
||||
},
|
||||
|
||||
{
|
||||
src: `^${path.join('/', entryDirectory)}$`,
|
||||
dest: `/${i18n.defaultLocale}`,
|
||||
continue: true,
|
||||
},
|
||||
|
||||
// Auto-prefix non-locale path with default locale
|
||||
// note for prerendered pages this will cause
|
||||
// x-now-route-matches to contain the path minus the locale
|
||||
// e.g. for /de/posts/[slug] x-now-route-matches would have
|
||||
// 1=posts%2Fpost-1
|
||||
{
|
||||
src: `^${path.join(
|
||||
'/',
|
||||
entryDirectory,
|
||||
'/'
|
||||
)}(?!(?:_next/.*|${i18n.locales
|
||||
.map(locale => escapeStringRegexp(locale))
|
||||
.join('|')})(?:/.*|$))(.*)$`,
|
||||
dest: `/${i18n.defaultLocale}/$1`,
|
||||
continue: true,
|
||||
},
|
||||
]
|
||||
: []),
|
||||
|
||||
// Make sure to 404 for the /404 path itself
|
||||
{
|
||||
src: path.join('/', entryDirectory, '404'),
|
||||
status: 404,
|
||||
continue: true,
|
||||
},
|
||||
...(i18n
|
||||
? [
|
||||
{
|
||||
src: `${path.join(
|
||||
'/',
|
||||
entryDirectory,
|
||||
'/'
|
||||
)}(?:${i18n.locales
|
||||
.map(locale => escapeStringRegexp(locale))
|
||||
.join('|')})?[/]?404`,
|
||||
status: 404,
|
||||
continue: true,
|
||||
},
|
||||
]
|
||||
: [
|
||||
{
|
||||
src: path.join('/', entryDirectory, '404'),
|
||||
status: 404,
|
||||
continue: true,
|
||||
},
|
||||
]),
|
||||
|
||||
// Next.js page lambdas, `static/` folder, reserved assets, and `public/`
|
||||
// folder
|
||||
{ handle: 'filesystem' },
|
||||
|
||||
// map pages to their lambda
|
||||
...pageLambdaRoutes,
|
||||
...pageLambdaRoutes.filter(route => {
|
||||
// filter out any SSG pages as they are already present in output
|
||||
if ('headers' in route) {
|
||||
let page = route.headers?.['x-nextjs-page']!;
|
||||
page = page === '/index' ? '/' : page;
|
||||
|
||||
// map /blog/[post] to correct lambda for iSSG
|
||||
...dynamicPageLambdaRoutes,
|
||||
if (
|
||||
prerenderManifest.staticRoutes[page] ||
|
||||
prerenderManifest.fallbackRoutes[page] ||
|
||||
prerenderManifest.blockingFallbackRoutes[page]
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}),
|
||||
|
||||
// These need to come before handle: miss or else they are grouped
|
||||
// with that routing section
|
||||
@@ -1788,6 +2226,40 @@ export const build = async ({
|
||||
dest: '$0',
|
||||
},
|
||||
|
||||
// remove default locale prefix to check public files
|
||||
...(i18n
|
||||
? [
|
||||
{
|
||||
src: `${path.join(
|
||||
'/',
|
||||
entryDirectory,
|
||||
i18n.defaultLocale,
|
||||
'/'
|
||||
)}(.*)`,
|
||||
dest: `${path.join('/', entryDirectory, '/')}$1`,
|
||||
check: true,
|
||||
},
|
||||
]
|
||||
: []),
|
||||
|
||||
// for non-shared lambdas remove locale prefix if present
|
||||
// to allow checking for lambda
|
||||
...(isSharedLambdas || !i18n
|
||||
? []
|
||||
: [
|
||||
{
|
||||
src: `${path.join(
|
||||
'/',
|
||||
entryDirectory,
|
||||
'/'
|
||||
)}(?:${i18n?.locales
|
||||
.map(locale => escapeStringRegexp(locale))
|
||||
.join('|')})/(.*)`,
|
||||
dest: '/$1',
|
||||
check: true,
|
||||
},
|
||||
]),
|
||||
|
||||
// routes that are called after each rewrite or after routes
|
||||
// if there no rewrites
|
||||
{ handle: 'rewrite' },
|
||||
@@ -1828,39 +2300,60 @@ export const build = async ({
|
||||
// Custom Next.js 404 page
|
||||
{ handle: 'error' } as Handler,
|
||||
|
||||
isSharedLambdas
|
||||
? {
|
||||
src: path.join('/', entryDirectory, '.*'),
|
||||
// if static 404 is not present but we have pages/404.js
|
||||
// it is a lambda due to _app getInitialProps
|
||||
dest: path.join(
|
||||
'/',
|
||||
(static404Page
|
||||
? static404Page
|
||||
: pageLambdaMap[page404Path]) as string
|
||||
),
|
||||
|
||||
status: 404,
|
||||
headers: {
|
||||
'x-nextjs-page': page404Path,
|
||||
...(i18n && static404Page
|
||||
? [
|
||||
{
|
||||
src: `${path.join(
|
||||
'/',
|
||||
entryDirectory,
|
||||
'/'
|
||||
)}(?<nextLocale>${i18n.locales
|
||||
.map(locale => escapeStringRegexp(locale))
|
||||
.join('|')})(/.*|$)`,
|
||||
dest: '/$nextLocale/404',
|
||||
status: 404,
|
||||
},
|
||||
}
|
||||
: {
|
||||
src: path.join('/', entryDirectory, '.*'),
|
||||
// if static 404 is not present but we have pages/404.js
|
||||
// it is a lambda due to _app getInitialProps
|
||||
dest: static404Page
|
||||
? path.join('/', static404Page)
|
||||
: path.join(
|
||||
'/',
|
||||
entryDirectory,
|
||||
hasPages404 &&
|
||||
lambdas[path.join('./', entryDirectory, '404')]
|
||||
? '404'
|
||||
: '_error'
|
||||
),
|
||||
status: 404,
|
||||
},
|
||||
{
|
||||
src: path.join('/', entryDirectory, '.*'),
|
||||
dest: `/${i18n.defaultLocale}/404`,
|
||||
status: 404,
|
||||
},
|
||||
]
|
||||
: [
|
||||
isSharedLambdas
|
||||
? {
|
||||
src: path.join('/', entryDirectory, '.*'),
|
||||
// if static 404 is not present but we have pages/404.js
|
||||
// it is a lambda due to _app getInitialProps
|
||||
dest: path.join(
|
||||
'/',
|
||||
(static404Page
|
||||
? static404Page
|
||||
: pageLambdaMap[page404Path]) as string
|
||||
),
|
||||
|
||||
status: 404,
|
||||
headers: {
|
||||
'x-nextjs-page': page404Path,
|
||||
},
|
||||
}
|
||||
: {
|
||||
src: path.join('/', entryDirectory, '.*'),
|
||||
// if static 404 is not present but we have pages/404.js
|
||||
// it is a lambda due to _app getInitialProps
|
||||
dest: static404Page
|
||||
? path.join('/', static404Page)
|
||||
: path.join(
|
||||
'/',
|
||||
entryDirectory,
|
||||
hasPages404 &&
|
||||
lambdas[path.join('./', entryDirectory, '404')]
|
||||
? '404'
|
||||
: '_error'
|
||||
),
|
||||
status: 404,
|
||||
},
|
||||
]),
|
||||
]),
|
||||
],
|
||||
watch: [],
|
||||
|
||||
@@ -326,6 +326,16 @@ export type RoutesManifest = {
|
||||
namedDataRouteRegex?: string;
|
||||
routeKeys?: { [named: string]: string };
|
||||
}>;
|
||||
i18n?: {
|
||||
defaultLocale: string;
|
||||
locales: string[];
|
||||
domains?: Array<{
|
||||
http?: boolean;
|
||||
domain: string;
|
||||
locales?: string[];
|
||||
defaultLocale: string;
|
||||
}>;
|
||||
};
|
||||
};
|
||||
|
||||
export async function getRoutesManifest(
|
||||
@@ -502,6 +512,41 @@ export async function getDynamicRoutes(
|
||||
return routes;
|
||||
}
|
||||
|
||||
type LoaderKey = 'imgix' | 'cloudinary' | 'akamai' | 'default';
|
||||
|
||||
type ImagesManifest = {
|
||||
version: number;
|
||||
images: {
|
||||
loader: LoaderKey;
|
||||
sizes: number[];
|
||||
domains: string[];
|
||||
};
|
||||
};
|
||||
|
||||
export async function getImagesManifest(
|
||||
entryPath: string,
|
||||
outputDirectory: string
|
||||
): Promise<ImagesManifest | undefined> {
|
||||
const pathImagesManifest = path.join(
|
||||
entryPath,
|
||||
outputDirectory,
|
||||
'images-manifest.json'
|
||||
);
|
||||
|
||||
const hasImagesManifest = await fs
|
||||
.access(pathImagesManifest)
|
||||
.then(() => true)
|
||||
.catch(() => false);
|
||||
|
||||
if (!hasImagesManifest) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||
const imagesManifest: ImagesManifest = require(pathImagesManifest);
|
||||
return imagesManifest;
|
||||
}
|
||||
|
||||
function syncEnvVars(base: EnvConfig, removeEnv: EnvConfig, addEnv: EnvConfig) {
|
||||
// Remove any env vars from `removeEnv`
|
||||
// that are not present in the `addEnv`
|
||||
@@ -711,6 +756,8 @@ export type NextPrerenderedRoutes = {
|
||||
};
|
||||
|
||||
omittedRoutes: string[];
|
||||
|
||||
notFoundRoutes: string[];
|
||||
};
|
||||
|
||||
export async function getExportIntent(
|
||||
@@ -801,6 +848,7 @@ export async function getPrerenderManifest(
|
||||
fallbackRoutes: {},
|
||||
bypassToken: null,
|
||||
omittedRoutes: [],
|
||||
notFoundRoutes: [],
|
||||
};
|
||||
}
|
||||
|
||||
@@ -846,6 +894,7 @@ export async function getPrerenderManifest(
|
||||
preview: {
|
||||
previewModeId: string;
|
||||
};
|
||||
notFoundRoutes?: string[];
|
||||
} = JSON.parse(await fs.readFile(pathPrerenderManifest, 'utf8'));
|
||||
|
||||
switch (manifest.version) {
|
||||
@@ -860,6 +909,7 @@ export async function getPrerenderManifest(
|
||||
bypassToken:
|
||||
(manifest.preview && manifest.preview.previewModeId) || null,
|
||||
omittedRoutes: [],
|
||||
notFoundRoutes: [],
|
||||
};
|
||||
|
||||
routes.forEach(route => {
|
||||
@@ -914,8 +964,13 @@ export async function getPrerenderManifest(
|
||||
fallbackRoutes: {},
|
||||
bypassToken: manifest.preview.previewModeId,
|
||||
omittedRoutes: [],
|
||||
notFoundRoutes: [],
|
||||
};
|
||||
|
||||
if (manifest.notFoundRoutes) {
|
||||
ret.notFoundRoutes.push(...manifest.notFoundRoutes);
|
||||
}
|
||||
|
||||
routes.forEach(route => {
|
||||
const {
|
||||
initialRevalidateSeconds,
|
||||
@@ -969,6 +1024,7 @@ export async function getPrerenderManifest(
|
||||
fallbackRoutes: {},
|
||||
bypassToken: null,
|
||||
omittedRoutes: [],
|
||||
notFoundRoutes: [],
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1034,6 +1090,46 @@ function isDirectory(path: string) {
|
||||
return fs.existsSync(path) && fs.lstatSync(path).isDirectory();
|
||||
}
|
||||
|
||||
export function normalizeLocalePath(
|
||||
pathname: string,
|
||||
locales?: string[]
|
||||
): {
|
||||
detectedLocale?: string;
|
||||
pathname: string;
|
||||
} {
|
||||
let detectedLocale: string | undefined;
|
||||
// first item will be empty string from splitting at first char
|
||||
const pathnameParts = pathname.split('/');
|
||||
|
||||
(locales || []).some(locale => {
|
||||
if (pathnameParts[1].toLowerCase() === locale.toLowerCase()) {
|
||||
detectedLocale = locale;
|
||||
pathnameParts.splice(1, 1);
|
||||
pathname = pathnameParts.join('/') || '/';
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
return {
|
||||
pathname,
|
||||
detectedLocale,
|
||||
};
|
||||
}
|
||||
|
||||
export function addLocaleOrDefault(
|
||||
pathname: string,
|
||||
routesManifest?: RoutesManifest,
|
||||
locale?: string
|
||||
) {
|
||||
if (!routesManifest?.i18n) return pathname;
|
||||
if (!locale) locale = routesManifest.i18n.defaultLocale;
|
||||
|
||||
return locale
|
||||
? `/${locale}${pathname === '/index' ? '' : pathname}`
|
||||
: pathname;
|
||||
}
|
||||
|
||||
export {
|
||||
excludeFiles,
|
||||
validateEntrypoint,
|
||||
|
||||
21
packages/now-next/test/fixtures/00-i18n-support-no-shared-lambdas/next.config.js
vendored
Normal file
21
packages/now-next/test/fixtures/00-i18n-support-no-shared-lambdas/next.config.js
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
module.exports = {
|
||||
generateBuildId() {
|
||||
return 'testing-build-id';
|
||||
},
|
||||
i18n: {
|
||||
locales: ['nl-NL', 'nl-BE', 'nl', 'fr-BE', 'fr', 'en-US', 'en'],
|
||||
defaultLocale: 'en-US',
|
||||
// TODO: testing locale domains support, will require custom
|
||||
// testing set-up as test accounts are used currently
|
||||
domains: [
|
||||
{
|
||||
domain: 'example.be',
|
||||
defaultLocale: 'nl-BE',
|
||||
},
|
||||
{
|
||||
domain: 'example.fr',
|
||||
defaultLocale: 'fr',
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
318
packages/now-next/test/fixtures/00-i18n-support-no-shared-lambdas/now.json
vendored
Normal file
318
packages/now-next/test/fixtures/00-i18n-support-no-shared-lambdas/now.json
vendored
Normal file
@@ -0,0 +1,318 @@
|
||||
{
|
||||
"version": 2,
|
||||
"builds": [
|
||||
{
|
||||
"src": "package.json",
|
||||
"use": "@vercel/next",
|
||||
"config": {
|
||||
"sharedLambdas": false
|
||||
}
|
||||
}
|
||||
],
|
||||
"probes": [
|
||||
{
|
||||
"path": "/",
|
||||
"headers": {
|
||||
"accept-language": "en;q=0.9"
|
||||
},
|
||||
"fetchOptions": {
|
||||
"redirect": "manual"
|
||||
},
|
||||
"status": 307,
|
||||
"responseHeaders": {
|
||||
"location": "//en/"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "/",
|
||||
"headers": {
|
||||
"accept-language": "nl;q=0.9"
|
||||
},
|
||||
"fetchOptions": {
|
||||
"redirect": "manual"
|
||||
},
|
||||
"status": 307,
|
||||
"responseHeaders": {
|
||||
"location": "//nl/"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "/",
|
||||
"headers": {
|
||||
"accept-language": "nl-NL;q=0.9"
|
||||
},
|
||||
"fetchOptions": {
|
||||
"redirect": "manual"
|
||||
},
|
||||
"status": 307,
|
||||
"responseHeaders": {
|
||||
"location": "//nl-NL/"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "/",
|
||||
"headers": {
|
||||
"accept-language": "fr;q=0.9"
|
||||
},
|
||||
"fetchOptions": {
|
||||
"redirect": "manual"
|
||||
},
|
||||
"status": 307,
|
||||
"responseHeaders": {
|
||||
"location": "//fr/"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "/",
|
||||
"headers": {
|
||||
"accept-language": "en-US;q=0.9"
|
||||
},
|
||||
"fetchOptions": {
|
||||
"redirect": "manual"
|
||||
},
|
||||
"status": 200,
|
||||
"mustContain": "index page"
|
||||
},
|
||||
{
|
||||
"path": "/en-US",
|
||||
"headers": {
|
||||
"accept-language": "nl;q=0.9"
|
||||
},
|
||||
"fetchOptions": {
|
||||
"redirect": "manual"
|
||||
},
|
||||
"status": 200,
|
||||
"mustContain": "index page"
|
||||
},
|
||||
|
||||
{
|
||||
"path": "/",
|
||||
"status": 200,
|
||||
"mustContain": "index page"
|
||||
},
|
||||
{
|
||||
"path": "/",
|
||||
"status": 200,
|
||||
"mustContain": ">en-US<"
|
||||
},
|
||||
{
|
||||
"path": "/en",
|
||||
"status": 200,
|
||||
"mustContain": "index page"
|
||||
},
|
||||
{
|
||||
"path": "/en",
|
||||
"status": 200,
|
||||
"mustContain": ">en<"
|
||||
},
|
||||
{
|
||||
"path": "/fr",
|
||||
"status": 200,
|
||||
"mustContain": "index page"
|
||||
},
|
||||
{
|
||||
"path": "/fr",
|
||||
"status": 200,
|
||||
"mustContain": ">fr<"
|
||||
},
|
||||
{
|
||||
"path": "/nl",
|
||||
"status": 200,
|
||||
"mustContain": "index page"
|
||||
},
|
||||
{
|
||||
"path": "/nl",
|
||||
"status": 200,
|
||||
"mustContain": ">nl<"
|
||||
},
|
||||
{
|
||||
"path": "/nl-NL",
|
||||
"status": 200,
|
||||
"mustContain": "index page"
|
||||
},
|
||||
{
|
||||
"path": "/nl-NL",
|
||||
"status": 200,
|
||||
"mustContain": ">nl-NL<"
|
||||
},
|
||||
|
||||
{
|
||||
"path": "/non-existent",
|
||||
"status": 404
|
||||
},
|
||||
{
|
||||
"path": "/fr/non-existent",
|
||||
"status": 404,
|
||||
"mustContain": "lang=\"fr\""
|
||||
},
|
||||
{
|
||||
"path": "/en/non-existent",
|
||||
"status": 404,
|
||||
"mustContain": "lang=\"en\""
|
||||
},
|
||||
{
|
||||
"path": "/en-US/non-existent",
|
||||
"status": 404,
|
||||
"mustContain": "lang=\"en-US\""
|
||||
},
|
||||
{
|
||||
"path": "/nl/non-existent",
|
||||
"status": 404,
|
||||
"mustContain": "lang=\"nl\""
|
||||
},
|
||||
{
|
||||
"path": "/nl-NL/non-existent",
|
||||
"status": 404,
|
||||
"mustContain": "lang=\"nl-NL\""
|
||||
},
|
||||
|
||||
{
|
||||
"path": "/hello.txt",
|
||||
"status": 200,
|
||||
"mustContain": "hello world!"
|
||||
},
|
||||
|
||||
{
|
||||
"path": "/gsp",
|
||||
"status": 200,
|
||||
"mustContain": "gsp page"
|
||||
},
|
||||
{
|
||||
"path": "/gsp",
|
||||
"status": 200,
|
||||
"mustContain": ">en-US<"
|
||||
},
|
||||
{
|
||||
"path": "/en/gsp",
|
||||
"status": 200,
|
||||
"mustContain": "gsp page"
|
||||
},
|
||||
{
|
||||
"path": "/en/gsp",
|
||||
"status": 200,
|
||||
"mustContain": ">en<"
|
||||
},
|
||||
{
|
||||
"path": "/nl/gsp",
|
||||
"status": 200,
|
||||
"mustContain": "gsp page"
|
||||
},
|
||||
{
|
||||
"path": "/nl/gsp",
|
||||
"status": 200,
|
||||
"mustContain": ">nl<"
|
||||
},
|
||||
{
|
||||
"path": "/fr/gsp",
|
||||
"status": 200,
|
||||
"mustContain": "gsp page"
|
||||
},
|
||||
{
|
||||
"path": "/fr/gsp",
|
||||
"status": 200,
|
||||
"mustContain": ">fr<"
|
||||
},
|
||||
|
||||
{
|
||||
"path": "/gssp",
|
||||
"status": 200,
|
||||
"mustContain": "gssp page"
|
||||
},
|
||||
{
|
||||
"path": "/gssp",
|
||||
"status": 200,
|
||||
"mustContain": ">en-US<"
|
||||
},
|
||||
{
|
||||
"path": "/en/gssp",
|
||||
"status": 200,
|
||||
"mustContain": "gssp page"
|
||||
},
|
||||
{
|
||||
"path": "/en/gssp",
|
||||
"status": 200,
|
||||
"mustContain": ">en<"
|
||||
},
|
||||
{
|
||||
"path": "/nl/gssp",
|
||||
"status": 200,
|
||||
"mustContain": "gssp page"
|
||||
},
|
||||
{
|
||||
"path": "/nl/gssp",
|
||||
"status": 200,
|
||||
"mustContain": ">nl<"
|
||||
},
|
||||
{
|
||||
"path": "/fr/gssp",
|
||||
"status": 200,
|
||||
"mustContain": "gssp page"
|
||||
},
|
||||
{
|
||||
"path": "/fr/gssp",
|
||||
"status": 200,
|
||||
"mustContain": ">fr<"
|
||||
},
|
||||
|
||||
{
|
||||
"path": "/gssp/first",
|
||||
"status": 200,
|
||||
"mustContain": "gssp page"
|
||||
},
|
||||
{
|
||||
"path": "/gssp/first",
|
||||
"status": 200,
|
||||
"mustContain": ">en-US<"
|
||||
},
|
||||
{
|
||||
"path": "/gssp/first",
|
||||
"status": 200,
|
||||
"mustContain": "slug\":\"first\""
|
||||
},
|
||||
{
|
||||
"path": "/en/gssp/first",
|
||||
"status": 200,
|
||||
"mustContain": "gssp page"
|
||||
},
|
||||
{
|
||||
"path": "/en/gssp/first",
|
||||
"status": 200,
|
||||
"mustContain": ">en<"
|
||||
},
|
||||
{
|
||||
"path": "/en/gssp/first",
|
||||
"status": 200,
|
||||
"mustContain": "slug\":\"first\""
|
||||
},
|
||||
{
|
||||
"path": "/nl/gssp/first",
|
||||
"status": 200,
|
||||
"mustContain": "gssp page"
|
||||
},
|
||||
{
|
||||
"path": "/nl/gssp/first",
|
||||
"status": 200,
|
||||
"mustContain": ">nl<"
|
||||
},
|
||||
{
|
||||
"path": "/nl/gssp/first",
|
||||
"status": 200,
|
||||
"mustContain": "slug\":\"first\""
|
||||
},
|
||||
{
|
||||
"path": "/fr/gssp/first",
|
||||
"status": 200,
|
||||
"mustContain": "gssp page"
|
||||
},
|
||||
{
|
||||
"path": "/fr/gssp/first",
|
||||
"status": 200,
|
||||
"mustContain": ">fr<"
|
||||
},
|
||||
{
|
||||
"path": "/fr/gssp/first",
|
||||
"status": 200,
|
||||
"mustContain": "slug\":\"first\""
|
||||
}
|
||||
]
|
||||
}
|
||||
7
packages/now-next/test/fixtures/00-i18n-support-no-shared-lambdas/package.json
vendored
Normal file
7
packages/now-next/test/fixtures/00-i18n-support-no-shared-lambdas/package.json
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"dependencies": {
|
||||
"next": "canary",
|
||||
"react": "^16.8.6",
|
||||
"react-dom": "^16.8.6"
|
||||
}
|
||||
}
|
||||
31
packages/now-next/test/fixtures/00-i18n-support-no-shared-lambdas/pages/another.js
vendored
Normal file
31
packages/now-next/test/fixtures/00-i18n-support-no-shared-lambdas/pages/another.js
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
import Link from 'next/link';
|
||||
import { useRouter } from 'next/router';
|
||||
|
||||
export default function Page(props) {
|
||||
const router = useRouter();
|
||||
|
||||
return (
|
||||
<>
|
||||
<p id="another">another page</p>
|
||||
<p id="props">{JSON.stringify(props)}</p>
|
||||
<p id="router-locale">{router.locale}</p>
|
||||
<p id="router-locales">{JSON.stringify(router.locales)}</p>
|
||||
<p id="router-query">{JSON.stringify(router.query)}</p>
|
||||
<p id="router-pathname">{router.pathname}</p>
|
||||
<p id="router-as-path">{router.asPath}</p>
|
||||
<Link href="/">
|
||||
<a id="to-index">to /</a>
|
||||
</Link>
|
||||
<br />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export const getServerSideProps = ({ locale, locales }) => {
|
||||
return {
|
||||
props: {
|
||||
locale,
|
||||
locales,
|
||||
},
|
||||
};
|
||||
};
|
||||
21
packages/now-next/test/fixtures/00-i18n-support-no-shared-lambdas/pages/auto-export/index.js
vendored
Normal file
21
packages/now-next/test/fixtures/00-i18n-support-no-shared-lambdas/pages/auto-export/index.js
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
import Link from 'next/link';
|
||||
import { useRouter } from 'next/router';
|
||||
|
||||
export default function Page(props) {
|
||||
const router = useRouter();
|
||||
|
||||
return (
|
||||
<>
|
||||
<p id="auto-export">auto-export page</p>
|
||||
<p id="props">{JSON.stringify(props)}</p>
|
||||
<p id="router-locale">{router.locale}</p>
|
||||
<p id="router-locales">{JSON.stringify(router.locales)}</p>
|
||||
<p id="router-query">{JSON.stringify(router.query)}</p>
|
||||
<p id="router-pathname">{router.pathname}</p>
|
||||
<p id="router-as-path">{router.asPath}</p>
|
||||
<Link href="/">
|
||||
<a id="to-index">to /</a>
|
||||
</Link>
|
||||
</>
|
||||
);
|
||||
}
|
||||
44
packages/now-next/test/fixtures/00-i18n-support-no-shared-lambdas/pages/gsp/fallback/[slug].js
vendored
Normal file
44
packages/now-next/test/fixtures/00-i18n-support-no-shared-lambdas/pages/gsp/fallback/[slug].js
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
import Link from 'next/link';
|
||||
import { useRouter } from 'next/router';
|
||||
|
||||
export default function Page(props) {
|
||||
const router = useRouter();
|
||||
|
||||
if (router.isFallback) return 'Loading...';
|
||||
|
||||
return (
|
||||
<>
|
||||
<p id="gsp">gsp page</p>
|
||||
<p id="props">{JSON.stringify(props)}</p>
|
||||
<p id="router-locale">{router.locale}</p>
|
||||
<p id="router-locales">{JSON.stringify(router.locales)}</p>
|
||||
<p id="router-query">{JSON.stringify(router.query)}</p>
|
||||
<p id="router-pathname">{router.pathname}</p>
|
||||
<p id="router-as-path">{router.asPath}</p>
|
||||
<Link href="/">
|
||||
<a id="to-index">to /</a>
|
||||
</Link>
|
||||
<br />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export const getStaticProps = ({ params, locale, locales }) => {
|
||||
return {
|
||||
props: {
|
||||
params,
|
||||
locale,
|
||||
locales,
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
export const getStaticPaths = () => {
|
||||
return {
|
||||
// the default locale will be used since one isn't defined here
|
||||
paths: ['first', 'second'].map(slug => ({
|
||||
params: { slug },
|
||||
})),
|
||||
fallback: true,
|
||||
};
|
||||
};
|
||||
32
packages/now-next/test/fixtures/00-i18n-support-no-shared-lambdas/pages/gsp/index.js
vendored
Normal file
32
packages/now-next/test/fixtures/00-i18n-support-no-shared-lambdas/pages/gsp/index.js
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
import Link from 'next/link';
|
||||
import { useRouter } from 'next/router';
|
||||
|
||||
export default function Page(props) {
|
||||
const router = useRouter();
|
||||
|
||||
return (
|
||||
<>
|
||||
<p id="gsp">gsp page</p>
|
||||
<p id="props">{JSON.stringify(props)}</p>
|
||||
<p id="router-locale">{router.locale}</p>
|
||||
<p id="router-locales">{JSON.stringify(router.locales)}</p>
|
||||
<p id="router-query">{JSON.stringify(router.query)}</p>
|
||||
<p id="router-pathname">{router.pathname}</p>
|
||||
<p id="router-as-path">{router.asPath}</p>
|
||||
<Link href="/">
|
||||
<a id="to-index">to /</a>
|
||||
</Link>
|
||||
<br />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
// TODO: should non-dynamic GSP pages pre-render for each locale?
|
||||
export const getStaticProps = ({ locale, locales }) => {
|
||||
return {
|
||||
props: {
|
||||
locale,
|
||||
locales,
|
||||
},
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,46 @@
|
||||
import Link from 'next/link';
|
||||
import { useRouter } from 'next/router';
|
||||
|
||||
export default function Page(props) {
|
||||
const router = useRouter();
|
||||
|
||||
if (router.isFallback) return 'Loading...';
|
||||
|
||||
return (
|
||||
<>
|
||||
<p id="gsp">gsp page</p>
|
||||
<p id="props">{JSON.stringify(props)}</p>
|
||||
<p id="router-locale">{router.locale}</p>
|
||||
<p id="router-locales">{JSON.stringify(router.locales)}</p>
|
||||
<p id="router-query">{JSON.stringify(router.query)}</p>
|
||||
<p id="router-pathname">{router.pathname}</p>
|
||||
<p id="router-as-path">{router.asPath}</p>
|
||||
<Link href="/">
|
||||
<a id="to-index">to /</a>
|
||||
</Link>
|
||||
<br />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export const getStaticProps = ({ params, locale, locales }) => {
|
||||
return {
|
||||
props: {
|
||||
params,
|
||||
locale,
|
||||
locales,
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
export const getStaticPaths = () => {
|
||||
return {
|
||||
paths: [
|
||||
{ params: { slug: 'first' } },
|
||||
'/gsp/no-fallback/second',
|
||||
{ params: { slug: 'first' }, locale: 'en-US' },
|
||||
'/nl-NL/gsp/no-fallback/second',
|
||||
],
|
||||
fallback: false,
|
||||
};
|
||||
};
|
||||
32
packages/now-next/test/fixtures/00-i18n-support-no-shared-lambdas/pages/gssp/[slug].js
vendored
Normal file
32
packages/now-next/test/fixtures/00-i18n-support-no-shared-lambdas/pages/gssp/[slug].js
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
import Link from 'next/link';
|
||||
import { useRouter } from 'next/router';
|
||||
|
||||
export default function Page(props) {
|
||||
const router = useRouter();
|
||||
|
||||
return (
|
||||
<>
|
||||
<p id="gssp">gssp page</p>
|
||||
<p id="props">{JSON.stringify(props)}</p>
|
||||
<p id="router-locale">{router.locale}</p>
|
||||
<p id="router-locales">{JSON.stringify(router.locales)}</p>
|
||||
<p id="router-query">{JSON.stringify(router.query)}</p>
|
||||
<p id="router-pathname">{router.pathname}</p>
|
||||
<p id="router-as-path">{router.asPath}</p>
|
||||
<Link href="/">
|
||||
<a id="to-index">to /</a>
|
||||
</Link>
|
||||
<br />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export const getServerSideProps = ({ params, locale, locales }) => {
|
||||
return {
|
||||
props: {
|
||||
params,
|
||||
locale,
|
||||
locales,
|
||||
},
|
||||
};
|
||||
};
|
||||
31
packages/now-next/test/fixtures/00-i18n-support-no-shared-lambdas/pages/gssp/index.js
vendored
Normal file
31
packages/now-next/test/fixtures/00-i18n-support-no-shared-lambdas/pages/gssp/index.js
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
import Link from 'next/link';
|
||||
import { useRouter } from 'next/router';
|
||||
|
||||
export default function Page(props) {
|
||||
const router = useRouter();
|
||||
|
||||
return (
|
||||
<>
|
||||
<p id="gssp">gssp page</p>
|
||||
<p id="props">{JSON.stringify(props)}</p>
|
||||
<p id="router-locale">{router.locale}</p>
|
||||
<p id="router-locales">{JSON.stringify(router.locales)}</p>
|
||||
<p id="router-query">{JSON.stringify(router.query)}</p>
|
||||
<p id="router-pathname">{router.pathname}</p>
|
||||
<p id="router-as-path">{router.asPath}</p>
|
||||
<Link href="/">
|
||||
<a id="to-index">to /</a>
|
||||
</Link>
|
||||
<br />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export const getServerSideProps = ({ locale, locales }) => {
|
||||
return {
|
||||
props: {
|
||||
locale,
|
||||
locales,
|
||||
},
|
||||
};
|
||||
};
|
||||
46
packages/now-next/test/fixtures/00-i18n-support-no-shared-lambdas/pages/index.js
vendored
Normal file
46
packages/now-next/test/fixtures/00-i18n-support-no-shared-lambdas/pages/index.js
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
import Link from 'next/link';
|
||||
import { useRouter } from 'next/router';
|
||||
|
||||
export default function Page(props) {
|
||||
const router = useRouter();
|
||||
|
||||
return (
|
||||
<>
|
||||
<p id="index">index page</p>
|
||||
<p id="props">{JSON.stringify(props)}</p>
|
||||
<p id="router-locale">{router.locale}</p>
|
||||
<p id="router-locales">{JSON.stringify(router.locales)}</p>
|
||||
<p id="router-query">{JSON.stringify(router.query)}</p>
|
||||
<p id="router-pathname">{router.pathname}</p>
|
||||
<p id="router-as-path">{router.asPath}</p>
|
||||
<Link href="/another">
|
||||
<a id="to-another">to /another</a>
|
||||
</Link>
|
||||
<br />
|
||||
<Link href="/gsp">
|
||||
<a id="to-gsp">to /gsp</a>
|
||||
</Link>
|
||||
<br />
|
||||
<Link href="/gsp/fallback/first">
|
||||
<a id="to-fallback-first">to /gsp/fallback/first</a>
|
||||
</Link>
|
||||
<br />
|
||||
<Link href="/gsp/fallback/hello">
|
||||
<a id="to-fallback-hello">to /gsp/fallback/hello</a>
|
||||
</Link>
|
||||
<br />
|
||||
<Link href="/gsp/no-fallback/first">
|
||||
<a id="to-no-fallback-first">to /gsp/no-fallback/first</a>
|
||||
</Link>
|
||||
<br />
|
||||
<Link href="/gssp">
|
||||
<a id="to-gssp">to /gssp</a>
|
||||
</Link>
|
||||
<br />
|
||||
<Link href="/gssp/first">
|
||||
<a id="to-gssp-slug">to /gssp/first</a>
|
||||
</Link>
|
||||
<br />
|
||||
</>
|
||||
);
|
||||
}
|
||||
54
packages/now-next/test/fixtures/00-i18n-support-no-shared-lambdas/pages/links.js
vendored
Normal file
54
packages/now-next/test/fixtures/00-i18n-support-no-shared-lambdas/pages/links.js
vendored
Normal file
@@ -0,0 +1,54 @@
|
||||
import Link from 'next/link';
|
||||
import { useRouter } from 'next/router';
|
||||
|
||||
export default function Page(props) {
|
||||
const router = useRouter();
|
||||
const { nextLocale } = router.query;
|
||||
|
||||
return (
|
||||
<>
|
||||
<p id="links">links page</p>
|
||||
<p id="props">{JSON.stringify(props)}</p>
|
||||
<p id="router-locale">{router.locale}</p>
|
||||
<p id="router-locales">{JSON.stringify(router.locales)}</p>
|
||||
<p id="router-query">{JSON.stringify(router.query)}</p>
|
||||
<p id="router-pathname">{router.pathname}</p>
|
||||
<p id="router-as-path">{router.asPath}</p>
|
||||
<Link href="/another" locale={nextLocale}>
|
||||
<a id="to-another">to /another</a>
|
||||
</Link>
|
||||
<br />
|
||||
<Link href="/gsp" locale={nextLocale}>
|
||||
<a id="to-gsp">to /gsp</a>
|
||||
</Link>
|
||||
<br />
|
||||
<Link href="/gsp/fallback/first" locale={nextLocale}>
|
||||
<a id="to-fallback-first">to /gsp/fallback/first</a>
|
||||
</Link>
|
||||
<br />
|
||||
<Link href="/gsp/fallback/hello" locale={nextLocale}>
|
||||
<a id="to-fallback-hello">to /gsp/fallback/hello</a>
|
||||
</Link>
|
||||
<br />
|
||||
<Link href="/gsp/no-fallback/first" locale={nextLocale}>
|
||||
<a id="to-no-fallback-first">to /gsp/no-fallback/first</a>
|
||||
</Link>
|
||||
<br />
|
||||
<Link href="/gssp" locale={nextLocale}>
|
||||
<a id="to-gssp">to /gssp</a>
|
||||
</Link>
|
||||
<br />
|
||||
<Link href="/gssp/first" locale={nextLocale}>
|
||||
<a id="to-gssp-slug">to /gssp/first</a>
|
||||
</Link>
|
||||
<br />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
// make SSR page so we have query values immediately
|
||||
export const getServerSideProps = () => {
|
||||
return {
|
||||
props: {},
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,50 @@
|
||||
import Link from 'next/link';
|
||||
import { useRouter } from 'next/router';
|
||||
|
||||
export default function Page(props) {
|
||||
const router = useRouter();
|
||||
|
||||
if (router.isFallback) return 'Loading...';
|
||||
|
||||
return (
|
||||
<>
|
||||
<p id="gsp">gsp page</p>
|
||||
<p id="props">{JSON.stringify(props)}</p>
|
||||
<p id="router-locale">{router.locale}</p>
|
||||
<p id="router-locales">{JSON.stringify(router.locales)}</p>
|
||||
<p id="router-query">{JSON.stringify(router.query)}</p>
|
||||
<p id="router-pathname">{router.pathname}</p>
|
||||
<p id="router-as-path">{router.asPath}</p>
|
||||
<Link href="/">
|
||||
<a id="to-index">to /</a>
|
||||
</Link>
|
||||
<br />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export const getStaticProps = ({ params, locale, locales }) => {
|
||||
if (locale === 'en' || locale === 'nl') {
|
||||
return {
|
||||
notFound: true,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
props: {
|
||||
params,
|
||||
locale,
|
||||
locales,
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
export const getStaticPaths = () => {
|
||||
return {
|
||||
// the default locale will be used since one isn't defined here
|
||||
paths: ['first', 'second'].map(slug => ({
|
||||
params: { slug },
|
||||
})),
|
||||
fallback: true,
|
||||
};
|
||||
};
|
||||
37
packages/now-next/test/fixtures/00-i18n-support-no-shared-lambdas/pages/not-found/index.js
vendored
Normal file
37
packages/now-next/test/fixtures/00-i18n-support-no-shared-lambdas/pages/not-found/index.js
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
import Link from 'next/link';
|
||||
import { useRouter } from 'next/router';
|
||||
|
||||
export default function Page(props) {
|
||||
const router = useRouter();
|
||||
|
||||
return (
|
||||
<>
|
||||
<p id="gsp">gsp page</p>
|
||||
<p id="props">{JSON.stringify(props)}</p>
|
||||
<p id="router-locale">{router.locale}</p>
|
||||
<p id="router-locales">{JSON.stringify(router.locales)}</p>
|
||||
<p id="router-query">{JSON.stringify(router.query)}</p>
|
||||
<p id="router-pathname">{router.pathname}</p>
|
||||
<p id="router-as-path">{router.asPath}</p>
|
||||
<Link href="/">
|
||||
<a id="to-index">to /</a>
|
||||
</Link>
|
||||
<br />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export const getStaticProps = ({ locale, locales }) => {
|
||||
if (locale === 'en' || locale === 'nl') {
|
||||
return {
|
||||
notFound: true,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
props: {
|
||||
locale,
|
||||
locales,
|
||||
},
|
||||
};
|
||||
};
|
||||
1
packages/now-next/test/fixtures/00-i18n-support-no-shared-lambdas/public/hello.txt
vendored
Normal file
1
packages/now-next/test/fixtures/00-i18n-support-no-shared-lambdas/public/hello.txt
vendored
Normal file
@@ -0,0 +1 @@
|
||||
hello world!
|
||||
182
packages/now-next/test/fixtures/00-i18n-support-root-catchall/additional.js
vendored
Normal file
182
packages/now-next/test/fixtures/00-i18n-support-root-catchall/additional.js
vendored
Normal file
@@ -0,0 +1,182 @@
|
||||
/* eslint-env jest */
|
||||
const fetch = require('node-fetch');
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
module.exports = function (ctx) {
|
||||
it('should revalidate content properly from /', async () => {
|
||||
// we have to hit the _next/data URL first
|
||||
const dataRes = await fetch(
|
||||
`${ctx.deploymentUrl}/_next/data/testing-build-id/en-US.json`
|
||||
);
|
||||
expect(dataRes.status).toBe(200);
|
||||
await dataRes.json();
|
||||
|
||||
const res = await fetch(`${ctx.deploymentUrl}/`);
|
||||
expect(res.status).toBe(200);
|
||||
|
||||
let $ = cheerio.load(await res.text());
|
||||
const props = JSON.parse($('#props').text());
|
||||
const initialRandom = props.random;
|
||||
expect($('#router-locale').text()).toBe('en-US');
|
||||
|
||||
// wait for revalidation to occur
|
||||
await new Promise(resolve => setTimeout(resolve, 2000));
|
||||
|
||||
const res2 = await fetch(`${ctx.deploymentUrl}/`);
|
||||
expect(res2.status).toBe(200);
|
||||
|
||||
$ = cheerio.load(await res2.text());
|
||||
const props2 = JSON.parse($('#props').text());
|
||||
expect(initialRandom).not.toBe(props2.random);
|
||||
expect($('#router-locale').text()).toBe('en-US');
|
||||
});
|
||||
|
||||
it('should revalidate content properly from /fr', async () => {
|
||||
// we have to hit the _next/data URL first
|
||||
const dataRes = await fetch(
|
||||
`${ctx.deploymentUrl}/_next/data/testing-build-id/fr.json`
|
||||
);
|
||||
expect(dataRes.status).toBe(200);
|
||||
await dataRes.json();
|
||||
|
||||
const res = await fetch(`${ctx.deploymentUrl}/fr`);
|
||||
expect(res.status).toBe(200);
|
||||
|
||||
let $ = cheerio.load(await res.text());
|
||||
const props = JSON.parse($('#props').text());
|
||||
const initialRandom = props.random;
|
||||
expect($('#router-locale').text()).toBe('fr');
|
||||
|
||||
// wait for revalidation to occur
|
||||
await new Promise(resolve => setTimeout(resolve, 2000));
|
||||
|
||||
const res2 = await fetch(`${ctx.deploymentUrl}/fr`);
|
||||
expect(res2.status).toBe(200);
|
||||
|
||||
$ = cheerio.load(await res2.text());
|
||||
const props2 = JSON.parse($('#props').text());
|
||||
expect(initialRandom).not.toBe(props2.random);
|
||||
expect($('#router-locale').text()).toBe('fr');
|
||||
});
|
||||
|
||||
it('should revalidate content properly from /nl-NL', async () => {
|
||||
// we have to hit the _next/data URL first
|
||||
const dataRes = await fetch(
|
||||
`${ctx.deploymentUrl}/_next/data/testing-build-id/nl-NL/index.json`
|
||||
);
|
||||
expect(dataRes.status).toBe(200);
|
||||
await dataRes.json();
|
||||
|
||||
const res = await fetch(`${ctx.deploymentUrl}/nl-NL`);
|
||||
expect(res.status).toBe(200);
|
||||
|
||||
let $ = cheerio.load(await res.text());
|
||||
const props = JSON.parse($('#props').text());
|
||||
const initialRandom = props.random;
|
||||
expect($('#router-locale').text()).toBe('nl-NL');
|
||||
|
||||
// wait for revalidation to occur
|
||||
await new Promise(resolve => setTimeout(resolve, 2000));
|
||||
|
||||
const res2 = await fetch(`${ctx.deploymentUrl}/nl-NL`);
|
||||
expect(res2.status).toBe(200);
|
||||
|
||||
$ = cheerio.load(await res2.text());
|
||||
const props2 = JSON.parse($('#props').text());
|
||||
expect(initialRandom).not.toBe(props2.random);
|
||||
expect($('#router-locale').text()).toBe('nl-NL');
|
||||
});
|
||||
|
||||
it('should revalidate content properly from /second', async () => {
|
||||
// we have to hit the _next/data URL first
|
||||
const dataRes = await fetch(
|
||||
`${ctx.deploymentUrl}/_next/data/testing-build-id/en-US/second.json`
|
||||
);
|
||||
expect(dataRes.status).toBe(200);
|
||||
await dataRes.json();
|
||||
|
||||
await new Promise(resolve => setTimeout(resolve, 2000));
|
||||
|
||||
const res = await fetch(`${ctx.deploymentUrl}/second`);
|
||||
expect(res.status).toBe(200);
|
||||
|
||||
const html = await res.text();
|
||||
let $ = cheerio.load(html);
|
||||
const props = JSON.parse($('#props').text());
|
||||
const initialRandom = props.random;
|
||||
expect($('#router-locale').text()).toBe('en-US');
|
||||
|
||||
// wait for revalidation to occur
|
||||
await new Promise(resolve => setTimeout(resolve, 2000));
|
||||
|
||||
const res2 = await fetch(`${ctx.deploymentUrl}/second`);
|
||||
expect(res2.status).toBe(200);
|
||||
|
||||
$ = cheerio.load(await res2.text());
|
||||
const props2 = JSON.parse($('#props').text());
|
||||
expect(initialRandom).not.toBe(props2.random);
|
||||
expect($('#router-locale').text()).toBe('en-US');
|
||||
});
|
||||
|
||||
it('should revalidate content properly from /fr/second', async () => {
|
||||
// we have to hit the _next/data URL first
|
||||
const dataRes = await fetch(
|
||||
`${ctx.deploymentUrl}/_next/data/testing-build-id/fr/second.json`
|
||||
);
|
||||
expect(dataRes.status).toBe(200);
|
||||
await dataRes.json();
|
||||
|
||||
await new Promise(resolve => setTimeout(resolve, 2000));
|
||||
|
||||
const res = await fetch(`${ctx.deploymentUrl}/fr/second`);
|
||||
expect(res.status).toBe(200);
|
||||
|
||||
const html = await res.text();
|
||||
let $ = cheerio.load(html);
|
||||
const props = JSON.parse($('#props').text());
|
||||
const initialRandom = props.random;
|
||||
expect($('#router-locale').text()).toBe('fr');
|
||||
|
||||
// wait for revalidation to occur
|
||||
await new Promise(resolve => setTimeout(resolve, 2000));
|
||||
|
||||
const res2 = await fetch(`${ctx.deploymentUrl}/fr/second`);
|
||||
expect(res2.status).toBe(200);
|
||||
|
||||
$ = cheerio.load(await res2.text());
|
||||
const props2 = JSON.parse($('#props').text());
|
||||
expect(initialRandom).not.toBe(props2.random);
|
||||
expect($('#router-locale').text()).toBe('fr');
|
||||
});
|
||||
|
||||
it('should revalidate content properly from /nl-NL/second', async () => {
|
||||
// we have to hit the _next/data URL first
|
||||
const dataRes = await fetch(
|
||||
`${ctx.deploymentUrl}/_next/data/testing-build-id/nl-NL/second.json`
|
||||
);
|
||||
expect(dataRes.status).toBe(200);
|
||||
await dataRes.json();
|
||||
|
||||
await new Promise(resolve => setTimeout(resolve, 2000));
|
||||
|
||||
const res = await fetch(`${ctx.deploymentUrl}/nl-NL/second`);
|
||||
expect(res.status).toBe(200);
|
||||
|
||||
const html = await res.text();
|
||||
let $ = cheerio.load(html);
|
||||
const props = JSON.parse($('#props').text());
|
||||
const initialRandom = props.random;
|
||||
expect($('#router-locale').text()).toBe('nl-NL');
|
||||
|
||||
// wait for revalidation to occur
|
||||
await new Promise(resolve => setTimeout(resolve, 2000));
|
||||
|
||||
const res2 = await fetch(`${ctx.deploymentUrl}/nl-NL/second`);
|
||||
expect(res2.status).toBe(200);
|
||||
|
||||
$ = cheerio.load(await res2.text());
|
||||
const props2 = JSON.parse($('#props').text());
|
||||
expect(initialRandom).not.toBe(props2.random);
|
||||
expect($('#router-locale').text()).toBe('nl-NL');
|
||||
});
|
||||
};
|
||||
21
packages/now-next/test/fixtures/00-i18n-support-root-catchall/next.config.js
vendored
Normal file
21
packages/now-next/test/fixtures/00-i18n-support-root-catchall/next.config.js
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
module.exports = {
|
||||
generateBuildId() {
|
||||
return 'testing-build-id';
|
||||
},
|
||||
i18n: {
|
||||
locales: ['nl-NL', 'nl-BE', 'nl', 'fr-BE', 'fr', 'en-US', 'en'],
|
||||
defaultLocale: 'en-US',
|
||||
// TODO: testing locale domains support, will require custom
|
||||
// testing set-up as test accounts are used currently
|
||||
domains: [
|
||||
{
|
||||
domain: 'example.be',
|
||||
defaultLocale: 'nl-BE',
|
||||
},
|
||||
{
|
||||
domain: 'example.fr',
|
||||
defaultLocale: 'fr',
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
192
packages/now-next/test/fixtures/00-i18n-support-root-catchall/now.json
vendored
Normal file
192
packages/now-next/test/fixtures/00-i18n-support-root-catchall/now.json
vendored
Normal file
@@ -0,0 +1,192 @@
|
||||
{
|
||||
"version": 2,
|
||||
"builds": [
|
||||
{
|
||||
"src": "package.json",
|
||||
"use": "@vercel/next"
|
||||
}
|
||||
],
|
||||
"probes": [
|
||||
{
|
||||
"path": "/hello.txt",
|
||||
"status": 200,
|
||||
"mustContain": "hello world!"
|
||||
},
|
||||
{
|
||||
"path": "/",
|
||||
"headers": {
|
||||
"accept-language": "en;q=0.9"
|
||||
},
|
||||
"fetchOptions": {
|
||||
"redirect": "manual"
|
||||
},
|
||||
"status": 307,
|
||||
"responseHeaders": {
|
||||
"location": "//en/"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "/",
|
||||
"headers": {
|
||||
"accept-language": "nl;q=0.9"
|
||||
},
|
||||
"fetchOptions": {
|
||||
"redirect": "manual"
|
||||
},
|
||||
"status": 307,
|
||||
"responseHeaders": {
|
||||
"location": "//nl/"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "/",
|
||||
"headers": {
|
||||
"accept-language": "nl-NL;q=0.9"
|
||||
},
|
||||
"fetchOptions": {
|
||||
"redirect": "manual"
|
||||
},
|
||||
"status": 307,
|
||||
"responseHeaders": {
|
||||
"location": "//nl-NL/"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "/",
|
||||
"headers": {
|
||||
"accept-language": "fr;q=0.9"
|
||||
},
|
||||
"fetchOptions": {
|
||||
"redirect": "manual"
|
||||
},
|
||||
"status": 307,
|
||||
"responseHeaders": {
|
||||
"location": "//fr/"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "/",
|
||||
"headers": {
|
||||
"accept-language": "en-US;q=0.9"
|
||||
},
|
||||
"fetchOptions": {
|
||||
"redirect": "manual"
|
||||
},
|
||||
"status": 200,
|
||||
"mustContain": "catchall page"
|
||||
},
|
||||
{
|
||||
"path": "/en-US",
|
||||
"headers": {
|
||||
"accept-language": "nl;q=0.9"
|
||||
},
|
||||
"fetchOptions": {
|
||||
"redirect": "manual"
|
||||
},
|
||||
"status": 200,
|
||||
"mustContain": "catchall page"
|
||||
},
|
||||
|
||||
{
|
||||
"path": "/",
|
||||
"status": 200,
|
||||
"mustContain": "catchall page"
|
||||
},
|
||||
{
|
||||
"path": "/",
|
||||
"status": 200,
|
||||
"mustContain": ">en-US<"
|
||||
},
|
||||
{
|
||||
"path": "/en",
|
||||
"status": 200,
|
||||
"mustContain": "catchall page"
|
||||
},
|
||||
{
|
||||
"path": "/en",
|
||||
"status": 200,
|
||||
"mustContain": ">en<"
|
||||
},
|
||||
{
|
||||
"path": "/fr",
|
||||
"status": 200,
|
||||
"mustContain": "catchall page"
|
||||
},
|
||||
{
|
||||
"path": "/fr",
|
||||
"status": 200,
|
||||
"mustContain": ">fr<"
|
||||
},
|
||||
{
|
||||
"path": "/nl",
|
||||
"status": 200,
|
||||
"mustContain": "catchall page"
|
||||
},
|
||||
{
|
||||
"path": "/nl",
|
||||
"status": 200,
|
||||
"mustContain": ">nl<"
|
||||
},
|
||||
{
|
||||
"path": "/nl-NL",
|
||||
"status": 200,
|
||||
"mustContain": "catchall page"
|
||||
},
|
||||
{
|
||||
"path": "/nl-NL",
|
||||
"status": 200,
|
||||
"mustContain": ">nl-NL<"
|
||||
},
|
||||
|
||||
{
|
||||
"path": "/first",
|
||||
"status": 200,
|
||||
"mustContain": "catchall page"
|
||||
},
|
||||
{
|
||||
"path": "/first",
|
||||
"status": 200,
|
||||
"mustContain": ">en-US<"
|
||||
},
|
||||
{
|
||||
"path": "/en/first",
|
||||
"status": 200,
|
||||
"mustContain": "catchall page"
|
||||
},
|
||||
{
|
||||
"path": "/en/first",
|
||||
"status": 200,
|
||||
"mustContain": ">en<"
|
||||
},
|
||||
{
|
||||
"path": "/fr/first",
|
||||
"status": 200,
|
||||
"mustContain": "catchall page"
|
||||
},
|
||||
{
|
||||
"path": "/fr/first",
|
||||
"status": 200,
|
||||
"mustContain": ">fr<"
|
||||
},
|
||||
{
|
||||
"path": "/nl/first",
|
||||
"status": 200,
|
||||
"mustContain": "catchall page"
|
||||
},
|
||||
{
|
||||
"path": "/nl/first",
|
||||
"status": 200,
|
||||
"mustContain": ">nl<"
|
||||
},
|
||||
{
|
||||
"path": "/nl-NL/first",
|
||||
"status": 200,
|
||||
"mustContain": "catchall page"
|
||||
},
|
||||
{
|
||||
"path": "/nl-NL/first",
|
||||
"status": 200,
|
||||
"mustContain": ">nl-NL<"
|
||||
}
|
||||
]
|
||||
}
|
||||
7
packages/now-next/test/fixtures/00-i18n-support-root-catchall/package.json
vendored
Normal file
7
packages/now-next/test/fixtures/00-i18n-support-root-catchall/package.json
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"dependencies": {
|
||||
"next": "canary",
|
||||
"react": "^16.8.6",
|
||||
"react-dom": "^16.8.6"
|
||||
}
|
||||
}
|
||||
69
packages/now-next/test/fixtures/00-i18n-support-root-catchall/pages/[[...slug]].js
vendored
Normal file
69
packages/now-next/test/fixtures/00-i18n-support-root-catchall/pages/[[...slug]].js
vendored
Normal file
@@ -0,0 +1,69 @@
|
||||
import Link from 'next/link';
|
||||
import { useRouter } from 'next/router';
|
||||
|
||||
const Slug = props => {
|
||||
const router = useRouter();
|
||||
|
||||
// invariant ensuring fallback is never accidentally flipped
|
||||
if (router.isFallback) {
|
||||
return 'Loading...';
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
<p>catchall page</p>
|
||||
<p id="props">{JSON.stringify(props)}</p>
|
||||
<p id="router-locale">{router.locale}</p>
|
||||
<p id="router-locales">{JSON.stringify(router.locales)}</p>
|
||||
<p id="router-query">{JSON.stringify(router.query)}</p>
|
||||
<p id="router-pathname">{router.pathname}</p>
|
||||
<p id="router-as-path">{router.asPath}</p>
|
||||
<Link href="/gsp/blocking/hallo-wereld" locale={'nl-NL'}>
|
||||
<a>/nl-NL/gsp/blocking/hallo-wereld</a>
|
||||
</Link>
|
||||
<br />
|
||||
<Link href="/gsp/blocking/42" locale={'nl-NL'}>
|
||||
<a>/nl-NL/gsp/blocking/42</a>
|
||||
</Link>
|
||||
<br />
|
||||
<Link href="/gsp/blocking/hallo-welt" locale={'fr'}>
|
||||
<a>/fr/gsp/blocking/hallo-welt</a>
|
||||
</Link>
|
||||
<br />
|
||||
<Link href="/gsp/blocking/42" locale={'fr'}>
|
||||
<a>/fr/gsp/blocking/42</a>
|
||||
</Link>
|
||||
<br />
|
||||
<Link href="/">
|
||||
<a>/</a>
|
||||
</Link>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export const getStaticProps = ({ params }) => {
|
||||
return {
|
||||
props: {
|
||||
params,
|
||||
random: Math.random(),
|
||||
catchall: 'yes',
|
||||
},
|
||||
revalidate: 1,
|
||||
};
|
||||
};
|
||||
|
||||
export const getStaticPaths = ({ locales }) => {
|
||||
const paths = [];
|
||||
|
||||
for (const locale of locales) {
|
||||
paths.push({ params: { slug: ['first'] }, locale });
|
||||
paths.push({ params: { slug: ['first'] }, locale });
|
||||
}
|
||||
|
||||
return {
|
||||
paths,
|
||||
fallback: 'blocking',
|
||||
};
|
||||
};
|
||||
|
||||
export default Slug;
|
||||
1
packages/now-next/test/fixtures/00-i18n-support-root-catchall/public/hello.txt
vendored
Normal file
1
packages/now-next/test/fixtures/00-i18n-support-root-catchall/public/hello.txt
vendored
Normal file
@@ -0,0 +1 @@
|
||||
hello world!
|
||||
412
packages/now-next/test/fixtures/00-i18n-support/additional.js
vendored
Normal file
412
packages/now-next/test/fixtures/00-i18n-support/additional.js
vendored
Normal file
@@ -0,0 +1,412 @@
|
||||
/* eslint-env jest */
|
||||
const fetch = require('node-fetch');
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
module.exports = function (ctx) {
|
||||
it('should revalidate content properly from /', async () => {
|
||||
const dataRes = await fetch(
|
||||
`${ctx.deploymentUrl}/_next/data/testing-build-id/en-US/index.json`
|
||||
);
|
||||
expect(dataRes.status).toBe(200);
|
||||
await dataRes.json();
|
||||
|
||||
await new Promise(resolve => setTimeout(resolve, 2000));
|
||||
|
||||
const res = await fetch(`${ctx.deploymentUrl}/`);
|
||||
expect(res.status).toBe(200);
|
||||
|
||||
let $ = cheerio.load(await res.text());
|
||||
const props = JSON.parse($('#props').text());
|
||||
const initialRandom = props.random;
|
||||
expect($('#router-locale').text()).toBe('en-US');
|
||||
expect(JSON.parse($('#router-query').text())).toEqual({});
|
||||
|
||||
// wait for revalidation to occur
|
||||
await new Promise(resolve => setTimeout(resolve, 2000));
|
||||
|
||||
const res2 = await fetch(`${ctx.deploymentUrl}/`);
|
||||
expect(res2.status).toBe(200);
|
||||
|
||||
$ = cheerio.load(await res2.text());
|
||||
const props2 = JSON.parse($('#props').text());
|
||||
expect(initialRandom).not.toBe(props2.random);
|
||||
expect($('#router-locale').text()).toBe('en-US');
|
||||
expect(JSON.parse($('#router-query').text())).toEqual({});
|
||||
});
|
||||
|
||||
it('should revalidate content properly from /fr', async () => {
|
||||
const dataRes = await fetch(
|
||||
`${ctx.deploymentUrl}/_next/data/testing-build-id/fr/index.json`
|
||||
);
|
||||
expect(dataRes.status).toBe(200);
|
||||
await dataRes.json();
|
||||
|
||||
await new Promise(resolve => setTimeout(resolve, 2000));
|
||||
|
||||
const res = await fetch(`${ctx.deploymentUrl}/fr`);
|
||||
expect(res.status).toBe(200);
|
||||
|
||||
let $ = cheerio.load(await res.text());
|
||||
const props = JSON.parse($('#props').text());
|
||||
const initialRandom = props.random;
|
||||
expect($('#router-locale').text()).toBe('fr');
|
||||
expect(JSON.parse($('#router-query').text())).toEqual({});
|
||||
|
||||
// wait for revalidation to occur
|
||||
await new Promise(resolve => setTimeout(resolve, 2000));
|
||||
|
||||
const res2 = await fetch(`${ctx.deploymentUrl}/fr`);
|
||||
expect(res2.status).toBe(200);
|
||||
|
||||
$ = cheerio.load(await res2.text());
|
||||
const props2 = JSON.parse($('#props').text());
|
||||
expect(initialRandom).not.toBe(props2.random);
|
||||
expect($('#router-locale').text()).toBe('fr');
|
||||
expect(JSON.parse($('#router-query').text())).toEqual({});
|
||||
});
|
||||
|
||||
it('should revalidate content properly from /nl-NL', async () => {
|
||||
const dataRes = await fetch(
|
||||
`${ctx.deploymentUrl}/_next/data/testing-build-id/nl-NL/index.json`
|
||||
);
|
||||
expect(dataRes.status).toBe(200);
|
||||
await dataRes.json();
|
||||
|
||||
await new Promise(resolve => setTimeout(resolve, 2000));
|
||||
|
||||
const res = await fetch(`${ctx.deploymentUrl}/nl-NL`);
|
||||
expect(res.status).toBe(200);
|
||||
|
||||
let $ = cheerio.load(await res.text());
|
||||
const props = JSON.parse($('#props').text());
|
||||
const initialRandom = props.random;
|
||||
expect($('#router-locale').text()).toBe('nl-NL');
|
||||
expect(JSON.parse($('#router-query').text())).toEqual({});
|
||||
|
||||
// wait for revalidation to occur
|
||||
await new Promise(resolve => setTimeout(resolve, 2000));
|
||||
|
||||
const res2 = await fetch(`${ctx.deploymentUrl}/nl-NL`);
|
||||
expect(res2.status).toBe(200);
|
||||
|
||||
$ = cheerio.load(await res2.text());
|
||||
const props2 = JSON.parse($('#props').text());
|
||||
expect(initialRandom).not.toBe(props2.random);
|
||||
expect($('#router-locale').text()).toBe('nl-NL');
|
||||
expect(JSON.parse($('#router-query').text())).toEqual({});
|
||||
});
|
||||
|
||||
it('should revalidate content properly from /gsp/fallback/first', async () => {
|
||||
// check the _next/data URL first
|
||||
const dataRes = await fetch(
|
||||
`${ctx.deploymentUrl}/_next/data/testing-build-id/en-US/gsp/fallback/first.json`
|
||||
);
|
||||
expect(dataRes.status).toBe(200);
|
||||
await dataRes.json();
|
||||
|
||||
await new Promise(resolve => setTimeout(resolve, 2000));
|
||||
|
||||
const res = await fetch(`${ctx.deploymentUrl}/gsp/fallback/first`);
|
||||
expect(res.status).toBe(200);
|
||||
|
||||
const html = await res.text();
|
||||
let $ = cheerio.load(html);
|
||||
const props = JSON.parse($('#props').text());
|
||||
const initialRandom = props.random;
|
||||
expect($('#router-locale').text()).toBe('en-US');
|
||||
expect(props.params).toEqual({ slug: 'first' });
|
||||
expect(JSON.parse($('#router-query').text())).toEqual({ slug: 'first' });
|
||||
|
||||
// wait for revalidation to occur
|
||||
await new Promise(resolve => setTimeout(resolve, 2000));
|
||||
|
||||
const res2 = await fetch(`${ctx.deploymentUrl}/gsp/fallback/first`);
|
||||
expect(res2.status).toBe(200);
|
||||
|
||||
$ = cheerio.load(await res2.text());
|
||||
const props2 = JSON.parse($('#props').text());
|
||||
expect(initialRandom).not.toBe(props2.random);
|
||||
expect($('#router-locale').text()).toBe('en-US');
|
||||
expect(props2.params).toEqual({ slug: 'first' });
|
||||
expect(JSON.parse($('#router-query').text())).toEqual({ slug: 'first' });
|
||||
});
|
||||
|
||||
it('should revalidate content properly from /fr/gsp/fallback/first', async () => {
|
||||
// check the _next/data URL first
|
||||
const dataRes = await fetch(
|
||||
`${ctx.deploymentUrl}/_next/data/testing-build-id/fr/gsp/fallback/first.json`
|
||||
);
|
||||
expect(dataRes.status).toBe(200);
|
||||
await dataRes.json();
|
||||
|
||||
await new Promise(resolve => setTimeout(resolve, 2000));
|
||||
|
||||
const res = await fetch(`${ctx.deploymentUrl}/fr/gsp/fallback/first`);
|
||||
expect(res.status).toBe(200);
|
||||
|
||||
const html = await res.text();
|
||||
let $ = cheerio.load(html);
|
||||
const props = JSON.parse($('#props').text());
|
||||
const initialRandom = props.random;
|
||||
expect($('#router-locale').text()).toBe('fr');
|
||||
expect(props.params).toEqual({ slug: 'first' });
|
||||
expect(JSON.parse($('#router-query').text())).toEqual({ slug: 'first' });
|
||||
|
||||
// wait for revalidation to occur
|
||||
await new Promise(resolve => setTimeout(resolve, 2000));
|
||||
|
||||
const res2 = await fetch(`${ctx.deploymentUrl}/fr/gsp/fallback/first`);
|
||||
expect(res2.status).toBe(200);
|
||||
|
||||
$ = cheerio.load(await res2.text());
|
||||
const props2 = JSON.parse($('#props').text());
|
||||
expect(initialRandom).not.toBe(props2.random);
|
||||
expect($('#router-locale').text()).toBe('fr');
|
||||
expect(props2.params).toEqual({ slug: 'first' });
|
||||
expect(JSON.parse($('#router-query').text())).toEqual({ slug: 'first' });
|
||||
});
|
||||
|
||||
it('should revalidate content properly from /nl-NL/gsp/fallback/first', async () => {
|
||||
// check the _next/data URL first
|
||||
const dataRes = await fetch(
|
||||
`${ctx.deploymentUrl}/_next/data/testing-build-id/nl-NL/gsp/fallback/first.json`
|
||||
);
|
||||
expect(dataRes.status).toBe(200);
|
||||
await dataRes.json();
|
||||
|
||||
await new Promise(resolve => setTimeout(resolve, 2000));
|
||||
|
||||
const res = await fetch(`${ctx.deploymentUrl}/nl-NL/gsp/fallback/first`);
|
||||
expect(res.status).toBe(200);
|
||||
|
||||
const html = await res.text();
|
||||
let $ = cheerio.load(html);
|
||||
const props = JSON.parse($('#props').text());
|
||||
const initialRandom = props.random;
|
||||
expect($('#router-locale').text()).toBe('nl-NL');
|
||||
expect(props.params).toEqual({ slug: 'first' });
|
||||
expect(JSON.parse($('#router-query').text())).toEqual({ slug: 'first' });
|
||||
|
||||
// wait for revalidation to occur
|
||||
await new Promise(resolve => setTimeout(resolve, 2000));
|
||||
|
||||
const res2 = await fetch(`${ctx.deploymentUrl}/nl-NL/gsp/fallback/first`);
|
||||
expect(res2.status).toBe(200);
|
||||
|
||||
$ = cheerio.load(await res2.text());
|
||||
const props2 = JSON.parse($('#props').text());
|
||||
expect(initialRandom).not.toBe(props2.random);
|
||||
expect($('#router-locale').text()).toBe('nl-NL');
|
||||
expect(props2.params).toEqual({ slug: 'first' });
|
||||
expect(JSON.parse($('#router-query').text())).toEqual({ slug: 'first' });
|
||||
});
|
||||
//
|
||||
|
||||
it('should revalidate content properly from /gsp/fallback/new-page', async () => {
|
||||
const dataRes = await fetch(
|
||||
`${ctx.deploymentUrl}/_next/data/testing-build-id/en-US/gsp/fallback/new-page.json`
|
||||
);
|
||||
expect(dataRes.status).toBe(200);
|
||||
await dataRes.json();
|
||||
|
||||
const initRes = await fetch(`${ctx.deploymentUrl}/gsp/fallback/new-page`);
|
||||
expect(initRes.status).toBe(200);
|
||||
|
||||
await new Promise(resolve => setTimeout(resolve, 2000));
|
||||
|
||||
const res = await fetch(`${ctx.deploymentUrl}/gsp/fallback/new-page`);
|
||||
expect(res.status).toBe(200);
|
||||
|
||||
const html = await res.text();
|
||||
let $ = cheerio.load(html);
|
||||
const props = JSON.parse($('#props').text());
|
||||
const initialRandom = props.random;
|
||||
expect($('#router-locale').text()).toBe('en-US');
|
||||
expect(props.params).toEqual({ slug: 'new-page' });
|
||||
expect(JSON.parse($('#router-query').text())).toEqual({ slug: 'new-page' });
|
||||
|
||||
// wait for revalidation to occur
|
||||
await new Promise(resolve => setTimeout(resolve, 2000));
|
||||
|
||||
const res2 = await fetch(`${ctx.deploymentUrl}/gsp/fallback/new-page`);
|
||||
expect(res2.status).toBe(200);
|
||||
|
||||
$ = cheerio.load(await res2.text());
|
||||
const props2 = JSON.parse($('#props').text());
|
||||
expect(initialRandom).not.toBe(props2.random);
|
||||
expect($('#router-locale').text()).toBe('en-US');
|
||||
expect(props2.params).toEqual({ slug: 'new-page' });
|
||||
expect(JSON.parse($('#router-query').text())).toEqual({ slug: 'new-page' });
|
||||
});
|
||||
|
||||
it('should revalidate content properly from /fr/gsp/fallback/new-page', async () => {
|
||||
// we have to hit the _next/data URL first
|
||||
const dataRes = await fetch(
|
||||
`${ctx.deploymentUrl}/_next/data/testing-build-id/fr/gsp/fallback/new-page.json`
|
||||
);
|
||||
expect(dataRes.status).toBe(200);
|
||||
|
||||
await new Promise(resolve => setTimeout(resolve, 2000));
|
||||
|
||||
const res = await fetch(`${ctx.deploymentUrl}/fr/gsp/fallback/new-page`);
|
||||
expect(res.status).toBe(200);
|
||||
|
||||
const html = await res.text();
|
||||
let $ = cheerio.load(html);
|
||||
const props = JSON.parse($('#props').text());
|
||||
const initialRandom = props.random;
|
||||
expect($('#router-locale').text()).toBe('fr');
|
||||
expect(props.params).toEqual({ slug: 'new-page' });
|
||||
expect(JSON.parse($('#router-query').text())).toEqual({ slug: 'new-page' });
|
||||
|
||||
// wait for revalidation to occur
|
||||
await new Promise(resolve => setTimeout(resolve, 2000));
|
||||
|
||||
const res2 = await fetch(`${ctx.deploymentUrl}/fr/gsp/fallback/new-page`);
|
||||
expect(res2.status).toBe(200);
|
||||
|
||||
$ = cheerio.load(await res2.text());
|
||||
const props2 = JSON.parse($('#props').text());
|
||||
expect(initialRandom).not.toBe(props2.random);
|
||||
expect($('#router-locale').text()).toBe('fr');
|
||||
});
|
||||
|
||||
it('should revalidate content properly from /nl-NL/gsp/fallback/new-page', async () => {
|
||||
// we have to hit the _next/data URL first
|
||||
const dataRes = await fetch(
|
||||
`${ctx.deploymentUrl}/_next/data/testing-build-id/nl-NL/gsp/fallback/new-page.json`
|
||||
);
|
||||
expect(dataRes.status).toBe(200);
|
||||
|
||||
await new Promise(resolve => setTimeout(resolve, 2000));
|
||||
|
||||
const res = await fetch(`${ctx.deploymentUrl}/nl-NL/gsp/fallback/new-page`);
|
||||
expect(res.status).toBe(200);
|
||||
|
||||
const html = await res.text();
|
||||
let $ = cheerio.load(html);
|
||||
const props = JSON.parse($('#props').text());
|
||||
const initialRandom = props.random;
|
||||
expect($('#router-locale').text()).toBe('nl-NL');
|
||||
expect(props.params).toEqual({ slug: 'new-page' });
|
||||
expect(JSON.parse($('#router-query').text())).toEqual({ slug: 'new-page' });
|
||||
|
||||
// wait for revalidation to occur
|
||||
await new Promise(resolve => setTimeout(resolve, 2000));
|
||||
|
||||
const res2 = await fetch(
|
||||
`${ctx.deploymentUrl}/nl-NL/gsp/fallback/new-page`
|
||||
);
|
||||
expect(res2.status).toBe(200);
|
||||
|
||||
$ = cheerio.load(await res2.text());
|
||||
const props2 = JSON.parse($('#props').text());
|
||||
expect(initialRandom).not.toBe(props2.random);
|
||||
expect($('#router-locale').text()).toBe('nl-NL');
|
||||
expect(props2.params).toEqual({ slug: 'new-page' });
|
||||
expect(JSON.parse($('#router-query').text())).toEqual({ slug: 'new-page' });
|
||||
});
|
||||
|
||||
it('should revalidate content properly from /gsp/no-fallback/first', async () => {
|
||||
const dataRes = await fetch(
|
||||
`${ctx.deploymentUrl}/_next/data/testing-build-id/en-US/gsp/no-fallback/first.json`
|
||||
);
|
||||
expect(dataRes.status).toBe(200);
|
||||
await dataRes.json();
|
||||
|
||||
await new Promise(resolve => setTimeout(resolve, 2000));
|
||||
|
||||
const res = await fetch(`${ctx.deploymentUrl}/gsp/no-fallback/first`);
|
||||
expect(res.status).toBe(200);
|
||||
|
||||
let $ = cheerio.load(await res.text());
|
||||
const props = JSON.parse($('#props').text());
|
||||
const initialRandom = props.random;
|
||||
expect($('#router-locale').text()).toBe('en-US');
|
||||
expect(props.params).toEqual({ slug: 'first' });
|
||||
expect(JSON.parse($('#router-query').text())).toEqual({ slug: 'first' });
|
||||
|
||||
// wait for revalidation to occur
|
||||
await new Promise(resolve => setTimeout(resolve, 2000));
|
||||
|
||||
const res2 = await fetch(`${ctx.deploymentUrl}/gsp/no-fallback/first`);
|
||||
expect(res2.status).toBe(200);
|
||||
|
||||
$ = cheerio.load(await res2.text());
|
||||
const props2 = JSON.parse($('#props').text());
|
||||
expect(initialRandom).not.toBe(props2.random);
|
||||
expect($('#router-locale').text()).toBe('en-US');
|
||||
expect(props2.params).toEqual({ slug: 'first' });
|
||||
expect(JSON.parse($('#router-query').text())).toEqual({ slug: 'first' });
|
||||
});
|
||||
|
||||
it('should revalidate content properly from /fr/gsp/no-fallback/first', async () => {
|
||||
const dataRes = await fetch(
|
||||
`${ctx.deploymentUrl}/_next/data/testing-build-id/fr/gsp/no-fallback/first.json`
|
||||
);
|
||||
expect(dataRes.status).toBe(200);
|
||||
await dataRes.json();
|
||||
|
||||
await new Promise(resolve => setTimeout(resolve, 2000));
|
||||
|
||||
const res = await fetch(`${ctx.deploymentUrl}/fr/gsp/no-fallback/first`);
|
||||
expect(res.status).toBe(200);
|
||||
|
||||
let $ = cheerio.load(await res.text());
|
||||
const props = JSON.parse($('#props').text());
|
||||
const initialRandom = props.random;
|
||||
expect($('#router-locale').text()).toBe('fr');
|
||||
expect(props.params).toEqual({ slug: 'first' });
|
||||
expect(JSON.parse($('#router-query').text())).toEqual({ slug: 'first' });
|
||||
|
||||
// wait for revalidation to occur
|
||||
await new Promise(resolve => setTimeout(resolve, 2000));
|
||||
|
||||
const res2 = await fetch(`${ctx.deploymentUrl}/fr/gsp/no-fallback/first`);
|
||||
expect(res2.status).toBe(200);
|
||||
|
||||
$ = cheerio.load(await res2.text());
|
||||
const props2 = JSON.parse($('#props').text());
|
||||
expect(initialRandom).not.toBe(props2.random);
|
||||
expect($('#router-locale').text()).toBe('fr');
|
||||
expect(props2.params).toEqual({ slug: 'first' });
|
||||
expect(JSON.parse($('#router-query').text())).toEqual({ slug: 'first' });
|
||||
});
|
||||
|
||||
it('should revalidate content properly from /nl-NL/gsp/no-fallback/second', async () => {
|
||||
const dataRes = await fetch(
|
||||
`${ctx.deploymentUrl}/_next/data/testing-build-id/nl-NL/gsp/no-fallback/second.json`
|
||||
);
|
||||
expect(dataRes.status).toBe(200);
|
||||
await dataRes.json();
|
||||
|
||||
await new Promise(resolve => setTimeout(resolve, 2000));
|
||||
|
||||
const res = await fetch(
|
||||
`${ctx.deploymentUrl}/nl-NL/gsp/no-fallback/second`
|
||||
);
|
||||
expect(res.status).toBe(200);
|
||||
|
||||
let $ = cheerio.load(await res.text());
|
||||
const props = JSON.parse($('#props').text());
|
||||
const initialRandom = props.random;
|
||||
expect($('#router-locale').text()).toBe('nl-NL');
|
||||
expect(props.params).toEqual({ slug: 'second' });
|
||||
expect(JSON.parse($('#router-query').text())).toEqual({ slug: 'second' });
|
||||
|
||||
// wait for revalidation to occur
|
||||
await new Promise(resolve => setTimeout(resolve, 2000));
|
||||
|
||||
const res2 = await fetch(
|
||||
`${ctx.deploymentUrl}/nl-NL/gsp/no-fallback/second`
|
||||
);
|
||||
expect(res2.status).toBe(200);
|
||||
|
||||
$ = cheerio.load(await res2.text());
|
||||
const props2 = JSON.parse($('#props').text());
|
||||
expect(initialRandom).not.toBe(props2.random);
|
||||
expect($('#router-locale').text()).toBe('nl-NL');
|
||||
expect(props2.params).toEqual({ slug: 'second' });
|
||||
expect(JSON.parse($('#router-query').text())).toEqual({ slug: 'second' });
|
||||
});
|
||||
};
|
||||
21
packages/now-next/test/fixtures/00-i18n-support/next.config.js
vendored
Normal file
21
packages/now-next/test/fixtures/00-i18n-support/next.config.js
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
module.exports = {
|
||||
generateBuildId() {
|
||||
return 'testing-build-id';
|
||||
},
|
||||
i18n: {
|
||||
locales: ['nl-NL', 'nl-BE', 'nl', 'fr-BE', 'fr', 'en-US', 'en'],
|
||||
defaultLocale: 'en-US',
|
||||
// TODO: testing locale domains support, will require custom
|
||||
// testing set-up as test accounts are used currently
|
||||
domains: [
|
||||
{
|
||||
domain: 'example.be',
|
||||
defaultLocale: 'nl-BE',
|
||||
},
|
||||
{
|
||||
domain: 'example.fr',
|
||||
defaultLocale: 'fr',
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
484
packages/now-next/test/fixtures/00-i18n-support/now.json
vendored
Normal file
484
packages/now-next/test/fixtures/00-i18n-support/now.json
vendored
Normal file
@@ -0,0 +1,484 @@
|
||||
{
|
||||
"version": 2,
|
||||
"builds": [
|
||||
{
|
||||
"src": "package.json",
|
||||
"use": "@vercel/next"
|
||||
}
|
||||
],
|
||||
"probes": [
|
||||
{
|
||||
"path": "/",
|
||||
"headers": {
|
||||
"accept-language": "en;q=0.9"
|
||||
},
|
||||
"fetchOptions": {
|
||||
"redirect": "manual"
|
||||
},
|
||||
"status": 307,
|
||||
"responseHeaders": {
|
||||
"location": "//en/"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "/",
|
||||
"headers": {
|
||||
"accept-language": "nl;q=0.9"
|
||||
},
|
||||
"fetchOptions": {
|
||||
"redirect": "manual"
|
||||
},
|
||||
"status": 307,
|
||||
"responseHeaders": {
|
||||
"location": "//nl/"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "/",
|
||||
"headers": {
|
||||
"accept-language": "nl-NL;q=0.9"
|
||||
},
|
||||
"fetchOptions": {
|
||||
"redirect": "manual"
|
||||
},
|
||||
"status": 307,
|
||||
"responseHeaders": {
|
||||
"location": "//nl-NL/"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "/",
|
||||
"headers": {
|
||||
"accept-language": "fr;q=0.9"
|
||||
},
|
||||
"fetchOptions": {
|
||||
"redirect": "manual"
|
||||
},
|
||||
"status": 307,
|
||||
"responseHeaders": {
|
||||
"location": "//fr/"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "/",
|
||||
"headers": {
|
||||
"accept-language": "en-US;q=0.9"
|
||||
},
|
||||
"fetchOptions": {
|
||||
"redirect": "manual"
|
||||
},
|
||||
"status": 200,
|
||||
"mustContain": "index page"
|
||||
},
|
||||
{
|
||||
"path": "/en-US",
|
||||
"headers": {
|
||||
"accept-language": "nl;q=0.9"
|
||||
},
|
||||
"fetchOptions": {
|
||||
"redirect": "manual"
|
||||
},
|
||||
"status": 200,
|
||||
"mustContain": "index page"
|
||||
},
|
||||
|
||||
{
|
||||
"path": "/",
|
||||
"status": 200,
|
||||
"mustContain": "index page"
|
||||
},
|
||||
{
|
||||
"path": "/",
|
||||
"status": 200,
|
||||
"mustContain": ">en-US<"
|
||||
},
|
||||
{
|
||||
"path": "/en",
|
||||
"status": 200,
|
||||
"mustContain": "index page"
|
||||
},
|
||||
{
|
||||
"path": "/en",
|
||||
"status": 200,
|
||||
"mustContain": ">en<"
|
||||
},
|
||||
{
|
||||
"path": "/fr",
|
||||
"status": 200,
|
||||
"mustContain": "index page"
|
||||
},
|
||||
{
|
||||
"path": "/fr",
|
||||
"status": 200,
|
||||
"mustContain": ">fr<"
|
||||
},
|
||||
{
|
||||
"path": "/nl",
|
||||
"status": 200,
|
||||
"mustContain": "index page"
|
||||
},
|
||||
{
|
||||
"path": "/nl",
|
||||
"status": 200,
|
||||
"mustContain": ">nl<"
|
||||
},
|
||||
{
|
||||
"path": "/nl-NL",
|
||||
"status": 200,
|
||||
"mustContain": "index page"
|
||||
},
|
||||
{
|
||||
"path": "/nl-NL",
|
||||
"status": 200,
|
||||
"mustContain": ">nl-NL<"
|
||||
},
|
||||
|
||||
{
|
||||
"path": "/non-existent",
|
||||
"status": 404
|
||||
},
|
||||
{
|
||||
"path": "/fr/non-existent",
|
||||
"status": 404,
|
||||
"mustContain": "lang=\"fr\""
|
||||
},
|
||||
{
|
||||
"path": "/en/non-existent",
|
||||
"status": 404,
|
||||
"mustContain": "lang=\"en\""
|
||||
},
|
||||
{
|
||||
"path": "/en-US/non-existent",
|
||||
"status": 404,
|
||||
"mustContain": "lang=\"en-US\""
|
||||
},
|
||||
{
|
||||
"path": "/nl/non-existent",
|
||||
"status": 404,
|
||||
"mustContain": "lang=\"nl\""
|
||||
},
|
||||
{
|
||||
"path": "/nl-NL/non-existent",
|
||||
"status": 404,
|
||||
"mustContain": "lang=\"nl-NL\""
|
||||
},
|
||||
|
||||
{
|
||||
"path": "/hello.txt",
|
||||
"status": 200,
|
||||
"mustContain": "hello world!"
|
||||
},
|
||||
|
||||
{
|
||||
"path": "/gsp",
|
||||
"status": 200,
|
||||
"mustContain": "gsp page"
|
||||
},
|
||||
{
|
||||
"path": "/gsp",
|
||||
"status": 200,
|
||||
"mustContain": ">en-US<"
|
||||
},
|
||||
{
|
||||
"path": "/en/gsp",
|
||||
"status": 200,
|
||||
"mustContain": "gsp page"
|
||||
},
|
||||
{
|
||||
"path": "/en/gsp",
|
||||
"status": 200,
|
||||
"mustContain": ">en<"
|
||||
},
|
||||
{
|
||||
"path": "/nl/gsp",
|
||||
"status": 200,
|
||||
"mustContain": "gsp page"
|
||||
},
|
||||
{
|
||||
"path": "/nl/gsp",
|
||||
"status": 200,
|
||||
"mustContain": ">nl<"
|
||||
},
|
||||
{
|
||||
"path": "/fr/gsp",
|
||||
"status": 200,
|
||||
"mustContain": "gsp page"
|
||||
},
|
||||
{
|
||||
"path": "/fr/gsp",
|
||||
"status": 200,
|
||||
"mustContain": ">fr<"
|
||||
},
|
||||
|
||||
{
|
||||
"path": "/gssp",
|
||||
"status": 200,
|
||||
"mustContain": "gssp page"
|
||||
},
|
||||
{
|
||||
"path": "/gssp",
|
||||
"status": 200,
|
||||
"mustContain": ">en-US<"
|
||||
},
|
||||
{
|
||||
"path": "/en/gssp",
|
||||
"status": 200,
|
||||
"mustContain": "gssp page"
|
||||
},
|
||||
{
|
||||
"path": "/en/gssp",
|
||||
"status": 200,
|
||||
"mustContain": ">en<"
|
||||
},
|
||||
{
|
||||
"path": "/nl/gssp",
|
||||
"status": 200,
|
||||
"mustContain": "gssp page"
|
||||
},
|
||||
{
|
||||
"path": "/nl/gssp",
|
||||
"status": 200,
|
||||
"mustContain": ">nl<"
|
||||
},
|
||||
{
|
||||
"path": "/fr/gssp",
|
||||
"status": 200,
|
||||
"mustContain": "gssp page"
|
||||
},
|
||||
{
|
||||
"path": "/fr/gssp",
|
||||
"status": 200,
|
||||
"mustContain": ">fr<"
|
||||
},
|
||||
|
||||
{
|
||||
"path": "/gssp/first",
|
||||
"status": 200,
|
||||
"mustContain": "gssp page"
|
||||
},
|
||||
{
|
||||
"path": "/gssp/first",
|
||||
"status": 200,
|
||||
"mustContain": ">en-US<"
|
||||
},
|
||||
{
|
||||
"path": "/gssp/first",
|
||||
"status": 200,
|
||||
"mustContain": "slug\":\"first\""
|
||||
},
|
||||
{
|
||||
"path": "/en/gssp/first",
|
||||
"status": 200,
|
||||
"mustContain": "gssp page"
|
||||
},
|
||||
{
|
||||
"path": "/en/gssp/first",
|
||||
"status": 200,
|
||||
"mustContain": ">en<"
|
||||
},
|
||||
{
|
||||
"path": "/en/gssp/first",
|
||||
"status": 200,
|
||||
"mustContain": "slug\":\"first\""
|
||||
},
|
||||
{
|
||||
"path": "/nl/gssp/first",
|
||||
"status": 200,
|
||||
"mustContain": "gssp page"
|
||||
},
|
||||
{
|
||||
"path": "/nl/gssp/first",
|
||||
"status": 200,
|
||||
"mustContain": ">nl<"
|
||||
},
|
||||
{
|
||||
"path": "/nl/gssp/first",
|
||||
"status": 200,
|
||||
"mustContain": "slug\":\"first\""
|
||||
},
|
||||
{
|
||||
"path": "/fr/gssp/first",
|
||||
"status": 200,
|
||||
"mustContain": "gssp page"
|
||||
},
|
||||
{
|
||||
"path": "/fr/gssp/first",
|
||||
"status": 200,
|
||||
"mustContain": ">fr<"
|
||||
},
|
||||
{
|
||||
"path": "/fr/gssp/first",
|
||||
"status": 200,
|
||||
"mustContain": "slug\":\"first\""
|
||||
},
|
||||
|
||||
// TODO: update when directory listing is disabled
|
||||
// and these are proper 404s
|
||||
{
|
||||
"path": "/en/not-found",
|
||||
"status": 200,
|
||||
"mustContain": "Index of"
|
||||
},
|
||||
{
|
||||
"path": "/nl/not-found",
|
||||
"status": 200,
|
||||
"mustContain": "Index of"
|
||||
},
|
||||
{
|
||||
"path": "/en-US/not-found",
|
||||
"status": 200,
|
||||
"mustContain": "lang=\"en-US\""
|
||||
},
|
||||
{
|
||||
"path": "/nl-NL/not-found",
|
||||
"status": 200,
|
||||
"mustContain": "lang=\"nl-NL\""
|
||||
},
|
||||
{
|
||||
"path": "/fr/not-found",
|
||||
"status": 200,
|
||||
"mustContain": "lang=\"fr\""
|
||||
},
|
||||
|
||||
// this will always be a 200 unless fallback: blocking is used
|
||||
// since the static fallback page is served before the 404
|
||||
// page is rendered
|
||||
{
|
||||
"path": "/en/not-found/fallback/first",
|
||||
"status": 200,
|
||||
"mustContain": "lang=\"en\""
|
||||
},
|
||||
{
|
||||
"delay": 2000
|
||||
},
|
||||
{
|
||||
"path": "/en/not-found/fallback/first",
|
||||
"status": 200,
|
||||
"mustNotContain": "gsp page"
|
||||
},
|
||||
{
|
||||
"path": "/_next/data/testing-build-id/en/not-found/fallback/first.json",
|
||||
"status": 404
|
||||
},
|
||||
{
|
||||
"path": "/en/not-found/fallback/first",
|
||||
"status": 200,
|
||||
"mustContain": "lang=\"en\""
|
||||
},
|
||||
{
|
||||
"path": "/en/not-found/fallback/first",
|
||||
"status": 200,
|
||||
"mustNotContain": "gsp page"
|
||||
},
|
||||
{
|
||||
"path": "/fr/not-found/fallback/first",
|
||||
"status": 200,
|
||||
"mustContain": "lang=\"fr\""
|
||||
},
|
||||
{
|
||||
"path": "/_next/data/testing-build-id/fr/not-found/fallback/first.json",
|
||||
"status": 200
|
||||
},
|
||||
{
|
||||
"path": "/fr/not-found/fallback/first",
|
||||
"status": 200,
|
||||
"mustContain": "lang=\"fr\""
|
||||
},
|
||||
{
|
||||
"delay": 2000
|
||||
},
|
||||
{
|
||||
"path": "/fr/not-found/fallback/first",
|
||||
"status": 200,
|
||||
"mustContain": "gsp page"
|
||||
},
|
||||
|
||||
{
|
||||
"path": "/_next/data/testing-build-id/en-US/index.json",
|
||||
"status": 200,
|
||||
"mustContain": "\"locale\":\"en-US\""
|
||||
},
|
||||
{
|
||||
"path": "/_next/data/testing-build-id/en/index.json",
|
||||
"status": 200,
|
||||
"mustContain": "\"locale\":\"en\""
|
||||
},
|
||||
{
|
||||
"path": "/_next/data/testing-build-id/fr/index.json",
|
||||
"status": 200,
|
||||
"mustContain": "\"locale\":\"fr\""
|
||||
},
|
||||
{
|
||||
"path": "/_next/data/testing-build-id/nl/index.json",
|
||||
"status": 200,
|
||||
"mustContain": "\"locale\":\"nl\""
|
||||
},
|
||||
|
||||
{
|
||||
"path": "/_next/data/testing-build-id/en-US/gsp.json",
|
||||
"status": 200,
|
||||
"mustContain": "\"locale\":\"en-US\""
|
||||
},
|
||||
{
|
||||
"path": "/_next/data/testing-build-id/en/gsp.json",
|
||||
"status": 200,
|
||||
"mustContain": "\"locale\":\"en\""
|
||||
},
|
||||
{
|
||||
"path": "/_next/data/testing-build-id/fr/gsp.json",
|
||||
"status": 200,
|
||||
"mustContain": "\"locale\":\"fr\""
|
||||
},
|
||||
{
|
||||
"path": "/_next/data/testing-build-id/nl/gsp.json",
|
||||
"status": 200,
|
||||
"mustContain": "\"locale\":\"nl\""
|
||||
},
|
||||
|
||||
{
|
||||
"path": "/gsp/blocking/first",
|
||||
"status": 200,
|
||||
"mustContain": "catchall"
|
||||
},
|
||||
{
|
||||
"path": "/gsp/blocking/first",
|
||||
"status": 200,
|
||||
"mustContain": "lang=\"en-US\""
|
||||
},
|
||||
{
|
||||
"path": "/_next/data/testing-build-id/en-US/gsp/blocking/first.json",
|
||||
"status": 200,
|
||||
"mustContain": "\"catchall\":\"yes\""
|
||||
},
|
||||
{
|
||||
"path": "/nl-NL/gsp/blocking/first",
|
||||
"status": 200,
|
||||
"mustContain": "catchall"
|
||||
},
|
||||
{
|
||||
"path": "/nl-NL/gsp/blocking/first",
|
||||
"status": 200,
|
||||
"mustContain": "lang=\"nl-NL\""
|
||||
},
|
||||
{
|
||||
"path": "/_next/data/testing-build-id/nl-NL/gsp/blocking/first.json",
|
||||
"status": 200,
|
||||
"mustContain": "\"catchall\":\"yes\""
|
||||
},
|
||||
{
|
||||
"path": "/fr/gsp/blocking/first",
|
||||
"status": 200,
|
||||
"mustContain": "catchall"
|
||||
},
|
||||
{
|
||||
"path": "/fr/gsp/blocking/first",
|
||||
"status": 200,
|
||||
"mustContain": "lang=\"fr\""
|
||||
},
|
||||
{
|
||||
"path": "/_next/data/testing-build-id/fr/gsp/blocking/first.json",
|
||||
"status": 200,
|
||||
"mustContain": "\"catchall\":\"yes\""
|
||||
}
|
||||
]
|
||||
}
|
||||
7
packages/now-next/test/fixtures/00-i18n-support/package.json
vendored
Normal file
7
packages/now-next/test/fixtures/00-i18n-support/package.json
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"dependencies": {
|
||||
"next": "canary",
|
||||
"react": "^16.8.6",
|
||||
"react-dom": "^16.8.6"
|
||||
}
|
||||
}
|
||||
31
packages/now-next/test/fixtures/00-i18n-support/pages/another.js
vendored
Normal file
31
packages/now-next/test/fixtures/00-i18n-support/pages/another.js
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
import Link from 'next/link';
|
||||
import { useRouter } from 'next/router';
|
||||
|
||||
export default function Page(props) {
|
||||
const router = useRouter();
|
||||
|
||||
return (
|
||||
<>
|
||||
<p id="another">another page</p>
|
||||
<p id="props">{JSON.stringify(props)}</p>
|
||||
<p id="router-locale">{router.locale}</p>
|
||||
<p id="router-locales">{JSON.stringify(router.locales)}</p>
|
||||
<p id="router-query">{JSON.stringify(router.query)}</p>
|
||||
<p id="router-pathname">{router.pathname}</p>
|
||||
<p id="router-as-path">{router.asPath}</p>
|
||||
<Link href="/">
|
||||
<a id="to-index">to /</a>
|
||||
</Link>
|
||||
<br />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export const getServerSideProps = ({ locale, locales }) => {
|
||||
return {
|
||||
props: {
|
||||
locale,
|
||||
locales,
|
||||
},
|
||||
};
|
||||
};
|
||||
21
packages/now-next/test/fixtures/00-i18n-support/pages/auto-export/index.js
vendored
Normal file
21
packages/now-next/test/fixtures/00-i18n-support/pages/auto-export/index.js
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
import Link from 'next/link';
|
||||
import { useRouter } from 'next/router';
|
||||
|
||||
export default function Page(props) {
|
||||
const router = useRouter();
|
||||
|
||||
return (
|
||||
<>
|
||||
<p id="auto-export">auto-export page</p>
|
||||
<p id="props">{JSON.stringify(props)}</p>
|
||||
<p id="router-locale">{router.locale}</p>
|
||||
<p id="router-locales">{JSON.stringify(router.locales)}</p>
|
||||
<p id="router-query">{JSON.stringify(router.query)}</p>
|
||||
<p id="router-pathname">{router.pathname}</p>
|
||||
<p id="router-as-path">{router.asPath}</p>
|
||||
<Link href="/">
|
||||
<a id="to-index">to /</a>
|
||||
</Link>
|
||||
</>
|
||||
);
|
||||
}
|
||||
43
packages/now-next/test/fixtures/00-i18n-support/pages/gsp/blocking/[[...slug]].js
vendored
Normal file
43
packages/now-next/test/fixtures/00-i18n-support/pages/gsp/blocking/[[...slug]].js
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
import Link from 'next/link';
|
||||
|
||||
const Slug = props => {
|
||||
return (
|
||||
<div>
|
||||
<p id="props">{JSON.stringify(props)}</p>
|
||||
<Link href="/gsp/blocking/hallo-wereld" locale={'nl-NL'}>
|
||||
<a>/nl-NL/gsp/blocking/hallo-wereld</a>
|
||||
</Link>
|
||||
<br />
|
||||
<Link href="/gsp/blocking/42" locale={'nl-NL'}>
|
||||
<a>/nl-NL/gsp/blocking/42</a>
|
||||
</Link>
|
||||
<br />
|
||||
<Link href="/gsp/blocking/hallo-welt" locale={'fr'}>
|
||||
<a>/fr/gsp/blocking/hallo-welt</a>
|
||||
</Link>
|
||||
<br />
|
||||
<Link href="/gsp/blocking/42" locale={'fr'}>
|
||||
<a>/fr/gsp/blocking/42</a>
|
||||
</Link>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export const getStaticProps = () => {
|
||||
return {
|
||||
props: {
|
||||
random: Math.random(),
|
||||
catchall: 'yes',
|
||||
},
|
||||
revalidate: 1,
|
||||
};
|
||||
};
|
||||
|
||||
export const getStaticPaths = () => {
|
||||
return {
|
||||
paths: [],
|
||||
fallback: 'blocking',
|
||||
};
|
||||
};
|
||||
|
||||
export default Slug;
|
||||
51
packages/now-next/test/fixtures/00-i18n-support/pages/gsp/fallback/[slug].js
vendored
Normal file
51
packages/now-next/test/fixtures/00-i18n-support/pages/gsp/fallback/[slug].js
vendored
Normal file
@@ -0,0 +1,51 @@
|
||||
import Link from 'next/link';
|
||||
import { useRouter } from 'next/router';
|
||||
|
||||
export default function Page(props) {
|
||||
const router = useRouter();
|
||||
|
||||
if (router.isFallback) return 'Loading...';
|
||||
|
||||
return (
|
||||
<>
|
||||
<p id="gsp">gsp page</p>
|
||||
<p id="props">{JSON.stringify(props)}</p>
|
||||
<p id="router-locale">{router.locale}</p>
|
||||
<p id="router-locales">{JSON.stringify(router.locales)}</p>
|
||||
<p id="router-query">{JSON.stringify(router.query)}</p>
|
||||
<p id="router-pathname">{router.pathname}</p>
|
||||
<p id="router-as-path">{router.asPath}</p>
|
||||
<Link href="/">
|
||||
<a id="to-index">to /</a>
|
||||
</Link>
|
||||
<br />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export const getStaticProps = ({ params, locale, locales }) => {
|
||||
return {
|
||||
props: {
|
||||
random: Math.random(),
|
||||
params,
|
||||
locale,
|
||||
locales,
|
||||
},
|
||||
revalidate: 1,
|
||||
};
|
||||
};
|
||||
|
||||
export const getStaticPaths = ({ locales }) => {
|
||||
const paths = [];
|
||||
|
||||
for (const locale of locales) {
|
||||
paths.push({ params: { slug: 'first' }, locale });
|
||||
paths.push({ params: { slug: 'second' }, locale });
|
||||
}
|
||||
|
||||
return {
|
||||
// the default locale will be used since one isn't defined here
|
||||
paths,
|
||||
fallback: true,
|
||||
};
|
||||
};
|
||||
32
packages/now-next/test/fixtures/00-i18n-support/pages/gsp/index.js
vendored
Normal file
32
packages/now-next/test/fixtures/00-i18n-support/pages/gsp/index.js
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
import Link from 'next/link';
|
||||
import { useRouter } from 'next/router';
|
||||
|
||||
export default function Page(props) {
|
||||
const router = useRouter();
|
||||
|
||||
return (
|
||||
<>
|
||||
<p id="gsp">gsp page</p>
|
||||
<p id="props">{JSON.stringify(props)}</p>
|
||||
<p id="router-locale">{router.locale}</p>
|
||||
<p id="router-locales">{JSON.stringify(router.locales)}</p>
|
||||
<p id="router-query">{JSON.stringify(router.query)}</p>
|
||||
<p id="router-pathname">{router.pathname}</p>
|
||||
<p id="router-as-path">{router.asPath}</p>
|
||||
<Link href="/">
|
||||
<a id="to-index">to /</a>
|
||||
</Link>
|
||||
<br />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
// TODO: should non-dynamic GSP pages pre-render for each locale?
|
||||
export const getStaticProps = ({ locale, locales }) => {
|
||||
return {
|
||||
props: {
|
||||
locale,
|
||||
locales,
|
||||
},
|
||||
};
|
||||
};
|
||||
49
packages/now-next/test/fixtures/00-i18n-support/pages/gsp/no-fallback/[slug].js
vendored
Normal file
49
packages/now-next/test/fixtures/00-i18n-support/pages/gsp/no-fallback/[slug].js
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
import Link from 'next/link';
|
||||
import { useRouter } from 'next/router';
|
||||
|
||||
export default function Page(props) {
|
||||
const router = useRouter();
|
||||
|
||||
if (router.isFallback) return 'Loading...';
|
||||
|
||||
return (
|
||||
<>
|
||||
<p id="gsp">gsp page</p>
|
||||
<p id="props">{JSON.stringify(props)}</p>
|
||||
<p id="router-locale">{router.locale}</p>
|
||||
<p id="router-locales">{JSON.stringify(router.locales)}</p>
|
||||
<p id="router-query">{JSON.stringify(router.query)}</p>
|
||||
<p id="router-pathname">{router.pathname}</p>
|
||||
<p id="router-as-path">{router.asPath}</p>
|
||||
<Link href="/">
|
||||
<a id="to-index">to /</a>
|
||||
</Link>
|
||||
<br />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export const getStaticProps = ({ params, locale, locales }) => {
|
||||
return {
|
||||
props: {
|
||||
random: Math.random(),
|
||||
params,
|
||||
locale,
|
||||
locales,
|
||||
},
|
||||
revalidate: 1,
|
||||
};
|
||||
};
|
||||
|
||||
export const getStaticPaths = () => {
|
||||
return {
|
||||
paths: [
|
||||
{ params: { slug: 'first' } },
|
||||
'/gsp/no-fallback/second',
|
||||
{ params: { slug: 'first' }, locale: 'en-US' },
|
||||
'/nl-NL/gsp/no-fallback/second',
|
||||
'/fr/gsp/no-fallback/first',
|
||||
],
|
||||
fallback: false,
|
||||
};
|
||||
};
|
||||
32
packages/now-next/test/fixtures/00-i18n-support/pages/gssp/[slug].js
vendored
Normal file
32
packages/now-next/test/fixtures/00-i18n-support/pages/gssp/[slug].js
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
import Link from 'next/link';
|
||||
import { useRouter } from 'next/router';
|
||||
|
||||
export default function Page(props) {
|
||||
const router = useRouter();
|
||||
|
||||
return (
|
||||
<>
|
||||
<p id="gssp">gssp page</p>
|
||||
<p id="props">{JSON.stringify(props)}</p>
|
||||
<p id="router-locale">{router.locale}</p>
|
||||
<p id="router-locales">{JSON.stringify(router.locales)}</p>
|
||||
<p id="router-query">{JSON.stringify(router.query)}</p>
|
||||
<p id="router-pathname">{router.pathname}</p>
|
||||
<p id="router-as-path">{router.asPath}</p>
|
||||
<Link href="/">
|
||||
<a id="to-index">to /</a>
|
||||
</Link>
|
||||
<br />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export const getServerSideProps = ({ params, locale, locales }) => {
|
||||
return {
|
||||
props: {
|
||||
params,
|
||||
locale,
|
||||
locales,
|
||||
},
|
||||
};
|
||||
};
|
||||
31
packages/now-next/test/fixtures/00-i18n-support/pages/gssp/index.js
vendored
Normal file
31
packages/now-next/test/fixtures/00-i18n-support/pages/gssp/index.js
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
import Link from 'next/link';
|
||||
import { useRouter } from 'next/router';
|
||||
|
||||
export default function Page(props) {
|
||||
const router = useRouter();
|
||||
|
||||
return (
|
||||
<>
|
||||
<p id="gssp">gssp page</p>
|
||||
<p id="props">{JSON.stringify(props)}</p>
|
||||
<p id="router-locale">{router.locale}</p>
|
||||
<p id="router-locales">{JSON.stringify(router.locales)}</p>
|
||||
<p id="router-query">{JSON.stringify(router.query)}</p>
|
||||
<p id="router-pathname">{router.pathname}</p>
|
||||
<p id="router-as-path">{router.asPath}</p>
|
||||
<Link href="/">
|
||||
<a id="to-index">to /</a>
|
||||
</Link>
|
||||
<br />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export const getServerSideProps = ({ locale, locales }) => {
|
||||
return {
|
||||
props: {
|
||||
locale,
|
||||
locales,
|
||||
},
|
||||
};
|
||||
};
|
||||
57
packages/now-next/test/fixtures/00-i18n-support/pages/index.js
vendored
Normal file
57
packages/now-next/test/fixtures/00-i18n-support/pages/index.js
vendored
Normal file
@@ -0,0 +1,57 @@
|
||||
import Link from 'next/link';
|
||||
import { useRouter } from 'next/router';
|
||||
|
||||
export default function Page(props) {
|
||||
const router = useRouter();
|
||||
|
||||
return (
|
||||
<>
|
||||
<p id="index">index page</p>
|
||||
<p id="props">{JSON.stringify(props)}</p>
|
||||
<p id="router-locale">{router.locale}</p>
|
||||
<p id="router-locales">{JSON.stringify(router.locales)}</p>
|
||||
<p id="router-query">{JSON.stringify(router.query)}</p>
|
||||
<p id="router-pathname">{router.pathname}</p>
|
||||
<p id="router-as-path">{router.asPath}</p>
|
||||
<Link href="/another">
|
||||
<a id="to-another">to /another</a>
|
||||
</Link>
|
||||
<br />
|
||||
<Link href="/gsp">
|
||||
<a id="to-gsp">to /gsp</a>
|
||||
</Link>
|
||||
<br />
|
||||
<Link href="/gsp/fallback/first">
|
||||
<a id="to-fallback-first">to /gsp/fallback/first</a>
|
||||
</Link>
|
||||
<br />
|
||||
<Link href="/gsp/fallback/hello">
|
||||
<a id="to-fallback-hello">to /gsp/fallback/hello</a>
|
||||
</Link>
|
||||
<br />
|
||||
<Link href="/gsp/no-fallback/first">
|
||||
<a id="to-no-fallback-first">to /gsp/no-fallback/first</a>
|
||||
</Link>
|
||||
<br />
|
||||
<Link href="/gssp">
|
||||
<a id="to-gssp">to /gssp</a>
|
||||
</Link>
|
||||
<br />
|
||||
<Link href="/gssp/first">
|
||||
<a id="to-gssp-slug">to /gssp/first</a>
|
||||
</Link>
|
||||
<br />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export const getStaticProps = ({ locale, locales }) => {
|
||||
return {
|
||||
props: {
|
||||
random: Math.random(),
|
||||
locale,
|
||||
locales,
|
||||
},
|
||||
revalidate: 1,
|
||||
};
|
||||
};
|
||||
54
packages/now-next/test/fixtures/00-i18n-support/pages/links.js
vendored
Normal file
54
packages/now-next/test/fixtures/00-i18n-support/pages/links.js
vendored
Normal file
@@ -0,0 +1,54 @@
|
||||
import Link from 'next/link';
|
||||
import { useRouter } from 'next/router';
|
||||
|
||||
export default function Page(props) {
|
||||
const router = useRouter();
|
||||
const { nextLocale } = router.query;
|
||||
|
||||
return (
|
||||
<>
|
||||
<p id="links">links page</p>
|
||||
<p id="props">{JSON.stringify(props)}</p>
|
||||
<p id="router-locale">{router.locale}</p>
|
||||
<p id="router-locales">{JSON.stringify(router.locales)}</p>
|
||||
<p id="router-query">{JSON.stringify(router.query)}</p>
|
||||
<p id="router-pathname">{router.pathname}</p>
|
||||
<p id="router-as-path">{router.asPath}</p>
|
||||
<Link href="/another" locale={nextLocale}>
|
||||
<a id="to-another">to /another</a>
|
||||
</Link>
|
||||
<br />
|
||||
<Link href="/gsp" locale={nextLocale}>
|
||||
<a id="to-gsp">to /gsp</a>
|
||||
</Link>
|
||||
<br />
|
||||
<Link href="/gsp/fallback/first" locale={nextLocale}>
|
||||
<a id="to-fallback-first">to /gsp/fallback/first</a>
|
||||
</Link>
|
||||
<br />
|
||||
<Link href="/gsp/fallback/hello" locale={nextLocale}>
|
||||
<a id="to-fallback-hello">to /gsp/fallback/hello</a>
|
||||
</Link>
|
||||
<br />
|
||||
<Link href="/gsp/no-fallback/first" locale={nextLocale}>
|
||||
<a id="to-no-fallback-first">to /gsp/no-fallback/first</a>
|
||||
</Link>
|
||||
<br />
|
||||
<Link href="/gssp" locale={nextLocale}>
|
||||
<a id="to-gssp">to /gssp</a>
|
||||
</Link>
|
||||
<br />
|
||||
<Link href="/gssp/first" locale={nextLocale}>
|
||||
<a id="to-gssp-slug">to /gssp/first</a>
|
||||
</Link>
|
||||
<br />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
// make SSR page so we have query values immediately
|
||||
export const getServerSideProps = () => {
|
||||
return {
|
||||
props: {},
|
||||
};
|
||||
};
|
||||
50
packages/now-next/test/fixtures/00-i18n-support/pages/not-found/fallback/[slug].js
vendored
Normal file
50
packages/now-next/test/fixtures/00-i18n-support/pages/not-found/fallback/[slug].js
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
import Link from 'next/link';
|
||||
import { useRouter } from 'next/router';
|
||||
|
||||
export default function Page(props) {
|
||||
const router = useRouter();
|
||||
|
||||
if (router.isFallback) return 'Loading...';
|
||||
|
||||
return (
|
||||
<>
|
||||
<p id="gsp">gsp page</p>
|
||||
<p id="props">{JSON.stringify(props)}</p>
|
||||
<p id="router-locale">{router.locale}</p>
|
||||
<p id="router-locales">{JSON.stringify(router.locales)}</p>
|
||||
<p id="router-query">{JSON.stringify(router.query)}</p>
|
||||
<p id="router-pathname">{router.pathname}</p>
|
||||
<p id="router-as-path">{router.asPath}</p>
|
||||
<Link href="/">
|
||||
<a id="to-index">to /</a>
|
||||
</Link>
|
||||
<br />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export const getStaticProps = ({ params, locale, locales }) => {
|
||||
if (locale === 'en' || locale === 'nl') {
|
||||
return {
|
||||
notFound: true,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
props: {
|
||||
params,
|
||||
locale,
|
||||
locales,
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
export const getStaticPaths = () => {
|
||||
return {
|
||||
// the default locale will be used since one isn't defined here
|
||||
paths: ['first', 'second'].map(slug => ({
|
||||
params: { slug },
|
||||
})),
|
||||
fallback: true,
|
||||
};
|
||||
};
|
||||
37
packages/now-next/test/fixtures/00-i18n-support/pages/not-found/index.js
vendored
Normal file
37
packages/now-next/test/fixtures/00-i18n-support/pages/not-found/index.js
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
import Link from 'next/link';
|
||||
import { useRouter } from 'next/router';
|
||||
|
||||
export default function Page(props) {
|
||||
const router = useRouter();
|
||||
|
||||
return (
|
||||
<>
|
||||
<p id="gsp">gsp page</p>
|
||||
<p id="props">{JSON.stringify(props)}</p>
|
||||
<p id="router-locale">{router.locale}</p>
|
||||
<p id="router-locales">{JSON.stringify(router.locales)}</p>
|
||||
<p id="router-query">{JSON.stringify(router.query)}</p>
|
||||
<p id="router-pathname">{router.pathname}</p>
|
||||
<p id="router-as-path">{router.asPath}</p>
|
||||
<Link href="/">
|
||||
<a id="to-index">to /</a>
|
||||
</Link>
|
||||
<br />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export const getStaticProps = ({ locale, locales }) => {
|
||||
if (locale === 'en' || locale === 'nl') {
|
||||
return {
|
||||
notFound: true,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
props: {
|
||||
locale,
|
||||
locales,
|
||||
},
|
||||
};
|
||||
};
|
||||
1
packages/now-next/test/fixtures/00-i18n-support/public/hello.txt
vendored
Normal file
1
packages/now-next/test/fixtures/00-i18n-support/public/hello.txt
vendored
Normal file
@@ -0,0 +1 @@
|
||||
hello world!
|
||||
@@ -152,6 +152,16 @@
|
||||
"x-vercel-cache": "/HIT|STALE|PRERENDER/"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "/",
|
||||
"status": 200,
|
||||
"mustContain": "Hi"
|
||||
},
|
||||
{
|
||||
"path": "/_next/data/testing-build-id/index.json",
|
||||
"status": 200,
|
||||
"mustContain": "\"hello\":\"index\""
|
||||
},
|
||||
{
|
||||
"path": "/_next/data/testing-build-id/api-docs/second.json",
|
||||
"status": 200
|
||||
|
||||
@@ -1 +1,9 @@
|
||||
export default () => 'Hi';
|
||||
|
||||
export const getStaticProps = () => {
|
||||
return {
|
||||
props: {
|
||||
hello: 'index',
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
@@ -19,5 +19,5 @@ export function getStaticProps({ params }) {
|
||||
}
|
||||
|
||||
export function getStaticPaths() {
|
||||
return { paths: [], fallback: 'unstable_blocking' };
|
||||
return { paths: [], fallback: 'blocking' };
|
||||
}
|
||||
|
||||
@@ -19,5 +19,5 @@ export function getStaticProps({ params }) {
|
||||
}
|
||||
|
||||
export function getStaticPaths() {
|
||||
return { paths: [], fallback: 'unstable_blocking' };
|
||||
return { paths: [], fallback: 'blocking' };
|
||||
}
|
||||
|
||||
@@ -207,7 +207,9 @@ it(
|
||||
|
||||
expect(contents.some(name => name === 'next.config.js')).toBeTruthy();
|
||||
expect(
|
||||
contents.some(name => name.includes('next.config.original.'))
|
||||
contents.some(name =>
|
||||
name.includes('next.config.__vercel_builder_backup__')
|
||||
)
|
||||
).toBeTruthy();
|
||||
},
|
||||
FOUR_MINUTES
|
||||
@@ -278,7 +280,9 @@ it(
|
||||
|
||||
expect(contents.some(name => name === 'next.config.js')).toBeTruthy();
|
||||
expect(
|
||||
contents.some(name => name.includes('next.config.original.'))
|
||||
contents.some(name =>
|
||||
name.includes('next.config.__vercel_builder_backup__')
|
||||
)
|
||||
).toBeTruthy();
|
||||
},
|
||||
FOUR_MINUTES
|
||||
@@ -345,7 +349,9 @@ it(
|
||||
|
||||
expect(contents.some(name => name === 'next.config.js')).toBeTruthy();
|
||||
expect(
|
||||
contents.some(name => name.includes('next.config.original.'))
|
||||
contents.some(name =>
|
||||
name.includes('next.config.__vercel_builder_backup__')
|
||||
)
|
||||
).toBeTruthy();
|
||||
},
|
||||
FOUR_MINUTES
|
||||
@@ -380,7 +386,9 @@ it(
|
||||
|
||||
expect(contents.some(name => name === 'next.config.js')).toBeTruthy();
|
||||
expect(
|
||||
contents.some(name => name.includes('next.config.original.'))
|
||||
contents.some(name =>
|
||||
name.includes('next.config.__vercel_builder_backup__')
|
||||
)
|
||||
).toBeFalsy();
|
||||
},
|
||||
FOUR_MINUTES
|
||||
@@ -422,7 +430,9 @@ it(
|
||||
|
||||
expect(contents.some(name => name === 'next.config.js')).toBeTruthy();
|
||||
expect(
|
||||
contents.some(name => name.includes('next.config.original.'))
|
||||
contents.some(name =>
|
||||
name.includes('next.config.__vercel_builder_backup__')
|
||||
)
|
||||
).toBeFalsy();
|
||||
},
|
||||
FOUR_MINUTES
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@vercel/routing-utils",
|
||||
"version": "1.9.0",
|
||||
"version": "1.9.1-canary.1",
|
||||
"description": "Vercel routing utilities",
|
||||
"main": "./dist/index.js",
|
||||
"types": "./dist/index.d.ts",
|
||||
|
||||
@@ -60,6 +60,10 @@ export const routesSchema = {
|
||||
type: 'string',
|
||||
maxLength: 4096,
|
||||
},
|
||||
cookie: {
|
||||
type: 'string',
|
||||
maxLength: 4096,
|
||||
},
|
||||
default: {
|
||||
type: 'string',
|
||||
maxLength: 4096,
|
||||
|
||||
@@ -17,6 +17,10 @@ export type Source = {
|
||||
continue?: boolean;
|
||||
check?: boolean;
|
||||
status?: number;
|
||||
locale?: {
|
||||
redirect: Record<string, string>;
|
||||
cookie: string;
|
||||
};
|
||||
};
|
||||
|
||||
export type Handler = {
|
||||
|
||||
@@ -42,6 +42,7 @@ describe('normalizeRoutes', () => {
|
||||
value: '$value',
|
||||
path: '$path',
|
||||
default: 'en',
|
||||
cookie: 'NEXT_LOCALE',
|
||||
},
|
||||
},
|
||||
{
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@vercel/redwood",
|
||||
"version": "0.1.1",
|
||||
"version": "0.1.2-canary.0",
|
||||
"main": "./dist/index.js",
|
||||
"license": "MIT",
|
||||
"homepage": "https://vercel.com/docs",
|
||||
@@ -19,7 +19,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@netlify/zip-it-and-ship-it": "1.2.0",
|
||||
"@vercel/frameworks": "0.1.1"
|
||||
"@vercel/frameworks": "0.1.2-canary.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/aws-lambda": "8.10.19",
|
||||
|
||||
13
yarn.lock
13
yarn.lock
@@ -4793,21 +4793,16 @@ escape-html@1.0.3:
|
||||
resolved "https://registry.yarnpkg.com/escape-html/-/escape-html-1.0.3.tgz#0258eae4d3d0c0974de1c169188ef0051d1d1988"
|
||||
integrity sha1-Aljq5NPQwJdN4cFpGI7wBR0dGYg=
|
||||
|
||||
escape-string-regexp@3.0.0:
|
||||
version "3.0.0"
|
||||
resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-3.0.0.tgz#1dad9cc28aed682be0de197280f79911a5fccd61"
|
||||
integrity sha512-11dXIUC3umvzEViLP117d0KN6LJzZxh5+9F4E/7WLAAw7GrHk8NpUR+g9iJi/pe9C0py4F8rs0hreyRCwlAuZg==
|
||||
escape-string-regexp@2.0.0, escape-string-regexp@^2.0.0:
|
||||
version "2.0.0"
|
||||
resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-2.0.0.tgz#a30304e99daa32e23b2fd20f51babd07cffca344"
|
||||
integrity sha512-UpzcLCXolUWcNu5HtVMHYdXJjArjsF9C0aNnquZYY4uW/Vu0miy5YoWvbV345HauVvcAUnpRuhMMcqTcGOY2+w==
|
||||
|
||||
escape-string-regexp@^1.0.2, escape-string-regexp@^1.0.5:
|
||||
version "1.0.5"
|
||||
resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4"
|
||||
integrity sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=
|
||||
|
||||
escape-string-regexp@^2.0.0:
|
||||
version "2.0.0"
|
||||
resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-2.0.0.tgz#a30304e99daa32e23b2fd20f51babd07cffca344"
|
||||
integrity sha512-UpzcLCXolUWcNu5HtVMHYdXJjArjsF9C0aNnquZYY4uW/Vu0miy5YoWvbV345HauVvcAUnpRuhMMcqTcGOY2+w==
|
||||
|
||||
escodegen@^1.8.0, escodegen@^1.9.1:
|
||||
version "1.14.2"
|
||||
resolved "https://registry.yarnpkg.com/escodegen/-/escodegen-1.14.2.tgz#14ab71bf5026c2aa08173afba22c6f3173284a84"
|
||||
|
||||
Reference in New Issue
Block a user