Revert "chore(deps): route @codemirror imports through src/editor/codemirror barrel"

This reverts commit 6c4d19d229.
This commit is contained in:
Zero Liu 2026-05-15 14:47:09 -07:00
parent dc08ced1f6
commit ef0c8f3387
No known key found for this signature in database
14 changed files with 19 additions and 74 deletions

View file

@ -141,42 +141,6 @@ export default [
},
},
// @codemirror/state and @codemirror/view are provided by Obsidian at runtime
// (declared as peerDependencies on `obsidian` and marked external in our
// esbuild config), so they intentionally aren't listed in our package.json
// — when they were, the obsidian community-plugins review ran out of memory
// analyzing the resulting dep tree. All imports of these packages must go
// through the `src/editor/codemirror.ts` barrel so we can scope the
// `import/no-extraneous-dependencies` exemption to a single file. The
// barrel itself is exempted here; everywhere else, the
// `no-restricted-imports` rule below blocks direct @codemirror imports.
{
files: ["src/editor/codemirror.ts"],
rules: {
"import/no-extraneous-dependencies": "off",
},
},
{
files: ["src/**/*.{ts,tsx}"],
ignores: ["src/editor/codemirror.ts"],
rules: {
"no-restricted-imports": [
"error",
{
patterns: [
{
group: ["@codemirror/state", "@codemirror/view"],
message:
"Import codemirror symbols from '@/editor/codemirror' instead. " +
"Direct imports from @codemirror/* are restricted because those packages " +
"are intentionally absent from package.json (see src/editor/codemirror.ts).",
},
],
},
],
},
},
// Test files need Jest globals
{
files: ["**/*.test.{js,jsx,ts,tsx}", "jest.setup.js", "__mocks__/**"],

View file

@ -11,7 +11,7 @@ import { logError } from "@/logger";
import { cleanMessageForCopy, findCustomModel, insertIntoEditor } from "@/utils";
import { computeVerticalPlacement } from "@/utils/panelPlacement";
import { computeSelectionAnchors } from "@/utils/selectionAnchors";
import type { EditorView } from "@/editor/codemirror";
import type { EditorView } from "@codemirror/view";
import { PenLine } from "lucide-react";
import { App, Component, MarkdownRenderer, Notice, MarkdownView, Scope } from "obsidian";
import React, { useCallback, useEffect, useMemo, useRef, useState } from "react";

View file

@ -6,7 +6,7 @@
* QuickAskPanel fills its container and delegates resize events here.
*/
import { EditorView } from "@/editor/codemirror";
import { EditorView } from "@codemirror/view";
import type { Editor } from "obsidian";
import React from "react";
import { Root } from "react-dom/client";

View file

@ -2,7 +2,7 @@
* Type definitions for Quick Ask feature.
*/
import type { EditorView } from "@/editor/codemirror";
import type { EditorView } from "@codemirror/view";
import type { Editor } from "obsidian";
import type CopilotPlugin from "@/main";
import type { ReplaceGuard } from "@/editor/replaceGuard";

View file

@ -6,7 +6,7 @@
* conflicts with SelectionHighlight used by QuickAsk and CustomCommandModal.
*/
import { EditorView } from "@/editor/codemirror";
import { EditorView } from "@codemirror/view";
import { MarkdownView, type WorkspaceLeaf } from "obsidian";
import type CopilotPlugin from "@/main";

View file

@ -1,18 +0,0 @@
// Re-exports for the @codemirror/* APIs the plugin uses.
//
// Why this barrel exists: Obsidian provides @codemirror/state and
// @codemirror/view at runtime (declared as peerDependencies on `obsidian` and
// marked external in esbuild.config.mjs), so they aren't listed in our own
// package.json — when we listed them as devDependencies, the obsidian
// community-plugins review ran out of memory analyzing the resulting dep tree.
// The `import/no-extraneous-dependencies` ESLint rule has no per-package
// whitelist, so we funnel every @codemirror import through this single file
// and exempt only this file in eslint.config.mjs (paired with a
// `no-restricted-imports` rule that forbids direct @codemirror imports
// elsewhere). All other source files import codemirror symbols from
// `@/editor/codemirror`.
export { EditorState, StateEffect, StateField } from "@codemirror/state";
export type { ChangeDesc, Extension, StateEffectType } from "@codemirror/state";
export { Decoration, EditorView, ViewPlugin } from "@codemirror/view";
export type { ViewUpdate } from "@codemirror/view";

View file

@ -1,5 +1,6 @@
import { createPersistentHighlight } from "./persistentHighlight";
import { EditorState, EditorView } from "@/editor/codemirror";
import { EditorState } from "@codemirror/state";
import { EditorView } from "@codemirror/view";
describe("createPersistentHighlight", () => {
describe("factory isolation", () => {

View file

@ -7,14 +7,8 @@
* (e.g. QuickAsk and Chat) can coexist without state conflicts.
*/
import {
Decoration,
EditorView,
StateEffect,
StateField,
type Extension,
type StateEffectType,
} from "@/editor/codemirror";
import { StateEffect, StateEffectType, StateField, type Extension } from "@codemirror/state";
import { Decoration, EditorView } from "@codemirror/view";
// ============================================================================
// Types

View file

@ -3,7 +3,8 @@
* Manages the lifecycle of Quick Ask panels and integrates with CM6.
*/
import { EditorView, type Extension } from "@/editor/codemirror";
import type { Extension } from "@codemirror/state";
import { EditorView } from "@codemirror/view";
import { MarkdownView } from "obsidian";
import { quickAskWidgetEffect, quickAskOverlayPlugin } from "./quickAskExtension";
import { QuickAskOverlay } from "@/components/quick-ask/QuickAskOverlay";

View file

@ -7,7 +7,8 @@
* that occur when dispatching from within ViewPlugin.update().
*/
import { EditorView, StateEffect, ViewPlugin, type ViewUpdate } from "@/editor/codemirror";
import { StateEffect } from "@codemirror/state";
import { EditorView, ViewPlugin, ViewUpdate } from "@codemirror/view";
import { QuickAskOverlay } from "@/components/quick-ask/QuickAskOverlay";
import type { QuickAskWidgetPayload } from "@/components/quick-ask/types";
import { mapQuickAskAnchorPositions } from "@/utils/quickAskAnchorMapping";

View file

@ -3,7 +3,7 @@ import {
createHighlightReplaceGuard,
getErrorMessage,
} from "./replaceGuard";
import type { EditorView } from "@/editor/codemirror";
import type { EditorView } from "@codemirror/view";
import type { WorkspaceLeaf } from "obsidian";
// Mock dependencies
@ -318,7 +318,7 @@ describe("createMapPosReplaceGuard", () => {
mapPos: (pos: number, assoc: number) => pos + 3,
};
guard.onDocChanged?.(mockChanges as unknown as import("@/editor/codemirror").ChangeDesc);
guard.onDocChanged?.(mockChanges as unknown as import("@codemirror/state").ChangeDesc);
expect(guard.getRange()).toEqual({ from: 3, to: 8 });
});

View file

@ -1,6 +1,7 @@
// src/editor/replaceGuard.ts
import type { ChangeDesc, EditorView } from "@/editor/codemirror";
import type { ChangeDesc } from "@codemirror/state";
import type { EditorView } from "@codemirror/view";
import type { WorkspaceLeaf } from "obsidian";
import { SelectionHighlight } from "./selectionHighlight";
import { logError } from "@/logger";

View file

@ -8,7 +8,8 @@
* factory, preserving the original public API for backwards compatibility.
*/
import { EditorView, StateEffect } from "@/editor/codemirror";
import { StateEffect } from "@codemirror/state";
import { EditorView } from "@codemirror/view";
import { logError } from "@/logger";
import {
createPersistentHighlight,

View file

@ -1,4 +1,4 @@
import type { EditorView } from "@/editor/codemirror";
import type { EditorView } from "@codemirror/view";
import { type TFile } from "obsidian";
declare module "obsidian" {