Skip to content

importScripts() should resolve against webworker file not cwd #192

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

Open
russaa opened this issue Dec 3, 2018 · 1 comment
Open

importScripts() should resolve against webworker file not cwd #192

russaa opened this issue Dec 3, 2018 · 1 comment

Comments

@russaa
Copy link
Contributor

russaa commented Dec 3, 2018

currently importScripts() resolves against the current working directory (cwd):
this makes it difficult to make it usable as an npm package, since the imported script path would need to be adjusted according to where the npm package is installed/run from.

The Web Worker implementations in browsers (e.g. Firefox, Chrome) do resolve against the Web Worker script file instead, e.g. for

index.html
index.js
workers/worker1.js
workers/helperScript.js

if worker1.js is loaded in index.html (or index.js), then worker1.js would load helperScript.js with
importScripts("helperScript.js")
and not
importScripts("workers/helperScript.js")

And if I understand the Web Worker specification correctly, importScripts() really should resolve against the (worker) script file where the importScripts() statement occurs:

5.1 Importing scripts and libraries:

  1. Resolve each argument relative to settings object's API base URL.

and then in 4.6.2 Script settings for workers:

The API base URL
Return script address.

@russaa russaa changed the title importScripts() should resolve again webworker file not cwd importScripts() should resolve against webworker file not cwd Dec 3, 2018
@audreyt
Copy link
Owner

audreyt commented Dec 4, 2018 via email

audreyt added a commit that referenced this issue Jan 28, 2019
#192 importScripts: resolve relative path against WebWorker location
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