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

Commit d2b8261

Browse files
committed
refactor: remove hash field of DependencyDescriptor
1 parent 139fbff commit d2b8261

File tree

1 file changed

+39
-51
lines changed

1 file changed

+39
-51
lines changed

server/app.ts

Lines changed: 39 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ export type Module = {
2626
/** The dependency descriptor. */
2727
export type DependencyDescriptor = {
2828
url: string
29-
hash: string
3029
isDynamic?: boolean
3130
}
3231

@@ -593,12 +592,12 @@ export class Application implements ServerApplication {
593592
once?: boolean,
594593
} = {}
595594
): Promise<Module> {
596-
const { sourceCode, forceCompile, once } = options
597595
const isRemote = util.isLikelyHttpURL(url)
598596
const localUrl = toLocalUrl(url)
599597
const name = trimModuleExt(path.basename(localUrl))
600598
const saveDir = path.join(this.buildDir, path.dirname(localUrl))
601599
const metaFile = path.join(saveDir, `${name}.meta.json`)
600+
const { sourceCode, forceCompile, once } = options
602601

603602
let mod: Module
604603
if (this.#modules.has(url)) {
@@ -757,17 +756,12 @@ export class Application implements ServerApplication {
757756
}
758757

759758
mod.deps = deps.map(({ specifier, isDynamic }) => {
760-
const dep: DependencyDescriptor = { url: specifier, hash: '' }
759+
const dep: DependencyDescriptor = { url: specifier }
761760
if (isDynamic) {
762761
dep.isDynamic = true
763762
}
764-
if (dep.url.startsWith('#useDeno-')) {
765-
dep.hash = util.trimPrefix(dep.url, '#useDeno-')
766-
if (!this.config.ssr) {
767-
log.warn(`use 'useDeno' hook in SPA mode: ${url}`)
768-
}
769-
} else if (dep.url.startsWith('#inline-style-')) {
770-
dep.hash = util.trimPrefix(dep.url, '#inline-style-')
763+
if (dep.url.startsWith('#useDeno-') && !this.config.ssr) {
764+
log.warn(`use 'useDeno' hook in SPA mode: ${url}`)
771765
}
772766
return dep
773767
})
@@ -778,29 +772,26 @@ export class Application implements ServerApplication {
778772
// compile deps
779773
for (const dep of mod.deps.filter(({ url }) => !url.startsWith('#'))) {
780774
const depMod = await this.compile(dep.url, { once })
781-
if (dep.hash === '' || dep.hash !== depMod.hash) {
782-
dep.hash = depMod.hash
783-
if (!util.isLikelyHttpURL(dep.url)) {
784-
const relativePathname = getRelativePath(
785-
path.dirname(toLocalUrl(url)),
786-
trimModuleExt(toLocalUrl(dep.url))
787-
)
788-
if (jsContent === '') {
789-
jsContent = await Deno.readTextFile(mod.jsFile)
790-
}
791-
const newContent = jsContent.replace(reHashResolve, (s, key, spaces, ql, importPath, qr) => {
792-
const importPathname = importPath.replace(reHashJs, '')
793-
if (importPathname == dep.url || importPathname === relativePathname) {
794-
return `${key}${spaces}${ql}${importPathname}.${dep.hash.slice(0, hashShortLength)}.js${qr}`
795-
}
796-
return s
775+
if (!util.isLikelyHttpURL(dep.url)) {
776+
const relativePathname = getRelativePath(
777+
path.dirname(toLocalUrl(url)),
778+
trimModuleExt(toLocalUrl(dep.url))
779+
)
780+
if (jsContent === '') {
781+
jsContent = await Deno.readTextFile(mod.jsFile)
782+
}
783+
const newContent = jsContent.replace(reHashResolve, (s, key, spaces, ql, importPath, qr) => {
784+
const importPathname = importPath.replace(reHashJs, '')
785+
if (importPathname == dep.url || importPathname === relativePathname) {
786+
return `${key}${spaces}${ql}${importPathname}.${depMod.hash.slice(0, hashShortLength)}.js${qr}`
797787
}
798-
)
799-
if (newContent !== jsContent) {
800-
jsContent = newContent
801-
if (!fsync) {
802-
fsync = true
803-
}
788+
return s
789+
}
790+
)
791+
if (newContent !== jsContent) {
792+
jsContent = newContent
793+
if (!fsync) {
794+
fsync = true
804795
}
805796
}
806797
}
@@ -1033,25 +1024,22 @@ export class Application implements ServerApplication {
10331024
for (const mod of this.#modules.values()) {
10341025
for (const dep of mod.deps) {
10351026
if (dep.url === url) {
1036-
if (dep.hash !== "" && dep.hash !== hash) {
1037-
dep.hash = hash
1038-
const relativePathname = getRelativePath(
1039-
path.dirname(toLocalUrl(mod.url)),
1040-
trimModuleExt(toLocalUrl(dep.url))
1041-
)
1042-
const jsContent = (await Deno.readTextFile(mod.jsFile))
1043-
.replace(reHashResolve, (s, key, spaces, ql, importPath, qr) => {
1044-
const importPathname = importPath.replace(reHashJs, '')
1045-
if (importPathname === dep.url || importPathname === relativePathname) {
1046-
return `${key}${spaces}${ql}${importPathname}.${dep.hash.slice(0, hashShortLength)}.js${qr}`
1047-
}
1048-
return s
1049-
})
1050-
await ensureTextFile(mod.jsFile, jsContent)
1051-
callback(mod)
1052-
log.debug('compilation side-effect:', mod.url, colors.dim('<-'), url)
1053-
this.checkCompilationSideEffect(mod.url, callback)
1054-
}
1027+
const relativePathname = getRelativePath(
1028+
path.dirname(toLocalUrl(mod.url)),
1029+
trimModuleExt(toLocalUrl(dep.url))
1030+
)
1031+
const jsContent = (await Deno.readTextFile(mod.jsFile))
1032+
.replace(reHashResolve, (s, key, spaces, ql, importPath, qr) => {
1033+
const importPathname = importPath.replace(reHashJs, '')
1034+
if (importPathname === dep.url || importPathname === relativePathname) {
1035+
return `${key}${spaces}${ql}${importPathname}.${hash.slice(0, hashShortLength)}.js${qr}`
1036+
}
1037+
return s
1038+
})
1039+
await ensureTextFile(mod.jsFile, jsContent)
1040+
callback(mod)
1041+
log.debug('compilation side-effect:', mod.url, colors.dim('<-'), url)
1042+
this.checkCompilationSideEffect(mod.url, callback)
10551043
break
10561044
}
10571045
}

0 commit comments

Comments
 (0)