-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaddConfig.js
More file actions
49 lines (39 loc) · 1.23 KB
/
Copy pathaddConfig.js
File metadata and controls
49 lines (39 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import * as fs from "fs"
// check if the file path is provided
if (process.argv.length < 3) {
console.log("Offer a file path as argument to add Vercel config, Please!")
process.exit(1)
}
const filePath = process.argv[2]
// the content to add in the file
const contentToAdd = `
// fix for Vercel. esbuild JS error: Error: Dynamic require of "assert" is not supported
// https://github.com/evanw/esbuild/issues/1921#issuecomment-1898197331
import { createRequire } from 'node:module';
import path from 'node:path';
import url from 'node:url';
globalThis.require = createRequire(import.meta.url);
globalThis.__filename = url.fileURLToPath(import.meta.url);
globalThis.__dirname = path.dirname(__filename);
export const config = {
supportsResponseStreaming: true,
api: {
badyParse: false,
},
}
export const dynamic = 'force-dynamic'
`
fs.readFile(filePath, "utf8", (err, data) => {
if (err) {
console.error(`Cannot read file: ${err.message}`)
process.exit(1)
}
const newData = contentToAdd + data
fs.writeFile(filePath, newData, "utf8", (err) => {
if (err) {
console.error(`Cannot write file: ${err.message}`)
process.exit(1)
}
console.log("Add Vercel config in compiled JS file successfully!")
})
})