next-bun-compile 0.6.1 → 0.6.3
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 +1 -1
- package/dist/{index-5m65k8kw.js → index-dxk9rwqh.js} +70 -7
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -8,17 +8,32 @@ import {
|
|
|
8
8
|
existsSync,
|
|
9
9
|
readdirSync,
|
|
10
10
|
statSync,
|
|
11
|
+
lstatSync,
|
|
12
|
+
realpathSync,
|
|
11
13
|
mkdirSync
|
|
12
14
|
} from "node:fs";
|
|
13
|
-
import { join, relative } from "node:path";
|
|
15
|
+
import { join, relative, basename } from "node:path";
|
|
14
16
|
import { createHash } from "node:crypto";
|
|
17
|
+
function tryStat(p) {
|
|
18
|
+
try {
|
|
19
|
+
return statSync(p);
|
|
20
|
+
} catch (err) {
|
|
21
|
+
const code = err.code;
|
|
22
|
+
if (code === "EPERM" || code === "EACCES" || code === "ENOENT")
|
|
23
|
+
return null;
|
|
24
|
+
throw err;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
15
27
|
function walkDir(dir, base = dir) {
|
|
16
28
|
const results = [];
|
|
17
29
|
if (!existsSync(dir))
|
|
18
30
|
return results;
|
|
19
31
|
for (const entry of readdirSync(dir)) {
|
|
20
32
|
const full = join(dir, entry);
|
|
21
|
-
|
|
33
|
+
const stat = tryStat(full);
|
|
34
|
+
if (!stat)
|
|
35
|
+
continue;
|
|
36
|
+
if (stat.isDirectory()) {
|
|
22
37
|
results.push(...walkDir(full, base));
|
|
23
38
|
} else {
|
|
24
39
|
results.push({ absolutePath: full, relativePath: relative(base, full) });
|
|
@@ -96,6 +111,26 @@ function generateStubs(standaloneDir) {
|
|
|
96
111
|
console.log(`next-bun-compile: Created ${count} module stubs`);
|
|
97
112
|
}
|
|
98
113
|
}
|
|
114
|
+
function findTurbopackAliases(standaloneNextDir) {
|
|
115
|
+
const nodeModulesDir = join(standaloneNextDir, "node_modules");
|
|
116
|
+
if (!existsSync(nodeModulesDir))
|
|
117
|
+
return [];
|
|
118
|
+
const aliases = [];
|
|
119
|
+
for (const entry of readdirSync(nodeModulesDir)) {
|
|
120
|
+
if (!/-[0-9a-f]{16}$/.test(entry))
|
|
121
|
+
continue;
|
|
122
|
+
const aliasPath = join(nodeModulesDir, entry);
|
|
123
|
+
try {
|
|
124
|
+
if (!lstatSync(aliasPath).isSymbolicLink())
|
|
125
|
+
continue;
|
|
126
|
+
const target = basename(realpathSync(aliasPath));
|
|
127
|
+
aliases.push({ alias: entry, target });
|
|
128
|
+
} catch {
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return aliases;
|
|
133
|
+
}
|
|
99
134
|
function findServerDir(standaloneDir) {
|
|
100
135
|
if (existsSync(join(standaloneDir, "server.js"))) {
|
|
101
136
|
return standaloneDir;
|
|
@@ -107,7 +142,8 @@ function findServerDir(standaloneDir) {
|
|
|
107
142
|
if (entry === "node_modules")
|
|
108
143
|
continue;
|
|
109
144
|
const full = join(dir, entry);
|
|
110
|
-
|
|
145
|
+
const stat = tryStat(full);
|
|
146
|
+
if (!stat || !stat.isDirectory())
|
|
111
147
|
continue;
|
|
112
148
|
if (existsSync(join(full, "server.js")))
|
|
113
149
|
return full;
|
|
@@ -163,12 +199,14 @@ function collectExternalModules(standaloneDir) {
|
|
|
163
199
|
if (entry.startsWith(".") || entry === "next-bun-compile")
|
|
164
200
|
continue;
|
|
165
201
|
const entryPath = join(dir, entry);
|
|
166
|
-
|
|
202
|
+
const stat = tryStat(entryPath);
|
|
203
|
+
if (!stat || !stat.isDirectory())
|
|
167
204
|
continue;
|
|
168
205
|
if (entry.startsWith("@")) {
|
|
169
206
|
for (const sub of readdirSync(entryPath)) {
|
|
170
207
|
const subPath = join(entryPath, sub);
|
|
171
|
-
|
|
208
|
+
const subStat = tryStat(subPath);
|
|
209
|
+
if (subStat && subStat.isDirectory())
|
|
172
210
|
addPkg(`${entry}/${sub}`, subPath);
|
|
173
211
|
}
|
|
174
212
|
} else {
|
|
@@ -206,7 +244,8 @@ function fixModuleResolution(standaloneDir) {
|
|
|
206
244
|
continue;
|
|
207
245
|
for (const entry of readdirSync(compiledDir)) {
|
|
208
246
|
const dir = join(compiledDir, entry);
|
|
209
|
-
|
|
247
|
+
const stat = tryStat(dir);
|
|
248
|
+
if (!stat || !stat.isDirectory())
|
|
210
249
|
continue;
|
|
211
250
|
const pkgJsonPath = join(dir, "package.json");
|
|
212
251
|
const indexPath = join(dir, "index.js");
|
|
@@ -252,7 +291,12 @@ function generateEntryPoint(options) {
|
|
|
252
291
|
urlPath: `/${f.relativePath.replace(/\\/g, "/")}`
|
|
253
292
|
}));
|
|
254
293
|
const standaloneNextDir = join(serverDir, ".next");
|
|
255
|
-
const
|
|
294
|
+
const turbopackAliases = findTurbopackAliases(standaloneNextDir);
|
|
295
|
+
const aliasNames = new Set(turbopackAliases.map((a) => a.alias));
|
|
296
|
+
const runtimeFiles = walkDir(standaloneNextDir).filter((f) => {
|
|
297
|
+
const m = f.relativePath.replace(/\\/g, "/").match(/^node_modules\/([^/]+)/);
|
|
298
|
+
return !(m && aliasNames.has(m[1]));
|
|
299
|
+
}).map((f) => ({
|
|
256
300
|
...f,
|
|
257
301
|
urlPath: `__runtime/.next/${f.relativePath.replace(/\\/g, "/")}`
|
|
258
302
|
}));
|
|
@@ -330,6 +374,7 @@ if (Number.isNaN(keepAliveTimeout) || !Number.isFinite(keepAliveTimeout) || keep
|
|
|
330
374
|
}
|
|
331
375
|
|
|
332
376
|
const extractions = ${JSON.stringify(assetExtractions)};
|
|
377
|
+
const turbopackAliases = ${JSON.stringify(turbopackAliases.map((a) => [a.alias, a.target]))};
|
|
333
378
|
async function extractAssets() {
|
|
334
379
|
let n = 0;
|
|
335
380
|
for (const [urlPath, diskPath] of extractions) {
|
|
@@ -339,6 +384,24 @@ async function extractAssets() {
|
|
|
339
384
|
const embedded = assetMap.get(urlPath);
|
|
340
385
|
if (embedded) { await Bun.write(fullPath, Bun.file(embedded)); n++; }
|
|
341
386
|
}
|
|
387
|
+
for (const [alias, target] of turbopackAliases) {
|
|
388
|
+
const aliasPath = path.join(baseDir, ".next/node_modules", alias);
|
|
389
|
+
if (fs.existsSync(aliasPath)) continue;
|
|
390
|
+
fs.mkdirSync(path.dirname(aliasPath), { recursive: true });
|
|
391
|
+
try {
|
|
392
|
+
fs.symlinkSync(target, aliasPath, "dir");
|
|
393
|
+
} catch {
|
|
394
|
+
fs.mkdirSync(aliasPath, { recursive: true });
|
|
395
|
+
fs.writeFileSync(
|
|
396
|
+
path.join(aliasPath, "package.json"),
|
|
397
|
+
JSON.stringify({ name: alias, main: "index.js" })
|
|
398
|
+
);
|
|
399
|
+
fs.writeFileSync(
|
|
400
|
+
path.join(aliasPath, "index.js"),
|
|
401
|
+
"module.exports = require(" + JSON.stringify(target) + ");"
|
|
402
|
+
);
|
|
403
|
+
}
|
|
404
|
+
}
|
|
342
405
|
if (n > 0) console.log(\`Extracted \${n} assets\`);
|
|
343
406
|
}
|
|
344
407
|
|
package/dist/index.js
CHANGED