next-bun-compile 0.6.5 → 0.6.7
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-mcq5wghd.js → index-qhwqnqff.js} +55 -23
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -113,9 +113,20 @@ 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
|
+
};
|
|
116
127
|
const serverDir = join(standaloneNextDir, "server");
|
|
117
128
|
if (existsSync(serverDir)) {
|
|
118
|
-
const re = /
|
|
129
|
+
const re = /["']([^"'\s/]+-[0-9a-f]{16})(?:\/([^"'\s]+))?["']/g;
|
|
119
130
|
for (const f of walkDir(serverDir)) {
|
|
120
131
|
if (!f.absolutePath.endsWith(".js"))
|
|
121
132
|
continue;
|
|
@@ -127,31 +138,37 @@ function findTurbopackAliases(standaloneNextDir) {
|
|
|
127
138
|
}
|
|
128
139
|
let m;
|
|
129
140
|
while (m = re.exec(content)) {
|
|
130
|
-
const
|
|
131
|
-
if (
|
|
132
|
-
|
|
133
|
-
seen.set(alias, alias.replace(/-[0-9a-f]{16}$/, ""));
|
|
141
|
+
const entry = ensure(m[1]);
|
|
142
|
+
if (m[2])
|
|
143
|
+
entry.subpaths.add(m[2]);
|
|
134
144
|
}
|
|
135
145
|
}
|
|
136
146
|
}
|
|
137
147
|
const nodeModulesDir = join(standaloneNextDir, "node_modules");
|
|
138
148
|
if (existsSync(nodeModulesDir)) {
|
|
139
|
-
for (const
|
|
140
|
-
if (!/-[0-9a-f]{16}$/.test(
|
|
149
|
+
for (const name of readdirSync(nodeModulesDir)) {
|
|
150
|
+
if (!/-[0-9a-f]{16}$/.test(name))
|
|
141
151
|
continue;
|
|
142
|
-
if (seen.has(
|
|
152
|
+
if (seen.has(name))
|
|
143
153
|
continue;
|
|
144
|
-
const aliasPath = join(nodeModulesDir,
|
|
154
|
+
const aliasPath = join(nodeModulesDir, name);
|
|
145
155
|
try {
|
|
146
156
|
if (!lstatSync(aliasPath).isSymbolicLink())
|
|
147
157
|
continue;
|
|
148
|
-
seen.set(
|
|
158
|
+
seen.set(name, {
|
|
159
|
+
target: basename(realpathSync(aliasPath)),
|
|
160
|
+
subpaths: new Set
|
|
161
|
+
});
|
|
149
162
|
} catch {
|
|
150
163
|
continue;
|
|
151
164
|
}
|
|
152
165
|
}
|
|
153
166
|
}
|
|
154
|
-
return Array.from(seen, ([alias, target]) => ({
|
|
167
|
+
return Array.from(seen, ([alias, { target, subpaths }]) => ({
|
|
168
|
+
alias,
|
|
169
|
+
target,
|
|
170
|
+
subpaths: Array.from(subpaths)
|
|
171
|
+
}));
|
|
155
172
|
}
|
|
156
173
|
function findServerDir(standaloneDir) {
|
|
157
174
|
if (existsSync(join(standaloneDir, "server.js"))) {
|
|
@@ -396,7 +413,7 @@ if (Number.isNaN(keepAliveTimeout) || !Number.isFinite(keepAliveTimeout) || keep
|
|
|
396
413
|
}
|
|
397
414
|
|
|
398
415
|
const extractions = ${JSON.stringify(assetExtractions)};
|
|
399
|
-
const turbopackAliases = ${JSON.stringify(turbopackAliases.map((a) => [a.alias, a.target]))};
|
|
416
|
+
const turbopackAliases = ${JSON.stringify(turbopackAliases.map((a) => [a.alias, a.target, a.subpaths]))};
|
|
400
417
|
async function extractAssets() {
|
|
401
418
|
let n = 0;
|
|
402
419
|
for (const [urlPath, diskPath] of extractions) {
|
|
@@ -406,18 +423,33 @@ async function extractAssets() {
|
|
|
406
423
|
const embedded = assetMap.get(urlPath);
|
|
407
424
|
if (embedded) { await Bun.write(fullPath, Bun.file(embedded)); n++; }
|
|
408
425
|
}
|
|
409
|
-
for (const [alias, target] of turbopackAliases) {
|
|
426
|
+
for (const [alias, target, subpaths] of turbopackAliases) {
|
|
410
427
|
const aliasPath = path.join(baseDir, ".next/node_modules", alias);
|
|
411
|
-
if (fs.existsSync(aliasPath))
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
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
|
+
}
|
|
421
453
|
}
|
|
422
454
|
if (n > 0) console.log(\`Extracted \${n} assets\`);
|
|
423
455
|
}
|
package/dist/index.js
CHANGED