Skip to content

Commit ddb54d3

Browse files
Netailhuozhi
andcommitted
fix typings
Co-authored-by: Jiachi Liu <inbox@huozhi.im>
1 parent 6989e72 commit ddb54d3

File tree

9 files changed

+34
-26
lines changed

9 files changed

+34
-26
lines changed

packages/next/errors.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -850,5 +850,6 @@
850850
"849": "Route %s with \\`dynamic = \"error\"\\` couldn't be rendered statically because it used \\`cookies()\\`. See more info here: https://nextjs.org/docs/app/building-your-application/rendering/static-and-dynamic#dynamic-rendering",
851851
"850": "metadataBase is not a valid URL: %s",
852852
"851": "Pass either `webpack` or `turbopack`, not both.",
853-
"852": "Only custom servers can pass `webpack`, `turbo`, or `turbopack`."
853+
"852": "Only custom servers can pass `webpack`, `turbo`, or `turbopack`.",
854+
"853": "No webpack compiler"
854855
}

packages/next/src/build/compiler.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ export function runCompiler(
5454
return new Promise((resolve, reject) => {
5555
const compiler = getWebpackBundler()(config)
5656

57+
if (!compiler) {
58+
throw new Error('No webpack compiler')
59+
}
60+
5761
// Ensure we use the previous inputFileSystem
5862
if (inputFileSystem) {
5963
compiler.inputFileSystem = inputFileSystem

packages/next/src/build/webpack-config.ts

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,8 +1111,8 @@ export default async function getBaseWebpackConfig(
11111111
chunks: 'all' as const,
11121112
name: 'framework',
11131113
// Ensures the framework chunk is not created for App Router.
1114-
layer: isWebpackDefaultLayer,
1115-
test(module: any) {
1114+
layer: isWebpackDefaultLayer as (layer: string | null) => boolean,
1115+
test(module: webpack.Module) {
11161116
const resource = module.nameForCondition?.()
11171117
return resource
11181118
? topLevelFrameworkPaths.some((pkgPath) =>
@@ -1127,32 +1127,25 @@ export default async function getBaseWebpackConfig(
11271127
}
11281128

11291129
const libCacheGroup = {
1130-
test(module: {
1131-
type: string
1132-
size: Function
1133-
nameForCondition: Function
1134-
}): boolean {
1130+
test(module: webpack.Module): boolean {
11351131
return (
11361132
!module.type?.startsWith('css') &&
11371133
module.size() > 160000 &&
11381134
/node_modules[/\\]/.test(module.nameForCondition() || '')
11391135
)
11401136
},
1141-
name(module: {
1142-
layer: string | null | undefined
1143-
type: string
1144-
libIdent?: Function
1145-
updateHash: (hash: crypto.Hash) => void
1146-
}): string {
1137+
name(module: webpack.Module): string {
11471138
const hash = crypto.createHash('sha1')
11481139
if (isModuleCSS(module)) {
1140+
// @ts-expect-error - updateHash is missing in typings
11491141
module.updateHash(hash)
11501142
} else {
11511143
if (!module.libIdent) {
11521144
throw new Error(
11531145
`Encountered unknown module type: ${module.type}. Please open an issue.`
11541146
)
11551147
}
1148+
// @ts-ignore
11561149
hash.update(module.libIdent({ context: dir }))
11571150
}
11581151

packages/next/src/build/webpack/loaders/next-flight-loader/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,9 @@ ${JSON.stringify(ref)},
166166

167167
return this.callback(null, esmSource, {
168168
version: 3,
169+
file: originalSourceURL,
169170
sources: [originalSourceURL],
171+
names: [],
170172
// minimal, parseable mappings
171173
mappings: 'AAAA',
172174
sourcesContent: [esmSource],
@@ -200,6 +202,8 @@ module.exports = createProxy(${stringifiedResourceKey})
200202
return this.callback(null, cjsSource, {
201203
version: 3,
202204
sources: [originalSourceURL],
205+
names: [],
206+
file: originalSourceURL,
203207
// minimal, parseable mappings
204208
mappings: 'AAAA',
205209
sourcesContent: [cjsSource],

packages/next/src/build/webpack/plugins/css-minimizer-plugin.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export class CssMinimizerPlugin {
4848
.process(input, postcssOptions)
4949
.then((res) => {
5050
if (res.map) {
51+
// @ts-expect-error of type 'RawSourceMap' version is not compatible, it's a small typing bug
5152
return new sources.SourceMapSource(res.css, file, res.map.toJSON())
5253
} else {
5354
return new sources.RawSource(res.css)

packages/next/src/build/webpack/plugins/eval-source-map-dev-tool-plugin.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,7 @@ export interface EvalSourceMapDevToolPluginOptions
4444
// https://github.com/webpack/webpack/blob/e237b580e2bda705c5ab39973f786f7c5a7026bc/lib/EvalSourceMapDevToolPlugin.js#L37
4545
export default class EvalSourceMapDevToolPlugin {
4646
sourceMapComment: string
47-
moduleFilenameTemplate: NonNullable<
48-
EvalSourceMapDevToolPluginOptions['moduleFilenameTemplate']
49-
>
47+
moduleFilenameTemplate: string | ((context?: any) => string)
5048
namespace: NonNullable<EvalSourceMapDevToolPluginOptions['namespace']>
5149
options: EvalSourceMapDevToolPluginOptions
5250
shouldIgnorePath: (modulePath: string) => boolean
@@ -67,9 +65,10 @@ export default class EvalSourceMapDevToolPlugin {
6765
options.append && typeof options.append !== 'function'
6866
? options.append
6967
: '//# sourceURL=[module]\n//# sourceMappingURL=[url]'
70-
this.moduleFilenameTemplate =
71-
options.moduleFilenameTemplate ||
72-
'webpack://[namespace]/[resource-path]?[hash]'
68+
this.moduleFilenameTemplate = (options.moduleFilenameTemplate ||
69+
'webpack://[namespace]/[resource-path]?[hash]') as
70+
| string
71+
| ((context?: any) => string)
7372
this.namespace = options.namespace || ''
7473
this.options = options
7574

packages/next/src/build/webpack/plugins/minify-webpack-plugin/src/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ export class MinifyPlugin {
191191
try {
192192
minifiedOutput = await getWorker().minify({
193193
input,
194-
inputSourceMap,
194+
inputSourceMap: inputSourceMap as Object,
195195
})
196196
} catch (error) {
197197
compilation.errors.push(buildError(error, name))
@@ -205,7 +205,8 @@ export class MinifyPlugin {
205205
name,
206206
minifiedOutput.map,
207207
input,
208-
inputSourceMap,
208+
// SourceMapSource excepts undefined, not null
209+
inputSourceMap || undefined,
209210
true
210211
)
211212
: new RawSource(minifiedOutput.code)

packages/next/src/build/webpack/plugins/wellknown-errors-plugin/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { webpack } from 'next/dist/compiled/webpack/webpack'
1+
import type { webpack, WebpackError } from 'next/dist/compiled/webpack/webpack'
22

33
import { getModuleBuildError } from './webpackModuleError'
44

@@ -12,7 +12,7 @@ export class WellKnownErrorsPlugin {
1212
compilation.warnings.map(async (warn, i) => {
1313
if (
1414
warn.name === 'ModuleDependencyWarning' &&
15-
warn.module?.context?.includes('node_modules')
15+
(warn as WebpackError).module?.context?.includes('node_modules')
1616
) {
1717
compilation.warnings.splice(i, 1)
1818
}

packages/next/src/server/dev/hot-reloader-webpack.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,8 @@ function findEntryModule(
185185

186186
function erroredPages(compilation: webpack.Compilation) {
187187
const failedPages: { [page: string]: WebpackError[] } = {}
188-
for (const error of compilation.errors) {
188+
for (const err of compilation.errors) {
189+
const error = err as WebpackError
189190
if (!error.module) {
190191
continue
191192
}
@@ -207,7 +208,7 @@ function erroredPages(compilation: webpack.Compilation) {
207208
failedPages[enhancedName] = []
208209
}
209210

210-
failedPages[enhancedName].push(error)
211+
failedPages[enhancedName].push(error as WebpackError)
211212
}
212213

213214
return failedPages
@@ -795,6 +796,10 @@ export default class HotReloaderWebpack implements NextJsHotReloaderInterface {
795796

796797
const fallbackCompiler = getWebpackBundler()(fallbackConfig)
797798

799+
if (!fallbackCompiler) {
800+
throw new Error('No webpack compiler')
801+
}
802+
798803
this.fallbackWatcher = await new Promise((resolve) => {
799804
let bootedFallbackCompiler = false
800805
fallbackCompiler.watch(

0 commit comments

Comments
 (0)