From 03317c750727c9588d500cea7b25649f8682e2f5 Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Thu, 2 Dec 2021 06:40:38 -0600 Subject: [PATCH 1/3] Fix copying swc binary for isolated tests locally (#32026) --- test/lib/create-next-install.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/test/lib/create-next-install.js b/test/lib/create-next-install.js index 190714959cb61..f3f5df619791f 100644 --- a/test/lib/create-next-install.js +++ b/test/lib/create-next-install.js @@ -18,15 +18,16 @@ async function createNextInstall(dependencies) { )) { if (folder.startsWith('swc-')) { const swcPkgPath = path.join(origRepoDir, 'node_modules/@next', folder) - await fs.copy( - swcPkgPath, - path.join(origRepoDir, 'packages/next-swc/native'), - { - filter: (item) => + const outputPath = path.join(origRepoDir, 'packages/next-swc/native') + await fs.copy(swcPkgPath, outputPath, { + filter: (item) => { + return ( item === swcPkgPath || - (item.endsWith('.node') && !fs.pathExistsSync(item)), - } - ) + (item.endsWith('.node') && + !fs.pathExistsSync(path.join(outputPath, path.basename(item)))) + ) + }, + }) } } From 25371dd1b06a4c0619e9878c4efeb0ea93df6d80 Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Thu, 2 Dec 2021 12:10:05 -0600 Subject: [PATCH 2/3] Lock node version for CI (#32057) --- .github/workflows/build_test_deploy.yml | 84 +++++++++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/.github/workflows/build_test_deploy.yml b/.github/workflows/build_test_deploy.yml index 1ae728400430b..8b52fd7678a62 100644 --- a/.github/workflows/build_test_deploy.yml +++ b/.github/workflows/build_test_deploy.yml @@ -28,6 +28,12 @@ jobs: docsChange: ${{ steps.docs-change.outputs.DOCS_CHANGE }} isRelease: ${{ steps.check-release.outputs.IS_RELEASE }} steps: + - name: Setup node + uses: actions/setup-node@v2 + if: ${{ steps.docs-change.outputs.docsChange != 'docs only change' }} + with: + node-version: 14 + - uses: actions/checkout@v2 with: fetch-depth: 25 @@ -62,6 +68,12 @@ jobs: runs-on: ubuntu-latest needs: build steps: + - name: Setup node + uses: actions/setup-node@v2 + if: ${{ steps.docs-change.outputs.docsChange != 'docs only change' }} + with: + node-version: 14 + - uses: actions/cache@v2 id: restore-build with: @@ -77,6 +89,12 @@ jobs: env: NEXT_TELEMETRY_DISABLED: 1 steps: + - name: Setup node + uses: actions/setup-node@v2 + if: ${{ steps.docs-change.outputs.docsChange != 'docs only change' }} + with: + node-version: 14 + # https://github.com/actions/virtual-environments/issues/1187 - name: tune linux network if: ${{needs.build.outputs.docsChange != 'docs only change'}} @@ -115,6 +133,12 @@ jobs: NEXT_TELEMETRY_DISABLED: 1 NEXT_TEST_JOB: 1 steps: + - name: Setup node + uses: actions/setup-node@v2 + if: ${{ steps.docs-change.outputs.docsChange != 'docs only change' }} + with: + node-version: 14 + - uses: actions/cache@v2 if: ${{needs.build.outputs.docsChange != 'docs only change'}} id: restore-build @@ -139,6 +163,12 @@ jobs: NEXT_TELEMETRY_DISABLED: 1 NEXT_TEST_JOB: 1 steps: + - name: Setup node + uses: actions/setup-node@v2 + if: ${{ steps.docs-change.outputs.docsChange != 'docs only change' }} + with: + node-version: 14 + - run: echo ${{needs.build.outputs.docsChange}} # https://github.com/actions/virtual-environments/issues/1187 @@ -187,6 +217,12 @@ jobs: NEXT_TELEMETRY_DISABLED: 1 NEXT_TEST_JOB: 1 steps: + - name: Setup node + uses: actions/setup-node@v2 + if: ${{ steps.docs-change.outputs.docsChange != 'docs only change' }} + with: + node-version: 14 + - run: echo ${{needs.build.outputs.docsChange}} # https://github.com/actions/virtual-environments/issues/1187 @@ -230,6 +266,12 @@ jobs: matrix: group: [1, 2, 3, 4, 5, 6] steps: + - name: Setup node + uses: actions/setup-node@v2 + if: ${{ steps.docs-change.outputs.docsChange != 'docs only change' }} + with: + node-version: 14 + - run: echo ${{needs.build.outputs.docsChange}} # https://github.com/actions/virtual-environments/issues/1187 @@ -274,6 +316,12 @@ jobs: NEXT_TEST_JOB: 1 TEST_ELECTRON: 1 steps: + - name: Setup node + uses: actions/setup-node@v2 + if: ${{ steps.docs-change.outputs.docsChange != 'docs only change' }} + with: + node-version: 14 + - uses: actions/cache@v2 if: ${{needs.build.outputs.docsChange != 'docs only change'}} id: restore-build @@ -300,6 +348,12 @@ jobs: NODE_OPTIONS: '--unhandled-rejections=strict' YARN_COMPRESSION_LEVEL: '0' steps: + - name: Setup node + uses: actions/setup-node@v2 + if: ${{ steps.docs-change.outputs.docsChange != 'docs only change' }} + with: + node-version: 14 + - uses: actions/cache@v2 if: ${{needs.build.outputs.docsChange != 'docs only change'}} id: restore-build @@ -342,6 +396,12 @@ jobs: BROWSER_NAME: 'firefox' NEXT_TELEMETRY_DISABLED: 1 steps: + - name: Setup node + uses: actions/setup-node@v2 + if: ${{ steps.docs-change.outputs.docsChange != 'docs only change' }} + with: + node-version: 14 + - uses: actions/cache@v2 if: ${{needs.build.outputs.docsChange != 'docs only change'}} id: restore-build @@ -370,6 +430,12 @@ jobs: BROWSERSTACK_USERNAME: ${{ secrets.BROWSERSTACK_USERNAME }} BROWSERSTACK_ACCESS_KEY: ${{ secrets.BROWSERSTACK_ACCESS_KEY }} steps: + - name: Setup node + uses: actions/setup-node@v2 + if: ${{ steps.docs-change.outputs.docsChange != 'docs only change' }} + with: + node-version: 14 + # https://github.com/actions/virtual-environments/issues/1187 - name: tune linux network run: sudo ethtool -K eth0 tx off rx off @@ -408,6 +474,12 @@ jobs: BROWSERSTACK_USERNAME: ${{ secrets.BROWSERSTACK_USERNAME }} BROWSERSTACK_ACCESS_KEY: ${{ secrets.BROWSERSTACK_ACCESS_KEY }} steps: + - name: Setup node + uses: actions/setup-node@v2 + if: ${{ steps.docs-change.outputs.docsChange != 'docs only change' }} + with: + node-version: 14 + # https://github.com/actions/virtual-environments/issues/1187 - name: tune linux network run: sudo ethtool -K eth0 tx off rx off @@ -479,6 +551,12 @@ jobs: env: NPM_TOKEN: ${{ secrets.NPM_TOKEN_ELEVATED }} steps: + - name: Setup node + uses: actions/setup-node@v2 + if: ${{ steps.docs-change.outputs.docsChange != 'docs only change' }} + with: + node-version: 14 + # https://github.com/actions/virtual-environments/issues/1187 - name: tune linux network run: sudo ethtool -K eth0 tx off rx off @@ -508,6 +586,12 @@ jobs: runs-on: ubuntu-latest needs: [publishRelease, build-native-dev] steps: + - name: Setup node + uses: actions/setup-node@v2 + if: ${{ steps.docs-change.outputs.docsChange != 'docs only change' }} + with: + node-version: 14 + - uses: actions/cache@v2 id: restore-build with: From cc9e1ea3a17dd5212df833ef6ad88cc8cec9de0d Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Thu, 2 Dec 2021 12:49:49 -0600 Subject: [PATCH 3/3] Fix middleware types with skipLibCheck: false (#32025) This ensures type checking passes correctly for middleware types when `skipLibCheck: false` is set in `tsconfig.json`. This also moves the `middleware-types` to be an isolated test to ensure it isn't relying on any monorepo dependencies. ## Bug - [x] Related issues linked using `fixes #number` - [x] Integration tests added - [ ] Errors have helpful link attached, see `contributing.md` Fixes: https://github.com/vercel/next.js/issues/31992#issuecomment-984174872 --- .../server/web/spec-extension/response.ts | 2 +- packages/next/server/web/types.ts | 11 +++++++ .../middleware-typescript/test/index.test.js | 16 --------- .../middleware-typescript/app}/next.config.js | 0 .../app}/pages/interface/[id]/index.tsx | 0 .../app}/pages/interface/_middleware.ts | 2 +- .../app}/pages/interface/static.tsx | 0 .../app}/pages/redirects/_middleware.ts | 0 .../app}/pages/redirects/index.tsx | 0 .../app}/pages/redirects/new-home.tsx | 0 .../app}/pages/redirects/old-home.tsx | 0 .../app}/pages/responses/_middleware.ts | 0 .../app}/pages/responses/index.tsx | 0 .../app}/pages/rewrites/_middleware.ts | 0 .../app}/pages/rewrites/a.tsx | 0 .../app}/pages/rewrites/b.tsx | 0 .../middleware-typescript/app}/tsconfig.json | 2 +- .../middleware-typescript/test/index.test.ts | 33 +++++++++++++++++++ 18 files changed, 47 insertions(+), 19 deletions(-) delete mode 100644 test/integration/middleware-typescript/test/index.test.js rename test/{integration/middleware-typescript => production/middleware-typescript/app}/next.config.js (100%) rename test/{integration/middleware-typescript => production/middleware-typescript/app}/pages/interface/[id]/index.tsx (100%) rename test/{integration/middleware-typescript => production/middleware-typescript/app}/pages/interface/_middleware.ts (92%) rename test/{integration/middleware-typescript => production/middleware-typescript/app}/pages/interface/static.tsx (100%) rename test/{integration/middleware-typescript => production/middleware-typescript/app}/pages/redirects/_middleware.ts (100%) rename test/{integration/middleware-typescript => production/middleware-typescript/app}/pages/redirects/index.tsx (100%) rename test/{integration/middleware-typescript => production/middleware-typescript/app}/pages/redirects/new-home.tsx (100%) rename test/{integration/middleware-typescript => production/middleware-typescript/app}/pages/redirects/old-home.tsx (100%) rename test/{integration/middleware-typescript => production/middleware-typescript/app}/pages/responses/_middleware.ts (100%) rename test/{integration/middleware-typescript => production/middleware-typescript/app}/pages/responses/index.tsx (100%) rename test/{integration/middleware-typescript => production/middleware-typescript/app}/pages/rewrites/_middleware.ts (100%) rename test/{integration/middleware-typescript => production/middleware-typescript/app}/pages/rewrites/a.tsx (100%) rename test/{integration/middleware-typescript => production/middleware-typescript/app}/pages/rewrites/b.tsx (100%) rename test/{integration/middleware-typescript => production/middleware-typescript/app}/tsconfig.json (94%) create mode 100644 test/production/middleware-typescript/test/index.test.ts diff --git a/packages/next/server/web/spec-extension/response.ts b/packages/next/server/web/spec-extension/response.ts index 337c7499bcdd1..ff18456b3aa24 100644 --- a/packages/next/server/web/spec-extension/response.ts +++ b/packages/next/server/web/spec-extension/response.ts @@ -1,8 +1,8 @@ import type { I18NConfig } from '../../config-shared' -import type { CookieSerializeOptions } from 'next/dist/compiled/cookie' import { NextURL } from '../next-url' import { toNodeHeaders } from '../utils' import cookie from 'next/dist/compiled/cookie' +import { CookieSerializeOptions } from '../types' const INTERNALS = Symbol('internal response') const REDIRECTS = new Set([301, 302, 303, 307, 308]) diff --git a/packages/next/server/web/types.ts b/packages/next/server/web/types.ts index 0fec937caf855..5a6d48fde63b0 100644 --- a/packages/next/server/web/types.ts +++ b/packages/next/server/web/types.ts @@ -7,6 +7,17 @@ export interface NodeHeaders { [header: string]: string | string[] | undefined } +export interface CookieSerializeOptions { + domain?: string + encode?(val: string): string + expires?: Date + httpOnly?: boolean + maxAge?: number + path?: string + sameSite?: boolean | 'lax' | 'strict' | 'none' + secure?: boolean +} + export interface RequestData { geo?: { city?: string diff --git a/test/integration/middleware-typescript/test/index.test.js b/test/integration/middleware-typescript/test/index.test.js deleted file mode 100644 index 245826c000d3e..0000000000000 --- a/test/integration/middleware-typescript/test/index.test.js +++ /dev/null @@ -1,16 +0,0 @@ -/* eslint-env jest */ - -import { join } from 'path' -import { nextBuild } from 'next-test-utils' - -const appDir = join(__dirname, '..') -describe('TypeScript Middleware', () => { - describe('next build', () => { - it('should not fail to build middleware', async () => { - const { stderr, code } = await nextBuild(appDir, [], { stderr: true }) - expect(stderr).not.toMatch(/Failed to compile/) - expect(stderr).not.toMatch(/is not assignable to type/) - expect(code).toBe(0) - }) - }) -}) diff --git a/test/integration/middleware-typescript/next.config.js b/test/production/middleware-typescript/app/next.config.js similarity index 100% rename from test/integration/middleware-typescript/next.config.js rename to test/production/middleware-typescript/app/next.config.js diff --git a/test/integration/middleware-typescript/pages/interface/[id]/index.tsx b/test/production/middleware-typescript/app/pages/interface/[id]/index.tsx similarity index 100% rename from test/integration/middleware-typescript/pages/interface/[id]/index.tsx rename to test/production/middleware-typescript/app/pages/interface/[id]/index.tsx diff --git a/test/integration/middleware-typescript/pages/interface/_middleware.ts b/test/production/middleware-typescript/app/pages/interface/_middleware.ts similarity index 92% rename from test/integration/middleware-typescript/pages/interface/_middleware.ts rename to test/production/middleware-typescript/app/pages/interface/_middleware.ts index 8c8f527503c79..04685749e3bc8 100644 --- a/test/integration/middleware-typescript/pages/interface/_middleware.ts +++ b/test/production/middleware-typescript/app/pages/interface/_middleware.ts @@ -5,7 +5,7 @@ export const middleware: NextMiddleware = function (request) { console.log(request.ua?.isBot) console.log(request.ua?.ua) - return new Response(null, { + return new Response('hello from middleware', { headers: { 'req-url-basepath': request.nextUrl.basePath, 'req-url-pathname': request.nextUrl.pathname, diff --git a/test/integration/middleware-typescript/pages/interface/static.tsx b/test/production/middleware-typescript/app/pages/interface/static.tsx similarity index 100% rename from test/integration/middleware-typescript/pages/interface/static.tsx rename to test/production/middleware-typescript/app/pages/interface/static.tsx diff --git a/test/integration/middleware-typescript/pages/redirects/_middleware.ts b/test/production/middleware-typescript/app/pages/redirects/_middleware.ts similarity index 100% rename from test/integration/middleware-typescript/pages/redirects/_middleware.ts rename to test/production/middleware-typescript/app/pages/redirects/_middleware.ts diff --git a/test/integration/middleware-typescript/pages/redirects/index.tsx b/test/production/middleware-typescript/app/pages/redirects/index.tsx similarity index 100% rename from test/integration/middleware-typescript/pages/redirects/index.tsx rename to test/production/middleware-typescript/app/pages/redirects/index.tsx diff --git a/test/integration/middleware-typescript/pages/redirects/new-home.tsx b/test/production/middleware-typescript/app/pages/redirects/new-home.tsx similarity index 100% rename from test/integration/middleware-typescript/pages/redirects/new-home.tsx rename to test/production/middleware-typescript/app/pages/redirects/new-home.tsx diff --git a/test/integration/middleware-typescript/pages/redirects/old-home.tsx b/test/production/middleware-typescript/app/pages/redirects/old-home.tsx similarity index 100% rename from test/integration/middleware-typescript/pages/redirects/old-home.tsx rename to test/production/middleware-typescript/app/pages/redirects/old-home.tsx diff --git a/test/integration/middleware-typescript/pages/responses/_middleware.ts b/test/production/middleware-typescript/app/pages/responses/_middleware.ts similarity index 100% rename from test/integration/middleware-typescript/pages/responses/_middleware.ts rename to test/production/middleware-typescript/app/pages/responses/_middleware.ts diff --git a/test/integration/middleware-typescript/pages/responses/index.tsx b/test/production/middleware-typescript/app/pages/responses/index.tsx similarity index 100% rename from test/integration/middleware-typescript/pages/responses/index.tsx rename to test/production/middleware-typescript/app/pages/responses/index.tsx diff --git a/test/integration/middleware-typescript/pages/rewrites/_middleware.ts b/test/production/middleware-typescript/app/pages/rewrites/_middleware.ts similarity index 100% rename from test/integration/middleware-typescript/pages/rewrites/_middleware.ts rename to test/production/middleware-typescript/app/pages/rewrites/_middleware.ts diff --git a/test/integration/middleware-typescript/pages/rewrites/a.tsx b/test/production/middleware-typescript/app/pages/rewrites/a.tsx similarity index 100% rename from test/integration/middleware-typescript/pages/rewrites/a.tsx rename to test/production/middleware-typescript/app/pages/rewrites/a.tsx diff --git a/test/integration/middleware-typescript/pages/rewrites/b.tsx b/test/production/middleware-typescript/app/pages/rewrites/b.tsx similarity index 100% rename from test/integration/middleware-typescript/pages/rewrites/b.tsx rename to test/production/middleware-typescript/app/pages/rewrites/b.tsx diff --git a/test/integration/middleware-typescript/tsconfig.json b/test/production/middleware-typescript/app/tsconfig.json similarity index 94% rename from test/integration/middleware-typescript/tsconfig.json rename to test/production/middleware-typescript/app/tsconfig.json index f19745af2af6e..e327470b18341 100644 --- a/test/integration/middleware-typescript/tsconfig.json +++ b/test/production/middleware-typescript/app/tsconfig.json @@ -6,7 +6,7 @@ "target": "es5", "lib": ["dom", "dom.iterable", "esnext"], "allowJs": true, - "skipLibCheck": true, + "skipLibCheck": false, "strict": true, "forceConsistentCasingInFileNames": true, "noEmit": true, diff --git a/test/production/middleware-typescript/test/index.test.ts b/test/production/middleware-typescript/test/index.test.ts new file mode 100644 index 0000000000000..6a1ca2c66492d --- /dev/null +++ b/test/production/middleware-typescript/test/index.test.ts @@ -0,0 +1,33 @@ +/* eslint-env jest */ + +import { join } from 'path' +import { createNext, FileRef } from 'e2e-utils' +import { NextInstance } from 'test/lib/next-modes/base' +import { renderViaHTTP } from 'next-test-utils' + +const appDir = join(__dirname, '../app') + +describe('should set-up next', () => { + let next: NextInstance + + beforeAll(async () => { + next = await createNext({ + files: { + pages: new FileRef(join(appDir, 'pages')), + 'tsconfig.json': new FileRef(join(appDir, 'tsconfig.json')), + 'next.config.js': new FileRef(join(appDir, 'next.config.js')), + }, + dependencies: { + typescript: 'latest', + '@types/react': 'latest', + '@types/react-dom': 'latest', + }, + }) + }) + afterAll(() => next.destroy()) + + it('should have built and started', async () => { + const html = await renderViaHTTP(next.url, '/interface/static') + expect(html).toContain('hello from middleware') + }) +})