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

Commit 0622b17

Browse files
committed
refactor: update config type
1 parent a61ff46 commit 0622b17

File tree

3 files changed

+23
-15
lines changed

3 files changed

+23
-15
lines changed

server/app.ts

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,15 @@ import {
1414
buildChecksum,
1515
ImportMap,
1616
parseExportNames,
17+
ReactResolve,
1718
SourceType,
1819
transform,
1920
TransformOptions
2021
} from '../compiler/mod.ts'
2122
import { EventEmitter } from '../framework/core/events.ts'
2223
import { moduleExts, toPagePath, trimModuleExt } from '../framework/core/module.ts'
2324
import { RouteModule, Routing } from '../framework/core/routing.ts'
24-
import {
25-
defaultReactEsmShBuildVersion, defaultReactVersion,
26-
minDenoVersion
27-
} from '../shared/constants.ts'
25+
import { minDenoVersion } from '../shared/constants.ts'
2826
import {
2927
ensureTextFile,
3028
existsDirSync,
@@ -74,7 +72,7 @@ type TransformFn = (url: string, code: string) => string
7472
export class Application implements ServerApplication {
7573
readonly workingDir: string
7674
readonly mode: 'development' | 'production'
77-
readonly config: Required<Config>
75+
readonly config: Required<Config & { react: ReactResolve }>
7876
readonly importMap: ImportMap
7977
readonly ready: Promise<void>
8078

@@ -145,10 +143,18 @@ export class Application implements ServerApplication {
145143

146144
const alephPkgUri = getAlephPkgUri()
147145
const buildManifestFile = join(this.buildDir, 'build.manifest.json')
148-
const configChecksum = computeHash(JSON.stringify({
149-
...this.sharedCompileOptions,
146+
const plugins = computeHash(JSON.stringify({
150147
plugins: this.config.plugins.filter(isLoaderPlugin).map(({ name }) => name),
151-
postcssPlugins: this.config.postcss.plugins.map(p => p.toString())
148+
postcssPlugins: this.config.postcss.plugins.map(p => {
149+
if (util.isString(p)) {
150+
return p
151+
} else if (util.isArray(p)) {
152+
return p[0] + JSON.stringify(p[1])
153+
} else {
154+
p.toString()
155+
}
156+
}),
157+
react: this.config.react,
152158
}, (key: string, value: any) => {
153159
if (key === 'inlineStylePreprocess') {
154160
return void 0
@@ -163,7 +169,7 @@ export class Application implements ServerApplication {
163169
typeof v !== 'object' ||
164170
v === null ||
165171
v.compiler !== buildChecksum ||
166-
v.configChecksum !== configChecksum
172+
v.plugins !== plugins
167173
)
168174
} catch (e) { }
169175
}
@@ -182,7 +188,7 @@ export class Application implements ServerApplication {
182188
aleph: VERSION,
183189
deno: Deno.version.deno,
184190
compiler: buildChecksum,
185-
configChecksum,
191+
plugins,
186192
}, undefined, 2))
187193
}
188194

@@ -696,8 +702,7 @@ export class Application implements ServerApplication {
696702
return {
697703
importMap: this.importMap,
698704
alephPkgUri: getAlephPkgUri(),
699-
reactVersion: defaultReactVersion,
700-
fixedReactEsmShBuildVersion: defaultReactEsmShBuildVersion,
705+
react: this.config.react,
701706
isDev: this.isDev,
702707
inlineStylePreprocess: async (key: string, type: string, tpl: string) => {
703708
if (type !== 'css') {

server/config.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { join } from 'https://deno.land/[email protected]/path/mod.ts'
2-
import type { ImportMap } from '../compiler/mod.ts'
2+
import type { ImportMap, ReactResolve } from '../compiler/mod.ts'
33
import { defaultReactVersion } from '../shared/constants.ts'
44
import { existsFileSync, existsDirSync } from '../shared/fs.ts'
55
import log from '../shared/log.ts'
66
import util from '../shared/util.ts'
77
import type { Config, PostCSSPlugin } from '../types.ts'
88
import { getAlephPkgUri, reLocaleID } from './helper.ts'
99

10-
export const defaultConfig: Readonly<Required<Config>> = {
10+
export const defaultConfig: Readonly<Required<Config> & { react: ReactResolve }> = {
1111
framework: 'react',
1212
buildTarget: 'es2015',
1313
baseUrl: '/',
@@ -21,6 +21,10 @@ export const defaultConfig: Readonly<Required<Config>> = {
2121
postcss: { plugins: ['autoprefixer'] },
2222
headers: {},
2323
env: {},
24+
react: {
25+
version: defaultReactVersion,
26+
esmShBuildVersion: 34,
27+
}
2428
}
2529

2630
/** load config from `aleph.config.(ts|js|json)` */

shared/constants.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
export const minDenoVersion = '1.8.0'
22
export const defaultReactVersion = '17.0.2'
3-
export const defaultReactEsmShBuildVersion = 33

0 commit comments

Comments
 (0)