Skip to content

Package improvements for bundling and tree-shaking#75

Merged
dentarg merged 3 commits intocloudamqp:mainfrom
ngbrown-forks:feature/package-improvements
Jul 25, 2023
Merged

Package improvements for bundling and tree-shaking#75
dentarg merged 3 commits intocloudamqp:mainfrom
ngbrown-forks:feature/package-improvements

Conversation

@ngbrown
Copy link
Copy Markdown
Contributor

@ngbrown ngbrown commented Jul 25, 2023

My application bundler (esbuild) wasn't able to completely tree-shake the AMQPWebSocketClient import and was adding a node-modules-polyfills:buffer to the output bundle.

This pull request resolves that through these changes:

  • "sideEffects": false, in package.json tells bundlers to not include an import if nothing is used from that import.
  • Setting the subpath conditional exports lets individual library files be imported instead of just through index.ts. Eliminates any question if something is going to be removed or not by tree-shaking, since it isn't imported in the first place. End applications will need to use a TypeScript moduleResolution setting of node16, nodenext, or bundler to use the additional subpath exports.
  • Removed the now obsolete ava config.
  • Enabled "moduleResolution": "node16" to enforce all imports correctly. "node" is for node v11 and earlier behavior (more info).
  • Enable eslint rule @typescript-eslint/consistent-type-imports and fix errors. May also help bundlers if an import is only being included for its types.

This also closes #63 because the AMQPBaseClient will be importable directly from the amqp-base-client.js file:

import { AMQPBaseClient } from "@cloudamqp/amqp-client/amqp-base-client";

I've tested the changes on my local application.

ngbrown added 3 commits July 24, 2023 15:48
- Add sideEffect: false for better treeshaking
- Remove "ava" section
- Set subpath exports for per-file importing
Comment thread .eslintrc.json
@@ -1,4 +1,5 @@
{
"ignorePatterns": ["types/", "dist/", "lib/"],
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I see this is useful when running eslint directly, e.g. npm exec -- eslint . and not npm run lint

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Also useful when running an eslint plugin within an editor such as Visual Studio Code.

Copy link
Copy Markdown
Member

@dentarg dentarg left a comment

Choose a reason for hiding this comment

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

This all makes sense to me

@dentarg dentarg merged commit 224f3ca into cloudamqp:main Jul 25, 2023
Comment thread .eslintrc.json
"rules": {
"no-console": "off"
"no-console": "off",
"@typescript-eslint/consistent-type-imports": "error"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'll drop a link to the docs on this rule as I looked it up: https://typescript-eslint.io/rules/consistent-type-imports/

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.

Export AMQPBaseClient type

2 participants