Skip to content

Commit

Permalink
Merge branch 'canary' into no_throw_in_error_event
Browse files Browse the repository at this point in the history
  • Loading branch information
leerob authored Aug 15, 2024
2 parents 74feec3 + 658ffe2 commit 5f085fc
Show file tree
Hide file tree
Showing 13 changed files with 254 additions and 104 deletions.
1 change: 1 addition & 0 deletions docs/02-app/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Here are some common authentication solutions that support the App Router:

- [NextAuth.js](https://next-auth.js.org/configuration/nextjs#in-app-router)
- [Clerk](https://clerk.com/docs/quickstarts/nextjs)
- [Stack Auth](https://docs.stack-auth.com/getting-started/setup)
- [Lucia](https://lucia-auth.com/getting-started/nextjs-app)
- [Auth0](https://github.com/auth0/nextjs-auth0#app-router)
- [Stytch](https://stytch.com/docs/example-apps/frontend/nextjs)
Expand Down
1 change: 0 additions & 1 deletion examples/cms-contentful/.env.local.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
CONTENTFUL_SPACE_ID=
CONTENTFUL_ACCESS_TOKEN=
CONTENTFUL_PREVIEW_ACCESS_TOKEN=
CONTENTFUL_PREVIEW_SECRET=
CONTENTFUL_REVALIDATE_SECRET=
24 changes: 2 additions & 22 deletions examples/cms-contentful/app/api/draft/route.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,2 @@
import { draftMode } from "next/headers";
import { redirect } from "next/navigation";
import { getPreviewPostBySlug } from "../../../lib/api";

export async function GET(request: Request) {
const { searchParams } = new URL(request.url);
const secret = searchParams.get("secret");
const slug = searchParams.get("slug");

if (secret !== process.env.CONTENTFUL_PREVIEW_SECRET) {
return new Response("Invalid token", { status: 401 });
}

const post = await getPreviewPostBySlug(slug);

if (!post) {
return new Response("Invalid slug", { status: 401 });
}

draftMode().enable();
redirect(`/posts/${post.slug}`);
}
//@ts-ignore
export { enableDraftHandler as GET } from "@contentful/vercel-nextjs-toolkit/app-router";
1 change: 1 addition & 0 deletions examples/cms-contentful/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"dependencies": {
"@contentful/rich-text-react-renderer": "^15.17.1",
"@contentful/rich-text-types": "^16.2.1",
"@contentful/vercel-nextjs-toolkit": "latest",
"@tailwindcss/typography": "0.5.9",
"@types/node": "^20.5.0",
"@types/react": "^18.2.20",
Expand Down
9 changes: 5 additions & 4 deletions examples/inngest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
"private": true,
"scripts": {
"dev": "concurrently \"npm:dev:*\"",
"dev:next": "next dev",
"dev:inngest": "npx inngest-cli@latest dev",
"dev:next": "next dev --turbo",
"dev:inngest": "inngest-cli dev --no-discovery -u http://localhost:3000/api/inngest",
"build": "next build",
"start": "next start"
},
"dependencies": {
"inngest": "latest",
"inngest": "3.x",
"next": "latest",
"react": "18.2.0",
"react-dom": "18.2.0"
Expand All @@ -19,6 +19,7 @@
"@types/react-dom": "18.2.7",
"concurrently": "^8.2.1",
"encoding": "^0.1.13",
"typescript": "5.2.2"
"inngest-cli": "latest",
"typescript": "5.5.4"
}
}
5 changes: 2 additions & 3 deletions examples/inngest/src/app/api/inngest/route.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { inngestConfig } from "@/inngest/inngest.config";
import { serve } from "inngest/next";
import { inngest } from "@/inngest/inngest.client";
import { helloWorld } from "@/inngest/functions/hello-world";

export const { GET, POST, PUT } = serve(inngest, [helloWorld]);
export const { GET, POST, PUT } = serve(inngestConfig);
2 changes: 1 addition & 1 deletion examples/inngest/src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { inngest } from "@/inngest/inngest.client";
import { inngest } from "@/inngest/inngest.config";
import { redirect } from "next/navigation";

export default function Home() {
Expand Down
10 changes: 0 additions & 10 deletions examples/inngest/src/inngest/functions/hello-world.ts

This file was deleted.

4 changes: 0 additions & 4 deletions examples/inngest/src/inngest/inngest.client.ts

This file was deleted.

33 changes: 33 additions & 0 deletions examples/inngest/src/inngest/inngest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { EventSchemas, Inngest } from "inngest";

// TypeScript schema for the events
export type Events = {
"test/hello.world": {
name: "test/hello.world";
data: {
message: string;
};
};
};

// Inngest client to send and receive events
export const inngest = new Inngest({
id: "demo-app",
schemas: new EventSchemas().fromRecord<Events>(),
});

// a function to execute, typically in its own file
const helloWorld = inngest.createFunction(
{ id: "hello-world", name: "Hello World" },
{ event: "test/hello.world" },
async ({ event, step }) => {
await step.sleep("sleep for a second", "1s");
return { event, body: event.data.message };
},
);

// configuration for the Inngest api router
export const inngestConfig = {
client: inngest,
functions: [helloWorld],
};
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
/* eslint-env jest */

import { nextTestSetup } from 'e2e-utils'
import { readdir, readFile } from 'fs-extra'
import { join } from 'path'

const nextConfig = {
productionBrowserSourceMaps: true,
Expand Down Expand Up @@ -33,55 +31,194 @@ describe.each([
;(isNextDev ? describe.skip : describe)('Production only', () => {
describe('CSS Compilation and Prefixing', () => {
it(`should've compiled and prefixed`, async () => {
const cssFolder = join(next.testDir, '.next/static/css')
const $ = await next.render$('/')

const files = await readdir(cssFolder)
const cssFiles = files.filter((f) => /\.css$/.test(f))
const cssSheet = $('link[rel="stylesheet"]')
expect(cssSheet.length).toBe(1)

expect(cssFiles.length).toBe(1)
const cssContent = await readFile(join(cssFolder, cssFiles[0]), 'utf8')
expect(
cssContent.replace(/\/\*.*?\*\//g, '').trim()
).toMatchInlineSnapshot(
`".redText ::placeholder{color:red}.flex-parsing{flex:0 0 calc(50% - var(--vertical-gutter))}"`
)
const stylesheetUrl = cssSheet.attr('href')

const cssContent = await next
.fetch(stylesheetUrl)
.then((res) => res.text())
const cssContentWithoutSourceMap = cssContent
.replace(/\/\*.*?\*\//g, '')
.trim()

if (process.env.TURBOPACK) {
if (dependencies.sass) {
expect(cssContentWithoutSourceMap).toMatchInlineSnapshot(`
".redText ::placeholder {
color: red;
}
.flex-parsing {
flex: 0 0 calc(50% - var(--vertical-gutter));
}"
`)
} else {
expect(cssContentWithoutSourceMap).toMatchInlineSnapshot(`
".redText ::placeholder {
color: red;
}
.flex-parsing {
flex: 0 0 calc(50% - var(--vertical-gutter));
}"
`)
}
} else {
if (dependencies.sass) {
expect(cssContentWithoutSourceMap).toMatchInlineSnapshot(
`".redText ::placeholder{color:red}.flex-parsing{flex:0 0 calc(50% - var(--vertical-gutter))}"`
)
} else {
expect(cssContentWithoutSourceMap).toMatchInlineSnapshot(
`".redText ::placeholder{color:red}.flex-parsing{flex:0 0 calc(50% - var(--vertical-gutter))}"`
)
}
}

// Contains a source map
console.log({ cssContent })
expect(cssContent).toMatch(/\/\*#\s*sourceMappingURL=(.+\.map)\s*\*\//)
})

it(`should've emitted a source map`, async () => {
const cssFolder = join(next.testDir, '.next/static/css')
// Check sourcemap
const sourceMapUrl = /\/\*#\s*sourceMappingURL=(.+\.map)\s*\*\//.exec(
cssContent
)[1]

const files = await readdir(cssFolder)
const cssMapFiles = files.filter((f) => /\.css\.map$/.test(f))
const actualSourceMapUrl = stylesheetUrl.replace(/[^/]+$/, sourceMapUrl)
const sourceMapContent = await next
.fetch(actualSourceMapUrl)
.then((res) => res.text())
const sourceMapContentParsed = JSON.parse(sourceMapContent)
// Ensure it doesn't have a specific path in the snapshot.
delete sourceMapContentParsed.file
delete sourceMapContentParsed.sources

expect(cssMapFiles.length).toBe(1)
const cssMapContent = (
await readFile(join(cssFolder, cssMapFiles[0]), 'utf8')
).trim()
if (process.env.TURBOPACK) {
if (dependencies.sass) {
expect(sourceMapContentParsed).toMatchInlineSnapshot(`
{
"sections": [
{
"map": {
"mappings": "AAAA;;;;AAAiC",
"names": [],
"sources": [
"turbopack://[project]/styles/global.scss.css",
],
"sourcesContent": [
".redText ::placeholder{color:red}.flex-parsing{flex:0 0 calc(50% - var(--vertical-gutter))}",
],
"version": 3,
},
"offset": {
"column": 0,
"line": 1,
},
},
{
"map": {
"mappings": "A",
"names": [],
"sources": [],
"version": 3,
},
"offset": {
"column": 0,
"line": 8,
},
},
],
"version": 3,
}
`)
} else {
expect(sourceMapContentParsed).toMatchInlineSnapshot(`
{
"sections": [
{
"map": {
"mappings": "AAAA;;;;AAAiC",
"names": [],
"sources": [
"turbopack://[project]/styles/global.scss.css",
],
"sourcesContent": [
".redText ::placeholder{color:red}.flex-parsing{flex:0 0 calc(50% - var(--vertical-gutter))}",
],
"version": 3,
},
"offset": {
"column": 0,
"line": 1,
},
},
{
"map": {
"mappings": "A",
"names": [],
"sources": [],
"version": 3,
},
"offset": {
"column": 0,
"line": 8,
},
},
],
"version": 3,
}
`)
}
} else {
if (dependencies.sass) {
expect(sourceMapContentParsed).toMatchInlineSnapshot(`
{
"mappings": "AAEE,uBACE,SAHE,CAON,cACE,2CAAA",
"names": [],
"sourceRoot": "",
"sourcesContent": [
"$var: red;
.redText {
::placeholder {
color: $var;
}
}
const { version, mappings, sourcesContent } = JSON.parse(cssMapContent)
expect({ version, mappings, sourcesContent }).toMatchInlineSnapshot(`
{
"mappings": "AAEE,uBACE,SAHE,CAON,cACE,2CAAA",
"sourcesContent": [
"$var: red;
.redText {
::placeholder {
color: $var;
}
}
.flex-parsing {
flex: 0 0 calc(50% - var(--vertical-gutter));
}
",
],
"version": 3,
}
`)
.flex-parsing {
flex: 0 0 calc(50% - var(--vertical-gutter));
}
",
],
"version": 3,
}
`)
} else {
expect(sourceMapContentParsed).toMatchInlineSnapshot(`
{
"mappings": "AAEE,uBACE,SAHE,CAON,cACE,2CAAA",
"names": [],
"sourceRoot": "",
"sourcesContent": [
"$var: red;
.redText {
::placeholder {
color: $var;
}
}
.flex-parsing {
flex: 0 0 calc(50% - var(--vertical-gutter));
}
",
],
"version": 3,
}
`)
}
}
})
})
})
Expand Down
2 changes: 1 addition & 1 deletion test/lib/next-test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -875,7 +875,7 @@ export async function assertNoRedbox(browser: BrowserInterface) {
`description: ${redboxDescription}\n` +
`source: ${redboxSource}`
)
Error.captureStackTrace(error, assertHasRedbox)
Error.captureStackTrace(error, assertNoRedbox)
throw error
}
}
Expand Down
Loading

0 comments on commit 5f085fc

Please sign in to comment.