package.json: use file extensions for esmodules compatibility #19
No reviewers
Labels
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: sheetjs/js-crc32#19
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "patch-1"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
thanks for this wonderful repository! we use it in @ethereumjs/common
we are just upgrading to esmodules support and found these file extensions necessary to get to the types, we'll put a hotfix in place but thought it would be nice to contribute upstream
Somehow we have 3 different packages with 3 different styles 😆
The
xlsx
package does not include the leading./
:The
adler-32
package does not have amain
extension:This PR is proposing
Ideally there'd be one style for the main script and for the types.
Ping @josh-hemphill @ntnyq
Also, since this is top of mind, would it be helpful to also ship an ESM version? For another project,
printj
, we ended up making the build script generate an ESM version as well as a normal CJS scriptUsing explicit extensions is necessary for compatibility with ESM and typescript. I personally like avoiding the use of
./
when practical because it's not a pattern that people coming from windows filesystems are familiar with. But most libraries I've been contributing to have been addingexports
fields to theirpackage.json
to support all the various usages, which ultimately requires./
to describe how nested imports should work.So for libraries, I think just always using
./
is probably the right call. Having theexports
field filled out to support various versions of Node.js and fallbacks forcjs
andesm
is usually a good idea, even if you don't need it yet to add listings for common nested import or internal files people are using.that's funny 😄
I also tended not to use relative imports, but I was reading the package.json "exports" proposal (https://github.com/jkrems/proposal-pkg-exports/) and it's recommended there, so I've been using
./
It's specifically talking about the values of the "exports" keys, so maybe it doesn't apply here, but I figure why not.
The official npm docs has an example with
main
referencing a subdirectory. Search for the code block with "ethopia-waza":@types/lodash
has atypes
field that does not include the leading./
:The "standard" approach seems to be "use file extensions" and "don't prepend with
./
"@ryanio please try it without the
./
. If it works in your local flow, please amend the PR and we'll accept:The
adler-32
andprintj
projects should be changed to follow the same style.Sounds good, will try and update, should be fine
edit: yep it worked for me locally!