From 027b87e55ac086fde07d8d0a5eb54025e565666b Mon Sep 17 00:00:00 2001 From: Marcos Candeia Date: Tue, 19 Mar 2024 12:23:52 -0300 Subject: [PATCH] Support/vfs (#232) * Update vfs deco version Signed-off-by: Marcos Candeia * Check vfs instance Signed-off-by: Marcos Candeia --------- Signed-off-by: Marcos Candeia --- .vscode/settings.json | 2 +- import_map.json | 2 +- plugins/tailwind/mod.ts | 31 +++++++++++++++++++++---------- 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 7a5a01c8..537ad5cb 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -24,4 +24,4 @@ "[css]": { "editor.defaultFormatter": "vscode.css-language-features" } -} \ No newline at end of file +} diff --git a/import_map.json b/import_map.json index b95c84c1..620324ba 100644 --- a/import_map.json +++ b/import_map.json @@ -1,7 +1,7 @@ { "imports": { "deco-sites/std/": "./", - "deco/": "https://denopkg.com/deco-cx/deco@1.51.5/", + "deco/": "https://denopkg.com/deco-cx/deco@1.57.18/", "partytown/": "https://deno.land/x/partytown@0.3.4/", "$fresh/": "https://deno.land/x/fresh@1.6.1/", "preact": "https://esm.sh/preact@10.15.1", diff --git a/plugins/tailwind/mod.ts b/plugins/tailwind/mod.ts index 4107bb24..8d57d7e6 100644 --- a/plugins/tailwind/mod.ts +++ b/plugins/tailwind/mod.ts @@ -2,6 +2,7 @@ import type { Plugin } from "$fresh/server.ts"; import { Context } from "deco/deco.ts"; import { join } from "std/path/mod.ts"; import { bundle, Config, loadTailwindConfig } from "./bundler.ts"; +import { VFS } from "deco/runtime/fs/mod.ts"; export type { Config } from "./bundler.ts"; @@ -99,17 +100,26 @@ export const plugin = (config?: Config): Plugin => { const mode = fresh.dev ? "dev" : "prod"; const ctx = Context.active(); - const withReleaseContent = async (config: Config) => { - const state = await ctx.release?.state({ forceFresh: true }); + const withReleaseContent = (config: Config) => { + const ctx = Context.active(); + const vfs = ctx.fs; + if (!vfs || !(vfs instanceof VFS)) { + return config; + } + + const allTsxFiles = []; + for (const [path, file] of Object.entries(vfs.fileSystem)) { + if (path.endsWith(".tsx") && file.content) { + allTsxFiles.push(file.content); + } + } return { ...config, - content: Array.isArray(config.content) - ? [...config.content, { - raw: JSON.stringify(state), - extension: "json", - }] - : config.content, + content: allTsxFiles.map((content) => ({ + raw: content, + extension: "tsx", + })), }; }; @@ -121,7 +131,7 @@ export const plugin = (config?: Config): Plugin => { from: FROM, mode, config: config - ? await withReleaseContent(config) + ? withReleaseContent(config) : await loadTailwindConfig(root), }).catch(() => "")); @@ -131,6 +141,7 @@ export const plugin = (config?: Config): Plugin => { routes.push({ path: "/styles.css", handler: safe(async () => { + const ctx = Context.active(); const revision = await ctx.release?.revision() || ""; let css = lru.get(revision); @@ -140,7 +151,7 @@ export const plugin = (config?: Config): Plugin => { css = await bundle({ from: FROM, mode, - config: await withReleaseContent(config), + config: withReleaseContent(config), }); lru.set(revision, css);