File: add-cli-entry.js

package info (click to toggle)
node-rollup 2.38.4-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 42,968 kB
  • sloc: javascript: 88,384; makefile: 10
file content (22 lines) | stat: -rw-r--r-- 543 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import MagicString from 'magic-string';

export default function addCliEntry() {
	return {
		name: 'add-cli-entry',
		buildStart() {
			this.emitFile({
				type: 'chunk',
				id: 'cli/cli.ts',
				fileName: 'bin/rollup',
				preserveSignature: false
			});
		},
		renderChunk(code, chunkInfo) {
			if (chunkInfo.fileName === 'bin/rollup') {
				const magicString = new MagicString(code);
				magicString.prepend('#!/usr/bin/node\n\n');
				return { code: magicString.toString(), map: magicString.generateMap({ hires: true }) };
			}
		}
	};
}