bryanmanio_obsidian-lexophile/esbuild.config.mjs
Bryan Maniotakis 5ca2254589 Address Obsidian community plugin submission warnings
Source code:
- Bump minAppVersion from 0.15.0 to 1.4.10 (covers
  AbstractInputSuggest, ButtonComponent.setDisabled, Vault.createFolder).
- New styles.css with `lex-*` classes. Convert all inline `element.style`
  /`cssText` assignments in main.ts, koboImportModal.ts, and
  massImportModal.ts to class assignments. Use theme variables instead
  of hardcoded colors so the callout works in dark mode.
- Replace `<h2>`/`<h3>` headings in the settings tab with
  `new Setting(containerEl).setName(...).setHeading()`. Modal titles
  remain on `<h3>` (allowed by Obsidian guidelines).
- Replace `innerHTML = totalLines.map(...).join('<br>')` with `<ul><li>`
  DOM building in both import done screens.
- Replace `setTimeout` with `window.setTimeout` everywhere (popout
  window compatibility).
- `vault.delete(existing)` → `fileManager.trashFile(existing)` so it
  respects the user's deletion preference.
- `vault.createFolder` → `vault.adapter.mkdir` in ensureFolder, working
  for both vault-content and config-dir paths.
- Drop the broad `/* eslint-disable */` in familiarityData.ts and the
  `@ts-ignore` in sqlite.ts (replaced with the existing src/types.d.ts
  module declaration for `*.wasm`).
- Tighten typing: stricter generics in lexicon.substitute, explicit
  `WordEntry` typing in wordModal.submit, `parsed as WordEntry` in
  server.handleRequest, typed chunks in server.readBody. Use `void`
  operator for fire-and-forget promises.
- Remove unused `DictionaryNotReadyError` imports from koboImportModal
  and massImportModal.
- kobo.ts: drop unnecessary `\-` escape in TRIM_CHARS and use
  `subarray(0, 15)` instead of the deprecated `Buffer.slice`.

Build pipeline:
- Replace the `builtin-modules` dependency with Node's built-in
  `module.builtinModules`; one fewer transitive dep.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-12 13:51:39 -06:00

85 lines
2.3 KiB
JavaScript

import esbuild from 'esbuild';
import { builtinModules } from 'module';
import process from 'process';
import path from 'path';
import { existsSync, readFileSync } from 'fs';
import { copyFile, mkdir } from 'fs/promises';
// Node built-ins to mark external in the bundle. We use `module.builtinModules`
// from Node core instead of the third-party `builtin-modules` package — same
// data, no extra dependency.
const builtins = builtinModules;
const prod = process.argv[2] === 'production';
// Auto-deploy main.js + manifest.json into your vault on every build.
// Resolution order:
// 1. vault-path.txt (gitignored) — single line containing your plugin folder path
// 2. LEXOPHILE_VAULT_PLUGIN_DIR env var
// 3. (none — skip deploy)
function resolveVaultPluginDir() {
if (existsSync('vault-path.txt')) {
const p = readFileSync('vault-path.txt', 'utf8').trim();
if (p) return p;
}
return process.env.LEXOPHILE_VAULT_PLUGIN_DIR ?? '';
}
const VAULT_PLUGIN_DIR = resolveVaultPluginDir();
const deployToVault = {
name: 'deploy-to-vault',
setup(build) {
build.onEnd(async (result) => {
if (result.errors.length > 0) return;
if (!VAULT_PLUGIN_DIR) {
console.log('[deploy] no vault-path.txt or LEXOPHILE_VAULT_PLUGIN_DIR — skipping');
return;
}
try {
await mkdir(VAULT_PLUGIN_DIR, { recursive: true });
await copyFile('main.js', path.join(VAULT_PLUGIN_DIR, 'main.js'));
await copyFile('manifest.json', path.join(VAULT_PLUGIN_DIR, 'manifest.json'));
console.log(`[deploy] copied main.js + manifest.json → ${VAULT_PLUGIN_DIR}`);
} catch (err) {
console.error('[deploy] failed:', err.message);
}
});
},
};
const context = await esbuild.context({
entryPoints: ['src/main.ts'],
bundle: true,
external: [
'obsidian',
'electron',
'@codemirror/autocomplete',
'@codemirror/collab',
'@codemirror/commands',
'@codemirror/language',
'@codemirror/lint',
'@codemirror/search',
'@codemirror/state',
'@codemirror/view',
'@lezer/common',
'@lezer/highlight',
'@lezer/lr',
...builtins,
],
format: 'cjs',
target: 'es2018',
logLevel: 'info',
sourcemap: prod ? false : 'inline',
treeShaking: true,
outfile: 'main.js',
loader: { '.wasm': 'binary' },
plugins: [deployToVault],
});
if (prod) {
await context.rebuild();
process.exit(0);
} else {
await context.watch();
}