From 0c0cff7241c2f91e763dfdae868db4652a93fdf7 Mon Sep 17 00:00:00 2001 From: Miorel-Lucian Palii Date: Sun, 22 Sep 2024 01:03:47 -0700 Subject: [PATCH] Move remaining packages to ESM --- .yarnrc.yml | 1 + .../goodies/typescript/Iterator.from/index.test.ts | 9 ++++----- .../goodies/typescript/Iterator.from/index.ts | 1 - .../src/app/__tests__/__snapshots__/equip-test.ts.snap | 2 -- .../src/app/__tests__/__snapshots__/render-test.ts.snap | 2 -- workspaces/eslint-config/package.json | 1 + workspaces/generate-health-report/src/main.ts | 1 + workspaces/util/{jest.config.mts => jest.config.ts} | 0 workspaces/util/package.json | 9 ++++++--- workspaces/util/src/__tests__/distinctArray-test.ts | 3 ++- workspaces/util/src/__tests__/getLines-test.ts | 2 +- workspaces/util/src/__tests__/isNonNullish-test.ts | 2 +- workspaces/util/src/__tests__/squashWhitespace-test.ts | 2 +- workspaces/util/src/__tests__/stripPrefix-test.ts | 2 +- workspaces/util/src/__tests__/stripSuffix-test.ts | 2 +- workspaces/util/src/__tests__/stripSuffixOrThrow-test.ts | 2 +- .../__tests__/timestampInSecondsToYearMonthDay-test.ts | 2 +- .../util/src/getCurrentGitRepositoryStatusPaths.ts | 2 +- yarn.config.cjs | 7 +++++++ yarn.lock | 8 +++++--- 20 files changed, 35 insertions(+), 25 deletions(-) rename workspaces/util/{jest.config.mts => jest.config.ts} (100%) create mode 100644 yarn.config.cjs diff --git a/.yarnrc.yml b/.yarnrc.yml index c742c77b..a2b0d837 100644 --- a/.yarnrc.yml +++ b/.yarnrc.yml @@ -1,4 +1,5 @@ defaultSemverRangePrefix: "" +enableConstraintsChecks: true enableInlineBuilds: true enableTelemetry: false nodeLinker: node-modules diff --git a/workspaces/adventure-pack/goodies/typescript/Iterator.from/index.test.ts b/workspaces/adventure-pack/goodies/typescript/Iterator.from/index.test.ts index 70a4cb69..ca3b673e 100644 --- a/workspaces/adventure-pack/goodies/typescript/Iterator.from/index.test.ts +++ b/workspaces/adventure-pack/goodies/typescript/Iterator.from/index.test.ts @@ -1,15 +1,14 @@ import { describe, expect, it } from "@jest/globals"; -import "../Iterator.prototype.map"; -import "../Iterator.prototype.filter"; +import "../Iterator.prototype.map/index.ts"; +import "../Iterator.prototype.filter/index.ts"; (globalThis as Record).Iterator && delete ( (globalThis as Record).Iterator as Record ).from; - -// eslint-disable-next-line import-x/first -import "./index"; +// eslint-disable-next-line import-x/first -- This has to happen after we delete the built-in implementation. +import "./index.ts"; describe("Iterator.from", () => { it("can convert an Array to an Iterator", () => { diff --git a/workspaces/adventure-pack/goodies/typescript/Iterator.from/index.ts b/workspaces/adventure-pack/goodies/typescript/Iterator.from/index.ts index bc12c367..9af6b333 100644 --- a/workspaces/adventure-pack/goodies/typescript/Iterator.from/index.ts +++ b/workspaces/adventure-pack/goodies/typescript/Iterator.from/index.ts @@ -12,7 +12,6 @@ declare global { } (globalThis as Record).Iterator ??= {}; - ((globalThis as Record).Iterator as { from: unknown }).from ??= function ( object: Iterator | Iterable | { next(): IteratorResult }, diff --git a/workspaces/adventure-pack/src/app/__tests__/__snapshots__/equip-test.ts.snap b/workspaces/adventure-pack/src/app/__tests__/__snapshots__/equip-test.ts.snap index 74426042..5e9c1c8e 100644 --- a/workspaces/adventure-pack/src/app/__tests__/__snapshots__/equip-test.ts.snap +++ b/workspaces/adventure-pack/src/app/__tests__/__snapshots__/equip-test.ts.snap @@ -1383,7 +1383,6 @@ iteratorPrototype.toIterable = function () { }; globalThis.Iterator ??= {}; - globalThis.Iterator.from ??= function (object) { const toIterable = iteratorPrototype.toIterable; @@ -3366,7 +3365,6 @@ iteratorPrototype.toIterable = function ( }; (globalThis as Record).Iterator ??= {}; - ((globalThis as Record).Iterator as { from: unknown }).from ??= function ( object: Iterator | Iterable | { next(): IteratorResult }, diff --git a/workspaces/adventure-pack/src/app/__tests__/__snapshots__/render-test.ts.snap b/workspaces/adventure-pack/src/app/__tests__/__snapshots__/render-test.ts.snap index c23fa11b..2aa3622e 100644 --- a/workspaces/adventure-pack/src/app/__tests__/__snapshots__/render-test.ts.snap +++ b/workspaces/adventure-pack/src/app/__tests__/__snapshots__/render-test.ts.snap @@ -805,7 +805,6 @@ exports[`App can render goody: JavaScript Iterator.from 1`] = ` import "Iterator.prototype.toIterable"; globalThis.Iterator ??= {}; - globalThis.Iterator.from ??= function (object) { const toIterable = iteratorPrototype.toIterable; @@ -1984,7 +1983,6 @@ declare global { } (globalThis as Record).Iterator ??= {}; - ((globalThis as Record).Iterator as { from: unknown }).from ??= function ( object: Iterator | Iterable | { next(): IteratorResult }, diff --git a/workspaces/eslint-config/package.json b/workspaces/eslint-config/package.json index 816fdeb9..da1b228b 100644 --- a/workspaces/eslint-config/package.json +++ b/workspaces/eslint-config/package.json @@ -12,6 +12,7 @@ "name": "Miorel-Lucian Palii", "url": "https://github.com/miorel" }, + "type": "module", "exports": { ".": "./eslint.config.mjs" }, diff --git a/workspaces/generate-health-report/src/main.ts b/workspaces/generate-health-report/src/main.ts index d523e412..c553e525 100644 --- a/workspaces/generate-health-report/src/main.ts +++ b/workspaces/generate-health-report/src/main.ts @@ -10,6 +10,7 @@ import { maybeThrow } from "@code-chronicles/util/maybeThrow"; import { spawnWithSafeStdio } from "@code-chronicles/util/spawnWithSafeStdio"; const COMMANDS = [ + "yarn constraints", "yarn test", "yarn workspace @code-chronicles/adventure-pack build-app", "yarn workspace @code-chronicles/adventure-pack build-chrome-extension", diff --git a/workspaces/util/jest.config.mts b/workspaces/util/jest.config.ts similarity index 100% rename from workspaces/util/jest.config.mts rename to workspaces/util/jest.config.ts diff --git a/workspaces/util/package.json b/workspaces/util/package.json index 015c6686..7683040c 100644 --- a/workspaces/util/package.json +++ b/workspaces/util/package.json @@ -12,23 +12,26 @@ "name": "Miorel-Lucian Palii", "url": "https://github.com/miorel" }, + "type": "module", "exports": { "./*": "./src/*.ts", + ".": null, "./__tests__/*": null }, "scripts": { "format": "prettier --color --write .", "lint": "eslint --color --max-warnings=0 .", - "test": "tsx ./jest.config.mts", + "test": "tsx ./jest.config.ts", "typecheck": "tsc --pretty --project ." }, - "dependencies": { + "peerDependencies": { "invariant": "2.2.4", - "nullthrows": "patch:nullthrows@npm%3A1.1.1#~/.yarn/patches/nullthrows-npm-1.1.1-3d1f817134.patch", + "nullthrows": "*", "zod": "3.23.8" }, "devDependencies": { "@code-chronicles/eslint-config": "workspace:*", + "@code-chronicles/util": "workspace:*", "@jest/globals": "29.7.0", "@types/node": "22.5.5", "eslint": "9.11.0", diff --git a/workspaces/util/src/__tests__/distinctArray-test.ts b/workspaces/util/src/__tests__/distinctArray-test.ts index 99bad2dd..7abd8635 100644 --- a/workspaces/util/src/__tests__/distinctArray-test.ts +++ b/workspaces/util/src/__tests__/distinctArray-test.ts @@ -1,5 +1,6 @@ import { describe, expect, it } from "@jest/globals"; -import { distinctArray } from "../distinctArray"; + +import { distinctArray } from "../distinctArray.ts"; describe("distinctArray", () => { it("returns an empty list if given an empty list", () => { diff --git a/workspaces/util/src/__tests__/getLines-test.ts b/workspaces/util/src/__tests__/getLines-test.ts index 7f207367..14e8c012 100644 --- a/workspaces/util/src/__tests__/getLines-test.ts +++ b/workspaces/util/src/__tests__/getLines-test.ts @@ -1,6 +1,6 @@ import { describe, expect, it } from "@jest/globals"; -import { getLines } from "../getLines"; +import { getLines } from "../getLines.ts"; describe("getLines", () => { it("gets lines when the new line at the begining", () => { diff --git a/workspaces/util/src/__tests__/isNonNullish-test.ts b/workspaces/util/src/__tests__/isNonNullish-test.ts index 4354013f..bedb9353 100644 --- a/workspaces/util/src/__tests__/isNonNullish-test.ts +++ b/workspaces/util/src/__tests__/isNonNullish-test.ts @@ -2,7 +2,7 @@ import { describe, expect, it } from "@jest/globals"; -import { isNonNullish } from "../isNonNullish"; +import { isNonNullish } from "../isNonNullish.ts"; describe("isNonNullish", () => { it.each([[], {}, new Set(), new Map(), "hi", 4, Symbol(undefined)])( diff --git a/workspaces/util/src/__tests__/squashWhitespace-test.ts b/workspaces/util/src/__tests__/squashWhitespace-test.ts index fb0b7d86..0d805d9d 100644 --- a/workspaces/util/src/__tests__/squashWhitespace-test.ts +++ b/workspaces/util/src/__tests__/squashWhitespace-test.ts @@ -1,6 +1,6 @@ import { describe, expect, it } from "@jest/globals"; -import { squashWhitespace } from "../squashWhitespace"; +import { squashWhitespace } from "../squashWhitespace.ts"; describe("squashWhitespace", () => { it("removes whitespace between words if it exists", () => { diff --git a/workspaces/util/src/__tests__/stripPrefix-test.ts b/workspaces/util/src/__tests__/stripPrefix-test.ts index 39b16036..d7ba98f7 100644 --- a/workspaces/util/src/__tests__/stripPrefix-test.ts +++ b/workspaces/util/src/__tests__/stripPrefix-test.ts @@ -1,6 +1,6 @@ import { describe, expect, it } from "@jest/globals"; -import { stripPrefix } from "../stripPrefix"; +import { stripPrefix } from "../stripPrefix.ts"; describe("stripPrefix", () => { it("removes the prefix if it exists", () => { diff --git a/workspaces/util/src/__tests__/stripSuffix-test.ts b/workspaces/util/src/__tests__/stripSuffix-test.ts index 7cfb6b10..04e3c2cb 100644 --- a/workspaces/util/src/__tests__/stripSuffix-test.ts +++ b/workspaces/util/src/__tests__/stripSuffix-test.ts @@ -1,6 +1,6 @@ import { describe, expect, it } from "@jest/globals"; -import { stripSuffix } from "../stripSuffix"; +import { stripSuffix } from "../stripSuffix.ts"; describe("stripSuffix", () => { it("removes the suffix if it exists", () => { diff --git a/workspaces/util/src/__tests__/stripSuffixOrThrow-test.ts b/workspaces/util/src/__tests__/stripSuffixOrThrow-test.ts index 04db4b76..d528606c 100644 --- a/workspaces/util/src/__tests__/stripSuffixOrThrow-test.ts +++ b/workspaces/util/src/__tests__/stripSuffixOrThrow-test.ts @@ -1,6 +1,6 @@ import { describe, expect, it } from "@jest/globals"; -import { stripSuffixOrThrow } from "../stripSuffixOrThrow"; +import { stripSuffixOrThrow } from "../stripSuffixOrThrow.ts"; describe("stripSuffixOrThrow", () => { it("removes the suffix if it exists", () => { diff --git a/workspaces/util/src/__tests__/timestampInSecondsToYearMonthDay-test.ts b/workspaces/util/src/__tests__/timestampInSecondsToYearMonthDay-test.ts index 1aa2db2e..5bb40dce 100644 --- a/workspaces/util/src/__tests__/timestampInSecondsToYearMonthDay-test.ts +++ b/workspaces/util/src/__tests__/timestampInSecondsToYearMonthDay-test.ts @@ -1,6 +1,6 @@ import { describe, expect, it } from "@jest/globals"; -import { timestampInSecondsToYearMonthDay } from "../timestampInSecondsToYearMonthDay"; +import { timestampInSecondsToYearMonthDay } from "../timestampInSecondsToYearMonthDay.ts"; describe("timestampInSecondsToYearMonthDay", () => { it.each([ diff --git a/workspaces/util/src/getCurrentGitRepositoryStatusPaths.ts b/workspaces/util/src/getCurrentGitRepositoryStatusPaths.ts index 44e12913..901103c7 100644 --- a/workspaces/util/src/getCurrentGitRepositoryStatusPaths.ts +++ b/workspaces/util/src/getCurrentGitRepositoryStatusPaths.ts @@ -15,7 +15,7 @@ export async function* getCurrentGitRepositoryStatusPaths(): AsyncGenerator< // Using a set to deduplicate, in case multiple files were "moved from" the // same file. I'm not even completely sure if that's possible, but no harm in - // defending aagainst it. + // defending against it. const yieldedPaths = new Set(); for (const line of getLines(gitCommandResult.stdout)) { diff --git a/yarn.config.cjs b/yarn.config.cjs new file mode 100644 index 00000000..87010d06 --- /dev/null +++ b/yarn.config.cjs @@ -0,0 +1,7 @@ +module.exports = { + async constraints({ Yarn }) { + for (const workspace of Yarn.workspaces()) { + workspace.set("type", "module"); + } + }, +}; diff --git a/yarn.lock b/yarn.lock index 4a97d543..2c6a6f61 100644 --- a/yarn.lock +++ b/yarn.lock @@ -699,18 +699,20 @@ __metadata: resolution: "@code-chronicles/util@workspace:workspaces/util" dependencies: "@code-chronicles/eslint-config": "workspace:*" + "@code-chronicles/util": "workspace:*" "@jest/globals": "npm:29.7.0" "@types/node": "npm:22.5.5" eslint: "npm:9.11.0" - invariant: "npm:2.2.4" jest: "npm:29.7.0" - nullthrows: "patch:nullthrows@npm%3A1.1.1#~/.yarn/patches/nullthrows-npm-1.1.1-3d1f817134.patch" prettier: "npm:3.3.3" ts-jest: "npm:29.2.5" tsx: "npm:4.19.1" type-fest: "npm:4.26.1" typescript: "npm:5.6.2" - zod: "npm:3.23.8" + peerDependencies: + invariant: 2.2.4 + nullthrows: "*" + zod: 3.23.8 languageName: unknown linkType: soft