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

Switch to ESM #333

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

erjonify
Copy link
Collaborator

@erjonify erjonify commented Nov 7, 2023

closes #185

@jimmywarting
Copy link
Owner

;((name, definition) => {
typeof module !== 'undefined'
? module.exports = definition()
: typeof define === 'function' && typeof define.amd === 'object'
? define(definition)
: this[name] = definition()
})('streamSaver', () => {
'use strict'

  • Needs to be removed (and the end of it as well)

  • The script tag must be changed to have the type="module"

We can remove all of this:

<script src="https://cdn.jsdelivr.net/npm/web-streams-polyfill@2.0.2/dist/ponyfill.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/streamsaver@2.0.3/StreamSaver.min.js"></script>
<script>
  import streamSaver from 'streamsaver'
  const streamSaver = require('streamsaver')
  const streamSaver = window.streamSaver
</script>

and replace it with:

<script type="importmap">
  {
    "imports": {
      "streamsaver/StreamSaver.js": "https://cdn.jsdelivr.net/npm/streamsaver@3/StreamSaver.min.js"
    }
  }
</script>
<script type="module">
  // either one works fine, the later one requires importmaps or a web bundler. 
  import streamSaver from 'https://cdn.jsdelivr.net/npm/streamsaver@3/StreamSaver.min.js'
  import streamSaver from 'streamsaver/StreamSaver.min.js'

  const uInt8 = new TextEncoder().encode('StreamSaver is awesome')
  ...
</script>
  • Every green browser now days have good support for web streams, so i think we can remove the hole shebang where we mention any use of custom stream polyfill
// StreamSaver can detect and use the Ponyfill that is loaded from the cdn.
streamSaver.WritableStream = streamSaver.WritableStream
streamSaver.TransformStream = streamSaver.TransformStream

Copy link
Owner

@jimmywarting jimmywarting left a comment

Choose a reason for hiding this comment

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

☝️

@jimmywarting

This comment was marked as off-topic.

@erjonify
Copy link
Collaborator Author

erjonify commented Nov 9, 2023

  • type="module"

@jimmywarting , i did some small changes, feel free to complete the rest :)

Repository owner deleted a comment from erjonify Nov 11, 2023
Repository owner deleted a comment from erjonify Nov 11, 2023
@jimmywarting jimmywarting changed the title 185-configured package.json to treat all .js files in the package as ES mo… Switch to ESM Nov 11, 2023
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.

Please add 'module" entrypoint in package.json manifest to be compatible with modern web ES modules
2 participants