-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
9 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; | ||
|