Unverified Commit 7a61fb7f authored by Aaron Reisman's avatar Aaron Reisman Committed by GitHub

Cleanup Build Output Types (#11076)

parent bddd1ce5
...@@ -13,8 +13,8 @@ export function startedDevelopmentServer(appUrl: string) { ...@@ -13,8 +13,8 @@ export function startedDevelopmentServer(appUrl: string) {
consoleStore.setState({ appUrl }) consoleStore.setState({ appUrl })
} }
let previousClient: any = null let previousClient: import('webpack').Compiler | null = null
let previousServer: any = null let previousServer: import('webpack').Compiler | null = null
type CompilerDiagnosticsWithFile = { type CompilerDiagnosticsWithFile = {
errors: { file: string | undefined; message: string }[] | null errors: { file: string | undefined; message: string }[] | null
...@@ -203,7 +203,7 @@ export function ampValidation( ...@@ -203,7 +203,7 @@ export function ampValidation(
.filter(k => k !== page) .filter(k => k !== page)
.sort() .sort()
// eslint-disable-next-line no-sequences // eslint-disable-next-line no-sequences
.reduce((a, c) => ((a[c] = amp[c]), a), {} as any), .reduce((a, c) => ((a[c] = amp[c]), a), {} as AmpPageStatus),
}) })
return return
} }
...@@ -213,13 +213,13 @@ export function ampValidation( ...@@ -213,13 +213,13 @@ export function ampValidation(
amp: Object.keys(newAmp) amp: Object.keys(newAmp)
.sort() .sort()
// eslint-disable-next-line no-sequences // eslint-disable-next-line no-sequences
.reduce((a, c) => ((a[c] = newAmp[c]), a), {} as any), .reduce((a, c) => ((a[c] = newAmp[c]), a), {} as AmpPageStatus),
}) })
} }
export function watchCompilers( export function watchCompilers(
client: any, client: import('webpack').Compiler,
server: any, server: import('webpack').Compiler,
enableTypeCheckingOnClient: boolean, enableTypeCheckingOnClient: boolean,
onTypeChecked: (diagnostics: CompilerDiagnostics) => void onTypeChecked: (diagnostics: CompilerDiagnostics) => void
) { ) {
...@@ -285,75 +285,78 @@ export function watchCompilers( ...@@ -285,75 +285,78 @@ export function watchCompilers(
) )
} }
compiler.hooks.done.tap(`NextJsDone-${key}`, (stats: any) => { compiler.hooks.done.tap(
buildStore.setState({ amp: {} }) `NextJsDone-${key}`,
(stats: import('webpack').Stats) => {
buildStore.setState({ amp: {} })
const { errors, warnings } = formatWebpackMessages( const { errors, warnings } = formatWebpackMessages(
stats.toJson({ all: false, warnings: true, errors: true }) stats.toJson({ all: false, warnings: true, errors: true })
) )
const hasErrors = !!errors?.length
const hasWarnings = !!warnings?.length
onEvent({
loading: false,
typeChecking: hasTypeChecking,
errors: hasErrors ? errors : null,
warnings: hasWarnings ? warnings : null,
})
const typePromise = tsMessagesPromise
if (!hasErrors && typePromise) { const hasErrors = !!errors?.length
typePromise.then(typeMessages => { const hasWarnings = !!warnings?.length
if (typePromise !== tsMessagesPromise) {
// a new compilation started so we don't care about this
return
}
const reportFiles = stats.compilation.modules onEvent({
.map((m: any) => (m.resource || '').replace(/\\/g, '/')) loading: false,
.filter(Boolean) typeChecking: hasTypeChecking,
errors: hasErrors ? errors : null,
let filteredErrors = typeMessages.errors warnings: hasWarnings ? warnings : null,
? typeMessages.errors })
.filter(({ file }) => file && reportFiles.includes(file))
.map(({ message }) => message)
: null
if (filteredErrors && filteredErrors.length < 1) {
filteredErrors = null
}
let filteredWarnings = typeMessages.warnings
? typeMessages.warnings
.filter(({ file }) => file && reportFiles.includes(file))
.map(({ message }) => message)
: null
if (filteredWarnings && filteredWarnings.length < 1) {
filteredWarnings = null
}
stats.compilation.errors.push(...(filteredErrors || [])) const typePromise = tsMessagesPromise
stats.compilation.warnings.push(...(filteredWarnings || []))
onTypeChecked({ if (!hasErrors && typePromise) {
errors: stats.compilation.errors.length typePromise.then(typeMessages => {
? stats.compilation.errors if (typePromise !== tsMessagesPromise) {
: null, // a new compilation started so we don't care about this
warnings: stats.compilation.warnings.length return
? stats.compilation.warnings }
: null,
}) const reportFiles = stats.compilation.modules
.map(m => (m.resource || '').replace(/\\/g, '/'))
.filter(Boolean)
let filteredErrors = typeMessages.errors
? typeMessages.errors
.filter(({ file }) => file && reportFiles.includes(file))
.map(({ message }) => message)
: null
if (filteredErrors && filteredErrors.length < 1) {
filteredErrors = null
}
let filteredWarnings = typeMessages.warnings
? typeMessages.warnings
.filter(({ file }) => file && reportFiles.includes(file))
.map(({ message }) => message)
: null
if (filteredWarnings && filteredWarnings.length < 1) {
filteredWarnings = null
}
stats.compilation.errors.push(...(filteredErrors || []))
stats.compilation.warnings.push(...(filteredWarnings || []))
onTypeChecked({
errors: stats.compilation.errors.length
? stats.compilation.errors
: null,
warnings: stats.compilation.warnings.length
? stats.compilation.warnings
: null,
})
onEvent({ onEvent({
loading: false, loading: false,
typeChecking: false, typeChecking: false,
errors: filteredErrors, errors: filteredErrors,
warnings: hasWarnings warnings: hasWarnings
? [...warnings, ...(filteredWarnings || [])] ? [...warnings, ...(filteredWarnings || [])]
: filteredWarnings, : filteredWarnings,
})
}) })
}) }
} }
}) )
} }
tapCompiler('client', client, enableTypeCheckingOnClient, status => tapCompiler('client', client, enableTypeCheckingOnClient, status =>
......
...@@ -17,12 +17,14 @@ export type OutputState = ...@@ -17,12 +17,14 @@ export type OutputState =
export const store = createStore<OutputState>({ appUrl: null, bootstrap: true }) export const store = createStore<OutputState>({ appUrl: null, bootstrap: true })
let lastStore: OutputState = {} as any let lastStore: OutputState = { appUrl: null, bootstrap: true }
function hasStoreChanged(nextStore: OutputState) { function hasStoreChanged(nextStore: OutputState) {
if ( if (
[ ([
...new Set([...Object.keys(lastStore), ...Object.keys(nextStore)]), ...new Set([...Object.keys(lastStore), ...Object.keys(nextStore)]),
].every(key => Object.is((lastStore as any)[key], (nextStore as any)[key])) ] as Array<keyof OutputState>).every(key =>
Object.is(lastStore[key], nextStore[key])
)
) { ) {
return false return false
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment