Skip to content

Commit 5d1c767

Browse files
authored
fix(build): replace Pika with esbuild and tsc (#562)
* build: remove pika * build: use `@octokit/tsconfig` * test: remove unused variables and parameters * build: add esbuild * build: update `build` script * buid(tsconfig): add options for `.d.ts` generation
1 parent e1fd75e commit 5d1c767

File tree

9 files changed

+1992
-4674
lines changed

9 files changed

+1992
-4674
lines changed

package-lock.json

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

package.json

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
},
77
"description": "Extendable client for GitHub's REST & GraphQL APIs",
88
"scripts": {
9-
"build": "pika-pack build",
9+
"build": "node scripts/build.mjs && tsc -p tsconfig.json",
1010
"lint": "prettier --check '{src,test}/**/*.{ts,md}' README.md package.json",
1111
"lint:fix": "prettier --write '{src,test}/**/*.{ts,md}' README.md package.json",
1212
"pretest": "npm run -s lint",
@@ -34,15 +34,14 @@
3434
},
3535
"devDependencies": {
3636
"@octokit/auth": "^3.0.1",
37-
"@pika/pack": "^0.3.7",
38-
"@pika/plugin-build-node": "^0.9.0",
39-
"@pika/plugin-build-web": "^0.9.0",
40-
"@pika/plugin-ts-standard-pkg": "^0.9.0",
37+
"@octokit/tsconfig": "^1.0.2",
4138
"@types/fetch-mock": "^7.3.1",
4239
"@types/jest": "^29.0.0",
4340
"@types/lolex": "^5.1.0",
4441
"@types/node": "^18.0.0",
42+
"esbuild": "^0.17.19",
4543
"fetch-mock": "^9.0.0",
44+
"glob": "^10.2.5",
4645
"http-proxy-agent": "^6.0.0",
4746
"jest": "^29.0.0",
4847
"lolex": "^6.0.0",
@@ -64,22 +63,6 @@
6463
}
6564
}
6665
},
67-
"@pika/pack": {
68-
"pipeline": [
69-
[
70-
"@pika/plugin-ts-standard-pkg"
71-
],
72-
[
73-
"@pika/plugin-build-node",
74-
{
75-
"minNodeVersion": "14"
76-
}
77-
],
78-
[
79-
"@pika/plugin-build-web"
80-
]
81-
]
82-
},
8366
"release": {
8467
"branches": [
8568
"+([0-9]).x",

scripts/build.mjs

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

test/constructor.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ describe("Smoke test", () => {
5757
},
5858
});
5959

60-
octokit.hook.wrap("request", (request, options) => {
60+
octokit.hook.wrap("request", (_request, options) => {
6161
// @ts-ignore
6262
expect(options.request.foo).toEqual("bar");
6363
return {

test/defaults.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ describe("Octokit.defaults", () => {
198198
});
199199

200200
it("Octokit.defaults(function)", () => {
201-
const plugin = (octokit: Octokit, options: any) => {
201+
const plugin = (_octokit: Octokit, options: any) => {
202202
expect(options).toStrictEqual({
203203
foo: {
204204
bar: 1,
@@ -225,7 +225,7 @@ describe("Octokit.defaults", () => {
225225
});
226226

227227
it("Octokit.defaults(opts).defaults(function)", () => {
228-
const plugin = (octokit: Octokit, options: any) => {
228+
const plugin = (_octokit: Octokit, options: any) => {
229229
expect(options).toStrictEqual({
230230
other: "foo",
231231
foo: {
@@ -257,7 +257,7 @@ describe("Octokit.defaults", () => {
257257
});
258258

259259
it("Octokit.defaults(function).defaults(opts)", () => {
260-
const plugin = (octokit: Octokit, options: any) => {
260+
const plugin = (_octokit: Octokit, options: any) => {
261261
expect(options).toStrictEqual({
262262
other: "foo",
263263
foo: {

test/graphql.test.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
import { getUserAgent } from "universal-user-agent";
21
import fetchMock from "fetch-mock";
32

43
import { Octokit } from "../src";
54

6-
const userAgent = `octokit-core.js/0.0.0-development ${getUserAgent()}`;
7-
85
describe("octokit.graphql()", () => {
96
it("is a function", () => {
107
const octokit = new Octokit();
@@ -21,7 +18,7 @@ describe("octokit.graphql()", () => {
2118
};
2219
const mock = fetchMock
2320
.sandbox()
24-
.postOnce("https://api.github.com/graphql", (url, request) => {
21+
.postOnce("https://api.github.com/graphql", (_url, request) => {
2522
const body = JSON.parse(request.body!.toString());
2623
expect(body.query).toEqual(query);
2724

@@ -60,7 +57,7 @@ describe("octokit.graphql()", () => {
6057
};
6158
const mock = fetchMock
6259
.sandbox()
63-
.postOnce("https://github.acme-inc.com/api/graphql", (url, request) => {
60+
.postOnce("https://github.acme-inc.com/api/graphql", (_url, request) => {
6461
const body = JSON.parse(request.body!.toString());
6562
expect(body.query).toEqual(query);
6663

@@ -93,7 +90,7 @@ describe("octokit.graphql()", () => {
9390
it("custom headers: octokit.graphql({ query, headers })", async () => {
9491
const mock = fetchMock
9592
.sandbox()
96-
.postOnce("https://api.github.com/graphql", (url, request) => {
93+
.postOnce("https://api.github.com/graphql", (_url, request) => {
9794
// @ts-ignore `request.headers` are typed incorrectly by fetch-mock
9895
expect(request.headers["x-custom"]).toEqual("value");
9996

@@ -122,7 +119,7 @@ describe("octokit.graphql()", () => {
122119
it("custom headers: octokit.graphql(query, { headers })", async () => {
123120
const mock = fetchMock
124121
.sandbox()
125-
.postOnce("https://api.github.com/graphql", (url, request) => {
122+
.postOnce("https://api.github.com/graphql", (_url, request) => {
126123
// @ts-ignore `request.headers` are typed incorrectly by fetch-mock
127124
expect(request.headers["x-custom"]).toEqual("value");
128125

test/hook.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,11 +201,11 @@ describe("octokit.hook", () => {
201201
const octokit = new Octokit();
202202

203203
let beforeMagicCalled = false;
204-
octokit.hook.before("magic", (options: any) => {
204+
octokit.hook.before("magic", (_options: any) => {
205205
beforeMagicCalled = true;
206206
});
207207

208-
await octokit.hook("magic", (options: any) => {
208+
await octokit.hook("magic", (_options: any) => {
209209
return {
210210
magic: true,
211211
};

test/plugin.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ describe("Octokit.plugin()", () => {
3333
});
3434

3535
it("receives client options", () => {
36-
const MyOctokit = Octokit.plugin((octokit, options) => {
36+
const MyOctokit = Octokit.plugin((_octokit, options) => {
3737
expect(options).toStrictEqual({
3838
foo: "bar",
3939
});

tsconfig.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
{
2+
"extends": "@octokit/tsconfig",
23
"compilerOptions": {
34
"esModuleInterop": true,
4-
"module": "esnext",
5-
"moduleResolution": "node",
6-
"strict": true,
7-
"target": "es2018"
5+
"declaration": true,
6+
"outDir": "pkg/dist-types",
7+
"emitDeclarationOnly": true,
8+
"sourceMap": true
89
},
910
"include": ["src/**/*"]
1011
}

0 commit comments

Comments
 (0)