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

breaking: remove polyfills & top level await #41

Merged
merged 4 commits into from
Nov 24, 2022
Merged

Conversation

jimmywarting
Copy link
Owner

@jimmywarting jimmywarting commented Nov 22, 2022

some ppl have had issues with top level await and my way of loading stream polyfills from a CDN

This will totally remove all top level await and dependency on fetch-blob and web stream polyfills and making it zero dependent on any other library. considering now that all green env now has WritableStream, ReadableStream, TransformStream, Blob, File, and DOMException globally now.

right now if you want to use it in NodeJS and want to get a File class from handle.getFile() then you would have to install the optional dependency of fetch-blob in order to use the fileFrom(path) also

However if you depend on some older environment then there is an option to do so using the config

import config from 'native-file-system-adapter/config.js'
const config = {
  ReadableStream: globalThis.ReadableStream,
  WritableStream: globalThis.WritableStream,
  TransformStream: globalThis.TransformStream,
  DOMException: globalThis.DOMException,
  Blob: globalThis.Blob,
  File: globalThis.File,
}

closes #36
closes #20

@jimmywarting jimmywarting changed the title breaking: remove polyfills breaking: remove polyfills & top level await Nov 22, 2022
@jimmywarting
Copy link
Owner Author

ping @maxkatz6, @mathieu-fournier, @klauszhang, @koomootoz, @lucasljsb, @jarrvis, @crazoter, @nlynzaad @fryck @spencer-jacobs hoping for somebody to review this as well

@maxkatz6
Copy link

@jimmywarting I am not a specialist in a typical JS libraries API design. But it looks good to me.
Thanks!

However if you depend on some older environment then there is an option to do so using the config

Do you mean, to mutate the imported config if any of these types are not available?

@milahu
Copy link

milahu commented Nov 24, 2022

thanks!

this fixes the vite error

Top-level await is not available in the configured target environment

update commands for pnpm + vite

pnpm rm native-file-system-adapter
pnpm install github:jimmywarting/native-file-system-adapter#pull/41/merge
rm -rf node_modules/.vite/

now i can just

import h from 'hyperscript';
import {showDirectoryPicker} from "native-file-system-adapter"

const button = h("button", "open directory to write files");
button.onclick = async () => {
  const dataDir = await showDirectoryPicker({
    mode: 'readwrite',
    recursive: true,
  });
  const dir = await dataDir.getDirectoryHandle("some-dir", { create: true });
  const file = await dir.getFileHandle("some-file.txt", { create: true });
  // limitation: we cannot get the absolute path of dataDir
  const path = dataDir.name + "/" + (await dataDir.resolve(file))?.join("/");
  const writer = await file.createWritable({ keepExistingData: false });
  await writer.write('hello');
  await writer.close();
  console.log(`done ${path}`);
  console.dir({ dataDir, dir, file });
}
document.body.appendChild(button);

@jimmywarting jimmywarting merged commit 5d3d0d4 into master Nov 24, 2022
@jimmywarting jimmywarting deleted the feature/breaking branch November 24, 2022 13:02
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.

web-streams-polyfill dependency upgrade
3 participants