deictic 0.8.1 → 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.
Files changed (128) hide show
  1. package/API.md +81 -17
  2. package/README.md +1 -1
  3. package/dist/annotations/client.js +1 -1
  4. package/dist/bun.d.ts.map +1 -1
  5. package/dist/bun.js +26 -8
  6. package/dist/bun.js.map +1 -1
  7. package/dist/cli.js +1 -1
  8. package/dist/cli.js.map +1 -1
  9. package/dist/client/index.d.ts +13 -13
  10. package/dist/client/index.d.ts.map +1 -1
  11. package/dist/client/index.js +19 -7
  12. package/dist/client/index.js.map +1 -1
  13. package/dist/next.d.ts.map +1 -1
  14. package/dist/next.js +45 -25
  15. package/dist/next.js.map +1 -1
  16. package/dist/react/client.d.ts +19 -0
  17. package/dist/react/client.d.ts.map +1 -0
  18. package/dist/react/client.js +504 -0
  19. package/dist/react/client.js.map +1 -0
  20. package/dist/react/index.d.ts +2 -0
  21. package/dist/react/index.js +1 -0
  22. package/dist/recommended/index.d.ts +15 -7
  23. package/dist/recommended/index.d.ts.map +1 -1
  24. package/dist/recommended/index.js +1 -1
  25. package/dist/recordings/client.d.ts.map +1 -1
  26. package/dist/recordings/client.js +48 -5
  27. package/dist/recordings/client.js.map +1 -1
  28. package/dist/screenshots/client.d.ts +9 -1
  29. package/dist/screenshots/client.d.ts.map +1 -1
  30. package/dist/screenshots/rrweb.d.ts +0 -6
  31. package/dist/screenshots/rrweb.d.ts.map +1 -1
  32. package/dist/screenshots/rrweb.js +46 -12
  33. package/dist/screenshots/rrweb.js.map +1 -1
  34. package/dist/shared/board.js +1 -1
  35. package/dist/shared/client.js +44 -2
  36. package/dist/shared/client.js.map +1 -1
  37. package/dist/shared/dom.js +7 -1
  38. package/dist/shared/dom.js.map +1 -1
  39. package/dist/shared/drawer.js +1 -1
  40. package/dist/shared/endpoints.js +15 -4
  41. package/dist/shared/endpoints.js.map +1 -1
  42. package/dist/shared/index.d.ts +11 -0
  43. package/dist/shared/index.d.ts.map +1 -1
  44. package/dist/shared/index10.d.ts +70 -0
  45. package/dist/shared/index10.d.ts.map +1 -0
  46. package/dist/shared/index3.d.ts +11 -0
  47. package/dist/shared/index3.d.ts.map +1 -1
  48. package/dist/shared/index7.d.ts +92 -312
  49. package/dist/shared/index7.d.ts.map +1 -1
  50. package/dist/shared/index8.d.ts +324 -47
  51. package/dist/shared/index8.d.ts.map +1 -1
  52. package/dist/shared/index9.d.ts +45 -63
  53. package/dist/shared/index9.d.ts.map +1 -1
  54. package/dist/shared/init.js +15 -11
  55. package/dist/shared/init.js.map +1 -1
  56. package/dist/shared/integration.d.ts +6 -0
  57. package/dist/shared/integration.d.ts.map +1 -1
  58. package/dist/shared/integration.js +28 -1
  59. package/dist/shared/integration.js.map +1 -1
  60. package/dist/shared/marks.js +7 -1
  61. package/dist/shared/marks.js.map +1 -1
  62. package/dist/shared/package.js +3 -1
  63. package/dist/shared/packages.js +1 -1
  64. package/dist/shared/playwright.js +39 -1
  65. package/dist/shared/playwright.js.map +1 -1
  66. package/dist/shared/react.js +25 -0
  67. package/dist/shared/react.js.map +1 -0
  68. package/dist/shared/recommended.js +6 -3
  69. package/dist/shared/recommended.js.map +1 -1
  70. package/dist/shared/recording.js +80 -3
  71. package/dist/shared/recording.js.map +1 -1
  72. package/dist/shared/recordings.js +30 -2
  73. package/dist/shared/recordings.js.map +1 -1
  74. package/dist/shared/screenshots.js.map +1 -1
  75. package/dist/shared/src.js.map +1 -1
  76. package/dist/shared/task.js +1 -0
  77. package/dist/shared/task.js.map +1 -1
  78. package/dist/shared/tasks.js +11 -0
  79. package/dist/shared/tasks.js.map +1 -1
  80. package/dist/shared/vite.d.ts +1 -1
  81. package/dist/shared/vite.d.ts.map +1 -1
  82. package/dist/shared/vite.js +28 -10
  83. package/dist/shared/vite.js.map +1 -1
  84. package/dist/tailwind/client.d.ts +1 -1
  85. package/dist/tailwind/index.d.ts +1 -1
  86. package/dist/tasks/client.d.ts +1 -1
  87. package/dist/tasks/client.js +45 -19
  88. package/dist/tasks/client.js.map +1 -1
  89. package/dist/tasks/index.d.ts +1 -1
  90. package/dist/voice/client.d.ts +1 -1
  91. package/dist/voice/client.js +1 -1
  92. package/dist/voice/index.d.ts +1 -1
  93. package/dist/webpack.d.ts +4 -0
  94. package/dist/webpack.d.ts.map +1 -1
  95. package/dist/webpack.js +37 -15
  96. package/dist/webpack.js.map +1 -1
  97. package/package.json +25 -1
  98. package/src/bun.ts +32 -8
  99. package/src/cli/bun.ts +2 -2
  100. package/src/cli/init.ts +14 -9
  101. package/src/cli/recording.ts +90 -4
  102. package/src/cli/task.ts +4 -0
  103. package/src/cli.ts +13 -6
  104. package/src/client/dom.ts +14 -0
  105. package/src/client/index.ts +25 -14
  106. package/src/index.ts +11 -0
  107. package/src/next.ts +34 -15
  108. package/src/plugins/react/client.ts +162 -0
  109. package/src/plugins/react/index.ts +130 -0
  110. package/src/plugins/react/renders.ts +219 -0
  111. package/src/plugins/react/serialize.ts +139 -0
  112. package/src/plugins/react/timeline.ts +143 -0
  113. package/src/plugins/recommended/index.ts +17 -5
  114. package/src/plugins/recordings/client.ts +64 -4
  115. package/src/plugins/recordings/marks.ts +7 -0
  116. package/src/plugins/recordings/replay.ts +30 -2
  117. package/src/plugins/screenshots/client.ts +42 -2
  118. package/src/plugins/screenshots/index.ts +11 -0
  119. package/src/plugins/screenshots/playwright.ts +65 -1
  120. package/src/plugins/screenshots/rrweb.ts +55 -28
  121. package/src/plugins/screenshots/states.ts +26 -0
  122. package/src/plugins/tasks/client.ts +41 -6
  123. package/src/plugins/tasks/composer.ts +24 -7
  124. package/src/plugins/tasks/index.ts +16 -2
  125. package/src/tools/integration.ts +33 -0
  126. package/src/tools/source.ts +14 -2
  127. package/src/vite.ts +31 -10
  128. package/src/webpack.ts +48 -16
@@ -1 +1 @@
1
- {"version":3,"file":"next.d.ts","names":[],"sources":["../src/next.ts"],"mappings":";iBA2BiB,2BAA2B;;EAE1C;;KAUG,eAAe,MAAM,eAAe;EAAW,eAAe;MAAQ,IAAI,QAAQ;;;;;wBAavE,YAAY,kBAC1B,OAAM,IAAI,eAAe,IACzB,UAAS,sBACP,eAAe;EAAW,eAAe;MAAQ,QAAQ"}
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 { h as JSX, o as prepare, s as writeClient, t as beside } from "./shared/integration.js";
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
- const { plugins, shortcut } = prepare(options);
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 root = resolve(options.root ?? process.cwd());
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
- return withRewrite(withWebpack(withRules(resolved, GLOBS.flatMap((glob) => [[glob, {
44
- condition: { all: ["browser", { not: "foreign" }] },
45
- loaders: [{
46
- loader: loaderPath,
47
- options: {
48
- root,
49
- client
50
- }
51
- }]
52
- }], [glob, {
53
- condition: { all: [{ not: "browser" }, { not: "foreign" }] },
54
- loaders: [{
55
- loader: loaderPath,
56
- options: { root }
57
- }]
58
- }]])), root, client), await serve(root, plugins, base));
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, plugins, base) {
142
+ function serve(root, base) {
123
143
  const running = serving.get(root);
124
144
  if (running !== void 0) return running;
125
- const handle = endpoints({
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 middleware = nodeMiddleware(handle);
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,SAAS,CACtD,CAAC,MAAM;GAAE,WAAW,EAAE,KAAK,CAAC,WAAW,EAAE,KAAK,UAAU,CAAC,EAAE;GAAG,SAAS,CAAC;IAAE,QAAQ;IAAY,SAAS;KAAE;KAAM;IAAO;GAAE,CA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;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":";;;;;;;;;;;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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"}
@@ -0,0 +1,19 @@
1
+ import { t as Commit } from "../shared/index7.js";
2
+ /** What a task asks of the plugin, and a recording. */
3
+ export interface Inspector {
4
+ /** The snapshot of the element's components, as the JSON a task attaches: `undefined` where React didn't render it in development. */
5
+ snapshot(el: Element): Promise<string | undefined>;
6
+ /**
7
+ * React's commits from now, an entry a frame (`emit` hears each), until what's answered stops it: for a recording.
8
+ * `undefined` where renders aren't counted (`renders: false`, or no DevTools hook on the page).
9
+ */
10
+ commits?: (emit: (commit: Commit) => void) => () => void;
11
+ }
12
+ declare module 'deictic' {
13
+ interface ClientApis {
14
+ react: Inspector;
15
+ }
16
+ }
17
+ declare const _default: import("deictic").ClientPlugin<never, never, Inspector>;
18
+ export { _default as default };
19
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","names":[],"sources":["../../src/plugins/react/client.ts"],"mappings":";;iBAgBiB;;EAEf,SAAS,IAAI,UAAU;;;;;EAKvB,WAAW,OAAO,QAAQ;;;YAIhB;IACR,OAAO;;;cAuDX,4B"}