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

Fastboot incompatible with modern state of the ecosystem #913

Open
runspired opened this issue Mar 17, 2023 · 3 comments
Open

Fastboot incompatible with modern state of the ecosystem #913

runspired opened this issue Mar 17, 2023 · 3 comments

Comments

@runspired
Copy link
Contributor

runspired commented Mar 17, 2023

Issues:

  • Expected globals are not present, such as fetch, Headers ReadableStream etc.
  • buildSandboxGlobal no longer runs, so there is no way to enhance the built in globals with WHATWG spec implementations of APIs such as AbortController and fetch even when these things exist as globals in node. (this turned out to be a config mishap for ember-cli-fastboot-testing see Config not working embermap/ember-cli-fastboot-testing#488)
  • fastbootDependencies does not allow whitelisting local dependencies, which prevents applications from addressing this shortcoming short of using pnpm patch to splice in new globals. For instance the following fails to resolve with Fastboot.require
{
  "dependencies":  {
     "fastboot-abort-controller": "file:./fastboot-overrides/abort-controller"
  },
  "fastbootDependencies": [
     "fastboot-abort-controller",
  ]
}

Example recommended config for use with EmberData and fetch

/* global ReadableStream, WritableStream, TransformStream */
module.exports = function (environment) {
  return {
    buildSandboxGlobals(defaultGlobals) {
      return Object.assign({}, defaultGlobals, {
        AbortController,
        fetch: fetch,
        ReadableStream:
          typeof ReadableStream !== 'undefined' ? ReadableStream : require('node:stream/web').ReadableStream,
        WritableStream:
          typeof WritableStream !== 'undefined' ? WritableStream : require('node:stream/web').WritableStream,
        TransformStream:
          typeof TransformStream !== 'undefined' ? TransformStream : require('node:stream/web').TransformStream,
        Headers: typeof Headers !== 'undefined' ? Headers : undefined,
      });
    },
  };
};
@ef4
Copy link
Contributor

ef4 commented Apr 3, 2023

AFAIK there's no reason to use Fastboot.require anymore, because ember-auto-import and embroider both allow you to import dependencies and keep those working in both browser and fastboot.

It was only needed in the era when apps didn't normally import NPM dependencies. It makes no sense as an API anymore.

Both embroider and ember-auto-import test under fastboot to make sure this works.

@runspired
Copy link
Contributor Author

runspired commented Apr 5, 2023

@ef4 are you saying that ember-auto-import allows you to require any node (not browser) module? This seems suspect, because for instance import fetch from "node:fetch" isn't valid unless you are in a Fastboot context, but if this works there's probably a bunch of docs updates to do 😅

@ef4
Copy link
Contributor

ef4 commented Apr 5, 2023

Oh yeah, no, I don't mean node built-ins or packages with native binaries will work both ways.

But even for those you can manage the swap between them with embroider/macros. That's actually what embroider does internally when we encounter classical fastboot directories that are intended to override a module only in fastboot.

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

No branches or pull requests

2 participants