Skip to content

Commit 90f2465

Browse files
Netailhuozhi
andcommitted
fix typings
Co-authored-by: Jiachi Liu <[email protected]>
1 parent 904d1dd commit 90f2465

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
@@ -775,5 +775,6 @@
775775
"774": "Route %s used %s outside of a Server Component. This is not allowed.",
776776
"775": "Node.js instrumentation extensions should not be loaded in the Edge runtime.",
777777
"776": "`unstable_isUnrecognizedActionError` can only be used on the client.",
778-
"777": "Invariant: failed to find source route %s for prerender %s"
778+
"777": "Invariant: failed to find source route %s for prerender %s",
779+
"778": "No webpack compiler"
779780
}

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

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

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)