Skip to content

Commit 912b6c9

Browse files
committed
update to es2022
1 parent 8b83ff2 commit 912b6c9

File tree

7 files changed

+46
-35
lines changed

7 files changed

+46
-35
lines changed

build.ts

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,38 +9,36 @@ Everything below is theres
99
Copyright (c) 2022 Taishi Naritomi
1010
*/
1111

12-
import { exec } from 'child_process'
13-
import fs from 'fs'
14-
import path from 'path'
15-
import { build } from 'esbuild'
16-
import type { Plugin, PluginBuild, BuildOptions } from 'esbuild'
17-
import glob from 'glob'
12+
import { exec } from "child_process"
13+
import fs from "fs"
14+
import path from "path"
15+
import { build } from "esbuild"
16+
import type { Plugin, PluginBuild, BuildOptions } from "esbuild"
17+
import glob from "glob"
1818

19-
20-
21-
const entryPoints = glob.sync('./src/**/*.ts', {
22-
ignore: ['./src/**/*.test.ts', './src/mod.ts', './src/middleware.ts', './src/deno/**/*.ts'],
19+
const entryPoints = glob.sync("./src/**/*.ts", {
20+
ignore: ["./src/**/*.test.ts", "./src/mod.ts", "./src/middleware.ts", "./src/deno/**/*.ts"]
2321
})
2422

2523
/*
2624
This plugin is inspired by the following.
2725
https://github.com/evanw/esbuild/issues/622#issuecomment-769462611
2826
*/
29-
const addExtension = (extension: string = '.js', fileExtension: string = '.ts'): Plugin => ({
30-
name: 'add-extension',
27+
const addExtension = (extension: string = ".js", fileExtension: string = ".ts"): Plugin => ({
28+
name: "add-extension",
3129
setup(build: PluginBuild) {
3230
build.onResolve({ filter: /.*/ }, (args) => {
3331
if (args.importer) {
3432
const p = path.join(args.resolveDir, args.path)
3533
let tsPath = `${p}${fileExtension}`
3634

37-
let importPath = ''
35+
let importPath = ""
3836
if (fs.existsSync(tsPath)) {
3937
importPath = args.path + extension
4038
} else {
4139
tsPath = path.join(args.resolveDir, args.path, `index${fileExtension}`)
4240
if (fs.existsSync(tsPath)) {
43-
if (args.path.endsWith('/')) {
41+
if (args.path.endsWith("/")) {
4442
importPath = `${args.path}index${extension}`
4543
} else {
4644
importPath = `${args.path}/index${extension}`
@@ -50,35 +48,36 @@ const addExtension = (extension: string = '.js', fileExtension: string = '.ts'):
5048
return { path: importPath, external: true }
5149
}
5250
})
53-
},
51+
}
5452
})
5553

5654
const commonOptions: BuildOptions = {
5755
entryPoints,
58-
logLevel: 'info',
59-
platform: 'node',
60-
tsconfig: 'tsconfig.json',
56+
logLevel: "info",
57+
platform: "node",
58+
tsconfig: "tsconfig.json",
59+
target: "es2022"
6160
}
6261

6362
const cjsBuild = () =>
6463
build({
6564
...commonOptions,
66-
outbase: './src',
67-
outdir: './dist/cjs',
68-
format: 'cjs',
69-
tsconfig: 'tsconfig.cjs.json',
65+
outbase: "./src",
66+
outdir: "./dist/cjs",
67+
format: "cjs",
68+
tsconfig: "tsconfig.cjs.json"
7069
})
7170

7271
const esmBuild = () =>
7372
build({
7473
...commonOptions,
7574
bundle: true,
76-
outbase: './src',
77-
outdir: './dist',
78-
format: 'esm',
79-
plugins: [addExtension('.js')],
75+
outbase: "./src",
76+
outdir: "./dist",
77+
format: "esm",
78+
plugins: [addExtension(".js")]
8079
})
8180

8281
Promise.all([esmBuild(), cjsBuild()])
8382

84-
exec(`tsc --emitDeclarationOnly --declaration --project tsconfig.build.json`)
83+
exec(`tsc --emitDeclarationOnly --declaration --project tsconfig.build.json`)

examples/mightFailStaticMethods.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,13 @@ async function race() {
100100
race()
101101

102102
async function any() {
103-
const { error, result } = await mightFail.any([
103+
const promises = [
104104
Promise.reject(new Error("Failure 1")),
105105
returnStringAfter("success", 100),
106106
Promise.reject(new Error("Failure 2"))
107-
])
107+
]
108+
109+
const { error, result } = await mightFail.any<typeof promises>(promises)
108110
if (error) {
109111
console.error(error)
110112
return

examples/tsconfig.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"extends": "../tsconfig.json",
3+
"include": ["./**/*"],
4+
"compilerOptions": {
5+
"rootDir": ".",
6+
"outDir": "../dist/examples"
7+
}
8+
}

src/mightFail.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,6 @@ export const Might = function Might<T>(result: T): Either<T> {
8989
*
9090
* @param error
9191
*/
92-
export const Fail = function Fail<T = any, E extends Error = Error>(error: unknown): Either<undefined, E> {
93-
return createEither<undefined, E>({ result: undefined, error: handleError<E>(error) })
92+
export const Fail = function Fail<T = unknown, E extends Error = Error>(error: unknown): Either<T, E> {
93+
return createEither<T, E>({ result: undefined, error: handleError<E>(error) })
9494
}

tsconfig.build.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
{
22
"extends": "./tsconfig.json",
33
"compilerOptions": {
4+
"target": "es2022",
5+
"lib": ["es2022", "dom"],
46
"module": "ES2020",
57
"rootDir": "./src/",
68
"outDir": "./dist/",

tsconfig.cjs.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"compilerOptions": {
44
"module": "commonjs",
55
"outDir": "./dist/cjs",
6-
"target": "es2020",
6+
"target": "es2022",
77
"moduleResolution": "node"
88
}
99
}

tsconfig.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
22
"compilerOptions": {
3-
"target": "es2020",
3+
"target": "es2022",
44
"declaration": true,
55
"moduleResolution": "node",
66
"esModuleInterop": true,
77
"forceConsistentCasingInFileNames": true,
88
"strict": true,
99
"skipLibCheck": false,
10-
"lib": ["es2020", "dom"],
10+
"lib": ["es2022", "dom"],
1111
"declarationMap": true,
1212
"sourceMap": true,
1313
"outDir": "./dist",
@@ -17,7 +17,7 @@
1717
"isolatedModules": true,
1818
},
1919
"include": [
20-
"src/**/*"
20+
"src/**/*",
2121
],
2222
"exclude": [
2323
"node_modules",

0 commit comments

Comments
 (0)