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

Commit c917da5

Browse files
committed
Add es2021 polyfill
1 parent 67ff0c6 commit c917da5

File tree

7 files changed

+22
-14
lines changed

7 files changed

+22
-14
lines changed

bundler/mod.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ export class Bundler {
7676
}
7777
})
7878

79-
await this.bundlePolyfillChunck()
79+
if (this.#app.config.buildTarget !== 'esnext') {
80+
await this.bundlePolyfillChunck()
81+
}
8082
await this.bundleChunk(
8183
'deps',
8284
Array.from(remoteEntries),
@@ -203,11 +205,12 @@ export class Bundler {
203205
private async bundlePolyfillChunck() {
204206
const alephPkgUri = getAlephPkgUri()
205207
const { buildTarget } = this.#app.config
206-
const hash = computeHash(buildTarget + Deno.version.deno + VERSION)
208+
const polyfillTarget = 'es' + (parseInt(buildTarget.slice(2)) + 1)
209+
const hash = computeHash(polyfillTarget + '/[email protected]/' + VERSION)
207210
const bundleFilename = `polyfill.bundle.${hash.slice(0, hashShort)}.js`
208211
const bundleFilePath = join(this.#app.buildDir, bundleFilename)
209212
if (!existsFileSync(bundleFilePath)) {
210-
const rawPolyfillFile = `${alephPkgUri}/bundler/polyfills/${buildTarget}/mod.ts`
213+
const rawPolyfillFile = `${alephPkgUri}/bundler/polyfills/${polyfillTarget}/mod.ts`
211214
await this.build(rawPolyfillFile, bundleFilePath)
212215
}
213216
this.#bundledFiles.set('polyfill', bundleFilename)

bundler/polyfills/es2015/mod.ts

Lines changed: 0 additions & 5 deletions
This file was deleted.

bundler/polyfills/es2019/mod.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
import flatShim from 'https://esm.sh/array.prototype.flat/shim'
2-
import flatmapShim from 'https://esm.sh/array.prototype.flatmap/shim'
2+
import flatMapShim from 'https://esm.sh/array.prototype.flatmap/shim'
33
import descriptionShim from 'https://esm.sh/symbol.prototype.description/shim'
4-
import fromentriesShim from 'https://esm.sh/object.fromentries/shim'
4+
import fromEntriesShim from 'https://esm.sh/object.fromentries/shim'
5+
import trimStartShim from 'https://esm.sh/string.prototype.trimstart/shim'
6+
import trimEndShim from 'https://esm.sh/string.prototype.trimend/shim'
7+
58
import '../es2020/mod.ts'
69

710
flatShim()
8-
flatmapShim()
11+
flatMapShim()
912
descriptionShim()
10-
fromentriesShim()
13+
fromEntriesShim()
14+
trimStartShim()
15+
trimEndShim()

bundler/polyfills/es2020/mod.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import matchallShim from 'https://esm.sh/string.prototype.matchall/shim'
22
import globalthisShim from 'https://esm.sh/globalthis/shim'
33
import allsettledShim from 'https://esm.sh/promise.allsettled/shim'
4+
import '../es2021/mod.ts'
45

56
matchallShim()
67
globalthisShim()

bundler/polyfills/es2021/mod.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import replaceAllShim from 'https://esm.sh/string.prototype.replaceall/shim'
2+
3+
replaceAllShim()

server/config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,14 +222,15 @@ function isFramework(v: any): v is 'react' {
222222
}
223223
}
224224

225-
function isBuildTarget(v: any): v is 'es2015' | 'es2016' | 'es2017' | 'es2018' | 'es2019' | 'es2020' {
225+
function isBuildTarget(v: any): v is 'es2015' | 'es2016' | 'es2017' | 'es2018' | 'es2019' | 'es2020' | 'esnext' {
226226
switch (v) {
227227
case 'es2015':
228228
case 'es2016':
229229
case 'es2017':
230230
case 'es2018':
231231
case 'es2019':
232232
case 'es2020':
233+
case 'esnext':
233234
return true
234235
default:
235236
return false

types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export type ServerPlugin = {
5151

5252
export type PostCSSPlugin = string | [string, any] | Plugin | PluginCreator<any>
5353

54-
export type BuildTarget = 'es2015' | 'es2016' | 'es2017' | 'es2018' | 'es2019' | 'es2020'
54+
export type BuildTarget = 'es2015' | 'es2016' | 'es2017' | 'es2018' | 'es2019' | 'es2020' | 'esnext'
5555

5656
export type BrowserTarget = {
5757
name: 'chrome' | 'edge' | 'firefox' | 'ios' | 'Safari'

0 commit comments

Comments
 (0)