Skip to content

Commit a5a7d6c

Browse files
committed
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
1 parent cb855c4 commit a5a7d6c

30 files changed

Lines changed: 92 additions & 63 deletions

‎packages/format/bin/generate-schema-yamls.js‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
const fs = require("fs");
2-
const path = require("path");
3-
const YAML = require("yaml");
1+
import fs from "fs";
2+
import path from "path";
3+
import { fileURLToPath } from "url";
4+
import YAML from "yaml";
45

5-
const filename = __dirname;
6-
const repositoryRoot = path.resolve(filename, "../../../");
6+
const __filename = fileURLToPath(import.meta.url);
7+
const __dirname = path.dirname(__filename);
8+
9+
const repositoryRoot = path.resolve(__dirname, "../../../");
710
const schemasRoot = path.resolve(repositoryRoot, "./schemas");
811

912
const readSchemaYamls = (directory) => {

‎packages/format/package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"name": "@ethdebug/format",
33
"version": "0.1.0-0",
44
"description": "ethdebug/format schemas distributed as NPM package",
5+
"type": "module",
56
"main": "dist/src/index.js",
67
"repository": "https://github.com/ethdebug/format",
78
"license": "MIT",

‎packages/format/src/describe.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as YAML from "yaml";
22

3-
import { schemaYamls } from "./schemas/yamls";
3+
import { schemaYamls } from "./schemas/yamls.js";
44

55
import type { JSONSchema as JSONSchemaTyped } from "json-schema-typed/draft-2020-12";
66

‎packages/format/src/index.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export * from "./describe";
2-
export { schemas, schemaIds, type Schema } from "./schemas";
1+
export * from "./describe.js";
2+
export { schemas, schemaIds, type Schema } from "./schemas/index.js";
33

4-
export * from "./types";
4+
export * from "./types/index.js";

‎packages/format/src/schemas/examples.test.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { expect, describe, it } from "vitest";
22

3-
import { schemaExtensions } from "../../test/extensions";
4-
import { schemas } from ".";
5-
import type { JSONSchema } from "../describe";
3+
import { schemaExtensions } from "../../test/extensions.js";
4+
import { schemas } from "./index.js";
5+
import type { JSONSchema } from "../describe.js";
66

77
// loads schemas into global hyperjump json schema validator
8-
import "../../test/hyperjump";
8+
import "../../test/hyperjump.js";
99

1010
const idsOfSchemasAllowedToOmitExamples = new Set([
1111
"schema:ethdebug/format/type",

‎packages/format/src/schemas/index.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { describeSchema } from "../describe";
2-
import { schemaYamls } from "./yamls";
3-
export type { Schema } from "./yamls";
1+
import { describeSchema } from "../describe.js";
2+
import { schemaYamls } from "./yamls.js";
3+
export type { Schema } from "./yamls.js";
44

55
export const schemaIds: string[] = Object.keys(schemaYamls);
66
export const schemas = schemaIds

‎packages/format/src/schemas/validity.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import {
55
InvalidSchemaError,
66
} from "@hyperjump/json-schema/draft-2020-12";
77

8-
import { schemas } from ".";
8+
import { schemas } from "./index.js";
99

1010
// loads schemas into global hyperjump json schema validator
11-
import "../../test/hyperjump";
11+
import "../../test/hyperjump.js";
1212

1313
const printErrors = (output: { errors?: OutputUnit[] }): string =>
1414
output

‎packages/format/src/types/data/index.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { testSchemaGuards } from "../../../test/guards";
1+
import { testSchemaGuards } from "../../../test/guards.js";
22

33
import { Data } from "./index.js";
44

‎packages/format/src/types/index.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
export * from "./data";
2-
export * from "./materials";
3-
export * from "./type";
4-
export * from "./pointer";
5-
export * from "./program";
1+
export * from "./data/index.js";
2+
export * from "./materials/index.js";
3+
export * from "./type/index.js";
4+
export * from "./pointer/index.js";
5+
export * from "./program/index.js";

‎packages/format/src/types/materials/index.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { testSchemaGuards } from "../../../test/guards";
2-
import { Materials } from "./index";
1+
import { testSchemaGuards } from "../../../test/guards.js";
2+
import { Materials } from "./index.js";
33

44
testSchemaGuards("ethdebug/format/materials", [
55
{

0 commit comments

Comments
 (0)