diff options
author | 2024-08-20 18:25:04 +0800 | |
---|---|---|
committer | 2024-08-20 18:25:04 +0800 | |
commit | 1fd84b6bbc42885d0a80ea65a87b4a7946320924 (patch) | |
tree | 6bf19520a56b9c7cecdf3a64f2f9e65d868bb8bd /scripts/utils/svelte-plugin.js | |
parent | 88b6dca63b56ef12b92543384365f8f7f1cad85d (diff) | |
download | astro-1fd84b6bbc42885d0a80ea65a87b4a7946320924.tar.gz astro-1fd84b6bbc42885d0a80ea65a87b4a7946320924.tar.zst astro-1fd84b6bbc42885d0a80ea65a87b4a7946320924.zip |
Remove unused code in internal scripts (#11769)
Diffstat (limited to 'scripts/utils/svelte-plugin.js')
-rw-r--r-- | scripts/utils/svelte-plugin.js | 70 |
1 files changed, 0 insertions, 70 deletions
diff --git a/scripts/utils/svelte-plugin.js b/scripts/utils/svelte-plugin.js deleted file mode 100644 index 6781c28a4..000000000 --- a/scripts/utils/svelte-plugin.js +++ /dev/null @@ -1,70 +0,0 @@ -// @ts-nocheck -import { promises as fs } from 'node:fs'; -import { dirname, isAbsolute, join, relative } from 'node:path'; -import { compile } from 'svelte/compiler'; - -const convertMessage = ({ message, start, end, filename, frame }) => ({ - text: message, - location: start && - end && { - file: filename, - line: start.line, - column: start.column, - length: start.line === end.line ? end.column - start.column : 0, - lineText: frame, - }, -}); - -const handleLoad = async (args, generate, { isDev }) => { - const { path } = args; - const source = await fs.readFile(path, 'utf8'); - const filename = relative(process.cwd(), path); - - try { - let compileOptions = { dev: isDev, css: false, generate, hydratable: true }; - - let { js, warnings } = compile(source, { ...compileOptions, filename }); - let contents = js.code + `\n//# sourceMappingURL=` + js.map.toUrl(); - - return { - loader: 'js', - contents, - resolveDir: dirname(path), - warnings: warnings.map((w) => convertMessage(w)), - }; - } catch (e) { - return { errors: [convertMessage(e)] }; - } -}; - -export default function sveltePlugin({ isDev = false }) { - return { - name: 'svelte-esbuild', - setup(build) { - build.onResolve({ filter: /\.svelte$/ }, (args) => { - let path = args.path.replace(/\.(?:client|server)/, ''); - path = isAbsolute(path) ? path : join(args.resolveDir, path); - - if (/\.client\.svelte$/.test(args.path)) { - return { - path, - namespace: 'svelte:client', - }; - } - - if (/\.server\.svelte$/.test(args.path)) { - return { - path, - namespace: 'svelte:server', - }; - } - }); - build.onLoad({ filter: /.*/, namespace: 'svelte:client' }, (args) => - handleLoad(args, 'dom', { isDev }) - ); - build.onLoad({ filter: /.*/, namespace: 'svelte:server' }, (args) => - handleLoad(args, 'ssr', { isDev }) - ); - }, - }; -} |