Skip to content

Commit

Permalink
the way towards webpack 5 typings (#29105)
Browse files Browse the repository at this point in the history
Co-authored-by: sokra <sokra@users.noreply.github.com>
  • Loading branch information
sokra and sokra committed Sep 21, 2021
1 parent 90a3b50 commit 4f212ee
Show file tree
Hide file tree
Showing 75 changed files with 209,076 additions and 238,602 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
packages/next/bundles/** -text
packages/next/compiled/** -text
75 changes: 60 additions & 15 deletions .github/workflows/build_test_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ jobs:
- uses: actions/cache@v2
id: cache-build
with:
path: ./*
path: |
./*
!./.git
key: ${{ github.sha }}

lint:
Expand All @@ -63,7 +65,9 @@ jobs:
- uses: actions/cache@v2
id: restore-build
with:
path: ./*
path: |
./*
!./.git
key: ${{ github.sha }}
- run: ./scripts/check-manifests.js
- run: yarn lint
Expand All @@ -75,29 +79,44 @@ jobs:
env:
NEXT_TELEMETRY_DISABLED: 1
steps:
- uses: actions/checkout@v2
if: ${{needs.build.outputs.docsChange != 'docs only change'}}

# https://github.com/actions/virtual-environments/issues/1187
- name: tune linux network
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
run: sudo ethtool -K eth0 tx off rx off

- uses: actions/cache@v2
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
id: restore-build
with:
path: ./*
path: |
./*
!./.git
key: ${{ github.sha }}

- uses: actions/download-artifact@v2
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
with:
name: next-swc-binaries
path: packages/next/build/swc/dist

# Only check linux build for now, mac builds can sometimes be different even with the same code
- run: |
mv ./packages/next/build/swc/dist/next-swc.linux-x64-gnu.node \
./packages/next/native/next-swc.linux-x64-gnu.node
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
- run: ./scripts/check-pre-compiled.sh
if: ${{needs.build.outputs.docsChange != 'docs only change'}}

- uses: EndBug/add-and-commit@v7
if: ${{ failure() }}
with:
add: 'packages/next/compiled packages/next/bundles --force'
message: '⚙ Update compiled files'

testUnit:
name: Test Unit
runs-on: ubuntu-latest
Expand All @@ -110,7 +129,9 @@ jobs:
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
id: restore-build
with:
path: ./*
path: |
./*
!./.git
key: ${{ github.sha }}

- run: node run-tests.js --type unit
Expand All @@ -134,7 +155,9 @@ jobs:
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
id: restore-build
with:
path: ./*
path: |
./*
!./.git
key: ${{ github.sha }}

- run: npm i -g playwright-chromium@1.14.1 && npx playwright install-deps
Expand Down Expand Up @@ -170,7 +193,9 @@ jobs:
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
id: restore-build
with:
path: ./*
path: |
./*
!./.git
key: ${{ github.sha }}

- run: npm i -g playwright-chromium@1.14.1 && npx playwright install-deps
Expand Down Expand Up @@ -210,7 +235,9 @@ jobs:
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
id: restore-build
with:
path: ./*
path: |
./*
!./.git
key: ${{ github.sha }}

- run: npm i -g playwright-chromium@1.14.1 && npx playwright install-deps
Expand All @@ -236,7 +263,9 @@ jobs:
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
id: restore-build
with:
path: ./*
path: |
./*
!./.git
key: ${{ github.sha }}

# TODO: remove after we fix watchpack watching too much
Expand All @@ -260,7 +289,9 @@ jobs:
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
id: restore-build
with:
path: ./*
path: |
./*
!./.git
key: ${{ github.sha }}

- run: bash ./scripts/test-pnp.sh
Expand All @@ -272,6 +303,8 @@ jobs:
needs:
[
lint,
check-examples,
test-native,
checkPrecompiled,
testIntegration,
testUnit,
Expand Down Expand Up @@ -300,7 +333,9 @@ jobs:
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
id: restore-build
with:
path: ./*
path: |
./*
!./.git
key: ${{ github.sha }}

- run: npm i -g playwright-chromium@1.14.1 && npx playwright install-deps
Expand All @@ -321,7 +356,9 @@ jobs:
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
id: restore-build
with:
path: ./*
path: |
./*
!./.git
key: ${{ github.sha }}
- run: npx playwright install-deps && npx playwright install firefox
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
Expand All @@ -348,7 +385,9 @@ jobs:
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
id: restore-build
with:
path: ./*
path: |
./*
!./.git
key: ${{ github.sha }}

# TODO: use macos runner so that we can use playwright to test against
Expand Down Expand Up @@ -380,7 +419,9 @@ jobs:
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
id: restore-build
with:
path: ./*
path: |
./*
!./.git
key: ${{ github.sha }}

- run: '[[ -z "$BROWSERSTACK_ACCESS_KEY" ]] && echo "Skipping for PR" || npm i -g browserstack-local@1.4.0'
Expand All @@ -404,7 +445,9 @@ jobs:
- uses: actions/cache@v2
id: restore-build
with:
path: ./*
path: |
./*
!./.git
key: ${{ github.sha }}
- uses: actions/download-artifact@v2
with:
Expand All @@ -422,7 +465,9 @@ jobs:
- uses: actions/cache@v2
id: restore-build
with:
path: ./*
path: |
./*
!./.git
key: ${{ github.sha }}
- run: ./scripts/release-stats.sh
- uses: ./.github/actions/next-stats-action
Expand Down
21 changes: 20 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "nextjs-project",
"version": "0.0.0",
"private": true,
"workspaces": [
"packages/*"
Expand Down Expand Up @@ -61,14 +62,32 @@
"@typescript-eslint/eslint-plugin": "4.29.1",
"@typescript-eslint/parser": "4.29.1",
"@vercel/fetch": "6.1.1",
"@webassemblyjs/ast": "1.11.1",
"@webassemblyjs/floating-point-hex-parser": "1.11.1",
"@webassemblyjs/helper-api-error": "1.11.1",
"@webassemblyjs/helper-buffer": "1.11.1",
"@webassemblyjs/helper-code-frame": "npm:empty-npm-package@1.0.0",
"@webassemblyjs/helper-module-context": "npm:empty-npm-package@1.0.0",
"@webassemblyjs/helper-numbers": "1.11.1",
"@webassemblyjs/helper-wasm-bytecode": "1.11.1",
"@webassemblyjs/helper-wasm-section": "1.11.1",
"@webassemblyjs/ieee754": "1.11.1",
"@webassemblyjs/leb128": "1.11.1",
"@webassemblyjs/utf8": "1.11.1",
"@webassemblyjs/wasm-edit": "1.11.1",
"@webassemblyjs/wasm-gen": "1.11.1",
"@webassemblyjs/wasm-opt": "1.11.1",
"@webassemblyjs/wasm-parser": "1.11.1",
"@webassemblyjs/wast-parser": "npm:empty-npm-package@1.0.0",
"@webassemblyjs/wast-printer": "1.11.1",
"@zeit/next-css": "1.0.2-canary.2",
"@zeit/next-sass": "1.0.2-canary.2",
"@zeit/next-typescript": "1.1.2-canary.0",
"abort-controller": "3.0.0",
"alex": "9.1.0",
"amphtml-validator": "1.0.33",
"async-sema": "3.0.1",
"browserslist": "^4.14.7",
"browserslist": "4.16.6",
"cheerio": "0.22.0",
"clone": "2.1.2",
"cookie": "0.4.1",
Expand Down
21 changes: 5 additions & 16 deletions packages/next/build/entries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { ClientPagesLoaderOptions } from './webpack/loaders/next-client-pages-lo
import { ServerlessLoaderQuery } from './webpack/loaders/next-serverless-loader'
import { LoadedEnvFiles } from '@next/env'
import { NextConfigComplete } from '../server/config-shared'
import type webpack5 from 'webpack5'

type PagesMapping = {
[page: string]: string
Expand Down Expand Up @@ -62,21 +63,9 @@ export function createPagesMapping(
return pages
}

export type WebpackEntrypoints = {
[bundle: string]:
| string
| string[]
| {
import: string | string[]
dependOn?: string | string[]
publicPath?: string
runtime?: string
}
}

type Entrypoints = {
client: WebpackEntrypoints
server: WebpackEntrypoints
client: webpack5.EntryObject
server: webpack5.EntryObject
}

export function createEntrypoints(
Expand All @@ -87,8 +76,8 @@ export function createEntrypoints(
config: NextConfigComplete,
loadedEnvFiles: LoadedEnvFiles
): Entrypoints {
const client: WebpackEntrypoints = {}
const server: WebpackEntrypoints = {}
const client: webpack5.EntryObject = {}
const server: webpack5.EntryObject = {}

const hasRuntimeConfig =
Object.keys(config.publicRuntimeConfig).length > 0 ||
Expand Down
27 changes: 15 additions & 12 deletions packages/next/build/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -840,22 +840,25 @@ export async function isPageStatic(
try {
require('../shared/lib/runtime-config').setConfig(runtimeEnvConfig)
setHttpAgentOptions(httpAgentOptions)
const components = await loadComponents(distDir, page, serverless)
const mod = components.ComponentMod
const Comp = mod.default || mod
const mod = await loadComponents(distDir, page, serverless)
const Comp = mod.Component

if (!Comp || !isValidElementType(Comp) || typeof Comp === 'string') {
throw new Error('INVALID_DEFAULT_EXPORT')
}

const hasGetInitialProps = !!(Comp as any).getInitialProps
const hasStaticProps = !!(await mod.getStaticProps)
const hasStaticPaths = !!(await mod.getStaticPaths)
const hasServerProps = !!(await mod.getServerSideProps)
const hasLegacyServerProps = !!(await mod.unstable_getServerProps)
const hasLegacyStaticProps = !!(await mod.unstable_getStaticProps)
const hasLegacyStaticPaths = !!(await mod.unstable_getStaticPaths)
const hasLegacyStaticParams = !!(await mod.unstable_getStaticParams)
const hasStaticProps = !!mod.getStaticProps
const hasStaticPaths = !!mod.getStaticPaths
const hasServerProps = !!mod.getServerSideProps
const hasLegacyServerProps = !!(await mod.ComponentMod
.unstable_getServerProps)
const hasLegacyStaticProps = !!(await mod.ComponentMod
.unstable_getStaticProps)
const hasLegacyStaticPaths = !!(await mod.ComponentMod
.unstable_getStaticPaths)
const hasLegacyStaticParams = !!(await mod.ComponentMod
.unstable_getStaticParams)

if (hasLegacyStaticParams) {
throw new Error(
Expand Down Expand Up @@ -921,14 +924,14 @@ export async function isPageStatic(
encodedPaths: encodedPrerenderRoutes,
} = await buildStaticPaths(
page,
mod.getStaticPaths,
mod.getStaticPaths!,
locales,
defaultLocale
))
}

const isNextImageImported = (global as any).__NEXT_IMAGE_IMPORTED
const config: PageConfig = mod.config || {}
const config: PageConfig = mod.pageConfig
return {
isStatic: !hasStaticProps && !hasGetInitialProps && !hasServerProps,
isHybridAmp: config.amp === 'hybrid',
Expand Down

0 comments on commit 4f212ee

Please sign in to comment.