@n6k.io/serve 0.2.3 → 0.2.5

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,13 +1,14 @@
1
1
  {
2
2
  "name": "@n6k.io/serve",
3
- "version": "0.2.3",
3
+ "version": "0.2.5",
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",
7
7
  "license": "MIT",
8
8
  "type": "module",
9
9
  "files": [
10
- "src"
10
+ "src",
11
+ "tsconfig.json"
11
12
  ],
12
13
  "bin": {
13
14
  "n6k-serve": "src/cli.ts"
@@ -29,7 +30,8 @@
29
30
  "@n6k.io/db": "^0.13.1",
30
31
  "@n6k.io/runtime": "^0.1.2",
31
32
  "@n6k.io/ui": "^0.10.6",
32
- "@tailwindcss/cli": "^4.3.3",
33
+ "@tailwindcss/node": "^4.3.5",
34
+ "@tailwindcss/oxide": "^4.3.5",
33
35
  "@tailwindcss/typography": "^0.5.20",
34
36
  "@tanstack/react-query": "^5.104.1",
35
37
  "esbuild": "^0.28.2",
package/src/assets.ts CHANGED
@@ -40,9 +40,9 @@ export async function serveAsset(
40
40
  });
41
41
  }
42
42
  if (pathname.startsWith("/files/")) {
43
- const font = findFontFile(
44
- SERVE_NODE_MODULES,
45
- pathname.slice("/files/".length),
43
+ const name = pathname.slice("/files/".length);
44
+ const font = SERVE_NODE_MODULES.map((dir) => findFontFile(dir, name)).find(
45
+ Boolean,
46
46
  );
47
47
  if (font) {
48
48
  return new Response(Bun.file(font), {
package/src/bundle.ts CHANGED
@@ -11,6 +11,7 @@ import {
11
11
  SERVE_ROOT,
12
12
  SRC_DIR,
13
13
  nearestNodeModules,
14
+ servePackageDir,
14
15
  } from "./paths";
15
16
 
16
17
  export type Bundle = Map<string, string>;
@@ -47,8 +48,8 @@ export async function bundlePage(
47
48
  absWorkingDir: SERVE_ROOT,
48
49
  tsconfig: path.join(SERVE_ROOT, "tsconfig.json"),
49
50
  nodePaths: [
50
- SERVE_NODE_MODULES,
51
- ...(pageNodeModules && pageNodeModules !== SERVE_NODE_MODULES
51
+ ...SERVE_NODE_MODULES,
52
+ ...(pageNodeModules && !SERVE_NODE_MODULES.includes(pageNodeModules)
52
53
  ? [pageNodeModules]
53
54
  : []),
54
55
  ],
@@ -60,8 +61,8 @@ export async function bundlePage(
60
61
  n6kDuckDBPlugin(undefined, { used: false }),
61
62
  ],
62
63
  alias: {
63
- react: path.join(SERVE_NODE_MODULES, "react"),
64
- "react-dom": path.join(SERVE_NODE_MODULES, "react-dom"),
64
+ react: servePackageDir("react"),
65
+ "react-dom": servePackageDir("react-dom"),
65
66
  },
66
67
  });
67
68
 
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(SRC_DIR)};\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/paths.ts CHANGED
@@ -4,15 +4,25 @@ import { fileURLToPath } from "node:url";
4
4
 
5
5
  export const SRC_DIR = path.dirname(fileURLToPath(import.meta.url));
6
6
  export const SERVE_ROOT = path.dirname(SRC_DIR);
7
- export const SERVE_NODE_MODULES = path.join(SERVE_ROOT, "node_modules");
8
7
 
9
- export function nearestNodeModules(fromDir: string): string | undefined {
8
+ export function nodeModulesChain(fromDir: string): string[] {
9
+ const dirs: string[] = [];
10
10
  let dir = fromDir;
11
11
  for (;;) {
12
12
  const candidate = path.join(dir, "node_modules");
13
- if (existsSync(candidate)) return candidate;
13
+ if (existsSync(candidate)) dirs.push(candidate);
14
14
  const parent = path.dirname(dir);
15
- if (parent === dir) return undefined;
15
+ if (parent === dir) return dirs;
16
16
  dir = parent;
17
17
  }
18
18
  }
19
+
20
+ export function nearestNodeModules(fromDir: string): string | undefined {
21
+ return nodeModulesChain(fromDir)[0];
22
+ }
23
+
24
+ export const SERVE_NODE_MODULES = nodeModulesChain(SERVE_ROOT);
25
+
26
+ export function servePackageDir(name: string): string {
27
+ return path.dirname(Bun.resolveSync(`${name}/package.json`, SRC_DIR));
28
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "compilerOptions": {
3
+ // Environment setup & latest features
4
+ "lib": ["ESNext", "DOM", "DOM.Iterable"],
5
+ "target": "ESNext",
6
+ "module": "Preserve",
7
+ "moduleDetection": "force",
8
+ "jsx": "react-jsx",
9
+ "allowJs": true,
10
+ "types": ["bun-types"],
11
+
12
+ // Bundler mode
13
+ "moduleResolution": "bundler",
14
+ "allowImportingTsExtensions": true,
15
+ "verbatimModuleSyntax": true,
16
+ "noEmit": true,
17
+
18
+ // Best practices
19
+ "strict": true,
20
+ "skipLibCheck": true,
21
+ "noFallthroughCasesInSwitch": true,
22
+ "noImplicitOverride": true,
23
+
24
+ // Some stricter flags (disabled by default)
25
+ "noUnusedLocals": false,
26
+ "noUnusedParameters": false,
27
+ "noPropertyAccessFromIndexSignature": false
28
+ }
29
+ }