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

Build hybrid package - provide commonjs and ESM entry points #535

Merged
merged 1 commit into from
Jan 3, 2023

Conversation

susnux
Copy link
Contributor

@susnux susnux commented Dec 19, 2022

Provide also an entry point for packages using ESM instead of commonjs.
The target for ESM is set to ES2020 / ES2022 which is fully supported by node 16, the lowest node version nextcloud supports.

Signed-off-by: Ferdinand Thiessen <rpm@fthiessen.de>
Copy link
Contributor

@ChristophWurst ChristophWurst left a comment

Choose a reason for hiding this comment

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

👍

Comment on lines +1 to +15
{
"presets": [
"@babel/typescript",
[
"@babel/env",
{
"useBuiltIns": "usage",
"corejs": "3.0.0"
}
]
],
"plugins": [
"transform-class-properties"
]
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this actually needed?

This library is never used as is, but always in another app.
The app should be responsible for babel and transpiling into a specific ES level.

All the other libs are just exporting straight away without any transformations beside es6/commonjs exports syntax

Copy link
Contributor

Choose a reason for hiding this comment

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

Really? I thought we did run also the libs through babel+browserslist. Otherwise users of the lib also have to transpile dependencies, no?

Copy link
Contributor

Choose a reason for hiding this comment

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

As far as I understand this aspect hasn't changed. It just moved from one configuration file to another.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@skjnldsv this is only copied from js to json to be independent to node resolution (mjs vs cjs). So this is untouched, but from my point of view I agree that this is not needed, see my comment below #535 (comment)

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

@skjnldsv skjnldsv Dec 27, 2022

Choose a reason for hiding this comment

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

It seems the one you created indeed use babel.
My guess is that you went for the same pattern on their initialisation?

Anyway, do you have any clue about one library that would be used as is without going through webpack in one of our apps?

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

@nextcloud/vue is babelizing the dist output :)

Copy link
Contributor Author

@susnux susnux Dec 28, 2022

Choose a reason for hiding this comment

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

Anyway, do you have any clue about one library that would be used as is without going through webpack in one of our apps?

I am not sure all apps transpile the dependencies, while this should be done by any application targeting browsers instead of node, as you can not trust every package matches your browser targets.
Because most webpack configs look like this:

// Rules
{
    test: /\.js$/,
    loader: 'babel-loader',
    exclude: /node_modules/,
}

So all dependencies are excluded from the babel transpilation.

But I do not suggest enabling transpilation of all dependencies using babel-loader, the build times are awful.
Instead I recommend to get rid of babel (we do not need ES5 at all, as all supported browsers support ES6), and instead use the build in webpack loader for JS files and only transpile all output on the minification step by using the ESBuildMinifyPlugin (together with browserslist-to-esbuild for setting the output target).
Besides that all dependencies are transpiled this also reduces the bundle size and build time significantly.

Copy link
Contributor

Choose a reason for hiding this comment

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

Interesting, this is a quite wide discussion.
I'm not confortable having only the three of us take a decision that have a company-wide impact.

Can you raise this in https://github.com/nextcloud/standards ?
So we can discuss and decide what to do consistently for all libs?

@susnux
Copy link
Contributor Author

susnux commented Dec 23, 2022

Another question which came up while writhing the PR is:

Is the babel transpiling needed at all? Is there any specific reason for doing it (same with the core-js dependency)?
Because the javascript, emitted by tsc, is already fully compatible with all of the browsers nextcloud supports (checked that with check-es-compat), e.g. this could look like this: 907bbee

@skjnldsv
Copy link
Contributor

Another question which came up while writhing the PR is:

Is the babel transpiling needed at all? Is there any specific reason for doing it (same with the core-js dependency)? Because the javascript, emitted by tsc, is already fully compatible with all of the browsers nextcloud supports (checked that with check-es-compat), e.g. this could look like this: 907bbee

That was my point :)
We don't need transpiling on libs that are imported by apps.
Apps are already transpiling for our browserlist config

@susnux
Copy link
Contributor Author

susnux commented Dec 28, 2022

That was my point :) We don't need transpiling on libs that are imported by apps. Apps are already transpiling for our browserlist config

So should I include the commit for dropping babel transpilation with this PR or open a new one after this is merged?

Copy link
Contributor

@skjnldsv skjnldsv left a comment

Choose a reason for hiding this comment

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

Approving as this does not change the actual behaviour.
Regardless of the discussion it raised :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants