-
Notifications
You must be signed in to change notification settings - Fork 365
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
Fixing exports #2977
Comments
Thank you, this is very helpful and I agree we should start fixing this!
Yes, that needs to be resolved. I think 1) + 2) are the same problem really and due to the missing entrypoint.
Not sure I agree with that. We got a lot of feedback on AWS CDK that submodules exports are the preferred way. It might not even be possible with naming conflicts. And there's also the general disadvantage of using barrel files. 🤔 Why do you think exporting everything at top-level is preferred?
Looks like this is also mostly due to the missing entrypoint and thus the tool picking up bundled modules. Which I guess you can import today, but really shouldn't. 😓 |
Fewer import lines. It's not uncommon to have 5 lines importing from
Yes, just saw on HN yesterday a benchmark of barrels - and they do slow things down a lot. But only when not using bundling. If the entire projen is bundled into a single
Yes, thought of that, but didn't investigate. Would be a deal breaker, perhaps, unless, of course, renaming and breaking change is an option when going to v1 ;)
But, IMO this could be done both ways? import { Component, typescript } from 'projen'
import { ... } from 'projen/typescript' But, ideally I think, at least the high-level components and projects can be exported from the root as well: import { TypeScriptProject } from 'projen' Right now we must do the following: import { TypeScriptProject } from 'projen/lib/typescript' Which is quite verbose IMO for something so commonly used. |
Right, it is about defining entry points. But those also need to be carefully considered, as they would constitute a public interface. Unless, of course, a wildcard is used exposing everything. But I think this needs to be closed up, and only allow importing from a well-defined export path, like cdk does. But it can go slightly beyond that also, if we want to have truly universal packages that support both CJS and ESM ecosystems. Those exports, and bundling, need to support both cases. If we use This is what a "good" export setup looks like that passes "main": "./lib/index.js",
"types": "./lib/index.d.ts",
"module": "./lib/index.mjs",
"exports": {
".": {
"require": {
"types": "./lib/index.d.ts",
"default": "./lib/index.js"
},
"import": {
"types": "./lib/index.d.mts",
"default": "./lib/index.mjs"
}
}
}, This structure is generated by |
The absolutely only way I recommend everyone to use projen today is: import { Component, typescript } from 'projen'
new typescript.TypeScriptProject({ /*...*/ }); If that's to verbose you could alias: import { Component, typescript as ts } from 'projen'
new ts.TypeScriptProject({ /*...*/ }); And with submodule exports, you will have the option to make some trade-offs based on your preferences: import { Component } from 'projen'
import { TypeScriptProject } from 'projen/typescript'
// or this
import * as ts from 'projen/typescript' |
Bundling and ESM are another thing to look at - at some point. These can be v2 things, if we adopt a regular release cadence. |
By modern npm and Node.js standards, projen does a few things wrong regarding packaging.
package.json
./
(see screenshot). This needs to be cleaned up. Only contents oflib/
need to be exported, not the root of the projen repo (e.g.projen/javascript
notprojen/lib/javascript
).projen
, so we don't have import from many sub-paths. E.g. we should be able to do this:import { NodePackage } from 'projen'
Projen exports:
AWS CDK exports:
This is a follow up to: #2976 (comment)
The text was updated successfully, but these errors were encountered: