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
Fixed the default export shape in strict ESM environments #543
Conversation
🦋 Changeset detectedLatest commit: a863d53 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## main #543 +/- ##
==========================================
+ Coverage 90.64% 91.30% +0.66%
==========================================
Files 36 37 +1
Lines 1592 1667 +75
Branches 452 468 +16
==========================================
+ Hits 1443 1522 +79
+ Misses 141 137 -4
Partials 8 8
☔ View full report in Codecov by Sentry. |
de04cfa
to
a9c11a8
Compare
a9c11a8
to
fd91a80
Compare
packages/cli/src/package.ts
Outdated
@@ -420,6 +422,15 @@ function parseExportsFieldConfig( | |||
name | |||
); | |||
} | |||
} else if (key === "unwrappedDefaultExportForImportCondition") { |
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 love to use this repo-wide, see a similar concern+question here
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.
Yes to making it project-wide, an empty object should be valid and equivalent to true (i would imagine an empty object already works on a package)
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 proxy files need to be written for preconstruct dev
as well (let’s just do an export * from
there)
what about declaration maps and other source map things? i'm not sure how to handle those correctly |
We only generate js source maps for UMD builds so that isn’t a thing. For declaration maps, you should be able to just write the same declaration map we use for .cjs.d.ts but as .cjs.d.mts |
Thinking about this more and the fact that I think the right answer is just to avoid default exports, I’d like to have three modes:
For the config, probably this: "importConditionDefaultExport": "namespace" | "default" | "namespace-disallow-default" It would be outside of the |
While there are good reasons to avoid I also believe that the problem is not even exclusive to packages with import ns from 'cjs-lib' I think that's not a good thing because it can accidentally be used by users and it's likely not how the lib's usage is documented. |
Yeah, fair. I was initially thinking who cares about the namespace being technically available but i suppose if more people actually use native ESM, it'll be kinda annoying so sure. I do think I prefer the config with string values instead of booleans though, so if you could make the config this (still inside of exports unlike my last comment suggests though + allow it to be specified at a project level exports option), that would be great. "importConditionDefaultExport": "namespace" | "default" |
241b4ad
to
3dbee6f
Compare
37f4a38
to
34ca570
Compare
ddae703
to
f9011d4
Compare
🎁 packages/pkg-b/src/index.ts:1:14 - error TS2841: The type of this expression cannot be named without a 'resolution-mode' assertion, which is an unstable feature. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'. | ||
🎁 | ||
🎁 1 export const thing = import("pkg-a"); |
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.
is this because TS already supported import
in declaration files, it had its own semantics and stuff so now it can't use that syntax alone to differentiate between loading a thing with import/require semantics? 🤔
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.
yes
Re naming bike shedding: curious to hear reasoning behind the naming you've done? I've added some docs using the naming I suggested. To me, |
316e58c
to
c5cc67a
Compare
The time has come, brace yourself, yadayada 😉