Skip to content

Commit f03bed9

Browse files
Netailhuozhi
andcommitted
fix typings
Co-authored-by: Jiachi Liu <[email protected]>
1 parent bffa9ab commit f03bed9

File tree

13 files changed

+34
-30
lines changed

13 files changed

+34
-30
lines changed

packages/next/errors.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -778,5 +778,6 @@
778778
"777": "Invariant: failed to find source route %s for prerender %s",
779779
"778": "`prerenderAndAbortInSequentialTasksWithStages` should not be called in edge runtime.",
780780
"779": "Route %s used \"searchParams\" inside \"use cache\". Accessing dynamic request data inside a cache scope is not supported. If you need some search params inside a cached function await \"searchParams\" outside of the cached function and pass only the required search params as arguments to the cached function. See more info here: https://nextjs.org/docs/messages/next-request-in-use-cache",
781-
"780": "Invariant: failed to find parent dynamic route for notFound route %s"
781+
"780": "Invariant: failed to find parent dynamic route for notFound route %s",
782+
"781": "No webpack compiler"
782783
}

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
@@ -1120,8 +1120,8 @@ export default async function getBaseWebpackConfig(
11201120
chunks: 'all' as const,
11211121
name: 'framework',
11221122
// Ensures the framework chunk is not created for App Router.
1123-
layer: isWebpackDefaultLayer,
1124-
test(module: any) {
1123+
layer: isWebpackDefaultLayer as (layer: string | null) => boolean,
1124+
test(module: webpack.Module) {
11251125
const resource = module.nameForCondition?.()
11261126
return resource
11271127
? topLevelFrameworkPaths.some((pkgPath) =>
@@ -1136,32 +1136,25 @@ export default async function getBaseWebpackConfig(
11361136
}
11371137

11381138
const libCacheGroup = {
1139-
test(module: {
1140-
type: string
1141-
size: Function
1142-
nameForCondition: Function
1143-
}): boolean {
1139+
test(module: webpack.Module): boolean {
11441140
return (
11451141
!module.type?.startsWith('css') &&
11461142
module.size() > 160000 &&
11471143
/node_modules[/\\]/.test(module.nameForCondition() || '')
11481144
)
11491145
},
1150-
name(module: {
1151-
layer: string | null | undefined
1152-
type: string
1153-
libIdent?: Function
1154-
updateHash: (hash: crypto.Hash) => void
1155-
}): string {
1146+
name(module: webpack.Module): string {
11561147
const hash = crypto.createHash('sha1')
11571148
if (isModuleCSS(module)) {
1149+
// @ts-expect-error - updateHash is missing in typings
11581150
module.updateHash(hash)
11591151
} else {
11601152
if (!module.libIdent) {
11611153
throw new Error(
11621154
`Encountered unknown module type: ${module.type}. Please open an issue.`
11631155
)
11641156
}
1157+
// @ts-ignore
11651158
hash.update(module.libIdent({ context: dir }))
11661159
}
11671160

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/bundles/webpack/packages/HotModuleReplacement.runtime.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
var $interceptModuleExecution$ = undefined;
1010
var $moduleCache$ = undefined;
11-
// eslint-disable-next-line no-unused-vars
1211
var $hmrModuleData$ = undefined;
1312
/** @type {() => Promise} */
1413
var $hmrDownloadManifest$ = undefined;

packages/next/src/bundles/webpack/packages/JavascriptHotModuleReplacement.runtime.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ module.exports = function () {
117117
for (var moduleId in currentUpdate) {
118118
if ($hasOwnProperty$(currentUpdate, moduleId)) {
119119
var newModuleFactory = currentUpdate[moduleId];
120-
/** @type {TODO} */
121120
var result = newModuleFactory
122121
? getAffectedModuleEffects(moduleId)
123122
: {

0 commit comments

Comments
 (0)