Skip to content

Commit

Permalink
fix(build): replace Pika with esbuild and tsc (#527)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
wolfy1339 committed May 19, 2023
1 parent 9240b2f commit 3ba0db6
Show file tree
Hide file tree
Showing 11 changed files with 5,575 additions and 8,129 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/release.yml
Expand Up @@ -18,8 +18,6 @@ jobs:
cache: npm
- run: npm ci
- run: npm run build
- name: "Fix pkg.files file pattern"
run: node scripts/fix-package-json.js
- run: npx semantic-release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
13,542 changes: 5,465 additions & 8,077 deletions package-lock.json

Large diffs are not rendered by default.

25 changes: 4 additions & 21 deletions package.json
Expand Up @@ -6,7 +6,7 @@
"version": "0.0.0-development",
"description": "Octokit plugin to paginate REST API endpoint responses",
"scripts": {
"build": "pika-pack build",
"build": "node scripts/build.mjs && tsc -p tsconfig.json",
"lint": "prettier --check '{src,test}/**/*' README.md package.json",
"lint:fix": "prettier --write '{src,test}/**/*' README.md package.json",
"pretest": "npm run -s lint",
Expand All @@ -25,6 +25,7 @@
],
"license": "MIT",
"dependencies": {
"@octokit/tsconfig": "^1.0.2",
"@octokit/types": "^9.2.3"
},
"peerDependencies": {
Expand All @@ -33,15 +34,13 @@
"devDependencies": {
"@octokit/core": "^4.0.0",
"@octokit/plugin-rest-endpoint-methods": "^7.1.0",
"@pika/pack": "^0.3.7",
"@pika/plugin-build-node": "^0.9.0",
"@pika/plugin-build-web": "^0.9.0",
"@pika/plugin-ts-standard-pkg": "^0.9.0",
"@types/fetch-mock": "^7.3.1",
"@types/jest": "^29.0.0",
"@types/node": "^18.0.0",
"esbuild": "^0.17.19",
"fetch-mock": "^9.0.0",
"github-openapi-graphql-query": "^4.0.0",
"glob": "^10.2.5",
"jest": "^29.0.0",
"npm-run-all": "^4.1.5",
"prettier": "2.8.8",
Expand All @@ -60,22 +59,6 @@
}
}
},
"@pika/pack": {
"pipeline": [
[
"@pika/plugin-ts-standard-pkg"
],
[
"@pika/plugin-build-node",
{
"minNodeVersion": "14"
}
],
[
"@pika/plugin-build-web"
]
]
},
"release": {
"branches": [
"+([0-9]).x",
Expand Down
92 changes: 92 additions & 0 deletions scripts/build.mjs
@@ -0,0 +1,92 @@
// @ts-check
import esbuild from "esbuild";
import { copyFile, readFile, writeFile, rm } from "fs/promises";
import { glob } from "glob";

/**
* @type {esbuild.BuildOptions}
*/
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",
module: "dist-web/index.js",
types: "dist-types/index.d.ts",
source: "dist-src/index.js",
sideEffects: false,
},
null,
2
)
);
}
main();
15 changes: 0 additions & 15 deletions scripts/fix-package-json.js

This file was deleted.

2 changes: 1 addition & 1 deletion src/compose-paginate.ts
@@ -1,7 +1,7 @@
import { paginate } from "./paginate";
import { iterator } from "./iterator";

import { ComposePaginateInterface } from "./types";
import type { ComposePaginateInterface } from "./types";

export const composePaginateRest = Object.assign(paginate, {
iterator,
Expand Down
7 changes: 3 additions & 4 deletions src/index.ts
@@ -1,12 +1,11 @@
import { Octokit } from "@octokit/core";
import type { Octokit } from "@octokit/core";

import { VERSION } from "./version";
import { paginate } from "./paginate";
import { iterator } from "./iterator";
import { PaginateInterface } from "./types";
import type { PaginateInterface } from "./types";

export { PaginateInterface } from "./types";
export { PaginatingEndpoints } from "./types";
export type { PaginateInterface, PaginatingEndpoints } from "./types";
export { composePaginateRest } from "./compose-paginate";
export {
isPaginatingEndpoint,
Expand Down
4 changes: 2 additions & 2 deletions src/iterator.ts
@@ -1,7 +1,7 @@
import { Octokit } from "@octokit/core";
import type { Octokit } from "@octokit/core";

import { normalizePaginatedListResponse } from "./normalize-paginated-list-response";
import {
import type {
EndpointOptions,
RequestInterface,
RequestParameters,
Expand Down
2 changes: 1 addition & 1 deletion src/normalize-paginated-list-response.ts
Expand Up @@ -15,7 +15,7 @@
* otherwise match: https://developer.github.com/v3/repos/statuses/#get-the-combined-status-for-a-specific-ref
*/

import { OctokitResponse } from "./types";
import type { OctokitResponse } from "./types";

export function normalizePaginatedListResponse(
response: OctokitResponse<any>
Expand Down
4 changes: 2 additions & 2 deletions src/paginate.ts
@@ -1,7 +1,7 @@
import { Octokit } from "@octokit/core";
import type { Octokit } from "@octokit/core";

import { iterator } from "./iterator";
import {
import type {
MapFunction,
PaginationResults,
RequestParameters,
Expand Down
9 changes: 5 additions & 4 deletions tsconfig.json
@@ -1,10 +1,11 @@
{
"extends": "@octokit/tsconfig",
"compilerOptions": {
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"strict": true,
"target": "es2018"
"declaration": true,
"outDir": "pkg/dist-types",
"emitDeclarationOnly": true,
"sourceMap": true
},
"include": [
"src/**/*"
Expand Down

0 comments on commit 3ba0db6

Please sign in to comment.