-
Notifications
You must be signed in to change notification settings - Fork 550
build(drivers/framework): Fix type generation for ESM and add exports field #18824
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
Conversation
⯅ @fluid-example/bundle-size-tests: +18 Bytes
Baseline commit: 04a597c |
@@ -73,6 +73,7 @@ | |||
"uuid": "^9.0.0" | |||
}, | |||
"devDependencies": { | |||
"@arethetypeswrong/cli": "^0.13.3", |
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.
policy-check caught this missing dep
I guess I am a little late to the party. Renaming doesn't feel like a robust build step. Is it not possible for compile step to output |
I don't love it either, but every time I tried to do it in tsc-multi I broke something else. See commentary at tylerbutler/tsc-multi#1 along with the tsc-multi patch I made to make it rewrite the imports. |
Assuming you're referring to odsp-driver, good catch. I updated the PR description to explain that:
|
I looked up more information on this. Surely there is a tsc option. No, there surely is not. And the reason seems to be that typescript is formally against dual emit. Are we making sure that all of our clients understand fullstack and we are only getting ESM or CommonJS? The fact that we run into issues downstream internally is concerning. If our long term plan is to drop CommonJS, then okay. I think there is another option for the rename issue. We inject a package.json with |
That doesn't seem quite right. Shouldn't those fallback? [edit] Ah, well, perhaps the problem is that those folks downstream are using illegal imports. It isn't the module resolution in here that matters but that exports is defined and limited.? |
…ts field (#18825) This PR updates sequence and merge-tree to generate proper types in ESM builds and adds an exports field. I had to update the test files a bit to clean up imports. I also added a ./dist/test export from merge-tree since its internals are used by sequence tests. This is a demonstration of the mechanism we will have to use any time we want to export something for use in another package. No more reaching into internals! This PR includes some configuration and settings changes that are not strictly needed for this PR, but splitting them out doesn't seem worth the time since they're all needed for other pending PRs like #18823 and #18824.
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.
Please do edit the description before merging to be more about the commit than the PR.
Call out the changes that do land in this commit (versus elsewhere).
Also recommend noting why odsp-driver doesn't set exports.
That's true for internal usage and is the primary blocker. However, we did release internal 7.3 with an expoerts field that pointed to non-existent types for ESM, and that definitely broke some people. Now that we have are-the-type-wrong tests in place I am more confident that our packages will work correctly in both node10 and node16 modes when we do enable exports in odsp-driver. |
From an earlier internal discussion:
Relevant bit from the other comment:
|
Does this sufficiently address any TS dependees with |
That comment in the commit is not correct from what I understand. |
Yes, it should work for people using node10 in TypeScript. What node10 users won't be able to use is the non-default exports, like /beta. But node10 is very permissive, just like node is with commonjs. Keep in mind that the module resolution typescript uses has no bearing on what node does at runtime. If you take code compiled in typescript moduleResolution node10 and run the JS output in node 18, node will resolve according to node16 rules. It might work. It might not. This is one of the things I was setting out to fix when I started working in this area. We produce ESM but no one can actually use it, and if they tried to use it in node, it wasn't going to work. Compiling using node16 is the only supported way to get Typescript to help prevent you from shipping bad imports. Thus, while I can confidently say our packages will work with node10, I am also reasonably confident anyone compiling for LTS+ versions of node (i.e. not for a bundler) with that moduleResolution will produce code that won't run in node. |
Sort of. If a downstream consumer is using node10, then they can continue to dig into the internals of a package. Even if we add an exports field, it's not used in node10 as far as I can tell. This seems to corroborate that: https://www.typescriptlang.org/tsconfig#resolvePackageJsonExports |
The comment says downstream need to use |
I don't think you can simplify things like the first statement tries. Typescript is being very explicit about trying to match node as best it can. You quoted https://www.typescriptlang.org/docs/handbook/modules/theory.html#module-format-detection in a Teams chat. TSC cannot know what the ultimate version of node is and what rules are at play, but
The dual emit goes against explicit typescript recommendations in more than the dual hazard.
We workaround with Is there any reason to keep |
…ts field (microsoft#18825) This PR updates sequence and merge-tree to generate proper types in ESM builds and adds an exports field. I had to update the test files a bit to clean up imports. I also added a ./dist/test export from merge-tree since its internals are used by sequence tests. This is a demonstration of the mechanism we will have to use any time we want to export something for use in another package. No more reaching into internals! This PR includes some configuration and settings changes that are not strictly needed for this PR, but splitting them out doesn't seem worth the time since they're all needed for other pending PRs like microsoft#18823 and microsoft#18824.
This PR updates the majority of packages in packages/drivers and packages/framework to generate proper types in ESM builds and adds an
exports
field. The packages were already building using moduleResolution: node16 by virtue of inheriting from the new shared configs, so no changes were needed there. They also have a test using arethetypeswrong that runs in CI.I did NOT add an exports field to the odsp-driver package, because doing that right now breaks a lot of downstream compilation. We should be able to resolve that once more/all packages are using node16 module resolution.