diff --git a/bin/patch-build.js b/bin/patch-build.js new file mode 100644 index 0000000..0f8b302 --- /dev/null +++ b/bin/patch-build.js @@ -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') diff --git a/package.json b/package.json index 154fde1..9129300 100644 --- a/package.json +++ b/package.json @@ -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",