@aziontech/opennextjs-azion
Version:
Azion builder for next apps
34 lines (33 loc) • 1.02 kB
JavaScript
/**
* This code was originally copied and modified from the @opennextjs/cloudflare repository.
* Significant changes have been made to adapt it for use with Azion.
*/
/**
* Inline `getBuildId` as it relies on `readFileSync` that is not supported by workerd.
*/
import { patchCode } from "@opennextjs/aws/build/patch/astCodePatcher.js";
import { getCrossPlatformPathRegex } from "@opennextjs/aws/utils/regex.js";
export function inlineBuildId(updater) {
return updater.updateContent("inline-build-id", [
{
field: {
filter: getCrossPlatformPathRegex(String.raw `/next/dist/server/next-server\.js$`, {
escape: false,
}),
contentFilter: /getBuildId\(/,
callback: ({ contents }) => patchCode(contents, rule),
},
},
]);
}
export const rule = `
rule:
kind: method_definition
has:
field: name
regex: ^getBuildId$
fix: |-
getBuildId() {
return process.env.NEXT_BUILD_ID;
}
`;