mirror of
https://github.com/tiddly-gittly/TidGi-Desktop.git
synced 2025-12-06 02:30:47 -08:00
Feat/watch fs (#649)
* Add watch-filesystem-adaptor plugin and worker IPC Introduces the watch-filesystem-adaptor TiddlyWiki plugin, enabling tag-based routing of tiddlers to sub-wikis by querying workspace info via worker thread IPC. Adds workerServiceCaller utility for worker-to-main service calls, updates workerAdapter and bindServiceAndProxy to support explicit service registration for workers, and documents the new IPC architecture. Updates wikiWorker and startNodeJSWiki to preload workspace ID and load the new plugin. Also updates the plugin build script to compile and copy the new plugin. * test: wiki operation steps * Add per-wiki labeled logging and console hijack Introduces labeled loggers for each wiki, writing logs to separate files. Adds a logFor method to NativeService for logging with labels, updates interfaces, and hijacks worker thread console methods to redirect logs to main process for wiki-specific logging. Refactors workspaceID usage to workspace object for improved context. * Update log handling for wiki worker and tests Enhanced logging tests to check all log files, including wiki logs. Adjusted logger to write wiki worker logs to the main log directory. Updated e2e app script comment for correct usage. * Enable worker thread access to main process services Introduces a proxy system allowing worker threads to call main process services with full type safety and observable support. Adds worker-side service proxy creation, auto-attaches proxies to global.service, and updates service registration to use IPC descriptors. Documentation is added for usage and architecture. * Update ErrorDuringStart.md * chore: upgrade ipc cat and allow clean vite cache * Refactor wiki worker initialization and service readiness Moved wiki worker implementation from wikiWorker.ts to wikiWorker/index.ts and deleted the old file. Added servicesReady.ts to manage worker service readiness and callbacks, and integrated notifyServicesReady into the worker lifecycle. Updated console hijack logic to wait for service readiness before hijacking. Improved worker management in Wiki service to support detaching workers and notifying readiness. * Refactor wiki logging to use centralized logger Removed per-wiki loggers and console hijacking in favor of a single labeled logger. All wiki logs, including errors, are now written to a unified log file. Updated worker and service code to route logs through the main logger and removed obsolete log file naming and management logic. * fix: ipc cat log error * Refactor wiki test paths and improve file save logic Updated test step to use wikiTestRootPath for directory replacements and added wikiTestRootPath to paths.ts for clarity. Improved error handling and directory logic in watch-filesystem-adaptor.ts, including saving tiddlers directly to sub-wiki folders, more informative logging, and ensuring cleanup after file writes is properly awaited. * rename * Initial commit when init a new git. * Initial commit when init a new git. * Initial commit when init a new git. * Initial commit when init a new git. * Initial commit when init a new git. * Initial commit when init a new git. * feat: basic watch-fs * feat: check file not exist * refactor: use exponential-backoff * Initial commit when init a new git. * Initial commit when init a new git. * Initial commit when init a new git. * Initial commit when init a new git. * Initial commit when init a new git. * Initial commit when init a new git. * Initial commit when init a new git. * Initial commit when init a new git. * Initial commit when init a new git. * Initial commit when init a new git. * Initial commit when init a new git. * Initial commit when init a new git. * fix: cleanup * Refactor test setup and cleanup to separate file Moved Before and After hooks from application.ts to a new cleanup.ts file for better organization and separation of concerns. Also removed unused imports and related code from application.ts. Minor type simplification in agent.ts for row parsing. * test: modify and rename * feat: enableFileSystemWatch * refactor: unused utils.ts * Update watch-filesystem-adaptor.ts * refactor: use node-sentinel-file-watcher * refactor: extract to two classes * The logFor method lacks JSDoc describing the level parameter's * Update startNodeJSWiki.ts * fix: napi build * Update electron-rebuild command in workflows Changed the electron-rebuild command in release and test GitHub Actions workflows to use a comma-separated list for native modules instead of multiple -w flags. This simplifies the rebuild step for better-sqlite3 and nsfw modules. * lint * not build nsfw, try use prebuild * Update package.json * Update workerAdapter.ts * remove subWikiPlugin.ts as we use new filesystem adaptor that supports tag based sub wiki * fix: build * fix: wrong type * lint * remove `act(...)` warnings * uninstall chokidar * refactor and test * lint * remove unused logic, as we already use ipc syncadaptor, not afriad of wiki status change * Update translation.json * test: increast timeout in CI * Update application.ts * fix: AI's wrong cleanup logic hidden by as unknown as * fix: AI's wrong as unknown as * Update agent.feature * Update wikiSearchPlugin.ts * fix: A dynamic import callback was not specified.
This commit is contained in:
parent
ea78df0ab3
commit
9a6f3480f5
81 changed files with 5008 additions and 991 deletions
|
|
@ -5,47 +5,205 @@
|
|||
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-call */
|
||||
import esbuild from 'esbuild';
|
||||
import fs from 'fs-extra';
|
||||
import path from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
import { rimraf } from 'rimraf';
|
||||
|
||||
// put it here, so it can be loaded via `'+plugins/linonetwo/tidgi'` in cli, and get copied in scripts/afterPack.js when copying tiddlywiki (no need to copy this plugin again)
|
||||
const tidgiIpcSyncadaptorOutDir = path.join(__dirname, '../node_modules/tiddlywiki/plugins/linonetwo/tidgi-ipc-syncadaptor');
|
||||
// delete if exist
|
||||
await rimraf(tidgiIpcSyncadaptorOutDir);
|
||||
await fs.mkdirp(tidgiIpcSyncadaptorOutDir);
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
|
||||
/**
|
||||
* esbuild plugin to handle native .node files and their parent packages
|
||||
* Rewrites require() calls for .node files to use absolute paths from node_modules
|
||||
*/
|
||||
const nativeNodeModulesPlugin = {
|
||||
name: 'native-node-modules',
|
||||
setup(build) {
|
||||
// Rewrite nsfw's require() to use node_modules path
|
||||
build.onLoad({ filter: /nsfw[/\\]js[/\\]src[/\\]index\.js$/ }, async (args) => {
|
||||
let contents = await fs.readFile(args.path, 'utf8');
|
||||
|
||||
// Replace relative path with require from node_modules
|
||||
// Original: require('../../build/Release/nsfw.node')
|
||||
// New: require('nsfw/build/Release/nsfw.node')
|
||||
contents = contents.replace(
|
||||
/require\(['"]\.\.\/\.\.\/build\/Release\/nsfw\.node['"]\)/g,
|
||||
"require('nsfw/build/Release/nsfw.node')"
|
||||
);
|
||||
|
||||
return {
|
||||
contents,
|
||||
loader: 'js',
|
||||
};
|
||||
});
|
||||
|
||||
// Mark the .node file itself as external
|
||||
build.onResolve({ filter: /nsfw[/\\]build[/\\]Release[/\\]nsfw\.node$/ }, () => ({
|
||||
external: true,
|
||||
}));
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* Configuration for all plugins to build
|
||||
*/
|
||||
const PLUGINS = [
|
||||
{
|
||||
name: 'tidgi-ipc-syncadaptor',
|
||||
sourceFolder: '../src/services/wiki/plugin/ipcSyncAdaptor',
|
||||
entryPoints: [
|
||||
'ipc-syncadaptor.ts',
|
||||
'electron-ipc-cat.ts',
|
||||
'fix-location-info.ts',
|
||||
],
|
||||
},
|
||||
{
|
||||
name: 'tidgi-ipc-syncadaptor-ui',
|
||||
sourceFolder: '../src/services/wiki/plugin/ipcSyncAdaptorUI',
|
||||
entryPoints: [], // No TypeScript entry points, just copy files
|
||||
},
|
||||
{
|
||||
name: 'watch-filesystem-adaptor',
|
||||
sourceFolder: '../src/services/wiki/plugin/watchFileSystemAdaptor',
|
||||
entryPoints: [
|
||||
'watch-filesystem-adaptor.ts',
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
/**
|
||||
* Shared esbuild configuration
|
||||
*/
|
||||
const tsconfigPath = path.join(__dirname, '../tsconfig.json');
|
||||
const tidgiIpcSyncadaptorSourceFolder = '../src/services/wiki/plugin/ipcSyncAdaptor';
|
||||
const sharedConfig = {
|
||||
const ESBUILD_CONFIG = {
|
||||
logLevel: 'info',
|
||||
bundle: true,
|
||||
// use node so we have `exports`, otherwise `module.adaptorClass` in $:/core/modules/startup.js will be undefined
|
||||
platform: 'node',
|
||||
platform: 'node', // Use node so we have `exports`, otherwise `module.adaptorClass` will be undefined
|
||||
minify: process.env.NODE_ENV === 'production',
|
||||
outdir: tidgiIpcSyncadaptorOutDir,
|
||||
tsconfig: tsconfigPath,
|
||||
target: 'ESNEXT',
|
||||
plugins: [nativeNodeModulesPlugin],
|
||||
};
|
||||
await Promise.all([
|
||||
esbuild.build({
|
||||
...sharedConfig,
|
||||
entryPoints: [path.join(__dirname, tidgiIpcSyncadaptorSourceFolder, 'ipc-syncadaptor.ts')],
|
||||
}),
|
||||
esbuild.build({
|
||||
...sharedConfig,
|
||||
entryPoints: [path.join(__dirname, tidgiIpcSyncadaptorSourceFolder, 'electron-ipc-cat.ts')],
|
||||
}),
|
||||
esbuild.build({
|
||||
...sharedConfig,
|
||||
entryPoints: [path.join(__dirname, tidgiIpcSyncadaptorSourceFolder, 'fix-location-info.ts')],
|
||||
}),
|
||||
]);
|
||||
const filterFunc = (src) => {
|
||||
return !src.endsWith('.ts');
|
||||
};
|
||||
await fs.copy(path.join(__dirname, tidgiIpcSyncadaptorSourceFolder), tidgiIpcSyncadaptorOutDir, { filter: filterFunc });
|
||||
|
||||
const tidgiIpcSyncadaptorUISourceFolder = '../src/services/wiki/plugin/ipcSyncAdaptorUI';
|
||||
const tidgiIpcSyncadaptorUIOutDir = path.join(__dirname, '../node_modules/tiddlywiki/plugins/linonetwo/tidgi-ipc-syncadaptor-ui');
|
||||
// delete if exist
|
||||
await rimraf(tidgiIpcSyncadaptorUIOutDir);
|
||||
await fs.mkdirp(tidgiIpcSyncadaptorUIOutDir);
|
||||
await fs.copy(path.join(__dirname, tidgiIpcSyncadaptorUISourceFolder), tidgiIpcSyncadaptorUIOutDir, { filter: filterFunc });
|
||||
/**
|
||||
* Filter function to exclude TypeScript files when copying
|
||||
*/
|
||||
const filterNonTsFiles = (src) => !src.endsWith('.ts');
|
||||
|
||||
/**
|
||||
* Get all possible output directories for a plugin
|
||||
* Returns both development node_modules and packaged app directories
|
||||
*/
|
||||
function getPluginOutputDirs(pluginName) {
|
||||
const devOutDir = path.join(__dirname, '../node_modules/tiddlywiki/plugins/linonetwo', pluginName);
|
||||
const outDirs = [devOutDir];
|
||||
|
||||
// Check for packaged app directories (created by afterPack.ts)
|
||||
const outDir = path.join(__dirname, '../out');
|
||||
if (fs.existsSync(outDir)) {
|
||||
// Find all packaged app directories
|
||||
const packDirs = fs.readdirSync(outDir, { withFileTypes: true })
|
||||
.filter(dirent => dirent.isDirectory())
|
||||
.map(dirent => {
|
||||
// In packaged electron app, node_modules is in resources/
|
||||
const resourcesPath = path.join(outDir, dirent.name, 'resources/node_modules/tiddlywiki/plugins/linonetwo', pluginName);
|
||||
return resourcesPath;
|
||||
});
|
||||
|
||||
// Only add directories that exist (have been created by afterPack)
|
||||
packDirs.forEach(dir => {
|
||||
const parentDir = path.dirname(dir);
|
||||
if (fs.existsSync(parentDir)) {
|
||||
outDirs.push(dir);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return outDirs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare output directories for a plugin
|
||||
*/
|
||||
async function prepareOutputDirs(outDirs) {
|
||||
await Promise.all(outDirs.map(async (outDir) => {
|
||||
await rimraf(outDir);
|
||||
await fs.mkdirp(outDir);
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Build TypeScript entry points to all output directories
|
||||
*/
|
||||
async function buildEntryPoints(plugin, outDirs) {
|
||||
if (!plugin.entryPoints || plugin.entryPoints.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
const sourcePath = path.join(__dirname, plugin.sourceFolder);
|
||||
|
||||
await Promise.all(
|
||||
outDirs.flatMap(outDir =>
|
||||
plugin.entryPoints.map(entryPoint =>
|
||||
esbuild.build({
|
||||
...ESBUILD_CONFIG,
|
||||
entryPoints: [path.join(sourcePath, entryPoint)],
|
||||
outdir: outDir,
|
||||
})
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy non-TypeScript files to all output directories
|
||||
*/
|
||||
async function copyNonTsFiles(plugin, outDirs) {
|
||||
const sourcePath = path.join(__dirname, plugin.sourceFolder);
|
||||
|
||||
await Promise.all(outDirs.map(async (outDir) => {
|
||||
await fs.copy(sourcePath, outDir, { filter: filterNonTsFiles });
|
||||
console.log(`✓ Copied ${plugin.name} to: ${outDir}`);
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a single plugin to all output directories
|
||||
*/
|
||||
async function buildPlugin(plugin) {
|
||||
console.log(`\nBuilding plugin: ${plugin.name}`);
|
||||
|
||||
const outDirs = getPluginOutputDirs(plugin.name);
|
||||
console.log(` Output directories: ${outDirs.length}`);
|
||||
|
||||
// Prepare output directories
|
||||
await prepareOutputDirs(outDirs);
|
||||
|
||||
// Build TypeScript entry points
|
||||
await buildEntryPoints(plugin, outDirs);
|
||||
|
||||
// Copy non-TypeScript files
|
||||
await copyNonTsFiles(plugin, outDirs);
|
||||
|
||||
console.log(`✓ Completed ${plugin.name}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Main function to build all plugins
|
||||
*/
|
||||
async function main() {
|
||||
console.log('Starting plugin compilation...\n');
|
||||
|
||||
for (const plugin of PLUGINS) {
|
||||
await buildPlugin(plugin);
|
||||
}
|
||||
|
||||
console.log('\n✓ All plugins compiled successfully!');
|
||||
}
|
||||
|
||||
// Run main function
|
||||
main().catch((error) => {
|
||||
console.error('Error compiling plugins:', error);
|
||||
process.exit(1);
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue