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

Make library tree-shakable #44

Merged
merged 4 commits into from
Nov 27, 2023
Merged

Make library tree-shakable #44

merged 4 commits into from
Nov 27, 2023

Conversation

lawrence-forooghian
Copy link

For ably/ably-js#1492 I want to re-export this library from ably-js as a tree-shakable module. In order to make the library tree-shakable, I convert it to use ES modules and ES classes, and mark one expression as /* @__PURE__ */. See commit messages for more details.

@lawrence-forooghian lawrence-forooghian marked this pull request as ready for review November 21, 2023 13:27
lawrence-forooghian added a commit to ably/ably-js that referenced this pull request Nov 21, 2023
lawrence-forooghian added a commit to ably/ably-js that referenced this pull request Nov 22, 2023
lawrence-forooghian added a commit to ably/ably-js that referenced this pull request Nov 22, 2023
lawrence-forooghian added a commit to ably/ably-js that referenced this pull request Nov 23, 2023
lawrence-forooghian added a commit to ably/ably-js that referenced this pull request Nov 23, 2023
Copy link

@owenpearson owenpearson left a comment

Choose a reason for hiding this comment

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

Changes all looks reasonable to me but would you mind setting up a workflow to run npm test, feels quite important to be able to see the tests passing alongside this kind of refactoring

lawrence-forooghian added a commit to ably/ably-js that referenced this pull request Nov 24, 2023
We expose an ES module version of the library for module bundlers to
use, and generate a CommonJS version for Node.

The motivation is that, for [1] I want to re-export this library from
ably-js as a tree-shakable module. Tree-shakability requires that we use
ES modules.

I’ve output the Node bundle to a new `build` directory, since I don’t
know whether the `dist` directory has some special meaning for the
`ably-env deploy` script and so didn’t want to put non-CDN stuff in
there.

The version of Node that the README tells us to use does not support ES
modules, so we generate a CommonJS bundle for the tests to use, which
includes all of the internal components so that they can be tested.

I tested these changes for regressions by:

1. running `npm run grunt -- test:node`
2. running `npm run grunt -- test:browser:local`
3. generating an NPM package using `npm pack`, installing it in ably-js,
   and running the delta tests there

[1] ably/ably-js#1492
Motivation as in 9d8aeb8, and tested in the same way.

I don’t know exactly _what_ about the non-class way of doing things made
it not be tree-shakable; I can only speculate that it was the
`.prototype.foo = ...` statements.

The update to Babel is because the version we were using didn’t support
class fields.
Not running the BrowserStack ones because I don’t want to spend time
getting credentials set up right now.

I’ve changed the browser to headless to avoid the error "no DISPLAY
environment variable specified" in CI.
@lawrence-forooghian
Copy link
Author

Changes all looks reasonable to me but would you mind setting up a workflow to run npm test, feels quite important to be able to see the tests passing alongside this kind of refactoring

Sure, I've pushed a commit to run the Node tests and local browser tests (runs in Firefox). I haven't configured it to run the BrowserStack tests — would you like me to? If so, do you know whether we already have some credentials I could get my hands on?

Copy link

@owenpearson owenpearson left a comment

Choose a reason for hiding this comment

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

I think these tests are sufficient for now, we haven't used browserstack in a while and i'd lean towards using playwright if we want to expand the browser testing in future

@lawrence-forooghian lawrence-forooghian merged commit faaf677 into main Nov 27, 2023
1 check passed
@lawrence-forooghian lawrence-forooghian deleted the tree-shaking branch November 27, 2023 12:19
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.

2 participants