Skip to content

Commit

Permalink
Add patch-build script to workaround missing require in build
Browse files Browse the repository at this point in the history
  • Loading branch information
aral committed Mar 10, 2021
1 parent c6f2ba9 commit f0a2056
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
8 changes: 8 additions & 0 deletions bin/patch-build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import fs from 'fs'
import path from 'path'
const __dirname = new URL('.', import.meta.url).pathname

const build = path.join(__dirname, '..', 'place.js')
const unpatchedBuild = fs.readFileSync(build, 'utf-8')
const patchedBuild = unpatchedBuild.replace('#!/usr/bin/env node', '#!/usr/bin/env node\n\nconst require = createRequire(import.meta.url)\n')
fs.writeFileSync(build, patchedBuild, 'utf-8')
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
"scripts": {
"test": "tape test/*.js | tap-spec",
"coverage": "nyc tape test/*.js | tap-nyc",
"build": "esbuild bin/place.js --bundle --platform=node --external:fsevents --format=esm --outfile=place.js"
"build": "npm run esbuild && npm run patch-build",
"patch-build": "node bin/patch-build.js",
"esbuild": "esbuild bin/place.js --bundle --platform=node --external:fsevents --format=esm --outfile=place.js"
},
"funding": {
"type": "foundation",
Expand Down

0 comments on commit f0a2056

Please sign in to comment.