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

Commit 69ca844

Browse files
authored
Merge pull request #112 from alephjs/split-code
2 parents 3e14325 + 9f693cf commit 69ca844

File tree

20 files changed

+310
-269
lines changed

20 files changed

+310
-269
lines changed

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@
44
<a href="https://alephjs.org">Website</a> |
55
<a href="https://alephjs.org/docs/get-started">Get Started</a> |
66
<a href="https://alephjs.org/docs">Docs</a> |
7+
<a href="https://esm.sh">ESM.sh</a> |
78
<a href="./CONTRIBUTING.md">Contributing</a>
89
</p>
910

1011
<p>
1112
<a href="https://discord.gg/pWGdS7sAqD"><img src="https://img.shields.io/discord/775256646821085215?color=%23008181&label=Chat&labelColor=%23111&logo=discord&logoColor=%23aaaaaa" alt="Chat"></a>
1213
<a href="https://twitter.com/intent/follow?screen_name=alephjs"><img src="https://img.shields.io/twitter/follow/alephjs?style=social" alt="Twitter"></a>
1314
</p>
14-
15-
<br>

cli.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ import { Request } from './server/api.ts'
33
import { getContentType } from './server/mime.ts'
44
import { createHtml } from './server/util.ts'
55
import { existsDirSync, existsFileSync } from './shared/fs.ts'
6+
import type { LevelNames } from './shared/log.ts'
67
import log from './shared/log.ts'
78
import util from './shared/util.ts'
8-
import { ServerRequest } from './types.ts'
9+
import type { ServerRequest } from './types.ts'
910
import { VERSION } from './version.ts'
1011

1112
const commands = {
@@ -97,7 +98,7 @@ async function main() {
9798
// sets log level
9899
const l = flags.L || flags['log-level']
99100
if (util.isNEString(l)) {
100-
log.setLevel(l)
101+
log.setLevel(l.toLowerCase() as LevelNames)
101102
}
102103

103104
if (!hasCommand && !args[0]) {

compiler/dist/wasm-checksum.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export const checksum = "39c541b0232d174ab430a3ecd59cca39c945a339"
1+
export const checksum = "955cc1cd2630ed3851a53a627483e7f3f51879d9"

compiler/dist/wasm.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

compiler/src/fixer.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ impl Fold for JSXLinkFixer {
3636
let rel = rel.as_str();
3737
match rel {
3838
"style" | "stylesheet" => {
39-
let (url, _) = resolver.resolve(dep.specifier.as_str(), false, None);
39+
let (url, _) =
40+
resolver.resolve(dep.specifier.as_str(), false, Some(".".into()));
4041
items.push(ModuleItem::ModuleDecl(ModuleDecl::Import(ImportDecl {
4142
span: DUMMY_SP,
4243
specifiers: vec![],

compiler/src/resolve.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -346,11 +346,17 @@ impl Resolver {
346346
},
347347
None => {}
348348
};
349-
self.dep_graph.push(DependencyDescriptor {
350-
specifier: fixed_url.clone(),
351-
is_dynamic,
352-
rel,
353-
});
349+
let update_dep_graph = match rel {
350+
Some(ref rel) => !rel.eq("."),
351+
None => true,
352+
};
353+
if update_dep_graph {
354+
self.dep_graph.push(DependencyDescriptor {
355+
specifier: fixed_url.clone(),
356+
is_dynamic,
357+
rel,
358+
});
359+
}
354360
let path = resolved_path.to_slash().unwrap();
355361
if !path.starts_with("./") && !path.starts_with("../") && !path.starts_with("/") {
356362
return (format!("./{}", path), fixed_url);

deps.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
// std
2-
export { Untar } from 'https://deno.land/std@0.84.0/archive/tar.ts'
3-
export * as bytes from 'https://deno.land/std@0.84.0/bytes/mod.ts'
4-
export * as base64 from 'https://deno.land/std@0.84.0/encoding/base64.ts'
5-
export * as colors from 'https://deno.land/std@0.84.0/fmt/colors.ts'
6-
export { ensureDir } from 'https://deno.land/std@0.84.0/fs/ensure_dir.ts'
7-
export { walk } from 'https://deno.land/std@0.84.0/fs/walk.ts'
8-
export { Sha1 } from 'https://deno.land/std@0.84.0/hash/sha1.ts'
9-
export { Sha256 } from 'https://deno.land/std@0.84.0/hash/sha256.ts'
10-
export { listenAndServe, serve } from 'https://deno.land/std@0.84.0/http/server.ts'
11-
export * as bufio from 'https://deno.land/std@0.84.0/io/bufio.ts'
12-
export * as path from 'https://deno.land/std@0.84.0/path/mod.ts'
13-
export * as ws from 'https://deno.land/std@0.84.0/ws/mod.ts'
2+
export { Untar } from 'https://deno.land/std@0.85.0/archive/tar.ts'
3+
export * as bytes from 'https://deno.land/std@0.85.0/bytes/mod.ts'
4+
export * as base64 from 'https://deno.land/std@0.85.0/encoding/base64.ts'
5+
export * as colors from 'https://deno.land/std@0.85.0/fmt/colors.ts'
6+
export { ensureDir } from 'https://deno.land/std@0.85.0/fs/ensure_dir.ts'
7+
export { walk } from 'https://deno.land/std@0.85.0/fs/walk.ts'
8+
export { Sha1 } from 'https://deno.land/std@0.85.0/hash/sha1.ts'
9+
export { Sha256 } from 'https://deno.land/std@0.85.0/hash/sha256.ts'
10+
export { listenAndServe, serve } from 'https://deno.land/std@0.85.0/http/server.ts'
11+
export * as bufio from 'https://deno.land/std@0.85.0/io/bufio.ts'
12+
export * as path from 'https://deno.land/std@0.85.0/path/mod.ts'
13+
export * as ws from 'https://deno.land/std@0.85.0/ws/mod.ts'
1414
// deno.land/x
1515
export * as brotli from 'https://deno.land/x/[email protected]/mod.ts'
1616
export { gzipDecode, gzipEncode } from 'https://deno.land/x/[email protected]/mod.ts'

framework/core/routing_test.ts

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
import { assertEquals } from 'https://deno.land/[email protected]/testing/asserts.ts'
2+
import { Routing } from './routing.ts'
3+
4+
Deno.test(`routing`, () => {
5+
const routing = new Routing([], '/', 'en', ['en', 'zh-CN'])
6+
routing.update({ url: '/pages/index.tsx', hash: '' })
7+
routing.update({ url: '/pages/blog/index.tsx', hash: '' })
8+
routing.update({ url: '/pages/blog/[slug].tsx', hash: '' })
9+
routing.update({ url: '/pages/user/index.tsx', hash: '' })
10+
routing.update({ url: '/pages/user/[...all].tsx', hash: '' })
11+
routing.update({ url: '/pages/blog.tsx', hash: '' })
12+
routing.update({ url: '/pages/user.tsx', hash: '' })
13+
routing.update({ url: '/pages/blog/[slug]/subpage.tsx', hash: '' })
14+
routing.update({ url: '/pages/docs.tsx', hash: '' })
15+
routing.update({ url: '/pages/docs/get-started.tsx', hash: '' })
16+
routing.update({ url: '/pages/docs/installation.tsx', hash: '' })
17+
routing.update({ url: '/pages/index.tsx', hash: 'hsidfshy3yhfya49848' })
18+
19+
assertEquals(routing.paths, [
20+
'/',
21+
'/blog',
22+
'/user',
23+
'/docs',
24+
'/blog/[slug]',
25+
'/blog/[slug]/subpage',
26+
'/user/[...all]',
27+
'/docs/get-started',
28+
'/docs/installation',
29+
])
30+
31+
{
32+
const [router, chain] = routing.createRouter({ pathname: '/' })
33+
assertEquals(router.locale, 'en')
34+
assertEquals(router.pathname, '/')
35+
assertEquals(router.pagePath, '/')
36+
assertEquals(chain, [{ url: '/pages/index.tsx', hash: 'hsidfshy3yhfya49848' }])
37+
}
38+
39+
{
40+
const [router, chain] = routing.createRouter({ pathname: '/zh-CN' })
41+
assertEquals(router.locale, 'zh-CN')
42+
assertEquals(router.pathname, '/')
43+
assertEquals(router.pagePath, '/')
44+
assertEquals(chain, [{ url: '/pages/index.tsx', hash: 'hsidfshy3yhfya49848' }])
45+
}
46+
47+
{
48+
const [router, chain] = routing.createRouter({ pathname: '/blog' })
49+
assertEquals(router.locale, 'en')
50+
assertEquals(router.pathname, '/blog')
51+
assertEquals(router.pagePath, '/blog')
52+
assertEquals(chain.map(({ url }) => url), ['/pages/blog.tsx', '/pages/blog/index.tsx'])
53+
}
54+
55+
{
56+
const [router, chain] = routing.createRouter({ pathname: '/zh-CN/blog' })
57+
assertEquals(router.locale, 'zh-CN')
58+
assertEquals(router.pathname, '/blog')
59+
assertEquals(router.pagePath, '/blog')
60+
assertEquals(chain.map(({ url }) => url), ['/pages/blog.tsx', '/pages/blog/index.tsx'])
61+
}
62+
63+
{
64+
const [router, chain] = routing.createRouter({ pathname: '/blog/hello-world' })
65+
assertEquals(router.pathname, '/blog/hello-world')
66+
assertEquals(router.pagePath, '/blog/[slug]')
67+
assertEquals(router.params, { slug: 'hello-world' })
68+
assertEquals(chain.map(({ url }) => url), ['/pages/blog.tsx', '/pages/blog/[slug].tsx'])
69+
}
70+
71+
{
72+
const [router, chain] = routing.createRouter({ pathname: '/user' })
73+
assertEquals(router.pathname, '/user')
74+
assertEquals(router.pagePath, '/user')
75+
assertEquals(router.params, {})
76+
assertEquals(chain.map(({ url }) => url), ['/pages/user.tsx', '/pages/user/index.tsx'])
77+
}
78+
79+
{
80+
const [router, chain] = routing.createRouter({ pathname: '/user/projects' })
81+
assertEquals(router.pathname, '/user/projects')
82+
assertEquals(router.pagePath, '/user/[...all]')
83+
assertEquals(router.params, { all: 'projects' })
84+
assertEquals(chain.map(({ url }) => url), ['/pages/user.tsx', '/pages/user/[...all].tsx'])
85+
}
86+
87+
{
88+
const [router, chain] = routing.createRouter({ pathname: '/user/settings/profile' })
89+
assertEquals(router.pathname, '/user/settings/profile')
90+
assertEquals(router.pagePath, '/user/[...all]')
91+
assertEquals(router.params, { all: 'settings/profile' })
92+
assertEquals(chain.map(({ url }) => url), ['/pages/user.tsx', '/pages/user/[...all].tsx'])
93+
}
94+
95+
{
96+
const [router, chain] = routing.createRouter({ pathname: '/user/settings/security' })
97+
assertEquals(router.pathname, '/user/settings/security')
98+
assertEquals(router.pagePath, '/user/[...all]')
99+
assertEquals(router.params, { all: 'settings/security' })
100+
assertEquals(chain.map(({ url }) => url), ['/pages/user.tsx', '/pages/user/[...all].tsx'])
101+
}
102+
103+
{
104+
const [router, chain] = routing.createRouter({ pathname: '/null' })
105+
assertEquals(router.pathname, '/null')
106+
assertEquals(router.pagePath, '')
107+
assertEquals(router.params, {})
108+
assertEquals(chain, [])
109+
}
110+
})

framework/react/bootstrap.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ export default async function bootstrap(options: Options) {
3636
const imports = await Promise.all(pageModuleChain.map(async mod => {
3737
const [{ default: Component }] = await Promise.all([
3838
importModule(baseUrl, mod),
39-
mod.asyncDeps?.filter(({ isData }) => !!isData).length ? loadPageDataFromTag(url) : Promise.resolve(),
40-
mod.asyncDeps?.filter(({ isStyle }) => !!isStyle).map(dep => importModule(baseUrl, dep)) || Promise.resolve()
41-
].flat())
39+
mod.asyncDeps?.filter(({ isData }) => !!isData).length ? loadPageDataFromTag(url) : Promise.resolve()
40+
])
41+
await Promise.all(mod.asyncDeps?.filter(({ isStyle }) => !!isStyle).map(dep => importModule(baseUrl, dep)) || [])
4242
return {
4343
url: mod.url,
4444
Component,

framework/react/router.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ export default function Router({
4646
const [{ default: Component }] = await Promise.all([
4747
importModule(baseUrl, mod, e.forceRefetch),
4848
mod.asyncDeps?.filter(({ isData }) => !!isData).length ? loadPageData(url) : Promise.resolve(),
49-
mod.asyncDeps?.filter(({ isStyle }) => !!isStyle).map(dep => importModule(baseUrl, dep)) || Promise.resolve()
5049
])
50+
await Promise.all(mod.asyncDeps?.filter(({ isStyle }) => !!isStyle).map(dep => importModule(baseUrl, dep)) || [])
5151
return {
5252
url: mod.url,
5353
Component

0 commit comments

Comments
 (0)