@n6k.io/serve 0.2.2 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@n6k.io/serve",
3
- "version": "0.2.2",
3
+ "version": "0.2.4",
4
4
  "private": false,
5
5
  "description": "Serve .mdx pages with live data from n6kd or pykit",
6
6
  "repository": "https://github.com/n6k-io/js-serve",
@@ -29,7 +29,8 @@
29
29
  "@n6k.io/db": "^0.13.1",
30
30
  "@n6k.io/runtime": "^0.1.2",
31
31
  "@n6k.io/ui": "^0.10.6",
32
- "@tailwindcss/cli": "^4.3.3",
32
+ "@tailwindcss/node": "^4.3.5",
33
+ "@tailwindcss/oxide": "^4.3.5",
33
34
  "@tailwindcss/typography": "^0.5.20",
34
35
  "@tanstack/react-query": "^5.104.1",
35
36
  "esbuild": "^0.28.2",
package/src/bundle.ts CHANGED
@@ -18,6 +18,7 @@ export type Bundle = Map<string, string>;
18
18
  export type RootProps = {
19
19
  data: Record<string, string>;
20
20
  tokens: Record<string, string>;
21
+ bare?: boolean;
21
22
  };
22
23
 
23
24
  export async function bundlePage(
package/src/cli.ts CHANGED
@@ -67,6 +67,7 @@ if (positionals[0] === "sql") {
67
67
  fail(USAGE);
68
68
  await servePage(
69
69
  path.join(SRC_DIR, "sql", values.console ? "console.mdx" : "editor.mdx"),
70
+ true,
70
71
  );
71
72
  } else if (values.mcp) {
72
73
  if (
@@ -84,7 +85,7 @@ if (positionals[0] === "sql") {
84
85
  servePages(values.pages);
85
86
  }
86
87
 
87
- async function servePage(arg: string): Promise<void> {
88
+ async function servePage(arg: string, bare = false): Promise<void> {
88
89
  const mdxPath = path.resolve(arg);
89
90
  if (!mdxPath.endsWith(".mdx")) fail(`${arg}: not an .mdx file`);
90
91
  if (!existsSync(mdxPath)) fail(`${arg}: no such file`);
@@ -101,6 +102,7 @@ async function servePage(arg: string): Promise<void> {
101
102
  bundlePage(mdxPath, {
102
103
  data: Object.fromEntries(entries.map(([a, s]) => [a, s.url])),
103
104
  tokens: Object.fromEntries(entries.map(([a, s]) => [a, s.token])),
105
+ bare,
104
106
  }),
105
107
  buildCss(mdxPath),
106
108
  ]);
package/src/css.ts CHANGED
@@ -1,29 +1,19 @@
1
1
  import path from "node:path";
2
- import { mkdirSync, readFileSync } from "node:fs";
3
- import { SERVE_NODE_MODULES, SRC_DIR } from "./paths";
4
-
5
- // Under node_modules so the stylesheet's bare `@import`s resolve from serve's own deps.
6
- const CACHE_DIR = path.join(SERVE_NODE_MODULES, ".cache", "n6k-serve");
7
- const TAILWIND = path.join(SERVE_NODE_MODULES, ".bin", "tailwindcss");
2
+ import { readFileSync } from "node:fs";
3
+ import { compile } from "@tailwindcss/node";
4
+ import { Scanner } from "@tailwindcss/oxide";
5
+ import { SRC_DIR } from "./paths";
8
6
 
9
7
  export async function buildCss(mdxPath: string): Promise<string> {
10
- mkdirSync(CACHE_DIR, { recursive: true });
11
- const stem = `${process.pid}.${Bun.hash(mdxPath).toString(36)}`;
12
- const input = path.join(CACHE_DIR, `${stem}.in.css`);
13
- const output = path.join(CACHE_DIR, `${stem}.out.css`);
14
8
  const base = readFileSync(path.join(SRC_DIR, "globals.css"), "utf8");
15
- await Bun.write(
16
- input,
17
- `${base}\n@source ${JSON.stringify(path.dirname(mdxPath))};\n`,
18
- );
19
- const proc = Bun.spawn([TAILWIND, "-i", input, "-o", output], {
20
- stdout: "ignore",
21
- stderr: "pipe",
22
- });
23
- if ((await proc.exited) !== 0) {
24
- throw new Error(
25
- `tailwindcss failed:\n${await new Response(proc.stderr).text()}`,
26
- );
27
- }
28
- return readFileSync(output, "utf8");
9
+ const css = `${base}\n@source ${JSON.stringify(SRC_DIR)};\n@source ${JSON.stringify(path.dirname(mdxPath))};\n`;
10
+ const compiler = await compile(css, { base: SRC_DIR, onDependency() {} });
11
+ const root =
12
+ compiler.root === "none"
13
+ ? []
14
+ : compiler.root === null
15
+ ? [{ base: process.cwd(), pattern: "**/*", negated: false }]
16
+ : [{ ...compiler.root, negated: false }];
17
+ const sources = [...root, ...compiler.sources];
18
+ return compiler.build(new Scanner({ sources }).scan());
29
19
  }
package/src/root.tsx CHANGED
@@ -4,6 +4,7 @@ import { duckdbBundle } from "virtual:n6k-duckdb-bundle";
4
4
  import { N6kDuckDB, type DatabaseSpec, type SocketSpec } from "@n6k.io/db";
5
5
  import { DuckDBProvider, QueryProvider } from "@n6k.io/ui/duckdb";
6
6
  import { ConnectionLost, DuckDBConnectionGuard } from "@n6k.io/runtime";
7
+ import { Page } from "@n6k.io/ui/components";
7
8
 
8
9
  function engine(
9
10
  data: Record<string, string>,
@@ -31,16 +32,20 @@ export default function Root({
31
32
  children,
32
33
  data = {},
33
34
  tokens = {},
35
+ bare = false,
34
36
  }: {
35
37
  children: ReactNode;
36
38
  data?: Record<string, string>;
37
39
  tokens?: Record<string, string>;
40
+ bare?: boolean;
38
41
  }) {
39
42
  const [duckdb] = useState(() => engine(data, tokens));
40
43
  return (
41
44
  <QueryProvider>
42
45
  <DuckDBProvider connect={duckdb.connect} metadataFns={duckdb.metadataFns}>
43
- <DuckDBConnectionGuard>{children}</DuckDBConnectionGuard>
46
+ <DuckDBConnectionGuard>
47
+ {bare ? children : <Page>{children}</Page>}
48
+ </DuckDBConnectionGuard>
44
49
  <ConnectionLost duckdb={duckdb} />
45
50
  </DuckDBProvider>
46
51
  </QueryProvider>