this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Transforms for the nextjs-commerce app

+96
+23
builder/src/build/build-worker/index.ts
··· 90 90 */ "" 91 91 } 92 92 globalThis.__dirname ??= ""; 93 + 94 + // Do not crash on cache not supported 95 + let isPatchedAlready = globalThis.fetch.__nextPatched; 96 + const curFetch = globalThis.fetch; 97 + globalThis.fetch = (input, init) => { 98 + console.log("globalThis.fetch", input); 99 + if (init) delete init.cache; 100 + return curFetch(input, init); 101 + }; 102 + globalThis.fetch.__nextPatched = isPatchedAlready; 103 + fetch = globalThis.fetch; 104 + const CustomRequest = class extends globalThis.Request { 105 + constructor(input, init) { 106 + console.log("CustomRequest", input); 107 + if (init) delete init.cache; 108 + super(input, init); 109 + } 110 + }; 111 + globalThis.Request = CustomRequest; 112 + Request = globalThis.Request; 93 113 `, 94 114 }, 95 115 }); ··· 184 204 // Note: we (empty) shim require-hook modules as they generate problematic code that uses requires 185 205 build.onResolve({ filter: /^\.\/require-hook$/ }, (args) => ({ 186 206 path: `${templateDir}/shims/empty.ts`, 207 + })); 208 + build.onResolve({ filter: /\.\/lib\/node-fs-methods$/ }, (args) => ({ 209 + path: `${templateDir}/shims/node-fs.ts`, 187 210 })); 188 211 }, 189 212 };
+73
builder/src/build/build-worker/templates/shims/node-fs.ts
··· 1 + // https://github.com/vercel/next.js/blob/canary/packages/next/src/server/lib/node-fs-methods.ts 2 + 3 + export const nodeFs = { 4 + existsSync, 5 + readFile, 6 + readFileSync, 7 + writeFile, 8 + mkdir, 9 + stat, 10 + }; 11 + 12 + const FILES = new Map<string, unknown>(); 13 + const MTIME = Date.now(); 14 + 15 + function existsSync(path: string) { 16 + console.log( 17 + "existsSync", 18 + path, 19 + new Error().stack?.split("\n").slice(1).join("\n") 20 + ); 21 + return FILES.has(path); 22 + } 23 + 24 + async function readFile(path: string, options: unknown): Promise<any> { 25 + console.log( 26 + "readFile", 27 + { path, options } 28 + // new Error().stack.split("\n").slice(1).join("\n"), 29 + ); 30 + if (!FILES.has(path)) { 31 + throw new Error(path + "does not exist"); 32 + } 33 + return FILES.get(path); 34 + } 35 + 36 + function readFileSync(path: string, options: unknown) { 37 + console.log( 38 + "readFileSync", 39 + { path, options } 40 + // new Error().stack.split("\n").slice(1).join("\n"), 41 + ); 42 + if (!FILES.has(path)) { 43 + throw new Error(path + "does not exist"); 44 + } 45 + return FILES.get(path); 46 + } 47 + 48 + async function writeFile(file: string, data: unknown) { 49 + console.log( 50 + "writeFile", 51 + { file, data } 52 + // new Error().stack.split("\n").slice(1).join("\n"), 53 + ); 54 + FILES.set(file, data); 55 + return true; 56 + } 57 + 58 + async function mkdir(dir: string) { 59 + console.log( 60 + "mkdir", 61 + dir 62 + //new Error().stack.split("\n").slice(1).join("\n"), 63 + ); 64 + } 65 + 66 + async function stat(file: string) { 67 + console.log( 68 + "stat", 69 + file 70 + // new Error().stack.split("\n").slice(1).join("\n"), 71 + ); 72 + return { mtime: new Date(MTIME) }; 73 + }