Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/pink-walls-report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@workflow/next": patch
---

Fix condition for lazy discovery with canary
17 changes: 16 additions & 1 deletion packages/next/src/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,23 @@ export const WORKFLOW_DEFERRED_ENTRIES = [
'/.well-known/workflow/v1/webhook/[token]',
] as const;

let warnedAboutFlagAndVersion = false;

export function shouldUseDeferredBuilder(nextVersion: string): boolean {
return semver.gte(nextVersion, DEFERRED_BUILDER_MIN_VERSION);
const flagEnabled = Boolean(process.env.WORKFLOW_NEXT_LAZY_DISCOVERY);
const versionCompatible = semver.gte(
nextVersion,
DEFERRED_BUILDER_MIN_VERSION
);

if (flagEnabled && !versionCompatible && !warnedAboutFlagAndVersion) {
warnedAboutFlagAndVersion = true;
console.warn(
`Enabled lazyDiscovery but Next.js version is not compatible, needs ${DEFERRED_BUILDER_MIN_VERSION} have ${nextVersion}`
);
}

return flagEnabled && versionCompatible;
}

export async function getNextBuilder(nextVersion: string) {
Expand Down
14 changes: 5 additions & 9 deletions packages/next/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { NextConfig } from 'next';
import semver from 'semver';
import {
DEFERRED_BUILDER_MIN_VERSION,
getNextBuilder,
shouldUseDeferredBuilder,
WORKFLOW_DEFERRED_ENTRIES,
Expand All @@ -26,6 +25,10 @@ export function withWorkflow(
};
} = {}
) {
if (workflows?.lazyDiscovery) {
process.env.WORKFLOW_NEXT_LAZY_DISCOVERY = '1';
}

if (!process.env.VERCEL_DEPLOYMENT_ID) {
if (!process.env.WORKFLOW_TARGET_WORLD) {
process.env.WORKFLOW_TARGET_WORLD = 'local';
Expand Down Expand Up @@ -68,14 +71,7 @@ export function withWorkflow(
const existingRules = nextConfig.turbopack.rules as any;
const nextVersion = require('next/package.json').version;
const supportsTurboCondition = semver.gte(nextVersion, 'v16.0.0');
const useDeferredBuilder =
workflows?.lazyDiscovery && shouldUseDeferredBuilder(nextVersion);

if (workflows?.lazyDiscovery && !useDeferredBuilder) {
console.warn(
`Enabled lazyDiscovery but Next.js version is not compatible, needs ${DEFERRED_BUILDER_MIN_VERSION} have ${nextVersion}`
);
}
const useDeferredBuilder = shouldUseDeferredBuilder(nextVersion);

// Deferred builder discovers files via loader socket notifications, so
// turbopack content conditions are only needed with the eager builder.
Expand Down