e907e4791c
* Add new logger output * Fix tests * Fix tests * Update next start log for consistency * Fix cli tests * Fix tsconfig tests * Update plugins test * Fix invalid-custom-routes tests * Revert "Fix invalid-custom-routes tests" This reverts commit 8e8eec11dd21feb2186163856207bb974110c13e. * Revert "Update plugins test" This reverts commit 3f09270509ea52a1b4f0515cee8e4e711f7e1b16. * Revert "Fix tsconfig tests" This reverts commit a4c23bb120e81a15ea50dc6ad1ad097368ef3be6. * Revert "Fix cli tests" This reverts commit ff3a321d29bd9afb09f7cf550823010a08a54ae1. * Revert "Update next start log for consistency" This reverts commit 481509d8f713a918b7a125e4b7f7bc5c5990c2e1. * Revert "Fix tests" This reverts commit 6fb2cb59f79fdf8495fc7288c1c18ece75279ed7. * Revert "Fix tests" This reverts commit 9d37298dbc20392a33338cf45166ad86c556de4b. * Fix tests * Update next start message * Update packages/next/build/output/log.ts Co-Authored-By: Joe Haddad <timer@zeit.co> * Fix tests Co-authored-by: Joe Haddad <timer@zeit.co> Co-authored-by: Joe Haddad <joe.haddad@zeit.co>
87 lines
2 KiB
TypeScript
87 lines
2 KiB
TypeScript
import createStore from 'next/dist/compiled/unistore'
|
|
import stripAnsi from 'next/dist/compiled/strip-ansi'
|
|
|
|
import * as Log from './log'
|
|
|
|
export type OutputState =
|
|
| { bootstrap: true; appUrl: string | null }
|
|
| ({ bootstrap: false; appUrl: string | null } & (
|
|
| { loading: true }
|
|
| {
|
|
loading: false
|
|
typeChecking: boolean
|
|
errors: string[] | null
|
|
warnings: string[] | null
|
|
}
|
|
))
|
|
|
|
export const store = createStore<OutputState>({ appUrl: null, bootstrap: true })
|
|
|
|
let lastStore: OutputState = { appUrl: null, bootstrap: true }
|
|
function hasStoreChanged(nextStore: OutputState) {
|
|
if (
|
|
([
|
|
...new Set([...Object.keys(lastStore), ...Object.keys(nextStore)]),
|
|
] as Array<keyof OutputState>).every(key =>
|
|
Object.is(lastStore[key], nextStore[key])
|
|
)
|
|
) {
|
|
return false
|
|
}
|
|
|
|
lastStore = nextStore
|
|
return true
|
|
}
|
|
|
|
store.subscribe(state => {
|
|
if (!hasStoreChanged(state)) {
|
|
return
|
|
}
|
|
|
|
if (state.bootstrap) {
|
|
if (state.appUrl) {
|
|
Log.ready(`started server on ${state.appUrl}`)
|
|
}
|
|
return
|
|
}
|
|
|
|
if (state.loading) {
|
|
Log.wait('compiling...')
|
|
return
|
|
}
|
|
|
|
if (state.errors) {
|
|
Log.error(state.errors[0])
|
|
|
|
const cleanError = stripAnsi(state.errors[0])
|
|
if (cleanError.indexOf('SyntaxError') > -1) {
|
|
const matches = cleanError.match(/\[.*\]=/)
|
|
if (matches) {
|
|
for (const match of matches) {
|
|
const prop = (match.split(']').shift() || '').substr(1)
|
|
console.log(
|
|
`AMP bind syntax [${prop}]='' is not supported in JSX, use 'data-amp-bind-${prop}' instead. https://err.sh/zeit/next.js/amp-bind-jsx-alt`
|
|
)
|
|
}
|
|
return
|
|
}
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
if (state.warnings) {
|
|
Log.warn(state.warnings.join('\n\n'))
|
|
if (state.appUrl) {
|
|
Log.info(`ready on ${state.appUrl}`)
|
|
}
|
|
return
|
|
}
|
|
|
|
if (state.typeChecking) {
|
|
Log.info('bundled successfully, waiting for typecheck results...')
|
|
return
|
|
}
|
|
|
|
Log.event('compiled successfully')
|
|
})
|