Skip to content

Commit

Permalink
refactor: use node: specifier imports and full relative paths in im…
Browse files Browse the repository at this point in the history
…ports (#699)

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

* refactor: use full relative paths in imports
  • Loading branch information
wolfy1339 committed Nov 28, 2023
1 parent 03da512 commit 7355fcf
Show file tree
Hide file tree
Showing 15 changed files with 33 additions and 26 deletions.
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@
"functions": 100,
"lines": 100
}
},
"moduleNameMapper": {
"^(.+)\\.jsx?$": "$1"
}
},
"release": {
Expand Down
8 changes: 4 additions & 4 deletions scripts/update-endpoints/code.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { readFileSync, writeFileSync } from "fs";
import { join } from "path";
import { fileURLToPath } from "url";
import { readFileSync, writeFileSync } from "node:fs";
import { join } from "node:path";
import { fileURLToPath } from "node:url";

import { format } from "prettier";
import sortKeys from "sort-keys";
Expand Down Expand Up @@ -123,7 +123,7 @@ async function generateRoutes() {
writeFileSync(
ROUTES_PATH,
await format(
`import type { EndpointsDefaultsAndDecorations } from "../types";
`import type { EndpointsDefaultsAndDecorations } from "../types.js";
const Endpoints: EndpointsDefaultsAndDecorations = ${JSON.stringify(
sortKeys(newRoutes, { deep: true }),
)}
Expand Down
2 changes: 1 addition & 1 deletion scripts/update-endpoints/docs.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { format } from "prettier";

import { isDeprecated } from "./util.mjs";
import { readFileSync, mkdirSync, writeFileSync } from "fs";
import { readFileSync, mkdirSync, writeFileSync } from "node:fs";

const ENDPOINTS = JSON.parse(
readFileSync(
Expand Down
6 changes: 3 additions & 3 deletions scripts/update-endpoints/fetch-json.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { writeFileSync } from "fs";
import { resolve } from "path";
import { fileURLToPath } from "url";
import { writeFileSync } from "node:fs";
import { resolve } from "node:path";
import { fileURLToPath } from "node:url";

import graphql from "github-openapi-graphql-query";
import { format } from "prettier";
Expand Down
4 changes: 2 additions & 2 deletions scripts/update-endpoints/types.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { writeFileSync, readFileSync } from "fs";
import { join as pathJoin } from "path";
import { writeFileSync, readFileSync } from "node:fs";
import { join as pathJoin } from "node:path";

import camelCase from "lodash.camelcase";
import { format } from "prettier";
Expand Down
6 changes: 3 additions & 3 deletions src/endpoints-to-methods.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { Octokit } from "@octokit/core";
import type { EndpointOptions, RequestParameters, Route } from "@octokit/types";
import ENDPOINTS from "./generated/endpoints";
import type { RestEndpointMethods } from "./generated/method-types";
import type { EndpointDecorations } from "./types";
import ENDPOINTS from "./generated/endpoints.js";
import type { RestEndpointMethods } from "./generated/method-types.js";
import type { EndpointDecorations } from "./types.js";

// The following code was refactored in: https://github.com/octokit/plugin-rest-endpoint-methods.js/pull/622
// to optimise the runtime performance of Octokit initialization.
Expand Down
2 changes: 1 addition & 1 deletion src/generated/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/method-types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { EndpointInterface, RequestInterface } from "@octokit/types";
import type { RestEndpointMethodTypes } from "./parameters-and-response-types";
import type { RestEndpointMethodTypes } from "./parameters-and-response-types.js";

export type RestEndpointMethods = {
actions: {
Expand Down
8 changes: 4 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { Octokit } from "@octokit/core";

export type { RestEndpointMethodTypes } from "./generated/parameters-and-response-types";
import { VERSION } from "./version";
import type { Api } from "./types";
import { endpointsToMethods } from "./endpoints-to-methods";
export type { RestEndpointMethodTypes } from "./generated/parameters-and-response-types.js";
import { VERSION } from "./version.js";
import type { Api } from "./types.js";
import { endpointsToMethods } from "./endpoints-to-methods.js";

export function restEndpointMethods(octokit: Octokit): Api {
const api = endpointsToMethods(octokit);
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Route, RequestParameters } from "@octokit/types";

import type { RestEndpointMethods } from "./generated/method-types";
import type { RestEndpointMethods } from "./generated/method-types.js";

export type Api = { rest: RestEndpointMethods };

Expand Down
2 changes: 1 addition & 1 deletion test/issues.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 { restEndpointMethods } from "../src";
import { restEndpointMethods } from "../src/index.ts";

describe("https://github.com/octokit/plugin-rest-endpoint-methods.js/issues/83", () => {
it("git.gists.update({ gist_id, files })", async () => {
Expand Down
7 changes: 5 additions & 2 deletions test/rest-endpoint-methods.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ import { Octokit } from "@octokit/core";
import fetchMock from "fetch-mock";

import sinon from "sinon";
import { legacyRestEndpointMethods, restEndpointMethods } from "../src";
import { Api } from "../src/types";
import {
legacyRestEndpointMethods,
restEndpointMethods,
} from "../src/index.ts";
import { Api } from "../src/types.ts";

describe("REST API endpoint methods", () => {
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 { restEndpointMethods } from "../src";
import { restEndpointMethods } from "../src/index.ts";

describe("Smoke test", () => {
it("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.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Octokit } from "@octokit/core";
import { RestEndpointMethodTypes, restEndpointMethods } from "../src";
import { RestEndpointMethodTypes, restEndpointMethods } from "../src/index.ts";

describe("Smoke test", () => {
it("Get parameters type for octokit.rest.issues.updateLabel()", async () => {
Expand Down

0 comments on commit 7355fcf

Please sign in to comment.