Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: mark async_hooks as external #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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/shiny-knives-obey.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@fleek-platform/next-on-fleek': patch
---

Mark `async_hooks` as external.
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,12 @@ export async function buildWorkerFile(
banner: { js: generateGlobalJs() },
bundle: true,
inject: [functionsFile],
external: ['node:*', './__next-on-fleek-dist__/*', 'cloudflare:*'],
external: [
'node:*',
'async_hooks',
'./__next-on-fleek-dist__/*',
'cloudflare:*',
],
define: {
__CONFIG__: JSON.stringify(vercelConfig),
__NODE_ENV__: JSON.stringify(getNodeEnv()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,13 @@ export async function buildFile(
platform: 'neutral',
outfile: filePath,
bundle: true,
external: ['node:*', `${relativeNopDistPath}/*`, '*.wasm', 'cloudflare:*'],
external: [
'node:*',
'async_hooks',
`${relativeNopDistPath}/*`,
'*.wasm',
'cloudflare:*',
],
minify: false,
plugins: [builtInModulesPlugin],
loader: { '.ttf': 'file' },
Expand Down Expand Up @@ -96,21 +102,24 @@ type RelativePathOpts = {
* breaks at runtime. The following fixes this by updating the dynamic require to a standard esm
* import from the built-in module.
*
* This applies to `require("node:*")` and `require("cloudflare:*")`.
* This applies to `require("node:*")`, `require("cloudflare:*")`, and `require("async_hooks")`.
*/
export const builtInModulesPlugin: Plugin = {
name: 'built-in:modules',
setup(build) {
build.onResolve({ filter: /^(node|cloudflare):/ }, ({ kind, path }) => {
/**
* This plugin converts `require("<PREFIX>:*")` calls, those are the only ones that need
* updating (esm imports to "<PREFIX>:*" are totally valid), so here we tag with the
* built-in-modules namespace only imports that are require calls.
*/
return kind === 'require-call'
? { path, namespace: 'built-in-modules' }
: undefined;
});
build.onResolve(
{ filter: /^(node:|cloudflare:|async_hooks)/ },
({ kind, path }) => {
/**
* This plugin converts `require("<PREFIX>:*")` calls, those are the only ones that need
* updating (esm imports to "<PREFIX>:*" are totally valid), so here we tag with the
* built-in-modules namespace only imports that are require calls.
*/
return kind === 'require-call'
? { path, namespace: 'built-in-modules' }
: undefined;
}
);

/**
* We convert the imports we tagged with the built-in-modules namespace so that instead of
Expand Down