Skip to content

Commit

Permalink
Support/vfs (#232)
Browse files Browse the repository at this point in the history
* Update vfs deco version

Signed-off-by: Marcos Candeia <[email protected]>

* Check vfs instance

Signed-off-by: Marcos Candeia <[email protected]>

---------

Signed-off-by: Marcos Candeia <[email protected]>
  • Loading branch information
mcandeia authored Mar 19, 2024
1 parent 7701397 commit 027b87e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@
"[css]": {
"editor.defaultFormatter": "vscode.css-language-features"
}
}
}
2 changes: 1 addition & 1 deletion import_map.json
Original file line number Diff line number Diff line change
@@ -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/[email protected]/",
"$fresh/": "https://deno.land/x/[email protected]/",
"preact": "https://esm.sh/[email protected]",
Expand Down
31 changes: 21 additions & 10 deletions plugins/tailwind/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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",
})),
};
};

Expand All @@ -121,7 +131,7 @@ export const plugin = (config?: Config): Plugin => {
from: FROM,
mode,
config: config
? await withReleaseContent(config)
? withReleaseContent(config)
: await loadTailwindConfig(root),
}).catch(() => ""));

Expand All @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit 027b87e

Please sign in to comment.