Skip to content

Explicitly require the commands to help JS bundlers find all the code #962

@lambrospetrou

Description

@lambrospetrou

Node version (or tell us if you're using electron or some other framework):

v12.8.1

ShellJS version (the most recent version/Github branch you see the bug on):

0.8.3

Operating system:

Ubuntu 18.04.3 LTS

Description of the bug:

First of all, thanks for an amazing library, it has been working great for me in all cases I needed it. Apart from today that I tried bundling one of my Node apps.

It would be great if the calls to requires were explicit and not dynamic as it's done at

shelljs/shell.js

Lines 24 to 26 in 57df38c

require('./commands').forEach(function (command) {
require('./src/' + command);
});

Reason is that when we want to bundle the whole Node application/script into a single JS file, it's impossible to get it to bundle correctly.

One example is something I was trying to do today using Shadow-CLJS; more details at thheller/shadow-cljs#290 (comment)

I tried almost every popular bundler, including @zeit/ncc, Parcel-bundler, Rollup, and finally Webpack.

To be honest, I believe webpack managed to resolve the dynamic requires but then had other issues with __dirname which I use in my code (whole other different issue).

However, it would be much easier to integrate with these bundlers if the requires calls were explicit. Any specific reason why you go through the indirection of array of strings and a loop to require versus the direct require of the commands (other than saving a few characters)?

Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionQuestion from a user (which may not require code/documentation changes to the project)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions