Skip to content

Commit

Permalink
fix(build): use typescript to produce declaration files (#550)
Browse files Browse the repository at this point in the history
Co-authored-by: wolfy1339 <4595477+wolfy1339@users.noreply.github.com>
  • Loading branch information
kfcampbell and wolfy1339 committed Jun 13, 2023
1 parent 2b10252 commit 9953e34
Show file tree
Hide file tree
Showing 8 changed files with 6,118 additions and 18,183 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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"
}
}
],
[
"@pika/plugin-build-node"
],
[
"@pika/plugin-build-web"
]
]
},
"release": {
"branches": [
"+([0-9]).x",
Expand Down
34 changes: 34 additions & 0 deletions scripts/build.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { copyFile, readFile, writeFile, rm, mkdir } from "node:fs/promises";


async function main() {
// 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-types/**"],
types: "dist-types/index.d.ts",
sideEffects: false,
},
null,
2
)
);
}
main();
6 changes: 3 additions & 3 deletions test.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"emitDeclarationOnly": false,
"noEmit": true,
"declaration": true,
"noUnusedLocals": true
Expand Down

0 comments on commit 9953e34

Please sign in to comment.