Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: idleberg/node-makensis
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v2.0.4
Choose a base ref
...
head repository: idleberg/node-makensis
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: main
Choose a head ref

Commits on Feb 8, 2023

  1. add events option

    idleberg committed Feb 8, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    494783c View commit details
  2. fix badge

    idleberg committed Feb 8, 2023
    Copy the full SHA
    2b22e85 View commit details

Commits on Feb 11, 2023

  1. update description

    idleberg committed Feb 11, 2023
    Copy the full SHA
    8825aeb View commit details

Commits on Feb 12, 2023

  1. update dependencies

    idleberg committed Feb 12, 2023
    Copy the full SHA
    953d844 View commit details
  2. use console.log

    idleberg committed Feb 12, 2023
    Copy the full SHA
    447c288 View commit details
  3. fix mission option

    idleberg committed Feb 12, 2023
    Copy the full SHA
    d9e7712 View commit details
  4. add np

    idleberg committed Feb 12, 2023
    Copy the full SHA
    843cf7b View commit details

Commits on Feb 14, 2023

  1. 2.0.5

    idleberg committed Feb 14, 2023
    Copy the full SHA
    e7e6209 View commit details
  2. update badge

    idleberg committed Feb 14, 2023
    Copy the full SHA
    2f7f8fc View commit details

Commits on Jul 7, 2023

  1. update types

    idleberg committed Jul 7, 2023
    Copy the full SHA
    3b8f933 View commit details
  2. update dependencies

    idleberg committed Jul 7, 2023
    Copy the full SHA
    308f54d View commit details
  3. update types

    idleberg committed Jul 7, 2023
    Copy the full SHA
    5c8cb69 View commit details
  4. improve types

    idleberg committed Jul 7, 2023
    Copy the full SHA
    5aab0b0 View commit details
  5. fix pipeline

    idleberg committed Jul 7, 2023
    Copy the full SHA
    dd388d8 View commit details
  6. fix pipeline

    idleberg committed Jul 7, 2023
    Copy the full SHA
    85b7771 View commit details
  7. add .npmrc

    idleberg committed Jul 7, 2023
    Copy the full SHA
    347be6a View commit details
  8. reorder args,

    idleberg committed Jul 7, 2023
    Copy the full SHA
    0bb6c54 View commit details
  9. downgrade pnpm

    idleberg committed Jul 7, 2023
    Copy the full SHA
    f4ec3bc View commit details
  10. update readme

    idleberg committed Jul 7, 2023
    Copy the full SHA
    f051400 View commit details
  11. 2.0.6

    idleberg committed Jul 7, 2023
    Copy the full SHA
    faa1cdd View commit details
  12. add missing type

    idleberg committed Jul 7, 2023
    Copy the full SHA
    d0ea8c1 View commit details
  13. downgrade np

    idleberg committed Jul 7, 2023
    Copy the full SHA
    683f551 View commit details
  14. whitespace

    idleberg committed Jul 7, 2023
    Copy the full SHA
    31fd285 View commit details
  15. 2.0.7

    idleberg committed Jul 7, 2023
    Copy the full SHA
    5a13046 View commit details
  16. fix type handling

    idleberg committed Jul 7, 2023
    Copy the full SHA
    02a03d6 View commit details

Commits on Jul 9, 2023

  1. improve types

    idleberg committed Jul 9, 2023
    Copy the full SHA
    16389fe View commit details
  2. update types

    idleberg committed Jul 9, 2023
    Copy the full SHA
    2e83d5b View commit details
  3. 2.0.8

    idleberg committed Jul 9, 2023
    Copy the full SHA
    10135b2 View commit details
  4. update badges

    idleberg committed Jul 9, 2023
    Copy the full SHA
    1cf07f7 View commit details

Commits on Jul 15, 2023

  1. fix badges

    idleberg committed Jul 15, 2023
    Copy the full SHA
    87950dc View commit details

Commits on Jul 16, 2023

  1. set skipLibCheck to true

    idleberg committed Jul 16, 2023
    Copy the full SHA
    2a042fd View commit details
Showing with 2,891 additions and 1,489 deletions.
  1. +22 −5 .github/workflows/default.yml
  2. +25 −8 .github/workflows/wine.yml
  3. +2 −0 .npmrc
  4. +22 −7 README.md
  5. +22 −21 package.json
  6. +2,713 −1,390 pnpm-lock.yaml
  7. +15 −16 src/commands.ts
  8. +36 −26 src/util.ts
  9. +7 −7 tests/native/commands.test.mjs
  10. +10 −7 tsconfig.json
  11. +17 −2 types/index.d.ts
27 changes: 22 additions & 5 deletions .github/workflows/default.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
name: CI

on: [push]
on:
push:
paths:
- '.github/**'
- 'src/**'
- 'test/**'
- 'types/**'
- 'package.json'
- 'pnpm-lock.yaml'
pull_request:
paths:
- '.github/**'
- 'src/**'
- 'test/**'
- 'types/**'
- 'package.json'
- 'pnpm-lock.yaml'
workflow_dispatch:

jobs:
default:
@@ -54,7 +71,7 @@ jobs:
- uses: pnpm/action-setup@v2.0.1
with:
version: 6
version: 7
run_install: |
- recursive: true
- args: [--frozen-lockfile, --strict-peer-dependencies]
@@ -64,10 +81,10 @@ jobs:
node-version: ${{ matrix.node-version }}

- name: Lint Source
run: pnpm run lint --if-present
run: pnpm run --if-present lint

- name: Build Source
run: pnpm run build --if-present
run: pnpm run --if-present build

- name: Run Tests
run: pnpm run test --if-present
run: pnpm run --if-present test
33 changes: 25 additions & 8 deletions .github/workflows/wine.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
name: CI:Wine

on: [push]
on:
push:
paths:
- '.github/**'
- 'src/**'
- 'test/**'
- 'types/**'
- 'package.json'
- 'pnpm-lock.yaml'
pull_request:
paths:
- '.github/**'
- 'src/**'
- 'test/**'
- 'types/**'
- 'package.json'
- 'pnpm-lock.yaml'
workflow_dispatch:

jobs:
default:
@@ -16,7 +33,7 @@ jobs:
with:
fetch-depth: 10

- uses: actions/setup-node@v2
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}

@@ -42,7 +59,7 @@ jobs:

- name: Install NSIS
run: |
curl -L https://downloads.sourceforge.net/project/nsis/NSIS%203/3.07/nsis-3.07-setup.exe -o ${{ runner.temp }}/nsis-setup-$GITHUB_SHA.exe
curl -L https://downloads.sourceforge.net/project/nsis/NSIS%203/3.09/nsis-3.09-setup.exe -o ${{ runner.temp }}/nsis-setup-$GITHUB_SHA.exe
wine ${{ runner.temp }}/nsis-setup-$GITHUB_SHA.exe /S
wine regedit "${GITHUB_WORKSPACE}/.github/nsis.reg"
env:
@@ -87,22 +104,22 @@ jobs:
- uses: pnpm/action-setup@v2.0.1
with:
version: 6
version: 7
run_install: |
- recursive: true
- args: [--frozen-lockfile, --strict-peer-dependencies]
- name: Lint Source
run: pnpm run lint --if-present
run: pnpm --if-present run lint

- name: Build Source
run: pnpm run build --if-present
run: pnpm --if-present run build

- name: Run Tests (macOS)
if: matrix.os == 'macos-10.15'
run: pnpm run test:wine --if-present
run: pnpm run --if-present test:wine
continue-on-error: true # unreliable, often times out

- name: Run Tests (Ubuntu)
if: matrix.os == 'ubuntu-latest'
run: pnpm run test:wine --if-present
run: pnpm run --if-present test:wine
2 changes: 2 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
auto-install-peers=true
strict-peer-dependencies=false
29 changes: 22 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
# makensis

[![npm](https://flat.badgen.net/npm/license/makensis)](https://www.npmjs.org/package/makensis)
[![npm](https://flat.badgen.net/npm/v/makensis)](https://www.npmjs.org/package/makensis)
[![CI](https://img.shields.io/github/workflow/status/idleberg/node-makensis/CI?style=flat-square)](https://github.com/idleberg/node-makensis/actions)
[![Snyk](https://flat.badgen.net/snyk/idleberg/node-makensis)](https://snyk.io/vuln/npm:makensis)
[![License](https://img.shields.io/github/license/idleberg/node-makensis?style=for-the-badge)](LICENSE)
[![Version](https://img.shields.io/github/v/release/idleberg/node-makensis?style=for-the-badge)](https://github.com/idleberg/node-makensis/releases)
![NodeJS version](https://img.shields.io/node/v/makensis?style=for-the-badge)
[![CI](https://img.shields.io/github/actions/workflow/status/idleberg/node-makensis/default.yml?style=for-the-badge)](https://github.com/idleberg/node-makensis/actions)

A Node wrapper for `makensis`, the compiler for NSIS installers. Supports both, native and [Wine][wine].

## Prerequisites

Make sure that NSIS is properly installed. If `makensis` isn't exposed to your PATH [environment variable][envvars], you need to set [`pathToMakensis`](#pathtomakensis).

### Windows
<details>
<summary><strong>Windows</strong></summary>

Install NSIS using the [Windows Package Manager][winget] or [Scoop][scoop]:

@@ -25,7 +26,10 @@ $ scoop install nsis/nsis

Alternatively, you can download the NSIS installer from [SourceForge][sourceforge].

### Linux
</details>

<details>
<summary><strong>Linux</strong></summary>

Install NSIS from your distribution's default package manager, for example:

@@ -37,7 +41,10 @@ $ sudo apt-get install nsis
$ sudo dnf install nsis
```

### macOS
</details>

<details>
<summary><strong>macOS</strong></summary>

Install NSIS using [Homebrew][homebrew] or [MacPorts][macports]:

@@ -49,6 +56,8 @@ $ brew install nsis
$ port install nsis
```

</details>

## Installation

`npm install makensis`
@@ -158,6 +167,12 @@ NSIS_APP_ENVIRONMENT=development

</details>

#### events

Type: `boolean`

Allows dispatching the log events `stdout`, `stderr` and `exit`.

#### inputCharset

Type: `string`
43 changes: 22 additions & 21 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "makensis",
"version": "2.0.4",
"version": "2.0.8",
"description": "A Node wrapper for makensis, the NSIS compiler",
"type": "module",
"exports": "./dist/makensis.mjs",
@@ -25,33 +25,33 @@
"license": "MIT",
"dependencies": {
"@nsis/language-data": "^0.9.0",
"dotenv": "^16.0.3",
"dotenv-expand": "^9.0.0"
"dotenv": "^16.3.1",
"dotenv-expand": "^10.0.0"
},
"devDependencies": {
"@ava/babel": "^2.0.0",
"@rollup/plugin-commonjs": "^23.0.2",
"@rollup/plugin-json": "^5.0.1",
"@rollup/plugin-typescript": "^9.0.2",
"@types/node": "^18.11.5",
"@typescript-eslint/eslint-plugin": "^5.41.0",
"@typescript-eslint/parser": "^5.41.0",
"eslint": "^8.26.0",
"@rollup/plugin-commonjs": "^25.0.2",
"@rollup/plugin-json": "^6.0.0",
"@rollup/plugin-typescript": "^11.1.2",
"@types/node": "^20.4.0",
"@typescript-eslint/eslint-plugin": "^5.61.0",
"@typescript-eslint/parser": "^5.61.0",
"eslint": "^8.44.0",
"eslint-plugin-json": "^3.1.0",
"husky": "^8.0.1",
"lint-staged": "13.0.3",
"npm-run-all2": "^6.0.2",
"prettier": "^2.7.1",
"husky": "^8.0.3",
"lint-staged": "13.2.3",
"np": "^7.6.3",
"npm-run-all2": "^6.0.6",
"prettier": "^3.0.0",
"remark-cli": "^11.0.0",
"remark-preset-lint-recommended": "^6.1.2",
"remark-preset-lint-recommended": "^6.1.3",
"remark-preset-prettier": "^2.0.1",
"rimraf": "^3.0.2",
"rollup": "^3.2.3",
"tslib": "^2.4.0",
"typescript": "^4.8.4",
"rimraf": "^5.0.1",
"rollup": "^3.26.2",
"tslib": "^2.6.0",
"typescript": "^5.1.6",
"uuid": "^9.0.0",
"uvu": "^0.5.6",
"which": "^2.0.2"
"which": "^3.0.1"
},
"scripts": {
"build": "rollup -c",
@@ -60,6 +60,7 @@
"lint:code": "eslint ./src --ignore-path .gitignore",
"lint:md": "remark . --quiet --frail --ignore-path .gitignore",
"lint": "npm-run-all --parallel lint:*",
"package": "np --no-yarn --any-branch",
"prepack": "npm run build",
"prepare": "husky install",
"prepublishOnly": "npm run lint && npm run build",
4,103 changes: 2,713 additions & 1,390 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

31 changes: 15 additions & 16 deletions src/commands.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import { mapArguments, objectify, spawnMakensis, splitCommands } from './util';

import type { SpawnOptions } from 'node:child_process';
import type makensis from '../types';

/**
* Returns usage information for a command, or list all commands
* @param command - an NSIS command
* @param compilerOptions - compiler options
* @returns - usage description
*/
async function commandHelp(command = '', compilerOptions: makensis.CompilerOptions = {}, spawnOptions: SpawnOptions = {}): Promise<makensis.CompilerOutput> {
const options: makensis.CompilerOptions = { ...compilerOptions, verbose: 0 };
async function commandHelp(command = '', compilerOptions: Makensis.CompilerOptions = {}, spawnOptions: SpawnOptions = {}): Promise<Makensis.CompilerOutput> {
const options: Makensis.CompilerOptions = { ...compilerOptions, verbose: 0 };

const [cmd, args, opts]: makensis.MapArguments = await mapArguments(['-CMDHELP'], options);
const [cmd, args, opts]: Makensis.MapArguments = await mapArguments(['-CMDHELP'], options);

if (command?.length && typeof command === 'string') {
args.push(command);
@@ -26,8 +25,8 @@ async function commandHelp(command = '', compilerOptions: makensis.CompilerOptio
* @param script - path to NSIS script
* @param compilerOptions - compiler options
*/
async function compile(script: string, compilerOptions: makensis.CompilerOptions = {}, spawnOptions: SpawnOptions = {}): Promise<makensis.CompilerOutput> {
const [cmd, args, opts]: makensis.MapArguments = await mapArguments([], compilerOptions);
async function compile(script: string, compilerOptions: Makensis.CompilerOptions = {}, spawnOptions: SpawnOptions = {}): Promise<Makensis.CompilerOutput> {
const [cmd, args, opts]: Makensis.MapArguments = await mapArguments([], compilerOptions);

if (script) {
if (cmd === 'wine') {
@@ -52,9 +51,9 @@ async function compile(script: string, compilerOptions: makensis.CompilerOptions
* @param compilerOptions - compiler options
* @returns - compiler options
*/
async function headerInfo(compilerOptions: makensis.CompilerOptions = {}, spawnOptions: SpawnOptions = {}): Promise<makensis.CompilerOutput> {
const options: makensis.CompilerOptions = { ...compilerOptions, verbose: 0 };
const [cmd, args, opts]: makensis.MapArguments = await mapArguments(['-HDRINFO'], options);
async function headerInfo(compilerOptions: Makensis.CompilerOptions = {}, spawnOptions: SpawnOptions = {}): Promise<Makensis.CompilerOutput> {
const options: Makensis.CompilerOptions = { ...compilerOptions, verbose: 0 };
const [cmd, args, opts]: Makensis.MapArguments = await mapArguments(['-HDRINFO'], options);

return spawnMakensis(cmd, args, opts, spawnOptions);
}
@@ -64,8 +63,8 @@ async function headerInfo(compilerOptions: makensis.CompilerOptions = {}, spawnO
* @param compilerOptions - compiler options
* @returns - compiler license
*/
async function license(compilerOptions: makensis.CompilerOptions = {}, spawnOptions: SpawnOptions = {}): Promise<makensis.CompilerOutput> {
const [cmd, args, opts]: makensis.MapArguments = await mapArguments(['-LICENSE'], compilerOptions);
async function license(compilerOptions: Makensis.CompilerOptions = {}, spawnOptions: SpawnOptions = {}): Promise<Makensis.CompilerOutput> {
const [cmd, args, opts]: Makensis.MapArguments = await mapArguments(['-LICENSE'], compilerOptions);

return spawnMakensis(cmd, args, opts, spawnOptions);
}
@@ -75,8 +74,8 @@ async function license(compilerOptions: makensis.CompilerOptions = {}, spawnOpti
* @param compilerOptions - compiler options
* @returns - NSIS directory
*/
async function nsisDir(compilerOptions: makensis.CompilerOptions = {}): Promise<string | JSON> {
const hdrOptions: makensis.CompilerOptions = { ...compilerOptions, json: true };
async function nsisDir(compilerOptions: Makensis.CompilerOptions = {}): Promise<string | JSON> {
const hdrOptions: Makensis.CompilerOptions = { ...compilerOptions, json: true };

// eslint-disable-next-line @typescript-eslint/no-explicit-any
function handler(hdrinfo: any) {
@@ -101,9 +100,9 @@ async function nsisDir(compilerOptions: makensis.CompilerOptions = {}): Promise<
* @param compilerOptions - compiler options
* @returns - compiler version
*/
async function version(compilerOptions: makensis.CompilerOptions = {}, spawnOptions: SpawnOptions = {}): Promise<makensis.CompilerOutput> {
const options: makensis.CompilerOptions = { ...compilerOptions, verbose: 0 };
const [cmd, args, opts]: makensis.MapArguments = await mapArguments(['-VERSION'], options);
async function version(compilerOptions: Makensis.CompilerOptions = {}, spawnOptions: SpawnOptions = {}): Promise<Makensis.CompilerOutput> {
const options: Makensis.CompilerOptions = { ...compilerOptions, verbose: 0 };
const [cmd, args, opts]: Makensis.MapArguments = await mapArguments(['-VERSION'], options);

return spawnMakensis(cmd, args, opts, spawnOptions);
}
62 changes: 36 additions & 26 deletions src/util.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { eventEmitter } from './events';
import { constants, promises as fs } from 'node:fs';
import { eventEmitter } from './events';
import { expand as dotenvExpand } from 'dotenv-expand';
import { input as inputCharsets, output as outputCharsets } from './charsets';
import { join } from 'node:path';
import { platform } from 'node:os';
import { spawn } from 'node:child_process';
import dotenv from 'dotenv';
import { expand as dotenvExpand } from 'dotenv-expand';

import type { ChildProcess, SpawnOptions } from 'node:child_process';
import type makensis from '../types';

function detectOutfile(str: string): string {
if (str.includes('Output: "')) {
@@ -72,10 +71,10 @@ async function findEnvFile(dotenvPath: string | boolean): Promise<string | undef
return dotenvFile;
}

function formatOutput(stream: makensis.StreamOptions, args: Array<string>, opts: makensis.CompilerOptions): makensis.StreamOptionsFormatted {
function formatOutput(stream: Makensis.StreamOptions, args: Array<string>, opts: Makensis.CompilerOptions): Makensis.StreamOptionsFormatted {
const stdOut = stream.stdout.toString().trim();
const stdErr = stream.stderr.toString().trim();
const output: makensis.StreamOptionsFormatted = {
const output: Makensis.StreamOptionsFormatted = {
stdout: stdOut,
stderr: stdErr,
};
@@ -106,14 +105,14 @@ function formatOutput(stream: makensis.StreamOptions, args: Array<string>, opts:
return output;
}

async function getMagicEnvVars(envFile: string | boolean): Promise<makensis.EnvironmentVariables> {
async function getMagicEnvVars(envFile: string | boolean): Promise<Makensis.EnvironmentVariables> {
dotenvExpand(
dotenv.config({
path: await findEnvFile(envFile),
})
);

const definitions: makensis.EnvironmentVariables = {};
const definitions: Makensis.EnvironmentVariables = {};
const prefix = 'NSIS_APP_';

Object.keys(process.env).map((item) => {
@@ -161,7 +160,7 @@ function inRange(value: number, min: number, max: number): boolean {
return value >= min && value <= max;
}

async function mapArguments(args: string[], options: makensis.CompilerOptions): Promise<makensis.MapArguments> {
async function mapArguments(args: string[], options: Makensis.CompilerOptions): Promise<Makensis.MapArguments> {
const pathToMakensis: string = options.pathToMakensis ? options.pathToMakensis : 'makensis';

const pathToWine: string = options.pathToWine ? options.pathToWine : 'wine';
@@ -180,8 +179,9 @@ async function mapArguments(args: string[], options: makensis.CompilerOptions):
cmd,
args,
{
events: options.events,
json: options.json,
wine: options.wine,
wine: options.wine
},
];
}
@@ -267,10 +267,10 @@ async function mapArguments(args: string[], options: makensis.CompilerOptions):
args = [...args, ...options.rawArguments];
}

return [cmd, args, { json: options.json, wine: options.wine }];
return [cmd, args, { events: options.events, json: options.json, wine: options.wine }];
}

function objectify(input: string, key: string | null): makensis.Objectified | string {
function objectify(input: string, key: string | null): Makensis.Objectified | string {
if (key === 'version' && input.startsWith('v')) {
input = input.substr(1);
}
@@ -279,14 +279,14 @@ function objectify(input: string, key: string | null): makensis.Objectified | st
return input;
}

const output: makensis.Objectified = {};
const output: Makensis.Objectified = {};
output[key] = input;

return output;
}

function objectifyFlags(input: string, opts: makensis.CompilerOptions): makensis.HeaderInfo {
const output: makensis.HeaderInfo = {
function objectifyFlags(input: string, opts: Makensis.CompilerOptions): Makensis.HeaderInfo {
const output: Makensis.HeaderInfo = {
sizes: {},
defined_symbols: {},
};
@@ -303,8 +303,8 @@ function objectifyFlags(input: string, opts: makensis.CompilerOptions): makensis
}
});

const tableSizes: makensis.HeaderInfoSizes = {};
const tableSymbols: makensis.HeaderInfoSymbols = {};
const tableSizes: Makensis.HeaderInfoSizes = {};
const tableSymbols: Makensis.HeaderInfoSymbols = {};
let symbols: string[] = [];

if (!filteredLines?.length) {
@@ -352,11 +352,11 @@ function objectifyFlags(input: string, opts: makensis.CompilerOptions): makensis
return output;
}

function objectifyHelp(input: string, opts: makensis.CompilerOptions): makensis.HelpObject | string {
function objectifyHelp(input: string, opts: Makensis.CompilerOptions): Makensis.HelpObject | string {
const lines = splitLines(input, opts);
lines.sort();

const output: makensis.CommandHelpOptions = {};
const output: Makensis.CommandHelpOptions = {};

if (lines?.length) {
lines.map((line) => {
@@ -375,8 +375,8 @@ function objectifyHelp(input: string, opts: makensis.CompilerOptions): makensis.
return output;
}

function spawnMakensis(cmd: string, args: Array<string>, compilerOptions: makensis.CompilerOptions, spawnOptions: SpawnOptions = {}): Promise<makensis.CompilerOutput> {
return new Promise<makensis.CompilerOutput>((resolve, reject) => {
function spawnMakensis(cmd: string, args: Array<string>, compilerOptions: Makensis.CompilerOptions, spawnOptions: SpawnOptions = {}): Promise<Makensis.CompilerOutput> {
return new Promise<Makensis.CompilerOutput>((resolve, reject) => {
if (compilerOptions.wine) {
spawnOptions['env'] = Object.freeze({
WINEDEBUG: '-all',
@@ -385,7 +385,7 @@ function spawnMakensis(cmd: string, args: Array<string>, compilerOptions: makens
});
}

const stream: makensis.StreamOptions = {
const stream: Makensis.StreamOptions = {
stdout: '',
stderr: '',
};
@@ -397,6 +397,7 @@ function spawnMakensis(cmd: string, args: Array<string>, compilerOptions: makens

child.stdout?.on('data', (data: Buffer) => {
const line = data.toString();
stream.stdout += line;
const warnings = hasWarnings(line);

warningsCounter += warnings;
@@ -405,23 +406,30 @@ function spawnMakensis(cmd: string, args: Array<string>, compilerOptions: makens
outFile = detectOutfile(line);
}

if (!compilerOptions.events) {
return;
}

eventEmitter.emit('stdout', {
line,
outFile,
hasWarning: Boolean(warnings),
});

stream.stdout += line;
});

child.stderr?.on('data', (data: Buffer) => {
const line = data.toString();
stream.stderr += line;

if (!compilerOptions.events) {
return;
}

eventEmitter.emit('stderr', {
line,
});

stream.stderr += line;
});

child.on('error', (errorMessage: string) => {
@@ -432,7 +440,7 @@ function spawnMakensis(cmd: string, args: Array<string>, compilerOptions: makens
child.on('close', (code: number) => {
const streamFormatted = formatOutput(stream, args, compilerOptions);

const output: makensis.CompilerOutput = {
const output: Makensis.CompilerOutput = {
status: code,
stdout: streamFormatted.stdout || '',
stderr: streamFormatted.stderr || '',
@@ -443,7 +451,9 @@ function spawnMakensis(cmd: string, args: Array<string>, compilerOptions: makens
output['outFile'] = outFile;
}

eventEmitter.emit('exit', output);
if (compilerOptions.events) {
eventEmitter.emit('exit', output);
}

if (code === 0 || (streamFormatted.stderr && !hasErrorCode(streamFormatted.stderr))) {
// Promise will be resolved on MakeNSIS errors...
@@ -482,7 +492,7 @@ function splitCommands(data: string | string[]): string[] {
return args;
}

function splitLines(input: string, opts: makensis.CompilerOptions = {}): string[] {
function splitLines(input: string, opts: Makensis.CompilerOptions = {}): string[] {
const lineBreak = platform() === 'win32' || opts.wine === true ? '\r\n' : '\n';
const output = input.split(lineBreak);

14 changes: 7 additions & 7 deletions tests/native/commands.test.mjs
Original file line number Diff line number Diff line change
@@ -60,7 +60,7 @@ test('Print makensis license', async (t) => {
assert.is(actual, expected);
} catch ({ stdout }) {
// NSIS < 3.03
t.log('Legacy NSIS');
console.log('Legacy NSIS');
const expected = shared.license;
const actual = stdout;

@@ -82,7 +82,7 @@ test('Print makensis license as JSON', async (t) => {
assert.is(actual, expected);
} catch ({ stdout }) {
// NSIS < 3.03
t.log('Legacy NSIS');
console.log('Legacy NSIS');
let expected = shared.license;
expected = JSON.stringify({ license: expected });

@@ -104,7 +104,7 @@ test('Print compiler information', async (t) => {
assert.is(actual, expected);
} catch ({ stdout }) {
// NSIS < 3.03
t.log('Legacy NSIS');
console.log('Legacy NSIS');
const expected = shared.headerInfo;
const actual = stdout;

@@ -121,7 +121,7 @@ test('Print compiler information as JSON', async (t) => {
assert.is(actual, expected);
} catch (error) {
// NSIS < 3.03
t.log('Legacy NSIS');
console.log('Legacy NSIS');
const expected = true;
const actual = stdout.defined_symbols.__GLOBAL__;

@@ -139,7 +139,7 @@ test('Print help for all commands', async (t) => {
assert.is(actual, expected);
} catch ({ stdout }) {
// NSIS < 3.03
t.log('Legacy NSIS');
console.log('Legacy NSIS');
const expected = shared.commandHelp.replace(/\s+/g, '');
const actual = stdout.replace(/\s+/g, '');

@@ -157,7 +157,7 @@ test('Print help for OutFile command', async (t) => {
assert.is(actual, expected);
} catch ({ stdout }) {
// NSIS < 3.03
t.log('Legacy NSIS');
console.log('Legacy NSIS');
const expected = shared.outFile;
const actual = stdout;

@@ -176,7 +176,7 @@ test('Print help for OutFile command as JSON', async (t) => {
assert.is(actual, expected);
} catch ({ stdout }) {
// NSIS < 3.03
t.log('Legacy NSIS');
console.log('Legacy NSIS');
const expected = outFile;
const actual = stdout;

17 changes: 10 additions & 7 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
{
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"module": "ES2020",
"moduleResolution": "node",
"strict": true
},
"typeRoots": ["./types", "./node_modules/@types"]
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"declaration": true,
"module": "ES2020",
"moduleResolution": "node",
"outDir": "dist",
"skipLibCheck": true,
"strict": true
},
"typeRoots": ["./types", "./node_modules/@types"]
}
19 changes: 17 additions & 2 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
declare namespace makensis {
import type { EventEmitter } from 'node:events';
import type { SpawnOptions } from 'node:child_process';

declare namespace Makensis {
function commandHelp(command: string, compilerOptions: CompilerOptions, spawnOptions: SpawnOptions): Promise<CompilerOutput>;
function compile(script: string, compilerOptions: CompilerOptions, spawnOptions: SpawnOptions): Promise<CompilerOutput>;
function headerInfo(compilerOptions: CompilerOptions, spawnOptions: SpawnOptions): Promise<CompilerOutput>;
function license(compilerOptions: CompilerOptions, spawnOptions: SpawnOptions): Promise<CompilerOutput>;
function nsisDir(compilerOptions: CompilerOptions): Promise<string | JSON>;
function version(compilerOptions: CompilerOptions, spawnOptions: SpawnOptions): Promise<CompilerOutput>;

const events: EventEmitter;

interface CommandHelpOptions {
[key: string]: string;
}

interface CompilerOptions {
define?: DefineOptions;
env?: string | boolean;
events?: boolean;
inputCharset?: string;
json?: boolean;
noCD?: boolean;
@@ -63,6 +76,7 @@ declare namespace makensis {
type MapArguments = [string, string[], MapArgumentOptions];

interface MapArgumentOptions {
events?: boolean;
json?: boolean;
wine?: boolean;
}
@@ -81,4 +95,5 @@ declare namespace makensis {
}
}

export default makensis;
export = Makensis;
export as namespace Makensis;