Skip to content

Commit d9e2174

Browse files
authored
refactor: use node: specifier imports and full relative paths (#209)
* refactor: replace NodeJS internal module imports with `node:` specifier imports * refactor: use full relative paths
1 parent fedaaac commit d9e2174

File tree

10 files changed

+24
-19
lines changed

10 files changed

+24
-19
lines changed

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,11 @@
6060
"testPathIgnorePatterns": [
6161
"<rootDir>/node_modules/",
6262
"<rootDir>/test/deno/"
63-
]
63+
],
64+
"testEnvironment": "node",
65+
"moduleNameMapper": {
66+
"^(.+)\\.jsx?$": "$1"
67+
}
6468
},
6569
"release": {
6670
"branches": [

scripts/build.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import esbuild from "esbuild";
2-
import { copyFile, readFile, writeFile, rm } from "fs/promises";
2+
import { copyFile, readFile, writeFile, rm } from "node:fs/promises";
33
import { glob } from "glob";
44

55
const sharedOptions = {

src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
export { sign } from "./node/sign";
2-
import { verify } from "./node/verify";
1+
export { sign } from "./node/sign.js";
2+
import { verify } from "./node/verify.js";
33
export { verify };
44

55
export async function verifyWithFallback(

src/node/sign.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { createHmac } from "crypto";
2-
import { Algorithm, type SignOptions } from "../types";
3-
import { VERSION } from "../version";
1+
import { createHmac } from "node:crypto";
2+
import { Algorithm, type SignOptions } from "../types.js";
3+
import { VERSION } from "../version.js";
44

55
export async function sign(
66
options: SignOptions | string,

src/node/verify.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { timingSafeEqual } from "crypto";
2-
import { Buffer } from "buffer";
1+
import { timingSafeEqual } from "node:crypto";
2+
import { Buffer } from "node:buffer";
33

4-
import { sign } from "./sign";
5-
import { VERSION } from "../version";
6-
import { getAlgorithm } from "../utils";
4+
import { sign } from "./sign.js";
5+
import { VERSION } from "../version.js";
6+
import { getAlgorithm } from "../utils.js";
77

88
export async function verify(
99
secret: string,

src/web.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { Algorithm, type AlgorithmLike, type SignOptions } from "./types";
2-
import { getAlgorithm } from "./utils";
1+
import { Algorithm, type AlgorithmLike, type SignOptions } from "./types.js";
2+
import { getAlgorithm } from "./utils.js";
33

44
const enc = new TextEncoder();
55

test/browser-test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
const { strictEqual } = require("assert");
1+
const { strictEqual } = require("node:assert");
22

3-
const { readFile } = require("fs").promises;
3+
const { readFile } = require("node:fs/promises");
44
const puppeteer = require("puppeteer");
55

66
runTests();

test/sign.test.ts

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

33
const eventPayload = {
44
foo: "bar",

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/verify.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { verify, verifyWithFallback } from "../src";
1+
import { verify, verifyWithFallback } from "../src/index.ts";
22

33
function toNormalizedJsonString(payload: object) {
44
// GitHub sends its JSON with an indentation of 2 spaces and a line break at the end

0 commit comments

Comments
 (0)