Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(build): use typescript to produce declaration files #550

Merged
merged 11 commits into from Jun 13, 2023
3 changes: 2 additions & 1 deletion .github/workflows/test.yml
Expand Up @@ -15,7 +15,8 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
node-version: 18
cache: npm
- run: npm ci
- run: npm run build
- run: npm test
2 changes: 1 addition & 1 deletion .github/workflows/update.yml
Expand Up @@ -11,7 +11,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
node-version: "lts/*"
cache: npm
- run: git checkout routes-update || true
- run: npm install @octokit/openapi-types@latest
Expand Down
24,213 changes: 6,067 additions & 18,146 deletions package-lock.json

Large diffs are not rendered by default.

29 changes: 2 additions & 27 deletions package.json
Expand Up @@ -9,7 +9,7 @@
"@octokit/openapi-types": "^18.0.0"
},
"scripts": {
"build": "pika-pack build",
"build": "node scripts/build.mjs && tsc -p tsconfig.json",
"docs": "typedoc --readme none --out docs src/index.ts && touch docs/.nojekyll",
"lint": "prettier --check \"{src,test,scripts}/**/*.{js,ts,json}\" README.md package.json !src/generated/* !scripts/update-endpoints/generated/*",
"lint:fix": "prettier --write \"{src,test,scripts}/**/*.{js,ts,json}\" README.md package.json !src/generated/* !scripts/update-endpoints/generated/*",
Expand All @@ -31,18 +31,14 @@
"author": "Gregor Martynus (https://twitter.com/gr2m)",
"license": "MIT",
"devDependencies": {
"@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",
"@octokit/tsconfig": "^1.0.2",
"@types/node": ">= 8",
"github-openapi-graphql-query": "^4.0.0",
"handlebars": "^4.7.6",
"json-schema-to-typescript": "^13.0.0",
"lodash.set": "^4.3.2",
"npm-run-all": "^4.1.5",
"pascal-case": "^3.1.1",
"pika-plugin-merge-properties": "^1.0.6",
"prettier": "^2.0.0",
"semantic-release": "^21.0.0",
"semantic-release-plugin-update-version-in-files": "^1.0.0",
Expand All @@ -51,27 +47,6 @@
"typedoc": "^0.24.0",
"typescript": "^5.0.0"
},
"@pika/pack": {
"pipeline": [
[
"@pika/plugin-ts-standard-pkg"
],
[
"pika-plugin-merge-properties",
{
"properties": {
"octokit": "see https://github.com/jabuco/pika-plugin-merge-properties/issues/2"
}
}
],
wolfy1339 marked this conversation as resolved.
Show resolved Hide resolved
[
"@pika/plugin-build-node"
],
[
"@pika/plugin-build-web"
]
]
},
"release": {
"branches": [
"+([0-9]).x",
Expand Down
37 changes: 37 additions & 0 deletions scripts/build.mjs
@@ -0,0 +1,37 @@
import { copyFile, readFile, writeFile, rm, mkdir } from "node:fs/promises";


async function main() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation needs fixing

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

npm run lint:fix reports correct indentation for me.

// Start with a clean slate
await rm("pkg", { recursive: true, force: true });
await mkdir("pkg");

// 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",
kfcampbell marked this conversation as resolved.
Show resolved Hide resolved
sideEffects: false,
},
null,
2
)
);
}
main();
6 changes: 3 additions & 3 deletions test.ts
Expand Up @@ -8,9 +8,9 @@ import {
} from "./src";

const endpoint = {} as EndpointInterface;
function assertString(type: string) {}
function assertNullableString(type: string | null | undefined) {}
function assertArray(type: unknown[]) {}
function assertString(_: string) {}
function assertNullableString(_: string | null | undefined) {}
function assertArray(_: unknown[]) {}
const assertPaginate = {} as {
<R extends Route>(route: R): Promise<void>;
<R extends RequestInterface>(request: R): Promise<void>;
Expand Down
13 changes: 8 additions & 5 deletions tsconfig.json
@@ -1,10 +1,13 @@
{
"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/**/*"]
"include": [
"src/**/*"
]
}
1 change: 1 addition & 0 deletions tsconfig.test.json
@@ -1,6 +1,7 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"emitDeclarationOnly": false,
"noEmit": true,
"declaration": true,
"noUnusedLocals": true
Expand Down