npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

yjs-bundle

v0.1.6

Published

bundles several yjs packages in a single module in order to avoid "Yjs was already imported" problems

Downloads

37

Readme

yjs-bundle

bundles several yjs packages in a single module in order to avoid "Yjs was already imported" problems

Background

When using Yjs in a browser (or another no-build environment, typical import statements such as

import * as Y                from 'yjs'
import { WebsocketProvider } from 'y-websocket'
import { YKeyValue }         from 'y-utility/y-keyvalue'

may lead to a completely unpredictable behaviour of Yjs.

A brief look into the browser console will reveal one or multiple error messages starting with Yjs was already imported. This breaks constructor checks and will lead to issues!

As written by dmonad: this message has to be taken seriously - Yjs will not work as expected!

But how does it then become possible to use Yjs within a browser without having to use a build environment (which will collect all required imports and build a large package including every import only once - together with other advantages)?

One possibility is to just bundle Yjs and all packages that depend on it into one module which may then be safely imported into a script - such an approach is by no means elegant but makes Yjs usable even within no-build environments.

This is what this repo wants to provide.

It currently bundles

  • Yjs
  • y-indexeddb
  • y-websocket
  • y-webrtc
  • y-keyvalue and
  • y-lwwmap

into a single monolith.

Usage

As a consequence, import statements like those shown above will either have to be rewritten as

import * as Y                from 'https://rozek.github.io/yjs-bundle/dist/yjs-bundle.esm.js'
import { WebsocketProvider } from 'https://rozek.github.io/yjs-bundle/dist/yjs-bundle.esm.js'
import { YKeyValue }         from 'https://rozek.github.io/yjs-bundle/dist/yjs-bundle.esm.js'
import { LWWMap }            from 'https://rozek.github.io/yjs-bundle/dist/yjs-bundle.esm.js'

or - and that's the recommended approach - you will have to provide an importmap with the following contents:

<script type="importmap">
{
  "imports": {
    "yjs":          "https://rozek.github.io/yjs-bundle/dist/yjs-bundle.esm.js",
    "y-indexeddb":  "https://rozek.github.io/yjs-bundle/dist/yjs-bundle.esm.js",
    "y-websocket":  "https://rozek.github.io/yjs-bundle/dist/yjs-bundle.esm.js",
    "y-webrtc":     "https://rozek.github.io/yjs-bundle/dist/yjs-bundle.esm.js",
    "y-utility/y-keyvalue":"https://rozek.github.io/yjs-bundle/dist/yjs-bundle.esm.js",
    "y-lwwmap":     "https://rozek.github.io/yjs-bundle/dist/yjs-bundle.esm.js"
  }
}
</script>

and use the same import statements as shown in the docs.

The potential disadvantage of importmaps, however, is that you - or your customers - will need a reasonably modern browser. Definitely supported browsers include:

  • Chrome ≥ 89
  • MS Edge ≥ 89
  • Safari ≥ 16.4
  • Firefox ≥ 108
  • Opera ≥ 76  
  • Chrome for Android ≥ 111
  • Safari on iOS ≥ 16.4

(see "Can I use" for additional details, especially if your browser is not listed above)

Build Instructions

You may easily build this package yourself.

Just install NPM according to the instructions for your platform and follow these steps:

  1. either clone this repository using git or download a ZIP archive with its contents to your disk and unpack it there
  2. open a shell and navigate to the root directory of this repository
  3. run npm install in order to install the complete build environment
  4. execute npm run build to create a new build

You may also look into the author's build-configuration-study for a general description of his build environment.

License

MIT License