Skip to content

Commit

Permalink
Merge pull request #96 from jhurliman/jhurliman/esm-type-module
Browse files Browse the repository at this point in the history
Drop just-performance, ttypescript, use *.js imports, create cjs/esm package.json files, bump deps
  • Loading branch information
jhurliman authored Apr 25, 2024
2 parents 9bbd3b0 + 68c8230 commit a9e0da1
Show file tree
Hide file tree
Showing 11 changed files with 2,280 additions and 3,648 deletions.
21 changes: 21 additions & 0 deletions create-package-json.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env node

const fs = require("fs");
const path = require("path");

const createPackageJson = (type, dir) => {
const content = {
type: type,
};
const directory = path.resolve(__dirname, dir);
if (!fs.existsSync(directory)) {
fs.mkdirSync(directory, { recursive: true });
}
fs.writeFileSync(
path.join(directory, "package.json"),
JSON.stringify(content, null, 2)
);
};

createPackageJson("commonjs", "./dist/cjs");
createPackageJson("module", "./dist/esm");
38 changes: 19 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,30 @@
"dist",
"src"
],
"jest": {
"moduleNameMapper": {
"^(.*)\\.js$": "$1"
}
},
"scripts": {
"lint": "eslint --fix src",
"prepack": "yarn ttsc -p tsconfig.json && ttsc -p tsconfig.cjs.json",
"prepack": "yarn tsc -p tsconfig.json && tsc -p tsconfig.cjs.json && node ./create-package-json.js",
"test": "jest src"
},
"dependencies": {
"just-performance": "4.3.0"
},
"devDependencies": {
"@babel/core": "^7.13.16",
"@babel/preset-env": "^7.13.15",
"@babel/preset-typescript": "^7.13.0",
"@types/babel__generator": "^7.6.2",
"@types/jest": "^26.0.23",
"@typescript-eslint/eslint-plugin": "^4.22.0",
"@typescript-eslint/parser": "^4.22.0",
"@zoltu/typescript-transformer-append-js-extension": "^1.0.1",
"babel-jest": "^26.6.3",
"eslint": "^7.25.0",
"eslint-plugin-prettier": "^3.4.0",
"jest": "^26.6.3",
"prettier": "^2.2.1",
"ttypescript": "^1.5.12",
"typescript": "^4.2.4"
"@babel/core": "^7.24.4",
"@babel/preset-env": "^7.24.4",
"@babel/preset-typescript": "^7.24.1",
"@types/babel__generator": "^7.6.8",
"@types/jest": "^29.5.12",
"@typescript-eslint/eslint-plugin": "^7.7.0",
"@typescript-eslint/parser": "^7.7.0",
"babel-jest": "^29.7.0",
"eslint": "^9.1.0",
"eslint-plugin-prettier": "^5.1.3",
"jest": "^29.7.0",
"prettier": "^3.2.5",
"typescript": "^5.4.5"
},
"keywords": [
"rate",
Expand Down
4 changes: 2 additions & 2 deletions src/RateLimiter.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { RateLimiter } from "./RateLimiter";
import { Interval } from "./TokenBucket";
import { RateLimiter } from "./RateLimiter.js";
import { Interval } from "./TokenBucket.js";

describe("RateLimiter", () => {
describe("interval validation", () => {
Expand Down
4 changes: 2 additions & 2 deletions src/RateLimiter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Interval, TokenBucket } from "./TokenBucket";
import { getMilliseconds, wait } from "./clock";
import { Interval, TokenBucket } from "./TokenBucket.js";
import { getMilliseconds, wait } from "./clock.js";

export type RateLimiterOpts = {
tokensPerInterval: number;
Expand Down
4 changes: 2 additions & 2 deletions src/TokenBucket.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { TokenBucket } from "./TokenBucket";
import { wait } from "./clock";
import { TokenBucket } from "./TokenBucket.js";
import { wait } from "./clock.js";

const TIMING_EPSILON = 10;

Expand Down
2 changes: 1 addition & 1 deletion src/TokenBucket.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getMilliseconds, wait } from "./clock";
import { getMilliseconds, wait } from "./clock.js";

export type Interval = number | "second" | "sec" | "minute" | "min" | "hour" | "hr" | "day";

Expand Down
2 changes: 0 additions & 2 deletions src/clock.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { performance } from "just-performance";

// generate timestamp or delta
// see http://nodejs.org/api/process.html#process_process_hrtime
function hrtime(previousTimestamp?: [number, number]): [number, number] {
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from "./RateLimiter";
export * from "./TokenBucket";
export * from "./RateLimiter.js";
export * from "./TokenBucket.js";
3 changes: 2 additions & 1 deletion tsconfig.cjs.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "./dist/cjs",
"module": "commonjs"
"module": "commonjs",
"moduleResolution": "node"
}
}
14 changes: 4 additions & 10 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,12 @@
{
"include": ["./src/**/*.ts"],
"compilerOptions": {
"plugins": [
{
"transform": "@zoltu/typescript-transformer-append-js-extension/output/index.js",
"after": true
}
],
"outDir": "./dist/esm",
"rootDir": "./src",
"target": "es2019",
"module": "es2020",
"lib": ["es2019"],
"moduleResolution": "node",
"target": "es2022",
"module": "es2022",
"moduleResolution": "bundler",
"lib": ["dom", "es2022"],
"isolatedModules": true,
"composite": true,
"newLine": "lf",
Expand Down
Loading

0 comments on commit a9e0da1

Please sign in to comment.