deictic 0.9.0 → 0.10.0
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 +10 -0
- package/dist/bun.d.ts.map +1 -1
- package/dist/bun.js +26 -8
- package/dist/bun.js.map +1 -1
- package/dist/client/index.js +8 -0
- package/dist/client/index.js.map +1 -1
- package/dist/next.d.ts.map +1 -1
- package/dist/next.js +45 -25
- package/dist/next.js.map +1 -1
- package/dist/shared/endpoints.js +14 -3
- package/dist/shared/endpoints.js.map +1 -1
- package/dist/shared/index.d.ts +5 -0
- package/dist/shared/index.d.ts.map +1 -1
- package/dist/shared/integration.d.ts +6 -0
- package/dist/shared/integration.d.ts.map +1 -1
- package/dist/shared/integration.js +28 -1
- package/dist/shared/integration.js.map +1 -1
- package/dist/shared/package.js +1 -1
- package/dist/shared/src.js.map +1 -1
- package/dist/shared/vite.d.ts +1 -1
- package/dist/shared/vite.d.ts.map +1 -1
- package/dist/shared/vite.js +28 -10
- package/dist/shared/vite.js.map +1 -1
- package/dist/webpack.d.ts +4 -0
- package/dist/webpack.d.ts.map +1 -1
- package/dist/webpack.js +37 -15
- package/dist/webpack.js.map +1 -1
- package/package.json +1 -1
- package/src/bun.ts +32 -8
- package/src/client/index.ts +4 -0
- package/src/index.ts +5 -0
- package/src/next.ts +34 -15
- package/src/tools/integration.ts +33 -0
- package/src/tools/source.ts +14 -2
- package/src/vite.ts +31 -10
- package/src/webpack.ts +48 -16
package/dist/next.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"next.d.ts","names":[],"sources":["../src/next.ts"],"mappings":";
|
|
1
|
+
{"version":3,"file":"next.d.ts","names":[],"sources":["../src/next.ts"],"mappings":";iBAgCiB,2BAA2B;;EAE1C;;KAUG,eAAe,MAAM,eAAe;EAAW,eAAe;MAAQ,IAAI,QAAQ;;;;;wBAiBvE,YAAY,kBAC1B,OAAM,IAAI,eAAe,IACzB,UAAS,sBACP,eAAe;EAAW,eAAe;MAAQ,QAAQ"}
|
package/dist/next.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createServer } from "node:http";
|
|
2
2
|
import { resolve } from "node:path";
|
|
3
3
|
import { n as nodeMiddleware, r as redirect, t as endpoints } from "./shared/endpoints.js";
|
|
4
|
-
import {
|
|
4
|
+
import { c as writeClient, g as JSX, o as merge, s as prepare, t as beside } from "./shared/integration.js";
|
|
5
5
|
// src/next.ts
|
|
6
6
|
/**
|
|
7
7
|
* `deictic/next`: deictic in `next dev`, on Turbopack or webpack (`--webpack`). Nothing runs in `next build`.
|
|
@@ -19,6 +19,11 @@ import { h as JSX, o as prepare, s as writeClient, t as beside } from "./shared/
|
|
|
19
19
|
*
|
|
20
20
|
* Both bundlers' rules are always set, as the config can't tell which will run: Next refuses a Turbopack
|
|
21
21
|
* build whose config has a `webpack` key only where it has no `turbopack` one, and ours always does.
|
|
22
|
+
*
|
|
23
|
+
* A config may be wrapped more than once: by the app, and by a package that adds its own plugin (`defaults`), as
|
|
24
|
+
* `withProsebook` does. The config each returns carries the options it was given (`GIVEN`), so the next one out adds
|
|
25
|
+
* no rules of its own: it writes the client again with all of them merged (`merge`), and the endpoints, made at the
|
|
26
|
+
* first request, load them all.
|
|
22
27
|
*/
|
|
23
28
|
const DEV = "phase-development-server";
|
|
24
29
|
const loaderPath = beside(import.meta.url, "loader");
|
|
@@ -28,34 +33,49 @@ const GLOBS = [
|
|
|
28
33
|
"*.js"
|
|
29
34
|
];
|
|
30
35
|
const serving = /* @__PURE__ */ new Map();
|
|
36
|
+
const loaded = /* @__PURE__ */ new Map();
|
|
37
|
+
/** On a config a `withDeictic` returned: the options of every one it went through. */
|
|
38
|
+
const GIVEN = Symbol.for("deictic.given");
|
|
31
39
|
/**
|
|
32
40
|
* Wraps the Next config: `export default withDeictic({ ... }, { plugins: [tailwind()] })`. Takes the
|
|
33
41
|
* config as an object or as the function Next calls with the phase, and returns the function.
|
|
34
42
|
*/
|
|
35
43
|
function withDeictic(next = {}, options = {}) {
|
|
36
|
-
|
|
44
|
+
prepare(options);
|
|
37
45
|
return async (phase, context) => {
|
|
38
46
|
const resolved = typeof next === "function" ? await next(phase, context) : next;
|
|
39
47
|
if (phase !== DEV) return resolved;
|
|
40
|
-
const
|
|
48
|
+
const before = resolved[GIVEN];
|
|
49
|
+
const given = [...before ?? [], options];
|
|
50
|
+
const merged = given.length === 1 ? options : merge(given);
|
|
51
|
+
const { plugins, shortcut } = prepare(merged);
|
|
52
|
+
const root = resolve(merged.root ?? process.cwd());
|
|
41
53
|
const base = `${resolved.basePath ?? ""}/`;
|
|
42
54
|
const client = writeClient(root, plugins, base, shortcut);
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
55
|
+
loaded.set(root, plugins);
|
|
56
|
+
if (before !== void 0) return {
|
|
57
|
+
...resolved,
|
|
58
|
+
[GIVEN]: given
|
|
59
|
+
};
|
|
60
|
+
return {
|
|
61
|
+
...withRewrite(withWebpack(withRules(resolved, GLOBS.flatMap((glob) => [[glob, {
|
|
62
|
+
condition: { all: ["browser", { not: "foreign" }] },
|
|
63
|
+
loaders: [{
|
|
64
|
+
loader: loaderPath,
|
|
65
|
+
options: {
|
|
66
|
+
root,
|
|
67
|
+
client
|
|
68
|
+
}
|
|
69
|
+
}]
|
|
70
|
+
}], [glob, {
|
|
71
|
+
condition: { all: [{ not: "browser" }, { not: "foreign" }] },
|
|
72
|
+
loaders: [{
|
|
73
|
+
loader: loaderPath,
|
|
74
|
+
options: { root }
|
|
75
|
+
}]
|
|
76
|
+
}]])), root, client), await serve(root, base)),
|
|
77
|
+
[GIVEN]: given
|
|
78
|
+
};
|
|
59
79
|
};
|
|
60
80
|
}
|
|
61
81
|
/** The app's rules and ours: where both have one for a glob, theirs first, then ours, in a list. */
|
|
@@ -119,21 +139,21 @@ function withRewrite(resolved, port) {
|
|
|
119
139
|
};
|
|
120
140
|
}
|
|
121
141
|
/** Serves the endpoints on a free local port, for as long as the process lives. */
|
|
122
|
-
function serve(root,
|
|
142
|
+
function serve(root, base) {
|
|
123
143
|
const running = serving.get(root);
|
|
124
144
|
if (running !== void 0) return running;
|
|
125
|
-
|
|
145
|
+
let middleware;
|
|
146
|
+
const made = () => middleware ??= nodeMiddleware(endpoints({
|
|
126
147
|
root,
|
|
127
|
-
plugins,
|
|
148
|
+
plugins: loaded.get(root) ?? [],
|
|
128
149
|
base: "/",
|
|
129
150
|
open: (path, { line, column }) => redirect(`${base}__nextjs_launch-editor?${new URLSearchParams({
|
|
130
151
|
file: path,
|
|
131
152
|
line1: String(line),
|
|
132
153
|
column1: String(column)
|
|
133
154
|
})}`)
|
|
134
|
-
});
|
|
135
|
-
const
|
|
136
|
-
const server = createServer((req, res) => middleware(req, res, () => {
|
|
155
|
+
}));
|
|
156
|
+
const server = createServer((req, res) => made()(req, res, () => {
|
|
137
157
|
res.statusCode = 404;
|
|
138
158
|
res.end();
|
|
139
159
|
}));
|
package/dist/next.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"next.js","names":[],"sources":["../src/next.ts"],"sourcesContent":["/**\n * `deictic/next`: deictic in `next dev`, on Turbopack or webpack (`--webpack`). Nothing runs in `next build`.\n *\n * Turbopack has no transform hook and no virtual modules, so a loader rule (`loader.ts`) marks each JSX\n * module, on the server too, which marks server components' elements in the HTML they render; in the\n * browser it also imports the client module, written to `.deictic/client.js`. Only code the browser\n * loads can start the overlay, so a page with no client component at all has none. Under webpack the\n * same loader is a `pre` rule, as in `webpack.ts`.\n *\n * The endpoints can't be a route of the app without a file in it, so a server of their own answers them\n * on a local port, and a rewrite sends `/__deictic/*` there, before any of the app's own; Next's proxy\n * forwards the page's host, so writes are still checked against its origin. A place opens through\n * Next's own `/__nextjs_launch-editor`.\n *\n * Both bundlers' rules are always set, as the config can't tell which will run: Next refuses a Turbopack\n * build whose config has a `webpack` key only where it has no `turbopack` one, and ours always does.\n */\nimport { createServer } from 'node:http';\nimport type { AddressInfo } from 'node:net';\nimport { resolve } from 'node:path';\n\nimport type { ServerPlugin } from './index.ts';\nimport type { LoaderOptions } from './loader.ts';\nimport { endpoints, nodeMiddleware, redirect } from './tools/endpoints.ts';\nimport { beside, type DeicticOptions, prepare, writeClient } from './tools/integration.ts';\nimport { JSX } from './tools/locate.ts';\n\nexport interface DeicticNextOptions extends DeicticOptions {\n /** The project's root, which marks and edits are from: the working directory `next dev` runs in by default. */\n root?: string;\n}\n\n/** A Turbopack rule: ours, or whatever the app has. */\ntype Rule = { condition?: unknown; loaders: { loader: string; options: LoaderOptions }[] } | object;\ntype Rules = Record<string, Rule | Rule[]>;\ntype Rewrite = { source: string; destination: string };\ntype Rewrites = Rewrite[] | { beforeFiles?: Rewrite[]; afterFiles?: Rewrite[]; fallback?: Rewrite[] };\n/** What Next's `webpack` option reads and answers, as far as it's used here. Not async: Next doesn't wait for one. */\ntype Webpack = (config: { module: { rules: unknown[] } }, context: { isServer: boolean }) => { module: { rules: unknown[] } };\ntype ConfigFunction<C> = (phase: string, context: { defaultConfig: C }) => C | Promise<C>;\n\nconst DEV = 'phase-development-server';\nconst loaderPath = beside(import.meta.url, 'loader');\nconst GLOBS = ['*.tsx', '*.jsx', '*.js'];\n\n// Next loads its config more than once in a process: one endpoints server per project is enough.\nconst serving = new Map<string, Promise<number>>();\n\n/**\n * Wraps the Next config: `export default withDeictic({ ... }, { plugins: [tailwind()] })`. Takes the\n * config as an object or as the function Next calls with the phase, and returns the function.\n */\nexport function withDeictic<C extends object>(\n next: C | ConfigFunction<C> = {} as C,\n options: DeicticNextOptions = {},\n): (phase: string, context: { defaultConfig: C }) => Promise<C> {\n // Now, so a wrong set of plugins stops the dev server as it starts, rather than the page.\n const { plugins, shortcut } = prepare(options);\n return async (phase, context) => {\n const resolved = typeof next === 'function' ? await next(phase, context) : next;\n if (phase !== DEV) return resolved;\n const root = resolve(options.root ?? process.cwd());\n const base = `${(resolved as { basePath?: string }).basePath ?? ''}/`;\n const client = writeClient(root, plugins, base, shortcut);\n const rules: [string, Rule][] = GLOBS.flatMap((glob) => [\n [glob, { condition: { all: ['browser', { not: 'foreign' }] }, loaders: [{ loader: loaderPath, options: { root, client } }] }],\n [glob, { condition: { all: [{ not: 'browser' }, { not: 'foreign' }] }, loaders: [{ loader: loaderPath, options: { root } }] }],\n ]);\n return withRewrite(withWebpack(withRules(resolved, rules), root, client), await serve(root, plugins, base));\n };\n}\n\n/** The app's rules and ours: where both have one for a glob, theirs first, then ours, in a list. */\nfunction withRules<C extends object>(resolved: C, ours: [string, Rule][]): C {\n const turbopack = (resolved as { turbopack?: { rules?: Rules } }).turbopack;\n const rules: Rules = { ...turbopack?.rules };\n for (const [glob, rule] of ours) rules[glob] = glob in rules ? [rules[glob], rule].flat() : rule;\n return { ...resolved, turbopack: { ...turbopack, rules } };\n}\n\n/** For `next dev --webpack`: the app's own `webpack`, then the loader, `pre`, with the client in the browser's build. */\nfunction withWebpack<C extends object>(resolved: C, root: string, client: string): C {\n const theirs = (resolved as { webpack?: Webpack | null }).webpack;\n const webpack: Webpack = (config, context) => {\n const made = theirs?.(config, context) ?? config;\n const options: LoaderOptions = context.isServer ? { root } : { root, client };\n made.module.rules.unshift({ test: JSX, exclude: /[\\\\/]node_modules[\\\\/]/, enforce: 'pre', use: [{ loader: loaderPath, options }] });\n return made;\n };\n return { ...resolved, webpack };\n}\n\n/** Sends `/__deictic/*` to the endpoints' server, before any of the app's own rewrites. */\nfunction withRewrite<C extends object>(resolved: C, port: number): C {\n const theirs = (resolved as { rewrites?: () => Promise<Rewrites> }).rewrites;\n const ours = [{ source: '/__deictic/:path*', destination: `http://127.0.0.1:${port}/__deictic/:path*` }];\n const rewrites = async (): Promise<Rewrites> => {\n const r = (await theirs?.()) ?? [];\n return Array.isArray(r) ? { beforeFiles: ours, afterFiles: r } : { ...r, beforeFiles: [...ours, ...(r.beforeFiles ?? [])] };\n };\n return { ...resolved, rewrites };\n}\n\n/** Serves the endpoints on a free local port, for as long as the process lives. */\nfunction serve(root: string, plugins: ServerPlugin[], base: string): Promise<number> {\n const running = serving.get(root);\n if (running !== undefined) return running;\n const handle = endpoints({\n root,\n plugins,\n // Rewritten from under the base, but served at the root of their own server.\n base: '/',\n open: (path, { line, column }) =>\n redirect(`${base}__nextjs_launch-editor?${new URLSearchParams({ file: path, line1: String(line), column1: String(column) })}`),\n });\n const middleware = nodeMiddleware(handle);\n const server = createServer((req, res) =>\n middleware(req, res, () => {\n res.statusCode = 404;\n res.end();\n }),\n );\n const port = new Promise<number>((done, fail) => {\n server.once('error', fail);\n server.listen(0, '127.0.0.1', () => done((server.address() as AddressInfo).port));\n });\n // Not keeping the process alive past Next's own server.\n server.unref();\n serving.set(root, port);\n return port;\n}\n\nexport default withDeictic;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAyCA,MAAM,MAAM;AACZ,MAAM,aAAa,OAAO,YAAY,KAAK,QAAQ;AACnD,MAAM,QAAQ;CAAC;CAAS;CAAS;AAAM;AAGvC,MAAM,0BAAU,IAAI,IAA6B;;;;;AAMjD,SAAgB,YACd,OAA8B,CAAC,GAC/B,UAA8B,CAAC,GAC+B;CAE9D,MAAM,EAAE,SAAS,aAAa,QAAQ,OAAO;CAC7C,OAAO,OAAO,OAAO,YAAY;EAC/B,MAAM,WAAW,OAAO,SAAS,aAAa,MAAM,KAAK,OAAO,OAAO,IAAI;EAC3E,IAAI,UAAU,KAAK,OAAO;EAC1B,MAAM,OAAO,QAAQ,QAAQ,QAAQ,QAAQ,IAAI,CAAC;EAClD,MAAM,OAAO,GAAI,SAAmC,YAAY,GAAG;EACnE,MAAM,SAAS,YAAY,MAAM,SAAS,MAAM,QAAQ;EAKxD,OAAO,YAAY,YAAY,UAAU,UAJT,MAAM,SAAS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C;EAAE,QAAQ;EAAqB,aAAa,oBAAoB,KAAK;CAAmB,CAAC;CACvG,MAAM,WAAW,YAA+B;EAC9C,MAAM,IAAK,MAAM,SAAS,KAAM,CAAC;EACjC,OAAO,MAAM,QAAQ,CAAC,IAAI;GAAE,aAAa;GAAM,YAAY;EAAE,IAAI;GAAE,GAAG;GAAG,aAAa,CAAC,GAAG,MAAM,GAAI,EAAE,eAAe,CAAC,CAAE;EAAE;CAC5H;CACA,OAAO;EAAE,GAAG;EAAU;CAAS;AACjC;;AAGA,SAAS,MAAM,MAAc,SAAyB,MAA+B;CACnF,MAAM,UAAU,QAAQ,IAAI,IAAI;CAChC,IAAI,YAAY,KAAA,GAAW,OAAO;CAClC,MAAM,SAAS,UAAU;EACvB;EACA;EAEA,MAAM;EACN,OAAO,MAAM,EAAE,MAAM,aACnB,SAAS,GAAG,KAAK,yBAAyB,IAAI,gBAAgB;GAAE,MAAM;GAAM,OAAO,OAAO,IAAI;GAAG,SAAS,OAAO,MAAM;EAAE,CAAC,GAAG;CACjI,CAAC;CACD,MAAM,aAAa,eAAe,MAAM;CACxC,MAAM,SAAS,cAAc,KAAK,QAChC,WAAW,KAAK,WAAW;EACzB,IAAI,aAAa;EACjB,IAAI,IAAI;CACV,CAAC,CACH;CACA,MAAM,OAAO,IAAI,SAAiB,MAAM,SAAS;EAC/C,OAAO,KAAK,SAAS,IAAI;EACzB,OAAO,OAAO,GAAG,mBAAmB,KAAM,OAAO,QAAQ,CAAC,CAAiB,IAAI,CAAC;CAClF,CAAC;CAED,OAAO,MAAM;CACb,QAAQ,IAAI,MAAM,IAAI;CACtB,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"next.js","names":[],"sources":["../src/next.ts"],"sourcesContent":["/**\n * `deictic/next`: deictic in `next dev`, on Turbopack or webpack (`--webpack`). Nothing runs in `next build`.\n *\n * Turbopack has no transform hook and no virtual modules, so a loader rule (`loader.ts`) marks each JSX\n * module, on the server too, which marks server components' elements in the HTML they render; in the\n * browser it also imports the client module, written to `.deictic/client.js`. Only code the browser\n * loads can start the overlay, so a page with no client component at all has none. Under webpack the\n * same loader is a `pre` rule, as in `webpack.ts`.\n *\n * The endpoints can't be a route of the app without a file in it, so a server of their own answers them\n * on a local port, and a rewrite sends `/__deictic/*` there, before any of the app's own; Next's proxy\n * forwards the page's host, so writes are still checked against its origin. A place opens through\n * Next's own `/__nextjs_launch-editor`.\n *\n * Both bundlers' rules are always set, as the config can't tell which will run: Next refuses a Turbopack\n * build whose config has a `webpack` key only where it has no `turbopack` one, and ours always does.\n *\n * A config may be wrapped more than once: by the app, and by a package that adds its own plugin (`defaults`), as\n * `withProsebook` does. The config each returns carries the options it was given (`GIVEN`), so the next one out adds\n * no rules of its own: it writes the client again with all of them merged (`merge`), and the endpoints, made at the\n * first request, load them all.\n */\nimport { createServer } from 'node:http';\nimport type { AddressInfo } from 'node:net';\nimport { resolve } from 'node:path';\n\nimport type { ServerPlugin } from './index.ts';\nimport type { LoaderOptions } from './loader.ts';\nimport { endpoints, nodeMiddleware, redirect } from './tools/endpoints.ts';\nimport { beside, type DeicticOptions, merge, prepare, writeClient } from './tools/integration.ts';\nimport { JSX } from './tools/locate.ts';\n\nexport interface DeicticNextOptions extends DeicticOptions {\n /** The project's root, which marks and edits are from: the working directory `next dev` runs in by default. */\n root?: string;\n}\n\n/** A Turbopack rule: ours, or whatever the app has. */\ntype Rule = { condition?: unknown; loaders: { loader: string; options: LoaderOptions }[] } | object;\ntype Rules = Record<string, Rule | Rule[]>;\ntype Rewrite = { source: string; destination: string };\ntype Rewrites = Rewrite[] | { beforeFiles?: Rewrite[]; afterFiles?: Rewrite[]; fallback?: Rewrite[] };\n/** What Next's `webpack` option reads and answers, as far as it's used here. Not async: Next doesn't wait for one. */\ntype Webpack = (config: { module: { rules: unknown[] } }, context: { isServer: boolean }) => { module: { rules: unknown[] } };\ntype ConfigFunction<C> = (phase: string, context: { defaultConfig: C }) => C | Promise<C>;\n\nconst DEV = 'phase-development-server';\nconst loaderPath = beside(import.meta.url, 'loader');\nconst GLOBS = ['*.tsx', '*.jsx', '*.js'];\n\n// Next loads its config more than once in a process: one endpoints server per project is enough.\nconst serving = new Map<string, Promise<number>>();\n// Each project's plugins as its config last merged them, for its endpoints to load at their first request.\nconst loaded = new Map<string, ServerPlugin[]>();\n/** On a config a `withDeictic` returned: the options of every one it went through. */\nconst GIVEN = Symbol.for('deictic.given');\n\n/**\n * Wraps the Next config: `export default withDeictic({ ... }, { plugins: [tailwind()] })`. Takes the\n * config as an object or as the function Next calls with the phase, and returns the function.\n */\nexport function withDeictic<C extends object>(\n next: C | ConfigFunction<C> = {} as C,\n options: DeicticNextOptions = {},\n): (phase: string, context: { defaultConfig: C }) => Promise<C> {\n // Now, so a wrong set of plugins stops the dev server as it starts, rather than the page.\n prepare(options);\n return async (phase, context) => {\n const resolved = typeof next === 'function' ? await next(phase, context) : next;\n if (phase !== DEV) return resolved;\n const before = (resolved as { [GIVEN]?: DeicticNextOptions[] })[GIVEN];\n const given = [...(before ?? []), options];\n const merged = given.length === 1 ? options : merge(given);\n const { plugins, shortcut } = prepare(merged);\n const root = resolve(merged.root ?? process.cwd());\n const base = `${(resolved as { basePath?: string }).basePath ?? ''}/`;\n const client = writeClient(root, plugins, base, shortcut);\n loaded.set(root, plugins);\n // Wrapped already: the rules and the rewrite are there, and only the client and the plugins change.\n if (before !== undefined) return { ...resolved, [GIVEN]: given };\n const rules: [string, Rule][] = GLOBS.flatMap((glob) => [\n [glob, { condition: { all: ['browser', { not: 'foreign' }] }, loaders: [{ loader: loaderPath, options: { root, client } }] }],\n [glob, { condition: { all: [{ not: 'browser' }, { not: 'foreign' }] }, loaders: [{ loader: loaderPath, options: { root } }] }],\n ]);\n return { ...withRewrite(withWebpack(withRules(resolved, rules), root, client), await serve(root, base)), [GIVEN]: given };\n };\n}\n\n/** The app's rules and ours: where both have one for a glob, theirs first, then ours, in a list. */\nfunction withRules<C extends object>(resolved: C, ours: [string, Rule][]): C {\n const turbopack = (resolved as { turbopack?: { rules?: Rules } }).turbopack;\n const rules: Rules = { ...turbopack?.rules };\n for (const [glob, rule] of ours) rules[glob] = glob in rules ? [rules[glob], rule].flat() : rule;\n return { ...resolved, turbopack: { ...turbopack, rules } };\n}\n\n/** For `next dev --webpack`: the app's own `webpack`, then the loader, `pre`, with the client in the browser's build. */\nfunction withWebpack<C extends object>(resolved: C, root: string, client: string): C {\n const theirs = (resolved as { webpack?: Webpack | null }).webpack;\n const webpack: Webpack = (config, context) => {\n const made = theirs?.(config, context) ?? config;\n const options: LoaderOptions = context.isServer ? { root } : { root, client };\n made.module.rules.unshift({ test: JSX, exclude: /[\\\\/]node_modules[\\\\/]/, enforce: 'pre', use: [{ loader: loaderPath, options }] });\n return made;\n };\n return { ...resolved, webpack };\n}\n\n/** Sends `/__deictic/*` to the endpoints' server, before any of the app's own rewrites. */\nfunction withRewrite<C extends object>(resolved: C, port: number): C {\n const theirs = (resolved as { rewrites?: () => Promise<Rewrites> }).rewrites;\n const ours = [{ source: '/__deictic/:path*', destination: `http://127.0.0.1:${port}/__deictic/:path*` }];\n const rewrites = async (): Promise<Rewrites> => {\n const r = (await theirs?.()) ?? [];\n return Array.isArray(r) ? { beforeFiles: ours, afterFiles: r } : { ...r, beforeFiles: [...ours, ...(r.beforeFiles ?? [])] };\n };\n return { ...resolved, rewrites };\n}\n\n/** Serves the endpoints on a free local port, for as long as the process lives. */\nfunction serve(root: string, base: string): Promise<number> {\n const running = serving.get(root);\n if (running !== undefined) return running;\n let middleware: ReturnType<typeof nodeMiddleware> | undefined;\n const made = () =>\n (middleware ??= nodeMiddleware(\n endpoints({\n root,\n plugins: loaded.get(root) ?? [],\n // Rewritten from under the base, but served at the root of their own server.\n base: '/',\n open: (path, { line, column }) =>\n redirect(`${base}__nextjs_launch-editor?${new URLSearchParams({ file: path, line1: String(line), column1: String(column) })}`),\n }),\n ));\n const server = createServer((req, res) =>\n made()(req, res, () => {\n res.statusCode = 404;\n res.end();\n }),\n );\n const port = new Promise<number>((done, fail) => {\n server.once('error', fail);\n server.listen(0, '127.0.0.1', () => done((server.address() as AddressInfo).port));\n });\n // Not keeping the process alive past Next's own server.\n server.unref();\n serving.set(root, port);\n return port;\n}\n\nexport default withDeictic;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AA8CA,MAAM,MAAM;AACZ,MAAM,aAAa,OAAO,YAAY,KAAK,QAAQ;AACnD,MAAM,QAAQ;CAAC;CAAS;CAAS;AAAM;AAGvC,MAAM,0BAAU,IAAI,IAA6B;AAEjD,MAAM,yBAAS,IAAI,IAA4B;;AAE/C,MAAM,QAAQ,OAAO,IAAI,eAAe;;;;;AAMxC,SAAgB,YACd,OAA8B,CAAC,GAC/B,UAA8B,CAAC,GAC+B;CAE9D,QAAQ,OAAO;CACf,OAAO,OAAO,OAAO,YAAY;EAC/B,MAAM,WAAW,OAAO,SAAS,aAAa,MAAM,KAAK,OAAO,OAAO,IAAI;EAC3E,IAAI,UAAU,KAAK,OAAO;EAC1B,MAAM,SAAU,SAAgD;EAChE,MAAM,QAAQ,CAAC,GAAI,UAAU,CAAC,GAAI,OAAO;EACzC,MAAM,SAAS,MAAM,WAAW,IAAI,UAAU,MAAM,KAAK;EACzD,MAAM,EAAE,SAAS,aAAa,QAAQ,MAAM;EAC5C,MAAM,OAAO,QAAQ,OAAO,QAAQ,QAAQ,IAAI,CAAC;EACjD,MAAM,OAAO,GAAI,SAAmC,YAAY,GAAG;EACnE,MAAM,SAAS,YAAY,MAAM,SAAS,MAAM,QAAQ;EACxD,OAAO,IAAI,MAAM,OAAO;EAExB,IAAI,WAAW,KAAA,GAAW,OAAO;GAAE,GAAG;IAAW,QAAQ;EAAM;EAK/D,OAAO;GAAE,GAAG,YAAY,YAAY,UAAU,UAJd,MAAM,SAAS,SAAS,CACtD,CAAC,MAAM;IAAE,WAAW,EAAE,KAAK,CAAC,WAAW,EAAE,KAAK,UAAU,CAAC,EAAE;IAAG,SAAS,CAAC;KAAE,QAAQ;KAAY,S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AM,CAAC;EACjC,OAAO,MAAM,QAAQ,CAAC,IAAI;GAAE,aAAa;GAAM,YAAY;EAAE,IAAI;GAAE,GAAG;GAAG,aAAa,CAAC,GAAG,MAAM,GAAI,EAAE,eAAe,CAAC,CAAE;EAAE;CAC5H;CACA,OAAO;EAAE,GAAG;EAAU;CAAS;AACjC;;AAGA,SAAS,MAAM,MAAc,MAA+B;CAC1D,MAAM,UAAU,QAAQ,IAAI,IAAI;CAChC,IAAI,YAAY,KAAA,GAAW,OAAO;CAClC,IAAI;CACJ,MAAM,aACH,eAAe,eACd,UAAU;EACR;EACA,SAAS,OAAO,IAAI,IAAI,KAAK,CAAC;EAE9B,MAAM;EACN,OAAO,MAAM,EAAE,MAAM,aACnB,SAAS,GAAG,KAAK,yBAAyB,IAAI,gBAAgB;GAAE,MAAM;GAAM,OAAO,OAAO,IAAI;GAAG,SAAS,OAAO,MAAM;EAAE,CAAC,GAAG;CACjI,CAAC,CACH;CACF,MAAM,SAAS,cAAc,KAAK,QAChC,KAAK,CAAC,CAAC,KAAK,WAAW;EACrB,IAAI,aAAa;EACjB,IAAI,IAAI;CACV,CAAC,CACH;CACA,MAAM,OAAO,IAAI,SAAiB,MAAM,SAAS;EAC/C,OAAO,KAAK,SAAS,IAAI;EACzB,OAAO,OAAO,GAAG,mBAAmB,KAAM,OAAO,QAAQ,CAAC,CAAiB,IAAI,CAAC;CAClF,CAAC;CAED,OAAO,MAAM;CACb,QAAQ,IAAI,MAAM,IAAI;CACtB,OAAO;AACT"}
|
package/dist/shared/endpoints.js
CHANGED
|
@@ -2,7 +2,7 @@ import { t as Refusal } from "./src.js";
|
|
|
2
2
|
import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
3
3
|
import { dirname, isAbsolute, relative, resolve, sep } from "node:path";
|
|
4
4
|
import { t as keptIn } from "./kept.js";
|
|
5
|
-
import { _ as
|
|
5
|
+
import { _ as isHost, b as openingsIn, d as problemIn, f as reporter, h as parseAstro, l as setUp, m as ASTRO, p as stackOf, u as messageOf, v as lineStarts, x as parse, y as offsetOf } from "./integration.js";
|
|
6
6
|
import { i as missingProblem } from "./packages.js";
|
|
7
7
|
// src/tools/source.ts
|
|
8
8
|
/**
|
|
@@ -66,13 +66,16 @@ function astro(root, file, code) {
|
|
|
66
66
|
if ("problem" in parsed) throw new Refusal(`${file} can't be read: ${parsed.problem}`);
|
|
67
67
|
return parsed;
|
|
68
68
|
}
|
|
69
|
-
/**
|
|
69
|
+
/**
|
|
70
|
+
* Each file's text after its edits, which must not overlap. A file that isn't there is made where every edit to it is
|
|
71
|
+
* at its start (a locale's first translation, say); any other edit to one is refused.
|
|
72
|
+
*/
|
|
70
73
|
function applyEdits(source, edits) {
|
|
71
74
|
const byFile = Map.groupBy(edits, (e) => e.file ?? source.file);
|
|
72
75
|
const out = /* @__PURE__ */ new Map();
|
|
73
76
|
for (const [file, list] of byFile) {
|
|
74
77
|
const sorted = list.toSorted((a, b) => b.start - a.start);
|
|
75
|
-
let code = file === source.file ? source.code : source
|
|
78
|
+
let code = file === source.file ? source.code : textOf(source, file, list);
|
|
76
79
|
let floor = 1e400;
|
|
77
80
|
for (const edit of sorted) {
|
|
78
81
|
if (edit.end > floor) throw new Error(`deictic: edits to ${file} overlap at ${edit.end}`);
|
|
@@ -83,6 +86,14 @@ function applyEdits(source, edits) {
|
|
|
83
86
|
}
|
|
84
87
|
return out;
|
|
85
88
|
}
|
|
89
|
+
function textOf(source, file, edits) {
|
|
90
|
+
try {
|
|
91
|
+
return source.read(file);
|
|
92
|
+
} catch (e) {
|
|
93
|
+
if (e instanceof Refusal && e.cause !== void 0 && edits.every((edit) => edit.start === 0 && edit.end === 0)) return "";
|
|
94
|
+
throw e;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
86
97
|
// src/tools/history.ts
|
|
87
98
|
/**
|
|
88
99
|
* Every change deictic made, to undo and redo. A change to files holds each file's whole text
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"endpoints.js","names":[],"sources":["../../src/tools/source.ts","../../src/tools/history.ts","../../src/tools/endpoints.ts"],"sourcesContent":["/**\n * The source a server half reads: a target's file, parsed, and the opening tag the page's attribute\n * points at. Files are only ever read and written under the project's root, outside `node_modules`.\n */\nimport { readFileSync } from 'node:fs';\nimport { isAbsolute, relative, resolve, sep } from 'node:path';\n\nimport { Refusal, type Source, type Target, type TextEdit } from '#src/index.ts';\n\nimport { ASTRO, parseAstro, type Parsed } from './astro.ts';\nimport { isHost, lineStarts, offsetOf, openingsIn, parse } from './locate.ts';\n\n/** A file from the project's root, as an absolute path; refused anywhere the page has no business writing. */\nexport function resolveFile(root: string, file: string): string {\n const path = resolve(root, file);\n const from = relative(root, path);\n // `relative` gives an absolute path for another drive.\n if (from === '' || from.startsWith('..') || isAbsolute(from) || from.split(sep).includes('node_modules'))\n throw new Refusal(`${file} is not a file of this project's own`);\n return path;\n}\n\nexport function readSource(root: string, file: string): string {\n try {\n return readFileSync(resolveFile(root, file), 'utf8');\n } catch (e) {\n if (e instanceof Refusal) throw e;\n throw new Refusal(`can't read ${file}: has it moved since the page loaded?`, { cause: e });\n }\n}\n\n/**\n * The target's file and element, as they are on disk now. The element is the one the page's mark names, or else the\n * only one of its tag on that line: the page may count columns in code a plugin before deictic's changed.\n */\nexport function sourceAt(root: string, target: Target): Source {\n const { file, line, column } = target.loc;\n const code = readSource(root, file);\n const lines = lineStarts(code);\n const offset = offsetOf(lines, line, column);\n const { program, elements } = ASTRO.test(file) ? astro(root, file, code) : jsx(file, code);\n const tagged = elements.filter((el) => isHost(el) && el.name.type === 'JSXIdentifier' && el.name.name === target.tag);\n const start = lines[line - 1];\n const onLine = start === undefined ? [] : tagged.filter((el) => el.start >= start && el.start < (lines[line] ?? Infinity));\n const element = tagged.find((el) => el.start === offset) ?? (onLine.length === 1 ? onLine[0] : undefined);\n if (element === undefined) throw new Refusal(notThere(target, code, lines, onLine.length));\n return { file, code, program, element, read: (other) => readSource(root, other) };\n}\n\n/** Why the page's element isn't in the file, from what the file has there: it may not have changed at all. */\nfunction notThere({ loc: { file, line, column }, tag }: Target, code: string, lines: number[], onLine: number): string {\n const start = lines[line - 1];\n const found =\n start === undefined\n ? `${file} has no line ${line}`\n : onLine === 0\n ? `line ${line} of ${file} has no <${tag}>: it reads \\`${clip(code.slice(start, (lines[line] ?? code.length + 1) - 1).trim())}\\``\n : `line ${line} of ${file} has ${onLine} <${tag}>s, none at column ${column}`;\n return `${found}. The page isn't running the file as it is: reload it, and if it says this again, a plugin before deictic's changes the file, so put deictic first`;\n}\n\nconst clip = (text: string) => (text.length > 80 ? `${text.slice(0, 79)}…` : text);\n\nfunction jsx(file: string, code: string): Parsed {\n const { program, errors } = parse(file, code);\n if (errors.length > 0) throw new Refusal(`${file} doesn't parse: fix it first (${errors[0]!.message})`);\n return { program, elements: openingsIn(program) };\n}\n\nfunction astro(root: string, file: string, code: string): Parsed {\n const parsed = parseAstro(root, code);\n if ('problem' in parsed) throw new Refusal(`${file} can't be read: ${parsed.problem}`);\n return parsed;\n}\n\n/** Each file's text after its edits, which must not overlap. */\nexport function applyEdits(source: Source, edits: TextEdit[]): Map<string, string> {\n const byFile = Map.groupBy(edits, (e) => e.file ?? source.file);\n const out = new Map<string, string>();\n for (const [file, list] of byFile) {\n const sorted = list.toSorted((a, b) => b.start - a.start);\n let code = file === source.file ? source.code : source.read(file);\n let floor = Infinity;\n for (const edit of sorted) {\n if (edit.end > floor) throw new Error(`deictic: edits to ${file} overlap at ${edit.end}`);\n code = code.slice(0, edit.start) + edit.text + code.slice(edit.end);\n floor = edit.start;\n }\n out.set(file, code);\n }\n return out;\n}\n","/**\n * Every change deictic made, to undo and redo. A change to files holds each file's whole text\n * before and after: source files are small, and the texts make undo exact without a diff to go stale.\n * A change a plugin made itself (`Done`) holds the plugin's name and its record, and undoing it is the\n * plugin's `undo`.\n *\n * Each change has a scope, the plugin and the element it was made on, and the popup undoes and redoes\n * within its own: the latest change of this tab on this element, not the latest of all. So a change\n * is taken back out of order, with later ones to the same file still in it. Then only the lines the\n * change wrote go back to what they were, where they're still in the file as it wrote them, once.\n *\n * Anything else is refused, not merged: a file whose lines were edited since has the editor's own undo\n * for it; and a redo likewise. A plugin's undo refuses on its own terms. Kept under `.deictic`, so it\n * outlives a restart of the dev server and stays out of git.\n */\nimport { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';\nimport { dirname } from 'node:path';\n\nimport { Refusal, type ServerPlugin } from '#src/index.ts';\n\nimport { keptIn } from './kept.ts';\nimport { resolveFile } from './source.ts';\n\nexport interface FileChange {\n file: string;\n /** The text before, or nothing for a file the change made. */\n before: string | null;\n after: string;\n}\n\n/** Whose a change is: the plugin whose tab made it, and the element it was open on, as `file:line:column`. */\nexport interface Scope {\n plugin: string;\n target: string;\n}\n\ninterface Base {\n id: number;\n at: string;\n label: string;\n /** None on a change made without one, which only an undo of the whole history reaches. */\n scope?: Scope;\n}\n\nexport type Change = Base & ({ files: FileChange[] } | { plugin: string; record: unknown });\n\n/** A change as the page lists it. `files` is empty for one a plugin made itself. */\nexport interface Summary {\n id: number;\n at: string;\n label: string;\n files: string[];\n}\n\nexport interface HistoryOptions {\n /** Whose `undo` and `redo` take back the changes they made themselves. */\n plugins?: ServerPlugin[];\n store?: string;\n}\n\nconst LIMIT = 200;\n\n/** Whether a change is in a scope: any is in none. */\nconst within = (scope: Scope | undefined) => (c: Change) =>\n scope === undefined || (c.scope?.plugin === scope.plugin && c.scope.target === scope.target);\n\nconst summary = (c: Change): Summary => ({ id: c.id, at: c.at, label: c.label, files: 'files' in c ? c.files.map((f) => f.file) : [] });\n\nexport class History {\n #done: Change[] = [];\n #undone: Change[] = [];\n readonly #root: string;\n readonly #store: string;\n readonly #plugins: Map<string, ServerPlugin>;\n\n constructor(root: string, { plugins = [], store = keptIn(root, 'history.json') }: HistoryOptions = {}) {\n this.#root = root;\n this.#store = store;\n this.#plugins = new Map(plugins.map((p) => [p.name, p]));\n if (!existsSync(store)) return;\n try {\n ({ done: this.#done, undone: this.#undone } = JSON.parse(readFileSync(store, 'utf8')) as { done: Change[]; undone: Change[] });\n } catch {\n // A history that doesn't read is one we start over, not one to stop the dev server for.\n }\n }\n\n /** Writes each file's new text and records it as one change. A redo after it, in its scope, is gone, as in any editor. */\n commit(label: string, texts: Map<string, string>, scope?: Scope): Summary {\n const files: FileChange[] = [];\n for (const [file, after] of texts) {\n const path = resolveFile(this.#root, file);\n const before = existsSync(path) ? readFileSync(path, 'utf8') : null;\n if (before !== after) files.push({ file, before, after });\n }\n if (files.length === 0) throw new Refusal('nothing to change: the source already says that');\n for (const f of files) write(resolveFile(this.#root, f.file), f.after);\n return this.#push({ label, files }, scope);\n }\n\n /** Records a change `plugin` made itself, with what its `undo` needs. */\n record(label: string, plugin: string, record: unknown, scope?: Scope): Summary {\n return this.#push({ label, plugin, record }, scope);\n }\n\n /** Takes back the latest change, of a scope where one is given. */\n async undo(scope?: Scope): Promise<Summary> {\n const change = this.#done.findLast(within(scope));\n if (change === undefined) throw new Refusal(scope === undefined ? 'nothing to undo' : 'nothing to undo here');\n if ('files' in change) this.#put(change, 'after', 'before');\n else change.record = (await this.#pluginOf(change, 'undo').undo!(change.record)) ?? change.record;\n this.#done = this.#done.filter((c) => c !== change);\n this.#undone.push(change);\n this.#save();\n return summary(change);\n }\n\n /** Makes the change last undone again, of a scope where one is given. */\n async redo(scope?: Scope): Promise<Summary> {\n const change = this.#undone.findLast(within(scope));\n if (change === undefined) throw new Refusal(scope === undefined ? 'nothing to redo' : 'nothing to redo here');\n if ('files' in change) this.#put(change, 'before', 'after');\n else change.record = await this.#pluginOf(change, 'redo').redo!(change.record);\n this.#undone = this.#undone.filter((c) => c !== change);\n this.#done.push(change);\n this.#save();\n return summary(change);\n }\n\n list(scope?: Scope): { done: Summary[]; undone: Summary[] } {\n return { done: this.#done.filter(within(scope)).map(summary), undone: this.#undone.filter(within(scope)).map(summary) };\n }\n\n #push(change: Omit<Base, 'id' | 'at'> & ({ files: FileChange[] } | { plugin: string; record: unknown }), scope?: Scope): Summary {\n const id = Math.max(0, ...[...this.#done, ...this.#undone].map((c) => c.id)) + 1;\n const made = { id, at: new Date().toISOString(), ...change, ...(scope === undefined ? {} : { scope }) };\n this.#done = [...this.#done, made].slice(-LIMIT);\n // What was undone in this scope can't be redone over the new change; another scope's still can.\n this.#undone = this.#undone.filter((c) => !within(scope)(c));\n this.#save();\n return summary(made);\n }\n\n #pluginOf(change: { label: string; plugin: string }, step: 'undo' | 'redo'): ServerPlugin {\n const plugin = this.#plugins.get(change.plugin);\n if (plugin?.[step] === undefined) {\n throw new Refusal(\n `can't ${step} \"${change.label}\": the ${change.plugin} plugin that made it isn't loaded, so add it back to \\`plugins\\``,\n );\n }\n return plugin;\n }\n\n /**\n * Puts each file's `to` text back, once every one of them still reads as its `from`, or still has the\n * lines that differ as `from` has them: then those lines alone change, and the rest stays as it is now.\n */\n #put(change: Base & { files: FileChange[] }, from: 'before' | 'after', to: 'before' | 'after'): void {\n const paths = change.files.map((f) => resolveFile(this.#root, f.file));\n const texts = change.files.map((f, i) => {\n const now = existsSync(paths[i]!) ? readFileSync(paths[i]!, 'utf8') : null;\n if (now === f[from]) return f[to];\n const text = now === null || f[from] === null || f[to] === null ? undefined : swapped(now, f[from], f[to]);\n if (text === undefined) {\n throw new Refusal(\n `${f.file} changed since \"${change.label}\" ${from === 'after' ? 'was made' : 'was undone'}: use the editor's undo there`,\n );\n }\n return text;\n });\n texts.forEach((text, i) => {\n if (text === null) rmSync(paths[i]!);\n else write(paths[i]!, text);\n });\n }\n\n #save(): void {\n write(this.#store, JSON.stringify({ done: this.#done, undone: this.#undone }));\n }\n}\n\n/**\n * `now` with the lines that differ between `from` and `to` put as `to` has them, where `now` has them as\n * `from` does, in one place only. Nothing where it doesn't (they were edited, or there are two of them), or\n * where `from` has no such lines to find (the change only removed some).\n */\nfunction swapped(now: string, from: string, to: string): string | undefined {\n const [a, b, lines] = [from.split('\\n'), to.split('\\n'), now.split('\\n')];\n let head = 0;\n while (head < a.length && head < b.length && a[head] === b[head]) head++;\n let tail = 0;\n while (tail < a.length - head && tail < b.length - head && a.at(-1 - tail) === b.at(-1 - tail)) tail++;\n const theirs = a.slice(head, a.length - tail);\n if (theirs.length === 0) return undefined;\n const found = lines.flatMap((_, i) => (theirs.every((line, j) => lines[i + j] === line) ? [i] : []));\n if (found.length !== 1) return undefined;\n return [...lines.slice(0, found[0]), ...b.slice(head, b.length - tail), ...lines.slice(found[0]! + theirs.length)].join('\\n');\n}\n\nfunction write(path: string, text: string): void {\n mkdirSync(dirname(path), { recursive: true });\n writeFileSync(path, text);\n}\n","/**\n * The dev server's half of deictic, under `/__deictic/`: `read` and `apply` an op through a\n * plugin, `undo`, `redo` and `history`, and `open`, which opens a place in the editor. Written over\n * `Request` and `Response`, so each integration mounts them its own way (Vite as middleware), and\n * served from the page's own origin, so no token travels to the page. `undo`, `redo` and `history` are a\n * plugin's on an element where the request names them (as the popup does: its tab, its element), and\n * the whole history's where it doesn't.\n *\n * Everything but `open` and `history` writes or may, so only the page itself may send it: a POST of\n * JSON from the same origin, which a form or a script on another site can't send without asking first.\n * `problem` is the page's way to report one (`Problem`): it and the server's own, and any request that fails with\n * something other than a `Refusal`, are said once and handed to the plugins that hear of them (`problems.ts`).\n *\n * Each plugin's own `routes` are under `plugins/<name>/`. A `GET` there reaches the plugin as it\n * comes; anything else only from the page's own origin, in whatever type it sends (an image, say).\n * Nothing is answered before every plugin's `setup` has run.\n */\nimport type { IncomingMessage, ServerResponse } from 'node:http';\n\nimport { type Loc, Refusal, type ServerPlugin, type Source, type Target } from '#src/index.ts';\n\nimport { History, type Scope } from './history.ts';\nimport { missingProblem } from './packages.ts';\nimport { setUp } from './plugins.ts';\nimport { messageOf, problemIn, reporter, stackOf } from './problems.ts';\nimport { applyEdits, resolveFile, sourceAt } from './source.ts';\n\nexport interface EndpointOptions {\n root: string;\n plugins: ServerPlugin[];\n /** The path the endpoints sit under, ending in `/`: `/` by default. */\n base?: string;\n /** Opens a place in the editor: a redirect to the dev server's own launcher. */\n open: (path: string, loc: Loc) => Response | Promise<Response>;\n history?: History;\n}\n\ninterface Body {\n plugin: string;\n target: Target;\n op?: unknown;\n}\n\nconst scopeOf = (plugin: string, { file, line, column }: Loc): Scope => ({ plugin, target: `${file}:${line}:${column}` });\n/** The scope an undo or a redo names, or none for the whole history. */\nconst scopeIn = ({ plugin, target }: Partial<Body>) =>\n plugin === undefined || target === undefined ? undefined : scopeOf(plugin, target.loc);\n\n/** Answers deictic's requests, and nothing for any other path. */\nexport function endpoints({ root, plugins, base = '/', open, history = new History(root, { plugins }) }: EndpointOptions) {\n const byName = new Map(plugins.map((p) => [p.name, p]));\n const prefix = `${base}__deictic/`;\n // What goes wrong that nothing in the page caused: said, and handed to the plugins that hear of it once set up.\n const report = reporter(plugins, () => ready);\n // Started now, awaited by every request: a plugin's API is there before anything asks for it.\n const ready = setUp(root, plugins, report);\n const gone = missingProblem(root, plugins);\n if (gone !== undefined) report(gone);\n\n const pluginOf = (name: string) => {\n const plugin = byName.get(name);\n if (plugin === undefined) throw new Refusal(`no plugin \"${name}\" on the server: is it in the bundler plugin's \\`plugins\\`?`);\n return plugin;\n };\n\n const routes: Record<string, (body: Body) => Promise<unknown>> = {\n read: async ({ plugin, target }) => ({ model: await readOf(pluginOf(plugin), target) }),\n apply: async ({ plugin: name, target, op }) => {\n const plugin = pluginOf(name);\n if (plugin.apply === undefined) throw new Refusal(`${name} changes nothing from its panel: it has no \\`apply\\``);\n const source = sourceOf(target);\n const before = await readOf(plugin, target, source);\n const { file, line } = target.loc;\n const label = `${name} ${file}:${line}: ${plugin.describe?.(op, before) ?? 'edit'}`;\n const result = await plugin.apply(source, target, op);\n const scope = scopeOf(name, target.loc);\n if (!Array.isArray(result)) return { change: history.record(label, name, result.done, scope), model: await readOf(plugin, target) };\n // Edits to a file whose element isn't found would go who knows where: refused, as only they need it.\n if (source instanceof Refusal) throw source;\n const change = history.commit(label, applyEdits(source, result), scope);\n return { model: await readOf(plugin, target), change };\n },\n undo: async (body) => ({ change: await history.undo(scopeIn(body)) }),\n redo: async (body) => ({ change: await history.redo(scopeIn(body)) }),\n };\n // The source or why it can't be had, for the plugin to decide: only an edit to the file needs it, not a task.\n const sourceOf = (target: Target): Source | Refusal => {\n try {\n return sourceAt(root, target);\n } catch (e) {\n if (e instanceof Refusal) return e;\n throw e;\n }\n };\n // A plugin without `read` has no model, and no need for its element to be where the page says.\n const readOf = (plugin: ServerPlugin, target: Target, source?: Source | Refusal) =>\n plugin.read === undefined ? null : plugin.read(source ?? sourceOf(target), target);\n // One write at a time: a plugin's change may wait on the network, and an undo sent meanwhile must\n // take back that change, not the one before it.\n let queue: Promise<unknown> = Promise.resolve();\n const serially = <T>(run: () => Promise<T>): Promise<T> => {\n const next = queue.then(run, run);\n queue = next.catch(() => {});\n return next;\n };\n\n return async (req: Request): Promise<Response | undefined> => {\n const url = new URL(req.url);\n if (!url.pathname.startsWith(prefix)) return undefined;\n const route = url.pathname.slice(prefix.length);\n const origin = req.headers.get('origin');\n const sameOrigin = origin !== null && new URL(origin).host === url.host;\n // What failed, for a problem's key: a plugin's route by its first segment, not the IDs after it.\n let where = route;\n let plugin: string | undefined;\n try {\n const context = await ready;\n if (route.startsWith('plugins/')) {\n const [name = '', first = ''] = route.slice('plugins/'.length).split('/');\n where = `plugins/${name}/${first}`;\n plugin = name;\n const handle = byName.get(name)?.routes?.[first];\n if (handle === undefined) return new Response(`no endpoint ${url.pathname}`, { status: 404 });\n if (req.method !== 'GET' && req.method !== 'HEAD' && !sameOrigin)\n return Response.json({ problem: `only the page itself may ${req.method} to ${name}` }, { status: 403 });\n return await handle(req, context);\n }\n const loc = {\n file: url.searchParams.get('file') ?? '',\n line: Number(url.searchParams.get('line')),\n column: Number(url.searchParams.get('column')),\n };\n if (route === 'history') {\n const plugin = url.searchParams.get('plugin');\n return Response.json(history.list(plugin === null ? undefined : scopeOf(plugin, loc)));\n }\n if (route === 'open') return await open(resolveFile(root, loc.file), loc);\n const handler = routes[route];\n if (handler === undefined && route !== 'problem') return new Response(`no endpoint ${url.pathname}`, { status: 404 });\n if (req.method !== 'POST' || !sameOrigin || req.headers.get('content-type')?.startsWith('application/json') !== true)\n return Response.json({ problem: 'edits come from the page, as JSON' }, { status: 403 });\n if (handler === undefined) {\n const problem = problemIn(await req.json());\n if (problem === undefined) return Response.json({ problem: 'a problem has a key, a kind and a message' }, { status: 400 });\n report(problem);\n return Response.json({});\n }\n const body = (await req.json()) as Body;\n plugin = body.plugin;\n return Response.json(await (route === 'read' ? handler(body) : serially(() => handler(body))));\n } catch (e) {\n if (e instanceof Refusal) return Response.json({ problem: e.message }, { status: 422 });\n // Not a refusal, which says what to do instead: something broke, which no one in the page can fix.\n const message = messageOf(e);\n report({\n key: `error:${where}:${message.split('\\n', 1)[0]!.slice(0, 200)}`,\n kind: 'bug',\n ...(plugin === undefined ? {} : { plugin }),\n message: `${prefix}${where} failed: ${message}`,\n ...stackOf(e),\n });\n return Response.json({ problem: e instanceof Error ? (e.stack ?? e.message) : String(e) }, { status: 500 });\n }\n };\n}\n\n/** A redirect within the page's origin, to a launcher the dev server answers itself. */\nexport const redirect = (path: string) => new Response(null, { status: 307, headers: { Location: path } });\n\n/**\n * The endpoints as Node middleware, for Vite's server. The request's host is the one the page was\n * served from: a proxy's `x-forwarded-host` before its own.\n */\nexport function nodeMiddleware(\n handle: (req: Request) => Promise<Response | undefined>,\n): (req: IncomingMessage, res: ServerResponse, next: () => void) => void {\n return (req, res, next) => {\n // Before reading the body, which a request for anything else leaves to whoever answers it.\n if (req.url?.includes('/__deictic/') !== true) return next();\n const forwarded = req.headers['x-forwarded-host'];\n const host = (Array.isArray(forwarded) ? forwarded[0] : forwarded) ?? req.headers.host ?? 'localhost';\n const headers = new Headers();\n for (const [name, value] of Object.entries(req.headers))\n for (const v of Array.isArray(value) ? value : value === undefined ? [] : [value]) headers.append(name, v);\n\n const chunks: Buffer[] = [];\n req.on('data', (chunk: Buffer) => chunks.push(chunk));\n req.on('end', () => {\n const body = req.method === 'GET' || req.method === 'HEAD' ? undefined : Buffer.concat(chunks);\n handle(new Request(`http://${host}${req.url}`, { method: req.method, headers, body }))\n .then(async (response) => {\n if (response === undefined) return next();\n res.statusCode = response.status;\n response.headers.forEach((value, name) => res.setHeader(name, value));\n res.end(Buffer.from(await response.arrayBuffer()));\n })\n .catch((e: unknown) => {\n res.statusCode = 500;\n res.end(e instanceof Error ? e.message : String(e));\n });\n });\n };\n}\n"],"mappings":";;;;;;;;;;;;AAaA,SAAgB,YAAY,MAAc,MAAsB;CAC9D,MAAM,OAAO,QAAQ,MAAM,IAAI;CAC/B,MAAM,OAAO,SAAS,MAAM,IAAI;CAEhC,IAAI,SAAS,MAAM,KAAK,WAAW,IAAI,KAAK,WAAW,IAAI,KAAK,KAAK,MAAM,GAAG,CAAC,CAAC,SAAS,cAAc,GACrG,MAAM,IAAI,QAAQ,GAAG,KAAK,qCAAqC;CACjE,OAAO;AACT;AAEA,SAAgB,WAAW,MAAc,MAAsB;CAC7D,IAAI;EACF,OAAO,aAAa,YAAY,MAAM,IAAI,GAAG,MAAM;CACrD,SAAS,GAAG;EACV,IAAI,aAAa,SAAS,MAAM;EAChC,MAAM,IAAI,QAAQ,cAAc,KAAK,wCAAwC,EAAE,OAAO,EAAE,CAAC;CAC3F;AACF;;;;;AAMA,SAAgB,SAAS,MAAc,QAAwB;CAC7D,MAAM,EAAE,MAAM,MAAM,WAAW,OAAO;CACtC,MAAM,OAAO,WAAW,MAAM,IAAI;CAClC,MAAM,QAAQ,WAAW,IAAI;CAC7B,MAAM,SAAS,SAAS,OAAO,MAAM,MAAM;CAC3C,MAAM,EAAE,SAAS,aAAa,MAAM,KAAK,IAAI,IAAI,MAAM,MAAM,MAAM,IAAI,IAAI,IAAI,MAAM,IAAI;CACzF,MAAM,SAAS,SAAS,QAAQ,OAAO,OAAO,EAAE,KAAK,GAAG,KAAK,SAAS,mBAAmB,GAAG,KAAK,SAAS,OAAO,GAAG;CACpH,MAAM,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Q,IAAI;IAAQ;IAAS;GAAK,CAAC,CAAC,CAAC,CACnF,KAAK,OAAO,aAAa;IACxB,IAAI,aAAa,KAAA,GAAW,OAAO,KAAK;IACxC,IAAI,aAAa,SAAS;IAC1B,SAAS,QAAQ,SAAS,OAAO,SAAS,IAAI,UAAU,MAAM,KAAK,CAAC;IACpE,IAAI,IAAI,OAAO,KAAK,MAAM,SAAS,YAAY,CAAC,CAAC;GACnD,CAAC,CAAC,CACD,OAAO,MAAe;IACrB,IAAI,aAAa;IACjB,IAAI,IAAI,aAAa,QAAQ,EAAE,UAAU,OAAO,CAAC,CAAC;GACpD,CAAC;EACL,CAAC;CACH;AACF"}
|
|
1
|
+
{"version":3,"file":"endpoints.js","names":[],"sources":["../../src/tools/source.ts","../../src/tools/history.ts","../../src/tools/endpoints.ts"],"sourcesContent":["/**\n * The source a server half reads: a target's file, parsed, and the opening tag the page's attribute\n * points at. Files are only ever read and written under the project's root, outside `node_modules`.\n */\nimport { readFileSync } from 'node:fs';\nimport { isAbsolute, relative, resolve, sep } from 'node:path';\n\nimport { Refusal, type Source, type Target, type TextEdit } from '#src/index.ts';\n\nimport { ASTRO, parseAstro, type Parsed } from './astro.ts';\nimport { isHost, lineStarts, offsetOf, openingsIn, parse } from './locate.ts';\n\n/** A file from the project's root, as an absolute path; refused anywhere the page has no business writing. */\nexport function resolveFile(root: string, file: string): string {\n const path = resolve(root, file);\n const from = relative(root, path);\n // `relative` gives an absolute path for another drive.\n if (from === '' || from.startsWith('..') || isAbsolute(from) || from.split(sep).includes('node_modules'))\n throw new Refusal(`${file} is not a file of this project's own`);\n return path;\n}\n\nexport function readSource(root: string, file: string): string {\n try {\n return readFileSync(resolveFile(root, file), 'utf8');\n } catch (e) {\n if (e instanceof Refusal) throw e;\n throw new Refusal(`can't read ${file}: has it moved since the page loaded?`, { cause: e });\n }\n}\n\n/**\n * The target's file and element, as they are on disk now. The element is the one the page's mark names, or else the\n * only one of its tag on that line: the page may count columns in code a plugin before deictic's changed.\n */\nexport function sourceAt(root: string, target: Target): Source {\n const { file, line, column } = target.loc;\n const code = readSource(root, file);\n const lines = lineStarts(code);\n const offset = offsetOf(lines, line, column);\n const { program, elements } = ASTRO.test(file) ? astro(root, file, code) : jsx(file, code);\n const tagged = elements.filter((el) => isHost(el) && el.name.type === 'JSXIdentifier' && el.name.name === target.tag);\n const start = lines[line - 1];\n const onLine = start === undefined ? [] : tagged.filter((el) => el.start >= start && el.start < (lines[line] ?? Infinity));\n const element = tagged.find((el) => el.start === offset) ?? (onLine.length === 1 ? onLine[0] : undefined);\n if (element === undefined) throw new Refusal(notThere(target, code, lines, onLine.length));\n return { file, code, program, element, read: (other) => readSource(root, other) };\n}\n\n/** Why the page's element isn't in the file, from what the file has there: it may not have changed at all. */\nfunction notThere({ loc: { file, line, column }, tag }: Target, code: string, lines: number[], onLine: number): string {\n const start = lines[line - 1];\n const found =\n start === undefined\n ? `${file} has no line ${line}`\n : onLine === 0\n ? `line ${line} of ${file} has no <${tag}>: it reads \\`${clip(code.slice(start, (lines[line] ?? code.length + 1) - 1).trim())}\\``\n : `line ${line} of ${file} has ${onLine} <${tag}>s, none at column ${column}`;\n return `${found}. The page isn't running the file as it is: reload it, and if it says this again, a plugin before deictic's changes the file, so put deictic first`;\n}\n\nconst clip = (text: string) => (text.length > 80 ? `${text.slice(0, 79)}…` : text);\n\nfunction jsx(file: string, code: string): Parsed {\n const { program, errors } = parse(file, code);\n if (errors.length > 0) throw new Refusal(`${file} doesn't parse: fix it first (${errors[0]!.message})`);\n return { program, elements: openingsIn(program) };\n}\n\nfunction astro(root: string, file: string, code: string): Parsed {\n const parsed = parseAstro(root, code);\n if ('problem' in parsed) throw new Refusal(`${file} can't be read: ${parsed.problem}`);\n return parsed;\n}\n\n/**\n * Each file's text after its edits, which must not overlap. A file that isn't there is made where every edit to it is\n * at its start (a locale's first translation, say); any other edit to one is refused.\n */\nexport function applyEdits(source: Source, edits: TextEdit[]): Map<string, string> {\n const byFile = Map.groupBy(edits, (e) => e.file ?? source.file);\n const out = new Map<string, string>();\n for (const [file, list] of byFile) {\n const sorted = list.toSorted((a, b) => b.start - a.start);\n let code = file === source.file ? source.code : textOf(source, file, list);\n let floor = Infinity;\n for (const edit of sorted) {\n if (edit.end > floor) throw new Error(`deictic: edits to ${file} overlap at ${edit.end}`);\n code = code.slice(0, edit.start) + edit.text + code.slice(edit.end);\n floor = edit.start;\n }\n out.set(file, code);\n }\n return out;\n}\n\nfunction textOf(source: Source, file: string, edits: TextEdit[]): string {\n try {\n return source.read(file);\n } catch (e) {\n if (e instanceof Refusal && e.cause !== undefined && edits.every((edit) => edit.start === 0 && edit.end === 0)) return '';\n throw e;\n }\n}\n","/**\n * Every change deictic made, to undo and redo. A change to files holds each file's whole text\n * before and after: source files are small, and the texts make undo exact without a diff to go stale.\n * A change a plugin made itself (`Done`) holds the plugin's name and its record, and undoing it is the\n * plugin's `undo`.\n *\n * Each change has a scope, the plugin and the element it was made on, and the popup undoes and redoes\n * within its own: the latest change of this tab on this element, not the latest of all. So a change\n * is taken back out of order, with later ones to the same file still in it. Then only the lines the\n * change wrote go back to what they were, where they're still in the file as it wrote them, once.\n *\n * Anything else is refused, not merged: a file whose lines were edited since has the editor's own undo\n * for it; and a redo likewise. A plugin's undo refuses on its own terms. Kept under `.deictic`, so it\n * outlives a restart of the dev server and stays out of git.\n */\nimport { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';\nimport { dirname } from 'node:path';\n\nimport { Refusal, type ServerPlugin } from '#src/index.ts';\n\nimport { keptIn } from './kept.ts';\nimport { resolveFile } from './source.ts';\n\nexport interface FileChange {\n file: string;\n /** The text before, or nothing for a file the change made. */\n before: string | null;\n after: string;\n}\n\n/** Whose a change is: the plugin whose tab made it, and the element it was open on, as `file:line:column`. */\nexport interface Scope {\n plugin: string;\n target: string;\n}\n\ninterface Base {\n id: number;\n at: string;\n label: string;\n /** None on a change made without one, which only an undo of the whole history reaches. */\n scope?: Scope;\n}\n\nexport type Change = Base & ({ files: FileChange[] } | { plugin: string; record: unknown });\n\n/** A change as the page lists it. `files` is empty for one a plugin made itself. */\nexport interface Summary {\n id: number;\n at: string;\n label: string;\n files: string[];\n}\n\nexport interface HistoryOptions {\n /** Whose `undo` and `redo` take back the changes they made themselves. */\n plugins?: ServerPlugin[];\n store?: string;\n}\n\nconst LIMIT = 200;\n\n/** Whether a change is in a scope: any is in none. */\nconst within = (scope: Scope | undefined) => (c: Change) =>\n scope === undefined || (c.scope?.plugin === scope.plugin && c.scope.target === scope.target);\n\nconst summary = (c: Change): Summary => ({ id: c.id, at: c.at, label: c.label, files: 'files' in c ? c.files.map((f) => f.file) : [] });\n\nexport class History {\n #done: Change[] = [];\n #undone: Change[] = [];\n readonly #root: string;\n readonly #store: string;\n readonly #plugins: Map<string, ServerPlugin>;\n\n constructor(root: string, { plugins = [], store = keptIn(root, 'history.json') }: HistoryOptions = {}) {\n this.#root = root;\n this.#store = store;\n this.#plugins = new Map(plugins.map((p) => [p.name, p]));\n if (!existsSync(store)) return;\n try {\n ({ done: this.#done, undone: this.#undone } = JSON.parse(readFileSync(store, 'utf8')) as { done: Change[]; undone: Change[] });\n } catch {\n // A history that doesn't read is one we start over, not one to stop the dev server for.\n }\n }\n\n /** Writes each file's new text and records it as one change. A redo after it, in its scope, is gone, as in any editor. */\n commit(label: string, texts: Map<string, string>, scope?: Scope): Summary {\n const files: FileChange[] = [];\n for (const [file, after] of texts) {\n const path = resolveFile(this.#root, file);\n const before = existsSync(path) ? readFileSync(path, 'utf8') : null;\n if (before !== after) files.push({ file, before, after });\n }\n if (files.length === 0) throw new Refusal('nothing to change: the source already says that');\n for (const f of files) write(resolveFile(this.#root, f.file), f.after);\n return this.#push({ label, files }, scope);\n }\n\n /** Records a change `plugin` made itself, with what its `undo` needs. */\n record(label: string, plugin: string, record: unknown, scope?: Scope): Summary {\n return this.#push({ label, plugin, record }, scope);\n }\n\n /** Takes back the latest change, of a scope where one is given. */\n async undo(scope?: Scope): Promise<Summary> {\n const change = this.#done.findLast(within(scope));\n if (change === undefined) throw new Refusal(scope === undefined ? 'nothing to undo' : 'nothing to undo here');\n if ('files' in change) this.#put(change, 'after', 'before');\n else change.record = (await this.#pluginOf(change, 'undo').undo!(change.record)) ?? change.record;\n this.#done = this.#done.filter((c) => c !== change);\n this.#undone.push(change);\n this.#save();\n return summary(change);\n }\n\n /** Makes the change last undone again, of a scope where one is given. */\n async redo(scope?: Scope): Promise<Summary> {\n const change = this.#undone.findLast(within(scope));\n if (change === undefined) throw new Refusal(scope === undefined ? 'nothing to redo' : 'nothing to redo here');\n if ('files' in change) this.#put(change, 'before', 'after');\n else change.record = await this.#pluginOf(change, 'redo').redo!(change.record);\n this.#undone = this.#undone.filter((c) => c !== change);\n this.#done.push(change);\n this.#save();\n return summary(change);\n }\n\n list(scope?: Scope): { done: Summary[]; undone: Summary[] } {\n return { done: this.#done.filter(within(scope)).map(summary), undone: this.#undone.filter(within(scope)).map(summary) };\n }\n\n #push(change: Omit<Base, 'id' | 'at'> & ({ files: FileChange[] } | { plugin: string; record: unknown }), scope?: Scope): Summary {\n const id = Math.max(0, ...[...this.#done, ...this.#undone].map((c) => c.id)) + 1;\n const made = { id, at: new Date().toISOString(), ...change, ...(scope === undefined ? {} : { scope }) };\n this.#done = [...this.#done, made].slice(-LIMIT);\n // What was undone in this scope can't be redone over the new change; another scope's still can.\n this.#undone = this.#undone.filter((c) => !within(scope)(c));\n this.#save();\n return summary(made);\n }\n\n #pluginOf(change: { label: string; plugin: string }, step: 'undo' | 'redo'): ServerPlugin {\n const plugin = this.#plugins.get(change.plugin);\n if (plugin?.[step] === undefined) {\n throw new Refusal(\n `can't ${step} \"${change.label}\": the ${change.plugin} plugin that made it isn't loaded, so add it back to \\`plugins\\``,\n );\n }\n return plugin;\n }\n\n /**\n * Puts each file's `to` text back, once every one of them still reads as its `from`, or still has the\n * lines that differ as `from` has them: then those lines alone change, and the rest stays as it is now.\n */\n #put(change: Base & { files: FileChange[] }, from: 'before' | 'after', to: 'before' | 'after'): void {\n const paths = change.files.map((f) => resolveFile(this.#root, f.file));\n const texts = change.files.map((f, i) => {\n const now = existsSync(paths[i]!) ? readFileSync(paths[i]!, 'utf8') : null;\n if (now === f[from]) return f[to];\n const text = now === null || f[from] === null || f[to] === null ? undefined : swapped(now, f[from], f[to]);\n if (text === undefined) {\n throw new Refusal(\n `${f.file} changed since \"${change.label}\" ${from === 'after' ? 'was made' : 'was undone'}: use the editor's undo there`,\n );\n }\n return text;\n });\n texts.forEach((text, i) => {\n if (text === null) rmSync(paths[i]!);\n else write(paths[i]!, text);\n });\n }\n\n #save(): void {\n write(this.#store, JSON.stringify({ done: this.#done, undone: this.#undone }));\n }\n}\n\n/**\n * `now` with the lines that differ between `from` and `to` put as `to` has them, where `now` has them as\n * `from` does, in one place only. Nothing where it doesn't (they were edited, or there are two of them), or\n * where `from` has no such lines to find (the change only removed some).\n */\nfunction swapped(now: string, from: string, to: string): string | undefined {\n const [a, b, lines] = [from.split('\\n'), to.split('\\n'), now.split('\\n')];\n let head = 0;\n while (head < a.length && head < b.length && a[head] === b[head]) head++;\n let tail = 0;\n while (tail < a.length - head && tail < b.length - head && a.at(-1 - tail) === b.at(-1 - tail)) tail++;\n const theirs = a.slice(head, a.length - tail);\n if (theirs.length === 0) return undefined;\n const found = lines.flatMap((_, i) => (theirs.every((line, j) => lines[i + j] === line) ? [i] : []));\n if (found.length !== 1) return undefined;\n return [...lines.slice(0, found[0]), ...b.slice(head, b.length - tail), ...lines.slice(found[0]! + theirs.length)].join('\\n');\n}\n\nfunction write(path: string, text: string): void {\n mkdirSync(dirname(path), { recursive: true });\n writeFileSync(path, text);\n}\n","/**\n * The dev server's half of deictic, under `/__deictic/`: `read` and `apply` an op through a\n * plugin, `undo`, `redo` and `history`, and `open`, which opens a place in the editor. Written over\n * `Request` and `Response`, so each integration mounts them its own way (Vite as middleware), and\n * served from the page's own origin, so no token travels to the page. `undo`, `redo` and `history` are a\n * plugin's on an element where the request names them (as the popup does: its tab, its element), and\n * the whole history's where it doesn't.\n *\n * Everything but `open` and `history` writes or may, so only the page itself may send it: a POST of\n * JSON from the same origin, which a form or a script on another site can't send without asking first.\n * `problem` is the page's way to report one (`Problem`): it and the server's own, and any request that fails with\n * something other than a `Refusal`, are said once and handed to the plugins that hear of them (`problems.ts`).\n *\n * Each plugin's own `routes` are under `plugins/<name>/`. A `GET` there reaches the plugin as it\n * comes; anything else only from the page's own origin, in whatever type it sends (an image, say).\n * Nothing is answered before every plugin's `setup` has run.\n */\nimport type { IncomingMessage, ServerResponse } from 'node:http';\n\nimport { type Loc, Refusal, type ServerPlugin, type Source, type Target } from '#src/index.ts';\n\nimport { History, type Scope } from './history.ts';\nimport { missingProblem } from './packages.ts';\nimport { setUp } from './plugins.ts';\nimport { messageOf, problemIn, reporter, stackOf } from './problems.ts';\nimport { applyEdits, resolveFile, sourceAt } from './source.ts';\n\nexport interface EndpointOptions {\n root: string;\n plugins: ServerPlugin[];\n /** The path the endpoints sit under, ending in `/`: `/` by default. */\n base?: string;\n /** Opens a place in the editor: a redirect to the dev server's own launcher. */\n open: (path: string, loc: Loc) => Response | Promise<Response>;\n history?: History;\n}\n\ninterface Body {\n plugin: string;\n target: Target;\n op?: unknown;\n}\n\nconst scopeOf = (plugin: string, { file, line, column }: Loc): Scope => ({ plugin, target: `${file}:${line}:${column}` });\n/** The scope an undo or a redo names, or none for the whole history. */\nconst scopeIn = ({ plugin, target }: Partial<Body>) =>\n plugin === undefined || target === undefined ? undefined : scopeOf(plugin, target.loc);\n\n/** Answers deictic's requests, and nothing for any other path. */\nexport function endpoints({ root, plugins, base = '/', open, history = new History(root, { plugins }) }: EndpointOptions) {\n const byName = new Map(plugins.map((p) => [p.name, p]));\n const prefix = `${base}__deictic/`;\n // What goes wrong that nothing in the page caused: said, and handed to the plugins that hear of it once set up.\n const report = reporter(plugins, () => ready);\n // Started now, awaited by every request: a plugin's API is there before anything asks for it.\n const ready = setUp(root, plugins, report);\n const gone = missingProblem(root, plugins);\n if (gone !== undefined) report(gone);\n\n const pluginOf = (name: string) => {\n const plugin = byName.get(name);\n if (plugin === undefined) throw new Refusal(`no plugin \"${name}\" on the server: is it in the bundler plugin's \\`plugins\\`?`);\n return plugin;\n };\n\n const routes: Record<string, (body: Body) => Promise<unknown>> = {\n read: async ({ plugin, target }) => ({ model: await readOf(pluginOf(plugin), target) }),\n apply: async ({ plugin: name, target, op }) => {\n const plugin = pluginOf(name);\n if (plugin.apply === undefined) throw new Refusal(`${name} changes nothing from its panel: it has no \\`apply\\``);\n const source = sourceOf(target);\n const before = await readOf(plugin, target, source);\n const { file, line } = target.loc;\n const label = `${name} ${file}:${line}: ${plugin.describe?.(op, before) ?? 'edit'}`;\n const result = await plugin.apply(source, target, op);\n const scope = scopeOf(name, target.loc);\n if (!Array.isArray(result)) return { change: history.record(label, name, result.done, scope), model: await readOf(plugin, target) };\n // Edits to a file whose element isn't found would go who knows where: refused, as only they need it.\n if (source instanceof Refusal) throw source;\n const change = history.commit(label, applyEdits(source, result), scope);\n return { model: await readOf(plugin, target), change };\n },\n undo: async (body) => ({ change: await history.undo(scopeIn(body)) }),\n redo: async (body) => ({ change: await history.redo(scopeIn(body)) }),\n };\n // The source or why it can't be had, for the plugin to decide: only an edit to the file needs it, not a task.\n const sourceOf = (target: Target): Source | Refusal => {\n try {\n return sourceAt(root, target);\n } catch (e) {\n if (e instanceof Refusal) return e;\n throw e;\n }\n };\n // A plugin without `read` has no model, and no need for its element to be where the page says.\n const readOf = (plugin: ServerPlugin, target: Target, source?: Source | Refusal) =>\n plugin.read === undefined ? null : plugin.read(source ?? sourceOf(target), target);\n // One write at a time: a plugin's change may wait on the network, and an undo sent meanwhile must\n // take back that change, not the one before it.\n let queue: Promise<unknown> = Promise.resolve();\n const serially = <T>(run: () => Promise<T>): Promise<T> => {\n const next = queue.then(run, run);\n queue = next.catch(() => {});\n return next;\n };\n\n return async (req: Request): Promise<Response | undefined> => {\n const url = new URL(req.url);\n if (!url.pathname.startsWith(prefix)) return undefined;\n const route = url.pathname.slice(prefix.length);\n const origin = req.headers.get('origin');\n const sameOrigin = origin !== null && new URL(origin).host === url.host;\n // What failed, for a problem's key: a plugin's route by its first segment, not the IDs after it.\n let where = route;\n let plugin: string | undefined;\n try {\n const context = await ready;\n if (route.startsWith('plugins/')) {\n const [name = '', first = ''] = route.slice('plugins/'.length).split('/');\n where = `plugins/${name}/${first}`;\n plugin = name;\n const handle = byName.get(name)?.routes?.[first];\n if (handle === undefined) return new Response(`no endpoint ${url.pathname}`, { status: 404 });\n if (req.method !== 'GET' && req.method !== 'HEAD' && !sameOrigin)\n return Response.json({ problem: `only the page itself may ${req.method} to ${name}` }, { status: 403 });\n return await handle(req, context);\n }\n const loc = {\n file: url.searchParams.get('file') ?? '',\n line: Number(url.searchParams.get('line')),\n column: Number(url.searchParams.get('column')),\n };\n if (route === 'history') {\n const plugin = url.searchParams.get('plugin');\n return Response.json(history.list(plugin === null ? undefined : scopeOf(plugin, loc)));\n }\n if (route === 'open') return await open(resolveFile(root, loc.file), loc);\n const handler = routes[route];\n if (handler === undefined && route !== 'problem') return new Response(`no endpoint ${url.pathname}`, { status: 404 });\n if (req.method !== 'POST' || !sameOrigin || req.headers.get('content-type')?.startsWith('application/json') !== true)\n return Response.json({ problem: 'edits come from the page, as JSON' }, { status: 403 });\n if (handler === undefined) {\n const problem = problemIn(await req.json());\n if (problem === undefined) return Response.json({ problem: 'a problem has a key, a kind and a message' }, { status: 400 });\n report(problem);\n return Response.json({});\n }\n const body = (await req.json()) as Body;\n plugin = body.plugin;\n return Response.json(await (route === 'read' ? handler(body) : serially(() => handler(body))));\n } catch (e) {\n if (e instanceof Refusal) return Response.json({ problem: e.message }, { status: 422 });\n // Not a refusal, which says what to do instead: something broke, which no one in the page can fix.\n const message = messageOf(e);\n report({\n key: `error:${where}:${message.split('\\n', 1)[0]!.slice(0, 200)}`,\n kind: 'bug',\n ...(plugin === undefined ? {} : { plugin }),\n message: `${prefix}${where} failed: ${message}`,\n ...stackOf(e),\n });\n return Response.json({ problem: e instanceof Error ? (e.stack ?? e.message) : String(e) }, { status: 500 });\n }\n };\n}\n\n/** A redirect within the page's origin, to a launcher the dev server answers itself. */\nexport const redirect = (path: string) => new Response(null, { status: 307, headers: { Location: path } });\n\n/**\n * The endpoints as Node middleware, for Vite's server. The request's host is the one the page was\n * served from: a proxy's `x-forwarded-host` before its own.\n */\nexport function nodeMiddleware(\n handle: (req: Request) => Promise<Response | undefined>,\n): (req: IncomingMessage, res: ServerResponse, next: () => void) => void {\n return (req, res, next) => {\n // Before reading the body, which a request for anything else leaves to whoever answers it.\n if (req.url?.includes('/__deictic/') !== true) return next();\n const forwarded = req.headers['x-forwarded-host'];\n const host = (Array.isArray(forwarded) ? forwarded[0] : forwarded) ?? req.headers.host ?? 'localhost';\n const headers = new Headers();\n for (const [name, value] of Object.entries(req.headers))\n for (const v of Array.isArray(value) ? value : value === undefined ? [] : [value]) headers.append(name, v);\n\n const chunks: Buffer[] = [];\n req.on('data', (chunk: Buffer) => chunks.push(chunk));\n req.on('end', () => {\n const body = req.method === 'GET' || req.method === 'HEAD' ? undefined : Buffer.concat(chunks);\n handle(new Request(`http://${host}${req.url}`, { method: req.method, headers, body }))\n .then(async (response) => {\n if (response === undefined) return next();\n res.statusCode = response.status;\n response.headers.forEach((value, name) => res.setHeader(name, value));\n res.end(Buffer.from(await response.arrayBuffer()));\n })\n .catch((e: unknown) => {\n res.statusCode = 500;\n res.end(e instanceof Error ? e.message : String(e));\n });\n });\n };\n}\n"],"mappings":";;;;;;;;;;;;AAaA,SAAgB,YAAY,MAAc,MAAsB;CAC9D,MAAM,OAAO,QAAQ,MAAM,IAAI;CAC/B,MAAM,OAAO,SAAS,MAAM,IAAI;CAEhC,IAAI,SAAS,MAAM,KAAK,WAAW,IAAI,KAAK,WAAW,IAAI,KAAK,KAAK,MAAM,GAAG,CAAC,CAAC,SAAS,cAAc,GACrG,MAAM,IAAI,QAAQ,GAAG,KAAK,qCAAqC;CACjE,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aAAa,QAAQ,EAAE,UAAU,OAAO,CAAC,CAAC;GACpD,CAAC;EACL,CAAC;CACH;AACF"}
|
package/dist/shared/index.d.ts
CHANGED
|
@@ -256,6 +256,11 @@ interface ClientContext {
|
|
|
256
256
|
request: (route: string, init?: RequestInit) => Promise<Response>;
|
|
257
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
258
|
report: (problem: Problem) => void;
|
|
259
|
+
/**
|
|
260
|
+
* Opens a place in a file under the root in the editor, as the popup's own link opens the element's: through the
|
|
261
|
+
* dev server, or what answers in its place (`Standalone`). Rejects with why it couldn't.
|
|
262
|
+
*/
|
|
263
|
+
edit: (place: Loc) => Promise<void>;
|
|
259
264
|
/**
|
|
260
265
|
* Opens the popup on an element at a plugin's tab, as its shortcut would, or with `at` on a spot in it: the
|
|
261
266
|
* popup is then beside the spot, which is what's lit, and the tab's context has it. An element rendered again
|
|
@@ -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;;EAET,SAAS;;EAET,KAAK;;;;;;;KAQK,cAAc,SAAS,YAAY,WAAW,QAAQ;;cAGrD,gBAAgB;EAClB;;;;;;UAOM,KAAK;EACpB,MAAM;;KAGH,MAAM,KAAK,IAAI,QAAQ;;;;;;UAOX;;;;;EAKf;;;;;EAKA;;EAEA;;EAEA;;EAEA;;;;;;UAQe;;UAIA;;KAGL,MAAM,MAAM,uBAAuB,mBAAmB,OAAO,KAAK;UAE7D;;EAEf;;;;;EAKA,MAAM,qBAAqB,MAAM,SAAS,MAAM,YAAY;;EAE5D,SAAS,SAAS;;;;;;KAOR,SAAS,SAAS,SAAS,SAAS,kBAAkB,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
|
|
|
9
9
|
* `false` for none, leaving only plugins' own shortcuts.
|
|
10
10
|
*/
|
|
11
11
|
shortcut?: Shortcut | false;
|
|
12
|
+
/**
|
|
13
|
+
* For a package that adds its own plugin to the bundler with deictic (prosebook does): these options give way to
|
|
14
|
+
* those of any other deictic in the same build, which merges them in, so the app's own `deictic()` decides the
|
|
15
|
+
* shortcut and its plugin of the same name is the one loaded.
|
|
16
|
+
*/
|
|
17
|
+
defaults?: boolean;
|
|
12
18
|
}
|
|
13
19
|
/**
|
|
14
20
|
* The client module: the overlay, started with deictic's own shortcut and each plugin that has a half
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"integration.d.ts","names":[],"sources":["../../src/tools/integration.ts"],"mappings":";;;UAmBiB;;EAEf,UAAU;;;;;EAKV,WAAW;;;;;;;
|
|
1
|
+
{"version":3,"file":"integration.d.ts","names":[],"sources":["../../src/tools/integration.ts"],"mappings":";;;UAmBiB;;EAEf,UAAU;;;;;EAKV,WAAW;;;;;;EAMX;;;;;;;cA0CW,eAAY,SAAa,gBAAc,cAAc,MAAQ,kBAAgB"}
|
|
@@ -247,6 +247,33 @@ async function setUp(root, plugins, report) {
|
|
|
247
247
|
* under Vite, a file in `.deictic/` elsewhere, as webpack, Turbopack and Bun have none), where the
|
|
248
248
|
* endpoints are served, and what opens the editor.
|
|
249
249
|
*/
|
|
250
|
+
/**
|
|
251
|
+
* Every deictic one build was given, as one: the app's and those packages added (`defaults`). The plugins of all of
|
|
252
|
+
* them, each name once, the first given winning, those of an instance with `defaults` after the rest's; any other
|
|
253
|
+
* option from the first that sets it, the same way. Two that aren't `defaults` setting one differently is an error,
|
|
254
|
+
* as neither can be the one meant.
|
|
255
|
+
*/
|
|
256
|
+
function merge(instances) {
|
|
257
|
+
const ordered = [...instances.filter((o) => o.defaults !== true), ...instances.filter((o) => o.defaults === true)];
|
|
258
|
+
const plugins = /* @__PURE__ */ new Map();
|
|
259
|
+
const merged = {};
|
|
260
|
+
const setBy = {};
|
|
261
|
+
for (const options of ordered) {
|
|
262
|
+
for (const plugin of options.plugins ?? []) if (!plugins.has(plugin.name)) plugins.set(plugin.name, plugin);
|
|
263
|
+
for (const [key, value] of Object.entries(options)) {
|
|
264
|
+
if (key === "plugins" || key === "defaults" || value === void 0) continue;
|
|
265
|
+
const first = setBy[key];
|
|
266
|
+
if (first === void 0) {
|
|
267
|
+
merged[key] = value;
|
|
268
|
+
setBy[key] = options;
|
|
269
|
+
} else if (first.defaults !== true && options.defaults !== true && JSON.stringify(merged[key]) !== JSON.stringify(value)) throw new Error(`deictic: the build has deictic twice, with ${key} set two ways: set it in one of them only`);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
return {
|
|
273
|
+
...merged,
|
|
274
|
+
plugins: [...plugins.values()]
|
|
275
|
+
};
|
|
276
|
+
}
|
|
250
277
|
/** The options with their defaults, checked now, so a wrong set stops the dev server as it starts, not the page. */
|
|
251
278
|
function prepare(options) {
|
|
252
279
|
const plugins = options.plugins ?? [];
|
|
@@ -328,6 +355,6 @@ function fileIn(path, root) {
|
|
|
328
355
|
const file = relative(root, path).replaceAll("\\", "/");
|
|
329
356
|
return file.startsWith("..") || isAbsolute(file) ? void 0 : file;
|
|
330
357
|
}
|
|
331
|
-
export {
|
|
358
|
+
export { isHost as _, markAstro as a, openingsIn as b, writeClient as c, problemIn as d, reporter as f, JSX as g, parseAstro as h, mark as i, setUp as l, ASTRO as m, clientModule as n, merge as o, stackOf as p, importOf as r, prepare as s, beside as t, messageOf as u, lineStarts as v, parse as x, offsetOf as y };
|
|
332
359
|
|
|
333
360
|
//# sourceMappingURL=integration.js.map
|