Skip to content

Commit 9953e34

Browse files
fix(build): use typescript to produce declaration files (#550)
Co-authored-by: wolfy1339 <[email protected]>
1 parent 2b10252 commit 9953e34

File tree

8 files changed

+6118
-18183
lines changed

8 files changed

+6118
-18183
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ jobs:
1515
- uses: actions/checkout@v3
1616
- uses: actions/setup-node@v3
1717
with:
18-
node-version: 16
18+
node-version: 18
1919
cache: npm
2020
- run: npm ci
21+
- run: npm run build
2122
- run: npm test

.github/workflows/update.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
- uses: actions/checkout@v3
1212
- uses: actions/setup-node@v3
1313
with:
14-
node-version: 16
14+
node-version: "lts/*"
1515
cache: npm
1616
- run: git checkout routes-update || true
1717
- run: npm install @octokit/openapi-types@latest

package-lock.json

Lines changed: 6067 additions & 18146 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"@octokit/openapi-types": "^18.0.0"
1010
},
1111
"scripts": {
12-
"build": "pika-pack build",
12+
"build": "node scripts/build.mjs && tsc -p tsconfig.json",
1313
"docs": "typedoc --readme none --out docs src/index.ts && touch docs/.nojekyll",
1414
"lint": "prettier --check \"{src,test,scripts}/**/*.{js,ts,json}\" README.md package.json !src/generated/* !scripts/update-endpoints/generated/*",
1515
"lint:fix": "prettier --write \"{src,test,scripts}/**/*.{js,ts,json}\" README.md package.json !src/generated/* !scripts/update-endpoints/generated/*",
@@ -31,18 +31,14 @@
3131
"author": "Gregor Martynus (https://twitter.com/gr2m)",
3232
"license": "MIT",
3333
"devDependencies": {
34-
"@pika/pack": "^0.3.7",
35-
"@pika/plugin-build-node": "^0.9.0",
36-
"@pika/plugin-build-web": "^0.9.0",
37-
"@pika/plugin-ts-standard-pkg": "^0.9.0",
34+
"@octokit/tsconfig": "^1.0.2",
3835
"@types/node": ">= 8",
3936
"github-openapi-graphql-query": "^4.0.0",
4037
"handlebars": "^4.7.6",
4138
"json-schema-to-typescript": "^13.0.0",
4239
"lodash.set": "^4.3.2",
4340
"npm-run-all": "^4.1.5",
4441
"pascal-case": "^3.1.1",
45-
"pika-plugin-merge-properties": "^1.0.6",
4642
"prettier": "^2.0.0",
4743
"semantic-release": "^21.0.0",
4844
"semantic-release-plugin-update-version-in-files": "^1.0.0",
@@ -51,27 +47,6 @@
5147
"typedoc": "^0.24.0",
5248
"typescript": "^5.0.0"
5349
},
54-
"@pika/pack": {
55-
"pipeline": [
56-
[
57-
"@pika/plugin-ts-standard-pkg"
58-
],
59-
[
60-
"pika-plugin-merge-properties",
61-
{
62-
"properties": {
63-
"octokit": "see https://github.com/jabuco/pika-plugin-merge-properties/issues/2"
64-
}
65-
}
66-
],
67-
[
68-
"@pika/plugin-build-node"
69-
],
70-
[
71-
"@pika/plugin-build-web"
72-
]
73-
]
74-
},
7550
"release": {
7651
"branches": [
7752
"+([0-9]).x",

scripts/build.mjs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { copyFile, readFile, writeFile, rm, mkdir } from "node:fs/promises";
2+
3+
4+
async function main() {
5+
// Start with a clean slate
6+
await rm("pkg", { recursive: true, force: true });
7+
await mkdir("pkg");
8+
9+
// Copy the README, LICENSE to the pkg folder
10+
await copyFile("LICENSE", "pkg/LICENSE");
11+
await copyFile("README.md", "pkg/README.md");
12+
13+
// Handle the package.json
14+
let pkg = JSON.parse((await readFile("package.json", "utf8")).toString());
15+
// Remove unnecessary fields from the package.json
16+
delete pkg.scripts;
17+
delete pkg.prettier;
18+
delete pkg.release;
19+
delete pkg.jest;
20+
await writeFile(
21+
"pkg/package.json",
22+
JSON.stringify(
23+
{
24+
...pkg,
25+
files: ["dist-types/**"],
26+
types: "dist-types/index.d.ts",
27+
sideEffects: false,
28+
},
29+
null,
30+
2
31+
)
32+
);
33+
}
34+
main();

test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ import {
88
} from "./src";
99

1010
const endpoint = {} as EndpointInterface;
11-
function assertString(type: string) {}
12-
function assertNullableString(type: string | null | undefined) {}
13-
function assertArray(type: unknown[]) {}
11+
function assertString(_: string) {}
12+
function assertNullableString(_: string | null | undefined) {}
13+
function assertArray(_: unknown[]) {}
1414
const assertPaginate = {} as {
1515
<R extends Route>(route: R): Promise<void>;
1616
<R extends RequestInterface>(request: R): Promise<void>;

tsconfig.json

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
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": ["src/**/*"]
10+
"include": [
11+
"src/**/*"
12+
]
1013
}

tsconfig.test.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"extends": "./tsconfig.json",
33
"compilerOptions": {
4+
"emitDeclarationOnly": false,
45
"noEmit": true,
56
"declaration": true,
67
"noUnusedLocals": true

0 commit comments

Comments
 (0)