From a5a7d6c20d01b075c0787de6fe45f70c6e5053a1 Mon Sep 17 00:00:00 2001 From: "g. nicholas d'andrea" Date: Tue, 13 Jan 2026 21:19:13 -0500 Subject: [PATCH] Convert @ethdebug/format to ESM and enable ESM imports in web app Format package changes: - Add "type": "module" to package.json - Update tsconfig.json to use module: "nodenext" - Add explicit .js extensions to all relative imports - Convert bin/generate-schema-yamls.js from CommonJS to ESM Web package changes: - Add babel-loader to transpile @ethdebug/* ESM packages - Add @ethdebug/pointers as a dependency - Configure webpack with fullySpecified: false for ESM compatibility --- packages/format/bin/generate-schema-yamls.js | 13 ++++++++----- packages/format/package.json | 1 + packages/format/src/describe.ts | 2 +- packages/format/src/index.ts | 6 +++--- packages/format/src/schemas/examples.test.ts | 8 ++++---- packages/format/src/schemas/index.ts | 6 +++--- packages/format/src/schemas/validity.test.ts | 4 ++-- packages/format/src/types/data/index.test.ts | 2 +- packages/format/src/types/index.ts | 10 +++++----- packages/format/src/types/materials/index.test.ts | 4 ++-- packages/format/src/types/materials/index.ts | 2 +- packages/format/src/types/pointer/index.ts | 2 +- packages/format/src/types/pointer/pointer.test.ts | 4 ++-- packages/format/src/types/program/context.test.ts | 4 ++-- packages/format/src/types/program/context.ts | 6 +++--- packages/format/src/types/program/index.ts | 2 +- .../format/src/types/program/instruction.test.ts | 4 ++-- packages/format/src/types/program/instruction.ts | 4 ++-- packages/format/src/types/program/program.test.ts | 4 ++-- packages/format/src/types/program/program.ts | 6 +++--- packages/format/src/types/type/base.test.ts | 4 ++-- packages/format/src/types/type/index.test.ts | 4 ++-- packages/format/src/types/type/index.ts | 6 +++--- packages/format/test/guards.ts | 2 +- packages/format/test/hyperjump.ts | 5 ++--- packages/format/tsconfig.json | 6 +++--- packages/format/vitest.d.ts | 2 +- packages/web/docusaurus.config.ts | 15 +++++++++++++++ packages/web/package.json | 4 ++++ yarn.lock | 13 ++++++++++--- 30 files changed, 92 insertions(+), 63 deletions(-) diff --git a/packages/format/bin/generate-schema-yamls.js b/packages/format/bin/generate-schema-yamls.js index 3671935f6..181b41a85 100644 --- a/packages/format/bin/generate-schema-yamls.js +++ b/packages/format/bin/generate-schema-yamls.js @@ -1,9 +1,12 @@ -const fs = require("fs"); -const path = require("path"); -const YAML = require("yaml"); +import fs from "fs"; +import path from "path"; +import { fileURLToPath } from "url"; +import YAML from "yaml"; -const filename = __dirname; -const repositoryRoot = path.resolve(filename, "../../../"); +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); + +const repositoryRoot = path.resolve(__dirname, "../../../"); const schemasRoot = path.resolve(repositoryRoot, "./schemas"); const readSchemaYamls = (directory) => { diff --git a/packages/format/package.json b/packages/format/package.json index a8a82323f..c9bec3773 100644 --- a/packages/format/package.json +++ b/packages/format/package.json @@ -2,6 +2,7 @@ "name": "@ethdebug/format", "version": "0.1.0-0", "description": "ethdebug/format schemas distributed as NPM package", + "type": "module", "main": "dist/src/index.js", "repository": "https://github.com/ethdebug/format", "license": "MIT", diff --git a/packages/format/src/describe.ts b/packages/format/src/describe.ts index 225e94c9d..1ccd08de2 100644 --- a/packages/format/src/describe.ts +++ b/packages/format/src/describe.ts @@ -1,6 +1,6 @@ import * as YAML from "yaml"; -import { schemaYamls } from "./schemas/yamls"; +import { schemaYamls } from "./schemas/yamls.js"; import type { JSONSchema as JSONSchemaTyped } from "json-schema-typed/draft-2020-12"; diff --git a/packages/format/src/index.ts b/packages/format/src/index.ts index 983b437c1..45840f0fc 100644 --- a/packages/format/src/index.ts +++ b/packages/format/src/index.ts @@ -1,4 +1,4 @@ -export * from "./describe"; -export { schemas, schemaIds, type Schema } from "./schemas"; +export * from "./describe.js"; +export { schemas, schemaIds, type Schema } from "./schemas/index.js"; -export * from "./types"; +export * from "./types/index.js"; diff --git a/packages/format/src/schemas/examples.test.ts b/packages/format/src/schemas/examples.test.ts index c4cc5e1fc..a8224dbec 100644 --- a/packages/format/src/schemas/examples.test.ts +++ b/packages/format/src/schemas/examples.test.ts @@ -1,11 +1,11 @@ import { expect, describe, it } from "vitest"; -import { schemaExtensions } from "../../test/extensions"; -import { schemas } from "."; -import type { JSONSchema } from "../describe"; +import { schemaExtensions } from "../../test/extensions.js"; +import { schemas } from "./index.js"; +import type { JSONSchema } from "../describe.js"; // loads schemas into global hyperjump json schema validator -import "../../test/hyperjump"; +import "../../test/hyperjump.js"; const idsOfSchemasAllowedToOmitExamples = new Set([ "schema:ethdebug/format/type", diff --git a/packages/format/src/schemas/index.ts b/packages/format/src/schemas/index.ts index 2d2c9c972..f1f9b2bd5 100644 --- a/packages/format/src/schemas/index.ts +++ b/packages/format/src/schemas/index.ts @@ -1,6 +1,6 @@ -import { describeSchema } from "../describe"; -import { schemaYamls } from "./yamls"; -export type { Schema } from "./yamls"; +import { describeSchema } from "../describe.js"; +import { schemaYamls } from "./yamls.js"; +export type { Schema } from "./yamls.js"; export const schemaIds: string[] = Object.keys(schemaYamls); export const schemas = schemaIds diff --git a/packages/format/src/schemas/validity.test.ts b/packages/format/src/schemas/validity.test.ts index 5b7385212..109876f87 100644 --- a/packages/format/src/schemas/validity.test.ts +++ b/packages/format/src/schemas/validity.test.ts @@ -5,10 +5,10 @@ import { InvalidSchemaError, } from "@hyperjump/json-schema/draft-2020-12"; -import { schemas } from "."; +import { schemas } from "./index.js"; // loads schemas into global hyperjump json schema validator -import "../../test/hyperjump"; +import "../../test/hyperjump.js"; const printErrors = (output: { errors?: OutputUnit[] }): string => output diff --git a/packages/format/src/types/data/index.test.ts b/packages/format/src/types/data/index.test.ts index 05f09b70c..2a7cf75af 100644 --- a/packages/format/src/types/data/index.test.ts +++ b/packages/format/src/types/data/index.test.ts @@ -1,4 +1,4 @@ -import { testSchemaGuards } from "../../../test/guards"; +import { testSchemaGuards } from "../../../test/guards.js"; import { Data } from "./index.js"; diff --git a/packages/format/src/types/index.ts b/packages/format/src/types/index.ts index de2fda8e1..47bef9427 100644 --- a/packages/format/src/types/index.ts +++ b/packages/format/src/types/index.ts @@ -1,5 +1,5 @@ -export * from "./data"; -export * from "./materials"; -export * from "./type"; -export * from "./pointer"; -export * from "./program"; +export * from "./data/index.js"; +export * from "./materials/index.js"; +export * from "./type/index.js"; +export * from "./pointer/index.js"; +export * from "./program/index.js"; diff --git a/packages/format/src/types/materials/index.test.ts b/packages/format/src/types/materials/index.test.ts index 6174af469..0cd0ba349 100644 --- a/packages/format/src/types/materials/index.test.ts +++ b/packages/format/src/types/materials/index.test.ts @@ -1,5 +1,5 @@ -import { testSchemaGuards } from "../../../test/guards"; -import { Materials } from "./index"; +import { testSchemaGuards } from "../../../test/guards.js"; +import { Materials } from "./index.js"; testSchemaGuards("ethdebug/format/materials", [ { diff --git a/packages/format/src/types/materials/index.ts b/packages/format/src/types/materials/index.ts index 80d837ebf..1be38c48b 100644 --- a/packages/format/src/types/materials/index.ts +++ b/packages/format/src/types/materials/index.ts @@ -1,4 +1,4 @@ -import { Data } from "../data"; +import { Data } from "../data/index.js"; export namespace Materials { export type Id = number | string; diff --git a/packages/format/src/types/pointer/index.ts b/packages/format/src/types/pointer/index.ts index a5db72c0f..bbf18126a 100644 --- a/packages/format/src/types/pointer/index.ts +++ b/packages/format/src/types/pointer/index.ts @@ -1 +1 @@ -export { Pointer, isPointer } from "./pointer"; +export { Pointer, isPointer } from "./pointer.js"; diff --git a/packages/format/src/types/pointer/pointer.test.ts b/packages/format/src/types/pointer/pointer.test.ts index 49dc73bfe..325b5dd74 100644 --- a/packages/format/src/types/pointer/pointer.test.ts +++ b/packages/format/src/types/pointer/pointer.test.ts @@ -1,6 +1,6 @@ -import { testSchemaGuards } from "../../../test/guards"; +import { testSchemaGuards } from "../../../test/guards.js"; -import { Pointer, isPointer } from "./pointer"; +import { Pointer, isPointer } from "./pointer.js"; const expressionSchema = "schema:ethdebug/format/pointer/expression"; testSchemaGuards("ethdebug/format/pointer", [ diff --git a/packages/format/src/types/program/context.test.ts b/packages/format/src/types/program/context.test.ts index a8c6a6d9a..cb182fe46 100644 --- a/packages/format/src/types/program/context.test.ts +++ b/packages/format/src/types/program/context.test.ts @@ -1,5 +1,5 @@ -import { testSchemaGuards } from "../../../test/guards"; -import { Context, isContext } from "./context"; +import { testSchemaGuards } from "../../../test/guards.js"; +import { Context, isContext } from "./context.js"; testSchemaGuards("ethdebug/format/program/context", [ { diff --git a/packages/format/src/types/program/context.ts b/packages/format/src/types/program/context.ts index 34de5899e..ebef4f526 100644 --- a/packages/format/src/types/program/context.ts +++ b/packages/format/src/types/program/context.ts @@ -1,6 +1,6 @@ -import { Materials } from "../materials"; -import { Type, isType } from "../type"; -import { Pointer, isPointer } from "../pointer"; +import { Materials } from "../materials/index.js"; +import { Type, isType } from "../type/index.js"; +import { Pointer, isPointer } from "../pointer/index.js"; export type Context = | Context.Code diff --git a/packages/format/src/types/program/index.ts b/packages/format/src/types/program/index.ts index e5f765d5a..016e46173 100644 --- a/packages/format/src/types/program/index.ts +++ b/packages/format/src/types/program/index.ts @@ -1 +1 @@ -export { Program, isProgram } from "./program"; +export { Program, isProgram } from "./program.js"; diff --git a/packages/format/src/types/program/instruction.test.ts b/packages/format/src/types/program/instruction.test.ts index d3c7287aa..1c5f694a9 100644 --- a/packages/format/src/types/program/instruction.test.ts +++ b/packages/format/src/types/program/instruction.test.ts @@ -1,5 +1,5 @@ -import { testSchemaGuards } from "../../../test/guards"; -import { isInstruction } from "./instruction"; +import { testSchemaGuards } from "../../../test/guards.js"; +import { isInstruction } from "./instruction.js"; testSchemaGuards("ethdebug/format/program/instruction", [ { diff --git a/packages/format/src/types/program/instruction.ts b/packages/format/src/types/program/instruction.ts index f8e10db1f..79223dbb0 100644 --- a/packages/format/src/types/program/instruction.ts +++ b/packages/format/src/types/program/instruction.ts @@ -1,6 +1,6 @@ -import { Data } from "../data"; +import { Data } from "../data/index.js"; -import { Context, isContext } from "./context"; +import { Context, isContext } from "./context.js"; export interface Instruction { offset: Data.Value; diff --git a/packages/format/src/types/program/program.test.ts b/packages/format/src/types/program/program.test.ts index 7e82206b1..cd74502e4 100644 --- a/packages/format/src/types/program/program.test.ts +++ b/packages/format/src/types/program/program.test.ts @@ -1,5 +1,5 @@ -import { testSchemaGuards } from "../../../test/guards"; -import { isProgram } from "./program"; +import { testSchemaGuards } from "../../../test/guards.js"; +import { isProgram } from "./program.js"; testSchemaGuards("ethdebug/format/program", [ { diff --git a/packages/format/src/types/program/program.ts b/packages/format/src/types/program/program.ts index 0bb9d6a75..2272baacd 100644 --- a/packages/format/src/types/program/program.ts +++ b/packages/format/src/types/program/program.ts @@ -1,11 +1,11 @@ -import { Materials } from "../materials"; +import { Materials } from "../materials/index.js"; -import { Context as _Context, isContext as _isContext } from "./context"; +import { Context as _Context, isContext as _isContext } from "./context.js"; import { Instruction as _Instruction, isInstruction as _isInstruction, -} from "./instruction"; +} from "./instruction.js"; export interface Program { compilation?: Materials.Reference; diff --git a/packages/format/src/types/type/base.test.ts b/packages/format/src/types/type/base.test.ts index e131b3b14..dfc445682 100644 --- a/packages/format/src/types/type/base.test.ts +++ b/packages/format/src/types/type/base.test.ts @@ -1,5 +1,5 @@ -import { testSchemaGuards } from "../../../test/guards"; -import * as Base from "./base"; +import { testSchemaGuards } from "../../../test/guards.js"; +import * as Base from "./base.js"; testSchemaGuards("ethdebug/format/type/base", [ { diff --git a/packages/format/src/types/type/index.test.ts b/packages/format/src/types/type/index.test.ts index 6480b85ca..3af9b0497 100644 --- a/packages/format/src/types/type/index.test.ts +++ b/packages/format/src/types/type/index.test.ts @@ -1,5 +1,5 @@ -import { testSchemaGuards } from "../../../test/guards"; -import { Type, isType } from "./index"; +import { testSchemaGuards } from "../../../test/guards.js"; +import { Type, isType } from "./index.js"; testSchemaGuards("ethdebug/format/type", [ { diff --git a/packages/format/src/types/type/index.ts b/packages/format/src/types/type/index.ts index 32d31e882..b3721a2d8 100644 --- a/packages/format/src/types/type/index.ts +++ b/packages/format/src/types/type/index.ts @@ -1,7 +1,7 @@ -import { Data } from "../data"; -import { Materials } from "../materials"; +import { Data } from "../data/index.js"; +import { Materials } from "../materials/index.js"; -import * as _Base from "./base"; +import * as _Base from "./base.js"; export type Type = Type.Known | Type.Unknown; diff --git a/packages/format/test/guards.ts b/packages/format/test/guards.ts index f03856640..27454c815 100644 --- a/packages/format/test/guards.ts +++ b/packages/format/test/guards.ts @@ -1,6 +1,6 @@ import { expect, describe, it } from "vitest"; -import { type DescribeSchemaOptions, describeSchema } from "../src"; +import { type DescribeSchemaOptions, describeSchema } from "../src/index.js"; export interface SchemaGuard extends DescribeSchemaOptions { guard(value: unknown): boolean; diff --git a/packages/format/test/hyperjump.ts b/packages/format/test/hyperjump.ts index de5c3e7e0..bbbaeead2 100644 --- a/packages/format/test/hyperjump.ts +++ b/packages/format/test/hyperjump.ts @@ -4,15 +4,14 @@ import { validate, setMetaSchemaOutputFormat, } from "@hyperjump/json-schema/draft-2020-12"; -// @ts-expect-error no types for experimental export import { BASIC } from "@hyperjump/json-schema/experimental"; import * as YAML from "yaml"; import indentString from "indent-string"; import { highlight } from "cli-highlight"; -import { describeSchema, type DescribeSchemaOptions } from "../src/describe"; +import { describeSchema, type DescribeSchemaOptions } from "../src/describe.js"; -import { schemas } from "../src/schemas"; +import { schemas } from "../src/schemas/index.js"; const main = () => { setMetaSchemaOutputFormat(BASIC); diff --git a/packages/format/tsconfig.json b/packages/format/tsconfig.json index 1ff58c752..52b9fef64 100644 --- a/packages/format/tsconfig.json +++ b/packages/format/tsconfig.json @@ -1,9 +1,9 @@ { "extends": "../../tsconfig.base.json", "compilerOptions": { - "target": "es2017", - "module": "commonjs", - "moduleResolution": "node10", + "target": "es2020", + "module": "nodenext", + "moduleResolution": "nodenext", "exactOptionalPropertyTypes": true, "rootDir": "./", "outDir": "./dist/" diff --git a/packages/format/vitest.d.ts b/packages/format/vitest.d.ts index 6b4b8f400..f6a44880a 100644 --- a/packages/format/vitest.d.ts +++ b/packages/format/vitest.d.ts @@ -1,5 +1,5 @@ import "vitest"; -import type { DescribeSchemaOptions } from "./src/describe"; +import type { DescribeSchemaOptions } from "./src/describe.js"; interface CustomMatchers { toValidate(schemaOptions: DescribeSchemaOptions): R; diff --git a/packages/web/docusaurus.config.ts b/packages/web/docusaurus.config.ts index 30cc36ebf..3abec10e5 100644 --- a/packages/web/docusaurus.config.ts +++ b/packages/web/docusaurus.config.ts @@ -45,6 +45,20 @@ const config: Config = { name: "custom-resolve", configureWebpack(config: Configuration) { return { + module: { + rules: [ + { + test: /\.m?js$/, + include: /node_modules\/@ethdebug/, + use: { + loader: "babel-loader", + options: { + presets: [["@babel/preset-env", { modules: false }]], + }, + }, + }, + ], + }, resolve: { alias: { react: path.resolve("../../node_modules/react"), @@ -53,6 +67,7 @@ const config: Config = { buffer: false, util: false, }, + fullySpecified: false, }, }; }, diff --git a/packages/web/package.json b/packages/web/package.json index e4f1883db..cdd5a76fe 100644 --- a/packages/web/package.json +++ b/packages/web/package.json @@ -22,6 +22,7 @@ "@docusaurus/tsconfig": "^3.9.2", "@docusaurus/types": "^3.9.2", "@ethdebug/format": "^0.1.0-0", + "@ethdebug/pointers": "^0.1.0-0", "@fortawesome/fontawesome-svg-core": "^6.7.2", "@fortawesome/free-brands-svg-icons": "^6.7.2", "@fortawesome/free-solid-svg-icons": "^6.7.2", @@ -44,9 +45,12 @@ "yaml-template": "^1.0.0" }, "devDependencies": { + "@babel/core": "^7.28.6", + "@babel/preset-env": "^7.28.6", "@docusaurus/module-type-aliases": "^3.9.2", "@docusaurus/tsconfig": "^3.9.2", "@docusaurus/types": "^3.9.2", + "babel-loader": "^10.0.0", "json-schema-typed": "8.0.1", "typescript": "^5.9.3" }, diff --git a/yarn.lock b/yarn.lock index d9b90ff83..33860f070 100644 --- a/yarn.lock +++ b/yarn.lock @@ -266,7 +266,7 @@ json5 "^2.2.3" semver "^6.3.1" -"@babel/core@^7.25.9": +"@babel/core@^7.25.9", "@babel/core@^7.28.6": version "7.28.6" resolved "https://registry.yarnpkg.com/@babel/core/-/core-7.28.6.tgz#531bf883a1126e53501ba46eb3bb414047af507f" integrity sha512-H3mcG6ZDLTlYfaSNi0iOKkigqMFvkTKlGUYlD8GW7nNOYRrevuA46iTypPyv+06V3fEmvvazfntkBU34L0azAw== @@ -1969,7 +1969,7 @@ core-js-compat "^3.31.0" semver "^6.3.1" -"@babel/preset-env@^7.25.9": +"@babel/preset-env@^7.25.9", "@babel/preset-env@^7.28.6": version "7.28.6" resolved "https://registry.yarnpkg.com/@babel/preset-env/-/preset-env-7.28.6.tgz#b4586bb59d8c61be6c58997f4912e7ea6bd17178" integrity sha512-GaTI4nXDrs7l0qaJ6Rg06dtOXTBCG6TMDB44zbqofCIC4PqC7SEvmFFtpxzCDw9W5aJ7RKVshgXTLvLdBFV/qw== @@ -6145,6 +6145,13 @@ axios@^1.8.3: form-data "^4.0.4" proxy-from-env "^1.1.0" +babel-loader@^10.0.0: + version "10.0.0" + resolved "https://registry.yarnpkg.com/babel-loader/-/babel-loader-10.0.0.tgz#b9743714c0e1e084b3e4adef3cd5faee33089977" + integrity sha512-z8jt+EdS61AMw22nSfoNJAZ0vrtmhPRVi6ghL3rCeRZI8cdNYFiV5xeV3HbE7rlZZNmGH8BVccwWt8/ED0QOHA== + dependencies: + find-up "^5.0.0" + babel-loader@^9.2.1: version "9.2.1" resolved "https://registry.yarnpkg.com/babel-loader/-/babel-loader-9.2.1.tgz#04c7835db16c246dd19ba0914418f3937797587b" @@ -8318,7 +8325,7 @@ etag@~1.8.1: resolved "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz" integrity sha512-aIL5Fx7mawVa300al2BnEE4iNvo1qETxLrPI/o05L7z6go7fCw1J6EQmbK4FmJ2AS7kgVF/KEZWufBfdClMcPg== -ethereum-cryptography@^2.2.1: +ethereum-cryptography@^2.1.3, ethereum-cryptography@^2.2.1: version "2.2.1" resolved "https://registry.yarnpkg.com/ethereum-cryptography/-/ethereum-cryptography-2.2.1.tgz#58f2810f8e020aecb97de8c8c76147600b0b8ccf" integrity sha512-r/W8lkHSiTLxUxW8Rf3u4HGB0xQweG2RyETjywylKZSzLWoWAijRz8WCuOtJ6wah+avllXBqZuk29HCCvhEIRg==