-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Transforms for the nextjs-commerce app
- Loading branch information
Showing
2 changed files
with
96 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// https://github.com/vercel/next.js/blob/canary/packages/next/src/server/lib/node-fs-methods.ts | ||
|
||
export const nodeFs = { | ||
existsSync, | ||
readFile, | ||
readFileSync, | ||
writeFile, | ||
mkdir, | ||
stat, | ||
}; | ||
|
||
const FILES = new Map<string, unknown>(); | ||
const MTIME = Date.now(); | ||
|
||
function existsSync(path: string) { | ||
console.log( | ||
"existsSync", | ||
path, | ||
new Error().stack?.split("\n").slice(1).join("\n") | ||
); | ||
return FILES.has(path); | ||
} | ||
|
||
async function readFile(path: string, options: unknown): Promise<any> { | ||
console.log( | ||
"readFile", | ||
{ path, options } | ||
// new Error().stack.split("\n").slice(1).join("\n"), | ||
); | ||
if (!FILES.has(path)) { | ||
throw new Error(path + "does not exist"); | ||
} | ||
return FILES.get(path); | ||
} | ||
|
||
function readFileSync(path: string, options: unknown) { | ||
console.log( | ||
"readFileSync", | ||
{ path, options } | ||
// new Error().stack.split("\n").slice(1).join("\n"), | ||
); | ||
if (!FILES.has(path)) { | ||
throw new Error(path + "does not exist"); | ||
} | ||
return FILES.get(path); | ||
} | ||
|
||
async function writeFile(file: string, data: unknown) { | ||
console.log( | ||
"writeFile", | ||
{ file, data } | ||
// new Error().stack.split("\n").slice(1).join("\n"), | ||
); | ||
FILES.set(file, data); | ||
return true; | ||
} | ||
|
||
async function mkdir(dir: string) { | ||
console.log( | ||
"mkdir", | ||
dir | ||
//new Error().stack.split("\n").slice(1).join("\n"), | ||
); | ||
} | ||
|
||
async function stat(file: string) { | ||
console.log( | ||
"stat", | ||
file | ||
// new Error().stack.split("\n").slice(1).join("\n"), | ||
); | ||
return { mtime: new Date(MTIME) }; | ||
} |