@n6k.io/serve 0.2.4 → 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 +3 -2
- package/src/assets.ts +3 -3
- package/src/bundle.ts +5 -4
- package/src/paths.ts +14 -4
- package/tsconfig.json +29 -0
package/package.json
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@n6k.io/serve",
|
|
3
|
-
"version": "0.2.
|
|
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"
|
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
|
|
44
|
-
|
|
45
|
-
|
|
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
|
|
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:
|
|
64
|
-
"react-dom":
|
|
64
|
+
react: servePackageDir("react"),
|
|
65
|
+
"react-dom": servePackageDir("react-dom"),
|
|
65
66
|
},
|
|
66
67
|
});
|
|
67
68
|
|
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
|
|
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))
|
|
13
|
+
if (existsSync(candidate)) dirs.push(candidate);
|
|
14
14
|
const parent = path.dirname(dir);
|
|
15
|
-
if (parent === dir) return
|
|
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
|
+
}
|