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

Commit bedc911

Browse files
committed
Improve init command
1 parent ed55de7 commit bedc911

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

cli/init.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ import { Untar } from 'https://deno.land/[email protected]/archive/tar.ts'
22
import { green, dim } from 'https://deno.land/[email protected]/fmt/colors.ts'
33
import { ensureDir } from 'https://deno.land/[email protected]/fs/ensure_dir.ts'
44
import { join } from 'https://deno.land/[email protected]/path/mod.ts'
5-
import { gunzip } from 'https://deno.land/x/[email protected]/mod.ts'
5+
import { gunzip } from 'https://deno.land/x/denoflate@1.2.1/mod.ts'
66
import { ensureTextFile } from '../shared/fs.ts'
77
import util from '../shared/util.ts'
88
import { defaultReactVersion } from '../shared/constants.ts'
99
import { VERSION } from '../version.ts'
10+
import { x_brotli, x_flate } from '../server/compress.ts'
1011

1112
export const helpMessage = `
1213
Usage:
@@ -61,6 +62,7 @@ export default async function (nameArg?: string) {
6162
imports: {
6263
'~/': './',
6364
'aleph/': `https://deno.land/x/aleph@v${VERSION}/`,
65+
'aleph/types': `https://deno.land/x/aleph@v${VERSION}/types.ts`,
6466
'framework': `https://deno.land/x/aleph@v${VERSION}/framework/core/mod.ts`,
6567
'framework/react': `https://deno.land/x/aleph@v${VERSION}/framework/react/mod.ts`,
6668
'react': `https://esm.sh/react@${defaultReactVersion}`,
@@ -73,6 +75,13 @@ export default async function (nameArg?: string) {
7375
Deno.writeTextFile(join(cwd, name, 'import_map.json'), JSON.stringify(importMap, undefined, 2))
7476
])
7577

78+
const urls = Object.values(importMap.imports).filter(v => !v.endsWith('/'))
79+
const p = Deno.run({
80+
cmd: [Deno.execPath(), 'cache', ...urls, x_brotli, x_flate]
81+
})
82+
await p.status()
83+
p.close()
84+
7685
if (vscode) {
7786
const extensions = {
7887
'recommendations': [

server/compress.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { ServerRequest, ServerResponse } from '../types.ts'
22

3-
const brotliMod = 'https://deno.land/x/[email protected]/mod.ts'
4-
const flateMod = 'https://deno.land/x/[email protected]/mod.ts'
3+
export const x_brotli = 'https://deno.land/x/[email protected]/mod.ts'
4+
export const x_flate = 'https://deno.land/x/[email protected]/mod.ts'
55

66
class Compression {
77
#brotli: ((data: Uint8Array) => Uint8Array) | null = null
@@ -10,11 +10,11 @@ class Compression {
1010

1111
async init() {
1212
if (this.#brotli === null) {
13-
const { compress } = await import(brotliMod)
13+
const { compress } = await import(x_brotli)
1414
this.#brotli = compress
1515
}
1616
if (this.#gzip === null) {
17-
const denoflate = await import(flateMod)
17+
const denoflate = await import(x_flate)
1818
this.#gzip = (data: Uint8Array) => denoflate.gzip(data, undefined)
1919
}
2020
this.#ready = true

0 commit comments

Comments
 (0)