Skip to content

Commit

Permalink
fix: temp workaround for next-js esm
Browse files Browse the repository at this point in the history
  • Loading branch information
segunadebayo committed Mar 18, 2023
1 parent 62ae899 commit 26800ee
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/integrations/next-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
},
"scripts": {
"build": "tsup src --dts",
"postbuild": "pnpm fix:import",
"fix:import": "node ./scripts/postbuild.mjs",
"dev": "pnpm build:fast -- --watch",
"clean": "rimraf dist .turbo",
"typecheck": "tsc --noEmit",
Expand Down
18 changes: 18 additions & 0 deletions packages/integrations/next-js/scripts/postbuild.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import fs from "fs-extra"

// get all mjs files in the dist folder
const files = await fs.readdir("dist")

// read the content of files that end with .mjs
const mjsFiles = files.filter((file) => file.endsWith(".mjs"))

// replace the content of the files
await Promise.all(
mjsFiles.map(async (file) => {
const content = fs.readFileSync(`dist/${file}`, "utf8")
// look for next/(*) and replace with "next/(*).js" equivalent
const newContent = content.replace(/next\/(\w+)/g, "next/$1.js")
// write the new content to the file
fs.writeFileSync(`dist/${file}`, newContent)
}),
)

1 comment on commit 26800ee

@vercel
Copy link

@vercel vercel bot commented on 26800ee Mar 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.