feat: publish tidgi-shared npm for types, and place tidgi.service

This commit is contained in:
linonetwo 2026-02-09 23:16:49 +08:00
parent 544a8b1bf3
commit 593ed2d29c
10 changed files with 533 additions and 16 deletions

View file

@ -1,6 +1,6 @@
// Auto-attach services to global.service - MUST import before using services
import './services';
import { native } from './services';
import { native, service } from './services';
import { onWorkerServicesReady } from './servicesReady';
import { getTidGiAuthHeaderWithToken } from '@/constants/auth';
@ -222,6 +222,19 @@ export function startNodeJSWiki(configs: IStartNodeJSWikiConfigs): Observable<IW
: [homePath, '--version'];
wikiInstance.boot.argv = [...fullBootArgv];
/**
* Attach service proxies to `$tw.tidgi.service` so that TiddlyWiki route modules
* (which run in vm.runInContext sandbox) can access them.
* The sandbox injects `$tw` but NOT `globalThis` or `global`,
* so `$tw.tidgi.service` is the only way for plugins to reach IPC service proxies.
*/
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any
if (!(wikiInstance as any).tidgi) {
(wikiInstance as any).tidgi = {};
}
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any
(wikiInstance as any).tidgi.service = service;
wikiInstance.hooks.addHook('th-server-command-post-start', function(_server: unknown, nodeServer: Server) {
nodeServer.on('error', function(error: Error) {
observer.next({ type: 'control', actions: WikiControlActions.error, message: error.message, argv: fullBootArgv });