next-bun-compile 0.4.0 → 0.4.1
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 +69 -0
- package/dist/generate.js +69 -0
- package/dist/index.js +69 -0
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -80,6 +80,56 @@ let resolve = (id) => { try { return _resolve(id); } catch { return ''; } };`);
|
|
|
80
80
|
writeFileSync(hookPath, content);
|
|
81
81
|
console.log("next-bun-compile: Patched require-hook.js for compiled binary compatibility");
|
|
82
82
|
}
|
|
83
|
+
function collectExternalModules(standaloneDir) {
|
|
84
|
+
const chunksDir = join(standaloneDir, ".next/server/chunks/ssr");
|
|
85
|
+
if (!existsSync(chunksDir))
|
|
86
|
+
return [];
|
|
87
|
+
const seeds = new Set;
|
|
88
|
+
for (const entry of readdirSync(chunksDir)) {
|
|
89
|
+
if (!entry.endsWith(".js"))
|
|
90
|
+
continue;
|
|
91
|
+
const content = readFileSync(join(chunksDir, entry), "utf-8");
|
|
92
|
+
for (const match of content.matchAll(/require\("(next\/dist\/[^"]+)"\)/g)) {
|
|
93
|
+
seeds.add(match[1]);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
const deps = new Set;
|
|
97
|
+
function trace(file) {
|
|
98
|
+
if (deps.has(file))
|
|
99
|
+
return;
|
|
100
|
+
let fullPath = join(standaloneDir, "node_modules", file);
|
|
101
|
+
if (existsSync(fullPath) && statSync(fullPath).isDirectory()) {
|
|
102
|
+
const pkgJson = join(fullPath, "package.json");
|
|
103
|
+
if (existsSync(pkgJson)) {
|
|
104
|
+
deps.add(file + "/package.json");
|
|
105
|
+
}
|
|
106
|
+
file = file + "/index.js";
|
|
107
|
+
fullPath = join(standaloneDir, "node_modules", file);
|
|
108
|
+
}
|
|
109
|
+
if (!existsSync(fullPath))
|
|
110
|
+
return;
|
|
111
|
+
deps.add(file);
|
|
112
|
+
const content = readFileSync(fullPath, "utf-8");
|
|
113
|
+
for (const match of content.matchAll(/require\("([^"]+)"\)/g)) {
|
|
114
|
+
const req = match[1];
|
|
115
|
+
let resolved;
|
|
116
|
+
if (req.startsWith(".")) {
|
|
117
|
+
resolved = join(file, "..", req).replace(/\\/g, "/");
|
|
118
|
+
if (!resolved.endsWith(".js"))
|
|
119
|
+
resolved += ".js";
|
|
120
|
+
} else if (req.startsWith("next/")) {
|
|
121
|
+
resolved = req;
|
|
122
|
+
if (!resolved.endsWith(".js"))
|
|
123
|
+
resolved += ".js";
|
|
124
|
+
}
|
|
125
|
+
if (resolved)
|
|
126
|
+
trace(resolved);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
for (const seed of seeds)
|
|
130
|
+
trace(seed);
|
|
131
|
+
return [...deps];
|
|
132
|
+
}
|
|
83
133
|
function generateEntryPoint(options) {
|
|
84
134
|
const { standaloneDir, distDir, projectDir } = options;
|
|
85
135
|
generateStubs(standaloneDir);
|
|
@@ -99,6 +149,25 @@ function generateEntryPoint(options) {
|
|
|
99
149
|
...f,
|
|
100
150
|
urlPath: `__runtime/.next/${f.relativePath.replace(/\\/g, "/")}`
|
|
101
151
|
}));
|
|
152
|
+
const externalModules = collectExternalModules(standaloneDir);
|
|
153
|
+
const externalPaths = ["next/package.json", ...externalModules];
|
|
154
|
+
const externalDir = join(standaloneDir, ".next/__external");
|
|
155
|
+
for (const mod of externalPaths) {
|
|
156
|
+
const src = join(standaloneDir, "node_modules", mod);
|
|
157
|
+
if (!existsSync(src))
|
|
158
|
+
continue;
|
|
159
|
+
const dest = join(externalDir, mod);
|
|
160
|
+
mkdirSync(join(dest, ".."), { recursive: true });
|
|
161
|
+
writeFileSync(dest, readFileSync(src));
|
|
162
|
+
runtimeFiles.push({
|
|
163
|
+
absolutePath: dest,
|
|
164
|
+
relativePath: `__external/${mod}`,
|
|
165
|
+
urlPath: `__runtime/.next/node_modules/${mod.replace(/\\/g, "/")}`
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
if (externalModules.length > 0) {
|
|
169
|
+
console.log(`next-bun-compile: Embedding ${externalModules.length} external modules for SSR`);
|
|
170
|
+
}
|
|
102
171
|
const ctx = JSON.parse(readFileSync(join(distDir, "bun-compile-ctx.json"), "utf-8"));
|
|
103
172
|
const { assetPrefix } = ctx;
|
|
104
173
|
const assetsToEmbed = assetPrefix ? [...publicFiles, ...runtimeFiles] : [...staticFiles, ...publicFiles, ...runtimeFiles];
|
package/dist/generate.js
CHANGED
|
@@ -79,6 +79,56 @@ let resolve = (id) => { try { return _resolve(id); } catch { return ''; } };`);
|
|
|
79
79
|
writeFileSync(hookPath, content);
|
|
80
80
|
console.log("next-bun-compile: Patched require-hook.js for compiled binary compatibility");
|
|
81
81
|
}
|
|
82
|
+
function collectExternalModules(standaloneDir) {
|
|
83
|
+
const chunksDir = join(standaloneDir, ".next/server/chunks/ssr");
|
|
84
|
+
if (!existsSync(chunksDir))
|
|
85
|
+
return [];
|
|
86
|
+
const seeds = new Set;
|
|
87
|
+
for (const entry of readdirSync(chunksDir)) {
|
|
88
|
+
if (!entry.endsWith(".js"))
|
|
89
|
+
continue;
|
|
90
|
+
const content = readFileSync(join(chunksDir, entry), "utf-8");
|
|
91
|
+
for (const match of content.matchAll(/require\("(next\/dist\/[^"]+)"\)/g)) {
|
|
92
|
+
seeds.add(match[1]);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
const deps = new Set;
|
|
96
|
+
function trace(file) {
|
|
97
|
+
if (deps.has(file))
|
|
98
|
+
return;
|
|
99
|
+
let fullPath = join(standaloneDir, "node_modules", file);
|
|
100
|
+
if (existsSync(fullPath) && statSync(fullPath).isDirectory()) {
|
|
101
|
+
const pkgJson = join(fullPath, "package.json");
|
|
102
|
+
if (existsSync(pkgJson)) {
|
|
103
|
+
deps.add(file + "/package.json");
|
|
104
|
+
}
|
|
105
|
+
file = file + "/index.js";
|
|
106
|
+
fullPath = join(standaloneDir, "node_modules", file);
|
|
107
|
+
}
|
|
108
|
+
if (!existsSync(fullPath))
|
|
109
|
+
return;
|
|
110
|
+
deps.add(file);
|
|
111
|
+
const content = readFileSync(fullPath, "utf-8");
|
|
112
|
+
for (const match of content.matchAll(/require\("([^"]+)"\)/g)) {
|
|
113
|
+
const req = match[1];
|
|
114
|
+
let resolved;
|
|
115
|
+
if (req.startsWith(".")) {
|
|
116
|
+
resolved = join(file, "..", req).replace(/\\/g, "/");
|
|
117
|
+
if (!resolved.endsWith(".js"))
|
|
118
|
+
resolved += ".js";
|
|
119
|
+
} else if (req.startsWith("next/")) {
|
|
120
|
+
resolved = req;
|
|
121
|
+
if (!resolved.endsWith(".js"))
|
|
122
|
+
resolved += ".js";
|
|
123
|
+
}
|
|
124
|
+
if (resolved)
|
|
125
|
+
trace(resolved);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
for (const seed of seeds)
|
|
129
|
+
trace(seed);
|
|
130
|
+
return [...deps];
|
|
131
|
+
}
|
|
82
132
|
function generateEntryPoint(options) {
|
|
83
133
|
const { standaloneDir, distDir, projectDir } = options;
|
|
84
134
|
generateStubs(standaloneDir);
|
|
@@ -98,6 +148,25 @@ function generateEntryPoint(options) {
|
|
|
98
148
|
...f,
|
|
99
149
|
urlPath: `__runtime/.next/${f.relativePath.replace(/\\/g, "/")}`
|
|
100
150
|
}));
|
|
151
|
+
const externalModules = collectExternalModules(standaloneDir);
|
|
152
|
+
const externalPaths = ["next/package.json", ...externalModules];
|
|
153
|
+
const externalDir = join(standaloneDir, ".next/__external");
|
|
154
|
+
for (const mod of externalPaths) {
|
|
155
|
+
const src = join(standaloneDir, "node_modules", mod);
|
|
156
|
+
if (!existsSync(src))
|
|
157
|
+
continue;
|
|
158
|
+
const dest = join(externalDir, mod);
|
|
159
|
+
mkdirSync(join(dest, ".."), { recursive: true });
|
|
160
|
+
writeFileSync(dest, readFileSync(src));
|
|
161
|
+
runtimeFiles.push({
|
|
162
|
+
absolutePath: dest,
|
|
163
|
+
relativePath: `__external/${mod}`,
|
|
164
|
+
urlPath: `__runtime/.next/node_modules/${mod.replace(/\\/g, "/")}`
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
if (externalModules.length > 0) {
|
|
168
|
+
console.log(`next-bun-compile: Embedding ${externalModules.length} external modules for SSR`);
|
|
169
|
+
}
|
|
101
170
|
const ctx = JSON.parse(readFileSync(join(distDir, "bun-compile-ctx.json"), "utf-8"));
|
|
102
171
|
const { assetPrefix } = ctx;
|
|
103
172
|
const assetsToEmbed = assetPrefix ? [...publicFiles, ...runtimeFiles] : [...staticFiles, ...publicFiles, ...runtimeFiles];
|
package/dist/index.js
CHANGED
|
@@ -79,6 +79,56 @@ let resolve = (id) => { try { return _resolve(id); } catch { return ''; } };`);
|
|
|
79
79
|
writeFileSync(hookPath, content);
|
|
80
80
|
console.log("next-bun-compile: Patched require-hook.js for compiled binary compatibility");
|
|
81
81
|
}
|
|
82
|
+
function collectExternalModules(standaloneDir) {
|
|
83
|
+
const chunksDir = join(standaloneDir, ".next/server/chunks/ssr");
|
|
84
|
+
if (!existsSync(chunksDir))
|
|
85
|
+
return [];
|
|
86
|
+
const seeds = new Set;
|
|
87
|
+
for (const entry of readdirSync(chunksDir)) {
|
|
88
|
+
if (!entry.endsWith(".js"))
|
|
89
|
+
continue;
|
|
90
|
+
const content = readFileSync(join(chunksDir, entry), "utf-8");
|
|
91
|
+
for (const match of content.matchAll(/require\("(next\/dist\/[^"]+)"\)/g)) {
|
|
92
|
+
seeds.add(match[1]);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
const deps = new Set;
|
|
96
|
+
function trace(file) {
|
|
97
|
+
if (deps.has(file))
|
|
98
|
+
return;
|
|
99
|
+
let fullPath = join(standaloneDir, "node_modules", file);
|
|
100
|
+
if (existsSync(fullPath) && statSync(fullPath).isDirectory()) {
|
|
101
|
+
const pkgJson = join(fullPath, "package.json");
|
|
102
|
+
if (existsSync(pkgJson)) {
|
|
103
|
+
deps.add(file + "/package.json");
|
|
104
|
+
}
|
|
105
|
+
file = file + "/index.js";
|
|
106
|
+
fullPath = join(standaloneDir, "node_modules", file);
|
|
107
|
+
}
|
|
108
|
+
if (!existsSync(fullPath))
|
|
109
|
+
return;
|
|
110
|
+
deps.add(file);
|
|
111
|
+
const content = readFileSync(fullPath, "utf-8");
|
|
112
|
+
for (const match of content.matchAll(/require\("([^"]+)"\)/g)) {
|
|
113
|
+
const req = match[1];
|
|
114
|
+
let resolved;
|
|
115
|
+
if (req.startsWith(".")) {
|
|
116
|
+
resolved = join(file, "..", req).replace(/\\/g, "/");
|
|
117
|
+
if (!resolved.endsWith(".js"))
|
|
118
|
+
resolved += ".js";
|
|
119
|
+
} else if (req.startsWith("next/")) {
|
|
120
|
+
resolved = req;
|
|
121
|
+
if (!resolved.endsWith(".js"))
|
|
122
|
+
resolved += ".js";
|
|
123
|
+
}
|
|
124
|
+
if (resolved)
|
|
125
|
+
trace(resolved);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
for (const seed of seeds)
|
|
129
|
+
trace(seed);
|
|
130
|
+
return [...deps];
|
|
131
|
+
}
|
|
82
132
|
function generateEntryPoint(options) {
|
|
83
133
|
const { standaloneDir, distDir, projectDir } = options;
|
|
84
134
|
generateStubs(standaloneDir);
|
|
@@ -98,6 +148,25 @@ function generateEntryPoint(options) {
|
|
|
98
148
|
...f,
|
|
99
149
|
urlPath: `__runtime/.next/${f.relativePath.replace(/\\/g, "/")}`
|
|
100
150
|
}));
|
|
151
|
+
const externalModules = collectExternalModules(standaloneDir);
|
|
152
|
+
const externalPaths = ["next/package.json", ...externalModules];
|
|
153
|
+
const externalDir = join(standaloneDir, ".next/__external");
|
|
154
|
+
for (const mod of externalPaths) {
|
|
155
|
+
const src = join(standaloneDir, "node_modules", mod);
|
|
156
|
+
if (!existsSync(src))
|
|
157
|
+
continue;
|
|
158
|
+
const dest = join(externalDir, mod);
|
|
159
|
+
mkdirSync(join(dest, ".."), { recursive: true });
|
|
160
|
+
writeFileSync(dest, readFileSync(src));
|
|
161
|
+
runtimeFiles.push({
|
|
162
|
+
absolutePath: dest,
|
|
163
|
+
relativePath: `__external/${mod}`,
|
|
164
|
+
urlPath: `__runtime/.next/node_modules/${mod.replace(/\\/g, "/")}`
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
if (externalModules.length > 0) {
|
|
168
|
+
console.log(`next-bun-compile: Embedding ${externalModules.length} external modules for SSR`);
|
|
169
|
+
}
|
|
101
170
|
const ctx = JSON.parse(readFileSync(join(distDir, "bun-compile-ctx.json"), "utf-8"));
|
|
102
171
|
const { assetPrefix } = ctx;
|
|
103
172
|
const assetsToEmbed = assetPrefix ? [...publicFiles, ...runtimeFiles] : [...staticFiles, ...publicFiles, ...runtimeFiles];
|