Skip to content

Commit

Permalink
chore
Browse files Browse the repository at this point in the history
  • Loading branch information
joshamaju committed Nov 11, 2024
1 parent f0a541e commit 003d71a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 18 deletions.
6 changes: 3 additions & 3 deletions integrations/island/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as path from "node:path";
import type { Plugin } from "vite";
import { Integration, ResolvedConfig } from "stack54/config";
import { makeIsland } from "./process.js";
import { make } from "./island.js";

type Island = { code: string; original: string; complete: boolean };

Expand Down Expand Up @@ -75,7 +75,7 @@ export default function islandIntegration(): Integration {
return;
}

const island = await makeIsland(code, filename, config);
const island = await make(code, filename);

if (island) {
islands.set(id, {
Expand Down Expand Up @@ -109,7 +109,7 @@ export default function islandIntegration(): Integration {
order: "pre",
async handle(code, id) {
const [filename] = id.split("?");
const island = await makeIsland(code, filename, config);
const island = await make(code, filename);
return island;
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import type { PreprocessorGroup } from "svelte/compiler";
import { parse, preprocess, walk } from "svelte/compiler";
import { BaseNode, Element } from "svelte/types/compiler/interfaces";

import { ResolvedConfig } from "stack54/config";
import { to_fs } from "stack54/internals";

type Attributes = Record<string, string | boolean>;
Expand Down Expand Up @@ -38,14 +37,10 @@ const CONFIG = "value";

const SFC_script_style = /<script[\s\S]*?<\/script>|<style[\s\S]*?<\/style>/g;

export async function makeIsland(
code: string,
filename: string,
config: ResolvedConfig
) {
export async function make(code: string, filename: string) {
let script: { content: string; attributes: Attributes } | undefined;

const get_island: PreprocessorGroup = {
const processor: PreprocessorGroup = {
name: "is-island",
script({ attributes, content }) {
if (KEY in attributes) {
Expand All @@ -54,14 +49,7 @@ export async function makeIsland(
},
};

const preprocess_ = config.svelte.preprocess ?? [];

const processors = [
...(Array.isArray(preprocess_) ? preprocess_ : [preprocess_]),
get_island,
];

const processed = await preprocess(code, processors, { filename });
const processed = await preprocess(code, [processor], { filename });

if (!script) return;

Expand Down

0 comments on commit 003d71a

Please sign in to comment.