Skip to content
This repository was archived by the owner on Jul 6, 2025. It is now read-only.

Commit 67f8b35

Browse files
author
Je
committed
refactor: cleanup
1 parent dd3033d commit 67f8b35

File tree

3 files changed

+28
-31
lines changed

3 files changed

+28
-31
lines changed

api.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type { APIRequest, APIRequestURL, APIResponse, RouterURL } from './types.
55
export class AlephAPIRequest implements APIRequest {
66
#req: ServerRequest
77
#url: APIRequestURL
8-
cookies: ReadonlyMap<string, string>
8+
#cookies: ReadonlyMap<string, string>
99

1010
constructor(req: ServerRequest, url: RouterURL) {
1111
this.#req = req
@@ -19,14 +19,17 @@ export class AlephAPIRequest implements APIRequest {
1919
params: paramsMap,
2020
query: url.query,
2121
}
22-
this.cookies = new Map()
23-
// todo: parse cookies
22+
this.#cookies = new Map() // todo: parse cookies
2423
}
2524

2625
get url(): APIRequestURL {
2726
return this.#url
2827
}
2928

29+
get cookies(): ReadonlyMap<string, string> {
30+
return this.#cookies
31+
}
32+
3033
get method(): string {
3134
return this.#req.method
3235
}
@@ -79,7 +82,7 @@ export class AlephAPIResponse implements APIResponse {
7982
return this
8083
}
8184

82-
send(data: string | Uint8Array | ArrayBuffer) {
85+
async send(data: string | Uint8Array | ArrayBuffer) {
8386
let body: string | Uint8Array
8487
if (data instanceof ArrayBuffer) {
8588
body = new Uint8Array(data)
@@ -93,7 +96,7 @@ export class AlephAPIResponse implements APIResponse {
9396
}).catch(err => log.warn('ServerRequest.respond:', err.message))
9497
}
9598

96-
json(data: any) {
99+
async json(data: any) {
97100
this.#headers.set('Content-Type', 'application/json')
98101
return this.#req.respond({
99102
status: this.#status,

bump.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ async function run(...cmd: string[]) {
2727
}
2828

2929
async function main() {
30-
const answer = await ask([...versions.map((v, i) => `${i + 1}. v${v}`), 'upgrade to:'].join('\n'))
30+
const answer = await ask([...versions.map((v, i) => `${i + 1} v${v}`), 'upgrade to:'].join('\n'))
3131
const n = parseInt(answer)
3232
if (!isNaN(n) && n > 0 && n <= versions.length) {
3333
const up = versions[n - 1]

project.ts

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ export class Project {
284284
}
285285
}
286286

287-
// wait project ready
287+
// wait for project ready
288288
await this.ready
289289

290290
// lookup output modules
@@ -295,13 +295,13 @@ export class Project {
295295
lookup('//deno.land/x/aleph/nomodule.js')
296296
lookup('//deno.land/x/aleph/tsc/tslib.js')
297297

298-
// ensure ouput directory ready
299298
if (existsDirSync(outputDir)) {
300299
await Deno.remove(outputDir, { recursive: true })
301300
}
302301
await ensureDir(outputDir)
303302
await ensureDir(distDir)
304303

304+
// ssg
305305
const { ssr } = this.config
306306
if (ssr) {
307307
log.info(colors.bold(' Pages (SSG)'))
@@ -329,22 +329,19 @@ export class Project {
329329
const fi = await Deno.lstat(p)
330330
await ensureDir(path.dirname(fp))
331331
await Deno.copyFile(p, fp)
332-
let sizeColorful = colors.dim
333-
if (fi.size > 10 * MB) {
334-
sizeColorful = colors.red
335-
} else if (fi.size > MB) {
336-
sizeColorful = colors.yellow
337-
}
338332
log.info(' ✹', rp, colors.dim('•'), getColorfulBytesString(fi.size))
339333
}
340334
}
341335

342-
let deps = 0
343-
let depsBytes = 0
344-
let modules = 0
345-
let modulesBytes = 0
346-
let styles = 0
347-
let stylesBytes = 0
336+
const moduleState = {
337+
deps: { bytes: 0, count: 0 },
338+
modules: { bytes: 0, count: 0 },
339+
styles: { bytes: 0, count: 0 }
340+
}
341+
const logModule = (key: 'deps' | 'modules' | 'styles', size: number) => {
342+
moduleState[key].bytes += size
343+
moduleState[key].count++
344+
}
348345

349346
// write modules
350347
const { sourceMap } = this.config
@@ -354,15 +351,12 @@ export class Project {
354351
const name = path.basename(sourceFilePath).replace(reModuleExt, '')
355352
const jsFile = path.join(saveDir, name + (isRemote ? '' : '.' + hash.slice(0, hashShort))) + '.js'
356353
if (isRemote) {
357-
deps++
358-
depsBytes += jsContent.length
354+
logModule('deps', jsContent.length)
359355
} else {
360356
if (sourceType === 'css' || sourceType === 'less') {
361-
styles++
362-
stylesBytes += jsContent.length
357+
logModule('styles', jsContent.length)
363358
} else {
364-
modules++
365-
modulesBytes += jsContent.length
359+
logModule('modules', jsContent.length)
366360
}
367361
}
368362
return Promise.all([
@@ -376,15 +370,15 @@ export class Project {
376370
const { hash } = this.#modules.get('/data.js')!
377371
const data = await this.getStaticData()
378372
const jsContent = `export default ${JSON.stringify(data)}`
379-
modules++
380-
modulesBytes += jsContent.length
381373
await writeTextFile(path.join(distDir, `data.${hash.slice(0, hashShort)}.js`), jsContent)
374+
logModule('modules', jsContent.length)
382375
}
383376

377+
const { deps, modules, styles } = moduleState
384378
log.info(colors.bold(' Modules'))
385-
log.info(' ▲', colors.bold(deps.toString()), 'deps', colors.dim(`• ${util.bytesString(depsBytes)} (mini, uncompress)`))
386-
log.info(' ▲', colors.bold(modules.toString()), 'modules', colors.dim(`• ${util.bytesString(modulesBytes)} (mini, uncompress)`))
387-
log.info(' ▲', colors.bold(styles.toString()), 'styles', colors.dim(`• ${util.bytesString(stylesBytes)} (mini, uncompress)`))
379+
log.info(' ▲', colors.bold(deps.count.toString()), 'deps', colors.dim(`• ${util.bytesString(deps.bytes)} (mini, uncompress)`))
380+
log.info(' ▲', colors.bold(modules.count.toString()), 'modules', colors.dim(`• ${util.bytesString(modules.bytes)} (mini, uncompress)`))
381+
log.info(' ▲', colors.bold(styles.count.toString()), 'styles', colors.dim(`• ${util.bytesString(styles.bytes)} (mini, uncompress)`))
388382

389383
log.info(`Done in ${Math.round(performance.now() - start)}ms`)
390384
}

0 commit comments

Comments
 (0)