@spotpatch/next 0.1.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/LICENSE +21 -0
- package/README.md +228 -0
- package/dist/cli.js +1527 -0
- package/dist/cli.js.map +1 -0
- package/dist/client.cjs +232 -0
- package/dist/client.cjs.map +1 -0
- package/dist/client.d.cts +11 -0
- package/dist/client.d.ts +11 -0
- package/dist/client.js +234 -0
- package/dist/client.js.map +1 -0
- package/dist/index.cjs +570 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +14 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +541 -0
- package/dist/index.js.map +1 -0
- package/dist/loader.cjs +235 -0
- package/dist/loader.cjs.map +1 -0
- package/dist/noop.cjs +19 -0
- package/dist/noop.cjs.map +1 -0
- package/dist/noop.d.cts +2 -0
- package/dist/noop.d.ts +2 -0
- package/dist/noop.js +1 -0
- package/dist/noop.js.map +1 -0
- package/loader.cjs +3 -0
- package/loader.d.cts +23 -0
- package/package.json +118 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 SpotPatch contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="https://github.com/huanglvjing/spotpatch">
|
|
3
|
+
<img src="https://raw.githubusercontent.com/huanglvjing/spotpatch/main/docs/assets/spotpatch-logo.svg" alt="SpotPatch" width="680" />
|
|
4
|
+
</a>
|
|
5
|
+
</p>
|
|
6
|
+
|
|
7
|
+
<p align="center">
|
|
8
|
+
<a href="#english">English</a> · <a href="#简体中文">简体中文</a>
|
|
9
|
+
</p>
|
|
10
|
+
|
|
11
|
+
<p align="center">
|
|
12
|
+
<a href="https://www.npmjs.com/package/@spotpatch/next"><img src="https://img.shields.io/npm/v/%40spotpatch%2Fnext?logo=npm&label=npm" alt="npm version" /></a>
|
|
13
|
+
<img src="https://img.shields.io/badge/status-public_preview-F59E0B" alt="Public preview" />
|
|
14
|
+
<a href="https://github.com/huanglvjing/spotpatch/actions/workflows/ci.yml"><img src="https://github.com/huanglvjing/spotpatch/actions/workflows/ci.yml/badge.svg?branch=main" alt="CI status" /></a>
|
|
15
|
+
<a href="https://github.com/huanglvjing/spotpatch/blob/main/LICENSE"><img src="https://img.shields.io/github/license/huanglvjing/spotpatch" alt="MIT license" /></a>
|
|
16
|
+
</p>
|
|
17
|
+
|
|
18
|
+
# `@spotpatch/next`
|
|
19
|
+
|
|
20
|
+
## English
|
|
21
|
+
|
|
22
|
+
> [!WARNING]
|
|
23
|
+
> This package is a **0.x public preview**, not a formally supported Next.js integration. Its peer dependency range must not be interpreted as a completed compatibility or production-support claim.
|
|
24
|
+
|
|
25
|
+
The preview connects SpotPatch's element picker, source-aware context, bilingual multi-target requests, and optional review-gated AI Agent to a Next.js development server.
|
|
26
|
+
|
|
27
|
+
### Implemented preview path
|
|
28
|
+
|
|
29
|
+
- `withSpotPatch()` composes an existing `next.config` without evaluating it twice.
|
|
30
|
+
- `spotpatch-next dev` owns the loopback-only Next child process and Sidecar lifecycle.
|
|
31
|
+
- Development-only Turbopack and webpack Loader paths register source and inject JSX/TSX markers.
|
|
32
|
+
- `@spotpatch/next/client` installs the React hook from `instrumentation-client`, then bootstraps one Runtime.
|
|
33
|
+
- Private API rewrites use a randomized loopback Sidecar origin and per-launch secrets.
|
|
34
|
+
- Production configuration aliases the client to a side-effect-free no-op and does not add the Loader, Sidecar, source registry, or private rewrite.
|
|
35
|
+
- `spotpatch-next init` previews and applies supported integration edits with rollback on failure.
|
|
36
|
+
- `spotpatch-next check` diagnoses the package graph and generated integration without starting development.
|
|
37
|
+
|
|
38
|
+
### Public preview integration
|
|
39
|
+
|
|
40
|
+
Install the single framework entry package. Its required SpotPatch internal packages are resolved automatically; do not install them individually.
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
pnpm add --save-dev @spotpatch/next
|
|
44
|
+
pnpm exec spotpatch-next init
|
|
45
|
+
pnpm exec spotpatch-next check
|
|
46
|
+
pnpm dev
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
The supported initializer result has three parts:
|
|
50
|
+
|
|
51
|
+
```ts
|
|
52
|
+
// next.config.ts
|
|
53
|
+
import type { NextConfig } from "next";
|
|
54
|
+
import { withSpotPatch } from "@spotpatch/next";
|
|
55
|
+
|
|
56
|
+
const nextConfig: NextConfig = {};
|
|
57
|
+
|
|
58
|
+
export default withSpotPatch()(nextConfig);
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
```ts
|
|
62
|
+
// instrumentation-client.ts
|
|
63
|
+
// Use src/instrumentation-client.ts when the router lives under src.
|
|
64
|
+
import "@spotpatch/next/client";
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
```json
|
|
68
|
+
{
|
|
69
|
+
"scripts": {
|
|
70
|
+
"dev": "spotpatch-next dev"
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Start development through the package script, not a direct `next dev` command. A successful startup prints one line beginning with `[spotpatch:next] ready`; the page then mounts one `spotpatch-root` Shadow DOM host with the **Select element** / **选择元素** action.
|
|
76
|
+
|
|
77
|
+
### Current evidence and remaining gates
|
|
78
|
+
|
|
79
|
+
The public preview has passed:
|
|
80
|
+
|
|
81
|
+
- package build, type publication, Publint, and Are The Types Wrong checks;
|
|
82
|
+
- formal unit and HTTP boundary tests;
|
|
83
|
+
- a locked Loader POC covering selected Next 15/React 18 and Next 16/React 19 combinations;
|
|
84
|
+
- one private Next 16 App Router host with Turbopack and webpack development startup;
|
|
85
|
+
- authenticated Runtime bootstrap, source registration, source-context lookup, and Runtime singleton checks in that host;
|
|
86
|
+
- Turbopack and webpack Fast Refresh in the private Runtime POC;
|
|
87
|
+
- webpack production isolation in the private host;
|
|
88
|
+
- a separate historical Turbopack production Loader POC for the locked host.
|
|
89
|
+
|
|
90
|
+
Formal public support remains blocked on the complete required Next/React/router/Node/OS matrix, Pages and hybrid router coverage, broader RSC navigation cases, fresh browser interaction evidence, complex rewrite/base path fixtures, and a full Turbopack production zero-residual fixture.
|
|
91
|
+
|
|
92
|
+
Read the [implementation status](https://github.com/huanglvjing/spotpatch/blob/main/docs/%E6%8A%80%E6%9C%AF%E6%96%B9%E6%A1%88/Next%E9%80%82%E9%85%8D/00-%E7%B4%A2%E5%BC%95%E4%B8%8E%E6%9E%B6%E6%9E%84%E6%91%98%E8%A6%81.md) and [required release matrix](https://github.com/huanglvjing/spotpatch/blob/main/docs/%E6%8A%80%E6%9C%AF%E6%96%B9%E6%A1%88/Next%E9%80%82%E9%85%8D/08-%E6%B5%8B%E8%AF%95%E9%AA%8C%E6%94%B6%E4%B8%8E%E5%AE%9E%E6%96%BD%E8%AE%A1%E5%88%92.md) before drawing compatibility conclusions.
|
|
93
|
+
|
|
94
|
+
### Declared peer range
|
|
95
|
+
|
|
96
|
+
| Dependency | Package range | What it means |
|
|
97
|
+
| ----------------- | ---------------------- | ---------------------------------------------------------------------------------------- |
|
|
98
|
+
| Node.js | `>=20.19.0` | Package engine requirement. |
|
|
99
|
+
| Next.js | `>=15.3.0 <17.0.0` | Candidate range for the preview matrix, not a support guarantee. |
|
|
100
|
+
| React / React DOM | `^18.2.0` or `^19.0.0` | Installable candidate range; React 19 Fiber semantics still degrade in controlled cases. |
|
|
101
|
+
|
|
102
|
+
The first preview accepts only loopback development hosts and rejects `allowLan: true`. Complex CommonJS `next.config` files, mixed root/`src` routers, conflicting Loader rules, and conflicting private-prefix rewrites fail closed or require manual integration.
|
|
103
|
+
|
|
104
|
+
### Production behavior
|
|
105
|
+
|
|
106
|
+
Use ordinary Next.js production commands:
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
pnpm exec next build
|
|
110
|
+
pnpm exec next start
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
`spotpatch-next` intentionally proxies only `dev`. Production use is not supported by the 0.x preview; validation must continue proving that production output contains no `data-spotpatch-source`, `spotpatch-root`, Runtime bootstrap state, private API prefix, or internal configuration and registration secrets.
|
|
114
|
+
|
|
115
|
+
### Hydration warning from browser extensions
|
|
116
|
+
|
|
117
|
+
If React reports only a removed body attribute such as `cz-shortcut-listen="true"`, a browser extension changed the document before hydration. That warning is independent of SpotPatch initialization; test in a clean browser profile before treating it as an adapter defect.
|
|
118
|
+
|
|
119
|
+
---
|
|
120
|
+
|
|
121
|
+
## 简体中文
|
|
122
|
+
|
|
123
|
+
> [!WARNING]
|
|
124
|
+
> 本包是 **0.x 公共预览版**,不是正式支持的 Next.js 接入。peer dependency 范围不能解释成兼容矩阵或生产支持已经完成。
|
|
125
|
+
|
|
126
|
+
当前预览把 SpotPatch 的元素选择、源码上下文、中英文多目标修改要求和可选审阅式 AI Agent 接入 Next.js 开发服务器。
|
|
127
|
+
|
|
128
|
+
### 已实现的预览链路
|
|
129
|
+
|
|
130
|
+
- `withSpotPatch()` 组合现有 `next.config`,不会重复执行宿主配置。
|
|
131
|
+
- `spotpatch-next dev` 管理只监听 loopback 的 Next 子进程与 Sidecar 生命周期。
|
|
132
|
+
- 仅开发期启用的 Turbopack/webpack Loader 注册源码并注入 JSX/TSX 标记。
|
|
133
|
+
- `@spotpatch/next/client` 从 `instrumentation-client` 安装 React hook,再启动唯一 Runtime。
|
|
134
|
+
- 私有 API rewrite 使用随机 loopback Sidecar origin 和每次启动生成的秘密。
|
|
135
|
+
- 生产配置把客户端入口替换为无副作用 no-op,不添加 Loader、Sidecar、源码注册或私有 rewrite。
|
|
136
|
+
- `spotpatch-next init` 预览并应用受支持的接入修改,失败时执行回滚。
|
|
137
|
+
- `spotpatch-next check` 在不启动开发服务器的情况下诊断包依赖和接入文件。
|
|
138
|
+
|
|
139
|
+
### 公共预览接入
|
|
140
|
+
|
|
141
|
+
只需安装一个框架入口包,所需 SpotPatch 内部包会自动解析,不要逐个手工安装。
|
|
142
|
+
|
|
143
|
+
```bash
|
|
144
|
+
pnpm add --save-dev @spotpatch/next
|
|
145
|
+
pnpm exec spotpatch-next init
|
|
146
|
+
pnpm exec spotpatch-next check
|
|
147
|
+
pnpm dev
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
受支持的初始化结果包含三部分:
|
|
151
|
+
|
|
152
|
+
```ts
|
|
153
|
+
// next.config.ts
|
|
154
|
+
import type { NextConfig } from "next";
|
|
155
|
+
import { withSpotPatch } from "@spotpatch/next";
|
|
156
|
+
|
|
157
|
+
const nextConfig: NextConfig = {};
|
|
158
|
+
|
|
159
|
+
export default withSpotPatch()(nextConfig);
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
```ts
|
|
163
|
+
// instrumentation-client.ts
|
|
164
|
+
// Router 位于 src 下时使用 src/instrumentation-client.ts。
|
|
165
|
+
import "@spotpatch/next/client";
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
```json
|
|
169
|
+
{
|
|
170
|
+
"scripts": {
|
|
171
|
+
"dev": "spotpatch-next dev"
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
必须通过 package script 启动,而不是直接运行 `next dev`。成功启动时终端只打印一条以 `[spotpatch:next] ready` 开头的信息;页面随后挂载唯一 `spotpatch-root` Shadow DOM,并显示 **Select element** / **选择元素** 操作。
|
|
177
|
+
|
|
178
|
+
### 当前证据与剩余门禁
|
|
179
|
+
|
|
180
|
+
公共预览已经通过:
|
|
181
|
+
|
|
182
|
+
- 包构建、类型发布、Publint 与 Are The Types Wrong;
|
|
183
|
+
- 正式单元测试与 HTTP 边界测试;
|
|
184
|
+
- 锁定范围的 Loader POC,覆盖选定的 Next 15/React 18 和 Next 16/React 19 组合;
|
|
185
|
+
- 一个私有 Next 16 App Router 宿主的 Turbopack 与 webpack 开发启动;
|
|
186
|
+
- 该宿主中的认证 Runtime bootstrap、源码注册、源码上下文读取和 Runtime 单例检查;
|
|
187
|
+
- 私有 Runtime POC 的 Turbopack 与 webpack Fast Refresh;
|
|
188
|
+
- 私有宿主的 webpack 生产隔离;
|
|
189
|
+
- 锁定宿主独立的历史 Turbopack 生产 Loader POC。
|
|
190
|
+
|
|
191
|
+
正式公共支持仍被以下项目阻断:完整 Next/React/router/Node/OS required matrix、Pages 与 hybrid Router、更广泛的 RSC 导航、全新浏览器交互证据、复杂 rewrite/basePath fixture,以及完整的 Turbopack 生产零残留 fixture。
|
|
192
|
+
|
|
193
|
+
判断兼容性前必须阅读[实现状态](https://github.com/huanglvjing/spotpatch/blob/main/docs/%E6%8A%80%E6%9C%AF%E6%96%B9%E6%A1%88/Next%E9%80%82%E9%85%8D/00-%E7%B4%A2%E5%BC%95%E4%B8%8E%E6%9E%B6%E6%9E%84%E6%91%98%E8%A6%81.md)与[发布 required matrix](https://github.com/huanglvjing/spotpatch/blob/main/docs/%E6%8A%80%E6%9C%AF%E6%96%B9%E6%A1%88/Next%E9%80%82%E9%85%8D/08-%E6%B5%8B%E8%AF%95%E9%AA%8C%E6%94%B6%E4%B8%8E%E5%AE%9E%E6%96%BD%E8%AE%A1%E5%88%92.md)。
|
|
194
|
+
|
|
195
|
+
### 声明的 peer 范围
|
|
196
|
+
|
|
197
|
+
| 依赖 | Package 范围 | 准确含义 |
|
|
198
|
+
| ----------------- | ---------------------- | --------------------------------------------------- |
|
|
199
|
+
| Node.js | `>=20.19.0` | 包的 engine 要求。 |
|
|
200
|
+
| Next.js | `>=15.3.0 <17.0.0` | 预览兼容矩阵候选范围,不是支持保证。 |
|
|
201
|
+
| React / React DOM | `^18.2.0` 或 `^19.0.0` | 可安装候选范围;React 19 Fiber 语义仍可能受控降级。 |
|
|
202
|
+
|
|
203
|
+
首版预览只接受 loopback 开发主机并拒绝 `allowLan: true`。复杂 CommonJS `next.config`、混合 root/`src` Router、冲突 Loader rule 和占用私有前缀的 rewrite 会安全失败或要求手动接入。
|
|
204
|
+
|
|
205
|
+
### 生产行为
|
|
206
|
+
|
|
207
|
+
生产环境使用普通 Next.js 命令:
|
|
208
|
+
|
|
209
|
+
```bash
|
|
210
|
+
pnpm exec next build
|
|
211
|
+
pnpm exec next start
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
`spotpatch-next` 只代理 `dev`。0.x 预览版不支持生产使用;验证必须继续证明生产产物中不存在 `data-spotpatch-source`、`spotpatch-root`、Runtime bootstrap 状态、私有 API 前缀和内部配置/注册秘密。
|
|
215
|
+
|
|
216
|
+
### 浏览器扩展造成的 Hydration 警告
|
|
217
|
+
|
|
218
|
+
如果 React 只报告类似 `cz-shortcut-listen="true"` 的 body 属性被移除,说明浏览器扩展在 hydration 前修改了文档。该警告与 SpotPatch 初始化无关;把它归因于适配器之前,应先在干净浏览器 Profile 中复现。
|
|
219
|
+
|
|
220
|
+
### Links / 链接
|
|
221
|
+
|
|
222
|
+
- [SpotPatch repository / 仓库](https://github.com/huanglvjing/spotpatch)
|
|
223
|
+
- [Next.js implementation status / 实现状态](https://github.com/huanglvjing/spotpatch/blob/main/docs/%E6%8A%80%E6%9C%AF%E6%96%B9%E6%A1%88/Next%E9%80%82%E9%85%8D/00-%E7%B4%A2%E5%BC%95%E4%B8%8E%E6%9E%B6%E6%9E%84%E6%91%98%E8%A6%81.md)
|
|
224
|
+
- [Issues / 问题反馈](https://github.com/huanglvjing/spotpatch/issues)
|
|
225
|
+
|
|
226
|
+
### License / 许可证
|
|
227
|
+
|
|
228
|
+
[MIT](https://github.com/huanglvjing/spotpatch/blob/main/LICENSE) © SpotPatch contributors.
|