Skip to content

Commit

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

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

* refactor: use full relative path imports

* test: fix jest config
  • Loading branch information
wolfy1339 committed Dec 5, 2023
1 parent 29dd976 commit 04ee633
Show file tree
Hide file tree
Showing 15 changed files with 32 additions and 28 deletions.
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@
"tsconfig": "test/tsconfig.test.json"
}
]
},
"moduleNameMapper": {
"^(.+)\\.jsx?$": "$1"
}
},
"release": {
Expand Down
12 changes: 6 additions & 6 deletions scripts/update-endpoints/code.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ async function generateRoutes() {
writeFileSync(
ALL_ENDPOINTS_PATH,
await prettier.format(
`import type { EndpointsDefaultsAndDecorations } from "../types";
`import type { EndpointsDefaultsAndDecorations } from "../types.js";
const Endpoints: EndpointsDefaultsAndDecorations = ${JSON.stringify(
sortKeys(newRoutes, { deep: true })
)}
Expand All @@ -94,7 +94,7 @@ async function generateRoutes() {
writeFileSync(
ADMIN_ENDPOINTS_PATH,
await prettier.format(
`import type { EndpointsDefaultsAndDecorations } from "../types";
`import type { EndpointsDefaultsAndDecorations } from "../types.js";
const Endpoints: EndpointsDefaultsAndDecorations = ${JSON.stringify(
sortKeys({ enterpriseAdmin: newRoutes.enterpriseAdmin }, { deep: true })
)}
Expand All @@ -108,8 +108,8 @@ async function generateRoutes() {
const INDEX_PATH = pathResolve(process.cwd(), `src/index.ts`);
const imports = GHE_VERSIONS.map(
(version) => `
import ENDPOINTS_${version} from "./generated/ghe-${version}-endpoints";
import ADMIN_ENDPOINTS_${version} from "./generated/ghe-${version}-admin-endpoints";
import ENDPOINTS_${version} from "./generated/ghe-${version}-endpoints.js";
import ADMIN_ENDPOINTS_${version} from "./generated/ghe-${version}-admin-endpoints.js";
`
).join("\n");
const methods = GHE_VERSIONS.map(
Expand All @@ -132,8 +132,8 @@ async function generateRoutes() {
import { Octokit } from "@octokit/core";
import { VERSION } from "./version";
import { endpointsToMethods } from "./endpoints-to-methods";
import { VERSION } from "./version.js";
import { endpointsToMethods } from "./endpoints-to-methods.js";
${imports}
Expand Down
2 changes: 1 addition & 1 deletion src/endpoints-to-methods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type {
Route,
Url,
} from "@octokit/types";
import type { EndpointsDefaultsAndDecorations } from "./types";
import type { EndpointsDefaultsAndDecorations } from "./types.js";

type EndpointMethods = {
[methodName: string]: typeof Octokit.prototype.request;
Expand Down
2 changes: 1 addition & 1 deletion src/generated/ghe-310-admin-endpoints.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { EndpointsDefaultsAndDecorations } from "../types";
import type { EndpointsDefaultsAndDecorations } from "../types.js";
const Endpoints: EndpointsDefaultsAndDecorations = {
enterpriseAdmin: {
addAuthorizedSshKey: ["POST {origin}/setup/api/settings/authorized-keys"],
Expand Down
2 changes: 1 addition & 1 deletion src/generated/ghe-310-endpoints.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { EndpointsDefaultsAndDecorations } from "../types";
import type { EndpointsDefaultsAndDecorations } from "../types.js";
const Endpoints: EndpointsDefaultsAndDecorations = {
actions: {
addCustomLabelsToSelfHostedRunnerForOrg: [
Expand Down
2 changes: 1 addition & 1 deletion src/generated/ghe-37-admin-endpoints.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { EndpointsDefaultsAndDecorations } from "../types";
import type { EndpointsDefaultsAndDecorations } from "../types.js";
const Endpoints: EndpointsDefaultsAndDecorations = {
enterpriseAdmin: {
addAuthorizedSshKey: ["POST {origin}/setup/api/settings/authorized-keys"],
Expand Down
2 changes: 1 addition & 1 deletion src/generated/ghe-37-endpoints.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { EndpointsDefaultsAndDecorations } from "../types";
import type { EndpointsDefaultsAndDecorations } from "../types.js";
const Endpoints: EndpointsDefaultsAndDecorations = {
actions: {
addCustomLabelsToSelfHostedRunnerForOrg: [
Expand Down
2 changes: 1 addition & 1 deletion src/generated/ghe-38-admin-endpoints.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { EndpointsDefaultsAndDecorations } from "../types";
import type { EndpointsDefaultsAndDecorations } from "../types.js";
const Endpoints: EndpointsDefaultsAndDecorations = {
enterpriseAdmin: {
addAuthorizedSshKey: ["POST {origin}/setup/api/settings/authorized-keys"],
Expand Down
2 changes: 1 addition & 1 deletion src/generated/ghe-38-endpoints.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { EndpointsDefaultsAndDecorations } from "../types";
import type { EndpointsDefaultsAndDecorations } from "../types.js";
const Endpoints: EndpointsDefaultsAndDecorations = {
actions: {
addCustomLabelsToSelfHostedRunnerForOrg: [
Expand Down
2 changes: 1 addition & 1 deletion src/generated/ghe-39-admin-endpoints.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { EndpointsDefaultsAndDecorations } from "../types";
import type { EndpointsDefaultsAndDecorations } from "../types.js";
const Endpoints: EndpointsDefaultsAndDecorations = {
enterpriseAdmin: {
addAuthorizedSshKey: ["POST {origin}/setup/api/settings/authorized-keys"],
Expand Down
2 changes: 1 addition & 1 deletion src/generated/ghe-39-endpoints.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { EndpointsDefaultsAndDecorations } from "../types";
import type { EndpointsDefaultsAndDecorations } from "../types.js";
const Endpoints: EndpointsDefaultsAndDecorations = {
actions: {
addCustomLabelsToSelfHostedRunnerForOrg: [
Expand Down
20 changes: 10 additions & 10 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@

import { Octokit } from "@octokit/core";

import { VERSION } from "./version";
import { endpointsToMethods } from "./endpoints-to-methods";
import { VERSION } from "./version.js";
import { endpointsToMethods } from "./endpoints-to-methods.js";

import ENDPOINTS_37 from "./generated/ghe-37-endpoints";
import ADMIN_ENDPOINTS_37 from "./generated/ghe-37-admin-endpoints";
import ENDPOINTS_37 from "./generated/ghe-37-endpoints.js";
import ADMIN_ENDPOINTS_37 from "./generated/ghe-37-admin-endpoints.js";

import ENDPOINTS_38 from "./generated/ghe-38-endpoints";
import ADMIN_ENDPOINTS_38 from "./generated/ghe-38-admin-endpoints";
import ENDPOINTS_38 from "./generated/ghe-38-endpoints.js";
import ADMIN_ENDPOINTS_38 from "./generated/ghe-38-admin-endpoints.js";

import ENDPOINTS_39 from "./generated/ghe-39-endpoints";
import ADMIN_ENDPOINTS_39 from "./generated/ghe-39-admin-endpoints";
import ENDPOINTS_39 from "./generated/ghe-39-endpoints.js";
import ADMIN_ENDPOINTS_39 from "./generated/ghe-39-admin-endpoints.js";

import ENDPOINTS_310 from "./generated/ghe-310-endpoints";
import ADMIN_ENDPOINTS_310 from "./generated/ghe-310-admin-endpoints";
import ENDPOINTS_310 from "./generated/ghe-310-endpoints.js";
import ADMIN_ENDPOINTS_310 from "./generated/ghe-310-admin-endpoints.js";

export function enterpriseServer37Admin(octokit: Octokit) {
return endpointsToMethods(octokit, ADMIN_ENDPOINTS_37);
Expand Down
2 changes: 1 addition & 1 deletion test/enterprise-server.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fetchMock from "fetch-mock";
import { Octokit } from "@octokit/core";

import { enterpriseServer38Admin } from "../src";
import { enterpriseServer38Admin } from "../src/index.ts";

describe("enterpriseCloud plugin", () => {
it("README example", async () => {
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 { enterpriseServer38, enterpriseServer38Admin } from "../src";
import { enterpriseServer38, enterpriseServer38Admin } from "../src/index.ts";

describe("Smoke test", () => {
it("enterpriseServer35 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/**/*"]
}

0 comments on commit 04ee633

Please sign in to comment.