Skip to content

Commit

Permalink
refactor: use node: specifier imports and full relative imports (#385)
Browse files Browse the repository at this point in the history
This PR replaces NodeJS internal module imports with `node:` specifier
imports.
  • Loading branch information
wolfy1339 authored Nov 28, 2023
1 parent a21fe60 commit e08d332
Show file tree
Hide file tree
Showing 30 changed files with 36 additions and 32 deletions.
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"start-fixtures-server": "octokit-fixtures-server",
"pretest": "npm run -s lint",
"test": "jest --coverage",
"test:typescript": "npx tsc --noEmit --declaration --noUnusedLocals test/typescript-validate.ts"
"test:typescript": "npx tsc --noEmit --declaration --allowImportingTsExtensions --moduleResolution node16 --module node16 --noUnusedLocals test/typescript-validate.ts"
},
"license": "MIT",
"jest": {
Expand All @@ -87,6 +87,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/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { paginateRest } from "@octokit/plugin-paginate-rest";
import { legacyRestEndpointMethods } from "@octokit/plugin-rest-endpoint-methods";
export type { RestEndpointMethodTypes } from "@octokit/plugin-rest-endpoint-methods";

import { VERSION } from "./version";
import { VERSION } from "./version.js";

export const Octokit = Core.plugin(
requestLog,
Expand Down
4 changes: 2 additions & 2 deletions test/integration/agent-ca/agent-ca-test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { readFileSync } = require("fs");
const { resolve } = require("path");
const { readFileSync } = require("node:fs");
const { resolve } = require("node:path");
const { fetch: undiciFetch, Agent } = require("undici");

const { Octokit } = require("../../..");
Expand Down
2 changes: 1 addition & 1 deletion test/integration/smoke.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fetchMock from "fetch-mock";

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

describe("Smoke tests", () => {
it("is a function", () => {
Expand Down
2 changes: 1 addition & 1 deletion test/issues/881-redirect-url.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fetchMock from "fetch-mock";

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

describe("https://github.com/octokit/rest.js/issues/881", () => {
it("returns response.url", () => {
Expand Down
2 changes: 1 addition & 1 deletion test/memory-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// as installing leakage broke for recent Node versions.
// We are looking for an alternative.
const { iterate } = require("leakage");
const { Octokit } = require("../pkg");
const { Octokit } = require("../pkg/index.js");

const TestOctokit = Octokit.plugin((octokit) => {
// skip sending requests altogether
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { loadFixture, fixtureToInstance, OctokitType } from "../util";
import { loadFixture, fixtureToInstance, OctokitType } from "../util.ts";

describe("api.github.com", () => {
let githubUserA: OctokitType;
Expand Down
2 changes: 1 addition & 1 deletion test/scenarios/add-labels-to-issue.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getInstance, OctokitType } from "../util";
import { getInstance, OctokitType } from "../util.ts";

describe("api.github.com", () => {
let octokit: OctokitType;
Expand Down
2 changes: 1 addition & 1 deletion test/scenarios/branch-protection.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getInstance, OctokitType } from "../util";
import { getInstance, OctokitType } from "../util.ts";

describe("api.github.com", () => {
let octokit: OctokitType;
Expand Down
2 changes: 1 addition & 1 deletion test/scenarios/create-file.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const btoa = require("btoa-lite");

import { getInstance, OctokitType } from "../util";
import { getInstance, OctokitType } from "../util.ts";

describe("api.github.com", () => {
let octokit: OctokitType;
Expand Down
2 changes: 1 addition & 1 deletion test/scenarios/create-status.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getInstance, OctokitType } from "../util";
import { getInstance, OctokitType } from "../util.ts";

describe("api.github.com", () => {
let octokit: OctokitType;
Expand Down
2 changes: 1 addition & 1 deletion test/scenarios/errors.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getInstance, OctokitType } from "../util";
import { getInstance, OctokitType } from "../util.ts";

describe("api.github.com", () => {
let octokit: OctokitType;
Expand Down
2 changes: 1 addition & 1 deletion test/scenarios/get-archive.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getInstance, OctokitType } from "../util";
import { getInstance, OctokitType } from "../util.ts";

describe("api.github.com", () => {
let octokit: OctokitType;
Expand Down
2 changes: 1 addition & 1 deletion test/scenarios/get-content.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getInstance, OctokitType } from "../util";
import { getInstance, OctokitType } from "../util.ts";

describe("api.github.com", () => {
let octokit: OctokitType;
Expand Down
2 changes: 1 addition & 1 deletion test/scenarios/get-organization.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getInstance, OctokitType } from "../util";
import { getInstance, OctokitType } from "../util.ts";

describe("api.github.com", () => {
let octokit: OctokitType;
Expand Down
2 changes: 1 addition & 1 deletion test/scenarios/get-repository.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getInstance, OctokitType } from "../util";
import { getInstance, OctokitType } from "../util.ts";

describe("api.github.com", () => {
let octokit: OctokitType;
Expand Down
2 changes: 1 addition & 1 deletion test/scenarios/labels.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getInstance, OctokitType } from "../util";
import { getInstance, OctokitType } from "../util.ts";

describe("api.github.com", () => {
let octokit: OctokitType;
Expand Down
2 changes: 1 addition & 1 deletion test/scenarios/lock-issue.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getInstance, OctokitType } from "../util";
import { getInstance, OctokitType } from "../util.ts";

describe("api.github.com", () => {
let octokit: OctokitType;
Expand Down
2 changes: 1 addition & 1 deletion test/scenarios/mark-notifications-as-read.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getInstance, OctokitType } from "../util";
import { getInstance, OctokitType } from "../util.ts";

describe("api.github.com", () => {
let octokit: OctokitType;
Expand Down
2 changes: 1 addition & 1 deletion test/scenarios/markdown.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getInstance, OctokitType } from "../util";
import { getInstance, OctokitType } from "../util.ts";

describe("api.github.com", () => {
let octokit: OctokitType;
Expand Down
2 changes: 1 addition & 1 deletion test/scenarios/paginate-issues-async-await.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// this file is not run directly but instead required in paginate-issues-test.js
// for Node v10 and higher only

import { getInstance, OctokitType } from "../util";
import { getInstance, OctokitType } from "../util.ts";

describe("api.github.com", () => {
let octokit: OctokitType;
Expand Down
2 changes: 1 addition & 1 deletion test/scenarios/paginate-issues.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getInstance, OctokitType } from "../util";
import { getInstance, OctokitType } from "../util.ts";

type IteratorResult = {
value: {
Expand Down
2 changes: 1 addition & 1 deletion test/scenarios/project-cards.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getInstance, OctokitType } from "../util";
import { getInstance, OctokitType } from "../util.ts";

describe("api.github.com", () => {
let octokit: OctokitType;
Expand Down
2 changes: 1 addition & 1 deletion test/scenarios/release-assets.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getInstance, OctokitType } from "../util";
import { getInstance, OctokitType } from "../util.ts";

describe("api.github.com", () => {
let octokit: OctokitType;
Expand Down
2 changes: 1 addition & 1 deletion test/scenarios/rename-repository.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getInstance, OctokitType } from "../util";
import { getInstance, OctokitType } from "../util.ts";

describe("api.github.com", () => {
let octokit: OctokitType;
Expand Down
2 changes: 1 addition & 1 deletion test/scenarios/search-issues.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getInstance, OctokitType } from "../util";
import { getInstance, OctokitType } from "../util.ts";

describe("api.github.com", () => {
let octokit: OctokitType;
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/**/*"]
}
4 changes: 2 additions & 2 deletions test/typescript-validate.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Agent } from "http";
import { Agent } from "node:http";

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

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

// ************************************************************
// THIS CODE IS NOT EXECUTED. IT IS JUST FOR TYPECHECKING
Expand Down
2 changes: 1 addition & 1 deletion test/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

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

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

type Unpacked<T> = T extends (infer U)[]
? U
Expand Down

0 comments on commit e08d332

Please sign in to comment.