next-bun-compile 0.6.5 → 0.6.6

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-mcq5wghd.js";
5
+ } from "./index-c4yr0spy.js";
6
6
 
7
7
  // src/cli.ts
8
8
  import { existsSync } from "node:fs";
@@ -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 = /require\(["']([^"'\s/]+-[0-9a-f]{16})["']\)/g;
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 alias = m[1];
131
- if (seen.has(alias))
132
- continue;
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 entry of readdirSync(nodeModulesDir)) {
140
- if (!/-[0-9a-f]{16}$/.test(entry))
149
+ for (const name of readdirSync(nodeModulesDir)) {
150
+ if (!/-[0-9a-f]{16}$/.test(name))
141
151
  continue;
142
- if (seen.has(entry))
152
+ if (seen.has(name))
143
153
  continue;
144
- const aliasPath = join(nodeModulesDir, entry);
154
+ const aliasPath = join(nodeModulesDir, name);
145
155
  try {
146
156
  if (!lstatSync(aliasPath).isSymbolicLink())
147
157
  continue;
148
- seen.set(entry, basename(realpathSync(aliasPath)));
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]) => ({ 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,34 @@ 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)) continue;
412
- fs.mkdirSync(aliasPath, { recursive: true });
413
- fs.writeFileSync(
414
- path.join(aliasPath, "package.json"),
415
- JSON.stringify({ name: alias, main: "index.js" })
416
- );
417
- fs.writeFileSync(
418
- path.join(aliasPath, "index.js"),
419
- "module.exports = require(" + JSON.stringify(target) + ");"
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
+ // Relative path bypasses bun's package-name resolver, which doesn't
435
+ // walk up to the parent node_modules from inside an alias directory.
436
+ fs.writeFileSync(
437
+ path.join(aliasPath, "index.js"),
438
+ "module.exports = require(" + JSON.stringify("../" + target) + ");"
439
+ );
440
+ }
441
+ for (const sub of subpaths) {
442
+ const subKey = sub.replace(/\\.js$/, "");
443
+ const shimFile = path.join(aliasPath, subKey + ".js");
444
+ if (fs.existsSync(shimFile)) continue;
445
+ fs.mkdirSync(path.dirname(shimFile), { recursive: true });
446
+ const canonicalFile = path.join(baseDir, ".next/node_modules", target, subKey);
447
+ const rel = path.relative(path.dirname(shimFile), canonicalFile);
448
+ const spec = rel.startsWith(".") ? rel : "./" + rel;
449
+ fs.writeFileSync(
450
+ shimFile,
451
+ "module.exports = require(" + JSON.stringify(spec) + ");"
452
+ );
453
+ }
421
454
  }
422
455
  if (n > 0) console.log(\`Extracted \${n} assets\`);
423
456
  }
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@ import {
2
2
  __require,
3
3
  compile,
4
4
  generateEntryPoint
5
- } from "./index-mcq5wghd.js";
5
+ } from "./index-c4yr0spy.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.5",
3
+ "version": "0.6.6",
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",