Skip to content

Commit b69f8d9

Browse files
authored
fix(build): switch to esbuild (#161)
Switch to esbuild
1 parent b95ee0f commit b69f8d9

File tree

8 files changed

+2929
-23864
lines changed

8 files changed

+2929
-23864
lines changed

package-lock.json

Lines changed: 2803 additions & 23832 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 & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
"version": "0.0.0-development",
77
"description": "Octokit authentication strategy for OAuth clients",
88
"scripts": {
9-
"build": "pika-pack build",
10-
"lint": "prettier --check '{src,test}/**/*' README.md package.json",
11-
"lint:fix": "prettier --write '{src,test}/**/*' README.md package.json",
9+
"build": "node scripts/build.mjs && tsc -p tsconfig.json",
10+
"lint": "prettier --check '{src,test,scripts}/**/*' README.md package.json",
11+
"lint:fix": "prettier --write '{src,test,scripts}/**/*' README.md package.json",
1212
"pretest": "npm run -s lint",
1313
"test": "jest --coverage"
1414
},
@@ -31,15 +31,13 @@
3131
},
3232
"devDependencies": {
3333
"@octokit/core": "^4.0.0",
34-
"@octokit/tsconfig": "^1.0.2",
35-
"@pika/pack": "^0.5.0",
36-
"@pika/plugin-build-node": "^0.9.2",
37-
"@pika/plugin-build-web": "^0.9.2",
38-
"@pika/plugin-ts-standard-pkg": "^0.9.2",
34+
"@octokit/tsconfig": "^2.0.0",
3935
"@types/btoa-lite": "^1.0.0",
4036
"@types/jest": "^29.0.0",
4137
"@types/node": "^18.0.0",
38+
"esbuild": "^0.17.19",
4239
"fetch-mock": "^9.11.0",
40+
"glob": "^10.2.7",
4341
"jest": "^29.0.0",
4442
"mockdate": "^3.0.4",
4543
"prettier": "2.8.8",
@@ -50,7 +48,14 @@
5048
},
5149
"peerDependencies": {},
5250
"jest": {
53-
"preset": "ts-jest",
51+
"transform": {
52+
"^.+\\.(ts|tsx)$": [
53+
"ts-jest",
54+
{
55+
"tsconfig": "test/tsconfig.test.json"
56+
}
57+
]
58+
},
5459
"coverageThreshold": {
5560
"global": {
5661
"statements": 100,
@@ -60,22 +65,6 @@
6065
}
6166
}
6267
},
63-
"@pika/pack": {
64-
"pipeline": [
65-
[
66-
"@pika/plugin-ts-standard-pkg"
67-
],
68-
[
69-
"@pika/plugin-build-node",
70-
{
71-
"minNodeVersion": "14"
72-
}
73-
],
74-
[
75-
"@pika/plugin-build-web"
76-
]
77-
]
78-
},
7968
"release": {
8069
"branches": [
8170
"+([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/auth.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {
1+
import type {
22
OAuthAppAuthOptions,
33
GitHubAppAuthOptions,
44
OAuthAppAuthentication,

src/hook.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import btoa from "btoa-lite";
2-
import {
2+
import type {
33
EndpointOptions,
44
EndpointDefaults,
55
OctokitResponse,
@@ -8,7 +8,7 @@ import {
88
Route,
99
} from "@octokit/types";
1010

11-
import { OAuthAppState, GitHubAppState } from "./types";
11+
import type { OAuthAppState, GitHubAppState } from "./types";
1212
import { auth } from "./auth";
1313
import { requiresBasicAuth } from "./requires-basic-auth";
1414

src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ import { request as octokitRequest } from "@octokit/request";
44
import { VERSION } from "./version";
55
import { auth } from "./auth";
66
import { hook } from "./hook";
7-
import {
7+
import type {
88
State,
99
OAuthAppStrategyOptions,
1010
GitHubAppStrategyOptions,
1111
OAuthAppAuthInterface,
1212
GitHubAppAuthInterface,
1313
} from "./types";
1414

15-
export {
15+
export type {
1616
OAuthAppStrategyOptionsWebFlow,
1717
GitHubAppStrategyOptionsWebFlow,
1818
OAuthAppStrategyOptionsDeviceFlow,

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)