Skip to content

Commit

Permalink
fix: add node prefix for builtin modules (#1931)
Browse files Browse the repository at this point in the history
chore: add node prefix, adapt some changes for deno compatibility
  • Loading branch information
Uzlopak committed Nov 25, 2023
1 parent 9d1fdcd commit f515b6a
Show file tree
Hide file tree
Showing 23 changed files with 60 additions and 40 deletions.
4 changes: 2 additions & 2 deletions src/apps/default.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { resolve } from "node:path";

import type { ApplicationFunctionOptions, Probot } from "../index.js";
import { loadPackageJson } from "../helpers/load-package-json.js";
import { resolve } from "path";

import { probotView } from "../views/probot.js";

export function defaultApp(
Expand Down
3 changes: 2 additions & 1 deletion src/apps/setup.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { exec } from "node:child_process";

import type { IncomingMessage, ServerResponse } from "http";
import { parse as parseQuery } from "querystring";
import express from "express";
import { exec } from "child_process";
import updateDotenv from "update-dotenv";

import { Probot } from "../probot.js";
Expand Down
6 changes: 3 additions & 3 deletions src/bin/probot-receive.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Usage: probot receive -e push -p path/to/payload app.js
import fs from "node:fs";
import path from "node:path";
import { randomUUID as uuidv4 } from "node:crypto";

import express, { Router } from "express";
import { config as dotenvConfig } from "dotenv";
dotenvConfig();

import fs from "fs";
import path from "path";
import { randomUUID as uuidv4 } from "crypto";
import { program } from "commander";
import { getPrivateKey } from "@probot/get-private-key";
import { getLog } from "../helpers/get-log.js";
Expand Down
6 changes: 4 additions & 2 deletions src/bin/probot.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { resolve } from "node:path";

import { program } from "commander";
import { config as dotenvConfig } from "dotenv";
import { isSupportedNodeVersion } from "../helpers/is-supported-node-version.js";
import { loadPackageJson } from "../helpers/load-package-json.js";
import { config as dotenvConfig } from "dotenv";
import { resolve } from "path";

/*import { dirname } from 'path';
import { fileURLToPath } from 'url';*/

Expand Down
2 changes: 1 addition & 1 deletion src/context.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import path from "path";
import path from "node:path";
import merge from "deepmerge";

import type {
Expand Down
5 changes: 3 additions & 2 deletions src/helpers/load-package-json.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import fs from "fs";
import path from "path";
import fs from "node:fs";
import path from "node:path";

import type { PackageJson } from "../types.js";

export function loadPackageJson(
Expand Down
8 changes: 5 additions & 3 deletions src/manifest-creation.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import fs from "fs";
import fs from "node:fs";
import path from "node:path";

import yaml from "js-yaml";
import path from "path";
import updateDotenv from "update-dotenv";
import type { RequestParameters } from "@octokit/types";

import { ProbotOctokit } from "./octokit/probot-octokit.js";
import { loadPackageJson } from "./helpers/load-package-json.js";
import type { Env, Manifest, OctokitOptions, PackageJson } from "./types.js";
import type { RequestParameters } from "@octokit/types";

export class ManifestCreation {
get pkg() {
Expand Down
3 changes: 2 additions & 1 deletion src/server/logging-middleware.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { randomUUID as uuidv4 } from "node:crypto";

import { pinoHttp, startTime, type Options, type HttpLogger } from "pino-http";
import type { Logger } from "pino";
import { randomUUID as uuidv4 } from "crypto";

export function getLoggingMiddleware(
logger: Logger,
Expand Down
4 changes: 2 additions & 2 deletions src/server/server.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { type Server as HttpServer } from "http";
import type { Server as HttpServer } from "node:http";
import { join } from "node:path";

import express, { Router, type Application } from "express";
import { join } from "path";
import type { Logger } from "pino";
import { createNodeMiddleware as createWebhooksMiddleware } from "@octokit/webhooks";

Expand Down
3 changes: 3 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ export type PackageJson = {
description?: string;
homepage?: string;
repository?: string;
engines?: {
[key: string]: string;
};
};

export type Env = Record<Uppercase<string>, string>;
Expand Down
2 changes: 1 addition & 1 deletion test/apps/default.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Stream from "stream";
import Stream from "node:stream";

import { pino } from "pino";
import request from "supertest";
Expand Down
6 changes: 3 additions & 3 deletions test/apps/setup.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { beforeEach, afterEach, describe, expect, it, vi } from "vitest";
import { Stream } from "node:stream";

import fetchMock from "fetch-mock";
import { Stream } from "stream";
import request from "supertest";
import { pino } from "pino";
import request from "supertest";
import { beforeEach, afterEach, describe, expect, it, vi } from "vitest";

import { Probot, Server } from "../../src/index.js";
import { setupAppFactory } from "../../src/apps/setup.js";
Expand Down
5 changes: 3 additions & 2 deletions test/bin/is-supported-node-version.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { describe, it, expect } from "vitest";

import { isSupportedNodeVersion } from "../../src/helpers/is-supported-node-version.js";
import { engines } from "../../package.json";
import { loadPackageJson } from "../../src/helpers/load-package-json.js";

describe("isSupportedNodeVersion", () => {
const { engines } = loadPackageJson();
it(`engines value is set to ">=18"`, () => {
expect(engines.node).toBe(">=18");
expect(engines!.node).toBe(">=18");
});

it("returns true if node is bigger or equal v18", () => {
Expand Down
4 changes: 2 additions & 2 deletions test/context.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import fs from "fs";
import path from "path";
import fs from "node:fs";
import path from "node:path";

import type { EmitterWebhookEvent as WebhookEvent } from "@octokit/webhooks";
import WebhookExamples from "@octokit/webhooks-examples";
Expand Down
4 changes: 2 additions & 2 deletions test/create-node-middleware.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createServer, IncomingMessage, ServerResponse } from "http";
import Stream from "stream";
import { createServer, IncomingMessage, ServerResponse } from "node:http";
import Stream from "node:stream";

import { pino } from "pino";
import getPort from "get-port";
Expand Down
2 changes: 1 addition & 1 deletion test/helpers/load-package-json.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { loadPackageJson } from "../../src/helpers/load-package-json.js";
import { resolve } from "path";
import { resolve } from "node:path";
import { describe, expect, it } from "vitest";

describe("loadPackageJson", () => {
Expand Down
2 changes: 1 addition & 1 deletion test/integration/integration-smee.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Writable } from "stream";
import { Writable } from "node:stream";
import { ManifestCreation } from "../../src/manifest-creation.js";
import { describe, test, expect, afterEach } from "vitest";
import getPort from "get-port";
Expand Down
16 changes: 12 additions & 4 deletions test/manifest-creation.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
import fs from "fs";
import pkg from "../package.json";
import { ManifestCreation } from "../src/manifest-creation.js";
import response from "./fixtures/setup/response.json";
import fs from "node:fs";
import path from "node:path";
import fetchMock from "fetch-mock";
import { describe, expect, test, beforeEach, afterEach, vi } from "vitest";

import { ManifestCreation } from "../src/manifest-creation.js";
import { loadPackageJson } from "../src/helpers/load-package-json.js";

describe("ManifestCreation", () => {
let setup: ManifestCreation;

const pkg = loadPackageJson();
const response = JSON.parse(
fs.readFileSync(
path.resolve(process.cwd(), "./test/fixtures/setup/response.json"),
"utf8",
),
);
beforeEach(() => {
setup = new ManifestCreation();
});
Expand Down
2 changes: 1 addition & 1 deletion test/probot.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Stream from "stream";
import Stream from "node:stream";

import type {
EmitterWebhookEvent,
Expand Down
2 changes: 1 addition & 1 deletion test/run.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import path from "path";
import path from "node:path";

import request from "supertest";
import { sign } from "@octokit/webhooks-methods";
Expand Down
2 changes: 1 addition & 1 deletion test/server.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Stream from "stream";
import Stream from "node:stream";

import type { NextFunction, Request, Response } from "express";
import request from "supertest";
Expand Down
2 changes: 1 addition & 1 deletion test/server/logging-middleware.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Stream from "stream";
import Stream from "node:stream";

import express from "express";
import request from "supertest";
Expand Down
7 changes: 4 additions & 3 deletions test/webhook-proxy.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { randomInt } from "crypto";
import { randomInt } from "node:crypto";
import http from "node:http";
import net from "node:net";

import express, { type Response } from "express";
const sse: (
req: express.Request,
Expand All @@ -7,8 +10,6 @@ const sse: (
) => void = require("connect-sse")();
import fetchMock from "fetch-mock";
import EventSource from "eventsource";
import http from "http";
import net from "net";
import { describe, expect, afterEach, test, vi } from "vitest";
import { getLog } from "../src/helpers/get-log.js";
import { createWebhookProxy } from "../src/helpers/webhook-proxy.js";
Expand Down

0 comments on commit f515b6a

Please sign in to comment.