Skip to content

Commit

Permalink
fix: Fix first time download (#10)
Browse files Browse the repository at this point in the history
* Fix first time download

Hi,

With Rollup.js i wasn't able to « import "https://…" » i notice « Url is undefined » (line https://github.com/egoist/import-http/blob/master/lib/rollup.js#L57) when the targeted library isn't in the cache.

Since the URL is also the key its solve the problem.

OS: MacOS
NodeJS Version : 11.13.0
Bundler : RollupJS
Original log : 

```sh
$ rollup -c

src/main.js → dist/bundle.js...
Downloading undefined...
[!] Error: Could not load https://cdn.jsdelivr.net/npm/vue/dist/vue.esm.browser.js (imported by /Users/valentinbrosseau/dev/vue-yasb/src/main.js): Only absolute URLs are supported
Error: Could not load https://cdn.jsdelivr.net/npm/vue/dist/vue.esm.browser.js (imported by /Users/valentinbrosseau/dev/vue-yasb/src/main.js): Only absolute URLs are supported
    at /usr/local/lib/node_modules/rollup/dist/rollup.js:17855:19
    at process.runNextTicks [as _tickCallback] (internal/process/task_queues.js:52:5)
    at Function.Module.runMain (internal/modules/cjs/loader.js:871:11)
    at internal/main/run_main_module.js:21:11
```

* Update http-cache.js

* Use ID instead of url

Since URL is undefined the first time (file not present in cache).
  • Loading branch information
c4software authored and egoist committed Apr 7, 2019
1 parent 42ce89f commit 8de9ae9
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rollup.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ module.exports = ({ reload, cacheDir = CACHE_DIR } = {}) => {
}

// We have never requested this before
const res = await fetch(url)
const res = await fetch(id)
file = getFilePathFromURL(res.url)
await httpCache.set(id, res.url)
const content = await res.buffer().then(buff => buff.toString('utf8'))
Expand Down

0 comments on commit 8de9ae9

Please sign in to comment.