next-bun-compile 0.6.11 → 0.6.12
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-8jf4ty06.js → index-7dvf3g60.js} +30 -0
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -167,6 +167,35 @@ function findTurbopackAliases(standaloneNextDir) {
|
|
|
167
167
|
subpaths: Array.from(subpaths)
|
|
168
168
|
}));
|
|
169
169
|
}
|
|
170
|
+
function rewriteTurbopackAliases(standaloneNextDir, aliases) {
|
|
171
|
+
if (aliases.length === 0)
|
|
172
|
+
return;
|
|
173
|
+
const serverDir = join(standaloneNextDir, "server");
|
|
174
|
+
if (!existsSync(serverDir))
|
|
175
|
+
return;
|
|
176
|
+
const escape = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
177
|
+
const pattern = new RegExp(`(["'])(` + aliases.map((a) => escape(a.alias)).join("|") + `)(?=[/"'])`, "g");
|
|
178
|
+
const targetByAlias = new Map(aliases.map((a) => [a.alias, a.target]));
|
|
179
|
+
let rewritten = 0;
|
|
180
|
+
for (const f of walkDir(serverDir)) {
|
|
181
|
+
if (!f.absolutePath.endsWith(".js"))
|
|
182
|
+
continue;
|
|
183
|
+
let content;
|
|
184
|
+
try {
|
|
185
|
+
content = readFileSync(f.absolutePath, "utf-8");
|
|
186
|
+
} catch {
|
|
187
|
+
continue;
|
|
188
|
+
}
|
|
189
|
+
const next = content.replace(pattern, (_m, q, alias) => q + targetByAlias.get(alias));
|
|
190
|
+
if (next !== content) {
|
|
191
|
+
writeFileSync(f.absolutePath, next);
|
|
192
|
+
rewritten++;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
if (rewritten > 0) {
|
|
196
|
+
console.log(`next-bun-compile: Rewrote turbopack-mangled aliases in ${rewritten} server chunks`);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
170
199
|
function findServerDir(standaloneDir) {
|
|
171
200
|
if (existsSync(join(standaloneDir, "server.js"))) {
|
|
172
201
|
return standaloneDir;
|
|
@@ -328,6 +357,7 @@ function generateEntryPoint(options) {
|
|
|
328
357
|
}));
|
|
329
358
|
const standaloneNextDir = join(serverDir, ".next");
|
|
330
359
|
const turbopackAliases = findTurbopackAliases(standaloneNextDir);
|
|
360
|
+
rewriteTurbopackAliases(standaloneNextDir, turbopackAliases);
|
|
331
361
|
const aliasNames = new Set(turbopackAliases.map((a) => a.alias));
|
|
332
362
|
const runtimeFiles = walkDir(standaloneNextDir).filter((f) => {
|
|
333
363
|
const m = f.relativePath.replace(/\\/g, "/").match(/^node_modules\/([^/]+)/);
|
package/dist/index.js
CHANGED