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

Commit d3c563d

Browse files
committed
Fix addModule method
1 parent 96a9c95 commit d3c563d

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

server/aleph.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -510,19 +510,21 @@ export class Aleph implements IAleph {
510510
/** add a module by given path and optional source code. */
511511
async addModule(specifier: string, sourceCode: string): Promise<Module> {
512512
let sourceType = getSourceType(specifier)
513+
let isStyle = false
513514
if (sourceType === SourceType.Unknown) {
514515
throw new Error("addModule: unknown souce type")
515516
}
516517
if (sourceType === SourceType.CSS) {
517518
const ret = await cssLoader({ specifier, data: (new TextEncoder).encode(sourceCode) }, this)
518519
sourceCode = ret.code
519520
sourceType = SourceType.JS
521+
isStyle = true
520522
}
521523
const module = await this.compile(specifier, {
522524
source: {
523525
code: sourceCode,
524526
type: sourceType,
525-
isStyle: false,
527+
isStyle,
526528
}
527529
})
528530
if (specifier.startsWith('pages/') || specifier.startsWith('api/')) {
@@ -1175,7 +1177,7 @@ export class Aleph implements IAleph {
11751177

11761178
const ms = new Measure()
11771179
const encoder = new TextEncoder()
1178-
const { code, deps, denoHooks, ssrPropsFn, ssgPathsFn, starExports, jsxStaticClassNames, map } = await transform(specifier, source.code, {
1180+
const { code, deps = [], denoHooks, ssrPropsFn, ssgPathsFn, starExports, jsxStaticClassNames, map } = await transform(specifier, source.code, {
11791181
...this.commonCompilerOptions,
11801182
sourceMap: this.isDev,
11811183
swcOptions: {
@@ -1200,7 +1202,7 @@ export class Aleph implements IAleph {
12001202
}
12011203

12021204
// revert external imports
1203-
if (deps && this.#resolverListeners.length > 0) {
1205+
if (deps.length > 0 && this.#resolverListeners.length > 0) {
12041206
deps.forEach(({ specifier }) => {
12051207
if (specifier !== module.specifier && util.isLikelyHttpURL(specifier)) {
12061208
let external = false
@@ -1225,7 +1227,7 @@ export class Aleph implements IAleph {
12251227
})
12261228
}
12271229

1228-
Object.assign(module, { ssrPropsFn, ssgPathsFn, jsxStaticClassNames })
1230+
Object.assign(module, { deps, ssrPropsFn, ssgPathsFn, jsxStaticClassNames })
12291231
if (util.isFilledArray(denoHooks)) {
12301232
module.denoHooks = denoHooks.map(id => util.trimPrefix(id, 'useDeno-'))
12311233
if (!this.#config.ssr) {
@@ -1252,7 +1254,7 @@ export class Aleph implements IAleph {
12521254
}
12531255

12541256
module.jsBuffer = encoder.encode(jsCode)
1255-
module.deps = deps?.filter(({ specifier }) => specifier !== module.specifier).map(({ specifier, resolved, isDynamic }) => {
1257+
module.deps = deps.filter(({ specifier }) => specifier !== module.specifier).map(({ specifier, resolved, isDynamic }) => {
12561258
const dep: DependencyDescriptor = { specifier }
12571259
if (isDynamic) {
12581260
dep.isDynamic = true
@@ -1265,7 +1267,7 @@ export class Aleph implements IAleph {
12651267
}
12661268
}
12671269
return dep
1268-
}) || []
1270+
})
12691271

12701272
ms.stop(`transpile '${specifier}'`)
12711273

0 commit comments

Comments
 (0)