@gigadrive/network-config 3.3.2 → 3.4.0
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/index.d.mts +187 -1
- package/dist/index.d.ts +187 -1
- package/dist/index.js +280 -18
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +279 -18
- package/dist/index.mjs.map +1 -1
- package/dist/nextjs-adapter.d.mts +7 -33
- package/dist/nextjs-adapter.d.ts +6 -34
- package/dist/nextjs-adapter.js +311 -21
- package/dist/nextjs-adapter.js.map +1 -1
- package/dist/nextjs-adapter.mjs +311 -22
- package/dist/nextjs-adapter.mjs.map +1 -1
- package/dist/nextjs-cache-components-handler.d.mts +20 -0
- package/dist/nextjs-cache-components-handler.d.ts +20 -0
- package/dist/nextjs-cache-components-handler.js +200 -0
- package/dist/nextjs-cache-components-handler.js.map +1 -0
- package/dist/nextjs-cache-components-handler.mjs +177 -0
- package/dist/nextjs-cache-components-handler.mjs.map +1 -0
- package/dist/nextjs-cache-handler.d.mts +12 -0
- package/dist/nextjs-cache-handler.d.ts +12 -0
- package/dist/nextjs-cache-handler.js +141 -0
- package/dist/nextjs-cache-handler.js.map +1 -0
- package/dist/nextjs-cache-handler.mjs +118 -0
- package/dist/nextjs-cache-handler.mjs.map +1 -0
- package/dist/nextjs-image-loader.d.mts +9 -0
- package/dist/nextjs-image-loader.d.ts +9 -0
- package/dist/nextjs-image-loader.js +36 -0
- package/dist/nextjs-image-loader.js.map +1 -0
- package/dist/nextjs-image-loader.mjs +15 -0
- package/dist/nextjs-image-loader.mjs.map +1 -0
- package/dist/v4/schema.json +85 -0
- package/package.json +19 -3
- package/src/v4/schema.json +85 -0
package/dist/nextjs-adapter.mjs
CHANGED
|
@@ -1,41 +1,330 @@
|
|
|
1
1
|
// src/nextjs-adapter.ts
|
|
2
|
-
import { mkdir, writeFile } from "fs/promises";
|
|
2
|
+
import { access, mkdir, stat, writeFile } from "fs/promises";
|
|
3
3
|
import path from "path";
|
|
4
|
+
import { fileURLToPath } from "url";
|
|
4
5
|
var PRODUCTION_BUILD_PHASE = "phase-production-build";
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
var runtimeDirectory = typeof __dirname === "string" ? __dirname : path.dirname(fileURLToPath(import.meta.url));
|
|
7
|
+
var runtimeModulePath = (environmentName, fileName) => process.env[environmentName] ?? path.join(runtimeDirectory, fileName);
|
|
8
|
+
var CACHE_HANDLER_PATH = () => runtimeModulePath("GIGADRIVE_NEXT_CACHE_HANDLER_PATH", "nextjs-cache-handler.js");
|
|
9
|
+
var CACHE_COMPONENTS_HANDLER_PATH = () => runtimeModulePath("GIGADRIVE_NEXT_CACHE_COMPONENTS_HANDLER_PATH", "nextjs-cache-components-handler.js");
|
|
10
|
+
var IMAGE_LOADER_PATH = () => runtimeModulePath("GIGADRIVE_NEXT_IMAGE_LOADER_PATH", "nextjs-image-loader.js");
|
|
11
|
+
var toJsonValue = (value) => {
|
|
12
|
+
const serialized = JSON.stringify(value);
|
|
13
|
+
return serialized === void 0 ? null : JSON.parse(serialized);
|
|
14
|
+
};
|
|
15
|
+
var isNext16OrNewer = (nextVersion) => {
|
|
16
|
+
const major = Number.parseInt(nextVersion.split(".")[0] ?? "", 10);
|
|
17
|
+
return Number.isFinite(major) && major >= 16;
|
|
18
|
+
};
|
|
19
|
+
var toPortableRelativePath = (from, to, allowCurrentDirectory = false) => {
|
|
20
|
+
const resolvedFrom = path.resolve(from);
|
|
21
|
+
const resolvedTo = path.resolve(path.isAbsolute(to) ? to : path.join(from, to));
|
|
22
|
+
const relativePath = path.relative(resolvedFrom, resolvedTo).replaceAll(path.sep, "/");
|
|
23
|
+
const normalized = relativePath === "" ? "." : relativePath;
|
|
24
|
+
if (!allowCurrentDirectory && normalized === "." || normalized.startsWith("/") || /^[A-Za-z]:/.test(normalized) || normalized.split("/").some((segment) => segment === "..")) {
|
|
25
|
+
throw new Error(`Next.js adapter output is outside the repository root: ${to}`);
|
|
26
|
+
}
|
|
27
|
+
return normalized;
|
|
28
|
+
};
|
|
29
|
+
var requireReadableFile = async (repoRoot, filePath) => {
|
|
30
|
+
const absolutePath = path.resolve(path.isAbsolute(filePath) ? filePath : path.join(repoRoot, filePath));
|
|
31
|
+
const portablePath = toPortableRelativePath(repoRoot, absolutePath);
|
|
32
|
+
await access(absolutePath);
|
|
33
|
+
const fileStat = await stat(absolutePath);
|
|
34
|
+
if (!fileStat.isFile()) throw new Error(`Next.js adapter output is not a readable file: ${filePath}`);
|
|
35
|
+
return portablePath;
|
|
36
|
+
};
|
|
37
|
+
var serializeFileMap = async (repoRoot, files) => {
|
|
38
|
+
const entries = await Promise.all(
|
|
39
|
+
Object.entries(files).map(async ([targetPath, sourcePath]) => [
|
|
40
|
+
toPortableRelativePath(repoRoot, targetPath),
|
|
41
|
+
await requireReadableFile(repoRoot, sourcePath)
|
|
42
|
+
])
|
|
43
|
+
);
|
|
44
|
+
return Object.fromEntries(entries);
|
|
45
|
+
};
|
|
46
|
+
var serializeRouteOutput = async (repoRoot, output) => {
|
|
47
|
+
const matchers = output.config.matchers;
|
|
48
|
+
return {
|
|
49
|
+
id: output.id,
|
|
50
|
+
type: String(output.type),
|
|
51
|
+
filePath: await requireReadableFile(repoRoot, output.filePath),
|
|
52
|
+
pathname: output.pathname,
|
|
53
|
+
sourcePage: output.sourcePage,
|
|
54
|
+
runtime: output.runtime,
|
|
55
|
+
assets: await serializeFileMap(repoRoot, output.assets),
|
|
56
|
+
...output.wasmAssets ? { wasmAssets: await serializeFileMap(repoRoot, output.wasmAssets) } : {},
|
|
57
|
+
...output.edgeRuntime ? {
|
|
58
|
+
edgeRuntime: {
|
|
59
|
+
modulePath: await requireReadableFile(repoRoot, output.edgeRuntime.modulePath),
|
|
60
|
+
entryKey: output.edgeRuntime.entryKey,
|
|
61
|
+
handlerExport: output.edgeRuntime.handlerExport
|
|
62
|
+
}
|
|
63
|
+
} : {},
|
|
64
|
+
config: {
|
|
65
|
+
maxDuration: output.config.maxDuration,
|
|
66
|
+
preferredRegion: output.config.preferredRegion,
|
|
67
|
+
env: output.config.env,
|
|
68
|
+
...matchers ? {
|
|
69
|
+
matchers: matchers.map((matcher) => ({
|
|
70
|
+
source: matcher.source,
|
|
71
|
+
sourceRegex: matcher.sourceRegex,
|
|
72
|
+
...matcher.has ? { has: toJsonValue(matcher.has) } : {},
|
|
73
|
+
...matcher.missing ? { missing: toJsonValue(matcher.missing) } : {}
|
|
74
|
+
}))
|
|
75
|
+
} : {}
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
var serializeStaticOutput = async (repoRoot, output) => ({
|
|
80
|
+
id: output.id,
|
|
81
|
+
type: "STATIC_FILE",
|
|
82
|
+
filePath: await requireReadableFile(repoRoot, output.filePath),
|
|
83
|
+
pathname: output.pathname,
|
|
84
|
+
...output.immutableHash ? { immutableHash: output.immutableHash } : {}
|
|
85
|
+
});
|
|
86
|
+
var buildEntrypointPlan = (outputs) => {
|
|
87
|
+
const byIdentity = /* @__PURE__ */ new Map();
|
|
88
|
+
const outputEntrypoints = {};
|
|
89
|
+
for (const output of outputs) {
|
|
90
|
+
const identity = JSON.stringify([
|
|
91
|
+
output.runtime,
|
|
92
|
+
output.filePath,
|
|
93
|
+
output.edgeRuntime?.modulePath,
|
|
94
|
+
output.edgeRuntime?.entryKey,
|
|
95
|
+
output.edgeRuntime?.handlerExport
|
|
96
|
+
]);
|
|
97
|
+
const existingEntrypoint = byIdentity.get(identity);
|
|
98
|
+
const entrypoint = existingEntrypoint ?? {
|
|
99
|
+
id: `next-${byIdentity.size}`,
|
|
100
|
+
runtime: output.runtime,
|
|
101
|
+
filePath: output.filePath,
|
|
102
|
+
outputIds: [],
|
|
103
|
+
assets: { ...output.assets },
|
|
104
|
+
...output.wasmAssets ? { wasmAssets: { ...output.wasmAssets } } : {},
|
|
105
|
+
...output.edgeRuntime ? { edgeRuntime: { ...output.edgeRuntime } } : {},
|
|
106
|
+
config: {
|
|
107
|
+
maxDuration: output.config.maxDuration,
|
|
108
|
+
preferredRegion: output.config.preferredRegion,
|
|
109
|
+
env: output.config.env
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
if (!existingEntrypoint) {
|
|
113
|
+
byIdentity.set(identity, entrypoint);
|
|
114
|
+
} else {
|
|
115
|
+
Object.assign(entrypoint.assets, output.assets);
|
|
116
|
+
if (output.wasmAssets) entrypoint.wasmAssets = { ...entrypoint.wasmAssets, ...output.wasmAssets };
|
|
117
|
+
if (output.config.maxDuration !== void 0) {
|
|
118
|
+
entrypoint.config.maxDuration = Math.max(entrypoint.config.maxDuration ?? 0, output.config.maxDuration);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
entrypoint.outputIds.push(output.id);
|
|
122
|
+
outputEntrypoints[output.id] = entrypoint.id;
|
|
123
|
+
}
|
|
124
|
+
return { entrypoints: [...byIdentity.values()], outputEntrypoints };
|
|
125
|
+
};
|
|
126
|
+
var writeEntrypointWrappers = async (projectDir, repoRoot, entrypoints) => {
|
|
127
|
+
const wrapperDirectory = path.join(projectDir, ".gigadrive", "nextjs", "entrypoints");
|
|
128
|
+
await mkdir(wrapperDirectory, { recursive: true });
|
|
129
|
+
await Promise.all(
|
|
130
|
+
entrypoints.map(async (entrypoint) => {
|
|
131
|
+
const wrapperPath = path.join(wrapperDirectory, `${entrypoint.id}.mjs`);
|
|
132
|
+
const executablePath = path.join(repoRoot, entrypoint.edgeRuntime?.modulePath ?? entrypoint.filePath);
|
|
133
|
+
const relativeImport = path.relative(wrapperDirectory, executablePath).replaceAll(path.sep, "/");
|
|
134
|
+
const importSpecifier = relativeImport.startsWith(".") ? relativeImport : `./${relativeImport}`;
|
|
135
|
+
const source = entrypoint.runtime === "edge" && entrypoint.edgeRuntime ? `import ${JSON.stringify(importSpecifier)};
|
|
136
|
+
|
|
137
|
+
export async function fetch(request) {
|
|
138
|
+
const pending = [];
|
|
139
|
+
const registry = globalThis._ENTRIES;
|
|
140
|
+
if (!registry) throw new Error('Next.js edge entry registry is unavailable');
|
|
141
|
+
const entry = await registry[${JSON.stringify(entrypoint.edgeRuntime.entryKey)}];
|
|
142
|
+
const handler = entry?.[${JSON.stringify(entrypoint.edgeRuntime.handlerExport)}];
|
|
143
|
+
if (typeof handler !== 'function') throw new Error('Next.js edge handler is unavailable');
|
|
144
|
+
const url = new URL(request.url);
|
|
145
|
+
const response = await handler(request, {
|
|
146
|
+
signal: request.signal,
|
|
147
|
+
waitUntil(promise) { pending.push(Promise.resolve(promise)); },
|
|
148
|
+
requestMeta: { hostname: url.hostname, invocationTarget: request.headers.get('x-gigadrive-next-invocation-target') ?? url.pathname, routeMatches: Object.fromEntries(new URLSearchParams(request.headers.get('x-now-route-matches') ?? '')), relativeProjectDir: ${JSON.stringify(
|
|
149
|
+
toPortableRelativePath(repoRoot, projectDir, true)
|
|
150
|
+
)} },
|
|
151
|
+
});
|
|
152
|
+
if (!response.body) { await Promise.allSettled(pending); return response; }
|
|
153
|
+
const reader = response.body.getReader();
|
|
154
|
+
const body = new ReadableStream({
|
|
155
|
+
async pull(controller) {
|
|
156
|
+
const result = await reader.read();
|
|
157
|
+
if (result.done) { await Promise.allSettled(pending); controller.close(); return; }
|
|
158
|
+
controller.enqueue(result.value);
|
|
159
|
+
},
|
|
160
|
+
cancel(reason) { return reader.cancel(reason); },
|
|
161
|
+
});
|
|
162
|
+
return new Response(body, response);
|
|
163
|
+
}
|
|
164
|
+
` : `import * as nextEntrypoint from ${JSON.stringify(importSpecifier)};
|
|
165
|
+
|
|
166
|
+
export default async function handler(req, res) {
|
|
167
|
+
const pending = [];
|
|
168
|
+
const nextHandler = nextEntrypoint.handler ?? nextEntrypoint.default?.handler ?? nextEntrypoint.default;
|
|
169
|
+
if (typeof nextHandler !== 'function') throw new Error('Next.js Node handler is unavailable');
|
|
170
|
+
await nextHandler(req, res, {
|
|
171
|
+
waitUntil(promise) { pending.push(Promise.resolve(promise)); },
|
|
172
|
+
requestMeta: { hostname: req.headers.host, invocationTarget: req.headers['x-gigadrive-next-invocation-target'] ?? req.url, routeMatches: Object.fromEntries(new URLSearchParams(req.headers['x-now-route-matches'] ?? '')), relativeProjectDir: ${JSON.stringify(
|
|
173
|
+
toPortableRelativePath(repoRoot, projectDir, true)
|
|
174
|
+
)} },
|
|
175
|
+
});
|
|
176
|
+
await Promise.allSettled(pending);
|
|
177
|
+
}
|
|
178
|
+
`;
|
|
179
|
+
await writeFile(wrapperPath, source, "utf8");
|
|
180
|
+
const portableWrapperPath = toPortableRelativePath(repoRoot, wrapperPath);
|
|
181
|
+
entrypoint.assets[portableWrapperPath] = portableWrapperPath;
|
|
182
|
+
entrypoint.filePath = portableWrapperPath;
|
|
183
|
+
})
|
|
184
|
+
);
|
|
185
|
+
};
|
|
186
|
+
var normalizeImages = (config) => {
|
|
187
|
+
if (config.images.unoptimized) return void 0;
|
|
188
|
+
return {
|
|
189
|
+
localPatterns: config.images.localPatterns ?? [{ pathname: "/**" }],
|
|
190
|
+
remotePatterns: config.images.remotePatterns.map((pattern) => {
|
|
191
|
+
if (pattern instanceof URL) {
|
|
192
|
+
return {
|
|
193
|
+
protocol: pattern.protocol === "http:" ? "http" : "https",
|
|
194
|
+
hostname: pattern.hostname,
|
|
195
|
+
port: pattern.port,
|
|
196
|
+
pathname: pattern.pathname,
|
|
197
|
+
search: pattern.search
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
return { ...pattern };
|
|
201
|
+
}),
|
|
202
|
+
widths: [.../* @__PURE__ */ new Set([...config.images.deviceSizes, ...config.images.imageSizes])].sort((a, b) => a - b),
|
|
203
|
+
heights: [],
|
|
204
|
+
qualities: config.images.qualities ?? [75],
|
|
205
|
+
formats: config.images.formats,
|
|
206
|
+
minimumCacheTTL: config.images.minimumCacheTTL,
|
|
207
|
+
dangerouslyAllowSVG: config.images.dangerouslyAllowSVG,
|
|
208
|
+
contentSecurityPolicy: config.images.contentSecurityPolicy,
|
|
209
|
+
contentDispositionType: config.images.contentDispositionType,
|
|
210
|
+
maximumRedirects: config.images.maximumRedirects,
|
|
211
|
+
maximumResponseBody: config.images.maximumResponseBody,
|
|
212
|
+
variants: {}
|
|
213
|
+
};
|
|
8
214
|
};
|
|
9
215
|
var gigadriveNextAdapter = {
|
|
10
216
|
name: "Gigadrive Network",
|
|
11
|
-
modifyConfig(config, { phase }) {
|
|
12
|
-
if (phase !== PRODUCTION_BUILD_PHASE)
|
|
13
|
-
return config;
|
|
14
|
-
}
|
|
217
|
+
modifyConfig(config, { phase, nextVersion }) {
|
|
218
|
+
if (phase !== PRODUCTION_BUILD_PHASE) return config;
|
|
15
219
|
const deploymentId = config.deploymentId ?? process.env.GIGADRIVE_DEPLOYMENT_ID;
|
|
220
|
+
if (!isNext16OrNewer(nextVersion)) {
|
|
221
|
+
return {
|
|
222
|
+
...config,
|
|
223
|
+
...deploymentId ? { deploymentId } : {},
|
|
224
|
+
output: config.output === "export" ? "export" : "standalone"
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
if (config.output === "export") {
|
|
228
|
+
return { ...config, ...deploymentId ? { deploymentId } : {} };
|
|
229
|
+
}
|
|
230
|
+
const injectCacheHandler = config.cacheHandler === void 0;
|
|
231
|
+
const injectCacheComponentHandlers = config.cacheHandlers === void 0;
|
|
232
|
+
const images = config.images;
|
|
233
|
+
const injectImageLoader = images !== void 0 && images.unoptimized !== true && images.loader === "default" && !images.loaderFile;
|
|
16
234
|
return {
|
|
17
235
|
...config,
|
|
18
236
|
...deploymentId ? { deploymentId } : {},
|
|
19
|
-
|
|
237
|
+
...injectCacheHandler ? { cacheHandler: CACHE_HANDLER_PATH() } : {},
|
|
238
|
+
...injectCacheComponentHandlers ? {
|
|
239
|
+
cacheHandlers: {
|
|
240
|
+
default: CACHE_COMPONENTS_HANDLER_PATH(),
|
|
241
|
+
remote: CACHE_COMPONENTS_HANDLER_PATH()
|
|
242
|
+
}
|
|
243
|
+
} : {},
|
|
244
|
+
...injectCacheHandler || injectCacheComponentHandlers ? { cacheMaxMemorySize: 0 } : {},
|
|
245
|
+
...injectImageLoader ? {
|
|
246
|
+
images: {
|
|
247
|
+
...images,
|
|
248
|
+
loader: "custom",
|
|
249
|
+
loaderFile: IMAGE_LOADER_PATH()
|
|
250
|
+
}
|
|
251
|
+
} : {}
|
|
20
252
|
};
|
|
21
253
|
},
|
|
22
|
-
async onBuildComplete({
|
|
23
|
-
projectDir,
|
|
24
|
-
repoRoot,
|
|
25
|
-
distDir,
|
|
26
|
-
config,
|
|
27
|
-
nextVersion,
|
|
28
|
-
buildId
|
|
29
|
-
}) {
|
|
30
|
-
const output = config.output === "export" ? "export" : "standalone";
|
|
254
|
+
async onBuildComplete({ projectDir, repoRoot, distDir, config, nextVersion, buildId, routing, outputs }) {
|
|
31
255
|
const metadataDirectory = path.join(projectDir, ".gigadrive");
|
|
256
|
+
const portableOutputs = {
|
|
257
|
+
pages: await Promise.all(outputs.pages.map((output) => serializeRouteOutput(repoRoot, output))),
|
|
258
|
+
...outputs.middleware ? { middleware: await serializeRouteOutput(repoRoot, outputs.middleware) } : {},
|
|
259
|
+
appPages: await Promise.all(outputs.appPages.map((output) => serializeRouteOutput(repoRoot, output))),
|
|
260
|
+
pagesApi: await Promise.all(outputs.pagesApi.map((output) => serializeRouteOutput(repoRoot, output))),
|
|
261
|
+
appRoutes: await Promise.all(outputs.appRoutes.map((output) => serializeRouteOutput(repoRoot, output))),
|
|
262
|
+
prerenders: await Promise.all(
|
|
263
|
+
outputs.prerenders.map(async (output) => {
|
|
264
|
+
const { bypassFor, ...prerenderConfig } = output.config;
|
|
265
|
+
return {
|
|
266
|
+
id: output.id,
|
|
267
|
+
type: "PRERENDER",
|
|
268
|
+
pathname: output.pathname,
|
|
269
|
+
parentOutputId: output.parentOutputId,
|
|
270
|
+
groupId: output.groupId,
|
|
271
|
+
...output.pprChain ? { pprChain: output.pprChain } : {},
|
|
272
|
+
...output.parentFallbackMode !== void 0 ? { parentFallbackMode: toJsonValue(output.parentFallbackMode) } : {},
|
|
273
|
+
...output.fallback ? {
|
|
274
|
+
fallback: {
|
|
275
|
+
...output.fallback.filePath ? { filePath: await requireReadableFile(repoRoot, output.fallback.filePath) } : {},
|
|
276
|
+
...output.fallback.initialStatus !== void 0 ? { initialStatus: output.fallback.initialStatus } : {},
|
|
277
|
+
...output.fallback.initialHeaders ? { initialHeaders: output.fallback.initialHeaders } : {},
|
|
278
|
+
...output.fallback.initialExpiration !== void 0 ? { initialExpiration: output.fallback.initialExpiration } : {},
|
|
279
|
+
...output.fallback.initialRevalidate !== void 0 ? { initialRevalidate: output.fallback.initialRevalidate } : {},
|
|
280
|
+
...output.fallback.postponedState !== void 0 ? { postponedState: output.fallback.postponedState } : {}
|
|
281
|
+
}
|
|
282
|
+
} : {},
|
|
283
|
+
config: {
|
|
284
|
+
...prerenderConfig,
|
|
285
|
+
...bypassFor ? { bypassFor: toJsonValue(bypassFor) } : {}
|
|
286
|
+
}
|
|
287
|
+
};
|
|
288
|
+
})
|
|
289
|
+
),
|
|
290
|
+
staticFiles: await Promise.all(outputs.staticFiles.map((output) => serializeStaticOutput(repoRoot, output)))
|
|
291
|
+
};
|
|
292
|
+
const executableOutputs = [
|
|
293
|
+
...portableOutputs.pages,
|
|
294
|
+
...portableOutputs.pagesApi,
|
|
295
|
+
...portableOutputs.appPages,
|
|
296
|
+
...portableOutputs.appRoutes,
|
|
297
|
+
...portableOutputs.middleware ? [portableOutputs.middleware] : []
|
|
298
|
+
];
|
|
299
|
+
const entrypointPlan = buildEntrypointPlan(executableOutputs);
|
|
300
|
+
await writeEntrypointWrappers(projectDir, repoRoot, entrypointPlan.entrypoints);
|
|
301
|
+
const images = normalizeImages(config);
|
|
32
302
|
const manifest = {
|
|
33
|
-
version:
|
|
34
|
-
output,
|
|
303
|
+
version: 2,
|
|
304
|
+
mode: config.output === "export" ? "export" : "adapter-v2",
|
|
35
305
|
distDir: toPortableRelativePath(projectDir, distDir),
|
|
36
|
-
repoRootToProject: toPortableRelativePath(repoRoot, projectDir),
|
|
306
|
+
repoRootToProject: toPortableRelativePath(repoRoot, projectDir, true),
|
|
37
307
|
nextVersion,
|
|
38
|
-
buildId
|
|
308
|
+
buildId,
|
|
309
|
+
config: {
|
|
310
|
+
basePath: config.basePath,
|
|
311
|
+
trailingSlash: config.trailingSlash,
|
|
312
|
+
cacheComponents: config.cacheComponents,
|
|
313
|
+
...config.i18n ? { i18n: toJsonValue(config.i18n) } : {},
|
|
314
|
+
...images ? { images } : {}
|
|
315
|
+
},
|
|
316
|
+
routing: {
|
|
317
|
+
beforeMiddleware: toJsonValue(routing.beforeMiddleware),
|
|
318
|
+
beforeFiles: toJsonValue(routing.beforeFiles),
|
|
319
|
+
afterFiles: toJsonValue(routing.afterFiles),
|
|
320
|
+
dynamicRoutes: toJsonValue(routing.dynamicRoutes),
|
|
321
|
+
onMatch: toJsonValue(routing.onMatch),
|
|
322
|
+
fallback: toJsonValue(routing.fallback),
|
|
323
|
+
shouldNormalizeNextData: routing.shouldNormalizeNextData,
|
|
324
|
+
rsc: toJsonValue(routing.rsc)
|
|
325
|
+
},
|
|
326
|
+
outputs: portableOutputs,
|
|
327
|
+
...entrypointPlan
|
|
39
328
|
};
|
|
40
329
|
await mkdir(metadataDirectory, { recursive: true });
|
|
41
330
|
await writeFile(path.join(metadataDirectory, "nextjs.json"), `${JSON.stringify(manifest, null, 2)}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/nextjs-adapter.ts"],"sourcesContent":["import { mkdir, writeFile } from 'node:fs/promises';\nimport path from 'node:path';\n\ninterface NextConfig {\n output?: string;\n [key: string]: unknown;\n}\n\ninterface ModifyConfigContext {\n phase: string;\n nextVersion: string;\n}\n\ninterface BuildCompleteContext {\n projectDir: string;\n repoRoot: string;\n distDir: string;\n config: NextConfig;\n nextVersion: string;\n buildId: string;\n}\n\nexport interface GigadriveNextBuildManifest {\n version: 1;\n output: 'standalone' | 'export';\n distDir: string;\n repoRootToProject: string;\n nextVersion: string;\n buildId: string;\n}\n\nconst PRODUCTION_BUILD_PHASE = 'phase-production-build';\n\nconst toPortableRelativePath = (from: string, to: string): string => {\n const relativePath = path.relative(from, to).replaceAll(path.sep, '/');\n return relativePath === '' ? '.' : relativePath;\n};\n\n/**\n * Next.js build adapter used automatically by Gigadrive Network build workers.\n *\n * It requests standalone output without changing user-owned Next.js config and\n * records the resolved build paths for post-build Network framework detection.\n */\nconst gigadriveNextAdapter = {\n name: 'Gigadrive Network',\n\n modifyConfig(config: NextConfig, { phase }: ModifyConfigContext): NextConfig {\n if (phase !== PRODUCTION_BUILD_PHASE) {\n return config;\n }\n\n const deploymentId = config.deploymentId ?? process.env.GIGADRIVE_DEPLOYMENT_ID;\n\n return {\n ...config,\n ...(deploymentId ? { deploymentId } : {}),\n output: config.output === 'export' ? 'export' : 'standalone',\n };\n },\n\n async onBuildComplete({\n projectDir,\n repoRoot,\n distDir,\n config,\n nextVersion,\n buildId,\n }: BuildCompleteContext): Promise<void> {\n const output = config.output === 'export' ? 'export' : 'standalone';\n const metadataDirectory = path.join(projectDir, '.gigadrive');\n const manifest: GigadriveNextBuildManifest = {\n version: 1,\n output,\n distDir: toPortableRelativePath(projectDir, distDir),\n repoRootToProject: toPortableRelativePath(repoRoot, projectDir),\n nextVersion,\n buildId,\n };\n\n await mkdir(metadataDirectory, { recursive: true });\n await writeFile(path.join(metadataDirectory, 'nextjs.json'), `${JSON.stringify(manifest, null, 2)}\\n`, 'utf8');\n },\n};\n\nexport default gigadriveNextAdapter;\n"],"mappings":";AAAA,SAAS,OAAO,iBAAiB;AACjC,OAAO,UAAU;AA8BjB,IAAM,yBAAyB;AAE/B,IAAM,yBAAyB,CAAC,MAAc,OAAuB;AACnE,QAAM,eAAe,KAAK,SAAS,MAAM,EAAE,EAAE,WAAW,KAAK,KAAK,GAAG;AACrE,SAAO,iBAAiB,KAAK,MAAM;AACrC;AAQA,IAAM,uBAAuB;AAAA,EAC3B,MAAM;AAAA,EAEN,aAAa,QAAoB,EAAE,MAAM,GAAoC;AAC3E,QAAI,UAAU,wBAAwB;AACpC,aAAO;AAAA,IACT;AAEA,UAAM,eAAe,OAAO,gBAAgB,QAAQ,IAAI;AAExD,WAAO;AAAA,MACL,GAAG;AAAA,MACH,GAAI,eAAe,EAAE,aAAa,IAAI,CAAC;AAAA,MACvC,QAAQ,OAAO,WAAW,WAAW,WAAW;AAAA,IAClD;AAAA,EACF;AAAA,EAEA,MAAM,gBAAgB;AAAA,IACpB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,GAAwC;AACtC,UAAM,SAAS,OAAO,WAAW,WAAW,WAAW;AACvD,UAAM,oBAAoB,KAAK,KAAK,YAAY,YAAY;AAC5D,UAAM,WAAuC;AAAA,MAC3C,SAAS;AAAA,MACT;AAAA,MACA,SAAS,uBAAuB,YAAY,OAAO;AAAA,MACnD,mBAAmB,uBAAuB,UAAU,UAAU;AAAA,MAC9D;AAAA,MACA;AAAA,IACF;AAEA,UAAM,MAAM,mBAAmB,EAAE,WAAW,KAAK,CAAC;AAClD,UAAM,UAAU,KAAK,KAAK,mBAAmB,aAAa,GAAG,GAAG,KAAK,UAAU,UAAU,MAAM,CAAC,CAAC;AAAA,GAAM,MAAM;AAAA,EAC/G;AACF;AAEA,IAAO,yBAAQ;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/nextjs-adapter.ts"],"sourcesContent":["import type { NextAdapter } from 'next';\nimport { access, mkdir, stat, writeFile } from 'node:fs/promises';\nimport path from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport type { NormalizedImagePolicy } from './image-policy';\nimport type {\n GigadriveNextBuildManifestV2,\n GigadriveNextEntrypoint,\n GigadriveNextRouteOutput,\n GigadriveNextStaticOutput,\n JsonValue,\n} from './nextjs-manifest';\n\ntype BuildCompleteContext = Parameters<NonNullable<NextAdapter['onBuildComplete']>>[0];\ntype NextRouteOutput =\n | BuildCompleteContext['outputs']['pages'][number]\n | BuildCompleteContext['outputs']['pagesApi'][number]\n | BuildCompleteContext['outputs']['appPages'][number]\n | BuildCompleteContext['outputs']['appRoutes'][number]\n | NonNullable<BuildCompleteContext['outputs']['middleware']>;\ntype NextStaticOutput = BuildCompleteContext['outputs']['staticFiles'][number];\n\nconst PRODUCTION_BUILD_PHASE = 'phase-production-build';\nconst runtimeDirectory = typeof __dirname === 'string' ? __dirname : path.dirname(fileURLToPath(import.meta.url));\n\nconst runtimeModulePath = (environmentName: string, fileName: string): string =>\n process.env[environmentName] ?? path.join(runtimeDirectory, fileName);\n\nconst CACHE_HANDLER_PATH = () => runtimeModulePath('GIGADRIVE_NEXT_CACHE_HANDLER_PATH', 'nextjs-cache-handler.js');\nconst CACHE_COMPONENTS_HANDLER_PATH = () =>\n runtimeModulePath('GIGADRIVE_NEXT_CACHE_COMPONENTS_HANDLER_PATH', 'nextjs-cache-components-handler.js');\nconst IMAGE_LOADER_PATH = () => runtimeModulePath('GIGADRIVE_NEXT_IMAGE_LOADER_PATH', 'nextjs-image-loader.js');\n\nconst toJsonValue = (value: unknown): JsonValue => {\n const serialized = JSON.stringify(value);\n return serialized === undefined ? null : (JSON.parse(serialized) as JsonValue);\n};\n\nconst isNext16OrNewer = (nextVersion: string): boolean => {\n const major = Number.parseInt(nextVersion.split('.')[0] ?? '', 10);\n return Number.isFinite(major) && major >= 16;\n};\n\nconst toPortableRelativePath = (from: string, to: string, allowCurrentDirectory = false): string => {\n const resolvedFrom = path.resolve(from);\n const resolvedTo = path.resolve(path.isAbsolute(to) ? to : path.join(from, to));\n const relativePath = path.relative(resolvedFrom, resolvedTo).replaceAll(path.sep, '/');\n const normalized = relativePath === '' ? '.' : relativePath;\n if (\n (!allowCurrentDirectory && normalized === '.') ||\n normalized.startsWith('/') ||\n /^[A-Za-z]:/.test(normalized) ||\n normalized.split('/').some((segment) => segment === '..')\n ) {\n throw new Error(`Next.js adapter output is outside the repository root: ${to}`);\n }\n return normalized;\n};\n\nconst requireReadableFile = async (repoRoot: string, filePath: string): Promise<string> => {\n const absolutePath = path.resolve(path.isAbsolute(filePath) ? filePath : path.join(repoRoot, filePath));\n const portablePath = toPortableRelativePath(repoRoot, absolutePath);\n await access(absolutePath);\n const fileStat = await stat(absolutePath);\n if (!fileStat.isFile()) throw new Error(`Next.js adapter output is not a readable file: ${filePath}`);\n return portablePath;\n};\n\nconst serializeFileMap = async (repoRoot: string, files: Record<string, string>): Promise<Record<string, string>> => {\n const entries = await Promise.all(\n Object.entries(files).map(async ([targetPath, sourcePath]) => [\n toPortableRelativePath(repoRoot, targetPath),\n await requireReadableFile(repoRoot, sourcePath),\n ])\n );\n return Object.fromEntries(entries);\n};\n\nconst serializeRouteOutput = async (repoRoot: string, output: NextRouteOutput): Promise<GigadriveNextRouteOutput> => {\n const matchers = (\n output.config as typeof output.config & {\n matchers?: Array<{\n source: string;\n sourceRegex: string;\n has?: unknown[];\n missing?: unknown[];\n }>;\n }\n ).matchers;\n return {\n id: output.id,\n type: String(output.type) as GigadriveNextRouteOutput['type'],\n filePath: await requireReadableFile(repoRoot, output.filePath),\n pathname: output.pathname,\n sourcePage: output.sourcePage,\n runtime: output.runtime,\n assets: await serializeFileMap(repoRoot, output.assets),\n ...(output.wasmAssets ? { wasmAssets: await serializeFileMap(repoRoot, output.wasmAssets) } : {}),\n ...(output.edgeRuntime\n ? {\n edgeRuntime: {\n modulePath: await requireReadableFile(repoRoot, output.edgeRuntime.modulePath),\n entryKey: output.edgeRuntime.entryKey,\n handlerExport: output.edgeRuntime.handlerExport,\n },\n }\n : {}),\n config: {\n maxDuration: output.config.maxDuration,\n preferredRegion: output.config.preferredRegion,\n env: output.config.env,\n ...(matchers\n ? {\n matchers: matchers.map((matcher) => ({\n source: matcher.source,\n sourceRegex: matcher.sourceRegex,\n ...(matcher.has ? { has: toJsonValue(matcher.has) as JsonValue[] } : {}),\n ...(matcher.missing ? { missing: toJsonValue(matcher.missing) as JsonValue[] } : {}),\n })),\n }\n : {}),\n },\n };\n};\n\nconst serializeStaticOutput = async (\n repoRoot: string,\n output: NextStaticOutput\n): Promise<GigadriveNextStaticOutput> => ({\n id: output.id,\n type: 'STATIC_FILE',\n filePath: await requireReadableFile(repoRoot, output.filePath),\n pathname: output.pathname,\n ...(output.immutableHash ? { immutableHash: output.immutableHash } : {}),\n});\n\nconst buildEntrypointPlan = (\n outputs: GigadriveNextRouteOutput[]\n): Pick<GigadriveNextBuildManifestV2, 'entrypoints' | 'outputEntrypoints'> => {\n const byIdentity = new Map<string, GigadriveNextEntrypoint>();\n const outputEntrypoints: Record<string, string> = {};\n\n for (const output of outputs) {\n const identity = JSON.stringify([\n output.runtime,\n output.filePath,\n output.edgeRuntime?.modulePath,\n output.edgeRuntime?.entryKey,\n output.edgeRuntime?.handlerExport,\n ]);\n const existingEntrypoint = byIdentity.get(identity);\n const entrypoint: GigadriveNextEntrypoint = existingEntrypoint ?? {\n id: `next-${byIdentity.size}`,\n runtime: output.runtime,\n filePath: output.filePath,\n outputIds: [],\n assets: { ...output.assets },\n ...(output.wasmAssets ? { wasmAssets: { ...output.wasmAssets } } : {}),\n ...(output.edgeRuntime ? { edgeRuntime: { ...output.edgeRuntime } } : {}),\n config: {\n maxDuration: output.config.maxDuration,\n preferredRegion: output.config.preferredRegion,\n env: output.config.env,\n },\n };\n if (!existingEntrypoint) {\n byIdentity.set(identity, entrypoint);\n } else {\n Object.assign(entrypoint.assets, output.assets);\n if (output.wasmAssets) entrypoint.wasmAssets = { ...entrypoint.wasmAssets, ...output.wasmAssets };\n if (output.config.maxDuration !== undefined) {\n entrypoint.config.maxDuration = Math.max(entrypoint.config.maxDuration ?? 0, output.config.maxDuration);\n }\n }\n entrypoint.outputIds.push(output.id);\n outputEntrypoints[output.id] = entrypoint.id;\n }\n\n return { entrypoints: [...byIdentity.values()], outputEntrypoints };\n};\n\nconst writeEntrypointWrappers = async (\n projectDir: string,\n repoRoot: string,\n entrypoints: GigadriveNextEntrypoint[]\n): Promise<void> => {\n const wrapperDirectory = path.join(projectDir, '.gigadrive', 'nextjs', 'entrypoints');\n await mkdir(wrapperDirectory, { recursive: true });\n\n await Promise.all(\n entrypoints.map(async (entrypoint) => {\n const wrapperPath = path.join(wrapperDirectory, `${entrypoint.id}.mjs`);\n const executablePath = path.join(repoRoot, entrypoint.edgeRuntime?.modulePath ?? entrypoint.filePath);\n const relativeImport = path.relative(wrapperDirectory, executablePath).replaceAll(path.sep, '/');\n const importSpecifier = relativeImport.startsWith('.') ? relativeImport : `./${relativeImport}`;\n const source =\n entrypoint.runtime === 'edge' && entrypoint.edgeRuntime\n ? `import ${JSON.stringify(importSpecifier)};\\n\\nexport async function fetch(request) {\\n const pending = [];\\n const registry = globalThis._ENTRIES;\\n if (!registry) throw new Error('Next.js edge entry registry is unavailable');\\n const entry = await registry[${JSON.stringify(entrypoint.edgeRuntime.entryKey)}];\\n const handler = entry?.[${JSON.stringify(entrypoint.edgeRuntime.handlerExport)}];\\n if (typeof handler !== 'function') throw new Error('Next.js edge handler is unavailable');\\n const url = new URL(request.url);\\n const response = await handler(request, {\\n signal: request.signal,\\n waitUntil(promise) { pending.push(Promise.resolve(promise)); },\\n requestMeta: { hostname: url.hostname, invocationTarget: request.headers.get('x-gigadrive-next-invocation-target') ?? url.pathname, routeMatches: Object.fromEntries(new URLSearchParams(request.headers.get('x-now-route-matches') ?? '')), relativeProjectDir: ${JSON.stringify(\n toPortableRelativePath(repoRoot, projectDir, true)\n )} },\\n });\\n if (!response.body) { await Promise.allSettled(pending); return response; }\\n const reader = response.body.getReader();\\n const body = new ReadableStream({\\n async pull(controller) {\\n const result = await reader.read();\\n if (result.done) { await Promise.allSettled(pending); controller.close(); return; }\\n controller.enqueue(result.value);\\n },\\n cancel(reason) { return reader.cancel(reason); },\\n });\\n return new Response(body, response);\\n}\\n`\n : `import * as nextEntrypoint from ${JSON.stringify(importSpecifier)};\\n\\nexport default async function handler(req, res) {\\n const pending = [];\\n const nextHandler = nextEntrypoint.handler ?? nextEntrypoint.default?.handler ?? nextEntrypoint.default;\\n if (typeof nextHandler !== 'function') throw new Error('Next.js Node handler is unavailable');\\n await nextHandler(req, res, {\\n waitUntil(promise) { pending.push(Promise.resolve(promise)); },\\n requestMeta: { hostname: req.headers.host, invocationTarget: req.headers['x-gigadrive-next-invocation-target'] ?? req.url, routeMatches: Object.fromEntries(new URLSearchParams(req.headers['x-now-route-matches'] ?? '')), relativeProjectDir: ${JSON.stringify(\n toPortableRelativePath(repoRoot, projectDir, true)\n )} },\\n });\\n await Promise.allSettled(pending);\\n}\\n`;\n await writeFile(wrapperPath, source, 'utf8');\n const portableWrapperPath = toPortableRelativePath(repoRoot, wrapperPath);\n entrypoint.assets[portableWrapperPath] = portableWrapperPath;\n entrypoint.filePath = portableWrapperPath;\n })\n );\n};\n\nconst normalizeImages = (config: BuildCompleteContext['config']): NormalizedImagePolicy | undefined => {\n if (config.images.unoptimized) return undefined;\n return {\n localPatterns: config.images.localPatterns ?? [{ pathname: '/**' }],\n remotePatterns: config.images.remotePatterns.map((pattern) => {\n if (pattern instanceof URL) {\n return {\n protocol: pattern.protocol === 'http:' ? ('http' as const) : ('https' as const),\n hostname: pattern.hostname,\n port: pattern.port,\n pathname: pattern.pathname,\n search: pattern.search,\n };\n }\n return { ...pattern };\n }),\n widths: [...new Set([...config.images.deviceSizes, ...config.images.imageSizes])].sort((a, b) => a - b),\n heights: [],\n qualities: config.images.qualities ?? [75],\n formats: config.images.formats,\n minimumCacheTTL: config.images.minimumCacheTTL,\n dangerouslyAllowSVG: config.images.dangerouslyAllowSVG,\n contentSecurityPolicy: config.images.contentSecurityPolicy,\n contentDispositionType: config.images.contentDispositionType,\n maximumRedirects: config.images.maximumRedirects,\n maximumResponseBody: config.images.maximumResponseBody,\n variants: {},\n };\n};\n\n/**\n * Next.js deployment adapter used automatically by Gigadrive Network build workers.\n *\n * Next 16 emits a portable, versioned runtime plan. Older Next versions retain the\n * standalone-server behavior so existing deployments remain compatible.\n */\nconst gigadriveNextAdapter: NextAdapter = {\n name: 'Gigadrive Network',\n\n modifyConfig(config, { phase, nextVersion }) {\n if (phase !== PRODUCTION_BUILD_PHASE) return config;\n\n const deploymentId = config.deploymentId ?? process.env.GIGADRIVE_DEPLOYMENT_ID;\n if (!isNext16OrNewer(nextVersion)) {\n return {\n ...config,\n ...(deploymentId ? { deploymentId } : {}),\n output: config.output === 'export' ? 'export' : 'standalone',\n };\n }\n if (config.output === 'export') {\n return { ...config, ...(deploymentId ? { deploymentId } : {}) };\n }\n\n const injectCacheHandler = config.cacheHandler === undefined;\n const injectCacheComponentHandlers = config.cacheHandlers === undefined;\n const images = config.images;\n const injectImageLoader =\n images !== undefined && images.unoptimized !== true && images.loader === 'default' && !images.loaderFile;\n\n return {\n ...config,\n ...(deploymentId ? { deploymentId } : {}),\n ...(injectCacheHandler ? { cacheHandler: CACHE_HANDLER_PATH() } : {}),\n ...(injectCacheComponentHandlers\n ? {\n cacheHandlers: {\n default: CACHE_COMPONENTS_HANDLER_PATH(),\n remote: CACHE_COMPONENTS_HANDLER_PATH(),\n },\n }\n : {}),\n ...(injectCacheHandler || injectCacheComponentHandlers ? { cacheMaxMemorySize: 0 } : {}),\n ...(injectImageLoader\n ? {\n images: {\n ...images,\n loader: 'custom',\n loaderFile: IMAGE_LOADER_PATH(),\n },\n }\n : {}),\n };\n },\n\n async onBuildComplete({ projectDir, repoRoot, distDir, config, nextVersion, buildId, routing, outputs }) {\n const metadataDirectory = path.join(projectDir, '.gigadrive');\n const portableOutputs = {\n pages: await Promise.all(outputs.pages.map((output) => serializeRouteOutput(repoRoot, output))),\n ...(outputs.middleware ? { middleware: await serializeRouteOutput(repoRoot, outputs.middleware) } : {}),\n appPages: await Promise.all(outputs.appPages.map((output) => serializeRouteOutput(repoRoot, output))),\n pagesApi: await Promise.all(outputs.pagesApi.map((output) => serializeRouteOutput(repoRoot, output))),\n appRoutes: await Promise.all(outputs.appRoutes.map((output) => serializeRouteOutput(repoRoot, output))),\n prerenders: await Promise.all(\n outputs.prerenders.map(async (output) => {\n const { bypassFor, ...prerenderConfig } = output.config;\n return {\n id: output.id,\n type: 'PRERENDER' as const,\n pathname: output.pathname,\n parentOutputId: output.parentOutputId,\n groupId: output.groupId,\n ...(output.pprChain ? { pprChain: output.pprChain } : {}),\n ...(output.parentFallbackMode !== undefined\n ? { parentFallbackMode: toJsonValue(output.parentFallbackMode) }\n : {}),\n ...(output.fallback\n ? {\n fallback: {\n ...(output.fallback.filePath\n ? { filePath: await requireReadableFile(repoRoot, output.fallback.filePath) }\n : {}),\n ...(output.fallback.initialStatus !== undefined\n ? { initialStatus: output.fallback.initialStatus }\n : {}),\n ...(output.fallback.initialHeaders ? { initialHeaders: output.fallback.initialHeaders } : {}),\n ...(output.fallback.initialExpiration !== undefined\n ? { initialExpiration: output.fallback.initialExpiration }\n : {}),\n ...(output.fallback.initialRevalidate !== undefined\n ? { initialRevalidate: output.fallback.initialRevalidate }\n : {}),\n ...(output.fallback.postponedState !== undefined\n ? { postponedState: output.fallback.postponedState }\n : {}),\n },\n }\n : {}),\n config: {\n ...prerenderConfig,\n ...(bypassFor ? { bypassFor: toJsonValue(bypassFor) as JsonValue[] } : {}),\n },\n };\n })\n ),\n staticFiles: await Promise.all(outputs.staticFiles.map((output) => serializeStaticOutput(repoRoot, output))),\n };\n const executableOutputs = [\n ...portableOutputs.pages,\n ...portableOutputs.pagesApi,\n ...portableOutputs.appPages,\n ...portableOutputs.appRoutes,\n ...(portableOutputs.middleware ? [portableOutputs.middleware] : []),\n ];\n const entrypointPlan = buildEntrypointPlan(executableOutputs);\n await writeEntrypointWrappers(projectDir, repoRoot, entrypointPlan.entrypoints);\n const images = normalizeImages(config);\n const manifest: GigadriveNextBuildManifestV2 = {\n version: 2,\n mode: config.output === 'export' ? 'export' : 'adapter-v2',\n distDir: toPortableRelativePath(projectDir, distDir),\n repoRootToProject: toPortableRelativePath(repoRoot, projectDir, true),\n nextVersion,\n buildId,\n config: {\n basePath: config.basePath,\n trailingSlash: config.trailingSlash,\n cacheComponents: config.cacheComponents,\n ...(config.i18n ? { i18n: toJsonValue(config.i18n) } : {}),\n ...(images ? { images } : {}),\n },\n routing: {\n beforeMiddleware: toJsonValue(routing.beforeMiddleware) as JsonValue[],\n beforeFiles: toJsonValue(routing.beforeFiles) as JsonValue[],\n afterFiles: toJsonValue(routing.afterFiles) as JsonValue[],\n dynamicRoutes: toJsonValue(routing.dynamicRoutes) as JsonValue[],\n onMatch: toJsonValue(routing.onMatch) as JsonValue[],\n fallback: toJsonValue(routing.fallback) as JsonValue[],\n shouldNormalizeNextData: routing.shouldNormalizeNextData,\n rsc: toJsonValue(routing.rsc),\n },\n outputs: portableOutputs,\n ...entrypointPlan,\n };\n\n await mkdir(metadataDirectory, { recursive: true });\n await writeFile(path.join(metadataDirectory, 'nextjs.json'), `${JSON.stringify(manifest, null, 2)}\\n`, 'utf8');\n },\n};\n\nexport default gigadriveNextAdapter;\n"],"mappings":";AACA,SAAS,QAAQ,OAAO,MAAM,iBAAiB;AAC/C,OAAO,UAAU;AACjB,SAAS,qBAAqB;AAmB9B,IAAM,yBAAyB;AAC/B,IAAM,mBAAmB,OAAO,cAAc,WAAW,YAAY,KAAK,QAAQ,cAAc,YAAY,GAAG,CAAC;AAEhH,IAAM,oBAAoB,CAAC,iBAAyB,aAClD,QAAQ,IAAI,eAAe,KAAK,KAAK,KAAK,kBAAkB,QAAQ;AAEtE,IAAM,qBAAqB,MAAM,kBAAkB,qCAAqC,yBAAyB;AACjH,IAAM,gCAAgC,MACpC,kBAAkB,gDAAgD,oCAAoC;AACxG,IAAM,oBAAoB,MAAM,kBAAkB,oCAAoC,wBAAwB;AAE9G,IAAM,cAAc,CAAC,UAA8B;AACjD,QAAM,aAAa,KAAK,UAAU,KAAK;AACvC,SAAO,eAAe,SAAY,OAAQ,KAAK,MAAM,UAAU;AACjE;AAEA,IAAM,kBAAkB,CAAC,gBAAiC;AACxD,QAAM,QAAQ,OAAO,SAAS,YAAY,MAAM,GAAG,EAAE,CAAC,KAAK,IAAI,EAAE;AACjE,SAAO,OAAO,SAAS,KAA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AQ,WAAW;AAAA,QAC5C,YAAY,YAAY,QAAQ,UAAU;AAAA,QAC1C,eAAe,YAAY,QAAQ,aAAa;AAAA,QAChD,SAAS,YAAY,QAAQ,OAAO;AAAA,QACpC,UAAU,YAAY,QAAQ,QAAQ;AAAA,QACtC,yBAAyB,QAAQ;AAAA,QACjC,KAAK,YAAY,QAAQ,GAAG;AAAA,MAC9B;AAAA,MACA,SAAS;AAAA,MACT,GAAG;AAAA,IACL;AAEA,UAAM,MAAM,mBAAmB,EAAE,WAAW,KAAK,CAAC;AAClD,UAAM,UAAU,KAAK,KAAK,mBAAmB,aAAa,GAAG,GAAG,KAAK,UAAU,UAAU,MAAM,CAAC,CAAC;AAAA,GAAM,MAAM;AAAA,EAC/G;AACF;AAEA,IAAO,yBAAQ;","names":[]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
interface CacheComponentEntry {
|
|
2
|
+
value: ReadableStream<Uint8Array>;
|
|
3
|
+
tags: string[];
|
|
4
|
+
stale: number;
|
|
5
|
+
timestamp: number;
|
|
6
|
+
expire: number;
|
|
7
|
+
revalidate: number;
|
|
8
|
+
}
|
|
9
|
+
/** Shared Network cache handler for Next.js Cache Components and `use cache`. */
|
|
10
|
+
declare const cacheHandler: {
|
|
11
|
+
get(cacheKey: string, softTags: string[]): Promise<CacheComponentEntry | undefined>;
|
|
12
|
+
set(cacheKey: string, pendingEntry: Promise<CacheComponentEntry>): Promise<void>;
|
|
13
|
+
refreshTags(): Promise<void>;
|
|
14
|
+
getExpiration(tags: string[]): Promise<number>;
|
|
15
|
+
updateTags(tags: string[], durations?: {
|
|
16
|
+
expire?: number;
|
|
17
|
+
}): Promise<void>;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export { cacheHandler as default };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
interface CacheComponentEntry {
|
|
2
|
+
value: ReadableStream<Uint8Array>;
|
|
3
|
+
tags: string[];
|
|
4
|
+
stale: number;
|
|
5
|
+
timestamp: number;
|
|
6
|
+
expire: number;
|
|
7
|
+
revalidate: number;
|
|
8
|
+
}
|
|
9
|
+
/** Shared Network cache handler for Next.js Cache Components and `use cache`. */
|
|
10
|
+
declare const cacheHandler: {
|
|
11
|
+
get(cacheKey: string, softTags: string[]): Promise<CacheComponentEntry | undefined>;
|
|
12
|
+
set(cacheKey: string, pendingEntry: Promise<CacheComponentEntry>): Promise<void>;
|
|
13
|
+
refreshTags(): Promise<void>;
|
|
14
|
+
getExpiration(tags: string[]): Promise<number>;
|
|
15
|
+
updateTags(tags: string[], durations?: {
|
|
16
|
+
expire?: number;
|
|
17
|
+
}): Promise<void>;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export = cacheHandler;
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/nextjs-cache-components-handler.ts
|
|
21
|
+
var nextjs_cache_components_handler_exports = {};
|
|
22
|
+
__export(nextjs_cache_components_handler_exports, {
|
|
23
|
+
default: () => nextjs_cache_components_handler_default
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(nextjs_cache_components_handler_exports);
|
|
26
|
+
|
|
27
|
+
// src/nextjs-runtime-cache-client.ts
|
|
28
|
+
var cachedToken;
|
|
29
|
+
var apiBaseUrl = () => (process.env.GIGADRIVE_API_URL ?? "https://api.gigadrive.network").replace(/\/$/, "");
|
|
30
|
+
var encodeBinary = (value, seen = /* @__PURE__ */ new WeakSet()) => {
|
|
31
|
+
if (value instanceof Uint8Array) {
|
|
32
|
+
return { __gigadriveType: "bytes", value: Buffer.from(value).toString("base64") };
|
|
33
|
+
}
|
|
34
|
+
if (value instanceof ArrayBuffer) {
|
|
35
|
+
return { __gigadriveType: "bytes", value: Buffer.from(value).toString("base64") };
|
|
36
|
+
}
|
|
37
|
+
if (Array.isArray(value)) return value.map((item) => encodeBinary(item, seen));
|
|
38
|
+
if (typeof value !== "object" || value === null) return value;
|
|
39
|
+
if (seen.has(value)) throw new Error("Next.js cache entry contains a circular value");
|
|
40
|
+
seen.add(value);
|
|
41
|
+
const result = {};
|
|
42
|
+
for (const [key, item] of Object.entries(value)) result[key] = encodeBinary(item, seen);
|
|
43
|
+
seen.delete(value);
|
|
44
|
+
return result;
|
|
45
|
+
};
|
|
46
|
+
var decodeBinary = (value) => {
|
|
47
|
+
if (Array.isArray(value)) return value.map(decodeBinary);
|
|
48
|
+
if (typeof value !== "object" || value === null) return value;
|
|
49
|
+
const record = value;
|
|
50
|
+
if (record.__gigadriveType === "bytes" && typeof record.value === "string")
|
|
51
|
+
return Buffer.from(record.value, "base64");
|
|
52
|
+
return Object.fromEntries(Object.entries(record).map(([key, item]) => [key, decodeBinary(item)]));
|
|
53
|
+
};
|
|
54
|
+
var getAccessToken = async () => {
|
|
55
|
+
if (cachedToken && cachedToken.expiresAt > Date.now() + 3e4) return cachedToken.value;
|
|
56
|
+
const clientId = process.env.GIGADRIVE_CLIENT_ID;
|
|
57
|
+
const clientSecret = process.env.GIGADRIVE_CLIENT_SECRET;
|
|
58
|
+
if (!clientId || !clientSecret) throw new Error("Gigadrive workload credentials are unavailable");
|
|
59
|
+
const response = await fetch(`${apiBaseUrl()}/oauth2/token`, {
|
|
60
|
+
method: "POST",
|
|
61
|
+
headers: {
|
|
62
|
+
authorization: `Basic ${Buffer.from(`${clientId}:${clientSecret}`).toString("base64")}`,
|
|
63
|
+
"content-type": "application/x-www-form-urlencoded"
|
|
64
|
+
},
|
|
65
|
+
body: "grant_type=client_credentials"
|
|
66
|
+
});
|
|
67
|
+
if (!response.ok) throw new Error(`Gigadrive workload authentication failed with status ${response.status}`);
|
|
68
|
+
const token = await response.json();
|
|
69
|
+
if (!token.access_token) throw new Error("Gigadrive workload authentication returned no access token");
|
|
70
|
+
cachedToken = {
|
|
71
|
+
value: token.access_token,
|
|
72
|
+
expiresAt: Date.now() + Math.max(60, token.expires_in ?? 300) * 1e3
|
|
73
|
+
};
|
|
74
|
+
return token.access_token;
|
|
75
|
+
};
|
|
76
|
+
var request = async (pathname, init, attempt = 0) => {
|
|
77
|
+
const token = await getAccessToken();
|
|
78
|
+
try {
|
|
79
|
+
const response = await fetch(`${apiBaseUrl()}${pathname}`, {
|
|
80
|
+
...init,
|
|
81
|
+
headers: {
|
|
82
|
+
authorization: `Bearer ${token}`,
|
|
83
|
+
"content-type": "application/json",
|
|
84
|
+
"x-gigadrive-deployment-id": process.env.GIGADRIVE_DEPLOYMENT_ID ?? process.env.NEBULA_DEPLOYMENT_ID ?? "",
|
|
85
|
+
"x-gigadrive-build-id": process.env.NEXT_BUILD_ID ?? "",
|
|
86
|
+
...init.headers
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
if (response.status === 401 && attempt === 0) {
|
|
90
|
+
cachedToken = void 0;
|
|
91
|
+
return request(pathname, init, attempt + 1);
|
|
92
|
+
}
|
|
93
|
+
if (response.status >= 500 && attempt < 2) return request(pathname, init, attempt + 1);
|
|
94
|
+
return response;
|
|
95
|
+
} catch (error) {
|
|
96
|
+
if (attempt < 2) return request(pathname, init, attempt + 1);
|
|
97
|
+
throw error;
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
var cachePath = (kind, key) => `/internal/runtime-cache/v1/entries/${encodeURIComponent(kind)}/${encodeURIComponent(key)}`;
|
|
101
|
+
var readRuntimeCache = async (kind, key) => {
|
|
102
|
+
try {
|
|
103
|
+
const response = await request(cachePath(kind, key), { method: "GET" });
|
|
104
|
+
if (response.status === 404) return void 0;
|
|
105
|
+
if (!response.ok) return void 0;
|
|
106
|
+
const envelope = await response.json();
|
|
107
|
+
return decodeBinary(envelope.value);
|
|
108
|
+
} catch {
|
|
109
|
+
return void 0;
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
var writeRuntimeCache = async (kind, key, value, tags = []) => {
|
|
113
|
+
const response = await request(cachePath(kind, key), {
|
|
114
|
+
method: "PUT",
|
|
115
|
+
body: JSON.stringify({ value: encodeBinary(value), tags })
|
|
116
|
+
});
|
|
117
|
+
if (!response.ok) throw new Error(`Gigadrive runtime cache write failed with status ${response.status}`);
|
|
118
|
+
};
|
|
119
|
+
var revalidateRuntimeCacheTags = async (kind, tags, durations) => {
|
|
120
|
+
const response = await request("/internal/runtime-cache/v1/tags/revalidate", {
|
|
121
|
+
method: "POST",
|
|
122
|
+
body: JSON.stringify({ kind, tags, durations })
|
|
123
|
+
});
|
|
124
|
+
if (!response.ok) throw new Error(`Gigadrive runtime cache revalidation failed with status ${response.status}`);
|
|
125
|
+
};
|
|
126
|
+
var getRuntimeCacheTagExpiration = async (kind, tags) => {
|
|
127
|
+
try {
|
|
128
|
+
const response = await request("/internal/runtime-cache/v1/tags/expiration", {
|
|
129
|
+
method: "POST",
|
|
130
|
+
body: JSON.stringify({ kind, tags })
|
|
131
|
+
});
|
|
132
|
+
if (!response.ok) return 0;
|
|
133
|
+
const value = await response.json();
|
|
134
|
+
return typeof value.expiration === "number" ? value.expiration : 0;
|
|
135
|
+
} catch {
|
|
136
|
+
return 0;
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
// src/nextjs-cache-components-handler.ts
|
|
141
|
+
var pendingWrites = /* @__PURE__ */ new Map();
|
|
142
|
+
var streamToBytes = async (stream) => {
|
|
143
|
+
const chunks = [];
|
|
144
|
+
let size = 0;
|
|
145
|
+
const reader = stream.getReader();
|
|
146
|
+
while (true) {
|
|
147
|
+
const result = await reader.read();
|
|
148
|
+
if (result.done) break;
|
|
149
|
+
chunks.push(result.value);
|
|
150
|
+
size += result.value.byteLength;
|
|
151
|
+
}
|
|
152
|
+
const bytes = new Uint8Array(size);
|
|
153
|
+
let offset = 0;
|
|
154
|
+
for (const chunk of chunks) {
|
|
155
|
+
bytes.set(chunk, offset);
|
|
156
|
+
offset += chunk.byteLength;
|
|
157
|
+
}
|
|
158
|
+
return bytes;
|
|
159
|
+
};
|
|
160
|
+
var cacheHandler = {
|
|
161
|
+
async get(cacheKey, softTags) {
|
|
162
|
+
await pendingWrites.get(cacheKey);
|
|
163
|
+
const value = await readRuntimeCache("component", cacheKey);
|
|
164
|
+
if (!value || !(value.value instanceof Uint8Array)) return void 0;
|
|
165
|
+
const expiration = await getRuntimeCacheTagExpiration("component", softTags);
|
|
166
|
+
if (expiration > value.timestamp) return void 0;
|
|
167
|
+
return {
|
|
168
|
+
...value,
|
|
169
|
+
value: new ReadableStream({
|
|
170
|
+
start(controller) {
|
|
171
|
+
controller.enqueue(value.value);
|
|
172
|
+
controller.close();
|
|
173
|
+
}
|
|
174
|
+
})
|
|
175
|
+
};
|
|
176
|
+
},
|
|
177
|
+
async set(cacheKey, pendingEntry) {
|
|
178
|
+
const write = (async () => {
|
|
179
|
+
const entry = await pendingEntry;
|
|
180
|
+
const value = await streamToBytes(entry.value);
|
|
181
|
+
await writeRuntimeCache("component", cacheKey, { ...entry, value }, entry.tags);
|
|
182
|
+
})();
|
|
183
|
+
pendingWrites.set(cacheKey, write);
|
|
184
|
+
try {
|
|
185
|
+
await write;
|
|
186
|
+
} finally {
|
|
187
|
+
if (pendingWrites.get(cacheKey) === write) pendingWrites.delete(cacheKey);
|
|
188
|
+
}
|
|
189
|
+
},
|
|
190
|
+
async refreshTags() {
|
|
191
|
+
},
|
|
192
|
+
getExpiration(tags) {
|
|
193
|
+
return getRuntimeCacheTagExpiration("component", tags);
|
|
194
|
+
},
|
|
195
|
+
updateTags(tags, durations) {
|
|
196
|
+
return revalidateRuntimeCacheTags("component", tags, durations);
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
var nextjs_cache_components_handler_default = cacheHandler;
|
|
200
|
+
//# sourceMappingURL=nextjs-cache-components-handler.js.map
|