Some checks failed
Test examples / Test Examples (20) (push) Has been cancelled
Test examples / Test Examples (22) (push) Has been cancelled
Lock Threads / action (push) Has been cancelled
Trigger Release / start (push) Has been cancelled
Stale issue handler / stale (push) Has been cancelled
Update Font Data / create-pull-request (push) Has been cancelled
build-and-deploy / deploy-target (push) Has been cancelled
build-and-deploy / build (push) Has been cancelled
build-and-deploy / stable - aarch64-unknown-linux-musl - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-unknown-linux-musl - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-unknown-linux-gnu - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-unknown-linux-gnu - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-pc-windows-msvc - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-pc-windows-msvc - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-apple-darwin - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-apple-darwin - node@16 (push) Has been cancelled
build-and-deploy / build-wasm (nodejs) (push) Has been cancelled
build-and-deploy / build-wasm (web) (push) Has been cancelled
build-and-deploy / Deploy preview tarball (push) Has been cancelled
build-and-deploy / Potentially publish release (push) Has been cancelled
build-and-deploy / publish-turbopack-npm-packages (push) Has been cancelled
build-and-deploy / Deploy examples (push) Has been cancelled
build-and-deploy / thank you, build (push) Has been cancelled
build-and-deploy / Upload Turbopack Bytesize metrics to Datadog (push) Has been cancelled
Rspack Next.js development integration tests / Rspack integration tests (push) Has been cancelled
Rspack Next.js production integration tests / Rspack integration tests (push) Has been cancelled
Turbopack Next.js development integration tests / Next.js integration tests (push) Has been cancelled
Turbopack Next.js production integration tests / Next.js integration tests (push) Has been cancelled
Update Rspack test manifest / Update and upload Rspack development test manifest (push) Has been cancelled
Update Rspack test manifest / Update and upload Rspack production test manifest (push) Has been cancelled
Upload bundler test manifests to areweturboyet.com / Upload test results (push) Has been cancelled
Update React / create-pull-request (push) Has been cancelled
test-e2e-project-reset-cron / reset-test-project (push) Has been cancelled
Notify about the top 15 issues/PRs/feature requests (most reacted) in the last 90 days / run (push) Has been cancelled
178 lines
5.4 KiB
JavaScript
178 lines
5.4 KiB
JavaScript
/**
|
|
* This adapter is not modifying outputs or the test
|
|
* it is just adding additional assertions ensuring
|
|
* we provide the expected outputs and file paths are valid
|
|
*/
|
|
import fs from 'fs'
|
|
|
|
// @ts-check
|
|
/** @type {import('next').NextAdapter } */
|
|
const myAdapter = {
|
|
name: 'my-custom-adapter',
|
|
modifyConfig: (config, { phase }) => {
|
|
if (process.env.NODE_ENV !== 'production') return config
|
|
if (typeof phase !== 'string') {
|
|
throw new Error(`invalid phase value provided to modifyConfig ${phase}`)
|
|
}
|
|
console.log('called modify config in adapter with phase', phase)
|
|
return config
|
|
},
|
|
onBuildComplete: async (ctx) => {
|
|
console.log('onBuildComplete called')
|
|
|
|
// Validate all output file paths exist on the filesystem
|
|
const allOutputs = [
|
|
...ctx.outputs.pages,
|
|
...ctx.outputs.pagesApi,
|
|
...ctx.outputs.appPages,
|
|
...ctx.outputs.appRoutes,
|
|
...ctx.outputs.prerenders,
|
|
...ctx.outputs.staticFiles,
|
|
]
|
|
|
|
if (ctx.outputs.middleware) {
|
|
allOutputs.push(ctx.outputs.middleware)
|
|
}
|
|
|
|
const validationErrors = []
|
|
|
|
// Check that all filePaths in outputs exist
|
|
for (const output of allOutputs) {
|
|
if (output.filePath) {
|
|
try {
|
|
await fs.promises.access(output.filePath, fs.constants.F_OK)
|
|
} catch (err) {
|
|
validationErrors.push(
|
|
`Missing file for output ${output.id}: ${output.filePath}`
|
|
)
|
|
}
|
|
}
|
|
|
|
// Check fallback filePath for prerenders
|
|
if (output.type === 'PRERENDER' && output.fallback) {
|
|
if (output.fallback.filePath) {
|
|
try {
|
|
await fs.promises.access(
|
|
output.fallback.filePath,
|
|
fs.constants.F_OK
|
|
)
|
|
} catch (err) {
|
|
validationErrors.push(
|
|
`Missing fallback file for prerender ${output.id}: ${JSON.stringify(output, null, 2)}`
|
|
)
|
|
}
|
|
}
|
|
}
|
|
|
|
// Check assets
|
|
if (output.assets) {
|
|
for (const [key, assetPath] of Object.entries(output.assets)) {
|
|
try {
|
|
await fs.promises.access(assetPath, fs.constants.F_OK)
|
|
} catch (err) {
|
|
validationErrors.push(
|
|
`Missing asset file for output ${output.id} (${key}): ${assetPath}`
|
|
)
|
|
}
|
|
}
|
|
}
|
|
|
|
// Check wasmAssets
|
|
if (output.wasmAssets) {
|
|
for (const [key, wasmPath] of Object.entries(output.wasmAssets)) {
|
|
try {
|
|
await fs.promises.access(wasmPath, fs.constants.F_OK)
|
|
} catch (err) {
|
|
validationErrors.push(
|
|
`Missing wasm file for output ${output.id} (${key}): ${wasmPath}`
|
|
)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Validate that segment routes are present in routing.dynamicRoutes
|
|
// Segment routes match the pattern: .segments/.+.segment.rsc
|
|
const segmentRoutes = ctx.routing.dynamicRoutes.filter((route) => {
|
|
// Check if the source or destination contains segment routes
|
|
return (
|
|
route.sourceRegex.includes('.segments/') ||
|
|
route.sourceRegex.includes('.segment.rsc')
|
|
)
|
|
})
|
|
|
|
// Ensure we have segment routes when we have app pages
|
|
if (ctx.outputs.appPages.length > 0) {
|
|
if (segmentRoutes.length === 0) {
|
|
validationErrors.push(
|
|
'Expected segment routes in routing.dynamicRoutes when app pages exist'
|
|
)
|
|
} else {
|
|
console.log(
|
|
`Found ${segmentRoutes.length} segment routes in routing.dynamicRoutes`
|
|
)
|
|
}
|
|
}
|
|
|
|
// Validate that all appPages have matching .rsc and non .rsc pathnames
|
|
const appPagePathnames = new Map()
|
|
for (const appPage of ctx.outputs.appPages) {
|
|
const pathname = appPage.pathname
|
|
if (pathname.endsWith('.rsc')) {
|
|
const basePathname = pathname.slice(0, -4) // Remove .rsc extension
|
|
if (!appPagePathnames.has(basePathname)) {
|
|
appPagePathnames.set(basePathname, { rsc: false, nonRsc: false })
|
|
}
|
|
appPagePathnames.get(basePathname).rsc = true
|
|
} else {
|
|
if (!appPagePathnames.has(pathname)) {
|
|
appPagePathnames.set(pathname, { rsc: false, nonRsc: false })
|
|
}
|
|
appPagePathnames.get(pathname).nonRsc = true
|
|
}
|
|
}
|
|
|
|
// Check that each pathname has both .rsc and non .rsc versions
|
|
for (const [pathname, versions] of appPagePathnames.entries()) {
|
|
if (!versions.rsc) {
|
|
validationErrors.push(
|
|
`App page ${pathname} is missing corresponding .rsc pathname`
|
|
)
|
|
}
|
|
if (!versions.nonRsc) {
|
|
validationErrors.push(
|
|
`App page ${pathname}.rsc is missing corresponding non .rsc pathname`
|
|
)
|
|
}
|
|
}
|
|
|
|
if (appPagePathnames.size > 0) {
|
|
console.log(
|
|
`Validated ${appPagePathnames.size} app page pathname(s) have matching .rsc and non .rsc versions`
|
|
)
|
|
}
|
|
|
|
if (validationErrors.length > 0) {
|
|
console.error('Validation errors:')
|
|
for (const error of validationErrors) {
|
|
console.error(` - ${error}`)
|
|
}
|
|
throw new Error(
|
|
`Adapter validation failed with ${validationErrors.length} error(s)`
|
|
)
|
|
}
|
|
|
|
console.log('Validation passed: All output files exist on filesystem')
|
|
console.log(
|
|
`Segment routes validated: ${segmentRoutes.length} routes found`
|
|
)
|
|
|
|
await fs.promises.writeFile(
|
|
'build-complete.json',
|
|
JSON.stringify(ctx, null, 2)
|
|
)
|
|
},
|
|
}
|
|
|
|
export default myAdapter
|