next-bun-compile 0.6.4 → 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 +1 -1
- package/dist/{index-rh4vdfr5.js → index-c4yr0spy.js} +47 -19
- 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,21 +423,32 @@ 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
|
-
fs.mkdirSync(path.dirname(aliasPath), { recursive: true });
|
|
413
|
-
try {
|
|
414
|
-
fs.symlinkSync(target, aliasPath, "dir");
|
|
415
|
-
} catch {
|
|
428
|
+
if (!fs.existsSync(aliasPath)) {
|
|
416
429
|
fs.mkdirSync(aliasPath, { recursive: true });
|
|
417
430
|
fs.writeFileSync(
|
|
418
431
|
path.join(aliasPath, "package.json"),
|
|
419
432
|
JSON.stringify({ name: alias, main: "index.js" })
|
|
420
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.
|
|
421
436
|
fs.writeFileSync(
|
|
422
437
|
path.join(aliasPath, "index.js"),
|
|
423
|
-
"module.exports = require(" + JSON.stringify(target) + ");"
|
|
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) + ");"
|
|
424
452
|
);
|
|
425
453
|
}
|
|
426
454
|
}
|
package/dist/index.js
CHANGED