Skip to content
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

fix: esModuleInterop not working for object-hash and dataloader imports #794

Merged
merged 3 commits into from
May 28, 2023

Conversation

turulix
Copy link
Contributor

@turulix turulix commented Mar 10, 2023

Fixes #793

Copy link
Owner

@stephenh stephenh left a comment

Choose a reason for hiding this comment

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

Hi @turulix , thanks for the PR! I've got a hopefully minor ask to try and let ts-poet do the rewriting/esModuleInterop conditionalization for us, but otherwise this looks great!

@@ -21,9 +21,6 @@ import SourceInfo, { Fields } from "./sourceInfo";
import { contextTypeVar } from "./main";
import { Context } from "./context";

const hash = imp("hash*object-hash");
const dataloader = imp("DataLoader*dataloader");
Copy link
Owner

Choose a reason for hiding this comment

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

Fwiw, this is admittedly kind of cute, but if you'd like how I've handled this in the past is by having ts-poet rewrite the imports.

That was more useful when the imports were scattered all over the ts-proto codebase, while granted for these imports, they're only used ~once/twice so it's not that bad.

That said, if you'd like to try it, I just pushed a new version of ts-poet to handle default --> star rewrites (stephenh/ts-poet@29c834d) so, in theory you could:

  • Bump ts-poet in package.json to 6.4.1
  • Keep these consts by as `const hash = imp("hash=object-hash");
  • Update getTsPoetOpts to include dataloader and object-hash in the imports list, which should a) leave them as-is if esModuleInterop is on, or b) rewrite them to the old import ... as * if esModuleInterop is not on

Do you mind trying that and seeing if it works?

@turulix
Copy link
Contributor Author

turulix commented Mar 11, 2023

I will try it tomorrow or on Monday. Also, I noticed that the 'long' package is imported in the same way that I did in this pull request - I took the syntax from there. Should I do the same thing with it, as mentioned above?

@stephenh
Copy link
Owner

Ah yeah, if the long imports can take advantage of the new ts-poet capability, it'd be great to move those over too. I must have forgotten about those when I taught ts-poet how to handle the protobufjs esModuleInterop conditional imports. Thank you!

@turulix
Copy link
Contributor Author

turulix commented Mar 12, 2023

Bumping ts-poet to 6.4.1 lets the utils-test fail , cause toCodeString() now requires some arguments.

@stephenh
Copy link
Owner

Ah shoot...sorry about that; I think toCodeString was kind of an internal api.

Glancing at it locally, it looks like just changing all the toCodeString -> toString and then updating the inline snapshots fixes it.

Would you like me to push out/merge a dedicated "bump-ts-poet" branch, or do you want to incorporate this fix into your branch?

@turulix
Copy link
Contributor Author

turulix commented Mar 12, 2023

Changing it to toString() makes it fail in a different way. So probably just make that a different branch.
image)

@stephenh
Copy link
Owner

@turulix cool, I just merged the ts-poet bump to main, so you should be able to rebase/merge on top of it. Thanks!

@turulix
Copy link
Contributor Author

turulix commented Mar 12, 2023

Not sure if i'm doing something wrong, but doing

  const imports = [
    "protobufjs/minimal" + _options.importSuffix,
    "object-hash" + _options.importSuffix,
    "dataloader" + _options.importSuffix
  ];

leaves them as import * as ...

@stephenh
Copy link
Owner

Ah yeah, you should be able to leave off the import suffix, so just like:

  const imports = [
    "protobufjs/minimal" + _options.importSuffix,
    "object-hash",
    "dataloader"
  ];

The import suffix is just for doing *.js / *.ts imports in strict ESM mode, but that shouldn't apply to packages like dataloader or object-hash.

...even protobufjs/minimal having the import suffix I'm a little curious about, but let's leave that as-is for now.

@turulix
Copy link
Contributor Author

turulix commented Mar 12, 2023

I assumed its just an empty String if its not set, cause never saw it generate unless i explicitly set it. So it shouldnt have any impact on it

@turulix
Copy link
Contributor Author

turulix commented Mar 13, 2023

It still dosn't change it when removing the suffix.

@stephenh stephenh merged commit 9fc9632 into stephenh:main May 28, 2023
stephenh pushed a commit that referenced this pull request Jun 4, 2023
## [1.148.2](v1.148.1...v1.148.2) (2023-06-04)

### Bug Fixes

* esModuleInterop not working for object-hash and dataloader imports ([#794](#794)) ([9fc9632](9fc9632))
@stephenh
Copy link
Owner

stephenh commented Jun 4, 2023

🎉 This PR is included in version 1.148.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

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.

esModuleInterop not working for object-hash and dataloader imports
2 participants