Skip to content

Commit

Permalink
fix(build): switch to esbuild (#161)
Browse files Browse the repository at this point in the history
Switch to esbuild
  • Loading branch information
kfcampbell authored Jun 9, 2023
1 parent 64411f1 commit 9539d9a
Show file tree
Hide file tree
Showing 17 changed files with 2,045 additions and 21,493 deletions.
23,354 changes: 1,904 additions & 21,450 deletions package-lock.json

Large diffs are not rendered by default.

35 changes: 14 additions & 21 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"version": "0.0.0-development",
"description": "Set of stateless request methods to create, check, reset, refresh, and delete user access tokens for OAuth and GitHub Apps",
"scripts": {
"build": "pika-pack build",
"lint": "prettier --check '{src,test}/**/*' README.md package.json",
"lint:fix": "prettier --write '{src,test}/**/*' README.md package.json",
"build": "node scripts/build.mjs && tsc -p tsconfig.json",
"lint": "prettier --check '{src,test,scripts}/**/*' README.md package.json",
"lint:fix": "prettier --write '{src,test,scripts}/**/*' README.md package.json",
"pretest": "npm run -s lint",
"test": "jest --coverage"
},
Expand All @@ -27,14 +27,13 @@
"btoa-lite": "^1.0.0"
},
"devDependencies": {
"@octokit/tsconfig": "^1.0.2",
"@pika/pack": "^0.5.0",
"@pika/plugin-build-node": "^0.9.2",
"@pika/plugin-ts-standard-pkg": "^0.9.2",
"@octokit/tsconfig": "^2.0.0",
"@types/btoa-lite": "^1.0.0",
"@types/jest": "^29.0.0",
"@types/node": "^18.0.0",
"esbuild": "^0.17.19",
"fetch-mock": "^9.11.0",
"glob": "^10.2.7",
"jest": "^29.0.0",
"prettier": "2.8.8",
"semantic-release": "^21.0.0",
Expand All @@ -44,7 +43,14 @@
},
"peerDependencies": {},
"jest": {
"preset": "ts-jest",
"transform": {
"^.+\\.(ts|tsx)$": [
"ts-jest",
{
"tsconfig": "test/tsconfig.test.json"
}
]
},
"coverageThreshold": {
"global": {
"statements": 100,
Expand All @@ -54,19 +60,6 @@
}
}
},
"@pika/pack": {
"pipeline": [
[
"@pika/plugin-ts-standard-pkg"
],
[
"@pika/plugin-build-node",
{
"minNodeVersion": "14"
}
]
]
},
"release": {
"branches": [
"+([0-9]).x",
Expand Down
88 changes: 88 additions & 0 deletions scripts/build.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import esbuild from "esbuild";
import { copyFile, readFile, writeFile, rm } from "node:fs/promises";
import { glob } from "glob";

const sharedOptions = {
sourcemap: "external",
sourcesContent: true,
minify: false,
allowOverwrite: true,
packages: "external",
};

async function main() {
// Start with a clean slate
await rm("pkg", { recursive: true, force: true });
// Build the source code for a neutral platform as ESM
await esbuild.build({
entryPoints: await glob(["./src/*.ts", "./src/**/*.ts"]),
outdir: "pkg/dist-src",
bundle: false,
platform: "neutral",
format: "esm",
...sharedOptions,
sourcemap: false,
});

// Remove the types file from the dist-src folder
const typeFiles = await glob([
"./pkg/dist-src/**/types.js.map",
"./pkg/dist-src/**/types.js",
]);
for (const typeFile of typeFiles) {
await rm(typeFile);
}

const entryPoints = ["./pkg/dist-src/index.js"];

await Promise.all([
// Build the a CJS Node.js bundle
esbuild.build({
entryPoints,
outdir: "pkg/dist-node",
bundle: true,
platform: "node",
target: "node14",
format: "cjs",
...sharedOptions,
}),
// Build an ESM browser bundle
esbuild.build({
entryPoints,
outdir: "pkg/dist-web",
bundle: true,
platform: "browser",
format: "esm",
...sharedOptions,
}),
]);

// Copy the README, LICENSE to the pkg folder
await copyFile("LICENSE", "pkg/LICENSE");
await copyFile("README.md", "pkg/README.md");

// Handle the package.json
let pkg = JSON.parse((await readFile("package.json", "utf8")).toString());
// Remove unnecessary fields from the package.json
delete pkg.scripts;
delete pkg.prettier;
delete pkg.release;
delete pkg.jest;
await writeFile(
"pkg/package.json",
JSON.stringify(
{
...pkg,
files: ["dist-*/**", "bin/**"],
main: "dist-node/index.js",
browser: "dist-web/index.js",
types: "dist-types/index.d.ts",
module: "dist-src/index.js",
sideEffects: false,
},
null,
2
)
);
}
main();
4 changes: 2 additions & 2 deletions src/check-token.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { request as defaultRequest } from "@octokit/request";
import { RequestInterface, Endpoints } from "@octokit/types";
import type { RequestInterface, Endpoints } from "@octokit/types";
import btoa from "btoa-lite";

import {
import type {
OAuthAppAuthentication,
GitHubAppAuthenticationWithExpirationEnabled,
GitHubAppAuthenticationWithExpirationDisabled,
Expand Down
2 changes: 1 addition & 1 deletion src/create-device-code.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { request as defaultRequest } from "@octokit/request";
import { OctokitResponse, RequestInterface } from "@octokit/types";
import type { OctokitResponse, RequestInterface } from "@octokit/types";

import { oauthRequest } from "./utils";

Expand Down
2 changes: 1 addition & 1 deletion src/delete-authorization.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { request as defaultRequest } from "@octokit/request";
import { RequestInterface, Endpoints } from "@octokit/types";
import type { RequestInterface, Endpoints } from "@octokit/types";
import btoa from "btoa-lite";

export type DeleteAuthorizationOAuthAppOptions = {
Expand Down
2 changes: 1 addition & 1 deletion src/delete-token.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { request as defaultRequest } from "@octokit/request";
import { RequestInterface, Endpoints } from "@octokit/types";
import type { RequestInterface, Endpoints } from "@octokit/types";
import btoa from "btoa-lite";

export type DeleteTokenOAuthAppOptions = {
Expand Down
4 changes: 2 additions & 2 deletions src/exchange-device-code.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { request as defaultRequest } from "@octokit/request";
import { OctokitResponse, RequestInterface } from "@octokit/types";
import type { OctokitResponse, RequestInterface } from "@octokit/types";

import {
import type {
OAuthAppAuthentication,
GitHubAppAuthenticationWithExpirationEnabled,
GitHubAppAuthenticationWithExpirationDisabled,
Expand Down
4 changes: 2 additions & 2 deletions src/exchange-web-flow-code.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { request as defaultRequest } from "@octokit/request";
import { OctokitResponse, RequestInterface } from "@octokit/types";
import type { OctokitResponse, RequestInterface } from "@octokit/types";

import {
import type {
OAuthAppAuthentication,
GitHubAppAuthenticationWithExpirationEnabled,
GitHubAppAuthenticationWithExpirationDisabled,
Expand Down
6 changes: 3 additions & 3 deletions src/get-web-flow-authorization-url.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {
oauthAuthorizationUrl,
import { oauthAuthorizationUrl } from "@octokit/oauth-authorization-url";
import type {
OAuthAppResult,
GitHubAppResult,
} from "@octokit/oauth-authorization-url";
import { request as defaultRequest } from "@octokit/request";
import { RequestInterface } from "@octokit/types";
import type { RequestInterface } from "@octokit/types";

import { requestToOAuthBaseUrl } from "./utils";

Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export * from "./scope-token";
export * from "./reset-token";
export * from "./delete-token";
export * from "./delete-authorization";
export {
export type {
OAuthAppAuthentication,
GitHubAppAuthenticationWithExpirationDisabled,
GitHubAppAuthenticationWithExpirationEnabled,
Expand Down
4 changes: 2 additions & 2 deletions src/refresh-token.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { request as defaultRequest } from "@octokit/request";
import { OctokitResponse, RequestInterface } from "@octokit/types";
import type { OctokitResponse, RequestInterface } from "@octokit/types";

import {
import type {
GitHubAppAuthenticationWithRefreshToken,
GitHubAppCreateTokenWithExpirationResponseData,
} from "./types";
Expand Down
4 changes: 2 additions & 2 deletions src/reset-token.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { request as defaultRequest } from "@octokit/request";
import { RequestInterface, Endpoints } from "@octokit/types";
import btoa from "btoa-lite";

import {
import type { Endpoints, RequestInterface } from "@octokit/types";
import type {
OAuthAppAuthentication,
GitHubAppAuthenticationWithExpirationEnabled,
GitHubAppAuthenticationWithExpirationDisabled,
Expand Down
4 changes: 2 additions & 2 deletions src/scope-token.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { request as defaultRequest } from "@octokit/request";
import { RequestInterface, Endpoints } from "@octokit/types";
import type { RequestInterface, Endpoints } from "@octokit/types";
import btoa from "btoa-lite";

import {
import type {
GitHubAppAuthenticationWithExpirationEnabled,
GitHubAppAuthenticationWithExpirationDisabled,
} from "./types";
Expand Down
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RequestInterface, RequestOptions } from "@octokit/types";
import type { RequestInterface, RequestOptions } from "@octokit/types";
import { RequestError } from "@octokit/request-error";

export function requestToOAuthBaseUrl(request: RequestInterface): string {
Expand Down
9 changes: 9 additions & 0 deletions test/tsconfig.test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"emitDeclarationOnly": false,
"noEmit": true,
"verbatimModuleSyntax": false
},
"include": ["src/**/*"]
}
12 changes: 10 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
{
"extends": "@octokit/tsconfig",
"include": ["src/**/*"],
"compilerOptions": { "esModuleInterop": true }
"compilerOptions": {
"esModuleInterop": true,
"declaration": true,
"outDir": "pkg/dist-types",
"emitDeclarationOnly": true,
"sourceMap": true
},
"include": [
"src/**/*"
]
}

0 comments on commit 9539d9a

Please sign in to comment.