-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create a post bundle script for preview-api
To workaround vercel/next.js#57962 cc @ndelangen. Not sure we want to merge this but it gets us through the demo for now.
- Loading branch information
Showing
2 changed files
with
32 additions
and
1 deletion.
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,30 @@ | ||
/// <reference types="node" /> | ||
|
||
// rewrite code from dist that triggers this bug: https://github.com/vercel/next.js/issues/57962 | ||
import { join, relative } from 'path'; | ||
import { cwd } from 'process'; | ||
import { promises } from 'fs'; | ||
|
||
const DIST = relative(cwd(), './dist'); | ||
|
||
async function go() { | ||
const filenames = await promises.readdir(DIST); | ||
|
||
await Promise.all( | ||
filenames.map(async (filename) => { | ||
if (filename.endsWith('.mjs')) { | ||
const fullFilename = join(DIST, filename); | ||
|
||
const content = await promises.readFile(fullFilename, 'utf-8'); | ||
|
||
const newContent = content | ||
.replace(/\(exports, module\)/g, '(exports, mod)') | ||
.replace(/module.exports = /g, 'mod.exports = '); | ||
|
||
await promises.writeFile(fullFilename, newContent); | ||
} | ||
}) | ||
); | ||
} | ||
|
||
go(); |