MCPcopy
hub / github.com/webpack/webpack / fetch

Method fetch

test/harness/runner/index.js:793–834  ·  view source on GitHub ↗
(/** @type {string | URL} */ url)

Source from the content-addressed store, hash-verified

791 };
792 }
793 const fetch = async (/** @type {string | URL} */ url) => {
794 try {
795 // universal targets pass a `URL` (often `file:`) to fetch
796 const filePath =
797 url instanceof URL || String(url).startsWith("file:")
798 ? fileURLToPath(url)
799 : urlToPath(String(url), this.outputDirectory);
800 const buffer = await new Promise((resolve, reject) => {
801 fs.readFile(filePath, (err, b) => (err ? reject(err) : resolve(b)));
802 });
803 // `instantiateStreaming` needs a real Response with a wasm mime type
804 if (typeof Response !== "undefined") {
805 const contentType = filePath.endsWith(".wasm")
806 ? "application/wasm"
807 : filePath.endsWith(".json")
808 ? "application/json"
809 : "text/plain";
810 return new Response(buffer, {
811 status: 200,
812 headers: { "Content-Type": contentType }
813 });
814 }
815 return {
816 status: 200,
817 ok: true,
818 headers: { get: () => "application/wasm" },
819 arrayBuffer: async () => buffer,
820 text: async () => buffer.toString("utf8"),
821 json: async () => JSON.parse(buffer.toString("utf8"))
822 };
823 } catch (/** @type {EXPECTED_ANY} */ err) {
824 if (err.code === "ENOENT") {
825 return typeof Response !== "undefined"
826 ? new Response(null, { status: 404 })
827 : {
828 status: 404,
829 ok: false
830 };
831 }
832 throw err;
833 }
834 };
835 const env = {
836 setTimeout,
837 document,

Callers

nothing calls this directly

Calls 5

urlToPathFunction · 0.85
resolveFunction · 0.85
readFileMethod · 0.80
toStringMethod · 0.45
parseMethod · 0.45

Tested by

no test coverage detected