aboutsummaryrefslogtreecommitdiff
path: root/scripts/utils/svelte-plugin.js
diff options
context:
space:
mode:
authorGravatar Jonathan Neal <jonathantneal@hotmail.com> 2021-12-22 16:11:05 -0500
committerGravatar GitHub <noreply@github.com> 2021-12-22 16:11:05 -0500
commit6ddd7678ffb6598ae6e263706813cb5e94535f02 (patch)
treed4b45f7590b59c3574bd6593b17d8066f71007c6 /scripts/utils/svelte-plugin.js
parent305ce4182fbe89abcfb88008ddce178bd8863b6a (diff)
downloadastro-6ddd7678ffb6598ae6e263706813cb5e94535f02.tar.gz
astro-6ddd7678ffb6598ae6e263706813cb5e94535f02.tar.zst
astro-6ddd7678ffb6598ae6e263706813cb5e94535f02.zip
Use accessible indentation (#2253)
Diffstat (limited to 'scripts/utils/svelte-plugin.js')
-rw-r--r--scripts/utils/svelte-plugin.js90
1 files changed, 45 insertions, 45 deletions
diff --git a/scripts/utils/svelte-plugin.js b/scripts/utils/svelte-plugin.js
index f8a30ff33..29e60c2d5 100644
--- a/scripts/utils/svelte-plugin.js
+++ b/scripts/utils/svelte-plugin.js
@@ -4,58 +4,58 @@ import { relative, isAbsolute, join, dirname } from 'path';
import { promises as fs } from 'fs';
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,
- },
+ 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);
+ 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 };
+ 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();
+ 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)] };
- }
+ 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 }));
- },
- };
+ 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 }));
+ },
+ };
}