Skip to content

Commit 917af29

Browse files
fix(build): switch to esbuild and tsc instead of pika (#644)
* Switch to esbuild and tsc instead of pika * Fix linting errors * import/export types explicitly * Move types to a dev dependency * Remove unused deprecation dependency * Move types back to a regular dependency * Update src/endpoints-to-methods.ts Co-authored-by: wolfy1339 <4595477+wolfy1339@users.noreply.github.com> * Update src/index.ts Co-authored-by: wolfy1339 <4595477+wolfy1339@users.noreply.github.com> * Regenerate package-lock.json with npm 14 * npm run lint:fix * Bump major version of tsconfig * Update package.json Co-authored-by: wolfy1339 <4595477+wolfy1339@users.noreply.github.com> --------- Co-authored-by: wolfy1339 <4595477+wolfy1339@users.noreply.github.com>
1 parent ca3eae8 commit 917af29

13 files changed

+1145
-12730
lines changed

package-lock.json

+1,010-12,683
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+13-24
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"version": "0.0.0-development",
44
"description": "Octokit plugin adding one method for all of api.github.com REST API endpoints",
55
"scripts": {
6-
"build": "pika-pack build",
6+
"build": "node scripts/build.mjs && tsc -p tsconfig.json",
77
"lint": "prettier --check '{src,test}/**/*' '!src/generated/**' README.md package.json",
88
"lint:fix": "prettier --write '{src,test}/**/*' '!src/generated/**' README.md package.json",
99
"pretest": "npm run -s lint",
@@ -24,22 +24,20 @@
2424
"author": "Gregor Martynus (https://twitter.com/gr2m)",
2525
"license": "MIT",
2626
"dependencies": {
27-
"@octokit/types": "^9.2.3",
28-
"deprecation": "^2.3.1"
27+
"@octokit/types": "^9.2.3"
2928
},
3029
"devDependencies": {
3130
"@gimenete/type-writer": "^0.1.5",
3231
"@octokit/core": "^4.0.0",
33-
"@pika/pack": "^0.3.7",
34-
"@pika/plugin-build-node": "^0.9.0",
35-
"@pika/plugin-build-web": "^0.9.0",
36-
"@pika/plugin-ts-standard-pkg": "^0.9.0",
32+
"@octokit/tsconfig": "^2.0.0",
3733
"@types/fetch-mock": "^7.3.1",
3834
"@types/jest": "^29.0.0",
3935
"@types/node": "^18.0.0",
36+
"esbuild": "^0.17.19",
4037
"fetch-mock": "^9.0.0",
4138
"fs-extra": "^11.0.0",
4239
"github-openapi-graphql-query": "^4.0.0",
40+
"glob": "^10.2.6",
4341
"jest": "^29.0.0",
4442
"lodash.camelcase": "^4.3.0",
4543
"lodash.set": "^4.3.2",
@@ -57,7 +55,14 @@
5755
"@octokit/core": ">=3"
5856
},
5957
"jest": {
60-
"preset": "ts-jest",
58+
"transform": {
59+
"^.+\\.(ts|tsx)$": [
60+
"ts-jest",
61+
{
62+
"tsconfig": "test/tsconfig.test.json"
63+
}
64+
]
65+
},
6166
"coverageThreshold": {
6267
"global": {
6368
"statements": 100,
@@ -67,22 +72,6 @@
6772
}
6873
}
6974
},
70-
"@pika/pack": {
71-
"pipeline": [
72-
[
73-
"@pika/plugin-ts-standard-pkg"
74-
],
75-
[
76-
"@pika/plugin-build-node",
77-
{
78-
"minNodeVersion": "14"
79-
}
80-
],
81-
[
82-
"@pika/plugin-build-web"
83-
]
84-
]
85-
},
8675
"release": {
8776
"branches": [
8877
"+([0-9]).x",

scripts/build.mjs

+88
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/endpoints-to-methods.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1-
import { Octokit } from "@octokit/core";
2-
import {
1+
import type { Octokit } from "@octokit/core";
2+
import type {
33
EndpointOptions,
44
RequestParameters,
55
RequestMethod,
66
Route,
77
Url,
88
} from "@octokit/types";
9-
import { EndpointsDefaultsAndDecorations, EndpointDecorations } from "./types";
10-
import { RestEndpointMethods } from "./generated/method-types";
9+
import type {
10+
EndpointsDefaultsAndDecorations,
11+
EndpointDecorations,
12+
} from "./types";
13+
import type { RestEndpointMethods } from "./generated/method-types";
1114

1215
type EndpointMethods = {
1316
[methodName: string]: typeof Octokit.prototype.request;

src/generated/endpoints.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { EndpointsDefaultsAndDecorations } from "../types";
1+
import type { EndpointsDefaultsAndDecorations } from "../types";
22
const Endpoints: EndpointsDefaultsAndDecorations = {
33
actions: {
44
addCustomLabelsToSelfHostedRunnerForOrg: [

src/generated/method-types.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { EndpointInterface, RequestInterface } from "@octokit/types";
2-
import { RestEndpointMethodTypes } from "./parameters-and-response-types";
1+
import type { EndpointInterface, RequestInterface } from "@octokit/types";
2+
import type { RestEndpointMethodTypes } from "./parameters-and-response-types";
33

44
export type RestEndpointMethods = {
55
actions: {

src/generated/parameters-and-response-types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Endpoints, RequestParameters } from "@octokit/types";
1+
import type { Endpoints, RequestParameters } from "@octokit/types";
22

33
export type RestEndpointMethodTypes = {
44
actions: {

src/index.ts

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

33
import ENDPOINTS from "./generated/endpoints";
4-
export { RestEndpointMethodTypes } from "./generated/parameters-and-response-types";
4+
export type { RestEndpointMethodTypes } from "./generated/parameters-and-response-types";
55
import { VERSION } from "./version";
6-
import { Api } from "./types";
6+
import type { Api } from "./types";
77
import { endpointsToMethods } from "./endpoints-to-methods";
88

99
export function restEndpointMethods(octokit: Octokit): Api {

src/types.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { Route, RequestParameters } from "@octokit/types";
1+
import type { Route, RequestParameters } from "@octokit/types";
22

3-
import { RestEndpointMethods } from "./generated/method-types";
3+
import type { RestEndpointMethods } from "./generated/method-types";
44

55
export type Api = { rest: RestEndpointMethods };
66

test/rest-endpoint-methods.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ describe("REST API endpoint methods", () => {
5757
headers: {
5858
"content-type": "text/plain; charset=utf-8",
5959
},
60-
matcher: (url, { body, headers }) => {
60+
matcher: (_, { body }) => {
6161
expect(body).toEqual("# Hello, world!");
6262
return true;
6363
},
@@ -94,7 +94,7 @@ describe("REST API endpoint methods", () => {
9494
name: "test.txt",
9595
label: "test",
9696
},
97-
matcher: (url, { body }) => {
97+
matcher: (_, { body }) => {
9898
expect(body).toEqual("test 1, 2");
9999
return true;
100100
},

test/tsconfig.test.json

+9
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+
}

test/typescript.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ describe("Smoke test", () => {
1313
return updateLabel(options);
1414

1515
async function updateLabel(
16-
options: RestEndpointMethodTypes["issues"]["updateLabel"]["parameters"]
16+
_: RestEndpointMethodTypes["issues"]["updateLabel"]["parameters"]
1717
): Promise<RestEndpointMethodTypes["issues"]["updateLabel"]["response"]> {
1818
return {
1919
headers: {},

tsconfig.json

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,12 +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
},
9-
"include": [
10-
"src/**/*"
11-
]
10+
"include": ["src/**/*"]
1211
}

0 commit comments

Comments
 (0)