Skip to content

Commit e08d332

Browse files
authored
refactor: use node: specifier imports and full relative imports (#385)
This PR replaces NodeJS internal module imports with `node:` specifier imports.
1 parent a21fe60 commit e08d332

30 files changed

+36
-32
lines changed

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
"start-fixtures-server": "octokit-fixtures-server",
6666
"pretest": "npm run -s lint",
6767
"test": "jest --coverage",
68-
"test:typescript": "npx tsc --noEmit --declaration --noUnusedLocals test/typescript-validate.ts"
68+
"test:typescript": "npx tsc --noEmit --declaration --allowImportingTsExtensions --moduleResolution node16 --module node16 --noUnusedLocals test/typescript-validate.ts"
6969
},
7070
"license": "MIT",
7171
"jest": {
@@ -87,6 +87,9 @@
8787
"functions": 100,
8888
"lines": 100
8989
}
90+
},
91+
"moduleNameMapper": {
92+
"^(.+)\\.jsx?$": "$1"
9093
}
9194
},
9295
"release": {

scripts/build.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// @ts-check
22
import esbuild from "esbuild";
3-
import { copyFile, readFile, writeFile, rm } from "fs/promises";
3+
import { copyFile, readFile, writeFile, rm } from "node:fs/promises";
44
import { glob } from "glob";
55

66
/**

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { paginateRest } from "@octokit/plugin-paginate-rest";
44
import { legacyRestEndpointMethods } from "@octokit/plugin-rest-endpoint-methods";
55
export type { RestEndpointMethodTypes } from "@octokit/plugin-rest-endpoint-methods";
66

7-
import { VERSION } from "./version";
7+
import { VERSION } from "./version.js";
88

99
export const Octokit = Core.plugin(
1010
requestLog,

test/integration/agent-ca/agent-ca-test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const { readFileSync } = require("fs");
2-
const { resolve } = require("path");
1+
const { readFileSync } = require("node:fs");
2+
const { resolve } = require("node:path");
33
const { fetch: undiciFetch, Agent } = require("undici");
44

55
const { Octokit } = require("../../..");

test/integration/smoke.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import fetchMock from "fetch-mock";
22

3-
import { Octokit } from "../../src";
3+
import { Octokit } from "../../src/index.ts";
44

55
describe("Smoke tests", () => {
66
it("is a function", () => {

test/issues/881-redirect-url.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import fetchMock from "fetch-mock";
22

3-
import { Octokit } from "../../src";
3+
import { Octokit } from "../../src/index.ts";
44

55
describe("https://github.com/octokit/rest.js/issues/881", () => {
66
it("returns response.url", () => {

test/memory-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// as installing leakage broke for recent Node versions.
33
// We are looking for an alternative.
44
const { iterate } = require("leakage");
5-
const { Octokit } = require("../pkg");
5+
const { Octokit } = require("../pkg/index.js");
66

77
const TestOctokit = Octokit.plugin((octokit) => {
88
// skip sending requests altogether

test/scenarios/add-and-remove-repository-collaborator.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { loadFixture, fixtureToInstance, OctokitType } from "../util";
1+
import { loadFixture, fixtureToInstance, OctokitType } from "../util.ts";
22

33
describe("api.github.com", () => {
44
let githubUserA: OctokitType;

test/scenarios/add-labels-to-issue.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getInstance, OctokitType } from "../util";
1+
import { getInstance, OctokitType } from "../util.ts";
22

33
describe("api.github.com", () => {
44
let octokit: OctokitType;

test/scenarios/branch-protection.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getInstance, OctokitType } from "../util";
1+
import { getInstance, OctokitType } from "../util.ts";
22

33
describe("api.github.com", () => {
44
let octokit: OctokitType;

test/scenarios/create-file.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const btoa = require("btoa-lite");
22

3-
import { getInstance, OctokitType } from "../util";
3+
import { getInstance, OctokitType } from "../util.ts";
44

55
describe("api.github.com", () => {
66
let octokit: OctokitType;

test/scenarios/create-status.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getInstance, OctokitType } from "../util";
1+
import { getInstance, OctokitType } from "../util.ts";
22

33
describe("api.github.com", () => {
44
let octokit: OctokitType;

test/scenarios/errors.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getInstance, OctokitType } from "../util";
1+
import { getInstance, OctokitType } from "../util.ts";
22

33
describe("api.github.com", () => {
44
let octokit: OctokitType;

test/scenarios/get-archive.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getInstance, OctokitType } from "../util";
1+
import { getInstance, OctokitType } from "../util.ts";
22

33
describe("api.github.com", () => {
44
let octokit: OctokitType;

test/scenarios/get-content.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getInstance, OctokitType } from "../util";
1+
import { getInstance, OctokitType } from "../util.ts";
22

33
describe("api.github.com", () => {
44
let octokit: OctokitType;

test/scenarios/get-organization.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getInstance, OctokitType } from "../util";
1+
import { getInstance, OctokitType } from "../util.ts";
22

33
describe("api.github.com", () => {
44
let octokit: OctokitType;

test/scenarios/get-repository.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getInstance, OctokitType } from "../util";
1+
import { getInstance, OctokitType } from "../util.ts";
22

33
describe("api.github.com", () => {
44
let octokit: OctokitType;

test/scenarios/labels.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getInstance, OctokitType } from "../util";
1+
import { getInstance, OctokitType } from "../util.ts";
22

33
describe("api.github.com", () => {
44
let octokit: OctokitType;

test/scenarios/lock-issue.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getInstance, OctokitType } from "../util";
1+
import { getInstance, OctokitType } from "../util.ts";
22

33
describe("api.github.com", () => {
44
let octokit: OctokitType;

test/scenarios/mark-notifications-as-read.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getInstance, OctokitType } from "../util";
1+
import { getInstance, OctokitType } from "../util.ts";
22

33
describe("api.github.com", () => {
44
let octokit: OctokitType;

test/scenarios/markdown.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getInstance, OctokitType } from "../util";
1+
import { getInstance, OctokitType } from "../util.ts";
22

33
describe("api.github.com", () => {
44
let octokit: OctokitType;

test/scenarios/paginate-issues-async-await.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// this file is not run directly but instead required in paginate-issues-test.js
22
// for Node v10 and higher only
33

4-
import { getInstance, OctokitType } from "../util";
4+
import { getInstance, OctokitType } from "../util.ts";
55

66
describe("api.github.com", () => {
77
let octokit: OctokitType;

test/scenarios/paginate-issues.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getInstance, OctokitType } from "../util";
1+
import { getInstance, OctokitType } from "../util.ts";
22

33
type IteratorResult = {
44
value: {

test/scenarios/project-cards.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getInstance, OctokitType } from "../util";
1+
import { getInstance, OctokitType } from "../util.ts";
22

33
describe("api.github.com", () => {
44
let octokit: OctokitType;

test/scenarios/release-assets.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getInstance, OctokitType } from "../util";
1+
import { getInstance, OctokitType } from "../util.ts";
22

33
describe("api.github.com", () => {
44
let octokit: OctokitType;

test/scenarios/rename-repository.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getInstance, OctokitType } from "../util";
1+
import { getInstance, OctokitType } from "../util.ts";
22

33
describe("api.github.com", () => {
44
let octokit: OctokitType;

test/scenarios/search-issues.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getInstance, OctokitType } from "../util";
1+
import { getInstance, OctokitType } from "../util.ts";
22

33
describe("api.github.com", () => {
44
let octokit: OctokitType;

test/tsconfig.test.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
"compilerOptions": {
44
"emitDeclarationOnly": false,
55
"noEmit": true,
6-
"verbatimModuleSyntax": false
6+
"verbatimModuleSyntax": false,
7+
"allowImportingTsExtensions": true
78
},
89
"include": ["src/**/*"]
910
}

test/typescript-validate.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { Agent } from "http";
1+
import { Agent } from "node:http";
22

33
import { EndpointDefaults } from "@octokit/types";
44

5-
import { Octokit, RestEndpointMethodTypes } from "../src";
5+
import { Octokit, RestEndpointMethodTypes } from "../src/index.ts";
66

77
// ************************************************************
88
// THIS CODE IS NOT EXECUTED. IT IS JUST FOR TYPECHECKING

test/util.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import { request } from "@octokit/request";
44

5-
import { Octokit } from "../src";
5+
import { Octokit } from "../src/index.ts";
66

77
type Unpacked<T> = T extends (infer U)[]
88
? U

0 commit comments

Comments
 (0)