Skip to content

Commit 3ba0db6

Browse files
authored
fix(build): replace Pika with esbuild and tsc (#527)
* build: remove pika * build: remove obsolete script * build(tsconfig): use `@octokit/tsconfig` * build: add esbuild * build(tsconfig): add options for `.d.ts` generation * build: update `build` npm script * chore: explicitly mark type imports/exports
1 parent 9240b2f commit 3ba0db6

11 files changed

+5575
-8129
lines changed

.github/workflows/release.yml

-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ jobs:
1818
cache: npm
1919
- run: npm ci
2020
- run: npm run build
21-
- name: "Fix pkg.files file pattern"
22-
run: node scripts/fix-package-json.js
2321
- run: npx semantic-release
2422
env:
2523
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

package-lock.json

+5,465-8,077
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+4-21
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"version": "0.0.0-development",
77
"description": "Octokit plugin to paginate REST API endpoint responses",
88
"scripts": {
9-
"build": "pika-pack build",
9+
"build": "node scripts/build.mjs && tsc -p tsconfig.json",
1010
"lint": "prettier --check '{src,test}/**/*' README.md package.json",
1111
"lint:fix": "prettier --write '{src,test}/**/*' README.md package.json",
1212
"pretest": "npm run -s lint",
@@ -25,6 +25,7 @@
2525
],
2626
"license": "MIT",
2727
"dependencies": {
28+
"@octokit/tsconfig": "^1.0.2",
2829
"@octokit/types": "^9.2.3"
2930
},
3031
"peerDependencies": {
@@ -33,15 +34,13 @@
3334
"devDependencies": {
3435
"@octokit/core": "^4.0.0",
3536
"@octokit/plugin-rest-endpoint-methods": "^7.1.0",
36-
"@pika/pack": "^0.3.7",
37-
"@pika/plugin-build-node": "^0.9.0",
38-
"@pika/plugin-build-web": "^0.9.0",
39-
"@pika/plugin-ts-standard-pkg": "^0.9.0",
4037
"@types/fetch-mock": "^7.3.1",
4138
"@types/jest": "^29.0.0",
4239
"@types/node": "^18.0.0",
40+
"esbuild": "^0.17.19",
4341
"fetch-mock": "^9.0.0",
4442
"github-openapi-graphql-query": "^4.0.0",
43+
"glob": "^10.2.5",
4544
"jest": "^29.0.0",
4645
"npm-run-all": "^4.1.5",
4746
"prettier": "2.8.8",
@@ -60,22 +59,6 @@
6059
}
6160
}
6261
},
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-
},
7962
"release": {
8063
"branches": [
8164
"+([0-9]).x",

scripts/build.mjs

+92
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();

scripts/fix-package-json.js

-15
This file was deleted.

src/compose-paginate.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { paginate } from "./paginate";
22
import { iterator } from "./iterator";
33

4-
import { ComposePaginateInterface } from "./types";
4+
import type { ComposePaginateInterface } from "./types";
55

66
export const composePaginateRest = Object.assign(paginate, {
77
iterator,

src/index.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
import { Octokit } from "@octokit/core";
1+
import type { Octokit } from "@octokit/core";
22

33
import { VERSION } from "./version";
44
import { paginate } from "./paginate";
55
import { iterator } from "./iterator";
6-
import { PaginateInterface } from "./types";
6+
import type { PaginateInterface } from "./types";
77

8-
export { PaginateInterface } from "./types";
9-
export { PaginatingEndpoints } from "./types";
8+
export type { PaginateInterface, PaginatingEndpoints } from "./types";
109
export { composePaginateRest } from "./compose-paginate";
1110
export {
1211
isPaginatingEndpoint,

src/iterator.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { Octokit } from "@octokit/core";
1+
import type { Octokit } from "@octokit/core";
22

33
import { normalizePaginatedListResponse } from "./normalize-paginated-list-response";
4-
import {
4+
import type {
55
EndpointOptions,
66
RequestInterface,
77
RequestParameters,

src/normalize-paginated-list-response.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* otherwise match: https://developer.github.com/v3/repos/statuses/#get-the-combined-status-for-a-specific-ref
1616
*/
1717

18-
import { OctokitResponse } from "./types";
18+
import type { OctokitResponse } from "./types";
1919

2020
export function normalizePaginatedListResponse(
2121
response: OctokitResponse<any>

src/paginate.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { Octokit } from "@octokit/core";
1+
import type { Octokit } from "@octokit/core";
22

33
import { iterator } from "./iterator";
4-
import {
4+
import type {
55
MapFunction,
66
PaginationResults,
77
RequestParameters,

tsconfig.json

+5-4
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": [
1011
"src/**/*"

0 commit comments

Comments
 (0)