@cara/porter
Advanced tools
Comparing version 4.0.0-beta.15 to 4.0.0-beta.16
@@ -44,3 +44,3 @@ /* eslint-env browser */ | ||
var basePath = system.baseUrl.replace(/([^\/])$/, '$1/'); | ||
var baseUrl = new URL(basePath, global.location.origin).toString(); | ||
var baseUrl = new URL(basePath, location.origin).toString(); | ||
var pkg = system.package; | ||
@@ -75,3 +75,3 @@ var alias = system.alias; | ||
try { | ||
importScripts(new URL(url, location.origin).toString()); | ||
importScripts(url); | ||
} catch (err) { | ||
@@ -131,3 +131,3 @@ return callback(err); | ||
function requestWasm(uri, callback) { | ||
var id = uri.replace(basePath, '').replace(/\.[0-9a-f]{8}(\.\w+)$/, '$1'); | ||
var id = uri.replace(baseUrl, '').replace(/\.[0-9a-f]{8}(\.\w+)$/, '$1'); | ||
var mod = registry[id]; | ||
@@ -246,11 +246,11 @@ var contextId = id.replace(rWasm, '.js'); | ||
*/ | ||
var rUri = /^(?:https?:)?\//; | ||
var rUri = /^(?:https?:)?\/\//; | ||
function parseUri(id) { | ||
var id = parseMap(id); | ||
// https://example.com/foo.js | ||
if (rUri.test(id)) return id; | ||
var mod = registry[id]; | ||
var isRootEntry = !mod.parent || (mod.parent.id in system.entries); | ||
var isRootEntry = !mod || !mod.parent || (mod.parent.id in system.entries); | ||
var obj = parseId(id); | ||
@@ -262,3 +262,3 @@ var name = obj.name; | ||
var meta = lock[pkg.name][pkg.version]; | ||
return basePath + (meta.manifest && meta.manifest[id] || id); | ||
return baseUrl + (meta.manifest && meta.manifest[id] || id); | ||
} | ||
@@ -272,7 +272,7 @@ | ||
if (meta.manifest && meta.manifest[file]) { | ||
return basePath + resolve(name, version, meta.manifest[file]); | ||
return baseUrl + resolve(name, version, meta.manifest[file]); | ||
} | ||
} | ||
var url = basePath + id; | ||
var url = baseUrl + id; | ||
if (isRootEntry) url += '?entry'; | ||
@@ -562,3 +562,3 @@ return url; | ||
return function(id) { | ||
var url = new URL(parseUri(resolve(context, suffix(id))), location.origin); | ||
var url = new URL(parseUri(resolve(context, suffix(id)))); | ||
return function createWorker() { | ||
@@ -569,3 +569,3 @@ url.searchParams.set('main', ''); | ||
}); | ||
return new Worker(URL.createObjectURL(blob)); | ||
return new Worker(URL.createObjectURL(blob), { credentials: 'same-origin' }); | ||
}; | ||
@@ -572,0 +572,0 @@ }; |
{ | ||
"name": "@cara/porter", | ||
"description": "A middleware for web modules", | ||
"version": "4.0.0-beta.15", | ||
"version": "4.0.0-beta.16", | ||
"main": "src/porter.js", | ||
@@ -43,3 +43,3 @@ "repository": { | ||
"license": "BSD-3-Clause", | ||
"gitHead": "6ab0f14aced5f65185b01010bb8d87421e6f9e32" | ||
"gitHead": "02e03ab5a40e5aed95a62a282aa1316b88db09ac" | ||
} |
@@ -127,3 +127,3 @@ 'use strict'; | ||
// might be WasmModule | ||
if (mod.isolated) continue; | ||
if (mod.isolated || (format === '.js' && mod.isRootEntry)) continue; | ||
yield* iterateEntry(mod, preload); | ||
@@ -311,6 +311,7 @@ } | ||
for (const mod of this) { | ||
const result = await mod.obtain(); | ||
const result = minify ? await mod.minify() : await mod.obtain(); | ||
this.#code = result.code; | ||
this.#cacheKey = cacheKey; | ||
this.updatedAt = new Date(); | ||
const { entryPath, outputPath } = this; | ||
debug('bundle complete %s -> %s', entryPath, outputPath, entries); | ||
return result; | ||
@@ -317,0 +318,0 @@ } |
@@ -226,5 +226,5 @@ 'use strict'; | ||
// lazyloaded packets still need to be compiled because preload might not take place | ||
for (const name in packet.dependencies) { | ||
if (packet.dependencies[name].lazyloaded) exclusives.add(name); | ||
// dependencies that have bundles as well (worker, wasm, etc.) | ||
for (const dep of packet.all) { | ||
if (dep !== packet && Object.keys(dep.bundles).length > 0) exclusives.add(dep.name); | ||
} | ||
@@ -242,4 +242,9 @@ | ||
debug('parse additional entries'); | ||
if (entries.filter(file => !this.packet.entries[file])) { | ||
entries = entries.filter(file => !this.packet.entries[file]); | ||
if (entries.length > 0) { | ||
await Promise.all(entries.map(entry => this.packet.parseEntry(entry))); | ||
// new entries might introduce new dependencies that need packing | ||
for (const dep of this.packet.all) { | ||
if (dep !== this.packet) await dep.pack({ minify: true }); | ||
} | ||
} | ||
@@ -246,0 +251,0 @@ entries = Object.keys(this.packet.entries); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
117876
3092