Skip to content

Commit

Permalink
refactor: use node: specifier imports and full relative path imports (
Browse files Browse the repository at this point in the history
#2583)

* refactor: replace NodeJS internal module imports with `node:` specifier imports

* refactor: use full relative path imports

* chore: remove comment, it seems like a fluke

---------

Co-authored-by: Nick Floyd <139819+nickfloyd@users.noreply.github.com>
  • Loading branch information
wolfy1339 and nickfloyd authored Dec 1, 2023
1 parent 2cba0ea commit a8afe8c
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 16 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 scripts/build.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @ts-check
import esbuild from "esbuild";
import { copyFile, readFile, writeFile, rm } from "fs/promises";
import { copyFile, readFile, writeFile, rm } from "node:fs/promises";
import { glob } from "glob";

/**
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";
19 changes: 14 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 @@ -27,8 +28,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 +48,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 +63,3 @@ function onSecondaryRateLimit(retryAfter: number, options: any, octokit: any) {
return true;
}
}

export type Octokit = InstanceType<typeof Octokit>;
4 changes: 2 additions & 2 deletions test/app.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { createServer } from "http";
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 a8afe8c

Please sign in to comment.