deictic 0.7.0 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/API.md +23 -3
- package/README.md +2 -1
- package/dist/bun.js +1 -1
- package/dist/client/index.d.ts +1 -1
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +77 -51
- package/dist/client/index.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/next.js +1 -1
- package/dist/recommended/index.d.ts +1 -1
- package/dist/recordings/client.js +8 -2
- package/dist/recordings/client.js.map +1 -1
- package/dist/screenshots/rrweb.d.ts.map +1 -1
- package/dist/screenshots/rrweb.js +11 -2
- package/dist/screenshots/rrweb.js.map +1 -1
- package/dist/shared/canvas.js +30 -0
- package/dist/shared/canvas.js.map +1 -0
- package/dist/shared/endpoints.js +26 -6
- package/dist/shared/endpoints.js.map +1 -1
- package/dist/shared/find.js +6 -1
- package/dist/shared/find.js.map +1 -1
- package/dist/shared/frame.js +5 -2
- package/dist/shared/frame.js.map +1 -1
- package/dist/shared/index.d.ts +35 -3
- package/dist/shared/index.d.ts.map +1 -1
- package/dist/shared/index7.d.ts +22 -2
- package/dist/shared/index7.d.ts.map +1 -1
- package/dist/shared/index9.d.ts +1 -1
- package/dist/shared/integration.d.ts +1 -1
- package/dist/shared/integration.js +59 -5
- package/dist/shared/integration.js.map +1 -1
- package/dist/shared/package.js +23 -0
- package/dist/shared/package.js.map +1 -0
- package/dist/shared/packages.js +14 -23
- package/dist/shared/packages.js.map +1 -1
- package/dist/shared/playwright.js +32 -6
- package/dist/shared/playwright.js.map +1 -1
- package/dist/shared/src.js.map +1 -1
- package/dist/shared/task.js +12 -3
- package/dist/shared/task.js.map +1 -1
- package/dist/shared/tasks.js +52 -4
- package/dist/shared/tasks.js.map +1 -1
- package/dist/shared/watch.js +2 -1
- package/dist/shared/watch.js.map +1 -1
- package/dist/tailwind/index.js +7 -2
- package/dist/tailwind/index.js.map +1 -1
- package/dist/tasks/client.d.ts.map +1 -1
- package/dist/tasks/client.js +50 -9
- package/dist/tasks/client.js.map +1 -1
- package/dist/tasks/index.d.ts +2 -2
- package/dist/webpack.js +1 -1
- package/package.json +2 -1
- package/src/cli/find.ts +5 -1
- package/src/cli/frame.ts +6 -3
- package/src/cli/task.ts +20 -4
- package/src/cli/watch.ts +3 -1
- package/src/client/index.ts +76 -43
- package/src/index.ts +35 -2
- package/src/plugins/recordings/client.ts +8 -2
- package/src/plugins/screenshots/canvas.ts +27 -0
- package/src/plugins/screenshots/playwright.ts +34 -7
- package/src/plugins/screenshots/rrweb.ts +30 -9
- package/src/plugins/tailwind/index.ts +3 -2
- package/src/plugins/tasks/client.ts +13 -3
- package/src/plugins/tasks/composer.ts +1 -1
- package/src/plugins/tasks/drawer.ts +3 -3
- package/src/plugins/tasks/index.ts +81 -3
- package/src/plugins/tasks/pins.ts +12 -7
- package/src/plugins/tasks/which.ts +34 -0
- package/src/tools/endpoints.ts +31 -5
- package/src/tools/packages.ts +12 -4
- package/src/tools/plugins.ts +18 -4
- package/src/tools/problems.ts +60 -0
package/dist/shared/find.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"find.js","names":[],"sources":["../../src/cli/find.ts"],"sourcesContent":["/**\n * Finding what a task carries: a recording or a voice clip, by a task's ID, a recording's ID, a replay URL or a path,\n * kept under a `.deictic/` near here or downloaded from the board. And the tools outside deictic some commands run\n * (ffmpeg, the project's Playwright).\n */\nimport { spawnSync } from 'node:child_process';\nimport { existsSync, mkdtempSync, readdirSync, readFileSync } from 'node:fs';\nimport { createRequire } from 'node:module';\nimport { tmpdir } from 'node:os';\nimport { join } from 'node:path';\nimport { pathToFileURL } from 'node:url';\n\nimport type { Kept } from '#src/plugins/recordings/index.ts';\n\nimport { deicticDirs, download, fail, type Message, task } from './board.ts';\n\nconst TASK = /^#?\\d+$/;\n\nexport interface Found {\n kept: Kept;\n id: string;\n /** Where it replays, where that's known. */\n replay?: string;\n /** The task it's attached to, where it was found by one. */\n task?: Message;\n}\n\nconst parsed = (path: string) => JSON.parse(readFileSync(path, 'utf8')) as Kept;\n\n/** An attachment of a task, written to a temporary folder: its path. */\nfunction fetched(root: Message, name: string): string {\n const file = root.attachments.find((a) => a.name === name);\n if (file === undefined) fail(`Task #${root.id} has no ${name}.`);\n const path = join(mkdtempSync(join(tmpdir(), 'deictic-')), file.name);\n download(file, path);\n return path;\n}\n\n/**\n * A recording, with where it came from. `ref` is a task's ID (its first recording, or the `nth`), a replay or\n * recording URL, a recording's ID kept under a `.deictic/`, or a path.\n */\nexport async function loadRecording(ref: string | undefined, nth = 1): Promise<Found> {\n if (ref === undefined) fail('Name a recording: a task (68), a replay URL, a recording ID or a JSON file.');\n if (TASK.test(ref)) {\n const root = task(ref);\n const files = root.attachments.filter((a) => /^recording-.*\\.json$/.test(a.name));\n const file = files[nth - 1];\n if (file === undefined) fail(`Task #${root.id} has ${files.length} recording(s), not a ${nth}th.`);\n const id = file.name.slice('recording-'.length, -'.json'.length);\n // Its `deictic.recording.N.replay` label, or in the text of a task added before that was a label.\n const where = (text: string) => new RegExp(`https?://\\\\S+/replay/${id}`).exec(text)?.[0];\n const replay = Object.values(root.labels).map(where).find(Boolean) ?? where(root.text);\n return { kept: parsed(fetched(root, file.name)), id, replay, task: root };\n }\n if (/^https?:/.test(ref)) {\n const url = new URL(ref);\n const id = url.pathname.split('/').at(-1) ?? '';\n const json = new URL(url.pathname.replace(/\\/(replay|recording)\\/[^/]+$/, `/recording/${id}`), url);\n const res = await fetch(json);\n if (!res.ok) fail(`${json.href}: ${res.status} ${await res.text()}`);\n return { kept: (await res.json()) as Kept, id, replay: new URL(json.pathname.replace(/\\/recording\\//, '/replay/'), url).href };\n }\n if (existsSync(ref)) return { kept: parsed(ref), id: ref.replace(/^.*[\\\\/]|\\.json$/g, '') };\n for (const dir of deicticDirs()) {\n const path = join(dir, 'recordings', `${ref}.json`);\n if (existsSync(path)) return { kept: parsed(path), id: ref };\n }\n return fail(`No recording ${ref} in ${deicticDirs().join(', ') || 'any .deictic/ near here'}: name its task or replay URL instead.`);\n}\n\n/** A voice clip kept under a `.deictic/` near here, by its ID. */\nfunction keptClip(id: string): string | undefined {\n for (const dir of deicticDirs()) {\n const voice = join(dir, 'voice');\n const name = existsSync(voice) ? readdirSync(voice).find((f) => f.startsWith(`${id}.`)) : undefined;\n if (name !== undefined) return join(voice, name);\n }\n return undefined;\n}\n\n/** A voice clip's audio as a file: kept under a `.deictic/`, or downloaded from `from`. */\nfunction voiceFile(id: string, from?: Message): string {\n const kept = keptClip(id);\n if (kept !== undefined) return kept;\n const file = from?.attachments.find((a) => a.name.startsWith(`voice-${id}.`));\n if (from === undefined || file === undefined) fail(`No voice clip ${id} here${from ? ` or on task #${from.id}` : ''}.`);\n return fetched(from, file.name);\n}\n\nexport interface Clip {\n id: string;\n file: string;\n /** Where it starts in its recording, or 0 for a voice note on its own. */\n at: number;\n recording?: string;\n}\n\n/**\n * The voice clips `ref` names: a task (every recording's clips and its voice notes), a recording as `loadRecording`\n * takes one, or a clip's ID.\n */\nexport async function voiceClips(ref: string | undefined): Promise<Clip[]> {\n if (ref === undefined) fail('Name a task, a recording or a voice clip.');\n const clips: Clip[] = [];\n if (TASK.test(ref)) {\n const root = task(ref);\n const recordings = root.attachments.filter((a) => /^recording-.*\\.json$/.test(a.name));\n const inRecordings = new Set<string>();\n for (let n = 1; n <= recordings.length; n++) {\n const { kept, id } = await loadRecording(ref, n);\n for (const c of kept.voice ?? []) {\n inRecordings.add(c.id);\n clips.push({ id: c.id, file: voiceFile(c.id, root), at: c.at, recording: id });\n }\n }\n for (const a of root.attachments) {\n const id = /^voice-(.+)\\.\\w+$/.exec(a.name)?.[1];\n if (id !== undefined && !inRecordings.has(id)) clips.push({ id, file: voiceFile(id, root), at: 0 });\n }\n } else if (!/^https?:/.test(ref) && !existsSync(ref) && keptClip(ref) !== undefined) {\n clips.push({ id: ref, file: voiceFile(ref), at: 0 });\n } else {\n const { kept, id } = await loadRecording(ref);\n for (const c of kept.voice ?? []) clips.push({ id: c.id, file: voiceFile(c.id), at: c.at, recording: id });\n }\n if (clips.length === 0) fail(`No voice on ${ref}.`);\n return clips;\n}\n\n/** Runs ffmpeg, which reads what MediaRecorder makes, and answers its log (stderr) and what it wrote to stdout. */\nexport function ffmpeg(args: string[]): { stdout: Buffer; log: string } {\n const run = spawnSync('ffmpeg', ['-hide_banner', '-nostats', ...args], { maxBuffer: 1 << 30 });\n if (run.error) fail('Needs ffmpeg on the PATH (https://ffmpeg.org/download.html).');\n return { stdout: run.stdout, log: run.stderr.toString('utf8') };\n}\n\n/** The project's own copy of a package deictic doesn't bring (Playwright, either of its names), from here. */\nexport async function fromProject<T>(...names: string[]): Promise<T> {\n const project = createRequire(join(process.cwd(), 'package.json'));\n for (const name of names) {\n try {\n return (await import(pathToFileURL(project.resolve(name)).href)) as T;\n } catch {\n // Not this one: the next name.\n }\n }\n return fail(`Needs ${names.join(' or ')} in the project: npm install -D ${names[0]}`);\n}\n"],"mappings":";;;;;;;;;;;;;AAgBA,MAAM,OAAO;AAWb,MAAM,UAAU,SAAiB,KAAK,MAAM,aAAa,MAAM,MAAM,CAAC;;AAGtE,SAAS,QAAQ,MAAe,MAAsB;CACpD,MAAM,OAAO,KAAK,YAAY,MAAM,MAAM,EAAE,SAAS,IAAI;CACzD,IAAI,SAAS,KAAA,GAAW,KAAK,SAAS,KAAK,GAAG,UAAU,KAAK,EAAE;CAC/D,MAAM,OAAO,KAAK,YAAY,KAAK,OAAO,GAAG,UAAU,CAAC,GAAG,KAAK,IAAI;CACpE,SAAS,MAAM,IAAI;CACnB,OAAO;AACT;;;;;AAMA,eAAsB,cAAc,KAAyB,MAAM,GAAmB;CACpF,IAAI,QAAQ,KAAA,GAAW,KAAK,6EAA6E;CACzG,IAAI,KAAK,KAAK,GAAG,GAAG;EAClB,MAAM,OAAO,KAAK,GAAG;EACrB,MAAM,QAAQ,KAAK,YAAY,QAAQ,MAAM,uBAAuB,KAAK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cAAc,QAAQ,QAAQ,IAAI,CAAC,CAAC,CAAC;CAC5D,QAAQ,CAER;CAEF,OAAO,KAAK,SAAS,MAAM,KAAK,MAAM,EAAE,kCAAkC,MAAM,IAAI;AACtF"}
|
|
1
|
+
{"version":3,"file":"find.js","names":[],"sources":["../../src/cli/find.ts"],"sourcesContent":["/**\n * Finding what a task carries: a recording or a voice clip, by a task's ID, a recording's ID, a replay URL or a path,\n * kept under a `.deictic/` near here or downloaded from the board. And the tools outside deictic some commands run\n * (ffmpeg, the project's Playwright).\n */\nimport { spawnSync } from 'node:child_process';\nimport { existsSync, mkdtempSync, readdirSync, readFileSync } from 'node:fs';\nimport { createRequire } from 'node:module';\nimport { tmpdir } from 'node:os';\nimport { join } from 'node:path';\nimport { pathToFileURL } from 'node:url';\n\nimport type { Kept } from '#src/plugins/recordings/index.ts';\n\nimport { deicticDirs, download, fail, type Message, task } from './board.ts';\n\nconst TASK = /^#?\\d+$/;\n\nexport interface Found {\n kept: Kept;\n id: string;\n /** Where it replays, where that's known. */\n replay?: string;\n /** The task it's attached to, where it was found by one. */\n task?: Message;\n}\n\nconst parsed = (path: string) => JSON.parse(readFileSync(path, 'utf8')) as Kept;\n\n/** An attachment of a task, written to a temporary folder: its path. */\nfunction fetched(root: Message, name: string): string {\n const file = root.attachments.find((a) => a.name === name);\n if (file === undefined) fail(`Task #${root.id} has no ${name}.`);\n const path = join(mkdtempSync(join(tmpdir(), 'deictic-')), file.name);\n download(file, path);\n return path;\n}\n\n/**\n * A recording, with where it came from. `ref` is a task's ID (its first recording, or the `nth`), a replay or\n * recording URL, a recording's ID kept under a `.deictic/`, or a path.\n */\nexport async function loadRecording(ref: string | undefined, nth = 1): Promise<Found> {\n if (ref === undefined) fail('Name a recording: a task (68), a replay URL, a recording ID or a JSON file.');\n if (TASK.test(ref)) {\n const root = task(ref);\n const files = root.attachments.filter((a) => /^recording-.*\\.json$/.test(a.name));\n const file = files[nth - 1];\n if (file === undefined) fail(`Task #${root.id} has ${files.length} recording(s), not a ${nth}th.`);\n const id = file.name.slice('recording-'.length, -'.json'.length);\n // Its `deictic.recording.N.replay` label, or in the text of a task added before that was a label.\n const where = (text: string) => new RegExp(`https?://\\\\S+/replay/${id}`).exec(text)?.[0];\n const replay = Object.values(root.labels).map(where).find(Boolean) ?? where(root.text);\n return { kept: parsed(fetched(root, file.name)), id, replay, task: root };\n }\n if (/^https?:/.test(ref)) {\n const url = new URL(ref);\n const id = url.pathname.split('/').at(-1) ?? '';\n const json = new URL(url.pathname.replace(/\\/(replay|recording)\\/[^/]+$/, `/recording/${id}`), url);\n const res = await fetch(json);\n if (!res.ok) fail(`${json.href}: ${res.status} ${await res.text()}`);\n return { kept: (await res.json()) as Kept, id, replay: new URL(json.pathname.replace(/\\/recording\\//, '/replay/'), url).href };\n }\n if (existsSync(ref)) return { kept: parsed(ref), id: ref.replace(/^.*[\\\\/]|\\.json$/g, '') };\n for (const dir of deicticDirs()) {\n const path = join(dir, 'recordings', `${ref}.json`);\n if (existsSync(path)) return { kept: parsed(path), id: ref };\n }\n return fail(`No recording ${ref} in ${deicticDirs().join(', ') || 'any .deictic/ near here'}: name its task or replay URL instead.`);\n}\n\n/** A voice clip kept under a `.deictic/` near here, by its ID. */\nfunction keptClip(id: string): string | undefined {\n for (const dir of deicticDirs()) {\n const voice = join(dir, 'voice');\n const name = existsSync(voice) ? readdirSync(voice).find((f) => f.startsWith(`${id}.`)) : undefined;\n if (name !== undefined) return join(voice, name);\n }\n return undefined;\n}\n\n/** A voice clip's audio as a file: kept under a `.deictic/`, or downloaded from `from`. */\nfunction voiceFile(id: string, from?: Message): string {\n const kept = keptClip(id);\n if (kept !== undefined) return kept;\n const file = from?.attachments.find((a) => a.name.startsWith(`voice-${id}.`));\n if (from === undefined || file === undefined) fail(`No voice clip ${id} here${from ? ` or on task #${from.id}` : ''}.`);\n return fetched(from, file.name);\n}\n\nexport interface Clip {\n id: string;\n file: string;\n /** Where it starts in its recording, or 0 for a voice note on its own. */\n at: number;\n recording?: string;\n}\n\n/**\n * The voice clips `ref` names: a task (every recording's clips and its voice notes), a recording as `loadRecording`\n * takes one, or a clip's ID.\n */\nexport async function voiceClips(ref: string | undefined): Promise<Clip[]> {\n if (ref === undefined) fail('Name a task, a recording or a voice clip.');\n const clips: Clip[] = [];\n if (TASK.test(ref)) {\n const root = task(ref);\n const recordings = root.attachments.filter((a) => /^recording-.*\\.json$/.test(a.name));\n const inRecordings = new Set<string>();\n for (let n = 1; n <= recordings.length; n++) {\n const { kept, id } = await loadRecording(ref, n);\n for (const c of kept.voice ?? []) {\n inRecordings.add(c.id);\n clips.push({ id: c.id, file: voiceFile(c.id, root), at: c.at, recording: id });\n }\n }\n for (const a of root.attachments) {\n const id = /^voice-(.+)\\.\\w+$/.exec(a.name)?.[1];\n if (id !== undefined && !inRecordings.has(id)) clips.push({ id, file: voiceFile(id, root), at: 0 });\n }\n } else if (!/^https?:/.test(ref) && !existsSync(ref) && keptClip(ref) !== undefined) {\n clips.push({ id: ref, file: voiceFile(ref), at: 0 });\n } else {\n const { kept, id } = await loadRecording(ref);\n for (const c of kept.voice ?? []) clips.push({ id: c.id, file: voiceFile(c.id), at: c.at, recording: id });\n }\n if (clips.length === 0) fail(`No voice on ${ref}.`);\n return clips;\n}\n\n/** Runs ffmpeg, which reads what MediaRecorder makes, and answers its log (stderr) and what it wrote to stdout. */\nexport function ffmpeg(args: string[]): { stdout: Buffer; log: string } {\n const run = spawnSync('ffmpeg', ['-hide_banner', '-nostats', ...args], { maxBuffer: 1 << 30 });\n if (run.error) fail('Needs ffmpeg on the PATH (https://ffmpeg.org/download.html).');\n return { stdout: run.stdout, log: run.stderr.toString('utf8') };\n}\n\n/** The project's own copy of a package deictic doesn't bring (Playwright, either of its names), from here. */\nexport async function fromProject<T>(...names: string[]): Promise<T> {\n const project = createRequire(join(process.cwd(), 'package.json'));\n for (const name of names) {\n try {\n const module = (await import(pathToFileURL(project.resolve(name)).href)) as Record<string, unknown>;\n // A CommonJS package whose exports Node can't name, as playwright-core's `module.exports = require(…)`, has\n // them on `default` alone.\n const exported = module.default;\n return (typeof exported === 'object' && exported !== null ? { ...exported, ...module } : module) as T;\n } catch {\n // Not this one: the next name.\n }\n }\n return fail(`Needs ${names.join(' or ')} in the project: npm install -D ${names[0]}`);\n}\n"],"mappings":";;;;;;;;;;;;;AAgBA,MAAM,OAAO;AAWb,MAAM,UAAU,SAAiB,KAAK,MAAM,aAAa,MAAM,MAAM,CAAC;;AAGtE,SAAS,QAAQ,MAAe,MAAsB;CACpD,MAAM,OAAO,KAAK,YAAY,MAAM,MAAM,EAAE,SAAS,IAAI;CACzD,IAAI,SAAS,KAAA,GAAW,KAAK,SAAS,KAAK,GAAG,UAAU,KAAK,EAAE;CAC/D,MAAM,OAAO,KAAK,YAAY,KAAK,OAAO,GAAG,UAAU,CAAC,GAAG,KAAK,IAAI;CACpE,SAAS,MAAM,IAAI;CACnB,OAAO;AACT;;;;;AAMA,eAAsB,cAAc,KAAyB,MAAM,GAAmB;CACpF,IAAI,QAAQ,KAAA,GAAW,KAAK,6EAA6E;CACzG,IAAI,KAAK,KAAK,GAAG,GAAG;EAClB,MAAM,OAAO,KAAK,GAAG;EACrB,MAAM,QAAQ,KAAK,YAAY,QAAQ,MAAM,uBAAuB,KAAK,EAAE,IAAI,CAAC;EAChF,MAAM,OAAO,MAAM,MAAM;EACzB,IAAI,SAAS,KAAA,GAAW,KAAK,SAAS,KAAK,GAAG,OAAO,MAAM,OAAO,uBAAuB,IAAI,IAAI;EACjG,MAAM,KAAK,KAAK,KAAK,MAAM,IAAqB,EAAe;EAE/D,MAAM,SAAS,SAAiB,IAAI,OAAO,wBAAwB,IAAI,CAAC,CAAC,KAAK,IAAI,CAAC,GAAG;EACtF,MAAM,SAAS,OAAO,OAAO,KAAK,MAAM,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,KAAK,OAAO,KAAK,MAAM,KAAK,IAAI;EACrF,OAAO;GAAE,MAAM,OAAO,QAAQ,MAAM,KAAK,I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SAAS,GAAG,MAAM,KAAA,GACxE,MAAM,KAAK;EAAE,IAAI;EAAK,MAAM,UAAU,GAAG;EAAG,IAAI;CAAE,CAAC;MAC9C;EACL,MAAM,EAAE,MAAM,OAAO,MAAM,cAAc,GAAG;EAC5C,KAAK,MAAM,KAAK,KAAK,SAAS,CAAC,GAAG,MAAM,KAAK;GAAE,IAAI,EAAE;GAAI,MAAM,UAAU,EAAE,EAAE;GAAG,IAAI,EAAE;GAAI,WAAW;EAAG,CAAC;CAC3G;CACA,IAAI,MAAM,WAAW,GAAG,KAAK,eAAe,IAAI,EAAE;CAClD,OAAO;AACT;;AAGA,SAAgB,OAAO,MAAiD;CACtE,MAAM,MAAM,UAAU,UAAU;EAAC;EAAgB;EAAY,GAAG;CAAI,GAAG,EAAE,WAAW,KAAK,GAAG,CAAC;CAC7F,IAAI,IAAI,OAAO,KAAK,8DAA8D;CAClF,OAAO;EAAE,QAAQ,IAAI;EAAQ,KAAK,IAAI,OAAO,SAAS,MAAM;CAAE;AAChE;;AAGA,eAAsB,YAAe,GAAG,OAA6B;CACnE,MAAM,UAAU,cAAc,KAAK,QAAQ,IAAI,GAAG,cAAc,CAAC;CACjE,KAAK,MAAM,QAAQ,OACjB,IAAI;EACF,MAAM,SAAU,MAAM,OAAO,cAAc,QAAQ,QAAQ,IAAI,CAAC,CAAC,CAAC;EAGlE,MAAM,WAAW,OAAO;EACxB,OAAQ,OAAO,aAAa,YAAY,aAAa,OAAO;GAAE,GAAG;GAAU,GAAG;EAAO,IAAI;CAC3F,QAAQ,CAER;CAEF,OAAO,KAAK,SAAS,MAAM,KAAK,MAAM,EAAE,kCAAkC,MAAM,IAAI;AACtF"}
|
package/dist/shared/frame.js
CHANGED
|
@@ -24,6 +24,7 @@ async function run(ref, values) {
|
|
|
24
24
|
mkdirSync(out, { recursive: true });
|
|
25
25
|
const playwright = await fromProject("playwright-core", "playwright");
|
|
26
26
|
let browser;
|
|
27
|
+
const tried = [];
|
|
27
28
|
for (const channel of [
|
|
28
29
|
void 0,
|
|
29
30
|
"chrome",
|
|
@@ -31,8 +32,10 @@ async function run(ref, values) {
|
|
|
31
32
|
]) try {
|
|
32
33
|
browser = await playwright.chromium.launch(channel === void 0 ? {} : { channel });
|
|
33
34
|
break;
|
|
34
|
-
} catch {
|
|
35
|
-
|
|
35
|
+
} catch (e) {
|
|
36
|
+
tried.push(`${channel ?? "Playwright's Chromium"}: ${(e instanceof Error ? e.message : String(e)).split("\n", 1)[0]}`);
|
|
37
|
+
}
|
|
38
|
+
if (browser === void 0) fail(`No Chromium to launch (${tried.join("; ")}): npx playwright install chromium, or install Chrome or Edge.`);
|
|
36
39
|
try {
|
|
37
40
|
const view = await browser.newPage({ viewport: kept.viewport });
|
|
38
41
|
for (const t of times) {
|
package/dist/shared/frame.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"frame.js","names":[],"sources":["../../src/cli/frame.ts"],"sourcesContent":["/**\n * `deictic frame`: screenshots of a recording at moments of it, as its replay page shows them (marks and pointer\n * included), at the recorded viewport's size. By default: just after each change to the marks, and the end. Needs\n * the dev server running (it serves the replay) and Playwright in the project.\n */\nimport { mkdirSync } from 'node:fs';\nimport { tmpdir } from 'node:os';\nimport { join, resolve } from 'node:path';\n\nimport type { Browser, chromium } from 'playwright-core';\n\nimport { clock, fail } from './board.ts';\nimport { fromProject, loadRecording } from './find.ts';\n\ninterface Marks {\n type: number;\n timestamp: number;\n data: { tag?: string; payload?: { svg?: string } };\n}\n\nexport async function run(ref: string, values: { nth: string; at?: string[]; every?: string; out?: string; base?: string }): Promise<void> {\n const { kept, id, replay } = await loadRecording(ref, Number(values.nth));\n // The replay is served by the dev server that recorded it, under deictic's routes.\n const page =\n values.base === undefined\n ? (replay ?? `${new URL(kept.page).origin}/__deictic/plugins/recordings/replay/${id}`)\n : `${values.base.replace(/\\/$/, '')}/__deictic/plugins/recordings/replay/${id}`;\n\n const events = kept.events as Marks[];\n const t0 = events[0]?.timestamp ?? 0;\n const end = kept.duration / 1000;\n let times = (values.at ?? []).map(Number);\n if (values.every !== undefined) for (let t = 0; t <= end; t += Number(values.every)) times.push(t);\n if (times.length === 0) {\n // Just after each change to the marks, so it's drawn, then the end.\n const marks = events.filter((e) => e.type === 5 && e.data.tag === 'deictic.annotations' && (e.data.payload?.svg ?? '') !== '');\n times = [...marks.map((e) => (e.timestamp - t0 + 50) / 1000), end];\n }\n times = [...new Set(times.map((t) => Math.min(Math.max(0, t), end)))].sort((a, b) => a - b);\n if (times.some((t) => !Number.isFinite(t))) fail('--at and --every take seconds: --at 4.2');\n\n const out = resolve(values.out ?? join(tmpdir(), 'deictic-frames', id));\n mkdirSync(out, { recursive: true });\n\n const playwright = await fromProject<{ chromium: typeof chromium }>('playwright-core', 'playwright');\n let browser: Browser | undefined;\n for (const channel of [undefined, 'chrome', 'msedge']) {\n try {\n browser = await playwright.chromium.launch(channel === undefined ? {} : { channel });\n break;\n } catch {\n
|
|
1
|
+
{"version":3,"file":"frame.js","names":[],"sources":["../../src/cli/frame.ts"],"sourcesContent":["/**\n * `deictic frame`: screenshots of a recording at moments of it, as its replay page shows them (marks and pointer\n * included), at the recorded viewport's size. By default: just after each change to the marks, and the end. Needs\n * the dev server running (it serves the replay) and Playwright in the project.\n */\nimport { mkdirSync } from 'node:fs';\nimport { tmpdir } from 'node:os';\nimport { join, resolve } from 'node:path';\n\nimport type { Browser, chromium } from 'playwright-core';\n\nimport { clock, fail } from './board.ts';\nimport { fromProject, loadRecording } from './find.ts';\n\ninterface Marks {\n type: number;\n timestamp: number;\n data: { tag?: string; payload?: { svg?: string } };\n}\n\nexport async function run(ref: string, values: { nth: string; at?: string[]; every?: string; out?: string; base?: string }): Promise<void> {\n const { kept, id, replay } = await loadRecording(ref, Number(values.nth));\n // The replay is served by the dev server that recorded it, under deictic's routes.\n const page =\n values.base === undefined\n ? (replay ?? `${new URL(kept.page).origin}/__deictic/plugins/recordings/replay/${id}`)\n : `${values.base.replace(/\\/$/, '')}/__deictic/plugins/recordings/replay/${id}`;\n\n const events = kept.events as Marks[];\n const t0 = events[0]?.timestamp ?? 0;\n const end = kept.duration / 1000;\n let times = (values.at ?? []).map(Number);\n if (values.every !== undefined) for (let t = 0; t <= end; t += Number(values.every)) times.push(t);\n if (times.length === 0) {\n // Just after each change to the marks, so it's drawn, then the end.\n const marks = events.filter((e) => e.type === 5 && e.data.tag === 'deictic.annotations' && (e.data.payload?.svg ?? '') !== '');\n times = [...marks.map((e) => (e.timestamp - t0 + 50) / 1000), end];\n }\n times = [...new Set(times.map((t) => Math.min(Math.max(0, t), end)))].sort((a, b) => a - b);\n if (times.some((t) => !Number.isFinite(t))) fail('--at and --every take seconds: --at 4.2');\n\n const out = resolve(values.out ?? join(tmpdir(), 'deictic-frames', id));\n mkdirSync(out, { recursive: true });\n\n const playwright = await fromProject<{ chromium: typeof chromium }>('playwright-core', 'playwright');\n let browser: Browser | undefined;\n // Why each browser didn't launch, said where none did.\n const tried: string[] = [];\n for (const channel of [undefined, 'chrome', 'msedge']) {\n try {\n browser = await playwright.chromium.launch(channel === undefined ? {} : { channel });\n break;\n } catch (e) {\n tried.push(`${channel ?? \"Playwright's Chromium\"}: ${(e instanceof Error ? e.message : String(e)).split('\\n', 1)[0]}`);\n }\n }\n if (browser === undefined)\n fail(`No Chromium to launch (${tried.join('; ')}): npx playwright install chromium, or install Chrome or Edge.`);\n try {\n // `bare`: the replay alone, at the recorded size, so a window that size shows it 1:1.\n const view = await browser.newPage({ viewport: kept.viewport });\n for (const t of times) {\n const url = new URL(page);\n url.searchParams.set('t', t.toFixed(2));\n url.searchParams.set('bare', '');\n const res = await view.goto(url.href).catch((e: unknown) => (e instanceof Error ? e.message.split('\\n')[0] : String(e)));\n if (typeof res === 'string' || !res?.ok()) {\n const why = typeof res === 'string' ? res : String(res?.status());\n await browser.close();\n fail(`${url.href}: ${why}. Is the dev server running? Start it, or pass --base with its URL.`);\n }\n await view.waitForSelector('body[data-ready]', { timeout: 15_000 });\n // The replayed page's images and fonts.\n await view.waitForLoadState('networkidle').catch(() => {});\n await view.waitForTimeout(200);\n const path = join(out, `${String(Math.round(t * 1000)).padStart(6, '0')}.png`);\n await view.screenshot({ path });\n console.log(`${clock(t * 1000).padStart(6)} ${path}`);\n }\n } finally {\n await browser.close();\n }\n}\n"],"mappings":";;;;;;;;;;;AAoBA,eAAsB,IAAI,KAAa,QAAoG;CACzI,MAAM,EAAE,MAAM,IAAI,WAAW,MAAM,cAAc,KAAK,OAAO,OAAO,GAAG,CAAC;CAExE,MAAM,OACJ,OAAO,SAAS,KAAA,IACX,UAAU,GAAG,IAAI,IAAI,KAAK,IAAI,CAAC,CAAC,OAAO,uCAAuC,OAC/E,GAAG,OAAO,KAAK,QAAQ,OAAO,EAAE,EAAE,uCAAuC;CAE/E,MAAM,SAAS,KAAK;CACpB,MAAM,KAAK,OAAO,EAAE,EAAE,aAAa;CACnC,MAAM,MAAM,KAAK,WAAW;CAC5B,IAAI,SAAS,OAAO,MAAM,CAAC,EAAA,CAAG,IAAI,MAAM;CACxC,IAAI,OAAO,UAAU,KAAA,GAAW,KAAK,IAAI,IAAI,GAAG,KAAK,KAAK,KAAK,OAAO,OAAO,KAAK,GAAG,MAAM,KAAK,CAAC;CACjG,IAAI,MAAM,WAAW,GAGnB,QAAQ,CAAC,GADK,OAAO,QAAQ,MAAM,EAAE,SAAS,KAAK,EAAE,KAAK,QAAQ,0BAA0B,EAAE,KAAK,SAAS,OAAO,QAAQ,EAC3G,CAAC,CAAC,KAAK,OAAO,EAAE,YAAY,KAAK,MAAM,GAAI,GAAG,GAAG;CAEnE,QAAQ,CAAC,GAAG,IAAI,IAAI,MAAM,KAAK,MAAM,KAAK,IAAI,KAAK,IAAI,GAAG,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,GAAG,MAAM,IAAI,CAAC;CAC1F,IAAI,MAAM,MAAM,MAAM,CAAC,OAAO,SAAS,CAAC,CAAC,GAAG,KAAK,yCAAyC;CAE1F,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C;GAElE,MAAM,KAAK,iBAAiB,aAAa,CAAC,CAAC,YAAY,CAAC,CAAC;GACzD,MAAM,KAAK,eAAe,GAAG;GAC7B,MAAM,OAAO,KAAK,KAAK,GAAG,OAAO,KAAK,MAAM,IAAI,GAAI,CAAC,CAAC,CAAC,SAAS,GAAG,GAAG,EAAE,KAAK;GAC7E,MAAM,KAAK,WAAW,EAAE,KAAK,CAAC;GAC9B,QAAQ,IAAI,GAAG,MAAM,IAAI,GAAI,CAAC,CAAC,SAAS,CAAC,EAAE,IAAI,MAAM;EACvD;CACF,UAAU;EACR,MAAM,QAAQ,MAAM;CACtB;AACF"}
|
package/dist/shared/index.d.ts
CHANGED
|
@@ -63,6 +63,29 @@ interface Done<Record = unknown> {
|
|
|
63
63
|
done: Record;
|
|
64
64
|
}
|
|
65
65
|
type Maybe<T> = T | Promise<T>;
|
|
66
|
+
/**
|
|
67
|
+
* Something of deictic's that went wrong, which nothing a person did in the page caused: a package the project
|
|
68
|
+
* hasn't installed, a plugin that failed. The dev server says it, and hands it to each plugin with a `problem`
|
|
69
|
+
* (tasks posts it to the board, for an agent to fix).
|
|
70
|
+
*/
|
|
71
|
+
interface Problem {
|
|
72
|
+
/**
|
|
73
|
+
* What tells it apart, and the same problem again from a new one: `packages:rrweb`, `setup:tailwind`. Never a
|
|
74
|
+
* time or an ID, so a problem that comes back is known.
|
|
75
|
+
*/
|
|
76
|
+
key: string;
|
|
77
|
+
/**
|
|
78
|
+
* `setup`: the project's to fix, as `message` says (install a package, configure a plugin). `bug`: deictic's own, or
|
|
79
|
+
* a plugin's, to report where it's made, not to patch where it's installed.
|
|
80
|
+
*/
|
|
81
|
+
kind: 'setup' | 'bug';
|
|
82
|
+
/** What went wrong, and the fix where there is one, as any problem message says it. */
|
|
83
|
+
message: string;
|
|
84
|
+
/** What more there is to look into: a stack. */
|
|
85
|
+
details?: string;
|
|
86
|
+
/** The plugin it's about, where it's one's: none for deictic's own. */
|
|
87
|
+
plugin?: string;
|
|
88
|
+
}
|
|
66
89
|
/**
|
|
67
90
|
* Each plugin's API to the others on the server, by name. A plugin adds its own, so `use` knows its type:
|
|
68
91
|
* `declare module 'deictic' { interface ServerApis { screenshots: Screenshots } }`.
|
|
@@ -76,10 +99,12 @@ interface ServerContext {
|
|
|
76
99
|
/** The project's root, as an absolute path. */
|
|
77
100
|
root: string;
|
|
78
101
|
/**
|
|
79
|
-
* Another plugin's API, as its `setup` answered it, or nothing when it isn't loaded
|
|
80
|
-
* `needs` always is; any other may not be, so check.
|
|
102
|
+
* Another plugin's API, as its `setup` answered it, or nothing when it isn't loaded (or its `setup` failed,
|
|
103
|
+
* which is reported). One the plugin `needs` always is loaded; any other may not be, so check.
|
|
81
104
|
*/
|
|
82
105
|
use: <Name extends string>(name: Name) => ApiOf<ServerApis, Name> | undefined;
|
|
106
|
+
/** Says a problem of the plugin's own, as deictic says its own: in the dev server's output, and to each plugin's `problem`. */
|
|
107
|
+
report: (problem: Problem) => void;
|
|
83
108
|
}
|
|
84
109
|
/**
|
|
85
110
|
* A route of the plugin's own, at `/__deictic/plugins/<name>/<route>`, and below it. A `GET` must
|
|
@@ -125,6 +150,11 @@ interface ServerPlugin<Model = unknown, Op = unknown, Record = unknown, Api = un
|
|
|
125
150
|
redo?(record: Record): Maybe<Record>;
|
|
126
151
|
/** Says what an op does, for the history: `className: px-2 → px-4`. */
|
|
127
152
|
describe?(op: Op, before: Model): string;
|
|
153
|
+
/**
|
|
154
|
+
* Hears each problem deictic or a plugin reports, on the server or in the page, after every `setup` has run: once
|
|
155
|
+
* per `key` while the dev server runs. Its own failure is only said, never reported again.
|
|
156
|
+
*/
|
|
157
|
+
problem?(problem: Problem): Maybe<void>;
|
|
128
158
|
}
|
|
129
159
|
declare const definePlugin: <Model, Op, Record = unknown, Api = unknown>(plugin: ServerPlugin<Model, Op, Record, Api>) => ServerPlugin<Model, Op, Record, Api>;
|
|
130
160
|
/** Where something is in an element, in CSS pixels from its top left. */
|
|
@@ -224,6 +254,8 @@ interface ClientContext {
|
|
|
224
254
|
use: <Name extends string>(name: Name) => ApiOf<ClientApis, Name> | undefined;
|
|
225
255
|
/** Asks one of this plugin's own routes, from the page: `request('shots', { method: 'POST', body: blob })`. */
|
|
226
256
|
request: (route: string, init?: RequestInit) => Promise<Response>;
|
|
257
|
+
/** Says a problem of the plugin's own to the dev server, as the server half's `report` does: its `plugin` is this one. */
|
|
258
|
+
report: (problem: Problem) => void;
|
|
227
259
|
/**
|
|
228
260
|
* Opens the popup on an element at a plugin's tab, as its shortcut would, or with `at` on a spot in it: the
|
|
229
261
|
* popup is then beside the spot, which is what's lit, and the tab's context has it. An element rendered again
|
|
@@ -352,5 +384,5 @@ interface ClientPlugin<Model = unknown, Op = unknown, Api = unknown> {
|
|
|
352
384
|
mount?: (panel: HTMLElement, context: PanelContext<Model, Op>) => (() => void) | void;
|
|
353
385
|
}
|
|
354
386
|
declare const defineClientPlugin: <Model, Op, Api = unknown>(plugin: ClientPlugin<Model, Op, Api>) => ClientPlugin<Model, Op, Api>;
|
|
355
|
-
export {
|
|
387
|
+
export { Modifier as A, Target as C, TrayItem as D, Tray as E, defineClientPlugin as O, Standalone as S, ToolPanel as T, ServerApis as _, Done as a, Source as b, LightboxItem as c, PanelContext as d, Point as f, Route as g, Resumed as h, ClientPlugin as i, Shortcut as j, definePlugin as k, LightboxOptions as l, Refusal as m, ClientApis as n, Drawer as o, Problem as p, ClientContext as r, LightboxAction as s, ApiOf as t, Loc as u, ServerContext as v, TextEdit as w, Spot as x, ServerPlugin as y };
|
|
356
388
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/shortcut.ts","../../src/index.ts"],"mappings":";;;;;;;;;;KAUY;UAEK;;EAEf,YAAY;;EAEZ;;;UCYe;EACf;EACA;EACA;;;UAIe;EACf,KAAK;EACL;;;UAIe;EACf;EACA;EACA;EACA;;;UAIe;;EAEf;EACA;;EAEA,SAAS;;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;EAKA,OAAO,SAAS,gBAAgB;;;;;;EAMhC,QAAQ,SAAS,gBAAgB;;;;;EAKjC,UAAU,SAAS;;EAEnB,SAAS,OAAO,aAAa,SAAS,aAAa,OAAO;;cAG/C,qBAAsB,OAAO,IAAI,eAAa,QAAU,aAAa,OAAO,IAAI,SAAO,aAAa,OAAO,IAAI"}
|
package/dist/shared/index7.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Board } from "@vercel/board";
|
|
2
|
-
import {
|
|
2
|
+
import { C as Target, f as Point, j as Shortcut, p as Problem } from "./index.js";
|
|
3
3
|
import { t as Box } from "./index3.js";
|
|
4
4
|
interface LocalOptions {
|
|
5
5
|
/**
|
|
@@ -59,6 +59,12 @@ interface TasksOptions {
|
|
|
59
59
|
html?: boolean;
|
|
60
60
|
/** What opens its tab directly, beside deictic's own shortcut, which opens any: none by default. */
|
|
61
61
|
shortcut?: Shortcut;
|
|
62
|
+
/**
|
|
63
|
+
* Whether deictic's own problems become tasks, for whoever works the board to fix: a package the project hasn't
|
|
64
|
+
* installed, a plugin that failed, a request that broke. One task per problem while it's open (`deictic.problem`
|
|
65
|
+
* is its key), about the project, not an element. True by default.
|
|
66
|
+
*/
|
|
67
|
+
problems?: boolean;
|
|
62
68
|
}
|
|
63
69
|
interface Task {
|
|
64
70
|
id: string;
|
|
@@ -77,11 +83,21 @@ interface Task {
|
|
|
77
83
|
dropped?: string;
|
|
78
84
|
/** The spot in the element it's about, where it's about one: CSS pixels from the element's top left. */
|
|
79
85
|
point?: Point;
|
|
86
|
+
/** Which of the elements from its place it's about, where the page had more than one. */
|
|
87
|
+
which?: Which;
|
|
80
88
|
/**
|
|
81
89
|
* Where it was added, where that isn't the element's place: where the element was before it moved.
|
|
82
90
|
*/
|
|
83
91
|
at?: Place;
|
|
84
92
|
}
|
|
93
|
+
/**
|
|
94
|
+
* One of several elements from the same place in the source (a list's items): its place among them on the page, from 1,
|
|
95
|
+
* and its text where it has any, which still finds it once the list is in another order.
|
|
96
|
+
*/
|
|
97
|
+
interface Which {
|
|
98
|
+
nth: number;
|
|
99
|
+
text?: string;
|
|
100
|
+
}
|
|
85
101
|
/** A place in the element's file: a line and a column, from 1, and the tag there as the task saw it. */
|
|
86
102
|
interface Place {
|
|
87
103
|
line: number;
|
|
@@ -101,6 +117,8 @@ interface Listed extends Task {
|
|
|
101
117
|
last?: string;
|
|
102
118
|
/** What the board says of where it stands: why it's blocked, what it came to, why it failed. */
|
|
103
119
|
said?: string;
|
|
120
|
+
/** A problem of deictic's it tells of, not a person's ask: the project's setup to fix, or a bug of deictic's. */
|
|
121
|
+
problem?: Problem['kind'];
|
|
104
122
|
}
|
|
105
123
|
/** A task with a place, as its mark has it: what the page pins to the element there. */
|
|
106
124
|
type Placed = Listed & {
|
|
@@ -186,6 +204,8 @@ interface Op {
|
|
|
186
204
|
};
|
|
187
205
|
/** How many elements on the page come from the same place in the source. */
|
|
188
206
|
count: number;
|
|
207
|
+
/** Which of them it is, where there's more than one: what the page tells it from the others by. */
|
|
208
|
+
which?: Which;
|
|
189
209
|
/**
|
|
190
210
|
* The other elements it's about, after the one it's sent on, in the order they were attached: each one's place,
|
|
191
211
|
* its tag, and its HTML as it rendered, where that's attached.
|
|
@@ -299,5 +319,5 @@ interface Removed extends Added {
|
|
|
299
319
|
*/
|
|
300
320
|
type Kept = Added | Edited | Removed;
|
|
301
321
|
declare function tasks(options?: TasksOptions): import("deictic").ServerPlugin<Model, Op, Kept, unknown>;
|
|
302
|
-
export { local as S, TasksOptions as _, Kept as a,
|
|
322
|
+
export { local as C, LocalOptions as S, TasksOptions as _, Kept as a, tasks as b, Model as c, Placed as d, Removed as f, TaskBoard as g, TaskAdded as h, Edited as i, Op as l, Task as m, Answer as n, Listed as o, Reply as p, Attached as r, Marks as s, Added as t, Place as u, Thread as v, LocalBoard as x, Which as y };
|
|
303
323
|
//# sourceMappingURL=index7.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index7.d.ts","names":[],"sources":["../../src/plugins/tasks/local.ts","../../src/plugins/tasks/index.ts"],"mappings":";;;UAkBiB;;;;;EAKf;;EAEA;;EAEA;;EAEA;;;UAIe;EACf,OAAO;;;;;;cAOI,QAAK,UAAa,iBAAoB;;
|
|
1
|
+
{"version":3,"file":"index7.d.ts","names":[],"sources":["../../src/plugins/tasks/local.ts","../../src/plugins/tasks/index.ts"],"mappings":";;;UAkBiB;;;;;EAKf;;EAEA;;EAEA;;EAEA;;;UAIe;EACf,OAAO;;;;;;cAOI,QAAK,UAAa,iBAAoB;;KCAvC,YAAY,KAAK;UAEZ;;;;;;;;EAQf,QAAQ,YAAY;;EAEpB;;;;;EAKA;;EAEA,SAAS;;;;;;;EAOT,QAAQ,iBAAiB;;;;;;;EAOzB;;EAEA,WAAW;;;;;;EAMX;;UAGe;EACf;;EAEA;;EAEA;EACA;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA,QAAQ;;EAER,QAAQ;;;;EAIR,KAAK;;;;;;UAOU;EACf;EACA;;;UAIe;EACf;EACA;EACA;;;UAIe,eAAe;;EAE9B;;EAEA;;EAEA;;EAEA;EACA;;EAEA;;EAEA,UAAU;;;KAIA,SAAS;EAAW;;;UAGf;;EAEf;EACA;;EAEA;;EAEA;;;;;EAKA;;EAEA;;;UAIe;EACf;;EAEA;;EAEA;EACA;;EAEA;;EAEA,OAAO;;;UAIQ;EACf,MAAM;;EAEN,OAAO;EACP,SAAS;;;;;;KAOC,SAAS,KAAK;UAET;EACf;;EAEA;;EAEA,OAAO;;;;;;;EAOP;;;UAIe;EACf;;EAEA;EACA;IAAY;IAAe;;;;;;EAK3B,QAAQ;;;;;EAKR;IAAY;IAAc;;;EAE1B;;EAEA,QAAQ;;;;;EAKR;IAAS;IAAY;IAAa;;;;;;EAKlC;;;;;;;EAOA;;EAEA;;;;;;;EAOA;IAAgB;IAAY,MAAM;IAAK;IAAoB,QAAQ;;;;;;EAKnE;IAAe;IAAY;IAAkB;IAAgB;;;EAE7D;IAAU;IAAY;;;EAEtB,cAAc;;;;;;UAOC;EACf;;EAEA;EACA;EACA;;EAEA,QAAQ;;EAER;;EAEA;IAAY;IAAqB;IAAoB;IAAe;;;;;;EAKpE;;;UAIe;EACf;EACA;;UAGe;EACf;EACA;EACA;EACA,QAAQ;;EAER;;;UAIe;EACf;EACA;EACA;EACA;;;;;;UAOe,gBAAgB;EAC/B;;;;;;KAOU,OAAO,QAAQ,SAAS;iBA0BpB,MAAM,UAAS,iCAAiB,aAAA,OAAA,IAAA"}
|
package/dist/shared/index9.d.ts
CHANGED
|
@@ -149,6 +149,47 @@ function locateAstro(code, file, root) {
|
|
|
149
149
|
const parsed = parseAstro(root, code);
|
|
150
150
|
return "problem" in parsed ? void 0 : marked(code, file, parsed.elements);
|
|
151
151
|
}
|
|
152
|
+
// src/tools/problems.ts
|
|
153
|
+
/** How much of a problem is kept: its words, and its details (a stack is shorter). */
|
|
154
|
+
const WORDS = 2e3;
|
|
155
|
+
const DETAILS = 2e4;
|
|
156
|
+
/** What reports a problem: `ready` is when the plugins that hear of them are set up to. */
|
|
157
|
+
function reporter(plugins, ready) {
|
|
158
|
+
const said = /* @__PURE__ */ new Set();
|
|
159
|
+
return (problem) => {
|
|
160
|
+
if (said.has(problem.key)) return;
|
|
161
|
+
said.add(problem.key);
|
|
162
|
+
console.warn(`deictic${problem.plugin === void 0 ? "" : `/${problem.plugin}`}: ${problem.message}`);
|
|
163
|
+
const hearing = plugins.filter((p) => p.problem !== void 0);
|
|
164
|
+
if (hearing.length === 0) return;
|
|
165
|
+
const tell = async (plugin) => {
|
|
166
|
+
try {
|
|
167
|
+
await plugin.problem?.(problem);
|
|
168
|
+
} catch (e) {
|
|
169
|
+
console.warn(`deictic: ${plugin.name} couldn't take that problem, as ${messageOf(e)}`);
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
Promise.resolve().then(ready).then(() => Promise.all(hearing.map(tell)), () => {});
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
/** What went wrong, as a problem's words say it: an error's message. */
|
|
176
|
+
const messageOf = (e) => e instanceof Error ? e.message : String(e);
|
|
177
|
+
/** An error's stack, where it has one, for a problem's details. */
|
|
178
|
+
const stackOf = (e) => e instanceof Error && e.stack !== void 0 ? { details: e.stack } : {};
|
|
179
|
+
/** A problem as the page sent it, checked and cut short, or nothing where it isn't one. */
|
|
180
|
+
function problemIn(value) {
|
|
181
|
+
if (typeof value !== "object" || value === null) return void 0;
|
|
182
|
+
const { key, kind, message, details, plugin } = value;
|
|
183
|
+
if (typeof key !== "string" || key === "" || typeof message !== "string" || message === "") return void 0;
|
|
184
|
+
if (kind !== "setup" && kind !== "bug") return void 0;
|
|
185
|
+
return {
|
|
186
|
+
key: key.slice(0, WORDS),
|
|
187
|
+
kind,
|
|
188
|
+
message: message.slice(0, WORDS),
|
|
189
|
+
...typeof details === "string" && details !== "" ? { details: details.slice(0, DETAILS) } : {},
|
|
190
|
+
...typeof plugin === "string" && plugin !== "" ? { plugin: plugin.slice(0, 100) } : {}
|
|
191
|
+
};
|
|
192
|
+
}
|
|
152
193
|
// src/tools/plugins.ts
|
|
153
194
|
const NAME = /^[a-z][a-z0-9-]*$/;
|
|
154
195
|
/** Throws what to fix in a set of plugins: names, what they need, and their shortcuts, beside deictic's own. */
|
|
@@ -172,16 +213,29 @@ function checkPlugins(plugins, own) {
|
|
|
172
213
|
/**
|
|
173
214
|
* Runs every plugin's `setup`, all at once, and answers the context they share: `use` reads an API
|
|
174
215
|
* when it's asked for, so setups may `use` each other's only after they've all run, from a route or an
|
|
175
|
-
* op, never in `setup` itself.
|
|
216
|
+
* op, never in `setup` itself. One that fails is reported and has no API: the others go on, so one of them
|
|
217
|
+
* can tell of it (tasks, on the board).
|
|
176
218
|
*/
|
|
177
|
-
async function setUp(root, plugins) {
|
|
219
|
+
async function setUp(root, plugins, report) {
|
|
178
220
|
const apis = /* @__PURE__ */ new Map();
|
|
179
221
|
const context = {
|
|
180
222
|
root,
|
|
181
|
-
use: (name) => apis.get(name)
|
|
223
|
+
use: (name) => apis.get(name),
|
|
224
|
+
report
|
|
182
225
|
};
|
|
183
226
|
await Promise.all(plugins.map(async (p) => {
|
|
184
|
-
if (p.setup
|
|
227
|
+
if (p.setup === void 0) return;
|
|
228
|
+
try {
|
|
229
|
+
apis.set(p.name, await p.setup(context));
|
|
230
|
+
} catch (e) {
|
|
231
|
+
report({
|
|
232
|
+
key: `setup:${p.name}`,
|
|
233
|
+
kind: "bug",
|
|
234
|
+
plugin: p.name,
|
|
235
|
+
message: `${p.name} failed to set up, so it does nothing until the dev server restarts: ${messageOf(e)}`,
|
|
236
|
+
...stackOf(e)
|
|
237
|
+
});
|
|
238
|
+
}
|
|
185
239
|
}));
|
|
186
240
|
return context;
|
|
187
241
|
}
|
|
@@ -274,6 +328,6 @@ function fileIn(path, root) {
|
|
|
274
328
|
const file = relative(root, path).replaceAll("\\", "/");
|
|
275
329
|
return file.startsWith("..") || isAbsolute(file) ? void 0 : file;
|
|
276
330
|
}
|
|
277
|
-
export { markAstro as a, setUp as c,
|
|
331
|
+
export { lineStarts as _, markAstro as a, parse as b, setUp as c, reporter as d, stackOf as f, isHost as g, JSX as h, mark as i, messageOf as l, parseAstro as m, clientModule as n, prepare as o, ASTRO as p, importOf as r, writeClient as s, beside as t, problemIn as u, offsetOf as v, openingsIn as y };
|
|
278
332
|
|
|
279
333
|
//# sourceMappingURL=integration.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"integration.js","names":["OWN","OWN"],"sources":["../../src/tools/locate.ts","../../src/tools/astro.ts","../../src/tools/plugins.ts","../../src/tools/integration.ts"],"sourcesContent":["/**\n * Marks each host element in a JSX module with where its opening tag starts:\n * `<div data-deictic=\"src/App.tsx:12:5\">`. The page reads it back to know what was clicked.\n *\n * At build time and not from React's fibers at runtime: it works for any framework that compiles JSX,\n * for server components (which have no fiber in the browser), and it names the element's own tag\n * rather than the component that rendered it. Only host elements (`div`, `button`) are marked, since a\n * component may not pass the attribute on; a component's call site is reached from its elements.\n *\n * The transform must run on the source as written (`enforce: 'pre'` under Vite), so lines and columns\n * are the file's. It runs alike on the server and in the browser, so a hydrated page matches its HTML.\n */\nimport MagicString from 'magic-string';\nimport { type JSXOpeningElement, parseSync, type Program, Visitor } from 'oxc-parser';\n\nexport const ATTRIBUTE = 'data-deictic';\n/** Modules that may hold JSX: `.jsx` and `.tsx`, and plain `.js`, as many React projects write theirs. */\nexport const JSX = /\\.[cm]?(?:[jt]sx|js)$/;\n\n/** A module parsed, with JSX read in a `.js` file too, which the parser reads there only when told. */\nexport const parse = (file: string, code: string) => parseSync(file, code, /\\.[cm]?js$/.test(file) ? { lang: 'jsx' } : undefined);\n\nexport interface Located {\n code: string;\n map: ReturnType<MagicString['generateMap']>;\n}\n\n/** Whether an opening tag is a host element's, `<div>` or `<svg>`, not a component's or a namespaced one. */\nexport const isHost = (el: JSXOpeningElement) => el.name.type === 'JSXIdentifier' && /^[a-z]/.test(el.name.name);\n\n/**\n * `code` with every host element marked, `file` being its path from the project's root, and `append`\n * after it (the client's import, in the browser); nothing when there is nothing to mark, or the module\n * doesn't parse, which the framework's own transform reports better.\n */\nexport function locate(code: string, file: string, append = ''): Located | undefined {\n // No tag, no parse: most `.js` modules have none, and every one of the project's comes through here.\n if (!/<[a-z]/.test(code)) return undefined;\n const { program, errors } = parse(file, code);\n if (errors.length > 0) return undefined;\n return marked(code, file, openingsIn(program), append);\n}\n\n/** Every opening tag in a module, in its order. */\nexport function openingsIn(program: Program): JSXOpeningElement[] {\n const elements: JSXOpeningElement[] = [];\n new Visitor({ JSXOpeningElement: (el) => void elements.push(el) }).visit(program);\n return elements;\n}\n\n/**\n * `code` with a mark in each of `elements` that is a host element's and has none yet, and `append` after\n * it; nothing with none to mark.\n */\nexport function marked(code: string, file: string, elements: JSXOpeningElement[], append = ''): Located | undefined {\n const lines = lineStarts(code);\n const s = new MagicString(code);\n for (const el of elements) {\n if (!isHost(el) || el.attributes.some((a) => a.type === 'JSXAttribute' && nameOf(a.name) === ATTRIBUTE)) continue;\n const { line, column } = position(lines, el.start);\n s.appendLeft(el.name.end, ` ${ATTRIBUTE}=\"${file}:${line}:${column}\"`);\n }\n if (!s.hasChanged()) return undefined;\n if (append !== '') s.append(append);\n // A map's source is read from the module's own folder, so it's the file's name, not its path from the root.\n return { code: s.toString(), map: s.generateMap({ source: file.slice(file.lastIndexOf('/') + 1), hires: 'boundary' }) };\n}\n\nconst nameOf = (name: { type: string; name?: unknown }) => (name.type === 'JSXIdentifier' ? name.name : undefined);\n\n/** Where each line starts, by offset. */\nexport function lineStarts(code: string): number[] {\n const starts = [0];\n for (let i = code.indexOf('\\n'); i !== -1; i = code.indexOf('\\n', i + 1)) starts.push(i + 1);\n return starts;\n}\n\n/** An offset's line and column, from 1. */\nexport function position(lines: number[], offset: number): { line: number; column: number } {\n let lo = 0;\n let hi = lines.length - 1;\n while (lo < hi) {\n const mid = (lo + hi + 1) >> 1;\n if (lines[mid]! <= offset) lo = mid;\n else hi = mid - 1;\n }\n return { line: lo + 1, column: offset - lines[lo]! + 1 };\n}\n\n/** A line and column's offset, or nothing past the file's end. */\nexport function offsetOf(lines: number[], line: number, column: number): number | undefined {\n const start = lines[line - 1];\n return start === undefined ? undefined : start + column - 1;\n}\n","/**\n * `.astro` components. They aren't JSX modules, but Astro 7's own parser reads a template as JSX, into the\n * tree oxc makes (offsets in UTF-16, as ours are), so its host elements are marked as a JSX module's are,\n * before Astro compiles the file. The parser is the project's own Astro's (`@astrojs/compiler-rs`, found\n * through `astro`), so it reads a file exactly as the compiler will; an Astro before 7 has none like it,\n * and its `.astro` files are left unmarked.\n */\nimport { createRequire } from 'node:module';\nimport { join } from 'node:path';\n\nimport type { JSXOpeningElement, Program } from 'oxc-parser';\n\nimport { type Located, marked } from './locate.ts';\n\nexport const ASTRO = /\\.astro$/;\n\n/** A file parsed: its module (an `.astro` file's frontmatter), and each opening tag in it, in the file's order. */\nexport interface Parsed {\n program: Program;\n elements: JSXOpeningElement[];\n}\n\ninterface Tree {\n ast: { frontmatter: { program: Program }; body: unknown };\n diagnostics: { severity: string; text: string }[];\n}\ntype Parse = (code: string) => Tree;\n\nconst parsers = new Map<string, Parse | undefined>();\n\n/** The parser of the Astro installed for the project at `root`, loaded once; nothing without Astro 7. */\nfunction parserOf(root: string): Parse | undefined {\n if (!parsers.has(root)) parsers.set(root, load(root));\n return parsers.get(root);\n}\n\nfunction load(root: string): Parse | undefined {\n try {\n // Astro's own dependency, which a strict package manager doesn't put where the project could import it.\n const astro = createRequire(createRequire(join(root, 'package.json')).resolve('astro/package.json'));\n // An ES module, required: every Node that runs Astro 7 can, and reading a source stays synchronous.\n const compiler: { parse?: Parse } = astro('@astrojs/compiler-rs');\n return compiler.parse;\n } catch {\n return undefined;\n }\n}\n\n/**\n * Astro gives a `<script>` or `<style>` with an attribute it doesn't know to the page as it is, unbundled and\n * unscoped, and a `<slot>` isn't an element at all: none of them can be pointed at, so none is marked.\n */\nconst OWN = new Set(['script', 'style', 'slot']);\n\nconst isOpening = (node: object): node is JSXOpeningElement => 'type' in node && node.type === 'JSXOpeningElement';\n\n/** An `.astro` file's text parsed, or the `problem` with it: no parser (an older Astro), or text that doesn't parse. */\nexport function parseAstro(root: string, code: string): Parsed | { problem: string } {\n const parse = parserOf(root);\n if (parse === undefined) return { problem: 'reading an .astro file takes Astro 7 or later, so update astro' };\n const { ast, diagnostics } = parse(code);\n const error = diagnostics.find((d) => d.severity === 'error');\n if (error !== undefined) return { problem: `fix it first (${error.text})` };\n const elements: JSXOpeningElement[] = [];\n const walk = (node: unknown): void => {\n if (Array.isArray(node)) return node.forEach(walk);\n if (node === null || typeof node !== 'object') return;\n if (isOpening(node) && !(node.name.type === 'JSXIdentifier' && OWN.has(node.name.name))) elements.push(node);\n Object.values(node).forEach(walk);\n };\n walk(ast.body);\n return { program: ast.frontmatter.program, elements };\n}\n\n/** An `.astro` file's text with every host element marked, as `locate` marks a JSX module; nothing where it can't be read. */\nexport function locateAstro(code: string, file: string, root: string): Located | undefined {\n // No tag, no parse.\n if (!/<[a-z]/.test(code)) return undefined;\n const parsed = parseAstro(root, code);\n return 'problem' in parsed ? undefined : marked(code, file, parsed.elements);\n}\n","/**\n * The plugins an integration was given: checked as it starts, so a wrong set fails the dev server with\n * what to write instead, and set up once before the endpoints answer anything.\n */\nimport type { ServerContext, ServerPlugin } from '#src/index.ts';\nimport { checkShortcuts, OWN, ownShortcut, type Shortcut } from '#src/shortcut.ts';\n\nconst NAME = /^[a-z][a-z0-9-]*$/;\n\n/** Throws what to fix in a set of plugins: names, what they need, and their shortcuts, beside deictic's own. */\nexport function checkPlugins(plugins: readonly ServerPlugin[], own?: Shortcut | false): void {\n const names = new Set<string>();\n for (const { name, client, shortcut } of plugins) {\n if (!NAME.test(name)) throw new Error(`deictic: a plugin is named \"${name}\": name it in lowercase letters, digits and -`);\n if (names.has(name)) throw new Error(`deictic: two plugins are named ${name}: load each once`);\n if (shortcut !== undefined && client === undefined)\n throw new Error(`deictic: ${name} has a shortcut but no \\`client\\` to draw its panel: give it one, or leave out its shortcut`);\n names.add(name);\n }\n for (const { name, needs = [] } of plugins) {\n const missing = needs.find((other) => !names.has(other));\n if (missing !== undefined) throw new Error(`deictic: ${name} needs the ${missing} plugin: add it to \\`plugins\\``);\n }\n checkShortcuts([{ name: OWN, shortcut: ownShortcut(own) }, ...plugins]);\n}\n\n/**\n * Runs every plugin's `setup`, all at once, and answers the context they share: `use` reads an API\n * when it's asked for, so setups may `use` each other's only after they've all run, from a route or an\n * op, never in `setup` itself.\n */\nexport async function setUp(root: string, plugins: readonly ServerPlugin[]): Promise<ServerContext> {\n const apis = new Map<string, unknown>();\n const context: ServerContext = { root, use: (name) => apis.get(name) as never };\n await Promise.all(\n plugins.map(async (p) => {\n if (p.setup !== undefined) apis.set(p.name, await p.setup(context));\n }),\n );\n return context;\n}\n","/**\n * What every bundler's integration shares: the options, the client module that starts the overlay, and\n * the transform that marks a JSX module. Each integration adds what its bundler does its own way: how a\n * module is transformed (a hook, a loader, `onLoad`), how the page loads the client (a virtual module\n * under Vite, a file in `.deictic/` elsewhere, as webpack, Turbopack and Bun have none), where the\n * endpoints are served, and what opens the editor.\n */\nimport { existsSync, readFileSync, writeFileSync } from 'node:fs';\nimport { dirname, isAbsolute, relative } from 'node:path';\nimport { fileURLToPath } from 'node:url';\n\nimport type { ServerPlugin } from '#src/index.ts';\nimport { checkShortcuts, OWN, ownShortcut, type Shortcut } from '#src/shortcut.ts';\n\nimport { ASTRO, locateAstro } from './astro.ts';\nimport { keptIn } from './kept.ts';\nimport { JSX, locate, type Located } from './locate.ts';\nimport { checkPlugins } from './plugins.ts';\n\nexport interface DeicticOptions {\n /** The plugins to load, server halves: `tailwind()`, `tasks()`, your own. None by default. */\n plugins?: ServerPlugin[];\n /**\n * What opens the popup on any plugin, at the tab used last: Alt and the left button by default, or\n * `false` for none, leaving only plugins' own shortcuts.\n */\n shortcut?: Shortcut | false;\n}\n\n/** The options with their defaults, checked now, so a wrong set stops the dev server as it starts, not the page. */\nexport function prepare(options: DeicticOptions): { plugins: ServerPlugin[]; shortcut: Shortcut | false | undefined } {\n const plugins = options.plugins ?? [];\n checkPlugins(plugins, options.shortcut);\n return { plugins, shortcut: options.shortcut };\n}\n\n/**\n * The client module: the overlay, started with deictic's own shortcut and each plugin that has a half\n * in the page, with its shortcut, checked; and with `server`, a module of the page's that answers its requests\n * where no dev server does.\n */\nexport const clientModule = (plugins: ServerPlugin[], base: string, own?: Shortcut | false, server?: string) => {\n const [shortcut, ...shortcuts] = checkShortcuts([{ name: OWN, shortcut: ownShortcut(own) }, ...plugins]);\n const paged = plugins.flatMap((p, i) =>\n p.client === undefined ? [] : [{ client: p.client, rest: { shortcut: shortcuts[i], options: p.clientOptions } }],\n );\n return [\n `import { start } from 'deictic/client';`,\n ...paged.map((p, i) => `import p${i} from ${JSON.stringify(p.client)};`),\n ...(server === undefined ? [] : [`import server from ${JSON.stringify(server)};`]),\n // Its shortcut and options as JSON, where it has them: `JSON.stringify` leaves out what's undefined.\n `start({ base: ${JSON.stringify(base)}, shortcut: ${JSON.stringify(shortcut) ?? 'undefined'}, plugins: [${paged.map((p, i) => `{ plugin: p${i}, ...${JSON.stringify(p.rest)} }`).join(', ')}]${server === undefined ? '' : ', server'} });`,\n ].join('\\n');\n};\n\n/**\n * Writes the client module to `.deictic/client.js` for a bundler without virtual modules, and answers\n * its path. Its imports are bare (`deictic/client`, each plugin's), found from the project as its own\n * are. Written only when it changed, so a watching bundler doesn't rebuild for nothing.\n */\nexport function writeClient(root: string, plugins: ServerPlugin[], base: string, own?: Shortcut | false): string {\n const code = `// Written by deictic as the dev server starts: it starts the overlay in the page.\\n${clientModule(plugins, base, own)}\\n`;\n // Its own package: an ES module that runs for its effect. An app whose package.json says\n // `\"sideEffects\": false` would otherwise have webpack drop the import, which is only for its effect.\n const manifest = `${JSON.stringify({ private: true, type: 'module', sideEffects: true }, null, 2)}\\n`;\n writeIfChanged(keptIn(root, 'package.json'), manifest);\n return writeIfChanged(keptIn(root, 'client.js'), code);\n}\n\nfunction writeIfChanged(path: string, text: string): string {\n if (!existsSync(path) || readFileSync(path, 'utf8') !== text) writeFileSync(path, text);\n return path;\n}\n\n/** A module beside `url`, by its name: `.ts` from the source, `.js` from `dist`, as `url` is. */\nexport const beside = (url: string, name: string) =>\n fileURLToPath(new URL(`./${name}${url.endsWith('.ts') ? '.ts' : '.js'}`, url)).replaceAll('\\\\', '/');\n\n/**\n * The import of the written client module in the module at `from`, by a relative path with forward\n * slashes: Turbopack can't import a Windows path, and every bundler takes a relative one.\n */\nexport function importOf(path: string, from: string): string {\n const to = relative(dirname(from), path).replaceAll('\\\\', '/');\n return `\\nimport ${JSON.stringify(to.startsWith('.') ? to : `./${to}`)};\\n`;\n}\n\n/**\n * A module marked, by its absolute path: its host elements, and `append` after it (the client's import,\n * in the browser). Nothing for a file that isn't JSX, is a dependency's, or is outside the project.\n */\nexport function mark(code: string, path: string, root: string, append = ''): Located | undefined {\n const file = JSX.test(path) ? fileIn(path, root) : undefined;\n return file === undefined ? undefined : locate(code, file, append);\n}\n\n/** An `.astro` component marked, by its absolute path, as `mark` does a module. It's no module of the browser's, so nothing is appended. */\nexport function markAstro(code: string, path: string, root: string): Located | undefined {\n const file = ASTRO.test(path) ? fileIn(path, root) : undefined;\n return file === undefined ? undefined : locateAstro(code, file, root);\n}\n\n/** A project file's path from the root, as a mark has it; nothing for a dependency's or one outside the project. */\nfunction fileIn(path: string, root: string): string | undefined {\n if (/[\\\\/]node_modules[\\\\/]/.test(path) || !isAbsolute(path)) return undefined;\n const file = relative(root, path).replaceAll('\\\\', '/');\n return file.startsWith('..') || isAbsolute(file) ? undefined : file;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAeA,MAAa,YAAY;;AAEzB,MAAa,MAAM;;AAGnB,MAAa,SAAS,MAAc,SAAiB,UAAU,MAAM,MAAM,aAAa,KAAK,IAAI,IAAI,EAAE,MAAM,MAAM,IAAI,KAAA,CAAS;;AAQhI,MAAa,UAAU,OAA0B,GAAG,KAAK,SAAS,mBAAmB,SAAS,KAAK,GAAG,KAAK,IAAI;;;;;;AAO/G,SAAgB,OAAO,MAAc,MAAc,SAAS,IAAyB;CAEnF,IAAI,CAAC,SAAS,KAAK,IAAI,GAAG,OAAO,KAAA;CACjC,MAAM,EAAE,SAAS,WAAW,MAAM,MAAM,IAAI;CAC5C,IAAI,OAAO,SAAS,GAAG,OAAO,KAAA;CAC9B,OAAO,OAAO,MAAM,MAAM,WAAW,OAAO,GAAG,MAAM;AACvD;;AAGA,SAAgB,WAAW,SAAuC;CAChE,MAAM,WAAgC,CAAC;CACvC,IAAI,QAAQ,EAAE,oBAAoB,OAAO,KAAK,SAAS,KAAK,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,OAAO;CAChF,OAAO;AACT;;;;;AAMA,SAAgB,OAAO,MAAc,MAAc,UAA+B,SAAS,IAAyB;CAClH,MAAM,QAAQ,WAAW,IAAI;CAC7B,MAAM,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src/tools/astro.ts","../../src/tools/problems.ts","../../src/tools/plugins.ts","../../src/tools/integration.ts"],"sourcesContent":["/**\n * Marks each host element in a JSX module with where its opening tag starts:\n * `<div data-deictic=\"src/App.tsx:12:5\">`. The page reads it back to know what was clicked.\n *\n * At build time and not from React's fibers at runtime: it works for any framework that compiles JSX,\n * for server components (which have no fiber in the browser), and it names the element's own tag\n * rather than the component that rendered it. Only host elements (`div`, `button`) are marked, since a\n * component may not pass the attribute on; a component's call site is reached from its elements.\n *\n * The transform must run on the source as written (`enforce: 'pre'` under Vite), so lines and columns\n * are the file's. It runs alike on the server and in the browser, so a hydrated page matches its HTML.\n */\nimport MagicString from 'magic-string';\nimport { type JSXOpeningElement, parseSync, type Program, Visitor } from 'oxc-parser';\n\nexport const ATTRIBUTE = 'data-deictic';\n/** Modules that may hold JSX: `.jsx` and `.tsx`, and plain `.js`, as many React projects write theirs. */\nexport const JSX = /\\.[cm]?(?:[jt]sx|js)$/;\n\n/** A module parsed, with JSX read in a `.js` file too, which the parser reads there only when told. */\nexport const parse = (file: string, code: string) => parseSync(file, code, /\\.[cm]?js$/.test(file) ? { lang: 'jsx' } : undefined);\n\nexport interface Located {\n code: string;\n map: ReturnType<MagicString['generateMap']>;\n}\n\n/** Whether an opening tag is a host element's, `<div>` or `<svg>`, not a component's or a namespaced one. */\nexport const isHost = (el: JSXOpeningElement) => el.name.type === 'JSXIdentifier' && /^[a-z]/.test(el.name.name);\n\n/**\n * `code` with every host element marked, `file` being its path from the project's root, and `append`\n * after it (the client's import, in the browser); nothing when there is nothing to mark, or the module\n * doesn't parse, which the framework's own transform reports better.\n */\nexport function locate(code: string, file: string, append = ''): Located | undefined {\n // No tag, no parse: most `.js` modules have none, and every one of the project's comes through here.\n if (!/<[a-z]/.test(code)) return undefined;\n const { program, errors } = parse(file, code);\n if (errors.length > 0) return undefined;\n return marked(code, file, openingsIn(program), append);\n}\n\n/** Every opening tag in a module, in its order. */\nexport function openingsIn(program: Program): JSXOpeningElement[] {\n const elements: JSXOpeningElement[] = [];\n new Visitor({ JSXOpeningElement: (el) => void elements.push(el) }).visit(program);\n return elements;\n}\n\n/**\n * `code` with a mark in each of `elements` that is a host element's and has none yet, and `append` after\n * it; nothing with none to mark.\n */\nexport function marked(code: string, file: string, elements: JSXOpeningElement[], append = ''): Located | undefined {\n const lines = lineStarts(code);\n const s = new MagicString(code);\n for (const el of elements) {\n if (!isHost(el) || el.attributes.some((a) => a.type === 'JSXAttribute' && nameOf(a.name) === ATTRIBUTE)) continue;\n const { line, column } = position(lines, el.start);\n s.appendLeft(el.name.end, ` ${ATTRIBUTE}=\"${file}:${line}:${column}\"`);\n }\n if (!s.hasChanged()) return undefined;\n if (append !== '') s.append(append);\n // A map's source is read from the module's own folder, so it's the file's name, not its path from the root.\n return { code: s.toString(), map: s.generateMap({ source: file.slice(file.lastIndexOf('/') + 1), hires: 'boundary' }) };\n}\n\nconst nameOf = (name: { type: string; name?: unknown }) => (name.type === 'JSXIdentifier' ? name.name : undefined);\n\n/** Where each line starts, by offset. */\nexport function lineStarts(code: string): number[] {\n const starts = [0];\n for (let i = code.indexOf('\\n'); i !== -1; i = code.indexOf('\\n', i + 1)) starts.push(i + 1);\n return starts;\n}\n\n/** An offset's line and column, from 1. */\nexport function position(lines: number[], offset: number): { line: number; column: number } {\n let lo = 0;\n let hi = lines.length - 1;\n while (lo < hi) {\n const mid = (lo + hi + 1) >> 1;\n if (lines[mid]! <= offset) lo = mid;\n else hi = mid - 1;\n }\n return { line: lo + 1, column: offset - lines[lo]! + 1 };\n}\n\n/** A line and column's offset, or nothing past the file's end. */\nexport function offsetOf(lines: number[], line: number, column: number): number | undefined {\n const start = lines[line - 1];\n return start === undefined ? undefined : start + column - 1;\n}\n","/**\n * `.astro` components. They aren't JSX modules, but Astro 7's own parser reads a template as JSX, into the\n * tree oxc makes (offsets in UTF-16, as ours are), so its host elements are marked as a JSX module's are,\n * before Astro compiles the file. The parser is the project's own Astro's (`@astrojs/compiler-rs`, found\n * through `astro`), so it reads a file exactly as the compiler will; an Astro before 7 has none like it,\n * and its `.astro` files are left unmarked.\n */\nimport { createRequire } from 'node:module';\nimport { join } from 'node:path';\n\nimport type { JSXOpeningElement, Program } from 'oxc-parser';\n\nimport { type Located, marked } from './locate.ts';\n\nexport const ASTRO = /\\.astro$/;\n\n/** A file parsed: its module (an `.astro` file's frontmatter), and each opening tag in it, in the file's order. */\nexport interface Parsed {\n program: Program;\n elements: JSXOpeningElement[];\n}\n\ninterface Tree {\n ast: { frontmatter: { program: Program }; body: unknown };\n diagnostics: { severity: string; text: string }[];\n}\ntype Parse = (code: string) => Tree;\n\nconst parsers = new Map<string, Parse | undefined>();\n\n/** The parser of the Astro installed for the project at `root`, loaded once; nothing without Astro 7. */\nfunction parserOf(root: string): Parse | undefined {\n if (!parsers.has(root)) parsers.set(root, load(root));\n return parsers.get(root);\n}\n\nfunction load(root: string): Parse | undefined {\n try {\n // Astro's own dependency, which a strict package manager doesn't put where the project could import it.\n const astro = createRequire(createRequire(join(root, 'package.json')).resolve('astro/package.json'));\n // An ES module, required: every Node that runs Astro 7 can, and reading a source stays synchronous.\n const compiler: { parse?: Parse } = astro('@astrojs/compiler-rs');\n return compiler.parse;\n } catch {\n return undefined;\n }\n}\n\n/**\n * Astro gives a `<script>` or `<style>` with an attribute it doesn't know to the page as it is, unbundled and\n * unscoped, and a `<slot>` isn't an element at all: none of them can be pointed at, so none is marked.\n */\nconst OWN = new Set(['script', 'style', 'slot']);\n\nconst isOpening = (node: object): node is JSXOpeningElement => 'type' in node && node.type === 'JSXOpeningElement';\n\n/** An `.astro` file's text parsed, or the `problem` with it: no parser (an older Astro), or text that doesn't parse. */\nexport function parseAstro(root: string, code: string): Parsed | { problem: string } {\n const parse = parserOf(root);\n if (parse === undefined) return { problem: 'reading an .astro file takes Astro 7 or later, so update astro' };\n const { ast, diagnostics } = parse(code);\n const error = diagnostics.find((d) => d.severity === 'error');\n if (error !== undefined) return { problem: `fix it first (${error.text})` };\n const elements: JSXOpeningElement[] = [];\n const walk = (node: unknown): void => {\n if (Array.isArray(node)) return node.forEach(walk);\n if (node === null || typeof node !== 'object') return;\n if (isOpening(node) && !(node.name.type === 'JSXIdentifier' && OWN.has(node.name.name))) elements.push(node);\n Object.values(node).forEach(walk);\n };\n walk(ast.body);\n return { program: ast.frontmatter.program, elements };\n}\n\n/** An `.astro` file's text with every host element marked, as `locate` marks a JSX module; nothing where it can't be read. */\nexport function locateAstro(code: string, file: string, root: string): Located | undefined {\n // No tag, no parse.\n if (!/<[a-z]/.test(code)) return undefined;\n const parsed = parseAstro(root, code);\n return 'problem' in parsed ? undefined : marked(code, file, parsed.elements);\n}\n","/**\n * deictic's problems on the server, and those the page sends (`/__deictic/problem`): each said once in the dev server's\n * output, and handed to every plugin with a `problem` once they're all set up, which the tasks plugin posts to the\n * board. Once per key while the dev server runs: a request that fails on every try is still one problem.\n */\nimport type { Problem, ServerPlugin } from '#src/index.ts';\n\n/** How much of a problem is kept: its words, and its details (a stack is shorter). */\nconst WORDS = 2000;\nconst DETAILS = 20_000;\n\nexport type Report = (problem: Problem) => void;\n\n/** What reports a problem: `ready` is when the plugins that hear of them are set up to. */\nexport function reporter(plugins: readonly ServerPlugin[], ready: () => Promise<unknown>): Report {\n const said = new Set<string>();\n return (problem) => {\n if (said.has(problem.key)) return;\n said.add(problem.key);\n console.warn(`deictic${problem.plugin === undefined ? '' : `/${problem.plugin}`}: ${problem.message}`);\n const hearing = plugins.filter((p) => p.problem !== undefined);\n if (hearing.length === 0) return;\n // Its own failure is said, not reported: a board that can't be reached would report itself for ever.\n const tell = async (plugin: ServerPlugin) => {\n try {\n await plugin.problem?.(problem);\n } catch (e) {\n console.warn(`deictic: ${plugin.name} couldn't take that problem, as ${messageOf(e)}`);\n }\n };\n // Later, never now: a setup that fails at once reports before what it's part of is ready to be waited for.\n void Promise.resolve()\n .then(ready)\n .then(\n () => Promise.all(hearing.map(tell)),\n () => {},\n );\n };\n}\n\n/** What went wrong, as a problem's words say it: an error's message. */\nexport const messageOf = (e: unknown) => (e instanceof Error ? e.message : String(e));\n\n/** An error's stack, where it has one, for a problem's details. */\nexport const stackOf = (e: unknown) => (e instanceof Error && e.stack !== undefined ? { details: e.stack } : {});\n\n/** A problem as the page sent it, checked and cut short, or nothing where it isn't one. */\nexport function problemIn(value: unknown): Problem | undefined {\n if (typeof value !== 'object' || value === null) return undefined;\n const { key, kind, message, details, plugin } = value as Record<string, unknown>;\n if (typeof key !== 'string' || key === '' || typeof message !== 'string' || message === '') return undefined;\n if (kind !== 'setup' && kind !== 'bug') return undefined;\n return {\n key: key.slice(0, WORDS),\n kind,\n message: message.slice(0, WORDS),\n ...(typeof details === 'string' && details !== '' ? { details: details.slice(0, DETAILS) } : {}),\n ...(typeof plugin === 'string' && plugin !== '' ? { plugin: plugin.slice(0, 100) } : {}),\n };\n}\n","/**\n * The plugins an integration was given: checked as it starts, so a wrong set fails the dev server with\n * what to write instead, and set up once before the endpoints answer anything.\n */\nimport type { ServerContext, ServerPlugin } from '#src/index.ts';\nimport { checkShortcuts, OWN, ownShortcut, type Shortcut } from '#src/shortcut.ts';\n\nimport { messageOf, type Report, stackOf } from './problems.ts';\n\nconst NAME = /^[a-z][a-z0-9-]*$/;\n\n/** Throws what to fix in a set of plugins: names, what they need, and their shortcuts, beside deictic's own. */\nexport function checkPlugins(plugins: readonly ServerPlugin[], own?: Shortcut | false): void {\n const names = new Set<string>();\n for (const { name, client, shortcut } of plugins) {\n if (!NAME.test(name)) throw new Error(`deictic: a plugin is named \"${name}\": name it in lowercase letters, digits and -`);\n if (names.has(name)) throw new Error(`deictic: two plugins are named ${name}: load each once`);\n if (shortcut !== undefined && client === undefined)\n throw new Error(`deictic: ${name} has a shortcut but no \\`client\\` to draw its panel: give it one, or leave out its shortcut`);\n names.add(name);\n }\n for (const { name, needs = [] } of plugins) {\n const missing = needs.find((other) => !names.has(other));\n if (missing !== undefined) throw new Error(`deictic: ${name} needs the ${missing} plugin: add it to \\`plugins\\``);\n }\n checkShortcuts([{ name: OWN, shortcut: ownShortcut(own) }, ...plugins]);\n}\n\n/**\n * Runs every plugin's `setup`, all at once, and answers the context they share: `use` reads an API\n * when it's asked for, so setups may `use` each other's only after they've all run, from a route or an\n * op, never in `setup` itself. One that fails is reported and has no API: the others go on, so one of them\n * can tell of it (tasks, on the board).\n */\nexport async function setUp(root: string, plugins: readonly ServerPlugin[], report: Report): Promise<ServerContext> {\n const apis = new Map<string, unknown>();\n const context: ServerContext = { root, use: (name) => apis.get(name) as never, report };\n await Promise.all(\n plugins.map(async (p) => {\n if (p.setup === undefined) return;\n try {\n apis.set(p.name, await p.setup(context));\n } catch (e) {\n report({\n key: `setup:${p.name}`,\n kind: 'bug',\n plugin: p.name,\n message: `${p.name} failed to set up, so it does nothing until the dev server restarts: ${messageOf(e)}`,\n ...stackOf(e),\n });\n }\n }),\n );\n return context;\n}\n","/**\n * What every bundler's integration shares: the options, the client module that starts the overlay, and\n * the transform that marks a JSX module. Each integration adds what its bundler does its own way: how a\n * module is transformed (a hook, a loader, `onLoad`), how the page loads the client (a virtual module\n * under Vite, a file in `.deictic/` elsewhere, as webpack, Turbopack and Bun have none), where the\n * endpoints are served, and what opens the editor.\n */\nimport { existsSync, readFileSync, writeFileSync } from 'node:fs';\nimport { dirname, isAbsolute, relative } from 'node:path';\nimport { fileURLToPath } from 'node:url';\n\nimport type { ServerPlugin } from '#src/index.ts';\nimport { checkShortcuts, OWN, ownShortcut, type Shortcut } from '#src/shortcut.ts';\n\nimport { ASTRO, locateAstro } from './astro.ts';\nimport { keptIn } from './kept.ts';\nimport { JSX, locate, type Located } from './locate.ts';\nimport { checkPlugins } from './plugins.ts';\n\nexport interface DeicticOptions {\n /** The plugins to load, server halves: `tailwind()`, `tasks()`, your own. None by default. */\n plugins?: ServerPlugin[];\n /**\n * What opens the popup on any plugin, at the tab used last: Alt and the left button by default, or\n * `false` for none, leaving only plugins' own shortcuts.\n */\n shortcut?: Shortcut | false;\n}\n\n/** The options with their defaults, checked now, so a wrong set stops the dev server as it starts, not the page. */\nexport function prepare(options: DeicticOptions): { plugins: ServerPlugin[]; shortcut: Shortcut | false | undefined } {\n const plugins = options.plugins ?? [];\n checkPlugins(plugins, options.shortcut);\n return { plugins, shortcut: options.shortcut };\n}\n\n/**\n * The client module: the overlay, started with deictic's own shortcut and each plugin that has a half\n * in the page, with its shortcut, checked; and with `server`, a module of the page's that answers its requests\n * where no dev server does.\n */\nexport const clientModule = (plugins: ServerPlugin[], base: string, own?: Shortcut | false, server?: string) => {\n const [shortcut, ...shortcuts] = checkShortcuts([{ name: OWN, shortcut: ownShortcut(own) }, ...plugins]);\n const paged = plugins.flatMap((p, i) =>\n p.client === undefined ? [] : [{ client: p.client, rest: { shortcut: shortcuts[i], options: p.clientOptions } }],\n );\n return [\n `import { start } from 'deictic/client';`,\n ...paged.map((p, i) => `import p${i} from ${JSON.stringify(p.client)};`),\n ...(server === undefined ? [] : [`import server from ${JSON.stringify(server)};`]),\n // Its shortcut and options as JSON, where it has them: `JSON.stringify` leaves out what's undefined.\n `start({ base: ${JSON.stringify(base)}, shortcut: ${JSON.stringify(shortcut) ?? 'undefined'}, plugins: [${paged.map((p, i) => `{ plugin: p${i}, ...${JSON.stringify(p.rest)} }`).join(', ')}]${server === undefined ? '' : ', server'} });`,\n ].join('\\n');\n};\n\n/**\n * Writes the client module to `.deictic/client.js` for a bundler without virtual modules, and answers\n * its path. Its imports are bare (`deictic/client`, each plugin's), found from the project as its own\n * are. Written only when it changed, so a watching bundler doesn't rebuild for nothing.\n */\nexport function writeClient(root: string, plugins: ServerPlugin[], base: string, own?: Shortcut | false): string {\n const code = `// Written by deictic as the dev server starts: it starts the overlay in the page.\\n${clientModule(plugins, base, own)}\\n`;\n // Its own package: an ES module that runs for its effect. An app whose package.json says\n // `\"sideEffects\": false` would otherwise have webpack drop the import, which is only for its effect.\n const manifest = `${JSON.stringify({ private: true, type: 'module', sideEffects: true }, null, 2)}\\n`;\n writeIfChanged(keptIn(root, 'package.json'), manifest);\n return writeIfChanged(keptIn(root, 'client.js'), code);\n}\n\nfunction writeIfChanged(path: string, text: string): string {\n if (!existsSync(path) || readFileSync(path, 'utf8') !== text) writeFileSync(path, text);\n return path;\n}\n\n/** A module beside `url`, by its name: `.ts` from the source, `.js` from `dist`, as `url` is. */\nexport const beside = (url: string, name: string) =>\n fileURLToPath(new URL(`./${name}${url.endsWith('.ts') ? '.ts' : '.js'}`, url)).replaceAll('\\\\', '/');\n\n/**\n * The import of the written client module in the module at `from`, by a relative path with forward\n * slashes: Turbopack can't import a Windows path, and every bundler takes a relative one.\n */\nexport function importOf(path: string, from: string): string {\n const to = relative(dirname(from), path).replaceAll('\\\\', '/');\n return `\\nimport ${JSON.stringify(to.startsWith('.') ? to : `./${to}`)};\\n`;\n}\n\n/**\n * A module marked, by its absolute path: its host elements, and `append` after it (the client's import,\n * in the browser). Nothing for a file that isn't JSX, is a dependency's, or is outside the project.\n */\nexport function mark(code: string, path: string, root: string, append = ''): Located | undefined {\n const file = JSX.test(path) ? fileIn(path, root) : undefined;\n return file === undefined ? undefined : locate(code, file, append);\n}\n\n/** An `.astro` component marked, by its absolute path, as `mark` does a module. It's no module of the browser's, so nothing is appended. */\nexport function markAstro(code: string, path: string, root: string): Located | undefined {\n const file = ASTRO.test(path) ? fileIn(path, root) : undefined;\n return file === undefined ? undefined : locateAstro(code, file, root);\n}\n\n/** A project file's path from the root, as a mark has it; nothing for a dependency's or one outside the project. */\nfunction fileIn(path: string, root: string): string | undefined {\n if (/[\\\\/]node_modules[\\\\/]/.test(path) || !isAbsolute(path)) return undefined;\n const file = relative(root, path).replaceAll('\\\\', '/');\n return file.startsWith('..') || isAbsolute(file) ? undefined : file;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAeA,MAAa,YAAY;;AAEzB,MAAa,MAAM;;AAGnB,MAAa,SAAS,MAAc,SAAiB,UAAU,MAAM,MAAM,aAAa,KAAK,IAAI,IAAI,EAAE,MAAM,MAAM,IAAI,KAAA,CA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IAAI,KAAK,OAAO,IAAI,SAAS,KAAK,IAAI,QAAQ,SAAS,GAAG,CAAC,CAAC,CAAC,WAAW,MAAM,GAAG;;;;;AAMrG,SAAgB,SAAS,MAAc,MAAsB;CAC3D,MAAM,KAAK,SAAS,QAAQ,IAAI,GAAG,IAAI,CAAC,CAAC,WAAW,MAAM,GAAG;CAC7D,OAAO,YAAY,KAAK,UAAU,GAAG,WAAW,GAAG,IAAI,KAAK,KAAK,IAAI,EAAE;AACzE;;;;;AAMA,SAAgB,KAAK,MAAc,MAAc,MAAc,SAAS,IAAyB;CAC/F,MAAM,OAAO,IAAI,KAAK,IAAI,IAAI,OAAO,MAAM,IAAI,IAAI,KAAA;CACnD,OAAO,SAAS,KAAA,IAAY,KAAA,IAAY,OAAO,MAAM,MAAM,MAAM;AACnE;;AAGA,SAAgB,UAAU,MAAc,MAAc,MAAmC;CACvF,MAAM,OAAO,MAAM,KAAK,IAAI,IAAI,OAAO,MAAM,IAAI,IAAI,KAAA;CACrD,OAAO,SAAS,KAAA,IAAY,KAAA,IAAY,YAAY,MAAM,MAAM,IAAI;AACtE;;AAGA,SAAS,OAAO,MAAc,MAAkC;CAC9D,IAAI,yBAAyB,KAAK,IAAI,KAAK,CAAC,WAAW,IAAI,GAAG,OAAO,KAAA;CACrE,MAAM,OAAO,SAAS,MAAM,IAAI,CAAC,CAAC,WAAW,MAAM,GAAG;CACtD,OAAO,KAAK,WAAW,IAAI,KAAK,WAAW,IAAI,IAAI,KAAA,IAAY;AACjE"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// package.json
|
|
2
|
+
var name = "deictic";
|
|
3
|
+
var version = "0.8.1";
|
|
4
|
+
var bugs = { "url": "https://github.com/gkurt/deictic/issues" };
|
|
5
|
+
var peerDependencies = {
|
|
6
|
+
"@rrweb/rrweb-plugin-console-record": "^2.2.2",
|
|
7
|
+
"@rrweb/rrweb-plugin-network-record": "^2.2.2",
|
|
8
|
+
"@rspack/core": ">=1",
|
|
9
|
+
"@vercel/board": ">=0.53.0",
|
|
10
|
+
"astro": ">=5",
|
|
11
|
+
"launch-editor": "^2.9.0",
|
|
12
|
+
"modern-screenshot": "^4.7.0",
|
|
13
|
+
"next": ">=16",
|
|
14
|
+
"playwright-core": "^1.50.0",
|
|
15
|
+
"rrweb": "^2.2.2",
|
|
16
|
+
"rrweb-player": "^2.2.2",
|
|
17
|
+
"rrweb-snapshot": "^2.2.2",
|
|
18
|
+
"vite": ">=6",
|
|
19
|
+
"webpack": ">=5"
|
|
20
|
+
};
|
|
21
|
+
export { version as i, name as n, peerDependencies as r, bugs as t };
|
|
22
|
+
|
|
23
|
+
//# sourceMappingURL=package.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package.js","names":[],"sources":["../../package.json"],"sourcesContent":[""],"mappings":""}
|
package/dist/shared/packages.js
CHANGED
|
@@ -1,25 +1,7 @@
|
|
|
1
1
|
import { existsSync, readFileSync } from "node:fs";
|
|
2
2
|
import { createRequire } from "node:module";
|
|
3
3
|
import { dirname, join } from "node:path";
|
|
4
|
-
|
|
5
|
-
var name = "deictic";
|
|
6
|
-
var version = "0.7.0";
|
|
7
|
-
var peerDependencies = {
|
|
8
|
-
"@rrweb/rrweb-plugin-console-record": "^2.2.2",
|
|
9
|
-
"@rrweb/rrweb-plugin-network-record": "^2.2.2",
|
|
10
|
-
"@rspack/core": ">=1",
|
|
11
|
-
"@vercel/board": ">=0.53.0",
|
|
12
|
-
"astro": ">=5",
|
|
13
|
-
"launch-editor": "^2.9.0",
|
|
14
|
-
"modern-screenshot": "^4.7.0",
|
|
15
|
-
"next": ">=16",
|
|
16
|
-
"playwright-core": "^1.50.0",
|
|
17
|
-
"rrweb": "^2.2.2",
|
|
18
|
-
"rrweb-player": "^2.2.2",
|
|
19
|
-
"rrweb-snapshot": "^2.2.2",
|
|
20
|
-
"vite": ">=6",
|
|
21
|
-
"webpack": ">=5"
|
|
22
|
-
};
|
|
4
|
+
import { i as version, n as name, r as peerDependencies } from "./package.js";
|
|
23
5
|
// src/tools/packages.ts
|
|
24
6
|
/**
|
|
25
7
|
* The packages plugins import that the project installs itself (`ServerPlugin.packages`: deictic's optional peers,
|
|
@@ -119,14 +101,23 @@ function missing(root, plugins) {
|
|
|
119
101
|
}];
|
|
120
102
|
});
|
|
121
103
|
}
|
|
122
|
-
/**
|
|
123
|
-
|
|
104
|
+
/**
|
|
105
|
+
* What to report as the dev server starts when plugins' packages are missing: which, and the command that installs
|
|
106
|
+
* them. Its key names them, so a problem fixed and then another missing is a new one.
|
|
107
|
+
*/
|
|
108
|
+
function missingProblem(root, plugins) {
|
|
124
109
|
const gone = missing(root, plugins);
|
|
125
110
|
if (gone.length === 0) return void 0;
|
|
126
111
|
const names = [...new Set(gone.flatMap((g) => g.packages))];
|
|
127
112
|
const which = gone.map((g) => g.plugin);
|
|
128
|
-
|
|
113
|
+
const who = which.length === 1 ? which[0] : `${which.slice(0, -1).join(", ")} and ${which.at(-1)}`;
|
|
114
|
+
const need = which.length === 1 ? "needs" : "need";
|
|
115
|
+
return {
|
|
116
|
+
key: `packages:${[...names].sort().join(",")}`,
|
|
117
|
+
kind: "setup",
|
|
118
|
+
message: `install what ${who} ${need}, then restart the dev server: ${installCommand(packageManager(root), names, root)}`
|
|
119
|
+
};
|
|
129
120
|
}
|
|
130
|
-
export { readJson as a, packageManager as i, installCommand as n, runnerOf as o,
|
|
121
|
+
export { readJson as a, packageManager as i, installCommand as n, runnerOf as o, missingProblem as r, execOf as t };
|
|
131
122
|
|
|
132
123
|
//# sourceMappingURL=packages.js.map
|