Skip to content

Neutral JavaScript runtime support (Deno, Bun, etc) #2169

Closed
@sgammon

Description

@sgammon

Hey there @tj,

First of all, big fan of commander; I've used it for a long time, so, longtime user first time contributor 😁. I have a patch for commander which makes it work neutrally on all JS runtimes; it was already working fine on Bun and Node, but with the following two small changes:

  • Prefixing Node API imports with node:*
  • Importing process into an explicit symbol

... it will now run smoothly on Deno as well.

For context: I'm trying to ship a tool downstream, hashlock, which uses commander, but I want it to be able to run on any JS runtime.

Distribution diff:

diff --git a/node_modules/commander/lib/command.js b/node_modules/commander/lib/command.js
index 5b16e60..e1ddedb 100644
--- a/node_modules/commander/lib/command.js
+++ b/node_modules/commander/lib/command.js
@@ -1,8 +1,8 @@
-const EventEmitter = require('events').EventEmitter;
-const childProcess = require('child_process');
-const path = require('path');
-const fs = require('fs');
-const process = require('process');
+const EventEmitter = require('node:events').EventEmitter;
+const childProcess = require('node:child_process');
+const path = require('node:path');
+const fs = require('node:fs');
+const process = require('node:process');
 
 const { Argument, humanReadableArgName } = require('./argument.js');
 const { CommanderError } = require('./error.js');

PR incoming shortly.

This issue body was partially generated by patch-package.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions