Skip to content

Commit

Permalink
fix require-call typo in nodeBufferPlugin (#200)
Browse files Browse the repository at this point in the history
* fix require-call typo in nodeBufferPlugin

resolves #199

* add useful comment to require-call check

* apply suggested refactoring and add another comment
  • Loading branch information
dario-piotrowicz authored Apr 25, 2023
1 parent bddbe04 commit 9f5b83c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/swift-islands-doubt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@cloudflare/next-on-pages': patch
---

fix require-call typo preventing nodeBufferPlugin from properly working
17 changes: 11 additions & 6 deletions src/buildApplication/buildWorkerFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,19 @@ const nodeBufferPlugin: Plugin = {
name: 'node:buffer',
setup(build) {
build.onResolve({ filter: /^node:buffer$/ }, ({ kind, path }) => {
if (kind === 'require-call') return;

return {
path,
namespace: 'node-buffer',
};
// this plugin converts `require("node:buffer")` calls, those are the only ones that
// need updating (esm imports to "node:buffer" are totally valid), so here we tag with the
// node-buffer namespace only imports that are require calls
return kind === 'require-call'
? {
path,
namespace: 'node-buffer',
}
: undefined;
});

// we convert the imports we tagged with the node-buffer namespace so that instead of `require("node:buffer")`
// they import from `export * from 'node:buffer;'`
build.onLoad({ filter: /.*/, namespace: 'node-buffer' }, () => ({
contents: `export * from 'node:buffer'`,
loader: 'js',
Expand Down

0 comments on commit 9f5b83c

Please sign in to comment.