next-bun-compile 0.6.2 → 0.6.4
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-v3pyz7g9.js → index-rh4vdfr5.js} +70 -2
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -8,9 +8,11 @@ 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";
|
|
15
17
|
function tryStat(p) {
|
|
16
18
|
try {
|
|
@@ -109,6 +111,48 @@ function generateStubs(standaloneDir) {
|
|
|
109
111
|
console.log(`next-bun-compile: Created ${count} module stubs`);
|
|
110
112
|
}
|
|
111
113
|
}
|
|
114
|
+
function findTurbopackAliases(standaloneNextDir) {
|
|
115
|
+
const seen = new Map;
|
|
116
|
+
const serverDir = join(standaloneNextDir, "server");
|
|
117
|
+
if (existsSync(serverDir)) {
|
|
118
|
+
const re = /require\(["']([^"'\s/]+-[0-9a-f]{16})["']\)/g;
|
|
119
|
+
for (const f of walkDir(serverDir)) {
|
|
120
|
+
if (!f.absolutePath.endsWith(".js"))
|
|
121
|
+
continue;
|
|
122
|
+
let content;
|
|
123
|
+
try {
|
|
124
|
+
content = readFileSync(f.absolutePath, "utf-8");
|
|
125
|
+
} catch {
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
let m;
|
|
129
|
+
while (m = re.exec(content)) {
|
|
130
|
+
const alias = m[1];
|
|
131
|
+
if (seen.has(alias))
|
|
132
|
+
continue;
|
|
133
|
+
seen.set(alias, alias.replace(/-[0-9a-f]{16}$/, ""));
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
const nodeModulesDir = join(standaloneNextDir, "node_modules");
|
|
138
|
+
if (existsSync(nodeModulesDir)) {
|
|
139
|
+
for (const entry of readdirSync(nodeModulesDir)) {
|
|
140
|
+
if (!/-[0-9a-f]{16}$/.test(entry))
|
|
141
|
+
continue;
|
|
142
|
+
if (seen.has(entry))
|
|
143
|
+
continue;
|
|
144
|
+
const aliasPath = join(nodeModulesDir, entry);
|
|
145
|
+
try {
|
|
146
|
+
if (!lstatSync(aliasPath).isSymbolicLink())
|
|
147
|
+
continue;
|
|
148
|
+
seen.set(entry, basename(realpathSync(aliasPath)));
|
|
149
|
+
} catch {
|
|
150
|
+
continue;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return Array.from(seen, ([alias, target]) => ({ alias, target }));
|
|
155
|
+
}
|
|
112
156
|
function findServerDir(standaloneDir) {
|
|
113
157
|
if (existsSync(join(standaloneDir, "server.js"))) {
|
|
114
158
|
return standaloneDir;
|
|
@@ -269,7 +313,12 @@ function generateEntryPoint(options) {
|
|
|
269
313
|
urlPath: `/${f.relativePath.replace(/\\/g, "/")}`
|
|
270
314
|
}));
|
|
271
315
|
const standaloneNextDir = join(serverDir, ".next");
|
|
272
|
-
const
|
|
316
|
+
const turbopackAliases = findTurbopackAliases(standaloneNextDir);
|
|
317
|
+
const aliasNames = new Set(turbopackAliases.map((a) => a.alias));
|
|
318
|
+
const runtimeFiles = walkDir(standaloneNextDir).filter((f) => {
|
|
319
|
+
const m = f.relativePath.replace(/\\/g, "/").match(/^node_modules\/([^/]+)/);
|
|
320
|
+
return !(m && aliasNames.has(m[1]));
|
|
321
|
+
}).map((f) => ({
|
|
273
322
|
...f,
|
|
274
323
|
urlPath: `__runtime/.next/${f.relativePath.replace(/\\/g, "/")}`
|
|
275
324
|
}));
|
|
@@ -347,6 +396,7 @@ if (Number.isNaN(keepAliveTimeout) || !Number.isFinite(keepAliveTimeout) || keep
|
|
|
347
396
|
}
|
|
348
397
|
|
|
349
398
|
const extractions = ${JSON.stringify(assetExtractions)};
|
|
399
|
+
const turbopackAliases = ${JSON.stringify(turbopackAliases.map((a) => [a.alias, a.target]))};
|
|
350
400
|
async function extractAssets() {
|
|
351
401
|
let n = 0;
|
|
352
402
|
for (const [urlPath, diskPath] of extractions) {
|
|
@@ -356,6 +406,24 @@ async function extractAssets() {
|
|
|
356
406
|
const embedded = assetMap.get(urlPath);
|
|
357
407
|
if (embedded) { await Bun.write(fullPath, Bun.file(embedded)); n++; }
|
|
358
408
|
}
|
|
409
|
+
for (const [alias, target] of turbopackAliases) {
|
|
410
|
+
const aliasPath = path.join(baseDir, ".next/node_modules", alias);
|
|
411
|
+
if (fs.existsSync(aliasPath)) continue;
|
|
412
|
+
fs.mkdirSync(path.dirname(aliasPath), { recursive: true });
|
|
413
|
+
try {
|
|
414
|
+
fs.symlinkSync(target, aliasPath, "dir");
|
|
415
|
+
} catch {
|
|
416
|
+
fs.mkdirSync(aliasPath, { recursive: true });
|
|
417
|
+
fs.writeFileSync(
|
|
418
|
+
path.join(aliasPath, "package.json"),
|
|
419
|
+
JSON.stringify({ name: alias, main: "index.js" })
|
|
420
|
+
);
|
|
421
|
+
fs.writeFileSync(
|
|
422
|
+
path.join(aliasPath, "index.js"),
|
|
423
|
+
"module.exports = require(" + JSON.stringify(target) + ");"
|
|
424
|
+
);
|
|
425
|
+
}
|
|
426
|
+
}
|
|
359
427
|
if (n > 0) console.log(\`Extracted \${n} assets\`);
|
|
360
428
|
}
|
|
361
429
|
|
package/dist/index.js
CHANGED