Skip to content

Commit 4f212ee

Browse files
authored
the way towards webpack 5 typings (vercel#29105)
Co-authored-by: sokra <[email protected]>
1 parent 90a3b50 commit 4f212ee

File tree

75 files changed

+209076
-238602
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+209076
-238602
lines changed

.gitattributes

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
packages/next/bundles/** -text
2+
packages/next/compiled/** -text

.github/workflows/build_test_deploy.yml

+60-15
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ jobs:
5353
- uses: actions/cache@v2
5454
id: cache-build
5555
with:
56-
path: ./*
56+
path: |
57+
./*
58+
!./.git
5759
key: ${{ github.sha }}
5860

5961
lint:
@@ -63,7 +65,9 @@ jobs:
6365
- uses: actions/cache@v2
6466
id: restore-build
6567
with:
66-
path: ./*
68+
path: |
69+
./*
70+
!./.git
6771
key: ${{ github.sha }}
6872
- run: ./scripts/check-manifests.js
6973
- run: yarn lint
@@ -75,29 +79,44 @@ jobs:
7579
env:
7680
NEXT_TELEMETRY_DISABLED: 1
7781
steps:
82+
- uses: actions/checkout@v2
83+
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
84+
7885
# https://github.com/actions/virtual-environments/issues/1187
7986
- name: tune linux network
87+
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
8088
run: sudo ethtool -K eth0 tx off rx off
8189

8290
- uses: actions/cache@v2
8391
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
8492
id: restore-build
8593
with:
86-
path: ./*
94+
path: |
95+
./*
96+
!./.git
8797
key: ${{ github.sha }}
98+
8899
- uses: actions/download-artifact@v2
89100
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
90101
with:
91102
name: next-swc-binaries
92103
path: packages/next/build/swc/dist
104+
93105
# Only check linux build for now, mac builds can sometimes be different even with the same code
94106
- run: |
95107
mv ./packages/next/build/swc/dist/next-swc.linux-x64-gnu.node \
96108
./packages/next/native/next-swc.linux-x64-gnu.node
97109
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
110+
98111
- run: ./scripts/check-pre-compiled.sh
99112
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
100113

114+
- uses: EndBug/add-and-commit@v7
115+
if: ${{ failure() }}
116+
with:
117+
add: 'packages/next/compiled packages/next/bundles --force'
118+
message: '⚙ Update compiled files'
119+
101120
testUnit:
102121
name: Test Unit
103122
runs-on: ubuntu-latest
@@ -110,7 +129,9 @@ jobs:
110129
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
111130
id: restore-build
112131
with:
113-
path: ./*
132+
path: |
133+
./*
134+
!./.git
114135
key: ${{ github.sha }}
115136

116137
- run: node run-tests.js --type unit
@@ -134,7 +155,9 @@ jobs:
134155
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
135156
id: restore-build
136157
with:
137-
path: ./*
158+
path: |
159+
./*
160+
!./.git
138161
key: ${{ github.sha }}
139162

140163
- run: npm i -g [email protected] && npx playwright install-deps
@@ -170,7 +193,9 @@ jobs:
170193
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
171194
id: restore-build
172195
with:
173-
path: ./*
196+
path: |
197+
./*
198+
!./.git
174199
key: ${{ github.sha }}
175200

176201
- run: npm i -g [email protected] && npx playwright install-deps
@@ -210,7 +235,9 @@ jobs:
210235
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
211236
id: restore-build
212237
with:
213-
path: ./*
238+
path: |
239+
./*
240+
!./.git
214241
key: ${{ github.sha }}
215242

216243
- run: npm i -g [email protected] && npx playwright install-deps
@@ -236,7 +263,9 @@ jobs:
236263
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
237264
id: restore-build
238265
with:
239-
path: ./*
266+
path: |
267+
./*
268+
!./.git
240269
key: ${{ github.sha }}
241270

242271
# TODO: remove after we fix watchpack watching too much
@@ -260,7 +289,9 @@ jobs:
260289
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
261290
id: restore-build
262291
with:
263-
path: ./*
292+
path: |
293+
./*
294+
!./.git
264295
key: ${{ github.sha }}
265296

266297
- run: bash ./scripts/test-pnp.sh
@@ -272,6 +303,8 @@ jobs:
272303
needs:
273304
[
274305
lint,
306+
check-examples,
307+
test-native,
275308
checkPrecompiled,
276309
testIntegration,
277310
testUnit,
@@ -300,7 +333,9 @@ jobs:
300333
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
301334
id: restore-build
302335
with:
303-
path: ./*
336+
path: |
337+
./*
338+
!./.git
304339
key: ${{ github.sha }}
305340

306341
- run: npm i -g [email protected] && npx playwright install-deps
@@ -321,7 +356,9 @@ jobs:
321356
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
322357
id: restore-build
323358
with:
324-
path: ./*
359+
path: |
360+
./*
361+
!./.git
325362
key: ${{ github.sha }}
326363
- run: npx playwright install-deps && npx playwright install firefox
327364
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
@@ -348,7 +385,9 @@ jobs:
348385
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
349386
id: restore-build
350387
with:
351-
path: ./*
388+
path: |
389+
./*
390+
!./.git
352391
key: ${{ github.sha }}
353392

354393
# TODO: use macos runner so that we can use playwright to test against
@@ -380,7 +419,9 @@ jobs:
380419
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
381420
id: restore-build
382421
with:
383-
path: ./*
422+
path: |
423+
./*
424+
!./.git
384425
key: ${{ github.sha }}
385426

386427
- run: '[[ -z "$BROWSERSTACK_ACCESS_KEY" ]] && echo "Skipping for PR" || npm i -g [email protected]'
@@ -404,7 +445,9 @@ jobs:
404445
- uses: actions/cache@v2
405446
id: restore-build
406447
with:
407-
path: ./*
448+
path: |
449+
./*
450+
!./.git
408451
key: ${{ github.sha }}
409452
- uses: actions/download-artifact@v2
410453
with:
@@ -422,7 +465,9 @@ jobs:
422465
- uses: actions/cache@v2
423466
id: restore-build
424467
with:
425-
path: ./*
468+
path: |
469+
./*
470+
!./.git
426471
key: ${{ github.sha }}
427472
- run: ./scripts/release-stats.sh
428473
- uses: ./.github/actions/next-stats-action

package.json

+20-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"name": "nextjs-project",
3+
"version": "0.0.0",
34
"private": true,
45
"workspaces": [
56
"packages/*"
@@ -61,14 +62,32 @@
6162
"@typescript-eslint/eslint-plugin": "4.29.1",
6263
"@typescript-eslint/parser": "4.29.1",
6364
"@vercel/fetch": "6.1.1",
65+
"@webassemblyjs/ast": "1.11.1",
66+
"@webassemblyjs/floating-point-hex-parser": "1.11.1",
67+
"@webassemblyjs/helper-api-error": "1.11.1",
68+
"@webassemblyjs/helper-buffer": "1.11.1",
69+
"@webassemblyjs/helper-code-frame": "npm:[email protected]",
70+
"@webassemblyjs/helper-module-context": "npm:[email protected]",
71+
"@webassemblyjs/helper-numbers": "1.11.1",
72+
"@webassemblyjs/helper-wasm-bytecode": "1.11.1",
73+
"@webassemblyjs/helper-wasm-section": "1.11.1",
74+
"@webassemblyjs/ieee754": "1.11.1",
75+
"@webassemblyjs/leb128": "1.11.1",
76+
"@webassemblyjs/utf8": "1.11.1",
77+
"@webassemblyjs/wasm-edit": "1.11.1",
78+
"@webassemblyjs/wasm-gen": "1.11.1",
79+
"@webassemblyjs/wasm-opt": "1.11.1",
80+
"@webassemblyjs/wasm-parser": "1.11.1",
81+
"@webassemblyjs/wast-parser": "npm:[email protected]",
82+
"@webassemblyjs/wast-printer": "1.11.1",
6483
"@zeit/next-css": "1.0.2-canary.2",
6584
"@zeit/next-sass": "1.0.2-canary.2",
6685
"@zeit/next-typescript": "1.1.2-canary.0",
6786
"abort-controller": "3.0.0",
6887
"alex": "9.1.0",
6988
"amphtml-validator": "1.0.33",
7089
"async-sema": "3.0.1",
71-
"browserslist": "^4.14.7",
90+
"browserslist": "4.16.6",
7291
"cheerio": "0.22.0",
7392
"clone": "2.1.2",
7493
"cookie": "0.4.1",

packages/next/build/entries.ts

+5-16
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { ClientPagesLoaderOptions } from './webpack/loaders/next-client-pages-lo
1010
import { ServerlessLoaderQuery } from './webpack/loaders/next-serverless-loader'
1111
import { LoadedEnvFiles } from '@next/env'
1212
import { NextConfigComplete } from '../server/config-shared'
13+
import type webpack5 from 'webpack5'
1314

1415
type PagesMapping = {
1516
[page: string]: string
@@ -62,21 +63,9 @@ export function createPagesMapping(
6263
return pages
6364
}
6465

65-
export type WebpackEntrypoints = {
66-
[bundle: string]:
67-
| string
68-
| string[]
69-
| {
70-
import: string | string[]
71-
dependOn?: string | string[]
72-
publicPath?: string
73-
runtime?: string
74-
}
75-
}
76-
7766
type Entrypoints = {
78-
client: WebpackEntrypoints
79-
server: WebpackEntrypoints
67+
client: webpack5.EntryObject
68+
server: webpack5.EntryObject
8069
}
8170

8271
export function createEntrypoints(
@@ -87,8 +76,8 @@ export function createEntrypoints(
8776
config: NextConfigComplete,
8877
loadedEnvFiles: LoadedEnvFiles
8978
): Entrypoints {
90-
const client: WebpackEntrypoints = {}
91-
const server: WebpackEntrypoints = {}
79+
const client: webpack5.EntryObject = {}
80+
const server: webpack5.EntryObject = {}
9281

9382
const hasRuntimeConfig =
9483
Object.keys(config.publicRuntimeConfig).length > 0 ||

packages/next/build/utils.ts

+15-12
Original file line numberDiff line numberDiff line change
@@ -840,22 +840,25 @@ export async function isPageStatic(
840840
try {
841841
require('../shared/lib/runtime-config').setConfig(runtimeEnvConfig)
842842
setHttpAgentOptions(httpAgentOptions)
843-
const components = await loadComponents(distDir, page, serverless)
844-
const mod = components.ComponentMod
845-
const Comp = mod.default || mod
843+
const mod = await loadComponents(distDir, page, serverless)
844+
const Comp = mod.Component
846845

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

851850
const hasGetInitialProps = !!(Comp as any).getInitialProps
852-
const hasStaticProps = !!(await mod.getStaticProps)
853-
const hasStaticPaths = !!(await mod.getStaticPaths)
854-
const hasServerProps = !!(await mod.getServerSideProps)
855-
const hasLegacyServerProps = !!(await mod.unstable_getServerProps)
856-
const hasLegacyStaticProps = !!(await mod.unstable_getStaticProps)
857-
const hasLegacyStaticPaths = !!(await mod.unstable_getStaticPaths)
858-
const hasLegacyStaticParams = !!(await mod.unstable_getStaticParams)
851+
const hasStaticProps = !!mod.getStaticProps
852+
const hasStaticPaths = !!mod.getStaticPaths
853+
const hasServerProps = !!mod.getServerSideProps
854+
const hasLegacyServerProps = !!(await mod.ComponentMod
855+
.unstable_getServerProps)
856+
const hasLegacyStaticProps = !!(await mod.ComponentMod
857+
.unstable_getStaticProps)
858+
const hasLegacyStaticPaths = !!(await mod.ComponentMod
859+
.unstable_getStaticPaths)
860+
const hasLegacyStaticParams = !!(await mod.ComponentMod
861+
.unstable_getStaticParams)
859862

860863
if (hasLegacyStaticParams) {
861864
throw new Error(
@@ -921,14 +924,14 @@ export async function isPageStatic(
921924
encodedPaths: encodedPrerenderRoutes,
922925
} = await buildStaticPaths(
923926
page,
924-
mod.getStaticPaths,
927+
mod.getStaticPaths!,
925928
locales,
926929
defaultLocale
927930
))
928931
}
929932

930933
const isNextImageImported = (global as any).__NEXT_IMAGE_IMPORTED
931-
const config: PageConfig = mod.config || {}
934+
const config: PageConfig = mod.pageConfig
932935
return {
933936
isStatic: !hasStaticProps && !hasGetInitialProps && !hasServerProps,
934937
isHybridAmp: config.amp === 'hybrid',

0 commit comments

Comments
 (0)