coreybutler / coreybutler/node-windows

[DATE]: Move the "node-windows is only supported on Windows" exception at execution time rather than at require time

Open
#297 2 comments 4 reactions 0 assignees View on GitHub
enhancement
Dominant language
JavaScript
Stars
2.9k
Forks
368
PR merge metrics
No merged PRs in 30d

Description

**Is your feature request related to a problem? Please describe.**
It's hard to test scripts on Mac or Linux as we can't neither `require` the package.

**Describe the solution you'd like**
The only way I found to test my programs on Linux is to write a mock, ok, quite easy. When working on large program, probably it's not a problem, the mock could be useful for many other reasons.
But sometimes it happens that we have to work on short scripts. To write a mock to test a 30 lines script could mean double or triple the time to write the script...

**Describe alternatives you've considered**
So I think that letting us to `require` the package, to call `new` and to attach listeners even if not under Windows and throw the exception only when it's performed an operation that actually can be done only under Windows would facilitate the tests of short scripts also under Linux or Mac.

**Additional context**
A quick script to try to be a bit more clear.
```javascript
// ATM neither this is possible under Linux or Mac, while it should be allowed
const nodeWindows = require("node-windows");

// This should be allowd under Linux and Mac
const { Service } = nodeWindows;

// Also this should be allowd under Linux and Mac
const service = new Service({});

// Both attaching a listener and referencing an impossible to call method should be allowd under Linux and Mac as well
service.on("install", () => service.start());

// This can't actually do nothing else than failing if under Linux or Mac
service.install();
```

Once said that, great job! Thank you very much!


Please use the reactions to cast a vote in favor of or against this feature suggestion »

Contributor guide

Open the contributing guide

Research direction

Start by tracing the require("node-windows") path and the Service constructor, listener attachment, and install entry points described in the example. The change is complete when requiring the package, creating a Service, and attaching listeners work on non-Windows systems while Windows-only operations still fail when performed there.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
backend-api-design, operating-systems
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.