Skip to content

Commit 9539d9a

Browse files
authored
fix(build): switch to esbuild (#161)
Switch to esbuild
1 parent 64411f1 commit 9539d9a

17 files changed

+2045
-21493
lines changed

package-lock.json

Lines changed: 1904 additions & 21450 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
"version": "0.0.0-development",
44
"description": "Set of stateless request methods to create, check, reset, refresh, and delete user access tokens for OAuth and GitHub Apps",
55
"scripts": {
6-
"build": "pika-pack build",
7-
"lint": "prettier --check '{src,test}/**/*' README.md package.json",
8-
"lint:fix": "prettier --write '{src,test}/**/*' README.md package.json",
6+
"build": "node scripts/build.mjs && tsc -p tsconfig.json",
7+
"lint": "prettier --check '{src,test,scripts}/**/*' README.md package.json",
8+
"lint:fix": "prettier --write '{src,test,scripts}/**/*' README.md package.json",
99
"pretest": "npm run -s lint",
1010
"test": "jest --coverage"
1111
},
@@ -27,14 +27,13 @@
2727
"btoa-lite": "^1.0.0"
2828
},
2929
"devDependencies": {
30-
"@octokit/tsconfig": "^1.0.2",
31-
"@pika/pack": "^0.5.0",
32-
"@pika/plugin-build-node": "^0.9.2",
33-
"@pika/plugin-ts-standard-pkg": "^0.9.2",
30+
"@octokit/tsconfig": "^2.0.0",
3431
"@types/btoa-lite": "^1.0.0",
3532
"@types/jest": "^29.0.0",
3633
"@types/node": "^18.0.0",
34+
"esbuild": "^0.17.19",
3735
"fetch-mock": "^9.11.0",
36+
"glob": "^10.2.7",
3837
"jest": "^29.0.0",
3938
"prettier": "2.8.8",
4039
"semantic-release": "^21.0.0",
@@ -44,7 +43,14 @@
4443
},
4544
"peerDependencies": {},
4645
"jest": {
47-
"preset": "ts-jest",
46+
"transform": {
47+
"^.+\\.(ts|tsx)$": [
48+
"ts-jest",
49+
{
50+
"tsconfig": "test/tsconfig.test.json"
51+
}
52+
]
53+
},
4854
"coverageThreshold": {
4955
"global": {
5056
"statements": 100,
@@ -54,19 +60,6 @@
5460
}
5561
}
5662
},
57-
"@pika/pack": {
58-
"pipeline": [
59-
[
60-
"@pika/plugin-ts-standard-pkg"
61-
],
62-
[
63-
"@pika/plugin-build-node",
64-
{
65-
"minNodeVersion": "14"
66-
}
67-
]
68-
]
69-
},
7063
"release": {
7164
"branches": [
7265
"+([0-9]).x",

scripts/build.mjs

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
import esbuild from "esbuild";
2+
import { copyFile, readFile, writeFile, rm } from "node:fs/promises";
3+
import { glob } from "glob";
4+
5+
const sharedOptions = {
6+
sourcemap: "external",
7+
sourcesContent: true,
8+
minify: false,
9+
allowOverwrite: true,
10+
packages: "external",
11+
};
12+
13+
async function main() {
14+
// Start with a clean slate
15+
await rm("pkg", { recursive: true, force: true });
16+
// Build the source code for a neutral platform as ESM
17+
await esbuild.build({
18+
entryPoints: await glob(["./src/*.ts", "./src/**/*.ts"]),
19+
outdir: "pkg/dist-src",
20+
bundle: false,
21+
platform: "neutral",
22+
format: "esm",
23+
...sharedOptions,
24+
sourcemap: false,
25+
});
26+
27+
// Remove the types file from the dist-src folder
28+
const typeFiles = await glob([
29+
"./pkg/dist-src/**/types.js.map",
30+
"./pkg/dist-src/**/types.js",
31+
]);
32+
for (const typeFile of typeFiles) {
33+
await rm(typeFile);
34+
}
35+
36+
const entryPoints = ["./pkg/dist-src/index.js"];
37+
38+
await Promise.all([
39+
// Build the a CJS Node.js bundle
40+
esbuild.build({
41+
entryPoints,
42+
outdir: "pkg/dist-node",
43+
bundle: true,
44+
platform: "node",
45+
target: "node14",
46+
format: "cjs",
47+
...sharedOptions,
48+
}),
49+
// Build an ESM browser bundle
50+
esbuild.build({
51+
entryPoints,
52+
outdir: "pkg/dist-web",
53+
bundle: true,
54+
platform: "browser",
55+
format: "esm",
56+
...sharedOptions,
57+
}),
58+
]);
59+
60+
// Copy the README, LICENSE to the pkg folder
61+
await copyFile("LICENSE", "pkg/LICENSE");
62+
await copyFile("README.md", "pkg/README.md");
63+
64+
// Handle the package.json
65+
let pkg = JSON.parse((await readFile("package.json", "utf8")).toString());
66+
// Remove unnecessary fields from the package.json
67+
delete pkg.scripts;
68+
delete pkg.prettier;
69+
delete pkg.release;
70+
delete pkg.jest;
71+
await writeFile(
72+
"pkg/package.json",
73+
JSON.stringify(
74+
{
75+
...pkg,
76+
files: ["dist-*/**", "bin/**"],
77+
main: "dist-node/index.js",
78+
browser: "dist-web/index.js",
79+
types: "dist-types/index.d.ts",
80+
module: "dist-src/index.js",
81+
sideEffects: false,
82+
},
83+
null,
84+
2
85+
)
86+
);
87+
}
88+
main();

src/check-token.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { request as defaultRequest } from "@octokit/request";
2-
import { RequestInterface, Endpoints } from "@octokit/types";
2+
import type { RequestInterface, Endpoints } from "@octokit/types";
33
import btoa from "btoa-lite";
44

5-
import {
5+
import type {
66
OAuthAppAuthentication,
77
GitHubAppAuthenticationWithExpirationEnabled,
88
GitHubAppAuthenticationWithExpirationDisabled,

src/create-device-code.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { request as defaultRequest } from "@octokit/request";
2-
import { OctokitResponse, RequestInterface } from "@octokit/types";
2+
import type { OctokitResponse, RequestInterface } from "@octokit/types";
33

44
import { oauthRequest } from "./utils";
55

src/delete-authorization.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { request as defaultRequest } from "@octokit/request";
2-
import { RequestInterface, Endpoints } from "@octokit/types";
2+
import type { RequestInterface, Endpoints } from "@octokit/types";
33
import btoa from "btoa-lite";
44

55
export type DeleteAuthorizationOAuthAppOptions = {

src/delete-token.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { request as defaultRequest } from "@octokit/request";
2-
import { RequestInterface, Endpoints } from "@octokit/types";
2+
import type { RequestInterface, Endpoints } from "@octokit/types";
33
import btoa from "btoa-lite";
44

55
export type DeleteTokenOAuthAppOptions = {

src/exchange-device-code.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { request as defaultRequest } from "@octokit/request";
2-
import { OctokitResponse, RequestInterface } from "@octokit/types";
2+
import type { OctokitResponse, RequestInterface } from "@octokit/types";
33

4-
import {
4+
import type {
55
OAuthAppAuthentication,
66
GitHubAppAuthenticationWithExpirationEnabled,
77
GitHubAppAuthenticationWithExpirationDisabled,

src/exchange-web-flow-code.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { request as defaultRequest } from "@octokit/request";
2-
import { OctokitResponse, RequestInterface } from "@octokit/types";
2+
import type { OctokitResponse, RequestInterface } from "@octokit/types";
33

4-
import {
4+
import type {
55
OAuthAppAuthentication,
66
GitHubAppAuthenticationWithExpirationEnabled,
77
GitHubAppAuthenticationWithExpirationDisabled,

src/get-web-flow-authorization-url.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import {
2-
oauthAuthorizationUrl,
1+
import { oauthAuthorizationUrl } from "@octokit/oauth-authorization-url";
2+
import type {
33
OAuthAppResult,
44
GitHubAppResult,
55
} from "@octokit/oauth-authorization-url";
66
import { request as defaultRequest } from "@octokit/request";
7-
import { RequestInterface } from "@octokit/types";
7+
import type { RequestInterface } from "@octokit/types";
88

99
import { requestToOAuthBaseUrl } from "./utils";
1010

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export * from "./scope-token";
99
export * from "./reset-token";
1010
export * from "./delete-token";
1111
export * from "./delete-authorization";
12-
export {
12+
export type {
1313
OAuthAppAuthentication,
1414
GitHubAppAuthenticationWithExpirationDisabled,
1515
GitHubAppAuthenticationWithExpirationEnabled,

src/refresh-token.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { request as defaultRequest } from "@octokit/request";
2-
import { OctokitResponse, RequestInterface } from "@octokit/types";
2+
import type { OctokitResponse, RequestInterface } from "@octokit/types";
33

4-
import {
4+
import type {
55
GitHubAppAuthenticationWithRefreshToken,
66
GitHubAppCreateTokenWithExpirationResponseData,
77
} from "./types";

src/reset-token.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { request as defaultRequest } from "@octokit/request";
2-
import { RequestInterface, Endpoints } from "@octokit/types";
32
import btoa from "btoa-lite";
43

5-
import {
4+
import type { Endpoints, RequestInterface } from "@octokit/types";
5+
import type {
66
OAuthAppAuthentication,
77
GitHubAppAuthenticationWithExpirationEnabled,
88
GitHubAppAuthenticationWithExpirationDisabled,

src/scope-token.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { request as defaultRequest } from "@octokit/request";
2-
import { RequestInterface, Endpoints } from "@octokit/types";
2+
import type { RequestInterface, Endpoints } from "@octokit/types";
33
import btoa from "btoa-lite";
44

5-
import {
5+
import type {
66
GitHubAppAuthenticationWithExpirationEnabled,
77
GitHubAppAuthenticationWithExpirationDisabled,
88
} from "./types";

src/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { RequestInterface, RequestOptions } from "@octokit/types";
1+
import type { RequestInterface, RequestOptions } from "@octokit/types";
22
import { RequestError } from "@octokit/request-error";
33

44
export function requestToOAuthBaseUrl(request: RequestInterface): string {

test/tsconfig.test.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"extends": "../tsconfig.json",
3+
"compilerOptions": {
4+
"emitDeclarationOnly": false,
5+
"noEmit": true,
6+
"verbatimModuleSyntax": false
7+
},
8+
"include": ["src/**/*"]
9+
}

tsconfig.json

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
{
22
"extends": "@octokit/tsconfig",
3-
"include": ["src/**/*"],
4-
"compilerOptions": { "esModuleInterop": true }
3+
"compilerOptions": {
4+
"esModuleInterop": true,
5+
"declaration": true,
6+
"outDir": "pkg/dist-types",
7+
"emitDeclarationOnly": true,
8+
"sourceMap": true
9+
},
10+
"include": [
11+
"src/**/*"
12+
]
513
}

0 commit comments

Comments
 (0)