UNPKG

astro

Version:

Astro is a modern site builder with web best practices, performance, and DX front-of-mind.

36 lines (35 loc) 893 B
import { joinPaths, prependForwardSlash } from "../../../core/path.js"; import { createPlaceholderURL, stringifyPlaceholderURL } from "../../utils/url.js"; class DevUrlResolver { #urls = /* @__PURE__ */ new Set(); #resolved = false; #base; #searchParams; constructor({ base, searchParams }) { this.#base = base; this.#searchParams = searchParams; } resolve(id) { this.#resolved ||= true; const urlPath = prependForwardSlash(joinPaths(this.#base, id)); const url = createPlaceholderURL(urlPath); this.#searchParams.forEach((value, key) => { url.searchParams.set(key, value); }); const result = stringifyPlaceholderURL(url); this.#urls.add(result); return result; } get cspResources() { return this.#resolved ? ["'self'"] : []; } get urls() { return Array.from(this.#urls); } } export { DevUrlResolver };