From cb1c0f9e7728e6e448e9aabfa74aed4c3d112c30 Mon Sep 17 00:00:00 2001 From: Vincent Driessen Date: Thu, 20 Feb 2025 14:05:47 +0100 Subject: [PATCH] Use recommended TS settings for libraries (#1136) --- CHANGELOG.md | 3 +++ package.json | 30 +++++++++++++++--------------- src/builtins.ts | 6 +++--- src/custom.ts | 8 ++++---- src/index.ts | 10 +++++----- src/itertools.ts | 8 ++++---- src/more-itertools.ts | 8 ++++---- src/utils.ts | 2 +- test-d/inference.test-d.ts | 2 +- test/builtins.test.ts | 2 +- test/custom.test.ts | 2 +- test/itertools.test.ts | 2 +- test/more-itertools.test.ts | 4 ++-- tsconfig.json | 7 +++---- 14 files changed, 48 insertions(+), 46 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d3d01acc..98906ec3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ ## [Unreleased] +- Use `node16` module resolution setting (recommended setting for libraries that run in + both browsers and Node environments) + ## [2.4.0] - 2025-02-19 - Add second param `index` to all predicates. This will make operations like diff --git a/package.json b/package.json index 0ddc5334..de099fc8 100644 --- a/package.json +++ b/package.json @@ -3,18 +3,9 @@ "version": "2.4.0", "description": "A JavaScript port of Python's awesome itertools standard library", "license": "MIT", - "repository": { - "type": "git", - "url": "git+https://github.com/nvie/itertools.git" - }, - "author": "Vincent Driessen", - "homepage": "https://github.com/nvie/itertools#readme", - "bugs": { - "url": "https://github.com/nvie/itertools/issues" - }, "type": "module", - "types": "./dist/index.d.cts", "main": "./dist/index.cjs", + "types": "./dist/index.d.cts", "exports": { ".": { "import": { @@ -44,11 +35,6 @@ "LICENSE", "README.md" ], - "keywords": [ - "itertool", - "itertools", - "node-itertools" - ], "devDependencies": { "@arethetypeswrong/cli": "^0.17.3", "@eslint/js": "^9.20.0", @@ -68,6 +54,20 @@ "vite-tsconfig-paths": "^5.1.4", "vitest": "^3.0.6" }, + "author": "Vincent Driessen", + "repository": { + "type": "git", + "url": "git+https://github.com/nvie/itertools.git" + }, + "homepage": "https://github.com/nvie/itertools#readme", + "bugs": { + "url": "https://github.com/nvie/itertools/issues" + }, + "keywords": [ + "itertool", + "itertools", + "node-itertools" + ], "githubUrl": "https://github.com/nvie/itertools", "sideEffects": false } diff --git a/src/builtins.ts b/src/builtins.ts index a9ac1940..581b004d 100644 --- a/src/builtins.ts +++ b/src/builtins.ts @@ -1,6 +1,6 @@ -import { count, ifilter, imap, izip, izip3, takewhile } from "./itertools"; -import type { Predicate, Primitive } from "./types"; -import { identityPredicate, keyToCmp, numberIdentity, primitiveIdentity } from "./utils"; +import { count, ifilter, imap, izip, izip3, takewhile } from "./itertools.js"; +import type { Predicate, Primitive } from "./types.js"; +import { identityPredicate, keyToCmp, numberIdentity, primitiveIdentity } from "./utils.js"; /** * Returns the first item in the iterable for which the predicate holds, if diff --git a/src/custom.ts b/src/custom.ts index b21e0459..8d7e1793 100644 --- a/src/custom.ts +++ b/src/custom.ts @@ -1,7 +1,7 @@ -import { find } from "./builtins"; -import { ifilter, imap } from "./itertools"; -import { flatten } from "./more-itertools"; -import type { Predicate } from "./types"; +import { find } from "./builtins.js"; +import { ifilter, imap } from "./itertools.js"; +import { flatten } from "./more-itertools.js"; +import type { Predicate } from "./types.js"; function isNullish(x: T): x is NonNullable { return x != null; diff --git a/src/index.ts b/src/index.ts index e6085171..f169d917 100644 --- a/src/index.ts +++ b/src/index.ts @@ -17,8 +17,8 @@ export { sum, zip, zip3, -} from "./builtins"; -export { compact, compactObject, first, flatmap, icompact } from "./custom"; +} from "./builtins.js"; +export { compact, compactObject, first, flatmap, icompact } from "./custom.js"; export { chain, compress, @@ -42,7 +42,7 @@ export { zipLongest, zipLongest3, zipMany, -} from "./itertools"; +} from "./itertools.js"; export { chunked, dupes, @@ -56,5 +56,5 @@ export { take, uniqueEverseen, uniqueJustseen, -} from "./more-itertools"; -export type { Predicate, Primitive } from "./types"; +} from "./more-itertools.js"; +export type { Predicate, Primitive } from "./types.js"; diff --git a/src/itertools.ts b/src/itertools.ts index be161bcb..23a6f126 100644 --- a/src/itertools.ts +++ b/src/itertools.ts @@ -1,7 +1,7 @@ -import { every, iter, range } from "./builtins"; -import { flatten } from "./more-itertools"; -import type { Predicate, Primitive } from "./types"; -import { primitiveIdentity } from "./utils"; +import { every, iter, range } from "./builtins.js"; +import { flatten } from "./more-itertools.js"; +import type { Predicate, Primitive } from "./types.js"; +import { primitiveIdentity } from "./utils.js"; const SENTINEL = Symbol(); diff --git a/src/more-itertools.ts b/src/more-itertools.ts index e68520a6..062723e0 100644 --- a/src/more-itertools.ts +++ b/src/more-itertools.ts @@ -1,7 +1,7 @@ -import { iter, map } from "./builtins"; -import { izip, repeat } from "./itertools"; -import type { Predicate, Primitive } from "./types"; -import { primitiveIdentity } from "./utils"; +import { iter, map } from "./builtins.js"; +import { izip, repeat } from "./itertools.js"; +import type { Predicate, Primitive } from "./types.js"; +import { primitiveIdentity } from "./utils.js"; /** * Break iterable into lists of length `size`: diff --git a/src/utils.ts b/src/utils.ts index da283a99..fcb3720e 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,4 +1,4 @@ -import type { Primitive } from "./types"; +import type { Primitive } from "./types.js"; type CmpFn = (a: T, b: T) => number; diff --git a/test-d/inference.test-d.ts b/test-d/inference.test-d.ts index bbbb621a..2d1fa4cf 100644 --- a/test-d/inference.test-d.ts +++ b/test-d/inference.test-d.ts @@ -1,4 +1,4 @@ -import { partition } from "../dist"; +import { partition } from "../dist/index.js"; import { expectType } from "tsd"; function isStr(x: unknown): x is string { diff --git a/test/builtins.test.ts b/test/builtins.test.ts index 208ad545..44b21882 100644 --- a/test/builtins.test.ts +++ b/test/builtins.test.ts @@ -18,7 +18,7 @@ import { sum, zip, zip3, -} from "~"; +} from "~/index.js"; const isEven = (n: number) => n % 2 === 0; const isEvenIndex = (_: unknown, index: number) => index % 2 === 0; diff --git a/test/custom.test.ts b/test/custom.test.ts index c06fddc2..5c82adbf 100644 --- a/test/custom.test.ts +++ b/test/custom.test.ts @@ -1,6 +1,6 @@ import { describe, expect, it } from "vitest"; -import { compact, compactObject, flatmap, repeat } from "~"; +import { compact, compactObject, flatmap, repeat } from "~/index.js"; describe("compact", () => { it("compact w/ empty list", () => { diff --git a/test/itertools.test.ts b/test/itertools.test.ts index 10504d27..f0704676 100644 --- a/test/itertools.test.ts +++ b/test/itertools.test.ts @@ -19,7 +19,7 @@ import { zipLongest, zipLongest3, zipMany, -} from "~"; +} from "~/index.js"; const isEven = (x: number) => x % 2 === 0; const isEvenIndex = (_: unknown, index: number) => index % 2 === 0; diff --git a/test/more-itertools.test.ts b/test/more-itertools.test.ts index 3bd2537b..4e3e144c 100644 --- a/test/more-itertools.test.ts +++ b/test/more-itertools.test.ts @@ -1,6 +1,7 @@ import * as fc from "fast-check"; import { describe, expect, it } from "vitest"; +import { find, iter, range } from "~/builtins.js"; import { chunked, dupes, @@ -14,8 +15,7 @@ import { take, uniqueEverseen, uniqueJustseen, -} from "~"; -import { find, iter, range } from "~/builtins"; +} from "~/index.js"; const isEven = (x: number) => x % 2 === 0; const isEvenIndex = (_: unknown, index: number) => index % 2 === 0; diff --git a/tsconfig.json b/tsconfig.json index a8086251..f1afc3ca 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,10 +2,9 @@ "compilerOptions": { "noEmit": true, "strict": true, - "target": "es2015", - "lib": ["es6"], - "module": "es2020", - "moduleResolution": "bundler", + "target": "es2020", + "module": "node16", + "moduleResolution": "node16", "esModuleInterop": true, "skipLibCheck": true, "forceConsistentCasingInFileNames": true,