Skip to content

Commit

Permalink
Cleanup Build Output Types (vercel#11076)
Browse files Browse the repository at this point in the history
  • Loading branch information
lifeiscontent authored Apr 6, 2020
1 parent bddd1ce commit 7a61fb7
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 71 deletions.
139 changes: 71 additions & 68 deletions packages/next/build/output/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ export function startedDevelopmentServer(appUrl: string) {
consoleStore.setState({ appUrl })
}

let previousClient: any = null
let previousServer: any = null
let previousClient: import('webpack').Compiler | null = null
let previousServer: import('webpack').Compiler | null = null

type CompilerDiagnosticsWithFile = {
errors: { file: string | undefined; message: string }[] | null
Expand Down Expand Up @@ -203,7 +203,7 @@ export function ampValidation(
.filter(k => k !== page)
.sort()
// 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
}
Expand All @@ -213,13 +213,13 @@ export function ampValidation(
amp: Object.keys(newAmp)
.sort()
// 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(
client: any,
server: any,
client: import('webpack').Compiler,
server: import('webpack').Compiler,
enableTypeCheckingOnClient: boolean,
onTypeChecked: (diagnostics: CompilerDiagnostics) => void
) {
Expand Down Expand Up @@ -285,75 +285,78 @@ export function watchCompilers(
)
}

compiler.hooks.done.tap(`NextJsDone-${key}`, (stats: any) => {
buildStore.setState({ amp: {} })
compiler.hooks.done.tap(
`NextJsDone-${key}`,
(stats: import('webpack').Stats) => {
buildStore.setState({ amp: {} })

const { errors, warnings } = formatWebpackMessages(
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
const { errors, warnings } = formatWebpackMessages(
stats.toJson({ all: false, warnings: true, errors: true })
)

if (!hasErrors && typePromise) {
typePromise.then(typeMessages => {
if (typePromise !== tsMessagesPromise) {
// a new compilation started so we don't care about this
return
}
const hasErrors = !!errors?.length
const hasWarnings = !!warnings?.length

const reportFiles = stats.compilation.modules
.map((m: any) => (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
}
onEvent({
loading: false,
typeChecking: hasTypeChecking,
errors: hasErrors ? errors : null,
warnings: hasWarnings ? warnings : 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,
})
const typePromise = tsMessagesPromise

if (!hasErrors && typePromise) {
typePromise.then(typeMessages => {
if (typePromise !== tsMessagesPromise) {
// a new compilation started so we don't care about this
return
}

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({
loading: false,
typeChecking: false,
errors: filteredErrors,
warnings: hasWarnings
? [...warnings, ...(filteredWarnings || [])]
: filteredWarnings,
onEvent({
loading: false,
typeChecking: false,
errors: filteredErrors,
warnings: hasWarnings
? [...warnings, ...(filteredWarnings || [])]
: filteredWarnings,
})
})
})
}
}
})
)
}

tapCompiler('client', client, enableTypeCheckingOnClient, status =>
Expand Down
8 changes: 5 additions & 3 deletions packages/next/build/output/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ export type OutputState =

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) {
if (
[
([
...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
}
Expand Down

0 comments on commit 7a61fb7

Please sign in to comment.