diff --git a/packages/core/src/core/diff.ts b/packages/core/src/core/diff.ts index 419f838..eb6043a 100644 --- a/packages/core/src/core/diff.ts +++ b/packages/core/src/core/diff.ts @@ -22,9 +22,9 @@ import { LoroTreeSchema, RootSchemaType, SchemaType, -} from "../schema"; -import { ChangeKinds, InferContainerOptions, type Change } from "./mirror"; -import { CID_KEY } from "../constants"; +} from "../schema/index.js"; +import { ChangeKinds, InferContainerOptions, type Change } from "./mirror.js"; +import { CID_KEY } from "../constants.js"; import { containerIdToContainerType, @@ -42,7 +42,7 @@ import { isArrayLike, isTreeID, defineCidProperty, -} from "./utils"; +} from "./utils.js"; /** * Finds the longest increasing subsequence of a sequence of numbers diff --git a/packages/core/src/core/index.ts b/packages/core/src/core/index.ts index 629a08d..41c7ba6 100644 --- a/packages/core/src/core/index.ts +++ b/packages/core/src/core/index.ts @@ -2,11 +2,11 @@ * Core mirroring functionality for syncing application state with Loro CRDT */ -export { Mirror, SyncDirection, toNormalizedJson } from "./mirror"; +export { Mirror, SyncDirection, toNormalizedJson } from "./mirror.js"; export type { InferContainerOptions, MirrorOptions, SetStateOptions, SubscriberCallback, UpdateMetadata, -} from "./mirror"; +} from "./mirror.js"; diff --git a/packages/core/src/core/loroEventApply.test.ts b/packages/core/src/core/loroEventApply.test.ts index d9d2f57..d2030a4 100644 --- a/packages/core/src/core/loroEventApply.test.ts +++ b/packages/core/src/core/loroEventApply.test.ts @@ -1,7 +1,7 @@ /* eslint-disable unicorn/consistent-function-scoping */ import { describe, it, expect } from "vitest"; import { LoroDoc, LoroText, LoroList, LoroMap, LoroCounter } from "loro-crdt"; -import { applyEventBatchToState } from "./loroEventApply"; +import { applyEventBatchToState } from "./loroEventApply.js"; const commitAndAssert = (doc: LoroDoc, getState: () => unknown) => { doc.commit(); diff --git a/packages/core/src/core/loroEventApply.ts b/packages/core/src/core/loroEventApply.ts index 3af593e..c5fb546 100644 --- a/packages/core/src/core/loroEventApply.ts +++ b/packages/core/src/core/loroEventApply.ts @@ -8,7 +8,7 @@ import { LoroEventBatch, TreeID, } from "loro-crdt"; -import { defineCidProperty, isTreeID } from "./utils"; +import { defineCidProperty, isTreeID } from "./utils.js"; // Plain JSON-like value held in Mirror state (no `any`) type JSONPrimitive = string | number | boolean | null | undefined; diff --git a/packages/core/src/core/mirror.ts b/packages/core/src/core/mirror.ts index 04cef9f..505969e 100644 --- a/packages/core/src/core/mirror.ts +++ b/packages/core/src/core/mirror.ts @@ -18,7 +18,7 @@ import { TreeID, } from "loro-crdt"; -import { applyEventBatchToState } from "./loroEventApply"; +import { applyEventBatchToState } from "./loroEventApply.js"; import { ContainerSchemaType, getDefaultValue, @@ -36,7 +36,7 @@ import { RootSchemaType, SchemaType, validateSchema, -} from "../schema"; +} from "../schema/index.js"; import { deepEqual, inferContainerTypeFromValue, @@ -46,9 +46,9 @@ import { tryInferContainerType, getRootContainerByType, defineCidProperty, -} from "./utils"; -import { diffContainer, diffTree } from "./diff"; -import { CID_KEY } from "../constants"; +} from "./utils.js"; +import { diffContainer, diffTree } from "./diff.js"; +import { CID_KEY } from "../constants.js"; // Plain JSON-like value used for state snapshots type JSONPrimitive = string | number | boolean | null | undefined; @@ -98,7 +98,7 @@ export interface MirrorOptions { /** * Initial state (optional) */ - initialState?: Partial>; + initialState?: Partial>; /** * Whether to validate state updates against the schema @@ -726,10 +726,7 @@ export class Mirror { /** * Update Loro based on state changes */ - private updateLoro( - newState: InferType, - options?: SetStateOptions, - ) { + private updateLoro(newState: InferType, options?: SetStateOptions) { if (this.syncing) return; this.syncing = true; diff --git a/packages/core/src/core/utils.ts b/packages/core/src/core/utils.ts index 2496047..71f31ce 100644 --- a/packages/core/src/core/utils.ts +++ b/packages/core/src/core/utils.ts @@ -3,9 +3,9 @@ */ import { Container, ContainerID, ContainerType, LoroDoc } from "loro-crdt"; -import { SchemaType } from "../schema"; -import { Change, InferContainerOptions } from "./mirror"; -import { CID_KEY } from "../constants"; +import { SchemaType } from "../schema/index.js"; +import { Change, InferContainerOptions } from "./mirror.js"; +import { CID_KEY } from "../constants.js"; export function defineCidProperty(target: unknown, cid: ContainerID) { if ( diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index d435a29..3618e4b 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -4,7 +4,7 @@ */ // Re-export all public APIs -export * from "./schema"; +export * from "./schema/index.js"; export { Mirror, toNormalizedJson, @@ -14,11 +14,11 @@ export { type SubscriberCallback, type InferContainerOptions, SyncDirection, -} from "./core"; +} from "./core/index.js"; // Default export -import * as schema from "./schema"; -import * as core from "./core"; +import * as schema from "./schema/index.js"; +import * as core from "./core/index.js"; type Combined = typeof schema & typeof core; const loroMirror: Combined = Object.assign({}, schema, core); diff --git a/packages/core/src/schema/index.ts b/packages/core/src/schema/index.ts index 45ca00e..8298dec 100644 --- a/packages/core/src/schema/index.ts +++ b/packages/core/src/schema/index.ts @@ -21,10 +21,10 @@ import { SchemaType, StringSchemaType, InferType, -} from "./types"; +} from "./types.js"; -export * from "./types"; -export * from "./validators"; +export * from "./types.js"; +export * from "./validators.js"; /** * Create a schema definition diff --git a/packages/core/src/schema/validators.ts b/packages/core/src/schema/validators.ts index 8634580..862920e 100644 --- a/packages/core/src/schema/validators.ts +++ b/packages/core/src/schema/validators.ts @@ -12,8 +12,8 @@ import { LoroTreeSchema, RootSchemaType, SchemaType, -} from "./types"; -import { isObject } from "../core/utils"; +} from "./types.js"; +import { isObject } from "../core/utils.js"; const schemaValidationCache = new WeakMap>(); diff --git a/packages/core/tests/cid.test.ts b/packages/core/tests/cid.test.ts index 261ad79..a9911f0 100644 --- a/packages/core/tests/cid.test.ts +++ b/packages/core/tests/cid.test.ts @@ -1,10 +1,10 @@ import { describe, it, expect, expectTypeOf } from "vitest"; import { LoroDoc, LoroMap } from "loro-crdt"; -import { Mirror } from "../src/core/mirror"; -import { schema } from "../src/schema"; -import { InferType } from "../src"; -import { CID_KEY } from "../src/constants"; -import { diffMap } from "../src/core/diff"; +import { Mirror } from "../src/core/mirror.js"; +import { schema } from "../src/schema/index.js"; +import { InferType } from "../src/index.js"; +import { CID_KEY } from "../src/constants.js"; +import { diffMap } from "../src/core/diff.js"; describe("$cid: state injection and write ignoring (always-on for LoroMap)", () => { it("types: LoroMap includes $cid by default", () => { diff --git a/packages/core/tests/diff-equality.test.ts b/packages/core/tests/diff-equality.test.ts index 1cc6402..e7ca265 100644 --- a/packages/core/tests/diff-equality.test.ts +++ b/packages/core/tests/diff-equality.test.ts @@ -1,7 +1,7 @@ import { describe, it, expect } from "vitest"; import { LoroDoc } from "loro-crdt"; -import { diffContainer } from "../src/core/diff"; -import { schema } from "../src/schema"; +import { diffContainer } from "../src/core/diff.js"; +import { schema } from "../src/schema/index.js"; describe("diffMap equality for falsy primitives", () => { it("does not emit changes when string field stays ''", () => { diff --git a/packages/core/tests/inferType.test-d.ts b/packages/core/tests/inferType.test-d.ts index fea4047..17d5ed1 100644 --- a/packages/core/tests/inferType.test-d.ts +++ b/packages/core/tests/inferType.test-d.ts @@ -1,5 +1,5 @@ import { test, expectTypeOf, describe } from "vitest"; -import { InferType, schema } from "../src"; +import { InferType, schema } from "../src/index.js"; describe("infer type", () => { test("catchall", () => { diff --git a/packages/core/tests/issue.test.ts b/packages/core/tests/issue.test.ts index ea8f139..07f7af3 100644 --- a/packages/core/tests/issue.test.ts +++ b/packages/core/tests/issue.test.ts @@ -1,6 +1,6 @@ import { it, expect } from "vitest"; import { LoroDoc, LoroMap } from "loro-crdt"; -import { Mirror, schema } from "../src/"; +import { Mirror, schema } from "../src/index.js"; it("Applying remote event then calling setState immediately may cause an event apply order issue", async () => { const docA = new LoroDoc(); diff --git a/packages/core/tests/list.test.ts b/packages/core/tests/list.test.ts index 66ff7a1..25ddefa 100644 --- a/packages/core/tests/list.test.ts +++ b/packages/core/tests/list.test.ts @@ -1,6 +1,6 @@ import { describe, it, expect } from "vitest"; -import { longestIncreasingSubsequence } from "../src/core/diff"; -import { Mirror, schema } from "../src"; +import { longestIncreasingSubsequence } from "../src/core/diff.js"; +import { Mirror, schema } from "../src/index.js"; import { LoroDoc } from "loro-crdt"; describe("longestIncreasingSubsequence", () => { diff --git a/packages/core/tests/mirror-list-updates.test.ts b/packages/core/tests/mirror-list-updates.test.ts index f6bf51f..15a3080 100644 --- a/packages/core/tests/mirror-list-updates.test.ts +++ b/packages/core/tests/mirror-list-updates.test.ts @@ -4,9 +4,9 @@ * based on whether an idSelector is provided */ -import { Mirror } from "../src/core/mirror"; +import { Mirror } from "../src/core/mirror.js"; import { LoroDoc, LoroMap } from "loro-crdt"; -import { schema } from "../src/schema"; +import { schema } from "../src/schema/index.js"; import { describe, expect, it } from "vitest"; // Utility function to wait for sync to complete (three microtasks for better reliability) diff --git a/packages/core/tests/mirror-movable-list.test.ts b/packages/core/tests/mirror-movable-list.test.ts index 139e4ba..dda53c1 100644 --- a/packages/core/tests/mirror-movable-list.test.ts +++ b/packages/core/tests/mirror-movable-list.test.ts @@ -1,9 +1,9 @@ /* eslint-disable unicorn/consistent-function-scoping */ -import { Mirror } from "../src/core/mirror"; +import { Mirror } from "../src/core/mirror.js"; import { LoroDoc } from "loro-crdt"; -import { schema } from "../src/schema"; +import { schema } from "../src/schema/index.js"; import { describe, expect, it } from "vitest"; -import { valueIsContainerOfType } from "../src/core/utils"; +import { valueIsContainerOfType } from "../src/core/utils.js"; // Utility function to wait for sync to complete (three microtasks for better reliability) const waitForSync = async () => { diff --git a/packages/core/tests/mirror-tags.test.ts b/packages/core/tests/mirror-tags.test.ts index 86780bc..6a47464 100644 --- a/packages/core/tests/mirror-tags.test.ts +++ b/packages/core/tests/mirror-tags.test.ts @@ -1,5 +1,5 @@ -import { Mirror, SyncDirection, UpdateMetadata } from "../src/core/mirror"; -import { schema } from "../src/schema"; +import { Mirror, SyncDirection, UpdateMetadata } from "../src/core/mirror.js"; +import { schema } from "../src/schema/index.js"; import { LoroDoc } from "loro-crdt"; import { describe, expect, it } from "vitest"; diff --git a/packages/core/tests/mirror-text.test.ts b/packages/core/tests/mirror-text.test.ts index eb6c656..74a75be 100644 --- a/packages/core/tests/mirror-text.test.ts +++ b/packages/core/tests/mirror-text.test.ts @@ -1,8 +1,8 @@ -import { Mirror } from "../src/core/mirror"; +import { Mirror } from "../src/core/mirror.js"; import { LoroDoc, LoroText } from "loro-crdt"; -import { schema } from "../src/schema"; +import { schema } from "../src/schema/index.js"; import { describe, expect, it } from "vitest"; -import { valueIsContainer, valueIsContainerOfType } from "../src/core/utils"; +import { valueIsContainer, valueIsContainerOfType } from "../src/core/utils.js"; // Utility function to wait for sync to complete (three microtasks for better reliability) const waitForSync = async () => { diff --git a/packages/core/tests/mirror-tree.test.ts b/packages/core/tests/mirror-tree.test.ts index 089ebef..514e530 100644 --- a/packages/core/tests/mirror-tree.test.ts +++ b/packages/core/tests/mirror-tree.test.ts @@ -2,9 +2,9 @@ /* eslint-disable unicorn/consistent-function-scoping */ import { describe, it, expect } from "vitest"; import { LoroDoc, LoroText, type LoroEventBatch } from "loro-crdt"; -import { Mirror } from "../src/core/mirror"; -import { applyEventBatchToState } from "../src/core/loroEventApply"; -import { schema } from "../src/schema"; +import { Mirror } from "../src/core/mirror.js"; +import { applyEventBatchToState } from "../src/core/loroEventApply.js"; +import { schema } from "../src/schema/index.js"; // Small helper to wait for microtasks (mirror commits async) const tick = async () => { diff --git a/packages/core/tests/mirror.human.test.ts b/packages/core/tests/mirror.human.test.ts index f957951..eb95d95 100644 --- a/packages/core/tests/mirror.human.test.ts +++ b/packages/core/tests/mirror.human.test.ts @@ -1,5 +1,5 @@ -import { Mirror } from "../src/core/mirror"; -import { schema } from "../src/schema"; +import { Mirror } from "../src/core/mirror.js"; +import { schema } from "../src/schema/index.js"; import { isContainer, LoroDoc, LoroMap } from "loro-crdt"; import { expect, it } from "vitest"; diff --git a/packages/core/tests/mirror.test.ts b/packages/core/tests/mirror.test.ts index f64b41e..e707282 100644 --- a/packages/core/tests/mirror.test.ts +++ b/packages/core/tests/mirror.test.ts @@ -1,6 +1,6 @@ -import { Mirror, SyncDirection } from "../src/core/mirror"; -import { valueIsContainer, valueIsContainerOfType } from "../src/core/utils"; -import { schema } from "../src/schema"; +import { Mirror, SyncDirection } from "../src/core/mirror.js"; +import { valueIsContainer, valueIsContainerOfType } from "../src/core/utils.js"; +import { schema } from "../src/schema/index.js"; import { LoroDoc, LoroList, LoroMap } from "loro-crdt"; import { beforeEach, describe, expect, it, vi } from "vitest"; diff --git a/packages/core/tests/null-in-map-consistency.test.ts b/packages/core/tests/null-in-map-consistency.test.ts index f48b423..69faca1 100644 --- a/packages/core/tests/null-in-map-consistency.test.ts +++ b/packages/core/tests/null-in-map-consistency.test.ts @@ -1,6 +1,6 @@ import { describe, it, expect } from "vitest"; import { LoroDoc, LoroMap, LoroList } from "loro-crdt"; -import { Mirror, schema, toNormalizedJson } from "../src"; +import { Mirror, schema, toNormalizedJson } from "../src/index.js"; function stripCid(value: unknown): unknown { if (Array.isArray(value)) return value.map(stripCid); diff --git a/packages/core/tests/readme.quickstart.test.ts b/packages/core/tests/readme.quickstart.test.ts index f62a90e..753e4de 100644 --- a/packages/core/tests/readme.quickstart.test.ts +++ b/packages/core/tests/readme.quickstart.test.ts @@ -1,6 +1,6 @@ import { describe, it, expect } from "vitest"; import { LoroDoc } from "loro-crdt"; -import { Mirror, schema, validateSchema } from "../src"; +import { Mirror, schema, validateSchema } from "../src/index.js"; describe("README Quick Start examples", () => { it("creates a store, updates immutably and via draft, and injects cid", async () => { diff --git a/packages/core/tests/schema-catchall.test.ts b/packages/core/tests/schema-catchall.test.ts index 0d39a07..8c7586c 100644 --- a/packages/core/tests/schema-catchall.test.ts +++ b/packages/core/tests/schema-catchall.test.ts @@ -2,7 +2,7 @@ * Test for schema catchall functionality */ import { describe, it, expect } from "vitest"; -import { schema } from "../src/schema"; +import { schema } from "../src/schema/index.js"; describe("Schema Catchall Functionality", () => { it("should create a schema with catchall support", () => { diff --git a/packages/core/tests/state.test.ts b/packages/core/tests/state.test.ts index 981641e..73d2a60 100644 --- a/packages/core/tests/state.test.ts +++ b/packages/core/tests/state.test.ts @@ -8,8 +8,8 @@ import { RootSchemaType, schema, StringSchemaType, -} from "../src/schema"; -import { Mirror, SyncDirection } from "../src/core/mirror"; +} from "../src/schema/index.js"; +import { Mirror, SyncDirection } from "../src/core/mirror.js"; import { LoroDoc } from "loro-crdt"; // Utility to wait for sync to complete (three microtasks for reliable sync) diff --git a/packages/core/tests/utils.test.ts b/packages/core/tests/utils.test.ts index e8c9608..ccf42cb 100644 --- a/packages/core/tests/utils.test.ts +++ b/packages/core/tests/utils.test.ts @@ -4,7 +4,7 @@ import { getPathValue, setPathValue, isObject, -} from "../src/core/utils"; +} from "../src/core/utils.js"; describe("Utility Functions", () => { describe("isObject", () => { diff --git a/packages/core/tests/validator.test.ts b/packages/core/tests/validator.test.ts index e9fd660..573f3f0 100644 --- a/packages/core/tests/validator.test.ts +++ b/packages/core/tests/validator.test.ts @@ -1,8 +1,8 @@ import { beforeEach, describe, expect, it, vi } from "vitest"; import { LoroDoc } from "loro-crdt"; -import { Mirror } from "../src/core/mirror"; -import { schema, validateSchema } from "../src/schema"; -import * as schemaModule from "../src/schema"; +import { Mirror } from "../src/core/mirror.js"; +import { schema, validateSchema } from "../src/schema/index.js"; +import * as schemaModule from "../src/schema/index.js"; describe("schema validator caching", () => { let doc: LoroDoc; diff --git a/packages/jotai/tests/index.test.tsx b/packages/jotai/tests/index.test.tsx index a811c88..03dab31 100644 --- a/packages/jotai/tests/index.test.tsx +++ b/packages/jotai/tests/index.test.tsx @@ -3,7 +3,7 @@ import { useAtom } from "jotai"; import { LoroDoc } from "loro-crdt"; import { schema } from "loro-mirror"; import { afterEach, describe, expect, it } from "vitest"; -import { loroMirrorAtom } from "../src"; +import { loroMirrorAtom } from "../src/index.js"; // Helper to wait for Jotai state propagation const waitFor = (ms: number) => diff --git a/packages/jotai/tests/readme.jotai.test.tsx b/packages/jotai/tests/readme.jotai.test.tsx index c7b401e..d092cde 100644 --- a/packages/jotai/tests/readme.jotai.test.tsx +++ b/packages/jotai/tests/readme.jotai.test.tsx @@ -2,7 +2,7 @@ import { describe, expect, it } from "vitest"; import { act, renderHook } from "@testing-library/react"; import { LoroDoc } from "loro-crdt"; import { InferInputType, schema } from "loro-mirror"; -import { loroMirrorAtom } from "../src"; +import { loroMirrorAtom } from "../src/index.js"; import { atom, useAtomValue, useSetAtom } from "jotai"; describe("Jotai README example", () => { diff --git a/packages/react/src/index.ts b/packages/react/src/index.ts index d2a8a1c..91b7363 100644 --- a/packages/react/src/index.ts +++ b/packages/react/src/index.ts @@ -2,4 +2,4 @@ * React integration for Loro Mirror */ -export * from "./hooks"; +export * from "./hooks.js"; diff --git a/packages/react/tests/readme.react.context.test.ts b/packages/react/tests/readme.react.context.test.ts index 386f8b0..cfffb7e 100644 --- a/packages/react/tests/readme.react.context.test.ts +++ b/packages/react/tests/readme.react.context.test.ts @@ -5,7 +5,7 @@ import { useLoroStore, useLoroValue, useLoroCallback, -} from "../src"; +} from "../src/index.js"; describe("React README examples", () => { it("createLoroContext returns provider and hooks for given schema", () => { diff --git a/tsconfig.json b/tsconfig.json index c7ce867..9e33af1 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,8 +1,8 @@ { "compilerOptions": { "target": "ES2020", - "module": "ESNext", - "moduleResolution": "node", + "module": "NodeNext", + "moduleResolution": "NodeNext", "esModuleInterop": true, "strict": true, "skipLibCheck": true,