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

Commit 7adee1a

Browse files
author
Je
committed
breaking: rewrite Config interface
1 parent fda8195 commit 7adee1a

File tree

3 files changed

+45
-32
lines changed

3 files changed

+45
-32
lines changed

hmr.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import runtime from 'https://esm.sh/react-refresh/runtime?dev'
1+
import runtime from 'https://esm.sh/react-refresh@0.8.3/runtime'
22
import events from './events.ts'
33
import util, { hashShort } from './util.ts'
44

project.ts

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ interface RenderResult {
4343
export class Project {
4444
readonly mode: 'development' | 'production'
4545
readonly appRoot: string
46-
readonly config: Readonly<Config>
46+
readonly config: Readonly<Required<Config>>
4747
readonly importMap: Readonly<{ imports: Record<string, string> }>
4848
readonly ready: Promise<void>
4949

@@ -68,7 +68,9 @@ export class Project {
6868
},
6969
buildTarget: mode === 'development' ? 'es2018' : 'es2015',
7070
sourceMap: false,
71-
env: {}
71+
env: {},
72+
reactUrl: 'https://esm.sh/[email protected]',
73+
reactDomUrl: 'https://esm.sh/[email protected]'
7274
}
7375
this.importMap = { imports: {} }
7476
this.ready = (async () => {
@@ -843,19 +845,16 @@ export class Project {
843845
break
844846
}
845847
}
846-
if (dlUrl.startsWith('https://esm.sh/[')) {
847-
dlUrl.replace(/\[([^\]]+)\]/, (_, s: string) => {
848-
const list = s.split(',').map(s => s.trim())
849-
if (list.length > 0) {
850-
const mod = util.trimPrefix(url, 'https://esm.sh/').replace(/\/+$/, '')
851-
if (!list.includes(mod)) {
852-
dlUrl = url
853-
}
854-
}
855-
return _
856-
})
848+
if (/^https?:\/\/[0-9a-z\.\-]+\/react(@[0-9a-z\.\-]+)?\/?$/i.test(url)) {
849+
dlUrl = this.config.reactUrl
850+
}
851+
if (/^https?:\/\/[0-9a-z\.\-]+\/react\-dom(@[0-9a-z\.\-]+)?(\/server)?\/?$/i.test(url)) {
852+
dlUrl = this.config.reactDomUrl
853+
if (/\/server\/?$/i.test(url)) {
854+
dlUrl += '/server'
855+
}
857856
}
858-
if (url.startsWith('https://esm.sh/')) {
857+
if (dlUrl.startsWith('https://esm.sh/')) {
859858
const u = new URL(dlUrl)
860859
u.searchParams.set('target', this.config.buildTarget)
861860
if (this.isDev && !u.searchParams.has('dev')) {
@@ -972,21 +971,21 @@ export class Project {
972971
this.isDev && ` _s();`,
973972
` const ref = useRef(null);`,
974973
` useEffect(() => {`,
975-
` const appLinks = [];`,
974+
` const anchors = [];`,
976975
` const onClick = e => {`,
977976
` e.preventDefault();`,
978977
` redirect(e.currentTarget.getAttribute("href"));`,
979978
` };`,
980979
` if (ref.current) {`,
981980
` ref.current.querySelectorAll("a").forEach(a => {`,
982981
` const href = a.getAttribute("href");`,
983-
` if (href && !/^(https?|mailto|file):/i.test(href)) {`,
982+
` if (href && !/^[a-z0-9]+:/i.test(href)) {`,
984983
` a.addEventListener("click", onClick, false);`,
985-
` appLinks.push(a);`,
984+
` anchors.push(a);`,
986985
` }`,
987986
` });`,
988987
` }`,
989-
` return () => appLinks.forEach(a => a.removeEventListener("click", onClick));`,
988+
` return () => anchors.forEach(a => a.removeEventListener("click", onClick));`,
990989
` }, []);`,
991990
` return React.createElement("div", {className: "markdown-page", ref, dangerouslySetInnerHTML: {__html: ${JSON.stringify(html)}}});`,
992991
`}`,

types.ts

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,36 @@ export interface AlephEnv {
66
}
77

88
export interface SSROptions {
9-
readonly fallback?: string // default is '_fallback.html'
10-
readonly include?: RegExp[]
11-
readonly exclude?: RegExp[]
12-
readonly staticPaths?: string[]
9+
fallback?: string // default is '_fallback.html'
10+
include?: RegExp[]
11+
exclude?: RegExp[]
12+
staticPaths?: string[]
1313
}
1414

15+
/** Config for Aleph.js */
1516
export interface Config {
16-
srcDir: string
17-
outputDir: string
18-
baseUrl: string
19-
defaultLocale: string
20-
locales: string[]
21-
ssr: boolean | SSROptions
22-
buildTarget: string
23-
sourceMap: boolean
24-
env: Record<string, string>
17+
/** `srcDir` to put all your app `pages`, app.tsx, etc directories (default is '/') */
18+
srcDir?: string
19+
/** `outputDir` specifies the output directory for `build` command (default is 'dist') */
20+
outputDir?: string
21+
/** `baseUrl` specifies the path prefix for the application (default is '/') */
22+
baseUrl?: string
23+
/** `reactUrl` specifies the **react** url (default is 'https://esm.sh/[email protected]') */
24+
reactUrl?: string
25+
/** `reactDomUrl` specifies the **react-dom** url (default is 'https://esm.sh/[email protected]') */
26+
reactDomUrl?: string
27+
/** `defaultLocale` specifies the default locale of the application (default is 'en') */
28+
defaultLocale?: string
29+
/** A list of locales */
30+
locales?: string[]
31+
/** Option for **SSR** */
32+
ssr?: boolean | SSROptions
33+
/** `buildTarget` specifies the build taget for **tsc** (possible values: `ES2015-ES2020, ESNext`, default is ES2015 for production and ES2018 for development) */
34+
buildTarget?: string
35+
/** Enable sourceMap in **production** mode (default is false) */
36+
sourceMap?: boolean
37+
/** `env` defines the `Window.ALEPH.ENV` object in the application */
38+
env?: Record<string, string>
2539
}
2640

2741
export interface APIHandler {

0 commit comments

Comments
 (0)