Skip to content

Explicitly require commands #1119

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 8, 2025
Merged

Conversation

Everspace
Copy link
Contributor

Currently anything that includes shelljs in it's chain cannot be bundled into a singular file due to the dynamic require. By explicitly requiring everything in src, this allows singular bundles through things like esbuild.

@Everspace Everspace closed this Mar 10, 2023
@TimothyJones
Copy link

I'd love to see this merged - is there a reason not to?

@7PH
Copy link

7PH commented Jun 5, 2024

I suggested another solution to this issue in here, but I've only tested it with esbuild, it would be interesting to know if it also fixes the other bundlers

@Everspace
Copy link
Contributor Author

It would apply to every bundler @7PH

@7PH
Copy link

7PH commented Oct 29, 2024

Later, I've tested more bundlers and some already work with shelljs, some don't because of this project's dynamic imports.

But my PR isn't getting a lot of attention by the owner of shelljs so I'm not sure this is going to get fixed soon.

@AlexanderLill
Copy link

AlexanderLill commented Dec 2, 2024

Dear maintainers @nfischer @freitagbr, please consider merging this minor change to make shelljs compatible with esbuild and other bundlers (see previous comments and many of the open issues, e.g. #1160 #1172 etc).

I am currently using my own fork of this repository to fix this, and I think many people would benefit from this change.

require('./src/echo');
require('./src/error');
require('./src/errorCode');
// require('./src/exec-child'); excluded since it is for commandline only
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we remove this line? This is just a code comment so it doesn't do anything in regular node. Is this commented-out code necessary in order to trick the bundler?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should change this to just actually require() the exec-child.js file. If you rebase on the lastest master branch, then I have changed this to be a NOOP. I think requiring is necessary to trick the bundler into realizing this file is necessary.

@Everspace
Copy link
Contributor Author

Everspace commented Feb 20, 2025 via email

Copy link
Member

@nfischer nfischer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please do the following:

  • Rebase on top of latest master branch, including PR #1187
  • Remove the commands.js file
  • Edit package.json to remove the reference to commands.js
  • Please confirm if this PR will fix either #1160 and #1172

require('./src/echo');
require('./src/error');
require('./src/errorCode');
// require('./src/exec-child'); excluded since it is for commandline only
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should change this to just actually require() the exec-child.js file. If you rebase on the lastest master branch, then I have changed this to be a NOOP. I think requiring is necessary to trick the bundler into realizing this file is necessary.

@nfischer
Copy link
Member

nfischer commented Mar 8, 2025

I'm going to approve now and land this. I'll send the necessary patches for followup fixes.

Thanks for your contribution!

@nfischer nfischer merged commit 127409c into shelljs:master Mar 8, 2025
@nfischer nfischer added this to the v0.9.0 milestone Mar 8, 2025
nfischer added a commit that referenced this pull request Mar 8, 2025
No change to logic. This is a follow up to PR #1119. This change:

* Deletes commands.js entirely and edits the 'files' section of
  package.json
* Undoes some duplicate imports (ex. src/error)
* Adds an explicit import for exec-child.js as a hint for the bundler

After this change, I expect that bundlers/minifiers such as esbuild will
now correctly process shelljs.

Fixes #1160
nfischer added a commit that referenced this pull request Mar 8, 2025
No change to logic. This is a follow up to PR #1119. This change:

* Deletes commands.js entirely and edits the 'files' section of
  package.json
* Undoes some duplicate imports (ex. src/error)
* Adds an explicit import for exec-child.js as a hint for the bundler

After this change, I expect that bundlers/minifiers such as esbuild will
now correctly process shelljs.

Fixes #1160
@Everspace
Copy link
Contributor Author

Ack I am so sorry, I've been busy. Thank you very much for your help and getting this merged in.

kmashint pushed a commit to kmashint/shelljs that referenced this pull request Apr 10, 2025
Currently anything that includes shelljs in it's chain cannot be bundled into a singular file due to the dynamic require. By explicitly requiring everything in src, this allows singular bundles through things like esbuild.
kmashint pushed a commit to kmashint/shelljs that referenced this pull request Apr 10, 2025
No change to logic. This is a follow up to PR shelljs#1119. This change:

* Deletes commands.js entirely and edits the 'files' section of
  package.json
* Undoes some duplicate imports (ex. src/error)
* Adds an explicit import for exec-child.js as a hint for the bundler

After this change, I expect that bundlers/minifiers such as esbuild will
now correctly process shelljs.

Fixes shelljs#1160
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants