mirror of
https://github.com/vrtmrz/obsidian-livesync.git
synced 2026-09-01 16:27:07 +00:00
Repo boundary breach detection on import normalise
This commit is contained in:
+18
-18
@@ -1,22 +1,22 @@
|
|||||||
import { LOG_LEVEL_INFO } from "octagonal-wheels/common/logger";
|
import { LOG_LEVEL_INFO } from "octagonal-wheels/common/logger";
|
||||||
import type PouchDB from "pouchdb-core";
|
import type PouchDB from "pouchdb-core";
|
||||||
import type { SimpleStore } from "octagonal-wheels/databases/SimpleStoreBase";
|
import type { SimpleStore } from "octagonal-wheels/databases/SimpleStoreBase";
|
||||||
import type { HasSettings, ObsidianLiveSyncSettings, EntryDoc } from "./lib/src/common/types";
|
import type { HasSettings, ObsidianLiveSyncSettings, EntryDoc } from "@lib/common/types";
|
||||||
import { __$checkInstanceBinding } from "./lib/src/dev/checks";
|
import { __$checkInstanceBinding } from "@lib/dev/checks";
|
||||||
import type { Confirm } from "./lib/src/interfaces/Confirm";
|
import type { Confirm } from "@lib/interfaces/Confirm";
|
||||||
import type { DatabaseFileAccess } from "./lib/src/interfaces/DatabaseFileAccess";
|
import type { DatabaseFileAccess } from "@lib/interfaces/DatabaseFileAccess";
|
||||||
import type { Rebuilder } from "./lib/src/interfaces/DatabaseRebuilder";
|
import type { Rebuilder } from "@lib/interfaces/DatabaseRebuilder";
|
||||||
import type { IFileHandler } from "./lib/src/interfaces/FileHandler";
|
import type { IFileHandler } from "@lib/interfaces/FileHandler";
|
||||||
import type { StorageAccess } from "./lib/src/interfaces/StorageAccess";
|
import type { StorageAccess } from "@lib/interfaces/StorageAccess";
|
||||||
import type { LiveSyncLocalDBEnv } from "./lib/src/pouchdb/LiveSyncLocalDB";
|
import type { LiveSyncLocalDBEnv } from "@lib/pouchdb/LiveSyncLocalDB";
|
||||||
import type { LiveSyncCouchDBReplicatorEnv } from "./lib/src/replication/couchdb/LiveSyncReplicator";
|
import type { LiveSyncCouchDBReplicatorEnv } from "@lib/replication/couchdb/LiveSyncReplicator";
|
||||||
import type { CheckPointInfo } from "./lib/src/replication/journal/JournalSyncTypes";
|
import type { CheckPointInfo } from "@lib/replication/journal/JournalSyncTypes";
|
||||||
import type { LiveSyncJournalReplicatorEnv } from "./lib/src/replication/journal/LiveSyncJournalReplicatorEnv";
|
import type { LiveSyncJournalReplicatorEnv } from "@lib/replication/journal/LiveSyncJournalReplicatorEnv";
|
||||||
import type { LiveSyncReplicatorEnv } from "./lib/src/replication/LiveSyncAbstractReplicator";
|
import type { LiveSyncReplicatorEnv } from "@lib/replication/LiveSyncAbstractReplicator";
|
||||||
import { useTargetFilters } from "./lib/src/serviceFeatures/targetFilter";
|
import { useTargetFilters } from "@lib/serviceFeatures/targetFilter";
|
||||||
import { useRemoteConfigurationMigration } from "./lib/src/serviceFeatures/remoteConfig";
|
import { useRemoteConfigurationMigration } from "@lib/serviceFeatures/remoteConfig";
|
||||||
import type { ServiceContext } from "./lib/src/services/base/ServiceBase";
|
import type { ServiceContext } from "@lib/services/base/ServiceBase";
|
||||||
import type { InjectableServiceHub } from "./lib/src/services/InjectableServices";
|
import type { InjectableServiceHub } from "@lib/services/InjectableServices";
|
||||||
import { AbstractModule } from "./modules/AbstractModule";
|
import { AbstractModule } from "./modules/AbstractModule";
|
||||||
import { ModulePeriodicProcess } from "./modules/core/ModulePeriodicProcess";
|
import { ModulePeriodicProcess } from "./modules/core/ModulePeriodicProcess";
|
||||||
import { ModuleReplicator } from "./modules/core/ModuleReplicator";
|
import { ModuleReplicator } from "./modules/core/ModuleReplicator";
|
||||||
@@ -26,9 +26,9 @@ import { ModuleConflictChecker } from "./modules/coreFeatures/ModuleConflictChec
|
|||||||
import { ModuleConflictResolver } from "./modules/coreFeatures/ModuleConflictResolver";
|
import { ModuleConflictResolver } from "./modules/coreFeatures/ModuleConflictResolver";
|
||||||
import { ModuleResolvingMismatchedTweaks } from "./modules/coreFeatures/ModuleResolveMismatchedTweaks";
|
import { ModuleResolvingMismatchedTweaks } from "./modules/coreFeatures/ModuleResolveMismatchedTweaks";
|
||||||
import { ModuleLiveSyncMain } from "./modules/main/ModuleLiveSyncMain";
|
import { ModuleLiveSyncMain } from "./modules/main/ModuleLiveSyncMain";
|
||||||
import type { ServiceModules } from "./lib/src/interfaces/ServiceModule";
|
import type { ServiceModules } from "@lib/interfaces/ServiceModule";
|
||||||
import { ModuleBasicMenu } from "./modules/essential/ModuleBasicMenu";
|
import { ModuleBasicMenu } from "./modules/essential/ModuleBasicMenu";
|
||||||
import { usePrepareDatabaseForUse } from "./lib/src/serviceFeatures/prepareDatabaseForUse";
|
import { usePrepareDatabaseForUse } from "@lib/serviceFeatures/prepareDatabaseForUse";
|
||||||
import type { Constructor } from "@lib/common/utils.type";
|
import type { Constructor } from "@lib/common/utils.type";
|
||||||
|
|
||||||
export class LiveSyncBaseCore<
|
export class LiveSyncBaseCore<
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
import { type FilePath } from "./lib/src/common/types.ts";
|
import { type FilePath } from "@lib/common/types.ts";
|
||||||
|
|
||||||
export {
|
export {
|
||||||
addIcon,
|
addIcon,
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
import { getLanguage, Notice, Plugin, type App, type PluginManifest } from "./deps";
|
import { getLanguage, Notice, Plugin, type App, type PluginManifest } from "./deps";
|
||||||
import { setGetLanguage } from "./lib/src/common/coreEnvFunctions.ts";
|
import { setGetLanguage } from "@lib/common/coreEnvFunctions.ts";
|
||||||
setGetLanguage(getLanguage);
|
setGetLanguage(getLanguage);
|
||||||
import { LiveSyncCommands } from "./features/LiveSyncCommands.ts";
|
import { LiveSyncCommands } from "./features/LiveSyncCommands.ts";
|
||||||
import { HiddenFileSync } from "./features/HiddenFileSync/CmdHiddenFileSync.ts";
|
import { HiddenFileSync } from "./features/HiddenFileSync/CmdHiddenFileSync.ts";
|
||||||
|
|||||||
+1
-1
@@ -2,7 +2,7 @@ import type { DatabaseFileAccess } from "@lib/interfaces/DatabaseFileAccess";
|
|||||||
import type { Rebuilder } from "@lib/interfaces/DatabaseRebuilder";
|
import type { Rebuilder } from "@lib/interfaces/DatabaseRebuilder";
|
||||||
import type { IFileHandler } from "@lib/interfaces/FileHandler";
|
import type { IFileHandler } from "@lib/interfaces/FileHandler";
|
||||||
import type { StorageAccess } from "@lib/interfaces/StorageAccess";
|
import type { StorageAccess } from "@lib/interfaces/StorageAccess";
|
||||||
import type { IServiceHub } from "./lib/src/services/base/IService";
|
import type { IServiceHub } from "@lib/services/base/IService";
|
||||||
|
|
||||||
export interface ServiceModules {
|
export interface ServiceModules {
|
||||||
storageAccess: StorageAccess;
|
storageAccess: StorageAccess;
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ function toPosixPath(filePath: string): string {
|
|||||||
const posixProjectRoot = toPosixPath(projectRoot);
|
const posixProjectRoot = toPosixPath(projectRoot);
|
||||||
const posixSrc = `${posixProjectRoot}/src`;
|
const posixSrc = `${posixProjectRoot}/src`;
|
||||||
const posixLibSrc = `${posixProjectRoot}/src/lib/src`;
|
const posixLibSrc = `${posixProjectRoot}/src/lib/src`;
|
||||||
|
const posixSubrepo = `${posixProjectRoot}/src/lib`;
|
||||||
|
|
||||||
console.log(`Project Root: ${posixProjectRoot}`);
|
console.log(`Project Root: ${posixProjectRoot}`);
|
||||||
console.log(`Source Directory: ${posixSrc}`);
|
console.log(`Source Directory: ${posixSrc}`);
|
||||||
@@ -93,12 +94,6 @@ for (const sourceFile of project.getSourceFiles()) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Keep relative sibling/child imports unchanged (e.g. ./utils) unless --all-alias is set.
|
|
||||||
const isSibling = isRelative && !moduleSpecifier.startsWith("..");
|
|
||||||
if (isSibling && !allAlias) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Resolve path to an absolute POSIX path.
|
// Resolve path to an absolute POSIX path.
|
||||||
let resolvedPath = "";
|
let resolvedPath = "";
|
||||||
if (moduleSpecifier.startsWith("@lib/")) {
|
if (moduleSpecifier.startsWith("@lib/")) {
|
||||||
@@ -112,6 +107,17 @@ for (const sourceFile of project.getSourceFiles()) {
|
|||||||
|
|
||||||
resolvedPath = toPosixPath(path.normalize(resolvedPath));
|
resolvedPath = toPosixPath(path.normalize(resolvedPath));
|
||||||
|
|
||||||
|
// Keep relative sibling/child imports unchanged (e.g. ./utils) unless:
|
||||||
|
// 1. --all-alias is set, OR
|
||||||
|
// 2. the import crosses the subrepository boundary (src/lib/)
|
||||||
|
const isSibling = isRelative && !moduleSpecifier.startsWith("..");
|
||||||
|
const importerInsideSubrepo = posixFilePath.startsWith(posixSubrepo + "/");
|
||||||
|
const targetInsideSubrepo = resolvedPath.startsWith(posixSubrepo + "/");
|
||||||
|
const crossesSubrepo = importerInsideSubrepo !== targetInsideSubrepo;
|
||||||
|
if (isSibling && !allAlias && !crossesSubrepo) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// Determine correct normalised specifier.
|
// Determine correct normalised specifier.
|
||||||
let newSpecifier = "";
|
let newSpecifier = "";
|
||||||
const hasExtension =
|
const hasExtension =
|
||||||
|
|||||||
Reference in New Issue
Block a user