next-bun-compile 0.6.7 → 0.6.8
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-qhwqnqff.js → index-mx555e90.js} +37 -53
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -113,20 +113,9 @@ function generateStubs(standaloneDir) {
|
|
|
113
113
|
}
|
|
114
114
|
function findTurbopackAliases(standaloneNextDir) {
|
|
115
115
|
const seen = new Map;
|
|
116
|
-
const ensure = (alias) => {
|
|
117
|
-
let entry = seen.get(alias);
|
|
118
|
-
if (!entry) {
|
|
119
|
-
entry = {
|
|
120
|
-
target: alias.replace(/-[0-9a-f]{16}$/, ""),
|
|
121
|
-
subpaths: new Set
|
|
122
|
-
};
|
|
123
|
-
seen.set(alias, entry);
|
|
124
|
-
}
|
|
125
|
-
return entry;
|
|
126
|
-
};
|
|
127
116
|
const serverDir = join(standaloneNextDir, "server");
|
|
128
117
|
if (existsSync(serverDir)) {
|
|
129
|
-
const re = /["']([^"'\s/]+-[0-9a-f]{16})(?:\/
|
|
118
|
+
const re = /["']([^"'\s/]+-[0-9a-f]{16})(?:\/[^"'\s]+)?["']/g;
|
|
130
119
|
for (const f of walkDir(serverDir)) {
|
|
131
120
|
if (!f.absolutePath.endsWith(".js"))
|
|
132
121
|
continue;
|
|
@@ -138,9 +127,10 @@ function findTurbopackAliases(standaloneNextDir) {
|
|
|
138
127
|
}
|
|
139
128
|
let m;
|
|
140
129
|
while (m = re.exec(content)) {
|
|
141
|
-
const
|
|
142
|
-
if (
|
|
143
|
-
|
|
130
|
+
const alias = m[1];
|
|
131
|
+
if (seen.has(alias))
|
|
132
|
+
continue;
|
|
133
|
+
seen.set(alias, alias.replace(/-[0-9a-f]{16}$/, ""));
|
|
144
134
|
}
|
|
145
135
|
}
|
|
146
136
|
}
|
|
@@ -155,20 +145,42 @@ function findTurbopackAliases(standaloneNextDir) {
|
|
|
155
145
|
try {
|
|
156
146
|
if (!lstatSync(aliasPath).isSymbolicLink())
|
|
157
147
|
continue;
|
|
158
|
-
seen.set(name,
|
|
159
|
-
target: basename(realpathSync(aliasPath)),
|
|
160
|
-
subpaths: new Set
|
|
161
|
-
});
|
|
148
|
+
seen.set(name, basename(realpathSync(aliasPath)));
|
|
162
149
|
} catch {
|
|
163
150
|
continue;
|
|
164
151
|
}
|
|
165
152
|
}
|
|
166
153
|
}
|
|
167
|
-
return Array.from(seen, ([alias,
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
154
|
+
return Array.from(seen, ([alias, target]) => ({ alias, target }));
|
|
155
|
+
}
|
|
156
|
+
function rewriteTurbopackAliases(standaloneNextDir, aliases) {
|
|
157
|
+
if (aliases.length === 0)
|
|
158
|
+
return;
|
|
159
|
+
const serverDir = join(standaloneNextDir, "server");
|
|
160
|
+
if (!existsSync(serverDir))
|
|
161
|
+
return;
|
|
162
|
+
const escape = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
163
|
+
const pattern = new RegExp(`(["'])(` + aliases.map((a) => escape(a.alias)).join("|") + `)(?=[/"'])`, "g");
|
|
164
|
+
const targetByAlias = new Map(aliases.map((a) => [a.alias, a.target]));
|
|
165
|
+
let rewritten = 0;
|
|
166
|
+
for (const f of walkDir(serverDir)) {
|
|
167
|
+
if (!f.absolutePath.endsWith(".js"))
|
|
168
|
+
continue;
|
|
169
|
+
let content;
|
|
170
|
+
try {
|
|
171
|
+
content = readFileSync(f.absolutePath, "utf-8");
|
|
172
|
+
} catch {
|
|
173
|
+
continue;
|
|
174
|
+
}
|
|
175
|
+
const next = content.replace(pattern, (_m, q, alias) => q + targetByAlias.get(alias));
|
|
176
|
+
if (next !== content) {
|
|
177
|
+
writeFileSync(f.absolutePath, next);
|
|
178
|
+
rewritten++;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
if (rewritten > 0) {
|
|
182
|
+
console.log(`next-bun-compile: Rewrote turbopack-mangled aliases in ${rewritten} server chunks`);
|
|
183
|
+
}
|
|
172
184
|
}
|
|
173
185
|
function findServerDir(standaloneDir) {
|
|
174
186
|
if (existsSync(join(standaloneDir, "server.js"))) {
|
|
@@ -331,6 +343,7 @@ function generateEntryPoint(options) {
|
|
|
331
343
|
}));
|
|
332
344
|
const standaloneNextDir = join(serverDir, ".next");
|
|
333
345
|
const turbopackAliases = findTurbopackAliases(standaloneNextDir);
|
|
346
|
+
rewriteTurbopackAliases(standaloneNextDir, turbopackAliases);
|
|
334
347
|
const aliasNames = new Set(turbopackAliases.map((a) => a.alias));
|
|
335
348
|
const runtimeFiles = walkDir(standaloneNextDir).filter((f) => {
|
|
336
349
|
const m = f.relativePath.replace(/\\/g, "/").match(/^node_modules\/([^/]+)/);
|
|
@@ -413,7 +426,6 @@ if (Number.isNaN(keepAliveTimeout) || !Number.isFinite(keepAliveTimeout) || keep
|
|
|
413
426
|
}
|
|
414
427
|
|
|
415
428
|
const extractions = ${JSON.stringify(assetExtractions)};
|
|
416
|
-
const turbopackAliases = ${JSON.stringify(turbopackAliases.map((a) => [a.alias, a.target, a.subpaths]))};
|
|
417
429
|
async function extractAssets() {
|
|
418
430
|
let n = 0;
|
|
419
431
|
for (const [urlPath, diskPath] of extractions) {
|
|
@@ -423,34 +435,6 @@ async function extractAssets() {
|
|
|
423
435
|
const embedded = assetMap.get(urlPath);
|
|
424
436
|
if (embedded) { await Bun.write(fullPath, Bun.file(embedded)); n++; }
|
|
425
437
|
}
|
|
426
|
-
for (const [alias, target, subpaths] of turbopackAliases) {
|
|
427
|
-
const aliasPath = path.join(baseDir, ".next/node_modules", alias);
|
|
428
|
-
if (!fs.existsSync(aliasPath)) {
|
|
429
|
-
fs.mkdirSync(aliasPath, { recursive: true });
|
|
430
|
-
fs.writeFileSync(
|
|
431
|
-
path.join(aliasPath, "package.json"),
|
|
432
|
-
JSON.stringify({ name: alias, main: "index.js" })
|
|
433
|
-
);
|
|
434
|
-
// Absolute path. bun's compiled-binary resolver won't traverse "."/".."
|
|
435
|
-
// segments out of a dynamically-written shim (presumably tied to the
|
|
436
|
-
// module's original compile-time location, not its on-disk path), so
|
|
437
|
-
// a literal absolute target is the only thing that resolves reliably.
|
|
438
|
-
fs.writeFileSync(
|
|
439
|
-
path.join(aliasPath, "index.js"),
|
|
440
|
-
"module.exports = require(" + JSON.stringify(path.join(baseDir, ".next/node_modules", target)) + ");"
|
|
441
|
-
);
|
|
442
|
-
}
|
|
443
|
-
for (const sub of subpaths) {
|
|
444
|
-
const subKey = sub.replace(/\\.js$/, "");
|
|
445
|
-
const shimFile = path.join(aliasPath, subKey + ".js");
|
|
446
|
-
if (fs.existsSync(shimFile)) continue;
|
|
447
|
-
fs.mkdirSync(path.dirname(shimFile), { recursive: true });
|
|
448
|
-
fs.writeFileSync(
|
|
449
|
-
shimFile,
|
|
450
|
-
"module.exports = require(" + JSON.stringify(path.join(baseDir, ".next/node_modules", target, subKey)) + ");"
|
|
451
|
-
);
|
|
452
|
-
}
|
|
453
|
-
}
|
|
454
438
|
if (n > 0) console.log(\`Extracted \${n} assets\`);
|
|
455
439
|
}
|
|
456
440
|
|
package/dist/index.js
CHANGED