Skip to content

Commit

Permalink
fix: completely virtual file system
Browse files Browse the repository at this point in the history
  • Loading branch information
mxdvl committed Apr 18, 2023
1 parent ba93baf commit 6473587
Showing 1 changed file with 9 additions and 25 deletions.
34 changes: 9 additions & 25 deletions src/esbuild_plugins/resolve_svelte_internal.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,24 @@
import {
basename,
dirname,
fromFileUrl,
} from "https://deno.land/[email protected]/path/mod.ts";
import type { Plugin } from "https://deno.land/x/[email protected]/mod.js";

const file = fromFileUrl(import.meta.url);
const file_name = basename(file);
const dir_name = dirname(file);

const svelte_internal = await fetch(
"https://esm.sh/v108/[email protected]/es2020/internal.js",
);
const svelte_internal_src = await svelte_internal.text();

const filter = /^svelte\/internal$/;

export const resolve_svelte_internal: Plugin = {
name: "svelte/internal",
setup(build) {
build.onResolve({ filter: /^svelte\/internal$/ }, async () => {
// this doesn't actually do anything, we just need to resolve a real
// module. the actual replacement happens in the onLoad hook below
const result = await build.resolve(
// this file name is used in the `onLoad` filter below
file_name,
{
resolveDir: dir_name,
kind: "import-rule",
},
);
if (result.errors.length > 0) {
return { errors: result.errors };
}
return { path: result.path, external: false };
build.onResolve({ filter }, () => {
return {
path: "svelte/internal",
namespace: "fs-virtual",
external: false,
};
});

build.onLoad({ filter: new RegExp(file_name) }, () => {
build.onLoad({ filter }, () => {
return {
contents: svelte_internal_src,
};
Expand Down

0 comments on commit 6473587

Please sign in to comment.