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

Commit e62100a

Browse files
committed
Rename fetchModule to fetchModuleSource
1 parent fd8cee7 commit e62100a

File tree

5 files changed

+37
-37
lines changed

5 files changed

+37
-37
lines changed

bundler/mod.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ export class Bundler {
134134
return jsFile
135135
}
136136

137-
const source = await this.#aleph.loadModuleSource(mod.specifier)
137+
const source = await this.#aleph.resolveModuleSource(mod.specifier)
138138
if (source === null) {
139139
this.#compiled.delete(mod.specifier)
140140
throw new Error(`Unsupported module '${mod.specifier}'`)

plugins/css.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export const cssLoader = async ({ specifier, data }: LoadInput, aleph: Aleph): P
7676
} else if (util.isFilledString(data)) {
7777
sourceCode = data
7878
} else {
79-
const { content } = await aleph.fetchModule(specifier)
79+
const { content } = await aleph.fetchModuleSource(specifier)
8080
sourceCode = (new TextDecoder).decode(content)
8181
}
8282

plugins/markdown.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export const markdownResovler = (specifier: string): ResolveResult => {
1919

2020
export const markdownLoader = async ({ specifier }: LoadInput, aleph: Aleph): Promise<LoadOutput> => {
2121
const { framework } = aleph.config
22-
const { content } = await aleph.fetchModule(specifier)
22+
const { content } = await aleph.fetchModuleSource(specifier)
2323
const { __content, ...meta } = safeLoadFront((new TextDecoder).decode(content))
2424
const html = marked.parse(__content)
2525
const props = {

server/aleph.ts

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,7 @@ export class Aleph implements IAleph {
733733

734734
/** parse the export names of the module. */
735735
async parseModuleExportNames(specifier: string): Promise<string[]> {
736-
const { content, contentType } = await this.fetchModule(specifier)
736+
const { content, contentType } = await this.fetchModuleSource(specifier)
737737
const sourceType = getSourceType(specifier, contentType || undefined)
738738
if (sourceType === SourceType.Unknown || sourceType === SourceType.CSS) {
739739
return []
@@ -873,34 +873,6 @@ export class Aleph implements IAleph {
873873
return [routePath, specifier, isIndex]
874874
}
875875

876-
/** fetch module content by the specifier. */
877-
async fetchModule(specifier: string): Promise<{ content: Uint8Array, contentType: string | null }> {
878-
if (!util.isLikelyHttpURL(specifier)) {
879-
const filepath = join(this.workingDir, this.config.srcDir, util.trimPrefix(specifier, 'file://'))
880-
if (await existsFile(filepath)) {
881-
const content = await Deno.readFile(filepath)
882-
return { content, contentType: getContentType(filepath) }
883-
} else {
884-
return Promise.reject(new Error(`No such file: ${util.trimPrefix(filepath, this.workingDir + '/')}`))
885-
}
886-
}
887-
888-
// append `dev` query for development mode
889-
if (this.isDev && specifier.startsWith('https://esm.sh/')) {
890-
const u = new URL(specifier)
891-
if (!u.searchParams.has('dev')) {
892-
u.searchParams.set('dev', '')
893-
u.search = u.search.replace('dev=', 'dev')
894-
specifier = u.toString()
895-
}
896-
}
897-
898-
return await cache(specifier, {
899-
forceRefresh: this.#reloading,
900-
retryTimes: 10
901-
})
902-
}
903-
904876
async importModule<T = any>({ jsFile, hash, sourceHash }: Module): Promise<T> {
905877
return await import(`file://${join(this.buildDir, jsFile)}#${(hash || sourceHash).slice(0, 6)}`)
906878
}
@@ -952,7 +924,35 @@ export class Aleph implements IAleph {
952924
].join('\n'))
953925
}
954926

955-
async loadModuleSource(specifier: string, data?: any): Promise<ModuleSource> {
927+
/** fetch module source by the specifier. */
928+
async fetchModuleSource(specifier: string): Promise<{ content: Uint8Array, contentType: string | null }> {
929+
if (!util.isLikelyHttpURL(specifier)) {
930+
const filepath = join(this.workingDir, this.config.srcDir, util.trimPrefix(specifier, 'file://'))
931+
if (await existsFile(filepath)) {
932+
const content = await Deno.readFile(filepath)
933+
return { content, contentType: getContentType(filepath) }
934+
} else {
935+
return Promise.reject(new Error(`No such file: ${util.trimPrefix(filepath, this.workingDir + '/')}`))
936+
}
937+
}
938+
939+
// append `dev` query for development mode
940+
if (this.isDev && specifier.startsWith('https://esm.sh/')) {
941+
const u = new URL(specifier)
942+
if (!u.searchParams.has('dev')) {
943+
u.searchParams.set('dev', '')
944+
u.search = u.search.replace('dev=', 'dev')
945+
specifier = u.toString()
946+
}
947+
}
948+
949+
return await cache(specifier, {
950+
forceRefresh: this.#reloading,
951+
retryTimes: 10
952+
})
953+
}
954+
955+
async resolveModuleSource(specifier: string, data?: any): Promise<ModuleSource> {
956956
let sourceCode: string = ''
957957
let sourceType: SourceType = SourceType.Unknown
958958
let sourceMap: string | null = null
@@ -981,7 +981,7 @@ export class Aleph implements IAleph {
981981
sourceCode = code
982982
sourceMap = map || null
983983
} else {
984-
const source = await this.fetchModule(specifier)
984+
const source = await this.fetchModuleSource(specifier)
985985
sourceType = getSourceType(specifier, source.contentType || undefined)
986986
if (sourceType !== SourceType.Unknown) {
987987
sourceCode = (new TextDecoder).decode(source.content)
@@ -1104,7 +1104,7 @@ export class Aleph implements IAleph {
11041104
)
11051105
if (shouldLoad) {
11061106
try {
1107-
const src = customSource || await this.loadModuleSource(specifier, data)
1107+
const src = customSource || await this.resolveModuleSource(specifier, data)
11081108
const sourceHash = computeHash(src.code)
11091109
if (mod.sourceHash === '' || mod.sourceHash !== sourceHash) {
11101110
mod.sourceHash = sourceHash

types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ export interface Aleph {
55
readonly mode: 'development' | 'production'
66
readonly workingDir: string
77
readonly config: RequiredConfig
8-
addModule(specifier: string, sourceCode?: string): Promise<void>
98
addDist(path: string, content: Uint8Array): Promise<void>
10-
fetchModule(specifier: string): Promise<{ content: Uint8Array, contentType: string | null }>
9+
addModule(specifier: string, sourceCode?: string): Promise<void>
10+
fetchModuleSource(specifier: string): Promise<{ content: Uint8Array, contentType: string | null }>
1111
onResolve(test: RegExp, resolve: (specifier: string) => ResolveResult): void
1212
onLoad(test: RegExp, load: (input: LoadInput) => LoadOutput | Promise<LoadOutput>): void
1313
onTransform(test: 'hmr' | 'mainscript' | RegExp, transform: (input: TransformInput) => TransformOutput): void

0 commit comments

Comments
 (0)