ember-fastboot / ember-fastboot/ember-cli-fastboot

In fastboot sandbox the `URL` global object is not WHATWG URL

Open
#816 10 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
850
Forks
161
Avg merge
17h 45m
Merged PRs (30d)
19

Description

Since Node.js 10 the `URL` is available as global variable, and it is [WHATWG URL API](https://nodejs.org/docs/latest-v14.x/api/url.html#url_the_whatwg_url_api) - "Browser-compatible URL class, implemented by following the WHATWG URL Standard".
But under fastboot I can not use `new URL(...)`, because sandbox globals assigns `URL` to `require('url')`.
https://github.com/ember-fastboot/ember-cli-fastboot/blob/9e0b053cced1189ffeaafa827a386a8f82a1b788/packages/fastboot/src/sandbox.js#L17-L26

It's very confusing because:
1. it differs from nodejs, where `globalThis.URL === require('url').URL`
2. I can't write code `new URL(...)` in app that will be valid for both environments - browser and fastboot.
Instead, I have to write like this `IS_FASTBOOT ? new URL.URL(...) : new URL(...)` or use `buildSandboxGlobals` to assign `URL` to `require('url').URL` instead of default `require('url')`.

In my opinion, the `URL` global variable in fastboot should be the same as for Node.js:
```js
- let URL = require('url');
+ let { URL } = require('url');
let globals = this.globals;

let sandbox = Object.assign(
{
sourceMapSupport,
console,
setTimeout,
clearTimeout,
URL,
```

Also, it make sense because support of Node < 10 has been dropped here (#695).

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.