next-bun-compile 0.6.2 → 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 CHANGED
@@ -2,7 +2,7 @@
2
2
  import {
3
3
  compile,
4
4
  generateEntryPoint
5
- } from "./index-v3pyz7g9.js";
5
+ } from "./index-dxk9rwqh.js";
6
6
 
7
7
  // src/cli.ts
8
8
  import { existsSync } from "node:fs";
@@ -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,26 @@ function generateStubs(standaloneDir) {
109
111
  console.log(`next-bun-compile: Created ${count} module stubs`);
110
112
  }
111
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
+ }
112
134
  function findServerDir(standaloneDir) {
113
135
  if (existsSync(join(standaloneDir, "server.js"))) {
114
136
  return standaloneDir;
@@ -269,7 +291,12 @@ function generateEntryPoint(options) {
269
291
  urlPath: `/${f.relativePath.replace(/\\/g, "/")}`
270
292
  }));
271
293
  const standaloneNextDir = join(serverDir, ".next");
272
- const runtimeFiles = walkDir(standaloneNextDir).map((f) => ({
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) => ({
273
300
  ...f,
274
301
  urlPath: `__runtime/.next/${f.relativePath.replace(/\\/g, "/")}`
275
302
  }));
@@ -347,6 +374,7 @@ if (Number.isNaN(keepAliveTimeout) || !Number.isFinite(keepAliveTimeout) || keep
347
374
  }
348
375
 
349
376
  const extractions = ${JSON.stringify(assetExtractions)};
377
+ const turbopackAliases = ${JSON.stringify(turbopackAliases.map((a) => [a.alias, a.target]))};
350
378
  async function extractAssets() {
351
379
  let n = 0;
352
380
  for (const [urlPath, diskPath] of extractions) {
@@ -356,6 +384,24 @@ async function extractAssets() {
356
384
  const embedded = assetMap.get(urlPath);
357
385
  if (embedded) { await Bun.write(fullPath, Bun.file(embedded)); n++; }
358
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
+ }
359
405
  if (n > 0) console.log(\`Extracted \${n} assets\`);
360
406
  }
361
407
 
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@ import {
2
2
  __require,
3
3
  compile,
4
4
  generateEntryPoint
5
- } from "./index-v3pyz7g9.js";
5
+ } from "./index-dxk9rwqh.js";
6
6
 
7
7
  // src/index.ts
8
8
  import { join } from "node:path";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-bun-compile",
3
- "version": "0.6.2",
3
+ "version": "0.6.3",
4
4
  "description": "Next.js Build Adapter that compiles your app into a Bun single-file executable",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",