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
#640)

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

* refactor: use full relative import paths
  • Loading branch information
wolfy1339 committed Dec 1, 2023
1 parent 3015ef0 commit 0e41096
Show file tree
Hide file tree
Showing 18 changed files with 30 additions and 26 deletions.
5 changes: 4 additions & 1 deletion package.json
Expand Up @@ -11,7 +11,7 @@
"lint:fix": "prettier --write '{src,test}/**/*.{ts,md}' README.md package.json",
"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 --noUnusedLocals --allowImportingTsExtensions test/typescript-validate.ts"
},
"repository": "github:octokit/core.js",
"keywords": [
Expand Down Expand Up @@ -72,6 +72,9 @@
"functions": 100,
"lines": 100
}
},
"moduleNameMapper": {
"^(.+)\\.jsx?$": "$1"
}
},
"release": {
Expand Down
2 changes: 1 addition & 1 deletion scripts/build.mjs
@@ -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
4 changes: 2 additions & 2 deletions src/index.ts
Expand Up @@ -13,8 +13,8 @@ import type {
RequestParameters,
ReturnTypeOf,
UnionToIntersection,
} from "./types";
import { VERSION } from "./version";
} from "./types.js";
import { VERSION } from "./version.js";

const noop = () => {};
const consoleWarn = console.warn.bind(console);
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
@@ -1,7 +1,7 @@
import * as OctokitTypes from "@octokit/types";
import { RequestError } from "@octokit/request-error";

import { Octokit } from ".";
import type { Octokit } from "./index.js";

export type RequestParameters = OctokitTypes.RequestParameters;

Expand Down
8 changes: 4 additions & 4 deletions test/agent-ca/agent-ca-test.test.ts
@@ -1,9 +1,9 @@
import { createServer, type Server } from "https";
import { readFileSync } from "fs";
import { resolve } from "path";
import { createServer, type Server } from "node:https";
import { readFileSync } from "node:fs";
import { resolve } from "node:path";
import { fetch as undiciFetch, Agent } from "undici";
import { request } from "@octokit/request";
import { type AddressInfo } from "net";
import { type AddressInfo } from "node:net";

const ca = readFileSync(resolve(__dirname, "./ca.crt"));

Expand Down
6 changes: 3 additions & 3 deletions test/agent-proxy/agent-proxy-test.test.ts
Expand Up @@ -9,11 +9,11 @@
* https://github.com/nodejs/undici/blob/512cdadc403874571cd5035a6c41debab1165310/test/proxy-agent.js#L370-L418
* Released under the MIT license
*/
import { Server, createServer } from "http";
import { type AddressInfo } from "net";
import { Server, createServer } from "node:http";
import { type AddressInfo } from "node:net";
import { ProxyServer, createProxy } from "proxy";
import { ProxyAgent, fetch as undiciFetch } from "undici";
import { Octokit } from "../../src";
import { Octokit } from "../../src/index.ts";

describe("client proxy", () => {
let server: Server;
Expand Down
2 changes: 1 addition & 1 deletion test/auth.test.ts
Expand Up @@ -5,7 +5,7 @@ import { createActionAuth } from "@octokit/auth-action";
import { createOAuthAppAuth } from "@octokit/auth-oauth-app";
import { install as installFakeTimers, type Clock } from "@sinonjs/fake-timers";

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

const userAgent = `octokit-core.js/0.0.0-development ${getUserAgent()}`;

Expand Down
2 changes: 1 addition & 1 deletion test/constructor.test.ts
@@ -1,4 +1,4 @@
import { Octokit } from "../src";
import { Octokit } from "../src/index.ts";
import fetchMock from "fetch-mock";

describe("Smoke test", () => {
Expand Down
2 changes: 1 addition & 1 deletion test/defaults.test.ts
Expand Up @@ -2,7 +2,7 @@ import fetchMock from "fetch-mock";
import { getUserAgent } from "universal-user-agent";
import { createActionAuth } from "@octokit/auth-action";

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

const userAgent = `octokit-core.js/0.0.0-development ${getUserAgent()}`;

Expand Down
2 changes: 1 addition & 1 deletion test/graphql.test.ts
@@ -1,6 +1,6 @@
import fetchMock from "fetch-mock";

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

describe("octokit.graphql()", () => {
it("is a function", () => {
Expand Down
2 changes: 1 addition & 1 deletion test/hook.test.ts
@@ -1,7 +1,7 @@
import { getUserAgent } from "universal-user-agent";
import fetchMock from "fetch-mock";

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

const userAgent = `octokit-core.js/0.0.0-development ${getUserAgent()}`;

Expand Down
2 changes: 1 addition & 1 deletion test/issues.test.ts
@@ -1,4 +1,4 @@
import { Octokit } from "../src";
import { Octokit } from "../src/index.ts";
import fetchMock from "fetch-mock";

/*
Expand Down
6 changes: 3 additions & 3 deletions test/log.test.ts
Expand Up @@ -14,7 +14,7 @@ describe("octokit.log", () => {
const error = jest
.spyOn(console, "error")
.mockImplementation(() => calls.push("error"));
const Octokit = (await import("../src")).Octokit;
const Octokit = (await import("../src/index.ts")).Octokit;

const octokit = new Octokit();

Expand All @@ -39,7 +39,7 @@ describe("octokit.log", () => {
});

it("has .debug(), .info(), .warn(), and .error() functions", async () => {
const Octokit = (await import("../src")).Octokit;
const Octokit = (await import("../src/index.ts")).Octokit;

const octokit = new Octokit();
expect(typeof octokit.log.debug).toBe("function");
Expand All @@ -49,7 +49,7 @@ describe("octokit.log", () => {
});

it("all .log.*() methods can be overwritten", async () => {
const Octokit = (await import("../src")).Octokit;
const Octokit = (await import("../src/index.ts")).Octokit;
const calls: String[] = [];

const octokit = new Octokit({
Expand Down
2 changes: 1 addition & 1 deletion test/plugin.test.ts
@@ -1,4 +1,4 @@
import { Octokit } from "../src";
import { Octokit } from "../src/index.ts";

const pluginFoo = () => {
return { foo: "bar" };
Expand Down
2 changes: 1 addition & 1 deletion test/request.test.ts
@@ -1,7 +1,7 @@
import { getUserAgent } from "universal-user-agent";
import fetchMock from "fetch-mock";

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

const userAgent = `octokit-core.js/0.0.0-development ${getUserAgent()}`;

Expand Down
2 changes: 1 addition & 1 deletion test/smoke.test.ts
@@ -1,4 +1,4 @@
import { Octokit } from "../src";
import { Octokit } from "../src/index.ts";

describe("Smoke test", () => {
it("is a function", () => {
Expand Down
3 changes: 2 additions & 1 deletion test/tsconfig.test.json
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
Expand Up @@ -2,7 +2,7 @@
// THIS CODE IS NOT EXECUTED. IT IS JUST FOR TYPECHECKING
// ************************************************************

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

export function expectType<T>(what: T) {}

Expand Down

0 comments on commit 0e41096

Please sign in to comment.