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

Update package.json #104

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Update package.json #104

wants to merge 2 commits into from

Conversation

denisx
Copy link

@denisx denisx commented Dec 3, 2024

Add sideEffects: false and module path, for better code split

This set help package works at commonjs and esm emulation

In code we have some named imports

{
  SCHEMES,
  normalize,
  resolve,
  resolveComponents,
  equal,
  serialize,
  parse
}

but it is not tree shaked by bundler, and it use all functions for build.

profit: it will be less unused code at prod bundle (now - using named imports make no effect)

Add sideEffects: false for better code split

Signed-off-by: denisx <[email protected]>
@denisx denisx marked this pull request as ready for review December 3, 2024 10:06
@zekth zekth requested a review from gurgunday December 3, 2024 11:10
@@ -15,6 +15,7 @@
"url": "https://github.com/fastify/fast-uri/issues"
},
"homepage": "https://github.com/fastify/fast-uri",
"sideEffects": false,
Copy link
Member

Choose a reason for hiding this comment

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

What is this? How is this used by the project?

Copy link
Member

Choose a reason for hiding this comment

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

Brave Search:

In a package.json file, sideEffects is a property that indicates whether a package has side effects or not. A side effect occurs when a module’s execution affects something outside its own scope, such as:

Modifying the global scope (e.g., adding properties to the window object).
Throwing errors or exceptions.
Logging messages to the console.
Making network requests or I/O operations.

Why is sideEffects important?

When a bundler like Webpack or Rollup builds a bundle, it uses the sideEffects property to determine which modules can be safely removed or “tree-shaken” from the bundle. This optimization helps reduce the bundle size and improves performance.

I don't know if we support these non-official properties though

Copy link
Member

Choose a reason for hiding this comment

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

  1. https://wiki.commonjs.org/wiki/Packages/1.0
  2. https://docs.npmjs.com/cli/v10/configuring-npm/package-json?v=true

In general, if it isn't documented in one of those places, and doesn't have a direct use by the project itself (e.g. a precommit field used by @fastify/pre-commit), I don't think unexplained properties should be added to the package manifest. If it requires searching the Internet to figure out its purpose, it is an unmaintainable property contributing nothing other than mystery to the project.

Copy link
Member

Choose a reason for hiding this comment

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

I agree with this in principle

Copy link
Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

None of which are used by this project.

Copy link
Member

@gurgunday gurgunday left a comment

Choose a reason for hiding this comment

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

I guess we could add this for isomorphic libraries

@jsumners jsumners dismissed their stale review December 3, 2024 12:20

I won't block this, but I think it is a mistake to add unexplained properties to the package manifest.

@denisx
Copy link
Author

denisx commented Dec 3, 2024

add more info at description 🙏

@jsumners
Copy link
Member

jsumners commented Dec 3, 2024

add more info at description 🙏

Please detail an actual problem. As it is written, I do not see what problem is being fixed. And it seems like there are probably better ways of fixing whatever the problem is.

@denisx
Copy link
Author

denisx commented Dec 3, 2024

adding more info. profit, we need size profit

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

Technically we can't set sideEffects to false because some lookup data is initialized at evaluation time.

@denisx
Copy link
Author

denisx commented Dec 3, 2024

Technically we can't set sideEffects to false because some lookup data is initialized at evaluation time.

Can we understand this data and set to sideEffects directly? (for skipping other unused)

@denisx
Copy link
Author

denisx commented Dec 5, 2024

@mcollina if some data used at evaluation time (or anywhere) and it have been imported, it won't be cutted by bundler

@denisx
Copy link
Author

denisx commented Dec 5, 2024

we can make rc and check

Copy link
Member

@jsumners jsumners left a comment

Choose a reason for hiding this comment

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

I have changed my mind about not adding a blocking review as it stands. We have not seen a clear explanation of what this actually fixes, and there is not any test included to prove that it fixes whatever that problem is. In my opinion, in order to merge this, it needs to include a test that fails without the change.

@denisx
Copy link
Author

denisx commented Dec 6, 2024

Have you test to check "main": "index.js" at package.json?

Second line to bundler

Signed-off-by: denisx <[email protected]>
@jsumners
Copy link
Member

jsumners commented Dec 6, 2024

Have you test to check "main": "index.js" at package.json?

I don't understand the question.

@denisx
Copy link
Author

denisx commented Dec 6, 2024

You write "it needs to include a test", but my pr set package.json settings, such another "main": "index.js" setting. But there are no tests )

Ok, my decision: a make a clone with another name, and publish not oficial rc version, to check at project. And then we will resolve or reject pr.

@jsumners
Copy link
Member

jsumners commented Dec 6, 2024

You write "it needs to include a test", but my pr set package.json settings, such another "main": "index.js" setting. But there are no tests )

Ok, my decision: a make a clone with another name, and publish not oficial rc version, to check at project. And then we will resolve or reject pr.

As detailed in #104 (comment), the main field is a documented manifest field guaranteed to be used by the package manager we support: npm.

Regardless, it is tested in all of the unit tests. As an example:

const URI = require('../')

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.

5 participants