Skip to content

Commit 1b54151

Browse files
committed
using import scopes for main project and deps.ts for internal
1 parent 3a89b32 commit 1b54151

20 files changed

+226
-148
lines changed

deno.json

+17-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@
99
"build": "deno run -A internal/commands/build.js",
1010
"prod": "deno task build && deno run -A ./out/server.js",
1111
"test": "deno test --allow-read --allow-sys",
12-
"format": "deno fmt ."
12+
"format": "deno fmt .",
13+
"esm:add": "deno run -A https://esm.sh/v135 add",
14+
"esm:update": "deno run -A https://esm.sh/v135 update",
15+
"esm:remove": "deno run -A https://esm.sh/v135 remove"
1316
},
1417
"compilerOptions": {
1518
"lib": [
@@ -34,11 +37,21 @@
3437
]
3538
},
3639
"imports": {
37-
"nano_jsx/jsx-runtime": "https://deno.land/x/nano_jsx@v0.1.0/jsx-runtime/index.ts",
3840
"#client": "./internal/exports/client.ts",
41+
"#components": "./components/index.tsx",
3942
"#lib": "./lib/index.ts",
4043
"#module": "./internal/exports/module.ts",
41-
"#components": "./components/index.tsx",
44+
"@std/fs": "jsr:@std/fs@^0.229.3",
45+
"@std/path": "jsr:@std/path@^1.0.1",
46+
"nano_jsx/jsx-runtime": "https://deno.land/x/nano_jsx@v0.1.0/jsx-runtime/index.ts",
47+
"to-vfile": "https://esm.sh/v135/*to-vfile@8.0.0",
48+
"vfile-matter": "https://esm.sh/v135/*vfile-matter@5.0.0",
4249
"~/": "./"
50+
},
51+
"scopes": {
52+
"https://esm.sh/v135/": {
53+
"vfile": "https://esm.sh/v135/vfile@6.0.2",
54+
"yaml": "https://esm.sh/v135/yaml@2.4.5"
55+
}
4356
}
44-
}
57+
}

internal/commands/build.js

+41-27
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,38 @@
22
// 1. Bundle as single file
33
// 2. Perform dynamic import for page files (code splitting)
44

5-
import { join } from "jsr:@std/path/join";
5+
import {
6+
basename,
7+
bold,
8+
commonjsPlugin,
9+
delay,
10+
denoPlugins,
11+
dim,
12+
esbuild,
13+
exists,
14+
extname,
15+
join,
16+
loadConfig,
17+
parseArgs,
18+
relative,
19+
walk,
20+
} from "../deps.ts";
621
import { Logger } from "../lib/logger.ts";
722
import { Runner } from "../lib/runner.ts";
8-
import { bold, dim } from "jsr:@std/fmt/colors";
9-
import { relative } from "jsr:@std/path/relative";
10-
import { exists } from "jsr:@std/fs/exists";
11-
import { walk } from "jsr:@std/fs/walk";
12-
import { basename, extname } from "jsr:@std/path";
13-
import { loadConfig } from "npm:c12";
1423
import { defaultConfig } from "../lib/config.ts";
1524
import renderEjs from "../scripts/render_ejs.js";
1625
import { buildRouter } from "../lib/router.ts";
1726
import deno from "../../deno.json" with { type: "json" };
18-
import { delay } from "jsr:@std/async/delay";
19-
20-
// @deno-types="https://deno.land/x/esbuild/mod.d.ts"
21-
import * as esbuild from "https://deno.land/x/esbuild/mod.js";
22-
import { denoPlugins } from "jsr:@luca/esbuild-deno-loader@^0.10.3";
23-
import commonjsPlugin from "npm:@chialab/esbuild-plugin-commonjs";
2427

2528
import "../lib/meta/prod.js";
26-
import { parseArgs } from "jsr:@std/cli@^0.224.7/parse-args";
2729

2830
const logger = new Logger();
2931
const runner = new Runner(logger);
3032
console.log(bold("Building the Production Server"));
3133
const args = parseArgs(Deno.args, {
3234
boolean: ["single"],
33-
default: { single: true }
34-
})
35+
default: { single: true },
36+
});
3537

3638
// set constants
3739
logger.info("Setting up");
@@ -107,8 +109,6 @@ if (
107109
}
108110
}
109111

110-
111-
112112
// await runner.run(Deno.execPath(), ["run", "-A", "./internal/scripts/render_ejs.js"]);
113113
const ejsMap = await renderEjs(false);
114114
logger.fine("EJS Rendered!");
@@ -174,7 +174,7 @@ await Deno.mkdir(outClientDir, { recursive: true });
174174

175175
if (args.single) {
176176
// skip
177-
logger.info("Single Build -- Pages Not Rendered Separately ")
177+
logger.info("Single Build -- Pages Not Rendered Separately ");
178178
} else {
179179
await esbuild.build({
180180
entryPoints: Array.from(routerMap.entries()).map((e) => e[1].fullPath),
@@ -183,9 +183,12 @@ if (args.single) {
183183
format: "esm",
184184
jsx: "automatic",
185185
jsxImportSource: deno.compilerOptions.jsxImportSource,
186-
plugins: [...denoPlugins({
187-
configPath: join(cwd, "deno.json"),
188-
}), commonjsPlugin()],
186+
plugins: [
187+
...denoPlugins({
188+
configPath: join(cwd, "deno.json"),
189+
}),
190+
commonjsPlugin(),
191+
],
189192
});
190193

191194
for (const [k, v] of Array.from(routerMap.entries())) {
@@ -200,7 +203,10 @@ if (args.single) {
200203
join(outDir, "client/blog/[name]/index.server.js"),
201204
Deno.readTextFileSync(
202205
join(outDir, "client/blog/[name]/index.server.js"),
203-
).replaceAll('from "url"', 'from "node:url"').replaceAll('from "fs"', 'from "node:fs"').replaceAll('from "path"', 'from "node:path"')
206+
).replaceAll('from "url"', 'from "node:url"').replaceAll(
207+
'from "fs"',
208+
'from "node:fs"',
209+
).replaceAll('from "path"', 'from "node:path"'),
204210
);
205211

206212
logger.fine("Bundled Pages!");
@@ -276,8 +282,16 @@ for await (
276282
}
277283

278284
// bundling svgs
279-
logger.info("Using SVGO to optimize SVGs")
280-
await runner.run(Deno.execPath(), ["run", "-A", "npm:svgo", "-f", join(cwd, "assets", "svg") , "-o", join(outDir, "assets", "svg")])
285+
logger.info("Using SVGO to optimize SVGs");
286+
await runner.run(Deno.execPath(), [
287+
"run",
288+
"-A",
289+
"npm:svgo",
290+
"-f",
291+
join(cwd, "assets", "svg"),
292+
"-o",
293+
join(outDir, "assets", "svg"),
294+
]);
281295

282296
// bundling content
283297
logger.info("Bundling Content");
@@ -332,14 +346,14 @@ Deno.writeTextFileSync(
332346
).replaceAll('from "url"', 'from "node:url"'),
333347
);
334348

335-
logger.info("Minifying Server")
349+
logger.info("Minifying Server");
336350
await esbuild.build({
337351
entryPoints: [join(outDir, "server.js")],
338352
outfile: join(outDir, "server.min.js"),
339353
minify: true,
340354
plugins: [...denoPlugins({
341355
configPath: join(cwd, "deno.json"),
342-
})]
356+
})],
343357
});
344358

345359
logger.fine(`Server built at ${join(outDir, "server.js")}`);

internal/commands/dev.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import { watchConfig } from "npm:c12";
1+
import { delay, watchConfig } from "../deps.ts";
22
import { defaultConfig } from "../lib/config.ts";
33
import { mergeConfig } from "../lib/config.ts";
44
import serve from "../lib/server/devServer.ts";
55
import { buildRouter } from "../lib/router.ts";
6-
import { delay } from "jsr:@std/async/delay";
76
import { Runner } from "../lib/runner.ts";
87
import { Logger } from "../lib/logger.ts";
98

internal/deps.ts

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
export { join } from "jsr:@std/path/join";
2+
export { walk, walkSync } from "jsr:@std/fs/walk";
3+
export { relative } from "jsr:@std/path/relative";
4+
export { normalize } from "jsr:@std/path/normalize";
5+
export { SEPARATOR } from "jsr:@std/path/constants";
6+
export { extname } from "jsr:@std/path/extname";
7+
export { basename } from "jsr:@std/path/basename";
8+
export { exists, existsSync } from "jsr:@std/fs/exists";
9+
export { globToRegExp } from "jsr:@std/path/glob-to-regexp";
10+
export { isAbsolute } from "jsr:@std/path/is-absolute";
11+
export { toFileUrl } from "jsr:@std/path/to-file-url";
12+
export { delay } from "jsr:@std/async/delay";
13+
export { parseArgs } from "jsr:@std/cli/parse-args";
14+
export { serveDir, serveFile } from "jsr:@std/http/file-server";
15+
export {
16+
blue,
17+
bold,
18+
dim,
19+
gray,
20+
green,
21+
italic,
22+
magenta,
23+
red,
24+
yellow,
25+
} from "jsr:@std/fmt/colors";
26+
export { denoPlugins } from "jsr:@luca/esbuild-deno-loader";
27+
28+
export { renderSSR } from "https://deno.land/x/nano_jsx@v0.1.0/ssr.ts";
29+
export { withStyles } from "https://deno.land/x/nano_jsx@v0.1.0/withStyles.ts";
30+
// @deno-types="https://deno.land/x/esbuild/mod.d.ts"
31+
export * as esbuild from "https://deno.land/x/esbuild/mod.js";
32+
33+
export { format } from "npm:prettier";
34+
// @deno-types="npm:@types/ejs"
35+
export { render as ejsRender } from "npm:ejs";
36+
// @deno-types="npm:@types/mime-types"
37+
export { lookup } from "npm:mime-types";
38+
export { loadConfig, watchConfig } from "npm:c12";
39+
export { default as commonjsPlugin } from "npm:@chialab/esbuild-plugin-commonjs";

internal/lib/logger.ts

+1-9
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,4 @@
1-
import {
2-
blue,
3-
bold,
4-
gray,
5-
green,
6-
magenta,
7-
red,
8-
yellow,
9-
} from "jsr:@std/fmt/colors";
1+
import { blue, bold, gray, green, magenta, red, yellow } from "../deps.ts";
102

113
type LogMode = "info" | "warn" | "error" | "fine" | "cmd";
124

internal/lib/router.ts

+9-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
import { join } from "jsr:@std/path/join";
2-
import { walkSync } from "jsr:@std/fs/walk";
3-
import { globToRegExp } from "jsr:@std/path/glob-to-regexp";
4-
import { extname } from "jsr:@std/path/extname";
5-
import { relative } from "jsr:@std/path/relative";
6-
import { SEPARATOR } from "jsr:@std/path/constants";
7-
import { basename } from "jsr:@std/path/basename";
1+
import {
2+
basename,
3+
extname,
4+
globToRegExp,
5+
join,
6+
relative,
7+
SEPARATOR,
8+
walkSync,
9+
} from "../deps.ts";
810

911
export interface RouteInfo {
1012
/** The name of the file/path route */

internal/lib/runner.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { italic } from "jsr:@std/fmt/colors";
1+
import { italic } from "../deps.ts";
22
import { Logger, VerboseLogger } from "./logger.ts";
33

44
export class Runner {

internal/lib/server/devServer.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
import { existsSync } from "jsr:@std/fs/exists";
1+
import { existsSync, join, serveDir, serveFile } from "../../deps.ts";
22
import { createError } from "../errors.ts";
3-
import { join } from "jsr:@std/path";
4-
import { serveDir } from "jsr:@std/http";
5-
63
import { getRouterParams } from "../router.ts";
74
import { NikeConfig } from "../config.ts";
85
import { RouterMap } from "../RouterMap.ts";
@@ -12,7 +9,6 @@ import {
129
renderClientPage,
1310
renderServerPage,
1411
} from "./utils.tsx";
15-
import { serveFile } from "jsr:@std/http/file-server";
1612
import { ClientRequest } from "../../lib/client.ts";
1713
import { APIRequest } from "../../lib/api.ts";
1814

internal/lib/server/prodServer.ts

+25-19
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
1-
import { join } from "jsr:@std/path";
2-
import { NikeConfig } from "../config.ts";
3-
import { ServerProdOptions } from "./options.ts";
4-
import { getRouterParams } from "../router.ts";
5-
import { RouterMap } from "../RouterMap.ts";
6-
import { existsSync } from "jsr:@std/fs/exists";
1+
import { existsSync, join, lookup } from "../../deps.ts";
2+
73
import {
84
convertSearchParams,
95
errorHandler,
106
renderClientPage,
117
renderServerPage,
128
} from "./utils.tsx";
139
import { createError } from "../errors.ts";
14-
// @deno-types="npm:@types/mime-types"
15-
import { lookup } from 'npm:mime-types'
10+
import { NikeConfig } from "../config.ts";
11+
import { ServerProdOptions } from "./options.ts";
12+
import { getRouterParams } from "../router.ts";
13+
import { RouterMap } from "../RouterMap.ts";
1614

1715
export default function serve(
1816
options: ServerProdOptions,
1917
config: NikeConfig,
2018
routerMap: RouterMap,
21-
components: Record<string, any>
19+
components: Record<string, any>,
2220
) {
2321
return Deno.serve({
2422
hostname: config.server?.host ?? "localhost",
@@ -55,7 +53,7 @@ export default function serve(
5553
routeInfo,
5654
options,
5755
reqObj: serverReqObj,
58-
component
56+
component,
5957
});
6058
return v;
6159
} catch (e) {
@@ -69,7 +67,13 @@ export default function serve(
6967
}
7068
} else {
7169
try {
72-
return await renderClientPage({ routeInfo, options, reqObj, config, component });
70+
return await renderClientPage({
71+
routeInfo,
72+
options,
73+
reqObj,
74+
config,
75+
component,
76+
});
7377
} catch (e) {
7478
const err = e as Error;
7579
console.error(err);
@@ -80,7 +84,6 @@ export default function serve(
8084
});
8185
}
8286
// serve client route with nanojsx
83-
8487
}
8588
}
8689

@@ -99,14 +102,16 @@ export default function serve(
99102
) {
100103
const publicFilePath = join(
101104
publicDir,
102-
pathname.startsWith("/") ? pathname.replace("/", "") : pathname
105+
pathname.startsWith("/") ? pathname.replace("/", "") : pathname,
103106
);
104107

105108
return new Response(Deno.readTextFileSync(publicFilePath), {
106109
headers: {
107-
"content-type": (lookup(publicFilePath) === false ? "text/plain" : lookup(publicFilePath)).toString(),
108-
}
109-
})
110+
"content-type": (lookup(publicFilePath) === false
111+
? "text/plain"
112+
: lookup(publicFilePath)).toString(),
113+
},
114+
});
110115
}
111116

112117
if (
@@ -124,9 +129,10 @@ export default function serve(
124129

125130
return new Response(Deno.readTextFileSync(path), {
126131
headers: {
127-
"content-type": (lookup(path) === false ? "text/plain" : lookup(path)).toString(),
128-
}
129-
})
132+
"content-type":
133+
(lookup(path) === false ? "text/plain" : lookup(path)).toString(),
134+
},
135+
});
130136
}
131137

132138
throw createError({

0 commit comments

Comments
 (0)