Skip to content

Conversation

@alexojegu
Copy link
Contributor

Exports shell.js and make.js on package.json so make.js can be imported as "shelljs/make" without require file extension when using ESM.

Exports shell.js and make.js on package.json so make.js can be imported as "shelljs/make" without require file extension when using ESM.
@nfischer
Copy link
Member

Can you link me to documentation on the exports attribute of package.json? I'm not familiar with this. Sounds like it might be specific to ESM modules, but I'd like to make sure I understand before merging.

@nfischer nfischer self-assigned this Nov 13, 2023
@alexojegu
Copy link
Contributor Author

alexojegu commented Nov 13, 2023

The related section of the official documentation: https://nodejs.org/docs/latest-v20.x/api/packages.html#package-entry-points

After rereading, can be better:

"main": "./shell.js",
"exports": {
  ".": "./shell.js"
  "./make": "./make.js",
  "./make.js": "./make.js"
},

What do you think?

@nfischer
Copy link
Member

That link suggests this applies to both commonjs and ESM, but your PR mentions you're running into problems with ESM specifically. Do I understand correctly that ESM doesn't respect the main attribute, but does respect exports? Or does ESM just struggle with the shelljs/make syntax (as opposed to shelljs/make.js)?

shelljs/make isn't officially supported anymore, but I'm OK with adding this as an export since that's fairly low effort.

@nfischer
Copy link
Member

Do you want to add a line for

"./make.js": "./make.js"

or should I merge as-is?

@alexojegu
Copy link
Contributor Author

alexojegu commented Nov 14, 2023

ESM respects the main attribute, but with only the main attribute it is not possible to include both shell.js and make.js.

The correct syntax with ESM to import from node_modules is shelljs/make without the extension (I could still import it using shelljs/make.js even if it was not correct).

I will make another PR, if I can this afternoon, to add the line "./make.js": "./make.js" since in CommonJS the correct syntax is shelljs/make.js with the extension.

shelljs/make isn't officially supported anymore, but I'm OK with adding this as an export since that's fairly low effort.

It is a pity (I will try to refactorice to use shell.js directly).

Exports make.js on package.json so make.js can be required as "shelljs/make.js" using CommonJS.
@codecov
Copy link

codecov bot commented Nov 17, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (6269733) 97.27% compared to head (a7ab844) 97.27%.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1135   +/-   ##
=======================================
  Coverage   97.27%   97.27%           
=======================================
  Files          36       36           
  Lines        1360     1360           
=======================================
  Hits         1323     1323           
  Misses         37       37           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@nfischer nfischer merged commit 78ed036 into shelljs:master Nov 17, 2023
@nfischer nfischer added this to the v0.9.0 milestone Nov 17, 2023
nfischer added a commit to shelljs/shx that referenced this pull request Mar 9, 2025
This updates the ShellJS peer dependency to the latest release. This
also drops support for all node versions prior to v18 to match ShellJS's
version range.

This includes some changes due to the latest shelljs version:

* `shx sed -i` will now run silently. This is compatible with unix
  behavior. See shelljs/shelljs#959
* `shx --version` no longer prints the ShellJS version. This is a
  consequence of the switch to an explicit "exports" list in shelljs
  (see shelljs/shelljs#1195 and shelljs/shelljs#1135).

Test: npm test
nfischer added a commit to shelljs/shx that referenced this pull request Mar 9, 2025
This updates the ShellJS peer dependency to the latest release. This
also drops support for all node versions prior to v18 to match ShellJS's
version range.

This includes some changes due to the latest shelljs version:

* `shx sed -i` will now run silently. This is compatible with unix
  behavior. See shelljs/shelljs#959
* `shx --version` no longer prints the ShellJS version. This is a
  consequence of the switch to an explicit "exports" list in shelljs
  (see shelljs/shelljs#1195 and shelljs/shelljs#1135).

Test: npm test
nfischer added a commit to shelljs/shx that referenced this pull request Mar 9, 2025
This updates the ShellJS peer dependency to the latest release. This
also drops support for all node versions prior to v18 to match ShellJS's
version range.

This includes some changes due to the latest shelljs version:

* `shx sed -i` will now run silently. This is compatible with unix
  behavior. See shelljs/shelljs#959
* `shx --version` no longer prints the ShellJS version. This is a
  consequence of the switch to an explicit "exports" list in shelljs
  (see shelljs/shelljs#1195 and shelljs/shelljs#1135).

Test: npm test
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.

2 participants