Skip to content

Commit

Permalink
refactor: use full relative path imports
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfy1339 committed Dec 1, 2023
1 parent aa1372e commit 326dde8
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 14 deletions.
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"lint:fix": "prettier --write \"{src,test}/**/*.{js,json,ts}\" \"*.{md,json}\"",
"pretest": "npm run -s lint",
"test": "jest --coverage",
"test:typescript": "npx tsc --noEmit --declaration --noUnusedLocals --esModuleInterop --strict test/typescript-validate.ts"
"test:typescript": "npx tsc --noEmit --declaration --noUnusedLocals --esModuleInterop --strict --allowImportingTsExtensions test/typescript-validate.ts"
},
"dependencies": {
"@octokit/app": "^14.0.2",
Expand Down Expand Up @@ -65,6 +65,9 @@
"functions": 100,
"lines": 100
}
},
"moduleNameMapper": {
"^(.+)\\.jsx?$": "$1"
}
},
"release": {
Expand Down
2 changes: 1 addition & 1 deletion src/app.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { App as DefaultApp } from "@octokit/app";
import { OAuthApp as DefaultOAuthApp } from "@octokit/oauth-app";

import { Octokit } from "./octokit";
import { Octokit } from "./octokit.js";

export const App = DefaultApp.defaults({ Octokit });
export type App = InstanceType<typeof App>;
Expand Down
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export { Octokit, RequestError } from "./octokit";
export type { PageInfoForward, PageInfoBackward } from "./octokit";
export { App, OAuthApp, createNodeMiddleware } from "./app";
export { Octokit, RequestError } from "./octokit.js";
export type { PageInfoForward, PageInfoBackward } from "./octokit.js";
export { App, OAuthApp, createNodeMiddleware } from "./app.js";
22 changes: 17 additions & 5 deletions src/octokit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import { restEndpointMethods } from "@octokit/plugin-rest-endpoint-methods";
import { retry } from "@octokit/plugin-retry";
import { throttling } from "@octokit/plugin-throttling";

import { VERSION } from "./version";
import { VERSION } from "./version.js";
import type { EndpointDefaults } from "@octokit/types";

export { RequestError } from "@octokit/request-error";
export type {
Expand All @@ -14,6 +15,9 @@ export type {
} from "@octokit/plugin-paginate-graphql";

export const Octokit = OctokitCore.plugin(
// There is a problem with TypeScript type hints when using the restEndpointMethods plugin along with the throttling plugin.
// It is safe to ignore.
// Using any method to make the "error" go away, will cause a real error in tests and the build.
restEndpointMethods,
paginateRest,
paginateGraphql,
Expand All @@ -27,8 +31,14 @@ export const Octokit = OctokitCore.plugin(
},
});

export type Octokit = InstanceType<typeof Octokit>;

// istanbul ignore next no need to test internals of the throttle plugin
function onRateLimit(retryAfter: number, options: any, octokit: any) {
function onRateLimit(
retryAfter: number,
options: Required<EndpointDefaults>,
octokit: InstanceType<typeof OctokitCore>,
) {
octokit.log.warn(
`Request quota exhausted for request ${options.method} ${options.url}`,
);
Expand All @@ -41,7 +51,11 @@ function onRateLimit(retryAfter: number, options: any, octokit: any) {
}

// istanbul ignore next no need to test internals of the throttle plugin
function onSecondaryRateLimit(retryAfter: number, options: any, octokit: any) {
function onSecondaryRateLimit(
retryAfter: number,
options: Required<EndpointDefaults>,
octokit: InstanceType<typeof OctokitCore>,
) {
octokit.log.warn(
`SecondaryRateLimit detected for request ${options.method} ${options.url}`,
);
Expand All @@ -52,5 +66,3 @@ function onSecondaryRateLimit(retryAfter: number, options: any, octokit: any) {
return true;
}
}

export type Octokit = InstanceType<typeof Octokit>;
2 changes: 1 addition & 1 deletion test/app.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { createServer } from "node:http";
import fetchMock from "fetch-mock";
import MockDate from "mockdate";

import { App, Octokit, createNodeMiddleware } from "../src";
import { App, Octokit, createNodeMiddleware } from "../src/index.ts";

const APP_ID = 1;
const PRIVATE_KEY = `-----BEGIN RSA PRIVATE KEY-----
Expand Down
2 changes: 1 addition & 1 deletion test/smoke.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Octokit, App, OAuthApp, RequestError } from "../src";
import { Octokit, App, OAuthApp, RequestError } from "../src/index.ts";

describe("Smoke tests", () => {
it("Octokit is a function", () => {
Expand Down
3 changes: 2 additions & 1 deletion test/tsconfig.test.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"compilerOptions": {
"emitDeclarationOnly": false,
"noEmit": true,
"verbatimModuleSyntax": false
"verbatimModuleSyntax": false,
"allowImportingTsExtensions": true
},
"include": ["src/**/*"]
}
2 changes: 1 addition & 1 deletion test/typescript-validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// THIS CODE IS NOT EXECUTED. IT IS JUST FOR TYPECHECKING
// ************************************************************

import { App, OAuthApp, Octokit, RequestError } from "../src";
import { App, OAuthApp, Octokit, RequestError } from "../src/index.ts";

function expect<T>(what: T) {}

Expand Down

0 comments on commit 326dde8

Please sign in to comment.