-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add hashbang if not exists in build (#121)
- Loading branch information
Showing
4 changed files
with
65 additions
and
35 deletions.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,19 @@ | ||
import MagicString from 'magic-string'; | ||
import * as fs from 'node:fs'; | ||
import { join } from 'pathe'; | ||
|
||
// Until pkgroll fixes the shebang bug, this needs to be run postbuild | ||
|
||
const addHashbang = (filepath: string) => { | ||
const path = join(process.cwd(), filepath); | ||
const s = new MagicString(fs.readFileSync(path, 'utf8')); | ||
|
||
// Only add the hashbang if it's not already there | ||
if (!s.toString().startsWith('#!')) { | ||
s.prepend('#!/usr/bin/env node\n'); | ||
fs.writeFileSync(path, s.toString()); | ||
} | ||
}; | ||
|
||
addHashbang('dist/cli.mjs'); | ||
addHashbang('dist/cli.js'); |
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 |
---|---|---|
@@ -1,41 +1,42 @@ | ||
{ | ||
/* Visit https://aka.ms/tsconfig.json to read more about this file */ | ||
"include": [ | ||
"src/**/*.ts", | ||
"src/**/*.json", | ||
"tests/**/*.ts", | ||
"tests/**/*.json", | ||
"vitest.config.ts" | ||
], | ||
"exclude": [".eslintrc.cjs"], | ||
"compilerOptions": { | ||
/* Projects */ | ||
//"incremental": true, | ||
/* Visit https://aka.ms/tsconfig.json to read more about this file */ | ||
"include": [ | ||
"src/**/*.ts", | ||
"src/**/*.json", | ||
"scripts/**/*.ts", | ||
"tests/**/*.ts", | ||
"tests/**/*.json", | ||
"vitest.config.ts" | ||
], | ||
"exclude": [".eslintrc.cjs"], | ||
"compilerOptions": { | ||
/* Projects */ | ||
//"incremental": true, | ||
|
||
/* Language and Environment */ | ||
"target": "esnext", | ||
"useDefineForClassFields": true, | ||
/* Language and Environment */ | ||
"target": "esnext", | ||
"useDefineForClassFields": true, | ||
|
||
/* Modules */ | ||
"module": "esnext", | ||
"moduleResolution": "node", | ||
"resolveJsonModule": true, | ||
/* Modules */ | ||
"module": "esnext", | ||
"moduleResolution": "node", | ||
"resolveJsonModule": true, | ||
|
||
/* Interop Constraints */ | ||
"allowSyntheticDefaultImports": true, | ||
"esModuleInterop": true, | ||
"forceConsistentCasingInFileNames": true, | ||
/* Interop Constraints */ | ||
"allowSyntheticDefaultImports": true, | ||
"esModuleInterop": true, | ||
"forceConsistentCasingInFileNames": true, | ||
|
||
/* Type Checking */ | ||
"strict": true, | ||
"isolatedModules": true, | ||
"noUnusedLocals": true, | ||
"noUnusedParameters": true, | ||
"noImplicitReturns": true, | ||
"noFallthroughCasesInSwitch": true, | ||
/* Type Checking */ | ||
"strict": true, | ||
"isolatedModules": true, | ||
"noUnusedLocals": true, | ||
"noUnusedParameters": true, | ||
"noImplicitReturns": true, | ||
"noFallthroughCasesInSwitch": true, | ||
|
||
/* Completeness */ | ||
"skipLibCheck": true // Skip type checking all .d.ts files. | ||
}, | ||
"$schema": "https://json.schemastore.org/tsconfig" | ||
/* Completeness */ | ||
"skipLibCheck": true // Skip type checking all .d.ts files. | ||
}, | ||
"$schema": "https://json.schemastore.org/tsconfig" | ||
} |