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

Commit 54099fb

Browse files
committed
refactor(server): add createPolyfillBundle method
1 parent c887365 commit 54099fb

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

server/app.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1290,7 +1290,7 @@ export class Application {
12901290
}
12911291

12921292
// download dep when deno cache failed
1293-
log.info('Redownload', url)
1293+
log.info('Force download from', url)
12941294
const buffer = await fetch(u.toString()).then(resp => resp.arrayBuffer())
12951295
return await Deno.readAll(new Deno.Buffer(buffer))
12961296
}
@@ -1358,12 +1358,20 @@ export class Application {
13581358
}
13591359

13601360
log.info('- Bundling')
1361+
await this.createPolyfillBundle()
13611362
await this.createChunkBundle('deps', remoteDeps)
13621363
if (localSharedDeps.length > 0) {
13631364
await this.createChunkBundle('shared', localSharedDeps)
13641365
}
13651366

13661367
// create and copy polyfill
1368+
// bundle and copy page moudles
1369+
await Promise.all(pageModules.map(async mod => this.createPageBundle(mod, localSharedDeps)))
1370+
}
1371+
1372+
/** create polyfill bundle. */
1373+
private async createPolyfillBundle() {
1374+
const alephPkgUrl = getAlephPkgUrl()
13671375
const { buildTarget } = this.config
13681376
const hash = computeHash(AlephRuntimeCode + buildTarget + buildChecksum + Deno.version.deno)
13691377
const polyfillFile = path.join(this.buildDir, `polyfill.bundle.${util.shortHash(hash)}.js`)
@@ -1374,14 +1382,11 @@ export class Application {
13741382
await this.runDenoBundle(rawPolyfillFile, polyfillFile, AlephRuntimeCode, true)
13751383
}
13761384
log.info(` {} polyfill (${buildTarget.toUpperCase()}) ${colors.dim('• ' + util.formatBytes(Deno.statSync(polyfillFile).size))}`)
1377-
1378-
// bundle and copy page moudles
1379-
await Promise.all(pageModules.map(async mod => this.createPageBundle(mod, localSharedDeps)))
13801385
}
13811386

13821387
/** create chunk bundle. */
1383-
private async createChunkBundle(name: string, list: string[]) {
1384-
const bundlingCode = list.map((url, i) => {
1388+
private async createChunkBundle(name: string, deps: string[]) {
1389+
const bundlingCode = deps.map((url, i) => {
13851390
const mod = this.#modules.get(url)
13861391
if (mod) {
13871392
const importUrl = util.isLikelyHttpURL(mod.url) ? mod.jsFile : mod.bundlingFile
@@ -1394,16 +1399,13 @@ export class Application {
13941399
const hash = computeHash(bundlingCode + buildChecksum + Deno.version.deno)
13951400
const bundleEntryFile = path.join(this.buildDir, `${name}.bundle.entry.js`)
13961401
const bundleFile = path.join(this.buildDir, `${name}.bundle.${util.shortHash(hash)}.js`)
1397-
1402+
const mod = this.newModule(`/${name}.js`)
1403+
mod.hash = mod.sourceHash = hash
13981404
if (!existsFileSync(bundleFile)) {
13991405
await Deno.writeTextFile(bundleEntryFile, bundlingCode)
14001406
await this.runDenoBundle(bundleEntryFile, bundleFile)
14011407
lazyRemove(bundleEntryFile)
14021408
}
1403-
1404-
const mod = this.newModule(`/${name}.js`)
1405-
mod.hash = mod.sourceHash = hash
1406-
14071409
log.info(` {} ${name} ${colors.dim('• ' + util.formatBytes(Deno.statSync(bundleFile).size))}`)
14081410
}
14091411

@@ -1484,7 +1486,6 @@ export class Application {
14841486
pageModules.push(mod)
14851487
}
14861488
}))
1487-
14881489
await Promise.all([
14891490
(async () => {
14901491
const mainJS = this.getMainJS(true)

0 commit comments

Comments
 (0)