This repository was archived by the owner on Nov 20, 2023. It is now read-only.
-
Couldn't load subscription status.
- Fork 116
fix(types): Enable plugin to be imported under ES6 #316
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
67ad874
add webpack types as dev and peer dependencies
lobsterkatie 5dc2ac9
switch to export= syntax for type declaration file
lobsterkatie a3465f9
add named default export of SentryCliPlugin
lobsterkatie 04e4497
Ignore engines when running yarn install
kamilogorek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,20 @@ | ||
| module.exports = require('./index').default; | ||
|
|
||
| // The assignment to `default` below saves us from having to use | ||
| // `esModuleInterop` (which then would force our users to set the same option), | ||
| // by manually doing the one part of `esModuleInterop`'s job we actually need. | ||
| // | ||
| // (In order to avoid a breaking change, we need to stick with default-exporting | ||
| // `SentryCliPlugin`. This means that if we want to use ES6 imports (in our own | ||
| // use of the plugin), our options are: | ||
| // | ||
| // `import * as x from y`, | ||
| // `import x from y`, and | ||
| // `import {default as x} from y`. | ||
| // | ||
| // If we use the first option, it correctly pulls in the above `module.exports` | ||
| // value, but it treats it as a namespace, not a class, and therefore refuses to | ||
| // let it be used with `new`. If we use either of the other two, it looks for | ||
| // `module.exports.default`, which will be undefined unless either we do (or | ||
| // `esModuleInterop` does) the below.) | ||
iker-barriocanal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| module.exports.default = module.exports; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure about this. This way we will make everyone install it, even when they are not using TypeScript. Otherwise, we'll warn every time they don't.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Warning is fine IMO. But, when does one install the webpack plugin and not webpack?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Never, but those are types, not webpack itself.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I debated about that. I can't believe we put a man on the moon more than half a century ago and still haven't solved this problem. Either we:
make it a hard dependency ( which is what the TS docs would have us do), and plain JS people install a package they don't need, or
make it a peer dependency, and plain JS people get warnings which don't apply to them, or
make it neither, and TS people get yelled at by their linter and/or compiler unless they just happen to already have the relevant types installed.
Which is the least bad, do we think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The first one is a no-go for me, and I rather the third over the second although not strongly opinionated against the second one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd also go with 3rd. If you are using TypeScript and Webpack, there's 99,99% chance that you already have those types installed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, but that's generally for their own dependencies, not transitive ones. I agree it's not the world's biggest blocker, and people will figure it out, so in this case I'm happy to go with option 3, especially since you're right, @kamilogorek, it's not like webpack is obscure and at least some folks will already have the types. (I'm less convinced it's everyone, though. If you're using our nextjs SDK and don't have any custom webpack config other than what you pass to our plugin, there's no reason you'd already have them.) So I can pull it.
As a general principle, though, and given just how popular TS is, it's still just amazing to me that npm/yarn haven't adapted to what has to be a pretty common situation/problem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure this is only an npm/yarn thing, but also from the npm registry? But yes, there should be a solution to this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure what you mean.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The npm registry is npmjs.com, and then the
npmtool which you use to manage the modules in the registry. Anyways, I haven't dived into the registry and I don't know where the solution should be coming from, just giving my thoughts.