Skip to content

Commit 3e48cd3

Browse files
committed
build!: switch target from ES5 to ES2021 (#135)
1 parent 906d8a6 commit 3e48cd3

File tree

14 files changed

+55
-95
lines changed

14 files changed

+55
-95
lines changed

.eslintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const sharedRules = {
2+
'prefer-const': 'off',
23
'spaced-comment': 'off',
34
'no-new-func': 'off',
45
'no-implied-eval': 'off',

package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,17 @@
2929
},
3030
"license": "MIT",
3131
"devDependencies": {
32-
"@microsoft/api-extractor": "^7.47.0",
33-
"@rollup/plugin-alias": "^5.1.0",
34-
"@rollup/plugin-node-resolve": "^15.2.3",
35-
"@rollup/plugin-replace": "^5.0.7",
32+
"@microsoft/api-extractor": "^7.49.1",
33+
"@rollup/plugin-alias": "^5.1.1",
34+
"@rollup/plugin-node-resolve": "^16.0.0",
35+
"@rollup/plugin-replace": "^6.0.2",
3636
"@rollup/plugin-terser": "^0.4.4",
37-
"@rollup/plugin-typescript": "^11.1.6",
37+
"@rollup/plugin-typescript": "^12.1.2",
3838
"@tybys/cross-zip": "^3.1.0",
3939
"@tybys/ts-transform-pure-class": "^0.1.1",
4040
"@tybys/tsapi": "^0.6.0",
4141
"@types/fs-extra": "^11.0.4",
42-
"@types/node": "^20.14.10",
42+
"@types/node": "^22.10.7",
4343
"@typescript-eslint/eslint-plugin": "^6.21.0",
4444
"@typescript-eslint/parser": "^6.21.0",
4545
"eslint": "^8.57.0",
@@ -49,8 +49,8 @@
4949
"eslint-plugin-promise": "^6.4.0",
5050
"fs-extra": "^11.2.0",
5151
"glob": "^10.4.5",
52-
"rollup": "^4.18.1",
53-
"typescript": "~5.4.2"
52+
"rollup": "^4.31.0",
53+
"typescript": "~5.7.2"
5454
},
5555
"workspaces": [
5656
"packages/ts-transform-macro",

packages/core/script/build.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ const dist = path.join(__dirname, '../dist')
1414
function build () {
1515
compile(path.join(__dirname, '../tsconfig.json'), {
1616
optionsToExtend: {
17-
target: ts.ScriptTarget.ES2019,
17+
target: ts.ScriptTarget.ES2021,
18+
outDir: path.join(__dirname, '../lib'),
1819
emitDeclarationOnly: true,
1920
declaration: true,
2021
declarationDir: path.join(__dirname, '../lib/typings')
@@ -88,7 +89,7 @@ function build () {
8889

8990
return Promise.all(([
9091
{
91-
input: createInput(ts.ScriptTarget.ES5, false),
92+
input: createInput(ts.ScriptTarget.ES2021, false),
9293
output: {
9394
file: path.join(dist, 'emnapi-core.js'),
9495
format: 'umd',
@@ -98,7 +99,7 @@ function build () {
9899
}
99100
},
100101
{
101-
input: createInput(ts.ScriptTarget.ES5, true),
102+
input: createInput(ts.ScriptTarget.ES2021, true),
102103
output: {
103104
file: path.join(dist, 'emnapi-core.min.js'),
104105
format: 'umd',
@@ -108,7 +109,7 @@ function build () {
108109
}
109110
},
110111
{
111-
input: createInput(ts.ScriptTarget.ES2019, false, ['tslib', '@emnapi/wasi-threads']),
112+
input: createInput(ts.ScriptTarget.ES2021, false, ['tslib', '@emnapi/wasi-threads']),
112113
output: {
113114
file: path.join(dist, 'emnapi-core.cjs.js'),
114115
format: 'cjs',
@@ -118,7 +119,7 @@ function build () {
118119
}
119120
},
120121
{
121-
input: createInput(ts.ScriptTarget.ES2019, true, ['tslib', '@emnapi/wasi-threads']),
122+
input: createInput(ts.ScriptTarget.ES2021, true, ['tslib', '@emnapi/wasi-threads']),
122123
output: {
123124
file: path.join(dist, 'emnapi-core.cjs.min.js'),
124125
format: 'cjs',
@@ -128,7 +129,7 @@ function build () {
128129
}
129130
},
130131
{
131-
input: createInput(ts.ScriptTarget.ES2019, false, ['tslib', '@emnapi/wasi-threads']),
132+
input: createInput(ts.ScriptTarget.ES2021, false, ['tslib', '@emnapi/wasi-threads']),
132133
output: {
133134
file: path.join(dist, 'emnapi-core.mjs'),
134135
format: 'esm',
@@ -138,7 +139,7 @@ function build () {
138139
}
139140
},
140141
{
141-
input: createInput(ts.ScriptTarget.ES2019, true, ['tslib', '@emnapi/wasi-threads']),
142+
input: createInput(ts.ScriptTarget.ES2021, true, ['tslib', '@emnapi/wasi-threads']),
142143
output: {
143144
file: path.join(dist, 'emnapi-core.min.mjs'),
144145
format: 'esm',
@@ -148,7 +149,7 @@ function build () {
148149
}
149150
},
150151
{
151-
input: createInput(ts.ScriptTarget.ES5, false, ['tslib', '@emnapi/wasi-threads']),
152+
input: createInput(ts.ScriptTarget.ES2021, false, ['tslib', '@emnapi/wasi-threads']),
152153
output: {
153154
file: path.join(dist, 'emnapi-core.esm-bundler.js'),
154155
format: 'esm',

packages/core/tsconfig.json

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,17 @@
22
"extends": "../shared/tsconfig.base.json",
33
"compilerOptions": {
44
"allowJs": true,
5-
"target": "ES5",
5+
"target": "ES2021",
66
"module": "ESNext",
77
"moduleResolution": "Bundler",
88
"noEmitHelpers": true,
99
"importHelpers": true,
10-
"outDir": "lib",
10+
"outDir": "./dist",
1111
"paths": {
1212
"tslib" : ["../../node_modules/tslib/tslib.d.ts"],
1313
"@emnapi/wasi-threads": ["../wasi-threads/lib/typings/index.d.ts"],
1414
"@/*": ["./src/*"],
15-
},
16-
"lib": [
17-
"ES5",
18-
"ES2015",
19-
"ES2020.BigInt",
20-
"ES2021.WeakRef",
21-
"ES2017.SharedMemory",
22-
"DOM"
23-
]
15+
}
2416
},
2517
"include": [
2618
"./src/**/*"

packages/emnapi/src/error.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export function _emnapi_get_last_error_info (env: napi_env, error_code: Pointer<
1717
// eslint-disable-next-line @typescript-eslint/no-unused-vars
1818
const engineErrorCode = lastError.engineErrorCode >>> 0
1919
// eslint-disable-next-line @typescript-eslint/no-unused-vars
20-
const engineReserved = lastError.engineReserved
20+
let engineReserved = lastError.engineReserved
2121
from64('engineReserved')
2222

2323
makeSetValue('error_code', 0, 'errorCode', 'i32')

packages/emnapi/src/function.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export function napi_get_cb_info (env: napi_env, cbinfo: napi_callback_info, arg
3838

3939
if (argv) {
4040
$CHECK_ARG!(envObject, argc)
41-
const argcValue = makeGetValue('argc', 0, SIZE_TYPE)
41+
let argcValue = makeGetValue('argc', 0, SIZE_TYPE)
4242
from64('argcValue')
4343

4444
const len = cbinfoValue.args.length

packages/emnapi/src/memory.ts

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,7 @@ import { _free, wasmMemory, _malloc } from 'emscripten:runtime'
22
import { emnapiCtx } from 'emnapi:shared'
33
import { to64 } from 'emscripten:parse-tools'
44

5-
export type ViewConstuctor =
6-
Int8ArrayConstructor |
7-
Uint8ArrayConstructor |
8-
Uint8ClampedArrayConstructor |
9-
Int16ArrayConstructor |
10-
Uint16ArrayConstructor |
11-
Int32ArrayConstructor |
12-
Uint32ArrayConstructor |
13-
BigInt64ArrayConstructor |
14-
BigUint64ArrayConstructor |
15-
Float32ArrayConstructor |
16-
Float64ArrayConstructor |
17-
DataViewConstructor |
18-
BufferCtor
5+
export type ViewConstuctor = new (...args: any[]) => ArrayBufferView
196

207
export interface ArrayBufferPointer {
218
address: void_p

packages/emnapi/tsconfig.base.json

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,13 @@
11
{
22
"extends": "../shared/tsconfig.base.json",
33
"compilerOptions": {
4-
"target": "ES5",
4+
"target": "ES2021",
55
"module": "ESNext",
66
"moduleResolution": "Bundler",
77
"importHelpers": false,
88
"noEmitHelpers": true,
99
"noUnusedLocals": false,
1010
"noUnusedParameters": false,
11-
"types": [],
12-
"lib": [
13-
"ES5",
14-
"ES2015",
15-
"ES2020.BigInt",
16-
"ES2021.WeakRef",
17-
"ES2017.SharedMemory",
18-
"DOM"
19-
]
11+
"types": []
2012
}
2113
}

packages/runtime/script/build.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ const { compile } = require('@tybys/tsapi')
1212
function build () {
1313
compile(path.join(__dirname, '../tsconfig.json'), {
1414
optionsToExtend: {
15-
target: require('typescript').ScriptTarget.ES2019,
15+
target: require('typescript').ScriptTarget.ES2021,
16+
outDir: path.join(__dirname, '../lib'),
1617
emitDeclarationOnly: true,
1718
declaration: true,
1819
declarationMap: true,
@@ -80,7 +81,7 @@ function build () {
8081

8182
return Promise.all(([
8283
{
83-
input: createInput(ts.ScriptTarget.ES5, false),
84+
input: createInput(ts.ScriptTarget.ES2021, false),
8485
output: {
8586
file: runtimeOut,
8687
format: 'iife',
@@ -90,7 +91,7 @@ function build () {
9091
}
9192
},
9293
{
93-
input: createInput(ts.ScriptTarget.ES5, false),
94+
input: createInput(ts.ScriptTarget.ES2021, false),
9495
output: {
9596
file: path.join(path.dirname(runtimeOut), 'emnapi.js'),
9697
format: 'umd',
@@ -100,7 +101,7 @@ function build () {
100101
}
101102
},
102103
{
103-
input: createInput(ts.ScriptTarget.ES5, true),
104+
input: createInput(ts.ScriptTarget.ES2021, true),
104105
output: {
105106
file: path.join(path.dirname(runtimeOut), 'emnapi.min.js'),
106107
format: 'umd',
@@ -110,7 +111,7 @@ function build () {
110111
}
111112
},
112113
{
113-
input: createInput(ts.ScriptTarget.ES2019, false, ['tslib']),
114+
input: createInput(ts.ScriptTarget.ES2021, false, ['tslib']),
114115
output: {
115116
file: path.join(path.dirname(runtimeOut), 'emnapi.cjs.js'),
116117
format: 'cjs',
@@ -120,7 +121,7 @@ function build () {
120121
}
121122
},
122123
{
123-
input: createInput(ts.ScriptTarget.ES2019, true, ['tslib']),
124+
input: createInput(ts.ScriptTarget.ES2021, true, ['tslib']),
124125
output: {
125126
file: path.join(path.dirname(runtimeOut), 'emnapi.cjs.min.js'),
126127
format: 'cjs',
@@ -130,7 +131,7 @@ function build () {
130131
}
131132
},
132133
{
133-
input: createInput(ts.ScriptTarget.ES2019, false, ['tslib']),
134+
input: createInput(ts.ScriptTarget.ES2021, false, ['tslib']),
134135
output: {
135136
file: path.join(path.dirname(runtimeOut), 'emnapi.mjs'),
136137
format: 'esm',
@@ -140,7 +141,7 @@ function build () {
140141
}
141142
},
142143
{
143-
input: createInput(ts.ScriptTarget.ES2019, true, ['tslib']),
144+
input: createInput(ts.ScriptTarget.ES2021, true, ['tslib']),
144145
output: {
145146
file: path.join(path.dirname(runtimeOut), 'emnapi.min.mjs'),
146147
format: 'esm',
@@ -150,7 +151,7 @@ function build () {
150151
}
151152
},
152153
{
153-
input: createInput(ts.ScriptTarget.ES5, false, ['tslib']),
154+
input: createInput(ts.ScriptTarget.ES2021, false, ['tslib']),
154155
output: {
155156
file: path.join(path.dirname(runtimeOut), 'emnapi.esm-bundler.js'),
156157
format: 'esm',

packages/runtime/src/util.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,13 @@ const _require = /*#__PURE__*/ (function () {
110110
return nativeRequire
111111
})()
112112

113+
const getBuiltinModule: (id: string) => any = _global.process?.getBuiltinModule ?? _require
114+
113115
export const _MessageChannel: typeof MessageChannel | undefined = typeof MessageChannel === 'function'
114116
? MessageChannel
115117
: /*#__PURE__*/ (function () {
116118
try {
117-
return _require!('worker_threads').MessageChannel
119+
return getBuiltinModule('worker_threads').MessageChannel
118120
} catch (_) {}
119121

120122
return undefined
@@ -143,7 +145,7 @@ export const _Buffer: BufferCtor | undefined = typeof Buffer === 'function'
143145
? Buffer
144146
: /*#__PURE__*/ (function () {
145147
try {
146-
return _require!('buffer').Buffer
148+
return getBuiltinModule('buffer').Buffer
147149
} catch (_) {}
148150

149151
return undefined

0 commit comments

Comments
 (0)