next-bun-compile 0.6.0 → 0.6.2
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/README.md +14 -4
- package/dist/cli.js +1 -1
- package/dist/{index-5m65k8kw.js → index-v3pyz7g9.js} +22 -5
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -27,7 +27,7 @@ Add the adapter to your `next.config.ts`:
|
|
|
27
27
|
import type { NextConfig } from "next";
|
|
28
28
|
|
|
29
29
|
const nextConfig: NextConfig = {
|
|
30
|
-
adapterPath:
|
|
30
|
+
adapterPath: import.meta.resolve("next-bun-compile"),
|
|
31
31
|
};
|
|
32
32
|
|
|
33
33
|
export default nextConfig;
|
|
@@ -39,7 +39,7 @@ export default nextConfig;
|
|
|
39
39
|
```ts
|
|
40
40
|
const nextConfig: NextConfig = {
|
|
41
41
|
experimental: {
|
|
42
|
-
adapterPath:
|
|
42
|
+
adapterPath: import.meta.resolve("next-bun-compile"),
|
|
43
43
|
},
|
|
44
44
|
};
|
|
45
45
|
```
|
|
@@ -91,7 +91,7 @@ If you configure `assetPrefix` in your `next.config.ts`, static assets (`/_next/
|
|
|
91
91
|
```ts
|
|
92
92
|
const nextConfig: NextConfig = {
|
|
93
93
|
assetPrefix: "https://cdn.example.com",
|
|
94
|
-
adapterPath:
|
|
94
|
+
adapterPath: import.meta.resolve("next-bun-compile"),
|
|
95
95
|
};
|
|
96
96
|
```
|
|
97
97
|
|
|
@@ -128,6 +128,16 @@ Some modules can't be resolved at compile time but are never reached in producti
|
|
|
128
128
|
|
|
129
129
|
## Troubleshooting
|
|
130
130
|
|
|
131
|
+
### Stale standalone output after upgrading Next.js
|
|
132
|
+
|
|
133
|
+
Next.js doesn't clean the standalone output directory between builds. If you upgrade Next.js versions, stale files from the old version can cause runtime errors like `Cannot find module 'next/dist/compiled/source-map'`.
|
|
134
|
+
|
|
135
|
+
**Fix:** Clean the standalone output before rebuilding:
|
|
136
|
+
|
|
137
|
+
```bash
|
|
138
|
+
rm -rf .next/standalone && bun next build && next-bun-compile
|
|
139
|
+
```
|
|
140
|
+
|
|
131
141
|
### Packages with dynamic `require()` calls (e.g. pino)
|
|
132
142
|
|
|
133
143
|
Some packages like `pino` use dynamic `require()` calls internally (for worker threads, transports, etc.). Turbopack can't resolve these at build time, so they fail at runtime inside the compiled binary with errors like:
|
|
@@ -141,7 +151,7 @@ Failed to load external module pino-142500b1eb3f4baf: Cannot find package ...
|
|
|
141
151
|
```ts
|
|
142
152
|
const nextConfig: NextConfig = {
|
|
143
153
|
transpilePackages: ["pino", "pino-pretty"],
|
|
144
|
-
adapterPath:
|
|
154
|
+
adapterPath: import.meta.resolve("next-bun-compile"),
|
|
145
155
|
};
|
|
146
156
|
```
|
|
147
157
|
|
package/dist/cli.js
CHANGED
|
@@ -12,13 +12,26 @@ import {
|
|
|
12
12
|
} from "node:fs";
|
|
13
13
|
import { join, relative } from "node:path";
|
|
14
14
|
import { createHash } from "node:crypto";
|
|
15
|
+
function tryStat(p) {
|
|
16
|
+
try {
|
|
17
|
+
return statSync(p);
|
|
18
|
+
} catch (err) {
|
|
19
|
+
const code = err.code;
|
|
20
|
+
if (code === "EPERM" || code === "EACCES" || code === "ENOENT")
|
|
21
|
+
return null;
|
|
22
|
+
throw err;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
15
25
|
function walkDir(dir, base = dir) {
|
|
16
26
|
const results = [];
|
|
17
27
|
if (!existsSync(dir))
|
|
18
28
|
return results;
|
|
19
29
|
for (const entry of readdirSync(dir)) {
|
|
20
30
|
const full = join(dir, entry);
|
|
21
|
-
|
|
31
|
+
const stat = tryStat(full);
|
|
32
|
+
if (!stat)
|
|
33
|
+
continue;
|
|
34
|
+
if (stat.isDirectory()) {
|
|
22
35
|
results.push(...walkDir(full, base));
|
|
23
36
|
} else {
|
|
24
37
|
results.push({ absolutePath: full, relativePath: relative(base, full) });
|
|
@@ -107,7 +120,8 @@ function findServerDir(standaloneDir) {
|
|
|
107
120
|
if (entry === "node_modules")
|
|
108
121
|
continue;
|
|
109
122
|
const full = join(dir, entry);
|
|
110
|
-
|
|
123
|
+
const stat = tryStat(full);
|
|
124
|
+
if (!stat || !stat.isDirectory())
|
|
111
125
|
continue;
|
|
112
126
|
if (existsSync(join(full, "server.js")))
|
|
113
127
|
return full;
|
|
@@ -163,12 +177,14 @@ function collectExternalModules(standaloneDir) {
|
|
|
163
177
|
if (entry.startsWith(".") || entry === "next-bun-compile")
|
|
164
178
|
continue;
|
|
165
179
|
const entryPath = join(dir, entry);
|
|
166
|
-
|
|
180
|
+
const stat = tryStat(entryPath);
|
|
181
|
+
if (!stat || !stat.isDirectory())
|
|
167
182
|
continue;
|
|
168
183
|
if (entry.startsWith("@")) {
|
|
169
184
|
for (const sub of readdirSync(entryPath)) {
|
|
170
185
|
const subPath = join(entryPath, sub);
|
|
171
|
-
|
|
186
|
+
const subStat = tryStat(subPath);
|
|
187
|
+
if (subStat && subStat.isDirectory())
|
|
172
188
|
addPkg(`${entry}/${sub}`, subPath);
|
|
173
189
|
}
|
|
174
190
|
} else {
|
|
@@ -206,7 +222,8 @@ function fixModuleResolution(standaloneDir) {
|
|
|
206
222
|
continue;
|
|
207
223
|
for (const entry of readdirSync(compiledDir)) {
|
|
208
224
|
const dir = join(compiledDir, entry);
|
|
209
|
-
|
|
225
|
+
const stat = tryStat(dir);
|
|
226
|
+
if (!stat || !stat.isDirectory())
|
|
210
227
|
continue;
|
|
211
228
|
const pkgJsonPath = join(dir, "package.json");
|
|
212
229
|
const indexPath = join(dir, "index.js");
|
package/dist/index.js
CHANGED