next-bun-compile 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js CHANGED
@@ -67,9 +67,23 @@ function generateStubs(standaloneDir) {
67
67
  console.log(`next-bun-compile: Created ${count} module stubs`);
68
68
  }
69
69
  }
70
+ function patchRequireHook(standaloneDir) {
71
+ const hookPath = join(standaloneDir, "node_modules/next/dist/server/require-hook.js");
72
+ if (!existsSync(hookPath))
73
+ return;
74
+ let content = readFileSync(hookPath, "utf-8");
75
+ const target = "let resolve = process.env.NEXT_MINIMAL ? __non_webpack_require__.resolve : require.resolve;";
76
+ if (!content.includes(target))
77
+ return;
78
+ content = content.replace(target, `let _resolve = process.env.NEXT_MINIMAL ? __non_webpack_require__.resolve : require.resolve;
79
+ let resolve = (id) => { try { return _resolve(id); } catch { return ''; } };`);
80
+ writeFileSync(hookPath, content);
81
+ console.log("next-bun-compile: Patched require-hook.js for compiled binary compatibility");
82
+ }
70
83
  function generateEntryPoint(options) {
71
84
  const { standaloneDir, distDir, projectDir } = options;
72
85
  generateStubs(standaloneDir);
86
+ patchRequireHook(standaloneDir);
73
87
  const staticDir = join(distDir, "static");
74
88
  const staticFiles = walkDir(staticDir).map((f) => ({
75
89
  ...f,
@@ -80,13 +94,18 @@ function generateEntryPoint(options) {
80
94
  ...f,
81
95
  urlPath: `/${f.relativePath.replace(/\\/g, "/")}`
82
96
  }));
97
+ const standaloneNextDir = join(standaloneDir, ".next");
98
+ const runtimeFiles = walkDir(standaloneNextDir).map((f) => ({
99
+ ...f,
100
+ urlPath: `__runtime/.next/${f.relativePath.replace(/\\/g, "/")}`
101
+ }));
83
102
  const ctx = JSON.parse(readFileSync(join(distDir, "bun-compile-ctx.json"), "utf-8"));
84
103
  const { assetPrefix } = ctx;
85
- const assetsToEmbed = assetPrefix ? publicFiles : [...staticFiles, ...publicFiles];
104
+ const assetsToEmbed = assetPrefix ? [...publicFiles, ...runtimeFiles] : [...staticFiles, ...publicFiles, ...runtimeFiles];
86
105
  if (assetPrefix) {
87
106
  console.log(`next-bun-compile: assetPrefix detected — skipping ${staticFiles.length} static assets (served from CDN)`);
88
107
  }
89
- console.log(`next-bun-compile: Embedding ${assetsToEmbed.length} assets (${assetPrefix ? "public only" : `${staticFiles.length} static + ${publicFiles.length} public`})`);
108
+ console.log(`next-bun-compile: Embedding ${assetsToEmbed.length} assets (${staticFiles.length} static + ${publicFiles.length} public + ${runtimeFiles.length} runtime)`);
90
109
  const imports = [];
91
110
  const mapEntries = [];
92
111
  for (const asset of assetsToEmbed) {
@@ -108,7 +127,14 @@ ${mapEntries.join(`
108
127
  throw new Error("next-bun-compile: Could not extract nextConfig from standalone server.js");
109
128
  }
110
129
  const assetExtractions = assetsToEmbed.map((a) => {
111
- const diskPath = a.urlPath.startsWith("/_next/static/") ? ".next/static/" + a.relativePath : "public/" + a.relativePath;
130
+ let diskPath;
131
+ if (a.urlPath.startsWith("__runtime/")) {
132
+ diskPath = a.urlPath.slice("__runtime/".length);
133
+ } else if (a.urlPath.startsWith("/_next/static/")) {
134
+ diskPath = ".next/static/" + a.relativePath;
135
+ } else {
136
+ diskPath = "public/" + a.relativePath;
137
+ }
112
138
  return [a.urlPath, diskPath];
113
139
  });
114
140
  const serverEntry = `import { assetMap } from "./assets.generated.js";
package/dist/generate.js CHANGED
@@ -66,9 +66,23 @@ function generateStubs(standaloneDir) {
66
66
  console.log(`next-bun-compile: Created ${count} module stubs`);
67
67
  }
68
68
  }
69
+ function patchRequireHook(standaloneDir) {
70
+ const hookPath = join(standaloneDir, "node_modules/next/dist/server/require-hook.js");
71
+ if (!existsSync(hookPath))
72
+ return;
73
+ let content = readFileSync(hookPath, "utf-8");
74
+ const target = "let resolve = process.env.NEXT_MINIMAL ? __non_webpack_require__.resolve : require.resolve;";
75
+ if (!content.includes(target))
76
+ return;
77
+ content = content.replace(target, `let _resolve = process.env.NEXT_MINIMAL ? __non_webpack_require__.resolve : require.resolve;
78
+ let resolve = (id) => { try { return _resolve(id); } catch { return ''; } };`);
79
+ writeFileSync(hookPath, content);
80
+ console.log("next-bun-compile: Patched require-hook.js for compiled binary compatibility");
81
+ }
69
82
  function generateEntryPoint(options) {
70
83
  const { standaloneDir, distDir, projectDir } = options;
71
84
  generateStubs(standaloneDir);
85
+ patchRequireHook(standaloneDir);
72
86
  const staticDir = join(distDir, "static");
73
87
  const staticFiles = walkDir(staticDir).map((f) => ({
74
88
  ...f,
@@ -79,13 +93,18 @@ function generateEntryPoint(options) {
79
93
  ...f,
80
94
  urlPath: `/${f.relativePath.replace(/\\/g, "/")}`
81
95
  }));
96
+ const standaloneNextDir = join(standaloneDir, ".next");
97
+ const runtimeFiles = walkDir(standaloneNextDir).map((f) => ({
98
+ ...f,
99
+ urlPath: `__runtime/.next/${f.relativePath.replace(/\\/g, "/")}`
100
+ }));
82
101
  const ctx = JSON.parse(readFileSync(join(distDir, "bun-compile-ctx.json"), "utf-8"));
83
102
  const { assetPrefix } = ctx;
84
- const assetsToEmbed = assetPrefix ? publicFiles : [...staticFiles, ...publicFiles];
103
+ const assetsToEmbed = assetPrefix ? [...publicFiles, ...runtimeFiles] : [...staticFiles, ...publicFiles, ...runtimeFiles];
85
104
  if (assetPrefix) {
86
105
  console.log(`next-bun-compile: assetPrefix detected — skipping ${staticFiles.length} static assets (served from CDN)`);
87
106
  }
88
- console.log(`next-bun-compile: Embedding ${assetsToEmbed.length} assets (${assetPrefix ? "public only" : `${staticFiles.length} static + ${publicFiles.length} public`})`);
107
+ console.log(`next-bun-compile: Embedding ${assetsToEmbed.length} assets (${staticFiles.length} static + ${publicFiles.length} public + ${runtimeFiles.length} runtime)`);
89
108
  const imports = [];
90
109
  const mapEntries = [];
91
110
  for (const asset of assetsToEmbed) {
@@ -107,7 +126,14 @@ ${mapEntries.join(`
107
126
  throw new Error("next-bun-compile: Could not extract nextConfig from standalone server.js");
108
127
  }
109
128
  const assetExtractions = assetsToEmbed.map((a) => {
110
- const diskPath = a.urlPath.startsWith("/_next/static/") ? ".next/static/" + a.relativePath : "public/" + a.relativePath;
129
+ let diskPath;
130
+ if (a.urlPath.startsWith("__runtime/")) {
131
+ diskPath = a.urlPath.slice("__runtime/".length);
132
+ } else if (a.urlPath.startsWith("/_next/static/")) {
133
+ diskPath = ".next/static/" + a.relativePath;
134
+ } else {
135
+ diskPath = "public/" + a.relativePath;
136
+ }
111
137
  return [a.urlPath, diskPath];
112
138
  });
113
139
  const serverEntry = `import { assetMap } from "./assets.generated.js";
package/dist/index.js CHANGED
@@ -66,9 +66,23 @@ function generateStubs(standaloneDir) {
66
66
  console.log(`next-bun-compile: Created ${count} module stubs`);
67
67
  }
68
68
  }
69
+ function patchRequireHook(standaloneDir) {
70
+ const hookPath = join(standaloneDir, "node_modules/next/dist/server/require-hook.js");
71
+ if (!existsSync(hookPath))
72
+ return;
73
+ let content = readFileSync(hookPath, "utf-8");
74
+ const target = "let resolve = process.env.NEXT_MINIMAL ? __non_webpack_require__.resolve : require.resolve;";
75
+ if (!content.includes(target))
76
+ return;
77
+ content = content.replace(target, `let _resolve = process.env.NEXT_MINIMAL ? __non_webpack_require__.resolve : require.resolve;
78
+ let resolve = (id) => { try { return _resolve(id); } catch { return ''; } };`);
79
+ writeFileSync(hookPath, content);
80
+ console.log("next-bun-compile: Patched require-hook.js for compiled binary compatibility");
81
+ }
69
82
  function generateEntryPoint(options) {
70
83
  const { standaloneDir, distDir, projectDir } = options;
71
84
  generateStubs(standaloneDir);
85
+ patchRequireHook(standaloneDir);
72
86
  const staticDir = join(distDir, "static");
73
87
  const staticFiles = walkDir(staticDir).map((f) => ({
74
88
  ...f,
@@ -79,13 +93,18 @@ function generateEntryPoint(options) {
79
93
  ...f,
80
94
  urlPath: `/${f.relativePath.replace(/\\/g, "/")}`
81
95
  }));
96
+ const standaloneNextDir = join(standaloneDir, ".next");
97
+ const runtimeFiles = walkDir(standaloneNextDir).map((f) => ({
98
+ ...f,
99
+ urlPath: `__runtime/.next/${f.relativePath.replace(/\\/g, "/")}`
100
+ }));
82
101
  const ctx = JSON.parse(readFileSync(join(distDir, "bun-compile-ctx.json"), "utf-8"));
83
102
  const { assetPrefix } = ctx;
84
- const assetsToEmbed = assetPrefix ? publicFiles : [...staticFiles, ...publicFiles];
103
+ const assetsToEmbed = assetPrefix ? [...publicFiles, ...runtimeFiles] : [...staticFiles, ...publicFiles, ...runtimeFiles];
85
104
  if (assetPrefix) {
86
105
  console.log(`next-bun-compile: assetPrefix detected — skipping ${staticFiles.length} static assets (served from CDN)`);
87
106
  }
88
- console.log(`next-bun-compile: Embedding ${assetsToEmbed.length} assets (${assetPrefix ? "public only" : `${staticFiles.length} static + ${publicFiles.length} public`})`);
107
+ console.log(`next-bun-compile: Embedding ${assetsToEmbed.length} assets (${staticFiles.length} static + ${publicFiles.length} public + ${runtimeFiles.length} runtime)`);
89
108
  const imports = [];
90
109
  const mapEntries = [];
91
110
  for (const asset of assetsToEmbed) {
@@ -107,7 +126,14 @@ ${mapEntries.join(`
107
126
  throw new Error("next-bun-compile: Could not extract nextConfig from standalone server.js");
108
127
  }
109
128
  const assetExtractions = assetsToEmbed.map((a) => {
110
- const diskPath = a.urlPath.startsWith("/_next/static/") ? ".next/static/" + a.relativePath : "public/" + a.relativePath;
129
+ let diskPath;
130
+ if (a.urlPath.startsWith("__runtime/")) {
131
+ diskPath = a.urlPath.slice("__runtime/".length);
132
+ } else if (a.urlPath.startsWith("/_next/static/")) {
133
+ diskPath = ".next/static/" + a.relativePath;
134
+ } else {
135
+ diskPath = "public/" + a.relativePath;
136
+ }
111
137
  return [a.urlPath, diskPath];
112
138
  });
113
139
  const serverEntry = `import { assetMap } from "./assets.generated.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-bun-compile",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "Next.js Build Adapter that compiles your app into a Bun single-file executable",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",