@solcreek/adapter-creek 0.1.3 → 0.1.4
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/build.js +326 -31
- package/dist/bundler.d.ts +3 -0
- package/dist/bundler.js +873 -27
- package/dist/index.js +24 -1
- package/dist/manifest.d.ts +2 -9
- package/dist/manifest.js +7 -0
- package/dist/worker-entry.js +4048 -460
- package/package.json +2 -2
- package/src/shims/fs.js +57 -13
- package/src/shims/http.js +20 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@solcreek/adapter-creek",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "Next.js deployment adapter for Creek (Cloudflare Workers)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
47
|
"@next/routing": "16.2.3",
|
|
48
|
-
"@solcreek/adapter-core": "^0.
|
|
48
|
+
"@solcreek/adapter-core": "^0.2.0",
|
|
49
49
|
"sql.js": "^1.14.1",
|
|
50
50
|
"wrangler": "^4.82.2"
|
|
51
51
|
},
|
package/src/shims/fs.js
CHANGED
|
@@ -33,6 +33,9 @@ function maybeDecodeBinary(value, enc) {
|
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
function normalizePath(filePath) {
|
|
36
|
+
if (filePath && typeof filePath === "object" && typeof filePath.pathname === "string") {
|
|
37
|
+
return decodeURIComponent(filePath.pathname).replace(/\\/g, "/");
|
|
38
|
+
}
|
|
36
39
|
return String(filePath).replace(/\\/g, "/");
|
|
37
40
|
}
|
|
38
41
|
|
|
@@ -119,6 +122,19 @@ function findInUserFiles(filePath) {
|
|
|
119
122
|
// Fixes next/og node-runtime `fs.readFileSync` of bundled wasm/ttf and
|
|
120
123
|
// twoslash loading `typescript/lib/lib.*.d.ts` in Workers.
|
|
121
124
|
const reqBase = requestedPath.split("/").pop() || "";
|
|
125
|
+
const originalServerAssetBase = requestedPath.includes("/server/assets/")
|
|
126
|
+
? reqBase.replace(/\.[a-z0-9_~-]{6,}(\.[^.]+)$/i, "$1")
|
|
127
|
+
: "";
|
|
128
|
+
if (originalServerAssetBase && originalServerAssetBase !== reqBase) {
|
|
129
|
+
let found;
|
|
130
|
+
for (const key in files) {
|
|
131
|
+
const keyBase = normalizePath(key).split("/").pop() || "";
|
|
132
|
+
if (keyBase !== originalServerAssetBase) continue;
|
|
133
|
+
if (found !== undefined) return undefined;
|
|
134
|
+
found = files[key];
|
|
135
|
+
}
|
|
136
|
+
if (found !== undefined) return found;
|
|
137
|
+
}
|
|
122
138
|
if (/\.(wasm|ttf|otf|woff2?)$/i.test(reqBase) || /^lib\..*\.d\.ts$/i.test(reqBase)) {
|
|
123
139
|
for (const key in files) {
|
|
124
140
|
if (normalizePath(key).split("/").pop() === reqBase) return files[key];
|
|
@@ -131,10 +147,11 @@ export const existsSync = (filePath) => {
|
|
|
131
147
|
if (findInUserFiles(filePath) !== undefined) return true;
|
|
132
148
|
if (isUserFilesDirectory(filePath)) return true;
|
|
133
149
|
if (typeof globalThis.__MANIFESTS === "undefined") return false;
|
|
150
|
+
const normalizedPath = normalizePath(filePath);
|
|
134
151
|
for (const key of Object.keys(globalThis.__MANIFESTS)) {
|
|
135
|
-
if (key ===
|
|
136
|
-
if (
|
|
137
|
-
const tail = ".next/" +
|
|
152
|
+
if (key === normalizedPath || key.endsWith(normalizedPath)) return true;
|
|
153
|
+
if (normalizedPath.includes(".next/")) {
|
|
154
|
+
const tail = ".next/" + normalizedPath.split(".next/").pop();
|
|
138
155
|
const keyTail = key.includes(".next/") ? ".next/" + key.split(".next/").pop() : "";
|
|
139
156
|
if (tail === keyTail) return true;
|
|
140
157
|
}
|
|
@@ -142,29 +159,29 @@ export const existsSync = (filePath) => {
|
|
|
142
159
|
return false;
|
|
143
160
|
};
|
|
144
161
|
export const readFileSync = (filePath, enc) => {
|
|
162
|
+
const normalizedPath = normalizePath(filePath);
|
|
163
|
+
// User files should win over manifest basename fallbacks. A request for
|
|
164
|
+
// process.cwd()/package.json must resolve the app package, not .next/package.json.
|
|
165
|
+
const userContent = findInUserFiles(filePath);
|
|
166
|
+
if (userContent !== undefined) return maybeDecodeBinary(userContent, enc);
|
|
145
167
|
// Try reading from embedded manifests
|
|
146
168
|
if (typeof globalThis.__MANIFESTS !== "undefined") {
|
|
147
169
|
for (const [key, val] of Object.entries(globalThis.__MANIFESTS)) {
|
|
148
|
-
if (key ===
|
|
170
|
+
if (key === normalizedPath || key.endsWith(normalizedPath)) return val;
|
|
149
171
|
// Match by .next/ relative tail — handles different path prefixes
|
|
150
172
|
// e.g. /bundle/.next/routes-manifest.json → .next/routes-manifest.json
|
|
151
|
-
if (
|
|
152
|
-
const tail = ".next/" +
|
|
173
|
+
if (normalizedPath.includes(".next/")) {
|
|
174
|
+
const tail = ".next/" + normalizedPath.split(".next/").pop();
|
|
153
175
|
const keyTail = key.includes(".next/") ? ".next/" + key.split(".next/").pop() : "";
|
|
154
176
|
if (tail === keyTail) return val;
|
|
155
177
|
}
|
|
156
178
|
// Last resort: match by filename
|
|
157
|
-
if (
|
|
179
|
+
if (normalizedPath.split("/").pop() === key.split("/").pop()) return val;
|
|
158
180
|
}
|
|
159
181
|
}
|
|
160
|
-
// Then try user-side data files (data.json, fixtures, fonts, etc.).
|
|
161
|
-
// Binary files are stored as base64 with a sentinel prefix — decode
|
|
162
|
-
// them lazily based on the caller's requested encoding.
|
|
163
|
-
const userContent = findInUserFiles(filePath);
|
|
164
|
-
if (userContent !== undefined) return maybeDecodeBinary(userContent, enc);
|
|
165
182
|
// Throw ENOENT like real fs — Next.js loadManifest relies on this
|
|
166
183
|
// to distinguish between missing and empty files.
|
|
167
|
-
const err = new Error(`ENOENT: no such file or directory, open '${
|
|
184
|
+
const err = new Error(`ENOENT: no such file or directory, open '${normalizedPath}'`);
|
|
168
185
|
err.code = "ENOENT";
|
|
169
186
|
throw err;
|
|
170
187
|
};
|
|
@@ -218,6 +235,33 @@ export const promises = {
|
|
|
218
235
|
rm: async () => {},
|
|
219
236
|
};
|
|
220
237
|
|
|
238
|
+
export function readFile(filePath, enc, cb) {
|
|
239
|
+
let encoding = enc;
|
|
240
|
+
let callback = cb;
|
|
241
|
+
if (typeof enc === "function") {
|
|
242
|
+
callback = enc;
|
|
243
|
+
encoding = undefined;
|
|
244
|
+
}
|
|
245
|
+
if (typeof callback === "function") {
|
|
246
|
+
queueMicrotask(() => {
|
|
247
|
+
try {
|
|
248
|
+
callback(null, readFileSync(filePath, encoding));
|
|
249
|
+
} catch (err) {
|
|
250
|
+
callback(err);
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
return promises.readFile(filePath, encoding);
|
|
256
|
+
}
|
|
257
|
+
export const writeFile = promises.writeFile;
|
|
258
|
+
export const mkdir = promises.mkdir;
|
|
259
|
+
export const readdir = promises.readdir;
|
|
260
|
+
export const stat = promises.stat;
|
|
261
|
+
export const access = promises.access;
|
|
262
|
+
export const unlink = promises.unlink;
|
|
263
|
+
export const rm = promises.rm;
|
|
264
|
+
|
|
221
265
|
export default {
|
|
222
266
|
existsSync, readFileSync, readAll, writeFileSync, mkdirSync, unlinkSync,
|
|
223
267
|
readdirSync, realpathSync, statSync, accessSync, createReadStream, createWriteStream,
|
package/src/shims/http.js
CHANGED
|
@@ -234,7 +234,26 @@ export function createServer() { throw new Error("http.createServer not availabl
|
|
|
234
234
|
export function request() { throw new Error("http.request not available in CF Workers"); }
|
|
235
235
|
export function get() { throw new Error("http.get not available in CF Workers"); }
|
|
236
236
|
|
|
237
|
+
export function Agent(options) {
|
|
238
|
+
EventEmitter.call(this);
|
|
239
|
+
this.options = options || {};
|
|
240
|
+
this.requests = {};
|
|
241
|
+
this.sockets = {};
|
|
242
|
+
this.freeSockets = {};
|
|
243
|
+
this.maxSockets = this.options.maxSockets || Agent.defaultMaxSockets;
|
|
244
|
+
}
|
|
245
|
+
Agent.prototype = Object.create(EventEmitter.prototype);
|
|
246
|
+
Agent.prototype.constructor = Agent;
|
|
247
|
+
Agent.defaultMaxSockets = Infinity;
|
|
248
|
+
Agent.prototype.addRequest = function(req) {
|
|
249
|
+
if (req && typeof req.emit === "function") {
|
|
250
|
+
queueMicrotask(() => req.emit("error", new Error("http.Agent sockets are not available in CF Workers")));
|
|
251
|
+
}
|
|
252
|
+
};
|
|
253
|
+
Agent.prototype.destroy = function() {};
|
|
254
|
+
export const globalAgent = new Agent();
|
|
255
|
+
|
|
237
256
|
export const METHODS = ["GET","POST","PUT","DELETE","PATCH","HEAD","OPTIONS"];
|
|
238
257
|
export const STATUS_CODES = { 200:"OK",201:"Created",204:"No Content",301:"Moved Permanently",302:"Found",304:"Not Modified",400:"Bad Request",401:"Unauthorized",403:"Forbidden",404:"Not Found",500:"Internal Server Error" };
|
|
239
258
|
|
|
240
|
-
export default { IncomingMessage, ServerResponse, createServer, request, get, METHODS, STATUS_CODES };
|
|
259
|
+
export default { IncomingMessage, ServerResponse, createServer, request, get, Agent, globalAgent, METHODS, STATUS_CODES };
|