Skip to content

Commit

Permalink
Downgrade to using nanoid@3 to support its use in CJS module bundle (#…
Browse files Browse the repository at this point in the history
…307)

* Downgrade to using nanoid@3 to support its use in CJS module bundle

Starting from nanoid v4, it only works with ESM projects. We need to
support both CJS and ESM bundles for the `spaces` SDK, so we have the
following options to use the nanoid package:

1. Replace `require('nanoid')` imports with async `await import('nanoid')`.
   This solution is not suitable as the methods we currently use nanoid
   in are not async, and changing them to async will create cascading
   effects for a bunch of other methods and change the public API for
   users.
2. Replace the nanoid package with an in-project utility function to
   generate ids. This may be undesired since nanoid uses different
   `crypto` packages for its browser and Node.js bundles with some other
   platform-specific optimizations. Including them locally would not be
   a trivial change.
3. Downgrade to using nanoid v3, which supports both CJS and ESM and is
   still being supported by the developers [1]. This is the option
   implemented in this commit.

Resolves #306

[1] https://github.com/ai/nanoid?tab=readme-ov-file#install

* Prevent `nanoid` major version updates by dependabot
  • Loading branch information
VeskeR authored May 1, 2024
1 parent 6fb182b commit cff95e3
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 81 deletions.
3 changes: 3 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ updates:
schedule:
interval: "daily" # weekdays (Monday to Friday)
labels: [ ] # prevent the default `dependencies` label from being added to pull requests
ignore:
- dependency-name: "nanoid"
update-types: ["version-update:semver-major"] # prevent from upgrading from nanoid@3, see for more info: https://github.com/ably/spaces/pull/307
64 changes: 20 additions & 44 deletions demo/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"ably": "^1.2.45",
"classnames": "^2.3.2",
"dayjs": "^1.11.9",
"nanoid": "^4.0.2",
"nanoid": "^3.3.7",
"random-words": "^2.0.0",
"react": "^18.2.0",
"react-contenteditable": "^3.3.7",
Expand Down
44 changes: 9 additions & 35 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"vitest": "^0.34.3"
},
"dependencies": {
"nanoid": "^5.0.2"
"nanoid": "^3.3.7"
},
"peerDependencies": {
"ably": "^1.2.46",
Expand Down

0 comments on commit cff95e3

Please sign in to comment.