Skip to content

Beautiful, AI-native markdown IDE and LLM wiki

fix(desktop): bundle @parcel/watcher into the CLI so packaged builds don't fall back to chokidar (#760) (#2906)

mike-inkeep4323d9574889
diff --git a/.changeset/bundle-parcel-watcher-into-cli.md b/.changeset/bundle-parcel-watcher-into-cli.md
new file mode 100644
index 000000000..f13907748
--- /dev/null
+++ b/.changeset/bundle-parcel-watcher-into-cli.md
@@ -0,0 +1,5 @@
+---
+"@inkeep/open-knowledge": patch
+---
+
+Restored the native `@parcel/watcher` file watcher in the packaged desktop app (inkeep/open-knowledge#760). The app runs `ok start` from a bundled CLI whose module resolver never reaches the app's own `@parcel/watcher` copy, so at server boot `import('@parcel/watcher')` failed with "Cannot find package" and the watcher silently fell back to chokidar. The macOS build now stages `@parcel/watcher` — its wrapper, the runtime dependencies it loads (`picomatch`, `is-glob`, `is-extglob`, `detect-libc`), and the per-architecture native binary — onto the CLI's own module path, so the fast native watcher loads as intended. Combined with the chokidar-fallback fix in the same release, external edits to files in subfolders are reflected in the graph, backlinks, and dead-link views without a restart. The staging resolves each dependency exactly as the wrapper loads it (the workspace carries two `picomatch` majors, so a naive copy could have shipped the wrong one), and a packaging test verifies the staged tree is CLI-resolvable without needing a full app build.
diff --git a/.github/workflows/desktop-build-win-linux.yml b/.github/workflows/desktop-build-win-linux.yml
index 8c0c3f390..2690561ee 100644
--- a/.github/workflows/desktop-build-win-linux.yml
+++ b/.github/workflows/desktop-build-win-linux.yml
@@ -193,6 +193,17 @@ jobs:
working-directory: packages/desktop
run: node scripts/prepare-platform-natives.mjs
+ # Stage @parcel/watcher onto the bundled CLI's module path. This workflow
+ # invokes electron-builder directly (not the build:win/build:linux npm
+ # scripts, which DO run this), so the step must be explicit here or the
+ # packaged app ships without @parcel/watcher on the CLI path and the
+ # server degrades to chokidar (#760). Stages only the host-arch binary
+ # today; the other-arch artifact uses the (subfolder-correct) chokidar
+ # fallback — see scripts/stage-parcel-watcher.mjs.
+ - name: Stage @parcel/watcher for the bundled CLI
+ working-directory: packages/desktop
+ run: node scripts/stage-parcel-watcher.mjs
+
- name: Build desktop main/preload/renderer
working-directory: packages/desktop
run: pnpm run build:desktop
@@ -277,6 +288,17 @@ jobs:
working-directory: packages/desktop
run: node scripts/prepare-platform-natives.mjs
+ # Stage @parcel/watcher onto the bundled CLI's module path. This workflow
+ # invokes electron-builder directly (not the build:win/build:linux npm
+ # scripts, which DO run this), so the step must be explicit here or the
+ # packaged app ships without @parcel/watcher on the CLI path and the
+ # server degrades to chokidar (#760). Stages only the host-arch binary
+ # today; the other-arch artifact uses the (subfolder-correct) chokidar
+ # fallback — see scripts/stage-parcel-watcher.mjs.
+ - name: Stage @parcel/watcher for the bundled CLI
+ working-directory: packages/desktop
+ run: node scripts/stage-parcel-watcher.mjs
+
- name: Build desktop main/preload/renderer
working-directory: packages/desktop
run: pnpm run build:desktop
diff --git a/.github/workflows/desktop-build.yml b/.github/workflows/desktop-build.yml
index 5744602ab..1e78aa5f1 100644
--- a/.github/workflows/desktop-build.yml
+++ b/.github/workflows/desktop-build.yml
@@ -222,6 +222,15 @@ jobs:
working-directory: packages/desktop
run: node scripts/prepare-universal.mjs
+ # Stage @parcel/watcher onto the bundled CLI's module path. This workflow
+ # invokes electron-builder directly (not the build:mac npm script, which
+ # DOES run this), so the step must be explicit here or the smoke/QA DMG
+ # ships without @parcel/watcher on the CLI path and the server degrades to
+ # chokidar (#760).
+ - name: Stage @parcel/watcher for the bundled CLI
+ working-directory: packages/desktop
+ run: node scripts/stage-parcel-watcher.mjs
+
# Step B: package via electron-builder. Kept as a separate runner step
# from step A (rather than chained via && in a single shell). The split
# was originally forced by a packaging bug in the previous script runner:
diff --git a/.github/workflows/desktop-release.yml b/.github/workflows/desktop-release.yml
index 80119b61d..5498ae8d6 100644
--- a/.github/workflows/desktop-release.yml
+++ b/.github/workflows/desktop-release.yml
@@ -341,6 +341,15 @@ jobs:
working-directory: packages/desktop
run: node scripts/prepare-universal.mjs
+ # Stage @parcel/watcher onto the bundled CLI's module path. This workflow
+ # invokes electron-builder directly (not the build:mac npm script, which
+ # DOES run this), so the step must be explicit here or the published DMG
+ # ships without @parcel/watcher on the CLI path and the server degrades to
+ # chokidar (#760).
+ - name: Stage @parcel/watcher for the bundled CLI
+ working-directory: packages/desktop
+ run: node scripts/stage-parcel-watcher.mjs
+
- name: Build + sign + notarize + publish DMG/ZIP
# electron-builder picks up CSC_LINK / CSC_KEY_PASSWORD from env +
# signs. afterSign.mjs picks up APPLE_* + notarizes + staples +
diff --git a/knip.config.ts b/knip.config.ts
index 6e3847861..296751a02 100644
--- a/knip.config.ts
+++ b/knip.config.ts
@@ -121,9 +121,7 @@ export default {
'packages/server': {
entry: ['src/**/*.test.ts', 'src/parse-worker.ts'],
project: 'src/**',
- ignoreDependencies: [
- '@types/shell-quote',
- ],
+ ignoreDependencies: ['@types/shell-quote'],
},
'packages/cli': {
entry: ['src/**/*.test.ts', 'scripts/*.ts', 'tests/**/*.ts', 'src/parse-worker.ts'],
diff --git a/packages/core/src/bridge/bind-frontmatter-doc.ts b/packages/core/src/bridge/bind-frontmatter-doc.ts
index 8f9d95287..c014b1413 100644
--- a/packages/core/src/bridge/bind-frontmatter-doc.ts
+++ b/packages/core/src/bridge/bind-frontmatter-doc.ts
@@ -1,4 +1,3 @@
-
import type * as Y from 'yjs';
import type { Err, Ok, Result } from '../config/result.ts';
import { type FrontmatterValidationError, toFrontmatterIssue } from '../frontmatter/errors.ts';
diff --git a/packages/core/src/bridge/bridge-invariant.ts b/packages/core/src/bridge/bridge-invariant.ts
index 8bfdb40cd..005627195 100644
--- a/packages/core/src/bridge/bridge-invariant.ts
+++ b/packages/core/src/bridge/bridge-invariant.ts
@@ -1,4 +1,3 @@
-
import { fnv1aDigest } from './hash-util.ts';
export type BridgeInvariantSite = 'observer-b' | 'persistence' | 'test-harness';
diff --git a/packages/core/src/bridge/doc-boundary-space.ts b/packages/core/src/bridge/doc-boundary-space.ts
index c18c086d5..8890f6739 100644
--- a/packages/core/src/bridge/doc-boundary-space.ts
+++ b/packages/core/src/bridge/doc-boundary-space.ts
@@ -1,4 +1,3 @@
-
import { FRONTMATTER_RE, stripFrontmatter } from '../extensions/frontmatter.ts';
const LEADING_BOUNDARY_RE = /^(?:\r?\n)+/;
diff --git a/packages/core/src/bridge/growth-detect.ts b/packages/core/src/bridge/growth-detect.ts
index 463e89595..9d9c244b0 100644
--- a/packages/core/src/bridge/growth-detect.ts
+++ b/packages/core/src/bridge/growth-detect.ts
@@ -1,4 +1,3 @@
-
const DEFAULT_MIN_SUBSTANTIVE_LINE_LENGTH = 16;
export const DUPLICATION_GATE_MIN_LINE_LENGTH = 8;
diff --git a/packages/core/src/bridge/merge-three-way.ts b/packages/core/src/bridge/merge-three-way.ts
index f06c1614e..3d5fd0771 100644
--- a/packages/core/src/bridge/merge-three-way.ts
+++ b/packages/core/src/bridge/merge-three-way.ts
@@ -65,7 +65,6 @@ export function tryLineLevelCombine(
return { clean: true, merged };
}
-
export type BridgeMergeContentLossSide = 'user' | 'agent';
export type BridgeMergeContentLossWhich = 'substring' | 'order' | 'growth';
diff --git a/packages/core/src/bridge/normalize.ts b/packages/core/src/bridge/normalize.ts
index 3f0880aa5..4b8890476 100644
--- a/packages/core/src/bridge/normalize.ts
+++ b/packages/core/src/bridge/normalize.ts
@@ -1,4 +1,3 @@
-
const COMMONMARK_ESCAPE_RE = /\\([!"#$%&'()*+,\-./:;<=>?@[\]^_`{|}~])/g;
const TABLE_ALIGN_ROW_RE = /^\s*\|?\s*:?-+:?\s*(\|\s*:?-+:?\s*)+\|?\s*$/;
diff --git a/packages/core/src/bridge/pm-structural-equivalence.ts b/packages/core/src/bridge/pm-structural-equivalence.ts
index 0be5203e4..754dc5cc2 100644
--- a/packages/core/src/bridge/pm-structural-equivalence.ts
+++ b/packages/core/src/bridge/pm-structural-equivalence.ts
@@ -32,7 +32,6 @@ const BR_SENTINEL: PmStructuralNode = { type: '__br__' };
const BR_LITERAL_RE = /^<br\s*\/?>$/i;
-
interface DegradeEntry {
readonly label: string;
readonly severity: ToleranceClassSeverity;
@@ -128,7 +127,6 @@ export interface ComparePmStructuralOptions {
ignoreAttrs?: (attrKey: string) => boolean;
}
-
/** Rebuild a node with `fn` applied to each child; identity when childless.
* Shared by the degrade canonicalizers so none re-implements the walk. */
function mapChildren(
@@ -250,7 +248,6 @@ function applyDegrades(tree: PmStructuralNode): {
return { normalized: current, fired };
}
-
export function comparePmStructural(
expected: PmStructuralNode,
actual: PmStructuralNode,
diff --git a/packages/core/src/bridge/subsequence.ts b/packages/core/src/bridge/subsequence.ts
index dca644141..af20de1e2 100644
--- a/packages/core/src/bridge/subsequence.ts
+++ b/packages/core/src/bridge/subsequence.ts
@@ -1,4 +1,3 @@
-
/** True when `needle` is a subsequence of `haystack` (two-pointer, O(n+m)):
* insertions in `haystack` are free; any dropped or substituted `needle` byte
* fails. */
diff --git a/packages/core/src/markdown/callout-transformer.ts b/packages/core/src/markdown/callout-transformer.ts
index a363dfd54..83d47404a 100644
--- a/packages/core/src/markdown/callout-transformer.ts
+++ b/packages/core/src/markdown/callout-transformer.ts
@@ -1,4 +1,3 @@
-
import type { Blockquote, Paragraph, Root } from 'mdast';
import type { MdxJsxAttribute, MdxJsxFlowElement } from 'mdast-util-mdx';
import { visit } from 'unist-util-visit';
diff --git a/packages/core/src/markdown/code-fence.ts b/packages/core/src/markdown/code-fence.ts
index 4499dbc92..9807a7e82 100644
--- a/packages/core/src/markdown/code-fence.ts
+++ b/packages/core/src/markdown/code-fence.ts
@@ -1,4 +1,3 @@
-
export function selectFenceChar(info: string): '`' | '~' {
return info.includes('`') ? '~' : '`';
}
diff --git a/packages/core/src/markdown/comment-promoter.ts b/packages/core/src/markdown/comment-promoter.ts
index 47f0d07e4..193e286b0 100644
--- a/packages/core/src/markdown/comment-promoter.ts
+++ b/packages/core/src/markdown/comment-promoter.ts
@@ -1,4 +1,3 @@
-
import type { Nodes, Paragraph, PhrasingContent, Root, RootContent, Text } from 'mdast';
import { SKIP, visit } from 'unist-util-visit';
import type { VFile } from 'vfile';
diff --git a/packages/core/src/markdown/dedent-block-jsx-close.ts b/packages/core/src/markdown/dedent-block-jsx-close.ts
index b6299a948..ece5c02a1 100644
--- a/packages/core/src/markdown/dedent-block-jsx-close.ts
+++ b/packages/core/src/markdown/dedent-block-jsx-close.ts
@@ -1,4 +1,3 @@
-
import { findFencedRegions, isInsideFence } from './fence-regions.ts';
const INDENTED_BLOCK_JSX_CLOSE_RE = /^([ ]{1,3})(<\/[A-Z][A-Za-z0-9_]*\s*>)([ \t]*)$/gm;
diff --git a/packages/core/src/markdown/details-accordion-promoter.ts b/packages/core/src/markdown/details-accordion-promoter.ts
index acd398aa6..54774764a 100644
--- a/packages/core/src/markdown/details-accordion-promoter.ts
+++ b/packages/core/src/markdown/details-accordion-promoter.ts
@@ -1,4 +1,3 @@
-
import type { Nodes, Paragraph, Parent, Root, Text } from 'mdast';
import type { MdxJsxAttribute, MdxJsxFlowElement } from 'mdast-util-mdx';
import { visit } from 'unist-util-visit';
diff --git a/packages/core/src/markdown/fence-regions.ts b/packages/core/src/markdown/fence-regions.ts
index fb5ac8e8a..c7518d614 100644
--- a/packages/core/src/markdown/fence-regions.ts
+++ b/packages/core/src/markdown/fence-regions.ts
@@ -1,4 +1,3 @@
-
const FENCE_RE = /^(`{3,}|~{3,})/gm;
export function findFencedRegions(src: string): Array<[number, number]> {
diff --git a/packages/core/src/markdown/fixtures/index.ts b/packages/core/src/markdown/fixtures/index.ts
index 6931623c7..00f5771ee 100644
--- a/packages/core/src/markdown/fixtures/index.ts
+++ b/packages/core/src/markdown/fixtures/index.ts
@@ -1,4 +1,3 @@
-
import { readFileSync } from 'node:fs';
import { dirname, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
@@ -9,7 +8,6 @@ function fixturePath(...segments: string[]): string {
return resolve(FIXTURES_DIR, ...segments);
}
-
interface GfmExample {
section: string;
markdown: string;
@@ -19,7 +17,6 @@ export function loadGfmExamples(): GfmExample[] {
return JSON.parse(readFileSync(fixturePath('gfm', 'examples.json'), 'utf8')) as GfmExample[];
}
-
interface MdxCrashEntry {
id: string;
input: string;
@@ -71,7 +68,6 @@ export function loadLargeEmbedFixtures(): LargeEmbedFixture[] {
) as LargeEmbedFixture[];
}
-
export function loadPrd6955Before(): string {
return readFileSync(fixturePath('regression', 'prd-6955-before.md'), 'utf8');
}
@@ -80,7 +76,6 @@ export function loadPrd6955CorruptedTriplicated(): string {
return readFileSync(fixturePath('regression', 'prd-6955-corrupted-triplicated.md'), 'utf8');
}
-
export interface NgPinnedCase {
id: string;
name: string;
@@ -97,7 +92,6 @@ export function loadNgPinnedCases(): NgPinnedCase[] {
) as NgPinnedCase[];
}
-
export function loadLargeRealistic(): string {
return readFileSync(fixturePath('perf', 'large-realistic.md'), 'utf8');
}
diff --git a/packages/core/src/markdown/fixtures/perf/generate.ts b/packages/core/src/markdown/fixtures/perf/generate.ts
index daa3ef82b..8b1eb8519 100644
--- a/packages/core/src/markdown/fixtures/perf/generate.ts
+++ b/packages/core/src/markdown/fixtures/perf/generate.ts
@@ -1,4 +1,3 @@
-
import { writeFileSync } from 'node:fs';
import { dirname, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
@@ -11,7 +10,6 @@ const BASELINE_ONLY_COUNTS = [500, 2500] as const;
const SEED = 0xf1de1117;
-
function mulberry32(seed: number): () => number {
let a = seed >>> 0;
return () => {
@@ -38,7 +36,6 @@ function pickWeighted<T>(rand: () => number, items: readonly [T, number][]): T {
return items[items.length - 1][0];
}
-
const WORDS = [
'lorem',
'ipsum',
@@ -156,7 +153,6 @@ function mdxBlock(rand: () => number): string {
return `<${name}>\n\n${sentence(rand)}\n\n</${name}>`;
}
-
type BlockKind = 'paragraph' | 'heading' | 'list' | 'code' | 'table' | 'mdx';
const MIX: readonly [BlockKind, number][] = [
@@ -195,7 +191,6 @@ function generateDocument(blockCount: number, seed: number): string {
return `${blocks.join('\n\n')}\n`;
}
-
function main(): void {
for (const count of [...BLOCK_COUNTS, ...BASELINE_ONLY_COUNTS]) {
const doc = generateDocument(count, SEED);
diff --git a/packages/core/src/markdown/guard-flanking-matrix.ts b/packages/core/src/markdown/guard-flanking-matrix.ts
index 32c055c5b..420dc0fe5 100644
--- a/packages/core/src/markdown/guard-flanking-matrix.ts
+++ b/packages/core/src/markdown/guard-flanking-matrix.ts
@@ -7,7 +7,6 @@ import {
import { BACKSLASH_GUARD_SUBSTITUTIONS, encodeBackslashEscapes } from './backslash-escape-guard.ts';
import { ENTITY_REF_GUARD_SUBSTITUTIONS, encodeEntityRefs } from './entity-ref-guard.ts';
-
export const ATTENTION_DELIMITERS = ['*', '_', '**', '~~', '=='] as const;
export type FlankClass = 'whitespace' | 'punctuation' | 'other';
diff --git a/packages/core/src/markdown/handler-shadow-audit.ts b/packages/core/src/markdown/handler-shadow-audit.ts
index 283913255..2653473da 100644
--- a/packages/core/src/markdown/handler-shadow-audit.ts
+++ b/packages/core/src/markdown/handler-shadow-audit.ts
@@ -1,4 +1,3 @@
-
export interface HandlerShadowWitness {
input: string;
expect: 'byte' | 'byte-and-reparse-type';
diff --git a/packages/core/src/markdown/highlight-promoter.ts b/packages/core/src/markdown/highlight-promoter.ts
index 6319f264f..f55912407 100644
--- a/packages/core/src/markdown/highlight-promoter.ts
+++ b/packages/core/src/markdown/highlight-promoter.ts
@@ -1,4 +1,3 @@
-
import type { Nodes, Parent, PhrasingContent, Root, Text } from 'mdast';
import type { MdxJsxTextElement } from 'mdast-util-mdx';
import { SKIP, visit } from 'unist-util-visit';
diff --git a/packages/core/src/markdown/html-to-mdast.ts b/packages/core/src/markdown/html-to-mdast.ts
index 8dc3a81b5..b1f252c31 100644
--- a/packages/core/src/markdown/html-to-mdast.ts
+++ b/packages/core/src/markdown/html-to-mdast.ts
@@ -1,4 +1,3 @@
-
import type { Root as HastRoot } from 'hast';
import type { List, Root as MdastRoot } from 'mdast';
import rehypeParse from 'rehype-parse';
@@ -86,8 +85,7 @@ export function htmlToMdast(html: string, options?: HtmlToMdastOptions): MdastRo
throw new HtmlPayloadTooLargeError(html.length, maxBytes);
}
- const processor = unified()
- .use(rehypeParse, { fragment: true });
+ const processor = unified().use(rehypeParse, { fragment: true });
for (const plugin of cleanupPlugins) {
processor.use(plugin);
diff --git a/packages/core/src/markdown/image-promoter.ts b/packages/core/src/markdown/image-promoter.ts
index 994eb6917..706fa9afb 100644
--- a/packages/core/src/markdown/image-promoter.ts
+++ b/packages/core/src/markdown/image-promoter.ts
@@ -1,4 +1,3 @@
-
import type { Image, Paragraph, Root } from 'mdast';
import type { MdxJsxAttribute, MdxJsxFlowElement } from 'mdast-util-mdx';
import { visit } from 'unist-util-visit';
diff --git a/packages/core/src/markdown/index.ts b/packages/core/src/markdown/index.ts
index fc30bda02..8b36807fd 100644
--- a/packages/core/src/markdown/index.ts
+++ b/packages/core/src/markdown/index.ts
@@ -1,4 +1,3 @@
-
import {
type FromProseMirrorOptions,
fromPmMark,
@@ -197,7 +196,6 @@ export class MarkdownManager {
}
}
-
const registry = createRegistry();
function destructureAttrs(
@@ -246,7 +244,6 @@ function destructureAttrs(
return result;
}
-
function hasDirtyDescendant(node: PmNode): boolean {
let found = false;
node.descendants((child) => {
@@ -266,7 +263,6 @@ function effectiveDirty(node: PmNode, freshnessChecker?: StructuralFreshnessChec
return freshnessChecker ? freshnessChecker.isDiverged(node.toJSON()) : false;
}
-
function isEmptyMdastParagraph(node: MdastNodes): boolean {
if (node.type !== 'paragraph') return false;
const children = node.children ?? [];
@@ -335,7 +331,6 @@ function extractTextFromMdastNodes(nodes: MdastNodes[]): string {
return out;
}
-
import {
AUDIO_EXTENSIONS,
FILE_ATTACHMENT_EXTENSIONS,
@@ -582,7 +577,6 @@ function buildMdastToPmHandlers(
}));
}
-
if (m.emphasis) {
handlers.emphasis = toPmMark(m.emphasis, (node: Emphasis) => ({
sourceDelimiter: node.data?.sourceDelimiter ?? '*',
@@ -663,7 +657,6 @@ function buildMdastToPmHandlers(
}));
}
-
if (m.link) {
const sourceLiteralMark = m.sourceLiteral;
handlers.link = (node: Link, _parent: MdastParent, state: MdastToPmState) => {
@@ -942,7 +935,6 @@ function buildMdastToPmHandlers(
};
}
-
const blockUnknownHandler = (node: {
type: string;
position?: { start: { offset: number }; end: { offset: number } };
@@ -1068,7 +1060,6 @@ function buildMdastToPmHandlers(
return handlers as RemarkProseMirrorOptions['handlers'];
}
-
function buildPmToMdastHandlers(
schema: Schema,
freshness: FreshnessCheckerHolder,
diff --git a/packages/core/src/markdown/lint/config-files.ts b/packages/core/src/markdown/lint/config-files.ts
index 94b34dee1..312c9c74b 100644
--- a/packages/core/src/markdown/lint/config-files.ts
+++ b/packages/core/src/markdown/lint/config-files.ts
@@ -1,4 +1,3 @@
-
const MARKDOWNLINT_JSON_CONFIG_FILES: ReadonlySet<string> = new Set([
'.markdownlint.json',
'.markdownlint.jsonc',
diff --git a/packages/core/src/markdown/lint/config-schemas.ts b/packages/core/src/markdown/lint/config-schemas.ts
index d90a7e5ab..9291ee4db 100644
--- a/packages/core/src/markdown/lint/config-schemas.ts
+++ b/packages/core/src/markdown/lint/config-schemas.ts
@@ -29,7 +29,6 @@ const fullPluginShape = Object.fromEntries(
LINT_PLUGINS.map((plugin) => [plugin.id, plugin.sliceSchema]),
) as z.ZodRawShape;
-
export const LinterConfigSchema = z.object({
enabled: z.boolean(),
plugins: z.object(fullPluginShape),
diff --git a/packages/core/src/markdown/lint/default-config.ts b/packages/core/src/markdown/lint/default-config.ts
index a51f2ffb0..d48eea5e4 100644
--- a/packages/core/src/markdown/lint/default-config.ts
+++ b/packages/core/src/markdown/lint/default-config.ts
@@ -6,7 +6,6 @@ export const DEFAULT_MARKDOWNLINT_CONFIG: Record<string, MarkdownlintRuleSetting
MD013: false,
};
-
export function resolveMarkdownlintConfig(
rules: Record<string, MarkdownlintRuleSetting> | undefined,
): Configuration {
diff --git a/packages/core/src/markdown/lint/index.ts b/packages/core/src/markdown/lint/index.ts
index a445cec4c..754f5e68e 100644
--- a/packages/core/src/markdown/lint/index.ts
+++ b/packages/core/src/markdown/lint/index.ts
@@ -1,4 +1,3 @@
-
import { LINT_PLUGINS, type LinterConfig } from './plugins.ts';
import type { LintDiagnostic } from './types.ts';
diff --git a/packages/core/src/markdown/lint/plugins.ts b/packages/core/src/markdown/lint/plugins.ts
index 65a1b564c..1cd40ef3a 100644
--- a/packages/core/src/markdown/lint/plugins.ts
+++ b/packages/core/src/markdown/lint/plugins.ts
@@ -1,4 +1,3 @@
-
import { z } from 'zod';
import { DEFAULT_MARKDOWNLINT_CONFIG, resolveMarkdownlintConfig } from './default-config.ts';
import { fixMarkdownText, runMarkdownlint } from './markdownlint-runner.ts';
@@ -9,7 +8,6 @@ import {
type MarkdownlintSlice,
} from './types.ts';
-
const MarkdownlintRuleSettingSchema = z.union([
z.boolean(),
z.enum(MARKDOWNLINT_RULE_SEVERITIES),
diff --git a/packages/core/src/markdown/lint/types.ts b/packages/core/src/markdown/lint/types.ts
index 015a94c1c..0f756702b 100644
--- a/packages/core/src/markdown/lint/types.ts
+++ b/packages/core/src/markdown/lint/types.ts
@@ -1,4 +1,3 @@
-
export const LINT_PLUGIN_IDS = ['markdownlint'] as const;
export type LintPluginId = (typeof LINT_PLUGIN_IDS)[number];
@@ -54,7 +53,6 @@ export interface MarkdownlintSlice {
rules: Record<string, MarkdownlintRuleSetting>;
}
-
interface RuleOptionSpecBase {
key: string;
description: string;
diff --git a/packages/core/src/markdown/math-promoter.ts b/packages/core/src/markdown/math-promoter.ts
index bd79424c7..a5b511f25 100644
--- a/packages/core/src/markdown/math-promoter.ts
+++ b/packages/core/src/markdown/math-promoter.ts
@@ -1,4 +1,3 @@
-
import type { Code, Root } from 'mdast';
import type { Math as MdastMath } from 'mdast-util-math';
import type { MdxJsxAttribute, MdxJsxFlowElement } from 'mdast-util-mdx';
diff --git a/packages/core/src/markdown/mdast-to-hast-handlers.ts b/packages/core/src/markdown/mdast-to-hast-handlers.ts
index f84967798..679c72ef7 100644
--- a/packages/core/src/markdown/mdast-to-hast-handlers.ts
+++ b/packages/core/src/markdown/mdast-to-hast-handlers.ts
@@ -1,4 +1,3 @@
-
import type { Comment, Element, ElementContent, Properties } from 'hast';
import type { FootnoteDefinition, FootnoteReference } from 'mdast';
import type { MdxJsxFlowElement, MdxJsxTextElement } from 'mdast-util-mdx';
diff --git a/packages/core/src/markdown/mdast-to-html.ts b/packages/core/src/markdown/mdast-to-html.ts
index df788a80d..8ce2b2492 100644
--- a/packages/core/src/markdown/mdast-to-html.ts
+++ b/packages/core/src/markdown/mdast-to-html.ts
@@ -1,4 +1,3 @@
-
import type { Element, Root as HastRoot, Text as HastText } from 'hast';
import type { Root as MdastRoot, Text as MdastText } from 'mdast';
import type { Handler } from 'mdast-util-to-hast';
diff --git a/packages/core/src/markdown/merged-walker.ts b/packages/core/src/markdown/merged-walker.ts
index fa3cfcd86..bfd7e3109 100644
--- a/packages/core/src/markdown/merged-walker.ts
+++ b/packages/core/src/markdown/merged-walker.ts
@@ -1,4 +1,3 @@
-
import type { Nodes, Parent, Root } from 'mdast';
import { SKIP, visit } from 'unist-util-visit';
import type { VFile } from 'vfile';
diff --git a/packages/core/src/markdown/mermaid-promoter.ts b/packages/core/src/markdown/mermaid-promoter.ts
index 17ed2b829..1a897fca8 100644
--- a/packages/core/src/markdown/mermaid-promoter.ts
+++ b/packages/core/src/markdown/mermaid-promoter.ts
@@ -1,4 +1,3 @@
-
import type { Code, Root } from 'mdast';
import type { MdxJsxAttribute, MdxJsxFlowElement } from 'mdast-util-mdx';
import { visit } from 'unist-util-visit';
diff --git a/packages/core/src/markdown/parse-with-fallback.ts b/packages/core/src/markdown/parse-with-fallback.ts
index 7e4a9a48b..9864b3b60 100644
--- a/packages/core/src/markdown/parse-with-fallback.ts
+++ b/packages/core/src/markdown/parse-with-fallback.ts
@@ -168,7 +168,6 @@ export function parseRecursive(
}
}
-
interface VFilePlace {
offset?: number;
start?: { offset?: number };
@@ -187,7 +186,6 @@ function extractErrorOffset(err: unknown): number | undefined {
return undefined;
}
-
interface Region {
start: number;
end: number;
@@ -211,7 +209,6 @@ function nearestBlankLineAfter(src: string, offset: number): number | null {
return null;
}
-
export interface TagEvent {
kind: 'open' | 'close' | 'self-close';
name: string;
@@ -358,7 +355,6 @@ function findFallbackRegion(src: string, errorOffset: number): Region {
return { start: blockStart, end: blockEnd };
}
-
interface SourceBlock {
src: string;
start: number;
@@ -456,7 +452,6 @@ function tryPerBlockFallback(
};
}
-
function wholeDocRawText(source: string): JSONContent {
return {
type: 'doc',
diff --git a/packages/core/src/markdown/parser-drop-closure.ts b/packages/core/src/markdown/parser-drop-closure.ts
index 43d420187..e6ab4fd57 100644
--- a/packages/core/src/markdown/parser-drop-closure.ts
+++ b/packages/core/src/markdown/parser-drop-closure.ts
@@ -1,4 +1,3 @@
-
export type DroppedTokenAdjudication =
| {
kind: 'format-dof-axis';
diff --git a/packages/core/src/markdown/pipeline.ts b/packages/core/src/markdown/pipeline.ts
index e9e507469..7f2d5adca 100644
--- a/packages/core/src/markdown/pipeline.ts
+++ b/packages/core/src/markdown/pipeline.ts
@@ -1,4 +1,3 @@
-
import {
type FromProseMirrorOptions,
fromProseMirror,
diff --git a/packages/core/src/markdown/position-aware-join.ts b/packages/core/src/markdown/position-aware-join.ts
index f8f5e8530..5a5e4c42a 100644
--- a/packages/core/src/markdown/position-aware-join.ts
+++ b/packages/core/src/markdown/position-aware-join.ts
@@ -1,4 +1,3 @@
-
import type { Join } from 'mdast-util-to-markdown';
import type { Position } from 'unist';
diff --git a/packages/core/src/markdown/position-slice.ts b/packages/core/src/markdown/position-slice.ts
index e5b4c9eba..0f399d34c 100644
--- a/packages/core/src/markdown/position-slice.ts
+++ b/packages/core/src/markdown/position-slice.ts
@@ -1,4 +1,3 @@
-
import type { Nodes, Root } from 'mdast';
import { visit } from 'unist-util-visit';
import type { VFile } from 'vfile';
@@ -477,8 +476,7 @@ export function applyPositionSliceToNode(
const first = source[startOff];
if (first !== '[' && first !== '<' && !node.title) {
node.data.sourceStyle = 'gfm-autolink';
- }
- else if (first === '[') {
+ } else if (first === '[') {
const slice = source.slice(startOff, endOff);
const closeBracketIdx = slice.lastIndexOf('](');
if (closeBracketIdx !== -1) {
diff --git a/packages/core/src/markdown/rehype-plugins/skip-notion-whitespace.ts b/packages/core/src/markdown/rehype-plugins/skip-notion-whitespace.ts
index ca225ce9b..db10fa54b 100644
--- a/packages/core/src/markdown/rehype-plugins/skip-notion-whitespace.ts
+++ b/packages/core/src/markdown/rehype-plugins/skip-notion-whitespace.ts
@@ -1,4 +1,3 @@
-
import type { Comment, Element, Root, Text } from 'hast';
import type { Plugin } from 'unified';
diff --git a/packages/core/src/markdown/rehype-plugins/strip-cocoa-meta.ts b/packages/core/src/markdown/rehype-plugins/strip-cocoa-meta.ts
index 3a2524a9a..34068d103 100644
--- a/packages/core/src/markdown/rehype-plugins/strip-cocoa-meta.ts
+++ b/packages/core/src/markdown/rehype-plugins/strip-cocoa-meta.ts
@@ -1,4 +1,3 @@
-
import type { Element, ElementContent, Root } from 'hast';
import type { Plugin } from 'unified';
diff --git a/packages/core/src/markdown/rehype-plugins/strip-gdocs-wrapper.ts b/packages/core/src/markdown/rehype-plugins/strip-gdocs-wrapper.ts
index 2279a0189..93151d43b 100644
--- a/packages/core/src/markdown/rehype-plugins/strip-gdocs-wrapper.ts
+++ b/packages/core/src/markdown/rehype-plugins/strip-gdocs-wrapper.ts
@@ -1,4 +1,3 @@
-
import type { Element, Root } from 'hast';
import type { Plugin } from 'unified';
diff --git a/packages/core/src/markdown/rehype-plugins/strip-github-hovercard.ts b/packages/core/src/markdown/rehype-plugins/strip-github-hovercard.ts
index a0f467c42..188f02d83 100644
--- a/packages/core/src/markdown/rehype-plugins/strip-github-hovercard.ts
+++ b/packages/core/src/markdown/rehype-plugins/strip-github-hovercard.ts
@@ -1,4 +1,3 @@
-
import type { Element, Root } from 'hast';
import type { Plugin } from 'unified';
diff --git a/packages/core/src/markdown/rehype-plugins/strip-gmail-classes.ts b/packages/core/src/markdown/rehype-plugins/strip-gmail-classes.ts
index 4e8542a21..4ba2c3418 100644
--- a/packages/core/src/markdown/rehype-plugins/strip-gmail-classes.ts
+++ b/packages/core/src/markdown/rehype-plugins/strip-gmail-classes.ts
@@ -1,4 +1,3 @@
-
import type { Element, Root } from 'hast';
import type { Plugin } from 'unified';
diff --git a/packages/core/src/markdown/rehype-plugins/strip-gsheets-wrapper.ts b/packages/core/src/markdown/rehype-plugins/strip-gsheets-wrapper.ts
index a3c96b24a..1a74b1272 100644
--- a/packages/core/src/markdown/rehype-plugins/strip-gsheets-wrapper.ts
+++ b/packages/core/src/markdown/rehype-plugins/strip-gsheets-wrapper.ts
@@ -1,4 +1,3 @@
-
import type { Element, ElementContent, Root } from 'hast';
import type { Plugin } from 'unified';
diff --git a/packages/core/src/markdown/rehype-plugins/strip-mso-styles.ts b/packages/core/src/markdown/rehype-plugins/strip-mso-styles.ts
index e95cf43d6..de35e7b79 100644
--- a/packages/core/src/markdown/rehype-plugins/strip-mso-styles.ts
+++ b/packages/core/src/markdown/rehype-plugins/strip-mso-styles.ts
@@ -1,4 +1,3 @@
-
import type { Comment, Element, ElementContent, Root } from 'hast';
import type { Plugin } from 'unified';
diff --git a/packages/core/src/markdown/rehype-plugins/strip-slack-classes.ts b/packages/core/src/markdown/rehype-plugins/strip-slack-classes.ts
index ffdb4d5b5..b4be1b2ea 100644
--- a/packages/core/src/markdown/rehype-plugins/strip-slack-classes.ts
+++ b/packages/core/src/markdown/rehype-plugins/strip-slack-classes.ts
@@ -1,4 +1,3 @@
-
import type { Element, ElementContent, Root } from 'hast';
import type { Plugin } from 'unified';
diff --git a/packages/core/src/markdown/rehype-plugins/strip-vscode-spans.ts b/packages/core/src/markdown/rehype-plugins/strip-vscode-spans.ts
index e2a96d1a7..3c8d88b7c 100644
--- a/packages/core/src/markdown/rehype-plugins/strip-vscode-spans.ts
+++ b/packages/core/src/markdown/rehype-plugins/strip-vscode-spans.ts
@@ -1,4 +1,3 @@
-
import type { Element, Root } from 'hast';
import type { Plugin } from 'unified';
diff --git a/packages/core/src/markdown/resolve-image-url.ts b/packages/core/src/markdown/resolve-image-url.ts
index 0389575ac..cf2c9da8e 100644
--- a/packages/core/src/markdown/resolve-image-url.ts
+++ b/packages/core/src/markdown/resolve-image-url.ts
@@ -1,4 +1,3 @@
-
import { isRelativeUrl } from './safe-url.ts';
function isDevDiagnosticContext(): boolean {
diff --git a/packages/core/src/markdown/safe-url.ts b/packages/core/src/markdown/safe-url.ts
index 8be632ba4..4d3250d3a 100644
--- a/packages/core/src/markdown/safe-url.ts
+++ b/packages/core/src/markdown/safe-url.ts
@@ -1,4 +1,3 @@
-
export const SAFE_URL_SCHEMES = ['https', 'http', 'mailto', 'tel', 'ftp', 'sms'] as const;
const SCHEME_ALT = SAFE_URL_SCHEMES.map((s) => `${s}:`).join('|');
diff --git a/packages/core/src/markdown/serialize-fidelity.test-helper.ts b/packages/core/src/markdown/serialize-fidelity.test-helper.ts
index 96304e7a5..0dd54070e 100644
--- a/packages/core/src/markdown/serialize-fidelity.test-helper.ts
+++ b/packages/core/src/markdown/serialize-fidelity.test-helper.ts
@@ -1,4 +1,3 @@
-
import type { JSONContent } from '@tiptap/core';
import type { Nodes } from 'mdast';
import { expect } from 'vitest';
diff --git a/packages/core/src/markdown/serialize-helpers.ts b/packages/core/src/markdown/serialize-helpers.ts
index 542204403..46cc6a074 100644
--- a/packages/core/src/markdown/serialize-helpers.ts
+++ b/packages/core/src/markdown/serialize-helpers.ts
@@ -1,4 +1,3 @@
-
import type { Node as PmNode } from '@tiptap/pm/model';
import type { MdxJsxAttribute, MdxJsxExpressionAttribute, MdxJsxFlowElement } from 'mdast-util-mdx';
import type { PropDef, SerializeContext } from '../registry/types.ts';
diff --git a/packages/core/src/markdown/single-dollar-math-promoter.ts b/packages/core/src/markdown/single-dollar-math-promoter.ts
index fe73659e6..be97d4d62 100644
--- a/packages/core/src/markdown/single-dollar-math-promoter.ts
+++ b/packages/core/src/markdown/single-dollar-math-promoter.ts
@@ -1,4 +1,3 @@
-
import type { PhrasingContent, Root, Text } from 'mdast';
import type { InlineMath } from 'mdast-util-math';
import { SKIP, visit } from 'unist-util-visit';
diff --git a/packages/core/src/markdown/to-markdown-handlers.ts b/packages/core/src/markdown/to-markdown-handlers.ts
index fd22d2c7b..7f6dfcfc3 100644
--- a/packages/core/src/markdown/to-markdown-handlers.ts
+++ b/packages/core/src/markdown/to-markdown-handlers.ts
@@ -1,4 +1,3 @@
-
import type { Nodes, Parents } from 'mdast';
import type { MdxJsxAttribute, MdxJsxExpressionAttribute, MdxJsxFlowElement } from 'mdast-util-mdx';
import type { Handle, Info, State } from 'mdast-util-to-markdown';
diff --git a/packages/core/src/markdown/unknown-mdast-guard.ts b/packages/core/src/markdown/unknown-mdast-guard.ts
index c5bfd2386..cd245c38c 100644
--- a/packages/core/src/markdown/unknown-mdast-guard.ts
+++ b/packages/core/src/markdown/unknown-mdast-guard.ts
@@ -1,4 +1,3 @@
-
import type { Root as MdastRoot } from 'mdast';
import type { VFile } from 'vfile';
diff --git a/packages/core/src/markdown/whitespace-char-ref.ts b/packages/core/src/markdown/whitespace-char-ref.ts
index ac9f5239b..d578476a7 100644
--- a/packages/core/src/markdown/whitespace-char-ref.ts
+++ b/packages/core/src/markdown/whitespace-char-ref.ts
@@ -1,4 +1,3 @@
-
const INLINE_WHITESPACE_BY_CODE: ReadonlyMap<number, string> = new Map([
[0x20, ' '],
[0x09, '\t'],
diff --git a/packages/core/src/markdown/wiki-link-micromark.ts b/packages/core/src/markdown/wiki-link-micromark.ts
index afd9936fe..6dad26200 100644
--- a/packages/core/src/markdown/wiki-link-micromark.ts
+++ b/packages/core/src/markdown/wiki-link-micromark.ts
@@ -17,7 +17,6 @@ declare module 'micromark-util-types' {
}
}
-
const CODE_BANG = 33; // !
const CODE_LBRACKET = 91; // [
const CODE_RBRACKET = 93; // ]
@@ -261,7 +260,6 @@ export function wikiLinkSyntax(): Extension {
};
}
-
function enterWikiLink(this: CompileContext, token: Token) {
this.enter(
{
@@ -387,7 +385,6 @@ export const wikiLinkToMarkdown: {
unsafe: [{ character: '[', inConstruct: ['phrasing'] }],
};
-
const MICROMARK_EXT = wikiLinkSyntax();
export function remarkWikiLink(this: Processor) {
diff --git a/packages/desktop/electron-builder.yml b/packages/desktop/electron-builder.yml
index 6fcdd064e..da67c2ed6 100644
--- a/packages/desktop/electron-builder.yml
+++ b/packages/desktop/electron-builder.yml
@@ -128,6 +128,22 @@ extraResources:
- "index.d.ts"
- "package.json"
- "*.node"
+ # @parcel/watcher for the bundled CLI. The `asarUnpack` globs below cover the
+ # desktop app's OWN copy under app.asar.unpacked/, but the spawned `ok start`
+ # CLI resolves from `cli/dist → cli → Resources → …` and never reaches it (the
+ # same resolver-scope wall keyring + native-config work around above). Without
+ # a copy on the CLI's path, `import('@parcel/watcher')` throws at server boot
+ # and the watcher degrades to chokidar, dropping external subfolder edits
+ # (inkeep/open-knowledge#760). `scripts/stage-parcel-watcher.mjs` (run from the
+ # per-platform build scripts) resolves the wrapper + its runtime deps
+ # (picomatch v4 / is-glob / is-extglob / detect-libc) + the present per-arch
+ # binary package the way Node's `require()` does — NOT via `.npmrc` hoist,
+ # which the tree's dual picomatch v2/v4 would make ship the wrong major — and
+ # stages them per-OS. This one rule copies that staged tree onto the CLI path.
+ # Coverage: tests/unit/electron-builder-parcel-watcher-deps.test.ts.
+ - from: "build/parcel-watcher-staging/node_modules"
+ to: "cli/node_modules"
+ filter: ["**/*"]
asarUnpack:
- "**/*.node"
@@ -211,9 +227,12 @@ mac:
# path so Universal's merger picks one slice deterministically, or (b)
# invoking @electron/universal with the `singleArchFiles` option for the
# native module. Both require validation against the keyring spec's
- # Pass 0 expectations. For now we ship arm64-only DMG/ZIP so the beta
- # cadence has a working artifact and electron-updater on the beta
- # channel can flow.
+ # Pass 0 expectations. When restoring Universal, the same arch-filter must
+ # also cover the staged `cli/node_modules/@parcel/watcher-darwin-<arch>/
+ # watcher.node` binary (via `scripts/stage-parcel-watcher.mjs`) — it hits the
+ # identical lipo "same in both slices" rejection. For now we ship arm64-only
+ # DMG/ZIP so the beta cadence has a working artifact and electron-updater on
+ # the beta channel can flow.
target:
- target: dmg
arch: [arm64]
diff --git a/packages/desktop/package.json b/packages/desktop/package.json
index 8abde284a..a8552683a 100644
--- a/packages/desktop/package.json
+++ b/packages/desktop/package.json
@@ -19,10 +19,10 @@
"dev:electron": "electron-vite dev --watch",
"build:desktop": "electron-vite build",
"build:dir": "pnpm run build:desktop && electron-builder --dir --publish never",
- "build:mac": "pnpm run build:desktop && node scripts/prepare-universal.mjs && electron-builder --mac --publish never",
- "build:mac:unsigned": "pnpm run build:desktop && node scripts/prepare-universal.mjs && CSC_IDENTITY_AUTO_DISCOVERY=false electron-builder --mac --publish never -c.mac.identity=null",
- "build:win": "pnpm run build:desktop && node scripts/prepare-platform-natives.mjs && electron-builder --win --publish never",
- "build:linux": "pnpm run build:desktop && node scripts/prepare-platform-natives.mjs && electron-builder --linux --publish never",
+ "build:mac": "pnpm run build:desktop && node scripts/prepare-universal.mjs && node scripts/stage-parcel-watcher.mjs && electron-builder --mac --publish never",
+ "build:mac:unsigned": "pnpm run build:desktop && node scripts/prepare-universal.mjs && node scripts/stage-parcel-watcher.mjs && CSC_IDENTITY_AUTO_DISCOVERY=false electron-builder --mac --publish never -c.mac.identity=null",
+ "build:win": "pnpm run build:desktop && node scripts/prepare-platform-natives.mjs && node scripts/stage-parcel-watcher.mjs && electron-builder --win --publish never",
+ "build:linux": "pnpm run build:desktop && node scripts/prepare-platform-natives.mjs && node scripts/stage-parcel-watcher.mjs && electron-builder --linux --publish never",
"prepare:universal": "node scripts/prepare-universal.mjs",
"prepare:platform-natives": "node scripts/prepare-platform-natives.mjs",
"postinstall": "node scripts/postinstall.mjs",
diff --git a/packages/desktop/scripts/stage-parcel-watcher.mjs b/packages/desktop/scripts/stage-parcel-watcher.mjs
new file mode 100644
index 000000000..ee168d609
--- /dev/null
+++ b/packages/desktop/scripts/stage-parcel-watcher.mjs
@@ -0,0 +1,150 @@
+#!/usr/bin/env node
+/**
+ * Stage @parcel/watcher + its runtime tree for the bundled CLI.
+ *
+ * The packaged app spawns `ok start` from `Resources/cli/`, whose ESM/CJS
+ * resolver walks `cli/dist → cli → Resources → …` and NEVER reaches
+ * `app.asar.unpacked/node_modules/` (the same resolver-scope wall the
+ * @napi-rs/keyring + native-config copies already work around). So the app's
+ * asarUnpack copy of @parcel/watcher is invisible to the CLI: at boot
+ * `import('@parcel/watcher')` throws `Cannot find package`, the file watcher
+ * degrades to chokidar, and external edits under content subfolders stop
+ * reaching the server until a restart. inkeep/open-knowledge#760.
+ *
+ * Fix: give the CLI its own copy under `cli/node_modules/`. This script stages
+ * that copy into `build/parcel-watcher-staging/node_modules/`; electron-builder
+ * copies the staged tree via a single `extraResources` rule.
+ *
+ * Resolver-accurate on purpose. @parcel/watcher's wrapper.js `require()`s
+ * picomatch/is-glob/is-extglob and index.js `require()`s detect-libc (linux)
+ * plus the per-arch `@parcel/watcher-<platform>-<arch>` binary. Those runtime
+ * deps are deliberately NOT flat-root-hoisted (`.npmrc`) — the tree carries
+ * both picomatch v2 and v4, so a static `from: node_modules/picomatch` rule
+ * could ship the wrong major. We resolve each dep the way Node's runtime
+ * `require()` does, from @parcel/watcher's own package dir, so the staged
+ * versions are exactly what the wrapper loads.
+ *
+ * Cross-arch: pnpm installs only the host-matching `@parcel/watcher-*` binary,
+ * and we stage whatever binary packages are present. The mac DMG is arm64-only
+ * (matches the arm64-only host), so its arm64 binary is always present and the
+ * fix is complete there. The win/linux dual-arch builds currently stage only
+ * the host-arch binary; the other-arch artifact keeps using the chokidar
+ * fallback (now subfolder-correct, #760), so it degrades gracefully rather than
+ * breaking. Fetching the missing-arch parcel binaries the way
+ * `prepare-platform-natives.mjs` does for keyring is a follow-up.
+ */
+import { cpSync, mkdirSync, readFileSync, rmSync } from 'node:fs';
+import { createRequire } from 'node:module';
+import { dirname, join, resolve } from 'node:path';
+import { fileURLToPath } from 'node:url';
+
+const HERE = dirname(fileURLToPath(import.meta.url));
+const DESKTOP_ROOT = resolve(HERE, '..');
+const REPO_ROOT = resolve(DESKTOP_ROOT, '..', '..');
+const STAGING = join(DESKTOP_ROOT, 'build', 'parcel-watcher-staging', 'node_modules');
+
+/** Runtime JS deps @parcel/watcher `require()`s. node-addon-api is headers-only. */
+const RUNTIME_DEPS = ['picomatch', 'is-glob', 'is-extglob', 'detect-libc'];
+
+/**
+ * Candidate per-arch binary packages for OUR build targets — mac (arm64/x64),
+ * win (x64/arm64), linux (x64/arm64). We stage whichever are present rather
+ * than hardcoding one target. @parcel/watcher also publishes musl and 32-bit
+ * `linux-arm` variants; those are intentionally omitted — Electron desktop
+ * ships glibc-only and we build no 32-bit-arm artifact, so they'd never load.
+ */
+const PREBUILD_SUFFIXES = [
+ 'darwin-arm64',
+ 'darwin-x64',
+ 'win32-x64',
+ 'win32-arm64',
+ 'linux-x64-glibc',
+ 'linux-arm64-glibc',
+];
+
+const requireFromRepo = createRequire(join(REPO_ROOT, 'noop.js'));
+
+/** Resolve a package's dir the way Node's `require()` does (pnpm-isolation-safe). */
+function resolvePkgDir(requireFrom, name) {
+ try {
+ return dirname(requireFrom.resolve(`${name}/package.json`));
+ } catch {
+ return undefined;
+ }
+}
+
+const parcelDir = resolvePkgDir(requireFromRepo, '@parcel/watcher');
+if (!parcelDir) {
+ console.error(
+ '[stage-parcel-watcher] @parcel/watcher not resolvable from the repo root. Run `pnpm install` first.',
+ );
+ process.exit(1);
+}
+const parcelVersion = JSON.parse(readFileSync(join(parcelDir, 'package.json'), 'utf8')).version;
+// Resolve the wrapper's own deps from ITS package dir so we copy the exact
+// versions it loads (picomatch v4, not the v2 elsewhere in the tree).
+const requireFromParcel = createRequire(join(parcelDir, 'package.json'));
+
+// Fresh staging tree each run — idempotent and never ships a stale version.
+rmSync(dirname(STAGING), { recursive: true, force: true });
+mkdirSync(STAGING, { recursive: true });
+
+/** Copy a resolved package dir into the staging tree, filtering to runtime files. */
+function stagePackage(name, srcDir, { runtimeFilesOnly = false } = {}) {
+ const dest = join(STAGING, name);
+ mkdirSync(dirname(dest), { recursive: true });
+ cpSync(srcDir, dest, {
+ recursive: true,
+ dereference: true,
+ filter: (src) => {
+ if (!runtimeFilesOnly) return true;
+ // Drop the C++ sources / gyp / prebuild scratch @parcel/watcher publishes
+ // — dead weight in the app, none of it is loaded at runtime. cpSync hands
+ // the filter native-separator paths, so split on both `/` and `\` or the
+ // exclusion silently no-ops on Windows builds.
+ const rel = src.slice(srcDir.length + 1);
+ const top = rel.split(/[\\/]/)[0];
+ return top !== 'src' && top !== 'build' && top !== 'prebuilds' && top !== 'binding.gyp';
+ },
+ });
+ return dest;
+}
+
+console.log(`[stage-parcel-watcher] @parcel/watcher v${parcelVersion} → ${STAGING}`);
+stagePackage('@parcel/watcher', parcelDir, { runtimeFilesOnly: true });
+
+for (const dep of RUNTIME_DEPS) {
+ const dir = resolvePkgDir(requireFromParcel, dep);
+ if (!dir) {
+ // detect-libc is only require()d on linux; the others are unconditional.
+ if (dep === 'detect-libc') {
+ console.log(`[stage-parcel-watcher] ${dep} not resolvable — skipping (linux-only dep)`);
+ continue;
+ }
+ console.error(`[stage-parcel-watcher] required runtime dep '${dep}' not resolvable`);
+ process.exit(1);
+ }
+ const version = JSON.parse(readFileSync(join(dir, 'package.json'), 'utf8')).version;
+ stagePackage(dep, dir);
+ console.log(`[stage-parcel-watcher] ${dep} v${version}`);
+}
+
+let prebuilds = 0;
+for (const suffix of PREBUILD_SUFFIXES) {
+ const name = `@parcel/watcher-${suffix}`;
+ const dir = resolvePkgDir(requireFromParcel, name);
+ if (!dir) continue;
+ stagePackage(name, dir);
+ prebuilds++;
+ console.log(`[stage-parcel-watcher] ${name}`);
+}
+if (prebuilds === 0) {
+ console.error(
+ '[stage-parcel-watcher] no @parcel/watcher-<platform>-<arch> binary package staged — the CLI would still fall back to chokidar.',
+ );
+ process.exit(1);
+}
+
+console.log(
+ `[stage-parcel-watcher] staged ${RUNTIME_DEPS.length} runtime deps + ${prebuilds} binary package(s).`,
+);
diff --git a/packages/desktop/tests/unit/electron-builder-cli-native-deps.test.ts b/packages/desktop/tests/unit/electron-builder-cli-native-deps.test.ts
index b39bd42a2..18d56ce0e 100644
--- a/packages/desktop/tests/unit/electron-builder-cli-native-deps.test.ts
+++ b/packages/desktop/tests/unit/electron-builder-cli-native-deps.test.ts
@@ -33,17 +33,29 @@ const okRoot = resolve(desktopRoot, '..', '..');
/**
* Natives intentionally NOT shipped into cli/node_modules, each with its
* reason. Every entry asserts "we considered this and decided the bundled-CLI
- * path doesn't need it." Keep this set as small as possible.
+ * path doesn't need it." Keep this set as small as possible — empty is ideal.
*
- * `@parcel/watcher`: only reached when `ok start` / `ok mcp` boots the server
- * in-process from the bundled CLI. Its absence degrades to chokidar (a
- * functional fallback), not a silent security downgrade, and shipping it
- * cleanly requires its transitive runtime JS deps too (detect-libc, is-glob,
- * picomatch, ...).
+ * `@parcel/watcher` used to live here (absence degraded to chokidar). It is now
+ * staged onto the CLI path via the `build/parcel-watcher-staging/node_modules →
+ * cli/node_modules` rule (see `stage-parcel-watcher.mjs`), so it is covered
+ * below through `shippedViaParcelStaging`, not allowlisted.
*/
-const KNOWN_UNCOVERED: Record<string, string> = {
- '@parcel/watcher': 'degrades to chokidar fallback; transitive runtime deps tracked as follow-up',
-};
+const KNOWN_UNCOVERED: Record<string, string> = {};
+
+/**
+ * @parcel/watcher ships as a whole staged tree copied to `cli/node_modules`
+ * (wrapper + runtime deps + per-arch binary), so its coverage is the presence
+ * of that one staging rule rather than a `cli/node_modules/@parcel/watcher`
+ * target. Recognizing it here means this test also fails loudly if the staging
+ * rule is ever dropped — defense in depth alongside
+ * electron-builder-parcel-watcher-deps.test.ts.
+ */
+function shippedViaParcelStaging(pkg: string): boolean {
+ if (pkg !== '@parcel/watcher') return false;
+ return readExtraResources().some(
+ (r) => r.to === 'cli/node_modules' && r.from === 'build/parcel-watcher-staging/node_modules',
+ );
+}
function readNeverBundle(): string[] {
try {
@@ -120,7 +132,7 @@ describe('bundled CLI can resolve tsdown neverBundle native addons', () => {
for (const pkg of neverBundle) {
test(`'${pkg}' is shipped to cli/node_modules or explicitly allowlisted`, () => {
- const shipped = targets.includes(`cli/node_modules/${pkg}`);
+ const shipped = targets.includes(`cli/node_modules/${pkg}`) || shippedViaParcelStaging(pkg);
const allowlisted = pkg in KNOWN_UNCOVERED;
expect(
shipped || allowlisted,
diff --git a/packages/desktop/tests/unit/electron-builder-parcel-watcher-deps.test.ts b/packages/desktop/tests/unit/electron-builder-parcel-watcher-deps.test.ts
index 6eba53128..4cfbf4916 100644
--- a/packages/desktop/tests/unit/electron-builder-parcel-watcher-deps.test.ts
+++ b/packages/desktop/tests/unit/electron-builder-parcel-watcher-deps.test.ts
@@ -1,4 +1,5 @@
-import { existsSync, readFileSync } from 'node:fs';
+import { execFileSync } from 'node:child_process';
+import { existsSync, readdirSync, readFileSync } from 'node:fs';
import { createRequire } from 'node:module';
import { dirname, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
@@ -163,3 +164,90 @@ describe('asarUnpack covers @parcel/watcher runtime deps', () => {
});
}
});
+
+/**
+ * The asarUnpack rules above cover the desktop app's OWN copy of
+ * @parcel/watcher. The spawned `ok start` CLI resolves from a separate tree
+ * (`cli/node_modules/`) it never reaches through the asar, so it needs its own
+ * copy — staged by `scripts/stage-parcel-watcher.mjs` and placed by the
+ * `build/parcel-watcher-staging/node_modules → cli/node_modules` extraResources
+ * rule. This suite runs the staging script and verifies the staged tree is
+ * actually resolvable the way the CLI will load it — the packaging-time
+ * signal for #760 that doesn't need a full DMG build.
+ */
+describe('stage-parcel-watcher stages a CLI-resolvable @parcel/watcher tree', () => {
+ const stageScript = resolve(desktopRoot, 'scripts', 'stage-parcel-watcher.mjs');
+ const stagedRoot = resolve(desktopRoot, 'build', 'parcel-watcher-staging', 'node_modules');
+ const stagedParcelPkg = resolve(stagedRoot, '@parcel', 'watcher', 'package.json');
+
+ let staged = false;
+ let stageError = '';
+ try {
+ execFileSync('node', [stageScript], { stdio: 'pipe' });
+ staged = true;
+ } catch (err) {
+ // Surface the script's own stderr so a CI failure names WHY (unresolvable
+ // package / dep, zero binaries) instead of a bare non-zero exit.
+ const e = err as { stderr?: Buffer; stdout?: Buffer; message?: string };
+ stageError = (e.stderr?.toString() || e.stdout?.toString() || e.message || '').trim();
+ }
+
+ test('the staging script runs and produces the staged wrapper', () => {
+ expect(staged, `node scripts/stage-parcel-watcher.mjs failed:\n${stageError}`).toBe(true);
+ expect(existsSync(stagedParcelPkg)).toBe(true);
+ });
+
+ test('the wrapper resolves its runtime deps from the staged tree, at picomatch v4', () => {
+ if (!existsSync(stagedParcelPkg)) {
+ expect(staged).toBe(true);
+ return;
+ }
+ const req = createRequire(stagedParcelPkg);
+ // detect-libc is require()d by index.js on linux; staged on every platform
+ // so a Linux staging regression is caught here rather than only in a Linux
+ // packaged build.
+ for (const dep of ['picomatch', 'is-glob', 'is-extglob', 'detect-libc']) {
+ expect(() => req.resolve(dep), `'${dep}' must resolve from the staged wrapper`).not.toThrow();
+ }
+ // The workspace carries both picomatch v2 and v4; the wrapper needs v4. A
+ // static `.npmrc` hoist could stage v2 — assert the resolver-accurate copy
+ // shipped the major the wrapper actually loads.
+ const picomatch = JSON.parse(readFileSync(req.resolve('picomatch/package.json'), 'utf8')) as {
+ version: string;
+ };
+ expect(picomatch.version.startsWith('4.')).toBe(true);
+ });
+
+ test('at least one per-arch binary package with a .node is staged', () => {
+ const parcelScope = resolve(stagedRoot, '@parcel');
+ if (!existsSync(parcelScope)) {
+ expect(staged).toBe(true);
+ return;
+ }
+ const prebuilds = readdirSync(parcelScope).filter((n) => n.startsWith('watcher-'));
+ expect(prebuilds.length).toBeGreaterThan(0);
+ const hasBinary = prebuilds.some((p) =>
+ readdirSync(resolve(parcelScope, p)).some((f) => f.endsWith('.node')),
+ );
+ expect(hasBinary, 'a staged @parcel/watcher-* package must carry its .node binary').toBe(true);
+ });
+
+ test('electron-builder copies the staged tree onto the CLI path', () => {
+ let extraResources: Array<{ from?: string; to?: string }> = [];
+ try {
+ const config = parse(readFileSync(builderYml, 'utf8')) as {
+ extraResources?: Array<{ from?: string; to?: string }>;
+ };
+ extraResources = config.extraResources ?? [];
+ } catch {
+ // Fall through — the assertion below names the missing/unreadable rule.
+ }
+ const rule = extraResources.find(
+ (r) => r.from === 'build/parcel-watcher-staging/node_modules' && r.to === 'cli/node_modules',
+ );
+ expect(
+ rule,
+ 'electron-builder.yml must copy build/parcel-watcher-staging/node_modules → cli/node_modules',
+ ).toBeTruthy();
+ });
+});