/rollup-plugin-shebang-bin

Richly configurable rollup plugin for preserving or inserting shebang (hashbang) and making scripts executable.

Primary LanguageJavaScriptMIT LicenseMIT

rollup-plugin-shebang-bin

Latest version Dependency status Coverage

Richly configurable Rollup plugin for preserving or inserting shebang (hashbang) and making scripts executable.

Requirements

This plugin requires Node.js 14 or newer and Rollup 2 or newer.

Installation

This module can be installed in your project using NPM, PNPM or Yarn. Make sure, that you use Node.js version 6 or newer.

npm i -D rollup-plugin-shebang-bin
pnpm i -D rollup-plugin-shebang-bin
yarn add rollup-plugin-shebang-bin

Usage

Create a rollup.config.js configuration file and import the plugin:

import shebang from 'rollup-plugin-shebang-bin'

export default {
  input: 'src/cli.js',
  output: {
    dir: 'bin',
    format: 'cjs'
  },
  plugins: [shebang()]
}

Then call rollup either via the command-line or programmatically.

The file bin/cli.js will be executable with the following content:

#!/usr/bin/env node

... // content of src/cli.js

Options

The following options can be passed in an object to the plugin function to change the default values.

include

Type: Array<String>
Default: ['**/*.js']

Pattern to match files which will be processed by the plugin.

exclude

Type: Array<String>
Default: []

Pattern to match files which will be ignored by the plugin.

regexp

Type: RegExp
Default: /^\s*#!.*\n*/

The regular expression to match the shebang at the beginning of an input file.

shebang

Type: String
Default: '#!/usr/bin/env node'

The shebang to insert to the beginning of an output file.

separator

Type: String
Default: '\n\n'

The whitespace to insert after the shebang to separate if from the rest of an output file.

mode

Type: Number
Default: 0o755

The permissions to apply to an output file. The value will be masked by the process umask.

insert

Type: Boolean
Default: true

If the shebang will be inserted to an output file.

preserve

Type: Boolean
Default: true

If an existing shebang will be preserved in an output file.

If you set preserve to false and insert to true, the existing shebang will be removed and a new one inserted to an output file.

executable

Type: Boolean
Default: true

If an output file should become executable permissions.

License

Copyright (C) 2022-2024 Ferdinand Prantl

Licensed under the MIT License.