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

Commit fd8cee7

Browse files
committed
Update types
1 parent 10f0612 commit fd8cee7

File tree

5 files changed

+24
-21
lines changed

5 files changed

+24
-21
lines changed

framework/react/init.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export async function init(aleph: Aleph) {
66
const alephPkgUri = getAlephPkgUri()
77
const alephPkgPath = alephPkgUri.replace('https://', '').replace('http://localhost:', 'http_localhost_')
88
await aleph.addModule(`${alephPkgUri}/framework/react/refresh.ts`)
9-
aleph.onTransform('main.js', ({ code }) => ({
9+
aleph.onTransform('mainscript', ({ code }) => ({
1010
code: [
1111
`import "./-/${alephPkgPath}/framework/react/refresh.js";`,
1212
code

plugins/css.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export const cssLoader = async ({ specifier, data }: LoadInput, aleph: Aleph): P
4141
}
4242
}
4343

44-
let plugins = cssConfig.postcss?.plugins || []
44+
let plugins = cssConfig.postcss.plugins || []
4545
let modulesJSON: Record<string, string> = {}
4646
if (/\.module\.[a-z]+$/.test(specifier)) {
4747
const options = {

server/aleph.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ type LoadListener = {
7676
}
7777

7878
type TransformListener = {
79-
test: RegExp | string,
79+
test: RegExp | 'hmr' | 'mainscript',
8080
transform(input: TransformInput): TransformOutput,
8181
}
8282

@@ -492,7 +492,7 @@ export class Aleph implements IAleph {
492492
this.#loadListeners.push({ test, load: callback })
493493
}
494494

495-
onTransform(test: RegExp | string, callback: (input: TransformInput) => TransformOutput): void {
495+
onTransform(test: RegExp | 'hmr' | 'mainscript', callback: (input: TransformInput) => TransformOutput): void {
496496
this.#transformListeners.push({ test, transform: callback })
497497
}
498498

@@ -671,7 +671,7 @@ export class Aleph implements IAleph {
671671
`bootstrap(${JSON.stringify(config, undefined, this.isDev ? 2 : undefined)});`
672672
].filter(Boolean).join('\n')
673673
this.#transformListeners.forEach(({ test, transform }) => {
674-
if (test === 'main.js') {
674+
if (test === 'mainscript') {
675675
const ret = transform({ specifier: '/main.js', code })
676676
code = ret.code
677677
}
@@ -1195,7 +1195,7 @@ export class Aleph implements IAleph {
11951195
}
11961196

11971197
this.#transformListeners.forEach(({ test, transform }) => {
1198-
if (test instanceof RegExp ? test.test(specifier) : test === '*') {
1198+
if (test instanceof RegExp && test.test(specifier)) {
11991199
const { code, map } = transform({ specifier, code: jsCode, map: sourceMap })
12001200
jsCode = code
12011201
if (map) {

server/config.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,11 @@ import { defaultReactVersion } from '../shared/constants.ts'
44
import { existsDir } from '../shared/fs.ts'
55
import log from '../shared/log.ts'
66
import util from '../shared/util.ts'
7-
import type { BrowserName, Config, ImportMap, PostCSSPlugin } from '../types.ts'
7+
import type { BrowserName, Config, RequiredConfig as TRequiredConfig, ImportMap, PostCSSPlugin } from '../types.ts'
88
import { getAlephPkgUri } from './helper.ts'
99

10-
export type RequiredConfig = Required<Config> & {
10+
export type RequiredConfig = TRequiredConfig & {
1111
srcDir: string
12-
i18n: Required<Config['i18n']>
13-
build: Required<Config['build']>
14-
server: Required<Config['server']>
1512
react: ReactOptions
1613
}
1714

@@ -33,6 +30,7 @@ export function defaultConfig(): Readonly<RequiredConfig> {
3330
plugins: [],
3431
css: {
3532
cache: false,
33+
modules: {},
3634
extract: {
3735
limit: 8 * 1024
3836
},
@@ -126,7 +124,7 @@ export async function loadConfig(specifier: string): Promise<Config> {
126124
config.css = {
127125
cache: Boolean(cache),
128126
extract: util.isPlainObject(extract) ? { limit: typeof extract.limit === 'number' ? extract.limit : 8 * 1024 } : Boolean(extract),
129-
modules: util.isPlainObject(modules) ? modules : undefined,
127+
modules: util.isPlainObject(modules) ? modules : {},
130128
postcss: isPostcssConfig(postcss) ? postcss : { plugins: ['autoprefixer'] }
131129
}
132130
}

types.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,18 @@
44
export interface Aleph {
55
readonly mode: 'development' | 'production'
66
readonly workingDir: string
7-
readonly config: Required<Config>
8-
readonly importMap: ImportMap
7+
readonly config: RequiredConfig
98
addModule(specifier: string, sourceCode?: string): Promise<void>
109
addDist(path: string, content: Uint8Array): Promise<void>
1110
fetchModule(specifier: string): Promise<{ content: Uint8Array, contentType: string | null }>
1211
onResolve(test: RegExp, resolve: (specifier: string) => ResolveResult): void
1312
onLoad(test: RegExp, load: (input: LoadInput) => LoadOutput | Promise<LoadOutput>): void
14-
onTransform(test: RegExp, transform: (input: TransformInput) => TransformOutput): void
15-
onTransform(specifier: string, transform: (input: TransformInput) => TransformOutput): void
13+
onTransform(test: 'hmr' | 'mainscript' | RegExp, transform: (input: TransformInput) => TransformOutput): void
1614
onSSR(callback: (path: string, html: string) => { html: string }): void
1715
}
1816

1917
/**
20-
* The config for aleph app.
18+
* The configuration for aleph app.
2119
*/
2220
export type Config = {
2321
/** `framework` specifies the framework (default is 'react'). */
@@ -26,18 +24,25 @@ export type Config = {
2624
basePath?: string
2725
/** `i18n` specifies the options for **Internationalization**. */
2826
i18n?: I18nOptions
27+
/** `css` specifies the css processing options. */
28+
css?: CSSOptions
2929
/** `build` specifies the options for **ES Build**. */
3030
build?: BuildOptions
3131
/** `ssr` specifies the options for **SSR**. */
3232
ssr?: boolean | GlobalSSROptions
33-
/** `server` specifies the options for **Server**. */
34-
server?: ServerOptions
35-
/** `css` specifies the css processing options. */
36-
css?: CSSOptions
3733
/** `plugins` specifies some plugins to extend Aleph runtime. */
3834
plugins?: Plugin[]
3935
/** `env` appends system env variables. */
4036
env?: Record<string, string>
37+
/** `server` specifies the options for **Server**. */
38+
server?: ServerOptions
39+
}
40+
41+
export type RequiredConfig = Required<Config> & {
42+
i18n: Required<I18nOptions>
43+
build: Required<BuildOptions>
44+
server: Required<ServerOptions>
45+
css: Required<CSSOptions>
4146
}
4247

4348
/**

0 commit comments

Comments
 (0)