Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

build!: switch target from ES5 to ES2021 #135

Merged
merged 2 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const sharedRules = {
'prefer-const': 'off',
'spaced-comment': 'off',
'no-new-func': 'off',
'no-implied-eval': 'off',
Expand Down
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@
},
"license": "MIT",
"devDependencies": {
"@microsoft/api-extractor": "^7.47.0",
"@rollup/plugin-alias": "^5.1.0",
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-replace": "^5.0.7",
"@microsoft/api-extractor": "^7.49.1",
"@rollup/plugin-alias": "^5.1.1",
"@rollup/plugin-node-resolve": "^16.0.0",
"@rollup/plugin-replace": "^6.0.2",
"@rollup/plugin-terser": "^0.4.4",
"@rollup/plugin-typescript": "^11.1.6",
"@rollup/plugin-typescript": "^12.1.2",
"@tybys/cross-zip": "^3.1.0",
"@tybys/ts-transform-pure-class": "^0.1.1",
"@tybys/tsapi": "^0.6.0",
"@types/fs-extra": "^11.0.4",
"@types/node": "^20.14.10",
"@types/node": "^22.10.7",
"@typescript-eslint/eslint-plugin": "^6.21.0",
"@typescript-eslint/parser": "^6.21.0",
"eslint": "^8.57.0",
Expand All @@ -49,8 +49,8 @@
"eslint-plugin-promise": "^6.4.0",
"fs-extra": "^11.2.0",
"glob": "^10.4.5",
"rollup": "^4.18.1",
"typescript": "~5.4.2"
"rollup": "^4.31.0",
"typescript": "~5.7.2"
},
"workspaces": [
"packages/ts-transform-macro",
Expand Down
17 changes: 9 additions & 8 deletions packages/core/script/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ const dist = path.join(__dirname, '../dist')
function build () {
compile(path.join(__dirname, '../tsconfig.json'), {
optionsToExtend: {
target: ts.ScriptTarget.ES2019,
target: ts.ScriptTarget.ES2021,
outDir: path.join(__dirname, '../lib'),
emitDeclarationOnly: true,
declaration: true,
declarationDir: path.join(__dirname, '../lib/typings')
Expand Down Expand Up @@ -88,7 +89,7 @@ function build () {

return Promise.all(([
{
input: createInput(ts.ScriptTarget.ES5, false),
input: createInput(ts.ScriptTarget.ES2021, false),
output: {
file: path.join(dist, 'emnapi-core.js'),
format: 'umd',
Expand All @@ -98,7 +99,7 @@ function build () {
}
},
{
input: createInput(ts.ScriptTarget.ES5, true),
input: createInput(ts.ScriptTarget.ES2021, true),
output: {
file: path.join(dist, 'emnapi-core.min.js'),
format: 'umd',
Expand All @@ -108,7 +109,7 @@ function build () {
}
},
{
input: createInput(ts.ScriptTarget.ES2019, false, ['tslib', '@emnapi/wasi-threads']),
input: createInput(ts.ScriptTarget.ES2021, false, ['tslib', '@emnapi/wasi-threads']),
output: {
file: path.join(dist, 'emnapi-core.cjs.js'),
format: 'cjs',
Expand All @@ -118,7 +119,7 @@ function build () {
}
},
{
input: createInput(ts.ScriptTarget.ES2019, true, ['tslib', '@emnapi/wasi-threads']),
input: createInput(ts.ScriptTarget.ES2021, true, ['tslib', '@emnapi/wasi-threads']),
output: {
file: path.join(dist, 'emnapi-core.cjs.min.js'),
format: 'cjs',
Expand All @@ -128,7 +129,7 @@ function build () {
}
},
{
input: createInput(ts.ScriptTarget.ES2019, false, ['tslib', '@emnapi/wasi-threads']),
input: createInput(ts.ScriptTarget.ES2021, false, ['tslib', '@emnapi/wasi-threads']),
output: {
file: path.join(dist, 'emnapi-core.mjs'),
format: 'esm',
Expand All @@ -138,7 +139,7 @@ function build () {
}
},
{
input: createInput(ts.ScriptTarget.ES2019, true, ['tslib', '@emnapi/wasi-threads']),
input: createInput(ts.ScriptTarget.ES2021, true, ['tslib', '@emnapi/wasi-threads']),
output: {
file: path.join(dist, 'emnapi-core.min.mjs'),
format: 'esm',
Expand All @@ -148,7 +149,7 @@ function build () {
}
},
{
input: createInput(ts.ScriptTarget.ES5, false, ['tslib', '@emnapi/wasi-threads']),
input: createInput(ts.ScriptTarget.ES2021, false, ['tslib', '@emnapi/wasi-threads']),
output: {
file: path.join(dist, 'emnapi-core.esm-bundler.js'),
format: 'esm',
Expand Down
14 changes: 3 additions & 11 deletions packages/core/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,17 @@
"extends": "../shared/tsconfig.base.json",
"compilerOptions": {
"allowJs": true,
"target": "ES5",
"target": "ES2021",
"module": "ESNext",
"moduleResolution": "Bundler",
"noEmitHelpers": true,
"importHelpers": true,
"outDir": "lib",
"outDir": "./dist",
"paths": {
"tslib" : ["../../node_modules/tslib/tslib.d.ts"],
"@emnapi/wasi-threads": ["../wasi-threads/lib/typings/index.d.ts"],
"@/*": ["./src/*"],
},
"lib": [
"ES5",
"ES2015",
"ES2020.BigInt",
"ES2021.WeakRef",
"ES2017.SharedMemory",
"DOM"
]
}
},
"include": [
"./src/**/*"
Expand Down
2 changes: 1 addition & 1 deletion packages/emnapi/src/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export function _emnapi_get_last_error_info (env: napi_env, error_code: Pointer<
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const engineErrorCode = lastError.engineErrorCode >>> 0
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const engineReserved = lastError.engineReserved
let engineReserved = lastError.engineReserved
from64('engineReserved')

makeSetValue('error_code', 0, 'errorCode', 'i32')
Expand Down
2 changes: 1 addition & 1 deletion packages/emnapi/src/function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export function napi_get_cb_info (env: napi_env, cbinfo: napi_callback_info, arg

if (argv) {
$CHECK_ARG!(envObject, argc)
const argcValue = makeGetValue('argc', 0, SIZE_TYPE)
let argcValue = makeGetValue('argc', 0, SIZE_TYPE)
from64('argcValue')

const len = cbinfoValue.args.length
Expand Down
15 changes: 1 addition & 14 deletions packages/emnapi/src/memory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,7 @@ import { _free, wasmMemory, _malloc } from 'emscripten:runtime'
import { emnapiCtx } from 'emnapi:shared'
import { to64 } from 'emscripten:parse-tools'

export type ViewConstuctor =
Int8ArrayConstructor |
Uint8ArrayConstructor |
Uint8ClampedArrayConstructor |
Int16ArrayConstructor |
Uint16ArrayConstructor |
Int32ArrayConstructor |
Uint32ArrayConstructor |
BigInt64ArrayConstructor |
BigUint64ArrayConstructor |
Float32ArrayConstructor |
Float64ArrayConstructor |
DataViewConstructor |
BufferCtor
export type ViewConstuctor = new (...args: any[]) => ArrayBufferView

export interface ArrayBufferPointer {
address: void_p
Expand Down
12 changes: 2 additions & 10 deletions packages/emnapi/tsconfig.base.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,13 @@
{
"extends": "../shared/tsconfig.base.json",
"compilerOptions": {
"target": "ES5",
"target": "ES2021",
"module": "ESNext",
"moduleResolution": "Bundler",
"importHelpers": false,
"noEmitHelpers": true,
"noUnusedLocals": false,
"noUnusedParameters": false,
"types": [],
"lib": [
"ES5",
"ES2015",
"ES2020.BigInt",
"ES2021.WeakRef",
"ES2017.SharedMemory",
"DOM"
]
"types": []
}
}
19 changes: 10 additions & 9 deletions packages/runtime/script/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ const { compile } = require('@tybys/tsapi')
function build () {
compile(path.join(__dirname, '../tsconfig.json'), {
optionsToExtend: {
target: require('typescript').ScriptTarget.ES2019,
target: require('typescript').ScriptTarget.ES2021,
outDir: path.join(__dirname, '../lib'),
emitDeclarationOnly: true,
declaration: true,
declarationMap: true,
Expand Down Expand Up @@ -80,7 +81,7 @@ function build () {

return Promise.all(([
{
input: createInput(ts.ScriptTarget.ES5, false),
input: createInput(ts.ScriptTarget.ES2021, false),
output: {
file: runtimeOut,
format: 'iife',
Expand All @@ -90,7 +91,7 @@ function build () {
}
},
{
input: createInput(ts.ScriptTarget.ES5, false),
input: createInput(ts.ScriptTarget.ES2021, false),
output: {
file: path.join(path.dirname(runtimeOut), 'emnapi.js'),
format: 'umd',
Expand All @@ -100,7 +101,7 @@ function build () {
}
},
{
input: createInput(ts.ScriptTarget.ES5, true),
input: createInput(ts.ScriptTarget.ES2021, true),
output: {
file: path.join(path.dirname(runtimeOut), 'emnapi.min.js'),
format: 'umd',
Expand All @@ -110,7 +111,7 @@ function build () {
}
},
{
input: createInput(ts.ScriptTarget.ES2019, false, ['tslib']),
input: createInput(ts.ScriptTarget.ES2021, false, ['tslib']),
output: {
file: path.join(path.dirname(runtimeOut), 'emnapi.cjs.js'),
format: 'cjs',
Expand All @@ -120,7 +121,7 @@ function build () {
}
},
{
input: createInput(ts.ScriptTarget.ES2019, true, ['tslib']),
input: createInput(ts.ScriptTarget.ES2021, true, ['tslib']),
output: {
file: path.join(path.dirname(runtimeOut), 'emnapi.cjs.min.js'),
format: 'cjs',
Expand All @@ -130,7 +131,7 @@ function build () {
}
},
{
input: createInput(ts.ScriptTarget.ES2019, false, ['tslib']),
input: createInput(ts.ScriptTarget.ES2021, false, ['tslib']),
output: {
file: path.join(path.dirname(runtimeOut), 'emnapi.mjs'),
format: 'esm',
Expand All @@ -140,7 +141,7 @@ function build () {
}
},
{
input: createInput(ts.ScriptTarget.ES2019, true, ['tslib']),
input: createInput(ts.ScriptTarget.ES2021, true, ['tslib']),
output: {
file: path.join(path.dirname(runtimeOut), 'emnapi.min.mjs'),
format: 'esm',
Expand All @@ -150,7 +151,7 @@ function build () {
}
},
{
input: createInput(ts.ScriptTarget.ES5, false, ['tslib']),
input: createInput(ts.ScriptTarget.ES2021, false, ['tslib']),
output: {
file: path.join(path.dirname(runtimeOut), 'emnapi.esm-bundler.js'),
format: 'esm',
Expand Down
6 changes: 4 additions & 2 deletions packages/runtime/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,13 @@ const _require = /*#__PURE__*/ (function () {
return nativeRequire
})()

const getBuiltinModule: (id: string) => any = _global.process?.getBuiltinModule ?? _require

export const _MessageChannel: typeof MessageChannel | undefined = typeof MessageChannel === 'function'
? MessageChannel
: /*#__PURE__*/ (function () {
try {
return _require!('worker_threads').MessageChannel
return getBuiltinModule('worker_threads').MessageChannel
} catch (_) {}

return undefined
Expand Down Expand Up @@ -143,7 +145,7 @@ export const _Buffer: BufferCtor | undefined = typeof Buffer === 'function'
? Buffer
: /*#__PURE__*/ (function () {
try {
return _require!('buffer').Buffer
return getBuiltinModule('buffer').Buffer
} catch (_) {}

return undefined
Expand Down
8 changes: 2 additions & 6 deletions packages/runtime/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
{
"extends": "../shared/tsconfig.base.json",
"compilerOptions": {
"target": "ES5",
"target": "ES2021",
"module": "ESNext",
"noEmitHelpers": true,
"importHelpers": true,
"moduleResolution": "Bundler",
"outDir": "lib",
"paths": {
"tslib" : ["../../node_modules/tslib/tslib.d.ts"]
},
"lib": [
"ES5",
"ES2015",
"ES2020.BigInt",
"ES2021.WeakRef",
"ES2021",
"DOM"
]
},
Expand Down
Loading
Loading